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