Commit 2f8dbd58 authored by Matija Obreza's avatar Matija Obreza

Fix: execute and *store* scheduled KPI executions

parent 51833dd1
......@@ -45,7 +45,7 @@ import org.springframework.web.bind.annotation.RestController;
*/
@RestController("meApi1")
@RequestMapping(org.genesys2.server.api.v1.MeController.API_URL)
@PreAuthorize("isAuthenticated() && hasRole('USER')") // Don't allow OAuth clients here
@PreAuthorize("isAuthenticated() && (hasRole('USER') || hasRole('ADMINISTRATOR'))") // Don't allow OAuth clients here
@Api(tags = { "me" })
public class MeController extends ApiBaseController {
......
......@@ -53,6 +53,11 @@ public class BooleanDimension extends Dimension<Boolean> {
@Column
private int mode = 3;
@Override
public Class<Boolean> getTargetType() {
return Boolean.class;
}
@JsonIgnore
@Override
public Set<Boolean> getValues() {
......
......@@ -92,4 +92,6 @@ public abstract class Dimension<T> extends AuditedVersionedModel {
public String toString() {
return "id=" + getId() + " name=" + name + " title=" + title;
}
public abstract Class<T> getTargetType();
}
......@@ -4,15 +4,15 @@
* 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.model.kpi;
......
......@@ -4,15 +4,15 @@
* 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.model.kpi;
......
......@@ -4,15 +4,15 @@
* 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.model.kpi;
......
......@@ -4,15 +4,15 @@
* 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.model.kpi;
......
......@@ -4,15 +4,15 @@
* 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.model.kpi;
......
......@@ -42,6 +42,11 @@ public class JpaDimension extends Dimension<Object> {
@Column(name = "`condition`", length = 100)
private String condition;
@Override
public Class<Object> getTargetType() {
return Object.class;
}
@JsonIgnore
@Override
public Set<Object> getValues() {
......
......@@ -4,15 +4,15 @@
* 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.model.kpi;
......
......@@ -47,6 +47,11 @@ public class NumericListDimension extends FixedListDimension<Number> {
@ElementCollection()
@CollectionTable(name = "kpidimensionnumeric", joinColumns = @JoinColumn(name = "dimensionId"))
private Set<Double> values;
@Override
public Class<Number> getTargetType() {
return Number.class;
}
public void setValues(Set<Number> list) {
if (list == null) {
......
/**
* Copyright 2014 Global Crop Diversity Trust
*
/*
* 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.model.kpi;
......
......@@ -32,11 +32,17 @@ public class StringListDimension extends FixedListDimension<String> {
*
*/
private static final long serialVersionUID = 7027186911390675241L;
@Column(name = "listvalue", nullable = false)
@ElementCollection()
@CollectionTable(name = "kpidimensionstring", joinColumns = @JoinColumn(name = "dimensionId"))
private Set<String> values = new HashSet<String>();
@Override
public Class<String> getTargetType() {
return String.class;
}
public void setValues(Set<String> values) {
this.values = values;
}
......
......@@ -28,6 +28,7 @@ import java.util.stream.Collectors;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import javax.persistence.TypedQuery;
import javax.validation.Valid;
import org.apache.commons.lang.ArrayUtils;
......@@ -220,7 +221,7 @@ public class KPIServiceImpl implements KPIService {
}
LOG.debug(paQuery.toString());
Query q = entityManager.createQuery(paQuery.toString());
TypedQuery<T> q = entityManager.createQuery(paQuery.toString(), dim.getTargetType());
return new HashSet<T>(q.getResultList());
} else {
......
......@@ -64,13 +64,13 @@ public class KpiScheduledExecutor {
Page<Execution> executions;
do {
executions = kpiService.listExecutions(new PageRequest(page, chunkSize));
for (Execution ex : executions.getContent()) {
for (Execution execution : executions.getContent()) {
try {
LOG.info("Started execution {} after {}ms", ex.getName(), stopWatch.getTime());
kpiService.execute(ex);
LOG.info("Execution {} successful after {}ms", ex.getName(), stopWatch.getTime());
LOG.info("Started execution {} after {}ms", execution.getName(), stopWatch.getTime());
kpiService.executeAndSave(execution);
LOG.info("Execution {} successful after {}ms", execution.getName(), stopWatch.getTime());
} catch (Throwable e) {
LOG.error("Error running KPI Execution {}: {}", ex.getName(), e.getMessage(), e);
LOG.error("Error running KPI Execution {}: {}", execution.getName(), e.getMessage(), e);
}
}
page++;
......
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