Search in sources :

Example 1 with BeVectorCollection

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

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

Aggregations

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