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