Search in sources :

Example 6 with Year

use of org.orcid.jaxb.model.common_rc4.Year in project ORCID-Source by ORCID.

the class MapperFacadeFactory method mapFuzzyDateToStartDateEntityAndEndDateEntity.

private void mapFuzzyDateToStartDateEntityAndEndDateEntity(MapperFactory mapperFactory) {
    mapperFactory.classMap(FuzzyDate.class, StartDateEntity.class).customize(new CustomMapper<FuzzyDate, StartDateEntity>() {

        @Override
        public void mapAtoB(FuzzyDate fuzzyDate, StartDateEntity entity, MappingContext context) {
            if (fuzzyDate.getYear() != null) {
                entity.setYear(Integer.valueOf(fuzzyDate.getYear().getValue()));
            } else {
                entity.setYear(null);
            }
            if (fuzzyDate.getMonth() != null) {
                entity.setMonth(Integer.valueOf(fuzzyDate.getMonth().getValue()));
            } else {
                entity.setMonth(null);
            }
            if (fuzzyDate.getDay() != null) {
                entity.setDay(Integer.valueOf(fuzzyDate.getDay().getValue()));
            } else {
                entity.setDay(null);
            }
        }

        @Override
        public void mapBtoA(StartDateEntity entity, FuzzyDate fuzzyDate, MappingContext context) {
            if (entity.getYear() != null) {
                fuzzyDate.setYear(new Year(entity.getYear()));
            } else {
                fuzzyDate.setYear(null);
            }
            if (entity.getMonth() != null) {
                fuzzyDate.setMonth(new Month(entity.getMonth()));
            } else {
                fuzzyDate.setMonth(null);
            }
            if (entity.getDay() != null) {
                fuzzyDate.setDay(new Day(entity.getDay()));
            } else {
                fuzzyDate.setDay(null);
            }
        }
    }).register();
    mapperFactory.classMap(FuzzyDate.class, EndDateEntity.class).customize(new CustomMapper<FuzzyDate, EndDateEntity>() {

        @Override
        public void mapAtoB(FuzzyDate fuzzyDate, EndDateEntity entity, MappingContext context) {
            if (fuzzyDate.getYear() != null) {
                entity.setYear(Integer.valueOf(fuzzyDate.getYear().getValue()));
            } else {
                entity.setYear(null);
            }
            if (fuzzyDate.getMonth() != null) {
                entity.setMonth(Integer.valueOf(fuzzyDate.getMonth().getValue()));
            } else {
                entity.setMonth(null);
            }
            if (fuzzyDate.getDay() != null) {
                entity.setDay(Integer.valueOf(fuzzyDate.getDay().getValue()));
            } else {
                entity.setDay(null);
            }
        }

        @Override
        public void mapBtoA(EndDateEntity entity, FuzzyDate fuzzyDate, MappingContext context) {
            if (entity.getYear() != null) {
                fuzzyDate.setYear(new Year(entity.getYear()));
            } else {
                fuzzyDate.setYear(null);
            }
            if (entity.getMonth() != null) {
                fuzzyDate.setMonth(new Month(entity.getMonth()));
            } else {
                fuzzyDate.setMonth(null);
            }
            if (entity.getDay() != null) {
                fuzzyDate.setDay(new Day(entity.getDay()));
            } else {
                fuzzyDate.setDay(null);
            }
        }
    }).register();
}
Also used : MappingContext(ma.glasnost.orika.MappingContext) EndDateEntity(org.orcid.persistence.jpa.entities.EndDateEntity) Month(org.orcid.jaxb.model.common_v2.Month) Year(org.orcid.jaxb.model.common_v2.Year) StartDateEntity(org.orcid.persistence.jpa.entities.StartDateEntity) FuzzyDate(org.orcid.jaxb.model.common_v2.FuzzyDate) CustomMapper(ma.glasnost.orika.CustomMapper) Day(org.orcid.jaxb.model.common_v2.Day)

Example 7 with Year

use of org.orcid.jaxb.model.common_rc4.Year in project ORCID-Source by ORCID.

the class PublicV2Test method createActivities.

private void createActivities() throws JSONException, InterruptedException, URISyntaxException {
    String accessToken = getAccessToken();
    long time = System.currentTimeMillis();
    Work workToCreate = (Work) unmarshallFromPath("/record_2.0_rc1/samples/work-2.0_rc1.xml", Work.class);
    for (int i = 0; i < 4; i++) {
        workToCreate.setPutCode(null);
        workToCreate.getWorkTitle().getTitle().setContent("Work # " + i);
        workToCreate.getExternalIdentifiers().getExternalIdentifier().clear();
        WorkExternalIdentifier wExtId = new WorkExternalIdentifier();
        wExtId.setWorkExternalIdentifierId(new WorkExternalIdentifierId(time + " Work Id " + i));
        wExtId.setWorkExternalIdentifierType(WorkExternalIdentifierType.AGR);
        wExtId.setRelationship(Relationship.SELF);
        workToCreate.getExternalIdentifiers().getExternalIdentifier().add(wExtId);
        if (i == 0 || i == 3)
            workToCreate.setVisibility(org.orcid.jaxb.model.common_rc1.Visibility.PUBLIC);
        else if (i == 1)
            workToCreate.setVisibility(org.orcid.jaxb.model.common_rc1.Visibility.LIMITED);
        else
            workToCreate.setVisibility(org.orcid.jaxb.model.common_rc1.Visibility.PRIVATE);
        ClientResponse postResponse = memberV2ApiClient.createWorkXml(getUser1OrcidId(), workToCreate, accessToken);
        assertNotNull(postResponse);
        assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
    }
    Funding fundingToCreate = (Funding) unmarshallFromPath("/record_2.0_rc1/samples/funding-2.0_rc1.xml", Funding.class);
    for (int i = 0; i < 4; i++) {
        fundingToCreate.setPutCode(null);
        fundingToCreate.getTitle().getTitle().setContent("Funding # " + i);
        fundingToCreate.getExternalIdentifiers().getExternalIdentifier().clear();
        FundingExternalIdentifier fExtId = new FundingExternalIdentifier();
        fExtId.setType(FundingExternalIdentifierType.GRANT_NUMBER);
        fExtId.setValue(time + " funding Id " + i);
        fExtId.setRelationship(Relationship.SELF);
        fundingToCreate.getExternalIdentifiers().getExternalIdentifier().add(fExtId);
        if (i == 0 || i == 3)
            fundingToCreate.setVisibility(org.orcid.jaxb.model.common_rc1.Visibility.PUBLIC);
        else if (i == 1)
            fundingToCreate.setVisibility(org.orcid.jaxb.model.common_rc1.Visibility.LIMITED);
        else
            fundingToCreate.setVisibility(org.orcid.jaxb.model.common_rc1.Visibility.PRIVATE);
        ClientResponse postResponse = memberV2ApiClient.createFundingXml(getUser1OrcidId(), fundingToCreate, accessToken);
        assertNotNull(postResponse);
        assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
    }
    Employment employmentToCreate = (Employment) unmarshallFromPath("/record_2.0_rc1/samples/employment-2.0_rc1.xml", Employment.class);
    for (int i = 0; i < 4; i++) {
        employmentToCreate.setPutCode(null);
        employmentToCreate.setRoleTitle("Employment # " + i);
        if (i == 0 || i == 3)
            employmentToCreate.setVisibility(org.orcid.jaxb.model.common_rc1.Visibility.PUBLIC);
        else if (i == 1)
            employmentToCreate.setVisibility(org.orcid.jaxb.model.common_rc1.Visibility.LIMITED);
        else
            employmentToCreate.setVisibility(org.orcid.jaxb.model.common_rc1.Visibility.PRIVATE);
        ClientResponse postResponse = memberV2ApiClient.createEmploymentXml(getUser1OrcidId(), employmentToCreate, accessToken);
        assertNotNull(postResponse);
        assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
    }
    Education educationToCreate = (Education) unmarshallFromPath("/record_2.0_rc1/samples/education-2.0_rc1.xml", Education.class);
    for (int i = 0; i < 4; i++) {
        educationToCreate.setPutCode(null);
        educationToCreate.setRoleTitle("Education # " + i);
        if (i == 0 || i == 3)
            educationToCreate.setVisibility(org.orcid.jaxb.model.common_rc1.Visibility.PUBLIC);
        else if (i == 1)
            educationToCreate.setVisibility(org.orcid.jaxb.model.common_rc1.Visibility.LIMITED);
        else
            educationToCreate.setVisibility(org.orcid.jaxb.model.common_rc1.Visibility.PRIVATE);
        ClientResponse postResponse = memberV2ApiClient.createEducationXml(getUser1OrcidId(), educationToCreate, accessToken);
        assertNotNull(postResponse);
        assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
    }
    PeerReview peerReviewToCreate = (PeerReview) unmarshallFromPath("/record_2.0_rc1/samples/peer-review-2.0_rc1.xml", PeerReview.class);
    for (int i = 0; i < 4; i++) {
        peerReviewToCreate.setPutCode(null);
        peerReviewToCreate.setGroupId(groupRecords.get(0).getGroupId());
        peerReviewToCreate.getSubjectName().getTitle().setContent("PeerReview # " + i);
        peerReviewToCreate.getCompletionDate().setDay(new Day(i + 1));
        peerReviewToCreate.getCompletionDate().setMonth(new Month(i + 1));
        peerReviewToCreate.getCompletionDate().setYear(new Year((i + 1) * 1000));
        peerReviewToCreate.getExternalIdentifiers().getExternalIdentifier().get(0).getWorkExternalIdentifierId().setContent("extId-" + (i + 1));
        if (i == 0 || i == 3) {
            peerReviewToCreate.setVisibility(org.orcid.jaxb.model.common_rc1.Visibility.PUBLIC);
        } else if (i == 1) {
            peerReviewToCreate.setVisibility(org.orcid.jaxb.model.common_rc1.Visibility.LIMITED);
        } else {
            peerReviewToCreate.setVisibility(org.orcid.jaxb.model.common_rc1.Visibility.PRIVATE);
        }
        ClientResponse postResponse = memberV2ApiClient.createPeerReviewXml(getUser1OrcidId(), peerReviewToCreate, accessToken);
        assertNotNull(postResponse);
        assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) Funding(org.orcid.jaxb.model.record_rc1.Funding) WorkExternalIdentifierId(org.orcid.jaxb.model.record_rc1.WorkExternalIdentifierId) FundingExternalIdentifier(org.orcid.jaxb.model.record_rc1.FundingExternalIdentifier) Month(org.orcid.jaxb.model.common_rc1.Month) Year(org.orcid.jaxb.model.common_rc1.Year) Employment(org.orcid.jaxb.model.record_rc1.Employment) Education(org.orcid.jaxb.model.record_rc1.Education) Work(org.orcid.jaxb.model.record_rc1.Work) WorkExternalIdentifier(org.orcid.jaxb.model.record_rc1.WorkExternalIdentifier) Day(org.orcid.jaxb.model.common_rc1.Day) PeerReview(org.orcid.jaxb.model.record_rc1.PeerReview)

Example 8 with Year

use of org.orcid.jaxb.model.common_rc4.Year in project ORCID-Source by ORCID.

the class PublicProfileVisibilityTest method peerReviewPrivacyTest.

@Test
public void peerReviewPrivacyTest() throws InterruptedException, JSONException, URISyntaxException {
    // Create peer review group
    String accessToken = getAccessToken(getScopes(ScopePathType.PERSON_READ_LIMITED, ScopePathType.PERSON_UPDATE, ScopePathType.ACTIVITIES_READ_LIMITED, ScopePathType.ACTIVITIES_UPDATE));
    List<GroupIdRecord> groups = createGroupIds();
    assertNotNull(groups);
    assertTrue(groups.size() > 0);
    GroupIdRecord g1 = groups.get(0);
    // Create peer review
    long time = System.currentTimeMillis();
    PeerReview peerReview = new PeerReview();
    peerReview.setGroupId(g1.getGroupId());
    ExternalIDs extIds = new ExternalIDs();
    peerReview.setExternalIdentifiers(extIds);
    peerReview.getExternalIdentifiers().getExternalIdentifier().clear();
    ExternalID wExtId = new ExternalID();
    wExtId.setValue("Work Id " + time);
    wExtId.setType(WorkExternalIdentifierType.AGR.value());
    wExtId.setRelationship(Relationship.SELF);
    peerReview.getExternalIdentifiers().getExternalIdentifier().add(wExtId);
    Organization organization = new Organization();
    organization.setName("My org name " + System.currentTimeMillis());
    OrganizationAddress address = new OrganizationAddress();
    address.setCity("Imagination city");
    address.setCountry(Iso3166Country.US);
    organization.setAddress(address);
    peerReview.setOrganization(organization);
    peerReview.setRole(Role.CHAIR);
    peerReview.setType(PeerReviewType.EVALUATION);
    peerReview.setCompletionDate(new FuzzyDate(new Year(2016), new Month(1), new Day(1)));
    ClientResponse postResponse = memberV2ApiClient.createPeerReviewXml(this.getUser1OrcidId(), peerReview, accessToken);
    assertNotNull(postResponse);
    assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
    ClientResponse getResponse = memberV2ApiClient.viewLocationXml(postResponse.getLocation(), accessToken);
    assertEquals(Response.Status.OK.getStatusCode(), getResponse.getStatus());
    peerReview = getResponse.getEntity(PeerReview.class);
    showMyOrcidPage();
    changePeerReviewVisibility(g1.getName(), Visibility.PRIVATE.name());
    try {
        // Verify it doesn't appear in the public page
        showPublicProfilePage(getUser1OrcidId());
        peerReviewAppearsInPublicPage(g1.getName());
        fail();
    } catch (Exception e) {
    }
    showMyOrcidPage();
    changePeerReviewVisibility(g1.getName(), Visibility.LIMITED.name());
    try {
        // Verify it doesn't appear in the public page
        showPublicProfilePage(getUser1OrcidId());
        peerReviewAppearsInPublicPage(g1.getName());
        fail();
    } catch (Exception e) {
    }
    showMyOrcidPage();
    changePeerReviewVisibility(g1.getName(), Visibility.PUBLIC.name());
    showPublicProfilePage(getUser1OrcidId());
    peerReviewAppearsInPublicPage(g1.getName());
    // Rollback
    ClientResponse deleteResponse = memberV2ApiClient.deletePeerReviewXml(this.getUser1OrcidId(), peerReview.getPutCode(), accessToken);
    assertNotNull(deleteResponse);
    assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deleteResponse.getStatus());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) ExternalIDs(org.orcid.jaxb.model.record_v2.ExternalIDs) Organization(org.orcid.jaxb.model.common_v2.Organization) GroupIdRecord(org.orcid.jaxb.model.groupid_v2.GroupIdRecord) ExternalID(org.orcid.jaxb.model.record_v2.ExternalID) OrganizationAddress(org.orcid.jaxb.model.common_v2.OrganizationAddress) FuzzyDate(org.orcid.jaxb.model.common_v2.FuzzyDate) URISyntaxException(java.net.URISyntaxException) JSONException(org.codehaus.jettison.json.JSONException) Month(org.orcid.jaxb.model.common_v2.Month) Year(org.orcid.jaxb.model.common_v2.Year) Day(org.orcid.jaxb.model.common_v2.Day) PeerReview(org.orcid.jaxb.model.record_v2.PeerReview) Test(org.junit.Test)

Example 9 with Year

use of org.orcid.jaxb.model.common_rc4.Year in project ORCID-Source by ORCID.

the class JpaJaxbEmploymentAdapterTest method getEmploymentWithDatesWithNullMonthAndDay.

private Employment getEmploymentWithDatesWithNullMonthAndDay() {
    Employment employment = new Employment();
    employment.setRoleTitle("role title");
    FuzzyDate startDate = new FuzzyDate(new Year(2017), null, null);
    FuzzyDate endDate = new FuzzyDate(new Year(2017), null, null);
    employment.setStartDate(startDate);
    employment.setEndDate(endDate);
    return employment;
}
Also used : Year(org.orcid.jaxb.model.common_v2.Year) Employment(org.orcid.jaxb.model.record_v2.Employment) FuzzyDate(org.orcid.jaxb.model.common_v2.FuzzyDate)

Example 10 with Year

use of org.orcid.jaxb.model.common_rc4.Year in project ORCID-Source by ORCID.

the class JpaJaxbEmploymentAdapterTest method getEmploymentWithDates.

private Employment getEmploymentWithDates() {
    Employment employment = new Employment();
    employment.setRoleTitle("role title");
    FuzzyDate startDate = new FuzzyDate(new Year(2017), new Month(1), new Day(1));
    FuzzyDate endDate = new FuzzyDate(new Year(2017), new Month(3), new Day(1));
    employment.setStartDate(startDate);
    employment.setEndDate(endDate);
    return employment;
}
Also used : Month(org.orcid.jaxb.model.common_v2.Month) Year(org.orcid.jaxb.model.common_v2.Year) Employment(org.orcid.jaxb.model.record_v2.Employment) FuzzyDate(org.orcid.jaxb.model.common_v2.FuzzyDate) Day(org.orcid.jaxb.model.common_v2.Day)

Aggregations

Year (org.orcid.jaxb.model.common_v2.Year)10 Day (org.orcid.jaxb.model.common_v2.Day)9 Month (org.orcid.jaxb.model.common_v2.Month)9 ClientResponse (com.sun.jersey.api.client.ClientResponse)8 Test (org.junit.Test)8 ArrayList (java.util.ArrayList)6 FuzzyDate (org.orcid.jaxb.model.common_v2.FuzzyDate)6 Employment (org.orcid.jaxb.model.record_v2.Employment)6 Education (org.orcid.jaxb.model.record_v2.Education)4 ExternalID (org.orcid.jaxb.model.record_v2.ExternalID)3 PeerReview (org.orcid.jaxb.model.record_v2.PeerReview)3 Work (org.orcid.jaxb.model.record_v2.Work)3 ActivityTypeValidationException (org.orcid.core.exception.ActivityTypeValidationException)2 OrcidValidationException (org.orcid.core.exception.OrcidValidationException)2 Day (org.orcid.jaxb.model.common_rc1.Day)2 Month (org.orcid.jaxb.model.common_rc1.Month)2 Year (org.orcid.jaxb.model.common_rc1.Year)2 Organization (org.orcid.jaxb.model.common_v2.Organization)2 OrganizationAddress (org.orcid.jaxb.model.common_v2.OrganizationAddress)2 PublicationDate (org.orcid.jaxb.model.common_v2.PublicationDate)2