Search in sources :

Example 1 with EntityCustomAction

use of org.meveo.model.crm.custom.EntityCustomAction in project meveo by meveo-org.

the class CustomEntityTemplateService method remove.

@Override
public void remove(CustomEntityTemplate cet) throws BusinessException {
    Map<String, CustomFieldTemplate> fields = customFieldTemplateService.findByAppliesToNoCache(cet.getAppliesTo());
    Map<String, EntityCustomAction> customActionMap = entityCustomActionService.findByAppliesTo(cet.getAppliesTo());
    for (CustomFieldTemplate cft : fields.values()) {
        // Don't remove super-template cfts
        if (cft.getAppliesTo().equals(cet.getAppliesTo())) {
            customFieldTemplateService.remove(cft);
        }
    }
    for (EntityCustomAction entityCustomAction : customActionMap.values()) {
        entityCustomActionService.remove(entityCustomAction.getId());
    }
    customFieldsCache.removeCustomEntityTemplate(cet);
    // Remove permissions
    permissionService.removeIfPresent(cet.getModifyPermission());
    permissionService.removeIfPresent(cet.getDecrpytPermission());
    permissionService.removeIfPresent(cet.getReadPermission());
    super.remove(cet);
}
Also used : CustomFieldTemplate(org.meveo.model.crm.CustomFieldTemplate) EntityCustomAction(org.meveo.model.crm.custom.EntityCustomAction)

Example 2 with EntityCustomAction

use of org.meveo.model.crm.custom.EntityCustomAction in project meveo by meveo-org.

the class EntityCustomActionApi method find.

/**
 * Find entity custom action by its code and appliesTo attributes
 *
 * @param actionCode Entity custom action code
 * @param appliesTo Applies to
 * @return DTO
 * @throws EntityDoesNotExistsException Entity custom action was not found
 * @throws MissingParameterException A parameter, necessary to find an entity custom action, was not provided
 */
public EntityCustomActionDto find(String actionCode, String appliesTo) throws EntityDoesNotExistsException, MissingParameterException {
    if (StringUtils.isBlank(actionCode)) {
        missingParameters.add("actionCode");
    }
    if (StringUtils.isBlank(appliesTo)) {
        missingParameters.add("appliesTo");
    }
    handleMissingParameters();
    EntityCustomAction action = entityCustomActionService.findByCodeAndAppliesTo(actionCode, appliesTo);
    if (action == null) {
        throw new EntityDoesNotExistsException(EntityCustomAction.class, actionCode + "/" + appliesTo);
    }
    EntityCustomActionDto actionDto = new EntityCustomActionDto(action);
    return actionDto;
}
Also used : EntityDoesNotExistsException(org.meveo.api.exception.EntityDoesNotExistsException) EntityCustomActionDto(org.meveo.api.dto.EntityCustomActionDto) EntityCustomAction(org.meveo.model.crm.custom.EntityCustomAction)

Example 3 with EntityCustomAction

use of org.meveo.model.crm.custom.EntityCustomAction in project meveo by meveo-org.

the class EntityCustomActionApi method update.

public List<ScriptInstanceErrorDto> update(EntityCustomActionDto actionDto, String appliesTo) throws MissingParameterException, EntityDoesNotExistsException, MeveoApiException, BusinessException {
    checkDtoAndSetAppliesTo(actionDto, appliesTo, true);
    EntityCustomAction action = entityCustomActionService.findByCodeAndAppliesTo(actionDto.getCode(), actionDto.getAppliesTo());
    if (action == null) {
        throw new EntityDoesNotExistsException(EntityCustomAction.class, actionDto.getCode() + "/" + actionDto.getAppliesTo());
    }
    entityCustomActionFromDTO(actionDto, action);
    action = entityCustomActionService.update(action);
    List<ScriptInstanceErrorDto> result = new ArrayList<ScriptInstanceErrorDto>();
    ScriptInstance scriptInstance = action.getScript();
    if (scriptInstance.isError() != null && scriptInstance.isError().booleanValue()) {
        for (ScriptInstanceError error : scriptInstance.getScriptErrors()) {
            ScriptInstanceErrorDto errorDto = new ScriptInstanceErrorDto(error);
            result.add(errorDto);
        }
    }
    return result;
}
Also used : ScriptInstance(org.meveo.model.scripts.ScriptInstance) EntityDoesNotExistsException(org.meveo.api.exception.EntityDoesNotExistsException) ArrayList(java.util.ArrayList) ScriptInstanceErrorDto(org.meveo.api.dto.ScriptInstanceErrorDto) EntityCustomAction(org.meveo.model.crm.custom.EntityCustomAction) ScriptInstanceError(org.meveo.model.scripts.ScriptInstanceError)

Example 4 with EntityCustomAction

use of org.meveo.model.crm.custom.EntityCustomAction in project meveo by meveo-org.

the class EntityCustomActionApi method execute.

@SuppressWarnings("rawtypes")
public String execute(String actionCode, String appliesTo, String entityCode) throws MeveoApiException, InvalidScriptException, ElementNotFoundException, InvalidPermissionException, BusinessException {
    EntityCustomAction action = entityCustomActionService.findByCodeAndAppliesTo(actionCode, appliesTo);
    if (action == null) {
        throw new EntityDoesNotExistsException(EntityCustomAction.class, actionCode + "/" + appliesTo);
    }
    Set<Class<?>> cfClasses = ReflectionUtils.getClassesAnnotatedWith(CustomFieldEntity.class, "org.meveo.model");
    Class entityClass = null;
    for (Class<?> clazz : cfClasses) {
        if (appliesTo.equals(clazz.getAnnotation(CustomFieldEntity.class).cftCodePrefix())) {
            entityClass = clazz;
            break;
        }
    }
    IEntity entity = (IEntity) entityCustomActionService.findByEntityClassAndCode(entityClass, entityCode);
    Map<String, Object> context = new HashMap<String, Object>();
    Map<Object, Object> elContext = new HashMap<>(context);
    elContext.put("entity", entity);
    action.getScriptParameters().forEach((key, value) -> {
        try {
            context.put(key, MeveoValueExpressionWrapper.evaluateExpression(value, elContext, Object.class));
        } catch (ELException e) {
            log.error("Failed to evaluate el for custom action", e);
        }
    });
    Map<String, Object> result = scriptInstanceService.execute(entity, repository, action.getScript().getCode(), context);
    if (result.containsKey(Script.RESULT_GUI_OUTCOME)) {
        return (String) result.get(Script.RESULT_GUI_OUTCOME);
    }
    return null;
}
Also used : EntityDoesNotExistsException(org.meveo.api.exception.EntityDoesNotExistsException) IEntity(org.meveo.model.IEntity) HashMap(java.util.HashMap) ELException(org.meveo.elresolver.ELException) EntityCustomAction(org.meveo.model.crm.custom.EntityCustomAction)

Example 5 with EntityCustomAction

use of org.meveo.model.crm.custom.EntityCustomAction in project meveo by meveo-org.

the class EntityCustomActionApi method createOrUpdate.

public List<ScriptInstanceErrorDto> createOrUpdate(EntityCustomActionDto postData, String appliesTo) throws MissingParameterException, EntityAlreadyExistsException, EntityDoesNotExistsException, MeveoApiException, BusinessException {
    List<ScriptInstanceErrorDto> result = new ArrayList<ScriptInstanceErrorDto>();
    checkDtoAndSetAppliesTo(postData, appliesTo, true);
    EntityCustomAction scriptInstance = entityCustomActionService.findByCodeAndAppliesTo(postData.getCode(), postData.getAppliesTo());
    if (scriptInstance == null) {
        result = create(postData, appliesTo);
    } else {
        result = update(postData, appliesTo);
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) ScriptInstanceErrorDto(org.meveo.api.dto.ScriptInstanceErrorDto) EntityCustomAction(org.meveo.model.crm.custom.EntityCustomAction)

Aggregations

EntityCustomAction (org.meveo.model.crm.custom.EntityCustomAction)24 CustomFieldTemplate (org.meveo.model.crm.CustomFieldTemplate)14 ArrayList (java.util.ArrayList)8 EntityDoesNotExistsException (org.meveo.api.exception.EntityDoesNotExistsException)7 EntityCustomActionDto (org.meveo.api.dto.EntityCustomActionDto)4 CustomFieldTemplateDto (org.meveo.api.dto.CustomFieldTemplateDto)3 ScriptInstanceErrorDto (org.meveo.api.dto.ScriptInstanceErrorDto)3 CustomEntityTemplate (org.meveo.model.customEntities.CustomEntityTemplate)3 ScriptInstance (org.meveo.model.scripts.ScriptInstance)3 HashMap (java.util.HashMap)2 Session (org.hibernate.Session)2 CustomEntityTemplateDto (org.meveo.api.dto.CustomEntityTemplateDto)2 EntityAlreadyExistsException (org.meveo.api.exception.EntityAlreadyExistsException)2 QueryBuilder (org.meveo.commons.utils.QueryBuilder)2 ModuleItem (org.meveo.model.ModuleItem)2 CustomEntityInstance (org.meveo.model.customEntities.CustomEntityInstance)2 MeveoModule (org.meveo.model.module.MeveoModule)2 ScriptInstanceError (org.meveo.model.scripts.ScriptInstanceError)2 DefaultTreeNode (org.primefaces.model.DefaultTreeNode)2 TreeNode (org.primefaces.model.TreeNode)2