use of org.broadleafcommerce.common.exception.ServiceException in project BroadleafCommerce by BroadleafCommerce.
the class AdminUserCustomPersistenceHandler method add.
@Override
public Entity add(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException {
adminRemoteSecurityService.securityCheck(persistencePackage, EntityOperationType.ADD);
Entity entity = persistencePackage.getEntity();
try {
PersistencePerspective persistencePerspective = persistencePackage.getPersistencePerspective();
AdminUser adminInstance = (AdminUser) Class.forName(entity.getType()[0]).newInstance();
Map<String, FieldMetadata> adminProperties = helper.getSimpleMergedProperties(AdminUser.class.getName(), persistencePerspective);
adminInstance = (AdminUser) helper.createPopulatedInstance(adminInstance, entity, adminProperties, false);
Entity errorEntity = validateLegalUsernameAndEmail(entity, adminInstance, true);
if (errorEntity != null) {
return errorEntity;
}
adminInstance.setUnencodedPassword(adminInstance.getPassword());
adminInstance.setPassword(null);
adminInstance = adminSecurityService.saveAdminUser(adminInstance);
Entity adminEntity = helper.getRecord(adminProperties, adminInstance, null, null);
return adminEntity;
} catch (Exception e) {
throw new ServiceException("Unable to add entity for " + entity.getType()[0], e);
}
}
use of org.broadleafcommerce.common.exception.ServiceException in project BroadleafCommerce by BroadleafCommerce.
the class DynamicEntityRemoteService method inspect.
@Override
public PersistenceResponse inspect(final PersistencePackage persistencePackage) throws ServiceException {
final PersistenceResponse[] response = new PersistenceResponse[1];
try {
PlatformTransactionManager transactionManager = identifyTransactionManager(persistencePackage);
transUtil.runOptionalTransactionalOperation(new StreamCapableTransactionalOperationAdapter() {
@Override
public void execute() throws Throwable {
response[0] = nonTransactionalInspect(persistencePackage);
}
}, RuntimeException.class, true, TransactionDefinition.PROPAGATION_REQUIRED, TransactionDefinition.ISOLATION_DEFAULT, true, transactionManager);
} catch (RuntimeException e) {
if (e.getCause() instanceof ServiceException) {
throw (ServiceException) e.getCause();
}
throw e;
}
return response[0];
}
use of org.broadleafcommerce.common.exception.ServiceException in project BroadleafCommerce by BroadleafCommerce.
the class DynamicEntityRemoteService method recreateSpecificServiceException.
protected ServiceException recreateSpecificServiceException(ServiceException e, String message, Throwable cause) {
try {
ServiceException newException;
if (cause == null) {
Constructor constructor = e.getClass().getConstructor(String.class);
newException = (ServiceException) constructor.newInstance(message);
} else {
Constructor constructor = e.getClass().getConstructor(String.class, Throwable.class);
newException = (ServiceException) constructor.newInstance(message, cause);
}
return newException;
} catch (Exception e1) {
throw new RuntimeException(e1);
}
}
use of org.broadleafcommerce.common.exception.ServiceException in project BroadleafCommerce by BroadleafCommerce.
the class DynamicEntityRemoteService method remove.
@Override
public PersistenceResponse remove(final PersistencePackage persistencePackage) throws ServiceException {
final PersistenceResponse[] response = new PersistenceResponse[1];
try {
PlatformTransactionManager transactionManager = identifyTransactionManager(persistencePackage);
transUtil.runTransactionalOperation(new StreamCapableTransactionalOperationAdapter() {
@Override
public void execute() throws Throwable {
response[0] = nonTransactionalRemove(persistencePackage);
}
@Override
public boolean shouldRetryOnTransactionLockAcquisitionFailure() {
return super.shouldRetryOnTransactionLockAcquisitionFailure();
}
}, RuntimeException.class, transactionManager);
} catch (RuntimeException e) {
if (e.getCause() instanceof ServiceException) {
throw (ServiceException) e.getCause();
}
throw e;
}
return response[0];
}
use of org.broadleafcommerce.common.exception.ServiceException in project BroadleafCommerce by BroadleafCommerce.
the class SolrIndexServiceImpl method buildIncrementalIndex.
@Override
public Collection<SolrInputDocument> buildIncrementalIndex(List<? extends Indexable> indexables, SolrClient solrServer) throws ServiceException {
TransactionStatus status = TransactionUtils.createTransaction("executeIncrementalIndex", TransactionDefinition.PROPAGATION_REQUIRED, transactionManager, true);
if (SolrIndexCachedOperation.getCache() == null) {
LOG.warn("Consider using SolrIndexService.performCachedOperation() in combination with " + "SolrIndexService.buildIncrementalIndex() for better caching performance during solr indexing");
}
if (LOG.isDebugEnabled()) {
LOG.debug(String.format("Building incremental product index - pageSize: [%s]...", indexables.size()));
}
StopWatch s = new StopWatch();
try {
sandBoxHelper.ignoreCloneCache(true);
extensionManager.getProxy().startBatchEvent(indexables);
Collection<SolrInputDocument> documents = new ArrayList<>();
List<Locale> locales = getAllLocales();
List<Long> productIds = BLCCollectionUtils.collectList(indexables, new TypedTransformer<Long>() {
@Override
public Long transform(Object input) {
return shs.getCurrentProductId((Indexable) input);
}
});
solrIndexDao.populateProductCatalogStructure(productIds, SolrIndexCachedOperation.getCache());
List<IndexField> fields = null;
FieldEntity currentFieldType = null;
for (Indexable indexable : indexables) {
if (fields == null || ObjectUtils.notEqual(currentFieldType, indexable.getFieldEntityType())) {
fields = indexFieldDao.readFieldsByEntityType(indexable.getFieldEntityType());
}
SolrInputDocument doc = buildDocument(indexable, fields, locales);
// to the index.
if (doc != null) {
documents.add(doc);
}
}
extensionManager.getProxy().modifyBuiltDocuments(documents, indexables, fields, locales);
logDocuments(documents);
if (!CollectionUtils.isEmpty(documents) && solrServer != null) {
solrServer.add(documents);
commit(solrServer);
}
TransactionUtils.finalizeTransaction(status, transactionManager, false);
if (LOG.isDebugEnabled()) {
LOG.debug(String.format("Built incremental product index - pageSize: [%s] in [%s]", indexables.size(), s.toLapString()));
}
return documents;
} catch (SolrServerException e) {
TransactionUtils.finalizeTransaction(status, transactionManager, true);
throw new ServiceException("Could not rebuild index", e);
} catch (IOException e) {
TransactionUtils.finalizeTransaction(status, transactionManager, true);
throw new ServiceException("Could not rebuild index", e);
} catch (RuntimeException e) {
TransactionUtils.finalizeTransaction(status, transactionManager, true);
throw e;
} finally {
extensionManager.getProxy().endBatchEvent(indexables);
sandBoxHelper.ignoreCloneCache(false);
}
}
Aggregations