use of com.emc.storageos.db.client.model.uimodels.CatalogCategory in project coprhd-controller by CoprHD.
the class CatalogCategoryFinder method getRootCategory.
public CatalogCategory getRootCategory(String tenant) {
CatalogCategory root = null;
if (StringUtils.isBlank(tenant)) {
return root;
}
List<NamedElement> catalogCategoryIds = client.findBy(CatalogCategory.class, CatalogCategory.CATALOG_CATEGORY_ID, URI.create(CatalogCategory.NO_PARENT));
List<CatalogCategory> tenantRootCategories = TenantUtils.filter(findByIds(toURIs(catalogCategoryIds)), tenant);
if (tenantRootCategories != null && !tenantRootCategories.isEmpty()) {
root = tenantRootCategories.get(0);
}
return root;
}
use of com.emc.storageos.db.client.model.uimodels.CatalogCategory in project coprhd-controller by CoprHD.
the class CatalogCategoryTest method createRoot.
private CatalogCategory createRoot(String tenant, String label) {
CatalogCategory model = new CatalogCategory();
model.setId(URIUtil.createId(CatalogCategory.class));
model.setLabel(label);
NamedURI parentId = new NamedURI(URI.create(CatalogCategory.NO_PARENT), "Home");
model.setCatalogCategoryId(parentId);
model.setDescription("my desc");
model.setImage("my image");
model.setTitle("my title");
model.setTenant(tenant);
return model;
}
use of com.emc.storageos.db.client.model.uimodels.CatalogCategory in project coprhd-controller by CoprHD.
the class CatalogCategoryTest method testReparentCategory.
@Test
public void testReparentCategory() throws Exception {
ModelClient modelClient = getModelClient();
CatalogCategory parent1 = createCategory("Parent1");
modelClient.save(parent1);
CatalogCategory parent2 = createCategory("Parent2");
modelClient.save(parent2);
CatalogCategory child = createCategory("Child");
setParent(parent1, child);
modelClient.save(child);
List<CatalogCategory> parent1Children = modelClient.catalogCategories().findSubCatalogCategories(parent1.getId());
Assert.assertEquals(1, parent1Children.size());
Assert.assertEquals(child.getId(), parent1Children.get(0).getId());
List<CatalogCategory> parent2Children = modelClient.catalogCategories().findSubCatalogCategories(parent2.getId());
Assert.assertEquals(0, parent2Children.size());
setParent(parent2, child);
modelClient.save(child);
parent1Children = modelClient.catalogCategories().findSubCatalogCategories(parent1.getId());
Assert.assertEquals(0, parent1Children.size());
parent2Children = modelClient.catalogCategories().findSubCatalogCategories(parent2.getId());
Assert.assertEquals(1, parent2Children.size());
Assert.assertEquals(child.getId(), parent2Children.get(0).getId());
}
use of com.emc.storageos.db.client.model.uimodels.CatalogCategory in project coprhd-controller by CoprHD.
the class CatalogCategoryTest method testFindSubCatalogCategories.
@Test
public void testFindSubCatalogCategories() {
_logger.info("Starting FindByLabel test");
ModelClient modelClient = getModelClient();
CatalogCategory root = createWithLabel("rooty");
CatalogCategory catalogCategory = createWithLabel("asdf");
catalogCategory.setCatalogCategoryId(new NamedURI(root.getId(), root.getLabel()));
modelClient.save(catalogCategory);
catalogCategory = createWithLabel("asdf2");
catalogCategory.setCatalogCategoryId(new NamedURI(root.getId(), root.getLabel()));
modelClient.save(catalogCategory);
catalogCategory = createWithLabel("asdf3");
catalogCategory.setCatalogCategoryId(new NamedURI(root.getId(), root.getLabel()));
modelClient.save(catalogCategory);
modelClient.save(root);
List<CatalogCategory> subCatalogCategories = modelClient.catalogCategories().findSubCatalogCategories(root.getId());
Assert.assertNotNull(subCatalogCategories);
Assert.assertEquals(3, subCatalogCategories.size());
}
use of com.emc.storageos.db.client.model.uimodels.CatalogCategory in project coprhd-controller by CoprHD.
the class CatalogServiceTest method testReparent.
@Test
public void testReparent() throws Exception {
_logger.info("Starting reparent CatalogService test");
ModelClient modelClient = getModelClient();
CatalogCategory parent1 = createCategoryWithLabel("Parent 1");
modelClient.save(parent1);
CatalogCategory parent2 = createCategoryWithLabel("Parent 2");
modelClient.save(parent2);
CatalogService service = createWithLabel("Service");
setParent(parent1, service);
modelClient.save(service);
List<CatalogService> parent1Children = modelClient.catalogServices().findByCatalogCategory(parent1.getId());
Assert.assertEquals(1, parent1Children.size());
Assert.assertEquals(service.getId(), parent1Children.get(0).getId());
List<CatalogService> parent2Children = modelClient.catalogServices().findByCatalogCategory(parent2.getId());
Assert.assertEquals(0, parent2Children.size());
setParent(parent2, service);
modelClient.save(service);
parent1Children = modelClient.catalogServices().findByCatalogCategory(parent1.getId());
Assert.assertEquals(0, parent1Children.size());
parent2Children = modelClient.catalogServices().findByCatalogCategory(parent2.getId());
Assert.assertEquals(1, parent2Children.size());
Assert.assertEquals(service.getId(), parent2Children.get(0).getId());
}
Aggregations