use of org.broadleafcommerce.common.exception.ServiceException in project BroadleafCommerce by BroadleafCommerce.
the class SolrIndexServiceImpl method deleteAllDocuments.
@Override
public void deleteAllDocuments(SolrClient server) throws ServiceException {
try {
String deleteQuery = "*:*";
LOG.debug("Deleting by query: " + deleteQuery);
server.deleteByQuery(deleteQuery);
server.commit();
} catch (Exception e) {
throw new ServiceException("Could not delete documents", e);
}
}
use of org.broadleafcommerce.common.exception.ServiceException in project BroadleafCommerce by BroadleafCommerce.
the class MultiTenantCopier method copyEntitiesOfType.
/**
* Subclasses will generally call this method in their {@link #copyEntities(MultiTenantCopyContext)} implementation.
*
* @param clazz
* @param fromSite
* @param fromCatalog
* @param context
* @param <T>
* @throws ServiceException
* @throws CloneNotSupportedException
*/
protected <T extends MultiTenantCloneable> void copyEntitiesOfType(final Class<T> clazz, final Site fromSite, final Catalog fromCatalog, final MultiTenantCopyContext context) throws ServiceException, CloneNotSupportedException {
genericEntityService.flush();
genericEntityService.clear();
transUtil.runStreamingTransactionalOperation(new StreamCapableTransactionalOperationAdapter() {
@Override
public Object[] retrievePage(int startPos, int pageSize) {
try {
Object[] temp = new Object[1];
List<T> results = readAll(clazz, pageSize, startPos, fromSite, fromCatalog);
temp[0] = results;
return temp;
} catch (ServiceException e) {
throw ExceptionHelper.refineException(e);
}
}
@Override
public void pagedExecute(Object[] param) throws Throwable {
try {
List<T> results = (List<T>) param[0];
for (T result : results) {
persistCopyObjectTree(new CopyOperation<T, CloneNotSupportedException>() {
@Override
public T execute(T original) throws CloneNotSupportedException {
return (T) original.createOrRetrieveCopyInstance(context).getClone();
}
}, clazz, result, context);
}
} finally {
genericEntityService.clear();
}
}
@Override
public Long retrieveTotalCount() {
try {
return readCount(clazz, fromSite, fromCatalog);
} catch (ServiceException e) {
throw ExceptionHelper.refineException(e);
}
}
@Override
public boolean shouldRetryOnTransactionLockAcquisitionFailure() {
return true;
}
}, RuntimeException.class);
}
use of org.broadleafcommerce.common.exception.ServiceException in project BroadleafCommerce by BroadleafCommerce.
the class PageTemplateCustomPersistenceHandler method addOrUpdate.
protected Entity addOrUpdate(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException {
String ceilingEntityFullyQualifiedClassname = persistencePackage.getCeilingEntityFullyQualifiedClassname();
try {
String pageId = persistencePackage.getCustomCriteria()[1];
if (StringUtils.isBlank(pageId)) {
return persistencePackage.getEntity();
}
Page page = pageService.findPageById(Long.valueOf(pageId));
Property[] properties = dynamicFieldUtil.buildDynamicPropertyList(getFieldGroups(page, null), PageTemplate.class);
Map<String, FieldMetadata> md = new HashMap<String, FieldMetadata>();
for (Property property : properties) {
md.put(property.getName(), property.getMetadata());
}
boolean validated = helper.validate(persistencePackage.getEntity(), null, md);
if (!validated) {
throw new ValidationException(persistencePackage.getEntity(), "Page dynamic fields failed validation");
}
List<String> templateFieldNames = new ArrayList<String>(20);
for (FieldGroup group : getFieldGroups(page, null)) {
for (FieldDefinition def : group.getFieldDefinitions()) {
templateFieldNames.add(def.getName());
}
}
Map<String, String> dirtyFieldsOrigVals = new HashMap<String, String>();
List<String> dirtyFields = new ArrayList<String>();
Map<String, PageField> pageFieldMap = page.getPageFields();
for (Property property : persistencePackage.getEntity().getProperties()) {
if (property.getEnabled() && templateFieldNames.contains(property.getName())) {
PageField pageField = pageFieldMap.get(property.getName());
if (pageField != null) {
boolean isDirty = (pageField.getValue() == null && property.getValue() != null) || (pageField.getValue() != null && property.getValue() == null);
if (isDirty || (pageField.getValue() != null && property.getValue() != null && !pageField.getValue().trim().equals(property.getValue().trim()))) {
dirtyFields.add(property.getName());
dirtyFieldsOrigVals.put(property.getName(), pageField.getValue());
pageField.setValue(property.getValue());
pageField = dynamicEntityDao.merge(pageField);
}
} else {
pageField = new PageFieldImpl();
pageField.setFieldKey(property.getName());
pageField.setValue(property.getValue());
pageField.setPage(page);
dynamicEntityDao.persist(pageField);
dirtyFields.add(property.getName());
}
}
}
List<String> removeItems = new ArrayList<String>();
for (String key : pageFieldMap.keySet()) {
if (persistencePackage.getEntity().findProperty(key) == null) {
removeItems.add(key);
}
}
if (removeItems.size() > 0) {
for (String removeKey : removeItems) {
pageFieldMap.remove(removeKey);
}
}
Collections.sort(dirtyFields);
Entity entity = fetchEntityBasedOnId(pageId, dirtyFields);
for (Map.Entry<String, String> entry : dirtyFieldsOrigVals.entrySet()) {
entity.getPMap().get(entry.getKey()).setOriginalValue(entry.getValue());
entity.getPMap().get(entry.getKey()).setOriginalDisplayValue(entry.getValue());
}
return entity;
} catch (ValidationException e) {
throw e;
} catch (Exception e) {
throw new ServiceException("Unable to perform update for entity: " + ceilingEntityFullyQualifiedClassname, e);
}
}
use of org.broadleafcommerce.common.exception.ServiceException in project BroadleafCommerce by BroadleafCommerce.
the class PageTemplateCustomPersistenceHandler method fetch.
@Override
public DynamicResultSet fetch(PersistencePackage persistencePackage, CriteriaTransferObject cto, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException {
String ceilingEntityFullyQualifiedClassname = persistencePackage.getCeilingEntityFullyQualifiedClassname();
try {
String pageId = persistencePackage.getCustomCriteria()[1];
Entity entity = fetchEntityBasedOnId(pageId, null);
DynamicResultSet results = new DynamicResultSet(new Entity[] { entity }, 1);
populateFKLookupValues(dynamicEntityDao, entity);
return results;
} catch (Exception e) {
throw new ServiceException("Unable to perform fetch for entity: " + ceilingEntityFullyQualifiedClassname, e);
}
}
use of org.broadleafcommerce.common.exception.ServiceException in project BroadleafCommerce by BroadleafCommerce.
the class StructuredContentTypeCustomPersistenceHandler method inspect.
@Override
public DynamicResultSet inspect(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, InspectHelper helper) throws ServiceException {
String ceilingEntityFullyQualifiedClassname = persistencePackage.getCeilingEntityFullyQualifiedClassname();
try {
String structuredContentTypeId = persistencePackage.getCustomCriteria()[3];
StructuredContentType structuredContentType = structuredContentService.findStructuredContentTypeById(Long.valueOf(structuredContentTypeId));
ClassMetadata metadata = new ClassMetadata();
metadata.setCeilingType(StructuredContentType.class.getName());
ClassTree entities = new ClassTree(StructuredContentTypeImpl.class.getName());
metadata.setPolymorphicEntities(entities);
Property[] properties = dynamicFieldUtil.buildDynamicPropertyList(structuredContentType.getStructuredContentFieldTemplate().getFieldGroups(), StructuredContentTypeImpl.class);
metadata.setProperties(properties);
DynamicResultSet results = new DynamicResultSet(metadata);
return results;
} catch (Exception e) {
throw new ServiceException("Unable to perform inspect for entity: " + ceilingEntityFullyQualifiedClassname, e);
}
}
Aggregations