Search in sources :

Example 21 with LoadContext

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();
    }
}
Also used : YamlDeserializer(com.developmentontheedge.be5.metadata.serialization.yaml.YamlDeserializer)

Example 22 with LoadContext

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();
    }
}
Also used : ReadException(com.developmentontheedge.be5.metadata.exception.ReadException) ProjectLoadException(com.developmentontheedge.be5.metadata.exception.ProjectLoadException) YamlDeserializer(com.developmentontheedge.be5.metadata.serialization.yaml.YamlDeserializer)

Example 23 with LoadContext

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();
    }
}
Also used : YamlDeserializer(com.developmentontheedge.be5.metadata.serialization.yaml.YamlDeserializer)

Example 24 with LoadContext

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;
}
Also used : BeConnectionProfile(com.developmentontheedge.be5.metadata.model.BeConnectionProfile) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) Yaml(org.yaml.snakeyaml.Yaml) LinkedHashMap(java.util.LinkedHashMap)

Example 25 with LoadContext

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

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