Search in sources :

Example 1 with PageCustomization

use of com.developmentontheedge.be5.metadata.model.PageCustomization 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 2 with PageCustomization

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

the class YamlSerializer method serializeCustomizations.

private Map<String, Object> serializeCustomizations(final BeVectorCollection<?> parent) {
    final Map<String, Object> serializedCustomizations = map();
    final BeModelCollection<PageCustomization> customiazations = parent.getCollection(PageCustomization.CUSTOMIZATIONS_COLLECTION, PageCustomization.class);
    if (customiazations != null) {
        final String projectOrigin = parent.getProject().getProjectOrigin();
        for (final PageCustomization customization : customiazations) {
            if (!projectOrigin.equals(customization.getOriginModuleName()))
                continue;
            final String name = customization.getDomain() + "." + customization.getType();
            final Map<String, Object> serializedCustomization = map();
            final List<String> serializedRoles = list(customization.getRoles());
            if (!serializedRoles.isEmpty())
                serializedCustomization.put(ATTR_ROLES, serializedRoles);
            serializedCustomization.put(TAG_CODE, customization.getCode());
            serializedCustomizations.put(name, serializedCustomization);
        }
    }
    return serializedCustomizations;
}
Also used : PageCustomization(com.developmentontheedge.be5.metadata.model.PageCustomization)

Example 3 with PageCustomization

use of com.developmentontheedge.be5.metadata.model.PageCustomization 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)

Aggregations

PageCustomization (com.developmentontheedge.be5.metadata.model.PageCustomization)2 LinkedHashMap (java.util.LinkedHashMap)2 ReadException (com.developmentontheedge.be5.metadata.exception.ReadException)1 PageCustomizations (com.developmentontheedge.be5.metadata.model.PageCustomizations)1 BeModelElement (com.developmentontheedge.be5.metadata.model.base.BeModelElement)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 MarkedYAMLException (org.yaml.snakeyaml.error.MarkedYAMLException)1 YAMLException (org.yaml.snakeyaml.error.YAMLException)1