use of com.cloud.resource.icon.ResourceIconVO in project cloudstack by apache.
the class ResourceIconDaoImpl method listResourceIcons.
@Override
public List<ResourceIconResponse> listResourceIcons(List<String> resourceUuids, ResourceTag.ResourceObjectType resourceType) {
SearchCriteria<ResourceIconVO> sc = AllFieldsSearch.create();
sc.setParameters("uuid", resourceUuids.toArray());
sc.setParameters("resourceType", resourceType);
List<ResourceIconVO> resourceIcons = listBy(sc);
List<ResourceIconResponse> iconResponses = new ArrayList<>();
for (ResourceIconVO resourceIcon : resourceIcons) {
ResourceIconResponse response = new ResourceIconResponse();
response.setResourceId(resourceIcon.getResourceUuid());
response.setResourceType(resourceIcon.getResourceType());
response.setImage(resourceIcon.getIcon());
response.setObjectName(ApiConstants.RESOURCE_ICON);
iconResponses.add(response);
}
return iconResponses;
}
use of com.cloud.resource.icon.ResourceIconVO in project cloudstack by apache.
the class DataCenterJoinDaoImpl method newDataCenterResponse.
@Override
public ZoneResponse newDataCenterResponse(ResponseView view, DataCenterJoinVO dataCenter, Boolean showCapacities, Boolean showResourceImage) {
ZoneResponse zoneResponse = new ZoneResponse();
zoneResponse.setId(dataCenter.getUuid());
zoneResponse.setName(dataCenter.getName());
zoneResponse.setSecurityGroupsEnabled(ApiDBUtils.isSecurityGroupEnabledInZone(dataCenter.getId()));
zoneResponse.setLocalStorageEnabled(dataCenter.isLocalStorageEnabled());
if ((dataCenter.getDescription() != null) && !dataCenter.getDescription().equalsIgnoreCase("null")) {
zoneResponse.setDescription(dataCenter.getDescription());
}
if (view == ResponseView.Full) {
zoneResponse.setDns1(dataCenter.getDns1());
zoneResponse.setDns2(dataCenter.getDns2());
zoneResponse.setIp6Dns1(dataCenter.getIp6Dns1());
zoneResponse.setIp6Dns2(dataCenter.getIp6Dns2());
zoneResponse.setInternalDns1(dataCenter.getInternalDns1());
zoneResponse.setInternalDns2(dataCenter.getInternalDns2());
// FIXME zoneResponse.setVlan(dataCenter.get.getVnet());
zoneResponse.setGuestCidrAddress(dataCenter.getGuestNetworkCidr());
if (showCapacities != null && showCapacities) {
zoneResponse.setCapacitites(ApiResponseHelper.getDataCenterCapacityResponse(dataCenter.getId()));
}
}
// set network domain info
zoneResponse.setDomain(dataCenter.getDomain());
// set domain info
zoneResponse.setDomainId(dataCenter.getDomainUuid());
zoneResponse.setDomainName(dataCenter.getDomainName());
zoneResponse.setNetworkType(dataCenter.getNetworkType().toString());
zoneResponse.setAllocationState(dataCenter.getAllocationState().toString());
zoneResponse.setZoneToken(dataCenter.getZoneToken());
zoneResponse.setDhcpProvider(dataCenter.getDhcpProvider());
// update tag information
List<ResourceTagJoinVO> resourceTags = ApiDBUtils.listResourceTagViewByResourceUUID(dataCenter.getUuid(), ResourceObjectType.Zone);
for (ResourceTagJoinVO resourceTag : resourceTags) {
ResourceTagResponse tagResponse = ApiDBUtils.newResourceTagResponse(resourceTag, false);
zoneResponse.addTag(tagResponse);
}
if (showResourceImage) {
ResourceIconVO resourceIcon = ApiDBUtils.getResourceIconByResourceUUID(dataCenter.getUuid(), ResourceObjectType.Zone);
if (resourceIcon != null) {
ResourceIconResponse iconResponse = ApiDBUtils.newResourceIconResponse(resourceIcon);
zoneResponse.setResourceIconResponse(iconResponse);
}
}
zoneResponse.setResourceDetails(ApiDBUtils.getResourceDetails(dataCenter.getId(), ResourceObjectType.Zone));
zoneResponse.setHasAnnotation(annotationDao.hasAnnotations(dataCenter.getUuid(), AnnotationService.EntityType.ZONE.name(), _accountMgr.isRootAdmin(CallContext.current().getCallingAccount().getId())));
zoneResponse.setObjectName("zone");
return zoneResponse;
}
use of com.cloud.resource.icon.ResourceIconVO in project cloudstack by apache.
the class ResourceIconManagerImpl method uploadResourceIcon.
@Override
@DB
@ActionEvent(eventType = EventTypes.EVENT_RESOURCE_ICON_UPLOAD, eventDescription = "uploading resource icon")
public boolean uploadResourceIcon(List<String> resourceIds, ResourceTag.ResourceObjectType resourceType, String base64Image) {
final Account caller = CallContext.current().getCallingAccount();
Transaction.execute(new TransactionCallbackNoReturn() {
@Override
public void doInTransactionWithoutResult(TransactionStatus status) {
for (String resourceId : resourceIds) {
if (!resourceType.resourceIconSupport()) {
throw new InvalidParameterValueException("The resource type " + resourceType + " doesn't support resource icons");
}
if (base64Image == null) {
throw new InvalidParameterValueException("No icon provided to be uploaded for resource: " + resourceId);
}
long id = resourceManagerUtil.getResourceId(resourceId, resourceType);
String resourceUuid = resourceManagerUtil.getUuid(resourceId, resourceType);
ResourceIconVO existingResourceIcon = resourceIconDao.findByResourceUuid(resourceUuid, resourceType);
ResourceIconVO resourceIcon = null;
Pair<Long, Long> accountDomainPair = getAccountDomain(id, resourceType);
Long domainId = accountDomainPair.second();
Long accountId = accountDomainPair.first();
resourceManagerUtil.checkResourceAccessible(accountId, domainId, String.format("Account ' %s ' doesn't have permissions to upload icon for resource ' %s ", caller, id));
if (existingResourceIcon == null) {
resourceIcon = new ResourceIconVO(id, resourceType, resourceUuid, base64Image);
} else {
resourceIcon = existingResourceIcon;
resourceIcon.setIcon(base64Image);
resourceIcon.setUpdated(new Date());
}
try {
resourceIconDao.persist(resourceIcon);
} catch (EntityExistsException e) {
throw new CloudRuntimeException(String.format("Image already uploaded for resource type: %s with id %s", resourceType.toString(), resourceId), e);
}
}
}
});
return true;
}
Aggregations