Search in sources :

Example 6 with CatalogCategory

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

the class CatalogBuilder method createCategory.

public CatalogCategory createCategory(String tenant, CategoryDef def, NamedURI parentId) {
    String label = getMessage(getLabel(def));
    String title = getMessage(def.title);
    String description = getMessage(def.description);
    CatalogCategory category = new CatalogCategory();
    category.setTenant(tenant);
    category.setLabel(StringUtils.deleteWhitespace(label));
    category.setTitle(title);
    category.setDescription(description);
    category.setImage(def.image);
    category.setCatalogCategoryId(parentId);
    category.setSortedIndex(sortedIndexCounter++);
    category.setVersion(def.version);
    models.save(category);
    NamedURI myId = new NamedURI(category.getId(), category.getLabel());
    if (def.categories != null) {
        for (CategoryDef categoryDef : def.categories) {
            createCategory(tenant, categoryDef, myId);
        }
    }
    if (def.services != null) {
        for (ServiceDef serviceDef : def.services) {
            createService(serviceDef, myId);
        }
    }
    return category;
}
Also used : NamedURI(com.emc.storageos.db.client.model.NamedURI) CatalogCategory(com.emc.storageos.db.client.model.uimodels.CatalogCategory)

Example 7 with CatalogCategory

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

the class CatalogCategoryManagerImpl method upgradeCategory.

/**
 * Updates the category, adding and removing out off date sub categories and services
 * (Warning: This is recursive)
 */
private void upgradeCategory(CatalogCategory currentCategory, com.emc.sa.catalog.CategoryDef newCategory) {
    if (newCategory.categories != null) {
        List<CatalogCategory> subCategories = client.catalogCategories().findSubCatalogCategories(currentCategory.getId());
        for (com.emc.sa.catalog.CategoryDef newSubCategory : newCategory.categories) {
            String label = StringUtils.deleteWhitespace(getMessage(getLabel(newSubCategory)));
            CatalogCategory currentSubCategory = findSubCategory(subCategories, label);
            if (currentSubCategory == null) {
                log.info(String.format("CREATING Missing Category : %s for tenant:%s", label, currentCategory.getTenant()));
                createCategory(currentCategory.getTenant(), newSubCategory, currentCategory);
            } else {
                upgradeCategory(currentSubCategory, newSubCategory);
            }
        }
    }
    upgradeServices(currentCategory, newCategory);
}
Also used : CatalogCategory(com.emc.storageos.db.client.model.uimodels.CatalogCategory)

Example 8 with CatalogCategory

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

the class CatalogCategoryManagerImpl method restoreDefaultCatalog.

public void restoreDefaultCatalog(URI tenant) throws IOException {
    // Delete old catalog
    CatalogCategory catalog = getOrCreateRootCategory(tenant);
    deleteCatalogCategory(catalog);
    // Rebuild catalog
    catalog = getOrCreateRootCategory(tenant);
    CatalogBuilder builder = new CatalogBuilder(client, serviceDescriptors);
    builder.clearCategory(catalog);
    builder.buildCatalog(tenant.toString(), getDefaultCatalog());
}
Also used : CatalogCategory(com.emc.storageos.db.client.model.uimodels.CatalogCategory)

Example 9 with CatalogCategory

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

the class CatalogCategoryManagerImpl method getOrCreateRootCategory.

public CatalogCategory getOrCreateRootCategory(URI tenantId) {
    CatalogCategory root = null;
    root = client.catalogCategories().getRootCategory(tenantId.toString());
    if (root == null) {
        root = createDefaultCatalog(tenantId);
    }
    return root;
}
Also used : CatalogCategory(com.emc.storageos.db.client.model.uimodels.CatalogCategory)

Example 10 with CatalogCategory

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

the class CatalogCategoryTest method testPersistObject.

@Test
public void testPersistObject() throws Exception {
    _logger.info("Starting persist CatalogCategory test");
    ModelClient modelClient = getModelClient();
    CatalogCategory model = new CatalogCategory();
    model.setId(URIUtil.createId(CatalogCategory.class));
    model.setLabel("my label");
    URI parentUri = URIUtil.createId(CatalogCategory.class);
    NamedURI parentId = new NamedURI(parentUri, "my parent");
    model.setCatalogCategoryId(parentId);
    model.setDescription("my desc");
    model.setImage("my image");
    model.setTitle("my title");
    model.setTenant(DEFAULT_TENANT);
    modelClient.save(model);
    model = modelClient.catalogCategories().findById(model.getId());
    Assert.assertNotNull(model);
    Assert.assertEquals("my label", model.getLabel());
    Assert.assertEquals(parentId, model.getCatalogCategoryId());
    Assert.assertEquals("my desc", model.getDescription());
    Assert.assertEquals("my image", model.getImage());
    Assert.assertEquals("my title", model.getTitle());
    Assert.assertEquals(DEFAULT_TENANT, model.getTenant());
}
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) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) BaseModelTest(com.emc.sa.model.BaseModelTest) Test(org.junit.Test)

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