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