Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions kanban-server/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,19 @@ dependencies {
compile 'org.springframework.security:spring-security-config:5.0.7.RELEASE'
compile 'org.springframework:spring-context-support:5.0.7.RELEASE'
compile 'net.sf.ehcache:ehcache-core:2.6.11'
compile('org.springframework.cloud:spring-cloud-starter-netflix-hystrix:2.0.2.RELEASE')

// compile 'org.liquibase:liquibase-core:3.6.2'

compile('org.springframework.boot:spring-boot-starter-data-jpa:1.5.8.RELEASE')
compile 'org.springframework.cloud:spring-cloud-starter-hystrix-dashboard:1.4.5.RELEASE'
compile 'org.springframework.boot:spring-boot-starter-actuator:2.0.5.RELEASE'
runtime('com.h2database:h2')

implementation('org.springframework.boot:spring-boot-starter-activemq')
implementation('org.springframework.boot:spring-boot-starter-aop')


// All of your normal project dependencies would be here in addition to...
// liquibaseRuntime 'org.liquibase:liquibase-core:3.6.1'
// liquibaseRuntime 'org.liquibase:liquibase-groovy-dsl:2.0.1'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package ru.otus.spring.courseproject.yag.dto;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.format.DateTimeFormatter;

@Data
@NoArgsConstructor
@Builder
@AllArgsConstructor
public class TaskDTO {

private long id;
@JsonProperty("start_date")
private String startDate;
@JsonProperty("text")
private String description;
private double progress;
private int duration;
private Long parent;
private Long project;
private String executor;


}
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
package ru.otus.spring.hw.kanban;

import com.netflix.hystrix.HystrixCommand;
import com.netflix.hystrix.HystrixCommandGroupKey;
import com.netflix.hystrix.HystrixCommandProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.security.crypto.password.PasswordEncoder;
import ru.otus.spring.hw.kanban.security.UserAccount;
Expand All @@ -13,10 +19,22 @@

@SpringBootApplication(scanBasePackages = "ru.otus.spring.hw.kanban")
@EnableJpaRepositories(basePackages = {"ru.otus.spring.hw.kanban.repository", "ru.otus.spring.hw.kanban.security"})
@EnableCircuitBreaker
@EnableHystrix
@EnableHystrixDashboard
public class KanbanApplication {

public static void main(String[] args) {
SpringApplication.run(KanbanApplication.class, args);

HystrixCommand.Setter config = HystrixCommand.Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey("boards"));

HystrixCommandProperties.Setter properties = HystrixCommandProperties.Setter();
properties.withExecutionTimeoutInMilliseconds(1000);
properties.withCircuitBreakerSleepWindowInMilliseconds(4000);
properties.withCircuitBreakerEnabled(true);
config.andCommandPropertiesDefaults(properties);

}


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package ru.otus.spring.hw.kanban.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.lang.reflect.Parameter;
import java.util.stream.IntStream;

@Aspect
@Component
public class JMSAudit {
private static final String DASH_LINE = "===================================";
private static final String NEXT_LINE = "\n";
private static final Logger log =LoggerFactory.getLogger("JMSAudit");

@Pointcut("execution(* ru.otus.spring.hw.kanban.messaging.*.*(..))")
public void logJms(){};

@Around("logJms()")
public Object jmsAudit(ProceedingJoinPoint pjp) throws Throwable{
Object[] args = pjp.getArgs();
Parameter[] parameters = ((MethodSignature)pjp.getSignature()).getMethod().getParameters();

StringBuilder builder = new StringBuilder(NEXT_LINE);
builder.append(DASH_LINE);
builder.append(NEXT_LINE);
builder.append("[BEFORE]");
builder.append(NEXT_LINE);
builder.append("Method: ");
builder.append(pjp.getSignature().getName());
builder.append(NEXT_LINE);
builder.append("Params: ");
builder.append(NEXT_LINE);
IntStream.range(0,args.length).forEach(index -> {
builder.append("> ");
builder.append(parameters[index].getName());
builder.append(": ");
builder.append(args[index]);
builder.append(NEXT_LINE);
});
builder.append(DASH_LINE);
log.info(builder.toString());

Object object = pjp.proceed(args);

//Some Extra logging [AFTER]

return object;
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package ru.otus.spring.hw.kanban.controllers;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import ru.otus.spring.hw.kanban.dto.BoardDTO;
import ru.otus.spring.hw.kanban.service.BoardService;

import java.util.Collections;
import java.util.List;

@RestController
Expand All @@ -19,28 +21,50 @@ public BoardController(BoardService boardService) {
}

@GetMapping(value = "/boards")
@HystrixCommand(groupKey = "boards", fallbackMethod = "findAllFallback")
public List<BoardDTO> getBoards() {
return boardService.findAll();
}

@PostMapping("/boards")
@HystrixCommand(groupKey = "boards", fallbackMethod = "createFallback")
BoardDTO newBoard(@RequestBody BoardDTO newBoard) {
return boardService.create(newBoard);
}

@GetMapping("/boards/{id}")
@HystrixCommand(groupKey = "boards", fallbackMethod = "findFallback")
public BoardDTO getBoard(@PathVariable int id) {
return boardService.find(id);
}

@PutMapping("/boards/{id}")
@HystrixCommand(groupKey = "boards", fallbackMethod = "updateFallback")
BoardDTO updateBoard(@RequestBody BoardDTO boardDTO, @PathVariable Long id) {
return boardService.update(boardDTO);
}

@DeleteMapping("/boards/{id}")
@HystrixCommand(groupKey = "boards")
void deleteBoard(@PathVariable int id) {
boardService.deleteById(id);
}

public List<BoardDTO> findAllFallback() {
return Collections.emptyList();
}

public BoardDTO findFallback(int id) {
return null;
}

public BoardDTO createFallback(BoardDTO newBoard)
{
return null;
}

public BoardDTO updateFallback(BoardDTO boardToUpdate) {
return null;
}

}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package ru.otus.spring.hw.kanban.controllers;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import ru.otus.spring.hw.kanban.dto.StageDTO;
import ru.otus.spring.hw.kanban.service.StageService;

import java.util.Collections;
import java.util.List;

@RestController
Expand All @@ -19,33 +21,64 @@ public StageController(StageService stageService) {
}

@GetMapping(value = "/stages")
@HystrixCommand(groupKey = "stages", fallbackMethod = "findAllFallback")
public List<StageDTO> getStages() {
return stageService.findAll();
}

@GetMapping(value = "/boards/{id}/stages")
@HystrixCommand(groupKey = "stages", fallbackMethod = "findAllByBoardFallback")
public List<StageDTO> getStagesByBoard(@PathVariable int id) {
return stageService.findByBoard(id);
}


@PostMapping("/stages")
@HystrixCommand(groupKey = "stages", fallbackMethod = "createStageFallback")
StageDTO newStage(@RequestBody StageDTO newStage) {
return stageService.create(newStage);
}

@GetMapping("/stages/{id}")
@HystrixCommand(groupKey = "stages", fallbackMethod = "getStageFallback")
public StageDTO getStage(@PathVariable int id) {
return stageService.find(id);
}

@PutMapping("/stages/{id}")
@HystrixCommand(groupKey = "stages", fallbackMethod = "updateStageFallback")
StageDTO updateStage(@RequestBody StageDTO stageDTO, @PathVariable Long id) {
return stageService.update(stageDTO);
}

@DeleteMapping("/stages/{id}")
@HystrixCommand(groupKey = "stages", fallbackMethod = "deleteStageFallback")
void deleteStage(@PathVariable int id) {
stageService.deleteById(id);
}

public List<StageDTO> findAllFallback() {
return Collections.emptyList();
}

public List<StageDTO> findAllByBoardFallback(int id) {
return Collections.emptyList();
}

StageDTO createStageFallback(StageDTO newStage) {
return null;
}


public StageDTO getStageFallback(int id) {
return null;
}

StageDTO updateStageFallback(StageDTO stageDTO, Long id) {
return null;
}

void deleteStageFallback(int id) {

}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ru.otus.spring.hw.kanban.controllers;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PostFilter;
import org.springframework.security.access.prepost.PreFilter;
Expand All @@ -8,6 +9,7 @@
import ru.otus.spring.hw.kanban.service.TaskService;

import java.security.Principal;
import java.util.Collections;
import java.util.List;

@RestController
Expand All @@ -21,34 +23,64 @@ public TaskController(TaskService taskService) {
}

@GetMapping(value = "/stages/{id}/tasks")
@PostFilter("hasPermission(filterObject,'READ')")
// @PostFilter("hasPermission(filterObject,'READ')")
@HystrixCommand(groupKey = "tasks", fallbackMethod = "findAllByStageFallback")
public List<TaskDTO> getTasksByStage(@PathVariable int id) {
return taskService.findAllByStage(id);
}

@GetMapping(value = "/tasks")
@HystrixCommand(groupKey = "tasks", fallbackMethod = "findAllFallback")
public List<TaskDTO> getTasks() {
return taskService.findAll();
}

@PostMapping("/tasks")
@HystrixCommand(groupKey = "tasks", fallbackMethod = "createFallback")
TaskDTO newTask(Principal principal, @RequestBody TaskDTO newTask) {
newTask.username = principal.getName();
return taskService.create(newTask);
}

@GetMapping("/tasks/{id}")
@HystrixCommand(groupKey = "tasks", fallbackMethod = "getTaskFallback")
public TaskDTO getTask(@PathVariable int id) {
return taskService.find(id);
}

@PutMapping("/tasks/{id}")
@HystrixCommand(groupKey = "tasks", fallbackMethod = "updateTaskFallback")
TaskDTO updateTask(@RequestBody TaskDTO taskDTO, @PathVariable Long id) {
return taskService.update(taskDTO);
}

@DeleteMapping("/tasks/{id}")
@HystrixCommand(groupKey = "tasks")
void deleteTask(@PathVariable int id) {
taskService.deleteById(id);
}



public List<TaskDTO> findAllByStageFallback(int id) {
return Collections.emptyList();
}

public List<TaskDTO> findAllFallback() {
return Collections.emptyList();
}

TaskDTO createFallback(Principal principal, TaskDTO newTask) {
return null;
}


public TaskDTO getTaskFallback(int id) {
return null;
}

TaskDTO updateTaskFallback(TaskDTO taskDTO, Long id) {
return null;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package ru.otus.spring.hw.kanban.messaging;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jms.support.converter.MappingJackson2MessageConverter;
import org.springframework.jms.support.converter.MessageConverter;
import org.springframework.jms.support.converter.MessageType;

@Configuration
public class JMSConfig {

@Bean
public MessageConverter jacksonJmsMessageConverter() {
MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter();
converter.setTargetType(MessageType.TEXT);
converter.setTypeIdPropertyName("_class_"); // This value can be anything, it will save the JSON class name and it must be the same for sender/receiver
return converter;
}
}
Loading