Search in sources :

Example 21 with UserGroup

use of com.emc.storageos.db.client.model.UserGroup in project coprhd-controller by CoprHD.

the class ApiTestUserGroup method testUserGroupEditByChangingDomain.

@Test
public void testUserGroupEditByChangingDomain() {
    final String testName = "testUserGroupEditByChangingDomain - ";
    createDefaultAuthnProvider(testName + DEFAULT_AUTH_PROVIDER_CREATION);
    UserGroupCreateParam createParam = getDefaultUserGroupCreateParam();
    ClientResponse clientUserGroupCreateResp = rSys.path(getTestApi()).post(ClientResponse.class, createParam);
    UserGroupRestRep userGroupCreateResp = validateUserGroupCreateSuccess(createParam, clientUserGroupCreateResp);
    UserGroup createdUserGroup = buildUserGroupFromRestRep(userGroupCreateResp);
    UserGroupUpdateParam updateParam = getUserGroupUpdateParamFromRestRep(userGroupCreateResp);
    // Clear both add and remove attributes. This should be successful.
    updateParam.getAddAttributes().clear();
    updateParam.getRemoveAttributes().clear();
    // Change the domain.
    updateParam.setDomain(getSecondDomain());
    String testEditAPI = getTestEditApi(userGroupCreateResp.getId());
    ClientResponse clientUserGroupEditResp = rSys.path(testEditAPI).put(ClientResponse.class, updateParam);
    validateUserGroupEditSuccess(createdUserGroup, updateParam, clientUserGroupEditResp);
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) UserGroup(com.emc.storageos.db.client.model.UserGroup) Test(org.junit.Test)

Example 22 with UserGroup

use of com.emc.storageos.db.client.model.UserGroup in project coprhd-controller by CoprHD.

the class UserGroupService method getUserGroupIds.

/**
 * Gets the user group list (of URNs).
 *
 * @brief List active user group URNs
 * @return All the user groups details as UserGroupList
 * @see UserGroupList
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public UserGroupList getUserGroupIds() {
    checkCompatibleVersion();
    checkIfUserHasPermissions();
    NamedElementQueryResultList userGroups = new NamedElementQueryResultList();
    List<URI> uris = _dbClient.queryByType(UserGroup.class, true);
    List<UserGroup> configs = _dbClient.queryObject(UserGroup.class, uris);
    List<NamedElementQueryResultList.NamedElement> elements = new ArrayList<NamedElementQueryResultList.NamedElement>(configs.size());
    for (UserGroup p : configs) {
        elements.add(NamedElementQueryResultList.NamedElement.createElement(p.getId(), p.getLabel()));
    }
    userGroups.setResult(elements.iterator());
    UserGroupList list = new UserGroupList();
    list.getUserGroups().addAll(DbObjectMapper.map(ResourceTypeEnum.USER_GROUP, userGroups));
    return list;
}
Also used : NamedElementQueryResultList(com.emc.storageos.db.client.constraint.NamedElementQueryResultList) URI(java.net.URI) UserGroup(com.emc.storageos.db.client.model.UserGroup) MapUserGroup(com.emc.storageos.api.mapper.functions.MapUserGroup)

Example 23 with UserGroup

use of com.emc.storageos.db.client.model.UserGroup in project coprhd-controller by CoprHD.

the class UserGroupService method getUserGroupById.

/**
 * @param id the URN of a ViPR UserGroup to get details from
 * @param checkInactive If true, make sure that provider is not inactive
 * @return UserGroup object for the given id
 */
private UserGroup getUserGroupById(URI id, boolean checkInactive) {
    if (id == null) {
        _log.debug("User Group ID is NULL");
        return null;
    }
    _log.debug("User Group ID is {}", id.toString());
    UserGroup userGroup = _permissionsHelper.getObjectById(id, UserGroup.class);
    ArgValidator.checkEntity(userGroup, id, isIdEmbeddedInURL(id), checkInactive);
    return userGroup;
}
Also used : UserGroup(com.emc.storageos.db.client.model.UserGroup) MapUserGroup(com.emc.storageos.api.mapper.functions.MapUserGroup)

Example 24 with UserGroup

use of com.emc.storageos.db.client.model.UserGroup in project coprhd-controller by CoprHD.

the class UserGroupMapper method map.

public static final UserGroup map(UserGroupCreateParam from) {
    if (from == null) {
        _log.info("Invalid user group create param");
        return null;
    }
    UserGroup to = new UserGroup();
    to.setDomain(from.getDomain());
    to.setLabel(from.getLabel());
    Map<String, UserAttributeParam> attributeParamMap = new TreeMap<String, UserAttributeParam>(String.CASE_INSENSITIVE_ORDER);
    if (!CollectionUtils.isEmpty(from.getAttributes())) {
        for (UserAttributeParam attribute : from.getAttributes()) {
            UserAttributeParam userAttributeParam = attributeParamMap.get(attribute.getKey());
            if (userAttributeParam == null) {
                userAttributeParam = new UserAttributeParam(attribute.getKey(), attribute.getValues());
                attributeParamMap.put(attribute.getKey(), userAttributeParam);
            } else {
                userAttributeParam.getValues().addAll(attribute.getValues());
            }
        }
    } else {
        _log.error("Empty attributes list in user group create param {}", from.getLabel());
    }
    if (!CollectionUtils.isEmpty(attributeParamMap)) {
        for (UserAttributeParam attribute : attributeParamMap.values()) {
            to.getAttributes().add(attribute.toString());
        }
    } else {
        _log.warn("Mapping from UserGroupCreateParam {} to UserGroup did not create any attributes list", from.getLabel());
    }
    return to;
}
Also used : TreeMap(java.util.TreeMap) UserGroup(com.emc.storageos.db.client.model.UserGroup) UserAttributeParam(com.emc.storageos.model.usergroup.UserAttributeParam)

Aggregations

UserGroup (com.emc.storageos.db.client.model.UserGroup)24 MapUserGroup (com.emc.storageos.api.mapper.functions.MapUserGroup)7 StringSet (com.emc.storageos.db.client.model.StringSet)5 StringSetMap (com.emc.storageos.db.client.model.StringSetMap)4 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)3 ClientResponse (com.sun.jersey.api.client.ClientResponse)3 Test (org.junit.Test)3 UserAttributeParam (com.emc.storageos.model.usergroup.UserAttributeParam)2 URI (java.net.URI)2 NamedElementQueryResultList (com.emc.storageos.db.client.constraint.NamedElementQueryResultList)1 StorageOSPrincipal (com.emc.storageos.security.validator.StorageOSPrincipal)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1