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