Search in sources :

Example 11 with SearchedResRepList

use of com.emc.storageos.api.service.impl.response.SearchedResRepList 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)

Example 12 with SearchedResRepList

use of com.emc.storageos.api.service.impl.response.SearchedResRepList in project coprhd-controller by CoprHD.

the class BlockConsistencyGroupService method getProjectSearchResults.

/**
 * Get search results by project alone.
 *
 * @return SearchedResRepList
 */
@Override
protected SearchedResRepList getProjectSearchResults(final URI projectId) {
    SearchedResRepList resRepList = new SearchedResRepList(getResourceType());
    _dbClient.queryByConstraint(ContainmentConstraint.Factory.getProjectBlockConsistencyGroupConstraint(projectId), resRepList);
    return resRepList;
}
Also used : SearchedResRepList(com.emc.storageos.api.service.impl.response.SearchedResRepList)

Example 13 with SearchedResRepList

use of com.emc.storageos.api.service.impl.response.SearchedResRepList in project coprhd-controller by CoprHD.

the class BlockSnapshotSessionService method getProjectSearchResults.

/**
 * Get search results by project alone.
 *
 * @return SearchedResRepList
 */
@Override
protected SearchedResRepList getProjectSearchResults(URI projectId) {
    SearchedResRepList resRepList = new SearchedResRepList(getResourceType());
    _dbClient.queryByConstraint(ContainmentConstraint.Factory.getProjectBlockSnapshotSessionConstraint(projectId), resRepList);
    return resRepList;
}
Also used : SearchedResRepList(com.emc.storageos.api.service.impl.response.SearchedResRepList)

Example 14 with SearchedResRepList

use of com.emc.storageos.api.service.impl.response.SearchedResRepList in project coprhd-controller by CoprHD.

the class FileService method getProjectSearchResults.

/**
 * Get search results by project alone.
 *
 * @return SearchedResRepList
 */
@Override
protected SearchedResRepList getProjectSearchResults(URI projectId) {
    SearchedResRepList resRepList = new SearchedResRepList(getResourceType());
    _dbClient.queryByConstraint(ContainmentConstraint.Factory.getProjectFileshareConstraint(projectId), resRepList);
    return resRepList;
}
Also used : SearchedResRepList(com.emc.storageos.api.service.impl.response.SearchedResRepList)

Example 15 with SearchedResRepList

use of com.emc.storageos.api.service.impl.response.SearchedResRepList in project coprhd-controller by CoprHD.

the class ExportService method searchHostInDb.

private Host searchHostInDb(String hostname) {
    SearchedResRepList resRepList = new SearchedResRepList(ResourceTypeEnum.HOST);
    _dbClient.queryByConstraint(AlternateIdConstraint.Factory.getConstraint(Host.class, "hostName", hostname), resRepList);
    if (resRepList.iterator() != null) {
        for (SearchResultResourceRep res : resRepList) {
            Host host = _dbClient.queryObject(Host.class, res.getId());
            if ((host != null) && !(host.getInactive())) {
                return host;
            }
        }
    }
    // if not found
    return null;
}
Also used : SearchResultResourceRep(com.emc.storageos.model.search.SearchResultResourceRep) SearchedResRepList(com.emc.storageos.api.service.impl.response.SearchedResRepList) Host(com.emc.storageos.db.client.model.Host)

Aggregations

SearchedResRepList (com.emc.storageos.api.service.impl.response.SearchedResRepList)20 SearchResultResourceRep (com.emc.storageos.model.search.SearchResultResourceRep)9 SearchResults (com.emc.storageos.model.search.SearchResults)5 List (java.util.List)5 BulkList (com.emc.storageos.api.service.impl.response.BulkList)4 ResRepFilter (com.emc.storageos.api.service.impl.response.ResRepFilter)3 URI (java.net.URI)3 Map (java.util.Map)3 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)2 StringMap (com.emc.storageos.db.client.model.StringMap)2 RestLinkRep (com.emc.storageos.model.RestLinkRep)2 ITLRestRepList (com.emc.storageos.model.block.export.ITLRestRepList)2 ArrayList (java.util.ArrayList)2 Consumes (javax.ws.rs.Consumes)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 MapCustomConfig (com.emc.storageos.api.mapper.functions.MapCustomConfig)1 MapVolume (com.emc.storageos.api.mapper.functions.MapVolume)1 ProjOwnedResRepFilter (com.emc.storageos.api.service.impl.response.ProjOwnedResRepFilter)1