use of org.orcid.jaxb.model.v3.dev1.common.Title in project ORCID-Source by ORCID.
the class MemberV3ApiServiceDelegator_ServicesTest method testUpdateService.
@Test
public void testUpdateService() {
SecurityContextTestUtils.setUpSecurityContext(ORCID, ScopePathType.READ_LIMITED, ScopePathType.ACTIVITIES_UPDATE);
Response response = serviceDelegator.viewService(ORCID, 47L);
assertNotNull(response);
Service service = (Service) response.getEntity();
assertNotNull(service);
assertEquals("PUBLIC Department", service.getDepartmentName());
assertEquals("PUBLIC", service.getRoleTitle());
Utils.verifyLastModified(service.getLastModifiedDate());
LastModifiedDate before = service.getLastModifiedDate();
service.setDepartmentName("Updated department name");
service.setRoleTitle("The updated role title");
// disambiguated org is required in API v3
DisambiguatedOrganization disambiguatedOrg = new DisambiguatedOrganization();
disambiguatedOrg.setDisambiguatedOrganizationIdentifier("abc456");
disambiguatedOrg.setDisambiguationSource("WDB");
service.getOrganization().setDisambiguatedOrganization(disambiguatedOrg);
response = serviceDelegator.updateService(ORCID, 47L, service);
assertNotNull(response);
assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
response = serviceDelegator.viewService(ORCID, 47L);
assertNotNull(response);
service = (Service) response.getEntity();
assertNotNull(service);
Utils.verifyLastModified(service.getLastModifiedDate());
assertTrue(service.getLastModifiedDate().after(before));
assertEquals("Updated department name", service.getDepartmentName());
assertEquals("The updated role title", service.getRoleTitle());
// Rollback changes
service.setDepartmentName("PUBLIC Department");
service.setRoleTitle("PUBLIC");
response = serviceDelegator.updateService(ORCID, 47L, service);
assertNotNull(response);
assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
}
use of org.orcid.jaxb.model.v3.dev1.common.Title in project ORCID-Source by ORCID.
the class MemberV3ApiServiceDelegator_WorksTest method testUpdateWorkYouAreNotTheSourceOf.
@Test(expected = WrongSourceException.class)
public void testUpdateWorkYouAreNotTheSourceOf() {
SecurityContextTestUtils.setUpSecurityContext("4444-4444-4444-4443", ScopePathType.READ_LIMITED, ScopePathType.ACTIVITIES_UPDATE);
Response response = serviceDelegator.viewWork("4444-4444-4444-4443", 2L);
assertNotNull(response);
Work work = (Work) response.getEntity();
assertNotNull(work);
Utils.verifyLastModified(work.getLastModifiedDate());
assertEquals(Long.valueOf(2), work.getPutCode());
assertNotNull(work.getWorkTitle());
assertNotNull(work.getWorkTitle().getTitle());
assertEquals("Another day in the life", work.getWorkTitle().getTitle().getContent());
assertEquals(WorkType.BOOK, work.getWorkType());
work.setWorkType(WorkType.EDITED_BOOK);
work.getWorkTitle().getTitle().setContent("Updated work title");
ExternalIDs extIds = new ExternalIDs();
ExternalID extId = new ExternalID();
extId.setRelationship(Relationship.PART_OF);
extId.setType(WorkExternalIdentifierType.AGR.value());
extId.setValue("ext-id-" + System.currentTimeMillis());
extId.setUrl(new Url("http://thisIsANewUrl.com"));
extIds.getExternalIdentifier().add(extId);
work.setWorkExternalIdentifiers(extIds);
serviceDelegator.updateWork("4444-4444-4444-4443", 2L, work);
fail();
}
use of org.orcid.jaxb.model.v3.dev1.common.Title in project ORCID-Source by ORCID.
the class MemberV3ApiServiceDelegator_WorksTest method testAddWork.
@Test
public void testAddWork() {
SecurityContextTestUtils.setUpSecurityContext("4444-4444-4444-4445", ScopePathType.READ_LIMITED, ScopePathType.ACTIVITIES_UPDATE);
Response response = serviceDelegator.viewActivities("4444-4444-4444-4445");
assertNotNull(response);
ActivitiesSummary summary = (ActivitiesSummary) response.getEntity();
assertNotNull(summary);
Utils.verifyLastModified(summary.getLastModifiedDate());
// Check works
assertNotNull(summary.getWorks());
assertNotNull(summary.getWorks().getWorkGroup());
assertEquals(1, summary.getWorks().getWorkGroup().size());
Utils.verifyLastModified(summary.getWorks().getLastModifiedDate());
assertNotNull(summary.getWorks().getWorkGroup().get(0));
Utils.verifyLastModified(summary.getWorks().getWorkGroup().get(0).getLastModifiedDate());
assertNotNull(summary.getWorks().getWorkGroup().get(0).getWorkSummary());
assertEquals(1, summary.getWorks().getWorkGroup().get(0).getWorkSummary().size());
String title = "work # 1 " + System.currentTimeMillis();
Work work = Utils.getWork(title);
response = serviceDelegator.createWork("4444-4444-4444-4445", work);
assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatus());
Long putCode = Utils.getPutCode(response);
response = serviceDelegator.viewActivities("4444-4444-4444-4445");
assertNotNull(response);
summary = (ActivitiesSummary) response.getEntity();
assertNotNull(summary);
Utils.verifyLastModified(summary.getLastModifiedDate());
// Check works
assertNotNull(summary.getWorks());
assertNotNull(summary.getWorks().getWorkGroup());
assertEquals(2, summary.getWorks().getWorkGroup().size());
boolean haveOld = false;
boolean haveNew = false;
for (WorkGroup group : summary.getWorks().getWorkGroup()) {
Utils.verifyLastModified(group.getLastModifiedDate());
assertNotNull(group.getWorkSummary());
assertNotNull(group.getWorkSummary().get(0));
WorkSummary workSummary = group.getWorkSummary().get(0);
Utils.verifyLastModified(workSummary.getLastModifiedDate());
assertNotNull(workSummary.getTitle());
assertNotNull(workSummary.getTitle().getTitle());
if ("A Book With Contributors JSON".equals(workSummary.getTitle().getTitle().getContent())) {
haveOld = true;
} else if (title.equals(workSummary.getTitle().getTitle().getContent())) {
haveNew = true;
}
}
assertTrue(haveOld);
assertTrue(haveNew);
// Delete them
serviceDelegator.deleteWork("4444-4444-4444-4445", putCode);
}
use of org.orcid.jaxb.model.v3.dev1.common.Title in project ORCID-Source by ORCID.
the class JSONInputValidatorTest method testValidateJSONInputForValidV3Work.
@Test
public void testValidateJSONInputForValidV3Work() throws JAXBException, SAXException, IOException {
Work work = org.orcid.test.helper.v3.Utils.getWork("title");
validator.validateJSONInput(work);
}
use of org.orcid.jaxb.model.v3.dev1.common.Title in project ORCID-Source by ORCID.
the class PeerReviewsController method createPeerReviewIdList.
/**
* Create a funding id list and sorts a map associated with the list in in
* the session
*/
private List<String> createPeerReviewIdList(HttpServletRequest request) {
String orcid = getCurrentUserOrcid();
List<PeerReview> peerReviews = peerReviewManager.findPeerReviews(orcid);
Map<String, String> languages = lm.buildLanguageMap(getUserLocale(), false);
HashMap<Long, PeerReviewForm> peerReviewMap = new HashMap<>();
List<String> peerReviewIds = new ArrayList<String>();
if (peerReviews != null) {
for (PeerReview peerReview : peerReviews) {
try {
PeerReviewForm form = PeerReviewForm.valueOf(peerReview);
if (form.getExternalIdentifiers() != null && !form.getExternalIdentifiers().isEmpty()) {
for (WorkExternalIdentifier wExtId : form.getExternalIdentifiers()) {
if (PojoUtil.isEmpty(wExtId.getRelationship())) {
wExtId.setRelationship(Text.valueOf(Relationship.SELF.value()));
}
}
}
if (form.getTranslatedSubjectName() != null) {
// Set translated title language name
if (!(form.getTranslatedSubjectName() == null) && !StringUtils.isEmpty(form.getTranslatedSubjectName().getLanguageCode())) {
String languageName = languages.get(form.getTranslatedSubjectName().getLanguageCode());
form.getTranslatedSubjectName().setLanguageName(languageName);
}
}
form.setCountryForDisplay(getMessage(buildInternationalizationKey(CountryIsoEntity.class, peerReview.getOrganization().getAddress().getCountry().name())));
// Set the numeric id (the table id in the group_id_record table) of the group id
if (form.getGroupId() != null && !PojoUtil.isEmpty(form.getGroupId().getValue())) {
GroupIdRecord groupId = groupIdRecordManager.findByGroupId(form.getGroupId().getValue()).get();
form.setGroupIdPutCode(Text.valueOf(groupId.getPutCode()));
}
peerReviewMap.put(peerReview.getPutCode(), form);
peerReviewIds.add(String.valueOf(peerReview.getPutCode()));
} catch (Exception e) {
LOGGER.error("Failed to parse as PeerReview. Put code" + peerReview.getPutCode(), e);
}
}
request.getSession().setAttribute(PEER_REVIEW_MAP, peerReviewMap);
}
return peerReviewIds;
}
Aggregations