Search in sources :

Example 11 with ReadException

use of com.developmentontheedge.be5.metadata.exception.ReadException in project be5 by DevelopmentOnTheEdge.

the class YamlDeserializer method reloadEntity.

public Entity reloadEntity(final Entity oldEntity) throws ReadException {
    this.fileSystem = new ProjectFileSystem(oldEntity.getProject());
    this.setProject(oldEntity.getProject());
    final Entity entity = this.readEntity(oldEntity.getModule(), oldEntity.getName());
    if (oldEntity.getPrototype() != null) {
        @SuppressWarnings("unchecked") final BeModelCollection<BeModelElement> prototype = (BeModelCollection<BeModelElement>) oldEntity.getPrototype();
        entity.merge(prototype, true, true);
    }
    EntitiesFactory.addToModule(entity, oldEntity.getModule());
    return entity;
}
Also used : ProjectFileSystem(com.developmentontheedge.be5.metadata.serialization.ProjectFileSystem) Entity(com.developmentontheedge.be5.metadata.model.Entity) BeModelElement(com.developmentontheedge.be5.metadata.model.base.BeModelElement) BeModelCollection(com.developmentontheedge.be5.metadata.model.base.BeModelCollection)

Example 12 with ReadException

use of com.developmentontheedge.be5.metadata.exception.ReadException 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 13 with ReadException

use of com.developmentontheedge.be5.metadata.exception.ReadException in project be5 by DevelopmentOnTheEdge.

the class YamlDeserializer method readConnectionProfiles.

private void readConnectionProfiles(BeConnectionProfileType type, BeConnectionProfilesRoot target) throws ReadException {
    Path connectionProfilesFile = getFileSystem().getConnectionProfilesFile(type);
    if (target.getProject().isModuleProject() && !Files.exists(connectionProfilesFile))
        return;
    if (type == BeConnectionProfileType.LOCAL && !Files.exists(connectionProfilesFile)) {
        target.put(new BeConnectionProfiles(BeConnectionProfileType.LOCAL, target));
        return;
    }
    new ConnectionProfilesDeserializer(connectionProfilesFile, type, target).deserialize();
}
Also used : Path(java.nio.file.Path) DataElementPath(com.developmentontheedge.be5.metadata.model.base.DataElementPath) BeConnectionProfiles(com.developmentontheedge.be5.metadata.model.BeConnectionProfiles)

Example 14 with ReadException

use of com.developmentontheedge.be5.metadata.exception.ReadException in project be5 by DevelopmentOnTheEdge.

the class YamlDeserializer method reloadForms.

public JavaScriptForms reloadForms(final Path path, final Module target) throws ReadException {
    final JavaScriptForms forms = new JavaScriptForms(target);
    final FormsDeserializer deserializer = new FormsDeserializer(path, forms);
    deserializer.deserialize();
    DataElementUtils.saveQuiet(forms);
    return forms;
}
Also used : JavaScriptForms(com.developmentontheedge.be5.metadata.model.JavaScriptForms)

Example 15 with ReadException

use of com.developmentontheedge.be5.metadata.exception.ReadException in project be5 by DevelopmentOnTheEdge.

the class ProjectFileSystem method read.

public static String read(final Path file) throws ReadException {
    if (!Files.exists(file)) {
        throw new ReadException(file, ReadException.LEE_NOT_FOUND);
    }
    if (!Files.isRegularFile(file)) {
        throw new ReadException(file, ReadException.LEE_NOT_A_FILE);
    }
    final byte[] bytes;
    try {
        bytes = readBytes(file);
    } catch (Exception e) {
        throw new ReadException(e, file, ReadException.LEE_UNREADABLE);
    }
    ByteBuffer buffer = ByteBuffer.wrap(bytes);
    CharsetDecoder decoder = StandardCharsets.UTF_8.newDecoder();
    decoder.onMalformedInput(CodingErrorAction.REPORT);
    decoder.onUnmappableCharacter(CodingErrorAction.REPORT);
    char[] resultArray = new char[(int) (bytes.length * decoder.maxCharsPerByte() + 1)];
    CharBuffer decoded = CharBuffer.wrap(resultArray);
    CoderResult result = decoder.decode(buffer, decoded, true);
    try {
        if (!result.isUnderflow())
            result.throwException();
        result = decoder.flush(decoded);
        if (!result.isUnderflow())
            result.throwException();
    } catch (UnmappableCharacterException e) {
        throw new ReadException(new Exception("Unmappable character at " + calcPosition(decoded)), file, ReadException.LEE_ENCODING_ERROR);
    } catch (CharacterCodingException e) {
        throw new ReadException(new Exception("Malformed character at " + calcPosition(decoded)), file, ReadException.LEE_ENCODING_ERROR);
    }
    int start = 0;
    if (// Ignore BOM
    resultArray.length > 0 && resultArray[0] == '\uFEFF')
        start++;
    return new String(resultArray, start, decoded.position() - start);
}
Also used : ReadException(com.developmentontheedge.be5.metadata.exception.ReadException) CharsetDecoder(java.nio.charset.CharsetDecoder) UnmappableCharacterException(java.nio.charset.UnmappableCharacterException) CharBuffer(java.nio.CharBuffer) CharacterCodingException(java.nio.charset.CharacterCodingException) ByteBuffer(java.nio.ByteBuffer) CharacterCodingException(java.nio.charset.CharacterCodingException) ReadException(com.developmentontheedge.be5.metadata.exception.ReadException) IOException(java.io.IOException) UnmappableCharacterException(java.nio.charset.UnmappableCharacterException) UncheckedIOException(java.io.UncheckedIOException) ClosedByInterruptException(java.nio.channels.ClosedByInterruptException) CoderResult(java.nio.charset.CoderResult)

Aggregations

YamlDeserializer (com.developmentontheedge.be5.metadata.serialization.yaml.YamlDeserializer)10 ReadException (com.developmentontheedge.be5.metadata.exception.ReadException)9 Map (java.util.Map)5 IOException (java.io.IOException)4 Entity (com.developmentontheedge.be5.metadata.model.Entity)3 Path (java.nio.file.Path)3 BeConnectionProfile (com.developmentontheedge.be5.metadata.model.BeConnectionProfile)2 BeModelElement (com.developmentontheedge.be5.metadata.model.base.BeModelElement)2 DataElementPath (com.developmentontheedge.be5.metadata.model.base.DataElementPath)2 LinkedHashMap (java.util.LinkedHashMap)2 MarkedYAMLException (org.yaml.snakeyaml.error.MarkedYAMLException)2 YAMLException (org.yaml.snakeyaml.error.YAMLException)2 FreemarkerSqlException (com.developmentontheedge.be5.metadata.exception.FreemarkerSqlException)1 ProcessInterruptedException (com.developmentontheedge.be5.metadata.exception.ProcessInterruptedException)1 ProjectLoadException (com.developmentontheedge.be5.metadata.exception.ProjectLoadException)1 BeConnectionProfiles (com.developmentontheedge.be5.metadata.model.BeConnectionProfiles)1 ColumnDef (com.developmentontheedge.be5.metadata.model.ColumnDef)1 Daemons (com.developmentontheedge.be5.metadata.model.Daemons)1 DataElementUtils (com.developmentontheedge.be5.metadata.model.DataElementUtils)1 DdlElement (com.developmentontheedge.be5.metadata.model.DdlElement)1