JAVA-84: Moved 3 articles to spring-boot-libraries

This commit is contained in:
sampadawagde
2020-08-28 17:56:09 +05:30
parent 854ba76efd
commit e1a1af012e
33 changed files with 587 additions and 33 deletions

View File

@@ -44,22 +44,6 @@
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>com.graphql-java</groupId>
<artifactId>graphql-spring-boot-starter</artifactId>
<version>${graphql-spring-boot-starter.version}</version>
</dependency>
<dependency>
<groupId>com.graphql-java</groupId>
<artifactId>graphql-java-tools</artifactId>
<version>${graphql-java-tools.version}</version>
</dependency>
<dependency>
<groupId>com.graphql-java</groupId>
<artifactId>graphiql-spring-boot-starter</artifactId>
<version>${graphiql-spring-boot-starter.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
@@ -104,18 +88,6 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.togglz</groupId>
<artifactId>togglz-spring-boot-starter</artifactId>
<version>${togglz.version}</version>
</dependency>
<dependency>
<groupId>org.togglz</groupId>
<artifactId>togglz-spring-security</artifactId>
<version>${togglz.version}</version>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>artemis-server</artifactId>
@@ -204,11 +176,7 @@
<!-- The main class to start by executing java -jar -->
<start-class>com.baeldung.intro.App</start-class>
<tomee-servlet-api.version>8.5.11</tomee-servlet-api.version>
<togglz.version>2.4.1.Final</togglz.version>
<rome.version>1.9.0</rome.version>
<graphql-spring-boot-starter.version>5.0.2</graphql-spring-boot-starter.version>
<graphiql-spring-boot-starter.version>5.0.2</graphiql-spring-boot-starter.version>
<graphql-java-tools.version>5.2.4</graphql-java-tools.version>
<guava.version>18.0</guava.version>
<resource.delimiter>@</resource.delimiter>
</properties>

View File

@@ -1,31 +0,0 @@
package com.baeldung.graphql;
public class Author {
private String id;
private String name;
private String thumbnail;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getThumbnail() {
return thumbnail;
}
public void setThumbnail(String thumbnail) {
this.thumbnail = thumbnail;
}
}

View File

@@ -1,16 +0,0 @@
package com.baeldung.graphql;
import java.util.List;
import java.util.Optional;
public class AuthorDao {
private List<Author> authors;
public AuthorDao(List<Author> authors) {
this.authors = authors;
}
public Optional<Author> getAuthor(String id) {
return authors.stream().filter(author -> id.equals(author.getId())).findFirst();
}
}

View File

@@ -1,17 +0,0 @@
package com.baeldung.graphql;
import java.util.List;
import com.coxautodev.graphql.tools.GraphQLResolver;
public class AuthorResolver implements GraphQLResolver<Author> {
private PostDao postDao;
public AuthorResolver(PostDao postDao) {
this.postDao = postDao;
}
public List<Post> getPosts(Author author) {
return postDao.getAuthorPosts(author.getId());
}
}

View File

@@ -1,59 +0,0 @@
package com.baeldung.graphql;
import java.util.ArrayList;
import java.util.List;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class GraphqlConfiguration {
@Bean
public PostDao postDao() {
List<Post> posts = new ArrayList<>();
for (int postId = 0; postId < 10; ++postId) {
for (int authorId = 0; authorId < 10; ++authorId) {
Post post = new Post();
post.setId("Post" + authorId + postId);
post.setTitle("Post " + authorId + ":" + postId);
post.setText("Post " + postId + " + by author " + authorId);
post.setAuthorId("Author" + authorId);
posts.add(post);
}
}
return new PostDao(posts);
}
@Bean
public AuthorDao authorDao() {
List<Author> authors = new ArrayList<>();
for (int authorId = 0; authorId < 10; ++authorId) {
Author author = new Author();
author.setId("Author" + authorId);
author.setName("Author " + authorId);
author.setThumbnail("http://example.com/authors/" + authorId);
authors.add(author);
}
return new AuthorDao(authors);
}
@Bean
public PostResolver postResolver(AuthorDao authorDao) {
return new PostResolver(authorDao);
}
@Bean
public AuthorResolver authorResolver(PostDao postDao) {
return new AuthorResolver(postDao);
}
@Bean
public Query query(PostDao postDao) {
return new Query(postDao);
}
@Bean
public Mutation mutation(PostDao postDao) {
return new Mutation(postDao);
}
}

View File

@@ -1,25 +0,0 @@
package com.baeldung.graphql;
import java.util.UUID;
import com.coxautodev.graphql.tools.GraphQLMutationResolver;
public class Mutation implements GraphQLMutationResolver {
private PostDao postDao;
public Mutation(PostDao postDao) {
this.postDao = postDao;
}
public Post writePost(String title, String text, String category, String author) {
Post post = new Post();
post.setId(UUID.randomUUID().toString());
post.setTitle(title);
post.setText(text);
post.setCategory(category);
post.setAuthorId(author);
postDao.savePost(post);
return post;
}
}

View File

@@ -1,49 +0,0 @@
package com.baeldung.graphql;
public class Post {
private String id;
private String title;
private String text;
private String category;
private String authorId;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
public String getCategory() {
return category;
}
public void setCategory(String category) {
this.category = category;
}
public String getAuthorId() {
return authorId;
}
public void setAuthorId(String authorId) {
this.authorId = authorId;
}
}

View File

@@ -1,24 +0,0 @@
package com.baeldung.graphql;
import java.util.List;
import java.util.stream.Collectors;
public class PostDao {
private List<Post> posts;
public PostDao(List<Post> posts) {
this.posts = posts;
}
public List<Post> getRecentPosts(int count, int offset) {
return posts.stream().skip(offset).limit(count).collect(Collectors.toList());
}
public List<Post> getAuthorPosts(String author) {
return posts.stream().filter(post -> author.equals(post.getAuthorId())).collect(Collectors.toList());
}
public void savePost(Post post) {
posts.add(0, post);
}
}

View File

@@ -1,17 +0,0 @@
package com.baeldung.graphql;
import java.util.Optional;
import com.coxautodev.graphql.tools.GraphQLResolver;
public class PostResolver implements GraphQLResolver<Post> {
private AuthorDao authorDao;
public PostResolver(AuthorDao authorDao) {
this.authorDao = authorDao;
}
public Optional<Author> getAuthor(Post post) {
return authorDao.getAuthor(post.getAuthorId());
}
}

View File

@@ -1,17 +0,0 @@
package com.baeldung.graphql;
import java.util.List;
import com.coxautodev.graphql.tools.GraphQLQueryResolver;
public class Query implements GraphQLQueryResolver {
private PostDao postDao;
public Query(PostDao postDao) {
this.postDao = postDao;
}
public List<Post> getRecentPosts(int count, int offset) {
return postDao.getRecentPosts(count, offset);
}
}

View File

@@ -1,31 +0,0 @@
package com.baeldung.kong;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @author aiet
*/
@RestController
@RequestMapping("/stock")
public class QueryController {
private static int REQUEST_COUNTER = 0;
@GetMapping("/reqcount")
public int getReqCount() {
return REQUEST_COUNTER;
}
@GetMapping("/{code}")
public String getStockPrice(@PathVariable String code) {
REQUEST_COUNTER++;
if ("BTC".equalsIgnoreCase(code))
return "10000";
else
return "N/A";
}
}

View File

@@ -1,13 +0,0 @@
package com.baeldung.kong;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class StockApp {
public static void main(String[] args) {
SpringApplication.run(StockApp.class, args);
}
}

View File

@@ -1,7 +0,0 @@
package com.baeldung.toggle;
import org.springframework.data.repository.CrudRepository;
public interface EmployeeRepository extends CrudRepository<Employee, Long> {
}

View File

@@ -1,12 +0,0 @@
package com.baeldung.toggle;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.METHOD, ElementType.TYPE })
public @interface FeatureAssociation {
MyFeatures value();
}

View File

@@ -1,26 +0,0 @@
package com.baeldung.toggle;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;
@Aspect
@Component
public class FeaturesAspect {
private static final Logger LOG = LogManager.getLogger(FeaturesAspect.class);
@Around(value = "@within(featureAssociation) || @annotation(featureAssociation)")
public Object checkAspect(ProceedingJoinPoint joinPoint, FeatureAssociation featureAssociation) throws Throwable {
if (featureAssociation.value().isActive()) {
return joinPoint.proceed();
} else {
LOG.info("Feature " + featureAssociation.value().name() + " is not enabled!");
return null;
}
}
}

View File

@@ -1,23 +0,0 @@
package com.baeldung.toggle;
import org.togglz.core.Feature;
import org.togglz.core.activation.SystemPropertyActivationStrategy;
import org.togglz.core.annotation.ActivationParameter;
import org.togglz.core.annotation.DefaultActivationStrategy;
import org.togglz.core.annotation.EnabledByDefault;
import org.togglz.core.annotation.Label;
import org.togglz.core.context.FeatureContext;
public enum MyFeatures implements Feature {
@Label("Employee Management Feature")
@EnabledByDefault
@DefaultActivationStrategy(id = SystemPropertyActivationStrategy.ID, parameters = { @ActivationParameter(name = SystemPropertyActivationStrategy.PARAM_PROPERTY_NAME, value = "employee.feature"),
@ActivationParameter(name = SystemPropertyActivationStrategy.PARAM_PROPERTY_VALUE, value = "true") })
EMPLOYEE_MANAGEMENT_FEATURE;
public boolean isActive() {
return FeatureContext.getFeatureManager().isActive(this);
}
}

View File

@@ -1,20 +0,0 @@
package com.baeldung.toggle;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class SalaryController {
@Autowired
SalaryService salaryService;
@PostMapping(value = "/increaseSalary")
@ResponseBody
public void increaseSalary(@RequestParam long id) {
salaryService.increaseSalary(id);
}
}

View File

@@ -1,19 +0,0 @@
package com.baeldung.toggle;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class SalaryService {
@Autowired
EmployeeRepository employeeRepository;
@FeatureAssociation(value = MyFeatures.EMPLOYEE_MANAGEMENT_FEATURE)
public void increaseSalary(long id) {
Employee employee = employeeRepository.findById(id).orElse(null);
employee.setSalary(employee.getSalary() + employee.getSalary() * 0.1);
employeeRepository.save(employee);
}
}

View File

@@ -1,14 +0,0 @@
package com.baeldung.toggle;
import javax.annotation.security.RolesAllowed;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class ToggleApplication {
@RolesAllowed("*")
public static void main(String[] args) {
SpringApplication.run(ToggleApplication.class, args);
}
}

View File

@@ -1,20 +0,0 @@
package com.baeldung.toggle;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.togglz.core.manager.EnumBasedFeatureProvider;
import org.togglz.core.spi.FeatureProvider;
@Configuration
@EnableJpaRepositories("com.baeldung.toggle")
@EntityScan("com.baeldung.toggle")
public class ToggleConfiguration {
@Bean
public FeatureProvider featureProvider() {
return new EnumBasedFeatureProvider(MyFeatures.class);
}
}