Search in sources :

Example 31 with WorkBulk

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

the class OrcidSecurityManager_WorkBulkTest method testLimitedWorkBulkReadPublicTokenNoSource.

@Test
public void testLimitedWorkBulkReadPublicTokenNoSource() {
    WorkBulk workBulk = new WorkBulk();
    workBulk.setBulk(Arrays.asList(createWork(Visibility.LIMITED, null), createWork(Visibility.LIMITED, null)));
    SecurityContextTestUtils.setUpSecurityContext(ORCID_1, CLIENT_2, ScopePathType.READ_PUBLIC);
    orcidSecurityManager.checkAndFilter(ORCID_1, workBulk, ScopePathType.ORCID_WORKS_READ_LIMITED);
    assertNotNull(workBulk);
    assertEquals(2, workBulk.getBulk().size());
    assertTrue(workBulk.getBulk().get(0) instanceof OrcidError);
    assertTrue(workBulk.getBulk().get(1) instanceof OrcidError);
}
Also used : OrcidError(org.orcid.jaxb.model.v3.dev1.error.OrcidError) WorkBulk(org.orcid.jaxb.model.v3.dev1.record.WorkBulk) Test(org.junit.Test)

Example 32 with WorkBulk

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

the class OrcidSecurityManager_WorkBulkTest method testPublicWorkBulkReadPublicToken.

@Test
public void testPublicWorkBulkReadPublicToken() {
    WorkBulk workBulk = new WorkBulk();
    workBulk.setBulk(Arrays.asList(createWork(Visibility.PUBLIC, CLIENT_2)));
    SecurityContextTestUtils.setUpSecurityContext(ORCID_1, CLIENT_1, ScopePathType.READ_PUBLIC);
    orcidSecurityManager.checkAndFilter(ORCID_1, workBulk, ScopePathType.ORCID_WORKS_READ_LIMITED);
    assertNotNull(workBulk);
    assertEquals(1, workBulk.getBulk().size());
}
Also used : WorkBulk(org.orcid.jaxb.model.v3.dev1.record.WorkBulk) Test(org.junit.Test)

Example 33 with WorkBulk

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

the class ActivityUtilsTest method cleanBulkWorkTest.

@Test
public void cleanBulkWorkTest() {
    // Test it cleans empty fields
    WorkBulk bulk = new WorkBulk();
    Work w = getEmptyWork();
    bulk.getBulk().add(w);
    assertNotNull(((Work) bulk.getBulk().get(0)).getWorkTitle().getTranslatedTitle());
    assertNotNull(((Work) bulk.getBulk().get(0)).getWorkCitation());
    assertNotNull(((Work) bulk.getBulk().get(0)).getWorkContributors().getContributor().get(0).getCreditName());
    ActivityUtils.cleanEmptyFields(bulk);
    assertNull(((Work) bulk.getBulk().get(0)).getWorkTitle().getTranslatedTitle());
    assertNull(((Work) bulk.getBulk().get(0)).getWorkCitation());
    assertNull(((Work) bulk.getBulk().get(0)).getWorkContributors().getContributor().get(0).getCreditName());
    // Test it doesn't remove non empty fields
    bulk = new WorkBulk();
    w = getEmptyWork();
    w.getWorkTitle().getTranslatedTitle().setContent("translated_title");
    w.getWorkTitle().getTranslatedTitle().setLanguageCode("en_us");
    w.getWorkCitation().setCitation("citation");
    w.getWorkCitation().setWorkCitationType(CitationType.BIBTEX);
    w.getWorkContributors().getContributor().get(0).getCreditName().setContent("credit_name");
    bulk.getBulk().add(w);
    assertEquals("translated_title", ((Work) bulk.getBulk().get(0)).getWorkTitle().getTranslatedTitle().getContent());
    assertEquals("en_us", ((Work) bulk.getBulk().get(0)).getWorkTitle().getTranslatedTitle().getLanguageCode());
    assertEquals("citation", ((Work) bulk.getBulk().get(0)).getWorkCitation().getCitation());
    assertEquals(CitationType.BIBTEX, ((Work) bulk.getBulk().get(0)).getWorkCitation().getWorkCitationType());
    assertEquals("credit_name", ((Work) bulk.getBulk().get(0)).getWorkContributors().getContributor().get(0).getCreditName().getContent());
    ActivityUtils.cleanEmptyFields(bulk);
    assertEquals("translated_title", ((Work) bulk.getBulk().get(0)).getWorkTitle().getTranslatedTitle().getContent());
    assertEquals("en_us", ((Work) bulk.getBulk().get(0)).getWorkTitle().getTranslatedTitle().getLanguageCode());
    assertEquals("citation", ((Work) bulk.getBulk().get(0)).getWorkCitation().getCitation());
    assertEquals(CitationType.BIBTEX, ((Work) bulk.getBulk().get(0)).getWorkCitation().getWorkCitationType());
    assertEquals("credit_name", ((Work) bulk.getBulk().get(0)).getWorkContributors().getContributor().get(0).getCreditName().getContent());
}
Also used : WorkBulk(org.orcid.jaxb.model.v3.dev1.record.WorkBulk) Work(org.orcid.jaxb.model.v3.dev1.record.Work) Test(org.junit.Test)

Example 34 with WorkBulk

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

the class MemberV3ApiServiceDelegatorImpl method createWorks.

@Override
public Response createWorks(String orcid, WorkBulk works) {
    orcidSecurityManager.checkClientAccessAndScopes(orcid, ScopePathType.ORCID_WORKS_CREATE, ScopePathType.ORCID_WORKS_UPDATE);
    if (works != null) {
        for (int i = 0; i < works.getBulk().size(); i++) {
            if (Work.class.isAssignableFrom(works.getBulk().get(i).getClass())) {
                Work work = (Work) works.getBulk().get(i);
                try {
                    schemaValidator.validate(work);
                    clearSource(work);
                } catch (WebApplicationException e) {
                    OrcidError error = orcidCoreExceptionMapper.getOrcidErrorV3Dev1(9001, 400, e);
                    works.getBulk().remove(i);
                    works.getBulk().add(i, error);
                }
            }
        }
    }
    works = workManager.createWorks(orcid, works);
    sourceUtils.setSourceName(works);
    return Response.ok(works).build();
}
Also used : OrcidError(org.orcid.jaxb.model.v3.dev1.error.OrcidError) WebApplicationException(javax.ws.rs.WebApplicationException) Work(org.orcid.jaxb.model.v3.dev1.record.Work)

Example 35 with WorkBulk

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

the class WorksTest method testThreeWithInvalidTypeAllOthersAreFine.

@Test
public void testThreeWithInvalidTypeAllOthersAreFine() throws InterruptedException, JSONException {
    String accessToken = getAccessToken();
    WorkBulk bulk = createBulk(10, null);
    // Work 3: no type
    Work work3 = (Work) bulk.getBulk().get(3);
    work3.setWorkType(null);
    bulk.getBulk().set(3, work3);
    // Work 5: empty title
    Work work5 = (Work) bulk.getBulk().get(5);
    work5.getWorkTitle().getTitle().setContent(null);
    bulk.getBulk().set(5, work5);
    // Work 7: translated title language code empty
    Work work7 = (Work) bulk.getBulk().get(7);
    work7.getWorkTitle().getTranslatedTitle().setLanguageCode(null);
    bulk.getBulk().set(7, work7);
    ClientResponse postResponse = memberV3Dev1ApiClient.createWorksJson(this.getUser1OrcidId(), bulk, accessToken);
    assertNotNull(postResponse);
    assertEquals(Response.Status.OK.getStatusCode(), postResponse.getStatus());
    bulk = postResponse.getEntity(WorkBulk.class);
    assertNotNull(bulk);
    assertNotNull(bulk.getBulk());
    for (int i = 0; i < bulk.getBulk().size(); i++) {
        BulkElement element = bulk.getBulk().get(i);
        if (i == 3 || i == 5 || i == 7) {
            assertTrue(OrcidError.class.isAssignableFrom(element.getClass()));
            OrcidError error = (OrcidError) element;
            switch(i) {
                case 3:
                    assertEquals(Integer.valueOf(9001), error.getErrorCode());
                    assertTrue(error.getDeveloperMessage().endsWith("\"http://www.orcid.org/ns/work\":type}' is expected.)"));
                    break;
                case 5:
                    assertEquals(Integer.valueOf(9001), error.getErrorCode());
                    assertTrue(error.getDeveloperMessage().contains("Object must have some value in its @XmlValue field: org.orcid.jaxb.model.v3.dev1.common.Title"));
                    break;
                case 7:
                    assertEquals(Integer.valueOf(9001), error.getErrorCode());
                    assertTrue(error.getDeveloperMessage().endsWith("Attribute 'language-code' must appear on element 'common:translated-title'.)"));
                    break;
            }
        } else {
            assertTrue(Work.class.isAssignableFrom(element.getClass()));
            Work work = (Work) element;
            assertNotNull(work.getPutCode());
            memberV3Dev1ApiClient.deleteWorkXml(this.getUser1OrcidId(), work.getPutCode(), accessToken);
        }
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) OrcidError(org.orcid.jaxb.model.v3.dev1.error.OrcidError) BulkElement(org.orcid.jaxb.model.record.bulk.BulkElement) WorkBulk(org.orcid.jaxb.model.v3.dev1.record.WorkBulk) Work(org.orcid.jaxb.model.v3.dev1.record.Work) Test(org.junit.Test)

Aggregations

WorkBulk (org.orcid.jaxb.model.v3.dev1.record.WorkBulk)33 Test (org.junit.Test)29 Work (org.orcid.jaxb.model.v3.dev1.record.Work)23 OrcidError (org.orcid.jaxb.model.v3.dev1.error.OrcidError)22 BulkElement (org.orcid.jaxb.model.record.bulk.BulkElement)9 BaseTest (org.orcid.core.BaseTest)8 ExternalID (org.orcid.jaxb.model.v3.dev1.record.ExternalID)8 Title (org.orcid.jaxb.model.v3.dev1.common.Title)7 ExternalIDs (org.orcid.jaxb.model.v3.dev1.record.ExternalIDs)7 WorkTitle (org.orcid.jaxb.model.v3.dev1.record.WorkTitle)7 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)7 Url (org.orcid.jaxb.model.v3.dev1.common.Url)6 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)6 Response (javax.ws.rs.core.Response)5 DBUnitTest (org.orcid.test.DBUnitTest)5 ClientResponse (com.sun.jersey.api.client.ClientResponse)4 ArrayList (java.util.ArrayList)4 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)3 OrcidNoResultException (org.orcid.core.exception.OrcidNoResultException)2 TranslatedTitle (org.orcid.jaxb.model.v3.dev1.common.TranslatedTitle)2