Search in sources :

Example 26 with NamedElement

use of com.emc.storageos.db.client.constraint.NamedElementQueryResultList.NamedElement 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 27 with NamedElement

use of com.emc.storageos.db.client.constraint.NamedElementQueryResultList.NamedElement in project coprhd-controller by CoprHD.

the class CustomServicesDBHelper method checkResourceNotReferenced.

private static <T extends CustomServicesDBResource> BadRequestException checkResourceNotReferenced(final Class<? extends ModelObject> referencedByClazz, final String referencedByColumnName, final ModelClient client, final URI resourceId, final T resource) {
    List<NamedElement> resourceExistList = Collections.emptyList();
    final BadRequestException resourceReferencedexception = null;
    if (null != referencedByClazz) {
        resourceExistList = client.findBy(referencedByClazz, referencedByColumnName, resourceId);
        if (null != resourceExistList && !resourceExistList.isEmpty()) {
            return APIException.badRequests.resourceHasActiveReferencesWithType(resource.getClass().getSimpleName(), resourceId, StringUtils.substringAfterLast(referencedByClazz.getName(), "."));
        }
    }
    return resourceReferencedexception;
}
Also used : BadRequestException(com.emc.storageos.svcs.errorhandling.resources.BadRequestException) NamedElement(com.emc.storageos.db.client.constraint.NamedElementQueryResultList.NamedElement)

Example 28 with NamedElement

use of com.emc.storageos.db.client.constraint.NamedElementQueryResultList.NamedElement in project coprhd-controller by CoprHD.

the class CustomServicesDBHelper method checkNotInUse.

/**
 * Check if a primitive is in use in a workflow. Throw a bad request exception if it is being used.
 *
 * @param client ModelClient
 * @param id The ID of the primitive
 * @param primitive The primitive instance
 */
private static <T extends CustomServicesDBPrimitive> void checkNotInUse(final ModelClient client, final URI id, final T primitive) {
    final List<NamedElement> workflows = client.customServicesWorkflows().getByPrimitive(id);
    if (CollectionUtils.isNotEmpty(workflows)) {
        final StringBuilder wfName = new StringBuilder();
        String prefix = ". Workflows used : ";
        for (final NamedElement eachWf : workflows) {
            wfName.append(prefix);
            prefix = ", ";
            wfName.append(eachWf.getName());
        }
        throw APIException.badRequests.resourceHasActiveReferencesWithType(primitive.getClass().getSimpleName(), primitive.getLabel(), CustomServicesWorkflow.class.getSimpleName() + wfName.toString());
    }
}
Also used : NamedElement(com.emc.storageos.db.client.constraint.NamedElementQueryResultList.NamedElement)

Example 29 with NamedElement

use of com.emc.storageos.db.client.constraint.NamedElementQueryResultList.NamedElement in project coprhd-controller by CoprHD.

the class OrderFinder method findScheduledByExecutionWindow.

public List<Order> findScheduledByExecutionWindow(String executionWindowId) {
    List<Order> results = Lists.newArrayList();
    if (StringUtils.isBlank(executionWindowId)) {
        return results;
    }
    Set<URI> orderIds = Sets.newHashSet();
    List<NamedElement> scheduledOrderElems = client.findByAlternateId(Order.class, Order.ORDER_STATUS, OrderStatus.SCHEDULED.name());
    for (NamedElement scheduledOrderElem : scheduledOrderElems) {
        Order scheduledOrder = client.findById(Order.class, scheduledOrderElem.getId());
        if (scheduledOrder.getExecutionWindowId() != null && scheduledOrder.getExecutionWindowId().getURI() != null && executionWindowId.equalsIgnoreCase(scheduledOrder.getExecutionWindowId().getURI().toString())) {
            results.add(scheduledOrder);
        }
    }
    results.addAll(findByIds(Lists.newArrayList(orderIds)));
    return results;
}
Also used : Order(com.emc.storageos.db.client.model.uimodels.Order) URI(java.net.URI) NamedElement(com.emc.storageos.db.client.constraint.NamedElementQueryResultList.NamedElement)

Example 30 with NamedElement

use of com.emc.storageos.db.client.constraint.NamedElementQueryResultList.NamedElement in project coprhd-controller by CoprHD.

the class InMemoryDbClient method findOrdersByAlternateId.

@Override
public List<NamedElement> findOrdersByAlternateId(String columnField, String value, long startTime, long endTime, int maxCount) throws DataAccessException {
    List<NamedElement> results = Lists.newArrayList();
    for (URI modelId : findAllIds(Order.class)) {
        Order order = findById(Order.class, modelId);
        Object o = getColumnField(order, columnField);
        if (ObjectUtils.equals(o, value)) {
            results.add(createNamedElement(order));
        }
    }
    return results;
}
Also used : Order(com.emc.storageos.db.client.model.uimodels.Order) DataObject(com.emc.storageos.db.client.model.DataObject) NamedElement(com.emc.storageos.db.client.constraint.NamedElementQueryResultList.NamedElement) URI(java.net.URI)

Aggregations

NamedElement (com.emc.storageos.db.client.constraint.NamedElementQueryResultList.NamedElement)32 URI (java.net.URI)14 DataObject (com.emc.storageos.db.client.model.DataObject)6 ArrayList (java.util.ArrayList)6 NamedURI (com.emc.storageos.db.client.model.NamedURI)4 CustomServicesWorkflow (com.emc.storageos.db.client.model.uimodels.CustomServicesWorkflow)4 Order (com.emc.storageos.db.client.model.uimodels.Order)3 NamedElementQueryResultList (com.emc.storageos.db.client.constraint.NamedElementQueryResultList)2 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)2 ActionableEvent (com.emc.storageos.db.client.model.ActionableEvent)2 Cluster (com.emc.storageos.db.client.model.Cluster)2 ExportGroup (com.emc.storageos.db.client.model.ExportGroup)2 Host (com.emc.storageos.db.client.model.Host)2 ScheduledEvent (com.emc.storageos.db.client.model.uimodels.ScheduledEvent)2 ImmutableList (com.google.common.collect.ImmutableList)2 HashSet (java.util.HashSet)2 ServiceDescriptor (com.emc.sa.descriptor.ServiceDescriptor)1 ResourcePackage (com.emc.sa.workflow.CustomServicesWorkflowPackage.ResourcePackage)1 TimeSeriesConstraint (com.emc.storageos.db.client.constraint.TimeSeriesConstraint)1 CatalogCategory (com.emc.storageos.db.client.model.uimodels.CatalogCategory)1