Search in sources :

Example 86 with Url

use of org.orcid.jaxb.model.common_rc2.Url in project ORCID-Source by ORCID.

the class MemberV2Test method testTokenWorksOnlyForTheScopeItWasIssued.

@SuppressWarnings({ "deprecation", "rawtypes" })
@Test
public void testTokenWorksOnlyForTheScopeItWasIssued() throws JSONException, InterruptedException, URISyntaxException {
    long time = System.currentTimeMillis();
    List<String> scopes = getScopes(ScopePathType.FUNDING_CREATE, ScopePathType.FUNDING_UPDATE);
    String accessToken = getAccessToken(scopes);
    Work work1 = (Work) unmarshallFromPath("/record_2.0_rc2/samples/work-2.0_rc2.xml", Work.class);
    work1.setPutCode(null);
    work1.getExternalIdentifiers().getExternalIdentifier().clear();
    org.orcid.jaxb.model.record_rc2.WorkTitle title1 = new org.orcid.jaxb.model.record_rc2.WorkTitle();
    title1.setTitle(new Title("Work # 1"));
    work1.setWorkTitle(title1);
    ExternalID wExtId1 = new ExternalID();
    wExtId1.setValue("Work Id " + time);
    wExtId1.setType(WorkExternalIdentifierType.AGR.value());
    wExtId1.setRelationship(Relationship.SELF);
    wExtId1.setUrl(new Url("http://orcid.org/work#1"));
    work1.getExternalIdentifiers().getExternalIdentifier().clear();
    work1.getExternalIdentifiers().getExternalIdentifier().add(wExtId1);
    //Add the work
    ClientResponse postResponse = memberV2ApiClient.createWorkXml(this.getUser1OrcidId(), work1, accessToken);
    assertNotNull(postResponse);
    assertEquals(Response.Status.FORBIDDEN.getStatusCode(), postResponse.getStatus());
    Funding funding = (Funding) unmarshallFromPath("/record_2.0_rc2/samples/funding-2.0_rc2.xml", Funding.class);
    funding.setPutCode(null);
    funding.setVisibility(Visibility.PUBLIC);
    funding.getExternalIdentifiers().getExternalIdentifier().clear();
    ExternalID fExtId = new ExternalID();
    fExtId.setType(FundingExternalIdentifierType.GRANT_NUMBER.value());
    fExtId.setValue("Funding Id " + time);
    fExtId.setRelationship(Relationship.SELF);
    funding.getExternalIdentifiers().getExternalIdentifier().add(fExtId);
    //Add the funding
    postResponse = memberV2ApiClient.createFundingXml(this.getUser1OrcidId(), funding, accessToken);
    assertNotNull(postResponse);
    assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
    // Delete funding        
    Map map = postResponse.getMetadata();
    assertNotNull(map);
    assertTrue(map.containsKey("Location"));
    List resultWithPutCode = (List) map.get("Location");
    String location = resultWithPutCode.get(0).toString();
    Long putCode = Long.valueOf(location.substring(location.lastIndexOf('/') + 1));
    ClientResponse deleteResponse = memberV2ApiClient.deleteFundingXml(this.getUser1OrcidId(), putCode, accessToken);
    assertNotNull(deleteResponse);
    assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deleteResponse.getStatus());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) Funding(org.orcid.jaxb.model.record_rc2.Funding) ExternalID(org.orcid.jaxb.model.record_rc2.ExternalID) Title(org.orcid.jaxb.model.common_rc2.Title) Url(org.orcid.jaxb.model.common_rc2.Url) Work(org.orcid.jaxb.model.record_rc2.Work) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) Test(org.junit.Test)

Example 87 with Url

use of org.orcid.jaxb.model.common_rc2.Url in project ORCID-Source by ORCID.

the class ValidateV2IdentifiersTest method testActivities.

@Test
public void testActivities() {
    ActivitiesSummary as = unmarshallFromPath("/record_2.0/samples/read_samples/activities-2.0.xml", ActivitiesSummary.class);
    ExternalIDs fundingIDs = as.getFundings().getFundingGroup().get(0).getFundingSummary().get(0).getExternalIdentifiers();
    ExternalIDs fundingIDs2 = as.getFundings().getFundingGroup().get(0).getIdentifiers();
    assertEquals("grant_number", fundingIDs.getExternalIdentifier().get(0).getType());
    assertEquals("external-id-value", fundingIDs.getExternalIdentifier().get(0).getValue());
    assertEquals(new Url("http://tempuri.org"), fundingIDs.getExternalIdentifier().get(0).getUrl());
    assertEquals(Relationship.SELF, fundingIDs.getExternalIdentifier().get(0).getRelationship());
    assertEquals(fundingIDs.getExternalIdentifier().get(0).getType(), fundingIDs2.getExternalIdentifier().get(0).getType());
    assertEquals(fundingIDs.getExternalIdentifier().get(0).getValue(), fundingIDs2.getExternalIdentifier().get(0).getValue());
    ExternalIDs peerIDs = as.getPeerReviews().getPeerReviewGroup().get(0).getPeerReviewSummary().get(0).getExternalIdentifiers();
    ExternalIDs peerIDs2 = as.getPeerReviews().getPeerReviewGroup().get(0).getIdentifiers();
    assertEquals("something", peerIDs.getExternalIdentifier().get(0).getType());
    assertEquals("external-id-value", peerIDs.getExternalIdentifier().get(0).getValue());
    assertEquals(new Url("http://orcid.org"), peerIDs.getExternalIdentifier().get(0).getUrl());
    assertEquals(Relationship.SELF, peerIDs.getExternalIdentifier().get(0).getRelationship());
    assertEquals(peerIDs.getExternalIdentifier().get(0).getType(), peerIDs2.getExternalIdentifier().get(0).getType());
    assertEquals(peerIDs.getExternalIdentifier().get(0).getValue(), peerIDs2.getExternalIdentifier().get(0).getValue());
    ExternalIDs workIDs = as.getWorks().getWorkGroup().get(0).getWorkSummary().get(0).getExternalIdentifiers();
    ExternalIDs workIDs2 = as.getWorks().getWorkGroup().get(0).getIdentifiers();
    assertEquals("agr", workIDs.getExternalIdentifier().get(0).getType());
    assertEquals("external-id-value", workIDs.getExternalIdentifier().get(0).getValue());
    assertEquals(new Url("http://orcid.org"), workIDs.getExternalIdentifier().get(0).getUrl());
    assertEquals(Relationship.SELF, workIDs.getExternalIdentifier().get(0).getRelationship());
    assertEquals(workIDs.getExternalIdentifier().get(0).getType(), workIDs2.getExternalIdentifier().get(0).getType());
    assertEquals(workIDs.getExternalIdentifier().get(0).getValue(), workIDs2.getExternalIdentifier().get(0).getValue());
}
Also used : ExternalIDs(org.orcid.jaxb.model.record_v2.ExternalIDs) Url(org.orcid.jaxb.model.common_v2.Url) ActivitiesSummary(org.orcid.jaxb.model.record.summary_v2.ActivitiesSummary) MarshallingTest(org.orcid.jaxb.model.notification.custom.MarshallingTest) Test(org.junit.Test)

Example 88 with Url

use of org.orcid.jaxb.model.common_rc2.Url in project ORCID-Source by ORCID.

the class ValidateV2IdentifiersTest method testPerson.

/**
     * <external-identifier:external-identifiers>
                <external-identifier:external-identifier visibility="public" put-code="1">
                        <common:external-id-type>type-1</common:external-id-type>
                        <common:external-id-value>value-1</common:external-id-value>
                        <common:external-id-url>http://url.com/1</common:external-id-url>
                        <common:created-date>2001-12-31T12:00:00</common:created-date>
                        <common:last-modified-date>2001-12-31T12:00:00</common:last-modified-date>
                        <common:source>
                                <common:source-orcid>
                                        <common:uri>http://orcid.org/8888-8888-8888-8880</common:uri>
                                        <common:path>8888-8888-8888-8880</common:path>
                                        <common:host>orcid.org</common:host>
                                </common:source-orcid>
                                <common:source-name />
                        </common:source>
                </external-identifier:external-identifier>
        </external-identifier:external-identifiers>
        
     * @throws SAXException
     * @throws IOException
     * @throws JAXBException
     * @throws ParserConfigurationException
     */
@Test
public void testPerson() throws SAXException, IOException, JAXBException, ParserConfigurationException {
    Person person = unmarshallFromPath("/record_2.0/samples/read_samples/person-2.0.xml", Person.class);
    assertEquals("credit-name", person.getName().getCreditName().getContent());
    assertEquals(1, person.getExternalIdentifiers().getExternalIdentifiers().size());
    PersonExternalIdentifier id = person.getExternalIdentifiers().getExternalIdentifiers().get(0);
    assertEquals("type-1", id.getType());
    assertEquals("value-1", id.getValue());
    assertEquals(new Url("http://url.com/1"), id.getUrl());
    assertNull(id.getRelationship());
    assertNotNull(id.getCreatedDate().getValue());
    assertNotNull(id.getLastModifiedDate().getValue());
    assertEquals(new Long(1), id.getPutCode());
    assertEquals(Visibility.PUBLIC, id.getVisibility());
    Validator validator = getValidator("person");
    validator.validate(marshall(Person.class, person));
    validator.validate(marshallToDOM(Person.class, person));
}
Also used : PersonExternalIdentifier(org.orcid.jaxb.model.record_v2.PersonExternalIdentifier) Person(org.orcid.jaxb.model.record_v2.Person) Url(org.orcid.jaxb.model.common_v2.Url) Validator(javax.xml.validation.Validator) MarshallingTest(org.orcid.jaxb.model.notification.custom.MarshallingTest) Test(org.junit.Test)

Example 89 with Url

use of org.orcid.jaxb.model.common_rc2.Url in project ORCID-Source by ORCID.

the class ValidateV2IdentifiersTest method testRecord.

@Test
public void testRecord() {
    Record record = unmarshallFromPath("/record_2.0/samples/read_samples/record-2.0.xml", Record.class);
    ActivitiesSummary as = record.getActivitiesSummary();
    ExternalIDs fundingIDs = as.getFundings().getFundingGroup().get(0).getFundingSummary().get(0).getExternalIdentifiers();
    ExternalIDs fundingIDs2 = as.getFundings().getFundingGroup().get(0).getIdentifiers();
    assertEquals("grant_number", fundingIDs.getExternalIdentifier().get(0).getType());
    assertEquals("external-id-value", fundingIDs.getExternalIdentifier().get(0).getValue());
    assertEquals(new Url("http://tempuri.org"), fundingIDs.getExternalIdentifier().get(0).getUrl());
    assertEquals(Relationship.SELF, fundingIDs.getExternalIdentifier().get(0).getRelationship());
    assertEquals(fundingIDs.getExternalIdentifier().get(0).getType(), fundingIDs2.getExternalIdentifier().get(0).getType());
    assertEquals(fundingIDs.getExternalIdentifier().get(0).getValue(), fundingIDs2.getExternalIdentifier().get(0).getValue());
    ExternalIDs workIDs = as.getWorks().getWorkGroup().get(0).getWorkSummary().get(0).getExternalIdentifiers();
    ExternalIDs workIDs2 = as.getWorks().getWorkGroup().get(0).getIdentifiers();
    assertEquals("agr", workIDs.getExternalIdentifier().get(0).getType());
    assertEquals("external-id-value", workIDs.getExternalIdentifier().get(0).getValue());
    assertEquals(new Url("http://tempuri.org"), workIDs.getExternalIdentifier().get(0).getUrl());
    assertEquals(Relationship.SELF, workIDs.getExternalIdentifier().get(0).getRelationship());
    assertEquals(workIDs.getExternalIdentifier().get(0).getType(), workIDs2.getExternalIdentifier().get(0).getType());
    assertEquals(workIDs.getExternalIdentifier().get(0).getValue(), workIDs2.getExternalIdentifier().get(0).getValue());
}
Also used : ExternalIDs(org.orcid.jaxb.model.record_v2.ExternalIDs) Record(org.orcid.jaxb.model.record_v2.Record) Url(org.orcid.jaxb.model.common_v2.Url) ActivitiesSummary(org.orcid.jaxb.model.record.summary_v2.ActivitiesSummary) MarshallingTest(org.orcid.jaxb.model.notification.custom.MarshallingTest) Test(org.junit.Test)

Example 90 with Url

use of org.orcid.jaxb.model.common_rc2.Url in project ORCID-Source by ORCID.

the class MemberV2ApiServiceDelegator_ExternalIdentifiersTest method testUpdateExaternalIdentifierYouAreNotTheSourceOf.

@Test(expected = WrongSourceException.class)
public void testUpdateExaternalIdentifierYouAreNotTheSourceOf() {
    SecurityContextTestUtils.setUpSecurityContext("4444-4444-4444-4442", ScopePathType.PERSON_READ_LIMITED, ScopePathType.PERSON_UPDATE);
    Response response = serviceDelegator.viewExternalIdentifier("4444-4444-4444-4442", 3L);
    assertNotNull(response);
    PersonExternalIdentifier extId = (PersonExternalIdentifier) response.getEntity();
    assertNotNull(extId);
    assertEquals("Facebook", extId.getType());
    assertEquals("abc456", extId.getValue());
    assertNotNull(extId.getUrl());
    assertEquals("http://www.facebook.com/abc456", extId.getUrl().getValue());
    extId.setType("other-common-name");
    extId.setValue("other-reference");
    extId.setUrl(new Url("http://otherUrl.com"));
    serviceDelegator.updateExternalIdentifier("4444-4444-4444-4442", 3L, extId);
    fail();
}
Also used : Response(javax.ws.rs.core.Response) PersonExternalIdentifier(org.orcid.jaxb.model.record_v2.PersonExternalIdentifier) Url(org.orcid.jaxb.model.common_v2.Url) ResearcherUrl(org.orcid.jaxb.model.record_v2.ResearcherUrl) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Aggregations

Url (org.orcid.jaxb.model.common_v2.Url)86 Test (org.junit.Test)84 ExternalID (org.orcid.jaxb.model.record_v2.ExternalID)55 ExternalIDs (org.orcid.jaxb.model.record_v2.ExternalIDs)37 ClientResponse (com.sun.jersey.api.client.ClientResponse)30 MarshallingTest (org.orcid.jaxb.model.notification.custom.MarshallingTest)24 Title (org.orcid.jaxb.model.common_v2.Title)23 Work (org.orcid.jaxb.model.record_v2.Work)21 ResearcherUrl (org.orcid.jaxb.model.record_v2.ResearcherUrl)20 WorkTitle (org.orcid.jaxb.model.record_v2.WorkTitle)18 Validator (javax.xml.validation.Validator)16 Funding (org.orcid.jaxb.model.record_v2.Funding)15 ArrayList (java.util.ArrayList)14 Url (org.orcid.jaxb.model.common_rc3.Url)11 Url (org.orcid.jaxb.model.common_rc4.Url)11 PersonExternalIdentifier (org.orcid.jaxb.model.record_v2.PersonExternalIdentifier)11 Response (javax.ws.rs.core.Response)10 FundingTitle (org.orcid.jaxb.model.record_v2.FundingTitle)10 DBUnitTest (org.orcid.test.DBUnitTest)10 PeerReview (org.orcid.jaxb.model.record_v2.PeerReview)9