Search in sources :

Example 6 with GroupIdRecord

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

the class MemberV2ApiServiceDelegator_GroupIdTest method testUpdateGroupIdRecord.

@Test
public void testUpdateGroupIdRecord() {
    SecurityContextTestUtils.setUpSecurityContextForGroupIdClientOnly();
    Response response = serviceDelegator.viewGroupIdRecord(Long.valueOf("3"));
    assertNotNull(response);
    GroupIdRecord groupIdRecord = (GroupIdRecord) response.getEntity();
    assertNotNull(groupIdRecord);
    Utils.verifyLastModified(groupIdRecord.getLastModifiedDate());
    LastModifiedDate before = groupIdRecord.getLastModifiedDate();
    // Verify the name
    assertEquals(groupIdRecord.getName(), "TestGroup3");
    // Set a new name for update
    groupIdRecord.setName("TestGroup33");
    serviceDelegator.updateGroupIdRecord(groupIdRecord, Long.valueOf("3"));
    // Get the entity again and verify the name
    response = serviceDelegator.viewGroupIdRecord(Long.valueOf("3"));
    assertNotNull(response);
    GroupIdRecord groupIdRecordNew = (GroupIdRecord) response.getEntity();
    assertNotNull(groupIdRecordNew);
    Utils.verifyLastModified(groupIdRecordNew.getLastModifiedDate());
    assertTrue(groupIdRecordNew.getLastModifiedDate().after(before));
    // Verify the name
    assertEquals(groupIdRecordNew.getName(), "TestGroup33");
}
Also used : Response(javax.ws.rs.core.Response) LastModifiedDate(org.orcid.jaxb.model.common_v2.LastModifiedDate) GroupIdRecord(org.orcid.jaxb.model.groupid_v2.GroupIdRecord) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 7 with GroupIdRecord

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

the class Api2_0_rc2_LastModifiedDatesHelper method calculateLatest.

public static Date calculateLatest(GroupIdRecords groupIdRecords) {
    Date latestAct = null;
    if (groupIdRecords != null && groupIdRecords.getGroupIdRecord() != null && !groupIdRecords.getGroupIdRecord().isEmpty()) {
        XMLGregorianCalendar latest = groupIdRecords.getGroupIdRecord().get(0).getLastModifiedDate().getValue();
        for (GroupIdRecord groupid : groupIdRecords.getGroupIdRecord()) {
            if (latest.compare(groupid.getLastModifiedDate().getValue()) == -1) {
                latest = groupid.getLastModifiedDate().getValue();
            }
        }
        latestAct = latest.toGregorianCalendar().getTime();
        groupIdRecords.setLastModifiedDate(new LastModifiedDate(latest));
    }
    return latestAct;
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) LastModifiedDate(org.orcid.jaxb.model.common_rc2.LastModifiedDate) GroupIdRecord(org.orcid.jaxb.model.groupid_rc2.GroupIdRecord) LastModifiedDate(org.orcid.jaxb.model.common_rc2.LastModifiedDate) Date(java.util.Date)

Example 8 with GroupIdRecord

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

the class Api2_0_LastModifiedDatesHelper method calculateLastModified.

public static void calculateLastModified(GroupIdRecords groupIdRecords) {
    if (groupIdRecords != null && groupIdRecords.getGroupIdRecord() != null && !groupIdRecords.getGroupIdRecord().isEmpty()) {
        LastModifiedDate latest = null;
        for (GroupIdRecord groupid : groupIdRecords.getGroupIdRecord()) {
            if (groupid.getLastModifiedDate() != null && groupid.getLastModifiedDate().after(latest)) {
                latest = groupid.getLastModifiedDate();
            }
        }
        groupIdRecords.setLastModifiedDate(latest);
    }
}
Also used : LastModifiedDate(org.orcid.jaxb.model.common_v2.LastModifiedDate) GroupIdRecord(org.orcid.jaxb.model.groupid_v2.GroupIdRecord)

Example 9 with GroupIdRecord

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

the class GroupIdRecordManagerTest method testCreateDuplicateGroupIdRecords.

@Test
public void testCreateDuplicateGroupIdRecords() {
    GroupIdRecord g1 = new GroupIdRecord();
    g1.setDescription("Description");
    g1.setGroupId("orcid-generated:valid-group-id#1");
    g1.setName("Group # " + System.currentTimeMillis());
    g1.setType("publisher");
    //Create the first one
    g1 = groupIdRecordManager.createGroupIdRecord(g1);
    Long putCode = g1.getPutCode();
    assertNotNull(g1.getSource());
    assertNotNull(g1.getSource().getSourceClientId());
    assertEquals(CLIENT_ID, g1.getSource().getSourceClientId().getPath());
    //Try to create a duplicate
    try {
        g1.setPutCode(null);
        g1 = groupIdRecordManager.createGroupIdRecord(g1);
        fail();
    } catch (DuplicatedGroupIdRecordException e) {
    } catch (Exception e) {
        fail();
    }
    //Try to create a UPPER duplicate
    try {
        g1.setPutCode(null);
        g1.setGroupId("orcid-generated:VALID-GROUP-ID#1");
        g1 = groupIdRecordManager.createGroupIdRecord(g1);
        fail();
    } catch (DuplicatedGroupIdRecordException e) {
    } catch (Exception e) {
        fail();
    }
    //Try to create a duplicate mixed cases
    try {
        g1.setPutCode(null);
        g1.setGroupId("orcid-generated:VaLiD-GrOuP-Id#1");
        g1 = groupIdRecordManager.createGroupIdRecord(g1);
        fail();
    } catch (DuplicatedGroupIdRecordException e) {
    } catch (Exception e) {
        fail();
    }
    //Create a different one
    g1.setPutCode(null);
    g1.setGroupId("orcid-generated:valid-group-id#2");
    GroupIdRecord g2 = groupIdRecordManager.createGroupIdRecord(g1);
    assertNotNull(g2);
    assertNotNull(g2.getPutCode());
    assertTrue(!g2.getPutCode().equals(putCode));
    assertEquals("orcid-generated:valid-group-id#2", g2.getGroupId());
    assertNotNull(g2.getSource());
    assertNotNull(g2.getSource().getSourceClientId());
    assertEquals(CLIENT_ID, g2.getSource().getSourceClientId().getPath());
    //Try to create again a duplicate for any of the two existing
    try {
        g1.setPutCode(null);
        g1.setGroupId("orcid-generated:VaLiD-GrOuP-Id#1");
        g1 = groupIdRecordManager.createGroupIdRecord(g1);
        fail();
    } catch (DuplicatedGroupIdRecordException e) {
    } catch (Exception e) {
        fail();
    }
    try {
        g1.setPutCode(null);
        g1.setGroupId("orcid-generated:VaLiD-GrOuP-Id#2");
        g1 = groupIdRecordManager.createGroupIdRecord(g1);
        fail();
    } catch (DuplicatedGroupIdRecordException e) {
    } catch (Exception e) {
        fail();
    }
    groupIdRecordManager.deleteGroupIdRecord(putCode);
    groupIdRecordManager.deleteGroupIdRecord(g2.getPutCode());
}
Also used : GroupIdRecord(org.orcid.jaxb.model.groupid_v2.GroupIdRecord) DuplicatedGroupIdRecordException(org.orcid.core.exception.DuplicatedGroupIdRecordException) InvalidPutCodeException(org.orcid.core.exception.InvalidPutCodeException) OrcidValidationException(org.orcid.core.exception.OrcidValidationException) DuplicatedGroupIdRecordException(org.orcid.core.exception.DuplicatedGroupIdRecordException) GroupIdRecordNotFoundException(org.orcid.core.exception.GroupIdRecordNotFoundException) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Example 10 with GroupIdRecord

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

the class ActivityValidatorTest method validateGroupId_invalidPutCodeTest.

@Test(expected = InvalidPutCodeException.class)
public void validateGroupId_invalidPutCodeTest() {
    SourceEntity source = mock(SourceEntity.class);
    when(source.getSourceName()).thenReturn("source name");
    GroupIdRecord g = getGroupIdRecord();
    g.setPutCode(1L);
    activityValidator.validateGroupIdRecord(g, true, source);
}
Also used : SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) GroupIdRecord(org.orcid.jaxb.model.groupid_v2.GroupIdRecord) 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