Search in sources :

Example 11 with LoadContext

use of com.developmentontheedge.be5.metadata.serialization.LoadContext in project be5 by DevelopmentOnTheEdge.

the class ModuleLoader2 method loadModules.

public static List<Project> loadModules(Project application, ProcessController logger, LoadContext loadContext) throws ProjectLoadException {
    List<Project> result = new ArrayList<>();
    for (Module module : application.getModules()) {
        if (containsModule(module.getName())) {
            Project moduleProject = modulesMap.get(module.getName());
            result.add(moduleProject);
        } else {
            throw new RuntimeException("Module project not found " + module.getName());
        }
    }
    // todo ????? topological sort?
    result.sort((o1, o2) -> {
        if (o1.getModules().contains(o2.getName()))
            return 1;
        if (o2.getModules().contains(o1.getName()))
            return -1;
        return 0;
    });
    return result;
}
Also used : Project(com.developmentontheedge.be5.metadata.model.Project) ArrayList(java.util.ArrayList) Module(com.developmentontheedge.be5.metadata.model.Module)

Example 12 with LoadContext

use of com.developmentontheedge.be5.metadata.serialization.LoadContext in project be5 by DevelopmentOnTheEdge.

the class ModuleLoader2 method foldModules.

private static Project foldModules(final Project model, final List<Project> modules, LoadContext context) {
    if (modules.isEmpty()) {
        return null;
    }
    Project compositeModule = null;
    for (Project module : modules) {
        if (compositeModule != null) {
            module.getModules().merge(compositeModule.getModules(), true, true);
            module.getApplication().merge(compositeModule.getModule(module.getProjectOrigin()), true, true);
        }
        module.applyMassChanges(context);
        compositeModule = module;
        if (compositeModule.isModuleProject()) {
            DataElementUtils.addQuiet(module.getModules(), module.getApplication());
            module.setApplication(new Module(model.getProjectOrigin(), model));
        }
    }
    return compositeModule;
}
Also used : Project(com.developmentontheedge.be5.metadata.model.Project) Module(com.developmentontheedge.be5.metadata.model.Module)

Example 13 with LoadContext

use of com.developmentontheedge.be5.metadata.serialization.LoadContext in project be5 by DevelopmentOnTheEdge.

the class MassChangeTest method testMassChange.

@Test
public void testMassChange() {
    Project project = new Project("test");
    Entity entity = new Entity("entity", project.getApplication(), EntityType.TABLE);
    DataElementUtils.save(entity);
    Query queryToChange = new Query("queryToChange", entity);
    DataElementUtils.save(queryToChange);
    Query query = new Query("query", entity);
    DataElementUtils.save(query);
    MassChange mc = new MassChange("Query[name*=\"Change\"]", project.getApplication().getMassChangeCollection(), Collections.singletonMap("type", QueryType.D2));
    assertEquals("type", mc.getPropertiesString());
    assertEquals("Query[name*=Change]", mc.getSelectorString());
    DataElementUtils.save(mc);
    assertEquals(QueryType.D1, queryToChange.getType());
    assertEquals(QueryType.D1, query.getType());
    LoadContext context = new LoadContext();
    project.applyMassChanges(context);
    context.check();
    assertEquals(QueryType.D2, entity.getQueries().get("queryToChange").getType());
    assertEquals(QueryType.D1, entity.getQueries().get("query").getType());
}
Also used : LoadContext(com.developmentontheedge.be5.metadata.serialization.LoadContext) Test(org.junit.Test)

Example 14 with LoadContext

use of com.developmentontheedge.be5.metadata.serialization.LoadContext in project be5 by DevelopmentOnTheEdge.

the class ReadModelFromXmlTest method testWriteReadConnectionProfile.

/**
 * Unexpected error when serializing 'connectionUrl' of TestProject/Connection profiles/Local/test
 * on windows
 * @throws Exception
 */
@Test
public void testWriteReadConnectionProfile() throws Exception {
    Assume.assumeFalse(System.getProperty("os.name").toLowerCase().startsWith("win"));
    final Project project = new Project("TestProject");
    BeConnectionProfile profile = new BeConnectionProfile("test", project.getConnectionProfiles().getLocalProfiles());
    profile.setConnectionUrl("jdbc:db2://localhost:50000/housing:retrieveMessagesFromServerOnGetMessage=true;");
    profile.setUsername("test");
    profile.setPassword("password");
    LinkedHashMap<String, Object> serializedProfiles = new LinkedHashMap<>();
    serializedProfiles.put(profile.getName(), YamlSerializer.serializeProfile(profile));
    String serialized = new Yaml().dump(serializedProfiles);
    LoadContext loadContext = new LoadContext();
    BeConnectionProfile createdProfile = YamlDeserializer.deserializeConnectionProfile(loadContext, serialized, project);
    assertNotNull(createdProfile);
    if (!loadContext.getWarnings().isEmpty())
        throw loadContext.getWarnings().get(0);
    assertEquals(profile.getConnectionUrl(), createdProfile.getConnectionUrl());
    assertEquals(profile.getUsername(), createdProfile.getUsername());
}
Also used : Project(com.developmentontheedge.be5.metadata.model.Project) BeConnectionProfile(com.developmentontheedge.be5.metadata.model.BeConnectionProfile) LoadContext(com.developmentontheedge.be5.metadata.serialization.LoadContext) Yaml(org.yaml.snakeyaml.Yaml) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 15 with LoadContext

use of com.developmentontheedge.be5.metadata.serialization.LoadContext in project be5 by DevelopmentOnTheEdge.

the class Be5Mojo method loadProject.

protected Project loadProject(final Path root) throws MojoFailureException {
    final LoadContext loadContext = new LoadContext();
    Project prj;
    try {
        prj = Serialization.load(root, loadContext);
    } catch (final ProjectLoadException e) {
        throw new MojoFailureException("Can not load project", e);
    }
    checkErrors(loadContext, "Project has %d error(s)");
    return prj;
}
Also used : Project(com.developmentontheedge.be5.metadata.model.Project) ProjectLoadException(com.developmentontheedge.be5.metadata.exception.ProjectLoadException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) LoadContext(com.developmentontheedge.be5.metadata.serialization.LoadContext)

Aggregations

YamlDeserializer (com.developmentontheedge.be5.metadata.serialization.yaml.YamlDeserializer)10 Project (com.developmentontheedge.be5.metadata.model.Project)9 LoadContext (com.developmentontheedge.be5.metadata.serialization.LoadContext)7 ProjectLoadException (com.developmentontheedge.be5.metadata.exception.ProjectLoadException)5 ReadException (com.developmentontheedge.be5.metadata.exception.ReadException)5 URL (java.net.URL)4 Path (java.nio.file.Path)4 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 BeConnectionProfile (com.developmentontheedge.be5.metadata.model.BeConnectionProfile)3 Query (com.developmentontheedge.be5.metadata.model.Query)3 LinkedHashMap (java.util.LinkedHashMap)3 Map (java.util.Map)3 Yaml (org.yaml.snakeyaml.Yaml)3 Entity (com.developmentontheedge.be5.metadata.model.Entity)2 Module (com.developmentontheedge.be5.metadata.model.Module)2 IOException (java.io.IOException)2 URISyntaxException (java.net.URISyntaxException)2 MojoFailureException (org.apache.maven.plugin.MojoFailureException)2 Before (org.junit.Before)2