use of org.alfresco.repo.search.impl.solr.facet.Exceptions.UnrecognisedFacetId in project alfresco-remote-api by Alfresco.
the class SolrFacetConfigAdminPut method unprotectedExecuteImpl.
@Override
protected Map<String, Object> unprotectedExecuteImpl(WebScriptRequest req, Status status, Cache cache) {
final String relativePosString = req.getParameter(PARAM_RELATIVE_POS);
try {
if (relativePosString != null) {
// This is a request to 'move' (reposition) the specified facet.
// We need the relative position that the facet will move.
final int relativePos;
try {
relativePos = Integer.parseInt(relativePosString);
} catch (NumberFormatException nfe) {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Cannot move facet as could not parse relative position: '" + relativePosString + "'");
}
// And we need the filterID for the facet we're moving.
final Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
String filterId = templateVars.get(URL_PARAM_FILTER_ID);
if (filterId == null) {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Illegal null filterId");
}
// So let's move the filter...
try {
// Get the current sequence of filter IDs.
List<SolrFacetProperties> facets = facetService.getFacets();
List<String> facetIDs = CollectionUtils.transform(facets, new Function<SolrFacetProperties, String>() {
@Override
public String apply(SolrFacetProperties value) {
return value.getFilterID();
}
});
List<String> reorderedIDs = CollectionUtils.moveRight(relativePos, filterId, facetIDs);
this.facetService.reorderFacets(reorderedIDs);
if (logger.isDebugEnabled()) {
logger.debug("Moved facet " + filterId + " to relative position: " + relativePos);
}
} catch (UnrecognisedFacetId ufi) {
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Unrecognised filter ID: " + ufi.getFacetId());
}
} else // TODO Allow for simultaneous move and update of facet.
{
SolrFacetProperties fp = parseRequestForFacetProperties(req);
facetService.updateFacet(fp);
if (logger.isDebugEnabled()) {
logger.debug("Updated facet node: " + fp);
}
}
} catch (Throwable t) {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Could not update the facet configuration.", t);
}
Map<String, Object> model = new HashMap<String, Object>(1);
return model;
}
Aggregations