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;
}
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;
}
Aggregations