Search in sources :

Example 76 with ServiceException

use of org.broadleafcommerce.common.exception.ServiceException in project BroadleafCommerce by BroadleafCommerce.

the class SearchFacetDTOServiceImpl method buildSearchCriteria.

@Override
public SearchCriteria buildSearchCriteria(HttpServletRequest request) {
    SearchCriteria searchCriteria = createSearchCriteria();
    searchCriteria.setPageSize(getDefaultPageSize());
    Map<String, String[]> facets = new HashMap<>();
    for (Entry<String, String[]> entry : request.getParameterMap().entrySet()) {
        String key = entry.getKey();
        if (Objects.equals(key, SearchCriteria.SORT_STRING)) {
            searchCriteria.setSortQuery(StringUtils.join(entry.getValue(), ","));
        } else if (Objects.equals(key, SearchCriteria.PAGE_NUMBER)) {
            searchCriteria.setPage(Integer.parseInt(entry.getValue()[0]));
        } else if (Objects.equals(key, SearchCriteria.PAGE_SIZE_STRING)) {
            int requestedPageSize = Integer.parseInt(entry.getValue()[0]);
            int maxPageSize = getMaxPageSize();
            searchCriteria.setPageSize(Math.min(requestedPageSize, maxPageSize));
        } else if (Objects.equals(key, SearchCriteria.QUERY_STRING)) {
            String query = request.getParameter(SearchCriteria.QUERY_STRING);
            try {
                if (StringUtils.isNotEmpty(query)) {
                    query = exploitProtectionService.cleanString(StringUtils.trim(query));
                }
            } catch (ServiceException e) {
                query = null;
            }
            searchCriteria.setQuery(query);
        } else if (Objects.equals(key, SearchCriteria.REQUEST_HANDLER)) {
            String requestHandler = entry.getValue()[0];
            if (!requestHandler.startsWith("/")) {
                requestHandler = "/" + requestHandler;
            }
            searchCriteria.setRequestHandler(requestHandler);
        } else {
            facets.put(key, entry.getValue());
        }
    }
    searchCriteria.setFilterCriteria(facets);
    searchCriteria.setCategory((Category) request.getAttribute(CategoryHandlerMapping.CURRENT_CATEGORY_ATTRIBUTE_NAME));
    return searchCriteria;
}
Also used : ServiceException(org.broadleafcommerce.common.exception.ServiceException) HashMap(java.util.HashMap) SearchCriteria(org.broadleafcommerce.core.search.domain.SearchCriteria)

Example 77 with ServiceException

use of org.broadleafcommerce.common.exception.ServiceException in project BroadleafCommerce by BroadleafCommerce.

the class SolrHelperServiceImpl method swapActiveCores.

/**
 * This should only ever be called when using the Solr reindex service to do a full reindex.
 * @throws SecurityException
 * @throws NoSuchFieldException
 * @throws IllegalAccessException
 * @throws IllegalArgumentException
 */
@Override
public synchronized void swapActiveCores(SolrConfiguration solrConfiguration) throws ServiceException {
    if (!isSolrConfigured) {
        return;
    }
    if (CloudSolrClient.class.isAssignableFrom(solrConfiguration.getServer().getClass()) && CloudSolrClient.class.isAssignableFrom(solrConfiguration.getReindexServer().getClass())) {
        CloudSolrClient primaryCloudClient = (CloudSolrClient) solrConfiguration.getServer();
        CloudSolrClient reindexCloudClient = (CloudSolrClient) solrConfiguration.getReindexServer();
        try {
            primaryCloudClient.connect();
            Aliases aliases = primaryCloudClient.getZkStateReader().getAliases();
            Map<String, String> aliasCollectionMap = aliases.getCollectionAliasMap();
            if (aliasCollectionMap == null || !aliasCollectionMap.containsKey(primaryCloudClient.getDefaultCollection()) || !aliasCollectionMap.containsKey(reindexCloudClient.getDefaultCollection())) {
                throw new IllegalStateException("Could not determine the PRIMARY or REINDEX " + "collection or collections from the Solr aliases.");
            }
            String primaryCollectionName = aliasCollectionMap.get(primaryCloudClient.getDefaultCollection());
            // Do this just in case primary is aliased to more than one collection
            primaryCollectionName = primaryCollectionName.split(",")[0];
            String reindexCollectionName = aliasCollectionMap.get(reindexCloudClient.getDefaultCollection());
            // Do this just in case primary is aliased to more than one collection
            reindexCollectionName = reindexCollectionName.split(",")[0];
            // Essentially "swap cores" here by reassigning the aliases
            new CollectionAdminRequest.CreateAlias().setAliasName(primaryCloudClient.getDefaultCollection()).setAliasedCollections(reindexCollectionName).process(primaryCloudClient);
            new CollectionAdminRequest.CreateAlias().setAliasName(reindexCloudClient.getDefaultCollection()).setAliasedCollections(primaryCollectionName).process(reindexCloudClient);
        } catch (Exception e) {
            LOG.error("An exception occured swapping cores.", e);
            throw new ServiceException("Unable to swap SolrCloud collections after a full reindex.", e);
        }
    } else {
        if (solrConfiguration.getReindexServer() == null || solrConfiguration.getServer() == solrConfiguration.getReindexServer()) {
            LOG.debug("In single core mode. There are no cores to swap.");
        } else {
            LOG.debug("Swapping active cores");
            String primaryCoreName = solrConfiguration.getPrimaryName();
            String reindexCoreName = solrConfiguration.getReindexName();
            if (!StringUtils.isEmpty(primaryCoreName) && !StringUtils.isEmpty(reindexCoreName)) {
                CoreAdminRequest car = new CoreAdminRequest();
                car.setCoreName(primaryCoreName);
                car.setOtherCoreName(reindexCoreName);
                car.setAction(CoreAdminAction.SWAP);
                try {
                    solrConfiguration.getAdminServer().request(car);
                } catch (Exception e) {
                    LOG.error(e);
                    throw new ServiceException("Unable to swap cores", e);
                }
            } else {
                LOG.error("Could not determine core names for the Solr Clients provided");
                throw new ServiceException("Unable to swap cores");
            }
        }
    }
}
Also used : IllegalStateException(javax.jms.IllegalStateException) ServiceException(org.broadleafcommerce.common.exception.ServiceException) CollectionAdminRequest(org.apache.solr.client.solrj.request.CollectionAdminRequest) CoreAdminRequest(org.apache.solr.client.solrj.request.CoreAdminRequest) Aliases(org.apache.solr.common.cloud.Aliases) SolrServerException(org.apache.solr.client.solrj.SolrServerException) ServiceException(org.broadleafcommerce.common.exception.ServiceException) IllegalStateException(javax.jms.IllegalStateException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException) CloudSolrClient(org.apache.solr.client.solrj.impl.CloudSolrClient)

Aggregations

ServiceException (org.broadleafcommerce.common.exception.ServiceException)77 Entity (org.broadleafcommerce.openadmin.dto.Entity)46 FieldMetadata (org.broadleafcommerce.openadmin.dto.FieldMetadata)44 PersistencePerspective (org.broadleafcommerce.openadmin.dto.PersistencePerspective)39 BasicFieldMetadata (org.broadleafcommerce.openadmin.dto.BasicFieldMetadata)25 InvocationTargetException (java.lang.reflect.InvocationTargetException)19 SecurityServiceException (org.broadleafcommerce.common.exception.SecurityServiceException)17 ValidationException (org.broadleafcommerce.openadmin.server.service.ValidationException)16 Serializable (java.io.Serializable)15 DynamicResultSet (org.broadleafcommerce.openadmin.dto.DynamicResultSet)14 CriteriaTransferObject (org.broadleafcommerce.openadmin.dto.CriteriaTransferObject)13 Property (org.broadleafcommerce.openadmin.dto.Property)12 ArrayList (java.util.ArrayList)11 HashMap (java.util.HashMap)11 Map (java.util.Map)11 AdminMainEntity (org.broadleafcommerce.common.admin.domain.AdminMainEntity)9 ForeignKey (org.broadleafcommerce.openadmin.dto.ForeignKey)9 StreamCapableTransactionalOperationAdapter (org.broadleafcommerce.common.util.StreamCapableTransactionalOperationAdapter)6 Sku (org.broadleafcommerce.core.catalog.domain.Sku)6 ClassMetadata (org.broadleafcommerce.openadmin.dto.ClassMetadata)6