Search in sources :

Example 16 with GroupIdRecord

use of org.orcid.jaxb.model.groupid_rc3.GroupIdRecord 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 17 with GroupIdRecord

use of org.orcid.jaxb.model.groupid_rc3.GroupIdRecord in project ORCID-Source by ORCID.

the class ValidateV2RC1SamplesTest method validateGroupIdValue.

@Test
public void validateGroupIdValue() throws SAXException, IOException, JAXBException {
    SchemaFactory factory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
    Schema schema = factory.newSchema(getClass().getResource("/group-id-2.0_rc1/group-id-2.0_rc1.xsd"));
    Validator validator = schema.newValidator();
    char[] alphabet = "abcdefghijklmnopqrstuvwxyz".toCharArray();
    char[] upperAlphabet = "abcdefghijklmnopqrstuvwxyz".toUpperCase().toCharArray();
    char[] numbers = "0123456789".toCharArray();
    char[] validCharacters = "^._~:/?#[]@!$&'()*+,;=-".toCharArray();
    //All valid characters
    char[] allValid = ArrayUtils.addAll(alphabet, upperAlphabet);
    allValid = ArrayUtils.addAll(allValid, numbers);
    allValid = ArrayUtils.addAll(allValid, validCharacters);
    String invalidCharactersString = "{}\"<>\\";
    char[] invalidCharacters = invalidCharactersString.toCharArray();
    //All valid and non valid characters
    char[] allWithInvalids = ArrayUtils.addAll(allValid, invalidCharacters);
    GroupIdRecord g1 = new GroupIdRecord();
    g1.setDescription("description");
    g1.setType("newsletter");
    System.out.println("Validating group_id agains a list of 3000 valid values");
    for (int i = 0; i < 3000; i++) {
        String randomValue = "orcid-generated:" + RandomStringUtils.random(200, allValid);
        g1.setName(randomValue);
        g1.setGroupId(randomValue);
        JAXBContext context;
        context = JAXBContext.newInstance(GroupIdRecord.class);
        Source source = new JAXBSource(context, g1);
        try {
            validator.validate(source);
        } catch (Exception e) {
            fail("fail validating: " + randomValue + " on iteration " + i);
        }
    }
    System.out.println("Validating group_id agains a list of 3000 invalid values");
    for (int i = 0; i < 3000; i++) {
        String randomValue = "orcid-generated:" + RandomStringUtils.random(200, allWithInvalids);
        boolean regenerateString = true;
        do {
            for (int j = 0; j < randomValue.length(); j++) {
                if (invalidCharactersString.contains(String.valueOf(randomValue.charAt(j)))) {
                    regenerateString = false;
                    break;
                }
            }
            if (regenerateString) {
                randomValue += RandomStringUtils.random(3, invalidCharacters);
                regenerateString = false;
            }
        } while (regenerateString);
        g1.setName(randomValue);
        g1.setGroupId(randomValue);
        JAXBContext context;
        context = JAXBContext.newInstance(GroupIdRecord.class);
        Source source = new JAXBSource(context, g1);
        try {
            validator.validate(source);
            fail(randomValue + " should not be vaild according to the XSD on iteration " + i);
        } catch (Exception e) {
        }
    }
}
Also used : SchemaFactory(javax.xml.validation.SchemaFactory) GroupIdRecord(org.orcid.jaxb.model.groupid_rc1.GroupIdRecord) Schema(javax.xml.validation.Schema) JAXBContext(javax.xml.bind.JAXBContext) Validator(javax.xml.validation.Validator) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) JAXBSource(javax.xml.bind.util.JAXBSource) JAXBSource(javax.xml.bind.util.JAXBSource) IOException(java.io.IOException) JAXBException(javax.xml.bind.JAXBException) SAXException(org.xml.sax.SAXException) MarshallingTest(org.orcid.jaxb.model.notification.custom.MarshallingTest) Test(org.junit.Test)

Example 18 with GroupIdRecord

use of org.orcid.jaxb.model.groupid_rc3.GroupIdRecord in project ORCID-Source by ORCID.

the class MemberV2ApiServiceDelegatorImpl method viewGroupIdRecord.

@Override
public Response viewGroupIdRecord(Long putCode) {
    orcidSecurityManager.checkScopes(ScopePathType.GROUP_ID_RECORD_READ);
    GroupIdRecord record = groupIdRecordManagerReadOnly.getGroupIdRecord(putCode);
    return Response.ok(record).build();
}
Also used : GroupIdRecord(org.orcid.jaxb.model.groupid_v2.GroupIdRecord)

Example 19 with GroupIdRecord

use of org.orcid.jaxb.model.groupid_rc3.GroupIdRecord in project ORCID-Source by ORCID.

the class MemberV2ApiServiceDelegator_GroupIdTest method testGetGroupIdRecord.

@Test
public void testGetGroupIdRecord() {
    SecurityContextTestUtils.setUpSecurityContextForGroupIdClientOnly();
    Response response = serviceDelegator.viewGroupIdRecord(Long.valueOf("2"));
    assertNotNull(response);
    GroupIdRecord groupIdRecord = (GroupIdRecord) response.getEntity();
    assertNotNull(groupIdRecord);
    Utils.verifyLastModified(groupIdRecord.getLastModifiedDate());
    assertEquals(Long.valueOf(2), groupIdRecord.getPutCode());
    assertEquals("issn:0000002", groupIdRecord.getGroupId());
    assertEquals("TestGroup2", groupIdRecord.getName());
    assertEquals("TestDescription2", groupIdRecord.getDescription());
    assertEquals("publisher", groupIdRecord.getType());
}
Also used : Response(javax.ws.rs.core.Response) GroupIdRecord(org.orcid.jaxb.model.groupid_v2.GroupIdRecord) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 20 with GroupIdRecord

use of org.orcid.jaxb.model.groupid_rc3.GroupIdRecord in project ORCID-Source by ORCID.

the class MemberV2ApiServiceDelegator_GeneralTest method testOrcidProfileCreateCanViewAndCreateGroupIds.

@Test
public void testOrcidProfileCreateCanViewAndCreateGroupIds() {
    SecurityContextTestUtils.setUpSecurityContextForClientOnly();
    try {
        serviceDelegator.viewGroupIdRecord(1L);
    } catch (Exception e) {
        fail();
    }
    try {
        serviceDelegator.viewGroupIdRecords("10", "1");
    } catch (Exception e) {
        fail();
    }
    GroupIdRecord groupIdRecord = Utils.getGroupIdRecord();
    try {
        serviceDelegator.createGroupIdRecord(groupIdRecord);
    } catch (Exception e) {
        fail();
    }
    GroupIdRecordEntity toDelete = groupIdRecordDao.findByGroupId(groupIdRecord.getGroupId());
    groupIdRecordDao.remove(toDelete.getId());
}
Also used : GroupIdRecord(org.orcid.jaxb.model.groupid_v2.GroupIdRecord) NoResultException(javax.persistence.NoResultException) OrcidBadRequestException(org.orcid.core.exception.OrcidBadRequestException) AccessControlException(java.security.AccessControlException) OrcidAccessControlException(org.orcid.core.exception.OrcidAccessControlException) GroupIdRecordEntity(org.orcid.persistence.jpa.entities.GroupIdRecordEntity) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Aggregations

GroupIdRecord (org.orcid.jaxb.model.groupid_v2.GroupIdRecord)22 Test (org.junit.Test)12 DBUnitTest (org.orcid.test.DBUnitTest)4 Response (javax.ws.rs.core.Response)3 BaseTest (org.orcid.core.BaseTest)3 DuplicatedGroupIdRecordException (org.orcid.core.exception.DuplicatedGroupIdRecordException)3 GroupIdRecordNotFoundException (org.orcid.core.exception.GroupIdRecordNotFoundException)3 InvalidPutCodeException (org.orcid.core.exception.InvalidPutCodeException)3 OrcidValidationException (org.orcid.core.exception.OrcidValidationException)3 PeerReview (org.orcid.jaxb.model.record_v2.PeerReview)3 GroupIdRecordEntity (org.orcid.persistence.jpa.entities.GroupIdRecordEntity)3 ClientResponse (com.sun.jersey.api.client.ClientResponse)2 URISyntaxException (java.net.URISyntaxException)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 LastModifiedDate (org.orcid.jaxb.model.common_v2.LastModifiedDate)2 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)2 IOException (java.io.IOException)1 URI (java.net.URI)1 AccessControlException (java.security.AccessControlException)1