Search in sources :

Example 41 with Url

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

the class WorkManagerTest method testCreateWorksWithBulkAllOK.

@Test
public void testCreateWorksWithBulkAllOK() {
    String orcid = "0000-0000-0000-0003";
    Long time = System.currentTimeMillis();
    when(sourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ClientDetailsEntity(CLIENT_1_ID)));
    WorkBulk bulk = new WorkBulk();
    for (int i = 0; i < 5; i++) {
        Work work = new Work();
        WorkTitle title = new WorkTitle();
        title.setTitle(new Title("Bulk work " + i + " " + time));
        work.setWorkTitle(title);
        ExternalIDs extIds = new ExternalIDs();
        ExternalID extId = new ExternalID();
        extId.setRelationship(Relationship.SELF);
        extId.setType("doi");
        extId.setUrl(new Url("http://doi/" + i + "/" + time));
        extId.setValue("doi-" + i + "-" + time);
        extIds.getExternalIdentifier().add(extId);
        work.setWorkExternalIdentifiers(extIds);
        work.setWorkType(WorkType.BOOK);
        bulk.getBulk().add(work);
    }
    bulk = workManager.createWorks(orcid, bulk);
    assertNotNull(bulk);
    assertEquals(5, bulk.getBulk().size());
    for (int i = 0; i < 5; i++) {
        assertTrue(Work.class.isAssignableFrom(bulk.getBulk().get(i).getClass()));
        Work w = (Work) bulk.getBulk().get(i);
        assertNotNull(w.getPutCode());
        assertTrue(0L < w.getPutCode());
        assertEquals("Bulk work " + i + " " + time, w.getWorkTitle().getTitle().getContent());
        assertNotNull(w.getExternalIdentifiers().getExternalIdentifier());
        assertEquals("doi-" + i + "-" + time, w.getExternalIdentifiers().getExternalIdentifier().get(0).getValue());
        Work w1 = workManager.getWork(orcid, w.getPutCode(), 0L);
        assertNotNull(w1);
        assertEquals("Bulk work " + i + " " + time, w1.getWorkTitle().getTitle().getContent());
        //Delete the work
        assertTrue(workManager.checkSourceAndRemoveWork(orcid, w1.getPutCode()));
    }
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) ExternalIDs(org.orcid.jaxb.model.record_v2.ExternalIDs) WorkTitle(org.orcid.jaxb.model.record_v2.WorkTitle) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) WorkBulk(org.orcid.jaxb.model.record_v2.WorkBulk) ExternalID(org.orcid.jaxb.model.record_v2.ExternalID) Work(org.orcid.jaxb.model.record_v2.Work) WorkTitle(org.orcid.jaxb.model.record_v2.WorkTitle) Title(org.orcid.jaxb.model.common_v2.Title) Url(org.orcid.jaxb.model.common_v2.Url) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Example 42 with Url

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

the class WorkManagerTest method getWorkSummary.

private WorkSummary getWorkSummary(String titleValue, String extIdValue, Visibility visibility, String displayIndex) {
    WorkSummary summary = new WorkSummary();
    summary.setDisplayIndex(displayIndex);
    Title title = new Title(titleValue);
    WorkTitle workTitle = new WorkTitle();
    workTitle.setTitle(title);
    summary.setTitle(workTitle);
    summary.setType(WorkType.ARTISTIC_PERFORMANCE);
    summary.setVisibility(visibility);
    ExternalIDs extIds = new ExternalIDs();
    ExternalID extId = new ExternalID();
    extId.setRelationship(Relationship.SELF);
    extId.setType("doi");
    extId.setUrl(new Url("http://orcid.org"));
    extId.setValue(extIdValue);
    extIds.getExternalIdentifier().add(extId);
    summary.setExternalIdentifiers(extIds);
    return summary;
}
Also used : WorkSummary(org.orcid.jaxb.model.record.summary_v2.WorkSummary) ExternalIDs(org.orcid.jaxb.model.record_v2.ExternalIDs) WorkTitle(org.orcid.jaxb.model.record_v2.WorkTitle) ExternalID(org.orcid.jaxb.model.record_v2.ExternalID) WorkTitle(org.orcid.jaxb.model.record_v2.WorkTitle) Title(org.orcid.jaxb.model.common_v2.Title) Url(org.orcid.jaxb.model.common_v2.Url)

Example 43 with Url

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

the class WorkManagerTest method testCreateWorksWithBulkSomeOKSomeErrors.

@Test
public void testCreateWorksWithBulkSomeOKSomeErrors() {
    String orcid = "0000-0000-0000-0003";
    when(sourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ClientDetailsEntity(CLIENT_2_ID)));
    //Lets send a bulk of 6 works
    WorkBulk bulk = new WorkBulk();
    //Work # 1 - Fine
    Work work1 = getWork(null);
    ExternalID extId = new ExternalID();
    extId.setRelationship(Relationship.SELF);
    extId.setType("doi");
    extId.setUrl(new Url("http://doi/1"));
    extId.setValue("doi-1");
    work1.getExternalIdentifiers().getExternalIdentifier().clear();
    work1.getExternalIdentifiers().getExternalIdentifier().add(extId);
    work1.getWorkTitle().getTitle().setContent("Work # 1");
    bulk.getBulk().add(work1);
    //Work # 2 - Fine
    Work work2 = getWork(null);
    work2.getWorkTitle().getTitle().setContent("Work # 2");
    bulk.getBulk().add(work2);
    //Work # 3 - Duplicated of Work # 1
    Work work3 = getWork(null);
    work3.getExternalIdentifiers().getExternalIdentifier().clear();
    work3.getExternalIdentifiers().getExternalIdentifier().add(extId);
    work3.getWorkTitle().getTitle().setContent("Work # 3");
    bulk.getBulk().add(work3);
    //Work # 4 - Fine
    Work work4 = getWork("new-ext-id-" + System.currentTimeMillis());
    work4.getWorkTitle().getTitle().setContent("Work # 4");
    bulk.getBulk().add(work4);
    //Work # 5 - Duplicated of existing work
    Work work5 = getWork(null);
    ExternalID dupExtId = new ExternalID();
    dupExtId.setRelationship(Relationship.SELF);
    dupExtId.setType("doi");
    dupExtId.setValue("1");
    work5.getExternalIdentifiers().getExternalIdentifier().clear();
    work5.getExternalIdentifiers().getExternalIdentifier().add(dupExtId);
    work5.getWorkTitle().getTitle().setContent("Work # 5");
    bulk.getBulk().add(work5);
    //Work # 6 - No title specified
    Work work6 = getWork(null);
    work6.getWorkTitle().getTitle().setContent(null);
    bulk.getBulk().add(work6);
    bulk = workManager.createWorks(orcid, bulk);
    assertNotNull(bulk);
    assertEquals(6, bulk.getBulk().size());
    List<Long> worksToDelete = new ArrayList<Long>();
    for (int i = 0; i < bulk.getBulk().size(); i++) {
        BulkElement element = bulk.getBulk().get(i);
        switch(i) {
            case 0:
            case 1:
            case 3:
                assertTrue(Work.class.isAssignableFrom(element.getClass()));
                Work work = (Work) element;
                assertNotNull(work);
                assertNotNull(work.getPutCode());
                if (i == 0) {
                    assertEquals("Work # 1", work.getWorkTitle().getTitle().getContent());
                } else if (i == 1) {
                    assertEquals("Work # 2", work.getWorkTitle().getTitle().getContent());
                } else {
                    assertEquals("Work # 4", work.getWorkTitle().getTitle().getContent());
                }
                worksToDelete.add(work.getPutCode());
                break;
            case 2:
            case 4:
            case 5:
                assertTrue("Error on id: " + i, OrcidError.class.isAssignableFrom(element.getClass()));
                OrcidError error = (OrcidError) element;
                if (i == 2) {
                    assertEquals(Integer.valueOf(9021), error.getErrorCode());
                } else if (i == 4) {
                    assertEquals(Integer.valueOf(9021), error.getErrorCode());
                } else {
                    assertEquals(Integer.valueOf(9022), error.getErrorCode());
                }
                break;
        }
    }
    //Delete new works
    for (Long putCode : worksToDelete) {
        assertTrue(workManager.checkSourceAndRemoveWork(orcid, putCode));
    }
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) OrcidError(org.orcid.jaxb.model.error_v2.OrcidError) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) WorkBulk(org.orcid.jaxb.model.record_v2.WorkBulk) ExternalID(org.orcid.jaxb.model.record_v2.ExternalID) ArrayList(java.util.ArrayList) Url(org.orcid.jaxb.model.common_v2.Url) BulkElement(org.orcid.jaxb.model.record_v2.BulkElement) Work(org.orcid.jaxb.model.record_v2.Work) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Example 44 with Url

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

the class ExternalIDValidatorTest method testValidateWorkOrPeerReview.

@Test
public void testValidateWorkOrPeerReview() {
    //call for ExternalID and ExternalIDs
    //ID valid
    ExternalID id1 = new ExternalID();
    id1.setRelationship(Relationship.SELF);
    id1.setType("doi");
    id1.setValue("value1");
    id1.setUrl(new Url("http://value1.com"));
    validator.validateWorkOrPeerReview(id1);
    //ID bad type
    try {
        id1.setType("invalid");
        validator.validateWorkOrPeerReview(id1);
        fail("no exception thrown for invalid type");
    } catch (Exception e) {
        if (!(e instanceof ActivityIdentifierValidationException))
            throw e;
    }
    //id null
    try {
        id1.setType(null);
        validator.validateWorkOrPeerReview(id1);
        fail("no exception thrown for invalid type");
    } catch (Exception e) {
        if (!(e instanceof ActivityIdentifierValidationException))
            throw e;
    }
    ExternalIDs ids = new ExternalIDs();
    ids.getExternalIdentifier().add(id1);
    //IDS one invalid
    id1.setType("invalid");
    try {
        validator.validateWorkOrPeerReview(ids);
        fail("no exception thrown for invalid type");
    } catch (Exception e) {
        if (!(e instanceof ActivityIdentifierValidationException))
            throw e;
    }
    //IDS one valid (lowercase)
    id1.setType("doi");
    validator.validateWorkOrPeerReview(ids);
    //IDS two valid
    ExternalID id2 = new ExternalID();
    id2.setRelationship(Relationship.SELF);
    id2.setType("source-work-id");
    id2.setValue("value2");
    id2.setUrl(new Url("http://value1.com"));
    ids.getExternalIdentifier().add(id2);
    validator.validateWorkOrPeerReview(ids);
    //IDS one invalid, one valid
    id2.setType("not-a-type");
    try {
        validator.validateWorkOrPeerReview(ids);
        fail("no exception thrown for invalid type");
    } catch (Exception e) {
        if (!(e instanceof ActivityIdentifierValidationException))
            throw e;
    }
}
Also used : ExternalIDs(org.orcid.jaxb.model.record_v2.ExternalIDs) ExternalID(org.orcid.jaxb.model.record_v2.ExternalID) Url(org.orcid.jaxb.model.common_v2.Url) ActivityIdentifierValidationException(org.orcid.core.exception.ActivityIdentifierValidationException) ActivityIdentifierValidationException(org.orcid.core.exception.ActivityIdentifierValidationException) Test(org.junit.Test)

Example 45 with Url

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

the class ExternalIDValidatorTest method testValidateNotificationItems.

@Test
public void testValidateNotificationItems() {
    Item i = new Item();
    Item i2 = new Item();
    Items items = new Items();
    ExternalID id1 = new ExternalID();
    id1.setRelationship(Relationship.SELF);
    id1.setType("doi");
    id1.setValue("value1");
    id1.setUrl(new Url("http://value1.com"));
    ExternalID id2 = new ExternalID();
    id2.setRelationship(Relationship.SELF);
    id2.setType("source-work-id");
    id2.setValue("value2");
    id2.setUrl(new Url("http://value1.com"));
    i.setExternalIdentifier(id1);
    i2.setExternalIdentifier(id2);
    items.getItems().add(i);
    items.getItems().add(i2);
    //both valid
    validator.validateNotificationItems(items);
    //IDS one valid, one invalid
    id2.setType("blah");
    try {
        validator.validateNotificationItems(items);
        fail("no exception thrown for invalid type");
    } catch (Exception e) {
        if (!(e instanceof ActivityIdentifierValidationException))
            throw e;
    }
    //IDS one valid, one VALID due to null (at least we have to do this if we want other tests to pass!)
    id2.setType(null);
    validator.validateNotificationItems(items);
}
Also used : Item(org.orcid.jaxb.model.notification.permission_v2.Item) ExternalID(org.orcid.jaxb.model.record_v2.ExternalID) Items(org.orcid.jaxb.model.notification.permission_v2.Items) Url(org.orcid.jaxb.model.common_v2.Url) ActivityIdentifierValidationException(org.orcid.core.exception.ActivityIdentifierValidationException) ActivityIdentifierValidationException(org.orcid.core.exception.ActivityIdentifierValidationException) 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