use of io.jans.orm.exception.operation.DuplicateEntryException in project jans by JanssenProject.
the class PersonService method addPerson.
// TODO: Review this methods. We need to check if uid is unique in outside method
public void addPerson(GluuCustomPerson person) throws Exception {
try {
List<GluuCustomPerson> persons = getPersonsByUid(person.getUid());
if (persons == null || persons.size() == 0) {
person.setCreationDate(new Date());
attributeService.applyMetaData(person.getCustomAttributes());
persistenceEntryManager.persist(person);
} else {
throw new DuplicateEntryException("Duplicate UID value: " + person.getUid());
}
} catch (Exception e) {
if (e.getCause().getMessage().contains("unique attribute conflict was detected for attribute mail")) {
throw new DuplicateEmailException("Email Already Registered");
} else {
throw new Exception("Duplicate UID value: " + person.getUid());
}
}
}
use of io.jans.orm.exception.operation.DuplicateEntryException in project jans by JanssenProject.
the class NativePersistenceCacheProvider method putImpl.
private void putImpl(String key, Object object, Date creationDate, int expirationInSeconds) {
Calendar expirationDate = Calendar.getInstance();
expirationDate.setTime(creationDate);
expirationDate.add(Calendar.SECOND, expirationInSeconds);
String originalKey = key;
key = hashKey(key);
NativePersistenceCacheEntity entity = new NativePersistenceCacheEntity();
entity.setTtl(expirationInSeconds);
entity.setData(asString(object));
entity.setId(key);
entity.setDn(createDn(key));
entity.setCreationDate(creationDate);
entity.setExpirationDate(expirationDate.getTime());
entity.setDeletable(true);
try {
if (attemptUpdateBeforeInsert) {
entryManager.merge(entity);
} else {
if (!skipRemoveBeforePut) {
silentlyRemoveEntityIfExists(entity.getDn());
}
entryManager.persist(entity);
}
} catch (EntryPersistenceException e) {
if (e.getCause() instanceof DuplicateEntryException) {
// on duplicate, remove entry and try to persist again
try {
silentlyRemoveEntityIfExists(entity.getDn());
entryManager.persist(entity);
return;
} catch (Exception ex) {
log.error("Failed to retry put entry, key: " + originalKey + ", hashedKey: " + key + ", message: " + ex.getMessage(), ex);
}
}
if (attemptUpdateBeforeInsert) {
try {
entryManager.persist(entity);
return;
} catch (Exception ex) {
log.error("Failed to retry put entry, key: " + originalKey + ", hashedKey: " + key + ", message: " + ex.getMessage(), ex);
}
}
log.error("Failed to put entry, key: " + originalKey + ", hashedKey: " + key + ", message: " + e.getMessage(), e);
} catch (Exception e) {
// log as trace since it is perfectly valid that entry is removed by timer for example
log.error("Failed to put entry, key: " + originalKey + ", hashedKey: " + key + ", message: " + e.getMessage(), e);
}
}
use of io.jans.orm.exception.operation.DuplicateEntryException in project jans by JanssenProject.
the class GroupWebService method checkDisplayNameExistence.
private void checkDisplayNameExistence(String displayName, String id) throws DuplicateEntryException {
// Validate if there is an attempt to supply a displayName already in use by a
// group other than current
GluuGroup groupToFind = new GluuGroup();
groupToFind.setDisplayName(displayName);
List<GluuGroup> list = groupService.findGroups(groupToFind, 2);
if (list != null && list.stream().anyMatch(g -> !g.getInum().equals(id))) {
throw new DuplicateEntryException("Duplicate group displayName value: " + displayName);
}
}
use of io.jans.orm.exception.operation.DuplicateEntryException in project jans by JanssenProject.
the class GroupService method addGroup.
public void addGroup(GluuGroup group) throws Exception {
GluuGroup displayNameGroup = new GluuGroup();
displayNameGroup.setDisplayName(group.getDisplayName());
List<GluuGroup> groups = findGroups(displayNameGroup, 1);
if (groups == null || groups.size() == 0) {
persistenceEntryManager.persist(group);
} else {
throw new DuplicateEntryException("Duplicate displayName: " + group.getDisplayName());
}
}
Aggregations