Search in sources :

Example 71 with Person

use of test1.Person in project ORCID-Source by ORCID.

the class ValidateV2RC3Identifiers 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_rc3/samples/person-2.0_rc3.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_rc3.PersonExternalIdentifier) Person(org.orcid.jaxb.model.record_rc3.Person) Url(org.orcid.jaxb.model.common_rc3.Url) Validator(javax.xml.validation.Validator) MarshallingTest(org.orcid.jaxb.model.notification.custom.MarshallingTest) Test(org.junit.Test)

Example 72 with Person

use of test1.Person in project ORCID-Source by ORCID.

the class OpenIDConnectTokenEnhancer method enhance.

@Override
public OAuth2AccessToken enhance(OAuth2AccessToken accessToken, OAuth2Authentication authentication) {
    // We check for a nonce and max_age which are added back into request by
    // OrcidClientCredentialEndPointDelegatorImpl
    Map<String, String> params = authentication.getOAuth2Request().getRequestParameters();
    // only add if we're using openid scope.
    // only add in implicit flow if response_type id_token is present
    String scopes = params.get(OrcidOauth2Constants.SCOPE_PARAM);
    if (PojoUtil.isEmpty(scopes) || !ScopePathType.getScopesFromSpaceSeparatedString(scopes).contains(ScopePathType.OPENID)) {
        return accessToken;
    }
    // purposes. Some APIs support it, but it is not part of the spec.
    try {
        String orcid = authentication.getName();
        Builder claims = new JWTClaimsSet.Builder();
        claims.audience(params.get(OrcidOauth2Constants.CLIENT_ID_PARAM));
        claims.issuer("https://orcid.org");
        claims.subject("https://orcid.org" + "/" + orcid);
        claims.claim("id_path", orcid);
        claims.claim("at_hash", createAccessTokenHash(accessToken.getValue()));
        Date now = new Date();
        claims.expirationTime(new Date(now.getTime() + 600000));
        claims.issueTime(now);
        claims.jwtID(UUID.randomUUID().toString());
        if (params.get(OrcidOauth2Constants.NONCE) != null)
            claims.claim(OrcidOauth2Constants.NONCE, params.get(OrcidOauth2Constants.NONCE));
        claims.claim(OrcidOauth2Constants.AUTH_TIME, profileEntityManager.getLastLogin(orcid));
        Person person = personDetailsManagerReadOnly.getPublicPersonDetails(orcid);
        if (person.getName() != null) {
            if (person.getName().getCreditName() != null) {
                claims.claim("name", person.getName().getCreditName().getContent());
            }
            if (person.getName().getFamilyName() != null) {
                claims.claim("family_name", person.getName().getFamilyName().getContent());
            }
            if (person.getName().getGivenNames() != null) {
                claims.claim("given_name", person.getName().getGivenNames().getContent());
            }
        }
        SignedJWT signedJWT = keyManager.sign(claims.build());
        String idTok = signedJWT.serialize();
        accessToken.getAdditionalInformation().put(OrcidOauth2Constants.ID_TOKEN, idTok);
    } catch (JOSEException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return accessToken;
}
Also used : Builder(com.nimbusds.jwt.JWTClaimsSet.Builder) SignedJWT(com.nimbusds.jwt.SignedJWT) Person(org.orcid.jaxb.model.record_v2.Person) JOSEException(com.nimbusds.jose.JOSEException) Date(java.util.Date) JOSEException(com.nimbusds.jose.JOSEException)

Example 73 with Person

use of test1.Person in project ORCID-Source by ORCID.

the class RDFWriterTest method fakeBio.

private Record fakeBio() throws DatatypeConfigurationException {
    Record r = new Record();
    r.setOrcidIdentifier(new OrcidIdentifier());
    r.getOrcidIdentifier().setPath("000-1337");
    r.getOrcidIdentifier().setUri("http://orcid.example.com/000-1337");
    r.setHistory(new History());
    r.getHistory().setCreationMethod(CreationMethod.WEBSITE);
    XMLGregorianCalendar value = dataTypeFactory.newXMLGregorianCalendar(1980, 12, 31, 23, 29, 29, 999, 0);
    r.getHistory().setLastModifiedDate(new LastModifiedDate(value));
    r.getHistory().setClaimed(true);
    r.setPerson(new Person());
    r.getPerson().setBiography(new Biography());
    r.getPerson().setName(new Name());
    r.getPerson().getName().setFamilyName(new FamilyName("Doe"));
    r.getPerson().getName().setCreditName(new CreditName("John F Doe"));
    r.getPerson().getName().setGivenNames(new GivenNames("John"));
    r.getPerson().setOtherNames(new OtherNames());
    r.getPerson().getOtherNames().setOtherNames(new ArrayList<OtherName>());
    OtherName n = new OtherName();
    n.setContent("Johnny");
    n.setVisibility(Visibility.PUBLIC);
    OtherName n1 = new OtherName();
    n1.setContent("Mr Doe");
    n1.setVisibility(Visibility.PUBLIC);
    r.getPerson().getOtherNames().getOtherNames().add(n);
    r.getPerson().getOtherNames().getOtherNames().add(n1);
    r.getPerson().setResearcherUrls(new ResearcherUrls());
    r.getPerson().getResearcherUrls().setResearcherUrls(new ArrayList<ResearcherUrl>());
    ResearcherUrl anonymous = new ResearcherUrl();
    anonymous.setUrl(new Url("http://example.com/anon"));
    anonymous.setVisibility(Visibility.PUBLIC);
    r.getPerson().getResearcherUrls().getResearcherUrls().add(anonymous);
    r.getPerson().getResearcherUrls().getResearcherUrls().add(buildRUrl("http://example.com/myPage", "homePage"));
    r.getPerson().getResearcherUrls().getResearcherUrls().add(buildRUrl("http://example.com/foaf#me", "FOAF"));
    r.getPerson().getResearcherUrls().getResearcherUrls().add(buildRUrl("http://example.com/webId", "webID"));
    r.getPerson().getResearcherUrls().getResearcherUrls().add(buildRUrl("http://example.com/other", "other"));
    r.getPerson().setAddresses(new Addresses());
    r.getPerson().getAddresses().setAddress(new ArrayList<Address>());
    Address a = new Address();
    a.setCountry(new Country());
    a.getCountry().setValue(Iso3166Country.GB);
    r.getPerson().getAddresses().getAddress().add(a);
    r.getPerson().setEmails(new Emails());
    r.getPerson().getEmails().setEmails(new ArrayList<Email>());
    Email e = new Email();
    e.setEmail("john@example.org");
    e.setCurrent(true);
    Email e1 = new Email();
    e1.setEmail("doe@example.com");
    e1.setCurrent(true);
    r.getPerson().getEmails().getEmails().add(e);
    r.getPerson().getEmails().getEmails().add(e1);
    return r;
}
Also used : LastModifiedDate(org.orcid.jaxb.model.common_v2.LastModifiedDate) Email(org.orcid.jaxb.model.record_v2.Email) Address(org.orcid.jaxb.model.record_v2.Address) FamilyName(org.orcid.jaxb.model.record_v2.FamilyName) OtherNames(org.orcid.jaxb.model.record_v2.OtherNames) History(org.orcid.jaxb.model.record_v2.History) Url(org.orcid.jaxb.model.common_v2.Url) ResearcherUrl(org.orcid.jaxb.model.record_v2.ResearcherUrl) FamilyName(org.orcid.jaxb.model.record_v2.FamilyName) CreditName(org.orcid.jaxb.model.common_v2.CreditName) OtherName(org.orcid.jaxb.model.record_v2.OtherName) Name(org.orcid.jaxb.model.record_v2.Name) Addresses(org.orcid.jaxb.model.record_v2.Addresses) OrcidIdentifier(org.orcid.jaxb.model.common_v2.OrcidIdentifier) GivenNames(org.orcid.jaxb.model.record_v2.GivenNames) Biography(org.orcid.jaxb.model.record_v2.Biography) ResearcherUrls(org.orcid.jaxb.model.record_v2.ResearcherUrls) Record(org.orcid.jaxb.model.record_v2.Record) ResearcherUrl(org.orcid.jaxb.model.record_v2.ResearcherUrl) Emails(org.orcid.jaxb.model.record_v2.Emails) CreditName(org.orcid.jaxb.model.common_v2.CreditName) OtherName(org.orcid.jaxb.model.record_v2.OtherName) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) Country(org.orcid.jaxb.model.common_v2.Country) Iso3166Country(org.orcid.jaxb.model.common_v2.Iso3166Country) Person(org.orcid.jaxb.model.record_v2.Person)

Example 74 with Person

use of test1.Person in project webofneeds by researchstudio-sat.

the class GeneratedSourcesTests method test1Generated_rdfgen002.

@Test
public void test1Generated_rdfgen002() throws IOException {
    Shapes shapes = loadShapes(testBaseFolder.createRelative("test1/shapes.ttl"));
    Person bob = new Person("http://example.com/ns#Bob");
    bob.setNode(NodeFactory.createURI("http://example.com/ns#Bob"));
    bob.addFirstName("Bob");
    bob.setLastName("The Builder");
    Address address = new Address();
    address.setPostalCode("1234");
    bob.addAddress(address);
    Graph graph = test1.RdfOutput.toGraph(bob);
    Model expected = loadData(new ClassPathResource("won/shacl2java/test1/expected-rdfgen002.ttl"));
    Assert.assertTrue("generated graph differs from expected", graph.isIsomorphicWith(expected.getGraph()));
}
Also used : Graph(org.apache.jena.graph.Graph) Address(test1.Address) Model(org.apache.jena.rdf.model.Model) Shapes(org.apache.jena.shacl.Shapes) Person(test1.Person) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)66 Person (org.orcid.jaxb.model.record_v2.Person)60 Email (org.orcid.jaxb.model.record_v2.Email)36 OtherName (org.orcid.jaxb.model.record_v2.OtherName)32 PersonExternalIdentifier (org.orcid.jaxb.model.record_v2.PersonExternalIdentifier)32 Address (org.orcid.jaxb.model.record_v2.Address)31 Emails (org.orcid.jaxb.model.record_v2.Emails)31 ResearcherUrl (org.orcid.jaxb.model.record_v2.ResearcherUrl)31 Keyword (org.orcid.jaxb.model.record_v2.Keyword)30 Name (org.orcid.jaxb.model.record_v2.Name)28 Addresses (org.orcid.jaxb.model.record_v2.Addresses)26 Biography (org.orcid.jaxb.model.record_v2.Biography)26 OtherNames (org.orcid.jaxb.model.record_v2.OtherNames)26 ResearcherUrls (org.orcid.jaxb.model.record_v2.ResearcherUrls)26 Keywords (org.orcid.jaxb.model.record_v2.Keywords)25 PersonExternalIdentifiers (org.orcid.jaxb.model.record_v2.PersonExternalIdentifiers)25 Record (org.orcid.jaxb.model.record_v2.Record)22 ActivitiesSummary (org.orcid.jaxb.model.record.summary_v2.ActivitiesSummary)20 WorkSummary (org.orcid.jaxb.model.record.summary_v2.WorkSummary)15 EducationSummary (org.orcid.jaxb.model.record.summary_v2.EducationSummary)14