Search in sources :

Example 1 with Operation

use of com.developmentontheedge.be5.metadata.model.Operation in project be5 by DevelopmentOnTheEdge.

the class DateTimeTest method testOperation.

@Test
public void testOperation() {
    Operation operation = createOperation("dateTime", "All records", "Insert", "0");
    ImmutableMap<String, Object> values = ImmutableMap.of("activeFrom", "1901-02-03");
    Either<Object, OperationResult> generate = generateOperation(operation, values);
    Object parameters = generate.getFirst();
    assertEquals("{" + "'values':{'activeFrom':'1901-02-03'}," + "'meta':{'/activeFrom':{'displayName':'activeFrom','type':'Date'}}," + "'order':['/activeFrom']" + "}", oneQuotes(JsonFactory.bean(parameters)));
    OperationResult result = executeOperation(operation, values).getSecond();
    assertEquals(OperationResult.redirect("table/dateTime/All records"), result);
}
Also used : OperationResult(com.developmentontheedge.be5.operation.OperationResult) Operation(com.developmentontheedge.be5.operation.Operation) Test(org.junit.Test) SqlMockOperationTest(com.developmentontheedge.be5.test.SqlMockOperationTest)

Example 2 with Operation

use of com.developmentontheedge.be5.metadata.model.Operation in project be5 by DevelopmentOnTheEdge.

the class MassChange method apply.

public List<BeModelElement> apply(LoadContext loadContext, Project project) {
    List<BeModelElement> elements = SelectorUtils.select(project, getRule());
    List<BeModelElement> changedElements = new ArrayList<>();
    for (BeModelElement element : elements) {
        if (element instanceof Query) {
            Query oldQuery = (Query) element;
            Query newQuery = YamlDeserializer.readQuery(loadContext, oldQuery.getName(), data, oldQuery.getEntity());
            DataElementUtils.saveQuiet(newQuery);
            newQuery.merge(oldQuery, false, true);
            newQuery.setOriginModuleName(oldQuery.getOriginModuleName());
        } else if (element instanceof Operation) {
            Operation oldOperation = (Operation) element;
            Map<String, Object> realData = data;
            // Set type, because it cannot be inherited yet
            if (!data.containsKey("type") && !Operation.OPERATION_TYPE_JAVA.equals(oldOperation.getType())) {
                realData = new HashMap<>(data);
                realData.put("type", oldOperation.getType());
            }
            Operation newOperation = YamlDeserializer.readOperation(loadContext, oldOperation.getName(), realData, oldOperation.getEntity());
            DataElementUtils.saveQuiet(newOperation);
            newOperation.merge(oldOperation, false, true);
            newOperation.setOriginModuleName(oldOperation.getOriginModuleName());
        } else if (element instanceof Entity) {
            Entity oldEntity = (Entity) element;
            Map<String, Object> realData = data;
            // Set type, because it cannot be inherited yet
            if (!data.containsKey("type")) {
                realData = new HashMap<>(data);
                realData.put("type", oldEntity.getType().getSqlName());
            }
            Entity newEntity = YamlDeserializer.readEntity(loadContext, oldEntity.getName(), realData, oldEntity.getModule());
            for (EntityItem q : newEntity.getQueries()) q.setOriginModuleName(oldEntity.getModule().getName());
            for (EntityItem o : newEntity.getOperations()) o.setOriginModuleName(oldEntity.getModule().getName());
            DataElementUtils.saveQuiet(newEntity);
            newEntity.merge(oldEntity, false, true);
        } else {
            loadContext.addWarning(new ReadException(element, null, "Mass change is not supported for type " + element.getClass().getSimpleName()));
            continue;
        }
        changedElements.add(element);
    }
    return changedElements;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) ReadException(com.developmentontheedge.be5.metadata.exception.ReadException) BeModelElement(com.developmentontheedge.be5.metadata.model.base.BeModelElement) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 3 with Operation

use of com.developmentontheedge.be5.metadata.model.Operation in project be5 by DevelopmentOnTheEdge.

the class Entity method getErrors.

@Override
public List<ProjectElementException> getErrors() {
    final List<ProjectElementException> errors = new ArrayList<>();
    if (getName().length() > Constants.MAX_ID_LENGTH) {
        errors.add(new ProjectElementException(getCompletePath(), "name", "Entity name is too long."));
    }
    for (final Module module : getProject().getModulesAndApplication()) {
        final Module thisModule = getModule();
        if (module == thisModule)
            break;
        final Entity duplicate = module.getEntity(getName());
        if (duplicate != null) {
            errors.add(new ProjectElementException(getCompletePath(), "name", "Entity with name '" + getName() + "' already exists."));
            break;
        }
    }
    final TableDef tableDef = findTableDefinition();
    if (tableDef != null) {
        errors.addAll(tableDef.getErrors());
    }
    for (final Query query : getQueries()) {
        errors.addAll(query.getErrors());
    }
    for (final Operation operation : getOperations()) {
        errors.addAll(operation.getErrors());
    }
    return errors;
}
Also used : ProjectElementException(com.developmentontheedge.be5.metadata.exception.ProjectElementException) ArrayList(java.util.ArrayList)

Example 4 with Operation

use of com.developmentontheedge.be5.metadata.model.Operation in project be5 by DevelopmentOnTheEdge.

the class YamlDeserializer method readCustomizations.

/**
 * Used with customizations (module), entity, query, operation and static page.
 */
@SuppressWarnings("unchecked")
private void readCustomizations(final Map<String, Object> serialized, final BeVectorCollection<?> target, boolean replace) {
    if (project == null)
        throw new IllegalStateException();
    final Map<String, Object> serializedCustomizations = (Map<String, Object>) serialized.get("customizations");
    if (serializedCustomizations == null || serializedCustomizations.isEmpty())
        return;
    final BeVectorCollection<PageCustomization> customizations = replace ? new PageCustomizations(target) : target.getOrCreateCollection(PageCustomization.CUSTOMIZATIONS_COLLECTION, PageCustomization.class);
    try {
        for (final String name : serializedCustomizations.keySet()) {
            final Map<String, Object> content = (Map<String, Object>) serializedCustomizations.get(name);
            final List<String> splitted = StreamEx.split(name, "\\.").toList();
            final String type;
            final String domain;
            if (splitted.size() == 1) {
                type = "";
                domain = splitted.get(0);
            } else {
                type = splitted.get(splitted.size() - 1);
                splitted.remove(splitted.size() - 1);
                domain = String.join(".", splitted);
            }
            final PageCustomization customization = new PageCustomization(type, domain, customizations);
            customization.setCode((String) content.get(TAG_CODE));
            customization.setOriginModuleName(project.getProjectOrigin());
            DataElementUtils.saveQuiet(customization);
        }
    } catch (Exception e) {
        loadContext.addWarning(new ReadException(e, target, project.getLocation()));
    }
    if (replace)
        DataElementUtils.save(customizations);
}
Also used : ReadException(com.developmentontheedge.be5.metadata.exception.ReadException) PageCustomizations(com.developmentontheedge.be5.metadata.model.PageCustomizations) PageCustomization(com.developmentontheedge.be5.metadata.model.PageCustomization) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) ReadException(com.developmentontheedge.be5.metadata.exception.ReadException) InvocationTargetException(java.lang.reflect.InvocationTargetException) MarkedYAMLException(org.yaml.snakeyaml.error.MarkedYAMLException) YAMLException(org.yaml.snakeyaml.error.YAMLException)

Example 5 with Operation

use of com.developmentontheedge.be5.metadata.model.Operation in project be5 by DevelopmentOnTheEdge.

the class ReadModelFromXmlTest method testWriteReadQueryOperation.

@Test
public void testWriteReadQueryOperation() throws Exception {
    final Project project = new Project("TestProject");
    final Module module = project.getApplication();
    DataElementUtils.saveQuiet(module);
    final Entity table = new Entity("table", module, EntityType.TABLE);
    DataElementUtils.saveQuiet(table);
    final Operation op = Operation.createOperation("op", Operation.OPERATION_TYPE_JAVA, table);
    DataElementUtils.saveQuiet(op);
    final Query query = new Query("q", table);
    DataElementUtils.saveQuiet(query);
    query.getOperationNames().add("op");
    final Path tempFolder = Files.createTempDirectory("be4-temp");
    Serialization.save(project, tempFolder);
    final Project readProject = Serialization.load(tempFolder);
    final Entity readEntity = readProject.getApplication().getEntity("table");
    assertEquals("op", readEntity.getQueries().get("q").getOperationNames().getValuesArray()[0]);
    FileUtils.deleteRecursively(tempFolder);
}
Also used : Path(java.nio.file.Path) Project(com.developmentontheedge.be5.metadata.model.Project) Entity(com.developmentontheedge.be5.metadata.model.Entity) Query(com.developmentontheedge.be5.metadata.model.Query) Operation(com.developmentontheedge.be5.metadata.model.Operation) Module(com.developmentontheedge.be5.metadata.model.Module) Test(org.junit.Test)

Aggregations

Operation (com.developmentontheedge.be5.metadata.model.Operation)9 Entity (com.developmentontheedge.be5.metadata.model.Entity)6 Operation (com.developmentontheedge.be5.operation.Operation)6 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)6 Module (com.developmentontheedge.be5.metadata.model.Module)5 Query (com.developmentontheedge.be5.metadata.model.Query)5 Project (com.developmentontheedge.be5.metadata.model.Project)4 OperationResult (com.developmentontheedge.be5.operation.OperationResult)4 Path (java.nio.file.Path)3 HashMap (java.util.HashMap)3 LinkedHashMap (java.util.LinkedHashMap)3 ReadException (com.developmentontheedge.be5.metadata.exception.ReadException)2 BeModelElement (com.developmentontheedge.be5.metadata.model.base.BeModelElement)2 Action (com.developmentontheedge.be5.model.Action)2 FormPresentation (com.developmentontheedge.be5.model.FormPresentation)2 TableOperationPresentation (com.developmentontheedge.be5.model.TableOperationPresentation)2 ResourceData (com.developmentontheedge.be5.model.jsonapi.ResourceData)2 SqlMockOperationTest (com.developmentontheedge.be5.test.SqlMockOperationTest)2 HashUrl (com.developmentontheedge.be5.util.HashUrl)2