Search in sources :

Example 21 with Resource

use of org.gluu.oxtrust.model.scim2.Resource in project oxTrust by GluuFederation.

the class Scim2GroupService method updateGroup.

public Group updateGroup(String id, Group group) throws Exception {
    GluuGroup gluuGroup = groupService.getGroupByInum(id);
    if (gluuGroup == null) {
        throw new EntryPersistenceException("Scim2GroupService.updateGroup(): " + "Resource " + id + " not found");
    } else {
        // Validate if attempting to update displayName of a different id
        if (gluuGroup.getDisplayName() != null) {
            GluuGroup groupToFind = new GluuGroup();
            groupToFind.setDisplayName(group.getDisplayName());
            List<GluuGroup> foundGroups = groupService.findGroups(groupToFind, 2);
            if (foundGroups != null && foundGroups.size() > 0) {
                for (GluuGroup foundGroup : foundGroups) {
                    if (foundGroup != null && !foundGroup.getInum().equalsIgnoreCase(gluuGroup.getInum())) {
                        throw new DuplicateEntryException("Cannot update displayName of a different id: " + group.getDisplayName());
                    }
                }
            }
        }
    }
    GluuGroup updatedGluuGroup = copyUtils2.copy(group, gluuGroup, true);
    if (group.getMembers().size() > 0) {
        serviceUtil.personMembersAdder(updatedGluuGroup, groupService.getDnForGroup(id));
    }
    log.info(" Setting meta: update group ");
    // Date should be in UTC format
    DateTimeFormatter dateTimeFormatter = ISODateTimeFormat.dateTime().withZoneUTC();
    Date dateLastModified = DateTime.now().toDate();
    updatedGluuGroup.setAttribute("oxTrustMetaLastModified", dateTimeFormatter.print(dateLastModified.getTime()));
    if (updatedGluuGroup.getAttribute("oxTrustMetaLocation") == null || (updatedGluuGroup.getAttribute("oxTrustMetaLocation") != null && updatedGluuGroup.getAttribute("oxTrustMetaLocation").isEmpty())) {
        String relativeLocation = "/scim/v2/Groups/" + id;
        updatedGluuGroup.setAttribute("oxTrustMetaLocation", relativeLocation);
    }
    // For custom script: update group
    if (externalScimService.isEnabled()) {
        externalScimService.executeScimUpdateGroupMethods(updatedGluuGroup);
    }
    groupService.updateGroup(updatedGluuGroup);
    log.debug(" group updated ");
    Group updatedGroup = copyUtils2.copy(updatedGluuGroup, null);
    return updatedGroup;
}
Also used : Group(org.gluu.oxtrust.model.scim2.Group) GluuGroup(org.gluu.oxtrust.model.GluuGroup) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) DuplicateEntryException(org.gluu.site.ldap.exception.DuplicateEntryException) GluuGroup(org.gluu.oxtrust.model.GluuGroup) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) Date(java.util.Date)

Aggregations

EntryPersistenceException (org.gluu.site.ldap.persistence.exception.EntryPersistenceException)18 DuplicateEntryException (org.gluu.site.ldap.exception.DuplicateEntryException)17 DefaultValue (javax.ws.rs.DefaultValue)15 HeaderParam (javax.ws.rs.HeaderParam)15 Produces (javax.ws.rs.Produces)15 ListResponse (org.gluu.oxtrust.model.scim2.ListResponse)15 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)13 Path (javax.ws.rs.Path)13 Response (javax.ws.rs.core.Response)13 VirtualListViewResponse (org.xdi.ldap.model.VirtualListViewResponse)13 URI (java.net.URI)12 PersonRequiredFieldsException (org.gluu.oxtrust.exception.PersonRequiredFieldsException)7 User (org.gluu.oxtrust.model.scim2.User)6 GET (javax.ws.rs.GET)5 Date (java.util.Date)4 Consumes (javax.ws.rs.Consumes)4 PUT (javax.ws.rs.PUT)4 GluuCustomPerson (org.gluu.oxtrust.model.GluuCustomPerson)4 GluuGroup (org.gluu.oxtrust.model.GluuGroup)4 Group (org.gluu.oxtrust.model.scim2.Group)4