use of org.orcid.jaxb.model.record_rc3.Work in project ORCID-Source by ORCID.
the class MemberV2ApiServiceDelegator_WorksTest method testUpdateWorkChangingVisibilityTest.
@Test(expected = VisibilityMismatchException.class)
public void testUpdateWorkChangingVisibilityTest() {
SecurityContextTestUtils.setUpSecurityContext("4444-4444-4444-4445", ScopePathType.READ_LIMITED, ScopePathType.ACTIVITIES_UPDATE);
Response response = serviceDelegator.viewWork("4444-4444-4444-4445", 3L);
assertNotNull(response);
Work work = (Work) response.getEntity();
assertNotNull(work);
assertEquals(Visibility.LIMITED, work.getVisibility());
work.setVisibility(Visibility.PRIVATE);
response = serviceDelegator.updateWork("4444-4444-4444-4445", 3L, work);
fail();
}
use of org.orcid.jaxb.model.record_rc3.Work in project ORCID-Source by ORCID.
the class MemberV2ApiServiceDelegator_WorksTest method testViewPrivateWork.
@Test
public void testViewPrivateWork() {
// Use the smallest scope in the pyramid to verify that you can read
// your own limited and protected data
SecurityContextTestUtils.setUpSecurityContext("4444-4444-4444-4446", ScopePathType.READ_LIMITED);
Response response = serviceDelegator.viewWork("4444-4444-4444-4446", 7L);
assertNotNull(response);
Work work = (Work) response.getEntity();
Utils.verifyLastModified(work.getLastModifiedDate());
assertNotNull(work.getWorkTitle());
assertNotNull(work.getWorkTitle().getTitle());
assertEquals("Journal article C", work.getWorkTitle().getTitle().getContent());
assertEquals(Long.valueOf(7), work.getPutCode());
assertEquals("/4444-4444-4444-4446/work/7", work.getPath());
assertEquals(WorkType.JOURNAL_ARTICLE, work.getWorkType());
assertEquals(Visibility.PRIVATE.value(), work.getVisibility().value());
}
use of org.orcid.jaxb.model.record_rc3.Work in project ORCID-Source by ORCID.
the class MapperFacadeFactory method getWorkMapperFacade.
public MapperFacade getWorkMapperFacade() {
MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();
ConverterFactory converterFactory = mapperFactory.getConverterFactory();
converterFactory.registerConverter("workExternalIdentifiersConverterId", new WorkExternalIDsConverter());
converterFactory.registerConverter("workContributorsConverterId", new JsonOrikaConverter<WorkContributors>());
ClassMapBuilder<Work, WorkEntity> workClassMap = mapperFactory.classMap(Work.class, WorkEntity.class);
workClassMap.byDefault();
workClassMap.field("putCode", "id");
addV2DateFields(workClassMap);
registerSourceConverters(mapperFactory, workClassMap);
workClassMap.field("journalTitle.content", "journalTitle");
workClassMap.field("workTitle.title.content", "title");
workClassMap.field("workTitle.translatedTitle.content", "translatedTitle");
workClassMap.field("workTitle.translatedTitle.languageCode", "translatedTitleLanguageCode");
workClassMap.field("workTitle.subtitle.content", "subtitle");
workClassMap.field("shortDescription", "description");
workClassMap.field("workCitation.workCitationType", "citationType");
workClassMap.field("workCitation.citation", "citation");
workClassMap.field("workType", "workType");
workClassMap.field("publicationDate", "publicationDate");
workClassMap.fieldMap("workExternalIdentifiers", "externalIdentifiersJson").converter("workExternalIdentifiersConverterId").add();
workClassMap.field("url.value", "workUrl");
workClassMap.fieldMap("workContributors", "contributorsJson").converter("workContributorsConverterId").add();
workClassMap.field("languageCode", "languageCode");
workClassMap.field("country.value", "iso2Country");
workClassMap.register();
ClassMapBuilder<WorkSummary, WorkEntity> workSummaryClassMap = mapperFactory.classMap(WorkSummary.class, WorkEntity.class);
registerSourceConverters(mapperFactory, workSummaryClassMap);
workSummaryClassMap.field("putCode", "id");
workSummaryClassMap.field("title.title.content", "title");
workSummaryClassMap.field("title.translatedTitle.content", "translatedTitle");
workSummaryClassMap.field("title.translatedTitle.languageCode", "translatedTitleLanguageCode");
workSummaryClassMap.field("type", "workType");
workSummaryClassMap.field("publicationDate", "publicationDate");
workSummaryClassMap.fieldMap("externalIdentifiers", "externalIdentifiersJson").converter("workExternalIdentifiersConverterId").add();
workSummaryClassMap.byDefault();
workSummaryClassMap.register();
ClassMapBuilder<WorkSummary, MinimizedWorkEntity> workSummaryMinimizedClassMap = mapperFactory.classMap(WorkSummary.class, MinimizedWorkEntity.class);
addV2CommonFields(workSummaryMinimizedClassMap);
registerSourceConverters(mapperFactory, workSummaryMinimizedClassMap);
workSummaryMinimizedClassMap.field("title.title.content", "title");
workSummaryMinimizedClassMap.field("title.translatedTitle.content", "translatedTitle");
workSummaryMinimizedClassMap.field("title.translatedTitle.languageCode", "translatedTitleLanguageCode");
workSummaryMinimizedClassMap.field("type", "workType");
workSummaryMinimizedClassMap.field("publicationDate.year.value", "publicationYear");
workSummaryMinimizedClassMap.field("publicationDate.month.value", "publicationMonth");
workSummaryMinimizedClassMap.field("publicationDate.day.value", "publicationDay");
workSummaryMinimizedClassMap.fieldMap("externalIdentifiers", "externalIdentifiersJson").converter("workExternalIdentifiersConverterId").add();
workSummaryMinimizedClassMap.byDefault();
workSummaryMinimizedClassMap.register();
ClassMapBuilder<Work, MinimizedWorkEntity> minimizedWorkClassMap = mapperFactory.classMap(Work.class, MinimizedWorkEntity.class);
minimizedWorkClassMap.byDefault();
registerSourceConverters(mapperFactory, minimizedWorkClassMap);
minimizedWorkClassMap.field("putCode", "id");
minimizedWorkClassMap.field("journalTitle.content", "journalTitle");
minimizedWorkClassMap.field("workTitle.title.content", "title");
minimizedWorkClassMap.field("workTitle.translatedTitle.content", "translatedTitle");
minimizedWorkClassMap.field("workTitle.translatedTitle.languageCode", "translatedTitleLanguageCode");
minimizedWorkClassMap.field("workTitle.subtitle.content", "subtitle");
minimizedWorkClassMap.field("shortDescription", "description");
minimizedWorkClassMap.field("workType", "workType");
minimizedWorkClassMap.field("publicationDate.year.value", "publicationYear");
minimizedWorkClassMap.field("publicationDate.month.value", "publicationMonth");
minimizedWorkClassMap.field("publicationDate.day.value", "publicationDay");
minimizedWorkClassMap.fieldMap("workExternalIdentifiers", "externalIdentifiersJson").converter("workExternalIdentifiersConverterId").add();
minimizedWorkClassMap.field("url.value", "workUrl");
minimizedWorkClassMap.register();
mapperFactory.classMap(PublicationDate.class, PublicationDateEntity.class).field("year.value", "year").field("month.value", "month").field("day.value", "day").register();
return mapperFactory.getMapperFacade();
}
use of org.orcid.jaxb.model.record_rc3.Work in project ORCID-Source by ORCID.
the class BibtexManagerImpl method generateBibtexReferenceList.
@Override
public String generateBibtexReferenceList(String orcid) {
long last = workManager.getLastModified(orcid);
ActivitiesSummary summary = activitiesManager.getActivitiesSummary(orcid);
List<String> citations = new ArrayList<String>();
if (summary.getWorks() != null) {
for (WorkGroup group : summary.getWorks().getWorkGroup()) {
WorkSummary workSummary = group.getWorkSummary().get(0);
Work work = workManager.getWork(orcid, workSummary.getPutCode(), last);
String bibtex = generateBibtex(orcid, work);
if (bibtex != null)
citations.add(bibtex);
}
}
return Joiner.on(",\n").join(citations);
}
use of org.orcid.jaxb.model.record_rc3.Work in project ORCID-Source by ORCID.
the class WorkManagerImpl method updateWork.
@Override
@Transactional
public Work updateWork(String orcid, Work work, boolean isApiRequest) {
WorkEntity workEntity = workDao.getWork(orcid, work.getPutCode());
Visibility originalVisibility = workEntity.getVisibility();
SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
//Save the original source
String existingSourceId = workEntity.getSourceId();
String existingClientSourceId = workEntity.getClientSourceId();
if (isApiRequest) {
activityValidator.validateWork(work, sourceEntity, false, isApiRequest, workEntity.getVisibility());
long lastModifiedTime = getLastModified(orcid);
List<Work> existingWorks = this.findWorks(orcid, lastModifiedTime);
for (Work existing : existingWorks) {
// Dont compare the updated peer review with the DB version
if (!existing.getPutCode().equals(work.getPutCode())) {
activityValidator.checkExternalIdentifiersForDuplicates(work.getExternalIdentifiers(), existing.getExternalIdentifiers(), existing.getSource(), sourceEntity);
}
}
} else {
//validate external ID vocab
externalIDValidator.validateWorkOrPeerReview(work.getExternalIdentifiers());
}
orcidSecurityManager.checkSource(workEntity);
jpaJaxbWorkAdapter.toWorkEntity(work, workEntity);
workEntity.setVisibility(originalVisibility);
//Be sure it doesn't overwrite the source
workEntity.setSourceId(existingSourceId);
workEntity.setClientSourceId(existingClientSourceId);
workDao.merge(workEntity);
workDao.flush();
notificationManager.sendAmendEmail(orcid, AmendedSection.WORK, createItem(workEntity));
return jpaJaxbWorkAdapter.toWork(workEntity);
}
Aggregations