use of com.emc.storageos.model.search.SearchResultResourceRep in project coprhd-controller by CoprHD.
the class OrderService method getOtherSearchResults.
/**
* parameter: 'orderStatus' The status for the order
* parameter: 'startTime' Start time to search for orders
* parameter: 'endTime' End time to search for orders
*
* @return Return a list of matching orders or an empty list if no match was found.
*/
@Override
protected SearchResults getOtherSearchResults(Map<String, List<String>> parameters, boolean authorized) {
StorageOSUser user = getUserFromContext();
String tenantId = user.getTenantId();
if (parameters.containsKey(SearchConstants.TENANT_ID_PARAM)) {
tenantId = parameters.get(SearchConstants.TENANT_ID_PARAM).get(0);
}
verifyAuthorizedInTenantOrg(uri(tenantId), user);
if (!parameters.containsKey(SearchConstants.ORDER_STATUS_PARAM) && !parameters.containsKey(SearchConstants.START_TIME_PARAM) && !parameters.containsKey(SearchConstants.END_TIME_PARAM)) {
throw APIException.badRequests.invalidParameterSearchMissingParameter(getResourceClass().getName(), SearchConstants.ORDER_STATUS_PARAM + " or " + SearchConstants.START_TIME_PARAM + " or " + SearchConstants.END_TIME_PARAM);
}
if (parameters.containsKey(SearchConstants.ORDER_STATUS_PARAM) && (parameters.containsKey(SearchConstants.START_TIME_PARAM) || parameters.containsKey(SearchConstants.END_TIME_PARAM))) {
throw APIException.badRequests.parameterForSearchCouldNotBeCombinedWithAnyOtherParameter(getResourceClass().getName(), SearchConstants.ORDER_STATUS_PARAM, SearchConstants.START_TIME_PARAM + " or " + SearchConstants.END_TIME_PARAM);
}
List<Order> orders = Lists.newArrayList();
if (parameters.containsKey(SearchConstants.ORDER_STATUS_PARAM)) {
String orderStatus = parameters.get(SearchConstants.ORDER_STATUS_PARAM).get(0);
ArgValidator.checkFieldNotEmpty(orderStatus, SearchConstants.ORDER_STATUS_PARAM);
orders = orderManager.findOrdersByStatus(uri(tenantId), OrderStatus.valueOf(orderStatus));
} else if (parameters.containsKey(SearchConstants.START_TIME_PARAM) || parameters.containsKey(SearchConstants.END_TIME_PARAM)) {
Date startTime = null;
if (parameters.containsKey(SearchConstants.START_TIME_PARAM)) {
startTime = TimeUtils.getDateTimestamp(parameters.get(SearchConstants.START_TIME_PARAM).get(0));
}
Date endTime = null;
if (parameters.containsKey(SearchConstants.END_TIME_PARAM)) {
endTime = TimeUtils.getDateTimestamp(parameters.get(SearchConstants.END_TIME_PARAM).get(0));
}
if (startTime == null && endTime == null) {
throw APIException.badRequests.invalidParameterSearchMissingParameter(getResourceClass().getName(), SearchConstants.ORDER_STATUS_PARAM + " or " + SearchConstants.START_TIME_PARAM + " or " + SearchConstants.END_TIME_PARAM);
}
if (startTime.after(endTime)) {
throw APIException.badRequests.endTimeBeforeStartTime(startTime.toString(), endTime.toString());
}
int maxCount = -1;
List<String> c = parameters.get(SearchConstants.ORDER_MAX_COUNT);
if (c != null) {
String maxCountParam = parameters.get(SearchConstants.ORDER_MAX_COUNT).get(0);
maxCount = Integer.parseInt(maxCountParam);
}
orders = orderManager.findOrdersByTimeRange(uri(tenantId), startTime, endTime, maxCount);
}
ResRepFilter<SearchResultResourceRep> resRepFilter = (ResRepFilter<SearchResultResourceRep>) getPermissionFilter(getUserFromContext(), _permissionsHelper);
List<SearchResultResourceRep> searchResultResourceReps = Lists.newArrayList();
for (Order order : orders) {
RestLinkRep selfLink = new RestLinkRep("self", RestLinkFactory.newLink(getResourceType(), order.getId()));
SearchResultResourceRep searchResultResourceRep = new SearchResultResourceRep();
searchResultResourceRep.setId(order.getId());
searchResultResourceRep.setLink(selfLink);
if (authorized || resRepFilter.isAccessible(searchResultResourceRep)) {
searchResultResourceReps.add(searchResultResourceRep);
}
}
SearchResults result = new SearchResults();
result.setResource(searchResultResourceReps);
return result;
}
use of com.emc.storageos.model.search.SearchResultResourceRep in project coprhd-controller by CoprHD.
the class ApprovalService method getOtherSearchResults.
/**
* parameter: 'orderId' The id of the order to search for approvals
* parameter: 'approvalStatus' The status for the approval.
* parameter: 'tenantId' The id of the tenant (if not the current tenant)
*
* @return Return a list of matching approvals or an empty list if no match was found.
*/
@Override
protected SearchResults getOtherSearchResults(Map<String, List<String>> parameters, boolean authorized) {
StorageOSUser user = getUserFromContext();
String tenantId = user.getTenantId();
if (parameters.containsKey(SearchConstants.TENANT_ID_PARAM)) {
tenantId = parameters.get(SearchConstants.TENANT_ID_PARAM).get(0);
}
verifyAuthorizedInTenantOrg(uri(tenantId), user);
if (!parameters.containsKey(SearchConstants.ORDER_ID_PARAM) && !parameters.containsKey(SearchConstants.APPROVAL_STATUS_PARAM)) {
throw APIException.badRequests.invalidParameterSearchMissingParameter(getResourceClass().getName(), SearchConstants.ORDER_ID_PARAM + " or " + SearchConstants.APPROVAL_STATUS_PARAM);
}
if (parameters.containsKey(SearchConstants.ORDER_ID_PARAM) && parameters.containsKey(SearchConstants.APPROVAL_STATUS_PARAM)) {
throw APIException.badRequests.parameterForSearchCouldNotBeCombinedWithAnyOtherParameter(getResourceClass().getName(), SearchConstants.ORDER_ID_PARAM, SearchConstants.APPROVAL_STATUS_PARAM);
}
List<ApprovalRequest> approvals = Lists.newArrayList();
if (parameters.containsKey(SearchConstants.ORDER_ID_PARAM)) {
String orderId = parameters.get(SearchConstants.ORDER_ID_PARAM).get(0);
ArgValidator.checkFieldNotEmpty(orderId, SearchConstants.ORDER_ID_PARAM);
approvals = approvalManager.findApprovalsByOrderId(uri(orderId));
} else if (parameters.containsKey(SearchConstants.APPROVAL_STATUS_PARAM)) {
String approvalStatus = parameters.get(SearchConstants.APPROVAL_STATUS_PARAM).get(0);
ArgValidator.checkFieldNotEmpty(approvalStatus, SearchConstants.APPROVAL_STATUS_PARAM);
approvals = approvalManager.findApprovalsByStatus(uri(tenantId), ApprovalStatus.valueOf(approvalStatus));
}
ResRepFilter<SearchResultResourceRep> resRepFilter = (ResRepFilter<SearchResultResourceRep>) getPermissionFilter(getUserFromContext(), _permissionsHelper);
List<SearchResultResourceRep> searchResultResourceReps = Lists.newArrayList();
for (ApprovalRequest approval : approvals) {
RestLinkRep selfLink = new RestLinkRep("self", RestLinkFactory.newLink(getResourceType(), approval.getId()));
SearchResultResourceRep searchResultResourceRep = new SearchResultResourceRep();
searchResultResourceRep.setId(approval.getId());
searchResultResourceRep.setLink(selfLink);
if (authorized || resRepFilter.isAccessible(searchResultResourceRep)) {
searchResultResourceReps.add(searchResultResourceRep);
}
}
SearchResults result = new SearchResults();
result.setResource(searchResultResourceReps);
return result;
}
use of com.emc.storageos.model.search.SearchResultResourceRep in project coprhd-controller by CoprHD.
the class AbstractResources method performSearch.
/**
* Performs a search for resources matching the given parameters.
*
* @param params
* the search query parameters.
* @return the list of resources.
*/
public List<SearchResultResourceRep> performSearch(Map<String, Object> params) {
UriBuilder builder = client.uriBuilder(getSearchUrl());
for (Map.Entry<String, Object> entry : params.entrySet()) {
builder.queryParam(entry.getKey(), entry.getValue());
}
SearchResults searchResults = client.getURI(SearchResults.class, builder.build());
List<SearchResultResourceRep> results = searchResults.getResource();
if (results == null) {
results = new ArrayList<SearchResultResourceRep>();
}
return results;
}
use of com.emc.storageos.model.search.SearchResultResourceRep in project coprhd-controller by CoprHD.
the class ExportGroupService method getOtherSearchResults.
/**
* Additional search criteria for a export group.
*
* If a matching export group is not found, an empty list is returned.
*
* Parameters - host String - URI of the host
* - cluster String - URI of the cluster
* - initiator String - URI of the initiator
* - self_only - Optional parameter to allow for specific type search, [true or false]
*/
@Override
protected SearchResults getOtherSearchResults(Map<String, List<String>> parameters, boolean authorized) {
SearchResults result = new SearchResults();
String[] searchCriteria = { SEARCH_HOST, SEARCH_CLUSTER, SEARCH_INITIATOR, SEARCH_LEVEL };
validateSearchParameters(parameters, searchCriteria);
boolean selfOnly = isSelfOnly(parameters, SEARCH_LEVEL);
List<SearchResultResourceRep> resRepLists = new ArrayList<SearchResultResourceRep>();
for (Map.Entry<String, List<String>> entry : parameters.entrySet()) {
for (String searchValue : entry.getValue()) {
if (entry.getKey().equals(SEARCH_HOST)) {
// Search for host export
searchForHostExport(searchValue, resRepLists, selfOnly, authorized);
} else if (entry.getKey().equals(SEARCH_CLUSTER)) {
// search for cluster export
searchForClusterExport(searchValue, resRepLists, selfOnly, authorized);
} else if (entry.getKey().equals(SEARCH_INITIATOR)) {
// search for initiator export
if (isInitiatorId(searchValue)) {
searchforInitiatorExport(searchValue, resRepLists, selfOnly, authorized);
} else {
searchforInitiatorExportByWWN(searchValue, resRepLists, selfOnly, authorized);
}
}
result.setResource(resRepLists);
}
}
return result;
}
use of com.emc.storageos.model.search.SearchResultResourceRep in project coprhd-controller by CoprHD.
the class TaggedResource method search.
/**
* @brief search API
* Search resources by name, tag, project or additional parameters (for example, wwn or initiator_port etc.)
*
* @prereq none
* @return search results
*/
/*
* Parameters:
* Common Parameters:
* name: Name has to be a minimum of 2 characters. Could only be combined with project parameter
* tag: Tag has to be a minimum of 2 characters. Could only be combined with tenant parameter
* project: The full project URI needs to be provided.
*
* NOTE: Name and tag are not case sensitive.
* For Zone level resources, search by project is not allowed.
* Special Parameters:
* wwn: only used by block service
* initiator_port: only used by virtual array service.
*/
@GET
@Path("/search")
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public SearchResults search() {
// 1. Figure out user privilege
boolean bAuthorized = false;
StorageOSUser user = getUserFromContext();
if (_permissionsHelper.userHasGivenRole(user, null, Role.SYSTEM_MONITOR)) {
bAuthorized = true;
} else if ((isZoneLevelResource() || isSysAdminReadableResource()) && (_permissionsHelper.userHasGivenRole(user, null, Role.SYSTEM_ADMIN))) {
bAuthorized = true;
}
// 2. Parameter check and early detection for unsupported search
String name = null, tag = null;
URI projectId = null, tenant = null;
Map<String, List<String>> parameters = uriInfo.getQueryParameters();
// remove non-search related common parameters
parameters.remove(RequestProcessingUtils.REQUESTING_COOKIES);
if (parameters.containsKey("name")) {
name = parameters.get("name").get(0);
checkSearchParameterLength("name", name, getResourceClass());
checkParameterCombination(parameters, getResourceClass(), "name", "project");
}
if (parameters.containsKey("tag")) {
tag = parameters.get("tag").get(0);
checkSearchParameterLength("tag", tag, getResourceClass());
checkParameterCombination(parameters, getResourceClass(), "tag", "tenant");
// set tenant scope for non-zone resources
if (!isZoneLevelResource()) {
if (parameters.containsKey("tenant")) {
tenant = URI.create(parameters.get("tenant").get(0));
}
}
}
if (parameters.containsKey("project")) {
checkParameterCombination(parameters, getResourceClass(), "project", "name");
projectId = URI.create(parameters.get("project").get(0));
if (isZoneLevelResource()) {
throw APIException.badRequests.invalidParameterSearchProjectNotSupported(getResourceClass().getName());
}
// check if user is authorized for the project
if (!bAuthorized) {
if (!isAuthorized(projectId)) {
throw APIException.forbidden.insufficientPermissionsForUser(getUserFromContext().toString());
}
bAuthorized = true;
}
}
// 3. Search from db and response permission-eligible results
SearchResults result = new SearchResults();
if (name != null || tag != null) {
SearchedResRepList resRepList = null;
if (name != null) {
// search named resources
resRepList = getNamedSearchResults(name, projectId);
} else {
// search tagged resources
resRepList = getTagSearchResults(tag, tenant);
}
if (!bAuthorized) {
SearchedResRepList filteredResRepList = new SearchedResRepList();
Iterator<SearchResultResourceRep> _queryResultIterator = resRepList.iterator();
ResRepFilter<SearchResultResourceRep> resrepFilter = null;
resrepFilter = (ResRepFilter<SearchResultResourceRep>) getPermissionFilter(getUserFromContext(), _permissionsHelper);
filteredResRepList.setResult(new FilterIterator<SearchResultResourceRep>(_queryResultIterator, resrepFilter));
result.setResource(filteredResRepList);
} else {
result.setResource(resRepList);
}
return result;
}
if (projectId != null) {
// start resource search within project
// note: for project resources search, the permission check
// has been addressed in parameter checke period.
result.setResource(getProjectSearchResults(projectId));
return result;
}
// some other resource specific search
return getOtherSearchResults(parameters, bAuthorized);
}
Aggregations