use of org.broadleafcommerce.common.exception.ServiceException in project BroadleafCommerce by BroadleafCommerce.
the class CustomerCustomPersistenceHandler method remove.
@Override
public void remove(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException {
Entity entity = persistencePackage.getEntity();
try {
Long customerId = Long.parseLong(entity.findProperty("id").getValue());
Customer customer = customerService.readCustomerById(customerId);
if (Status.class.isAssignableFrom(customer.getClass())) {
((Status) customer).setArchived('Y');
// If the customer has a conditional weave on ArchiveStatus, nothing triggers the delete so other
// normally-cascaded deletes don't happen (like CustomerAddress)
List<CustomerAddress> addressList = customer.getCustomerAddresses();
for (CustomerAddress address : addressList) {
address.setArchived('Y');
}
customer = customerService.saveCustomer(customer);
return;
}
// Remove the customer roles for the customer since it's not cascaded
roleDao.removeCustomerRolesByCustomerId(customerId);
helper.getCompatibleModule(OperationType.BASIC).remove(persistencePackage);
} catch (Exception e) {
LOG.error("Unable to execute persistence activity", e);
throw new ServiceException("Unable to remove entity for " + entity.getType()[0], e);
}
}
use of org.broadleafcommerce.common.exception.ServiceException in project BroadleafCommerce by BroadleafCommerce.
the class CustomerCustomPersistenceHandler method update.
@Override
public Entity update(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException {
Entity entity = persistencePackage.getEntity();
try {
PersistencePerspective persistencePerspective = persistencePackage.getPersistencePerspective();
Map<String, FieldMetadata> adminProperties = helper.getSimpleMergedProperties(Customer.class.getName(), persistencePerspective);
Object primaryKey = helper.getPrimaryKey(entity, adminProperties);
Customer adminInstance = (Customer) dynamicEntityDao.retrieve(Class.forName(entity.getType()[0]), primaryKey);
String passwordBefore = adminInstance.getPassword();
adminInstance.setPassword(null);
adminInstance = (Customer) helper.createPopulatedInstance(adminInstance, entity, adminProperties, false);
adminInstance.setPassword(passwordBefore);
if (useEmailForLogin) {
adminInstance.setUsername(adminInstance.getEmailAddress());
}
adminInstance = customerService.saveCustomer(adminInstance);
Entity adminEntity = helper.getRecord(adminProperties, adminInstance, null, null);
return adminEntity;
} catch (Exception e) {
throw new ServiceException("Unable to update entity for " + entity.getType()[0], e);
}
}
use of org.broadleafcommerce.common.exception.ServiceException in project BroadleafCommerce by BroadleafCommerce.
the class IndexFieldCustomPersistenceHandler method update.
@Override
public Entity update(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException {
Entity entity = persistencePackage.getEntity();
try {
PersistencePerspective persistencePerspective = persistencePackage.getPersistencePerspective();
Map<String, FieldMetadata> adminProperties = helper.getSimpleMergedProperties(IndexField.class.getName(), persistencePerspective);
Object primaryKey = helper.getPrimaryKey(entity, adminProperties);
IndexField adminInstance = (IndexField) dynamicEntityDao.retrieve(Class.forName(entity.getType()[0]), primaryKey);
return getEntity(persistencePackage, dynamicEntityDao, helper, entity, adminProperties, adminInstance);
} catch (Exception e) {
throw new ServiceException("Unable to perform update for entity: " + IndexField.class.getName(), e);
}
}
use of org.broadleafcommerce.common.exception.ServiceException in project BroadleafCommerce by BroadleafCommerce.
the class SolrSearchServiceImpl method findSearchResults.
/**
* Given a qualified solr query string (such as "category:2002"), actually performs a solr search. It will
* take into considering the search criteria to build out facets / pagination / sorting.
*
* @param searchCriteria
* @param facets
* @return the ProductSearchResult of the search
* @throws ServiceException
*/
protected SearchResult findSearchResults(String qualifiedSolrQuery, List<SearchFacetDTO> facets, SearchCriteria searchCriteria, String defaultSort, String... filterQueries) throws ServiceException {
Map<String, SearchFacetDTO> namedFacetMap = getNamedFacetMap(facets, searchCriteria);
// Left here for backwards compatibility for this method signature
if (searchCriteria.getQuery() == null && qualifiedSolrQuery != null) {
searchCriteria.setQuery(qualifiedSolrQuery);
}
// Build the basic query
// Solr queries with a 'start' parameter cannot be a negative number
int start = (searchCriteria.getPage() <= 0) ? 0 : (searchCriteria.getPage() - 1);
SolrQuery solrQuery = new SolrQuery().setQuery(searchCriteria.getQuery()).setRows(searchCriteria.getPageSize()).setStart((start) * searchCriteria.getPageSize()).setRequestHandler(searchCriteria.getRequestHandler());
// This is for SolrCloud. We assume that we are always searching against a collection aliased as "PRIMARY"
if (solrConfiguration.isSiteCollections()) {
solrQuery.setParam("collection", solrConfiguration.getSiteAliasName(BroadleafRequestContext.getBroadleafRequestContext().getNonPersistentSite()));
} else {
// This should be ignored if not using SolrCloud
solrQuery.setParam("collection", solrConfiguration.getPrimaryName());
}
solrQuery.setFields(shs.getIndexableIdFieldName());
if (filterQueries != null) {
solrQuery.setFilterQueries(filterQueries);
}
// add category filter if applicable
if (searchCriteria.getCategory() != null) {
solrQuery.addFilterQuery(getCategoryFilter(searchCriteria));
}
solrQuery.addFilterQuery(shs.getNamespaceFieldName() + ":(\"" + solrConfiguration.getNamespace() + "\")");
solrQuery.set("defType", "edismax");
solrQuery.set("qf", buildQueryFieldsString(solrQuery, searchCriteria));
// Attach additional restrictions
attachActiveFacetFilters(solrQuery, namedFacetMap, searchCriteria);
attachFacets(solrQuery, namedFacetMap, searchCriteria);
modifySolrQuery(solrQuery, searchCriteria.getQuery(), facets, searchCriteria, defaultSort);
// on child documents.
if (StringUtils.isNotBlank(defaultSort) || StringUtils.isNotBlank(searchCriteria.getSortQuery())) {
solrQuery.remove("bq");
solrQuery.remove("bf");
solrQuery.remove("boost");
}
attachSortClause(solrQuery, searchCriteria, defaultSort);
solrQuery.setShowDebugInfo(shouldShowDebugQuery());
if (LOG.isTraceEnabled()) {
try {
LOG.trace(URLDecoder.decode(solrQuery.toString(), "UTF-8"));
} catch (Exception e) {
LOG.trace("Couldn't UTF-8 URL Decode: " + solrQuery.toString());
}
}
// Query solr
QueryResponse response;
List<SolrDocument> responseDocuments;
int numResults = 0;
try {
response = solrConfiguration.getServer().query(solrQuery, getSolrQueryMethod());
responseDocuments = getResponseDocuments(response);
numResults = (int) response.getResults().getNumFound();
if (LOG.isTraceEnabled()) {
LOG.trace(response.toString());
for (SolrDocument doc : responseDocuments) {
LOG.trace(doc);
}
}
} catch (SolrServerException e) {
throw new ServiceException("Could not perform search", e);
} catch (IOException e) {
throw new ServiceException("Could not perform search", e);
}
// Get the facets
setFacetResults(namedFacetMap, response);
sortFacetResults(namedFacetMap);
filterEmptyFacets(facets);
SearchResult result = new SearchResult();
result.setFacets(facets);
result.setQueryResponse(response);
setPagingAttributes(result, numResults, searchCriteria);
if (useSku) {
List<Sku> skus = getSkus(responseDocuments);
result.setSkus(skus);
} else {
// Get the products
List<Product> products = getProducts(responseDocuments);
result.setProducts(products);
}
return result;
}
use of org.broadleafcommerce.common.exception.ServiceException in project BroadleafCommerce by BroadleafCommerce.
the class SolrIndexServiceImpl method deleteAllNamespaceDocuments.
@Override
public void deleteAllNamespaceDocuments(SolrClient server) throws ServiceException {
try {
String deleteQuery = StringUtil.sanitize(shs.getNamespaceFieldName()) + ":(\"" + StringUtil.sanitize(solrConfiguration.getNamespace()) + "\")";
LOG.debug("Deleting by query: " + deleteQuery);
server.deleteByQuery(deleteQuery);
// Explicitly do a hard commit here since we just deleted the entire index
server.commit();
} catch (Exception e) {
if (ServiceException.class.isAssignableFrom(e.getClass())) {
throw (ServiceException) e;
}
throw new ServiceException("Could not delete documents", e);
}
}
Aggregations