Commit bd95b862 authored by Jonathan Shahen's avatar Jonathan Shahen

Implemented ONLY option which allows for running only 1 reduction on a MohawkT...

Implemented ONLY option which allows for running only 1 reduction on a MohawkT file (currently implemented Remove CanEnable v1 and Remove CanEnable v2)
parent 52f657de
package mohawk.converter;
import java.io.*;
import java.util.ArrayList;
import java.util.logging.*;
import org.apache.commons.cli.*;
......@@ -15,7 +16,9 @@ import mohawk.converter.to.asaptime.ConvertToASAPTimeSA;
import mohawk.converter.to.mohawk.ConvertToMohawk;
import mohawk.converter.to.tred.ConvertToTRole;
import mohawk.global.FileExtensions;
import mohawk.global.helper.RoleHelper;
import mohawk.global.pieces.MohawkT;
import mohawk.global.pieces.Rule;
import mohawk.global.timing.MohawkTiming;
public class ConverterInstance {
......@@ -101,98 +104,132 @@ public class ConverterInstance {
logger.info("No errors found while parsing file, continuing on to converting");
}
if (cmd.hasOption(OptionString.TO_ASAPTIME_NSA.toString())
|| cmd.hasOption(OptionString.TO_ALL.toString())) {
logger.info("[CONVERTING] Converting to ASAPTime NSA... " + specFile.getName());
/* Timing */timing.startTimer("convertToASAPTimeNSA (" + i + ")");
// TODO: implement ONLY reductions up here
if (cmd.hasOption(OptionString.ONLYREDUCTION.toString())) {
String onlyOpt = cmd.getOptionValue(OptionString.ONLYREDUCTION.toString());
ConvertToASAPTimeNSA toASAPTimeNSA = new ConvertToASAPTimeNSA(timing);
toASAPTimeNSA.convert(m, specFile, true);
ArrayList<Rule> workableRules = null;
RoleHelper roleHelper = new RoleHelper(m.roleHelper);
MohawkT m2 = new MohawkT();
if (onlyOpt.equals("enable1")) {
workableRules = roleHelper.removeEnableDisableRules(m.getAllRules());
if (toASAPTimeNSA.lastError == null) {
logger.info("[SUCCESS] Successfully converted to ASAPTimeNSA's Input Format");
} else {
logger.warning("[FAILURE] Failed to convert to ASAPTimeNSA's Input Format; Error code "
+ toASAPTimeNSA.lastError);
}
m2.generatorName = "Remove CanEnable v1";
} else if (onlyOpt.equals("enable2")) {
workableRules = roleHelper.removeEnableDisableRulesv2(m.getAllRules());
/* Timing */timing.stopTimer("convertToASAPTimeNSA (" + i + ")");
logger.info("[CONVERTING] ...Done Converting to ASAPTime NSA");
}
m2.generatorName = "Remove CanEnable v2";
}
if (cmd.hasOption(OptionString.TO_ASAPTIME_SA.toString())
|| cmd.hasOption(OptionString.TO_ALL.toString())) {
logger.info("[CONVERTING] Converting to ASAPTime SA... " + specFile.getName());
/* Timing */timing.startTimer("convertToASAPTimeSA (" + i + ")");
if (workableRules != null) {
m2.query = m.query;
m2.roleHelper = m.roleHelper;
m2.timeIntervalHelper = m.timeIntervalHelper;
m2.expectedResult = m.expectedResult;
ConvertToASAPTimeSA toASAPTimeSA = new ConvertToASAPTimeSA(timing);
toASAPTimeSA.convert(m, specFile, true);
m2.addRules(workableRules);
if (toASAPTimeSA.lastError == null) {
logger.info("[SUCCESS] Successfully converted to ASAPTimeSA's Input Format");
} else {
logger.warning("[FAILURE] Failed to convert to ASAPTimeSA's Input Format; Error code "
+ toASAPTimeSA.lastError);
FileWriter fw = new FileWriter(specFile.getAbsolutePath() + "_ONLY_" + onlyOpt);
fw.write(m2.getString("\n\n", true, true));
fw.close();
}
} else {
if (cmd.hasOption(OptionString.TO_ASAPTIME_NSA.toString())
|| cmd.hasOption(OptionString.TO_ALL.toString())) {
logger.info("[CONVERTING] Converting to ASAPTime NSA... " + specFile.getName());
/* Timing */timing.startTimer("convertToASAPTimeNSA (" + i + ")");
ConvertToASAPTimeNSA toASAPTimeNSA = new ConvertToASAPTimeNSA(timing);
toASAPTimeNSA.convert(m, specFile, true);
if (toASAPTimeNSA.lastError == null) {
logger.info("[SUCCESS] Successfully converted to ASAPTimeNSA's Input Format");
} else {
logger.warning("[FAILURE] Failed to convert to ASAPTimeNSA's Input Format; Error code "
+ toASAPTimeNSA.lastError);
}
/* Timing */timing.stopTimer("convertToASAPTimeNSA (" + i + ")");
logger.info("[CONVERTING] ...Done Converting to ASAPTime NSA");
}
/* Timing */timing.stopTimer("convertToASAPTimeSA (" + i + ")");
logger.info("[CONVERTING] ...Done Converting to ASAPTime SA");
}
if (cmd.hasOption(OptionString.TO_ASAPTIME_SA.toString())
|| cmd.hasOption(OptionString.TO_ALL.toString())) {
logger.info("[CONVERTING] Converting to ASAPTime SA... " + specFile.getName());
/* Timing */timing.startTimer("convertToASAPTimeSA (" + i + ")");
if (cmd.hasOption(OptionString.TO_TROLE.toString()) || cmd.hasOption(OptionString.TO_ALL.toString())) {
logger.info("[CONVERTING] Converting to TRole... " + specFile.getName());
/* Timing */timing.startTimer("convertToTRole (" + i + ")");
ConvertToASAPTimeSA toASAPTimeSA = new ConvertToASAPTimeSA(timing);
toASAPTimeSA.convert(m, specFile, true);
ConvertToTRole toTRole = new ConvertToTRole(timing);
toTRole.convert(m, specFile, true);
if (toASAPTimeSA.lastError == null) {
logger.info("[SUCCESS] Successfully converted to ASAPTimeSA's Input Format");
} else {
logger.warning("[FAILURE] Failed to convert to ASAPTimeSA's Input Format; Error code "
+ toASAPTimeSA.lastError);
}
if (toTRole.lastError == null) {
logger.info("[SUCCESS] Successfully converted to TRole Input Format");
} else {
logger.warning(
"[FAILURE] Failed to convert to TRole Input Format; Error code " + toTRole.lastError);
/* Timing */timing.stopTimer("convertToASAPTimeSA (" + i + ")");
logger.info("[CONVERTING] ...Done Converting to ASAPTime SA");
}
/* Timing */timing.stopTimer("convertToTRole (" + i + ")");
logger.info("[CONVERTING] ...Done Converting to TRole");
}
if (cmd.hasOption(OptionString.TO_TROLE.toString())
|| cmd.hasOption(OptionString.TO_ALL.toString())) {
logger.info("[CONVERTING] Converting to TRole... " + specFile.getName());
/* Timing */timing.startTimer("convertToTRole (" + i + ")");
if (cmd.hasOption(OptionString.TO_MOHAWK.toString()) || cmd.hasOption(OptionString.TO_ALL.toString())) {
logger.info("[CONVERTING] Converting to Mohawk... " + specFile.getName());
/* Timing */timing.startTimer("convertToMohawk (" + i + ")");
ConvertToTRole toTRole = new ConvertToTRole(timing);
toTRole.convert(m, specFile, true);
ConvertToMohawk toMohawk = new ConvertToMohawk(timing);
if (toTRole.lastError == null) {
logger.info("[SUCCESS] Successfully converted to TRole Input Format");
} else {
logger.warning(
"[FAILURE] Failed to convert to TRole Input Format; Error code "
+ toTRole.lastError);
}
if (cmd.hasOption(OptionString.SHORT_ROLENAMES.toString())) {
logger.fine("[OPTION] Short Rolenames: Enabled");
toMohawk.shortRolenames = true;
} else {
logger.fine("[OPTION] Short Rolenames: Disabled");
/* Timing */timing.stopTimer("convertToTRole (" + i + ")");
logger.info("[CONVERTING] ...Done Converting to TRole");
}
toMohawk.convert(m, specFile, true);
if (cmd.hasOption(OptionString.TO_MOHAWK.toString())
|| cmd.hasOption(OptionString.TO_ALL.toString())) {
logger.info("[CONVERTING] Converting to Mohawk... " + specFile.getName());
/* Timing */timing.startTimer("convertToMohawk (" + i + ")");
if (toMohawk.lastError == null) {
logger.info("[SUCCESS] Successfully converted to Mohawk's Input Format");
} else {
logger.warning("[FAILURE] Failed to convert to Mohawk's Input Format; Error code "
+ toMohawk.lastError);
}
ConvertToMohawk toMohawk = new ConvertToMohawk(timing);
/* Timing */timing.stopTimer("convertToMohawk (" + i + ")");
logger.info("[CONVERTING] ...Done Converting to Mohawk");
}
if (cmd.hasOption(OptionString.SHORT_ROLENAMES.toString())) {
logger.fine("[OPTION] Short Rolenames: Enabled");
toMohawk.shortRolenames = true;
} else {
logger.fine("[OPTION] Short Rolenames: Disabled");
}
toMohawk.convert(m, specFile, true);
if (cmd.hasOption(OptionString.TO_MOHAWK_T.toString())) {
logger.info("[CONVERTING] Converting to Mohawk-T... " + specFile.getName());
/* Timing */timing.startTimer("convertToMohawkT (" + i + ")");
if (toMohawk.lastError == null) {
logger.info("[SUCCESS] Successfully converted to Mohawk's Input Format");
} else {
logger.warning("[FAILURE] Failed to convert to Mohawk's Input Format; Error code "
+ toMohawk.lastError);
}
/* Timing */timing.stopTimer("convertToMohawk (" + i + ")");
logger.info("[CONVERTING] ...Done Converting to Mohawk");
}
FileWriter fw = new FileWriter(specFile.getAbsolutePath() + "_2");
fw.write(m.getString("\n\n", true, true));
fw.close();
if (cmd.hasOption(OptionString.TO_MOHAWK_T.toString())) {
logger.info("[CONVERTING] Converting to Mohawk-T... " + specFile.getName());
/* Timing */timing.startTimer("convertToMohawkT (" + i + ")");
/* Timing */timing.stopTimer("convertToMohawkT (" + i + ")");
logger.info("[CONVERTING] ...Done Converting to Mohawk-T");
FileWriter fw = new FileWriter(specFile.getAbsolutePath() + "_2");
fw.write(m.getString("\n\n", true, true));
fw.close();
/* Timing */timing.stopTimer("convertToMohawkT (" + i + ")");
logger.info("[CONVERTING] ...Done Converting to Mohawk-T");
}
}
}
/* Timing */timing.stopTimer("totalTime");
......@@ -306,6 +343,14 @@ public class ConverterInstance {
"Convert input SPEC file to Mohawk-T's ATRBAC format");
options.addOption(OptionString.TO_ALL.toString(), false,
"Convert input SPEC file to All formats except Mohawk-T (Mohawk, ASAPTime NSA, ASAPTime SA, TRole, TRule)");
// ONLY Commands (limits the reduction steps
options.addOption(OptionBuilder.withArgName("reduction")
.withDescription("Only reduce using one reduction (overwrites the 'TO_' commands:\n"
+ " enable1 - Remove CanEnable/CanDisable Reduction V1,\n"
+ " enable2 - Remove CanEnable/CanDisable Reduction V2,\n"
+ " (others to be added)")
.hasArg().create(OptionString.ONLYREDUCTION.toString()));
}
public Level getLoggerLevel() {
......
......@@ -11,6 +11,7 @@ public enum OptionString {
LOGFOLDER("logfolder"),
MAXW("maxw"),
NOHEADER("noheader"),
ONLYREDUCTION("only"),
RESULTSFILE("output"),
SPECFILE("input"),
SPECEXT("specext"),
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment