Search in sources :

Example 1 with DuplicateEntryException

use of org.gluu.persist.exception.operation.DuplicateEntryException in project oxTrust by GluuFederation.

the class UserWebServiceDecorator method updateUser.

public Response updateUser(UserResource user, String id, String attrsList, String excludedAttrsList) {
    Response response;
    try {
        // Check if the ids match in case the user coming has one
        if (user.getId() != null && !user.getId().equals(id))
            throw new SCIMException("Parameter id does not match with id attribute of User");
        response = validateExistenceOfUser(id);
        if (response == null) {
            executeValidation(user, true);
            if (StringUtils.isNotEmpty(user.getUserName()))
                checkUidExistence(user.getUserName(), id);
            ScimResourceUtil.adjustPrimarySubAttributes(user);
            // Proceed with actual implementation of updateUser method
            response = service.updateUser(user, id, attrsList, excludedAttrsList);
        }
    } catch (DuplicateEntryException e) {
        log.error(e.getMessage());
        response = getErrorResponse(Response.Status.CONFLICT, ErrorScimType.UNIQUENESS, e.getMessage());
    } catch (SCIMException e) {
        log.error("Validation check at updateUser returned: {}", e.getMessage());
        response = getErrorResponse(Response.Status.BAD_REQUEST, ErrorScimType.INVALID_VALUE, e.getMessage());
    }
    return response;
}
Also used : Response(javax.ws.rs.core.Response) SCIMException(org.gluu.oxtrust.model.exception.SCIMException) DuplicateEntryException(org.gluu.persist.exception.operation.DuplicateEntryException)

Example 2 with DuplicateEntryException

use of org.gluu.persist.exception.operation.DuplicateEntryException in project oxTrust by GluuFederation.

the class GroupService method addGroup.

/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.gluu.oxtrust.ldap.service.IGroupService#addGroup(org.gluu.oxtrust.model.
	 * GluuGroup)
	 */
@Override
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());
    }
}
Also used : DuplicateEntryException(org.gluu.persist.exception.operation.DuplicateEntryException) GluuGroup(org.gluu.oxtrust.model.GluuGroup)

Example 3 with DuplicateEntryException

use of org.gluu.persist.exception.operation.DuplicateEntryException in project oxTrust by GluuFederation.

the class PersonService method addPerson.

/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.gluu.oxtrust.ldap.service.IPersonService#addPerson(org.gluu.oxtrust.model
	 * .GluuCustomPerson)
	 */
// TODO: Review this methods. We need to check if uid is unique in outside
// method
@Override
public void addPerson(GluuCustomPerson person) throws Exception {
    try {
        List<GluuCustomPerson> persons = getPersonsByUid(person.getUid());
        if (persons == null || persons.size() == 0) {
            person.setCreationDate(new Date());
            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());
        }
    }
}
Also used : GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) DuplicateEmailException(org.gluu.oxtrust.exception.DuplicateEmailException) DuplicateEntryException(org.gluu.persist.exception.operation.DuplicateEntryException) Date(java.util.Date) DuplicateEmailException(org.gluu.oxtrust.exception.DuplicateEmailException) DuplicateEntryException(org.gluu.persist.exception.operation.DuplicateEntryException)

Example 4 with DuplicateEntryException

use of org.gluu.persist.exception.operation.DuplicateEntryException in project oxTrust by GluuFederation.

the class GroupService method addGroup.

/* (non-Javadoc)
	 * @see org.gluu.oxtrust.ldap.service.IGroupService#addGroup(org.gluu.oxtrust.model.GluuGroup)
	 */
@Override
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) {
        ldapEntryManager.persist(group);
    } else {
        throw new DuplicateEntryException("Duplicate displayName: " + group.getDisplayName());
    }
}
Also used : DuplicateEntryException(org.gluu.persist.exception.operation.DuplicateEntryException) GluuGroup(org.gluu.oxtrust.model.GluuGroup)

Example 5 with DuplicateEntryException

use of org.gluu.persist.exception.operation.DuplicateEntryException in project oxTrust by GluuFederation.

the class PersonService method addPerson.

/* (non-Javadoc)
     * @see org.gluu.oxtrust.ldap.service.IPersonService#addPerson(org.gluu.oxtrust.model.GluuCustomPerson)
     */
// TODO: Review this methods. We need to check if uid is unique in outside
// method
@Override
public void addPerson(GluuCustomPerson person) throws Exception {
    GluuCustomPerson uidPerson = new GluuCustomPerson();
    uidPerson.setUid(person.getUid());
    List<GluuCustomPerson> persons = findPersons(uidPerson, 1);
    if (persons == null || persons.size() == 0) {
        person.setCreationDate(new Date());
        ldapEntryManager.persist(person);
    } else {
        throw new DuplicateEntryException("Duplicate UID value: " + person.getUid());
    }
}
Also used : GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) DuplicateEntryException(org.gluu.persist.exception.operation.DuplicateEntryException) Date(java.util.Date)

Aggregations

DuplicateEntryException (org.gluu.persist.exception.operation.DuplicateEntryException)10 Response (javax.ws.rs.core.Response)4 SCIMException (org.gluu.oxtrust.model.exception.SCIMException)4 GluuGroup (org.gluu.oxtrust.model.GluuGroup)3 Date (java.util.Date)2 GluuCustomPerson (org.gluu.oxtrust.model.GluuCustomPerson)2 Calendar (java.util.Calendar)1 DuplicateEmailException (org.gluu.oxtrust.exception.DuplicateEmailException)1 EntryPersistenceException (org.gluu.persist.exception.EntryPersistenceException)1