Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Genesys Backend
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
19
Issues
19
List
Boards
Labels
Service Desk
Milestones
Operations
Operations
Incidents
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Genesys PGR
Genesys Backend
Commits
88b56904
Commit
88b56904
authored
Oct 23, 2018
by
Matija Obreza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
KPI Controller v1
parent
8e7c3d51
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
233 additions
and
25 deletions
+233
-25
src/main/java/org/genesys2/server/api/admin/v0/KPIController.java
.../java/org/genesys2/server/api/admin/v0/KPIController.java
+2
-4
src/main/java/org/genesys2/server/api/v1/KPIController.java
src/main/java/org/genesys2/server/api/v1/KPIController.java
+160
-0
src/main/java/org/genesys2/server/model/kpi/Dimension.java
src/main/java/org/genesys2/server/model/kpi/Dimension.java
+2
-2
src/main/java/org/genesys2/server/model/kpi/ExecutionRun.java
...main/java/org/genesys2/server/model/kpi/ExecutionRun.java
+13
-0
src/main/java/org/genesys2/server/persistence/kpi/DimensionRepository.java
.../genesys2/server/persistence/kpi/DimensionRepository.java
+2
-0
src/main/java/org/genesys2/server/service/KPIService.java
src/main/java/org/genesys2/server/service/KPIService.java
+25
-15
src/main/java/org/genesys2/server/service/impl/KPIServiceImpl.java
...java/org/genesys2/server/service/impl/KPIServiceImpl.java
+29
-4
No files found.
src/main/java/org/genesys2/server/api/admin/v0/KPIController.java
View file @
88b56904
...
...
@@ -243,11 +243,9 @@ public class KPIController extends ApiBaseController {
public
@ResponseBody
List
<
Observation
>
execute
(
@PathVariable
(
"executionName"
)
String
executionName
)
{
Execution
execution
=
kpiService
.
getExecution
(
executionName
);
LOG
.
info
(
"Running execute on : {}"
,
executionName
);
List
<
Observation
>
res
=
kpiService
.
execute
(
execution
);
LOG
.
info
(
"Saving results: count={}"
,
res
.
size
());
List
<
Observation
>
x
=
kpiService
.
save
(
execution
,
res
);
List
<
Observation
>
res
=
kpiService
.
executeAndSave
(
execution
).
getObservations
();
LOG
.
info
(
"Done saving results."
);
return
x
;
return
res
;
}
/**
...
...
src/main/java/org/genesys2/server/api/v1/KPIController.java
0 → 100644
View file @
88b56904
/*
* Copyright 2018 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.genesys2.server.api.v1
;
import
java.util.List
;
import
org.apache.commons.lang3.StringUtils
;
import
org.genesys.blocks.model.JsonViews
;
import
org.genesys2.server.api.ApiBaseController
;
import
org.genesys2.server.api.Pagination
;
import
org.genesys2.server.exception.NotFoundElement
;
import
org.genesys2.server.model.kpi.Dimension
;
import
org.genesys2.server.model.kpi.Execution
;
import
org.genesys2.server.model.kpi.ExecutionRun
;
import
org.genesys2.server.model.kpi.KPIParameter
;
import
org.genesys2.server.service.KPIService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.PageRequest
;
import
org.springframework.web.bind.annotation.DeleteMapping
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
com.fasterxml.jackson.annotation.JsonView
;
import
io.swagger.annotations.Api
;
@RestController
(
"kpiApi1"
)
@RequestMapping
(
value
=
{
KPIController
.
CONTROLLER_URL
})
@Api
(
tags
=
{
"kpi"
})
public
class
KPIController
{
public
static
final
String
CONTROLLER_URL
=
ApiBaseController
.
APIv1_BASE
+
"/kpi"
;
@Autowired
private
KPIService
kpiService
;
/**
* First declare the KPI parameters: e.g. `Accession where `
*
* @param parameter
* @return
*/
@PostMapping
(
value
=
"/parameters/save"
)
public
KPIParameter
saveParameter
(
@RequestBody
KPIParameter
parameter
)
{
return
kpiService
.
save
(
parameter
);
}
@DeleteMapping
(
value
=
"/parameters/{name}"
)
public
KPIParameter
deleteParameter
(
@PathVariable
String
name
)
{
return
kpiService
.
delete
(
kpiService
.
getParameter
(
name
));
}
@GetMapping
(
value
=
"/parameters"
)
public
Page
<
KPIParameter
>
listParameters
(
final
Pagination
page
)
{
return
kpiService
.
listParameters
(
page
.
toPageRequest
(
100
));
}
/**
* Then declare the KPI dimensions: e.g. `FaoInstitute#code where accessionCount gt 0`
* Dimensions provide query parameters to KPI execution
*
* @param dimension
* @return
*/
@PostMapping
(
value
=
"/dimensions/save"
)
public
Dimension
<?>
saveDimension
(
@RequestBody
Dimension
<?>
dimension
)
{
return
kpiService
.
save
(
dimension
);
}
@DeleteMapping
(
value
=
"/dimensions/{name}"
)
public
Dimension
<?>
deleteDimension
(
@PathVariable
String
name
)
{
return
kpiService
.
delete
(
kpiService
.
getDimension
(
name
));
}
@GetMapping
(
value
=
"/dimensions"
)
public
Page
<
Dimension
<?>>
listDimensions
(
final
Pagination
page
)
{
return
kpiService
.
listDimensions
(
page
.
toPageRequest
(
100
));
}
/**
* Declare execution with a {@link KPIParameter} and one or more {@link Dimension}
*
* @param execution
* @return
*/
@PostMapping
(
value
=
"/executions/save"
)
public
Execution
saveExecution
(
@RequestBody
Execution
execution
)
{
return
kpiService
.
save
(
execution
);
}
@DeleteMapping
(
value
=
"/executions/{name}"
)
public
Execution
deleteExecution
(
@PathVariable
String
name
)
{
return
kpiService
.
save
(
kpiService
.
getExecution
(
name
));
}
@GetMapping
(
value
=
"/executions"
)
public
Page
<
Execution
>
listExecution
(
final
Pagination
page
)
{
return
kpiService
.
listExecutions
(
page
.
toPageRequest
(
100
));
}
@PostMapping
(
value
=
"/executions/{name}/execute"
)
public
ExecutionRun
runExecution
(
@PathVariable
String
name
)
{
return
kpiService
.
executeAndSave
(
kpiService
.
getExecution
(
name
));
}
/**
* Execution details
*/
@GetMapping
(
value
=
"/executions/{name}"
)
public
ExecutionDetails
executionDetails
(
@PathVariable
String
name
)
{
Execution
execution
=
kpiService
.
getExecution
(
name
);
return
ExecutionDetails
.
from
(
execution
,
kpiService
.
listExecutionRuns
(
execution
,
new
PageRequest
(
0
,
10
)));
}
@GetMapping
(
value
=
"/executions/{name}/runs"
)
public
List
<
ExecutionRun
>
executionRuns
(
final
@PathVariable
String
name
,
final
Pagination
page
)
{
return
kpiService
.
listExecutionRuns
(
kpiService
.
getExecution
(
name
),
page
.
toPageRequest
(
100
));
}
@GetMapping
(
value
=
"/executions/{name}/runs/{id}"
)
public
ExecutionRun
executionRun
(
final
@PathVariable
String
name
,
final
long
runId
)
{
ExecutionRun
run
=
kpiService
.
getExecutionRun
(
runId
);
if
(!
StringUtils
.
equals
(
run
.
getExecution
().
getName
(),
name
))
{
throw
new
NotFoundElement
(
"No run "
+
runId
+
" for execution "
+
name
);
}
return
run
;
}
/**
* Details
*/
public
static
class
ExecutionDetails
{
public
Execution
execution
;
public
List
<
ExecutionRun
>
runs
;
public
static
ExecutionDetails
from
(
Execution
execution
,
List
<
ExecutionRun
>
runs
)
{
ExecutionDetails
ed
=
new
ExecutionDetails
();
ed
.
execution
=
execution
;
ed
.
runs
=
runs
;
return
ed
;
}
}
}
src/main/java/org/genesys2/server/model/kpi/Dimension.java
View file @
88b56904
...
...
@@ -54,9 +54,9 @@ public abstract class Dimension<T> extends AuditedVersionedModel {
*
*/
private
static
final
long
serialVersionUID
=
1672379271657218936L
;
@Column
(
length
=
100
,
nullable
=
false
)
@Column
(
length
=
100
,
nullable
=
false
,
unique
=
true
)
private
String
name
;
@Column
(
length
=
1
00
,
nullable
=
false
)
@Column
(
length
=
3
00
,
nullable
=
false
)
private
String
title
;
final
public
String
getName
()
{
...
...
src/main/java/org/genesys2/server/model/kpi/ExecutionRun.java
View file @
88b56904
...
...
@@ -17,10 +17,12 @@
package
org.genesys2.server.model.kpi
;
import
java.util.Date
;
import
java.util.List
;
import
javax.persistence.Column
;
import
javax.persistence.Entity
;
import
javax.persistence.ManyToOne
;
import
javax.persistence.OneToMany
;
import
javax.persistence.Table
;
import
javax.persistence.Temporal
;
import
javax.persistence.TemporalType
;
...
...
@@ -46,6 +48,9 @@ public class ExecutionRun extends BasicModel {
@ManyToOne
(
cascade
=
{},
optional
=
false
)
private
Execution
execution
;
@OneToMany
(
mappedBy
=
"executionRun"
,
orphanRemoval
=
true
)
private
List
<
Observation
>
observations
;
public
Date
getTimestamp
()
{
return
timestamp
;
}
...
...
@@ -61,4 +66,12 @@ public class ExecutionRun extends BasicModel {
public
void
setExecution
(
Execution
execution
)
{
this
.
execution
=
execution
;
}
public
List
<
Observation
>
getObservations
()
{
return
observations
;
}
public
void
setObservations
(
List
<
Observation
>
observations
)
{
this
.
observations
=
observations
;
}
}
src/main/java/org/genesys2/server/persistence/kpi/DimensionRepository.java
View file @
88b56904
...
...
@@ -21,4 +21,6 @@ import org.springframework.data.jpa.repository.JpaRepository;
public
interface
DimensionRepository
extends
JpaRepository
<
Dimension
<?>,
Long
>
{
Dimension
<?>
findByName
(
String
name
);
}
src/main/java/org/genesys2/server/service/KPIService.java
View file @
88b56904
/*
*
* Copyright 201
4
Global Crop Diversity Trust
*
/*
* Copyright 201
8
Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*
/
*/
package
org.genesys2.server.service
;
...
...
@@ -25,44 +25,54 @@ import org.genesys2.server.model.kpi.Execution;
import
org.genesys2.server.model.kpi.ExecutionRun
;
import
org.genesys2.server.model.kpi.KPIParameter
;
import
org.genesys2.server.model.kpi.Observation
;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.Pageable
;
public
interface
KPIService
{
long
getSingleResult
(
String
paQuery
,
Object
...
params
);
Set
<?>
getValues
(
Dimension
<?>
loadedJpa
);
KPIParameter
save
(
KPIParameter
parameter
);
KPIParameter
delete
(
KPIParameter
parameter
);
KPIParameter
getParameter
(
String
name
);
KPIParameter
getParameter
(
long
id
);
KPIParameter
delete
(
KPIParameter
parameter
);
List
<
KPIParameter
>
listParameters
();
Page
<
KPIParameter
>
listParameters
(
Pageable
page
);
Dimension
<?>
save
(
Dimension
<?>
dimension
);
Dimension
<?>
getDimension
(
long
id
);
Dimension
<?>
getDimension
(
String
name
);
Dimension
<?>
delete
(
Dimension
<?>
dimension
);
Set
<?>
getValues
(
Dimension
<?>
loadedJpa
);
List
<
Dimension
<?>>
listDimensions
();
Page
<
Dimension
<?>>
listDimensions
(
Pageable
page
);
Execution
save
(
Execution
execution
);
Execution
getExecution
(
long
id
);
Execution
getExecution
(
String
executionName
);
Execution
delete
(
Execution
execution
);
List
<
Observation
>
execu
te
(
Execution
execution
);
Execution
dele
te
(
Execution
execution
);
List
<
Observation
>
save
(
Execution
execution
,
List
<
Observation
>
observations
);
List
<
Execution
>
listExecutions
(
);
List
<
KPIParameter
>
listParameters
(
);
Page
<
Execution
>
listExecutions
(
Pageable
page
);
List
<
Dimension
<?>>
listDimensions
(
);
List
<
Observation
>
execute
(
Execution
execution
);
List
<
Execution
>
listExecutions
(
);
ExecutionRun
executeAndSave
(
Execution
execution
);
List
<
Observation
>
listObservations
(
ExecutionRun
executionRun
,
Map
<
String
,
String
>
dimensionFilters
,
Pageable
page
);
...
...
src/main/java/org/genesys2/server/service/impl/KPIServiceImpl.java
View file @
88b56904
...
...
@@ -47,6 +47,7 @@ import org.genesys2.server.service.KPIService;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.PageRequest
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.data.domain.Sort
;
...
...
@@ -101,6 +102,11 @@ public class KPIServiceImpl implements KPIService {
public
List
<
KPIParameter
>
listParameters
()
{
return
parameterRepository
.
findAll
(
new
Sort
(
"name"
));
}
@Override
public
Page
<
KPIParameter
>
listParameters
(
Pageable
page
)
{
return
parameterRepository
.
findAll
(
page
);
}
@PreAuthorize
(
"hasRole('ADMINISTRATOR') or hasPermission(#parameter, 'ADMINISTRATION')"
)
@Override
...
...
@@ -136,10 +142,23 @@ public class KPIServiceImpl implements KPIService {
return
dim
;
}
@Override
public
Dimension
<?>
getDimension
(
String
name
)
{
Dimension
<?>
dim
=
dimensionRepository
.
findByName
(
name
);
if
(!(
dim
instanceof
JpaDimension
))
dim
.
getValues
().
size
();
return
dim
;
}
@Override
public
List
<
Dimension
<?>>
listDimensions
()
{
return
dimensionRepository
.
findAll
(
new
Sort
(
"name"
));
}
@Override
public
Page
<
Dimension
<?>>
listDimensions
(
Pageable
page
)
{
return
dimensionRepository
.
findAll
(
page
);
}
@Override
public
Execution
getExecution
(
long
id
)
{
...
...
@@ -168,6 +187,11 @@ public class KPIServiceImpl implements KPIService {
public
List
<
Execution
>
listExecutions
()
{
return
executionRepository
.
findAll
();
}
@Override
public
Page
<
Execution
>
listExecutions
(
Pageable
page
)
{
return
executionRepository
.
findAll
(
page
);
}
@PreAuthorize
(
"hasRole('ADMINISTRATOR') or hasPermission(#execution, 'ADMINISTRATION')"
)
@Override
...
...
@@ -235,9 +259,10 @@ public class KPIServiceImpl implements KPIService {
@PreAuthorize
(
"hasRole('ADMINISTRATOR') or hasPermission(#execution, 'ADMINISTRATION')"
)
@Override
@Transactional
public
List
<
Observation
>
save
(
Execution
execution
,
List
<
Observation
>
observations
)
{
public
ExecutionRun
executeAndSave
(
Execution
execution
)
{
ExecutionRun
executionRun
=
new
ExecutionRun
();
List
<
Observation
>
observations
=
execute
(
execution
);
executionRun
.
setExecution
(
execution
);
executionRun
.
setTimestamp
(
new
Date
());
...
...
@@ -291,11 +316,11 @@ public class KPIServiceImpl implements KPIService {
if
(
observations
.
size
()
==
0
)
{
LOG
.
warn
(
"No observations to save. Not storing execution run."
);
return
observations
;
return
null
;
}
executionRunRepository
.
save
(
executionRun
);
return
observationRepository
.
save
(
observations
);
observationRepository
.
save
(
observations
);
return
executionRunRepository
.
save
(
executionRun
);
}
// private void removeSameResult(ExecutionRun previousRun, List<Observation>
...
...
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