use of org.orcid.core.exception.GroupIdRecordNotFoundException 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();
}
}
use of org.orcid.core.exception.GroupIdRecordNotFoundException in project ORCID-Source by ORCID.
the class GroupIdRecordManagerImpl method deleteGroupIdRecord.
@Override
public void deleteGroupIdRecord(Long putCode) {
GroupIdRecordEntity existingEntity = groupIdRecordDao.find(putCode);
if (existingEntity != null) {
if (groupIdRecordDao.haveAnyPeerReview(existingEntity.getGroupId())) {
throw new OrcidElementCantBeDeletedException("Unable to delete group id because there are peer reviews associated to it");
}
orcidSecurityManager.checkSource(existingEntity);
groupIdRecordDao.remove(Long.valueOf(putCode));
} else {
throw new GroupIdRecordNotFoundException();
}
}
use of org.orcid.core.exception.GroupIdRecordNotFoundException in project ORCID-Source by ORCID.
the class GroupIdRecordManagerImpl method updateGroupIdRecord.
@Override
public GroupIdRecord updateGroupIdRecord(Long putCode, GroupIdRecord groupIdRecord) {
GroupIdRecordEntity existingEntity = groupIdRecordDao.find(putCode);
if (existingEntity == null) {
throw new GroupIdRecordNotFoundException();
}
SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
// Save the original source
String existingSourceId = existingEntity.getSourceId();
String existingClientSourceId = existingEntity.getClientSourceId();
activityValidator.validateGroupIdRecord(groupIdRecord, false, sourceEntity);
validateDuplicate(groupIdRecord);
orcidSecurityManager.checkSource(existingEntity);
GroupIdRecordEntity updatedEntity = jpaJaxbGroupIdRecordAdapter.toGroupIdRecordEntity(groupIdRecord);
updatedEntity.setDateCreated(existingEntity.getDateCreated());
// Be sure it doesn't overwrite the source
updatedEntity.setSourceId(existingSourceId);
updatedEntity.setClientSourceId(existingClientSourceId);
updatedEntity = groupIdRecordDao.merge(updatedEntity);
return jpaJaxbGroupIdRecordAdapter.toGroupIdRecord(updatedEntity);
}
Aggregations