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);
}
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;
}
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;
}
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;
}
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;
}
Aggregations