use of org.orcid.persistence.jpa.entities.PeerReviewEntity in project ORCID-Source by ORCID.
the class PeerReviewDaoImpl method getPeerReview.
@Override
public PeerReviewEntity getPeerReview(String userOrcid, Long peerReviewId) {
Query query = entityManager.createQuery("from PeerReviewEntity where profile.id=:userOrcid and id=:peerReviewId");
query.setParameter("userOrcid", userOrcid);
query.setParameter("peerReviewId", Long.valueOf(peerReviewId));
return (PeerReviewEntity) query.getSingleResult();
}
use of org.orcid.persistence.jpa.entities.PeerReviewEntity in project ORCID-Source by ORCID.
the class MapperFacadeFactory method getPeerReviewMapperFacade.
public MapperFacade getPeerReviewMapperFacade() {
MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();
ConverterFactory converterFactory = mapperFactory.getConverterFactory();
converterFactory.registerConverter("workExternalIdentifiersConverterId", new WorkExternalIDsConverter());
converterFactory.registerConverter("workExternalIdentifierConverterId", new PeerReviewWorkExternalIDConverter());
//do same as work
ClassMapBuilder<PeerReview, PeerReviewEntity> classMap = mapperFactory.classMap(PeerReview.class, PeerReviewEntity.class);
addV2CommonFields(classMap);
registerSourceConverters(mapperFactory, classMap);
classMap.field("url.value", "url");
classMap.field("organization.name", "org.name");
classMap.field("organization.address.city", "org.city");
classMap.field("organization.address.region", "org.region");
classMap.field("organization.address.country", "org.country");
classMap.field("organization.disambiguatedOrganization.disambiguatedOrganizationIdentifier", "org.orgDisambiguated.sourceId");
classMap.field("organization.disambiguatedOrganization.disambiguationSource", "org.orgDisambiguated.sourceType");
classMap.field("groupId", "groupId");
classMap.field("subjectType", "subjectType");
classMap.field("subjectUrl.value", "subjectUrl");
classMap.field("subjectName.title.content", "subjectName");
classMap.field("subjectName.translatedTitle.content", "subjectTranslatedName");
classMap.field("subjectName.translatedTitle.languageCode", "subjectTranslatedNameLanguageCode");
classMap.field("subjectContainerName.content", "subjectContainerName");
classMap.fieldMap("externalIdentifiers", "externalIdentifiersJson").converter("workExternalIdentifiersConverterId").add();
classMap.fieldMap("subjectExternalIdentifier", "subjectExternalIdentifiersJson").converter("workExternalIdentifierConverterId").add();
classMap.register();
ClassMapBuilder<PeerReviewSummary, PeerReviewEntity> peerReviewSummaryClassMap = mapperFactory.classMap(PeerReviewSummary.class, PeerReviewEntity.class);
addV2CommonFields(peerReviewSummaryClassMap);
registerSourceConverters(mapperFactory, peerReviewSummaryClassMap);
peerReviewSummaryClassMap.fieldMap("externalIdentifiers", "externalIdentifiersJson").converter("workExternalIdentifiersConverterId").add();
peerReviewSummaryClassMap.field("organization.name", "org.name");
peerReviewSummaryClassMap.field("organization.address.city", "org.city");
peerReviewSummaryClassMap.field("organization.address.region", "org.region");
peerReviewSummaryClassMap.field("organization.address.country", "org.country");
peerReviewSummaryClassMap.field("organization.disambiguatedOrganization.disambiguatedOrganizationIdentifier", "org.orgDisambiguated.sourceId");
peerReviewSummaryClassMap.field("organization.disambiguatedOrganization.disambiguationSource", "org.orgDisambiguated.sourceType");
peerReviewSummaryClassMap.register();
mapperFactory.classMap(FuzzyDate.class, CompletionDateEntity.class).field("year.value", "year").field("month.value", "month").field("day.value", "day").register();
return mapperFactory.getMapperFacade();
}
use of org.orcid.persistence.jpa.entities.PeerReviewEntity in project ORCID-Source by ORCID.
the class JpaJaxbPeerReviewAdapterTest method testToOrgAffiliationRelationEntity.
@Test
public void testToOrgAffiliationRelationEntity() throws JAXBException {
PeerReview e = getPeerReview(true);
assertNotNull(e);
PeerReviewEntity pe = jpaJaxbPeerReviewAdapter.toPeerReviewEntity(e);
assertNotNull(pe);
//General info
assertEquals(Long.valueOf(12345), pe.getId());
assertEquals(Visibility.PRIVATE.value(), pe.getVisibility().value());
assertEquals("{\"workExternalIdentifier\":[{\"relationship\":\"SELF\",\"url\":{\"value\":\"http://orcid.org\"},\"workExternalIdentifierType\":\"SOURCE_WORK_ID\",\"workExternalIdentifierId\":{\"content\":\"work:external-identifier-id\"}}]}", pe.getExternalIdentifiersJson());
assertEquals("reviewer", pe.getRole().value());
assertEquals("review", pe.getType().value());
assertEquals("peer-review:url", pe.getUrl());
//Dates
assertEquals(Integer.valueOf(2), pe.getCompletionDate().getDay());
assertEquals(Integer.valueOf(2), pe.getCompletionDate().getMonth());
assertEquals(Integer.valueOf(1848), pe.getCompletionDate().getYear());
// Source
assertNull(pe.getSourceId());
assertNull(pe.getClientSourceId());
assertNull(pe.getElementSourceId());
//Check org values
assertEquals("common:name", pe.getOrg().getName());
assertEquals("common:city", pe.getOrg().getCity());
assertEquals("common:region", pe.getOrg().getRegion());
assertEquals(Iso3166Country.AF.value(), pe.getOrg().getCountry().value());
assertEquals("common:disambiguated-organization-identifier", pe.getOrg().getOrgDisambiguated().getSourceId());
assertEquals("common:disambiguation-source", pe.getOrg().getOrgDisambiguated().getSourceType());
//Check subject
assertEquals("{\"relationship\":\"SELF\",\"url\":{\"value\":\"http://orcid.org\"},\"workExternalIdentifierType\":\"DOI\",\"workExternalIdentifierId\":{\"content\":\"peer-review:subject-external-identifier-id\"}}", pe.getSubjectExternalIdentifiersJson());
assertEquals("peer-review:subject-container-name", pe.getSubjectContainerName());
assertEquals("peer-review:subject-name", pe.getSubjectName());
assertEquals("peer-review:subject-translated-name", pe.getSubjectTranslatedName());
assertEquals("en", pe.getSubjectTranslatedNameLanguageCode());
assertEquals("peer-review:subject-url", pe.getSubjectUrl());
assertEquals(WorkType.JOURNAL_ARTICLE, pe.getSubjectType());
//Check group id
assertEquals("orcid-generated:12345", pe.getGroupId());
}
use of org.orcid.persistence.jpa.entities.PeerReviewEntity in project ORCID-Source by ORCID.
the class PeerReviewManagerImpl method createPeerReview.
@Override
public PeerReview createPeerReview(String orcid, PeerReview peerReview, boolean isApiRequest) {
SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
// If request comes from the API, perform the validations
if (isApiRequest) {
// Validate it have at least one ext id
activityValidator.validatePeerReview(peerReview, sourceEntity, true, isApiRequest, null);
List<PeerReviewEntity> peerReviews = peerReviewDao.getByUser(orcid);
// duplicates
if (!sourceEntity.getSourceId().equals(orcid)) {
if (peerReviews != null) {
for (PeerReviewEntity entity : peerReviews) {
PeerReview existing = jpaJaxbPeerReviewAdapter.toPeerReview(entity);
activityValidator.checkExternalIdentifiersForDuplicates(peerReview.getExternalIdentifiers(), existing.getExternalIdentifiers(), existing.getSource(), sourceEntity);
}
}
} else {
//check vocab of external identifiers
externalIDValidator.validateWorkOrPeerReview(peerReview.getExternalIdentifiers());
externalIDValidator.validateWorkOrPeerReview(peerReview.getSubjectExternalIdentifier());
}
validateGroupId(peerReview);
}
PeerReviewEntity entity = jpaJaxbPeerReviewAdapter.toPeerReviewEntity(peerReview);
// Updates the give organization with the latest organization from
// database
OrgEntity updatedOrganization = orgManager.getOrgEntity(peerReview);
entity.setOrg(updatedOrganization);
//Set the source
if (sourceEntity.getSourceProfile() != null) {
entity.setSourceId(sourceEntity.getSourceProfile().getId());
}
if (sourceEntity.getSourceClient() != null) {
entity.setClientSourceId(sourceEntity.getSourceClient().getId());
}
ProfileEntity profile = profileEntityCacheManager.retrieve(orcid);
entity.setProfile(profile);
setIncomingPrivacy(entity, profile);
DisplayIndexCalculatorHelper.setDisplayIndexOnNewEntity(entity, isApiRequest);
peerReviewDao.persist(entity);
peerReviewDao.flush();
notificationManager.sendAmendEmail(orcid, AmendedSection.PEER_REVIEW, createItem(entity));
return jpaJaxbPeerReviewAdapter.toPeerReview(entity);
}
use of org.orcid.persistence.jpa.entities.PeerReviewEntity in project ORCID-Source by ORCID.
the class PeerReviewManagerImpl method updatePeerReview.
@Override
public PeerReview updatePeerReview(String orcid, PeerReview peerReview, boolean isApiRequest) {
PeerReviewEntity existingEntity = peerReviewDao.getPeerReview(orcid, peerReview.getPutCode());
Visibility originalVisibility = existingEntity.getVisibility();
SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
//Save the original source
String existingSourceId = existingEntity.getSourceId();
String existingClientSourceId = existingEntity.getClientSourceId();
// If request comes from the API perform validations
if (isApiRequest) {
activityValidator.validatePeerReview(peerReview, sourceEntity, false, isApiRequest, originalVisibility);
validateGroupId(peerReview);
List<PeerReview> existingReviews = this.findPeerReviews(orcid, System.currentTimeMillis());
for (PeerReview existing : existingReviews) {
// Dont compare the updated peer review with the DB version
if (!existing.getPutCode().equals(peerReview.getPutCode())) {
activityValidator.checkExternalIdentifiersForDuplicates(peerReview.getExternalIdentifiers(), existing.getExternalIdentifiers(), existing.getSource(), sourceManager.retrieveSourceEntity());
}
}
} else {
//check vocab of external identifiers
externalIDValidator.validateWorkOrPeerReview(peerReview.getExternalIdentifiers());
externalIDValidator.validateWorkOrPeerReview(peerReview.getSubjectExternalIdentifier());
}
PeerReviewEntity updatedEntity = new PeerReviewEntity();
orcidSecurityManager.checkSource(existingEntity);
jpaJaxbPeerReviewAdapter.toPeerReviewEntity(peerReview, updatedEntity);
updatedEntity.setProfile(new ProfileEntity(orcid));
updatedEntity.setVisibility(originalVisibility);
//Be sure it doesn't overwrite the source
updatedEntity.setSourceId(existingSourceId);
updatedEntity.setClientSourceId(existingClientSourceId);
OrgEntity updatedOrganization = orgManager.getOrgEntity(peerReview);
updatedEntity.setOrg(updatedOrganization);
updatedEntity = peerReviewDao.merge(updatedEntity);
peerReviewDao.flush();
notificationManager.sendAmendEmail(orcid, AmendedSection.PEER_REVIEW, createItem(updatedEntity));
return jpaJaxbPeerReviewAdapter.toPeerReview(updatedEntity);
}
Aggregations