Search in sources :

Example 11 with Title

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());
}
Also used : Response(javax.ws.rs.core.Response) LastModifiedDate(org.orcid.jaxb.model.v3.dev1.common.LastModifiedDate) DisambiguatedOrganization(org.orcid.jaxb.model.v3.dev1.common.DisambiguatedOrganization) Service(org.orcid.jaxb.model.v3.dev1.record.Service) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 12 with Title

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();
}
Also used : Response(javax.ws.rs.core.Response) ExternalIDs(org.orcid.jaxb.model.v3.dev1.record.ExternalIDs) ExternalID(org.orcid.jaxb.model.v3.dev1.record.ExternalID) Work(org.orcid.jaxb.model.v3.dev1.record.Work) ResearcherUrl(org.orcid.jaxb.model.v3.dev1.record.ResearcherUrl) Url(org.orcid.jaxb.model.v3.dev1.common.Url) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 13 with Title

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);
}
Also used : Response(javax.ws.rs.core.Response) WorkGroup(org.orcid.jaxb.model.v3.dev1.record.summary.WorkGroup) WorkSummary(org.orcid.jaxb.model.v3.dev1.record.summary.WorkSummary) Work(org.orcid.jaxb.model.v3.dev1.record.Work) ActivitiesSummary(org.orcid.jaxb.model.v3.dev1.record.summary.ActivitiesSummary) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 14 with Title

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);
}
Also used : Work(org.orcid.jaxb.model.v3.dev1.record.Work) Test(org.junit.Test)

Example 15 with Title

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;
}
Also used : HashMap(java.util.HashMap) GroupIdRecord(org.orcid.jaxb.model.v3.dev1.groupid.GroupIdRecord) ArrayList(java.util.ArrayList) PeerReviewForm(org.orcid.pojo.ajaxForm.PeerReviewForm) WorkExternalIdentifier(org.orcid.pojo.ajaxForm.WorkExternalIdentifier) PeerReview(org.orcid.jaxb.model.v3.dev1.record.PeerReview)

Aggregations

Test (org.junit.Test)81 Title (org.orcid.jaxb.model.v3.dev1.common.Title)44 Work (org.orcid.jaxb.model.v3.dev1.record.Work)43 WorkTitle (org.orcid.jaxb.model.v3.dev1.record.WorkTitle)40 ExternalID (org.orcid.jaxb.model.v3.dev1.record.ExternalID)38 Url (org.orcid.jaxb.model.v3.dev1.common.Url)33 DBUnitTest (org.orcid.test.DBUnitTest)29 ExternalIDs (org.orcid.jaxb.model.v3.dev1.record.ExternalIDs)27 ClientResponse (com.sun.jersey.api.client.ClientResponse)26 Response (javax.ws.rs.core.Response)25 Funding (org.orcid.jaxb.model.v3.dev1.record.Funding)23 FundingTitle (org.orcid.jaxb.model.v3.dev1.record.FundingTitle)19 OrcidError (org.orcid.jaxb.model.v3.dev1.error.OrcidError)17 PeerReview (org.orcid.jaxb.model.v3.dev1.record.PeerReview)17 TranslatedTitle (org.orcid.jaxb.model.v3.dev1.common.TranslatedTitle)14 ResearcherUrl (org.orcid.jaxb.model.v3.dev1.record.ResearcherUrl)14 ArrayList (java.util.ArrayList)13 DisambiguatedOrganization (org.orcid.jaxb.model.v3.dev1.common.DisambiguatedOrganization)13 LastModifiedDate (org.orcid.jaxb.model.v3.dev1.common.LastModifiedDate)13 Visibility (org.orcid.jaxb.model.v3.dev1.common.Visibility)13