Search in sources :

Example 6 with CustomServicesDBResource

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

the class CustomServicesDBHelper method deleteReferencedInventoryResources.

/**
 * Delete the inventory files assciated with the resource files
 *
 * @param resourceId The resourceId to search for inventory files
 * @param primitiveManager The database access component
 * @param client The model client
 * @param referencedByresourceType The DB component which is the inventory resource to delete
 */
private static void deleteReferencedInventoryResources(final URI resourceId, final CustomServicesPrimitiveManager primitiveManager, final ModelClient client, final Class<? extends CustomServicesDBResource> referencedByresourceType) {
    if (null != resourceId && null != referencedByresourceType) {
        final List<NamedElement> refResource = listResources(referencedByresourceType, client, CustomServicesDBResource.PARENTID, resourceId.toString());
        for (final NamedElement eachResource : refResource) {
            final CustomServicesDBResource refDBResource = primitiveManager.findResource(referencedByresourceType, eachResource.getId());
            // delete the associated inventory files if exist for the DB model
            client.delete(refDBResource);
        }
    }
}
Also used : CustomServicesDBResource(com.emc.storageos.db.client.model.uimodels.CustomServicesDBResource) NamedElement(com.emc.storageos.db.client.constraint.NamedElementQueryResultList.NamedElement)

Example 7 with CustomServicesDBResource

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

the class CustomServicesDBHelper method create.

/**
 * Given a creation 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 database column family java class
 * @param resourceType The resource
 * @param primitiveManager The database access component
 * @param param The primitive creation param
 * @return The primitive type java object
 */
public static <DBModel extends CustomServicesDBPrimitive, T extends CustomServicesDBPrimitiveType> T create(final Function<DBModel, T> mapper, final Class<DBModel> dbModel, final Class<? extends CustomServicesDBResource> resourceType, final CustomServicesPrimitiveManager primitiveManager, final Function<CustomServicesPrimitiveCreateParam, StringSetMap> createInputFunc, final Function<CustomServicesPrimitiveCreateParam, StringMap> createAttributesFunc, final CustomServicesPrimitiveCreateParam param) {
    final DBModel primitive;
    try {
        primitive = dbModel.newInstance();
    } catch (InstantiationException | IllegalAccessException e) {
        throw new RuntimeException("Failed to create custom services primitive: " + dbModel.getSimpleName());
    }
    primitive.setId(URIUtil.createId(primitive.getClass()));
    if (StringUtils.isNotBlank(param.getName())) {
        checkDuplicateLabel(param.getName().trim(), primitiveManager, dbModel);
        primitive.setLabel(param.getName().trim());
    } else {
        throw APIException.badRequests.requiredParameterMissingOrEmpty("name");
    }
    primitive.setFriendlyName(param.getFriendlyName());
    primitive.setDescription(param.getDescription());
    if (!resourceType.isAssignableFrom(CustomServicesDBNoResource.class)) {
        if (param.getResource() == null) {
            throw APIException.badRequests.requiredParameterMissingOrEmpty("resource");
        }
        final CustomServicesDBResource 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 if (null != param.getResource()) {
        throw APIException.badRequests.invalidParameter("resource", param.getResource().toString());
    }
    primitive.setAttributes(createAttributesFunc.apply(param));
    primitive.setInput(createInputFunc.apply(param));
    primitive.setOutput(createOutput(param.getOutput()));
    primitiveManager.save(primitive);
    return mapper.apply(primitive);
}
Also used : CustomServicesDBResource(com.emc.storageos.db.client.model.uimodels.CustomServicesDBResource) NamedURI(com.emc.storageos.db.client.model.NamedURI)

Aggregations

CustomServicesDBResource (com.emc.storageos.db.client.model.uimodels.CustomServicesDBResource)7 NamedURI (com.emc.storageos.db.client.model.NamedURI)2 BadRequestException (com.emc.storageos.svcs.errorhandling.resources.BadRequestException)2 NamedElement (com.emc.storageos.db.client.constraint.NamedElementQueryResultList.NamedElement)1 CustomServicesDBPrimitive (com.emc.storageos.db.client.model.uimodels.CustomServicesDBPrimitive)1