Search in sources :

Example 1 with SearchResultResourceRep

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

the class InitiatorService method getOtherSearchResults.

/**
 * parameter: 'initiator_port' The identifier of the initiator port.
 *
 * @return Return a list of initiator that containts the initiator port specified
 *         or an empty list if no match was found.
 */
@Override
protected SearchResults getOtherSearchResults(Map<String, List<String>> parameters, boolean authorized) {
    SearchResults result = new SearchResults();
    if (!parameters.containsKey("initiator_port")) {
        throw APIException.badRequests.invalidParameterSearchMissingParameter(getResourceClass().getName(), "initiator_port");
    }
    for (Map.Entry<String, List<String>> entry : parameters.entrySet()) {
        if (!entry.getKey().equals("initiator_port")) {
            throw APIException.badRequests.parameterForSearchCouldNotBeCombinedWithAnyOtherParameter(getResourceClass().getName(), "initiator_port", entry.getKey());
        }
    }
    String port = parameters.get("initiator_port").get(0);
    // Validate that the initiator_port value is not empty
    ArgValidator.checkFieldNotEmpty(port, "initiator_port");
    // Validate the format of the initiator port.
    if (!EndpointUtility.isValidEndpoint(port, EndpointType.SAN)) {
        throw APIException.badRequests.initiatorPortNotValid();
    }
    SearchedResRepList resRepList = new SearchedResRepList(getResourceType());
    // Finds the Initiator that includes the initiator port specified, if any.
    _dbClient.queryByConstraint(AlternateIdConstraint.Factory.getInitiatorPortInitiatorConstraint(port), resRepList);
    // Filter list based on permission
    if (!authorized) {
        Iterator<SearchResultResourceRep> _queryResultIterator = resRepList.iterator();
        ResRepFilter<SearchResultResourceRep> resRepFilter = (ResRepFilter<SearchResultResourceRep>) getPermissionFilter(getUserFromContext(), _permissionsHelper);
        SearchedResRepList filteredResRepList = new SearchedResRepList();
        filteredResRepList.setResult(new FilterIterator<SearchResultResourceRep>(_queryResultIterator, resRepFilter));
        result.setResource(filteredResRepList);
    } else {
        result.setResource(resRepList);
    }
    return result;
}
Also used : SearchResultResourceRep(com.emc.storageos.model.search.SearchResultResourceRep) SearchedResRepList(com.emc.storageos.api.service.impl.response.SearchedResRepList) ITLRestRepList(com.emc.storageos.model.block.export.ITLRestRepList) List(java.util.List) BulkList(com.emc.storageos.api.service.impl.response.BulkList) SearchedResRepList(com.emc.storageos.api.service.impl.response.SearchedResRepList) SearchResults(com.emc.storageos.model.search.SearchResults) ResRepFilter(com.emc.storageos.api.service.impl.response.ResRepFilter) Map(java.util.Map)

Example 2 with SearchResultResourceRep

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

the class IpInterfaceService method getOtherSearchResults.

/**
 * parameter: 'ip_address' The ip address of the ipInterface
 *
 * @return Return a list of ipinterfaces that contains the ip address specified
 *         or an empty list if no match was found.
 */
@Override
protected SearchResults getOtherSearchResults(Map<String, List<String>> parameters, boolean authorized) {
    SearchResults result = new SearchResults();
    if (!parameters.containsKey("ip_address")) {
        throw APIException.badRequests.invalidParameterSearchMissingParameter(getResourceClass().getName(), "ip_address");
    }
    for (Map.Entry<String, List<String>> entry : parameters.entrySet()) {
        if (!entry.getKey().equals("ip_address")) {
            throw APIException.badRequests.parameterForSearchCouldNotBeCombinedWithAnyOtherParameter(getResourceClass().getName(), "ip_address", entry.getKey());
        }
    }
    String ip = parameters.get("ip_address").get(0);
    // Validate that the ip_address value is not empty
    ArgValidator.checkFieldNotEmpty(ip, "ip_address");
    // Validate the format of the initiator port.
    if (!EndpointUtility.isValidEndpoint(ip, EndpointType.IP)) {
        throw APIException.badRequests.invalidParameterInvalidIP("ip_address", ip);
    }
    SearchedResRepList resRepList = new SearchedResRepList(getResourceType());
    // Finds the IpInterface that includes the ip address specified, if any.
    _dbClient.queryByConstraint(AlternateIdConstraint.Factory.getIpInterfaceIpAddressConstraint(ip), resRepList);
    // Filter list based on permission
    if (!authorized) {
        Iterator<SearchResultResourceRep> _queryResultIterator = resRepList.iterator();
        ResRepFilter<SearchResultResourceRep> resRepFilter = (ResRepFilter<SearchResultResourceRep>) getPermissionFilter(getUserFromContext(), _permissionsHelper);
        SearchedResRepList filteredResRepList = new SearchedResRepList();
        filteredResRepList.setResult(new FilterIterator<SearchResultResourceRep>(_queryResultIterator, resRepFilter));
        result.setResource(filteredResRepList);
    } else {
        result.setResource(resRepList);
    }
    return result;
}
Also used : SearchResultResourceRep(com.emc.storageos.model.search.SearchResultResourceRep) SearchedResRepList(com.emc.storageos.api.service.impl.response.SearchedResRepList) List(java.util.List) BulkList(com.emc.storageos.api.service.impl.response.BulkList) SearchedResRepList(com.emc.storageos.api.service.impl.response.SearchedResRepList) SearchResults(com.emc.storageos.model.search.SearchResults) ResRepFilter(com.emc.storageos.api.service.impl.response.ResRepFilter) Map(java.util.Map)

Example 3 with SearchResultResourceRep

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

the class FileService method getOtherSearchResults.

/**
 * 'mountPath' is not case sensitive. The complete mountPath should be specified.
 *
 * If a matching filesystem is not found, an empty list is returned.
 *
 * Parameters - mountPath String - mountPath of the filesystem
 */
@Override
protected SearchResults getOtherSearchResults(Map<String, List<String>> parameters, boolean authorized) {
    SearchResults result = new SearchResults();
    // Here we search by mountPath
    if (!parameters.containsKey("mountPath")) {
        throw APIException.badRequests.invalidParameterSearchMissingParameter(getResourceClass().getName(), "mountPath");
    }
    String mountPath = parameters.get("mountPath").get(0);
    List<SearchResultResourceRep> resRepList = new ArrayList<SearchResultResourceRep>();
    URIQueryResultList fsUriList = new URIQueryResultList();
    _dbClient.queryByConstraint(AlternateIdConstraint.Factory.getFileSystemMountPathConstraint(mountPath), fsUriList);
    _log.info("After query of the database for {} and result {}", mountPath, fsUriList);
    Iterator<URI> fsListIterator = fsUriList.iterator();
    while (fsListIterator.hasNext()) {
        URI uri = fsListIterator.next();
        FileShare fs = _dbClient.queryObject(FileShare.class, uri);
        if (!fs.getInactive()) {
            if (authorized || isAuthorized(fs.getProject().getURI())) {
                RestLinkRep selfLink = new RestLinkRep("self", RestLinkFactory.newLink(getResourceType(), uri));
                SearchResultResourceRep r = new SearchResultResourceRep(uri, selfLink, fs.getMountPath());
                resRepList.add(r);
                _log.info("Mount path match " + fs.getMountPath());
            } else {
                _log.info("Mount path match but not authorized " + fs.getMountPath());
            }
        }
    }
    result.setResource(resRepList);
    return result;
}
Also used : SearchResultResourceRep(com.emc.storageos.model.search.SearchResultResourceRep) ArrayList(java.util.ArrayList) RestLinkRep(com.emc.storageos.model.RestLinkRep) SearchResults(com.emc.storageos.model.search.SearchResults) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) MapFileShare(com.emc.storageos.api.mapper.functions.MapFileShare) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Example 4 with SearchResultResourceRep

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

the class ExportGroupService method buildExportGroupSearchResponse.

/**
 * Build search response based on query result.
 *
 * @param exportGroups from query
 * @param resRepLists result
 * @param selfOnly true or false
 * @param type Cluster, Host or Initiator
 */
private void buildExportGroupSearchResponse(List<ExportGroup> exportGroups, List<SearchResultResourceRep> resRepLists, boolean selfOnly, String type, boolean authorized) {
    PermissionsEnforcingResourceFilter<ExportGroup> filter = new ExportGroupSearchFilter(getUserFromContext(), _permissionsHelper);
    for (ExportGroup eg : exportGroups) {
        if (!authorized && !filter.isExposed(eg)) {
            // authorization failed, don't add to search result
            continue;
        }
        if (selfOnly) {
            if (!eg.getType().equals(type)) {
                // match invalid, only return matching types, process next
                continue;
            }
        }
        RestLinkRep selfLink = new RestLinkRep("self", RestLinkFactory.newLink(getResourceType(), eg.getId()));
        SearchResultResourceRep searchResult = new SearchResultResourceRep(eg.getId(), selfLink, eg.getLabel());
        resRepLists.add(searchResult);
    }
}
Also used : ExportGroup(com.emc.storageos.db.client.model.ExportGroup) SearchResultResourceRep(com.emc.storageos.model.search.SearchResultResourceRep) RestLinkRep(com.emc.storageos.model.RestLinkRep)

Example 5 with SearchResultResourceRep

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

the class CustomConfigService method search.

/**
 * Search configs
 * <p>
 * Users could search configs by name, or config_name, or scope or system_default flag. e.g. /search?name=;
 * /search?config_name=SanZoneName; /search?config_name=SanZoneName&&scope=systemType.mds
 *
 * @brief Search configs
 * @return search result
 */
@GET
@Path("/search")
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public SearchResults search() {
    Map<String, List<String>> parameters = uriInfo.getQueryParameters();
    // remove non-search related common parameters
    parameters.remove(RequestProcessingUtils.REQUESTING_COOKIES);
    SearchedResRepList resRepList = null;
    SearchResults result = new SearchResults();
    String name = null;
    if (parameters.containsKey(NAME)) {
        name = parameters.get(NAME).get(0);
        ArgValidator.checkFieldNotEmpty(name, NAME);
        resRepList = new SearchedResRepList(getResourceType());
        _dbClient.queryByConstraint(PrefixConstraint.Factory.getLabelPrefixConstraint(CustomConfig.class, name), resRepList);
        String systemDefault = null;
        if (parameters.containsKey(SYSTEM_DEFAULT)) {
            systemDefault = parameters.get(SYSTEM_DEFAULT).get(0);
            List<SearchResultResourceRep> searchResultList = new ArrayList<SearchResultResourceRep>();
            Iterator<SearchResultResourceRep> it = resRepList.iterator();
            while (it.hasNext()) {
                SearchResultResourceRep rp = it.next();
                URI id = rp.getId();
                CustomConfig config = queryResource(id);
                if (systemDefault.equals(config.getSystemDefault().toString())) {
                    RestLinkRep selfLink = new RestLinkRep("self", RestLinkFactory.newLink(getResourceType(), id));
                    SearchResultResourceRep searchResult = new SearchResultResourceRep(id, selfLink, config.getLabel());
                    searchResultList.add(searchResult);
                }
            }
            result.setResource(searchResultList);
        } else {
            result.setResource(resRepList);
        }
    } else if (parameters.containsKey(CONFIG_TYPE)) {
        String configName = parameters.get(CONFIG_TYPE).get(0);
        // Validate the user passed a value for the config type.
        ArgValidator.checkFieldNotEmpty(configName, CONFIG_TYPE);
        StringMap scopeMap = null;
        if (parameters.containsKey(SCOPE)) {
            String scope = parameters.get(SCOPE).get(0);
            scopeMap = new StringMap();
            if (scope.contains(".")) {
                String[] scopeSplits = scope.split("\\.");
                scopeMap.put(scopeSplits[0], scopeSplits[1]);
            } else {
                throw APIException.badRequests.invalidScopeFomart(scope);
            }
        }
        String systemDefault = null;
        if (parameters.containsKey(SYSTEM_DEFAULT)) {
            systemDefault = parameters.get(SYSTEM_DEFAULT).get(0);
        }
        List<SearchResultResourceRep> searchResultList = new ArrayList<SearchResultResourceRep>();
        List<CustomConfig> configList = getCustomConfig(configName, scopeMap);
        for (CustomConfig config : configList) {
            if (config.getInactive()) {
                continue;
            }
            if (systemDefault != null && !systemDefault.equals(config.getSystemDefault().toString())) {
                continue;
            }
            RestLinkRep selfLink = new RestLinkRep("self", RestLinkFactory.newLink(getResourceType(), config.getId()));
            SearchResultResourceRep searchResult = new SearchResultResourceRep(config.getId(), selfLink, config.getLabel());
            searchResultList.add(searchResult);
        }
        result.setResource(searchResultList);
    } else if (parameters.containsKey(SYSTEM_DEFAULT)) {
        // search parameters only contains system_default
        List<SearchResultResourceRep> searchResultList = new ArrayList<SearchResultResourceRep>();
        String systemDefault = parameters.get(SYSTEM_DEFAULT).get(0);
        List<URI> ids = _dbClient.queryByType(CustomConfig.class, true);
        Iterator<CustomConfig> iter = _dbClient.queryIterativeObjects(CustomConfig.class, ids);
        while (iter.hasNext()) {
            CustomConfig config = iter.next();
            if (systemDefault.equals(config.getSystemDefault().toString())) {
                RestLinkRep selfLink = new RestLinkRep("self", RestLinkFactory.newLink(getResourceType(), config.getId()));
                SearchResultResourceRep searchResult = new SearchResultResourceRep(config.getId(), selfLink, config.getLabel());
                searchResultList.add(searchResult);
            }
        }
        result.setResource(searchResultList);
    }
    return result;
}
Also used : CustomConfig(com.emc.storageos.db.client.model.CustomConfig) MapCustomConfig(com.emc.storageos.api.mapper.functions.MapCustomConfig) StringMap(com.emc.storageos.db.client.model.StringMap) SearchResultResourceRep(com.emc.storageos.model.search.SearchResultResourceRep) ArrayList(java.util.ArrayList) RestLinkRep(com.emc.storageos.model.RestLinkRep) SearchedResRepList(com.emc.storageos.api.service.impl.response.SearchedResRepList) SearchResults(com.emc.storageos.model.search.SearchResults) URI(java.net.URI) CustomConfigVariableList(com.emc.storageos.model.customconfig.CustomConfigVariableList) List(java.util.List) ArrayList(java.util.ArrayList) ScopeParamList(com.emc.storageos.model.customconfig.ScopeParamList) CustomConfigList(com.emc.storageos.model.customconfig.CustomConfigList) BulkList(com.emc.storageos.api.service.impl.response.BulkList) SearchedResRepList(com.emc.storageos.api.service.impl.response.SearchedResRepList) CustomConfigRuleList(com.emc.storageos.model.customconfig.CustomConfigRuleList) CustomConfigTypeList(com.emc.storageos.model.customconfig.CustomConfigTypeList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

SearchResultResourceRep (com.emc.storageos.model.search.SearchResultResourceRep)19 SearchResults (com.emc.storageos.model.search.SearchResults)11 SearchedResRepList (com.emc.storageos.api.service.impl.response.SearchedResRepList)10 RestLinkRep (com.emc.storageos.model.RestLinkRep)8 ArrayList (java.util.ArrayList)8 List (java.util.List)8 URI (java.net.URI)7 BulkList (com.emc.storageos.api.service.impl.response.BulkList)6 ResRepFilter (com.emc.storageos.api.service.impl.response.ResRepFilter)5 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)5 Map (java.util.Map)5 StringMap (com.emc.storageos.db.client.model.StringMap)3 ITLRestRepList (com.emc.storageos.model.block.export.ITLRestRepList)3 StorageOSUser (com.emc.storageos.security.authentication.StorageOSUser)3 NamedElementQueryResultList (com.emc.storageos.db.client.constraint.NamedElementQueryResultList)2 ExportGroup (com.emc.storageos.db.client.model.ExportGroup)2 Host (com.emc.storageos.db.client.model.Host)2 HashMap (java.util.HashMap)2 OrderMapper.toExecutionLogList (com.emc.sa.api.mapper.OrderMapper.toExecutionLogList)1 OrderMapper.toOrderLogList (com.emc.sa.api.mapper.OrderMapper.toOrderLogList)1