use of org.orcid.jaxb.model.v3.dev1.groupid.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.v3.dev1.groupid.GroupIdRecord in project ORCID-Source by ORCID.
the class GroupIdRecordManagerReadOnlyImpl method getGroupIdRecords.
@Override
public GroupIdRecords getGroupIdRecords(String pageSize, String pageNum) {
int pageNumInt = convertToInteger(pageNum);
int pageSizeInt = convertToInteger(pageSize);
GroupIdRecords records = new GroupIdRecords();
records.setPage(pageNumInt);
records.setPageSize(pageSizeInt);
List<GroupIdRecordEntity> recordEntities = groupIdRecordDao.getGroupIdRecords(pageSizeInt, pageNumInt);
List<GroupIdRecord> recordsReturned = jpaJaxbGroupIdRecordAdapter.toGroupIdRecords(recordEntities);
if (recordsReturned != null) {
records.setTotal(recordsReturned.size());
records.getGroupIdRecord().addAll(recordsReturned);
} else {
records.setTotal(0);
}
return records;
}
use of org.orcid.jaxb.model.v3.dev1.groupid.GroupIdRecord in project ORCID-Source by ORCID.
the class Api3_0_Dev1LastModifiedDatesHelper 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.v3.dev1.groupid.GroupIdRecord in project ORCID-Source by ORCID.
the class MemberV3ApiServiceDelegator_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());
}
use of org.orcid.jaxb.model.v3.dev1.groupid.GroupIdRecord in project ORCID-Source by ORCID.
the class MemberV3ApiServiceDelegator_GroupIdTest method testDeleteGroupIdRecord.
@Test(expected = GroupIdRecordNotFoundException.class)
public void testDeleteGroupIdRecord() {
SecurityContextTestUtils.setUpSecurityContextForGroupIdClientOnly();
// Verify if the record exists
Response response = serviceDelegator.viewGroupIdRecord(5L);
assertNotNull(response);
GroupIdRecord groupIdRecord = (GroupIdRecord) response.getEntity();
assertNotNull(groupIdRecord);
// Delete the record
serviceDelegator.deleteGroupIdRecord(5L);
// Throws a record not found exception
serviceDelegator.viewGroupIdRecord(5L);
}
Aggregations