Commit d072460b authored by Matija Obreza's avatar Matija Obreza
Browse files

Introduced ExecutionRun to group Observations

parent f11aded1
......@@ -144,4 +144,5 @@ public class Execution extends VersionedAuditedModel {
public void setTitle(String title) {
this.title = title;
}
}
/**
* Copyright 2014 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;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.genesys2.server.model.BusinessModel;
import com.fasterxml.jackson.annotation.JsonIgnore;
@Entity
@Table(name = "kpiexecutionrun")
public class ExecutionRun extends BusinessModel {
@Column(nullable = false)
@Temporal(TemporalType.TIMESTAMP)
private Date timestamp = new Date();
@JsonIgnore
@ManyToOne(cascade = {}, optional = false)
private Execution execution;
public Date getTimestamp() {
return timestamp;
}
public void setTimestamp(Date timestamp) {
this.timestamp = timestamp;
}
public Execution getExecution() {
return execution;
}
public void setExecution(Execution execution) {
this.execution = execution;
}
}
......@@ -16,7 +16,6 @@
package org.genesys2.server.model.kpi;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
......@@ -29,13 +28,9 @@ import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.PrePersist;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.genesys2.server.model.BusinessModel;
import com.fasterxml.jackson.annotation.JsonIgnore;
/**
* Holds results of {@link Execution} run.
*/
......@@ -43,17 +38,12 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
@Table(name = "kpiobservation")
public class Observation extends BusinessModel {
@Column(nullable = false)
@Temporal(TemporalType.TIMESTAMP)
private Date timestamp = new Date();
@Column(name = "`value`")
private double value;
@JsonIgnore
@ManyToOne(cascade = {}, fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "executionId")
private Execution execution;
@JoinColumn(name = "executionRunId")
private ExecutionRun executionRun;
@ManyToMany(fetch = FetchType.LAZY)
@JoinTable(name = "kpiobservationdimension", joinColumns = @JoinColumn(name = "observationId"), inverseJoinColumns = @JoinColumn(name = "dimensionKeyId"))
......@@ -91,24 +81,16 @@ public class Observation extends BusinessModel {
this.dimensionCount = dimensionCount;
}
public Date getTimestamp() {
return timestamp;
}
public void setTimestamp(Date timestamp) {
this.timestamp = timestamp;
}
public Execution getExecution() {
return execution;
public ExecutionRun getExecutionRun() {
return executionRun;
}
public void setExecution(Execution execution) {
this.execution = execution;
public void setExecutionRun(ExecutionRun executionRun) {
this.executionRun = executionRun;
}
@Override
public String toString() {
return execution.getName() + "=" + value + " D=" + dimensions + " T=" + timestamp.getTime();
return "value =" + value + " D=" + dimensions;
}
}
/**
* Copyright 2014 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.persistence.domain.kpi;
import java.util.List;
import org.genesys2.server.model.kpi.Execution;
import org.genesys2.server.model.kpi.ExecutionRun;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
public interface ExecutionRunRepository extends JpaRepository<ExecutionRun, Long> {
List<ExecutionRun> findByExecution(Execution execution, Pageable pageable);
}
......@@ -28,13 +28,14 @@ import org.springframework.data.jpa.repository.Query;
public interface ObservationRepository extends JpaRepository<Observation, Long>, ObservationCustomRepository {
@Query("select o from Observation o where o.executionRun.execution=?1")
List<Observation> findByExecution(Execution execution, Pageable page);
@Query("select o from Observation o where o.execution=?1 and ?2 member of o.dimensions order by o.timestamp desc")
@Query("select o from Observation o where o.executionRun.execution=?1 and ?2 member of o.dimensions order by o.executionRun.timestamp desc")
List<Observation> listObservationsByDimensionKey(Execution execution, DimensionKey next, Pageable page);
@Modifying
@Query("delete from Observation o where o.execution=?1")
@Query("delete from Observation o where o.executionRun.execution=?1")
void deleteByExecution(Execution execution);
}
......@@ -17,6 +17,7 @@
package org.genesys2.server.service.impl;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
......@@ -32,12 +33,14 @@ import org.apache.commons.logging.LogFactory;
import org.genesys2.server.model.kpi.Dimension;
import org.genesys2.server.model.kpi.DimensionKey;
import org.genesys2.server.model.kpi.Execution;
import org.genesys2.server.model.kpi.ExecutionRun;
import org.genesys2.server.model.kpi.JpaDimension;
import org.genesys2.server.model.kpi.KPIParameter;
import org.genesys2.server.model.kpi.Observation;
import org.genesys2.server.persistence.domain.kpi.DimensionKeyRepository;
import org.genesys2.server.persistence.domain.kpi.DimensionRepository;
import org.genesys2.server.persistence.domain.kpi.ExecutionRepository;
import org.genesys2.server.persistence.domain.kpi.ExecutionRunRepository;
import org.genesys2.server.persistence.domain.kpi.KPIParameterRepository;
import org.genesys2.server.persistence.domain.kpi.ObservationRepository;
import org.genesys2.server.service.KPIService;
......@@ -72,6 +75,9 @@ public class KPIServiceImpl implements KPIService {
@Autowired
private DimensionKeyRepository dimensionKeyRepository;
@Autowired
private ExecutionRunRepository executionRunRepository;
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#parameter, 'ADMINISTRATION')")
@Override
@Transactional
......@@ -221,8 +227,13 @@ public class KPIServiceImpl implements KPIService {
@Override
@Transactional
public List<Observation> save(Execution execution, List<Observation> observations) {
ExecutionRun executionRun=new ExecutionRun();
executionRun.setExecution(execution);
executionRun.setTimestamp(new Date());
executionRunRepository.save(executionRun);
for (Observation obs : observations) {
obs.setExecution(execution);
obs.setExecutionRun(executionRun);
Set<DimensionKey> dims = new HashSet<DimensionKey>();
for (DimensionKey dk : obs.getDimensions()) {
DimensionKey existing = dimensionKeyRepository.findByNameAndValue(dk.getName(), dk.getValue());
......@@ -271,7 +282,6 @@ public class KPIServiceImpl implements KPIService {
Observation observation = new Observation();
observation.setValue(res);
observation.setExecution(paramExec);
for (int i = 0; i < array.length; i++) {
String name = paramExec.getDimension(i).getName();
String value = array[i].toString();
......
......@@ -230,7 +230,6 @@ public class KPIServiceTest {
}
Observation observation = new Observation();
observation.setExecution(paramExec);
observation.setValue((Long) res);
for (int i = 0; i < array.length; i++) {
DimensionKey dk = new DimensionKey();
......
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