Commit 08dd77ac authored by Jonathan Shahen's avatar Jonathan Shahen

MOHAWK-32 (Convert MohawkT to MohawkT with verbose comments and query up top) is done

Some work done on MOHAWK-23 (Reduction for Timeintervals)
parent 8517e505
......@@ -56,11 +56,16 @@ public class ConverterCUI {
}
public static void printCommonCommands() {
System.out.println("\n\n--- Common Commands ---");
System.out.println("-to_uzun -rbacspec data/regressiontests/positive1.spec -loglevel debug !exit");
System.out.println("-to_uzun -rbacspec data/regressiontests/positive2.spec -loglevel debug !exit");
System.out.println("-to_uzun -rbacspec data/regressiontests/positive3.spec -loglevel debug !exit");
System.out.println("-to_uzun -rbacspec data/regressiontests/positive4.spec -loglevel debug !exit");
System.out.println(OptionString.TO_TROLE.c() + OptionString.SPECFILE.c()
+ "data/regressiontests/positive1.spec " + OptionString.LOGLEVEL.c() + "debug !exit");
System.out.println(OptionString.TO_TROLE.c() + OptionString.SPECFILE.c()
+ "data/regressiontests/positive2.spec " + OptionString.LOGLEVEL.c() + "debug !exit");
System.out.println(OptionString.TO_TROLE.c() + OptionString.SPECFILE.c()
+ "data/regressiontests/positive3.spec " + OptionString.LOGLEVEL.c() + "debug !exit");
System.out.println(OptionString.TO_TROLE.c() + OptionString.SPECFILE.c()
+ "data/regressiontests/positive4.spec " + OptionString.LOGLEVEL.c() + "debug !exit");
System.out.println("");
}
}
......@@ -2,6 +2,7 @@ package mohawk.converter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
......@@ -45,25 +46,6 @@ public class ConverterInstance {
public SpecHelper specHelper = new SpecHelper();
public MohawkTiming timing = new MohawkTiming();
public enum OptionString {
HELP("help"), AUTHORS("authors"), VERSION("version"), CHECKNUSMV("checknusmv"), LOGLEVEL("loglevel"), LOGFILE(
"logfile"), LOGFOLDER("logfolder"), NOHEADER("noheader"), RESULTSFILE("output"), MAXW("maxw"), LINESTR(
"linstr"), SPECFILE("input"), SPECEXT("specext"), BULK("bulk"), TO_ASAPTIME_NSA("to_asaptime_nsa"), TO_ASAPTIME_SA(
"to_asaptime_sa"), TO_TROLE("to_trole"), TO_TRULE("to_trule"), TO_MOHAWK("to_mohawk"), TO_MOHAWK_T(
"to_mohawk_t"), TO_ALL("to_all");
private String _str;
private OptionString(String s) {
_str = s;
}
@Override
public String toString() {
return _str;
}
}
public int run(String[] args) {
try {
Options options = new Options();
......@@ -174,6 +156,20 @@ public class ConverterInstance {
} else {
logger.info("[SKIP] Skipping converting to Mohawk");
}
if (cmd.hasOption(OptionString.TO_MOHAWK_T.toString())) {
logger.info("[CONVERTING] Converting to Mohawk-T...");
/* Timing */timing.startTimer("convertToMohawkT (" + i + ")");
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");
} else {
logger.info("[SKIP] Skipping converting to Mohawk");
}
}
/* Timing */timing.stopTimer("totalTime");
......@@ -358,12 +354,10 @@ public class ConverterInstance {
}
// Add Logger File Handler
if (!Logger_filepath.isEmpty()) {
File logfile = new File(cmd.getOptionValue(OptionString.LOGFOLDER.toString()));
File logfile = new File(Logger_folderpath);
logfile.mkdirs();
if (logfile.isDirectory()) {
Logger_folderpath = cmd.getOptionValue(OptionString.LOGFOLDER.toString());
} else {
if (!logfile.isDirectory()) {
logger.severe("logfolder did not contain a folder that exists or that could be created!");
}
fileHandler = new FileHandler(Logger_folderpath + File.separator + Logger_filepath);
......
package mohawk.converter;
public enum OptionString {
HELP("help"), AUTHORS("authors"), VERSION("version"), CHECKNUSMV("checknusmv"), LOGLEVEL("loglevel"), LOGFILE(
"logfile"), LOGFOLDER("logfolder"), NOHEADER("noheader"), RESULTSFILE("output"), MAXW("maxw"), LINESTR(
"linstr"), SPECFILE("input"), SPECEXT("specext"), BULK("bulk"), TO_ASAPTIME_NSA("to_asaptime_nsa"), TO_ASAPTIME_SA(
"to_asaptime_sa"), TO_TROLE("to_trole"), TO_TRULE("to_trule"), TO_MOHAWK("to_mohawk"), TO_MOHAWK_T(
"to_mohawk_t"), TO_ALL("to_all");
private String _str;
private OptionString(String s) {
_str = s;
}
@Override
public String toString() {
return _str;
}
/**
* Returns the commandline equivalent with the hyphen and a space following: AUTHORS -> "-authors "
*
* @return
*/
public String c() {
return "-" + _str + " ";
}
}
<! Conversion to Ranise's Input Format !>
<! !>
CONFIG <numRoles> <numTimeslots>
GOAL <goalRole> <goalTimeslot>
GOAL <goalRole> t<goalTimeslot>
<! !>
<! can_revoke 3 , t3 , true ; t5 , 14 !>
<rules:{r|<r.ruleType> <if(r.adminRole >= 0)><r.adminRole><else>true<endif> , <r.adminTime> , <if(r.precondition)><r.precondition; separator=" & "><else>true<endif> ; <r.roleTime> , <r.role><\n>}>
\ No newline at end of file
<rules_nsa:{r|<r.ruleType> <if(r.adminRole >= 0)><r.adminRole><else>true<endif> , t<r.adminTime> , <if(r.precondition)><r.precondition; separator=" & "><else>true<endif> ; t<r.roleTime> , <r.role><\n>}>
\ No newline at end of file
......@@ -9,8 +9,12 @@ import java.util.ArrayList;
import java.util.logging.Logger;
import mohawk.converter.to.ConvertTo;
import mohawk.global.helper.RoleHelper;
import mohawk.global.helper.TimeIntervalHelper;
import mohawk.global.pieces.MohawkT;
import mohawk.global.pieces.Query;
import mohawk.global.pieces.Rule;
import mohawk.global.pieces.reduced.query.ASAPTimeNSA_Query;
import mohawk.global.pieces.reduced.rules.ASAPTimeNSA_Rule;
import org.stringtemplate.v4.ST;
......@@ -24,18 +28,28 @@ public class ConvertToASAPTimeNSA extends ConvertTo {
String template = ConvertTo.readFile(this.getClass().getResource("ASAPTimeNSATemplate.st"),
Charset.defaultCharset());
ST st = new ST(template);
st.add("numRoles", m.roleHelper.size());
st.add("numTimeslots", m.timeIntervalHelper.size());
st.add("goalRole", m.roleHelper.indexOf(m.query._roles.get(0)));
st.add("goalTimeslot", m.query._timeslot.toString());
ArrayList<ASAPTimeNSA_Rule> rules = new ArrayList<ASAPTimeNSA_Rule>();
// Reduce Roles to Integers
m.roleHelper.allowZeroRole = false; // roles start from 1 NOT 0!
m.roleHelper.setupSortedRoles();
// Reduce TimeIntervals to Timeslots
m.timeIntervalHelper.allowZeroTimeslot = false; // time-slots start from t1 NOT t0!
m.timeIntervalHelper.reduceToTimeslots();
// Convert Rules into Reduced ASAPTime NSA Rules
ArrayList<ASAPTimeNSA_Rule> rules = new ArrayList<ASAPTimeNSA_Rule>();
for (Rule r : m.getAllRules()) {
rules.add(new ASAPTimeNSA_Rule(r, m.roleHelper, m.timeIntervalHelper));
rules.addAll(toASAPTimeNSA_Rules(r, m.roleHelper, m.timeIntervalHelper));
}
st.add("rules", rules);
// Convert Query to Reduced ASAPTime NSA Query and add any extra rules as needed
ASAPTimeNSA_Query query = toASAPTimeNSA_Query(m.query, rules, m.roleHelper, m.timeIntervalHelper);
st.add("numRoles", m.roleHelper.size());
st.add("numTimeslots", m.timeIntervalHelper.sizeReduced());
st.add("goalRole", query.goalRole);
st.add("goalTimeslot", query.goalTimeslot);
st.add("rules_nsa", rules);
convertedStr = st.render();
......@@ -60,6 +74,33 @@ public class ConvertToASAPTimeNSA extends ConvertTo {
return convertedStr;
}
/**
*
* @param query
* @param rules
* @param roleHelper
* @param timeIntervalHelper
* @return
*/
public ASAPTimeNSA_Query toASAPTimeNSA_Query(Query query, ArrayList<ASAPTimeNSA_Rule> rules, RoleHelper roleHelper,
TimeIntervalHelper timeIntervalHelper) {
// TODO Auto-generated method stub
return null;
}
/**
*
* @param r
* @param roleHelper
* @param timeIntervalHelper
* @return
*/
public ArrayList<ASAPTimeNSA_Rule> toASAPTimeNSA_Rules(Rule r, RoleHelper roleHelper,
TimeIntervalHelper timeIntervalHelper) {
// TODO Auto-generated method stub
return null;
}
@Override
public String getFileExtenstion() {
return ".ranise";
......
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