diff --git a/src/main/java/com/kumofactory/cloud/blueprint/BlueprintController.java b/src/main/java/com/kumofactory/cloud/blueprint/BlueprintController.java index ce582d3..9dafc31 100644 --- a/src/main/java/com/kumofactory/cloud/blueprint/BlueprintController.java +++ b/src/main/java/com/kumofactory/cloud/blueprint/BlueprintController.java @@ -4,29 +4,35 @@ import com.kumofactory.cloud.blueprint.dto.aws.AwsBluePrintDto; import com.kumofactory.cloud.blueprint.service.AwsBlueprintService; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.web.bind.annotation.*; @RestController @RequiredArgsConstructor @RequestMapping("/blueprint") +@Slf4j public class BlueprintController { + private final Logger logger = LoggerFactory.getLogger(BlueprintController.class); + private final AwsBlueprintService awsBlueprintService; - private final AwsBlueprintService awsBlueprintService; + // TODO : 토큰에서 유저 정보 가져오는 로직 추가 + // TODO : blueprint list 주는 api 추가 + // TODO : blueprint id 값으로 blueprint 가져오는 api 추가 + @GetMapping("/aws") + public AwsBluePrintDto getAwsBlueprint() { + try { + AwsBluePrintDto awsBlueprint = awsBlueprintService.getAwsBlueprint(); + return awsBlueprint; + } catch (RuntimeException e) { + return null; + } + } - // TODO : 토큰에서 유저 정보 가져오는 로직 추가 - @GetMapping("/aws") - public AwsBluePrintDto getAwsBlueprint() { - try { - AwsBluePrintDto awsBlueprint = awsBlueprintService.getAwsBlueprint(); - return awsBlueprint; - } catch (RuntimeException e) { - return null; - } - } - - @PostMapping("/aws") - public String createAwsBlueprint(@RequestBody AwsBluePrintDto awsBluePrintDto) { - awsBlueprintService.store(awsBluePrintDto); - return "hello-world"; - } + @PostMapping("/aws") + public String createAwsBlueprint(@RequestBody AwsBluePrintDto awsBluePrintDto) { + awsBlueprintService.store(awsBluePrintDto); + return "hello-world"; + } } diff --git a/src/main/java/com/kumofactory/cloud/blueprint/domain/ComponentDot.java b/src/main/java/com/kumofactory/cloud/blueprint/domain/ComponentDot.java new file mode 100644 index 0000000..1e7f557 --- /dev/null +++ b/src/main/java/com/kumofactory/cloud/blueprint/domain/ComponentDot.java @@ -0,0 +1,43 @@ +package com.kumofactory.cloud.blueprint.domain; + +import com.kumofactory.cloud.blueprint.dto.ComponentDotDto; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import org.hibernate.annotations.CreationTimestamp; +import org.hibernate.annotations.UpdateTimestamp; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import java.util.Date; + +@Entity +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +public class ComponentDot { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + @CreationTimestamp + private Date created_at; + @UpdateTimestamp + private Date updated_at; + + private Integer x; // 점의 x 좌표 + private Integer y; // 점의 y 좌표 + private String componentId; // 점이 속한 컴포넌트의 id + + public static ComponentDot createComponentDot(ComponentDotDto componentDotDto) { + ComponentDot componentDot = new ComponentDot(); + componentDot.setComponentId(componentDotDto.getComponentId()); + componentDot.setX(componentDotDto.getX()); + componentDot.setY(componentDotDto.getY()); + return componentDot; + } + +} diff --git a/src/main/java/com/kumofactory/cloud/blueprint/domain/ComponentLine.java b/src/main/java/com/kumofactory/cloud/blueprint/domain/ComponentLine.java new file mode 100644 index 0000000..18f0e04 --- /dev/null +++ b/src/main/java/com/kumofactory/cloud/blueprint/domain/ComponentLine.java @@ -0,0 +1,45 @@ +package com.kumofactory.cloud.blueprint.domain; + +import com.kumofactory.cloud.blueprint.domain.aws.AwsBluePrint; +import com.kumofactory.cloud.blueprint.dto.ComponentLineDto; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import org.hibernate.annotations.CreationTimestamp; +import org.hibernate.annotations.UpdateTimestamp; + +import javax.persistence.*; +import java.util.Date; + +@Entity +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +public class ComponentLine { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + @CreationTimestamp + private Date created_at; + @UpdateTimestamp + private Date updated_at; + + private String ui_id; // Client 에서 생성하는 uuid + @OneToOne(cascade = CascadeType.ALL) + private ComponentDot source; + @OneToOne(cascade = CascadeType.ALL) + private ComponentDot destination; + @ManyToOne + private AwsBluePrint bluePrint; + + public static ComponentLine createComponentLink(ComponentLineDto lineDto, AwsBluePrint bluePrint) { + ComponentLine componentLink = new ComponentLine(); + componentLink.setUi_id(lineDto.getId()); + componentLink.setSource(ComponentDot.createComponentDot(lineDto.getSrc())); + componentLink.setDestination(ComponentDot.createComponentDot(lineDto.getDst())); + componentLink.setBluePrint(bluePrint); + return componentLink; + } +} diff --git a/src/main/java/com/kumofactory/cloud/blueprint/domain/ComponentPoint.java b/src/main/java/com/kumofactory/cloud/blueprint/domain/ComponentPoint.java deleted file mode 100644 index 4240aba..0000000 --- a/src/main/java/com/kumofactory/cloud/blueprint/domain/ComponentPoint.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.kumofactory.cloud.blueprint.domain; - -import com.kumofactory.cloud.blueprint.domain.aws.AwsComponent; -import com.kumofactory.cloud.blueprint.dto.ComponentPointDto; -import java.util.Date; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.FetchType; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.ManyToOne; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; -import org.hibernate.annotations.CreationTimestamp; -import org.hibernate.annotations.UpdateTimestamp; - -@Entity -@Getter -@Setter -@NoArgsConstructor -public class ComponentPoint { - - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; - - @CreationTimestamp - private Date created_at; - @UpdateTimestamp - private Date updated_at; - - @Column(unique = true) - private String ui_id; // Client 에서 생성하는 uuid - - // Component 의 찍힌 point 위치 - private Integer position_x; - private Integer position_y; - - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "csp_component_id") - private AwsComponent cspComponent; - - // ============== 생성함수 ================= // - public static ComponentPoint createComponentPoint(ComponentPointDto pointLinkDto, - AwsComponent cspComponent) { - ComponentPoint componentPoint = new ComponentPoint(); - componentPoint.setUi_id(pointLinkDto.getId()); - componentPoint.setPosition_x(pointLinkDto.getX()); - componentPoint.setPosition_y(pointLinkDto.getY()); - componentPoint.setCspComponent(cspComponent); - return componentPoint; - } -} diff --git a/src/main/java/com/kumofactory/cloud/blueprint/domain/PointLink.java b/src/main/java/com/kumofactory/cloud/blueprint/domain/PointLink.java deleted file mode 100644 index 1b304cf..0000000 --- a/src/main/java/com/kumofactory/cloud/blueprint/domain/PointLink.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.kumofactory.cloud.blueprint.domain; - -import com.kumofactory.cloud.blueprint.domain.aws.AwsBluePrint; -import com.kumofactory.cloud.blueprint.dto.PointLinkDto; -import java.util.Date; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.ManyToOne; -import javax.persistence.OneToOne; -import javax.persistence.Table; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; -import org.hibernate.annotations.CreationTimestamp; -import org.hibernate.annotations.UpdateTimestamp; - -@Entity -@Getter -@Setter -@NoArgsConstructor -@Table -public class PointLink { - - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; - - @CreationTimestamp - private Date created_at; - @UpdateTimestamp - private Date updated_at; - - @Column(unique = true) - private String ui_id; // Client 에서 생성하는 uuid - - private String source_id; - private String destination_id; - - @ManyToOne - private AwsBluePrint bluePrint; - - // ============== 생성함수 ================= // - public static PointLink createPointLink(PointLinkDto pointLinkDto, AwsBluePrint bluePrint) { - PointLink pointLink = new PointLink(); - pointLink.setUi_id(pointLinkDto.getId()); - pointLink.setSource_id(pointLinkDto.getSource()); - pointLink.setDestination_id(pointLinkDto.getTarget()); - pointLink.setBluePrint(bluePrint); - return pointLink; - } -} diff --git a/src/main/java/com/kumofactory/cloud/blueprint/domain/aws/AwsBluePrint.java b/src/main/java/com/kumofactory/cloud/blueprint/domain/aws/AwsBluePrint.java index 4d87a0f..d520931 100644 --- a/src/main/java/com/kumofactory/cloud/blueprint/domain/aws/AwsBluePrint.java +++ b/src/main/java/com/kumofactory/cloud/blueprint/domain/aws/AwsBluePrint.java @@ -1,6 +1,8 @@ package com.kumofactory.cloud.blueprint.domain.aws; +import com.kumofactory.cloud.blueprint.domain.ComponentLine; import com.kumofactory.cloud.member.domain.Member; + import java.util.Date; import java.util.List; import javax.persistence.CascadeType; @@ -11,6 +13,7 @@ import javax.persistence.Id; import javax.persistence.ManyToOne; import javax.persistence.OneToMany; + import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; @@ -40,5 +43,7 @@ public class AwsBluePrint { @OneToMany(mappedBy = "bluePrint", cascade = CascadeType.REMOVE, fetch = FetchType.LAZY) private List cspComponents; + @OneToMany(mappedBy = "bluePrint", cascade = CascadeType.REMOVE, fetch = FetchType.LAZY) + private List lines; } diff --git a/src/main/java/com/kumofactory/cloud/blueprint/domain/aws/AwsComponent.java b/src/main/java/com/kumofactory/cloud/blueprint/domain/aws/AwsComponent.java index 0e43678..f242204 100644 --- a/src/main/java/com/kumofactory/cloud/blueprint/domain/aws/AwsComponent.java +++ b/src/main/java/com/kumofactory/cloud/blueprint/domain/aws/AwsComponent.java @@ -1,6 +1,5 @@ package com.kumofactory.cloud.blueprint.domain.aws; -import com.kumofactory.cloud.blueprint.domain.ComponentPoint; import com.kumofactory.cloud.blueprint.dto.aws.AwsComponentDto; import java.util.Date; @@ -11,7 +10,6 @@ import lombok.NoArgsConstructor; import lombok.Setter; import org.hibernate.annotations.CreationTimestamp; -import org.hibernate.annotations.Fetch; import org.hibernate.annotations.UpdateTimestamp; @Entity @@ -20,40 +18,37 @@ @NoArgsConstructor public class AwsComponent { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; - - @CreationTimestamp - private Date created_at; - @UpdateTimestamp - private Date updated_at; - - @Column(unique = true) - private String ui_id; // Client 에서 생성하는 uuid - - @Enumerated(EnumType.STRING) - private AwsComponentType type; // Component 타입 (vm, vpc, subnet, ...) - - // Component 의 좌측 상단 좌표 - private Integer position_x; - private Integer position_y; - - @ManyToOne - private AwsBluePrint bluePrint; - - @OneToMany(mappedBy = "cspComponent", cascade = CascadeType.ALL, fetch = FetchType.EAGER) - private List componentPoint; - - // ============== 생성함수 ================= // - public static AwsComponent createAwsComponent(AwsComponentDto awsComponentDto, - AwsBluePrint awsBluePrint) { - AwsComponent awsComponent = new AwsComponent(); - awsComponent.setUi_id(awsComponentDto.getId()); - awsComponent.setPosition_x(awsComponentDto.getX()); - awsComponent.setPosition_y(awsComponentDto.getY()); - awsComponent.setType(awsComponentDto.getType()); - awsComponent.setBluePrint(awsBluePrint); - return awsComponent; - } + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @CreationTimestamp + private Date created_at; + @UpdateTimestamp + private Date updated_at; + + @Column(unique = true) + private String ui_id; // Client 에서 생성하는 uuid + + @Enumerated(EnumType.STRING) + private AwsComponentType type; // Component 타입 (vm, vpc, subnet, ...) + + // Component 의 좌측 상단 좌표 + private Integer position_x; + private Integer position_y; + + @ManyToOne + private AwsBluePrint bluePrint; + + // ============== 생성함수 ================= // + public static AwsComponent createAwsComponent(AwsComponentDto awsComponentDto, + AwsBluePrint awsBluePrint) { + AwsComponent awsComponent = new AwsComponent(); + awsComponent.setUi_id(awsComponentDto.getId()); + awsComponent.setPosition_x(awsComponentDto.getX()); + awsComponent.setPosition_y(awsComponentDto.getY()); + awsComponent.setType(awsComponentDto.getType()); + awsComponent.setBluePrint(awsBluePrint); + return awsComponent; + } } diff --git a/src/main/java/com/kumofactory/cloud/blueprint/domain/aws/AwsComponentType.java b/src/main/java/com/kumofactory/cloud/blueprint/domain/aws/AwsComponentType.java index 9fb122c..e5221ad 100644 --- a/src/main/java/com/kumofactory/cloud/blueprint/domain/aws/AwsComponentType.java +++ b/src/main/java/com/kumofactory/cloud/blueprint/domain/aws/AwsComponentType.java @@ -1,5 +1,5 @@ package com.kumofactory.cloud.blueprint.domain.aws; public enum AwsComponentType { - VPC, SUBNET, ELB, EC2, EFS, WAF, ROUTE53, NAT_GATEWAY, RDS + VPC, SUBNET, ELB, EC2, EFS, WAF, ROUTE53, NAT_GATEWAY, RDS, } diff --git a/src/main/java/com/kumofactory/cloud/blueprint/dto/ComponentDotDto.java b/src/main/java/com/kumofactory/cloud/blueprint/dto/ComponentDotDto.java new file mode 100644 index 0000000..c9cb93e --- /dev/null +++ b/src/main/java/com/kumofactory/cloud/blueprint/dto/ComponentDotDto.java @@ -0,0 +1,21 @@ +package com.kumofactory.cloud.blueprint.dto; + +import com.kumofactory.cloud.blueprint.domain.ComponentDot; +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class ComponentDotDto { + private Integer x; + private Integer y; + private String componentId; + + public static ComponentDotDto mapper(ComponentDot componentDot) { + ComponentDotDto componentDotDto = new ComponentDotDto(); + componentDotDto.setX(componentDot.getX()); + componentDotDto.setY(componentDot.getY()); + componentDotDto.setComponentId(componentDot.getComponentId()); + return componentDotDto; + } +} diff --git a/src/main/java/com/kumofactory/cloud/blueprint/dto/ComponentLineDto.java b/src/main/java/com/kumofactory/cloud/blueprint/dto/ComponentLineDto.java new file mode 100644 index 0000000..7c5f3f0 --- /dev/null +++ b/src/main/java/com/kumofactory/cloud/blueprint/dto/ComponentLineDto.java @@ -0,0 +1,21 @@ +package com.kumofactory.cloud.blueprint.dto; + +import com.kumofactory.cloud.blueprint.domain.ComponentLine; +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class ComponentLineDto { + private String id; // Client 에서 생성하는 uuid + private ComponentDotDto src; + private ComponentDotDto dst; + + public static ComponentLineDto mapper(ComponentLine componentLink) { + ComponentLineDto componentLinkDto = new ComponentLineDto(); + componentLinkDto.setId(componentLink.getUi_id()); + componentLinkDto.setSrc(ComponentDotDto.mapper(componentLink.getSource())); + componentLinkDto.setDst(ComponentDotDto.mapper(componentLink.getDestination())); + return componentLinkDto; + } +} diff --git a/src/main/java/com/kumofactory/cloud/blueprint/dto/ComponentPointDto.java b/src/main/java/com/kumofactory/cloud/blueprint/dto/ComponentPointDto.java deleted file mode 100644 index b615e3e..0000000 --- a/src/main/java/com/kumofactory/cloud/blueprint/dto/ComponentPointDto.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.kumofactory.cloud.blueprint.dto; - -import javax.validation.constraints.NotNull; - -import com.kumofactory.cloud.blueprint.domain.ComponentPoint; -import lombok.Getter; -import lombok.Setter; - -@Getter -@Setter -public class ComponentPointDto { - - @NotNull - private String id; - @NotNull - private Integer x; - @NotNull - private Integer y; - - public static ComponentPointDto mapper(ComponentPoint componentPoint) { - ComponentPointDto componentPointDto = new ComponentPointDto(); - componentPointDto.setId(componentPoint.getUi_id()); - componentPointDto.setX(componentPoint.getPosition_x()); - componentPointDto.setY(componentPoint.getPosition_y()); - return componentPointDto; - } -} diff --git a/src/main/java/com/kumofactory/cloud/blueprint/dto/PointLinkDto.java b/src/main/java/com/kumofactory/cloud/blueprint/dto/PointLinkDto.java deleted file mode 100644 index f3d8840..0000000 --- a/src/main/java/com/kumofactory/cloud/blueprint/dto/PointLinkDto.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.kumofactory.cloud.blueprint.dto; - -import javax.validation.constraints.NotNull; - -import com.kumofactory.cloud.blueprint.domain.PointLink; -import lombok.Getter; -import lombok.Setter; - -@Getter -@Setter -public class PointLinkDto { - - @NotNull - private String id; - // Component uuid 값 - @NotNull - private String source; - @NotNull - private String target; - - public static PointLinkDto mapper(PointLink pointLink) { - PointLinkDto pointLinkDto = new PointLinkDto(); - pointLinkDto.setId(pointLink.getUi_id()); - pointLinkDto.setSource(pointLink.getSource_id()); - pointLinkDto.setTarget(pointLink.getDestination_id()); - return pointLinkDto; - } -} diff --git a/src/main/java/com/kumofactory/cloud/blueprint/dto/aws/AwsBluePrintDto.java b/src/main/java/com/kumofactory/cloud/blueprint/dto/aws/AwsBluePrintDto.java index f232d28..91d662e 100644 --- a/src/main/java/com/kumofactory/cloud/blueprint/dto/aws/AwsBluePrintDto.java +++ b/src/main/java/com/kumofactory/cloud/blueprint/dto/aws/AwsBluePrintDto.java @@ -1,36 +1,35 @@ package com.kumofactory.cloud.blueprint.dto.aws; -import com.kumofactory.cloud.blueprint.domain.PointLink; +import com.kumofactory.cloud.blueprint.domain.ComponentLine; import com.kumofactory.cloud.blueprint.domain.aws.AwsComponent; -import com.kumofactory.cloud.blueprint.dto.PointLinkDto; +import com.kumofactory.cloud.blueprint.dto.ComponentLineDto; import java.util.ArrayList; import java.util.List; import lombok.Data; -import lombok.Getter; @Data public class AwsBluePrintDto { - private String name; - private List components; - private List links; - - public static List awsComponentDtosMapper(List awsComponentDtos) { - List awsComponentDtoList = new ArrayList<>(); - for (AwsComponent awsComponent : awsComponentDtos) { - awsComponentDtoList.add(AwsComponentDto.mapper(awsComponent)); - } - return awsComponentDtoList; - } - - public static List pointLinkDtosMapper(List pointLinks) { - List pointLinkDtoList = new ArrayList<>(); - for (PointLink pointLink : pointLinks) { - pointLinkDtoList.add(PointLinkDto.mapper(pointLink)); - } - return pointLinkDtoList; - } + private String name; + private List components; + private List links; + + public static List awsComponentDtosMapper(List awsComponentDtos) { + List awsComponentDtoList = new ArrayList<>(); + for (AwsComponent awsComponent : awsComponentDtos) { + awsComponentDtoList.add(AwsComponentDto.mapper(awsComponent)); + } + return awsComponentDtoList; + } + + public static List componentLinkDtoListMapper(List componentLinks) { + List componentLinkDtoList = new ArrayList<>(); + for (ComponentLine pointLink : componentLinks) { + componentLinkDtoList.add(ComponentLineDto.mapper(pointLink)); + } + return componentLinkDtoList; + } } diff --git a/src/main/java/com/kumofactory/cloud/blueprint/dto/aws/AwsComponentDto.java b/src/main/java/com/kumofactory/cloud/blueprint/dto/aws/AwsComponentDto.java index cb28f67..8905048 100644 --- a/src/main/java/com/kumofactory/cloud/blueprint/dto/aws/AwsComponentDto.java +++ b/src/main/java/com/kumofactory/cloud/blueprint/dto/aws/AwsComponentDto.java @@ -1,47 +1,35 @@ package com.kumofactory.cloud.blueprint.dto.aws; -import com.kumofactory.cloud.blueprint.domain.ComponentPoint; import com.kumofactory.cloud.blueprint.domain.aws.AwsComponent; import com.kumofactory.cloud.blueprint.domain.aws.AwsComponentType; -import com.kumofactory.cloud.blueprint.dto.ComponentPointDto; -import java.util.ArrayList; -import java.util.List; import javax.validation.constraints.NotNull; import lombok.Getter; import lombok.Setter; -import org.springframework.lang.Nullable; @Getter @Setter public class AwsComponentDto { - @NotNull - private String id; - - @NotNull - private Integer x; - - @NotNull - private Integer y; - - @NotNull - private AwsComponentType type; - - private List points; - - public static AwsComponentDto mapper(AwsComponent awsComponent) { - AwsComponentDto awsComponentDto = new AwsComponentDto(); - awsComponentDto.setId(awsComponent.getUi_id()); - awsComponentDto.setX(awsComponent.getPosition_x()); - awsComponentDto.setY(awsComponent.getPosition_y()); - awsComponentDto.setType(awsComponent.getType()); - List points = new ArrayList<>(); - for (ComponentPoint componentPoint : awsComponent.getComponentPoint()) { - points.add(ComponentPointDto.mapper(componentPoint)); - } - awsComponentDto.setPoints(points); - return awsComponentDto; - } + @NotNull + private String id; + + @NotNull + private Integer x; + + @NotNull + private Integer y; + + @NotNull + private AwsComponentType type; + + public static AwsComponentDto mapper(AwsComponent awsComponent) { + AwsComponentDto awsComponentDto = new AwsComponentDto(); + awsComponentDto.setId(awsComponent.getUi_id()); + awsComponentDto.setX(awsComponent.getPosition_x()); + awsComponentDto.setY(awsComponent.getPosition_y()); + awsComponentDto.setType(awsComponent.getType()); + return awsComponentDto; + } } diff --git a/src/main/java/com/kumofactory/cloud/blueprint/repository/ComponentPointRepository.java b/src/main/java/com/kumofactory/cloud/blueprint/repository/ComponentDotRepository.java similarity index 54% rename from src/main/java/com/kumofactory/cloud/blueprint/repository/ComponentPointRepository.java rename to src/main/java/com/kumofactory/cloud/blueprint/repository/ComponentDotRepository.java index 072fe45..fdfbb19 100644 --- a/src/main/java/com/kumofactory/cloud/blueprint/repository/ComponentPointRepository.java +++ b/src/main/java/com/kumofactory/cloud/blueprint/repository/ComponentDotRepository.java @@ -1,10 +1,9 @@ package com.kumofactory.cloud.blueprint.repository; -import com.kumofactory.cloud.blueprint.domain.ComponentPoint; +import com.kumofactory.cloud.blueprint.domain.ComponentDot; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; @Repository -public interface ComponentPointRepository extends JpaRepository { - +public interface ComponentDotRepository extends JpaRepository { } diff --git a/src/main/java/com/kumofactory/cloud/blueprint/repository/ComponentLineRepository.java b/src/main/java/com/kumofactory/cloud/blueprint/repository/ComponentLineRepository.java new file mode 100644 index 0000000..94fccd1 --- /dev/null +++ b/src/main/java/com/kumofactory/cloud/blueprint/repository/ComponentLineRepository.java @@ -0,0 +1,13 @@ +package com.kumofactory.cloud.blueprint.repository; + +import com.kumofactory.cloud.blueprint.domain.ComponentLine; +import com.kumofactory.cloud.blueprint.domain.aws.AwsBluePrint; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +import java.util.List; + +@Repository +public interface ComponentLineRepository extends JpaRepository { + List findAllByBluePrint(AwsBluePrint bluePrint); +} diff --git a/src/main/java/com/kumofactory/cloud/blueprint/repository/PointLinkRepository.java b/src/main/java/com/kumofactory/cloud/blueprint/repository/PointLinkRepository.java deleted file mode 100644 index f516ae4..0000000 --- a/src/main/java/com/kumofactory/cloud/blueprint/repository/PointLinkRepository.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.kumofactory.cloud.blueprint.repository; - -import com.kumofactory.cloud.blueprint.domain.PointLink; -import com.kumofactory.cloud.blueprint.domain.aws.AwsBluePrint; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.stereotype.Repository; -import org.springframework.transaction.annotation.Transactional; - -import java.util.List; - -@Repository -@Transactional -public interface PointLinkRepository extends JpaRepository { - List findAllByBluePrint(AwsBluePrint bluePrint); -} diff --git a/src/main/java/com/kumofactory/cloud/blueprint/service/AwsBlueprintService.java b/src/main/java/com/kumofactory/cloud/blueprint/service/AwsBlueprintService.java index 72bbff8..3354151 100644 --- a/src/main/java/com/kumofactory/cloud/blueprint/service/AwsBlueprintService.java +++ b/src/main/java/com/kumofactory/cloud/blueprint/service/AwsBlueprintService.java @@ -4,9 +4,13 @@ import com.kumofactory.cloud.blueprint.domain.aws.AwsBluePrint; import com.kumofactory.cloud.blueprint.dto.aws.AwsBluePrintDto; +import java.util.List; + public interface AwsBlueprintService { - AwsBluePrintDto getAwsBlueprint(); + AwsBluePrintDto getAwsBlueprint(); + + List getMyAwsBlueprints(); - void store(AwsBluePrintDto awsBluePrintDto); + void store(AwsBluePrintDto awsBluePrintDto); } diff --git a/src/main/java/com/kumofactory/cloud/blueprint/service/AwsBlueprintServiceImpl.java b/src/main/java/com/kumofactory/cloud/blueprint/service/AwsBlueprintServiceImpl.java index 5588258..e1f712b 100644 --- a/src/main/java/com/kumofactory/cloud/blueprint/service/AwsBlueprintServiceImpl.java +++ b/src/main/java/com/kumofactory/cloud/blueprint/service/AwsBlueprintServiceImpl.java @@ -1,26 +1,21 @@ package com.kumofactory.cloud.blueprint.service; -import com.kumofactory.cloud.blueprint.domain.ComponentPoint; -import com.kumofactory.cloud.blueprint.domain.PointLink; +import com.kumofactory.cloud.blueprint.domain.ComponentLine; import com.kumofactory.cloud.blueprint.domain.aws.AwsBluePrint; import com.kumofactory.cloud.blueprint.domain.aws.AwsComponent; -import com.kumofactory.cloud.blueprint.dto.ComponentPointDto; -import com.kumofactory.cloud.blueprint.dto.PointLinkDto; +import com.kumofactory.cloud.blueprint.dto.ComponentLineDto; import com.kumofactory.cloud.blueprint.dto.aws.AwsBluePrintDto; import com.kumofactory.cloud.blueprint.dto.aws.AwsComponentDto; -import com.kumofactory.cloud.blueprint.repository.ComponentPointRepository; -import com.kumofactory.cloud.blueprint.repository.PointLinkRepository; +import com.kumofactory.cloud.blueprint.repository.ComponentDotRepository; +import com.kumofactory.cloud.blueprint.repository.ComponentLineRepository; import com.kumofactory.cloud.blueprint.repository.aws.AwsBluePrintRepository; import com.kumofactory.cloud.blueprint.repository.aws.AwsComponentRepository; import com.kumofactory.cloud.member.MemberRepository; -import com.kumofactory.cloud.member.domain.Member; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; import org.springframework.stereotype.Repository; import org.springframework.stereotype.Service; @@ -33,72 +28,63 @@ @Repository public class AwsBlueprintServiceImpl implements AwsBlueprintService { - private final MemberRepository memberRepository; - private final AwsBluePrintRepository awsBluePrintRepository; - private final AwsComponentRepository awsComponentRepository; - private final ComponentPointRepository componentPointRepository; - private final PointLinkRepository pointLinkRepository; - private final Logger logger = LoggerFactory.getLogger(AwsBlueprintServiceImpl.class); + private final MemberRepository memberRepository; + private final AwsBluePrintRepository awsBluePrintRepository; + private final AwsComponentRepository awsComponentRepository; + private final ComponentLineRepository componentLineRepository; + private final ComponentDotRepository componentDotRepository; + private final Logger logger = LoggerFactory.getLogger(AwsBlueprintServiceImpl.class); - @Override - public AwsBluePrintDto getAwsBlueprint() { - AwsBluePrint awsBluePrintById = awsBluePrintRepository.findAwsBluePrintById(1L); - List awsComponents = awsComponentRepository.findAllByBluePrint(awsBluePrintById); - List pointLinks = pointLinkRepository.findAllByBluePrint(awsBluePrintById); - logger.info("awsBluePrintById: {}", awsBluePrintById); - if (awsBluePrintById == null) { - throw new RuntimeException("awsBluePrintById is null"); - } - AwsBluePrintDto awsBluePrintDto = new AwsBluePrintDto(); - awsBluePrintDto.setName(awsBluePrintById.getName()); - awsBluePrintDto.setComponents(AwsBluePrintDto.awsComponentDtosMapper(awsComponents)); - awsBluePrintDto.setLinks(AwsBluePrintDto.pointLinkDtosMapper(pointLinks)); + @Override + public AwsBluePrintDto getAwsBlueprint() { + AwsBluePrint awsBluePrintById = awsBluePrintRepository.findAwsBluePrintById(1L); + logger.info("awsBluePrintById: {}", awsBluePrintById); + if (awsBluePrintById == null) { + throw new RuntimeException("awsBluePrintById is null"); + } - return awsBluePrintDto; - } + List awsComponents = awsComponentRepository.findAllByBluePrint(awsBluePrintById); + List componentLines = componentLineRepository.findAllByBluePrint(awsBluePrintById); + AwsBluePrintDto awsBluePrintDto = new AwsBluePrintDto(); + awsBluePrintDto.setName(awsBluePrintById.getName()); + awsBluePrintDto.setComponents(AwsBluePrintDto.awsComponentDtosMapper(awsComponents)); + awsBluePrintDto.setLinks(AwsBluePrintDto.componentLinkDtoListMapper(componentLines)); + return awsBluePrintDto; + } - @Override - public void store(AwsBluePrintDto awsBluePrintDto) { + @Override + public List getMyAwsBlueprints() { + return null; + } + + @Override + public void store(AwsBluePrintDto awsBluePrintDto) { // Member member = memberRepository.findMemberById(1L); - // BluePrint 저장 - AwsBluePrint awsBluePrint = new AwsBluePrint(); - awsBluePrint.setName(awsBluePrintDto.getName()); + // BluePrint 저장 + AwsBluePrint awsBluePrint = new AwsBluePrint(); + awsBluePrint.setName(awsBluePrintDto.getName()); // awsBluePrint.setMember(member); - AwsBluePrint savedBlueprint = awsBluePrintRepository.save(awsBluePrint); - logger.info("savedBlueprint: {}", savedBlueprint); - - List components = new ArrayList<>(); - List links = awsBluePrintDto.getLinks(); - - for (AwsComponentDto component : awsBluePrintDto.getComponents()) { - AwsComponent awsComponent = AwsComponent.createAwsComponent(component, savedBlueprint); + AwsBluePrint savedBlueprint = awsBluePrintRepository.save(awsBluePrint); + logger.info("savedBlueprint: {}", savedBlueprint); - List componentPoints = new ArrayList<>(); - List points = component.getPoints(); - if (points.size() != 0) { - for (ComponentPointDto point : points) { - ComponentPoint componentPoint = ComponentPoint.createComponentPoint(point, - awsComponent); - componentPoints.add(componentPoint); - } - } - awsComponent.setComponentPoint(componentPoints); - components.add(awsComponent); - } - awsComponentRepository.saveAll(components); + List components = new ArrayList<>(); + List links = awsBluePrintDto.getLinks(); - // Component 저장 - if (links.size() != 0) { - // PointLink 저장 - List toSaveLink = new ArrayList<>(); - for (PointLinkDto link : links) { - PointLink pointLink = PointLink.createPointLink(link, savedBlueprint); - toSaveLink.add(pointLink); - } + // Components 저장 + for (AwsComponentDto component : awsBluePrintDto.getComponents()) { + AwsComponent awsComponent = AwsComponent.createAwsComponent(component, savedBlueprint); + components.add(awsComponent); + } + awsComponentRepository.saveAll(components); - pointLinkRepository.saveAll(toSaveLink); - } - } + // Lines 저장 + List componentLines = new ArrayList<>(); + for (ComponentLineDto link : links) { + ComponentLine componentLink = ComponentLine.createComponentLink(link, savedBlueprint); + componentLines.add(componentLink); + } + componentLineRepository.saveAll(componentLines); + } }