Commit 71a1c9ba authored by Jonathan Shahen's avatar Jonathan Shahen

Merge branch 'NewCanEnable'

# Conflicts:
#	src/mohawk/converter/ConverterInstance.java - not really a conflict, took everything from NewCanEnable
parents 351d9664 2a59f8fd
......@@ -8,3 +8,4 @@ logs/
*.ranise_nsa
*.ranise_sa
data/
*.md.html
# Change Log
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).
## [1.2.0] - 2015-08-16
### Fixed
- Fixed conversion error which produced a system that was not always correct
### Bugs
- AGTUniv10 takes a really long time, and a lot of refinement steps;
each refinement step is quick, so the abstraction-refinement process might need to updated
### Added
- CHANGELOG
- VERSION
1.2.0
\ No newline at end of file
This diff is collapsed.
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");
AUTHORS("authors"),
BULK("bulk"),
CHECKNUSMV("checknusmv"),
HELP("help"),
LINESTR("linstr"),
LOGLEVEL("loglevel"),
LOGFILE("logfile"),
LOGFOLDER("logfolder"),
MAXW("maxw"),
NOHEADER("noheader"),
ONLYREDUCTION("only"),
RESULTSFILE("output"),
SPECFILE("input"),
SPECEXT("specext"),
SHORT_ROLENAMES("shortnames"),
TO_ALL("to_all"),
TO_ASAPTIME_NSA("to_asaptime_nsa"),
TO_ASAPTIME_SA("to_asaptime_sa"),
TO_MOHAWK("to_mohawk"),
TO_MOHAWK_T("to_mohawk_t"),
TO_TROLE("to_trole"),
TO_TRULE("to_trule"),
VERSION("version");
private String _str;
......
......@@ -231,7 +231,7 @@ rolecondition returns [Role r] @init {
)? myrole
{
$r = new Role($myrole.rolet, not);
$r = new Role($myrole.rolet, "", not);
/* logmsg("Role: "+ $r); */
}
......
package mohawk.converter.to.asaptime;
import java.io.File;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.*;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.*;
import java.util.logging.Logger;
import org.stringtemplate.v4.ST;
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.Role;
import mohawk.global.pieces.Rule;
import mohawk.global.pieces.TimeSlot;
import mohawk.global.pieces.*;
import mohawk.global.pieces.reduced.query.ASAPTimeNSA_Query;
import mohawk.global.pieces.reduced.rules.ASAPTimeNSA_Rule;
import mohawk.global.timing.MohawkTiming;
import org.stringtemplate.v4.ST;
public class ConvertToASAPTimeNSA extends ConvertTo {
public static final Logger logger = Logger.getGlobal();
public static final Logger logger = Logger.getLogger("mohawk");
public ConvertToASAPTimeNSA(MohawkTiming timing) {
super(timing);
......@@ -45,10 +37,10 @@ public class ConvertToASAPTimeNSA extends ConvertTo {
/* Timing */timing.startTimer(tPrefix + "_" + "sortRolesReduceTimeslots");
// Reduce Roles to Integers
roleHelper.allowZeroRole = false; // roles start from 1 NOT 0!
roleHelper.allowZeroRole = false;// roles start from 1 NOT 0!
roleHelper.setupSortedRoles();
// Reduce TimeIntervals to Timeslots
timeIntervalHelper.allowZeroTimeslot = false; // time-slots start from t1 NOT t0!
timeIntervalHelper.allowZeroTimeslot = false;// time-slots start from t1 NOT t0!
timeIntervalHelper.reduceToTimeslots();
/* Timing */timing.stopTimer(tPrefix + "_" + "sortRolesReduceTimeslots");
......@@ -64,8 +56,8 @@ public class ConvertToASAPTimeNSA extends ConvertTo {
// Stats and logging
numberOfRules = rules.size();
logger.finest("Rules: " + m.getAllRules());
logger.finest("Reduced Rules: " + rules);
logger.fine("Rules: " + m.getAllRules());
logger.fine("Reduced Rules: " + rules);
// Generate the Converted String
/* Timing */timing.startTimer(tPrefix + "_" + "template");
......@@ -125,11 +117,18 @@ public class ConvertToASAPTimeNSA extends ConvertTo {
// Set the Goal Timeslot
SortedSet<Integer> goalTimeslots = timeIntervalHelper.indexOfReduced(query._timeslot);
assert (goalTimeslots.size() == 1) : "The reduced query must have only one timeslot";
if (goalTimeslots.size() != 1) {
logger.severe("goalTimeslots size: " + goalTimeslots.size());
throw new IllegalArgumentException("The reduced query must have only one timeslot");
}
q.goalTimeslot = goalTimeslots.first();
// Set the Goal Role
assert (query._roles.size() > 0) : "The query must have atleast one Goal Role";
if (query._roles.size() == 0) {
logger.severe("query._roles size: " + query._roles.size());
throw new IllegalArgumentException("The query must have atleast one Goal Role");
}
if (query._roles.size() == 1) {
q.goalRole = roleHelper.indexOf(query._roles.get(0));
} else {
......
package mohawk.converter.to.asaptime;
import java.io.File;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.*;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.stringtemplate.v4.ST;
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.Role;
import mohawk.global.pieces.Rule;
import mohawk.global.pieces.TimeSlot;
import mohawk.global.pieces.*;
import mohawk.global.pieces.reduced.query.ASAPTimeSA_Query;
import mohawk.global.pieces.reduced.rules.ASAPTimeSA_Rule;
import mohawk.global.timing.MohawkTiming;
import org.stringtemplate.v4.ST;
public class ConvertToASAPTimeSA extends ConvertTo {
public static final Logger logger = Logger.getLogger("mohawk");
public int canEnableVersion = 2;
public ConvertToASAPTimeSA(MohawkTiming timing) {
super(timing);
......@@ -46,23 +39,41 @@ public class ConvertToASAPTimeSA extends ConvertTo {
/* Timing */timing.stopTimer(tPrefix + "_" + "deepcopy");
// removeEnableDisableRules and alwaysOnRules are Deep Copies
/* Timing */timing.startTimer(tPrefix + "_" + "removeEnableDisableRules");
workableRules = roleHelper.removeEnableDisableRules(m.getAllRules());
/* Timing */timing.stopTimer(tPrefix + "_" + "removeEnableDisableRules");
/* Timing */timing.startTimer(tPrefix + "_removeEnableDisableRules");
switch (canEnableVersion) {
case 1:
workableRules = roleHelper.removeEnableDisableRules(m.getAllRules());
break;
case 2:
workableRules = roleHelper.removeEnableDisableRulesv2(m.getAllRules());
break;
}
/* Timing */timing.stopTimer(tPrefix + "_removeEnableDisableRules");
if (logger.isLoggable(Level.FINE)) {
logger.fine("[STEPWISE] Query Before roleHelper.alwaysOnRules Conversion: " + workableQuery);
logger.fine("[STEPWISE] Rules Before roleHelper.alwaysOnRules Conversion: " + workableRules);
}
/* Timing */timing.startTimer(tPrefix + "_" + "alwaysOnRules");
workableRules = roleHelper.alwaysOnRules(workableRules, workableQuery, timeIntervalHelper);
/* Timing */timing.stopTimer(tPrefix + "_" + "alwaysOnRules");
/* Timing */timing.startTimer(tPrefix + "_" + "reduceToTimeslots");
// Reduce TimeIntervals to Timeslots
timeIntervalHelper.allowZeroTimeslot = false; // time-slots start from t1 NOT t0!
timeIntervalHelper.reduceToTimeslots();
// Reduce Roles to Integers
roleHelper.allowZeroRole = false; // roles start from 1 NOT 0!
roleHelper.setupSortedRoles();
timeIntervalHelper.allowZeroTimeslot = false;// time-slots start from t1 NOT t0!
timeIntervalHelper.reduceToTimeslots();// Reduce TimeIntervals to Timeslots
roleHelper.allowZeroRole = false;// roles start from 1 NOT 0!
roleHelper.setupSortedRoles();// Reduce Roles to Integers
/* Timing */timing.stopTimer(tPrefix + "_" + "reduceToTimeslots");
if (logger.isLoggable(Level.FINE)) {
logger.fine("[STEPWISE] Query Before ASAPTimeSA_Query Conversion: " + workableQuery);
logger.fine("[STEPWISE] Rules Before toASAPTimeSA_Rules Conversion: " + workableRules);
}
// Convert Query to Reduced ASAPTime SA Query and add any extra rules as needed
ASAPTimeSA_Query query = toASAPTimeSA_Query(workableQuery, workableRules, roleHelper, timeIntervalHelper);
......@@ -75,8 +86,10 @@ public class ConvertToASAPTimeSA extends ConvertTo {
// Stats and logging
numberOfRules = newRules.size();
logger.finest("Rules: " + m.getAllRules());
logger.finest("Reduced Rules: " + newRules);
if (logger.isLoggable(Level.FINE)) {
logger.fine("Rules: " + m.getAllRules());
logger.fine("Reduced Rules: " + newRules);
}
// Generate the Converted String
/* Timing */timing.startTimer(tPrefix + "_" + "template");
......@@ -104,7 +117,7 @@ public class ConvertToASAPTimeSA extends ConvertTo {
Charset charset = Charset.forName("US-ASCII");
try (BufferedWriter writer = Files.newBufferedWriter(convertedFile.toPath(), charset)) {
writer.write(convertedStr);
for (ASAPTimeSA_Rule r : newRules) {
writer.write(r.getString() + "\n");
}
......@@ -152,11 +165,18 @@ public class ConvertToASAPTimeSA extends ConvertTo {
// Set the Goal Timeslot
SortedSet<Integer> goalTimeslots = timeIntervalHelper.indexOfReduced(query._timeslot);
assert (goalTimeslots.size() == 1) : "The reduced query must have only one timeslot";
if (goalTimeslots.size() != 1) {
logger.severe("goalTimeslots size: " + goalTimeslots.size());
throw new IllegalArgumentException("The reduced query must have only one timeslot");
}
q.goalTimeslot = goalTimeslots.first();
// Set the Goal Role
assert (query._roles.size() > 0) : "The query must have atleast one Goal Role";
if (query._roles.size() == 0) {
logger.severe("query._roles size: " + query._roles.size());
throw new IllegalArgumentException("The query must have atleast one Goal Role");
}
if (query._roles.size() == 1) {
q.goalRole = roleHelper.indexOf(query._roles.get(0));
} else {
......@@ -198,7 +218,7 @@ public class ConvertToASAPTimeSA extends ConvertTo {
}
// Convert Preconditions to the Role Indexes
//System.out.println("[toASAPTimeSA_Rules] Rule: " + rule);
// System.out.println("[toASAPTimeSA_Rules] Rule: " + rule);
Integer id;
for (Role r : rule._preconditions) {
id = roleHelper.indexOf(r);
......@@ -209,10 +229,12 @@ public class ConvertToASAPTimeSA extends ConvertTo {
precondition.add(id);
}
logger.fine("Timeslots: " + timeIntervalHelper._timeIntervals + "; Reduced Timeslots: "
+ timeIntervalHelper._reducedTimeIntervals);
logger.fine("Admin Interval: " + adminInterval + "Precondition: " + rule._preconditions + "; Role Schedule: "
+ roleSchedule + "; Target Role: " + rule._role);
if (logger.isLoggable(Level.FINE)) {
logger.fine("Timeslots: " + timeIntervalHelper._timeIntervals + "; Reduced Timeslots: "
+ timeIntervalHelper._reducedTimeIntervals);
logger.fine("Admin Interval: " + adminInterval + "Precondition: " + rule._preconditions
+ "; Role Schedule: " + roleSchedule + "; Target Role: " + rule._role);
}
ASAPTimeSA_Rule rule_t;
for (Integer adminTimeslot : adminInterval) {
......@@ -229,7 +251,9 @@ public class ConvertToASAPTimeSA extends ConvertTo {
rule_t.precondition = precondition;
rule_t.roleTime = roleTimeslot;
logger.fine("Adding to rules: " + rule_t);
if (logger.isLoggable(Level.FINE)) {
logger.fine("Adding to rules: " + rule_t);
}
rules.add(rule_t);
}
......
package mohawk.converter.to.mohawk;
import java.io.File;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.*;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.stringtemplate.v4.ST;
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.Role;
import mohawk.global.pieces.Rule;
import mohawk.global.pieces.RuleType;
import mohawk.global.pieces.TimeSlot;
import mohawk.global.pieces.*;
import mohawk.global.pieces.reduced.query.Mohawk_Query;
import mohawk.global.pieces.reduced.rules.MohawkCA_Rule;
import mohawk.global.pieces.reduced.rules.MohawkCR_Rule;
import mohawk.global.timing.MohawkTiming;
import org.stringtemplate.v4.ST;
public class ConvertToMohawk extends ConvertTo {
public static final Logger logger = Logger.getLogger("mohawk-converter");
public static final Logger logger = Logger.getLogger("mohawk");
public boolean shortRolenames = false;
public int canEnableVersion = 2;
public ConvertToMohawk(MohawkTiming timing) {
super(timing);
......@@ -34,51 +30,89 @@ public class ConvertToMohawk extends ConvertTo {
@Override
public String convert(MohawkT m, File f, Boolean writeToFile) {
try {
ArrayList<MohawkCA_Rule> newCARules = new ArrayList<MohawkCA_Rule>();
ArrayList<MohawkCR_Rule> newCRRules = new ArrayList<MohawkCR_Rule>();
ArrayList<Rule> workableRules = new ArrayList<Rule>();
// Deep Copy Helpers
/* Timing */timing.startTimer(tPrefix + "_" + "deepcopy");
RoleHelper roleHelper = new RoleHelper(m.roleHelper);
TimeIntervalHelper timeIntervalHelper = new TimeIntervalHelper(m.timeIntervalHelper);
Query workableQuery = new Query(m.query);
/* Timing */timing.stopTimer(tPrefix + "_deepcopy");
ArrayList<MohawkCA_Rule> newCARules = new ArrayList<MohawkCA_Rule>();
ArrayList<MohawkCR_Rule> newCRRules = new ArrayList<MohawkCR_Rule>();
ArrayList<Rule> workableRules = new ArrayList<Rule>();
// Deep Copy Helpers
/* Timing */timing.startTimer(tPrefix + "_" + "deepcopy");
RoleHelper roleHelper = new RoleHelper(m.roleHelper);
RoleHelper roleHelperTemporality = null;
TimeIntervalHelper timeIntervalHelper = new TimeIntervalHelper(m.timeIntervalHelper);
Query workableQuery = new Query(m.query);
/* Timing */timing.stopTimer(tPrefix + "_deepcopy");
try {
/* Timing */timing.startTimer(tPrefix + "_removeEnableDisableRules");
workableRules = roleHelper.removeEnableDisableRules(m.getAllRules()); // (3)
switch (canEnableVersion) {
case 1:
workableRules = roleHelper.removeEnableDisableRules(m.getAllRules());
break;
case 2:
workableRules = roleHelper.removeEnableDisableRulesv2(m.getAllRules());
break;
}
// (3)
/* Timing */timing.stopTimer(tPrefix + "_removeEnableDisableRules");
// Convert Query to Reduced ASAPTime SA Query and add any extra rules as needed
//Mohawk_Query query = toMohawk_Query(workableQuery, workableRules, roleHelper, timeIntervalHelper);
// Mohawk_Query query = toMohawk_Query(workableQuery, workableRules, roleHelper, timeIntervalHelper);
/* Timing */timing.startTimer(tPrefix + "_alwaysOnRules");
workableRules = roleHelper.alwaysOnRules(workableRules, workableQuery, timeIntervalHelper); // (4)
workableRules = roleHelper.alwaysOnRules(workableRules, workableQuery, timeIntervalHelper);
// (4)
/* Timing */timing.stopTimer(tPrefix + "_alwaysOnRules");
// Convert Query to Reduced ASAPTime SA Query and add any extra rules as needed
Mohawk_Query query = toMohawk_Query(workableQuery, workableRules, roleHelper, timeIntervalHelper);
/* Timing */timing.startTimer(tPrefix + "_removeUninvokablePrecondtions");
workableRules = roleHelper.removeUninvokablePrecondtions(workableRules, false); // (6)
workableRules = roleHelper.removeUninvokablePrecondtions(workableRules, false);
// (6)
/* Timing */timing.stopTimer(tPrefix + "_removeUninvokablePrecondtions");
if (logger.isLoggable(Level.FINE)) {
logger.fine("[STEPWISE] Rules Before roleHelperTemporality.removePrecondtionsCanRevoke Conversion: "
+ workableRules);
}
/* Timing */timing.startTimer(tPrefix + "_removePrecondtionsCanRevoke");
workableRules = roleHelper.removePrecondtionsCanRevoke(workableRules, false); // (6)
workableRules = roleHelper.removePrecondtionsCanRevoke(workableRules, false);
// (6)
/* Timing */timing.stopTimer(tPrefix + "_removePrecondtionsCanRevoke");
if (logger.isLoggable(Level.FINE)) {
logger.fine(
"[STEPWISE] Rules Before roleHelperTemporality.removeTemporality Conversion: " + workableRules);
}
/* Timing */timing.startTimer(tPrefix + "_removeTemporality");
RoleHelper roleHelperTemporality = new RoleHelper(roleHelper);
roleHelperTemporality = new RoleHelper(roleHelper);
ArrayList<Object> reducedRules = roleHelperTemporality.removeTemporality(workableRules, timeIntervalHelper);
/* Timing */timing.stopTimer(tPrefix + "_removeTemporality");
if (logger.isLoggable(Level.FINE)) {
logger.fine("[STEPWISE] Rules After CA and CR Conversion: " + workableRules);
}
if (shortRolenames) {
logger.info("Creating Short Rolenames");
roleHelperTemporality.setupSortedRoles();
}
// Convert Rules into Reduced Mohawk CA and CR Rules (5)
/* Timing */timing.startTimer(tPrefix + "_convertRules");
for (Object r : reducedRules) {
if (r instanceof MohawkCA_Rule) {
if (shortRolenames) {
((MohawkCA_Rule) r).shortRolenames(roleHelperTemporality);
}
newCARules.add((MohawkCA_Rule) r);
} else if (r instanceof MohawkCR_Rule) {
if (shortRolenames) {
((MohawkCR_Rule) r).shortRolenames(roleHelperTemporality);
}
newCRRules.add((MohawkCR_Rule) r);
} else {
throw new IllegalArgumentException("Can only convert Can Assign and Can Revoke Rules in Mohawk");
......@@ -86,7 +120,7 @@ public class ConvertToMohawk extends ConvertTo {
}
/* Timing */timing.stopTimer(tPrefix + "_convertRules");
boolean queryFound = query.finalize(roleHelperTemporality);
boolean queryFound = query.finalize(roleHelperTemporality, shortRolenames);
if (queryFound == false) { throw new Exception("The query could not find the Goal Role!"); }
// Stats and logging
numberOfRules = newCARules.size() + newCRRules.size();
......@@ -94,12 +128,20 @@ public class ConvertToMohawk extends ConvertTo {
/* Timing */timing.startTimer(tPrefix + "_template");
String template = ConvertTo.readFile(this.getClass().getResource("mohawkTemplate.st"));
ST st = new ST(template);
st.add("roles", roleHelperTemporality.getArray());
st.add("users", new String[] { "AdminUser", "User" });
st.add("specuser", "User");
if (shortRolenames) {
st.add("roles", roleHelperTemporality.getArrayShortNames());
st.add("adminuser", "AU");
st.add("adminrole", "A");
st.add("users", new String[] { "AU", "User" });
st.add("specuser", "User");// Can't use 'U'
} else {
st.add("roles", roleHelperTemporality.getArray());
st.add("adminuser", "AdminUser");
st.add("adminrole", "AdminRole");
st.add("users", new String[] { "AdminUser", "User" });
st.add("specuser", "User");
}
st.add("specrole", query.specRole);
st.add("adminuser", "AdminUser");
st.add("adminrole", "AdminRole");
st.add("canrevoke", newCRRules);
st.add("canassign", newCARules);
convertedStr = st.render();
......@@ -120,10 +162,20 @@ public class ConvertToMohawk extends ConvertTo {
} catch (Exception e) {
StringWriter errors = new StringWriter();
e.printStackTrace(new PrintWriter(errors));
logger.fine(errors.toString());
logger.warning(errors.toString());
logger.warning("[ERROR] Unable to convert to Mohawk: " + e.getMessage());
lastError = "Error ConvertToRanise.convert.Exception #1";
if (logger.isLoggable(Level.FINE)) {
if (roleHelperTemporality == null) {
roleHelper.dumpRoleSet("ToMohawkRoleHelperDump.txt");
roleHelper.dumpHashedRoles("ToMohawkRoleHelperDump_Hashed.txt");
} else {
roleHelperTemporality.dumpRoleSet("ToMohawkRoleHelperDump.txt");
roleHelperTemporality.dumpHashedRoles("ToMohawkRoleHelperDump_Hashed.txt");
}
}
}
return convertedStr;
}
......
<! Roles role0 role1 role2 role3; !>
Roles <roles:{r|<r._name>}; separator=" "> <adminrole>;
Roles <roles:{r|<r.Name>}; separator=" "> <adminrole>;
<! Users user0 user1 user2 user3 user4; !>
Users <users; separator=" ">;
......
package mohawk.converter.to.tred;
import java.io.BufferedWriter;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.*;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.stringtemplate.v4.ST;
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.Role;
import mohawk.global.pieces.Rule;
import mohawk.global.pieces.RuleType;
import mohawk.global.pieces.TimeSlot;
import mohawk.global.pieces.*;
import mohawk.global.pieces.reduced.query.TRole_Query;
import mohawk.global.pieces.reduced.rules.TRole_Rule;
import mohawk.global.timing.MohawkTiming;
import org.stringtemplate.v4.ST;
public class ConvertToTRole extends ConvertTo {
public static final Logger logger = Logger.getGlobal();
public static final Logger logger = Logger.getLogger("mohawk");
public int canEnableVersion = 2;
public ConvertToTRole(MohawkTiming timing) {
super(timing);
......@@ -48,16 +41,24 @@ public class ConvertToTRole extends ConvertTo {
Query workableQuery = new Query(m.query);
/* Timing */timing.stopTimer(tPrefix + "_" + "deepcopy");
/* Timing */timing.startTimer(tPrefix + "_" + "removeEnableDisableRules");
workableRules = roleHelper.removeEnableDisableRules(m.getAllRules());
/* Timing */timing.stopTimer(tPrefix + "_" + "removeEnableDisableRules");
/* Timing */timing.startTimer(tPrefix + "_removeEnableDisableRules");
switch (canEnableVersion) {
case 1:
workableRules = roleHelper.removeEnableDisableRules(m.getAllRules());
break;
case 2:
workableRules = roleHelper.removeEnableDisableRulesv2(m.getAllRules());
break;
}
/* Timing */timing.stopTimer(tPrefix + "_removeEnableDisableRules");
/* Timing */timing.startTimer(tPrefix + "_" + "alwaysOnRules");
workableRules = roleHelper.alwaysOnRules(workableRules, workableQuery, timeIntervalHelper);
/* Timing */timing.stopTimer(tPrefix + "_" + "alwaysOnRules");
// Reduce Roles to Integers
roleHelper.allowZeroRole = false; // roles start from 1 NOT 0!
roleHelper.allowZeroRole = false;// roles start from 1 NOT 0!
roleHelper.setupSortedRoles();
// Convert Query to Reduced ASAPTime SA Query and add any extra rules as needed
......@@ -68,8 +69,10 @@ public class ConvertToTRole extends ConvertTo {
// Stats and logging
numberOfRules = newRules.size();
logger.fine("Rules: " + m.getAllRules());
logger.fine("Reduced Rules: " + newRules);
if (logger.isLoggable(Level.FINE)) {
logger.fine("Rules: " + m.getAllRules());
logger.fine("Reduced Rules: " + newRules);
}
// Generate the Converted String
/* Timing */timing.startTimer(tPrefix + "_" + "template");
......@@ -87,7 +90,7 @@ public class ConvertToTRole extends ConvertTo {
/*
File convertedFile = new File(file.getAbsolutePath() + getFileExtenstion());
FileOutputStream out = new FileOutputStream(convertedFile);
out.write(header.getBytes());
// Convert Rules into Reduced ASAPTime NSA Rules
for (Rule r : workableRules) {
......@@ -99,12 +102,12 @@ public class ConvertToTRole extends ConvertTo {
*/
Charset charset = Charset.forName("US-ASCII");
try (BufferedWriter writer = Files.newBufferedWriter(
Paths.get(file.getAbsolutePath() + getFileExtenstion()), charset)) {
try (BufferedWriter writer = Files
.newBufferedWriter(Paths.get(file.getAbsolutePath() + getFileExtenstion()), charset)) {
writer.write(header);
// Convert Rules into Reduced ASAPTime NSA Rules
for (Rule r : workableRules) {
//newRules.add(new TRole_Rule(r, roleHelper, timeIntervalHelper));
// newRules.add(new TRole_Rule(r, roleHelper, timeIntervalHelper));
writer.write(new TRole_Rule(r, roleHelper, timeIntervalHelper).getString());
}
} catch (IOException x) {
......@@ -119,7 +122,7 @@ public class ConvertToTRole extends ConvertTo {
// Convert Rules into Reduced ASAPTime NSA Rules
for (Rule r : workableRules) {
//newRules.add(new TRole_Rule(r, roleHelper, timeIntervalHelper));
// newRules.add(new TRole_Rule(r, roleHelper, timeIntervalHelper));
sb.append(new TRole_Rule(r, roleHelper, timeIntervalHelper).getString());
}
convertedStr = sb.toString();
......@@ -158,7 +161,10 @@ public class ConvertToTRole extends ConvertTo {
public TRole_Query toTRole_Query(Query query, ArrayList<Rule> rules, RoleHelper roleHelper,
TimeIntervalHelper timeIntervalHelper) {
// Checking Conditions
assert (query._roles.size() > 0) : "The query must have atleast one Goal Role";
if (query._roles.size() == 0) {
logger.severe("The query must have atleast one Goal Role: " + query);
throw new IllegalArgumentException("The query must have atleast one Goal Role");
}
Role newGoalRole = roleHelper.addUniqueRole("goalRole");
TRole_Query q = new TRole_Query(newGoalRole);
......
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