Search in sources :

Example 6 with Items

use of org.orcid.jaxb.model.v3.dev1.notification.permission.Items in project ORCID-Source by ORCID.

the class ExternalIDValidator method validateNotificationItems.

public void validateNotificationItems(Items items) {
    if (items == null)
        return;
    List<String> errors = Lists.newArrayList();
    for (Item i : items.getItems()) {
        if (i.getExternalIdentifier() != null && i.getExternalIdentifier().getType() != null) {
            ExternalID extId = i.getExternalIdentifier();
            if (extId.getType() == null || !identifierTypeManager.fetchIdentifierTypesByAPITypeName(null).containsKey(extId.getType())) {
                errors.add(i.getExternalIdentifier().getType());
            }
            if (PojoUtil.isEmpty(extId.getValue())) {
                errors.add("value");
            }
            if (requireRelationshipOnExternalIdentifier) {
                if (extId.getRelationship() == null) {
                    errors.add("relationship");
                }
            }
        }
    }
    checkAndThrow(errors);
}
Also used : Item(org.orcid.jaxb.model.v3.dev1.notification.permission.Item) ExternalID(org.orcid.jaxb.model.v3.dev1.record.ExternalID)

Example 7 with Items

use of org.orcid.jaxb.model.v3.dev1.notification.permission.Items in project ORCID-Source by ORCID.

the class OrcidInfo method groupKeywords.

private LinkedHashMap<String, List<Keyword>> groupKeywords(Keywords keywords) {
    if (keywords == null || keywords.getKeywords() == null) {
        return null;
    }
    /* Grouping items */
    LinkedHashMap<String, List<Keyword>> groups = new LinkedHashMap<String, List<Keyword>>();
    for (Keyword k : keywords.getKeywords()) {
        if (groups.containsKey(k.getContent())) {
            groups.get(k.getContent()).add(k);
        } else {
            List<Keyword> list = new ArrayList<Keyword>();
            list.add(k);
            groups.put(k.getContent(), list);
        }
    }
    return groups;
}
Also used : Keyword(org.orcid.jaxb.model.v3.dev1.record.Keyword) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap)

Example 8 with Items

use of org.orcid.jaxb.model.v3.dev1.notification.permission.Items 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.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) ActivityIdentifierValidationException(org.orcid.core.exception.ActivityIdentifierValidationException) ActivityIdentifierValidationException(org.orcid.core.exception.ActivityIdentifierValidationException) Test(org.junit.Test)

Aggregations

Item (org.orcid.jaxb.model.v3.dev1.notification.permission.Item)6 Items (org.orcid.jaxb.model.v3.dev1.notification.permission.Items)6 ExternalID (org.orcid.jaxb.model.v3.dev1.record.ExternalID)6 Test (org.junit.Test)5 Url (org.orcid.jaxb.model.v3.dev1.common.Url)3 ArrayList (java.util.ArrayList)2 Source (org.orcid.jaxb.model.v3.dev1.common.Source)2 SourceClientId (org.orcid.jaxb.model.v3.dev1.common.SourceClientId)2 NotificationAmended (org.orcid.jaxb.model.v3.dev1.notification.amended.NotificationAmended)2 NotificationEntity (org.orcid.persistence.jpa.entities.NotificationEntity)2 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Locale (java.util.Locale)1 ActivityIdentifierValidationException (org.orcid.core.exception.ActivityIdentifierValidationException)1 AuthorizationUrl (org.orcid.jaxb.model.v3.dev1.notification.permission.AuthorizationUrl)1 NotificationPermission (org.orcid.jaxb.model.v3.dev1.notification.permission.NotificationPermission)1 Keyword (org.orcid.jaxb.model.v3.dev1.record.Keyword)1 NotificationAddItemsEntity (org.orcid.persistence.jpa.entities.NotificationAddItemsEntity)1 NotificationAmendedEntity (org.orcid.persistence.jpa.entities.NotificationAmendedEntity)1