package hu.u_szeged.nbo.server.plugins;
import hu.u_szeged.nbo.server.NBOServer;
import hu.u_szeged.nbo.server.User;
import java.io.File;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.logging.FileHandler;
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;
public class NBOPlugin extends Thread {
public static final int LP = 0;
public static final int MILP = -1;
public static final int GEOM = -2;
public static final int RES_ALLOC = -3;
protected HashMap<String, String> inputFiles;
protected String task;
protected User user;
protected Integer uniqueHash;
protected String pathOfTask;
protected String problemName;
protected Logger pluginLogger;
protected FileHandler fileHandler;
public NBOPlugin(User user, String problemName, HashMap<String, String> inputFiles, String subDirectoryName) {
this.user = user;
this.inputFiles = inputFiles;
this.problemName = (problemName.endsWith(".mps") ?
problemName.substring(0, problemName.length() - 4) : problemName);
this.uniqueHash = Integer.parseInt(inputFiles.get("properties.txt").split("hashcode: ")[1].split("\n")[0]);
this.pathOfTask = user.getHomeDirectory() + "/" + subDirectoryName + "/" + this.problemName + "_" + uniqueHash.toString();
this.pluginLogger = Logger.getLogger(this.getClass().getName());
String pluginLog = this.pathOfTask + "/" + this.problemName + ".log";
try {
(new File(this.pathOfTask)).mkdirs();
fileHandler = new FileHandler(pluginLog);
fileHandler.setFormatter(new SimpleFormatter());
pluginLogger.addHandler(fileHandler);
String temp = "";
for (String key : this.inputFiles.keySet()) {
temp = this.pathOfTask + "/" + key;
PrintWriter out = new PrintWriter(new FileWriter(temp));
out.print(inputFiles.get(key));
out.close();
}
if (inputFiles.size() == 1) this.task = temp;
else this.task = pathOfTask;
}
catch (Exception e) {
NBOServer.log("Error during file creation:\n" + e, 2);
}
}
}