Skip to content

Commit 0cae180

Browse files
committed
Improvements in the way we load the source names on retrieveWorkSummaryExtended
1 parent 08f8318 commit 0cae180

11 files changed

Lines changed: 317 additions & 129 deletions

File tree

orcid-core/src/main/java/org/orcid/core/adapter/v3/converter/ContributorsRolesAndSequencesConverter.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import ma.glasnost.orika.converter.BidirectionalConverter;
77
import ma.glasnost.orika.metadata.Type;
88
import org.orcid.core.contributors.roles.ContributorRoleConverter;
9+
import org.orcid.core.contributors.roles.ContributorRoleConverterImpl;
910
import org.orcid.core.contributors.roles.credit.CreditRole;
1011
import org.orcid.core.utils.JsonUtils;
1112
import org.orcid.core.utils.v3.ContributorUtils;
@@ -15,18 +16,19 @@
1516
import org.slf4j.Logger;
1617
import org.slf4j.LoggerFactory;
1718

19+
import javax.annotation.Resource;
1820
import java.util.ArrayList;
1921
import java.util.List;
2022

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

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

25-
private ContributorRoleConverter roleConverter;
27+
@Resource(name = "workContributorRoleConverter")
28+
private ContributorRoleConverter workContributorRoleConverter;
2629

27-
public ContributorsRolesAndSequencesConverter(ContributorRoleConverter roleConverter) {
28-
this.roleConverter = roleConverter;
29-
}
30+
@Resource(name = "contributorUtilsV3")
31+
private ContributorUtils contributorUtils;
3032

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

4143
public List<ContributorsRolesAndSequences> getContributorsRolesAndSequencesList(String source) {
42-
ContributorUtils contributorUtils = new ContributorUtils(null);
4344
final ObjectMapper objectMapper = new ObjectMapper();
4445
List<ContributorsRolesAndSequences> contributorsRolesAndSequencesResult = new ArrayList<>();
4546
try {
@@ -54,7 +55,7 @@ public List<ContributorsRolesAndSequences> getContributorsRolesAndSequencesList(
5455
if (cr != null) {
5556
providedRoleValue = cr.name();
5657
}
57-
crs.setContributorRole(contributorUtils.getCreditRole(roleConverter.toRoleValue(providedRoleValue)));
58+
crs.setContributorRole(contributorUtils.getCreditRole(workContributorRoleConverter.toRoleValue(providedRoleValue)));
5859
}
5960
}
6061
}

orcid-core/src/main/java/org/orcid/core/adapter/v3/impl/MapperFacadeFactory.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -170,13 +170,6 @@ public class MapperFacadeFactory implements FactoryBean<MapperFacade> {
170170
@Resource
171171
private WorkDao workDao;
172172

173-
@Resource
174-
private SourceNameCacheManager sourceNameCacheManager;
175-
176-
@Resource
177-
private ClientDetailsEntityCacheManager clientDetailsEntityCacheManager;
178-
179-
180173
@Resource
181174
private IdentityProviderManager identityProviderManager;
182175

@@ -201,6 +194,9 @@ public class MapperFacadeFactory implements FactoryBean<MapperFacade> {
201194
@Resource
202195
private SourceEntityUtils sourceEntityUtils;
203196

197+
@Resource
198+
private ContributorsRolesAndSequencesConverter contributorsRolesAndSequencesConverter;
199+
204200
@Override
205201
public MapperFacade getObject() throws Exception {
206202
MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();
@@ -546,8 +542,6 @@ public MapperFacade getWorkMapperFacade() {
546542
MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();
547543

548544
WorkContributorsConverter wcc = new WorkContributorsConverter(workContributorsRoleConverter);
549-
ContributorsRolesAndSequencesConverter contributorsRolesAndSequencesConverter = new ContributorsRolesAndSequencesConverter(workContributorsRoleConverter);
550-
551545
ConverterFactory converterFactory = mapperFactory.getConverterFactory();
552546
converterFactory.registerConverter("workExternalIdentifiersConverterId", new JSONWorkExternalIdentifiersConverterV3(norm, resolverService, localeManager));
553547
converterFactory.registerConverter("workContributorsConverterId", wcc);

orcid-core/src/main/java/org/orcid/core/cli/FilterTopContributors.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ private void filter() {
6565

6666
private void filterTopContributors(Object[] workObject) {
6767
WorkEntity workEntity = workDao.find(((BigInteger) workObject[0]).longValue());
68-
ContributorUtils contributorUtils = new ContributorUtils(0);
68+
ContributorUtils contributorUtils = new ContributorUtils();
6969
WorkSummaryExtended wse = new WorkSummaryExtended.WorkSummaryExtendedBuilder(((BigInteger) workObject[0]))
7070
.contributors(workContributorsConverter.getContributorsList(isEmpty(workObject[1])))
7171
.build();

orcid-core/src/main/java/org/orcid/core/manager/v3/read_only/impl/WorkManagerReadOnlyImpl.java

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import javax.annotation.Resource;
1010

11+
import org.apache.commons.lang3.StringUtils;
1112
import org.orcid.core.adapter.jsonidentifier.converter.JSONWorkExternalIdentifiersConverterV3;
1213
import org.orcid.core.adapter.v3.JpaJaxbWorkAdapter;
1314
import org.orcid.core.adapter.v3.converter.ContributorsRolesAndSequencesConverter;
@@ -107,9 +108,6 @@ public class WorkManagerReadOnlyImpl extends ManagerReadOnlyBaseImpl implements
107108
@Resource
108109
private ContributorsRolesAndSequencesConverter contributorsRolesAndSequencesConverter;
109110

110-
@Resource
111-
private OrcidUrlManager orcidUrlManager;
112-
113111
@Resource
114112
private SourceEntityUtils sourceEntityUtils;
115113

@@ -198,6 +196,7 @@ public WorkSummary getWorkSummary(String orcid, Long workId) {
198196
@Override
199197
public List<WorkSummary> getWorksSummaryList(String orcid) {
200198
List<MinimizedWorkEntity> works = workEntityCacheManager.retrieveMinimizedWorks(orcid, getLastModified(orcid));
199+
long t0 = System.currentTimeMillis();
201200
Set<String> clientIds = works.stream()
202201
.map(MinimizedWorkEntity::getClientSourceId)
203202
.filter(clientId -> !PojoUtil.isEmpty(clientId))
@@ -219,7 +218,10 @@ public List<WorkSummary> getWorksSummaryList(String orcid) {
219218

220219
// This map should be read-only
221220
Map<String, Source> readOnlySources = Collections.unmodifiableMap(sources);
222-
return jpaJaxbWorkAdapter.toWorkSummaryFromMinimized(works, readOnlySources);
221+
List<WorkSummary> list = jpaJaxbWorkAdapter.toWorkSummaryFromMinimized(works, readOnlySources);
222+
long t1 = System.currentTimeMillis();
223+
System.out.println("Time to convert to JAXB WorkSummary: " + (t1 - t0));
224+
return list;
223225
}
224226

225227
/**
@@ -248,6 +250,8 @@ public List<WorkSummaryExtended> getWorksSummaryExtendedList(String orcid, boole
248250

249251
private List<WorkSummaryExtended> retrieveWorkSummaryExtended(String orcid, boolean featuredOnly) {
250252
List<WorkSummaryExtended> workSummaryExtendedList = new ArrayList<>();
253+
Map<String, Boolean> isUserOBOEnabled = new HashMap<String, Boolean>();
254+
long l0 = System.currentTimeMillis();
251255
List<Object[]> list = workDao.getWorksByOrcid(orcid, featuredOnly);
252256
for (Object[] q1 : list) {
253257
BigInteger putCode = (BigInteger) q1[0];
@@ -274,21 +278,34 @@ private List<WorkSummaryExtended> retrieveWorkSummaryExtended(String orcid, bool
274278
}
275279
String sourceName = null;
276280
String assertionOriginName = null;
277-
if (clientSourceId != null) {
278-
assertionOriginSourceId = contributorUtils.getAssertionOriginOrcid(clientSourceId, orcid, putCode.longValue(), clientDetailsEntityCacheManager, workDao);
281+
if (StringUtils.isNotBlank(clientSourceId)) {
282+
//Set the source name
283+
sourceName = sourceNameCacheManager.retrieve(clientSourceId);
284+
// Check if user OBO is enabled
285+
if (!PojoUtil.isEmpty(assertionOriginSourceId)) {
286+
if(!isUserOBOEnabled.containsKey(clientSourceId)) {
287+
ClientDetailsEntity clientEntity = clientDetailsEntityCacheManager.retrieve(clientSourceId);
288+
if(clientEntity != null && clientEntity.isUserOBOEnabled()) {
289+
isUserOBOEnabled.put(clientSourceId, true);
290+
} else {
291+
isUserOBOEnabled.put(clientSourceId, false);
292+
}
293+
}
294+
if(isUserOBOEnabled.get(clientSourceId)) {
295+
assertionOriginName = sourceNameCacheManager.retrieve(assertionOriginSourceId);
296+
}
297+
}
279298
}
280-
if (!PojoUtil.isEmpty(assertionOriginSourceId)) {
281-
assertionOriginName = contributorUtils.getSourceName(assertionOriginSourceId, sourceNameCacheManager);
299+
300+
// Check the sourceId name only if there is no clientSourceId
301+
if (PojoUtil.isEmpty(sourceName) && !PojoUtil.isEmpty(sourceId)) {
302+
sourceName = sourceNameCacheManager.retrieve(sourceId);
282303
}
304+
283305
if (!PojoUtil.isEmpty(assertionOriginClientSourceId)) {
284-
assertionOriginName = contributorUtils.getSourceName(assertionOriginClientSourceId, sourceNameCacheManager);
285-
}
286-
if (!PojoUtil.isEmpty(sourceId)) {
287-
sourceName = contributorUtils.getSourceName(sourceId, sourceNameCacheManager);
288-
}
289-
if (!PojoUtil.isEmpty(clientSourceId)) {
290-
sourceName = contributorUtils.getSourceName(clientSourceId, sourceNameCacheManager);
306+
assertionOriginName = sourceNameCacheManager.retrieve(assertionOriginClientSourceId);
291307
}
308+
292309
List<WorkContributorsList> contributorList = new ArrayList<>();
293310
List<ContributorsRolesAndSequences> contributorsRolesAndSequencesList = new ArrayList<>();
294311

@@ -306,6 +323,8 @@ private List<WorkSummaryExtended> retrieveWorkSummaryExtended(String orcid, bool
306323
.build();
307324
workSummaryExtendedList.add(wse);
308325
}
326+
long l1 = System.currentTimeMillis();
327+
System.out.println("Time to retrieve WorkSummaryExtended: " + (l1 - l0));
309328
return workSummaryExtendedList;
310329
}
311330

orcid-core/src/main/java/org/orcid/core/utils/SourceEntityUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public Source extractSourceFromEntity(SourceAwareEntity<?> e) {
115115
source.setSourceClientId(new SourceClientId(e.getClientSourceId()));
116116
if(e instanceof OrcidAware) {
117117
ClientDetailsEntity clientSource = clientDetailsEntityCacheManager.retrieve(e.getClientSourceId());
118-
if (clientSource.isUserOBOEnabled()) {
118+
if (clientSource != null && clientSource.isUserOBOEnabled()) {
119119
String orcidId = ((OrcidAware) e).getOrcid();
120120
source.setAssertionOriginOrcid(new SourceOrcid(orcidId));
121121
}

orcid-core/src/main/java/org/orcid/core/utils/v3/ContributorUtils.java

Lines changed: 18 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import org.orcid.core.manager.SourceNameCacheManager;
1212
import org.orcid.core.manager.v3.ActivityManager;
1313
import org.orcid.core.manager.v3.ProfileEntityManager;
14+
import org.orcid.core.manager.v3.read_only.ProfileEntityManagerReadOnly;
15+
import org.orcid.core.manager.v3.read_only.RecordNameManagerReadOnly;
1416
import org.orcid.jaxb.model.v3.release.common.Contributor;
1517
import org.orcid.jaxb.model.v3.release.common.ContributorAttributes;
1618
import org.orcid.jaxb.model.v3.release.common.CreditName;
@@ -24,34 +26,32 @@
2426
import org.orcid.pojo.ajaxForm.PojoUtil;
2527
import org.springframework.beans.factory.annotation.Value;
2628

29+
import javax.annotation.Resource;
30+
2731
public class ContributorUtils {
2832

29-
private final Integer BATCH_SIZE;
30-
31-
private ActivityManager cacheManager;
33+
@Resource(name = "recordNameManagerReadOnlyV3")
34+
private RecordNameManagerReadOnly recordNameManagerReadOnlyV3;
3235

33-
private ProfileEntityManager profileEntityManager;
36+
@Resource(name = "profileEntityManagerV3")
37+
private ProfileEntityManager profileEntityManagerV3;
3438

35-
protected ProfileLastModifiedAspect profileLastModifiedAspect;
36-
37-
public ContributorUtils(@Value("${org.orcid.contributor.names.batch_size:2500}") Integer batchSize) {
38-
if(batchSize == null) {
39-
BATCH_SIZE = 2500;
40-
} else {
41-
BATCH_SIZE = batchSize;
42-
}
43-
}
39+
@Resource
40+
private ClientDetailsEntityCacheManager clientDetailsEntityCacheManager;
41+
42+
@Resource(name = "workDaoReadOnly")
43+
private WorkDao workDaoReadOnly;
4444

4545
public void filterContributorPrivateData(Funding funding) {
4646
if (funding.getContributors() != null && funding.getContributors().getContributor() != null) {
4747
for (FundingContributor contributor : funding.getContributors().getContributor()) {
4848
contributor.setContributorEmail(null);
4949
if (!PojoUtil.isEmpty(contributor.getContributorOrcid())) {
5050
String contributorOrcid = contributor.getContributorOrcid().getPath();
51-
if (profileEntityManager.orcidExists(contributorOrcid)) {
51+
if (profileEntityManagerV3.orcidExists(contributorOrcid)) {
5252
// contributor is an ORCID user - visibility of user's
5353
// name in record must be taken into account
54-
String publicContributorCreditName = cacheManager.getPublicCreditName(contributorOrcid);
54+
String publicContributorCreditName = recordNameManagerReadOnlyV3.fetchDisplayablePublicName(contributorOrcid);
5555
CreditName creditName = new CreditName(publicContributorCreditName != null ? publicContributorCreditName : "");
5656
contributor.setCreditName(creditName);
5757
}
@@ -60,18 +60,6 @@ public void filterContributorPrivateData(Funding funding) {
6060
}
6161
}
6262

63-
public void setCacheManager(ActivityManager cacheManager) {
64-
this.cacheManager = cacheManager;
65-
}
66-
67-
public void setProfileEntityManager(ProfileEntityManager profileEntityManager) {
68-
this.profileEntityManager = profileEntityManager;
69-
}
70-
71-
public void setProfileLastModifiedAspect(ProfileLastModifiedAspect profileLastModifiedAspect) {
72-
this.profileLastModifiedAspect = profileLastModifiedAspect;
73-
}
74-
7563
public List<ContributorsRolesAndSequences> getContributorsGroupedByOrcid(List<Contributor> contributors, Integer maxContributorsForUI) {
7664
List<ContributorsRolesAndSequences> contributorsRolesAndSequencesList = new ArrayList<>();
7765
for(Contributor contributor : contributors) {
@@ -156,32 +144,12 @@ private ContributorsRolesAndSequences addContributor(Contributor contributor) {
156144
return crs;
157145
}
158146

159-
public String getCreditRole(String contributorRole) {
147+
public static String getCreditRole(String contributorRole) {
160148
try {
161-
CreditRole cr = CreditRole.fromValue(contributorRole);
162-
return cr.getUiValue();
163-
} catch(IllegalArgumentException e) {
149+
return CreditRole.fromValue(contributorRole).getUiValue();
150+
} catch(Exception e) {
164151
return contributorRole;
165152
}
166153
}
167154

168-
public String getAssertionOriginOrcid(String clientSourceId, String orcid, Long putCode, ClientDetailsEntityCacheManager clientDetailsEntityCacheManager, WorkDao workDao) {
169-
String assertionOriginOrcid = null;
170-
ClientDetailsEntity clientSource = clientDetailsEntityCacheManager.retrieve(clientSourceId);
171-
if (clientSource.isUserOBOEnabled()) {
172-
WorkEntity e = workDao.getWork(orcid, putCode);
173-
174-
String orcidId = null;
175-
if (e instanceof OrcidAware) {
176-
orcidId = ((OrcidAware) e).getOrcid();
177-
}
178-
assertionOriginOrcid = orcidId;
179-
}
180-
181-
return assertionOriginOrcid;
182-
}
183-
184-
public String getSourceName(String sourceId, SourceNameCacheManager sourceNameCacheManager) {
185-
return sourceNameCacheManager.retrieve(sourceId);
186-
}
187155
}

orcid-core/src/main/java/org/orcid/pojo/ContributorsRolesAndSequences.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,9 @@ public boolean compare(Object obj) {
5959
}
6060
AtomicBoolean isDifferent = new AtomicBoolean(false);
6161
WorkContributorRoleConverter roleConverter = new WorkContributorRoleConverter();
62-
ContributorUtils contributorUtils = new ContributorUtils(null);
6362
for (int i = 0; i < rolesAndSequences.size() ; i++) {
6463
if (rolesAndSequences.get(i).getContributorRole() != null && other.rolesAndSequences.get(i).getContributorRole() != null) {
65-
if (!WorkForm.compareStrings(rolesAndSequences.get(i).getContributorRole(), contributorUtils.getCreditRole(roleConverter.toRoleValue(other.rolesAndSequences.get(i).getContributorRole())))) {
64+
if (!WorkForm.compareStrings(rolesAndSequences.get(i).getContributorRole(), ContributorUtils.getCreditRole(roleConverter.toRoleValue(other.rolesAndSequences.get(i).getContributorRole())))) {
6665
isDifferent.set(true);
6766
break;
6867
}

orcid-core/src/main/resources/orcid-core-context.xml

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -413,19 +413,9 @@
413413
<property name="sourceNameCacheManager" ref="sourceNameCacheManagerReadOnly" />
414414
</bean>
415415

416-
<bean id="contributorUtilsV3" class="org.orcid.core.utils.v3.ContributorUtils">
417-
<property name="cacheManager" ref="activityManagerV3" />
418-
<property name="profileEntityManager" ref="profileEntityManagerV3" />
419-
<property name="profileLastModifiedAspect" ref="profileLastModifiedAspect" />
420-
</bean>
421-
422-
<bean id="contributorUtilsReadOnlyV3" class="org.orcid.core.utils.v3.ContributorUtils">
423-
<property name="cacheManager" ref="activityManagerV3" />
424-
<property name="profileEntityManager" ref="profileEntityManagerV3" />
425-
<property name="profileLastModifiedAspect" ref="profileLastModifiedAspect" />
426-
</bean>
416+
<bean id="contributorUtilsV3" class="org.orcid.core.utils.v3.ContributorUtils" />
427417

428-
<bean id="sourceUtilsV3" class="org.orcid.core.utils.v3.SourceUtils">
418+
<bean id="sourceUtilsV3" class="org.orcid.core.utils.v3.SourceUtils">
429419
<property name="sourceNameCacheManager" ref="sourceNameCacheManager" />
430420
</bean>
431421

@@ -1232,9 +1222,7 @@
12321222
<constructor-arg ref="localeManager" />
12331223
</bean>
12341224

1235-
<bean id="contributorsRolesAndSequencesConverter" class="org.orcid.core.adapter.v3.converter.ContributorsRolesAndSequencesConverter">
1236-
<constructor-arg ref="workContributorRoleConverter" />
1237-
</bean>
1225+
<bean id="contributorsRolesAndSequencesConverter" class="org.orcid.core.adapter.v3.converter.ContributorsRolesAndSequencesConverter" />
12381226

12391227
<bean id="contributorsRolesAndSequencesConverterV2" class="org.orcid.core.adapter.v3.converter.ContributorsRolesAndSequencesConverterV2"/>
12401228

0 commit comments

Comments
 (0)