Search in sources :

Example 1 with PageCustomizations

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

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

the class YamlSerializer method serialize.

public void serialize(final PageCustomizations customizations) throws WriteException {
    this.fileSystem = new ProjectFileSystem(customizations.getProject());
    new CustomizationSerializer().serialize(customizations.getModule());
}
Also used : ProjectFileSystem(com.developmentontheedge.be5.metadata.serialization.ProjectFileSystem)

Example 3 with PageCustomizations

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

the class Serialization method reloadCustomizations.

public static PageCustomizations reloadCustomizations(final Path file, final Module target) throws ReadException {
    checkProject(target.getProject());
    turnOffAutomaticSerialization();
    try {
        return new YamlDeserializer(new LoadContext()).reloadCustomizations(file, target);
    } finally {
        turnOnAutomaticSerialization();
    }
}
Also used : YamlDeserializer(com.developmentontheedge.be5.metadata.serialization.yaml.YamlDeserializer)

Aggregations

ReadException (com.developmentontheedge.be5.metadata.exception.ReadException)1 PageCustomization (com.developmentontheedge.be5.metadata.model.PageCustomization)1 PageCustomizations (com.developmentontheedge.be5.metadata.model.PageCustomizations)1 ProjectFileSystem (com.developmentontheedge.be5.metadata.serialization.ProjectFileSystem)1 YamlDeserializer (com.developmentontheedge.be5.metadata.serialization.yaml.YamlDeserializer)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