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

clean articles and models controllers

parent a50b7a29
No related branches found
No related tags found
No related merge requests found
......@@ -89,10 +89,9 @@ public class ArticlesApi {
}
article.setCreatedBy(user);
Long count;
int i = 0;
do{
i++;
long count = 1;
for(int i = 0; count > 0; i++)
{
count = articleRepository.countByTitle(article.getTitle());
if(count > 0)
......@@ -104,7 +103,7 @@ public class ArticlesApi {
}
article.setTitle(title + " (" + i + ")");
}
} while(count > 0);
}
String slug;
try {
......@@ -114,10 +113,9 @@ public class ArticlesApi {
LOGGER.trace(e);
}
i = 0;
boolean alreadyExists;
do {
i++;
boolean alreadyExists = true;
for(int i = 0; alreadyExists; i++)
{
alreadyExists = articleRepository.exists(slug);
if(alreadyExists)
{
......@@ -128,7 +126,7 @@ public class ArticlesApi {
slug += "-"+i;
}
article.setSlug(slug);
} while(alreadyExists);
}
articleRepository.save(article);
return new ResponseEntity<>(HttpStatus.CREATED);
......@@ -175,10 +173,9 @@ public class ArticlesApi {
String newTitle = article.getTitle();
if(!newTitle.equals(oldTitle)) {
Long count;
int i = 0;
do {
i++;
long count = 1;
for(int i = 0; count > 0 && !newTitle.equals(oldTitle); i++)
{
newTitle = article.getTitle();
count = articleRepository.countByTitle(newTitle);
if (count > 0 && !newTitle.equals(oldTitle)) {
......@@ -187,7 +184,7 @@ public class ArticlesApi {
}
article.setTitle(newTitle + " (" + i + ")");
}
} while (count > 0 && !newTitle.equals(oldTitle));
}
}
articleRepository.save(article);
......
......@@ -109,10 +109,9 @@ public class ModelsApi {
model.setValid(false);
}
Long count;
int i = 0;
do{
i++;
long count = 1;
for(int i = 0; count > 0; i++)
{
count = modelRepository.countByTitle(model.getTitle());
if(count > 0)
......@@ -124,7 +123,7 @@ public class ModelsApi {
}
model.setTitle(title + " (" + i + ")");
}
} while(count > 0);
}
String slug = null;
try {
......@@ -134,10 +133,9 @@ public class ModelsApi {
LOGGER.trace(e);
}
i = 0;
boolean alreadyExists;
do {
i++;
boolean alreadyExists = true;
for(int i = 0; alreadyExists; i++)
{
alreadyExists = modelRepository.exists(slug);
if(alreadyExists)
{
......@@ -148,7 +146,7 @@ public class ModelsApi {
slug += "-"+i;
}
model.setSlug(slug);
} while(alreadyExists);
}
Map<String, String> map = new HashMap<>(model.getConfig().getTitle());
map.put("text", model.getTitle());
......@@ -179,59 +177,6 @@ public class ModelsApi {
return new ResponseEntity<>(HttpStatus.FORBIDDEN);
}
if(model != null) {
org.hbp.mip.model.Query q = null;
q = queryRepository.findOne(model.getQuery().getId());
if(q != null) {
List<Variable> vars = new LinkedList<>();
for (Variable var : q.getVariables()) {
Variable v = new Variable();
v.setCode(var.getCode());
vars.add(v);
}
List<Variable> covs = new LinkedList<>();
for (Variable cov : q.getCovariables()) {
Variable v = new Variable();
v.setCode(cov.getCode());
covs.add(v);
}
List<Variable> grps = new LinkedList<>();
for (Variable grp : q.getGrouping()) {
Variable v = new Variable();
v.setCode(grp.getCode());
grps.add(v);
}
List<Filter> fltrs = new LinkedList<>();
for (Filter fltr : q.getFilters()) {
Filter f = new Filter();
f.setId(fltr.getId());
f.setOperator(fltr.getOperator());
f.setValues(fltr.getValues());
f.setVariable(fltr.getVariable());
fltrs.add(f);
}
org.hbp.mip.model.Query myQuery = new org.hbp.mip.model.Query();
myQuery.setId(q.getId());
myQuery.setVariables(vars);
myQuery.setCovariables(covs);
myQuery.setGrouping(grps);
myQuery.setFilters(fltrs);
model.setQuery(myQuery);
}
Dataset ds = csvUtil.parseValues(DATA_FILE, model.getQuery());
model.setDataset(ds);
}
return new ResponseEntity<>(HttpStatus.OK).ok(model);
}
......@@ -261,10 +206,9 @@ public class ModelsApi {
String newTitle = model.getTitle();
if(!newTitle.equals(oldTitle)) {
Long count;
int i = 0;
do {
i++;
long count = 1;
for(int i = 0; count > 0 && !newTitle.equals(oldTitle); i++)
{
newTitle = model.getTitle();
count = modelRepository.countByTitle(newTitle);
if (count > 0 && !newTitle.equals(oldTitle)) {
......@@ -273,7 +217,7 @@ public class ModelsApi {
}
model.setTitle(newTitle + " (" + i + ")");
}
} while (count > 0 && !newTitle.equals(oldTitle));
}
}
Map<String, String> map = new HashMap<>(model.getConfig().getTitle());
......
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