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);
}
}
}
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;
}
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());
}
}
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;
}
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;
}
Aggregations