use of org.orcid.jaxb.model.record_rc3.Work in project ORCID-Source by ORCID.
the class WorkManagerImpl method createWork.
@Override
@Transactional
public Work createWork(String orcid, Work work, boolean isApiRequest) {
SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
if (isApiRequest) {
activityValidator.validateWork(work, sourceEntity, true, isApiRequest, null);
// duplicates
if (!sourceEntity.getSourceId().equals(orcid)) {
long lastModifiedTime = getLastModified(orcid);
List<Work> existingWorks = this.findWorks(orcid, lastModifiedTime);
if (existingWorks != null) {
for (Work existing : existingWorks) {
activityValidator.checkExternalIdentifiersForDuplicates(work.getExternalIdentifiers(), existing.getExternalIdentifiers(), existing.getSource(), sourceEntity);
}
}
}
} else {
// validate external ID vocab
externalIDValidator.validateWorkOrPeerReview(work.getExternalIdentifiers());
}
WorkEntity workEntity = jpaJaxbWorkAdapter.toWorkEntity(work);
ProfileEntity profile = profileEntityCacheManager.retrieve(orcid);
workEntity.setProfile(profile);
workEntity.setAddedToProfileDate(new Date());
// Set source id
if (sourceEntity.getSourceProfile() != null) {
workEntity.setSourceId(sourceEntity.getSourceProfile().getId());
}
if (sourceEntity.getSourceClient() != null) {
workEntity.setClientSourceId(sourceEntity.getSourceClient().getId());
}
setIncomingWorkPrivacy(workEntity, profile);
DisplayIndexCalculatorHelper.setDisplayIndexOnNewEntity(workEntity, isApiRequest);
workDao.persist(workEntity);
workDao.flush();
notificationManager.sendAmendEmail(orcid, AmendedSection.WORK, createItem(workEntity));
return jpaJaxbWorkAdapter.toWork(workEntity);
}
use of org.orcid.jaxb.model.record_rc3.Work in project ORCID-Source by ORCID.
the class JpaJaxbWorkAdapterTest method testToWorkEntity.
@Test
public void testToWorkEntity() throws JAXBException {
Work work = getWork(true);
assertNotNull(work);
WorkEntity workEntity = jpaJaxbWorkAdapter.toWorkEntity(work);
assertNotNull(workEntity);
assertEquals(Visibility.PRIVATE, workEntity.getVisibility());
assertNotNull(workEntity);
assertEquals(123, workEntity.getId().longValue());
assertEquals("common:title", workEntity.getTitle());
assertTrue(PojoUtil.isEmpty(workEntity.getSubtitle()));
assertEquals("common:translated-title", workEntity.getTranslatedTitle());
assertEquals("en", workEntity.getTranslatedTitleLanguageCode());
assertEquals("work:short-description", workEntity.getDescription());
assertEquals(CitationType.FORMATTED_UNSPECIFIED, workEntity.getCitationType());
assertEquals(WorkType.ARTISTIC_PERFORMANCE, workEntity.getWorkType());
PublicationDateEntity publicationDateEntity = workEntity.getPublicationDate();
assertNotNull(publicationDateEntity);
assertEquals(1848, publicationDateEntity.getYear().intValue());
assertEquals(02, publicationDateEntity.getMonth().intValue());
assertEquals(02, publicationDateEntity.getDay().intValue());
assertEquals("{\"workExternalIdentifier\":[{\"relationship\":\"SELF\",\"url\":{\"value\":\"http://orcid.org\"},\"workExternalIdentifierType\":\"AGR\",\"workExternalIdentifierId\":{\"content\":\"work:external-identifier-id\"}}]}", workEntity.getExternalIdentifiersJson());
assertEquals("http://tempuri.org", workEntity.getWorkUrl());
assertEquals("{\"contributor\":[{\"contributorOrcid\":{\"uri\":\"http://orcid.org/8888-8888-8888-8880\",\"path\":\"8888-8888-8888-8880\",\"host\":\"orcid.org\"},\"creditName\":{\"content\":\"work:credit-name\"},\"contributorEmail\":{\"value\":\"work@contributor.email\"},\"contributorAttributes\":{\"contributorSequence\":\"FIRST\",\"contributorRole\":\"AUTHOR\"}}]}", workEntity.getContributorsJson());
assertEquals("en", workEntity.getLanguageCode());
assertEquals(Iso3166Country.AF, workEntity.getIso2Country());
// Source
assertNull(workEntity.getSourceId());
assertNull(workEntity.getClientSourceId());
assertNull(workEntity.getElementSourceId());
}
use of org.orcid.jaxb.model.record_rc3.Work in project ORCID-Source by ORCID.
the class OrcidSecurityManagerTestBase method createWork.
protected Work createWork(Visibility v, String sourceId) {
Work work = new Work();
work.setVisibility(v);
setSource(work, sourceId);
return work;
}
use of org.orcid.jaxb.model.record_rc3.Work in project ORCID-Source by ORCID.
the class ActivityValidatorTest method validateWork_emptyContributorEmailTest.
@Test(expected = OrcidValidationException.class)
public void validateWork_emptyContributorEmailTest() {
Work work = getWork();
work.getWorkContributors().getContributor().get(0).getContributorEmail().setValue("");
activityValidator.validateWork(work, null, true, true, Visibility.PUBLIC);
}
use of org.orcid.jaxb.model.record_rc3.Work in project ORCID-Source by ORCID.
the class ActivityValidatorTest method validateWork_invalidLanguageCodeTest.
@Test(expected = ActivityTypeValidationException.class)
public void validateWork_invalidLanguageCodeTest() {
Work work = getWork();
work.setLanguageCode("xx");
activityValidator.validateWork(work, null, true, true, Visibility.PUBLIC);
}
Aggregations