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

Merge branch 'sonar_suggestions' into 'stable'

Sonar suggestions

Did some re-factoring.

See merge request !10
parents fde60129 12c95e0d
No related branches found
No related tags found
No related merge requests found
This diff is collapsed.
......@@ -5,12 +5,19 @@ import com.google.gson.GsonBuilder;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.annotations.Expose;
import org.apache.log4j.Logger;
import org.hbp.mip.utils.HibernateUtil;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.annotations.*;
import org.hibernate.exception.DataException;
import javax.persistence.*;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import java.util.UUID;
/**
......@@ -20,6 +27,8 @@ import java.util.UUID;
@Table(name = "`experiment`")
public class Experiment {
private static final Logger LOGGER = Logger.getLogger(Experiment.class);
private static final Gson gson = new GsonBuilder()
.serializeNulls()
.setDateFormat("yyyy-MM-dd'T'HH:mm:ssZ")
......@@ -94,6 +103,63 @@ public class Experiment {
return outgoingQuery.toString();
}
public String computeExaremeQuery() {
List<ExaremeQueryElement> queryElements = new LinkedList<>();
for (Variable var : model.getQuery().getVariables())
{
ExaremeQueryElement el = new ExaremeQueryElement();
el.setName("variable");
el.setDesc("");
el.setValue(var.getCode());
queryElements.add(el);
}
for (Variable var : model.getQuery().getCovariables())
{
ExaremeQueryElement el = new ExaremeQueryElement();
el.setName("covariables");
el.setDesc("");
el.setValue(var.getCode());
queryElements.add(el);
}
for (Variable var : model.getQuery().getGrouping())
{
ExaremeQueryElement el = new ExaremeQueryElement();
el.setName("groupings");
el.setDesc("");
el.setValue(var.getCode());
queryElements.add(el);
}
ExaremeQueryElement tableEl = new ExaremeQueryElement();
tableEl.setName("showtable");
tableEl.setDesc("");
tableEl.setValue("TotalResults");
queryElements.add(tableEl);
ExaremeQueryElement formatEl = new ExaremeQueryElement();
formatEl.setName("format");
formatEl.setDesc("");
formatEl.setValue("True");
queryElements.add(formatEl);
return new Gson().toJson(queryElements);
}
public void finish() {
this.setFinished(new Date());
try {
Session session = HibernateUtil.getSessionFactory().openSession();
Transaction transaction = session.beginTransaction();
session.update(this);
transaction.commit();
session.close();
} catch (DataException e) {
LOGGER.trace(e);
throw e;
}
}
public String getValidations() {
return validations;
}
......
package org.hbp.mip.utils;
import com.google.gson.JsonParseException;
import com.google.gson.JsonParser;
import org.apache.log4j.Logger;
/**
* Created by mirco on 01.07.16.
*/
public class JSONUtil {
private static final Logger LOGGER = Logger.getLogger(JSONUtil.class);
private JSONUtil() {
/* Hide implicit public constructor */
throw new IllegalAccessError("JSONUtil class");
}
public static boolean isJSONValid(String test) {
try {
new JsonParser().parse(test);
} catch (JsonParseException jpe)
{
LOGGER.trace(jpe); // This is the normal behavior when the input string is not JSON-ified
return false;
}
return true;
}
}
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