Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
amontenegro committed May 17, 2023
1 parent 6e6ee4a commit 5f5f185
Show file tree
Hide file tree
Showing 13 changed files with 90 additions and 235 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public Work createWork(String orcid, Work work, boolean isApiRequest) {

setIncomingWorkPrivacy(workEntity, profile);
DisplayIndexCalculatorHelper.setDisplayIndexOnNewEntity(workEntity, isApiRequest);
if (isApiRequest && Features.STORE_TOP_CONTRIBUTORS.isActive()) {
if (isApiRequest) {
filterContributors(work, workEntity);
}
workDao.persist(workEntity);
Expand Down Expand Up @@ -270,9 +270,7 @@ public WorkBulk createWorks(String orcid, WorkBulk workBulk) {

setIncomingWorkPrivacy(workEntity, profile);
DisplayIndexCalculatorHelper.setDisplayIndexOnNewEntity(workEntity, true);
if (Features.STORE_TOP_CONTRIBUTORS.isActive()) {
filterContributors(work, workEntity);
}
filterContributors(work, workEntity);
workDao.persist(workEntity);

// Update the element in the bulk
Expand Down Expand Up @@ -388,9 +386,7 @@ public Work updateWork(String orcid, Work work, boolean isApiRequest) {
}
}

if (Features.STORE_TOP_CONTRIBUTORS.isActive()) {
filterContributors(work, workEntity);
}
filterContributors(work, workEntity);
} else {
// validate external ID vocab
externalIDValidator.validateWorkOrPeerReview(work.getExternalIdentifiers());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,7 @@ public Work createWork(String orcid, Work work, boolean isApiRequest) {

setIncomingWorkPrivacy(workEntity, profile, isApiRequest);
DisplayIndexCalculatorHelper.setDisplayIndexOnNewEntity(workEntity, isApiRequest);
if (Features.STORE_TOP_CONTRIBUTORS.isActive()) {
filterContributors(work, workEntity);
}
filterContributors(work, workEntity);
workDao.persist(workEntity);
workDao.flush();
notificationManager.sendAmendEmail(orcid, AmendedSection.WORK, createItemList(workEntity, work.getExternalIdentifiers(), ActionType.CREATE));
Expand Down Expand Up @@ -281,9 +279,7 @@ public WorkBulk createWorks(String orcid, WorkBulk workBulk) {

setIncomingWorkPrivacy(workEntity, profile);
DisplayIndexCalculatorHelper.setDisplayIndexOnNewEntity(workEntity, true);
if (Features.STORE_TOP_CONTRIBUTORS.isActive()) {
filterContributors(work, workEntity);
}
filterContributors(work, workEntity);
workDao.persist(workEntity);

//Update the element in the bulk
Expand Down Expand Up @@ -387,7 +383,7 @@ public Work updateWork(String orcid, Work work, boolean isApiRequest) {
activityValidator.checkExternalIdentifiersForDuplicates(work, existing, existing.getSource(), activeSource);
}
}
}else{
} else {
//validate external ID vocab
externalIDValidator.validateWork(work.getExternalIdentifiers(), isApiRequest);
}
Expand All @@ -401,9 +397,7 @@ public Work updateWork(String orcid, Work work, boolean isApiRequest) {
//Be sure it doesn't overwrite the source
workEntity.setSourceId(existingSourceId);
workEntity.setClientSourceId(existingClientSourceId);
if (Features.STORE_TOP_CONTRIBUTORS.isActive()) {
filterContributors(work, workEntity);
}
filterContributors(work, workEntity);
workDao.merge(workEntity);
workDao.flush();
notificationManager.sendAmendEmail(orcid, AmendedSection.WORK, createItemList(workEntity, work.getExternalIdentifiers(), ActionType.UPDATE));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public List<WorkSummaryExtended> getWorksSummaryExtendedList(String orcid) {
// Filter the contributors list
if (Features.ORCID_ANGULAR_WORKS_CONTRIBUTORS.isActive()) {
for (WorkSummaryExtended wse : wseList) {
if (Features.STORE_TOP_CONTRIBUTORS.isActive() && wse.getContributorsGroupedByOrcid() != null && wse.getContributorsGroupedByOrcid().size() > 0) {
if (wse.getContributorsGroupedByOrcid() != null && wse.getContributorsGroupedByOrcid().size() > 0) {
contributorUtils.filterContributorsGroupedByOrcidPrivateData(wse.getContributorsGroupedByOrcid(), maxContributorsForUI);
wse.setNumberOfContributors(wse.getContributorsGroupedByOrcid().size());
} else {
Expand All @@ -214,7 +214,7 @@ public List<WorkSummaryExtended> getWorksSummaryExtendedList(String orcid) {

private List<WorkSummaryExtended> retrieveWorkSummaryExtended(String orcid) {
List<WorkSummaryExtended> workSummaryExtendedList = new ArrayList<>();
List<Object[]> list = workDao.getWorksByOrcid(orcid, Features.STORE_TOP_CONTRIBUTORS.isActive());
List<Object[]> list = workDao.getWorksByOrcid(orcid);
for(Object[] q1 : list){
BigInteger putCode = (BigInteger) q1[0];
String workType = isEmpty(q1[1]);
Expand Down Expand Up @@ -257,7 +257,7 @@ private List<WorkSummaryExtended> retrieveWorkSummaryExtended(String orcid) {
List<WorkContributorsList> contributorList = new ArrayList<>();
List<ContributorsRolesAndSequences> contributorsRolesAndSequencesList = new ArrayList<>();

if (Features.STORE_TOP_CONTRIBUTORS.isActive() && contributors != null && !"".equals(contributors)) {
if (contributors != null && !"".equals(contributors)) {
contributorsRolesAndSequencesList = contributorsRolesAndSequencesConverter.getContributorsRolesAndSequencesList(contributors);
} else {
contributorList = workContributorsConverter.getContributorsList(contributors);
Expand Down
8 changes: 1 addition & 7 deletions orcid-core/src/main/java/org/orcid/core/togglz/Features.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ public enum Features implements Feature {
ADD_OTHER_WORK_CONTRIBUTORS_WITH_DOI_PUBMED,

@Label("Add other people contributions manually")
ADD_OTHER_WORK_CONTRIBUTORS,

@Label("Store and read top_contributors_json")
STORE_TOP_CONTRIBUTORS,
ADD_OTHER_WORK_CONTRIBUTORS,

@Label("Restrict delegator access to account settings")
RESTRICTED_DELEGATORS,
Expand Down Expand Up @@ -60,9 +57,6 @@ public enum Features implements Feature {
@Label("Orcid Angular Search")
ORCID_ANGULAR_SEARCH,

@Label("Works pagination")
WORKS_PAGINATION,

@Label("Email status dropdown option")
EMAIL_STATUS_DROPDOWN_OPTION,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1598,8 +1598,6 @@ public void testCreateWorkFromAPIAndValidateTopContributorsInWorkEntity() {

ReflectionTestUtils.setField(workManager, "workDao", mockDao);

togglzRule.enable(Features.STORE_TOP_CONTRIBUTORS);

Work work = workManager.createWork(orcid, getWorkWith100Contributors(), true);

ArgumentCaptor<WorkEntity> workEntityCaptor = ArgumentCaptor.forClass(WorkEntity.class);
Expand All @@ -1624,8 +1622,6 @@ public void testCreateWorkFromAPIAndValidateTopContributors() {

ReflectionTestUtils.setField(workManager, "contributorsRolesAndSequencesConverter", mockContributorsRolesAndSequencesConverter);

togglzRule.enable(Features.STORE_TOP_CONTRIBUTORS);

Work work = workManager.createWork(orcid, getWorkWith100Contributors(), true);

ArgumentCaptor<List<ContributorsRolesAndSequences>> captor = ArgumentCaptor.forClass((Class) List.class);
Expand All @@ -1649,8 +1645,6 @@ public void testCreateWorkFromAPIAndValidateContributorsDefaultValue() {

ReflectionTestUtils.setField(workManager, "workDao", mockDao);

togglzRule.enable(Features.STORE_TOP_CONTRIBUTORS);

Work work = workManager.createWork(orcid, getWork(null), true);

ArgumentCaptor<WorkEntity> workEntityCaptor = ArgumentCaptor.forClass(WorkEntity.class);
Expand All @@ -1673,8 +1667,6 @@ public void testCreateWorkFromUIAndValidateTopContributorsInWorkEntity() {

ReflectionTestUtils.setField(workManager, "workDao", mockDao);

togglzRule.enable(Features.STORE_TOP_CONTRIBUTORS);

Work workResult = workManager.createWork(orcid, getWorkWithContributorsMultipleRoles());

ArgumentCaptor<WorkEntity> workEntityCaptor = ArgumentCaptor.forClass(WorkEntity.class);
Expand All @@ -1696,8 +1688,6 @@ public void testCreateWorkFromUIAndValidateTopContributorsInWorkEntity() {
public void testUpdateWorkFromUIAndRemoveOneCreditRole() {
String orcid = "0000-0000-0000-0004";

togglzRule.enable(Features.STORE_TOP_CONTRIBUTORS);

WorkForm workForm = getWorkWithContributorsMultipleRoles();

Work work = workManager.createWork(orcid, workForm);
Expand Down Expand Up @@ -1883,7 +1873,6 @@ public void testCompareWorksContributorsGroupedByOrcidId() {
ReflectionTestUtils.setField(workManager, "notificationManager", mockNotificationManager);

togglzRule.enable(Features.STOP_SENDING_NOTIFICATION_WORK_NOT_UPDATED);
togglzRule.enable(Features.STORE_TOP_CONTRIBUTORS);

WorkForm workForm = getWorkWithContributorsMultipleRoles();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public interface WorkDao extends GenericDao<WorkEntity, Long> {

List<BigInteger> getIdsOfWorksReferencingClientProfiles(int i, List<String> clientProfileOrcidIds);

List<Object[]> getWorksByOrcid(String orcid, boolean topContributorsTogglz);
List<Object[]> getWorksByOrcid(String orcid);

List<Object[]> getWorksStartingFromWorkId(Long WorkId, int numberOfWorks);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,8 @@

import javax.persistence.Query;
import javax.persistence.TypedQuery;
import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;

import org.hibernate.type.BigIntegerType;
import org.hibernate.type.DateType;
import org.hibernate.type.IntegerType;
import org.hibernate.type.StringType;
import org.hibernate.type.TimestampType;
Expand All @@ -30,6 +26,12 @@

public class WorkDaoImpl extends GenericDaoImpl<WorkEntity, Long> implements WorkDao {

private final String WORKS_BY_ORCID_WITH_CONTRIBUTORS = "SELECT "
+ " w.work_id, w.work_type, w.title, w.journal_title, w.external_ids_json, "
+ " w.publication_year, w.publication_month, w.publication_day, w.date_created, "
+ " w.last_modified, w.visibility, w.display_index, w.source_id, w.client_source_id," + " w.assertion_origin_source_id, w.assertion_origin_client_source_id, "
+ " w.top_contributors_json as contributors " + " FROM work w" + " WHERE orcid=:orcid";

public WorkDaoImpl() {
super(WorkEntity.class);
}
Expand Down Expand Up @@ -368,25 +370,8 @@ public WorkEntity merge(WorkEntity entity) {
}

@Override
public List<Object[]> getWorksByOrcid(String orcid, boolean topContributorsTogglz) {
String contributorsSQL = null;
if (topContributorsTogglz) {
contributorsSQL = " w.top_contributors_json as contributors";
} else {
contributorsSQL = " (SELECT to_json(array_agg(row_to_json(t))) FROM (SELECT json_array_elements(json_extract_path(contributors_json, 'contributor')) AS contributor FROM work WHERE work_id=w.work_id limit 100) t) as contributors ";
}

String sqlString =
"SELECT " +
" w.work_id, w.work_type, w.title, w.journal_title, w.external_ids_json, " +
" w.publication_year, w.publication_month, w.publication_day, w.date_created, " +
" w.last_modified, w.visibility, w.display_index, w.source_id, w.client_source_id," +
" w.assertion_origin_source_id, w.assertion_origin_client_source_id, " +
contributorsSQL +
" FROM work w" +
" WHERE orcid=:orcid";

Query query = entityManager.createNativeQuery(sqlString);
public List<Object[]> getWorksByOrcid(String orcid) {
Query query = entityManager.createNativeQuery(WORKS_BY_ORCID_WITH_CONTRIBUTORS);
query.setParameter("orcid", orcid)
.unwrap(org.hibernate.query.NativeQuery.class)
.addScalar("work_id", BigIntegerType.INSTANCE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,14 @@
import org.orcid.core.manager.ProfileEntityCacheManager;
import org.orcid.core.manager.v3.ActivityManager;
import org.orcid.core.manager.v3.MembersManager;
import org.orcid.core.manager.v3.read_only.*;
import org.orcid.core.manager.v3.read_only.AffiliationsManagerReadOnly;
import org.orcid.core.manager.v3.read_only.GroupIdRecordManagerReadOnly;
import org.orcid.core.manager.v3.read_only.PeerReviewManagerReadOnly;
import org.orcid.core.manager.v3.read_only.PersonalDetailsManagerReadOnly;
import org.orcid.core.manager.v3.read_only.ProfileFundingManagerReadOnly;
import org.orcid.core.manager.v3.read_only.ResearchResourceManagerReadOnly;
import org.orcid.core.manager.v3.read_only.WorkManagerReadOnly;
import org.orcid.core.oauth.OrcidOauth2TokenDetailService;
import org.orcid.core.togglz.Features;
import org.orcid.core.utils.v3.ContributorUtils;
import org.orcid.core.utils.v3.SourceUtils;
import org.orcid.core.utils.v3.activities.FundingComparators;
Expand All @@ -40,8 +45,17 @@
import org.orcid.jaxb.model.message.OrcidType;
import org.orcid.jaxb.model.v3.release.common.Visibility;
import org.orcid.jaxb.model.v3.release.groupid.GroupIdRecord;
import org.orcid.jaxb.model.v3.release.record.*;
import org.orcid.jaxb.model.v3.release.record.summary.*;
import org.orcid.jaxb.model.v3.release.record.Affiliation;
import org.orcid.jaxb.model.v3.release.record.AffiliationType;
import org.orcid.jaxb.model.v3.release.record.Funding;
import org.orcid.jaxb.model.v3.release.record.PeerReview;
import org.orcid.jaxb.model.v3.release.record.Work;
import org.orcid.jaxb.model.v3.release.record.summary.AffiliationGroup;
import org.orcid.jaxb.model.v3.release.record.summary.AffiliationSummary;
import org.orcid.jaxb.model.v3.release.record.summary.FundingSummary;
import org.orcid.jaxb.model.v3.release.record.summary.Fundings;
import org.orcid.jaxb.model.v3.release.record.summary.PeerReviewSummary;
import org.orcid.jaxb.model.v3.release.record.summary.PeerReviews;
import org.orcid.persistence.jpa.entities.CountryIsoEntity;
import org.orcid.persistence.jpa.entities.ProfileEntity;
import org.orcid.pojo.OrgDisambiguated;
Expand All @@ -53,7 +67,6 @@
import org.orcid.pojo.ajaxForm.AffiliationForm;
import org.orcid.pojo.ajaxForm.AffiliationGroupContainer;
import org.orcid.pojo.ajaxForm.AffiliationGroupForm;
import org.orcid.pojo.ajaxForm.Contributor;
import org.orcid.pojo.ajaxForm.EmptyJsonResponse;
import org.orcid.pojo.ajaxForm.FundingForm;
import org.orcid.pojo.ajaxForm.PeerReviewForm;
Expand Down Expand Up @@ -447,17 +460,10 @@ public ModelAndView publicPreview(HttpServletRequest request, HttpServletRespons
Map<String, String> languages = lm.buildLanguageMap(localeManager.getLocale(), false);
if (workId == null)
return null;

WorkForm work = null;
Work workObj = null;
if (Features.STORE_TOP_CONTRIBUTORS.isActive()) {
WorkExtended workExtended = workManagerReadOnly.getWorkExtended(orcid, workId);
work = WorkForm.valueOf(workExtended, maxContributorsForUI);
workObj = workExtended;
} else {
workObj = workManagerReadOnly.getWork(orcid, workId);
work = WorkForm.valueOf(workObj, maxContributorsForUI);
}

WorkExtended workExtended = workManagerReadOnly.getWorkExtended(orcid, workId);
WorkForm work = WorkForm.valueOf(workExtended, maxContributorsForUI);
Work workObj = workExtended;

if (work != null && validateVisibility(workObj.getVisibility())) {
sourceUtils.setSourceName(workObj);
Expand All @@ -477,15 +483,9 @@ public ModelAndView publicPreview(HttpServletRequest request, HttpServletRespons
work.getTranslatedTitle().setLanguageName(languageName);
}

if (Features.STORE_TOP_CONTRIBUTORS.isActive()) {
if (work.getContributorsGroupedByOrcid() != null) {
contributorUtils.filterContributorsGroupedByOrcidPrivateData(work.getContributorsGroupedByOrcid(), maxContributorsForUI);
}
} else {
if (work.getContributors() != null) {
work.setContributors(filterContributors(work.getContributors(), activityManager));
}
}
if (work.getContributorsGroupedByOrcid() != null) {
contributorUtils.filterContributorsGroupedByOrcidPrivateData(work.getContributorsGroupedByOrcid(), maxContributorsForUI);
}

return new ResponseEntity<>(work, HttpStatus.OK);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.regex.Pattern;

import javax.annotation.Resource;
Expand Down Expand Up @@ -36,7 +35,6 @@
import org.orcid.jaxb.model.v3.release.record.WorkCategory;
import org.orcid.jaxb.model.v3.release.record.summary.WorkSummary;
import org.orcid.persistence.jpa.entities.ProfileEntity;
import org.orcid.pojo.ContributorsRolesAndSequences;
import org.orcid.pojo.GroupedWorks;
import org.orcid.pojo.IdentifierType;
import org.orcid.pojo.KeyValue;
Expand Down Expand Up @@ -316,15 +314,9 @@ private void initializePublicationDate(WorkForm w) {
if (workId == null)
return null;

WorkForm workForm = null;
if (Features.STORE_TOP_CONTRIBUTORS.isActive()) {
WorkExtended work = workManager.getWorkExtended(this.getEffectiveUserOrcid(), workId);
workForm = WorkForm.valueOf(work, maxContributorsForUI);
} else {
Work work = workManager.getWork(this.getEffectiveUserOrcid(), workId);
workForm = WorkForm.valueOf(work, maxContributorsForUI);
}

WorkExtended work = workManager.getWorkExtended(this.getEffectiveUserOrcid(), workId);
WorkForm workForm = WorkForm.valueOf(work, maxContributorsForUI);

if (workForm != null) {
if (workForm.getPublicationDate() == null) {
initializePublicationDate(workForm);
Expand Down Expand Up @@ -406,15 +398,9 @@ private void initializePublicationDate(WorkForm w) {
workForm.getTranslatedTitle().setLanguageName(languageName);
}

if (Features.STORE_TOP_CONTRIBUTORS.isActive()) {
if (workForm.getContributorsGroupedByOrcid() != null) {
contributorUtils.filterContributorsGroupedByOrcidPrivateData(workForm.getContributorsGroupedByOrcid(), maxContributorsForUI);
}
} else {
if (workForm.getContributors() != null) {
workForm.setContributors(filterContributors(workForm.getContributors(), activityManager));
}
}
if (workForm.getContributorsGroupedByOrcid() != null) {
contributorUtils.filterContributorsGroupedByOrcidPrivateData(workForm.getContributorsGroupedByOrcid(), maxContributorsForUI);
}

return workForm;
}
Expand Down
Loading

0 comments on commit 5f5f185

Please sign in to comment.