Search in sources :

Example 86 with Work

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

the class ActivityValidatorTest method validateWork_invalidCitationTypeTest.

@Test(expected = ActivityTypeValidationException.class)
public void validateWork_invalidCitationTypeTest() {
    Work work = getWork();
    work.getWorkCitation().setWorkCitationType(null);
    activityValidator.validateWork(work, null, true, true, Visibility.PUBLIC);
}
Also used : Work(org.orcid.jaxb.model.v3.dev1.record.Work) Test(org.junit.Test)

Example 87 with Work

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

the class ExternalIDValidatorTest method testEmptyRelationshipOnNotificationItemExternalIds_flagOn.

@Test(expected = ActivityIdentifierValidationException.class)
public void testEmptyRelationshipOnNotificationItemExternalIds_flagOn() {
    validator.setRequireRelationshipOnExternalIdentifier(true);
    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(null);
    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);
    fail("no exception thrown for invalid type");
}
Also used : Item(org.orcid.jaxb.model.v3.dev1.notification.permission.Item) ExternalID(org.orcid.jaxb.model.v3.dev1.record.ExternalID) Items(org.orcid.jaxb.model.v3.dev1.notification.permission.Items) Url(org.orcid.jaxb.model.v3.dev1.common.Url) Test(org.junit.Test)

Example 88 with Work

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

the class ExternalIDValidatorTest method testEmptyRelationshipOnNotificationItemExternalIds_flagOff.

@Test
public void testEmptyRelationshipOnNotificationItemExternalIds_flagOff() {
    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(null);
    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);
}
Also used : Item(org.orcid.jaxb.model.v3.dev1.notification.permission.Item) ExternalID(org.orcid.jaxb.model.v3.dev1.record.ExternalID) Items(org.orcid.jaxb.model.v3.dev1.notification.permission.Items) Url(org.orcid.jaxb.model.v3.dev1.common.Url) Test(org.junit.Test)

Example 89 with Work

use of org.orcid.jaxb.model.v3.dev1.record.Work 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.v3.dev1.record.ExternalIDs) ExternalID(org.orcid.jaxb.model.v3.dev1.record.ExternalID) Url(org.orcid.jaxb.model.v3.dev1.common.Url) ActivityIdentifierValidationException(org.orcid.core.exception.ActivityIdentifierValidationException) ActivityIdentifierValidationException(org.orcid.core.exception.ActivityIdentifierValidationException) Test(org.junit.Test)

Example 90 with Work

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

the class BibtexManagerImpl method workToBibtex.

public String workToBibtex(Work work, String creditName) {
    StringBuffer out = new StringBuffer();
    switch(work.getWorkType()) {
        case JOURNAL_ARTICLE:
            out.append("@article{");
            break;
        case BOOK:
        case BOOK_CHAPTER:
            out.append("@book{");
            break;
        case CONFERENCE_PAPER:
        case CONFERENCE_ABSTRACT:
        case CONFERENCE_POSTER:
            out.append("@conference{");
            break;
        default:
            out.append("@misc{");
            break;
    }
    // id
    out.append(escapeStringForBibtex(creditName).replace(' ', '_') + work.getPutCode());
    // title
    out.append(",\ntitle={" + escapeStringForBibtex((work.getWorkTitle() != null) ? work.getWorkTitle().getTitle().getContent() : "No Title") + "}");
    // journal title
    if (work.getJournalTitle() != null) {
        out.append(",\njournal={" + escapeStringForBibtex(work.getJournalTitle().getContent()) + "}");
    }
    // name
    List<String> names = new ArrayList<String>();
    names.add(creditName);
    if (work.getWorkContributors() != null && work.getWorkContributors().getContributor() != null) {
        for (Contributor c : work.getWorkContributors().getContributor()) {
            if (c.getCreditName() != null && c.getCreditName().getContent() != null) {
                names.add(c.getCreditName().getContent());
            }
        }
    }
    out.append(",\nauthor={" + escapeStringForBibtex(Joiner.on(" and ").skipNulls().join(names)) + "}");
    // ids
    String doi = extractID(work, WorkExternalIdentifierType.DOI);
    String url = extractID(work, WorkExternalIdentifierType.URI);
    if (doi != null) {
        out.append(",\ndoi={" + escapeStringForBibtex(doi) + "}");
    }
    if (url != null) {
        out.append(",\nurl={" + escapeStringForBibtex(url) + "}");
    } else if (doi != null) {
        out.append(",\nurl={" + escapeStringForBibtex("http://doi.org/" + doi) + "}");
    } else {
        url = extractID(work, WorkExternalIdentifierType.HANDLE);
        if (url != null) {
            out.append(",\nurl={" + escapeStringForBibtex(url) + "}");
        }
    }
    String isbn = extractID(work, WorkExternalIdentifierType.ISBN);
    if (isbn != null)
        out.append(",\nisbn={" + escapeStringForBibtex(isbn) + "}");
    String issn = extractID(work, WorkExternalIdentifierType.ISSN);
    if (issn != null)
        out.append(",\nissn={" + escapeStringForBibtex(issn) + "}");
    // year
    if (work.getPublicationDate() != null) {
        int year = 0;
        try {
            year = Integer.parseInt(work.getPublicationDate().getYear().getValue());
        } catch (Exception e) {
        }
        if (year > 0) {
            out.append(",\nyear={" + year + "}");
        }
    }
    out.append("\n}");
    return out.toString();
}
Also used : ArrayList(java.util.ArrayList) Contributor(org.orcid.jaxb.model.v3.dev1.common.Contributor)

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