create web application
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
package org.lucares.pdbui;
|
||||
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
@ComponentScan("org.lucares.pdbui")
|
||||
// @PropertySource("classpath:/config.system.properties")
|
||||
// @PropertySource("classpath:/config.user.properties")
|
||||
public class MySpringConfiguration {
|
||||
|
||||
}
|
||||
14
pdb-ui/src/main/java/org/lucares/pdbui/MyWebapp.java
Normal file
14
pdb-ui/src/main/java/org/lucares/pdbui/MyWebapp.java
Normal file
@@ -0,0 +1,14 @@
|
||||
package org.lucares.pdbui;
|
||||
|
||||
import java.nio.file.Paths;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
|
||||
public class MyWebapp {
|
||||
|
||||
public static final String IMAGE_DIR = Paths.get("/tmp/images").toFile().getAbsolutePath() + "/";
|
||||
|
||||
public static void main(final String[] args) throws Exception {
|
||||
SpringApplication.run(MySpringConfiguration.class, args);
|
||||
}
|
||||
}
|
||||
34
pdb-ui/src/main/java/org/lucares/pdbui/PdbController.java
Normal file
34
pdb-ui/src/main/java/org/lucares/pdbui/PdbController.java
Normal file
@@ -0,0 +1,34 @@
|
||||
package org.lucares.pdbui;
|
||||
|
||||
import org.lucares.pdbui.domain.PlotRequest;
|
||||
import org.lucares.pdbui.domain.PlotResponse;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
@Controller
|
||||
@EnableAutoConfiguration
|
||||
public class PdbController {
|
||||
|
||||
private final PdbRepository pdbRepository;
|
||||
|
||||
public PdbController(final PdbRepository pdbRepository) {
|
||||
this.pdbRepository = pdbRepository;
|
||||
}
|
||||
|
||||
@RequestMapping(path = "/plots", //
|
||||
method = RequestMethod.POST, //
|
||||
consumes = MediaType.APPLICATION_JSON_UTF8_VALUE, //
|
||||
produces = MediaType.APPLICATION_JSON_UTF8_VALUE //
|
||||
)
|
||||
@ResponseBody
|
||||
PlotResponse createPlot(@RequestBody final PlotRequest request) {
|
||||
System.out.println(request.getQuery());
|
||||
return new PlotResponse("img/abc.png");
|
||||
}
|
||||
|
||||
}
|
||||
19
pdb-ui/src/main/java/org/lucares/pdbui/PdbRepository.java
Normal file
19
pdb-ui/src/main/java/org/lucares/pdbui/PdbRepository.java
Normal file
@@ -0,0 +1,19 @@
|
||||
package org.lucares.pdbui;
|
||||
|
||||
import org.lucares.performance.db.PerformanceDb;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public class PdbRepository implements DisposableBean {
|
||||
private final PerformanceDb db;
|
||||
|
||||
public PdbRepository(final PerformanceDb db) {
|
||||
this.db = db;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
db.close();
|
||||
}
|
||||
}
|
||||
14
pdb-ui/src/main/java/org/lucares/pdbui/WebConfiguration.java
Normal file
14
pdb-ui/src/main/java/org/lucares/pdbui/WebConfiguration.java
Normal file
@@ -0,0 +1,14 @@
|
||||
package org.lucares.pdbui;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
||||
|
||||
@Configuration
|
||||
public class WebConfiguration extends WebMvcConfigurerAdapter {
|
||||
|
||||
@Override
|
||||
public void addResourceHandlers(final ResourceHandlerRegistry registry) {
|
||||
registry.addResourceHandler("/img/**").addResourceLocations("file:" + MyWebapp.IMAGE_DIR);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package org.lucares.pdbui.domain;
|
||||
|
||||
public class PlotRequest {
|
||||
private String query;
|
||||
|
||||
public String getQuery() {
|
||||
return query;
|
||||
}
|
||||
|
||||
public void setQuery(final String query) {
|
||||
this.query = query;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return query;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package org.lucares.pdbui.domain;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class PlotResponse {
|
||||
private List<String> imageUrls = new ArrayList<>();
|
||||
|
||||
public PlotResponse() {
|
||||
super();
|
||||
}
|
||||
|
||||
public PlotResponse(final String... imageUrls) {
|
||||
this.imageUrls.addAll(Arrays.asList(imageUrls));
|
||||
}
|
||||
|
||||
public List<String> getImageUrls() {
|
||||
return imageUrls;
|
||||
}
|
||||
|
||||
public void setImageUrls(final List<String> imageUrls) {
|
||||
this.imageUrls = imageUrls;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.valueOf(imageUrls);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user