mirror of https://github.com/apache/cloudstack.git
refactored changes
Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
This commit is contained in:
parent
f431711922
commit
94f425f6b1
|
|
@ -16,10 +16,14 @@
|
|||
// under the License.
|
||||
package com.cloud.service.dao;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.cloudstack.resourcedetail.ResourceDetailsDao;
|
||||
|
||||
import com.cloud.service.ServiceOfferingDetailsVO;
|
||||
import com.cloud.utils.db.GenericDao;
|
||||
|
||||
public interface ServiceOfferingDetailsDao extends GenericDao<ServiceOfferingDetailsVO, Long>, ResourceDetailsDao<ServiceOfferingDetailsVO> {
|
||||
List<Long> findDomainIds(final long resourceId);
|
||||
List<Long> findZoneIds(final long resourceId);
|
||||
}
|
||||
|
|
@ -17,9 +17,12 @@
|
|||
package com.cloud.service.dao;
|
||||
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
import org.apache.cloudstack.resourcedetail.ResourceDetailsDaoBase;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.cloud.service.ServiceOfferingDetailsVO;
|
||||
|
||||
|
|
@ -31,4 +34,28 @@ public class ServiceOfferingDetailsDaoImpl extends ResourceDetailsDaoBase<Servic
|
|||
super.addDetail(new ServiceOfferingDetailsVO(resourceId, key, value, display));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Long> findDomainIds(long resourceId) {
|
||||
final List<Long> domainIds = new ArrayList<>();
|
||||
for (final ServiceOfferingDetailsVO detail: findDetails(resourceId, ApiConstants.DOMAIN_ID)) {
|
||||
final Long domainId = Long.valueOf(detail.getValue(), -1);
|
||||
if (domainId != -1) {
|
||||
domainIds.add(domainId);
|
||||
}
|
||||
}
|
||||
return domainIds;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Long> findZoneIds(long resourceId) {
|
||||
final List<Long> zoneIds = new ArrayList<>();
|
||||
for (final ServiceOfferingDetailsVO detail: findDetails(resourceId, ApiConstants.ZONE_ID)) {
|
||||
final Long zoneId = Long.valueOf(detail.getValue(), -1);
|
||||
if (zoneId != -1) {
|
||||
zoneIds.add(zoneId);
|
||||
}
|
||||
}
|
||||
return zoneIds;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@
|
|||
// under the License.
|
||||
package com.cloud.storage.dao;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
|
@ -151,26 +150,4 @@ public class DiskOfferingDaoImpl extends GenericDaoBase<DiskOfferingVO, Long> im
|
|||
|
||||
return update(id, diskOffering);
|
||||
}
|
||||
|
||||
private List<DiskOfferingVO> filterOfferingsForDomain(final List<DiskOfferingVO> offerings, Long domainId) {
|
||||
List<DiskOfferingVO> filteredOfferings = null;
|
||||
if (offerings != null && !offerings.isEmpty() && domainId != null) {
|
||||
filteredOfferings = new ArrayList<>(offerings);
|
||||
for (int i = filteredOfferings.size() - 1; i >= 0; i--) {
|
||||
DiskOfferingVO offering = offerings.get(i);
|
||||
Map<String, String> offeringDetails = detailsDao.listDetailsKeyPairs(offering.getId());
|
||||
if (!Strings.isNullOrEmpty(offeringDetails.get(ApiConstants.DOMAIN_ID_LIST))) {
|
||||
String[] domainIdsArray = offeringDetails.get(ApiConstants.DOMAIN_ID_LIST).split(",");
|
||||
List<Long> domainIds = new ArrayList<>();
|
||||
for (String dIdStr : domainIdsArray) {
|
||||
domainIds.add(Long.valueOf(dIdStr.trim()));
|
||||
}
|
||||
if (!domainIds.contains(domainId)) {
|
||||
filteredOfferings.remove(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return filteredOfferings;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,11 +16,14 @@
|
|||
// under the License.
|
||||
package org.apache.cloudstack.resourcedetail.dao;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.cloudstack.resourcedetail.DiskOfferingDetailVO;
|
||||
import org.apache.cloudstack.resourcedetail.ResourceDetailsDao;
|
||||
|
||||
import com.cloud.utils.db.GenericDao;
|
||||
|
||||
public interface DiskOfferingDetailsDao extends GenericDao<DiskOfferingDetailVO, Long>, ResourceDetailsDao<DiskOfferingDetailVO> {
|
||||
|
||||
List<Long> findDomainIds(final long resourceId);
|
||||
List<Long> findZoneIds(final long resourceId);
|
||||
}
|
||||
|
|
@ -17,6 +17,10 @@
|
|||
package org.apache.cloudstack.resourcedetail.dao;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
import org.apache.cloudstack.resourcedetail.DiskOfferingDetailVO;
|
||||
import org.apache.cloudstack.resourcedetail.ResourceDetailsDaoBase;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
|
@ -28,4 +32,28 @@ public class DiskOfferingDetailsDaoImpl extends ResourceDetailsDaoBase<DiskOffer
|
|||
public void addDetail(long resourceId, String key, String value, boolean display) {
|
||||
super.addDetail(new DiskOfferingDetailVO(resourceId, key, value, display));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Long> findDomainIds(long resourceId) {
|
||||
final List<Long> domainIds = new ArrayList<>();
|
||||
for (final DiskOfferingDetailVO detail: findDetails(resourceId, ApiConstants.DOMAIN_ID)) {
|
||||
final Long domainId = Long.valueOf(detail.getValue(), -1);
|
||||
if (domainId != -1) {
|
||||
domainIds.add(domainId);
|
||||
}
|
||||
}
|
||||
return domainIds;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Long> findZoneIds(long resourceId) {
|
||||
final List<Long> zoneIds = new ArrayList<>();
|
||||
for (final DiskOfferingDetailVO detail: findDetails(resourceId, ApiConstants.ZONE_ID)) {
|
||||
final Long zoneId = Long.valueOf(detail.getValue(), -1);
|
||||
if (zoneId != -1) {
|
||||
zoneIds.add(zoneId);
|
||||
}
|
||||
}
|
||||
return zoneIds;
|
||||
}
|
||||
}
|
||||
|
|
@ -16,7 +16,6 @@
|
|||
// under the License.
|
||||
package com.cloud.acl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
|
@ -42,7 +41,6 @@ import com.cloud.offering.DiskOffering;
|
|||
import com.cloud.offering.ServiceOffering;
|
||||
import com.cloud.projects.ProjectManager;
|
||||
import com.cloud.projects.dao.ProjectAccountDao;
|
||||
import com.cloud.service.ServiceOfferingDetailsVO;
|
||||
import com.cloud.service.dao.ServiceOfferingDetailsDao;
|
||||
import com.cloud.storage.LaunchPermissionVO;
|
||||
import com.cloud.storage.dao.LaunchPermissionDao;
|
||||
|
|
@ -227,10 +225,7 @@ public class DomainChecker extends AdapterBase implements SecurityChecker {
|
|||
|
||||
@Override
|
||||
public boolean checkAccess(Account account, ServiceOffering so) throws PermissionDeniedException {
|
||||
final List<Long> soDomainIds = new ArrayList<>();
|
||||
for (final ServiceOfferingDetailsVO detail: serviceOfferingDetailsDao.findDetails(so.getId(), ApiConstants.DOMAIN_ID)) {
|
||||
soDomainIds.add(Long.valueOf(detail.getValue()));
|
||||
}
|
||||
final List<Long> soDomainIds = serviceOfferingDetailsDao.findDomainIds(so.getId());
|
||||
if (account == null || soDomainIds.isEmpty()) { //public offering
|
||||
return true;
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Reference in New Issue