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;
}
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);
}
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());
}
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;
}
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());
}
Aggregations