Search in sources :

Example 1 with ProjectList

use of com.emc.storageos.model.project.ProjectList in project coprhd-controller by CoprHD.

the class TenantsService method listVolumeGroups.

/**
 * List volume groups the user is authorized to see
 *
 * @param id the URN of a ViPR Tenant/Subtenant
 * @prereq none
 * @brief List volume groups
 * @return List of volume groups
 */
@GET
@Path("/{id}/volume-groups")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public VolumeGroupList listVolumeGroups(@PathParam("id") URI id) {
    // tenant id and user permission will get validated in listProjects()
    ProjectList projectList = listProjects(id);
    Set<URI> projects = new HashSet<URI>();
    for (NamedRelatedResourceRep projectRep : projectList.getProjects()) {
        projects.add(projectRep.getId());
    }
    // for each project, get all volumes. Collect volume group ids for all volumes
    StringSet volumeGroups = new StringSet();
    for (URI project : projects) {
        URIQueryResultList list = new URIQueryResultList();
        _dbClient.queryByConstraint(ContainmentConstraint.Factory.getProjectVolumeConstraint(project), list);
        Iterator<Volume> resultsIt = _dbClient.queryIterativeObjects(Volume.class, list);
        while (resultsIt.hasNext()) {
            volumeGroups.addAll(resultsIt.next().getVolumeGroupIds());
        }
    }
    // form Volume Group list response
    VolumeGroupList volumeGroupList = new VolumeGroupList();
    for (String vg : volumeGroups) {
        VolumeGroup volumeGroup = _dbClient.queryObject(VolumeGroup.class, URI.create(vg));
        volumeGroupList.getVolumeGroups().add(toNamedRelatedResource(volumeGroup));
    }
    return volumeGroupList;
}
Also used : Volume(com.emc.storageos.db.client.model.Volume) VolumeGroup(com.emc.storageos.db.client.model.VolumeGroup) ProjectList(com.emc.storageos.model.project.ProjectList) StringSet(com.emc.storageos.db.client.model.StringSet) VolumeGroupList(com.emc.storageos.model.application.VolumeGroupList) NamedRelatedResourceRep(com.emc.storageos.model.NamedRelatedResourceRep) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) HashSet(java.util.HashSet) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 2 with ProjectList

use of com.emc.storageos.model.project.ProjectList in project coprhd-controller by CoprHD.

the class TenantsService method listProjects.

/**
 * List projects the user is authorized to see
 *
 * @param id the URN of a ViPR Tenant/Subtenant
 * @prereq none
 * @brief List projects
 * @return List of projects
 */
@GET
@Path("/{id}/projects")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public ProjectList listProjects(@PathParam("id") URI id) {
    TenantOrg tenant = getTenantById(id, false);
    StorageOSUser user = getUserFromContext();
    NamedElementQueryResultList projects = new NamedElementQueryResultList();
    if (_permissionsHelper.userHasGivenRole(user, tenant.getId(), Role.SYSTEM_MONITOR, Role.TENANT_ADMIN, Role.SECURITY_ADMIN)) {
        // list all
        _dbClient.queryByConstraint(ContainmentConstraint.Factory.getTenantOrgProjectConstraint(tenant.getId()), projects);
    } else {
        // list only projects that the user has access to
        if (!id.equals(URI.create(user.getTenantId()))) {
            throw APIException.forbidden.insufficientPermissionsForUser(user.getName());
        }
        Map<URI, Set<String>> allMyProjects = _permissionsHelper.getAllPermissionsForUser(user, tenant.getId(), null, false);
        if (!allMyProjects.keySet().isEmpty()) {
            List<Project> project_list = _dbClient.queryObjectField(Project.class, "label", new ArrayList<URI>(allMyProjects.keySet()));
            List<NamedElementQueryResultList.NamedElement> elements = new ArrayList<NamedElementQueryResultList.NamedElement>(project_list.size());
            for (Project p : project_list) {
                elements.add(NamedElementQueryResultList.NamedElement.createElement(p.getId(), p.getLabel()));
            }
            projects.setResult(elements.iterator());
        } else {
            // empty list
            projects.setResult(new ArrayList<NamedElementQueryResultList.NamedElement>().iterator());
        }
    }
    ProjectList list = new ProjectList();
    for (NamedElementQueryResultList.NamedElement el : projects) {
        list.getProjects().add(toNamedRelatedResource(ResourceTypeEnum.PROJECT, el.getId(), el.getName()));
    }
    return list;
}
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) Project(com.emc.storageos.db.client.model.Project) StorageOSUser(com.emc.storageos.security.authentication.StorageOSUser) ProjectList(com.emc.storageos.model.project.ProjectList) TenantOrg(com.emc.storageos.db.client.model.TenantOrg) NamedElementQueryResultList(com.emc.storageos.db.client.constraint.NamedElementQueryResultList) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

NamedURI (com.emc.storageos.db.client.model.NamedURI)2 StringSet (com.emc.storageos.db.client.model.StringSet)2 ProjectList (com.emc.storageos.model.project.ProjectList)2 URI (java.net.URI)2 HashSet (java.util.HashSet)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 NamedElementQueryResultList (com.emc.storageos.db.client.constraint.NamedElementQueryResultList)1 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)1 AbstractChangeTrackingSet (com.emc.storageos.db.client.model.AbstractChangeTrackingSet)1 Project (com.emc.storageos.db.client.model.Project)1 TenantOrg (com.emc.storageos.db.client.model.TenantOrg)1 Volume (com.emc.storageos.db.client.model.Volume)1 VolumeGroup (com.emc.storageos.db.client.model.VolumeGroup)1 NamedRelatedResourceRep (com.emc.storageos.model.NamedRelatedResourceRep)1 VolumeGroupList (com.emc.storageos.model.application.VolumeGroupList)1 StorageOSUser (com.emc.storageos.security.authentication.StorageOSUser)1 ArrayList (java.util.ArrayList)1 Set (java.util.Set)1