Search in sources :

Example 71 with ServiceException

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);
    }
}
Also used : ServiceException(org.broadleafcommerce.common.exception.ServiceException) SolrServerException(org.apache.solr.client.solrj.SolrServerException) ServiceException(org.broadleafcommerce.common.exception.ServiceException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException)

Example 72 with ServiceException

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);
}
Also used : ServiceException(org.broadleafcommerce.common.exception.ServiceException) StreamCapableTransactionalOperationAdapter(org.broadleafcommerce.common.util.StreamCapableTransactionalOperationAdapter) ArrayList(java.util.ArrayList) List(java.util.List)

Example 73 with ServiceException

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);
    }
}
Also used : Entity(org.broadleafcommerce.openadmin.dto.Entity) AdminMainEntity(org.broadleafcommerce.common.admin.domain.AdminMainEntity) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) ValidationException(org.broadleafcommerce.openadmin.server.service.ValidationException) HashMap(java.util.HashMap) FieldGroup(org.broadleafcommerce.cms.field.domain.FieldGroup) FieldDefinition(org.broadleafcommerce.cms.field.domain.FieldDefinition) ArrayList(java.util.ArrayList) Page(org.broadleafcommerce.cms.page.domain.Page) ServiceException(org.broadleafcommerce.common.exception.ServiceException) ValidationException(org.broadleafcommerce.openadmin.server.service.ValidationException) PageField(org.broadleafcommerce.cms.page.domain.PageField) ServiceException(org.broadleafcommerce.common.exception.ServiceException) Property(org.broadleafcommerce.openadmin.dto.Property) HashMap(java.util.HashMap) Map(java.util.Map) PageFieldImpl(org.broadleafcommerce.cms.page.domain.PageFieldImpl)

Example 74 with ServiceException

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

Example 75 with ServiceException

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);
    }
}
Also used : ClassMetadata(org.broadleafcommerce.openadmin.dto.ClassMetadata) StructuredContentTypeImpl(org.broadleafcommerce.cms.structure.domain.StructuredContentTypeImpl) ServiceException(org.broadleafcommerce.common.exception.ServiceException) ClassTree(org.broadleafcommerce.openadmin.dto.ClassTree) StructuredContentType(org.broadleafcommerce.cms.structure.domain.StructuredContentType) Property(org.broadleafcommerce.openadmin.dto.Property) DynamicResultSet(org.broadleafcommerce.openadmin.dto.DynamicResultSet) ServiceException(org.broadleafcommerce.common.exception.ServiceException) ValidationException(org.broadleafcommerce.openadmin.server.service.ValidationException)

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