+ Anfang Dateien Verwaltung
Signed-off-by: Johannes Theiner <j.theiner@live.de> #SPM-7 add work development 1h
This commit is contained in:
parent
691481dbc5
commit
fbcd9e913f
13
pom.xml
13
pom.xml
|
@ -80,6 +80,13 @@
|
|||
<server>TomcatServer</server>
|
||||
<path>/bauDas</path>
|
||||
</configuration>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>javax.servlet-api</artifactId>
|
||||
<version>4.0.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
|
@ -258,6 +265,12 @@
|
|||
<version>3.8.3</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
<version>2.8.2</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!--Annotations-->
|
||||
<dependency>
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
package de.hsel.spm.baudas.web;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
/**
|
||||
* @author Johannes Theiner
|
||||
* @version 0.1
|
||||
* @since 0.1
|
||||
**/
|
||||
public class Data {
|
||||
|
||||
@Getter
|
||||
private static ConcurrentMap<UUID, String> files = new ConcurrentHashMap<>();
|
||||
|
||||
|
||||
public static Path add(String name) {
|
||||
Path path;
|
||||
if(files.size() >= 5) {
|
||||
path = null;
|
||||
files.put(UUID.randomUUID(), name);
|
||||
}else {
|
||||
UUID uuid = UUID.randomUUID();
|
||||
files.put(uuid, name);
|
||||
path = Paths.get("target/" + uuid + ".csv");
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
public static File get(int index) {
|
||||
return new File("target/" + index + ".csv");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package de.hsel.spm.baudas.web;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.servlet.annotation.WebServlet;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
/**
|
||||
* @author Johannes Theiner
|
||||
* @version 0.1
|
||||
* @since 0.1
|
||||
**/
|
||||
|
||||
@WebServlet("/files")
|
||||
public class Files extends HttpServlet {
|
||||
|
||||
@Override
|
||||
protected void doGet(@NotNull HttpServletRequest req, @NotNull HttpServletResponse resp) throws IOException {
|
||||
resp.setContentType("application/json");
|
||||
PrintWriter out = resp.getWriter();
|
||||
Gson gson = new Gson();
|
||||
out.println(gson.toJson(Data.getFiles()));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
package de.hsel.spm.baudas.web;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.annotation.MultipartConfig;
|
||||
import javax.servlet.annotation.WebServlet;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.Part;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
|
||||
/**
|
||||
* @author Johannes Theiner
|
||||
* @version 0.1
|
||||
* @since 0.1
|
||||
**/
|
||||
|
||||
@WebServlet("/upload")
|
||||
@MultipartConfig
|
||||
public class Upload extends HttpServlet {
|
||||
|
||||
@Override
|
||||
protected void doPost(@NotNull HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
req.setCharacterEncoding(StandardCharsets.UTF_8.name());
|
||||
|
||||
Part filePart = req.getPart("file");
|
||||
String fileName = Paths.get(filePart.getSubmittedFileName()).getFileName().toString();
|
||||
InputStream inputStream = filePart.getInputStream();
|
||||
|
||||
|
||||
Path path = Data.add(fileName);
|
||||
System.out.println(path);
|
||||
if(!Files.exists(path)) {
|
||||
Files.createFile(path);
|
||||
}
|
||||
|
||||
Files.copy(inputStream, path, StandardCopyOption.REPLACE_EXISTING);
|
||||
|
||||
resp.sendRedirect("files");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
<%@ page import="weka.core.Version" %>
|
||||
Server info: <%= application.getServerInfo() %><br>
|
||||
Servlet version: <%= application.getMajorVersion() %>.<%= application.getMinorVersion() %><br>
|
||||
JSP version: <%= JspFactory.getDefaultFactory().getEngineInfo().getSpecificationVersion() %><br>
|
||||
Java version: <%= System.getProperty("java.version") %><br>
|
||||
|
||||
Weka version: <%= Version.VERSION %>
|
Loading…
Reference in New Issue