Commit a5619100 authored by Jonathan Shahen's avatar Jonathan Shahen

Fixed errors occurring in ASASPTime SA and TROLE where the EXTRA_ADMIN (see...

Fixed errors occurring in ASASPTime SA and TROLE where the EXTRA_ADMIN (see roles created with 'suffixAdminExtra') roles, with suffix number 0, were not added into the RoleHelper internal table; added a test now to throw an error if there is ever a role asked for and not within the table; Fixed a problem where ASASPTime SA was using legacy code instead of using the TEMPLATE code to generate the converted file (it was leaving empty preconditions instead of TRUE)
parent 3f58655a
......@@ -4,4 +4,4 @@ CONFIG <numRoles> <numTimeslots>
GOAL <goalRole> <goalTimeslot>
<! !>
<! can_revoke t3 , 28 -5 -3 -8 ; t5 , 14 !>
<!rules_sa:{r|<r.ruleType> t<r.adminTime> , <if(r.precondition)><r.precondition; separator=" "><else>true<endif> ; t<r.roleTime> , <r.role><\n>}!>
\ No newline at end of file
<rules_sa:{r|<r.ruleType> t<r.adminTime> , <if(r.precondition)><r.precondition; separator=" "><else>true<endif> ; t<r.roleTime> , <r.role><\n>}>
\ No newline at end of file
......@@ -79,7 +79,7 @@ public class ConvertToASAPTimeNSA extends ConvertTo {
convertedStr = st.render();
/* Timing */timing.stopTimer(tPrefix + "_" + "template");
// Potentially write the converted string out to "file + getFileExtenstion()"
// Write the converted string out to "file + getFileExtenstion()"
if (writeToFile) {
/* Timing */timing.startTimer(tPrefix + "_" + "Files.write");
File convertedFile = new File(file.getAbsolutePath() + getFileExtenstion());
......
package mohawk.converter.to.asaptime;
import java.io.BufferedWriter;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.logging.Level;
import java.util.logging.Logger;
import mohawk.converter.to.ConvertTo;
......@@ -27,7 +25,7 @@ import mohawk.global.timing.MohawkTiming;
import org.stringtemplate.v4.ST;
public class ConvertToASAPTimeSA extends ConvertTo {
public static final Logger logger = Logger.getGlobal();
public static final Logger logger = Logger.getLogger("mohawk");
public ConvertToASAPTimeSA(MohawkTiming timing) {
super(timing);
......@@ -88,20 +86,21 @@ public class ConvertToASAPTimeSA extends ConvertTo {
st.add("numTimeslots", timeIntervalHelper.sizeReduced());
st.add("goalRole", query.goalRole);
st.add("goalTimeslot", query.goalTimeslot);
//st.add("rules_sa", newRules);
st.add("rules_sa", newRules);
convertedStr = st.render();
/* Timing */timing.stopTimer(tPrefix + "_" + "template");
// Potentially write the converted string out to "file + getFileExtenstion()"
// Write the converted string out to "file + getFileExtenstion()"
if (writeToFile) {
/* Timing */timing.startTimer(tPrefix + "_" + "Files.write");
File convertedFile = new File(file.getAbsolutePath() + getFileExtenstion());
/*if (!convertedFile.exists()) {
if (!convertedFile.exists()) {
convertedFile.createNewFile();
}
Files.write(convertedFile.toPath(), convertedStr.getBytes());*/
Files.write(convertedFile.toPath(), convertedStr.getBytes());
/** Legacy code: use if the Template Files are not working
Charset charset = Charset.forName("US-ASCII");
try (BufferedWriter writer = Files.newBufferedWriter(convertedFile.toPath(), charset)) {
writer.write(convertedStr);
......@@ -114,6 +113,7 @@ public class ConvertToASAPTimeSA extends ConvertTo {
} catch (IOException x) {
System.err.format("IOException: %s%n", x);
}
*/
/* Timing */timing.stopTimer(tPrefix + "_" + "Files.write");
}
......@@ -199,14 +199,20 @@ public class ConvertToASAPTimeSA extends ConvertTo {
// Convert Preconditions to the Role Indexes
//System.out.println("[toASAPTimeSA_Rules] Rule: " + rule);
Integer id;
for (Role r : rule._preconditions) {
precondition.add(roleHelper.indexOf(r));
id = roleHelper.indexOf(r);
if (id == null) {
logger.log(Level.SEVERE, "Could not find role: " + r + " in " + roleHelper.toString());
throw new NullPointerException("Could not find role: " + r + " in " + roleHelper.toString());
}
precondition.add(id);
}
logger.fine("Timeslots: " + timeIntervalHelper._timeIntervals);
logger.fine("Reduced Timeslots: " + timeIntervalHelper._reducedTimeIntervals);
logger.fine("Admin Interval: " + adminInterval);
logger.fine("Role Schedule: " + roleSchedule);
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) {
......@@ -214,14 +220,16 @@ public class ConvertToASAPTimeSA extends ConvertTo {
rule_t = new ASAPTimeSA_Rule();
rule_t.ruleType = rule._type.toRanise();
if (!rule._adminRole.isAllRoles()) { throw new IllegalArgumentException(
"Rule contains a Admin Role that isn't TRUE!"); }
if (!rule._adminRole.isAllRoles()) {
logger.log(Level.SEVERE, "Rule does not have TRUE for the admin role: " + rule);
throw new IllegalArgumentException("Rule contains a Admin Role that isn't TRUE!");
}
rule_t.adminTime = adminTimeslot;
rule_t.role = roleHelper.indexOf(rule._role);
rule_t.precondition = precondition;
rule_t.roleTime = roleTimeslot;
logger.fine("Adding rule to rules");
logger.fine("Adding to rules: " + rule_t);
rules.add(rule_t);
}
......
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