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());
}
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();
}
}
}
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)");
}
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();
}
}
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);
}
}
Aggregations