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");
}
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;
}
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);
}
}
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());
}
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);
}
Aggregations