use of com.developmentontheedge.be5.metadata.serialization.LoadContext in project be5 by DevelopmentOnTheEdge.
the class Serialization method reloadDaemons.
public static Daemons reloadDaemons(final Path file, final Module target) throws ReadException {
checkProject(target.getProject());
turnOffAutomaticSerialization();
try {
return new YamlDeserializer(new LoadContext()).reloadDaemons(file, target);
} finally {
turnOnAutomaticSerialization();
}
}
use of com.developmentontheedge.be5.metadata.serialization.LoadContext in project be5 by DevelopmentOnTheEdge.
the class Serialization method load.
/**
* @param root
* @param fuseTemplates whether to fuse templates into entities (useful for modules loading)
* @param loadContext
* @return
* @throws ProjectLoadException
* @see Serialization#canBeLoaded(Path)
*/
public static Project load(final Path root, final boolean fuseTemplates, final LoadContext loadContext) throws ProjectLoadException {
Objects.requireNonNull(root);
turnOffAutomaticSerialization();
try {
return new YamlDeserializer(loadContext == null ? new LoadContext() : loadContext, fuseTemplates).readProject(root);
} catch (final ReadException e) {
throw new ProjectLoadException(root, e);
} finally {
turnOnAutomaticSerialization();
}
}
use of com.developmentontheedge.be5.metadata.serialization.LoadContext in project be5 by DevelopmentOnTheEdge.
the class Serialization method reloadCustomizations.
public static PageCustomizations reloadCustomizations(final Path file, final Module target) throws ReadException {
checkProject(target.getProject());
turnOffAutomaticSerialization();
try {
return new YamlDeserializer(new LoadContext()).reloadCustomizations(file, target);
} finally {
turnOnAutomaticSerialization();
}
}
use of com.developmentontheedge.be5.metadata.serialization.LoadContext in project be5 by DevelopmentOnTheEdge.
the class YamlDeserializer method deserializeConnectionProfile.
/**
* Parses a connection profile. Doesn't save it to connection profiles
* collection.
*
* @param serialized
* Must contain a serialized JSON with a map as a root element.
* This map should have only one key, that represents a
* connection profile name. The value should contain pairs of connection profile fields.
* @throws ReadException
* @throws ClassCastException
* @see Fields#connectionProfile()
* @see Fields#connectionProfileRead()
*/
public static BeConnectionProfile deserializeConnectionProfile(final LoadContext loadContext, final String serialized, final Project project) throws ReadException {
// unsafe
@SuppressWarnings("unchecked") final LinkedHashMap<String, Object> namedProfile = (LinkedHashMap<String, Object>) new Yaml().load(serialized);
final String profileName = namedProfile.keySet().iterator().next();
// unsafe
@SuppressWarnings("unchecked") final Map<String, Object> serializedProfileBody = (Map<String, Object>) namedProfile.get(profileName);
final BeConnectionProfile profile = readConnectionProfile(loadContext, profileName, serializedProfileBody, project);
return profile;
}
use of com.developmentontheedge.be5.metadata.serialization.LoadContext 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());
}
Aggregations