Search in sources :

Example 1 with SearchedResRepList

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

the class FileSnapshotService 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.getProjectFileSnapshotConstraint(projectId), resRepList);
    return resRepList;
}
Also used : SearchedResRepList(com.emc.storageos.api.service.impl.response.SearchedResRepList)

Example 2 with SearchedResRepList

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

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

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

the class ExportService method searchInDb.

// Sometimes there are multiple entries for the same initiator
// and so we return a list here
private Boolean searchInDb(String port, List<Initiator> list, String protocol) {
    SearchedResRepList resRepList = new SearchedResRepList(ResourceTypeEnum.INITIATOR);
    Boolean found = false;
    String formattedStr = "";
    if (protocol.equalsIgnoreCase(Protocol.FC.name())) {
        int index = 0;
        while (index < (port.length())) {
            formattedStr += port.substring(index, index + 2).toUpperCase();
            index = index + 2;
            if (index < (port.length())) {
                formattedStr += ":";
            }
        }
    } else if (protocol.equalsIgnoreCase(Protocol.iSCSI.name())) {
        formattedStr = port;
    }
    // Finds the Initiator that includes the initiator port specified, if any.
    _dbClient.queryByConstraint(AlternateIdConstraint.Factory.getInitiatorPortInitiatorConstraint(formattedStr), resRepList);
    if (resRepList.iterator() != null) {
        for (SearchResultResourceRep res : resRepList) {
            Initiator initiator = _dbClient.queryObject(Initiator.class, res.getId());
            if ((initiator != null) && !(initiator.getInactive())) {
                list.add(initiator);
                _log.info("Found initiator in DB for port = {}", port);
                found = true;
            }
        }
    }
    return found;
}
Also used : Initiator(com.emc.storageos.db.client.model.Initiator) SearchResultResourceRep(com.emc.storageos.model.search.SearchResultResourceRep) SearchedResRepList(com.emc.storageos.api.service.impl.response.SearchedResRepList) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint)

Example 5 with SearchedResRepList

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

the class TaggedResource method getNamedSearchResults.

/**
 * Get search results by name in zone (default) or in a specific project.
 *
 * @return SearchedResRepList
 */
protected SearchedResRepList getNamedSearchResults(String name, URI projectId) {
    SearchedResRepList resRepList = null;
    if (projectId == null) {
        resRepList = new SearchedResRepList(getResourceType());
        _dbClient.queryByConstraint(PrefixConstraint.Factory.getLabelPrefixConstraint(getResourceClass(), name), resRepList);
    } else {
        throw APIException.badRequests.parameterNotSupportedFor("project-level search", MessageFormat.format("{0} search", getResourceClass().getName()));
    }
    return resRepList;
}
Also used : SearchedResRepList(com.emc.storageos.api.service.impl.response.SearchedResRepList)

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