Search in sources :

Example 31 with Title

use of org.orcid.jaxb.model.common_rc1.Title in project ORCID-Source by ORCID.

the class MemberV2Test method testWorksWithPartOfRelationshipDontGetGrouped.

@Test
public void testWorksWithPartOfRelationshipDontGetGrouped() throws JSONException, InterruptedException, URISyntaxException {
    long time = System.currentTimeMillis();
    String accessTokenForClient1 = getAccessToken();
    String accessTokenForClient2 = getAccessToken(getUser1OrcidId(), getUser1Password(), getScopes(), getClient2ClientId(), getClient2ClientSecret(), getClient2RedirectUri());
    Work work1 = (Work) unmarshallFromPath("/record_2.0_rc1/samples/work-2.0_rc1.xml", Work.class);
    work1.setPutCode(null);
    work1.setVisibility(Visibility.PUBLIC);
    work1.getExternalIdentifiers().getExternalIdentifier().clear();
    org.orcid.jaxb.model.record_rc1.WorkTitle title1 = new org.orcid.jaxb.model.record_rc1.WorkTitle();
    title1.setTitle(new Title("Work # 1" + time));
    work1.setWorkTitle(title1);
    WorkExternalIdentifier wExtId1 = new WorkExternalIdentifier();
    wExtId1.setWorkExternalIdentifierId(new WorkExternalIdentifierId("Work Id " + time));
    wExtId1.setWorkExternalIdentifierType(WorkExternalIdentifierType.AGR);
    wExtId1.setRelationship(Relationship.SELF);
    wExtId1.setUrl(new Url("http://orcid.org/work#1"));
    work1.getExternalIdentifiers().getWorkExternalIdentifier().clear();
    work1.getExternalIdentifiers().getWorkExternalIdentifier().add(wExtId1);
    Work work2 = (Work) unmarshallFromPath("/record_2.0_rc1/samples/work-2.0_rc1.xml", Work.class);
    work2.setPutCode(null);
    work2.setVisibility(Visibility.PUBLIC);
    org.orcid.jaxb.model.record_rc1.WorkTitle title2 = new org.orcid.jaxb.model.record_rc1.WorkTitle();
    title2.setTitle(new Title("Work # 2" + time));
    work2.setWorkTitle(title2);
    work2.getExternalIdentifiers().getExternalIdentifier().clear();
    WorkExternalIdentifier wExtId2 = new WorkExternalIdentifier();
    wExtId2.setWorkExternalIdentifierId(new WorkExternalIdentifierId("Work Id " + time));
    wExtId2.setWorkExternalIdentifierType(WorkExternalIdentifierType.AGR);
    wExtId2.setRelationship(Relationship.PART_OF);
    wExtId2.setUrl(new Url("http://orcid.org/work#2"));
    work2.getExternalIdentifiers().getWorkExternalIdentifier().clear();
    work2.getExternalIdentifiers().getWorkExternalIdentifier().add(wExtId2);
    Work work3 = (Work) unmarshallFromPath("/record_2.0_rc1/samples/work-2.0_rc1.xml", Work.class);
    work3.setPutCode(null);
    work3.setVisibility(Visibility.PUBLIC);
    org.orcid.jaxb.model.record_rc1.WorkTitle title3 = new org.orcid.jaxb.model.record_rc1.WorkTitle();
    title3.setTitle(new Title("Work # 3" + time));
    work3.setWorkTitle(title3);
    work3.getExternalIdentifiers().getExternalIdentifier().clear();
    WorkExternalIdentifier wExtId3 = new WorkExternalIdentifier();
    wExtId3.setWorkExternalIdentifierId(new WorkExternalIdentifierId("Work Id " + time));
    wExtId3.setWorkExternalIdentifierType(WorkExternalIdentifierType.AGR);
    wExtId3.setRelationship(Relationship.SELF);
    wExtId3.setUrl(new Url("http://orcid.org/work#3"));
    work3.getExternalIdentifiers().getWorkExternalIdentifier().clear();
    work3.getExternalIdentifiers().getWorkExternalIdentifier().add(wExtId3);
    // Add the three works
    ClientResponse postResponse = memberV2ApiClient.createWorkXml(this.getUser1OrcidId(), work1, accessTokenForClient1);
    assertNotNull(postResponse);
    assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
    postResponse = memberV2ApiClient.createWorkXml(this.getUser1OrcidId(), work2, accessTokenForClient1);
    assertNotNull(postResponse);
    assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
    postResponse = memberV2ApiClient.createWorkXml(this.getUser1OrcidId(), work3, accessTokenForClient2);
    assertNotNull(postResponse);
    assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
    ClientResponse activitiesResponse = memberV2ApiClient.viewActivities(this.getUser1OrcidId(), accessTokenForClient1);
    assertEquals(Response.Status.OK.getStatusCode(), activitiesResponse.getStatus());
    ActivitiesSummary activities = activitiesResponse.getEntity(ActivitiesSummary.class);
    assertNotNull(activities);
    assertFalse(activities.getWorks().getWorkGroup().isEmpty());
    WorkGroup work1Group = null;
    WorkGroup work2Group = null;
    WorkGroup work3Group = null;
    boolean work1found = false;
    boolean work2found = false;
    boolean work3found = false;
    List<Long> putCodes = new ArrayList<Long>();
    for (WorkGroup group : activities.getWorks().getWorkGroup()) {
        if (group.getIdentifiers().getIdentifier() == null || group.getIdentifiers().getIdentifier().isEmpty()) {
            for (WorkSummary summary : group.getWorkSummary()) {
                String title = summary.getTitle().getTitle().getContent();
                if (("Work # 2" + time).equals(title)) {
                    work2found = true;
                    work2Group = group;
                    putCodes.add(summary.getPutCode());
                }
            }
        } else {
            for (Identifier id : group.getIdentifiers().getIdentifier()) {
                // If it is the ID is the one we are looking for
                if (id.getExternalIdentifierId().equals("Work Id " + time)) {
                    for (WorkSummary summary : group.getWorkSummary()) {
                        String title = summary.getTitle().getTitle().getContent();
                        if (("Work # 1" + time).equals(title)) {
                            work1found = true;
                            work1Group = group;
                            putCodes.add(summary.getPutCode());
                        } else if (("Work # 3" + time).equals(title)) {
                            work3found = true;
                            work3Group = group;
                            putCodes.add(summary.getPutCode());
                        }
                    }
                }
            }
        }
    }
    assertTrue("Work1: " + work1found + " work2 " + work2found + " work3 " + work3found, work1found && work2found && work3found);
    // Check that work # 1 and Work # 3 are in the same work
    assertEquals(work1Group, work3Group);
    // Check that work # 2 is not in the same group than group # 1
    assertThat(work2Group, not(work1Group));
    // Delete all elements created
    for (Long putCode : putCodes) {
        ClientResponse deleteResponse = memberV2ApiClient.deleteWorkXml(this.getUser1OrcidId(), putCode, accessTokenForClient1);
        if (Response.Status.NO_CONTENT.getStatusCode() != deleteResponse.getStatus()) {
            deleteResponse = memberV2ApiClient.deleteWorkXml(this.getUser1OrcidId(), putCode, accessTokenForClient2);
            assertEquals("Cant delete work " + putCode, Response.Status.NO_CONTENT.getStatusCode(), deleteResponse.getStatus());
        }
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) WorkExternalIdentifierId(org.orcid.jaxb.model.record_rc1.WorkExternalIdentifierId) ArrayList(java.util.ArrayList) Title(org.orcid.jaxb.model.common_rc1.Title) Url(org.orcid.jaxb.model.common_rc1.Url) ActivitiesSummary(org.orcid.jaxb.model.record.summary_rc1.ActivitiesSummary) WorkGroup(org.orcid.jaxb.model.record.summary_rc1.WorkGroup) WorkSummary(org.orcid.jaxb.model.record.summary_rc1.WorkSummary) WorkExternalIdentifier(org.orcid.jaxb.model.record_rc1.WorkExternalIdentifier) FundingExternalIdentifier(org.orcid.jaxb.model.record_rc1.FundingExternalIdentifier) Identifier(org.orcid.jaxb.model.record.summary_rc1.Identifier) Work(org.orcid.jaxb.model.record_rc1.Work) WorkExternalIdentifier(org.orcid.jaxb.model.record_rc1.WorkExternalIdentifier) Test(org.junit.Test)

Example 32 with Title

use of org.orcid.jaxb.model.common_rc1.Title in project ORCID-Source by ORCID.

the class MemberV2Test method createViewUpdateAndDeleteEducation.

@Test
public void createViewUpdateAndDeleteEducation() throws JSONException, InterruptedException, URISyntaxException {
    Education education = (Education) unmarshallFromPath("/record_2.0_rc1/samples/education-2.0_rc1.xml", Education.class);
    education.setPutCode(null);
    education.setVisibility(Visibility.PUBLIC);
    String accessToken = getAccessToken();
    ClientResponse postResponse = memberV2ApiClient.createEducationXml(this.getUser1OrcidId(), education, accessToken);
    assertNotNull(postResponse);
    assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
    String locationPath = postResponse.getLocation().getPath();
    assertTrue("Location header path should match pattern, but was " + locationPath, locationPath.matches(".*/v2.0_rc1/" + this.getUser1OrcidId() + "/education/\\d+"));
    ClientResponse getResponse = memberV2ApiClient.viewLocationXml(postResponse.getLocation(), accessToken);
    assertEquals(Response.Status.OK.getStatusCode(), getResponse.getStatus());
    Education gotEducation = getResponse.getEntity(Education.class);
    assertEquals("education:department-name", gotEducation.getDepartmentName());
    assertEquals("education:role-title", gotEducation.getRoleTitle());
    gotEducation.setDepartmentName("updated dept. name");
    gotEducation.setRoleTitle("updated role title");
    // Save the original visibility
    Visibility originalVisibility = gotEducation.getVisibility();
    Visibility updatedVisibility = Visibility.PRIVATE.equals(originalVisibility) ? Visibility.LIMITED : Visibility.PRIVATE;
    // Verify you cant update the visibility
    gotEducation.setVisibility(updatedVisibility);
    ClientResponse putResponse = memberV2ApiClient.updateLocationXml(postResponse.getLocation(), accessToken, gotEducation);
    assertEquals(Response.Status.FORBIDDEN.getStatusCode(), putResponse.getStatus());
    OrcidError error = putResponse.getEntity(OrcidError.class);
    assertNotNull(error);
    assertEquals(Integer.valueOf(9035), error.getErrorCode());
    // Set the visibility again to the initial one
    gotEducation.setVisibility(originalVisibility);
    putResponse = memberV2ApiClient.updateLocationXml(postResponse.getLocation(), accessToken, gotEducation);
    assertEquals(Response.Status.OK.getStatusCode(), putResponse.getStatus());
    ClientResponse getAfterUpdateResponse = memberV2ApiClient.viewLocationXml(postResponse.getLocation(), accessToken);
    assertEquals(Response.Status.OK.getStatusCode(), getAfterUpdateResponse.getStatus());
    Education gotAfterUpdateEducation = getAfterUpdateResponse.getEntity(Education.class);
    assertEquals("updated dept. name", gotAfterUpdateEducation.getDepartmentName());
    assertEquals("updated role title", gotAfterUpdateEducation.getRoleTitle());
    ClientResponse deleteResponse = memberV2ApiClient.deleteEducationXml(this.getUser1OrcidId(), gotEducation.getPutCode(), accessToken);
    assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deleteResponse.getStatus());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) OrcidError(org.orcid.jaxb.model.error_rc1.OrcidError) Education(org.orcid.jaxb.model.record_rc1.Education) Visibility(org.orcid.jaxb.model.common_rc1.Visibility) Test(org.junit.Test)

Example 33 with Title

use of org.orcid.jaxb.model.common_rc1.Title in project ORCID-Source by ORCID.

the class MemberV2Test method createViewUpdateAndDeletePeerReview.

@Test
public void createViewUpdateAndDeletePeerReview() throws JSONException, InterruptedException, URISyntaxException {
    long time = System.currentTimeMillis();
    PeerReview peerReviewToCreate = (PeerReview) unmarshallFromPath("/record_2.0_rc1/samples/peer-review-2.0_rc1.xml", PeerReview.class);
    peerReviewToCreate.setPutCode(null);
    peerReviewToCreate.setGroupId(groupRecords.get(0).getGroupId());
    peerReviewToCreate.getExternalIdentifiers().getExternalIdentifier().clear();
    WorkExternalIdentifier wExtId = new WorkExternalIdentifier();
    wExtId.setWorkExternalIdentifierId(new WorkExternalIdentifierId("Work Id " + time));
    wExtId.setWorkExternalIdentifierType(WorkExternalIdentifierType.AGR);
    wExtId.setRelationship(Relationship.SELF);
    peerReviewToCreate.getExternalIdentifiers().getExternalIdentifier().add(wExtId);
    String accessToken = getAccessToken();
    ClientResponse postResponse = memberV2ApiClient.createPeerReviewXml(this.getUser1OrcidId(), peerReviewToCreate, accessToken);
    assertNotNull(postResponse);
    assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
    String locationPath = postResponse.getLocation().getPath();
    assertTrue("Location header path should match pattern, but was " + locationPath, locationPath.matches(".*/v2.0_rc1/" + this.getUser1OrcidId() + "/peer-review/\\d+"));
    ClientResponse getResponse = memberV2ApiClient.viewLocationXml(postResponse.getLocation(), accessToken);
    assertEquals(Response.Status.OK.getStatusCode(), getResponse.getStatus());
    PeerReview gotPeerReview = getResponse.getEntity(PeerReview.class);
    // TODO: response does not contain full external identifier or disambig org.
    // Issue is that upgrading makes subject external identifier fail
    // https://www.diffchecker.com/g5laoiou
    // Note that this test does not hit disambiguated orgs (which are optional and also not being upgraded)
    assertEquals("peer-review:url", gotPeerReview.getUrl().getValue());
    assertEquals("peer-review:subject-name", gotPeerReview.getSubjectName().getTitle().getContent());
    assertEquals(groupRecords.get(0).getGroupId(), gotPeerReview.getGroupId());
    gotPeerReview.getSubjectName().getTitle().setContent("updated title");
    // Save the original visibility
    Visibility originalVisibility = gotPeerReview.getVisibility();
    Visibility updatedVisibility = Visibility.PRIVATE.equals(originalVisibility) ? Visibility.LIMITED : Visibility.PRIVATE;
    // Verify you cant update the visibility
    gotPeerReview.setVisibility(updatedVisibility);
    ClientResponse putResponse = memberV2ApiClient.updateLocationXml(postResponse.getLocation(), accessToken, gotPeerReview);
    assertEquals(Response.Status.FORBIDDEN.getStatusCode(), putResponse.getStatus());
    OrcidError error = putResponse.getEntity(OrcidError.class);
    assertNotNull(error);
    assertEquals(Integer.valueOf(9035), error.getErrorCode());
    // Set the visibility again to the initial one
    gotPeerReview.setVisibility(originalVisibility);
    putResponse = memberV2ApiClient.updateLocationXml(postResponse.getLocation(), accessToken, gotPeerReview);
    assertEquals(Response.Status.OK.getStatusCode(), putResponse.getStatus());
    ClientResponse getAfterUpdateResponse = memberV2ApiClient.viewLocationXml(postResponse.getLocation(), accessToken);
    assertEquals(Response.Status.OK.getStatusCode(), getAfterUpdateResponse.getStatus());
    PeerReview gotAfterUpdateWork = getAfterUpdateResponse.getEntity(PeerReview.class);
    assertEquals("updated title", gotAfterUpdateWork.getSubjectName().getTitle().getContent());
    assertEquals(groupRecords.get(0).getGroupId(), gotAfterUpdateWork.getGroupId());
    ClientResponse deleteResponse = memberV2ApiClient.deletePeerReviewXml(this.getUser1OrcidId(), gotAfterUpdateWork.getPutCode(), accessToken);
    assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deleteResponse.getStatus());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) OrcidError(org.orcid.jaxb.model.error_rc1.OrcidError) WorkExternalIdentifierId(org.orcid.jaxb.model.record_rc1.WorkExternalIdentifierId) Visibility(org.orcid.jaxb.model.common_rc1.Visibility) WorkExternalIdentifier(org.orcid.jaxb.model.record_rc1.WorkExternalIdentifier) PeerReview(org.orcid.jaxb.model.record_rc1.PeerReview) Test(org.junit.Test)

Example 34 with Title

use of org.orcid.jaxb.model.common_rc1.Title in project ORCID-Source by ORCID.

the class SourceInActivitiesTest method getWork.

private Work getWork(String userOrcid) {
    Work work = new Work();
    WorkTitle title = new WorkTitle();
    title.setTitle(new Title("Work " + System.currentTimeMillis()));
    work.setWorkTitle(title);
    work.setWorkType(org.orcid.jaxb.model.record_v2.WorkType.BOOK);
    ExternalID extId = new ExternalID();
    extId.setValue("111");
    extId.setType(WorkExternalIdentifierType.DOI.value());
    ExternalIDs extIdentifiers = new ExternalIDs();
    extIdentifiers.getExternalIdentifier().add(extId);
    work.setWorkExternalIdentifiers(extIdentifiers);
    work = workManager.createWork(userOrcid, work, false);
    return workManager.getWork(userOrcid, work.getPutCode());
}
Also used : ExternalIDs(org.orcid.jaxb.model.record_v2.ExternalIDs) WorkTitle(org.orcid.jaxb.model.record_v2.WorkTitle) ExternalID(org.orcid.jaxb.model.record_v2.ExternalID) Work(org.orcid.jaxb.model.record_v2.Work) WorkTitle(org.orcid.jaxb.model.record_v2.WorkTitle) FundingTitle(org.orcid.jaxb.model.record_v2.FundingTitle) Title(org.orcid.jaxb.model.common_v2.Title)

Example 35 with Title

use of org.orcid.jaxb.model.common_rc1.Title in project ORCID-Source by ORCID.

the class MongoMessageProcessorTest method testInsertAndUpsert.

@Test
public void testInsertAndUpsert() throws LockedRecordException, DeprecatedRecordException {
    Record record = new Record();
    record.setOrcidIdentifier(new OrcidIdentifier("http://orcid.org/" + this.orcid));
    ActivitiesSummary sum = new ActivitiesSummary();
    Works works = new Works();
    WorkGroup group = new WorkGroup();
    WorkSummary work = new WorkSummary();
    WorkTitle title = new WorkTitle();
    title.setTitle(new Title("blah"));
    work.setTitle(title);
    group.getWorkSummary().add(work);
    works.getWorkGroup().add(group);
    sum.setWorks(works);
    record.setActivitiesSummary(sum);
    when(mock_orcid20ApiClient.fetchPublicRecord(Matchers.any())).thenReturn(record);
    LastModifiedMessage m = new LastModifiedMessage(this.orcid, new Date());
    mongo.accept(m);
    // test record inserted (has work, no name)
    Document d = new Document();
    d.put("_id", this.orcid);
    assertEquals(col.count(d), 1);
    FindIterable<Document> it = col.find(d);
    Document found = it.first();
    assertEquals(found.get("orcid-identifier", Document.class).get("path"), "http://orcid.org/" + this.orcid);
    List<Document> groups = (List<Document>) found.get("activities-summary", Document.class).get("works", Document.class).get("group");
    List<Document> sums = (List<Document>) groups.get(0).get("work-summary");
    assertEquals(sums.get(0).get("title", Document.class).get("title", Document.class).get("value"), "blah");
    record.setPerson(new Person());
    record.getPerson().setName(new Name());
    record.getPerson().getName().setCreditName(new CreditName());
    record.getPerson().getName().getCreditName().setContent("name");
    ;
    LastModifiedMessage m2 = new LastModifiedMessage(this.orcid, new Date());
    mongo.accept(m2);
    it = col.find(d);
    found = it.first();
    assertEquals(found.get("person", Document.class).get("name", Document.class).get("credit-name", Document.class).get("value"), "name");
}
Also used : LastModifiedMessage(org.orcid.utils.listener.LastModifiedMessage) CreditName(org.orcid.jaxb.model.record_v2.CreditName) WorkTitle(org.orcid.jaxb.model.record_v2.WorkTitle) Title(org.orcid.jaxb.model.common_v2.Title) Document(org.bson.Document) Date(java.util.Date) DeactivationDate(org.orcid.jaxb.model.record_v2.DeactivationDate) ActivitiesSummary(org.orcid.jaxb.model.record.summary_v2.ActivitiesSummary) CreditName(org.orcid.jaxb.model.record_v2.CreditName) Name(org.orcid.jaxb.model.record_v2.Name) WorkGroup(org.orcid.jaxb.model.record.summary_v2.WorkGroup) WorkSummary(org.orcid.jaxb.model.record.summary_v2.WorkSummary) WorkTitle(org.orcid.jaxb.model.record_v2.WorkTitle) OrcidIdentifier(org.orcid.jaxb.model.common_v2.OrcidIdentifier) Record(org.orcid.jaxb.model.record_v2.Record) List(java.util.List) Works(org.orcid.jaxb.model.record.summary_v2.Works) Person(org.orcid.jaxb.model.record_v2.Person) Test(org.junit.Test)

Aggregations

Title (org.orcid.jaxb.model.common_v2.Title)47 WorkTitle (org.orcid.jaxb.model.record_v2.WorkTitle)41 Test (org.junit.Test)31 ExternalID (org.orcid.jaxb.model.record_v2.ExternalID)28 ExternalIDs (org.orcid.jaxb.model.record_v2.ExternalIDs)24 Work (org.orcid.jaxb.model.record_v2.Work)24 Url (org.orcid.jaxb.model.common_v2.Url)23 FundingTitle (org.orcid.jaxb.model.record_v2.FundingTitle)23 ClientResponse (com.sun.jersey.api.client.ClientResponse)20 TranslatedTitle (org.orcid.jaxb.model.common_v2.TranslatedTitle)14 Funding (org.orcid.jaxb.model.record_v2.Funding)11 ArrayList (java.util.ArrayList)8 List (java.util.List)8 WorkSummary (org.orcid.jaxb.model.record.summary_v2.WorkSummary)8 Visibility (org.orcid.jaxb.model.common_rc1.Visibility)7 Map (java.util.Map)6 Url (org.orcid.jaxb.model.common_rc1.Url)6 WorkExternalIdentifier (org.orcid.jaxb.model.record_rc1.WorkExternalIdentifier)6 WorkExternalIdentifierId (org.orcid.jaxb.model.record_rc1.WorkExternalIdentifierId)6 WorkBulk (org.orcid.jaxb.model.record_v2.WorkBulk)6