diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/solr/facet/solr-facet-config-admin.delete.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/solr/facet/solr-facet-config-admin.delete.desc.xml new file mode 100644 index 0000000000..3e7740642d --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/solr/facet/solr-facet-config-admin.delete.desc.xml @@ -0,0 +1,23 @@ + + Delete Faceted-Search Config + + :/alfresco/api/solr/facet-config + + Example response from this web script: + + { + "success" : true | false + } + + Notes: + - user must be an Admin, member of Alfresco_Search_Administrators group or a Network Admin for given network/tenant + ]]> + + /api/solr/facet-config/{filterID} + argument + user + required + \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/solr/facet/solr-facet-config-admin.delete.json.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/solr/facet/solr-facet-config-admin.delete.json.ftl new file mode 100644 index 0000000000..097efa3f7e --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/solr/facet/solr-facet-config-admin.delete.json.ftl @@ -0,0 +1,5 @@ +<#escape x as jsonUtils.encodeJSONString(x)> +{ + "success" : ${success?string} +} + \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/solr/facet/solr-facet-config-admin.get.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/solr/facet/solr-facet-config-admin.get.desc.xml new file mode 100644 index 0000000000..2e32f72993 --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/solr/facet/solr-facet-config-admin.get.desc.xml @@ -0,0 +1,41 @@ + + GET Faceted-Search Config + + :/alfresco/api/solr/facet-config + + Example response from this web script: + + { + "facets": [ + { + "filterID" : "filter_content_size", + "facetQName" : "{http://www.alfresco.org/model/content/1.0}content.size", + "displayName" : "faceted-search.facet-menu.facet.size", + "maxFilters" : 5, + "hitThreshold" : 1, + "minFilterValueLength" : 5, + "sortBy" : "ALPHABETICALLY", + "scope" : "SCOPED_SITES", + "scopedSites" : [ + "site3", + "site2", + "site1" + ], + "index" : 5, + "isEnabled" : true + } + ] + } + + Notes: + - user must be an Admin, member of Alfresco_Search_Administrators group or a Network Admin for given network/tenant + ]]> + + /api/solr/facet-config + argument + user + required + \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/solr/facet/solr-facet-config-admin.get.json.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/solr/facet/solr-facet-config-admin.get.json.ftl new file mode 100644 index 0000000000..9a2d021bd2 --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/solr/facet/solr-facet-config-admin.get.json.ftl @@ -0,0 +1,28 @@ +<#escape x as jsonUtils.encodeJSONString(x)> +{ + "facets": [ + <#list filters?keys as facet> + <#assign f=filters[facet]> + { + "filterID" : "${f.filterID}", + "facetQName" : "${f.facetQName}", + "displayName" : "${f.displayName}", + "maxFilters" : ${f.maxFilters?c}, + "hitThreshold" : ${f.hitThreshold?c}, + "minFilterValueLength" : ${f.minFilterValueLength?c}, + "sortBy" : "${f.sortBy}", + "scope" : "${f.scope}", + "scopedSites" : [ + <#if f.scopedSites??> + <#list f.scopedSites as site> + "${site}"<#if site_has_next>, + + + ], + "index" : ${f.index?c}, + "isEnabled" : ${f.enabled?c} + }<#if facet_has_next>, + + ] +} + diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/solr/facet/solr-facet-config-admin.post.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/solr/facet/solr-facet-config-admin.post.desc.xml new file mode 100644 index 0000000000..931dda90bc --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/solr/facet/solr-facet-config-admin.post.desc.xml @@ -0,0 +1,37 @@ + + POST Faceted-Search Config + + :/alfresco/api/solr/facet-config + + Example body to this web script: + + { + "filterID" : "filter_content_size", + "facetQName" : "{http://www.alfresco.org/model/content/1.0}content.size", + "displayName" : "faceted-search.facet-menu.facet.size", + "maxFilters" : 5, + "hitThreshold" : 1, + "minFilterValueLength" : 5, + "sortBy" : "ALPHABETICALLY", + "scope" : "SCOPED_SITES", + "scopedSites" : [ + "site3", + "site2", + "site1" + ], + "index" : 6, + "isEnabled" : true + } + + Notes: + - user must be an Admin, member of Alfresco_Search_Administrators group or a Network Admin for given network/tenant + ]]> + + /api/solr/facet-config + argument + user + required + \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/solr/facet/solr-facet-config-admin.post.json.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/solr/facet/solr-facet-config-admin.post.json.ftl new file mode 100644 index 0000000000..e69de29bb2 diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/solr/facet/solr-facet-config-admin.put.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/solr/facet/solr-facet-config-admin.put.desc.xml new file mode 100644 index 0000000000..3d721fa687 --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/solr/facet/solr-facet-config-admin.put.desc.xml @@ -0,0 +1,37 @@ + + PUT Faceted-Search Config + + :/alfresco/api/solr/facet-config + + Example body to this web script: + + { + "filterID" : "filter_content_size", + "facetQName" : "{http://www.alfresco.org/model/content/1.0}content.size", + "displayName" : "faceted-search.facet-menu.facet.size", + "maxFilters" : 5, + "hitThreshold" : 1, + "minFilterValueLength" : 5, + "sortBy" : "ALPHABETICALLY", + "scope" : "SCOPED_SITES", + "scopedSites" : [ + "site3", + "site2", + "site1" + ], + "index" : 6, + "isEnabled" : true + } + + Notes: + - user must be an Admin, member of Alfresco_Search_Administrators group or a Network Admin for given network/tenant + ]]> + + /api/solr/facet-config + argument + user + required + \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/solr/facet/solr-facet-config-admin.put.json.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/solr/facet/solr-facet-config-admin.put.json.ftl new file mode 100644 index 0000000000..e69de29bb2 diff --git a/config/alfresco/web-scripts-application-context.xml b/config/alfresco/web-scripts-application-context.xml index 7fb72ea487..6ac1d393ea 100644 --- a/config/alfresco/web-scripts-application-context.xml +++ b/config/alfresco/web-scripts-application-context.xml @@ -1819,6 +1819,31 @@ + + + + + + + + + + + + + diff --git a/source/java/org/alfresco/repo/web/scripts/solr/facet/AbstractSolrFacetConfigAdminWebScript.java b/source/java/org/alfresco/repo/web/scripts/solr/facet/AbstractSolrFacetConfigAdminWebScript.java new file mode 100644 index 0000000000..cff4a588eb --- /dev/null +++ b/source/java/org/alfresco/repo/web/scripts/solr/facet/AbstractSolrFacetConfigAdminWebScript.java @@ -0,0 +1,152 @@ +/* + * Copyright (C) 2005-2014 Alfresco Software Limited. + * + * This file is part of Alfresco + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + */ + +package org.alfresco.repo.web.scripts.solr.facet; + +import java.io.IOException; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import javax.servlet.http.HttpServletResponse; + +import org.alfresco.repo.search.impl.solr.facet.SolrFacetProperties; +import org.alfresco.repo.search.impl.solr.facet.SolrFacetService; +import org.alfresco.repo.security.authentication.AuthenticationUtil; +import org.alfresco.service.namespace.QName; +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; +import org.json.JSONTokener; +import org.springframework.extensions.webscripts.Cache; +import org.springframework.extensions.webscripts.DeclarativeWebScript; +import org.springframework.extensions.webscripts.Status; +import org.springframework.extensions.webscripts.WebScriptException; +import org.springframework.extensions.webscripts.WebScriptRequest; + +/** + * This class is an abstract base class for the various web script controllers + * in the SolrFacetService. + * + * @author Jamal Kaabi-Mofrad + */ +public abstract class AbstractSolrFacetConfigAdminWebScript extends DeclarativeWebScript +{ + protected static final String PARAM_FILTER_ID = "filterID"; + protected static final String PARAM_FACET_QNAME = "facetQName"; + protected static final String PARAM_DISPLAY_NAME = "displayName"; + protected static final String PARAM_MAX_FILTERS = "maxFilters"; + protected static final String PARAM_HIT_THRESHOLD = "hitThreshold"; + protected static final String PARAM_MIN_FILTER_VALUE_LENGTH = "minFilterValueLength"; + protected static final String PARAM_SORT_BY = "sortBy"; + protected static final String PARAM_SCOPE = "scope"; + protected static final String PARAM_SCOPED_SITES = "scopedSites"; + protected static final String PARAM_INDEX = "index"; + protected static final String PARAM_IS_ENABLED = "isEnabled"; + + protected SolrFacetService facetService; + + /** + * @param facetService the facetService to set + */ + public void setFacetService(SolrFacetService facetService) + { + this.facetService = facetService; + } + + @Override + protected Map executeImpl(final WebScriptRequest req, final Status status, final Cache cache) + { + validateCurrentUser(); + + return unprotectedExecuteImpl(req, status, cache); + } + + protected void validateCurrentUser() + { + String currentUser = AuthenticationUtil.getFullyAuthenticatedUser(); + // check the current user access rights + if (!facetService.isSearchAdmin(currentUser)) + { + throw new WebScriptException(HttpServletResponse.SC_FORBIDDEN, "Access denied."); + } + } + + protected SolrFacetProperties parseRequestForFacetProperties(WebScriptRequest req) + { + JSONObject json = null; + try + { + json = new JSONObject(new JSONTokener(req.getContent().getContent())); + + final String filterID = json.getString(PARAM_FILTER_ID); + final String facetQNameStr = json.getString(PARAM_FACET_QNAME); + if (filterID == null || facetQNameStr == null) + { + String requiredProp = (filterID == null) ? "filterID" : "facetQName"; + throw new WebScriptException(Status.STATUS_BAD_REQUEST, requiredProp + " not provided."); + } + + final QName facetQName = QName.createQName(facetQNameStr); + final String displayName = json.getString(PARAM_DISPLAY_NAME); + final int maxFilters = json.getInt(PARAM_MAX_FILTERS); + final int hitThreshold = json.getInt(PARAM_HIT_THRESHOLD); + final int minFilterValueLength = json.getInt(PARAM_MIN_FILTER_VALUE_LENGTH); + final String sortBy = json.getString(PARAM_SORT_BY); + final String scope = json.getString(PARAM_SCOPE); + final int index = json.getInt(PARAM_INDEX); + final boolean isEnabled = json.getBoolean(PARAM_IS_ENABLED); + JSONArray scopedSitesJsonArray = json.getJSONArray(PARAM_SCOPED_SITES); + Set scopedSites = null; + if (scopedSitesJsonArray != null) + { + scopedSites = new HashSet(scopedSitesJsonArray.length()); + for (int i = 0, length = scopedSitesJsonArray.length(); i < length; i++) + { + String site = scopedSitesJsonArray.getString(i); + scopedSites.add(site); + } + } + + SolrFacetProperties fp = new SolrFacetProperties.Builder() + .filterID(filterID) + .facetQName(facetQName) + .displayName(displayName) + .maxFilters(maxFilters) + .hitThreshold(hitThreshold) + .minFilterValueLength(minFilterValueLength) + .sortBy(sortBy) + .scope(scope) + .index(index) + .isEnabled(isEnabled) + .scopedSites(scopedSites).build(); + return fp; + } + catch (IOException e) + { + throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Could not read content from req.", e); + } + catch (JSONException e) + { + throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Could not parse JSON from req.", e); + } + } + + abstract protected Map unprotectedExecuteImpl(WebScriptRequest req, Status status, Cache cache); +} diff --git a/source/java/org/alfresco/repo/web/scripts/solr/facet/SolrFacetConfigAdminDelete.java b/source/java/org/alfresco/repo/web/scripts/solr/facet/SolrFacetConfigAdminDelete.java new file mode 100644 index 0000000000..2f10e31cab --- /dev/null +++ b/source/java/org/alfresco/repo/web/scripts/solr/facet/SolrFacetConfigAdminDelete.java @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2005-2014 Alfresco Software Limited. + * + * This file is part of Alfresco + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + */ + +package org.alfresco.repo.web.scripts.solr.facet; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.springframework.extensions.webscripts.Cache; +import org.springframework.extensions.webscripts.Status; +import org.springframework.extensions.webscripts.WebScriptException; +import org.springframework.extensions.webscripts.WebScriptRequest; + +/** + * This class is the controller for the "solr-facet-config-admin.delete" web script. + * + * @author Jamal Kaabi-Mofrad + */ +public class SolrFacetConfigAdminDelete extends AbstractSolrFacetConfigAdminWebScript +{ + private static final Log logger = LogFactory.getLog(SolrFacetConfigAdminDelete.class); + + @Override + protected Map unprotectedExecuteImpl(WebScriptRequest req, Status status, Cache cache) + { + // get the filterID parameter. + Map templateVars = req.getServiceMatch().getTemplateVars(); + String filterID = templateVars.get("filterID"); + + if (filterID == null) + { + throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Filter id not provided"); + } + facetService.deleteFacet(filterID); + + Map model = new HashMap(1); + model.put("success", true); + + if (logger.isDebugEnabled()) + { + logger.debug("Facet [" + filterID + "] has been deleted successfully"); + } + + return model; + } +} diff --git a/source/java/org/alfresco/repo/web/scripts/solr/facet/SolrFacetConfigAdminGet.java b/source/java/org/alfresco/repo/web/scripts/solr/facet/SolrFacetConfigAdminGet.java new file mode 100644 index 0000000000..64b6de1238 --- /dev/null +++ b/source/java/org/alfresco/repo/web/scripts/solr/facet/SolrFacetConfigAdminGet.java @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2005-2014 Alfresco Software Limited. + * + * This file is part of Alfresco + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + */ + +package org.alfresco.repo.web.scripts.solr.facet; + +import java.util.HashMap; +import java.util.Map; + +import org.alfresco.repo.search.impl.solr.facet.SolrFacetProperties; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.springframework.extensions.webscripts.Cache; +import org.springframework.extensions.webscripts.Status; +import org.springframework.extensions.webscripts.WebScriptRequest; + +/** + * This class is the controller for the "solr-facet-config-admin.get" web script. + * + * @author Jamal Kaabi-Mofrad + */ +public class SolrFacetConfigAdminGet extends AbstractSolrFacetConfigAdminWebScript +{ + private static final Log logger = LogFactory.getLog(SolrFacetConfigAdminGet.class); + + @Override + protected Map unprotectedExecuteImpl(WebScriptRequest req, Status status, Cache cache) + { + Map filters = facetService.getFacets(); + + Map model = new HashMap(1); + + model.put("filters", filters); + + if (logger.isDebugEnabled()) + { + logger.debug("Retrieved all available facets: " + filters); + } + + return model; + } + +} diff --git a/source/java/org/alfresco/repo/web/scripts/solr/facet/SolrFacetConfigAdminPost.java b/source/java/org/alfresco/repo/web/scripts/solr/facet/SolrFacetConfigAdminPost.java new file mode 100644 index 0000000000..9a12cbefe7 --- /dev/null +++ b/source/java/org/alfresco/repo/web/scripts/solr/facet/SolrFacetConfigAdminPost.java @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2005-2014 Alfresco Software Limited. + * + * This file is part of Alfresco + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + */ + +package org.alfresco.repo.web.scripts.solr.facet; + +import java.util.HashMap; +import java.util.Map; + +import org.alfresco.repo.search.impl.solr.facet.SolrFacetProperties; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.springframework.extensions.webscripts.Cache; +import org.springframework.extensions.webscripts.Status; +import org.springframework.extensions.webscripts.WebScriptException; +import org.springframework.extensions.webscripts.WebScriptRequest; + +/** + * This class is the controller for the "solr-facet-config-admin.post" web scripts. + * + * @author Jamal Kaabi-Mofrad + */ +public class SolrFacetConfigAdminPost extends AbstractSolrFacetConfigAdminWebScript +{ + private static final Log logger = LogFactory.getLog(SolrFacetConfigAdminPost.class); + + @Override + protected Map unprotectedExecuteImpl(WebScriptRequest req, Status status, Cache cache) + { + try + { + SolrFacetProperties fp = parseRequestForFacetProperties(req); + facetService.createFacetNode(fp); + + if (logger.isDebugEnabled()) + { + logger.debug("Created facet node: " + fp); + } + } + catch (Throwable t) + { + throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Could not save the facet configuration.", t); + } + + Map model = new HashMap(1); + return model; + } +} diff --git a/source/java/org/alfresco/repo/web/scripts/solr/facet/SolrFacetConfigAdminPut.java b/source/java/org/alfresco/repo/web/scripts/solr/facet/SolrFacetConfigAdminPut.java new file mode 100644 index 0000000000..9422293ed6 --- /dev/null +++ b/source/java/org/alfresco/repo/web/scripts/solr/facet/SolrFacetConfigAdminPut.java @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2005-2014 Alfresco Software Limited. + * + * This file is part of Alfresco + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + */ + +package org.alfresco.repo.web.scripts.solr.facet; + +import java.util.HashMap; +import java.util.Map; + +import org.alfresco.repo.search.impl.solr.facet.SolrFacetProperties; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.springframework.extensions.webscripts.Cache; +import org.springframework.extensions.webscripts.Status; +import org.springframework.extensions.webscripts.WebScriptException; +import org.springframework.extensions.webscripts.WebScriptRequest; + +/** + * This class is the controller for the "solr-facet-config-admin.put" web scripts. + * + * @author Jamal Kaabi-Mofrad + */ +public class SolrFacetConfigAdminPut extends AbstractSolrFacetConfigAdminWebScript +{ + private static final Log logger = LogFactory.getLog(SolrFacetConfigAdminPost.class); + + @Override + protected Map unprotectedExecuteImpl(WebScriptRequest req, Status status, Cache cache) + { + try + { + 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 model = new HashMap(1); + return model; + } + +}