Search in sources :

Example 1 with ExportIOException

use of edu.cmu.cs.hcii.cogtool.ui.DesignExportToHTML.ExportIOException in project cogtool by cogtool.

the class HCIPACmd method exportToHCIPA.

public static boolean exportToHCIPA(Project project, Design design, TaskGroup group, File scriptFile) {
    final String safeDblQuote = quotePHP("\"");
    //        final String safeDblQuote = "\"";   // no escaping needed for SQL
    StringBuilder php = new StringBuilder();
    php.append("<?php\n");
    php.append("// Generated by CogTool version: " + CogTool.getVersion() + "\n");
    php.append("$COGTOOL_EXPORT_VERSION = " + HCIPA_EXPORT_VERSION + ";\n");
    php.append("function insertIntoDatabase_" + HCIPA_EXPORT_VERSION + "($userId) {\n\t");
    String functionName = (String) group.getAttribute(WidgetAttributes.HCIPA_FUNCTION_ATTR);
    functionName = quotePHP(quoteSQL(functionName));
    String access = "Access " + safeDblQuote + functionName + safeDblQuote + " function";
    String enter = "Enter data for " + safeDblQuote + functionName + safeDblQuote + " Function";
    String confirm = "Confirm & Save data using " + safeDblQuote + functionName + safeDblQuote + " function";
    String monitor = "Monitor results of " + safeDblQuote + functionName + safeDblQuote + " function";
    php.append("$userId = mysql_real_escape_string($userId);\n\t");
    // fill out hcipa table
    php.append("$deviceId = Create_Task($userId, \"" + quotePHP(quoteSQL(design.getName())) + "\",\n\t");
    php.append('"' + RECOGNIZE_NEED + quotePHP(quoteSQL(group.getName())) + "\",\n\t");
    php.append('"' + DECIDE_TO_USE + functionName + "\",\n\t");
    php.append('"' + access + "\",\n\t\"" + enter + "\",\n\t");
    php.append('"' + confirm + "\",\n\t\"" + monitor + "\");\n\n");
    //        php.append("$sqlStmt =\n<<<SQL__INSERT__STRING\n\t");
    //        php.append(SQL_INSERT + "HCIPA (\n\tUser_Id,\n\tDescription,\n\tIdentify_Task,\n\t");
    //        php.append("Select_Function,\n\tAccess,\n\tEnter,\n\tConfirm_Save,\n\tMonitor)\n\t"
    //                   + SQL_VALUES + " ('$userId',\n\t'");
    //        php.append(quoteSQL(design.getName()) + "',\n\t");
    //        php.append("'" + RECOGNIZE_NEED + quoteSQL(group.getName()) + "',\n\t");
    //        php.append("'" + DECIDE_TO_USE + functionName + "',\n\t");
    //        php.append("'" + access + "',\n\t'" + enter + "',\n\t");
    //        php.append("'" + confirm + "',\n\t'" + monitor + "')\n");
    //        php.append("SQL__INSERT__STRING\n;\n\n\t");
    //        php.append("mysql_query($sqlStmt);\n\n\t");
    //        php.append("$deviceId = mysql_insert_id();\n");
    // fill out hcipa_actions table
    Iterator<AUndertaking> subtasks = group.getUndertakings().iterator();
    while (subtasks.hasNext()) {
        AUndertaking subtask = subtasks.next();
        TaskApplication ta = project.getTaskApplication(subtask, design);
        if (ta != null) {
            Demonstration demo = ta.getDemonstration();
            Iterator<AScriptStep> steps = demo.getSteps().iterator();
            while (steps.hasNext()) {
                AScriptStep step = steps.next();
                buildActionStepInsert(subtask, step, demo, php);
            }
        }
    }
    try {
        // write script to destFile
        FileWriter fileOut = null;
        BufferedWriter writer = null;
        try {
            fileOut = new FileWriter(scriptFile);
            writer = new BufferedWriter(fileOut);
            php.append("\treturn $deviceId;\n");
            php.append("} // insertIntoDatabase_" + HCIPA_EXPORT_VERSION + "\n?>\n");
            writer.write(php.toString());
        } finally {
            if (writer != null) {
                writer.close();
            } else if (fileOut != null) {
                fileOut.close();
            }
        }
    } catch (IOException ex) {
        // so we don't have to import DesignExportToHTML!
        throw new ExportIOException("Could not write PHP script ", ex);
    }
    return true;
}
Also used : AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) FileWriter(java.io.FileWriter) ExportIOException(edu.cmu.cs.hcii.cogtool.ui.DesignExportToHTML.ExportIOException) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) ExportIOException(edu.cmu.cs.hcii.cogtool.ui.DesignExportToHTML.ExportIOException) IOException(java.io.IOException) Demonstration(edu.cmu.cs.hcii.cogtool.model.Demonstration) AScriptStep(edu.cmu.cs.hcii.cogtool.model.AScriptStep) BufferedWriter(java.io.BufferedWriter)

Aggregations

AScriptStep (edu.cmu.cs.hcii.cogtool.model.AScriptStep)1 AUndertaking (edu.cmu.cs.hcii.cogtool.model.AUndertaking)1 Demonstration (edu.cmu.cs.hcii.cogtool.model.Demonstration)1 TaskApplication (edu.cmu.cs.hcii.cogtool.model.TaskApplication)1 ExportIOException (edu.cmu.cs.hcii.cogtool.ui.DesignExportToHTML.ExportIOException)1 BufferedWriter (java.io.BufferedWriter)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1