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; ...@@ -45,7 +45,7 @@ import org.springframework.web.bind.annotation.RestController;
*/ */
@RestController("meApi1") @RestController("meApi1")
@RequestMapping(org.genesys2.server.api.v1.MeController.API_URL) @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" }) @Api(tags = { "me" })
public class MeController extends ApiBaseController { public class MeController extends ApiBaseController {
......
...@@ -53,6 +53,11 @@ public class BooleanDimension extends Dimension<Boolean> { ...@@ -53,6 +53,11 @@ public class BooleanDimension extends Dimension<Boolean> {
@Column @Column
private int mode = 3; private int mode = 3;
@Override
public Class<Boolean> getTargetType() {
return Boolean.class;
}
@JsonIgnore @JsonIgnore
@Override @Override
public Set<Boolean> getValues() { public Set<Boolean> getValues() {
......
...@@ -92,4 +92,6 @@ public abstract class Dimension<T> extends AuditedVersionedModel { ...@@ -92,4 +92,6 @@ public abstract class Dimension<T> extends AuditedVersionedModel {
public String toString() { public String toString() {
return "id=" + getId() + " name=" + name + " title=" + title; return "id=" + getId() + " name=" + name + " title=" + title;
} }
public abstract Class<T> getTargetType();
} }
...@@ -4,15 +4,15 @@ ...@@ -4,15 +4,15 @@
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
**/ */
package org.genesys2.server.model.kpi; package org.genesys2.server.model.kpi;
......
...@@ -4,15 +4,15 @@ ...@@ -4,15 +4,15 @@
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
**/ */
package org.genesys2.server.model.kpi; package org.genesys2.server.model.kpi;
......
...@@ -4,15 +4,15 @@ ...@@ -4,15 +4,15 @@
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
**/ */
package org.genesys2.server.model.kpi; package org.genesys2.server.model.kpi;
......
...@@ -4,15 +4,15 @@ ...@@ -4,15 +4,15 @@
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
**/ */
package org.genesys2.server.model.kpi; package org.genesys2.server.model.kpi;
......
...@@ -4,15 +4,15 @@ ...@@ -4,15 +4,15 @@
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
**/ */
package org.genesys2.server.model.kpi; package org.genesys2.server.model.kpi;
......
...@@ -42,6 +42,11 @@ public class JpaDimension extends Dimension<Object> { ...@@ -42,6 +42,11 @@ public class JpaDimension extends Dimension<Object> {
@Column(name = "`condition`", length = 100) @Column(name = "`condition`", length = 100)
private String condition; private String condition;
@Override
public Class<Object> getTargetType() {
return Object.class;
}
@JsonIgnore @JsonIgnore
@Override @Override
public Set<Object> getValues() { public Set<Object> getValues() {
......
...@@ -4,15 +4,15 @@ ...@@ -4,15 +4,15 @@
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
**/ */
package org.genesys2.server.model.kpi; package org.genesys2.server.model.kpi;
......
...@@ -47,6 +47,11 @@ public class NumericListDimension extends FixedListDimension<Number> { ...@@ -47,6 +47,11 @@ public class NumericListDimension extends FixedListDimension<Number> {
@ElementCollection() @ElementCollection()
@CollectionTable(name = "kpidimensionnumeric", joinColumns = @JoinColumn(name = "dimensionId")) @CollectionTable(name = "kpidimensionnumeric", joinColumns = @JoinColumn(name = "dimensionId"))
private Set<Double> values; private Set<Double> values;
@Override
public Class<Number> getTargetType() {
return Number.class;
}
public void setValues(Set<Number> list) { public void setValues(Set<Number> list) {
if (list == null) { 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
**/ */
package org.genesys2.server.model.kpi; package org.genesys2.server.model.kpi;
......
...@@ -32,11 +32,17 @@ public class StringListDimension extends FixedListDimension<String> { ...@@ -32,11 +32,17 @@ public class StringListDimension extends FixedListDimension<String> {
* *
*/ */
private static final long serialVersionUID = 7027186911390675241L; private static final long serialVersionUID = 7027186911390675241L;
@Column(name = "listvalue", nullable = false) @Column(name = "listvalue", nullable = false)
@ElementCollection() @ElementCollection()
@CollectionTable(name = "kpidimensionstring", joinColumns = @JoinColumn(name = "dimensionId")) @CollectionTable(name = "kpidimensionstring", joinColumns = @JoinColumn(name = "dimensionId"))
private Set<String> values = new HashSet<String>(); private Set<String> values = new HashSet<String>();
@Override
public Class<String> getTargetType() {
return String.class;
}
public void setValues(Set<String> values) { public void setValues(Set<String> values) {
this.values = values; this.values = values;
} }
......
...@@ -28,6 +28,7 @@ import java.util.stream.Collectors; ...@@ -28,6 +28,7 @@ import java.util.stream.Collectors;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext; import javax.persistence.PersistenceContext;
import javax.persistence.Query; import javax.persistence.Query;
import javax.persistence.TypedQuery;
import javax.validation.Valid; import javax.validation.Valid;
import org.apache.commons.lang.ArrayUtils; import org.apache.commons.lang.ArrayUtils;
...@@ -220,7 +221,7 @@ public class KPIServiceImpl implements KPIService { ...@@ -220,7 +221,7 @@ public class KPIServiceImpl implements KPIService {
} }
LOG.debug(paQuery.toString()); 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()); return new HashSet<T>(q.getResultList());
} else { } else {
......
...@@ -64,13 +64,13 @@ public class KpiScheduledExecutor { ...@@ -64,13 +64,13 @@ public class KpiScheduledExecutor {
Page<Execution> executions; Page<Execution> executions;
do { do {
executions = kpiService.listExecutions(new PageRequest(page, chunkSize)); executions = kpiService.listExecutions(new PageRequest(page, chunkSize));
for (Execution ex : executions.getContent()) { for (Execution execution : executions.getContent()) {
try { try {
LOG.info("Started execution {} after {}ms", ex.getName(), stopWatch.getTime()); LOG.info("Started execution {} after {}ms", execution.getName(), stopWatch.getTime());
kpiService.execute(ex); kpiService.executeAndSave(execution);
LOG.info("Execution {} successful after {}ms", ex.getName(), stopWatch.getTime()); LOG.info("Execution {} successful after {}ms", execution.getName(), stopWatch.getTime());
} catch (Throwable e) { } 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++; 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