Search in sources :

Example 1 with ElementNotFoundException

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

the class Neo4jService method addCRTByNodeIds.

@JpaAmpNewTx
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public PersistenceActionResult addCRTByNodeIds(String neo4JConfiguration, String crtCode, Map<String, Object> crtValues, String startNodeId, String endNodeId) throws BusinessException, ELException {
    log.info("Persisting link with crtCode = {}", crtCode);
    /* Try to retrieve the associated CRT */
    CustomRelationshipTemplate customRelationshipTemplate = customFieldsCache.getCustomRelationshipTemplate(crtCode);
    if (customRelationshipTemplate == null) {
        log.error("Can't find CRT with code {}", crtCode);
        throw new ElementNotFoundException(crtCode, CustomRelationshipTemplate.class.getName());
    }
    /* Recuperation of the custom fields of the CRT */
    Map<String, CustomFieldTemplate> crtCustomFields = customFieldTemplateService.findByAppliesTo(customRelationshipTemplate.getAppliesTo());
    log.info("Custom fields are : {}", crtCustomFields);
    Map<String, Object> crtFields = validateAndConvertCustomFields(crtCustomFields, crtValues, null, true);
    final List<String> relationIds = saveCRT2Neo4jByNodeIds(neo4JConfiguration, customRelationshipTemplate, startNodeId, endNodeId, crtFields, false);
    if (!relationIds.isEmpty()) {
        return new PersistenceActionResult(relationIds.get(0));
    }
    return null;
}
Also used : CustomFieldTemplate(org.meveo.model.crm.CustomFieldTemplate) ElementNotFoundException(org.meveo.admin.exception.ElementNotFoundException) PersistenceActionResult(org.meveo.persistence.PersistenceActionResult) CustomRelationshipTemplate(org.meveo.model.customEntities.CustomRelationshipTemplate) JpaAmpNewTx(org.meveo.jpa.JpaAmpNewTx) TransactionAttribute(javax.ejb.TransactionAttribute)

Example 2 with ElementNotFoundException

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

the class ConcreteFunctionService method getFunctionService.

@SuppressWarnings("unchecked")
public FunctionService<?, ScriptInterface> getFunctionService(String executableCode) throws ElementNotFoundException {
    final Function function = findByCode(executableCode);
    if (function == null) {
        throw new ElementNotFoundException(executableCode, "Function");
    }
    // getEntityManager().detach(function);
    String functionType = function.getFunctionType();
    FunctionServiceLiteral literal = new FunctionServiceLiteral(functionType);
    return (FunctionService<?, ScriptInterface>) fnServiceInst.select(literal).get();
}
Also used : Function(org.meveo.model.scripts.Function) FunctionServiceLiteral(org.meveo.model.scripts.FunctionServiceLiteral) ElementNotFoundException(org.meveo.admin.exception.ElementNotFoundException)

Example 3 with ElementNotFoundException

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

the class Neo4jService method addCRTByNodeValues.

/**
 * Persist an instance of {@link CustomRelationshipTemplate}
 *
 * @param neo4JConfiguration Neo4J coordinates
 * @param crtCode            Code of the CustomRelationshipTemplate instance
 * @param crtValues          Properties of the link
 * @param startFieldValues   Filters on start node
 * @param endFieldValues     Filters on end node
 * @throws BusinessException If error happens
 */
@JpaAmpNewTx
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public PersistenceActionResult addCRTByNodeValues(String neo4JConfiguration, String crtCode, Map<String, Object> crtValues, Map<String, Object> startFieldValues, Map<String, Object> endFieldValues) throws BusinessException, ELException {
    log.info("Persisting link with crtCode = {}", crtCode);
    /* Try to retrieve the associated CRT */
    CustomRelationshipTemplate customRelationshipTemplate = customFieldsCache.getCustomRelationshipTemplate(crtCode);
    if (customRelationshipTemplate == null) {
        log.error("Can't find CRT with code {}", crtCode);
        throw new ElementNotFoundException(crtCode, CustomRelationshipTemplate.class.getName());
    }
    /* If pre-persist script was defined, execute it. fieldValues map may be modified by the script */
    executePrePersist(neo4JConfiguration, customRelationshipTemplate.getStartNode(), startFieldValues);
    executePrePersist(neo4JConfiguration, customRelationshipTemplate.getEndNode(), endFieldValues);
    /* Recuperation of the custom fields of the CRT */
    Map<String, CustomFieldTemplate> crtCustomFields = customFieldTemplateService.findByAppliesTo(customRelationshipTemplate.getAppliesTo());
    log.info("Custom fields are : {}", crtCustomFields);
    /* Recuperation of the custom fields of the source node */
    Map<String, CustomFieldTemplate> startNodeFields = customFieldTemplateService.findByAppliesTo(customRelationshipTemplate.getStartNode().getAppliesTo());
    Map<String, Object> startNodeFieldValues = validateAndConvertCustomFields(startNodeFields, startFieldValues, null, true);
    log.info("Filters on start node :" + startNodeFieldValues);
    Map<String, Object> startNodeKeysMap = getNodeKeys(customRelationshipTemplate.getStartNode().getAppliesTo(), startNodeFieldValues);
    /* Recuperation of the custom fields of the target node */
    Map<String, CustomFieldTemplate> endNodeFields = customFieldTemplateService.findByAppliesTo(customRelationshipTemplate.getEndNode().getAppliesTo());
    Map<String, Object> endNodeFieldValues = validateAndConvertCustomFields(endNodeFields, endFieldValues, null, true);
    log.info("Filters on end node : " + endNodeFieldValues);
    Map<String, Object> endNodeKeysMap = getNodeKeys(customRelationshipTemplate.getEndNode().getAppliesTo(), endNodeFieldValues);
    log.info("startNodeKeysMap:" + startNodeKeysMap);
    log.info("endNodeKeysMap:" + endNodeKeysMap);
    /* If matching source and target exists, persist the link */
    if (startNodeKeysMap.size() > 0 && endNodeKeysMap.size() > 0) {
        Map<String, Object> crtFields = validateAndConvertCustomFields(crtCustomFields, crtValues, null, true);
        final List<String> relationIds = saveCRT2Neo4j(neo4JConfiguration, customRelationshipTemplate, startNodeKeysMap, endNodeKeysMap, crtFields, false);
        if (!relationIds.isEmpty()) {
            return new PersistenceActionResult(relationIds.get(0));
        }
    }
    return null;
}
Also used : CustomFieldTemplate(org.meveo.model.crm.CustomFieldTemplate) ElementNotFoundException(org.meveo.admin.exception.ElementNotFoundException) PersistenceActionResult(org.meveo.persistence.PersistenceActionResult) CustomRelationshipTemplate(org.meveo.model.customEntities.CustomRelationshipTemplate) JpaAmpNewTx(org.meveo.jpa.JpaAmpNewTx) TransactionAttribute(javax.ejb.TransactionAttribute)

Example 4 with ElementNotFoundException

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

the class CustomScriptService method getScriptInterfaceWCompile.

/**
 * Compile the script class for a given script code if it is not compile yet.
 * NOTE: method is executed synchronously due to WRITE lock. DO NOT CHANGE IT,
 * so there would be only one attempt to compile a new script class
 *
 * @param scriptCode Script code
 * @return Script interface Class
 * @throws InvalidScriptException   Were not able to instantiate or compile a
 *                                  script
 * @throws ElementNotFoundException Script not found
 */
protected ScriptInterfaceSupplier getScriptInterfaceWCompile(String scriptCode) throws ElementNotFoundException, InvalidScriptException {
    ScriptInterfaceSupplier result;
    CacheKeyStr key = new CacheKeyStr(currentUser.getProviderCode(), scriptCode);
    result = ALL_SCRIPT_INTERFACES.get(key);
    if (result == null) {
        List<String> fetchFields = Arrays.asList("mavenDependencies");
        T script = findByCode(scriptCode, fetchFields);
        if (script == null) {
            log.debug("ScriptInstance with {} does not exist", scriptCode);
            throw new ElementNotFoundException(scriptCode, getEntityClass().getName());
        }
        if (script.getSourceTypeEnum() == JAVA) {
            loadClassInCache(scriptCode);
        } else if (script.getSourceTypeEnum() == ScriptSourceTypeEnum.ES5) {
            ALL_SCRIPT_INTERFACES.put(key, () -> new ES5ScriptEngine(script));
        } else if (script.getSourceTypeEnum() == ScriptSourceTypeEnum.PYTHON) {
            ALL_SCRIPT_INTERFACES.put(key, () -> new PythonScriptEngine(script));
        }
        if (script.isError()) {
            log.debug("ScriptInstance {} failed to compile. Errors: {}", scriptCode, script.getScriptErrors());
            throw new InvalidScriptException(scriptCode, getEntityClass().getName());
        }
        result = ALL_SCRIPT_INTERFACES.get(key);
        detach(script);
    }
    if (result == null) {
        log.debug("ScriptInstance with {} does not exist", scriptCode);
        throw new ElementNotFoundException(scriptCode, getEntityClass().getName());
    }
    return result;
}
Also used : InvalidScriptException(org.meveo.admin.exception.InvalidScriptException) ElementNotFoundException(org.meveo.admin.exception.ElementNotFoundException) ES5ScriptEngine(org.meveo.service.script.engines.ES5ScriptEngine) CacheKeyStr(org.meveo.cache.CacheKeyStr) PythonScriptEngine(org.meveo.service.script.engines.PythonScriptEngine)

Example 5 with ElementNotFoundException

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

the class ScriptInstanceService method execute.

/**
 * Execute the script identified by a script code. No init nor finalize methods are called.
 *
 * @param scriptCode ScriptInstanceCode
 * @param context Context parameters (optional)
 * @return Context parameters. Will not be null even if "context" parameter is null.
 * @throws org.meveo.admin.exception.InvalidPermissionException Insufficient access to run the script
 * @throws org.meveo.admin.exception.ElementNotFoundException Script not found
 * @throws org.meveo.admin.exception.BusinessException Any execution exception
 */
@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public Map<String, Object> execute(String scriptCode, Map<String, Object> context) throws BusinessException {
    if (scriptCode == null) {
        throw new IllegalArgumentException("Script code should not be null");
    }
    ScriptInstance scriptInstance = findByCode(scriptCode, List.of("executionRoles"));
    if (scriptInstance == null) {
        throw new ElementNotFoundException(scriptCode, "ScriptInstance");
    }
    // Check access to the script
    isUserHasExecutionRole(scriptInstance);
    ScriptInterface executionEngine = getExecutionEngine(scriptInstance, context);
    return super.execute(executionEngine, context);
}
Also used : ScriptInstance(org.meveo.model.scripts.ScriptInstance) ElementNotFoundException(org.meveo.admin.exception.ElementNotFoundException) TransactionAttribute(javax.ejb.TransactionAttribute)

Aggregations

ElementNotFoundException (org.meveo.admin.exception.ElementNotFoundException)8 TransactionAttribute (javax.ejb.TransactionAttribute)3 Function (org.meveo.model.scripts.Function)3 InvalidScriptException (org.meveo.admin.exception.InvalidScriptException)2 EntityDoesNotExistsException (org.meveo.api.exception.EntityDoesNotExistsException)2 JpaAmpNewTx (org.meveo.jpa.JpaAmpNewTx)2 CustomFieldTemplate (org.meveo.model.crm.CustomFieldTemplate)2 CustomRelationshipTemplate (org.meveo.model.customEntities.CustomRelationshipTemplate)2 ScriptInstance (org.meveo.model.scripts.ScriptInstance)2 PersistenceActionResult (org.meveo.persistence.PersistenceActionResult)2 ScriptInterface (org.meveo.service.script.ScriptInterface)2 ArrayList (java.util.ArrayList)1 CacheKeyStr (org.meveo.cache.CacheKeyStr)1 FunctionServiceLiteral (org.meveo.model.scripts.FunctionServiceLiteral)1 Endpoint (org.meveo.model.technicalservice.endpoint.Endpoint)1 EndpointPathParameter (org.meveo.model.technicalservice.endpoint.EndpointPathParameter)1 TSParameterMapping (org.meveo.model.technicalservice.endpoint.TSParameterMapping)1 WSEndpoint (org.meveo.model.technicalservice.wsendpoint.WSEndpoint)1 ES5ScriptEngine (org.meveo.service.script.engines.ES5ScriptEngine)1 PythonScriptEngine (org.meveo.service.script.engines.PythonScriptEngine)1