Search in sources :

Example 6 with ProjectLoadException

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

the class SerializationTest method testSerializationBasics.

@Test
public void testSerializationBasics() throws IOException, ProjectSaveException, ProjectLoadException {
    Path path = tmp.newFolder().toPath();
    Project project = ProjectTestUtils.getProject("test");
    Entity entity = ProjectTestUtils.createEntity(project, "entity", "ID");
    TableDef scheme = ProjectTestUtils.createScheme(entity);
    // only for test SqlColumnType getType( Collection<ColumnDef> stack )
    ColumnDef column3 = new ColumnDef("column3", scheme.getColumns());
    column3.setTableTo(entity.getName());
    column3.setColumnsTo("ID");
    DataElementUtils.save(column3);
    Query query = ProjectTestUtils.createQuery(entity, "All records", Arrays.asList('@' + SpecialRoleGroup.ALL_ROLES_EXCEPT_GUEST_GROUP, "-User"));
    query.getOperationNames().setValues(Collections.singleton("op"));
    ProjectTestUtils.createOperation(entity);
    Serialization.save(project, path);
    assertEquals(path, project.getLocation());
    LoadContext lc = new LoadContext();
    Project project2 = Serialization.load(path, lc);
    project2.setDatabaseSystem(Rdbms.POSTGRESQL);
    lc.check();
    Entity entity2 = project2.getEntity("entity");
    assertEquals(entity, entity2);
    assertTrue(entity2.isBesql());
    assertEquals("VARCHAR(20)", entity2.findTableDefinition().getColumns().get("name").getTypeString());
    assertEquals(StreamEx.of("Administrator", "Operator").toSet(), entity2.getQueries().get("All records").getRoles().getFinalValues());
    assertEquals("op", entity2.getQueries().get("All records").getOperationNames().getFinalValuesString());
}
Also used : Path(java.nio.file.Path) Project(com.developmentontheedge.be5.metadata.model.Project) Entity(com.developmentontheedge.be5.metadata.model.Entity) Query(com.developmentontheedge.be5.metadata.model.Query) ColumnDef(com.developmentontheedge.be5.metadata.model.ColumnDef) TableDef(com.developmentontheedge.be5.metadata.model.TableDef) Test(org.junit.Test)

Example 7 with ProjectLoadException

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

the class AppSync method execute.

// /////////////////////////////////////////////////////////////////
@Override
public void execute() throws MojoFailureException {
    init();
    PrintStream ps = null;
    try {
        if (logPath != null) {
            logPath.mkdirs();
            ps = new PrintStream(new File(logPath, be5Project.getName() + "_sync_ddl.sql"), "UTF-8");
        }
        sqlExecutor = new BeSqlExecutor(connector, ps);
        if (be5Project.getDebugStream() != null) {
            be5Project.getDebugStream().println("Modules and extras for " + be5Project.getName() + ":");
            be5Project.allModules().map(m -> "- " + m.getName() + ": " + (m.getExtras() == null ? "" : String.join(", ", m.getExtras()))).forEach(be5Project.getDebugStream()::println);
        }
        readSchema();
        createEntities();
        String ddlString = getDdlStatements(false);
        ddlString = MultiSqlParser.normalize(be5Project.getDatabaseSystem().getType(), ddlString);
        if (ddlString.isEmpty()) {
            getLog().info("Database scheme is up-to-date");
            return;
        }
        if (forceUpdate) {
            sqlExecutor.startSection("Sync schema");
            logger.setOperationName("[>] Schema");
            sqlExecutor.executeMultiple(ddlString);
            sqlExecutor.startSection(null);
        } else {
            System.err.println("The following statements should be executed to update database scheme:");
            System.err.println(ddlString);
            System.err.println("Use -DBE5_FORCE_UPDATE=true, for apply");
        }
        checkSynchronizationStatus();
        logger.setOperationName("Finished");
    } catch (// ReadException | ProjectLoadException | SQLException e )
    FreemarkerSqlException | ExtendedSqlException | SQLException e) {
        if (debug)
            throw new MojoFailureException("Synchronisation error: " + e.getMessage(), e);
        throw new MojoFailureException("Synchronisation error: " + e.getMessage());
    } catch (IOException | ProcessInterruptedException e) {
        throw new MojoFailureException("Synchronisation error: " + e.getMessage(), e);
    } catch (Throwable t) {
        t.printStackTrace();
        throw new MojoFailureException("Synchronisation error: " + t.getMessage(), t);
    } finally {
        if (ps != null) {
            ps.close();
        }
    }
}
Also used : FreemarkerSqlException(com.developmentontheedge.be5.metadata.exception.FreemarkerSqlException) Arrays(java.util.Arrays) ViewDef(com.developmentontheedge.be5.metadata.model.ViewDef) NullLogger(com.developmentontheedge.be5.metadata.util.NullLogger) HashMap(java.util.HashMap) BeSqlExecutor(com.developmentontheedge.be5.metadata.sql.BeSqlExecutor) Parameter(org.apache.maven.plugins.annotations.Parameter) MultiSqlParser(com.developmentontheedge.dbms.MultiSqlParser) Rdbms(com.developmentontheedge.be5.metadata.sql.Rdbms) ArrayList(java.util.ArrayList) Entity(com.developmentontheedge.be5.metadata.model.Entity) DefaultTypeManager(com.developmentontheedge.be5.metadata.sql.type.DefaultTypeManager) Mojo(org.apache.maven.plugins.annotations.Mojo) SQLException(java.sql.SQLException) IndexDef(com.developmentontheedge.be5.metadata.model.IndexDef) DatabaseUtils(com.developmentontheedge.be5.metadata.sql.DatabaseUtils) ResultSet(java.sql.ResultSet) Locale(java.util.Locale) Map(java.util.Map) ExtendedSqlException(com.developmentontheedge.dbms.ExtendedSqlException) DdlElement(com.developmentontheedge.be5.metadata.model.DdlElement) Module(com.developmentontheedge.be5.metadata.model.Module) TableDef(com.developmentontheedge.be5.metadata.model.TableDef) DataElementUtils(com.developmentontheedge.be5.metadata.model.DataElementUtils) ProcessController(com.developmentontheedge.be5.metadata.util.ProcessController) PrintStream(java.io.PrintStream) DbmsTypeManager(com.developmentontheedge.be5.metadata.sql.type.DbmsTypeManager) ProcessInterruptedException(com.developmentontheedge.be5.metadata.exception.ProcessInterruptedException) IndexColumnDef(com.developmentontheedge.be5.metadata.model.IndexColumnDef) IOException(java.io.IOException) File(java.io.File) MojoFailureException(org.apache.maven.plugin.MojoFailureException) SqlColumnInfo(com.developmentontheedge.be5.metadata.sql.pojo.SqlColumnInfo) List(java.util.List) ColumnDef(com.developmentontheedge.be5.metadata.model.ColumnDef) IndexInfo(com.developmentontheedge.be5.metadata.sql.pojo.IndexInfo) SqlColumnType(com.developmentontheedge.be5.metadata.model.SqlColumnType) DbmsType(com.developmentontheedge.dbms.DbmsType) IntStreamEx(one.util.streamex.IntStreamEx) Pattern(java.util.regex.Pattern) Project(com.developmentontheedge.be5.metadata.model.Project) Collections(java.util.Collections) EntityType(com.developmentontheedge.be5.metadata.model.EntityType) DbmsSchemaReader(com.developmentontheedge.be5.metadata.sql.schema.DbmsSchemaReader) FreemarkerSqlException(com.developmentontheedge.be5.metadata.exception.FreemarkerSqlException) PrintStream(java.io.PrintStream) SQLException(java.sql.SQLException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) IOException(java.io.IOException) ExtendedSqlException(com.developmentontheedge.dbms.ExtendedSqlException) BeSqlExecutor(com.developmentontheedge.be5.metadata.sql.BeSqlExecutor) File(java.io.File) ProcessInterruptedException(com.developmentontheedge.be5.metadata.exception.ProcessInterruptedException)

Example 8 with ProjectLoadException

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

the class AppValidate method loadModules.

private void loadModules() throws MojoFailureException {
    LoadContext loadContext = new LoadContext();
    // List<ProjectElementException> errors = new ArrayList<>();
    try {
        // final Project model = be5Project;
        // List<Project> moduleProjects = ModuleLoader2.loadModules(model, logger, loadContext);
        // errors.addAll( validateDeps(moduleProjects) );
        // ModuleLoader2.mergeAllModules( model, moduleProjects, loadContext );
        ModuleLoader2.mergeModules(be5Project, logger);
    } catch (ProjectLoadException e) {
        throw new MojoFailureException("Can not load project modules", e);
    }
    checkErrors(loadContext, "Modules have %d error(s)");
}
Also used : ProjectLoadException(com.developmentontheedge.be5.metadata.exception.ProjectLoadException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) LoadContext(com.developmentontheedge.be5.metadata.serialization.LoadContext)

Example 9 with ProjectLoadException

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

the class ModuleLoader2 method loadAllProjects.

public static void loadAllProjects(List<URL> urls) {
    modulesMap = new HashMap<>();
    try {
        replaceAndAddURLtoSource(urls);
        for (URL url : urls) {
            LoadContext loadContext = new LoadContext();
            Project module;
            String ext = url.toExternalForm();
            if (// usual file in directory
            ext.indexOf('!') < 0) {
                Path path = Paths.get(url.toURI()).getParent();
                module = Serialization.load(path, loadContext);
                log.fine("Load module from dir: " + path);
            } else // war or jar file
            {
                String jar = ext.substring(0, ext.indexOf('!'));
                // = FileSystems.getFileSystem(URI.create(jar));
                FileSystem fs;
                try {
                    fs = FileSystems.newFileSystem(URI.create(jar), Collections.emptyMap());
                } catch (FileSystemAlreadyExistsException e) {
                    fs = FileSystems.getFileSystem(URI.create(jar));
                    log.info("Get exists FileSystem after exception");
                }
                Path path = fs.getPath("./");
                module = Serialization.load(path, loadContext);
                log.fine("Load module from " + url.toExternalForm() + ", path=" + path);
            }
            loadContext.check();
            modulesMap.put(module.getAppName(), module);
        }
    } catch (ProjectLoadException | IOException | URISyntaxException e) {
        e.printStackTrace();
    }
}
Also used : Path(java.nio.file.Path) Project(com.developmentontheedge.be5.metadata.model.Project) ProjectLoadException(com.developmentontheedge.be5.metadata.exception.ProjectLoadException) FileSystem(java.nio.file.FileSystem) FileSystemAlreadyExistsException(java.nio.file.FileSystemAlreadyExistsException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) URL(java.net.URL)

Example 10 with ProjectLoadException

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

the class ModuleLoader2 method mergeAllModules.

public static void mergeAllModules(final Project model, List<Project> modules, final LoadContext context) throws ProjectLoadException {
    modules = new LinkedList<>(modules);
    for (Project module : modules) {
        module.mergeHostProject(model);
    }
    final Project compositeModule = foldModules(model, modules, context);
    if (compositeModule != null) {
        model.merge(compositeModule);
    }
}
Also used : Project(com.developmentontheedge.be5.metadata.model.Project)

Aggregations

Project (com.developmentontheedge.be5.metadata.model.Project)8 ProjectLoadException (com.developmentontheedge.be5.metadata.exception.ProjectLoadException)6 MojoFailureException (org.apache.maven.plugin.MojoFailureException)4 ColumnDef (com.developmentontheedge.be5.metadata.model.ColumnDef)2 Entity (com.developmentontheedge.be5.metadata.model.Entity)2 Module (com.developmentontheedge.be5.metadata.model.Module)2 TableDef (com.developmentontheedge.be5.metadata.model.TableDef)2 LoadContext (com.developmentontheedge.be5.metadata.serialization.LoadContext)2 IOException (java.io.IOException)2 Path (java.nio.file.Path)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Test (org.junit.Test)2 FreemarkerSqlException (com.developmentontheedge.be5.metadata.exception.FreemarkerSqlException)1 ProcessInterruptedException (com.developmentontheedge.be5.metadata.exception.ProcessInterruptedException)1 ReadException (com.developmentontheedge.be5.metadata.exception.ReadException)1 BeConnectionProfile (com.developmentontheedge.be5.metadata.model.BeConnectionProfile)1 DataElementUtils (com.developmentontheedge.be5.metadata.model.DataElementUtils)1 DdlElement (com.developmentontheedge.be5.metadata.model.DdlElement)1 EntityType (com.developmentontheedge.be5.metadata.model.EntityType)1