Search in sources :

Example 1 with Work

use of org.orcid.jaxb.model.v3.dev1.record.Work in project ORCID-Source by ORCID.

the class MemberV3ApiServiceDelegatorImpl method createWork.

@Override
public Response createWork(String orcid, Work work) {
    orcidSecurityManager.checkClientAccessAndScopes(orcid, ScopePathType.ORCID_WORKS_CREATE, ScopePathType.ORCID_WORKS_UPDATE);
    clearSource(work);
    Work w = workManager.createWork(orcid, work, true);
    sourceUtils.setSourceName(w);
    try {
        return Response.created(new URI(String.valueOf(w.getPutCode()))).build();
    } catch (URISyntaxException e) {
        throw new RuntimeException(localeManager.resolveMessage("apiError.creatework_response.exception"), e);
    }
}
Also used : Work(org.orcid.jaxb.model.v3.dev1.record.Work) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 2 with Work

use of org.orcid.jaxb.model.v3.dev1.record.Work in project ORCID-Source by ORCID.

the class MemberV3ApiServiceDelegatorImpl method updateWork.

@Override
public Response updateWork(String orcid, Long putCode, Work work) {
    orcidSecurityManager.checkClientAccessAndScopes(orcid, ScopePathType.ORCID_WORKS_UPDATE);
    if (!putCode.equals(work.getPutCode())) {
        Map<String, String> params = new HashMap<String, String>();
        params.put("urlPutCode", String.valueOf(putCode));
        params.put("bodyPutCode", String.valueOf(work.getPutCode()));
        throw new MismatchedPutCodeException(params);
    }
    clearSource(work);
    Work w = workManager.updateWork(orcid, work, true);
    sourceUtils.setSourceName(w);
    return Response.ok(w).build();
}
Also used : HashMap(java.util.HashMap) Work(org.orcid.jaxb.model.v3.dev1.record.Work) MismatchedPutCodeException(org.orcid.core.exception.MismatchedPutCodeException)

Example 3 with Work

use of org.orcid.jaxb.model.v3.dev1.record.Work in project ORCID-Source by ORCID.

the class MemberV3ApiServiceDelegatorImpl method viewWork.

@Override
public Response viewWork(String orcid, Long putCode) {
    Work w = workManagerReadOnly.getWork(orcid, putCode);
    orcidSecurityManager.checkAndFilter(orcid, w, ScopePathType.ORCID_WORKS_READ_LIMITED);
    contributorUtils.filterContributorPrivateData(w);
    ActivityUtils.cleanEmptyFields(w);
    ActivityUtils.setPathToActivity(w, orcid);
    sourceUtils.setSourceName(w);
    return Response.ok(w).build();
}
Also used : Work(org.orcid.jaxb.model.v3.dev1.record.Work)

Example 4 with Work

use of org.orcid.jaxb.model.v3.dev1.record.Work in project ORCID-Source by ORCID.

the class MemberV3ApiServiceDelegator_DistinctionsTest method testReadPublicScope_Distinctions.

@Test
public void testReadPublicScope_Distinctions() {
    SecurityContextTestUtils.setUpSecurityContext(ORCID, ScopePathType.READ_PUBLIC);
    Response r = serviceDelegator.viewDistinction(ORCID, 27L);
    assertNotNull(r);
    assertEquals(Distinction.class.getName(), r.getEntity().getClass().getName());
    r = serviceDelegator.viewDistinctionSummary(ORCID, 27L);
    assertNotNull(r);
    assertEquals(DistinctionSummary.class.getName(), r.getEntity().getClass().getName());
    // Limited that am the source of should work
    serviceDelegator.viewDistinction(ORCID, 28L);
    serviceDelegator.viewDistinctionSummary(ORCID, 28L);
    // Limited that am not the source of should fail
    try {
        serviceDelegator.viewDistinction(ORCID, 30L);
        fail();
    } catch (OrcidAccessControlException e) {
    } catch (Exception e) {
        fail();
    }
    try {
        serviceDelegator.viewDistinctionSummary(ORCID, 30L);
        fail();
    } catch (OrcidAccessControlException e) {
    } catch (Exception e) {
        fail();
    }
    // Private that am the source of should work
    serviceDelegator.viewDistinction(ORCID, 29L);
    serviceDelegator.viewDistinctionSummary(ORCID, 29L);
    // Private that am not the source of should fails
    try {
        serviceDelegator.viewDistinction(ORCID, 31L);
        fail();
    } catch (OrcidAccessControlException e) {
    } catch (Exception e) {
        fail();
    }
    try {
        serviceDelegator.viewDistinctionSummary(ORCID, 31L);
        fail();
    } catch (OrcidAccessControlException e) {
    } catch (Exception e) {
        fail();
    }
}
Also used : Response(javax.ws.rs.core.Response) DistinctionSummary(org.orcid.jaxb.model.v3.dev1.record.summary.DistinctionSummary) Distinction(org.orcid.jaxb.model.v3.dev1.record.Distinction) OrcidAccessControlException(org.orcid.core.exception.OrcidAccessControlException) NoResultException(javax.persistence.NoResultException) VisibilityMismatchException(org.orcid.core.exception.VisibilityMismatchException) WrongSourceException(org.orcid.core.exception.WrongSourceException) OrcidDuplicatedActivityException(org.orcid.core.exception.OrcidDuplicatedActivityException) OrcidValidationException(org.orcid.core.exception.OrcidValidationException) OrcidAccessControlException(org.orcid.core.exception.OrcidAccessControlException) OrcidVisibilityException(org.orcid.core.exception.OrcidVisibilityException) OrcidUnauthorizedException(org.orcid.core.exception.OrcidUnauthorizedException) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 5 with Work

use of org.orcid.jaxb.model.v3.dev1.record.Work in project ORCID-Source by ORCID.

the class MemberV3ApiServiceDelegator_EmploymentsTest method testReadPublicScope_Employments.

@Test
public void testReadPublicScope_Employments() {
    SecurityContextTestUtils.setUpSecurityContext(ORCID, ScopePathType.READ_PUBLIC);
    Response r = serviceDelegator.viewEmployment(ORCID, 17L);
    assertNotNull(r);
    assertEquals(Employment.class.getName(), r.getEntity().getClass().getName());
    r = serviceDelegator.viewEmploymentSummary(ORCID, 17L);
    assertNotNull(r);
    assertEquals(EmploymentSummary.class.getName(), r.getEntity().getClass().getName());
    // Limited that am the source of should work
    serviceDelegator.viewEmployment(ORCID, 18L);
    serviceDelegator.viewEmploymentSummary(ORCID, 18L);
    // Limited that am not the source of should fail
    try {
        serviceDelegator.viewEmployment(ORCID, 23L);
        fail();
    } catch (OrcidAccessControlException e) {
    } catch (Exception e) {
        fail();
    }
    try {
        serviceDelegator.viewEmploymentSummary(ORCID, 23L);
        fail();
    } catch (OrcidAccessControlException e) {
    } catch (Exception e) {
        fail();
    }
    // Private that am the source of should work
    serviceDelegator.viewEmployment(ORCID, 19L);
    serviceDelegator.viewEmploymentSummary(ORCID, 19L);
    // Private that am not the source of should fail
    try {
        serviceDelegator.viewEmployment(ORCID, 24L);
        fail();
    } catch (OrcidAccessControlException e) {
    } catch (Exception e) {
        fail();
    }
    try {
        serviceDelegator.viewEmploymentSummary(ORCID, 24L);
        fail();
    } catch (OrcidAccessControlException e) {
    } catch (Exception e) {
        fail();
    }
}
Also used : Response(javax.ws.rs.core.Response) Employment(org.orcid.jaxb.model.v3.dev1.record.Employment) EmploymentSummary(org.orcid.jaxb.model.v3.dev1.record.summary.EmploymentSummary) OrcidAccessControlException(org.orcid.core.exception.OrcidAccessControlException) NoResultException(javax.persistence.NoResultException) VisibilityMismatchException(org.orcid.core.exception.VisibilityMismatchException) WrongSourceException(org.orcid.core.exception.WrongSourceException) OrcidDuplicatedActivityException(org.orcid.core.exception.OrcidDuplicatedActivityException) OrcidValidationException(org.orcid.core.exception.OrcidValidationException) OrcidAccessControlException(org.orcid.core.exception.OrcidAccessControlException) OrcidVisibilityException(org.orcid.core.exception.OrcidVisibilityException) OrcidUnauthorizedException(org.orcid.core.exception.OrcidUnauthorizedException) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)154 Work (org.orcid.jaxb.model.v3.dev1.record.Work)141 ExternalID (org.orcid.jaxb.model.v3.dev1.record.ExternalID)46 DBUnitTest (org.orcid.test.DBUnitTest)41 Response (javax.ws.rs.core.Response)39 Title (org.orcid.jaxb.model.v3.dev1.common.Title)29 WorkTitle (org.orcid.jaxb.model.v3.dev1.record.WorkTitle)29 WorkSummary (org.orcid.jaxb.model.v3.dev1.record.summary.WorkSummary)29 Url (org.orcid.jaxb.model.v3.dev1.common.Url)28 ExternalIDs (org.orcid.jaxb.model.v3.dev1.record.ExternalIDs)24 WorkBulk (org.orcid.jaxb.model.v3.dev1.record.WorkBulk)22 OrcidError (org.orcid.jaxb.model.v3.dev1.error.OrcidError)21 BaseTest (org.orcid.core.BaseTest)20 NoResultException (javax.persistence.NoResultException)17 OrcidAccessControlException (org.orcid.core.exception.OrcidAccessControlException)17 OrcidUnauthorizedException (org.orcid.core.exception.OrcidUnauthorizedException)17 OrcidVisibilityException (org.orcid.core.exception.OrcidVisibilityException)17 VisibilityMismatchException (org.orcid.core.exception.VisibilityMismatchException)17 WrongSourceException (org.orcid.core.exception.WrongSourceException)17 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)15