Search in sources :

Example 16 with CatalogCategory

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

the class CatalogServiceTest method testFindByCatalogCategory.

@Test
public void testFindByCatalogCategory() {
    _logger.info("Starting FindByCatalogCategory test");
    ModelClient modelClient = getModelClient();
    CatalogCategory root = createCategoryWithLabel("rooty");
    modelClient.save(root);
    CatalogService s1 = createWithLabel("s1");
    s1.setCatalogCategoryId(new NamedURI(root.getId(), root.getLabel()));
    modelClient.save(s1);
    CatalogCategory c1 = createCategoryWithLabel("asdf");
    c1.setCatalogCategoryId(new NamedURI(root.getId(), root.getLabel()));
    modelClient.save(c1);
    CatalogService s2 = createWithLabel("s2");
    s2.setCatalogCategoryId(new NamedURI(c1.getId(), c1.getLabel()));
    modelClient.save(s2);
    CatalogService s3 = createWithLabel("s3");
    s3.setCatalogCategoryId(new NamedURI(c1.getId(), c1.getLabel()));
    modelClient.save(s3);
    CatalogCategory c2 = createCategoryWithLabel("asdf2");
    c2.setCatalogCategoryId(new NamedURI(root.getId(), root.getLabel()));
    modelClient.save(c2);
    CatalogService s4 = createWithLabel("s4");
    s4.setCatalogCategoryId(new NamedURI(c2.getId(), c2.getLabel()));
    modelClient.save(s4);
    CatalogService s5 = createWithLabel("s5");
    s5.setCatalogCategoryId(new NamedURI(c2.getId(), c2.getLabel()));
    modelClient.save(s5);
    CatalogService s6 = createWithLabel("s6");
    s6.setCatalogCategoryId(new NamedURI(c2.getId(), c2.getLabel()));
    modelClient.save(s6);
    List<CatalogService> results = modelClient.catalogServices().findByCatalogCategory(root.getId());
    Assert.assertNotNull(results);
    Assert.assertEquals(1, results.size());
    results = modelClient.catalogServices().findByCatalogCategory(c1.getId());
    Assert.assertNotNull(results);
    Assert.assertEquals(2, results.size());
    results = modelClient.catalogServices().findByCatalogCategory(c2.getId());
    Assert.assertNotNull(results);
    Assert.assertEquals(3, results.size());
}
Also used : NamedURI(com.emc.storageos.db.client.model.NamedURI) ModelClient(com.emc.sa.model.dao.ModelClient) CatalogCategory(com.emc.storageos.db.client.model.uimodels.CatalogCategory) CatalogService(com.emc.storageos.db.client.model.uimodels.CatalogService) BaseModelTest(com.emc.sa.model.BaseModelTest) Test(org.junit.Test)

Example 17 with CatalogCategory

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

the class BasePermissionsHelper method checkForActiveCatalogCategoryAclsUsingUserGroup.

/**
 * Checks whether the given the user group is present the any of the
 * catalog category acls or not
 *
 * @param label to check if any tenants role-assignments uses user group or not.
 * @return set of URI's catalog category that uses the user group.
 */
public Set<URI> checkForActiveCatalogCategoryAclsUsingUserGroup(String label) {
    Set<URI> catalogCategoryUsingUserGroup = null;
    // Find all the configured Catalog category IDs based on the type.
    List<URI> catalogCategoryURIList = _dbClient.queryByType(CatalogCategory.class, true);
    if (catalogCategoryURIList == null || !catalogCategoryURIList.iterator().hasNext()) {
        _log.warn("There are no catalog category configured.");
        return catalogCategoryUsingUserGroup;
    }
    // Find all the configured Catalog category objects based on the given list of IDs.
    List<CatalogCategory> catalogCategories = _dbClient.queryObject(CatalogCategory.class, catalogCategoryURIList);
    if (CollectionUtils.isEmpty(catalogCategories)) {
        _log.error("Could not find the Catalog category objects for the Ids {}", catalogCategoryURIList.toString());
        return catalogCategoryUsingUserGroup;
    }
    catalogCategoryUsingUserGroup = new HashSet<URI>();
    for (CatalogCategory catalogCategory : catalogCategories) {
        if (catalogCategory == null) {
            _log.info("Invalid catalog category");
            continue;
        }
        if (CollectionUtils.isEmpty(catalogCategory.getAcls())) {
            _log.debug("ACLs not configured for Catalog category {}", catalogCategory.getLabel());
            continue;
        }
        Set<String> aclKeys = catalogCategory.getAcls().keySet();
        if (checkUserGroupWithPermissionKeys(label, aclKeys)) {
            catalogCategoryUsingUserGroup.add(catalogCategory.getId());
        }
    }
    return catalogCategoryUsingUserGroup;
}
Also used : CatalogCategory(com.emc.storageos.db.client.model.uimodels.CatalogCategory) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI)

Example 18 with CatalogCategory

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

the class CatalogCategoryService method updateRoleAssignments.

@PUT
@Path("/{id}/acl")
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SECURITY_ADMIN, Role.TENANT_ADMIN }, acls = { ACL.OWN }, blockProxies = true)
public ACLAssignments updateRoleAssignments(@PathParam("id") URI id, ACLAssignmentChanges changes) {
    CatalogCategory catalogCategory = catalogCategoryManager.getCatalogCategoryById(id);
    URI tenantId = uri(catalogCategory.getTenant());
    _permissionsHelper.updateACLs(catalogCategory, changes, new CatalogACLInputFilter(tenantId));
    catalogCategoryManager.updateCatalogCategory(catalogCategory);
    ;
    auditOpSuccess(OperationTypeEnum.MODIFY_CATALOG_CATEGORY_ACL, catalogCategory.getId().toString(), catalogCategory.getLabel(), changes);
    catalogConfigUtils.notifyCatalogAclChange();
    return getRoleAssignmentsResponse(id);
}
Also used : CatalogCategoryMapper.createNewCatalogCategory(com.emc.sa.api.mapper.CatalogCategoryMapper.createNewCatalogCategory) CatalogCategory(com.emc.storageos.db.client.model.uimodels.CatalogCategory) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) CatalogACLInputFilter(com.emc.sa.api.utils.CatalogACLInputFilter) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 19 with CatalogCategory

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

the class CatalogCategoryService method getRootCatalogCategory.

/**
 * Get the root catalog category for a tenant
 *
 * @prereq none
 * @brief Get Root Catalog Category
 * @return Root Catalog Category
 */
@GET
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("")
public CatalogCategoryRestRep getRootCatalogCategory(@DefaultValue("") @QueryParam(SearchConstants.TENANT_ID_PARAM) String tenantId) {
    StorageOSUser user = getUserFromContext();
    if (StringUtils.isBlank(tenantId)) {
        tenantId = user.getTenantId();
    }
    verifyAuthorizedInTenantOrg(uri(tenantId), user);
    CatalogCategory catalogCategory = catalogCategoryManager.getOrCreateRootCategory(uri(tenantId));
    return map(catalogCategory);
}
Also used : StorageOSUser(com.emc.storageos.security.authentication.StorageOSUser) CatalogCategoryMapper.createNewCatalogCategory(com.emc.sa.api.mapper.CatalogCategoryMapper.createNewCatalogCategory) CatalogCategory(com.emc.storageos.db.client.model.uimodels.CatalogCategory) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 20 with CatalogCategory

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

the class CatalogCategoryService method deactivateCatalogCategory.

/**
 * Deactivates the catalog category
 *
 * @param id the URN of a catalog category to be deactivated
 * @brief Deactivate Catalog Category
 * @return OK if deactivation completed successfully
 * @throws DatabaseException when a DB error occurs
 */
@POST
@Path("/{id}/deactivate")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.TENANT_ADMIN })
public Response deactivateCatalogCategory(@PathParam("id") URI id) throws DatabaseException {
    CatalogCategory catalogCategory = queryResource(id);
    ArgValidator.checkEntity(catalogCategory, id, true);
    catalogCategoryManager.deleteCatalogCategory(catalogCategory);
    auditOpSuccess(OperationTypeEnum.DELETE_CATALOG_CATEGORY, catalogCategory.auditParameters());
    return Response.ok().build();
}
Also used : CatalogCategoryMapper.createNewCatalogCategory(com.emc.sa.api.mapper.CatalogCategoryMapper.createNewCatalogCategory) CatalogCategory(com.emc.storageos.db.client.model.uimodels.CatalogCategory) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Aggregations

CatalogCategory (com.emc.storageos.db.client.model.uimodels.CatalogCategory)36 NamedURI (com.emc.storageos.db.client.model.NamedURI)12 CatalogCategoryMapper.createNewCatalogCategory (com.emc.sa.api.mapper.CatalogCategoryMapper.createNewCatalogCategory)9 Path (javax.ws.rs.Path)9 BaseModelTest (com.emc.sa.model.BaseModelTest)7 ModelClient (com.emc.sa.model.dao.ModelClient)7 CatalogService (com.emc.storageos.db.client.model.uimodels.CatalogService)7 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)7 URI (java.net.URI)7 Consumes (javax.ws.rs.Consumes)7 Produces (javax.ws.rs.Produces)7 Test (org.junit.Test)7 StorageOSUser (com.emc.storageos.security.authentication.StorageOSUser)6 PUT (javax.ws.rs.PUT)4 CatalogServiceField (com.emc.storageos.db.client.model.uimodels.CatalogServiceField)3 POST (javax.ws.rs.POST)3 CatalogACLInputFilter (com.emc.sa.api.utils.CatalogACLInputFilter)2 WorkflowServiceDescriptor (com.emc.sa.catalog.WorkflowServiceDescriptor)2 ServiceDescriptor (com.emc.sa.descriptor.ServiceDescriptor)2 GET (javax.ws.rs.GET)2