Search in sources :

Example 21 with Entity

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

the class GdslGenegator method createService.

private void createService(String generatedSourcesPath, String packageName, String serviceClassName, Configuration cfg) throws IOException {
    Template serviceTpl = cfg.getTemplate("gdsl/entities.ftl");
    Meta meta = injector.getMeta();
    List<Entity> entities = meta.getOrderedEntities("ru");
    Map<String, Object> input = new HashMap<>();
    // input.put("serviceClassName", serviceClassName);
    // input.put("packageName", packageName);
    List<String> entityNames = new ArrayList<>();
    entityCount = entities.size();
    for (Entity entity : entities) {
        if (entity.getName().startsWith("_"))
            continue;
        // groovy have getProperties()
        if (entity.getName().equals("properties"))
            continue;
        entityNames.add(entity.getName());
    }
    input.put("entityNames", entityNames);
    Utils.createFile(generatedSourcesPath, packageName, serviceClassName + ".gdsl", serviceTpl, input);
}
Also used : Meta(com.developmentontheedge.be5.api.services.Meta) Entity(com.developmentontheedge.be5.metadata.model.Entity) Template(freemarker.template.Template)

Example 22 with Entity

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

the class ProvincesRepository method toMap.

@Override
public Map<String, Object> toMap(@DelegatesTo(strategy = Closure.DELEGATE_FIRST, value = Provinces.class) final Closure config) {
    Provinces entity = new Provinces();
    // todo need this
    Closure code = config.rehydrate(entity, entity, entity);
    code.setResolveStrategy(Closure.DELEGATE_FIRST);
    code.call();
    return toMap(entity);
}
Also used : Provinces(com.developmentontheedge.be5.entitygen.experimental.genegate.entities.Provinces) Closure(groovy.lang.Closure)

Example 23 with Entity

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

the class Project method getContext.

/**
 * Creates and returns FreeMarker context for given element
 * @param element to create context for (can be null)
 * @return
 */
public Map<String, Object> getContext(TemplateElement element) {
    Map<String, Object> context = new HashMap<>();
    BeModelElement parent = element;
    while (parent != null) {
        if (parent instanceof PageCustomization) {
            context.put("customization", parent);
        } else if (parent instanceof Query) {
            context.put("query", parent);
        } else if (parent instanceof Operation) {
            context.put("operation", parent);
        } else if (parent instanceof Entity) {
            context.put("entity", parent);
        } else if (parent instanceof Module) {
            context.put("module", parent);
        }
        parent = parent.getOrigin();
    }
    for (String name : getPropertyNames()) {
        context.put(name, getProperty(name));
    }
    BeConnectionProfile profile = getConnectionProfile();
    if (profile != null) {
        for (String name : profile.getPropertyNames()) {
            context.put(name, profile.getProperty(name));
        }
    }
    return context;
}
Also used : BeModelElement(com.developmentontheedge.be5.metadata.model.base.BeModelElement) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 24 with Entity

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

the class Query method getErrors.

@Override
public List<ProjectElementException> getErrors() {
    List<ProjectElementException> result = super.getErrors();
    try {
        ModelValidationUtils.checkValueInSet(this, "type", getType().getName(), getQueryTypes());
    } catch (ProjectElementException e) {
        result.add(e);
    }
    String templateQueryName = getTemplateQueryName();
    if (!templateQueryName.isEmpty()) {
        int pos = templateQueryName.indexOf('.');
        if (pos < 0) {
            result.add(new ProjectElementException(getCompletePath(), "templateQueryName", new IllegalArgumentException("templateQueryName must have format <entity>:<query>")));
        }
    }
    Set<String> missingEntries = getRoles().getMissingEntries();
    if (!missingEntries.isEmpty()) {
        result.add(new ProjectElementException(getCompletePath(), "roles", "Unknown role(s): " + missingEntries));
    }
    ProjectElementException error = getQueryCompiled().getError();
    if (error != null && !error.isNoError()) {
        DataElementPath path = getCompletePath();
        if (error.getPath().equals(path.toString()))
            result.add(error);
        else
            result.add(new ProjectElementException(path, "query", error));
    }
    return result;
}
Also used : ProjectElementException(com.developmentontheedge.be5.metadata.exception.ProjectElementException) DataElementPath(com.developmentontheedge.be5.metadata.model.base.DataElementPath)

Example 25 with Entity

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

the class Menu method collectEntityContent.

private void collectEntityContent(Entity entity, String language, Meta meta, UserAwareMeta userAwareMeta, List<String> roles, boolean withIds, List<RootNode> out) {
    List<Query> permittedQueries = meta.getQueries(entity, roles);
    if (permittedQueries.isEmpty()) {
        return;
    }
    String title = meta.getTitle(entity, language);
    List<OperationNode> operations = generateEntityOperations(entity, meta, userAwareMeta, roles, withIds);
    if (operations.isEmpty()) {
        operations = null;
    }
    if (canBeMovedToRoot(permittedQueries, title, language, meta)) {
        // Query in the root, contains an action.
        Id id = null;
        Action action = ActionUtils.toAction(permittedQueries.get(0));
        boolean isDefault = permittedQueries.get(0).isDefaultView();
        if (withIds) {
            String queryTitle = getTitleOfRootQuery(permittedQueries, title, language, meta);
            id = new Id(entity.getName(), queryTitle);
        }
        out.add(RootNode.action(id, title, isDefault, action, operations));
    } else {
        // No query in the root, just inner queries.
        List<QueryNode> children = generateEntityQueries(permittedQueries, language, meta, withIds);
        Id id = new Id(entity.getName(), null);
        out.add(RootNode.container(id, title, children, operations));
    }
}
Also used : Action(com.developmentontheedge.be5.model.Action) Query(com.developmentontheedge.be5.metadata.model.Query)

Aggregations

Entity (com.developmentontheedge.be5.metadata.model.Entity)36 Query (com.developmentontheedge.be5.metadata.model.Query)19 Module (com.developmentontheedge.be5.metadata.model.Module)16 Project (com.developmentontheedge.be5.metadata.model.Project)16 Test (org.junit.Test)11 Path (java.nio.file.Path)9 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)8 ColumnDef (com.developmentontheedge.be5.metadata.model.ColumnDef)7 Operation (com.developmentontheedge.be5.metadata.model.Operation)7 TableDef (com.developmentontheedge.be5.metadata.model.TableDef)7 Meta (com.developmentontheedge.be5.api.services.Meta)4 ReadException (com.developmentontheedge.be5.metadata.exception.ReadException)4 BeModelElement (com.developmentontheedge.be5.metadata.model.base.BeModelElement)4 Map (java.util.Map)4 ProjectElementException (com.developmentontheedge.be5.metadata.exception.ProjectElementException)3 DdlElement (com.developmentontheedge.be5.metadata.model.DdlElement)3 Localizations (com.developmentontheedge.be5.metadata.model.Localizations)3 LinkedHashMap (java.util.LinkedHashMap)3 Be5Exception (com.developmentontheedge.be5.api.exceptions.Be5Exception)2