diff --git a/README.MD b/README.MD deleted file mode 100644 index 39c95bb..0000000 --- a/README.MD +++ /dev/null @@ -1,24 +0,0 @@ -This repository contains SpringBoot examples developed on **Spring Tool suite (STS)**. - -## **Branch Contents:** - -##### [1] [SpringBootMasterExample](https://github.com/rahulvaish/SpringBoot-Java/tree/SpringBootMasterClass) : SpringBoot examples with Eureka + MySQL + ConfigServer + APIGateway. -##### [2] [SpringBootMongo](https://github.com/rahulvaish/SpringBoot-Java/tree/SpringBootMongo) : SpringBoot example with MongoDB -##### [3] [SpringBootRedis](https://github.com/rahulvaish/SpringBoot-Java/tree/SpringBootRedis) : SpringBoot example with Redis -##### [4] [SpringBootActiveMQ](https://github.com/rahulvaish/ApacheActiveMQ) : SpringBoot example with ActiveMQ - Queues and Topics -##### [5] [SpringBootDocker](https://github.com/rahulvaish/SpringBoot-Java/tree/SpringBootDocker) : Hello Spring Boot example for Docker -##### [6] [SpringBootSwagger*](https://github.com/rahulvaish/SpringBoot-Java/tree/SpringBootSwagger) : SpringBoot example with Swagger UI. -##### [7] [SpringBootJPA & H2](https://github.com/rahulvaish/SpringBoot-Java/tree/SpringBootJPA) : SpringBoot example with MySQL | H2. -##### [8] [SpringBoot Circuit Breaker](https://github.com/rahulvaish/SpringBoot-Java/tree/SpringBootCircuitBreaker) : SpringBoot example with CB. -##### [9] [SpringBoot Consul - Centralised Config](https://github.com/rahulvaish/SpringBoot-Java/tree/SpringBootConsul) : SpringBootConsul - Centralised Config. -##### [10] [SpringBoot Vault - Centralised Credentials](https://github.com/rahulvaish/SpringBoot-Java/tree/SpringBootVault) : SpringBoot Vault - Centralised Credentials -##### [11] [SpringBoot Bean XML](https://github.com/rahulvaish/SpringBoot-Java/tree/SpringBootBeanConfig) : SpringBoot With XML Bean Config and normal @Bean config -##### [12] [SpringBoot Multimodule](https://github.com/rahulvaish/SpringBoot-Java/tree/SpringBootMultiModule) : SpringBoot Multi Module Project -##### [13] [SpringBoot Profiles and Environments](https://github.com/rahulvaish/SpringBoot-Java/tree/SpringBootProfiles) : SpringBoot Profiles and Environments -##### [14] [SpringBoot Cache](https://github.com/rahulvaish/SpringBoot-Java/tree/SpringBootCache) : SpringBoot Cache -##### [15] [SpringBoot API Key](https://github.com/rahulvaish/SpringBoot-Java/tree/SpringBootAPIKey) : SpringBoot API Key -##### [16] [SpringBoot Header](https://github.com/rahulvaish/SpringBoot-Java/tree/SpringBootHeader) : SpringBoot Header -##### [17] [SpringBoot Pagination](https://github.com/rahulvaish/SpringBoot-Java/tree/SpringBootPagination) : SpringBoot Pagination -##### [18] [SpringBoot Feature Flag](https://github.com/rahulvaish/SpringBoot-Java/tree/SpringBootFeatureFlag) : SpringBoot Feature Flag -##### [19] [SpringBoot Rate Limiter](https://github.com/rahulvaish/SpringBoot-Java/tree/SpringBootRateLimiter): SpringBootRateLimiter -##### [20] [SpringBoot Retry](https://github.com/rahulvaish/SpringBoot-Java/tree/SpringBootRetry): SpringBootRetry diff --git a/README.md b/README.md new file mode 100644 index 0000000..6797dec --- /dev/null +++ b/README.md @@ -0,0 +1,20 @@ +Start Neo4J: + +``` +docker run \ + --name my-neo4j-container2 \ + --publish=7474:7474 --publish=7687:7687 \ + --env NEO4J_AUTH=neo4j/password \ + --volume=$HOME/neo4j/data:/data \ + neo4j:latest + +``` +Neo4J started: +image + + + +image + + +image diff --git a/SpringBootNeo4J/.gitignore b/SpringBootNeo4J/.gitignore new file mode 100644 index 0000000..8540414 --- /dev/null +++ b/SpringBootNeo4J/.gitignore @@ -0,0 +1,36 @@ +HELP.md +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ +spring-neo4j/db/* +spring-neo4j/mvnw +spring-neo4j/mvnw.cmd \ No newline at end of file diff --git a/SpringBootNeo4J/.mvn/wrapper/maven-wrapper.jar b/SpringBootNeo4J/.mvn/wrapper/maven-wrapper.jar new file mode 100644 index 0000000..cb28b0e Binary files /dev/null and b/SpringBootNeo4J/.mvn/wrapper/maven-wrapper.jar differ diff --git a/SpringBootNeo4J/.mvn/wrapper/maven-wrapper.properties b/SpringBootNeo4J/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 0000000..281ebbf --- /dev/null +++ b/SpringBootNeo4J/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.1/apache-maven-3.9.1-bin.zip +wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar diff --git a/SpringBootNeo4J/docker-compose.yml b/SpringBootNeo4J/docker-compose.yml new file mode 100644 index 0000000..8167a65 --- /dev/null +++ b/SpringBootNeo4J/docker-compose.yml @@ -0,0 +1,15 @@ +version: "3.8" +services: + neo4j: + image: neo4j:4.4.20-community + ports: + - 7474:7474 + - 7687:7687 + restart: unless-stopped + environment: + - NEO4J_AUTH=neo4j/password + volumes: + - ./db/data:/data + - ./db/conf:/conf + - ./db/logs:/logs + - ./db/plugins:/plugins \ No newline at end of file diff --git a/SpringBootNeo4J/pom.xml b/SpringBootNeo4J/pom.xml new file mode 100644 index 0000000..1ceea92 --- /dev/null +++ b/SpringBootNeo4J/pom.xml @@ -0,0 +1,70 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 3.2.4 + + + com.spring.neo4j + SpringBootNeo4J + 0.0.1-SNAPSHOT + SpringBootNeo4J + Demo project for Spring Boot + + 17 + + + + org.springframework.boot + spring-boot-starter-data-neo4j + + + org.springframework.boot + spring-boot-starter-graphql + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-devtools + runtime + true + + + org.springframework.boot + spring-boot-starter-test + test + + + org.springframework + spring-webflux + test + + + org.springframework.graphql + spring-graphql-test + test + + + org.projectlombok + lombok + 1.18.26 + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + diff --git a/SpringBootNeo4J/src/main/java/com/spring/neo4j/Application.java b/SpringBootNeo4J/src/main/java/com/spring/neo4j/Application.java new file mode 100644 index 0000000..b72043c --- /dev/null +++ b/SpringBootNeo4J/src/main/java/com/spring/neo4j/Application.java @@ -0,0 +1,17 @@ +package com.spring.neo4j; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.data.neo4j.config.EnableNeo4jAuditing; +import org.springframework.data.neo4j.repository.config.EnableNeo4jRepositories; + +@SpringBootApplication +@EnableNeo4jAuditing +@EnableNeo4jRepositories(basePackages = {"com.spring.neo4j.repository"}) +public class Application { + + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } + +} diff --git a/SpringBootNeo4J/src/main/java/com/spring/neo4j/controller/AuthorController.java b/SpringBootNeo4J/src/main/java/com/spring/neo4j/controller/AuthorController.java new file mode 100644 index 0000000..78dd8a5 --- /dev/null +++ b/SpringBootNeo4J/src/main/java/com/spring/neo4j/controller/AuthorController.java @@ -0,0 +1,42 @@ +package com.spring.neo4j.controller; + +import com.spring.neo4j.repository.node.Author; +import com.spring.neo4j.service.AuthorService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +@RestController +@RequestMapping("author") +public class AuthorController { + + private final AuthorService authorService; + + @Autowired + public AuthorController(AuthorService authorService) { + this.authorService = authorService; + } + + + @GetMapping + public List getAllAuthors(){ + return authorService.getAllAuthors(); + } + + @PostMapping + public Author addAuthor(@RequestBody Author author){ + return authorService.addAuthor(author); + } + + @PutMapping + public Author updateAuthor(@RequestBody Author author) { + return authorService.updateAuthor(author); + } + + @DeleteMapping("/author/{authorId}") + public void deleteAuthor(@PathVariable Long authorId){ + authorService.deleteAuthor(authorId); + } + +} diff --git a/SpringBootNeo4J/src/main/java/com/spring/neo4j/repository/AuthorRepository.java b/SpringBootNeo4J/src/main/java/com/spring/neo4j/repository/AuthorRepository.java new file mode 100644 index 0000000..e15e18a --- /dev/null +++ b/SpringBootNeo4J/src/main/java/com/spring/neo4j/repository/AuthorRepository.java @@ -0,0 +1,9 @@ +package com.spring.neo4j.repository; + +import com.spring.neo4j.repository.node.Author; +import org.springframework.data.neo4j.repository.Neo4jRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface AuthorRepository extends Neo4jRepository { +} diff --git a/SpringBootNeo4J/src/main/java/com/spring/neo4j/repository/node/Author.java b/SpringBootNeo4J/src/main/java/com/spring/neo4j/repository/node/Author.java new file mode 100644 index 0000000..cdf85d8 --- /dev/null +++ b/SpringBootNeo4J/src/main/java/com/spring/neo4j/repository/node/Author.java @@ -0,0 +1,24 @@ +package com.spring.neo4j.repository.node; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.springframework.data.neo4j.core.schema.GeneratedValue; +import org.springframework.data.neo4j.core.schema.Id; +import org.springframework.data.neo4j.core.schema.Node; +import org.springframework.data.neo4j.core.schema.Relationship; + +import java.util.List; + +@Data +@AllArgsConstructor +@NoArgsConstructor +@Node("Author") +public class Author { + @Id + @GeneratedValue + Long id; + String name; + @Relationship(type = "AUTHORED", direction = Relationship.Direction.INCOMING) + List books; +} diff --git a/SpringBootNeo4J/src/main/java/com/spring/neo4j/repository/node/Book.java b/SpringBootNeo4J/src/main/java/com/spring/neo4j/repository/node/Book.java new file mode 100644 index 0000000..b8082e0 --- /dev/null +++ b/SpringBootNeo4J/src/main/java/com/spring/neo4j/repository/node/Book.java @@ -0,0 +1,20 @@ +package com.spring.neo4j.repository.node; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.springframework.data.neo4j.core.schema.GeneratedValue; +import org.springframework.data.neo4j.core.schema.Id; +import org.springframework.data.neo4j.core.schema.Node; + +@Data +@AllArgsConstructor +@NoArgsConstructor +@Node("Book") +public class Book { + @Id + @GeneratedValue + Long id; + String name; + +} diff --git a/SpringBootNeo4J/src/main/java/com/spring/neo4j/service/AuthorService.java b/SpringBootNeo4J/src/main/java/com/spring/neo4j/service/AuthorService.java new file mode 100644 index 0000000..9c33c6c --- /dev/null +++ b/SpringBootNeo4J/src/main/java/com/spring/neo4j/service/AuthorService.java @@ -0,0 +1,45 @@ +package com.spring.neo4j.service; + +import com.spring.neo4j.repository.AuthorRepository; +import com.spring.neo4j.repository.node.Author; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + + +import java.util.List; +import java.util.Optional; + +@Service +public class AuthorService { + private final AuthorRepository authorRepository; + + @Autowired + public AuthorService(AuthorRepository authorRepository) { + this.authorRepository = authorRepository; + } + + public List getAllAuthors(){ + return authorRepository.findAll(); + } + + public Author addAuthor( Author author){ + return authorRepository.save(author); + } + + public Author updateAuthor(Author author) { + Optional authorFromDB= authorRepository.findById(author.getId()); + if(authorFromDB.isPresent()){ + Author authorFromDBVal = authorFromDB.get(); + authorFromDBVal.setBooks(author.getBooks()); + authorFromDBVal.setName(author.getName()); + authorRepository.save(authorFromDBVal); + }else{ + return null; + } + return author; + } + + public void deleteAuthor(Long id) { + authorRepository.deleteById(id); + } +} diff --git a/SpringBootNeo4J/src/main/resources/application.yml b/SpringBootNeo4J/src/main/resources/application.yml new file mode 100644 index 0000000..00ae67a --- /dev/null +++ b/SpringBootNeo4J/src/main/resources/application.yml @@ -0,0 +1,10 @@ +spring: + neo4j: + uri: bolt://localhost:7687 + authentication: + username: neo4j + password: password + + +server: + port: 8030 \ No newline at end of file diff --git a/SpringBootNeo4J/src/test/java/com/spring/neo4j/SpringNeo4jApplicationTests.java b/SpringBootNeo4J/src/test/java/com/spring/neo4j/SpringNeo4jApplicationTests.java new file mode 100644 index 0000000..f2af106 --- /dev/null +++ b/SpringBootNeo4J/src/test/java/com/spring/neo4j/SpringNeo4jApplicationTests.java @@ -0,0 +1,13 @@ +package com.spring.neo4j; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class SpringNeo4jApplicationTests { + + @Test + void contextLoads() { + } + +} diff --git a/SpringBootNeo4J/useful_resources/Spring Neo4j.postman_collection.json b/SpringBootNeo4J/useful_resources/Spring Neo4j.postman_collection.json new file mode 100644 index 0000000..64bfa2c --- /dev/null +++ b/SpringBootNeo4J/useful_resources/Spring Neo4j.postman_collection.json @@ -0,0 +1,132 @@ +{ + "info": { + "_postman_id": "74305697-76af-47c1-b5d5-8964365408d5", + "name": "Spring Neo4j", + "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json", + "_exporter_id": "2156043" + }, + "item": [ + { + "name": "getAllAuthors", + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "http://localhost:8080/author", + "protocol": "http", + "host": [ + "localhost" + ], + "port": "8080", + "path": [ + "author" + ] + } + }, + "response": [] + }, + { + "name": "addAuthor", + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "application/json", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"name\": \"Robin Sharma\",\n \"books\": [\n {\n \"name\": \"The 5 Am Club\"\n },\n {\n \"name\": \"Who Will Cry When You Die\"\n },\n {\n \"name\": \"The Monk Who Sold His Ferrari\"\n },\n {\n \"name\": \"Discover Your Destiny\"\n }\n ]\n}" + }, + "url": { + "raw": "http://localhost:8080/author", + "protocol": "http", + "host": [ + "localhost" + ], + "port": "8080", + "path": [ + "author" + ] + } + }, + "response": [] + }, + { + "name": "updateAuthor", + "request": { + "method": "PUT", + "header": [ + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "application/json", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"id\":\"6\",\n \"name\": \"Amita Roy\",\n \"books\": [\n {\n \"name\":\"Funney is money\"\n }\n ]\n}" + }, + "url": { + "raw": "http://localhost:8080/author", + "protocol": "http", + "host": [ + "localhost" + ], + "port": "8080", + "path": [ + "author" + ] + } + }, + "response": [] + }, + { + "name": "deleteAuthor", + "request": { + "method": "DELETE", + "header": [ + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "application/json", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "" + }, + "url": { + "raw": "http://localhost:8080/author/0", + "protocol": "http", + "host": [ + "localhost" + ], + "port": "8080", + "path": [ + "author", + "0" + ] + } + }, + "response": [] + } + ] +} \ No newline at end of file