Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
Jon Shahen
mohawk-t-conversion-tool
Commits
c91ddee1
Commit
c91ddee1
authored
Jan 12, 2015
by
Jonathan Shahen
Browse files
better naming convention; fixed build.xml
parent
8fad5ad4
Changes
25
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
414 additions
and
12 deletions
+414
-12
.classpath
.classpath
+1
-0
.gitignore
.gitignore
+4
-0
build.xml
build.xml
+22
-2
data/sharelatex/q3_enabled.spec
data/sharelatex/q3_enabled.spec
+28
-0
data/sharelatex/q3_role.spec
data/sharelatex/q3_role.spec
+32
-0
data/sharelatex/question2.spec
data/sharelatex/question2.spec
+31
-0
src/mohawk/converter/ConverterInstance.java
src/mohawk/converter/ConverterInstance.java
+4
-4
src/mohawk/converter/pieces/CanAssign.java
src/mohawk/converter/pieces/CanAssign.java
+1
-0
src/mohawk/converter/pieces/CanDisable.java
src/mohawk/converter/pieces/CanDisable.java
+1
-0
src/mohawk/converter/pieces/CanEnable.java
src/mohawk/converter/pieces/CanEnable.java
+1
-0
src/mohawk/converter/pieces/CanRevoke.java
src/mohawk/converter/pieces/CanRevoke.java
+1
-0
src/mohawk/converter/pieces/rules/ASAPTimeNSA_Rule.java
src/mohawk/converter/pieces/rules/ASAPTimeNSA_Rule.java
+50
-0
src/mohawk/converter/pieces/rules/ASAPTimeSA_Rule.java
src/mohawk/converter/pieces/rules/ASAPTimeSA_Rule.java
+50
-0
src/mohawk/converter/pieces/rules/Mohawk_Rule.java
src/mohawk/converter/pieces/rules/Mohawk_Rule.java
+5
-3
src/mohawk/converter/pieces/rules/TRedRole_Rule.java
src/mohawk/converter/pieces/rules/TRedRole_Rule.java
+50
-0
src/mohawk/converter/pieces/rules/TRedRule_Rule.java
src/mohawk/converter/pieces/rules/TRedRule_Rule.java
+50
-0
src/mohawk/converter/testing/RegressionTests.java
src/mohawk/converter/testing/RegressionTests.java
+19
-3
src/mohawk/converter/to/asaptime/ASAPTimeNSATemplate.st
src/mohawk/converter/to/asaptime/ASAPTimeNSATemplate.st
+0
-0
src/mohawk/converter/to/asaptime/ASAPTimeSATemplate.st
src/mohawk/converter/to/asaptime/ASAPTimeSATemplate.st
+7
-0
src/mohawk/converter/to/asaptime/ConvertToASAPTimeNSA.java
src/mohawk/converter/to/asaptime/ConvertToASAPTimeNSA.java
+57
-0
No files found.
.classpath
View file @
c91ddee1
...
...
@@ -13,5 +13,6 @@
<classpathentry
kind=
"lib"
path=
"lib/junit-4.12.jar"
/>
<classpathentry
kind=
"lib"
path=
"lib/hamcrest-core-1.3.jar"
/>
<classpathentry
kind=
"con"
path=
"org.eclipse.jdt.junit.JUNIT_CONTAINER/4"
/>
<classpathentry
combineaccessrules=
"false"
kind=
"src"
path=
"/Mohawk-T Globals"
/>
<classpathentry
kind=
"output"
path=
"bin"
/>
</classpath>
.gitignore
View file @
c91ddee1
...
...
@@ -3,3 +3,7 @@ target/
src/mohawk/converter/generated/*.java
src/mohawk/converter/generated/*.tokens
logs/
*.uzun
*.ranise
*.ranise_nsa
*.ranise_sa
build.xml
View file @
c91ddee1
...
...
@@ -16,7 +16,17 @@
<property
name=
"antlr"
location=
"${lib}/antlr-4.4-complete.jar"
/>
<property
name=
"junit"
location=
"${lib}/junit-4.12.jar"
/>
<property
name=
"qtest"
location=
"${data}/"
/>
<!-- TODO -->
<!-- Customize this line to point to the 'Mohawk-T Globals' Project's source folder -->
<property
name=
"src.globals"
location=
"../Mohawk-T Globals/src"
/>
<path
id=
"test.classpath"
>
<pathelement
location=
"${build}"
/>
<pathelement
location=
"${junit}"
/>
<fileset
dir=
"${lib}"
>
<include
name=
"**/*.jar"
/>
</fileset>
</path>
<target
name=
"init"
>
<!-- create the bin directory -->
...
...
@@ -46,6 +56,8 @@
<target
name=
"compile"
depends=
"parser"
description=
"compile the source "
>
<!-- compile the java code from ${src} into ${build} -->
<javac
srcdir=
"${src}"
destdir=
"${build}"
debug=
"on"
deprecation=
"true"
>
<src
path=
"${src}"
/>
<src
path=
"${src.globals}"
/>
<classpath>
<fileset
dir=
"${lib}"
>
<include
name=
"**/*.jar"
/>
...
...
@@ -89,10 +101,18 @@
<target
name=
"regression"
depends=
"dist"
description=
"Performs a regression test"
>
<!-- @author Jonathan Shahen -->
<echo>
java -cp ${dist}/${ant.project.name}.jar org.junit.runner.JUnitCore mohawk.testing.RegressionTests
</echo>
<exec
executable=
"cmd"
dir=
"."
failonerror=
"true"
>
<junit
haltonfailure=
"true"
printsummary=
"true"
>
<test
name=
"mohawk.converter.testing.RegressionTests"
/>
<formatter
type=
"plain"
usefile=
"false"
/>
<classpath
refid=
"test.classpath"
/>
</junit>
<!-- OLD Windows ONLY running JUnit through the commandline
<exec executable="cmd" dir="." failonerror="true" osfamily="windows">
<arg value="/c" />
<arg value="java -cp "${dist}/${ant.project.name}.jar" org.junit.runner.JUnitCore mohawk.converter.testing.RegressionTests" />
</exec>
-->
</target>
<target
name=
"clean"
description=
"clean up"
>
...
...
data/sharelatex/q3_enabled.spec
0 → 100644
View file @
c91ddee1
/*
* Question 3:
*
* Roles: role1, role2, role3
* Time-Slots: t0, t1
*
* If the roles are enabled by default then this example with succeed
*/
Query: t0,[role3]
Expected: TRUE
CanAssign {
/* <Admin role,
* starting timeslot - end timeslot for admin role,
* role preconditions,
* [time slot rule gives role to user for, another time slot (optional)...],
* role to give to the user>
*/
<TRUE,t0,TRUE,t0,role2> //(1)
<TRUE,t0,role2,t0,role3> //(2)
}
CanRevoke {}
CanEnable {}
CanDisable {}
data/sharelatex/q3_role.spec
0 → 100644
View file @
c91ddee1
/*
* Question 3:
*
* Roles: role1, role2
* Time-Slots: t0, t1
*
* if any of the rules are triggered it will show that some roles are allowed to be activated without a can assign
*/
Query: t0,[role2]
Expected: TRUE
CanAssign {
/* <Admin role,
* starting timeslot - end timeslot for admin role,
* role preconditions,
* [time slot rule gives role to user for, another time slot (optional)...],
* role to give to the user>
*/
<TRUE,t0,role1,t0,role2> //(1)
<TRUE,t0,role2,t0,role1> //(2)
/* Trying to include other time-slots to test with TRule */
<TRUE,t1,role1,t0,role2> //(3)
<TRUE,t1,role2,t0,role1> //(4)
}
CanRevoke {}
CanEnable {}
CanDisable {}
data/sharelatex/question2.spec
0 → 100644
View file @
c91ddee1
/*
* Question 2: Is time considered periodic?
*
* Roles: role1, role2, role3
* Time-Slots: t0
*
* rule 3 -> assign role 1 for t1 ->
* rule 2 -> assign role 2 to anyone with role 1 ->
* rule 1 -> assign role 3 to anyone with role 2
*/
Query: t2,[role3]
Expected: TRUE
CanAssign {
/* <Admin role,
* starting timeslot - end timeslot for admin role,
* role preconditions,
* [time slot rule gives role to user for, another time slot (optional)...],
* role to give to the user>
*/
<TRUE,t0,role2,t2,role3> //(1)
<TRUE,t1,role1,t0,role2> //(2)
<TRUE,t2,TRUE,t1,role1> //(3)
}
CanRevoke {}
CanEnable {}
CanDisable {}
src/mohawk/converter/ConverterInstance.java
View file @
c91ddee1
...
...
@@ -13,9 +13,9 @@ import mohawk.converter.helper.SpecHelper;
import
mohawk.converter.logging.MohawkCSVFileFormatter
;
import
mohawk.converter.logging.MohawkConsoleFormatter
;
import
mohawk.converter.logging.MohawkTiming
;
import
mohawk.converter.to.asaptime.ConvertToASAPTimeNSA
;
import
mohawk.converter.to.mohawk.ConvertToMohawk
;
import
mohawk.converter.to.ranise.ConvertToRanise
;
import
mohawk.converter.to.uzun.ConvertToUzun
;
import
mohawk.converter.to.tred.ConvertToTRedRule
;
import
org.apache.commons.cli.BasicParser
;
import
org.apache.commons.cli.CommandLine
;
...
...
@@ -92,7 +92,7 @@ public class ConverterInstance {
logger
.
info
(
"[CONVERTING] Converting to Rainse..."
);
/* Timing */
timing
.
startTimer
(
"convertToRanise ("
+
i
+
")"
);
ConvertTo
Ranise
toRanise
=
new
ConvertTo
Ranise
();
ConvertTo
ASAPTimeNSA
toRanise
=
new
ConvertTo
ASAPTimeNSA
();
String
raniseStr
=
toRanise
.
convert
(
parser
,
specFile
,
true
);
if
(
toRanise
.
lastError
==
null
)
{
...
...
@@ -113,7 +113,7 @@ public class ConverterInstance {
/* Timing */
timing
.
startTimer
(
"convertToUzun ("
+
i
+
")"
);
// TODO: Convert imported spec files to Uzun format
ConvertTo
Uzun
toUzun
=
new
ConvertTo
Uzun
();
ConvertTo
TRedRule
toUzun
=
new
ConvertTo
TRedRule
();
String
uzunStr
=
toUzun
.
convert
(
parser
,
specFile
,
true
);
if
(
toUzun
.
lastError
==
null
)
{
...
...
src/mohawk/converter/pieces/CanAssign.java
View file @
c91ddee1
package
mohawk.converter.pieces
;
public
class
CanAssign
extends
CanBlock
{
public
CanAssign
()
{
super
();
...
...
src/mohawk/converter/pieces/CanDisable.java
View file @
c91ddee1
package
mohawk.converter.pieces
;
public
class
CanDisable
extends
CanBlock
{
public
CanDisable
()
{
super
();
...
...
src/mohawk/converter/pieces/CanEnable.java
View file @
c91ddee1
package
mohawk.converter.pieces
;
public
class
CanEnable
extends
CanBlock
{
public
CanEnable
()
{
super
();
...
...
src/mohawk/converter/pieces/CanRevoke.java
View file @
c91ddee1
package
mohawk.converter.pieces
;
public
class
CanRevoke
extends
CanBlock
{
public
CanRevoke
()
{
super
();
...
...
src/mohawk/converter/pieces/rules/ASAPTimeNSA_Rule.java
0 → 100644
View file @
c91ddee1
package
mohawk.converter.pieces.rules
;
import
mohawk.converter.helper.RoleHelper
;
import
mohawk.converter.helper.TimeIntervalHelper
;
import
mohawk.converter.pieces.Role
;
import
mohawk.converter.pieces.Rule
;
public
class
ASAPTimeNSA_Rule
{
public
String
ruleType
;
public
Integer
startTime
;
public
Integer
finishTime
;
public
Integer
role
;
public
Integer
[]
precondition
;
public
Integer
[]
roleSchedule
;
public
ASAPTimeNSA_Rule
(
Rule
r
,
RoleHelper
rh
,
TimeIntervalHelper
tih
)
{
ruleType
=
r
.
_type
.
toUzun
();
startTime
=
r
.
_adminTimeInterval
.
getStartTime
();
finishTime
=
r
.
_adminTimeInterval
.
getFinishTime
();
role
=
rh
.
indexOf
(
r
.
_role
);
precondition
=
new
Integer
[
rh
.
size
()];
for
(
int
i
=
0
;
i
<
rh
.
size
();
i
++)
{
Role
role
=
rh
.
get
(
i
);
// Ignore
int
loc
=
r
.
_preconditions
.
indexOf
(
role
.
toLimitedRole
());
if
(
loc
!=
-
1
)
{
role
=
r
.
_preconditions
.
get
(
loc
);
if
(
role
.
_not
)
{
precondition
[
i
]
=
-
1
;
}
else
{
precondition
[
i
]
=
1
;
}
}
else
{
precondition
[
i
]
=
0
;
}
}
roleSchedule
=
new
Integer
[
tih
.
getNextTimeSlot
()];
for
(
Integer
i
=
0
;
i
<
roleSchedule
.
length
;
i
++)
{
if
(
r
.
_roleSchedule
.
contains
(
i
))
{
roleSchedule
[
i
]
=
1
;
}
else
{
roleSchedule
[
i
]
=
0
;
}
}
}
}
src/mohawk/converter/pieces/rules/ASAPTimeSA_Rule.java
0 → 100644
View file @
c91ddee1
package
mohawk.converter.pieces.rules
;
import
mohawk.converter.helper.RoleHelper
;
import
mohawk.converter.helper.TimeIntervalHelper
;
import
mohawk.converter.pieces.Role
;
import
mohawk.converter.pieces.Rule
;
public
class
ASAPTimeSA_Rule
{
public
String
ruleType
;
public
Integer
startTime
;
public
Integer
finishTime
;
public
Integer
role
;
public
Integer
[]
precondition
;
public
Integer
[]
roleSchedule
;
public
ASAPTimeSA_Rule
(
Rule
r
,
RoleHelper
rh
,
TimeIntervalHelper
tih
)
{
ruleType
=
r
.
_type
.
toUzun
();
startTime
=
r
.
_adminTimeInterval
.
getStartTime
();
finishTime
=
r
.
_adminTimeInterval
.
getFinishTime
();
role
=
rh
.
indexOf
(
r
.
_role
);
precondition
=
new
Integer
[
rh
.
size
()];
for
(
int
i
=
0
;
i
<
rh
.
size
();
i
++)
{
Role
role
=
rh
.
get
(
i
);
// Ignore
int
loc
=
r
.
_preconditions
.
indexOf
(
role
.
toLimitedRole
());
if
(
loc
!=
-
1
)
{
role
=
r
.
_preconditions
.
get
(
loc
);
if
(
role
.
_not
)
{
precondition
[
i
]
=
-
1
;
}
else
{
precondition
[
i
]
=
1
;
}
}
else
{
precondition
[
i
]
=
0
;
}
}
roleSchedule
=
new
Integer
[
tih
.
getNextTimeSlot
()];
for
(
Integer
i
=
0
;
i
<
roleSchedule
.
length
;
i
++)
{
if
(
r
.
_roleSchedule
.
contains
(
i
))
{
roleSchedule
[
i
]
=
1
;
}
else
{
roleSchedule
[
i
]
=
0
;
}
}
}
}
src/mohawk/converter/pieces/
Uzun
Rule.java
→
src/mohawk/converter/pieces/
rules/Mohawk_
Rule.java
View file @
c91ddee1
package
mohawk.converter.pieces
;
package
mohawk.converter.pieces
.rules
;
import
mohawk.converter.helper.RoleHelper
;
import
mohawk.converter.helper.TimeIntervalHelper
;
import
mohawk.converter.pieces.Role
;
import
mohawk.converter.pieces.Rule
;
public
class
Uzun
Rule
{
public
class
Mohawk_
Rule
{
public
String
ruleType
;
public
Integer
startTime
;
public
Integer
finishTime
;
...
...
@@ -11,7 +13,7 @@ public class UzunRule {
public
Integer
[]
precondition
;
public
Integer
[]
roleSchedule
;
public
Uzun
Rule
(
Rule
r
,
RoleHelper
rh
,
TimeIntervalHelper
tih
)
{
public
Mohawk_
Rule
(
Rule
r
,
RoleHelper
rh
,
TimeIntervalHelper
tih
)
{
ruleType
=
r
.
_type
.
toUzun
();
startTime
=
r
.
_adminTimeInterval
.
getStartTime
();
finishTime
=
r
.
_adminTimeInterval
.
getFinishTime
();
...
...
src/mohawk/converter/pieces/rules/TRedRole_Rule.java
0 → 100644
View file @
c91ddee1
package
mohawk.converter.pieces.rules
;
import
mohawk.converter.helper.RoleHelper
;
import
mohawk.converter.helper.TimeIntervalHelper
;
import
mohawk.converter.pieces.Role
;
import
mohawk.converter.pieces.Rule
;
public
class
TRedRole_Rule
{
public
String
ruleType
;
public
Integer
startTime
;
public
Integer
finishTime
;
public
Integer
role
;
public
Integer
[]
precondition
;
public
Integer
[]
roleSchedule
;
public
TRedRole_Rule
(
Rule
r
,
RoleHelper
rh
,
TimeIntervalHelper
tih
)
{
ruleType
=
r
.
_type
.
toUzun
();
startTime
=
r
.
_adminTimeInterval
.
getStartTime
();
finishTime
=
r
.
_adminTimeInterval
.
getFinishTime
();
role
=
rh
.
indexOf
(
r
.
_role
);
precondition
=
new
Integer
[
rh
.
size
()];
for
(
int
i
=
0
;
i
<
rh
.
size
();
i
++)
{
Role
role
=
rh
.
get
(
i
);
// Ignore
int
loc
=
r
.
_preconditions
.
indexOf
(
role
.
toLimitedRole
());
if
(
loc
!=
-
1
)
{
role
=
r
.
_preconditions
.
get
(
loc
);
if
(
role
.
_not
)
{
precondition
[
i
]
=
-
1
;
}
else
{
precondition
[
i
]
=
1
;
}
}
else
{
precondition
[
i
]
=
0
;
}
}
roleSchedule
=
new
Integer
[
tih
.
getNextTimeSlot
()];
for
(
Integer
i
=
0
;
i
<
roleSchedule
.
length
;
i
++)
{
if
(
r
.
_roleSchedule
.
contains
(
i
))
{
roleSchedule
[
i
]
=
1
;
}
else
{
roleSchedule
[
i
]
=
0
;
}
}
}
}
src/mohawk/converter/pieces/rules/TRedRule_Rule.java
0 → 100644
View file @
c91ddee1
package
mohawk.converter.pieces.rules
;
import
mohawk.converter.helper.RoleHelper
;
import
mohawk.converter.helper.TimeIntervalHelper
;
import
mohawk.converter.pieces.Role
;
import
mohawk.converter.pieces.Rule
;
public
class
TRedRule_Rule
{
public
String
ruleType
;
public
Integer
startTime
;
public
Integer
finishTime
;
public
Integer
role
;
public
Integer
[]
precondition
;
public
Integer
[]
roleSchedule
;
public
TRedRule_Rule
(
Rule
r
,
RoleHelper
rh
,
TimeIntervalHelper
tih
)
{
ruleType
=
r
.
_type
.
toUzun
();
startTime
=
r
.
_adminTimeInterval
.
getStartTime
();
finishTime
=
r
.
_adminTimeInterval
.
getFinishTime
();
role
=
rh
.
indexOf
(
r
.
_role
);
precondition
=
new
Integer
[
rh
.
size
()];
for
(
int
i
=
0
;
i
<
rh
.
size
();
i
++)
{
Role
role
=
rh
.
get
(
i
);
// Ignore
int
loc
=
r
.
_preconditions
.
indexOf
(
role
.
toLimitedRole
());
if
(
loc
!=
-
1
)
{
role
=
r
.
_preconditions
.
get
(
loc
);
if
(
role
.
_not
)
{
precondition
[
i
]
=
-
1
;
}
else
{
precondition
[
i
]
=
1
;
}
}
else
{
precondition
[
i
]
=
0
;
}
}
roleSchedule
=
new
Integer
[
tih
.
getNextTimeSlot
()];
for
(
Integer
i
=
0
;
i
<
roleSchedule
.
length
;
i
++)
{
if
(
r
.
_roleSchedule
.
contains
(
i
))
{
roleSchedule
[
i
]
=
1
;
}
else
{
roleSchedule
[
i
]
=
0
;
}
}
}
}
src/mohawk/converter/testing/RegressionTests.java
View file @
c91ddee1
...
...
@@ -2,6 +2,7 @@ package mohawk.converter.testing;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
java.io.ByteArrayInputStream
;
...
...
@@ -15,6 +16,7 @@ import mohawk.converter.generated.MohawkTARBACLexer;
import
mohawk.converter.generated.MohawkTARBACParser
;
import
mohawk.converter.pieces.Rule
;
import
mohawk.converter.pieces.TimeInterval
;
import
mohawk.global.FileExtensions
;
import
org.antlr.v4.runtime.ANTLRInputStream
;
import
org.antlr.v4.runtime.BaseErrorListener
;
...
...
@@ -64,7 +66,7 @@ public class RegressionTests {
// t0, t1, t2, t5
assertEquals
(
"Incorrect number of Timeslots"
,
new
Integer
(
4
),
parser
.
timeIntervalHelper
.
size
());
// t0, t1, t2, t5
assertEquals
(
"Incorrect max Timeslot"
,
new
Integer
(
5
),
parser
.
timeIntervalHelper
.
getNumberOf
TimeSlot
s
()
);
assertEquals
(
"Incorrect max Timeslot"
,
new
Integer
(
5
),
parser
.
timeIntervalHelper
.
max
TimeSlot
);
}
@Test
...
...
@@ -89,7 +91,7 @@ public class RegressionTests {
// t0, t1, t2, t5
assertEquals
(
"Incorrect number of Timeslots"
,
new
Integer
(
4
),
parser
.
timeIntervalHelper
.
size
());
// t0, t1, t2, t5
assertEquals
(
"Incorrect max Timeslot"
,
new
Integer
(
5
),
parser
.
timeIntervalHelper
.
getNumberOf
TimeSlot
s
()
);
assertEquals
(
"Incorrect max Timeslot"
,
new
Integer
(
5
),
parser
.
timeIntervalHelper
.
max
TimeSlot
);
}
@Test
...
...
@@ -114,7 +116,7 @@ public class RegressionTests {
// t0, t1, t2, t5
assertEquals
(
"Incorrect number of Timeslots"
,
new
Integer
(
4
),
parser
.
timeIntervalHelper
.
size
());
// t0, t1, t2, t5
assertEquals
(
"Incorrect max Timeslot"
,
new
Integer
(
5
),
parser
.
timeIntervalHelper
.
getNumberOf
TimeSlot
s
()
);
assertEquals
(
"Incorrect max Timeslot"
,
new
Integer
(
5
),
parser
.
timeIntervalHelper
.
max
TimeSlot
);
}
@Test
...
...
@@ -158,6 +160,20 @@ public class RegressionTests {
}
@Test
public
void
checkFileExtension
()
{
System
.
out
.
println
(
"Checking to make sure FileExtensions is included "
+
"(This is mainly for developing and including the Mohawk-T Globals project)"
);
try
{
FileExtensions
fe
=
new
FileExtensions
();
assertNotNull
(
"FileExtensions was not included!"
,
fe
);
}
catch
(
Exception
e
)
{
assertFalse
(
"An exception was raised when trying to create the object FileExtension!\n"
+
"Make sure you have included the Mohawk-T Globals project when building the jar"
,
true
);
}
}
@Test
public
void
runNegative0
()
throws
IOException
{
System
.
out
.
println
(
"Running Test: runNegative0\n\n"
);
...
...
src/mohawk/converter/to/
ranise/ranise
Template.st
→
src/mohawk/converter/to/
asaptime/ASAPTimeNSA
Template.st
View file @
c91ddee1
File moved
src/mohawk/converter/to/asaptime/ASAPTimeSATemplate.st
0 → 100644
View file @
c91ddee1
<
!
Conversion
to
Ranise
'
s
Input
Format
!>
CONFIG
<
numRoles
>
<
numTimeslots
>
GOAL
<
goalRole
>
<
goalTimeslot
>
<
!
can_revoke
3
,
t3
,
true
;
t5
,
14
!>
<
rules
;
separator=
"\n"
>
\ No newline at end of file
src/mohawk/converter/to/asaptime/ConvertToASAPTimeNSA.java
0 → 100644
View file @
c91ddee1
package
mohawk.converter.to.asaptime
;
import
java.io.File
;
import
java.io.PrintWriter
;
import
java.io.StringWriter
;
import
java.nio.charset.Charset
;
import
java.nio.file.Files
;
import
java.util.logging.Logger
;
import
mohawk.converter.generated.MohawkTARBACParser
;
import
mohawk.converter.to.ConvertTo
;
import
org.stringtemplate.v4.ST
;
public
class
ConvertToASAPTimeNSA
extends
ConvertTo
{
public
static
final
Logger
logger
=
Logger
.
getLogger
(
"mohawk-converter"
);
@Override
public
String
convert
(
MohawkTARBACParser
p
,
File
f
,
Boolean
writeToFile
)
{
try
{
String
template
=
ConvertTo
.
readFile
(
this
.
getClass
().
getResource
(
"ASAPTimeNSATemplate.st"
),
Charset
.
defaultCharset
());
ST
st
=
new
ST
(
template
);
st
.
add
(
"numRoles"
,
p
.
roleHelper
.
size
());
st
.
add
(
"numTimeslots"
,
p
.
timeIntervalHelper
.
size
());
st
.
add
(
"goalRole"
,
null
);
st
.
add
(
"goalTimeslot"
,
null
);
convertedStr
=
st
.
render
();
if
(
writeToFile
)
{
File
convertedFile
=
new
File
(
f
.
getAbsolutePath
()
+
getFileExtenstion
());
if
(!
convertedFile
.
exists
())
{
convertedFile
.
createNewFile
();
}
Files
.
write
(
convertedFile
.
toPath
(),
convertedStr
.
getBytes
());
}
lastError
=
null
;
}
catch
(
Exception
e
)
{
StringWriter
errors
=
new
StringWriter
();
e
.
printStackTrace
(
new
PrintWriter
(
errors
));
logger
.
fine
(
errors
.
toString
());
logger
.
warning
(
"[ERROR] Unable to convert to Ranise: "
+
e
.
getMessage
());
lastError
=
"Error ConvertToRanise.convert.Exception #1"
;
}
return
convertedStr
;
}
@Override
public
String
getFileExtenstion
()
{
return
".ranise"
;
}
}
Prev
1
2
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment