Search in sources :

Example 1 with DatabaseAccess

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());
}
Also used : RuntimeDataAccess(com.centurylink.mdw.dataaccess.RuntimeDataAccess) DatabaseAccess(com.centurylink.mdw.dataaccess.DatabaseAccess) SQLException(java.sql.SQLException) DocumentReference(com.centurylink.mdw.model.value.variable.DocumentReference) DataAccessException(com.centurylink.mdw.common.exception.DataAccessException)

Example 2 with DatabaseAccess

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;
}
Also used : DatabaseAccess(com.centurylink.mdw.dataaccess.DatabaseAccess) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) TreeMap(java.util.TreeMap) DataAccessException(com.centurylink.mdw.common.exception.DataAccessException)

Aggregations

DataAccessException (com.centurylink.mdw.common.exception.DataAccessException)2 DatabaseAccess (com.centurylink.mdw.dataaccess.DatabaseAccess)2 SQLException (java.sql.SQLException)2 RuntimeDataAccess (com.centurylink.mdw.dataaccess.RuntimeDataAccess)1 DocumentReference (com.centurylink.mdw.model.value.variable.DocumentReference)1 ResultSet (java.sql.ResultSet)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 TreeMap (java.util.TreeMap)1