Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Eric Duminil
RegionChooser
Commits
82952470
Commit
82952470
authored
Dec 10, 2014
by
bruse
Browse files
Introduced some convenience methods for the Job class.
parent
20454d45
Changes
11
Hide whitespace changes
Inline
Side-by-side
src/eu/simstadt/nf4j/ExportJob.java
View file @
82952470
package
eu.simstadt.nf4j
;
package
eu.simstadt.nf4j
;
import
java.io.File
;
import
java.util.Objects
;
import
java.util.Objects
;
/**
/**
...
@@ -7,37 +8,33 @@
...
@@ -7,37 +8,33 @@
*
*
* @author Marcel Bruse
* @author Marcel Bruse
*/
*/
public
class
ExportJob
extends
Job
{
public
class
ExportJob
extends
Job
<
ExportJobDescriptorImpl
>
{
/**
* Initializes a new export job instance with unknown state. This is a convenient method.
*
* @return Returns a new export job instance with unknown state.
*/
public
static
ExportJob
getNewInstance
()
{
return
new
ExportJob
(
JobStatus
.
UNKOWN
);
}
/**
/**
* Initializes a new export job instance with unknown state and connector instance. This is a
* This constructor forces the job to have a description and a connector instance. Every job which
* convenient method.
* is created by this constructor will have the status "local", because it is assumed that it has an unsent
* description and no job id yet.
*
*
* @param
The nF
connector
which answers status requests for this job
.
* @param connector
The job will use this connector to synchronize itself with the nF
.
* @
return Returns a new export job instance with unknown state
.
* @
param descriptor The description of this job
.
*/
*/
public
static
ExportJob
getNewInstance
(
NFConnector
<?,
?>
nFConnector
)
{
public
ExportJob
(
ExportJobDescriptorImpl
descriptor
,
NFConnector
connector
)
{
ExportJob
result
=
getNewInstance
();
super
(
descriptor
,
connector
);
result
.
setNFConnector
(
nFConnector
);
status
=
JobStatus
.
LOCAL
;
return
result
;
}
}
/**
/**
* This constructor forces the job to have a defined state.
* This constructor forces the job to have a id and a connector instance. Every job which is created by this
* constructor will have the status "sent", because it is assumed that the job is already enqueued at the
* nF job queue.
*
*
* @param status
* @param id The job id. If you call updateStatus() and the nF "knows" the job id, then the job status
* will be updated. If you call updateStatus() and the job id is "unkown" on the server side, then
* @param connector The job will use this connector to synchronize itself with the nF.
*/
*/
public
ExportJob
(
JobStatus
status
)
{
public
ExportJob
(
int
id
,
NFConnector
connector
)
{
super
(
status
);
super
(
id
,
connector
);
status
=
JobStatus
.
SENT
;
}
}
/**
/**
...
@@ -48,7 +45,7 @@ public ExportJob(JobStatus status) {
...
@@ -48,7 +45,7 @@ public ExportJob(JobStatus status) {
*/
*/
public
void
updateStatus
()
throws
FailedTransmissionException
{
public
void
updateStatus
()
throws
FailedTransmissionException
{
if
(
Objects
.
nonNull
(
getNFConnector
()))
{
if
(
Objects
.
nonNull
(
getNFConnector
()))
{
Job
job
=
getNFConnector
().
requestExportJob
(
get
Job
Id
());
Job
<
ExportJobDescriptorImpl
>
job
=
getNFConnector
().
requestExportJob
(
getId
());
setStatus
(
job
.
getStatus
());
setStatus
(
job
.
getStatus
());
}
else
{
}
else
{
throw
new
FailedTransmissionException
();
throw
new
FailedTransmissionException
();
...
@@ -83,5 +80,17 @@ public void setStatusForCode(int statusCode) {
...
@@ -83,5 +80,17 @@ public void setStatusForCode(int statusCode) {
public
boolean
isFinished
()
{
public
boolean
isFinished
()
{
return
Objects
.
nonNull
(
getStatus
())
&&
getStatus
().
equals
(
JobStatus
.
FINISHED
);
return
Objects
.
nonNull
(
getStatus
())
&&
getStatus
().
equals
(
JobStatus
.
FINISHED
);
}
}
@Override
public
void
send
()
throws
InvalidJobDescriptorException
,
FailedTransmissionException
{
connector
.
sendAndUpdateExportJob
(
this
);
}
public
File
requestExportJobResult
()
throws
FailedTransmissionException
{
if
(!
isFinished
())
{
throw
new
FailedTransmissionException
(
"Job is not finished yet!"
);
}
return
connector
.
requestExportJobResult
(
id
);
}
}
}
src/eu/simstadt/nf4j/ExportJobDescriptorImpl.java
View file @
82952470
...
@@ -42,14 +42,6 @@ public class ExportJobDescriptorImpl implements ExportJobDescriptor {
...
@@ -42,14 +42,6 @@ public class ExportJobDescriptorImpl implements ExportJobDescriptor {
private
static
final
String
DEFAULT_MERGE_MAP_SHEETS
=
"off"
;
private
static
final
String
DEFAULT_MERGE_MAP_SHEETS
=
"off"
;
private
static
final
String
DEFAULT_TILE1ASGN
=
"false"
;
private
static
final
String
DEFAULT_TILE1ASGN
=
"false"
;
private
static
final
String
DEFAULT_EXTERIOR
=
"0"
;
private
static
final
String
DEFAULT_FRAME
=
"0"
;
private
static
final
String
DEFAULT_SELECT_MAP_SHEETS
=
"0"
;
private
static
final
String
DEFAULT_SUBDIVISION
=
"4"
;
private
static
final
String
DEFAULT_SRS
=
"31467"
;
private
static
final
String
DEFAULT_SRS
=
"31467"
;
...
@@ -109,20 +101,8 @@ public class ExportJobDescriptorImpl implements ExportJobDescriptor {
...
@@ -109,20 +101,8 @@ public class ExportJobDescriptorImpl implements ExportJobDescriptor {
/** The tile1asgn attribute of the extent tag. */
/** The tile1asgn attribute of the extent tag. */
private
String
tile1asgn
;
private
String
tile1asgn
;
/** The exterior attribute of the unit tag. */
private
String
exterior
;
/** The frame attribute of the unit tag. */
private
String
frame
;
/** The select mapsheet attribute of the unit tag. */
private
String
selectMapsheets
;
/** The subdivision attribute of the unit tag. */
private
String
subdivision
;
/** The unit tag of the extent. */
/** The unit tag of the extent. */
private
String
unit
;
private
ArrayList
<
Unit
>
unitList
=
new
ArrayList
<>()
;
/** The polygon of the selected region which should be exported. */
/** The polygon of the selected region which should be exported. */
ArrayList
<
Coord
>
regionPolygon
=
new
ArrayList
<>();
ArrayList
<
Coord
>
regionPolygon
=
new
ArrayList
<>();
...
@@ -263,20 +243,12 @@ public void setMergeMapsheets(String mergeMapsheets) {
...
@@ -263,20 +243,12 @@ public void setMergeMapsheets(String mergeMapsheets) {
this
.
mergeMapsheets
=
mergeMapsheets
;
this
.
mergeMapsheets
=
mergeMapsheets
;
}
}
public
String
getUnit
()
{
public
ArrayList
<
Unit
>
getUnit
List
()
{
return
unit
;
return
unit
List
;
}
}
public
void
setUnit
(
String
unit
)
{
public
void
addUnit
(
Unit
unit
)
{
this
.
unit
=
unit
;
unitList
.
add
(
unit
);
}
public
String
getExterior
()
{
return
exterior
;
}
public
void
setExterior
(
String
exterior
)
{
this
.
exterior
=
exterior
;
}
}
public
String
getTile1asgn
()
{
public
String
getTile1asgn
()
{
...
@@ -286,30 +258,6 @@ public String getTile1asgn() {
...
@@ -286,30 +258,6 @@ public String getTile1asgn() {
public
void
setTile1asgn
(
String
tile1asgn
)
{
public
void
setTile1asgn
(
String
tile1asgn
)
{
this
.
tile1asgn
=
tile1asgn
;
this
.
tile1asgn
=
tile1asgn
;
}
}
public
String
getFrame
()
{
return
frame
;
}
public
void
setFrame
(
String
frame
)
{
this
.
frame
=
frame
;
}
public
String
getSelectMapsheets
()
{
return
selectMapsheets
;
}
public
void
setSelectMapsheets
(
String
selectMapsheets
)
{
this
.
selectMapsheets
=
selectMapsheets
;
}
public
String
getSubdivision
()
{
return
subdivision
;
}
public
void
setSubdivision
(
String
subdivision
)
{
this
.
subdivision
=
subdivision
;
}
public
String
getResolution
()
{
public
String
getResolution
()
{
return
resolution
;
return
resolution
;
...
@@ -443,13 +391,7 @@ public ArrayList<Coord> getRegionPolygon() {
...
@@ -443,13 +391,7 @@ public ArrayList<Coord> getRegionPolygon() {
*/
*/
@Override
@Override
public
boolean
isValid
()
{
public
boolean
isValid
()
{
if
((
regionPolygon
.
isEmpty
()
if
((
regionPolygon
.
isEmpty
()
&&
(
unitList
.
isEmpty
()))
&&
(
unit
.
isEmpty
()
||
exterior
.
isEmpty
()
||
frame
.
isEmpty
()
||
selectMapsheets
.
isEmpty
()
||
subdivision
.
isEmpty
()
))
||
layerList
.
isEmpty
()
||
layerList
.
isEmpty
()
||
initiator
.
isEmpty
()
||
initiator
.
isEmpty
()
||
account
.
isEmpty
()
||
account
.
isEmpty
()
...
@@ -486,11 +428,7 @@ public static ExportJobDescriptorImpl getDefaultDescriptor() {
...
@@ -486,11 +428,7 @@ public static ExportJobDescriptorImpl getDefaultDescriptor() {
descriptor
.
setSingle
(
DEFAULT_SINGLE
);
descriptor
.
setSingle
(
DEFAULT_SINGLE
);
descriptor
.
setSrs
(
DEFAULT_SRS
);
descriptor
.
setSrs
(
DEFAULT_SRS
);
descriptor
.
setMergeMapsheets
(
DEFAULT_MERGE_MAP_SHEETS
);
descriptor
.
setMergeMapsheets
(
DEFAULT_MERGE_MAP_SHEETS
);
descriptor
.
setExterior
(
DEFAULT_EXTERIOR
);
descriptor
.
setTile1asgn
(
DEFAULT_TILE1ASGN
);
descriptor
.
setTile1asgn
(
DEFAULT_TILE1ASGN
);
descriptor
.
setFrame
(
DEFAULT_FRAME
);
descriptor
.
setSelectMapsheets
(
DEFAULT_SELECT_MAP_SHEETS
);
descriptor
.
setSubdivision
(
DEFAULT_SUBDIVISION
);
descriptor
.
setResolution
(
DEFAULT_RESOLUTION
);
descriptor
.
setResolution
(
DEFAULT_RESOLUTION
);
descriptor
.
setScale
(
DEFAULT_SCALE
);
descriptor
.
setScale
(
DEFAULT_SCALE
);
descriptor
.
setFormat
(
DEFAULT_FORMAT
);
descriptor
.
setFormat
(
DEFAULT_FORMAT
);
...
...
src/eu/simstadt/nf4j/ImportJob.java
View file @
82952470
...
@@ -7,37 +7,33 @@
...
@@ -7,37 +7,33 @@
*
*
* @author Marcel Bruse
* @author Marcel Bruse
*/
*/
public
class
ImportJob
extends
Job
{
public
class
ImportJob
extends
Job
<
ImportJobDescriptorImpl
>
{
/**
/**
* Initializes a new import job instance with unknown state. This is a convenient method.
* This constructor forces the job to have a description and a connector instance. Every job which
* is created by this constructor will have the status "local", because it is assumed that it has an unsent
* description and no job id yet.
*
*
* @return Returns a new import job instance with unknown state.
* @param connector The job will use this connector to synchronize itself with the nF.
* @param descriptor The description of this job.
*/
*/
public
static
ImportJob
getNewInstance
()
{
public
ImportJob
(
ImportJobDescriptorImpl
descriptor
,
NFConnector
connector
)
{
return
new
ImportJob
(
JobStatus
.
UNKOWN
);
super
(
descriptor
,
connector
);
status
=
JobStatus
.
LOCAL
;
}
}
/**
/**
* Initializes a new import job instance with unknown state and connector instance. This is a
* This constructor forces the job to have a id and a connector instance. Every job which is created by this
* convenient method.
* constructor will have the status "sent", because it is assumed that the job is already enqueued at the
* nF job queue.
*
*
* @param The nF connector which answers status requests for this job.
* @param id The job id. If you call updateStatus() and the nF "knows" the job id, then the job status
* @return Returns a new import job instance with unknown state.
* will be updated. If you call updateStatus() and the job id is "unkown" on the server side, then
* @param connector The job will use this connector to synchronize itself with the nF.
*/
*/
public
static
ImportJob
getNewInstance
(
NFConnector
<?,
?>
nFConnector
)
{
public
ImportJob
(
int
id
,
NFConnector
connector
)
{
ImportJob
result
=
getNewInstance
();
super
(
id
,
connector
);
result
.
setNFConnector
(
nFConnector
);
status
=
JobStatus
.
SENT
;
return
result
;
}
/**
* This constructor forces the job to have a defined state.
*
* @param status
*/
public
ImportJob
(
JobStatus
status
)
{
super
(
status
);
}
}
/**
/**
...
@@ -48,7 +44,7 @@ public ImportJob(JobStatus status) {
...
@@ -48,7 +44,7 @@ public ImportJob(JobStatus status) {
*/
*/
public
void
updateStatus
()
throws
FailedTransmissionException
{
public
void
updateStatus
()
throws
FailedTransmissionException
{
if
(
Objects
.
nonNull
(
getNFConnector
()))
{
if
(
Objects
.
nonNull
(
getNFConnector
()))
{
Job
job
=
getNFConnector
().
requestImportJob
(
get
Job
Id
());
Job
<
ImportJobDescriptorImpl
>
job
=
getNFConnector
().
requestImportJob
(
getId
());
setStatus
(
job
.
getStatus
());
setStatus
(
job
.
getStatus
());
}
else
{
}
else
{
throw
new
FailedTransmissionException
();
throw
new
FailedTransmissionException
();
...
@@ -92,5 +88,11 @@ public void setStatusForCode(int statusCode) {
...
@@ -92,5 +88,11 @@ public void setStatusForCode(int statusCode) {
setStatus
(
JobStatus
.
UNKOWN
);
setStatus
(
JobStatus
.
UNKOWN
);
}
}
}
}
@Override
public
void
send
()
throws
InvalidJobDescriptorException
,
FailedTransmissionException
{
connector
.
sendAndUpdateImportJob
(
this
);
}
}
}
src/eu/simstadt/nf4j/Job.java
View file @
82952470
package
eu.simstadt.nf4j
;
package
eu.simstadt.nf4j
;
import
java.util.Objects
;
/**
/**
* This job class bundles the three attributes of every nF job: Id, status and last job related nF (error) message.
* This job class bundles the three attributes of every nF job: Id, status and last job related nF (error) message.
*
*
* @author Marcel Bruse
* @author Marcel Bruse
*/
*/
public
abstract
class
Job
{
public
abstract
class
Job
<
D
extends
JobDescriptor
>
{
/** The status of the job. There are different states for export and import jobs. */
/** The status of the job. There are different states for export and import jobs. */
private
JobStatus
status
;
protected
JobStatus
status
;
/** Every job should have a (valid) job descriptor. */
protected
D
descriptor
;
/** The id of the job. */
/** The id of the job. */
pr
iva
te
int
jobI
d
;
pr
otec
te
d
int
i
d
;
/** The connection to the nF. */
/** The connection to the nF. */
pr
ivate
NFConnector
<?,
?>
nFC
onnector
;
pr
otected
NFConnector
c
onnector
;
/**
/**
* This constructor forces the job to have a de
fined
sta
t
e.
* This constructor forces the job to have a de
scription and a connector in
sta
nc
e.
*
*
* @param status The initial status of this job.
* @param connector The job will use this connector to synchronize itself with the nF.
* @param descriptor The description of this job.
*/
*/
public
Job
(
JobStatus
status
)
{
public
Job
(
D
descriptor
,
NFConnector
connector
)
{
this
.
status
=
status
;
this
.
descriptor
=
descriptor
;
this
.
connector
=
connector
;
}
/**
* This constructor forces the job to have a id and a connector instance.
*
* @param id The job id. If you call updateStatus() and the nF "knows" the job id, then the job status
* will be updated. If you call updateStatus() and the job id is "unkown" on the server side, then
* @param connector The job will use this connector to synchronize itself with the nF.
*/
public
Job
(
int
id
,
NFConnector
connector
)
{
this
.
id
=
id
;
this
.
connector
=
connector
;
}
}
/**
/**
...
@@ -45,11 +60,18 @@ protected void setStatus(JobStatus status) {
...
@@ -45,11 +60,18 @@ protected void setStatus(JobStatus status) {
this
.
status
=
status
;
this
.
status
=
status
;
}
}
/**
* @return Returns the description of this job.
*/
public
D
getDescriptor
()
{
return
descriptor
;
}
/**
/**
* @return Returns the id of this job.
* @return Returns the id of this job.
*/
*/
public
int
get
Job
Id
()
{
public
int
getId
()
{
return
jobI
d
;
return
i
d
;
}
}
/**
/**
...
@@ -57,15 +79,15 @@ public int getJobId() {
...
@@ -57,15 +79,15 @@ public int getJobId() {
*
*
* @param jobId The job id about to be set.
* @param jobId The job id about to be set.
*/
*/
public
void
set
Job
Id
(
int
jobId
)
{
public
void
setId
(
int
jobId
)
{
this
.
jobI
d
=
jobId
;
this
.
i
d
=
jobId
;
}
}
/**
/**
* @return Returns the nF connector of this job.
* @return Returns the nF connector of this job.
*/
*/
public
NFConnector
<?,
?>
getNFConnector
()
{
public
NFConnector
getNFConnector
()
{
return
nFC
onnector
;
return
c
onnector
;
}
}
/**
/**
...
@@ -73,13 +95,25 @@ public void setJobId(int jobId) {
...
@@ -73,13 +95,25 @@ public void setJobId(int jobId) {
*
*
* @param nFConnector The connector of this job.
* @param nFConnector The connector of this job.
*/
*/
public
void
setNFConnector
(
NFConnector
<?,
?>
nFConnector
)
{
public
void
setNFConnector
(
NFConnector
nFConnector
)
{
this
.
nFC
onnector
=
nFConnector
;
this
.
c
onnector
=
nFConnector
;
}
}
/**
/**
* Connects to the nF and refreshes the status of this job. If there is no nF connector set,
* This method reads the job description, builds a job file from it and uses the connector to send the
* this operation will throw a FailedTransmissionException.
* job file to nF. You may want to implement the file building and file sending parts in the
* connector in order to reuse them here.
*
* This method is a object oriented convenience method for NFConnector.sendXXXJobFile(). It is sensible
* to have this convenience method, because it offers the API user centralized controls over the jobs
* status chain without switching between job instances and connector instances. In the end, the user is
* not interested in the connection to the nF, but in the job itself.
*/
public
abstract
void
send
()
throws
InvalidJobDescriptorException
,
FailedTransmissionException
;
/**
* Connects to the nF and refreshes the status of this job. If there is no nF connector set, or the job id
* is unkown by the nF, then this operation will throw a FailedTransmissionException.
*
*
* @throws FailedTransmissionException If the connection to the nF is broken you will get some of this.
* @throws FailedTransmissionException If the connection to the nF is broken you will get some of this.
*/
*/
...
...
src/eu/simstadt/nf4j/JobFileBuilderImpl.java
View file @
82952470
...
@@ -117,17 +117,19 @@ public File buildExportJobFile(ExportJobDescriptorImpl jobDescriptor) throws Inv
...
@@ -117,17 +117,19 @@ public File buildExportJobFile(ExportJobDescriptorImpl jobDescriptor) throws Inv
extent
.
setAttribute
(
"merge_mapsheets"
,
jobDescriptor
.
getMergeMapsheets
());
extent
.
setAttribute
(
"merge_mapsheets"
,
jobDescriptor
.
getMergeMapsheets
());
root
.
appendChild
(
extent
);
root
.
appendChild
(
extent
);
if
(!
jobDescriptor
.
getUnit
().
isEmpty
())
{
if
(!
jobDescriptor
.
getUnit
List
().
isEmpty
())
{
extent
.
setAttribute
(
"tile1asgn"
,
jobDescriptor
.
getTile1asgn
());
extent
.
setAttribute
(
"tile1asgn"
,
jobDescriptor
.
getTile1asgn
());
Element
unit
=
doc
.
createElement
(
"unit"
);
for
(
Unit
unit
:
jobDescriptor
.
getUnitList
())
{
unit
.
setAttribute
(
"exterior"
,
jobDescriptor
.
getExterior
());
Element
unitElement
=
doc
.
createElement
(
"unit"
);
unit
.
setAttribute
(
"frame"
,
jobDescriptor
.
getFrame
());
unitElement
.
setAttribute
(
"exterior"
,
unit
.
getExterior
());
unit
.
setAttribute
(
"select_mapsheets"
,
jobDescriptor
.
getSelectMapsheets
());
unitElement
.
setAttribute
(
"frame"
,
unit
.
getFrame
());
unit
.
setAttribute
(
"subdivision"
,
jobDescriptor
.
getSubdivision
());
unitElement
.
setAttribute
(
"select_mapsheets"
,
unit
.
getSelectMapsheets
());
unit
.
appendChild
(
doc
.
createTextNode
(
jobDescriptor
.
getUnit
()));
unitElement
.
setAttribute
(
"subdivision"
,
unit
.
getSubdivision
());
extent
.
appendChild
(
unit
);
unitElement
.
appendChild
(
doc
.
createTextNode
(
unit
.
getValue
()));
extent
.
appendChild
(
unitElement
);
}
}
else
{
}
else
{
Element
polygon
=
append
RegionPolygon
(
doc
,
jobDescriptor
.
regionPolygon
);
Element
polygon
=
create
RegionPolygon
Element
(
doc
,
jobDescriptor
.
regionPolygon
);
extent
.
appendChild
(
polygon
);
extent
.
appendChild
(
polygon
);
}
}
...
@@ -276,7 +278,7 @@ public static ProjCoordinate transformCoordinate(ProjCoordinate wgs84Position,
...
@@ -276,7 +278,7 @@ public static ProjCoordinate transformCoordinate(ProjCoordinate wgs84Position,
* @param regionPolygon The polygon of the region which has been selected to be exported.
* @param regionPolygon The polygon of the region which has been selected to be exported.
* @return The w3c.dom.Element of the XML export job which describes the region polygon.
* @return The w3c.dom.Element of the XML export job which describes the region polygon.
*/
*/
private
static
Element
append
RegionPolygon
(
Document
doc
,
List
<
Coord
>
regionPolygon
)
{
private
static
Element
create
RegionPolygon
Element
(
Document
doc
,
List
<
Coord
>
regionPolygon
)
{
Element
polygon
=
doc
.
createElement
(
"polygon"
);
Element
polygon
=
doc
.
createElement
(
"polygon"
);
polygon
.
setAttribute
(
"srs"
,
"31467"
);
polygon
.
setAttribute
(
"srs"
,
"31467"
);
CRSFactory
f
=
new
CRSFactory
();
CRSFactory
f
=
new
CRSFactory
();
...
...
src/eu/simstadt/nf4j/JobStatus.java
View file @
82952470
...
@@ -6,11 +6,13 @@
...
@@ -6,11 +6,13 @@
* @author Marcel Bruse
* @author Marcel Bruse
*/
*/
public
enum
JobStatus
{
public
enum
JobStatus
{
UNKOWN
(
0
),
PENDING
(
1
),
RUNNING
(
2
),
FAILED
(
3
),
FINISHED
(
4
),
READY_TO_RUN
(
5
),
ERROR
(
6
),
WARNING
(
7
),
APPROVE
(
8
),
UNKOWN
(
0
),
LOCAL
(
1
),
SENT
(
2
),
PENDING
(
3
),
RUNNING
(
4
),
FAILED
(
5
),
FINISHED
(
6
),
READY_TO_RUN
(
7
),
ERROR
(
8
),
REJECT
(
9
),
APPROVE_RUNNING
(
1
0
),
REJECT_RUNNING
(
1
1
),
APPROVE_REJECT_ERROR
(
1
2
),
APPROVE_REJECT_OK
(
13
),
WARNING
(
9
),
APPROVE
(
10
),
REJECT
(
11
),
APPROVE_RUNNING
(
1
2
),
REJECT_RUNNING
(
1
3
),
APPROVE_REJECT_ERROR
(
1
4
),
IMPORTED_WARNING
(
1
4
);
APPROVE_REJECT_OK
(
15
),
IMPORTED_WARNING
(
1
6
);
public
static
final
String
UNKNOWN_STATUS_MESSAGE
=
"The state of the job is unknown."
;
public
static
final
String
UNKNOWN_MESSAGE
=
"The state of the job is unknown."
;
public
static
final
String
LOCAL_MESSAGE
=
"The job is known locally only. It has not been sent yet."
;
public
static
final
String
SENT_MESSAGE
=
"The job has been sent, is enqueued at the nF and has a job id."
;
public
static
final
String
PENDING_MESSAGE
=
"Job is pending."
;
public
static
final
String
PENDING_MESSAGE
=
"Job is pending."
;
public
static
final
String
RUNNING_MESSAGE
=
"Job is running."
;
public
static
final
String
RUNNING_MESSAGE
=
"Job is running."
;
public
static
final
String
FAILED_MESSAGE
=
"Job failed."
;
public
static
final
String
FAILED_MESSAGE
=
"Job failed."
;
...
@@ -24,16 +26,20 @@ public enum JobStatus {
...
@@ -24,16 +26,20 @@ public enum JobStatus {
private
JobStatus
(
int
internalCode
)
{
private
JobStatus
(
int
internalCode
)
{
switch
(
internalCode
)
{
switch
(
internalCode
)
{
case
0
:
case
0
:
message
=
UNKNOWN_
STATUS_
MESSAGE
;
break
;
message
=
UNKNOWN_MESSAGE
;
break
;
case
1
:
case
1
:
case
5
:
message
=
LOCAL_MESSAGE
;
break
;
message
=
PENDING_MESSAGE
;
break
;
case
2
:
case
2
:
message
=
RUNNING
_MESSAGE
;
break
;
message
=
SENT
_MESSAGE
;
break
;
case
3
:
case
3
:
case
6
:
case
7
:
message
=
FAILED
_MESSAGE
;
break
;
message
=
PENDING
_MESSAGE
;
break
;
case
4
:
case
4
:
message
=
RUNNING_MESSAGE
;
break
;
case
5
:
case
8
:
message
=
FAILED_MESSAGE
;
break
;
case
6
:
message
=
FINISHED_MESSAGE
;
break
;
message
=
FINISHED_MESSAGE
;
break
;
default
:
default
:
message
=
""
;
message
=
""
;
...
...
src/eu/simstadt/nf4j/Layer.java
View file @
82952470
...
@@ -7,6 +7,12 @@
...
@@ -7,6 +7,12 @@
* @author Marcel Bruse
* @author Marcel Bruse
*/
*/
public
class
Layer
{
public
class
Layer
{
private
static
final
String
DEFAULT_NAME
=
"GML"
;
private
static
final
String
DEFAULT_PRODUCT
=
"WU3"
;
private
static
final
String
DEFAULT_STYLE
=
"#000000"
;
/** The name of the layer. */
/** The name of the layer. */
private
String
name
;
private
String
name
;
...
@@ -83,4 +89,12 @@ public void setStyle(String style) {
...
@@ -83,4 +89,12 @@ public void setStyle(String style) {
this
.
style
=
style
;
this
.
style
=
style
;
}
}
public
static
Layer
getDefaultLayer
()
{
Layer
layer
=
new
Layer
();
layer
.
setName
(
DEFAULT_NAME
);
layer
.
setProduct
(
DEFAULT_PRODUCT
);
layer
.
setStyle
(
DEFAULT_STYLE
);
return
layer
;
}
}
}
src/eu/simstadt/nf4j/Main.java
View file @
82952470
package
eu.simstadt.nf4j
;
package
eu.simstadt.nf4j
;
import
java.io.File
;
import
java.util.Arrays
;
import
java.util.function.Consumer
;
public
class
Main
{
public
class
Main
{
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
{
//// ImportJobDescriptorImpl desc = ImportJobDescriptorImpl.getDefaultDescriptor();
//// desc.setProduct("WUDEV");
ExportJobDescriptorImpl
jobDescriptor
=
ExportJobDescriptorImpl
.
getDefaultDescriptor
();
//// desc.setLeaf("820");
jobDescriptor
.
setProduct
(
"WU3"
);
//// desc.setCityGMLFile(new File("WUDEV_820_GML.gml"));
//// desc.addADESchemaFile(new File("energy.xsd"));
Arrays
.
asList
(
"820"
,
"821"
,
"822"
,
"823"
,
"824"
).
forEach
(
new
Consumer
<
String
>()
{
//// System.out.println(desc.getCityGMLFile().canRead());
@Override
//
public
void
accept
(
String
unitLabel
)
{
// NFConnectorImpl connector = new NFConnectorImpl("193.196.136.164");
Unit
unit
=
Unit
.
getDefaultUnit
();
//
unit
.
setValue
(
unitLabel
);
// try {
jobDescriptor
.
addUnit
(
unit
);
//// ImportJob job = connector.sendImportJobFile(desc);
}
// ImportJob job = connector.requestImportJob(301);
});
// job.updateStatus();
// System.out.println(job.getJobId() + ": " + job.getStatus());
Layer
layer
=
Layer
.
getDefaultLayer
();
// } catch (FailedTransmissionException ex) {
layer
.
setProduct
(
"WU3"
);
// ex.printStackTrace();
layer
.
setName
(
"GML"
);
// }
jobDescriptor
.
addLayer
(
layer
);
ExportJob
job
=
new
ExportJob
(
jobDescriptor
,
new
NFConnectorImpl
(
"193.196.136.164"
));
try
{
job
.
send
();
int
i
=
1
;
while
(!
job
.
isFinished
())
{
System
.
out
.
println
(
i
++);
Thread
.
sleep
(
5000
l
);
job
.
updateStatus
();
System
.
out
.
println
(
job
.
getStatus
());
}
job
.
requestExportJobResult
();
}
catch
(
FailedTransmissionException
|
InvalidJobDescriptorException
ex
)
{
ex
.
printStackTrace
();
}
catch
(
InterruptedException
ex
)
{
ex
.
printStackTrace
();
}
}
}
}
}
\ No newline at end of file
src/eu/simstadt/nf4j/NFConnector.java
View file @
82952470
...
@@ -6,11 +6,8 @@
...
@@ -6,11 +6,8 @@
* NFConnector lets you communicate with your novaFACTORY (nF) server instance.
* NFConnector lets you communicate with your novaFACTORY (nF) server instance.
*
*
* @author Marcel Bruse
* @author Marcel Bruse
*
* @param <I> The import job descriptor implementation for this connector.
* @param <E> The export job descriptor implementation for this connector.
*/
*/
public
interface
NFConnector
<
I
extends
ImportJobDescriptor
,
E
extends
ExportJobDescriptor
>
{
public
interface
NFConnector
{
/**
/**
* Callers of this NFConnector want to know the actual version of the novaFACTORY and the versions of its
* Callers of this NFConnector want to know the actual version of the novaFACTORY and the versions of its
...
@@ -27,12 +24,13 @@
...
@@ -27,12 +24,13 @@
/**
/**
* Sends an export job to nF. The job has to be passed to the nF in an appropriate XML job file.
* Sends an export job to nF. The job has to be passed to the nF in an appropriate XML job file.
* The DTD of the XML format can be obtained from the nF installation or documentation.
* The DTD of the XML format can be obtained from the nF installation or documentation.
* The contents of the XML job file are detailed in a job descriptor.
* The contents of the XML job file are detailed in the job's descriptor instance. This method is supposed to
*
* update the status of the job and the job id.
* @param jobDescriptor The nF export job description.
*
* @return The status of the job. Could be pending or failed.
* @param job The nF export job with description. If the job description is invalid, you will receive an
* InvalidJobDescriptorException.
*/
*/
public
ExportJob
sendExportJobFile
(
E
exportJobDescriptor
)
public
void
sendAndUpdateExportJob
(
ExportJob
job
)
throws
InvalidJobDescriptorException
,
FailedTransmissionException
;
throws
InvalidJobDescriptorException
,
FailedTransmissionException
;
/**
/**
...
@@ -59,10 +57,9 @@ public ExportJob sendExportJobFile(E exportJobDescriptor)
...
@@ -59,10 +57,9 @@ public ExportJob sendExportJobFile(E exportJobDescriptor)
* - 'DEL': Deletes the geometry of a particular LOD,
* - 'DEL': Deletes the geometry of a particular LOD,
* - 'DELALL': Deletes a whole building
* - 'DELALL': Deletes a whole building
*
*
* @param file The nF import job as a prepared ZIP file. It has to contain the CityGML file and the start file.
* @param job The nF import job to be sent. It has to contain a valid description.
* @return Returns the job id of your import job or -1 if something went wrong.
*/
*/
public
ImportJob
sendImportJobFile
(
I
importJobDescriptor
)
public
void
sendAndUpdateImportJob
(
ImportJob
job
)
throws
InvalidJobDescriptorException
,
FailedTransmissionException
;
throws
InvalidJobDescriptorException
,
FailedTransmissionException
;
/**
/**
...
...
src/eu/simstadt/nf4j/NFConnectorImpl.java
View file @
82952470
...
@@ -35,7 +35,7 @@
...
@@ -35,7 +35,7 @@
* @param <I> The import job descriptor implementation for this connector.
* @param <I> The import job descriptor implementation for this connector.
* @param <E> The export job descriptor implementation for this connector.
* @param <E> The export job descriptor implementation for this connector.
*/
*/
public
class
NFConnectorImpl
implements
NFConnector
<
ImportJobDescriptorImpl
,
ExportJobDescriptorImpl
>
{
public
class
NFConnectorImpl
implements
NFConnector
{
/** Supported version of the novaFACTORY. */
/** Supported version of the novaFACTORY. */
public
static
final
String
NOVA_FACTORY_VERSION
=
"6.3.1.1"
;
public
static
final
String
NOVA_FACTORY_VERSION
=
"6.3.1.1"
;
...
@@ -136,7 +136,7 @@ public String supportsNFVersion() {
...
@@ -136,7 +136,7 @@ public String supportsNFVersion() {
*/
*/
@Override
@Override
public
ExportJob
requestExportJob
(
int
jobId
)
throws
FailedTransmissionException
{
public
ExportJob
requestExportJob
(
int
jobId
)
throws
FailedTransmissionException
{
ExportJob
result
=
ExportJob
.
getNewInstance
(
this
);
ExportJob
result
=
new
ExportJob
(
jobId
,
this
);
try
{
try
{
List
<
String
>
parameters
=
Arrays
.
asList
(
buildParameter
(
"jobid"
,
jobId
));
List
<
String
>
parameters
=
Arrays
.
asList
(
buildParameter
(
"jobid"
,
jobId
));
getJobFromResponse
(
result
,
getResponse
(
buildURL
(
REMOTE_STATUS_SERVLET
,
parameters
)));
getJobFromResponse
(
result
,
getResponse
(
buildURL
(
REMOTE_STATUS_SERVLET
,
parameters
)));
...
@@ -162,7 +162,7 @@ public ExportJob requestExportJob(int jobId) throws FailedTransmissionException
...
@@ -162,7 +162,7 @@ public ExportJob requestExportJob(int jobId) throws FailedTransmissionException
*/
*/
@Override
@Override
public
ImportJob
requestImportJob
(
int
jobId
)
throws
FailedTransmissionException
{
public
ImportJob
requestImportJob
(
int
jobId
)
throws
FailedTransmissionException
{
ImportJob
result
=
ImportJob
.
getNewInstance
(
this
);
ImportJob
result
=
new
ImportJob
(
jobId
,
this
);
try
{
try
{
List
<
String
>
parameters
=
Arrays
.
asList
(
List
<
String
>
parameters
=
Arrays
.
asList
(
buildParameter
(
"jobid"
,
jobId
),
buildParameter
(
"jobid"
,
jobId
),
...
@@ -295,10 +295,8 @@ private String getResponse(HttpURLConnection httpConnection) throws UnsupportedE
...
@@ -295,10 +295,8 @@ private String getResponse(HttpURLConnection httpConnection) throws UnsupportedE
* @throws SAXException Some parse error.
* @throws SAXException Some parse error.
* @throws IOException Some parse error.
* @throws IOException Some parse error.
*/
*/
private
void
getJobFromResponse
(
Job
job
,
String
xml
)
private
void
getJobFromResponse
(
Job
<?>
job
,
String
xml
)
throws
ParserConfigurationException
,
SAXException
,
IOException
{
throws
ParserConfigurationException
,
SAXException
,
IOException
{
JobStatus
status
=
JobStatus
.
UNKOWN
;
job
.
setStatus
(
status
);
SAXParserFactory
saxFactory
=
SAXParserFactory
.
newInstance
();
SAXParserFactory
saxFactory
=
SAXParserFactory
.
newInstance
();
SAXParser
parser
=
saxFactory
.
newSAXParser
();
SAXParser
parser
=
saxFactory
.
newSAXParser
();
StringReader
reader
=
new
StringReader
(
xml
);
StringReader
reader
=
new
StringReader
(
xml
);
...
@@ -308,10 +306,10 @@ private void getJobFromResponse(Job job, String xml)
...
@@ -308,10 +306,10 @@ private void getJobFromResponse(Job job, String xml)
job
.
setStatusForCode
(
handler
.
statusId
);
job
.
setStatusForCode
(
handler
.
statusId
);
}
}
if
(
Objects
.
nonNull
(
handler
.
serviceException
))
{
if
(
Objects
.
nonNull
(
handler
.
serviceException
))
{
s
tatus
.
setMessage
(
handler
.
serviceException
);
job
.
getS
tatus
()
.
setMessage
(
handler
.
serviceException
);
}
}
if
(
Objects
.
nonNull
(
handler
.
jobId
))
{
if
(
Objects
.
nonNull
(
handler
.
jobId
))
{
job
.
set
Job
Id
(
handler
.
jobId
);
job
.
setId
(
handler
.
jobId
);
}
}
}
}
...
@@ -363,11 +361,10 @@ private File downloadFile(URL url) throws IOException {
...
@@ -363,11 +361,10 @@ private File downloadFile(URL url) throws IOException {
* @throws InvalidJobDescriptorException
* @throws InvalidJobDescriptorException
*/
*/
@Override
@Override
public
ExportJob
send
ExportJob
File
(
ExportJob
DescriptorImpl
jobDescriptor
)
public
void
sendAndUpdate
ExportJob
(
ExportJob
job
)
throws
InvalidJobDescriptorException
,
FailedTransmissionException
{
throws
InvalidJobDescriptorException
,
FailedTransmissionException
{
ExportJob
result
=
ExportJob
.
getNewInstance
();
JobFileBuilderImpl
jobFileBuilder
=
new
JobFileBuilderImpl
();
JobFileBuilderImpl
jobFileBuilder
=
new
JobFileBuilderImpl
();
File
exportJobFile
=
jobFileBuilder
.
buildExportJobFile
(
jobDescriptor
);
File
exportJobFile
=
jobFileBuilder
.
buildExportJobFile
(
job
.
get
Descriptor
()
);
try
{
try
{
URL
url
=
buildURL
(
REMOTE_ORDER_SERVLET
,
null
);
URL
url
=
buildURL
(
REMOTE_ORDER_SERVLET
,
null
);
HttpURLConnection
connection
=
(
HttpURLConnection
)
url
.
openConnection
();
HttpURLConnection
connection
=
(
HttpURLConnection
)
url
.
openConnection
();
...
@@ -382,23 +379,20 @@ public ExportJob sendExportJobFile(ExportJobDescriptorImpl jobDescriptor)
...
@@ -382,23 +379,20 @@ public ExportJob sendExportJobFile(ExportJobDescriptorImpl jobDescriptor)
Files
.
copy
(
exportJobFile
.
toPath
(),
os
);
Files
.
copy
(
exportJobFile
.
toPath
(),
os
);
os
.
flush
();
os
.
flush
();
writer
.
append
(
CRLF
).
flush
();
writer
.
append
(
CRLF
).
flush
();
getJobFromResponse
(
result
,
getResponse
(
connection
));
getJobFromResponse
(
job
,
getResponse
(
connection
));
// At this line, result will be UNKNOWN, although the job has been enqueued. A separate status request
// At this line, the job status will be unknown, although the job has been enqueued by the nF.
// will be sent in order to query for the actual state of the job.
// A separate status request has to be sent in order to get the actual state of the job.
if
(
result
.
getJobId
()
>
0
)
{
job
.
updateStatus
();
result
=
requestExportJob
(
result
.
getJobId
());
}
}
catch
(
MalformedURLException
ex
)
{
}
catch
(
MalformedURLException
ex
)
{
result
.
getStatus
().
setMessage
(
MALFORMED_URL
);
job
.
getStatus
().
setMessage
(
MALFORMED_URL
);
throw
new
FailedTransmissionException
(
ex
.
getMessage
());
throw
new
FailedTransmissionException
(
ex
.
getMessage
());
}
catch
(
IOException
ex
)
{
}
catch
(
IOException
ex
)
{
result
.
getStatus
().
setMessage
(
IO_EXCEPTION_OCCURRED
);
job
.
getStatus
().
setMessage
(
IO_EXCEPTION_OCCURRED
);
throw
new
FailedTransmissionException
(
ex
.
getMessage
());
throw
new
FailedTransmissionException
(
ex
.
getMessage
());
}
catch
(
ParserConfigurationException
|
SAXException
ex
)
{
}
catch
(
ParserConfigurationException
|
SAXException
ex
)
{
result
.
getStatus
().
setMessage
(
XML_PARSER_ERROR
);
job
.
getStatus
().
setMessage
(
XML_PARSER_ERROR
);
throw
new
FailedTransmissionException
(
ex
.
getMessage
());
throw
new
FailedTransmissionException
(
ex
.
getMessage
());
}
}
return
result
;
}
}
/**
/**
...
@@ -429,11 +423,10 @@ public ExportJob sendExportJobFile(ExportJobDescriptorImpl jobDescriptor)
...
@@ -429,11 +423,10 @@ public ExportJob sendExportJobFile(ExportJobDescriptorImpl jobDescriptor)
* @throws FailedTransmissionException
* @throws FailedTransmissionException
*/
*/
@Override
@Override
public
ImportJob
send
ImportJob
File
(
ImportJob
DescriptorImpl
jobDescriptor
)
public
void
sendAndUpdate
ImportJob
(
ImportJob
job
)
throws
InvalidJobDescriptorException
,
FailedTransmissionException
{
throws
InvalidJobDescriptorException
,
FailedTransmissionException
{
ImportJob
result
=
ImportJob
.
getNewInstance
();
JobFileBuilderImpl
jobFileBuilder
=
new
JobFileBuilderImpl
();
JobFileBuilderImpl
jobFileBuilder
=
new
JobFileBuilderImpl
();
File
importJobFile
=
jobFileBuilder
.
buildImportJobFile
(
jobDescriptor
);
File
importJobFile
=
jobFileBuilder
.
buildImportJobFile
(
job
.
get
Descriptor
()
);
try
{
try
{
List
<
String
>
parameters
=
Arrays
.
asList
(
List
<
String
>
parameters
=
Arrays
.
asList
(
buildParameter
(
"request"
,
"imp"
),
// trigger import
buildParameter
(
"request"
,
"imp"
),
// trigger import
...
@@ -453,18 +446,17 @@ public ImportJob sendImportJobFile(ImportJobDescriptorImpl jobDescriptor)
...
@@ -453,18 +446,17 @@ public ImportJob sendImportJobFile(ImportJobDescriptorImpl jobDescriptor)
Files
.
copy
(
importJobFile
.
toPath
(),
os
);
Files
.
copy
(
importJobFile
.
toPath
(),
os
);
os
.
flush
();
os
.
flush
();
writer
.
append
(
CRLF
).
flush
();
writer
.
append
(
CRLF
).
flush
();
getJobFromResponse
(
result
,
getResponse
(
connection
));
getJobFromResponse
(
job
,
getResponse
(
connection
));
}
catch
(
MalformedURLException
ex
)
{
}
catch
(
MalformedURLException
ex
)
{
result
.
getStatus
().
setMessage
(
MALFORMED_URL
);
job
.
getStatus
().
setMessage
(
MALFORMED_URL
);
throw
new
FailedTransmissionException
(
ex
.
getMessage
());
throw
new
FailedTransmissionException
(
ex
.
getMessage
());
}
catch
(
IOException
ex
)
{
}
catch
(
IOException
ex
)
{
result
.
getStatus
().
setMessage
(
IO_EXCEPTION_OCCURRED
);
job
.
getStatus
().
setMessage
(
IO_EXCEPTION_OCCURRED
);
throw
new
FailedTransmissionException
(
ex
.
getMessage
());
throw
new
FailedTransmissionException
(
ex
.
getMessage
());
}
catch
(
SAXException
|
ParserConfigurationException
ex
)
{
}
catch
(
SAXException
|
ParserConfigurationException
ex
)
{
result
.
getStatus
().
setMessage
(
XML_PARSER_ERROR
);
job
.
getStatus
().
setMessage
(
XML_PARSER_ERROR
);
throw
new
FailedTransmissionException
(
ex
.
getMessage
());
throw
new
FailedTransmissionException
(
ex
.
getMessage
());
}
}
return
result
;
}
}
}
}
\ No newline at end of file
src/eu/simstadt/nf4j/Unit.java
0 → 100644
View file @
82952470
package
eu.simstadt.nf4j
;
/**
* Units (Blattschnitte) divide regions into sections. For instance, the city of Stuttgart could have the units
* "Stg-Mitte", "Stg-West", "Bad Cannstatt", "Heslach", etc.
*
* @author Marcel Bruse
*
*/
public
class
Unit
{
private
static
final
String
DEFAULT_EXTERIOR
=
"0"
;
private
static
final
String
DEFAULT_FRAME
=
"0"
;
private
static
final
String
DEFAULT_SELECT_MAP_SHEETS
=
"0"
;
private
static
final
String
DEFAULT_SUBDIVISION
=
"4"
;
/** The exterior attribute of the unit tag. */
private
String
exterior
;
/** The frame attribute of the unit tag. */
private
String
frame
;
/** The select mapsheet attribute of the unit tag. */
private
String
selectMapsheets
;
/** The subdivision attribute of the unit tag. */
private
String
subdivision
;
/** The actual value of the unit tag. */
private
String
value
;
public
String
getExterior
()
{
return
exterior
;
}
public
void
setExterior
(
String
exterior
)
{
this
.
exterior
=
exterior
;
}
public
String
getFrame
()
{
return
frame
;
}
public
void
setFrame
(
String
frame
)
{
this
.
frame
=
frame
;
}
public
String
getSelectMapsheets
()
{
return
selectMapsheets
;
}
public
void
setSelectMapsheets
(
String
selectMapsheets
)
{
this
.
selectMapsheets
=
selectMapsheets
;
}
public
String
getSubdivision
()
{
return
subdivision
;
}
public
void
setSubdivision
(
String
subdivision
)
{
this
.
subdivision
=
subdivision
;
}
public
String
getValue
()
{
return
value
;
}
public
void
setValue
(
String
value
)
{
this
.
value
=
value
;
}
/**
* @return Returns true, if the unit is valid.
*/
public
boolean
isValid
()
{
return
!(
exterior
.
isEmpty
()
||
frame
.
isEmpty
()
||
selectMapsheets
.
isEmpty
()
||
subdivision
.
isEmpty
());
}
public
static
Unit
getDefaultUnit
()
{
Unit
unit
=
new
Unit
();
unit
.
setExterior
(
DEFAULT_EXTERIOR
);
unit
.
setFrame
(
DEFAULT_FRAME
);
unit
.
setSelectMapsheets
(
DEFAULT_SELECT_MAP_SHEETS
);
unit
.
setSubdivision
(
DEFAULT_SUBDIVISION
);
return
unit
;
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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