mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-11 16:05:44 +01:00
Heed sonar hints
This commit is contained in:
@@ -3,6 +3,8 @@ package sonia.scm.update;
|
||||
import com.github.mustachejava.DefaultMustacheFactory;
|
||||
import com.github.mustachejava.Mustache;
|
||||
import com.github.mustachejava.MustacheFactory;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import sonia.scm.boot.RestartEvent;
|
||||
import sonia.scm.event.ScmEventBus;
|
||||
import sonia.scm.update.repository.MigrationStrategy;
|
||||
@@ -15,9 +17,11 @@ import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static java.util.Arrays.stream;
|
||||
import static java.util.stream.Collectors.toList;
|
||||
@@ -25,6 +29,8 @@ import static java.util.stream.Collectors.toList;
|
||||
@Singleton
|
||||
class MigrationWizardServlet extends HttpServlet {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(MigrationWizardServlet.class);
|
||||
|
||||
private final XmlRepositoryV1UpdateStep repositoryV1UpdateStep;
|
||||
private final MigrationStrategyDao migrationStrategyDao;
|
||||
|
||||
@@ -42,8 +48,6 @@ class MigrationWizardServlet extends HttpServlet {
|
||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
|
||||
List<XmlRepositoryV1UpdateStep.V1Repository> missingMigrationStrategies = repositoryV1UpdateStep.missingMigrationStrategies();
|
||||
|
||||
resp.setStatus(200);
|
||||
|
||||
HashMap<String, Object> model = new HashMap<>();
|
||||
|
||||
model.put("contextPath", req.getContextPath());
|
||||
@@ -52,8 +56,8 @@ class MigrationWizardServlet extends HttpServlet {
|
||||
model.put("strategies", getMigrationStrategies());
|
||||
|
||||
MustacheFactory mf = new DefaultMustacheFactory();
|
||||
Mustache mustache = mf.compile("templates/repository-migration.mustache");
|
||||
mustache.execute(resp.getWriter(), model).flush();
|
||||
Mustache template = mf.compile("templates/repository-migration.mustache");
|
||||
respondWithTemplate(resp, model, template);
|
||||
}
|
||||
|
||||
private List<String> getMigrationStrategies() {
|
||||
@@ -61,7 +65,7 @@ class MigrationWizardServlet extends HttpServlet {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
|
||||
protected void doPost(HttpServletRequest req, HttpServletResponse resp) {
|
||||
resp.setStatus(200);
|
||||
|
||||
req.getParameterMap().forEach(
|
||||
@@ -69,9 +73,25 @@ class MigrationWizardServlet extends HttpServlet {
|
||||
);
|
||||
|
||||
MustacheFactory mf = new DefaultMustacheFactory();
|
||||
Mustache mustache = mf.compile("templates/repository-migration-restart.mustache");
|
||||
mustache.execute(resp.getWriter(), Collections.singletonMap("contextPath", req.getContextPath())).flush();
|
||||
Mustache template = mf.compile("templates/repository-migration-restart.mustache");
|
||||
Map<String, Object> model = Collections.singletonMap("contextPath", req.getContextPath());
|
||||
|
||||
respondWithTemplate(resp, model, template);
|
||||
|
||||
ScmEventBus.getInstance().post(new RestartEvent(MigrationWizardServlet.class, "wrote migration data"));
|
||||
}
|
||||
|
||||
private void respondWithTemplate(HttpServletResponse resp, Map<String, Object> model, Mustache template) {
|
||||
PrintWriter writer;
|
||||
try {
|
||||
writer = resp.getWriter();
|
||||
} catch (IOException e) {
|
||||
LOG.error("could not create writer for response", e);
|
||||
resp.setStatus(500);
|
||||
return;
|
||||
}
|
||||
template.execute(writer, model);
|
||||
writer.flush();
|
||||
resp.setStatus(200);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user