001package edu.pdx.cs410J.grader;
002
003import ch.qos.logback.classic.Level;
004import ch.qos.logback.classic.Logger;
005import com.google.common.annotations.VisibleForTesting;
006import edu.pdx.cs410J.grader.canvas.GradesFromCanvasImporter;
007import edu.pdx.cs410J.grader.gradebook.ui.GradeBookGUI;
008import edu.pdx.cs410J.grader.poa.ui.PlanOfAttackGrader;
009import org.slf4j.LoggerFactory;
010
011import java.io.PrintStream;
012import java.lang.reflect.InvocationTargetException;
013import java.lang.reflect.Method;
014import java.util.ArrayList;
015import java.util.List;
016
017public class GraderTools {
018
019  public static void main(String[] args) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
020    String tool = null;
021    List<String> toolArgs = new ArrayList<>();
022    for (String arg : args) {
023      if (arg.equals("-debug")) {
024        setLoggingLevelToDebug();
025
026      } else if (tool == null) {
027        tool = arg;
028
029      } else {
030        toolArgs.add(arg);
031      }
032    }
033
034    if (tool == null) {
035      usage("Missing tool");
036    }
037
038
039    invokeMainMethod(getToolClass(tool), toolArgs.toArray(new String[toolArgs.size()]));
040  }
041
042  @VisibleForTesting
043  static void setLoggingLevelToDebug() {
044    Logger logger = (Logger) LoggerFactory.getLogger("edu.pdx.cs410J.grader");
045    logger.setLevel(Level.DEBUG);
046  }
047
048  private static Class getToolClass(String tool) {
049    switch (tool) {
050      case "gradebook":
051        return GradeBookGUI.class;
052
053      case "fetch":
054        return FetchAndProcessGraderEmail.class;
055
056      case "importFromCanvas" :
057        return GradesFromCanvasImporter.class;
058
059      case "importFromProjectReports" :
060        return ProjectGradesImporter.class;
061
062      case "mailFileToStudent" :
063        return StudentFileMailer.class;
064
065      case "gradePOAs":
066        return PlanOfAttackGrader.class;
067
068      case "generateGradeSummary":
069        return SummaryReport.class;
070
071      case "htmlForSurveyResults":
072        return SurveyResponsesFromD2LGenerator.class;
073
074      case "fixAndroidZips":
075        return AndroidZipFixer.class;
076
077      case "projectTimeEstimates":
078        return ProjectTimeEstimatesSummary.class;
079
080      default:
081        usage("Unknown tool: " + tool);
082        return null;
083    }
084  }
085
086  @SuppressWarnings("unchecked")
087  private static void invokeMainMethod(Class aClass, String[] args) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
088    Method main = aClass.getMethod("main", args.getClass());
089    main.invoke(aClass, new Object[] { args });
090
091  }
092
093  private static void usage(String message) {
094    PrintStream err = System.err;
095    err.println("** " + message);
096    err.println();
097    err.println("Executes one of the Grader tools");
098    err.println();
099    err.println("usage: GraderTools tool toolArg*");
100    err.println("  tool                        The tool to execute");
101    err.println("    gradebook                 The Grade Book GUI");
102    err.println("    fetch                     Fetch student surveys or projects from the Grader's");
103    err.println("                              emails account");
104    err.println("    importFromCanvas          Import grades from a Canvas CSV");
105    err.println("    importFromProjectReports  Import grades from graded project reports");
106    err.println("    mailFileToStudent         Email text files to students");
107    err.println("    gradePOAs                 Tool for downloading and grading POAs");
108    err.println("    generateGradeSummary      Generate grade summary report for one or more students");
109    err.println("    htmlForSurveyResults      Generate an html file for the responses to a D2L survey");
110    err.println("    fixAndroidZips            Fix zip files for the Android project to work with grading script");
111    err.println("    projectTimeEstimates      Generate markdown that summarizes the estimated project hours");
112    err.println("  toolArg                     A command line argument to send to the tool");
113    err.println();
114
115    System.exit(1);
116  }
117}