use of com.developmentontheedge.be5.operation.Operation in project be5 by DevelopmentOnTheEdge.
the class ReadModelFromXmlTest method testWriteReadCompareXmlProject.
@Test
public void testWriteReadCompareXmlProject() throws Exception {
final Project project = new Project("TestProject");
project.setRoles(Arrays.asList("Admin", "Guest"));
final Module module = project.getApplication();
final Entity table = new Entity("testTable", module, EntityType.TABLE);
DataElementUtils.saveQuiet(table);
table.setDisplayName("$project.Name/$module.Name/$entity.Name");
final Operation op = Operation.createOperation("Insert", Operation.OPERATION_TYPE_JAVA, table);
DataElementUtils.saveQuiet(op);
final Query query = new Query("All records", table);
DataElementUtils.saveQuiet(query);
query.setQuery("<@distinct \"name\"/>");
query.setParametrizingOperation(op);
// TODO
// project.getMacroCollection().optScript( FreemarkerCatalog.MAIN_MACRO_LIBRARY )
// .setSource( "<#macro distinct column>SELECT DISTINCT ${column} FROM ${entity.getName()}</#macro>" );
// final BeModelCollection<TableRef> tableRefs = table.getOrCreateTableReferences();
// final TableRef tableRef = new TableRef("ref1", "user", tableRefs);
// tableRef.setTableTo("users");
// tableRef.setColumnsTo("userName");
// DataElementUtils.saveQuiet(tableRef);
//
// final Path tempFolder = Files.createTempDirectory("be4-temp");
// Serialization.save( project, tempFolder );
//
// final Project project2 = Serialization.load( tempFolder );
// assertEquals(new HashSet<>(Arrays.asList( "Admin", "Guest" )), project2.getRoles());
// assertEquals( project.getMacroCollection().optScript( FreemarkerCatalog.MAIN_MACRO_LIBRARY ).getSource(),
// project2.getMacroCollection().optScript( FreemarkerCatalog.MAIN_MACRO_LIBRARY ).getSource() );
// final Entity table2 = project2.getApplication().getEntity( "testTable" );
// assertNotNull(table2);
// assertEquals(table, table2);
// assertEquals(table2, table);
// final Query query2 = table2.getQueries().get("All records");
// assertNotNull(query2);
// assertEquals("<@distinct \"name\"/>", query2.getQuery());
// final Operation op2 = table2.getOperations().get("Insert");
// assertNotNull(op2);
// assertEquals(op, op2);
// assertSame(op2, query2.getParametrizingOperation());
//
// final BeModelCollection<TableRef> tableReferences = project.getEntity("testTable").getOrCreateTableReferences();
// final BeModelCollection<TableRef> tableReferences2 = project2.getEntity("testTable").getOrCreateTableReferences();
// assertEquals(tableReferences.getSize(), tableReferences2.getSize());
// assertEquals(tableReferences.iterator().next().getColumnsFrom(), tableReferences2.iterator().next().getColumnsFrom());
//
// FileUtils.deleteRecursively( tempFolder );
}
use of com.developmentontheedge.be5.operation.Operation in project be5 by DevelopmentOnTheEdge.
the class GroovyOperationLoader method initOperationMap.
void initOperationMap() {
Map<String, com.developmentontheedge.be5.metadata.model.Operation> newOperationMap = new HashMap<>();
List<Entity> entities = meta.getOrderedEntities("ru");
for (Entity entity : entities) {
List<String> operationNames = meta.getOperationNames(entity);
for (String operationName : operationNames) {
com.developmentontheedge.be5.metadata.model.Operation operation = meta.getOperationIgnoringRoles(entity, operationName);
if (operation.getType().equals(OPERATION_TYPE_GROOVY)) {
GroovyOperation groovyOperation = (GroovyOperation) operation;
String fileName = groovyOperation.getFileName().replace("/", ".");
newOperationMap.put(fileName, operation);
}
}
}
groovyOperationsMap = newOperationMap;
}
use of com.developmentontheedge.be5.operation.Operation in project be5 by DevelopmentOnTheEdge.
the class OperationExecutorImpl method create.
@Override
public Operation create(OperationInfo operationInfo, OperationContext operationContext) {
Operation operation;
switch(operationInfo.getType()) {
case OPERATION_TYPE_GROOVY:
try {
Class aClass = groovyOperationLoader.get(operationInfo);
if (aClass != null) {
operation = (Operation) aClass.newInstance();
} else {
throw Be5Exception.internalInOperation(new Error("Class " + operationInfo.getCode() + " is null."), operationInfo.getModel());
}
} catch (NoClassDefFoundError | IllegalAccessException | InstantiationException e) {
throw new UnsupportedOperationException("Groovy feature has been excluded", e);
} catch (Throwable e) {
throw Be5Exception.internalInOperation(e, operationInfo.getModel());
}
break;
case OPERATION_TYPE_JAVA:
try {
operation = (Operation) Class.forName(operationInfo.getCode()).newInstance();
break;
} catch (ClassNotFoundException | IllegalAccessException | InstantiationException e) {
throw Be5Exception.internalInOperation(new RuntimeException("It is possible to use the 'file:' instead of the 'code:' " + "in the yaml file. \n\t" + e.getMessage(), e), operationInfo.getModel());
}
case OPERATION_TYPE_JAVAFUNCTION:
case OPERATION_TYPE_SQL:
case OPERATION_TYPE_JAVASCRIPT:
case OPERATION_TYPE_JSSERVER:
case OPERATION_TYPE_DOTNET:
case OPERATION_TYPE_JAVADOTNET:
throw Be5Exception.internal("Not support operation type: " + operationInfo.getType());
default:
throw Be5Exception.internal("Unknown action type '" + operationInfo.getType() + "'");
}
operation.initialize(operationInfo, operationContext, OperationResult.create());
injector.injectAnnotatedFields(operation);
return operation;
}
use of com.developmentontheedge.be5.operation.Operation in project be5 by DevelopmentOnTheEdge.
the class OperationServiceImpl method execute.
@Override
public Either<Object, OperationResult> execute(Operation operation, Map<String, Object> values) {
Map<String, Object> presetValues = getPresetValues(operation.getContext(), values);
operation.setResult(OperationResult.execute());
Object parameters = operationExecutor.execute(operation, presetValues);
if (OperationStatus.ERROR == operation.getStatus()) {
try {
validator.isError(parameters);
} catch (RuntimeException e) {
log.log(Level.INFO, "error on execute in parameters", e);
operation.setResult(OperationResult.error(e));
return replaceNullValueToEmptyStringAndReturn(parameters);
}
OperationResult invokeResult = operation.getResult();
operation.setResult(OperationResult.execute());
Object newParameters = operationExecutor.generate(operation, presetValues);
if (OperationStatus.ERROR == operation.getStatus()) {
return Either.second(invokeResult);
}
if (newParameters != null) {
operation.setResult(invokeResult);
return replaceNullValueToEmptyStringAndReturn(newParameters);
} else {
return Either.second(invokeResult);
}
}
return Either.second(operation.getResult());
}
use of com.developmentontheedge.be5.operation.Operation in project be5 by DevelopmentOnTheEdge.
the class Menu method generateEntityOperations.
private List<OperationNode> generateEntityOperations(Entity entity, Meta meta, UserAwareMeta userAwareMeta, List<String> roles, boolean withIds) {
List<OperationNode> operations = new ArrayList<>();
Query allRecords = entity.getQueries().get(DatabaseConstants.ALL_RECORDS_VIEW);
String insertOperationName = INSERT_OPERATION;
if (allRecords != null && allRecords.getOperationNames().getFinalValues().contains(insertOperationName)) {
Operation insertOperation = entity.getOperations().get(insertOperationName);
if (insertOperation != null && meta.isAvailableFor(insertOperation, roles)) {
String title = userAwareMeta.getLocalizedOperationTitle(entity.getName(), insertOperationName);
Action action = ActionUtils.toAction(DatabaseConstants.ALL_RECORDS_VIEW, insertOperation);
OperationId id = withIds ? new OperationId(entity.getName(), insertOperationName) : null;
OperationNode operation = new OperationNode(id, title, action);
operations.add(operation);
}
}
return operations;
}
Aggregations