Search in sources :

Example 81 with NamedURI

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

the class CustomServicesDBHelper method update.

/**
 * Given an ID, update param, DB column family, and primitive type save a new primitive to the DB
 * and return the primitive type java object
 *
 * @param mapper The primitive mapper
 * @param dbModel The DB column family class
 * @param resourceType The resource
 * @param primitiveManager The database access component
 * @param client The model client
 * @param param The primitive update param
 * @param id The id of the primitive to update
 *
 * @return The primitive type java object
 */
public static <DBModel extends CustomServicesDBPrimitive, T extends CustomServicesDBPrimitiveType> T update(final Function<DBModel, T> mapper, final Class<DBModel> dbModel, final Class<? extends CustomServicesDBResource> resourceType, final CustomServicesPrimitiveManager primitiveManager, final ModelClient client, final CustomServicesPrimitiveUpdateParam param, final Function<UpdatePrimitive<DBModel>, StringSetMap> updateInputFunc, final Function<UpdatePrimitive<DBModel>, StringMap> updateAttributesFunc, final URI id, final Class<? extends CustomServicesDBResource> referencedByresourceType) {
    final DBModel primitive = primitiveManager.findById(dbModel, id);
    if (null == primitive) {
        throw APIException.notFound.unableToFindEntityInURL(id);
    } else if (primitive.getInactive()) {
        throw APIException.notFound.entityInURLIsInactive(id);
    }
    checkNotInUse(client, id, primitive);
    if (StringUtils.isNotBlank(param.getName())) {
        final String label = param.getName().trim();
        if (!label.equalsIgnoreCase(primitive.getLabel())) {
            checkDuplicateLabel(label, primitiveManager, dbModel);
            primitive.setLabel(label);
        }
    }
    if (null != param.getFriendlyName()) {
        primitive.setFriendlyName(param.getFriendlyName());
    }
    if (null != param.getDescription()) {
        primitive.setDescription(param.getDescription());
    }
    final NamedURI oldResourceId = primitive.getResource();
    final CustomServicesDBResource resource;
    if (param.getResource() == null) {
        resource = null;
    } else if (!resourceType.isAssignableFrom(CustomServicesDBNoResource.class)) {
        resource = primitiveManager.findResource(resourceType, param.getResource());
        if (null == resource) {
            throw APIException.notFound.unableToFindEntityInURL(param.getResource());
        }
        if (resource.getInactive()) {
            throw APIException.notFound.entityInURLIsInactive(param.getResource());
        }
        primitive.setResource(new NamedURI(resource.getId(), resource.getLabel()));
    } else {
        throw APIException.badRequests.invalidParameter("resource", param.getResource().toString());
    }
    final UpdatePrimitive<DBModel> updatePrimitive = new UpdatePrimitive<DBModel>(param, primitive);
    updateAttributesFunc.apply(updatePrimitive);
    updateInputFunc.apply(updatePrimitive);
    updateOutput(param.getOutput(), primitive);
    client.save(primitive);
    // check that the resource is not referenced by other primitives
    if (null != resource && null != oldResourceId && null == checkResourceNotReferenced(dbModel, CustomServicesDBPrimitive.RESOURCE, client, oldResourceId.getURI(), resource)) {
        // Find all the associated inventory files if exist for the old resource and delete the associated inventory files if exist
        deleteReferencedInventoryResources(oldResourceId.getURI(), primitiveManager, client, referencedByresourceType);
        // delete old resource (after updating the inventory, if any exists)
        client.delete(primitiveManager.findResource(resourceType, oldResourceId.getURI()));
    }
    return mapper.apply(primitive);
}
Also used : CustomServicesDBResource(com.emc.storageos.db.client.model.uimodels.CustomServicesDBResource) NamedURI(com.emc.storageos.db.client.model.NamedURI)

Example 82 with NamedURI

use of com.emc.storageos.db.client.model.NamedURI 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)

Example 83 with NamedURI

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

the class CatalogCategoryTest method testFindByLabel.

@Test
public void testFindByLabel() throws Exception {
    _logger.info("Starting FindByLabel test");
    ModelClient modelClient = getModelClient();
    CatalogCategory root = createWithLabel("root");
    CatalogCategory catalogCategory = createWithLabel("foo");
    catalogCategory.setCatalogCategoryId(new NamedURI(root.getId(), root.getLabel()));
    modelClient.save(catalogCategory);
    catalogCategory = createWithLabel("barOne");
    catalogCategory.setCatalogCategoryId(new NamedURI(root.getId(), root.getLabel()));
    modelClient.save(catalogCategory);
    catalogCategory = createWithLabel("barTwo");
    catalogCategory.setCatalogCategoryId(new NamedURI(root.getId(), root.getLabel()));
    modelClient.save(catalogCategory);
    modelClient.save(root);
    List<CatalogCategory> results = modelClient.catalogCategories().findByLabel(DEFAULT_TENANT, "fo");
    Assert.assertNotNull(results);
    Assert.assertEquals(1, results.size());
    results = modelClient.catalogCategories().findByLabel(DEFAULT_TENANT, "bar");
    Assert.assertNotNull(results);
    Assert.assertEquals(2, results.size());
    results = modelClient.catalogCategories().findByLabel(DEFAULT_TENANT, "foobar");
    Assert.assertNotNull(results);
    Assert.assertEquals(0, 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) BaseModelTest(com.emc.sa.model.BaseModelTest) Test(org.junit.Test)

Example 84 with NamedURI

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

the class CatalogCategoryTest method createWithLabel.

private CatalogCategory createWithLabel(String label) {
    CatalogCategory model = new CatalogCategory();
    model.setId(URIUtil.createId(CatalogCategory.class));
    model.setLabel(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);
    return model;
}
Also used : NamedURI(com.emc.storageos.db.client.model.NamedURI) CatalogCategory(com.emc.storageos.db.client.model.uimodels.CatalogCategory) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI)

Example 85 with NamedURI

use of com.emc.storageos.db.client.model.NamedURI 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)

Aggregations

NamedURI (com.emc.storageos.db.client.model.NamedURI)196 URI (java.net.URI)98 Volume (com.emc.storageos.db.client.model.Volume)74 StringSet (com.emc.storageos.db.client.model.StringSet)65 Project (com.emc.storageos.db.client.model.Project)54 ArrayList (java.util.ArrayList)46 TenantOrg (com.emc.storageos.db.client.model.TenantOrg)43 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)42 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)36 Test (org.junit.Test)32 StoragePool (com.emc.storageos.db.client.model.StoragePool)31 VirtualPool (com.emc.storageos.db.client.model.VirtualPool)31 VirtualArray (com.emc.storageos.db.client.model.VirtualArray)27 BlockConsistencyGroup (com.emc.storageos.db.client.model.BlockConsistencyGroup)26 StringMap (com.emc.storageos.db.client.model.StringMap)26 List (java.util.List)23 OpStatusMap (com.emc.storageos.db.client.model.OpStatusMap)20 StringSetMap (com.emc.storageos.db.client.model.StringSetMap)20 VirtualPoolCapabilityValuesWrapper (com.emc.storageos.volumecontroller.impl.utils.VirtualPoolCapabilityValuesWrapper)18 FileShare (com.emc.storageos.db.client.model.FileShare)17