Search in sources :

Example 1 with ReadException

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

the class MassChange method apply.

public List<BeModelElement> apply(LoadContext loadContext, Project project) {
    List<BeModelElement> elements = SelectorUtils.select(project, getRule());
    List<BeModelElement> changedElements = new ArrayList<>();
    for (BeModelElement element : elements) {
        if (element instanceof Query) {
            Query oldQuery = (Query) element;
            Query newQuery = YamlDeserializer.readQuery(loadContext, oldQuery.getName(), data, oldQuery.getEntity());
            DataElementUtils.saveQuiet(newQuery);
            newQuery.merge(oldQuery, false, true);
            newQuery.setOriginModuleName(oldQuery.getOriginModuleName());
        } else if (element instanceof Operation) {
            Operation oldOperation = (Operation) element;
            Map<String, Object> realData = data;
            // Set type, because it cannot be inherited yet
            if (!data.containsKey("type") && !Operation.OPERATION_TYPE_JAVA.equals(oldOperation.getType())) {
                realData = new HashMap<>(data);
                realData.put("type", oldOperation.getType());
            }
            Operation newOperation = YamlDeserializer.readOperation(loadContext, oldOperation.getName(), realData, oldOperation.getEntity());
            DataElementUtils.saveQuiet(newOperation);
            newOperation.merge(oldOperation, false, true);
            newOperation.setOriginModuleName(oldOperation.getOriginModuleName());
        } else if (element instanceof Entity) {
            Entity oldEntity = (Entity) element;
            Map<String, Object> realData = data;
            // Set type, because it cannot be inherited yet
            if (!data.containsKey("type")) {
                realData = new HashMap<>(data);
                realData.put("type", oldEntity.getType().getSqlName());
            }
            Entity newEntity = YamlDeserializer.readEntity(loadContext, oldEntity.getName(), realData, oldEntity.getModule());
            for (EntityItem q : newEntity.getQueries()) q.setOriginModuleName(oldEntity.getModule().getName());
            for (EntityItem o : newEntity.getOperations()) o.setOriginModuleName(oldEntity.getModule().getName());
            DataElementUtils.saveQuiet(newEntity);
            newEntity.merge(oldEntity, false, true);
        } else {
            loadContext.addWarning(new ReadException(element, null, "Mass change is not supported for type " + element.getClass().getSimpleName()));
            continue;
        }
        changedElements.add(element);
    }
    return changedElements;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) ReadException(com.developmentontheedge.be5.metadata.exception.ReadException) BeModelElement(com.developmentontheedge.be5.metadata.model.base.BeModelElement) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 2 with ReadException

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

the class Serialization method reloadMassChanges.

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

Example 3 with ReadException

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

the class Serialization method reloadForms.

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

Example 4 with ReadException

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

the class Serialization method reloadConnectionProfiles.

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

Example 5 with ReadException

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

the class Serialization method reloadSecurity.

public static SecurityCollection reloadSecurity(final Path file, final Project project) throws ReadException {
    checkProject(project);
    turnOffAutomaticSerialization();
    try {
        return new YamlDeserializer(new LoadContext()).reloadSecurityCollection(file, project);
    } finally {
        turnOnAutomaticSerialization();
    }
}
Also used : YamlDeserializer(com.developmentontheedge.be5.metadata.serialization.yaml.YamlDeserializer)

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