Search in sources :

Example 66 with ServiceException

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);
    }
}
Also used : Entity(org.broadleafcommerce.openadmin.dto.Entity) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) PersistencePerspective(org.broadleafcommerce.openadmin.dto.PersistencePerspective) ServiceException(org.broadleafcommerce.common.exception.ServiceException) AdminUser(org.broadleafcommerce.openadmin.server.security.domain.AdminUser) ServiceException(org.broadleafcommerce.common.exception.ServiceException) ValidationException(org.broadleafcommerce.openadmin.server.service.ValidationException)

Example 67 with ServiceException

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];
}
Also used : ServiceException(org.broadleafcommerce.common.exception.ServiceException) StreamCapableTransactionalOperationAdapter(org.broadleafcommerce.common.util.StreamCapableTransactionalOperationAdapter) PersistenceResponse(org.broadleafcommerce.openadmin.server.service.persistence.PersistenceResponse) PlatformTransactionManager(org.springframework.transaction.PlatformTransactionManager)

Example 68 with ServiceException

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);
    }
}
Also used : ServiceException(org.broadleafcommerce.common.exception.ServiceException) Constructor(java.lang.reflect.Constructor) ServiceException(org.broadleafcommerce.common.exception.ServiceException) CleanStringException(org.broadleafcommerce.common.security.service.CleanStringException)

Example 69 with ServiceException

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];
}
Also used : ServiceException(org.broadleafcommerce.common.exception.ServiceException) StreamCapableTransactionalOperationAdapter(org.broadleafcommerce.common.util.StreamCapableTransactionalOperationAdapter) PersistenceResponse(org.broadleafcommerce.openadmin.server.service.persistence.PersistenceResponse) PlatformTransactionManager(org.springframework.transaction.PlatformTransactionManager)

Example 70 with ServiceException

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);
    }
}
Also used : Locale(org.broadleafcommerce.common.locale.domain.Locale) FieldEntity(org.broadleafcommerce.core.search.domain.FieldEntity) SolrServerException(org.apache.solr.client.solrj.SolrServerException) ArrayList(java.util.ArrayList) TransactionStatus(org.springframework.transaction.TransactionStatus) IOException(java.io.IOException) StopWatch(org.broadleafcommerce.common.util.StopWatch) SolrInputDocument(org.apache.solr.common.SolrInputDocument) ServiceException(org.broadleafcommerce.common.exception.ServiceException) Indexable(org.broadleafcommerce.core.catalog.domain.Indexable) IndexField(org.broadleafcommerce.core.search.domain.IndexField)

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