use of com.emc.storageos.model.schedulepolicy.SchedulePolicyList in project coprhd-controller by CoprHD.
the class TenantsService method getSchedulePolicies.
/**
* Gets the policyIds, policyNames and self links for all schedule policies.
*
* @param id the URN of a CoprHD Tenant/Subtenant
* @brief List schedule policies
* @return policyList - A SchedulePolicyList reference specifying the policyIds, name and self links for
* the schedule policies.
*/
@GET
@Path("/{id}/schedule-policies")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.TENANT_ADMIN, Role.PROJECT_ADMIN })
public SchedulePolicyList getSchedulePolicies(@PathParam("id") URI id) {
TenantOrg tenant = getTenantById(id, false);
StorageOSUser user = getUserFromContext();
NamedElementQueryResultList schedulePolicies = new NamedElementQueryResultList();
if (_permissionsHelper.userHasGivenRole(user, tenant.getId(), Role.SYSTEM_MONITOR, Role.TENANT_ADMIN, Role.SECURITY_ADMIN)) {
// list all schedule policies
_dbClient.queryByConstraint(ContainmentConstraint.Factory.getTenantOrgSchedulePolicyConstraint(tenant.getId()), schedulePolicies);
} else {
// list only schedule policies that the user has access to
if (!id.equals(URI.create(user.getTenantId()))) {
throw APIException.forbidden.insufficientPermissionsForUser(user.getName());
}
Map<URI, Set<String>> allMySchedulePolicies = _permissionsHelper.getAllPermissionsForUser(user, tenant.getId(), null, false);
if (!allMySchedulePolicies.keySet().isEmpty()) {
List<SchedulePolicy> policyList = _dbClient.queryObjectField(SchedulePolicy.class, "label", new ArrayList<URI>(allMySchedulePolicies.keySet()));
List<NamedElementQueryResultList.NamedElement> elements = new ArrayList<NamedElementQueryResultList.NamedElement>(policyList.size());
for (SchedulePolicy policy : policyList) {
elements.add(NamedElementQueryResultList.NamedElement.createElement(policy.getId(), policy.getLabel()));
}
schedulePolicies.setResult(elements.iterator());
} else {
// empty list
schedulePolicies.setResult(new ArrayList<NamedElementQueryResultList.NamedElement>().iterator());
}
}
SchedulePolicyList policyList = new SchedulePolicyList();
for (NamedElementQueryResultList.NamedElement el : schedulePolicies) {
policyList.getSchdulePolicies().add(toNamedRelatedResource(ResourceTypeEnum.SCHEDULE_POLICY, el.getId(), el.getName()));
}
return policyList;
}
Aggregations