Search in sources :

Example 1 with CustomServicesDBPrimitive

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

the class CustomServicesPrimitiveManagerImpl method deactivate.

@Override
public <T extends CustomServicesDBPrimitive> void deactivate(final Class<T> clazz, final URI id) {
    final CustomServicesDBPrimitive primitive = findById(clazz, id);
    if (null == primitive) {
        throw APIException.notFound.unableToFindEntityInURL(id);
    }
    List<NamedElement> workflows = client.customServicesWorkflows().getByPrimitive(id);
    if (null != workflows && !workflows.isEmpty()) {
        throw APIException.badRequests.resourceHasActiveReferencesWithType(primitive.getClass().getSimpleName(), id, CustomServicesWorkflow.class.getSimpleName());
    }
    client.delete(primitive);
}
Also used : CustomServicesDBPrimitive(com.emc.storageos.db.client.model.uimodels.CustomServicesDBPrimitive) CustomServicesWorkflow(com.emc.storageos.db.client.model.uimodels.CustomServicesWorkflow) NamedElement(com.emc.storageos.db.client.constraint.NamedElementQueryResultList.NamedElement)

Example 2 with CustomServicesDBPrimitive

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

the class CustomServicesDBHelper method deactivate.

/**
 * Deactivate primitive with the given ID
 *
 * @param clazz The database column family class
 * @param primitiveManager The database access component
 * @param client The model client
 * @param id The ID of the primitive to deactivate
 */
public static void deactivate(final Class<? extends CustomServicesDBPrimitive> clazz, final CustomServicesPrimitiveManager primitiveManager, final ModelClient client, final URI id, final Class<? extends CustomServicesDBResource> resourceType, final Class<? extends CustomServicesDBResource> referencedByresourceType) {
    final CustomServicesDBPrimitive primitive = primitiveManager.findById(clazz, id);
    if (null == primitive) {
        throw APIException.notFound.unableToFindEntityInURL(id);
    }
    checkNotInUse(client, id, primitive);
    client.delete(primitive);
    if (!resourceType.isAssignableFrom(CustomServicesDBNoResource.class)) {
        final CustomServicesDBResource resource = primitiveManager.findResource(resourceType, primitive.getResource().getURI());
        if (null == resource) {
            throw APIException.notFound.unableToFindEntityInURL(primitive.getResource().getURI());
        }
        // check that the resource is not referenced by other primitives
        if (null != resource && null == checkResourceNotReferenced(clazz, CustomServicesDBPrimitive.RESOURCE, client, primitive.getResource().getURI(), resource)) {
            // Find all the associated inventory files if exist for the DB model and delete the associated inventory files if exist, for
            // the resource DB model
            deleteReferencedInventoryResources(primitive.getResource().getURI(), primitiveManager, client, referencedByresourceType);
            // then delete the resource
            client.delete(resource);
        }
    }
}
Also used : CustomServicesDBPrimitive(com.emc.storageos.db.client.model.uimodels.CustomServicesDBPrimitive) CustomServicesDBResource(com.emc.storageos.db.client.model.uimodels.CustomServicesDBResource)

Aggregations

CustomServicesDBPrimitive (com.emc.storageos.db.client.model.uimodels.CustomServicesDBPrimitive)2 NamedElement (com.emc.storageos.db.client.constraint.NamedElementQueryResultList.NamedElement)1 CustomServicesDBResource (com.emc.storageos.db.client.model.uimodels.CustomServicesDBResource)1 CustomServicesWorkflow (com.emc.storageos.db.client.model.uimodels.CustomServicesWorkflow)1