swaggerblueprint

Blueprint project
git clone git://git.wimdupont.com/swaggerblueprint.git
Log | Files | Refs | README | LICENSE

BlueprintService.java (1767B)


      1 package com.wimdupont.swagger.blueprint.service;
      2 
      3 import com.wimdupont.swagger.blueprint.controller.dto.BlueprintDto;
      4 import com.wimdupont.swagger.blueprint.exception.EntityNotFoundException;
      5 import org.springframework.stereotype.Service;
      6 
      7 import java.util.HashSet;
      8 import java.util.Set;
      9 import java.util.UUID;
     10 
     11 @Service
     12 public class BlueprintService {
     13 
     14     private final Set<BlueprintDto> blueprintDtoSet = new HashSet<>();
     15 
     16     public BlueprintService() {
     17         blueprintDtoSet.add(BlueprintDto.Builder.newBuilder()
     18                 .id(UUID.randomUUID())
     19                 .name("blueprint-one")
     20                 .number(420)
     21                 .build());
     22         blueprintDtoSet.add(BlueprintDto.Builder.newBuilder()
     23                 .id(UUID.randomUUID())
     24                 .name("blueprint-two")
     25                 .number(666)
     26                 .build());
     27     }
     28 
     29     public Set<BlueprintDto> getBlueprints() {
     30         return blueprintDtoSet;
     31     }
     32 
     33     public BlueprintDto getBlueprint(UUID id) {
     34         return getBlueprints().stream()
     35                 .filter(f -> f.getId().equals(id))
     36                 .findAny()
     37                 .orElseThrow(() -> new EntityNotFoundException(BlueprintDto.class, id.toString()));
     38     }
     39 
     40     public BlueprintDto createBlueprint(BlueprintDto blueprintDto) {
     41         blueprintDto.setId(UUID.randomUUID());
     42         blueprintDtoSet.add(blueprintDto);
     43         return blueprintDto;
     44     }
     45 
     46     public BlueprintDto updateBlueprint(UUID id, BlueprintDto blueprintDto) {
     47         var existing = getBlueprint(id);
     48         existing.setName(blueprintDto.getName());
     49         existing.setNumber(blueprintDto.getNumber());
     50         return existing;
     51     }
     52 
     53     public void deleteBlueprint(UUID id) {
     54         getBlueprints().remove(getBlueprint(id));
     55     }
     56 }