Search in sources :

Example 1 with BeConnectionProfile

use of com.developmentontheedge.be5.metadata.model.BeConnectionProfile in project be5 by DevelopmentOnTheEdge.

the class YamlDeserializer method readConnectionProfile.

/**
 * Parses a connection profile. Doesn't save it to connection profiles collection.
 *
 * @param serializedProfileBody just a map of properties
 * @throws ReadException
 */
private static BeConnectionProfile readConnectionProfile(final LoadContext loadContext, final String profileName, final Map<String, Object> serializedProfileBody, final Project project) throws ReadException {
    final YamlDeserializer yamlDeserializer = new YamlDeserializer(loadContext);
    final ConnectionProfilesDeserializer connectionProfilesDeserializer = yamlDeserializer.new ConnectionProfilesDeserializer(project.getConnectionProfiles().getLocalProfiles());
    final BeConnectionProfile connectionProfile = connectionProfilesDeserializer.deserializeConnectionProfile(profileName, serializedProfileBody);
    return connectionProfile;
}
Also used : BeConnectionProfile(com.developmentontheedge.be5.metadata.model.BeConnectionProfile)

Example 2 with BeConnectionProfile

use of com.developmentontheedge.be5.metadata.model.BeConnectionProfile 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 3 with BeConnectionProfile

use of com.developmentontheedge.be5.metadata.model.BeConnectionProfile in project be5 by DevelopmentOnTheEdge.

the class Be5Mojo method init.

// /////////////////////////////////////////////////////////////////
public void init() throws MojoFailureException {
    long startTime = System.nanoTime();
    initLogging();
    if (be5Project == null) {
        if (projectPath == null)
            throw new MojoFailureException("Please specify projectPath attribute");
        getLog().info("Reading be5 project from '" + projectPath + "'...");
        be5Project = loadProject(projectPath.toPath());
        if (debug) {
            be5Project.setDebugStream(System.err);
        }
        try {
            ModuleLoader2.mergeModules(be5Project, logger);
        } catch (ProjectLoadException e) {
            e.printStackTrace();
            throw new MojoFailureException(e.getMessage());
        }
    }
    if (connectionProfileName != null) {
        be5Project.setConnectionProfileName(connectionProfileName);
    }
    BeConnectionProfile profile = be5Project.getConnectionProfile();
    if (profile != null) {
        this.be5Project.setDatabaseSystem(Rdbms.getRdbms(profile.getConnectionUrl()));
        this.connector = new SimpleConnector(Rdbms.getRdbms(profile.getConnectionUrl()).getType(), profile.getConnectionUrl(), profile.getUsername(), connectionPassword != null ? connectionPassword : profile.getPassword());
        getLog().info("Using connection " + DatabaseUtils.formatUrl(profile.getConnectionUrl(), profile.getUsername(), "xxxxx"));
    } else {
        throw new MojoFailureException("Please specify connection profile: create " + be5Project.getProjectFileStructure().getSelectedProfileFile() + " file with profile name or use -DBE5_PROFILE=...");
    }
    getLog().info(ModuleLoader2.logLoadedProject(be5Project, startTime));
}
Also used : ProjectLoadException(com.developmentontheedge.be5.metadata.exception.ProjectLoadException) BeConnectionProfile(com.developmentontheedge.be5.metadata.model.BeConnectionProfile) SimpleConnector(com.developmentontheedge.dbms.SimpleConnector) MojoFailureException(org.apache.maven.plugin.MojoFailureException)

Example 4 with BeConnectionProfile

use of com.developmentontheedge.be5.metadata.model.BeConnectionProfile in project be5 by DevelopmentOnTheEdge.

the class Project method getContext.

/**
 * Creates and returns FreeMarker context for given element
 * @param element to create context for (can be null)
 * @return
 */
public Map<String, Object> getContext(TemplateElement element) {
    Map<String, Object> context = new HashMap<>();
    BeModelElement parent = element;
    while (parent != null) {
        if (parent instanceof PageCustomization) {
            context.put("customization", parent);
        } else if (parent instanceof Query) {
            context.put("query", parent);
        } else if (parent instanceof Operation) {
            context.put("operation", parent);
        } else if (parent instanceof Entity) {
            context.put("entity", parent);
        } else if (parent instanceof Module) {
            context.put("module", parent);
        }
        parent = parent.getOrigin();
    }
    for (String name : getPropertyNames()) {
        context.put(name, getProperty(name));
    }
    BeConnectionProfile profile = getConnectionProfile();
    if (profile != null) {
        for (String name : profile.getPropertyNames()) {
            context.put(name, profile.getProperty(name));
        }
    }
    return context;
}
Also used : BeModelElement(com.developmentontheedge.be5.metadata.model.base.BeModelElement) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 5 with BeConnectionProfile

use of com.developmentontheedge.be5.metadata.model.BeConnectionProfile 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)

Aggregations

BeConnectionProfile (com.developmentontheedge.be5.metadata.model.BeConnectionProfile)5 LinkedHashMap (java.util.LinkedHashMap)3 MojoFailureException (org.apache.maven.plugin.MojoFailureException)2 Yaml (org.yaml.snakeyaml.Yaml)2 ProjectLoadException (com.developmentontheedge.be5.metadata.exception.ProjectLoadException)1 FreemarkerScript (com.developmentontheedge.be5.metadata.model.FreemarkerScript)1 ParseResult (com.developmentontheedge.be5.metadata.model.ParseResult)1 Project (com.developmentontheedge.be5.metadata.model.Project)1 BeModelElement (com.developmentontheedge.be5.metadata.model.base.BeModelElement)1 LoadContext (com.developmentontheedge.be5.metadata.serialization.LoadContext)1 BeSqlExecutor (com.developmentontheedge.be5.metadata.sql.BeSqlExecutor)1 NullLogger (com.developmentontheedge.be5.metadata.util.NullLogger)1 ProcessController (com.developmentontheedge.be5.metadata.util.ProcessController)1 ExtendedSqlException (com.developmentontheedge.dbms.ExtendedSqlException)1 SimpleConnector (com.developmentontheedge.dbms.SimpleConnector)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Test (org.junit.Test)1