Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Simonstrator
API
Commits
dedd4810
Commit
dedd4810
authored
Mar 26, 2019
by
Tobias Meuser
Browse files
Added web runner functionality
parent
4f115f12
Changes
6
Hide whitespace changes
Inline
Side-by-side
src/de/tudarmstadt/maki/simonstrator/api/web/Scenario.java
0 → 100755
View file @
dedd4810
package
de.tudarmstadt.maki.simonstrator.api.web
;
import
java.util.ArrayList
;
import
java.util.List
;
import
javax.xml.bind.annotation.XmlAccessType
;
import
javax.xml.bind.annotation.XmlAccessorType
;
import
javax.xml.bind.annotation.XmlElement
;
import
javax.xml.bind.annotation.XmlElementWrapper
;
import
de.tudarmstadt.maki.simonstrator.api.web.approach.Approach
;
import
de.tudarmstadt.maki.simonstrator.api.web.parameter.Parameter
;
@XmlAccessorType
(
XmlAccessType
.
FIELD
)
public
class
Scenario
{
@XmlElement
(
name
=
"name"
)
private
String
_name
;
@XmlElement
(
name
=
"config"
)
private
String
_config
;
@XmlElementWrapper
(
name
=
"approaches"
)
@XmlElement
(
name
=
"approach"
)
List
<
Approach
>
_approaches
=
new
ArrayList
<>();
@XmlElementWrapper
(
name
=
"parameters"
)
@XmlElement
(
name
=
"parameter"
)
List
<
Parameter
>
_parameters
=
new
ArrayList
<>();
public
Scenario
()
{
}
public
Scenario
(
String
pName
,
String
pConfig
)
{
_name
=
pName
;
_config
=
pConfig
;
}
public
void
setName
(
String
pName
)
{
_name
=
pName
;
}
public
void
setConfig
(
String
pConfig
)
{
_config
=
pConfig
;
}
public
String
getName
()
{
return
_name
;
}
public
String
getConfig
()
{
return
_config
;
}
public
void
addApproach
(
Approach
pApproach
)
{
_approaches
.
add
(
pApproach
);
}
public
List
<
Approach
>
getApproaches
()
{
return
_approaches
;
}
public
void
addParameter
(
Parameter
pParameter
)
{
_parameters
.
add
(
pParameter
);
}
public
List
<
Parameter
>
getParameters
()
{
return
_parameters
;
}
public
Approach
getApproach
(
String
pName
)
{
for
(
Approach
approach
:
_approaches
)
{
if
(
approach
.
getName
().
equals
(
pName
))
{
return
approach
;
}
}
return
null
;
}
public
Parameter
getParameter
(
String
pName
)
{
for
(
Parameter
parameter
:
_parameters
)
{
if
(
parameter
.
getName
().
equals
(
pName
))
{
return
parameter
;
}
}
return
null
;
}
}
\ No newline at end of file
src/de/tudarmstadt/maki/simonstrator/api/web/WebConfiguration.java
0 → 100755
View file @
dedd4810
package
de.tudarmstadt.maki.simonstrator.api.web
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.List
;
import
javax.xml.bind.JAXBContext
;
import
javax.xml.bind.JAXBException
;
import
javax.xml.bind.Marshaller
;
import
javax.xml.bind.Unmarshaller
;
import
javax.xml.bind.annotation.XmlElement
;
import
javax.xml.bind.annotation.XmlElementWrapper
;
import
javax.xml.bind.annotation.XmlRootElement
;
import
de.tudarmstadt.maki.simonstrator.api.web.options.WebRunnerOptions
;
@XmlRootElement
(
name
=
"configuration"
)
public
class
WebConfiguration
{
@XmlElementWrapper
(
name
=
"scenarios"
)
@XmlElement
(
name
=
"scenario"
)
List
<
Scenario
>
_scenarios
=
new
ArrayList
<>();
@XmlElement
(
name
=
"options"
)
WebRunnerOptions
_options
=
new
WebRunnerOptions
();
public
Scenario
createScenario
(
String
pName
,
String
pConfig
)
{
return
new
Scenario
(
pName
,
pConfig
);
}
public
void
addScenario
(
Scenario
pScenario
)
{
if
(
getScenario
(
pScenario
.
getName
())
!=
null
)
{
_scenarios
.
remove
(
getScenario
(
pScenario
.
getName
()));
}
_scenarios
.
add
(
pScenario
);
}
public
List
<
Scenario
>
getScenarios
()
{
return
_scenarios
;
}
public
WebRunnerOptions
getOptions
()
{
if
(
_options
==
null
)
{
_options
=
new
WebRunnerOptions
();
}
return
_options
;
}
public
boolean
store
(
File
pScenarioFile
)
{
try
{
JAXBContext
context
=
JAXBContext
.
newInstance
(
WebConfiguration
.
class
);
Marshaller
marshaller
=
context
.
createMarshaller
();
FileOutputStream
output
=
new
FileOutputStream
(
pScenarioFile
);
marshaller
.
marshal
(
this
,
output
);
output
.
flush
();
output
.
close
();
return
true
;
}
catch
(
JAXBException
|
IOException
e
)
{
e
.
printStackTrace
();
return
false
;
}
}
public
static
WebConfiguration
load
(
File
pScenarioFile
)
{
try
{
JAXBContext
context
=
JAXBContext
.
newInstance
(
WebConfiguration
.
class
);
Unmarshaller
unmarshaller
=
context
.
createUnmarshaller
();
FileInputStream
input
=
new
FileInputStream
(
pScenarioFile
);
return
(
WebConfiguration
)
unmarshaller
.
unmarshal
(
input
);
}
catch
(
JAXBException
|
IOException
e
)
{
e
.
printStackTrace
();
return
null
;
}
}
public
Scenario
getScenario
(
String
pScenario
)
{
for
(
Scenario
scenario
:
_scenarios
)
{
if
(
scenario
.
getName
().
equals
(
pScenario
))
{
return
scenario
;
}
}
return
null
;
}
}
src/de/tudarmstadt/maki/simonstrator/api/web/WebConfigurationManager.java
0 → 100755
View file @
dedd4810
package
de.tudarmstadt.maki.simonstrator.api.web
;
import
java.io.File
;
public
class
WebConfigurationManager
{
private
static
final
File
CONFIGURATION_FILE
=
new
File
(
new
File
(
"assets/web/"
),
"configuration.xml"
);
private
static
final
WebConfigurationManager
INSTANCE
=
new
WebConfigurationManager
();
private
static
boolean
ACTIVE
;
private
WebConfiguration
_config
;
public
static
WebConfigurationManager
getInstance
()
{
return
INSTANCE
;
}
public
WebConfigurationManager
()
{
File
folder
=
CONFIGURATION_FILE
.
getParentFile
();
if
(!
folder
.
exists
())
{
if
(!
folder
.
mkdirs
())
{
throw
new
AssertionError
(
"Could not create file: "
+
folder
.
getAbsolutePath
());
}
}
if
(!
CONFIGURATION_FILE
.
exists
())
{
_config
=
new
WebConfiguration
();
store
();
}
_config
=
WebConfiguration
.
load
(
CONFIGURATION_FILE
);
}
public
static
WebConfiguration
getConfig
()
{
return
INSTANCE
.
_config
;
}
public
static
void
storeConfig
()
{
INSTANCE
.
_config
.
store
(
CONFIGURATION_FILE
);
}
public
void
store
()
{
_config
.
store
(
CONFIGURATION_FILE
);
}
public
static
void
setActive
()
{
ACTIVE
=
true
;
}
public
static
boolean
isActive
()
{
return
ACTIVE
;
}
}
src/de/tudarmstadt/maki/simonstrator/api/web/approach/Approach.java
0 → 100755
View file @
dedd4810
package
de.tudarmstadt.maki.simonstrator.api.web.approach
;
import
java.util.HashMap
;
import
java.util.Map
;
import
javax.xml.bind.annotation.XmlAccessType
;
import
javax.xml.bind.annotation.XmlAccessorType
;
import
javax.xml.bind.annotation.XmlElement
;
import
javax.xml.bind.annotation.XmlElementWrapper
;
@XmlAccessorType
(
XmlAccessType
.
FIELD
)
public
class
Approach
{
public
enum
ApproachType
{
OWN
,
BASELINE
,
REFERENCE
;
}
@XmlElement
(
name
=
"name"
)
private
String
_name
;
@XmlElement
(
name
=
"type"
)
private
ApproachType
_type
=
ApproachType
.
REFERENCE
;
@XmlElementWrapper
(
name
=
"variables"
)
@XmlElement
(
name
=
"variables"
)
private
Map
<
String
,
String
>
_variables
=
new
HashMap
<>();
public
Approach
()
{
}
public
Approach
(
String
pName
,
ApproachType
pType
)
{
_name
=
pName
;
_type
=
pType
;
}
public
String
getName
()
{
return
_name
;
}
public
Map
<
String
,
String
>
getVariables
()
{
return
_variables
;
}
public
void
addVariable
(
String
pKey
,
String
pValue
)
{
_variables
.
put
(
pKey
,
pValue
);
}
public
void
setName
(
String
pName
)
{
_name
=
pName
;
}
public
ApproachType
getType
()
{
return
_type
;
}
public
void
setType
(
ApproachType
pType
)
{
_type
=
pType
;
}
public
void
clearVariables
()
{
_variables
.
clear
();
}
}
src/de/tudarmstadt/maki/simonstrator/api/web/options/WebRunnerOptions.java
0 → 100755
View file @
dedd4810
package
de.tudarmstadt.maki.simonstrator.api.web.options
;
import
javax.xml.bind.annotation.XmlElement
;
public
class
WebRunnerOptions
{
@XmlElement
(
name
=
"processes"
)
private
int
_numberOfProcesses
=
1
;
@XmlElement
(
name
=
"username"
)
private
String
username
;
@XmlElement
(
name
=
"password"
)
private
String
password
;
@XmlElement
(
name
=
"database"
)
private
String
database
;
public
int
getNumberOfProcesses
()
{
return
_numberOfProcesses
;
}
public
void
setNumberOfProcesses
(
int
pNumberOfProcesses
)
{
_numberOfProcesses
=
pNumberOfProcesses
;
}
public
String
getUsername
()
{
return
username
;
}
public
void
setUsername
(
String
pUsername
)
{
username
=
pUsername
;
}
public
String
getPassword
()
{
return
password
;
}
public
void
setPassword
(
String
pPassword
)
{
password
=
pPassword
;
}
public
String
getDatabase
()
{
return
database
;
}
public
void
setDatabase
(
String
pDatabase
)
{
database
=
pDatabase
;
}
}
src/de/tudarmstadt/maki/simonstrator/api/web/parameter/Parameter.java
0 → 100755
View file @
dedd4810
package
de.tudarmstadt.maki.simonstrator.api.web.parameter
;
import
java.util.ArrayList
;
import
java.util.List
;
import
javax.xml.bind.annotation.XmlAccessType
;
import
javax.xml.bind.annotation.XmlAccessorType
;
import
javax.xml.bind.annotation.XmlElement
;
import
javax.xml.bind.annotation.XmlElementWrapper
;
@XmlAccessorType
(
XmlAccessType
.
FIELD
)
public
class
Parameter
{
@XmlElement
(
name
=
"name"
)
private
String
_name
;
@XmlElementWrapper
(
name
=
"values"
)
@XmlElement
(
name
=
"value"
)
private
List
<
String
>
_values
=
new
ArrayList
<>();
private
int
_defaultIndex
;
public
Parameter
()
{
}
public
Parameter
(
String
pName
)
{
_name
=
pName
;
}
public
String
getName
()
{
return
_name
;
}
public
List
<
String
>
getValues
()
{
return
_values
;
}
public
void
addValue
(
String
pValue
)
{
_values
.
add
(
pValue
);
}
public
void
setName
(
String
pName
)
{
_name
=
pName
;
}
public
void
clearValues
()
{
_values
.
clear
();
}
public
void
setDefault
(
int
pDefaultIndex
)
{
_defaultIndex
=
pDefaultIndex
;
}
public
int
getDefaultIndex
()
{
return
_defaultIndex
;
}
}
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