-
Notifications
You must be signed in to change notification settings - Fork 2
First version BE #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
9971d9b
f632ac7
fc606a1
2ed58fd
3de14a5
f3c299e
306b259
3437048
6ce801c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| <modelVersion>4.0.0</modelVersion> | ||
|
|
||
| <groupId>com.keter-backend</groupId> | ||
| <artifactId>keter-backend</artifactId> | ||
| <version>0.0.1-SNAPSHOT</version> | ||
| <packaging>jar</packaging> | ||
|
|
||
| <name>keter-backend</name> | ||
| <description>Demo project for Spring Boot</description> | ||
|
|
||
| <parent> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-starter-parent</artifactId> | ||
| <version>2.0.3.RELEASE</version> | ||
| <relativePath/> <!-- lookup parent from repository --> | ||
| </parent> | ||
|
|
||
| <properties> | ||
| <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
| <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> | ||
| <java.version>1.8</java.version> | ||
| </properties> | ||
|
|
||
| <dependencies> | ||
| <dependency> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-starter-security</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-starter-web</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-starter-web-services</artifactId> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-starter-test</artifactId> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.springframework.security</groupId> | ||
| <artifactId>spring-security-test</artifactId> | ||
| <scope>test</scope> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>com.fasterxml.jackson.core</groupId> | ||
| <artifactId>jackson-core</artifactId> | ||
| <version>2.9.6</version> | ||
| </dependency> | ||
| </dependencies> | ||
|
|
||
| <build> | ||
| <plugins> | ||
| <plugin> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-maven-plugin</artifactId> | ||
| </plugin> | ||
| </plugins> | ||
| </build> | ||
|
|
||
|
|
||
| </project> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| package ru.avplatonov.keter.backend; | ||
|
|
||
| import org.springframework.boot.CommandLineRunner; | ||
| import org.springframework.boot.SpringApplication; | ||
| import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
| import org.springframework.context.ApplicationContext; | ||
| import org.springframework.context.annotation.AnnotationConfigApplicationContext; | ||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.Configuration; | ||
| import org.springframework.security.config.annotation.web.builders.WebSecurity; | ||
| import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; | ||
| import org.springframework.web.servlet.view.InternalResourceViewResolver; | ||
| import ru.avplatonov.keter.backend.db.GraphsDB; | ||
| import ru.avplatonov.keter.backend.db.NodesDB; | ||
|
|
||
| import java.util.Arrays; | ||
|
|
||
| @SpringBootApplication | ||
| public class Application { | ||
|
|
||
| public static ApplicationContext context; | ||
| public static GraphsDB graphsDB; | ||
| public static NodesDB nodesDB; | ||
|
|
||
| public static void main(String[] args) { | ||
| context = new AnnotationConfigApplicationContext(GraphsDB.class, NodesDB.class); | ||
| graphsDB = context.getBean(GraphsDB.class); | ||
| nodesDB = context.getBean(NodesDB.class); | ||
| SpringApplication.run(Application.class, args); | ||
| } | ||
|
|
||
| @Configuration | ||
| static class WebSecurityConfig extends WebSecurityConfigurerAdapter { | ||
| @Override | ||
| public void configure(WebSecurity web) throws Exception { | ||
| web.ignoring().antMatchers("/**"); | ||
| } | ||
| } | ||
|
|
||
| @Bean | ||
| public InternalResourceViewResolver jspViewResolver() { | ||
| InternalResourceViewResolver resolver= new InternalResourceViewResolver(); | ||
| resolver.setPrefix("/"); | ||
| return resolver; | ||
| } | ||
|
|
||
| @Bean | ||
| public CommandLineRunner commandLineRunner(ApplicationContext ctx) { | ||
| return args -> { | ||
|
|
||
| System.out.println("Let's inspect the beans provided by Spring Boot:"); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. replace all printlns onto logging through slf4j |
||
|
|
||
| String[] beanNames = ctx.getBeanDefinitionNames(); | ||
| Arrays.sort(beanNames); | ||
| for (String beanName : beanNames) { | ||
| System.out.println(beanName); | ||
| } | ||
| }; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| package ru.avplatonov.keter.backend.controllers; | ||
|
|
||
| import org.springframework.boot.autoconfigure.EnableAutoConfiguration; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| @RestController | ||
| @EnableAutoConfiguration | ||
| public class Index { | ||
|
|
||
| @RequestMapping("/") | ||
| public String index() { | ||
| return "Welcome to Keter"; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| package ru.avplatonov.keter.backend.controllers.management.create; | ||
|
|
||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import org.springframework.boot.autoconfigure.EnableAutoConfiguration; | ||
| import org.springframework.web.bind.annotation.RequestBody; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| import ru.avplatonov.keter.backend.initialize.GraphTemplate; | ||
| import ru.avplatonov.keter.backend.initialize.NodeTemplate; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.*; | ||
|
|
||
| import static ru.avplatonov.keter.backend.Application.graphsDB; | ||
| import static ru.avplatonov.keter.backend.Application.nodesDB; | ||
|
|
||
| @RestController | ||
| @EnableAutoConfiguration | ||
| public class CreateGraph { | ||
|
|
||
| @RequestMapping(value = "/create/graphs", | ||
| headers = {"Content-type=application/json"}) | ||
| public String service( | ||
| @RequestBody GraphTemplate graphTemplate | ||
| ) throws IOException { | ||
| ObjectMapper mapper = new ObjectMapper(); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As I know you can use only one ObjectMapper |
||
| //listOfNodes.add(graphTemplate); | ||
| if(createGraph(graphTemplate).isEmpty()) | ||
| return "Uuid of node is not found."; | ||
| return "listOfGraphs.size=" + graphsDB.getListOfGraphs().size() + "\n" + mapper.writeValueAsString(createGraph(graphTemplate)); | ||
| } | ||
|
|
||
| private Set<NodeTemplate> createGraph(GraphTemplate uuidNodesToGraphTemplate) { | ||
| Set<NodeTemplate> listOfGraphsLocal = new HashSet<>(); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. list of nodes, maybe? |
||
| for (UUID graphUuid : uuidNodesToGraphTemplate.getListOfUuidNodes()) { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. iteration over all nodes |
||
| boolean containsNode = false; | ||
| for (NodeTemplate nodeTemplateUuid : nodesDB.getListOfNodeTemplates()) { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nodesDB.contains(nodeUUID) -> boolean |
||
| if(graphUuid.equals(nodeTemplateUuid.getUuid())){ | ||
| containsNode = true; | ||
| listOfGraphsLocal.add(nodeTemplateUuid); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why graph is just set of node templates? |
||
| } | ||
| } | ||
| if(!containsNode) | ||
| return new HashSet<>(); | ||
| } | ||
| graphsDB.addListOfNodes(listOfGraphsLocal); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. graphsDB.saveTemplate |
||
| return listOfGraphsLocal; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| package ru.avplatonov.keter.backend.controllers.management.create; | ||
|
|
||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import org.springframework.boot.autoconfigure.EnableAutoConfiguration; | ||
| import org.springframework.web.bind.annotation.RequestBody; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
| import ru.avplatonov.keter.backend.initialize.NodeTemplate; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| import static ru.avplatonov.keter.backend.Application.nodesDB; | ||
|
|
||
| @RestController | ||
| @EnableAutoConfiguration | ||
| public class CreateNode { | ||
|
|
||
| @RequestMapping(value = "/create/nodes", | ||
| headers = {"Content-type=application/json"}) | ||
| public String service( | ||
| @RequestBody NodeTemplate nodeTemplate | ||
| ) throws IOException { | ||
| ObjectMapper mapper = new ObjectMapper(); | ||
| nodesDB.addListOfNodes(nodeTemplate); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nodesDB.saveTemplate(...) |
||
| return "listOfNode.size=" + nodesDB.getListOfNodeTemplates().size() + "\n" + mapper.writeValueAsString(nodeTemplate) ; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| package ru.avplatonov.keter.backend.controllers.management.graphs; | ||
|
|
||
| import com.fasterxml.jackson.core.JsonProcessingException; | ||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import org.springframework.boot.autoconfigure.EnableAutoConfiguration; | ||
| import org.springframework.lang.NonNull; | ||
| import org.springframework.web.bind.annotation.*; | ||
| import ru.avplatonov.keter.backend.initialize.NodeTemplate; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| import static ru.avplatonov.keter.backend.Application.nodesDB; | ||
|
|
||
| @RestController | ||
| @EnableAutoConfiguration | ||
| public class GraphListController { | ||
|
|
||
| @RequestMapping(value = "/graphs/{graphSearch}") | ||
| public String listOfGraphs( | ||
| @PathVariable("graphSearch") @NonNull String value | ||
| ) throws JsonProcessingException { | ||
| return value + "\n" + searchGraph(value); | ||
| } | ||
|
|
||
| private List<String> searchGraph(String value) throws JsonProcessingException { | ||
| List<String> listOfGraphs = new ArrayList<>(); | ||
| ObjectMapper mapper = new ObjectMapper(); | ||
| for (NodeTemplate nodeTemplate : nodesDB.getListOfNodeTemplates()) { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. iteration over DB |
||
| if (nodeTemplate.getDescription().contains(value) || nodeTemplate.getTags().contains(value) || nodeTemplate.getName().contains(value)){ | ||
| listOfGraphs.add(mapper.writeValueAsString(nodeTemplate)); | ||
| } | ||
| } | ||
| return listOfGraphs; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| package ru.avplatonov.keter.backend.controllers.management.nodes; | ||
|
|
||
| import com.fasterxml.jackson.core.JsonProcessingException; | ||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import org.springframework.boot.autoconfigure.EnableAutoConfiguration; | ||
| import org.springframework.lang.NonNull; | ||
| import org.springframework.web.bind.annotation.*; | ||
| import ru.avplatonov.keter.backend.initialize.NodeTemplate; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.Set; | ||
|
|
||
| import static ru.avplatonov.keter.backend.Application.nodesDB; | ||
|
|
||
| @RestController | ||
| @EnableAutoConfiguration | ||
| public class NodeListController { | ||
|
|
||
| @RequestMapping(value = "/nodes/all") | ||
| public Set<NodeTemplate> service() throws JsonProcessingException { | ||
| return nodesDB.getListOfNodeTemplates(); | ||
| } | ||
|
|
||
| @RequestMapping(value = "/nodes/{nodeSearch}") | ||
| public String service( | ||
| @PathVariable("nodeSearch") @NonNull String value | ||
| ) throws JsonProcessingException { | ||
| return value + "\n" + searchNode(value); //.toLowerCase() ? | ||
| } | ||
|
|
||
| private List<String> searchNode(String value) throws JsonProcessingException { | ||
| List<String> listOfNodes = new ArrayList<>(); | ||
| ObjectMapper mapper = new ObjectMapper(); | ||
| for (NodeTemplate nodeTemplate : nodesDB.getListOfNodeTemplates()) { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wrote about it above |
||
| if (nodeTemplate.getDescription().contains(value) || nodeTemplate.getTags().contains(value) || nodeTemplate.getName().contains(value)){ | ||
| listOfNodes.add(mapper.writeValueAsString(nodeTemplate)); | ||
| } | ||
| } | ||
| return listOfNodes; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| package ru.avplatonov.keter.backend.controllers.management.services; | ||
|
|
||
| import org.springframework.boot.autoconfigure.EnableAutoConfiguration; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| @RestController | ||
| @EnableAutoConfiguration | ||
| public class ServiceListController { | ||
|
|
||
| @GetMapping("/services") | ||
| public String service() { | ||
| return null; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| package ru.avplatonov.keter.backend.db; | ||
|
|
||
| import org.springframework.stereotype.Component; | ||
| import ru.avplatonov.keter.backend.initialize.NodeTemplate; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.Set; | ||
|
|
||
| @Component | ||
| public class GraphsDB { | ||
|
|
||
| private List<Set<NodeTemplate>> listOfGraphs = new ArrayList<>(); | ||
|
|
||
| public List<Set<NodeTemplate>> getListOfGraphs() { | ||
| return listOfGraphs; | ||
| } | ||
|
|
||
| public void setListOfGraphs(List<Set<NodeTemplate>> listOfGraphs) { | ||
| this.listOfGraphs = listOfGraphs; | ||
| } | ||
|
|
||
| public void addListOfNodes(Set<NodeTemplate> listOfGraphs){ | ||
| this.listOfGraphs.add(listOfGraphs); | ||
| } | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| package ru.avplatonov.keter.backend.db; | ||
|
|
||
| import org.springframework.stereotype.Component; | ||
| import ru.avplatonov.keter.backend.initialize.NodeTemplate; | ||
|
|
||
| import java.util.HashSet; | ||
| import java.util.Set; | ||
|
|
||
| @Component | ||
| public class NodesDB { | ||
|
|
||
| private Set<NodeTemplate> listOfNodeTemplates = new HashSet<>(); | ||
|
|
||
| public Set<NodeTemplate> getListOfNodeTemplates() { | ||
| return listOfNodeTemplates; | ||
| } | ||
|
|
||
| public void addListOfNodes(NodeTemplate listOfNodes){ | ||
| this.listOfNodeTemplates.add(listOfNodes); | ||
| } | ||
|
|
||
| public void setListOfNodeTemplates(Set<NodeTemplate> listOfNodeTemplates) { | ||
| this.listOfNodeTemplates = listOfNodeTemplates; | ||
| } | ||
|
|
||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use dep. injections through annontations
Don't use static fields and getBean explicitly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
http://websystique.com/spring/spring-dependency-injection-annotation-beans-auto-wiring-using-autowired-qualifier-resource-annotations-configuration/