Skip to content
Snippets Groups Projects
Commit ba361cfd authored by Mirco Nasuti's avatar Mirco Nasuti
Browse files

bugfix duplicate variables

parent 11034ba9
No related branches found
No related tags found
No related merge requests found
...@@ -89,6 +89,8 @@ public class ExperimentApi { ...@@ -89,6 +89,8 @@ public class ExperimentApi {
LOGGER.info("Experiment saved"); LOGGER.info("Experiment saved");
experiment.getModel().cureVariables();
try { try {
if(isExaremeAlgo(experiment)) if(isExaremeAlgo(experiment))
{ {
...@@ -124,6 +126,9 @@ public class ExperimentApi { ...@@ -124,6 +126,9 @@ public class ExperimentApi {
if (experiment == null) { if (experiment == null) {
return new ResponseEntity<>("Not found", HttpStatus.NOT_FOUND); return new ResponseEntity<>("Not found", HttpStatus.NOT_FOUND);
} }
experiment.getModel().cureVariables();
return new ResponseEntity<>(gson.toJson(experiment), HttpStatus.OK); return new ResponseEntity<>(gson.toJson(experiment), HttpStatus.OK);
} }
...@@ -152,6 +157,8 @@ public class ExperimentApi { ...@@ -152,6 +157,8 @@ public class ExperimentApi {
LOGGER.info("Experiment updated (marked as viewed)"); LOGGER.info("Experiment updated (marked as viewed)");
experiment.getModel().cureVariables();
return new ResponseEntity<>(gson.toJson(experiment), HttpStatus.OK); return new ResponseEntity<>(gson.toJson(experiment), HttpStatus.OK);
} }
...@@ -280,6 +287,8 @@ public class ExperimentApi { ...@@ -280,6 +287,8 @@ public class ExperimentApi {
LOGGER.info("Experiment updated (marked as shared)"); LOGGER.info("Experiment updated (marked as shared)");
experiment.getModel().cureVariables();
return new ResponseEntity<>(gson.toJson(experiment), HttpStatus.OK); return new ResponseEntity<>(gson.toJson(experiment), HttpStatus.OK);
} }
......
...@@ -52,7 +52,7 @@ public class ModelsApi { ...@@ -52,7 +52,7 @@ public class ModelsApi {
@ApiOperation(value = "Get models", response = Model.class, responseContainer = "List") @ApiOperation(value = "Get models", response = Model.class, responseContainer = "List")
@ApiResponses(value = { @ApiResponse(code = 200, message = "Success") }) @ApiResponses(value = { @ApiResponse(code = 200, message = "Success") })
@RequestMapping(method = RequestMethod.GET) @RequestMapping(method = RequestMethod.GET)
public ResponseEntity<Iterable> getModels( public ResponseEntity<List> getModels(
@ApiParam(value = "Max number of results") @RequestParam(value = "limit", required = false) Integer limit, @ApiParam(value = "Max number of results") @RequestParam(value = "limit", required = false) Integer limit,
@ApiParam(value = "Only ask own models") @RequestParam(value = "own", required = false) Boolean own, @ApiParam(value = "Only ask own models") @RequestParam(value = "own", required = false) Boolean own,
@ApiParam(value = "Only ask models from own team") @RequestParam(value = "team", required = false) Boolean team, @ApiParam(value = "Only ask models from own team") @RequestParam(value = "team", required = false) Boolean team,
...@@ -72,6 +72,7 @@ public class ModelsApi { ...@@ -72,6 +72,7 @@ public class ModelsApi {
models = modelRepository.findByValidOrCreatedByOrderByCreatedAt(true, user); models = modelRepository.findByValidOrCreatedByOrderByCreatedAt(true, user);
} }
List<Model> modelsList = new LinkedList<>();
if(valid != null && models != null) if(valid != null && models != null)
{ {
for (Iterator<Model> i = models.iterator(); i.hasNext(); ) for (Iterator<Model> i = models.iterator(); i.hasNext(); )
...@@ -82,10 +83,15 @@ public class ModelsApi { ...@@ -82,10 +83,15 @@ public class ModelsApi {
{ {
i.remove(); i.remove();
} }
else
{
m.cureVariables();
modelsList.add(m);
}
} }
} }
return new ResponseEntity<List<Model>>(HttpStatus.OK).ok(models); return new ResponseEntity<List<Model>>(HttpStatus.OK).ok(modelsList);
} }
...@@ -197,33 +203,11 @@ public class ModelsApi { ...@@ -197,33 +203,11 @@ public class ModelsApi {
Collection<String> yAxisVarsColl = new LinkedHashSet<>(yAxisVars); Collection<String> yAxisVarsColl = new LinkedHashSet<>(yAxisVars);
model.getConfig().setyAxisVariables(new LinkedList<>(yAxisVarsColl)); model.getConfig().setyAxisVariables(new LinkedList<>(yAxisVarsColl));
List<Variable> varsQuery = queryRepository.findOne(model.getQuery().getId()).getVariables();
Collection<Variable> varsQueryColl = new LinkedHashSet<>(varsQuery);
model.getQuery().setVariables(new LinkedList<>(varsQueryColl));
List<Variable> grpgsQuery = queryRepository.findOne(model.getQuery().getId()).getGrouping();
Collection<Variable> grpgsQueryColl = new LinkedHashSet<>(grpgsQuery);
model.getQuery().setGrouping(new LinkedList<>(grpgsQueryColl));
List<Variable> covarsQuery = queryRepository.findOne(model.getQuery().getId()).getCovariables();
Collection<Variable> covarsQueryColl = new LinkedHashSet<>(covarsQuery);
model.getQuery().setCovariables(new LinkedList<>(covarsQueryColl));
List<Filter> fltrs = queryRepository.findOne(model.getQuery().getId()).getFilters(); List<Filter> fltrs = queryRepository.findOne(model.getQuery().getId()).getFilters();
Collection<Filter> fltrsColl = new LinkedHashSet<>(fltrs); Collection<Filter> fltrsColl = new LinkedHashSet<>(fltrs);
model.getQuery().setFilters(new LinkedList<>(fltrsColl)); model.getQuery().setFilters(new LinkedList<>(fltrsColl));
List<String> varsDS = datasetRepository.findOne(model.getDataset().getCode()).getVariable(); model.cureVariables();
Collection<String> varsDSColl = new LinkedHashSet<>(varsDS);
model.getDataset().setVariable(new LinkedList<>(varsDSColl));
List<String> grpgsDS = datasetRepository.findOne(model.getDataset().getCode()).getGrouping();
Collection<String> grpgsDSColl = new LinkedHashSet<>(grpgsDS);
model.getDataset().setGrouping(new LinkedList<>(grpgsDSColl));
List<String> headersDS = datasetRepository.findOne(model.getDataset().getCode()).getHeader();
Collection<String> headersDSColl = new LinkedHashSet<>(headersDS);
model.getDataset().setHeader(new LinkedList<>(headersDSColl));
return new ResponseEntity<>(HttpStatus.OK).ok(model); return new ResponseEntity<>(HttpStatus.OK).ok(model);
} }
......
...@@ -11,7 +11,10 @@ import org.hibernate.annotations.Cascade; ...@@ -11,7 +11,10 @@ import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType; import org.hibernate.annotations.CascadeType;
import javax.persistence.*; import javax.persistence.*;
import java.util.Collection;
import java.util.Date; import java.util.Date;
import java.util.LinkedHashSet;
import java.util.LinkedList;
@Entity @Entity
@Table(name = "`model`") @Table(name = "`model`")
...@@ -172,4 +175,25 @@ public class Model { ...@@ -172,4 +175,25 @@ public class Model {
this.textQuery = textQuery; this.textQuery = textQuery;
} }
public void cureVariables()
{
Collection<Variable> varsQueryColl = new LinkedHashSet<>(this.getQuery().getVariables());
this.getQuery().setVariables(new LinkedList<>(varsQueryColl));
Collection<Variable> coVarsQueryColl = new LinkedHashSet<>(this.getQuery().getCovariables());
this.getQuery().setCovariables(new LinkedList<>(coVarsQueryColl));
Collection<Variable> grpsQueryColl = new LinkedHashSet<>(this.getQuery().getGrouping());
this.getQuery().setGrouping(new LinkedList<>(grpsQueryColl));
Collection<String> varsDSQueryColl = new LinkedHashSet<>(this.getDataset().getVariable());
this.getDataset().setVariable(new LinkedList<>(varsDSQueryColl));
Collection<String> coVarsDSQueryColl = new LinkedHashSet<>(this.getDataset().getHeader());
this.getDataset().setHeader(new LinkedList<>(coVarsDSQueryColl));
Collection<String> grpsDSQueryColl = new LinkedHashSet<>(this.getDataset().getGrouping());
this.getDataset().setGrouping(new LinkedList<>(grpsDSQueryColl));
}
} }
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