Search in sources :

Example 6 with InvalidPutCodeException

use of org.orcid.core.exception.InvalidPutCodeException in project ORCID-Source by ORCID.

the class ActivityValidator method validateEducation.

public void validateEducation(Education education, SourceEntity sourceEntity, boolean createFlag, boolean isApiRequest, Visibility originalVisibility) {
    if (education.getPutCode() != null && createFlag) {
        Map<String, String> params = new HashMap<String, String>();
        if (sourceEntity != null) {
            params.put("clientName", sourceEntity.getSourceName());
        }
        throw new InvalidPutCodeException(params);
    }
    // Check that we are not changing the visibility
    if (isApiRequest && !createFlag) {
        Visibility updatedVisibility = education.getVisibility();
        validateVisibilityDoesntChange(updatedVisibility, originalVisibility);
    }
}
Also used : HashMap(java.util.HashMap) InvalidPutCodeException(org.orcid.core.exception.InvalidPutCodeException) Visibility(org.orcid.jaxb.model.common_v2.Visibility)

Example 7 with InvalidPutCodeException

use of org.orcid.core.exception.InvalidPutCodeException in project ORCID-Source by ORCID.

the class ActivityValidator method validateGroupIdRecord.

public void validateGroupIdRecord(GroupIdRecord groupIdRecord, boolean createFlag, SourceEntity sourceEntity) {
    if (createFlag) {
        if (groupIdRecord.getPutCode() != null) {
            Map<String, String> params = new HashMap<String, String>();
            if (sourceEntity != null) {
                params.put("clientName", sourceEntity.getSourceName());
            }
            throw new InvalidPutCodeException(params);
        }
    }
    Pattern validGroupIdRegexPattern = Pattern.compile("(ringgold:|issn:|orcid-generated:|fundref:|publons:)([0-9a-zA-Z\\^._~:/?#\\[\\]@!$&amp;'()*+,;=-]){2,}");
    Matcher matcher = validGroupIdRegexPattern.matcher(groupIdRecord.getGroupId());
    if (!matcher.matches()) {
        throw new OrcidValidationException("Invalid group-id: '" + groupIdRecord.getGroupId() + "'");
    }
}
Also used : Pattern(java.util.regex.Pattern) HashMap(java.util.HashMap) InvalidPutCodeException(org.orcid.core.exception.InvalidPutCodeException) Matcher(java.util.regex.Matcher) OrcidValidationException(org.orcid.core.exception.OrcidValidationException)

Example 8 with InvalidPutCodeException

use of org.orcid.core.exception.InvalidPutCodeException in project ORCID-Source by ORCID.

the class GroupIdRecordManagerTest method testCreateUpdateGetDeleteGroupIdRecord.

@Test
public void testCreateUpdateGetDeleteGroupIdRecord() {
    GroupIdRecord g1 = new GroupIdRecord();
    g1.setDescription("Description");
    g1.setGroupId("orcid-generated:valid-group-id");
    g1.setName("Group # " + System.currentTimeMillis());
    g1.setType("publisher");
    // Test create
    g1 = groupIdRecordManager.createGroupIdRecord(g1);
    Long putCode = g1.getPutCode();
    assertNotNull(putCode);
    assertNotNull(g1.getSource());
    assertNotNull(g1.getSource().getSourceClientId());
    assertEquals(CLIENT_ID, g1.getSource().getSourceClientId().getPath());
    // Test find
    assertTrue(groupIdRecordManager.exists(g1.getGroupId()));
    Optional<GroupIdRecord> existingByGroupId = groupIdRecordManager.findByGroupId(g1.getGroupId());
    assertTrue(existingByGroupId.isPresent());
    assertNotNull(existingByGroupId.get().getPutCode());
    assertEquals(putCode, existingByGroupId.get().getPutCode());
    assertEquals(g1.getGroupId(), existingByGroupId.get().getGroupId());
    assertNotNull(existingByGroupId.get().getSource());
    assertNotNull(existingByGroupId.get().getSource().getSourceClientId());
    assertEquals(CLIENT_ID, existingByGroupId.get().getSource().getSourceClientId().getPath());
    GroupIdRecord existingByPutCode = groupIdRecordManager.getGroupIdRecord(g1.getPutCode());
    assertNotNull(existingByPutCode);
    assertNotNull(existingByPutCode.getPutCode());
    assertEquals(putCode, existingByPutCode.getPutCode());
    assertEquals(g1.getGroupId(), existingByPutCode.getGroupId());
    assertNotNull(existingByPutCode.getSource());
    assertNotNull(existingByPutCode.getSource().getSourceClientId());
    assertEquals(CLIENT_ID, existingByPutCode.getSource().getSourceClientId().getPath());
    // Test update with invalid value
    try {
        g1.setGroupId("invalid-group-id");
        groupIdRecordManager.updateGroupIdRecord(g1.getPutCode(), g1);
        fail();
    } catch (OrcidValidationException e) {
        assertEquals("Invalid group-id: '" + g1.getGroupId() + "'", e.getMessage());
    } catch (Exception e) {
        fail();
    }
    // Test update with valid value
    try {
        g1.setGroupId("orcid-generated:other-valid-group-id");
        g1 = groupIdRecordManager.updateGroupIdRecord(g1.getPutCode(), g1);
        assertNotNull(g1);
        assertEquals("orcid-generated:other-valid-group-id", g1.getGroupId());
    } catch (Exception e) {
        fail();
    }
    // Test create with put code
    try {
        g1.setGroupId("orcid-generated:valid-group-id");
        groupIdRecordManager.createGroupIdRecord(g1);
        fail();
    } catch (InvalidPutCodeException e) {
    } catch (Exception e) {
        fail();
    }
    // Test create with invalid group id
    try {
        g1.setPutCode(null);
        g1.setGroupId("other-invalid-group-id");
        groupIdRecordManager.createGroupIdRecord(g1);
        fail();
    } catch (OrcidValidationException e) {
        assertEquals("Invalid group-id: '" + g1.getGroupId() + "'", e.getMessage());
    } catch (Exception e) {
        fail();
    }
    // Test delete
    groupIdRecordManager.deleteGroupIdRecord(putCode);
    try {
        groupIdRecordManager.deleteGroupIdRecord(Long.valueOf(-1L));
    } catch (GroupIdRecordNotFoundException e) {
    } catch (Exception e) {
        fail();
    }
}
Also used : InvalidPutCodeException(org.orcid.core.exception.InvalidPutCodeException) GroupIdRecord(org.orcid.jaxb.model.groupid_v2.GroupIdRecord) OrcidValidationException(org.orcid.core.exception.OrcidValidationException) InvalidPutCodeException(org.orcid.core.exception.InvalidPutCodeException) OrcidValidationException(org.orcid.core.exception.OrcidValidationException) DuplicatedGroupIdRecordException(org.orcid.core.exception.DuplicatedGroupIdRecordException) GroupIdRecordNotFoundException(org.orcid.core.exception.GroupIdRecordNotFoundException) GroupIdRecordNotFoundException(org.orcid.core.exception.GroupIdRecordNotFoundException) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Example 9 with InvalidPutCodeException

use of org.orcid.core.exception.InvalidPutCodeException in project ORCID-Source by ORCID.

the class ActivityValidator method validateAffiliation.

public void validateAffiliation(Affiliation affiliation, SourceEntity sourceEntity, boolean createFlag, boolean isApiRequest, Visibility originalVisibility) {
    if (affiliation.getPutCode() != null && createFlag) {
        Map<String, String> params = new HashMap<String, String>();
        if (sourceEntity != null) {
            params.put("clientName", sourceEntity.getSourceName());
        }
        throw new InvalidPutCodeException(params);
    }
    // Check that we are not changing the visibility
    if (isApiRequest && !createFlag) {
        Visibility updatedVisibility = affiliation.getVisibility();
        validateVisibilityDoesntChange(updatedVisibility, originalVisibility);
    }
    if (affiliation.getStartDate() == null) {
        throw new OrcidValidationException("Education start date is required");
    }
    if (isApiRequest) {
        validateDisambiguatedOrg(affiliation);
    }
}
Also used : HashMap(java.util.HashMap) InvalidPutCodeException(org.orcid.core.exception.InvalidPutCodeException) OrcidValidationException(org.orcid.core.exception.OrcidValidationException) Visibility(org.orcid.jaxb.model.v3.dev1.common.Visibility) TransientNonEmptyString(org.orcid.jaxb.model.v3.dev1.common.TransientNonEmptyString)

Example 10 with InvalidPutCodeException

use of org.orcid.core.exception.InvalidPutCodeException in project ORCID-Source by ORCID.

the class ActivityValidator method validateGroupIdRecord.

public void validateGroupIdRecord(GroupIdRecord groupIdRecord, boolean createFlag, SourceEntity sourceEntity) {
    if (createFlag) {
        if (groupIdRecord.getPutCode() != null) {
            Map<String, String> params = new HashMap<String, String>();
            if (sourceEntity != null) {
                params.put("clientName", sourceEntity.getSourceName());
            }
            throw new InvalidPutCodeException(params);
        }
    }
    Pattern validGroupIdRegexPattern = Pattern.compile("(ringgold:|issn:|orcid-generated:|fundref:|publons:)([0-9a-zA-Z\\^._~:/?#\\[\\]@!$&amp;'()*+,;=-]){2,}");
    Matcher matcher = validGroupIdRegexPattern.matcher(groupIdRecord.getGroupId());
    if (!matcher.matches()) {
        throw new OrcidValidationException("Invalid group-id: '" + groupIdRecord.getGroupId() + "'");
    }
}
Also used : Pattern(java.util.regex.Pattern) HashMap(java.util.HashMap) InvalidPutCodeException(org.orcid.core.exception.InvalidPutCodeException) Matcher(java.util.regex.Matcher) OrcidValidationException(org.orcid.core.exception.OrcidValidationException) TransientNonEmptyString(org.orcid.jaxb.model.v3.dev1.common.TransientNonEmptyString)

Aggregations

InvalidPutCodeException (org.orcid.core.exception.InvalidPutCodeException)13 HashMap (java.util.HashMap)11 OrcidValidationException (org.orcid.core.exception.OrcidValidationException)11 Matcher (java.util.regex.Matcher)6 Pattern (java.util.regex.Pattern)6 ActivityIdentifierValidationException (org.orcid.core.exception.ActivityIdentifierValidationException)6 ActivityTitleValidationException (org.orcid.core.exception.ActivityTitleValidationException)6 ActivityTypeValidationException (org.orcid.core.exception.ActivityTypeValidationException)6 Visibility (org.orcid.jaxb.model.common_v2.Visibility)5 TransientNonEmptyString (org.orcid.jaxb.model.v3.dev1.common.TransientNonEmptyString)5 Arrays (java.util.Arrays)4 Map (java.util.Map)4 Collectors (java.util.stream.Collectors)4 Resource (javax.annotation.Resource)4 StringUtils (org.apache.commons.lang3.StringUtils)4 OrcidDuplicatedActivityException (org.orcid.core.exception.OrcidDuplicatedActivityException)4 VisibilityMismatchException (org.orcid.core.exception.VisibilityMismatchException)4 Visibility (org.orcid.jaxb.model.v3.dev1.common.Visibility)4 SiteConstants (org.orcid.persistence.constants.SiteConstants)4 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)4