use of com.centurylink.mdw.dataaccess.DatabaseAccess in project mdw-designer by CenturyLinkCloud.
the class DesignerDataAccess method updateVariableInstanceInDb.
public void updateVariableInstanceInDb(VariableInstanceInfo varInstInfo, String newValue, boolean isDocument) throws DataAccessException {
// needs a separate db connection for some reason?
DatabaseAccess db = new DatabaseAccess(currentServer.getDatabaseUrl());
try {
RuntimeDataAccess runtimeDao = DataAccess.getRuntimeDataAccess(dbSchemaVersion, dbSupportedSchemaVersion, db, getVariableTypes());
db.openConnection();
if (isDocument) {
DocumentReference docRef = (DocumentReference) varInstInfo.getData();
runtimeDao.updateDocumentContent(docRef.getDocumentId(), newValue);
} else {
varInstInfo.setStringValue(newValue);
runtimeDao.updateVariableInstance(varInstInfo);
}
} catch (SQLException ex) {
throw new DataAccessException(-1, ex.getMessage(), ex);
} finally {
db.closeConnection();
}
auditLog(Action.Change, Entity.VariableInstance, varInstInfo.getInstanceId(), varInstInfo.getName());
}
use of com.centurylink.mdw.dataaccess.DatabaseAccess in project mdw-designer by CenturyLinkCloud.
the class PluginDataAccess method getTaskVariableMappings.
// TODO attribute overflow
public Map<String, List<String>> getTaskVariableMappings() throws DataAccessException {
Map<String, List<String>> ownerVars = new TreeMap<>(PluginUtil.getStringComparator());
DatabaseAccess db = new DatabaseAccess(workflowProject.getMdwDataSource().getJdbcUrlWithCredentials());
try {
db.openConnection();
if (workflowProject.checkRequiredVersion(5, 2)) {
String query = "select t.task_name, a.attribute_value \n " + "from task t, attribute a \n" + "where a.attribute_owner = 'TASK' \n" + "and t.task_id = a.attribute_owner_id \n" + "and a.attribute_name = 'Variables' \n" + "order by a.attribute_id desc";
ResultSet rs = db.runSelect(query, null);
while (rs.next()) {
String taskName = rs.getString("task_name");
if (!ownerVars.containsKey(taskName)) {
List<String> vars = new ArrayList<>();
String varString = rs.getString("attribute_value");
if (varString != null && varString.trim().length() > 0) {
for (String var : varString.split(";")) {
int first = var.indexOf(',');
int second = var.indexOf(',', first + 1);
int third = var.indexOf(',', second + 1);
if (!var.substring(second + 1, third).equals(TaskActivity.VARIABLE_DISPLAY_NOTDISPLAYED))
vars.add(first > 0 ? var.substring(0, first) : var);
}
}
Collections.sort(vars, PluginUtil.getStringComparator());
ownerVars.put(taskName, vars);
}
}
} else {
String query = "select t.task_name, v.variable_name \n " + "from task t, variable v, variable_mapping vm \n " + "where vm.mapping_owner = 'TASK' \n " + "and vm.mapping_owner_id = t.task_id \n " + "and v.variable_id = vm.variable_id \n " + "order by t.task_name, v.variable_name";
ResultSet rs = db.runSelect(query, null);
while (rs.next()) {
String taskName = rs.getString("task_name");
List<String> vars = ownerVars.get(taskName);
if (vars == null) {
vars = new ArrayList<>();
ownerVars.put(taskName, vars);
}
String var = rs.getString("variable_name");
if (!vars.contains(var))
vars.add(var);
}
}
} catch (SQLException ex) {
throw new DataAccessException(-1, ex.getMessage(), ex);
} finally {
db.closeConnection();
}
return ownerVars;
}
Aggregations