Search in sources :

Example 21 with BusinessException

use of org.meveo.admin.exception.BusinessException in project meveo by meveo-org.

the class CustomEntityInstanceObserver method onRemoved.

@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public void onRemoved(@Observes(during = TransactionPhase.AFTER_SUCCESS) @Removed CustomEntityInstance cei) throws BusinessException {
    log.debug("CEI onRemoved observer={}", cei);
    BusinessService businessService = businessServiceFinder.find(cei);
    MeveoModule module = businessService.findModuleOf(cei);
    try {
        if (module != null) {
            businessService.removeFilesFromModule(cei, module);
        }
    } catch (BusinessException e) {
        throw new BusinessException("CEI: " + cei.getCode() + " cannot be removed");
    }
}
Also used : BusinessService(org.meveo.service.base.BusinessService) BusinessException(org.meveo.admin.exception.BusinessException) MeveoModule(org.meveo.model.module.MeveoModule) TransactionAttribute(javax.ejb.TransactionAttribute)

Example 22 with BusinessException

use of org.meveo.admin.exception.BusinessException in project meveo by meveo-org.

the class FilterService method persistCustomFieldTemplates.

private void persistCustomFieldTemplates(Filter filter) throws BusinessException {
    try {
        List<CustomFieldTemplate> customFieldTemplates = new ArrayList<>();
        extractCustomFields(filter, filter.getFilterCondition(), customFieldTemplates);
        customFieldTemplateService.createMissingTemplates(filter, customFieldTemplates, true, true);
    } catch (CustomFieldException e) {
        throw new BusinessException(e);
    }
}
Also used : BusinessException(org.meveo.admin.exception.BusinessException) CustomFieldTemplate(org.meveo.model.crm.CustomFieldTemplate) ArrayList(java.util.ArrayList) CustomFieldException(org.meveo.service.crm.impl.CustomFieldException)

Example 23 with BusinessException

use of org.meveo.admin.exception.BusinessException in project meveo by meveo-org.

the class BaseBean method hfHandleFileUpload.

public void hfHandleFileUpload(FileUploadEvent event) throws BusinessException {
    uploadedFile = event.getFile();
    try {
        ImageUploadEventHandler<T> uploadHandler = new ImageUploadEventHandler<T>(currentUser.getProviderCode());
        String filename = uploadHandler.handleImageUpload(entity, uploadedFile);
        if (filename != null) {
            ((IImageUpload) entity).setImagePath(filename);
            messages.info(new BundleKey("messages", "message.upload.succesful"));
        }
    } catch (Exception e) {
        messages.error(new BundleKey("messages", "message.upload.fail"), e.getMessage());
    }
}
Also used : ImageUploadEventHandler(org.meveo.admin.util.ImageUploadEventHandler) IImageUpload(org.meveo.model.catalog.IImageUpload) BundleKey(org.jboss.seam.international.status.builder.BundleKey) ELException(org.meveo.elresolver.ELException) BusinessException(org.meveo.admin.exception.BusinessException) MeveoApiException(org.meveo.api.exception.MeveoApiException) ConstraintViolationException(org.meveo.admin.exception.ConstraintViolationException)

Example 24 with BusinessException

use of org.meveo.admin.exception.BusinessException in project meveo by meveo-org.

the class BaseBean method addToModule.

protected void addToModule(T entity, MeveoModule module) throws BusinessException {
    BusinessEntity businessEntity = (BusinessEntity) entity;
    MeveoModuleItem item = new MeveoModuleItem(businessEntity);
    if (!module.getModuleItems().contains(item)) {
        try {
            meveoModuleService.addModuleItem(item, module);
        } catch (BusinessException e2) {
            throw new BusinessException("Entity cannot be add or remove from the module", e2);
        }
        try {
            if (!org.meveo.commons.utils.StringUtils.isBlank(module.getModuleSource())) {
                module.setModuleSource(JacksonUtil.toString(updateModuleItemDto(module)));
            }
            meveoModuleService.update(module);
            messages.info(businessEntity.getCode() + " added to module " + module.getCode());
        } catch (Exception e) {
            messages.error(businessEntity.getCode() + " not added to module " + module.getCode(), e);
        }
    } else {
        messages.error(new BundleKey("messages", "meveoModule.error.moduleItemExisted"), businessEntity.getCode(), module.getCode());
        return;
    }
}
Also used : BusinessException(org.meveo.admin.exception.BusinessException) MeveoModuleItem(org.meveo.model.module.MeveoModuleItem) BusinessEntity(org.meveo.model.BusinessEntity) BundleKey(org.jboss.seam.international.status.builder.BundleKey) ELException(org.meveo.elresolver.ELException) BusinessException(org.meveo.admin.exception.BusinessException) MeveoApiException(org.meveo.api.exception.MeveoApiException) ConstraintViolationException(org.meveo.admin.exception.ConstraintViolationException)

Example 25 with BusinessException

use of org.meveo.admin.exception.BusinessException in project meveo by meveo-org.

the class BaseCrudBean method exportCSV.

public StreamedContent exportCSV() throws IOException, BusinessException, MeveoApiException {
    if (baseCrudApi == null) {
        throw new BusinessException(getClass().getSimpleName() + " is not using a base crud api");
    }
    PaginationConfiguration configuration = new PaginationConfiguration(getFilters());
    File exportCSV = baseCrudApi.exportCSV(configuration);
    DefaultStreamedContent defaultStreamedContent = new DefaultStreamedContent();
    defaultStreamedContent.setContentEncoding("UTF-8");
    defaultStreamedContent.setContentType("application/csv");
    defaultStreamedContent.setStream(new FileInputStream(exportCSV));
    defaultStreamedContent.setName(exportCSV.getName());
    return defaultStreamedContent;
}
Also used : BusinessException(org.meveo.admin.exception.BusinessException) DefaultStreamedContent(org.primefaces.model.DefaultStreamedContent) File(java.io.File) PaginationConfiguration(org.meveo.admin.util.pagination.PaginationConfiguration) FileInputStream(java.io.FileInputStream)

Aggregations

BusinessException (org.meveo.admin.exception.BusinessException)229 IOException (java.io.IOException)97 File (java.io.File)59 HashMap (java.util.HashMap)50 EntityDoesNotExistsException (org.meveo.api.exception.EntityDoesNotExistsException)50 ArrayList (java.util.ArrayList)48 MeveoApiException (org.meveo.api.exception.MeveoApiException)39 ELException (org.meveo.elresolver.ELException)39 CustomFieldTemplate (org.meveo.model.crm.CustomFieldTemplate)38 CustomEntityTemplate (org.meveo.model.customEntities.CustomEntityTemplate)37 Map (java.util.Map)34 BundleKey (org.jboss.seam.international.status.builder.BundleKey)30 TransactionAttribute (javax.ejb.TransactionAttribute)28 CustomEntityInstance (org.meveo.model.customEntities.CustomEntityInstance)27 List (java.util.List)25 MeveoModule (org.meveo.model.module.MeveoModule)25 NoResultException (javax.persistence.NoResultException)24 HashSet (java.util.HashSet)22 Response (javax.ws.rs.core.Response)22 Collection (java.util.Collection)20