use of org.apache.cloudstack.api.response.ResourceDetailResponse in project cloudstack by apache.
the class QueryManagerImpl method listResourceDetails.
@Override
public List<ResourceDetailResponse> listResourceDetails(ListResourceDetailsCmd cmd) {
String key = cmd.getKey();
Boolean forDisplay = cmd.getDisplay();
ResourceTag.ResourceObjectType resourceType = cmd.getResourceType();
String resourceIdStr = cmd.getResourceId();
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>();
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);
}
List<ResourceDetailResponse> responseList = new ArrayList<ResourceDetailResponse>();
if (requestedDetail != null) {
ResourceDetailResponse detailResponse = createResourceDetailsResponse(requestedDetail, resourceType);
responseList.add(detailResponse);
} else {
for (ResourceDetail detail : detailList) {
ResourceDetailResponse detailResponse = createResourceDetailsResponse(detail, resourceType);
responseList.add(detailResponse);
}
}
return responseList;
}
use of org.apache.cloudstack.api.response.ResourceDetailResponse in project cloudstack by apache.
the class QueryManagerImpl method createResourceDetailsResponse.
protected ResourceDetailResponse createResourceDetailsResponse(ResourceDetail requestedDetail, ResourceTag.ResourceObjectType resourceType) {
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