use of com.cloud.api.response.ResourceDetailResponse in project cosmic by MissionCriticalCloud.
the class QueryManagerImpl method listResourceDetails.
@Override
public List<ResourceDetailResponse> listResourceDetails(final ListResourceDetailsCmd cmd) {
final String key = cmd.getKey();
final Boolean forDisplay = cmd.getDisplay();
final ResourceTag.ResourceObjectType resourceType = cmd.getResourceType();
final String resourceIdStr = cmd.getResourceId();
final String value = cmd.getValue();
Long resourceId = null;
// Validation - 1.1 - resourceId and value cant be null.
if (resourceIdStr == null && value == null) {
throw new InvalidParameterValueException("Insufficient parameters passed for listing by resourceId OR key,value pair. Please check your params and try again.");
}
// Validation - 1.2 - Value has to be passed along with key.
if (value != null && key == null) {
throw new InvalidParameterValueException("Listing by (key, value) but key is null. Please check the params and try again");
}
// Validation - 1.3
if (resourceIdStr != null) {
resourceId = _taggedResourceMgr.getResourceId(resourceIdStr, resourceType);
if (resourceId == null) {
throw new InvalidParameterValueException("Cannot find resource with resourceId " + resourceIdStr + " and of resource type " + resourceType);
}
}
List<? extends ResourceDetail> detailList = new ArrayList<>();
ResourceDetail requestedDetail = null;
if (key == null) {
detailList = _resourceMetaDataMgr.getDetailsList(resourceId, resourceType, forDisplay);
} else if (value == null) {
requestedDetail = _resourceMetaDataMgr.getDetail(resourceId, resourceType, key);
if (requestedDetail != null && forDisplay != null && requestedDetail.isDisplay() != forDisplay) {
requestedDetail = null;
}
} else {
detailList = _resourceMetaDataMgr.getDetails(resourceType, key, value, forDisplay);
}
final List<ResourceDetailResponse> responseList = new ArrayList<>();
if (requestedDetail != null) {
final ResourceDetailResponse detailResponse = createResourceDetailsResponse(requestedDetail, resourceType);
responseList.add(detailResponse);
} else {
for (final ResourceDetail detail : detailList) {
final ResourceDetailResponse detailResponse = createResourceDetailsResponse(detail, resourceType);
responseList.add(detailResponse);
}
}
return responseList;
}
use of com.cloud.api.response.ResourceDetailResponse in project cosmic by MissionCriticalCloud.
the class QueryManagerImpl method createResourceDetailsResponse.
protected ResourceDetailResponse createResourceDetailsResponse(final ResourceDetail requestedDetail, final ResourceTag.ResourceObjectType resourceType) {
final ResourceDetailResponse resourceDetailResponse = new ResourceDetailResponse();
resourceDetailResponse.setResourceId(String.valueOf(requestedDetail.getResourceId()));
resourceDetailResponse.setName(requestedDetail.getName());
resourceDetailResponse.setValue(requestedDetail.getValue());
resourceDetailResponse.setForDisplay(requestedDetail.isDisplay());
resourceDetailResponse.setResourceType(resourceType.toString().toString());
resourceDetailResponse.setObjectName("resourcedetail");
return resourceDetailResponse;
}
Aggregations