Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

import java.util.Collection;
import java.util.List;
import java.util.Map;

import org.orcid.jaxb.model.v3.release.common.Source;
import org.orcid.jaxb.model.v3.release.record.Work;
import org.orcid.jaxb.model.v3.release.record.summary.WorkSummary;
import org.orcid.persistence.jpa.entities.MinimizedExtendedWorkEntity;
import org.orcid.persistence.jpa.entities.MinimizedWorkEntity;
import org.orcid.persistence.jpa.entities.ClientDetailsEntity;
import org.orcid.persistence.jpa.entities.WorkEntity;
import org.orcid.pojo.WorkExtended;
import org.orcid.pojo.WorkSummaryExtended;
Expand Down Expand Up @@ -34,6 +37,8 @@ public interface JpaJaxbWorkAdapter {

List<WorkSummary> toWorkSummaryFromMinimized(Collection<MinimizedWorkEntity> workEntities);

List<WorkSummary> toWorkSummaryFromMinimized(Collection<MinimizedWorkEntity> workEntities, Map<String, Source> sources);

List<WorkSummaryExtended> toWorkSummaryExtendedFromMinimized(Collection<MinimizedExtendedWorkEntity> workEntities);

WorkEntity toWorkEntity(Work work, WorkEntity existing);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import ma.glasnost.orika.converter.BidirectionalConverter;
import ma.glasnost.orika.metadata.Type;
import org.orcid.core.contributors.roles.ContributorRoleConverter;
import org.orcid.core.contributors.roles.ContributorRoleConverterImpl;
import org.orcid.core.contributors.roles.credit.CreditRole;
import org.orcid.core.utils.JsonUtils;
import org.orcid.core.utils.v3.ContributorUtils;
Expand All @@ -15,18 +16,19 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

public class ContributorsRolesAndSequencesConverter extends BidirectionalConverter<List<ContributorsRolesAndSequences>, String> {

private static final Logger LOGGER = LoggerFactory.getLogger(ContributorsRolesAndSequencesConverter.class);

private ContributorRoleConverter roleConverter;
@Resource(name = "workContributorRoleConverter")
private ContributorRoleConverter workContributorRoleConverter;

public ContributorsRolesAndSequencesConverter(ContributorRoleConverter roleConverter) {
this.roleConverter = roleConverter;
}
@Resource(name = "contributorUtilsV3")
private ContributorUtils contributorUtils;

@Override
public String convertTo(List<ContributorsRolesAndSequences> source, Type<String> destinationType) {
Expand All @@ -39,7 +41,6 @@ public List<ContributorsRolesAndSequences> convertFrom(String source, Type<List<
}

public List<ContributorsRolesAndSequences> getContributorsRolesAndSequencesList(String source) {
ContributorUtils contributorUtils = new ContributorUtils(null);
final ObjectMapper objectMapper = new ObjectMapper();
List<ContributorsRolesAndSequences> contributorsRolesAndSequencesResult = new ArrayList<>();
try {
Expand All @@ -54,7 +55,7 @@ public List<ContributorsRolesAndSequences> getContributorsRolesAndSequencesList(
if (cr != null) {
providedRoleValue = cr.name();
}
crs.setContributorRole(contributorUtils.getCreditRole(roleConverter.toRoleValue(providedRoleValue)));
crs.setContributorRole(contributorUtils.getCreditRole(workContributorRoleConverter.toRoleValue(providedRoleValue)));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@

import java.util.Collection;
import java.util.List;
import java.util.Map;

import ma.glasnost.orika.MappingContext;
import ma.glasnost.orika.MapperFacade;

import org.orcid.core.utils.SourceEntityUtils;
import org.orcid.core.adapter.v3.JpaJaxbWorkAdapter;
import org.orcid.jaxb.model.v3.release.common.Source;
import org.orcid.jaxb.model.v3.release.record.Work;
import org.orcid.jaxb.model.v3.release.record.summary.WorkSummary;
import org.orcid.persistence.jpa.entities.ClientDetailsEntity;
import org.orcid.persistence.jpa.entities.MinimizedExtendedWorkEntity;
import org.orcid.persistence.jpa.entities.MinimizedWorkEntity;
import org.orcid.persistence.jpa.entities.WorkEntity;
Expand Down Expand Up @@ -100,6 +105,16 @@ public List<WorkSummary> toWorkSummaryFromMinimized(Collection<MinimizedWorkEnti
return mapperFacade.mapAsList(workEntities, WorkSummary.class);
}

@Override
public List<WorkSummary> toWorkSummaryFromMinimized(Collection<MinimizedWorkEntity> workEntities, Map<String, Source> sourceMap) {
if(workEntities == null) {
return null;
}
MappingContext context = new MappingContext.Factory().getContext();
context.setProperty(SourceEntityUtils.SOURCE_MAP, sourceMap);
return mapperFacade.mapAsList(workEntities, WorkSummary.class, context);
}

@Override
public List<WorkSummaryExtended> toWorkSummaryExtendedFromMinimized(Collection<MinimizedExtendedWorkEntity> workEntities) {
if(workEntities == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,9 @@
import org.orcid.core.contributors.roles.works.WorkContributorRoleConverter;
import org.orcid.core.exception.OrcidValidationException;
import org.orcid.core.locale.LocaleManager;
import org.orcid.core.manager.ClientDetailsEntityCacheManager;
import org.orcid.core.manager.EncryptionManager;
import org.orcid.core.manager.IdentityProviderManager;
import org.orcid.core.manager.SourceNameCacheManager;
import org.orcid.core.manager.impl.OrcidUrlManager;
import org.orcid.core.manager.v3.read_only.ClientDetailsManagerReadOnly;
import org.orcid.core.utils.JsonUtils;
import org.orcid.core.utils.SourceEntityUtils;
import org.orcid.core.utils.v3.identifiers.PIDNormalizationService;
Expand Down Expand Up @@ -140,7 +137,6 @@
import org.orcid.persistence.jpa.entities.SpamEntity;
import org.orcid.persistence.jpa.entities.StartDateEntity;
import org.orcid.persistence.jpa.entities.WorkEntity;
import org.orcid.persistence.jpa.entities.keys.ClientRedirectUriPk;
import org.orcid.pojo.WorkExtended;
import org.orcid.pojo.WorkSummaryExtended;
import org.orcid.pojo.ajaxForm.PojoUtil;
Expand Down Expand Up @@ -170,15 +166,6 @@ public class MapperFacadeFactory implements FactoryBean<MapperFacade> {
@Resource
private WorkDao workDao;

@Resource
private SourceNameCacheManager sourceNameCacheManager;

@Resource
private ClientDetailsEntityCacheManager clientDetailsEntityCacheManager;

@Resource(name = "clientDetailsManagerReadOnlyV3")
private ClientDetailsManagerReadOnly clientDetailsManagerReadOnly;

@Resource
private IdentityProviderManager identityProviderManager;

Expand All @@ -200,6 +187,12 @@ public class MapperFacadeFactory implements FactoryBean<MapperFacade> {
@Resource
private FundingContributorRoleConverter fundingContributorsRoleConverter;

@Resource
private SourceEntityUtils sourceEntityUtils;

@Resource
private ContributorsRolesAndSequencesConverter contributorsRolesAndSequencesConverter;

@Override
public MapperFacade getObject() throws Exception {
MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();
Expand Down Expand Up @@ -387,10 +380,19 @@ public void registerSourceConverters(MapperFactory mapperFactory, ClassMapBuilde
}

private class SourceMapper<T, U> extends CustomMapper<SourceAware, SourceAwareEntity<?>> {
@SuppressWarnings("unchecked")
@Override
public void mapBtoA(SourceAwareEntity<?> b, SourceAware a, MappingContext context) {
Source source = SourceEntityUtils.extractSourceFromEntityComplete(b, sourceNameCacheManager, orcidUrlManager, clientDetailsEntityCacheManager);
a.setSource(source);
if (context != null && context.getProperty(SourceEntityUtils.SOURCE_MAP) != null) {
// The source map is set in the context, so we can use it to set the source.
Map<String, Source> sourceMap = (Map<String, Source>) context.getProperty(SourceEntityUtils.SOURCE_MAP);
Source source = sourceMap.get(sourceEntityUtils.getSourceKey(b));
a.setSource(source);
} else {
// We have to manually build the source elements
Source source = sourceEntityUtils.extractSourceFromEntityComplete(b);
a.setSource(source);
}
}
}

Expand Down Expand Up @@ -536,8 +538,6 @@ public MapperFacade getWorkMapperFacade() {
MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();

WorkContributorsConverter wcc = new WorkContributorsConverter(workContributorsRoleConverter);
ContributorsRolesAndSequencesConverter contributorsRolesAndSequencesConverter = new ContributorsRolesAndSequencesConverter(workContributorsRoleConverter);

ConverterFactory converterFactory = mapperFactory.getConverterFactory();
converterFactory.registerConverter("workExternalIdentifiersConverterId", new JSONWorkExternalIdentifiersConverterV3(norm, resolverService, localeManager));
converterFactory.registerConverter("workContributorsConverterId", wcc);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ private void filter() {

private void filterTopContributors(Object[] workObject) {
WorkEntity workEntity = workDao.find(((BigInteger) workObject[0]).longValue());
ContributorUtils contributorUtils = new ContributorUtils(0);
ContributorUtils contributorUtils = new ContributorUtils();
WorkSummaryExtended wse = new WorkSummaryExtended.WorkSummaryExtendedBuilder(((BigInteger) workObject[0]))
.contributors(workContributorsConverter.getContributorsList(isEmpty(workObject[1])))
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.orcid.core.utils.SourceEntityUtils;
import org.orcid.jaxb.model.v3.release.common.Source;

Expand All @@ -19,10 +20,10 @@ public InvalidPutCodeException(Map<String, String> params) {
super(params);
}

public static InvalidPutCodeException forSource(Source activeSource) {
public static InvalidPutCodeException forSource(String sourceName) {
Map<String, String> params = new HashMap<String, String>();
if (activeSource != null) {
params.put("clientName", SourceEntityUtils.getSourceName(activeSource));
if (StringUtils.isNoneBlank(sourceName)) {
params.put("clientName", sourceName);
}
return new InvalidPutCodeException(params);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ public class OrcidCoreExceptionMapper {
@Resource(name = "sourceManagerV3")
private SourceManager sourceManager;

@Resource
private SourceEntityUtils sourceEntityUtils;

private static Map<Class<? extends Throwable>, Pair<Response.Status, Integer>> HTTP_STATUS_AND_ERROR_CODE_BY_THROWABLE_TYPE = new HashMap<>();
{
// 301
Expand Down Expand Up @@ -226,7 +229,7 @@ public org.orcid.jaxb.model.v3.release.error.OrcidError getOrcidErrorV3(int erro
Map<String, String> params = null;
if (t instanceof PutCodeFormatException) {
params = new HashMap<String, String>();
params.put("clientName", SourceEntityUtils.getSourceName(sourceManager.retrieveActiveSource()));
params.put("clientName", sourceEntityUtils.getSourceName(sourceManager.retrieveActiveSource()));
} else if (t instanceof ApplicationException) {
params = ((ApplicationException) t).getParams();
} else if (t instanceof IllegalEnumValueException) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package org.orcid.core.manager;

import java.util.Collection;
import java.util.Map;

import org.orcid.persistence.jpa.entities.ClientDetailsEntity;

public interface ClientDetailsEntityCacheManager {

public ClientDetailsEntity retrieve(String clientId) throws IllegalArgumentException;

public Map<String, ClientDetailsEntity> retrieveAll(Collection<String> clientIds);

public ClientDetailsEntity retrieveByIdP(String clientId) throws IllegalArgumentException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public class AddressManagerImpl extends AddressManagerReadOnlyImpl implements Ad
@Resource
protected SourceManager sourceManager;

@Resource
private SourceEntityUtils sourceEntityUtils;

@Resource
private ProfileEntityCacheManager profileEntityCacheManager;

Expand Down Expand Up @@ -130,7 +133,7 @@ private boolean isDuplicated(AddressEntity existing, Address address, SourceEnti
if (!existing.getId().equals(address.getPutCode())) {
// If they have the same source
String existingSourceId = existing.getElementSourceId();
if (!PojoUtil.isEmpty(existingSourceId) && existingSourceId.equals(SourceEntityUtils.getSourceId(source))) {
if (!PojoUtil.isEmpty(existingSourceId) && existingSourceId.equals(sourceEntityUtils.getSourceId(source))) {
if (existing.getIso2Country().equals(address.getCountry().getValue())) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package org.orcid.core.manager.impl;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

Expand Down Expand Up @@ -46,6 +51,44 @@ public ClientDetailsEntity retrieve(String clientId) throws IllegalArgumentExcep
return clientDetails;
}

@Override
public Map<String, ClientDetailsEntity> retrieveAll(Collection<String> clientIds) {
Map<String, ClientDetailsEntity> clientDetailsById = new HashMap<>();
if (clientIds == null || clientIds.isEmpty()) {
return clientDetailsById;
}

List<String> clientIdList = new ArrayList<>(clientIds);
Map<String, Date> lastModifiedByClientId = clientDetailsManager.getLastModifiedByClientIds(clientIdList);
if (lastModifiedByClientId == null) {
return clientDetailsById;
}
List<String> staleOrMissingClientIds = new ArrayList<>();

for (String clientId : clientIdList) {
Date dbDate = lastModifiedByClientId.get(clientId);
if (dbDate == null) {
continue;
}
Object key = new ClientIdCacheKey(clientId, releaseName);
ClientDetailsEntity clientDetails = clientDetailsCache.get(key);
if (needsFresh(dbDate, clientDetails)) {
staleOrMissingClientIds.add(clientId);
} else {
clientDetailsById.put(clientId, clientDetails);
}
}

if (!staleOrMissingClientIds.isEmpty()) {
for (ClientDetailsEntity clientDetails : clientDetailsManager.findByClientIds(staleOrMissingClientIds)) {
clientDetailsCache.put(new ClientIdCacheKey(clientDetails.getId(), releaseName), clientDetails);
clientDetailsById.put(clientDetails.getId(), clientDetails);
}
}

return clientDetailsById;
}

@Override
public ClientDetailsEntity retrieveByIdP(String idp) throws IllegalArgumentException {
Object key = new ClientIdCacheKey("IdP+" + idp, releaseName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ public class ExternalIdentifierManagerImpl extends ExternalIdentifierManagerRead
private OrcidSecurityManager orcidSecurityManager;

@Resource
private ProfileEntityManager profileEntityManager;
private ProfileEntityCacheManager profileEntityCacheManager;

@Resource
private ProfileEntityCacheManager profileEntityCacheManager;
private SourceEntityUtils sourceEntityUtils;

@Override
public PersonExternalIdentifier createExternalIdentifier(String orcid, PersonExternalIdentifier externalIdentifier, boolean isApiRequest) {
Expand Down Expand Up @@ -109,7 +109,7 @@ private boolean isDuplicated(ExternalIdentifierEntity existing, PersonExternalId
if (!existing.getId().equals(newExternalIdentifier.getPutCode())) {
// If they have the same source
String existingSourceId = existing.getElementSourceId();
if (!PojoUtil.isEmpty(existingSourceId) && existingSourceId.equals(SourceEntityUtils.getSourceId(source))) {
if (!PojoUtil.isEmpty(existingSourceId) && existingSourceId.equals(sourceEntityUtils.getSourceId(source))) {
// And they have the same reference
if ((PojoUtil.isEmpty(existing.getExternalIdReference()) && PojoUtil.isEmpty(newExternalIdentifier.getValue()))
|| (!PojoUtil.isEmpty(existing.getExternalIdReference()) && existing.getExternalIdReference().equals(newExternalIdentifier.getValue()))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ public class PeerReviewManagerImpl extends PeerReviewManagerReadOnlyImpl impleme
@Resource
private ProfileEntityCacheManager profileEntityCacheManager;

@Resource
private SourceEntityUtils sourceEntityUtils;

@Override
public PeerReview createPeerReview(String orcid, PeerReview peerReview, boolean isApiRequest) {
SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
Expand All @@ -90,7 +93,7 @@ public PeerReview createPeerReview(String orcid, PeerReview peerReview, boolean
List<PeerReviewEntity> peerReviews = peerReviewDao.getByUser(orcid, getLastModified(orcid));
// If it is the user adding the peer review, allow him to add
// duplicates
if (!SourceEntityUtils.getSourceId(sourceEntity).equals(orcid)) {
if (!sourceEntityUtils.getSourceId(sourceEntity).equals(orcid)) {
if (peerReviews != null) {
for (PeerReviewEntity entity : peerReviews) {
PeerReview existing = jpaJaxbPeerReviewAdapter.toPeerReview(entity);
Expand Down
Loading
Loading