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 { ...@@ -89,10 +89,9 @@ public class ArticlesApi {
} }
article.setCreatedBy(user); article.setCreatedBy(user);
Long count; long count = 1;
int i = 0; for(int i = 0; count > 0; i++)
do{ {
i++;
count = articleRepository.countByTitle(article.getTitle()); count = articleRepository.countByTitle(article.getTitle());
if(count > 0) if(count > 0)
...@@ -104,7 +103,7 @@ public class ArticlesApi { ...@@ -104,7 +103,7 @@ public class ArticlesApi {
} }
article.setTitle(title + " (" + i + ")"); article.setTitle(title + " (" + i + ")");
} }
} while(count > 0); }
String slug; String slug;
try { try {
...@@ -114,10 +113,9 @@ public class ArticlesApi { ...@@ -114,10 +113,9 @@ public class ArticlesApi {
LOGGER.trace(e); LOGGER.trace(e);
} }
i = 0; boolean alreadyExists = true;
boolean alreadyExists; for(int i = 0; alreadyExists; i++)
do { {
i++;
alreadyExists = articleRepository.exists(slug); alreadyExists = articleRepository.exists(slug);
if(alreadyExists) if(alreadyExists)
{ {
...@@ -128,7 +126,7 @@ public class ArticlesApi { ...@@ -128,7 +126,7 @@ public class ArticlesApi {
slug += "-"+i; slug += "-"+i;
} }
article.setSlug(slug); article.setSlug(slug);
} while(alreadyExists); }
articleRepository.save(article); articleRepository.save(article);
return new ResponseEntity<>(HttpStatus.CREATED); return new ResponseEntity<>(HttpStatus.CREATED);
...@@ -175,10 +173,9 @@ public class ArticlesApi { ...@@ -175,10 +173,9 @@ public class ArticlesApi {
String newTitle = article.getTitle(); String newTitle = article.getTitle();
if(!newTitle.equals(oldTitle)) { if(!newTitle.equals(oldTitle)) {
Long count; long count = 1;
int i = 0; for(int i = 0; count > 0 && !newTitle.equals(oldTitle); i++)
do { {
i++;
newTitle = article.getTitle(); newTitle = article.getTitle();
count = articleRepository.countByTitle(newTitle); count = articleRepository.countByTitle(newTitle);
if (count > 0 && !newTitle.equals(oldTitle)) { if (count > 0 && !newTitle.equals(oldTitle)) {
...@@ -187,7 +184,7 @@ public class ArticlesApi { ...@@ -187,7 +184,7 @@ public class ArticlesApi {
} }
article.setTitle(newTitle + " (" + i + ")"); article.setTitle(newTitle + " (" + i + ")");
} }
} while (count > 0 && !newTitle.equals(oldTitle)); }
} }
articleRepository.save(article); articleRepository.save(article);
......
...@@ -109,10 +109,9 @@ public class ModelsApi { ...@@ -109,10 +109,9 @@ public class ModelsApi {
model.setValid(false); model.setValid(false);
} }
Long count; long count = 1;
int i = 0; for(int i = 0; count > 0; i++)
do{ {
i++;
count = modelRepository.countByTitle(model.getTitle()); count = modelRepository.countByTitle(model.getTitle());
if(count > 0) if(count > 0)
...@@ -124,7 +123,7 @@ public class ModelsApi { ...@@ -124,7 +123,7 @@ public class ModelsApi {
} }
model.setTitle(title + " (" + i + ")"); model.setTitle(title + " (" + i + ")");
} }
} while(count > 0); }
String slug = null; String slug = null;
try { try {
...@@ -134,10 +133,9 @@ public class ModelsApi { ...@@ -134,10 +133,9 @@ public class ModelsApi {
LOGGER.trace(e); LOGGER.trace(e);
} }
i = 0; boolean alreadyExists = true;
boolean alreadyExists; for(int i = 0; alreadyExists; i++)
do { {
i++;
alreadyExists = modelRepository.exists(slug); alreadyExists = modelRepository.exists(slug);
if(alreadyExists) if(alreadyExists)
{ {
...@@ -148,7 +146,7 @@ public class ModelsApi { ...@@ -148,7 +146,7 @@ public class ModelsApi {
slug += "-"+i; slug += "-"+i;
} }
model.setSlug(slug); model.setSlug(slug);
} while(alreadyExists); }
Map<String, String> map = new HashMap<>(model.getConfig().getTitle()); Map<String, String> map = new HashMap<>(model.getConfig().getTitle());
map.put("text", model.getTitle()); map.put("text", model.getTitle());
...@@ -179,59 +177,6 @@ public class ModelsApi { ...@@ -179,59 +177,6 @@ public class ModelsApi {
return new ResponseEntity<>(HttpStatus.FORBIDDEN); 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); return new ResponseEntity<>(HttpStatus.OK).ok(model);
} }
...@@ -261,10 +206,9 @@ public class ModelsApi { ...@@ -261,10 +206,9 @@ public class ModelsApi {
String newTitle = model.getTitle(); String newTitle = model.getTitle();
if(!newTitle.equals(oldTitle)) { if(!newTitle.equals(oldTitle)) {
Long count; long count = 1;
int i = 0; for(int i = 0; count > 0 && !newTitle.equals(oldTitle); i++)
do { {
i++;
newTitle = model.getTitle(); newTitle = model.getTitle();
count = modelRepository.countByTitle(newTitle); count = modelRepository.countByTitle(newTitle);
if (count > 0 && !newTitle.equals(oldTitle)) { if (count > 0 && !newTitle.equals(oldTitle)) {
...@@ -273,7 +217,7 @@ public class ModelsApi { ...@@ -273,7 +217,7 @@ public class ModelsApi {
} }
model.setTitle(newTitle + " (" + i + ")"); model.setTitle(newTitle + " (" + i + ")");
} }
} while (count > 0 && !newTitle.equals(oldTitle)); }
} }
Map<String, String> map = new HashMap<>(model.getConfig().getTitle()); 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