Search in sources :

Example 1 with SchedulePolicyList

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;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) AbstractChangeTrackingSet(com.emc.storageos.db.client.model.AbstractChangeTrackingSet) StringSet(com.emc.storageos.db.client.model.StringSet) ArrayList(java.util.ArrayList) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) SchedulePolicyList(com.emc.storageos.model.schedulepolicy.SchedulePolicyList) StorageOSUser(com.emc.storageos.security.authentication.StorageOSUser) TenantOrg(com.emc.storageos.db.client.model.TenantOrg) NamedElementQueryResultList(com.emc.storageos.db.client.constraint.NamedElementQueryResultList) SchedulePolicy(com.emc.storageos.db.client.model.SchedulePolicy) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Aggregations

NamedElementQueryResultList (com.emc.storageos.db.client.constraint.NamedElementQueryResultList)1 AbstractChangeTrackingSet (com.emc.storageos.db.client.model.AbstractChangeTrackingSet)1 NamedURI (com.emc.storageos.db.client.model.NamedURI)1 SchedulePolicy (com.emc.storageos.db.client.model.SchedulePolicy)1 StringSet (com.emc.storageos.db.client.model.StringSet)1 TenantOrg (com.emc.storageos.db.client.model.TenantOrg)1 SchedulePolicyList (com.emc.storageos.model.schedulepolicy.SchedulePolicyList)1 StorageOSUser (com.emc.storageos.security.authentication.StorageOSUser)1 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1