diff --git a/src/main/java/com/example/demo/controller/TrainingDefinitionController.java b/src/main/java/com/example/demo/controller/TrainingDefinitionController.java deleted file mode 100644 index 2dc4cb44da971a8d3b4d1686de92caa3cd43c305..0000000000000000000000000000000000000000 --- a/src/main/java/com/example/demo/controller/TrainingDefinitionController.java +++ /dev/null @@ -1,80 +0,0 @@ -package com.example.demo.controller; - -import com.example.demo.dto.TrainingDefinitionDto; -import com.example.demo.dto.input.GameDefinitionCreateDto; -import com.example.demo.service.TrainingDefinitionService; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import io.swagger.annotations.ApiParam; -import io.swagger.annotations.ApiResponse; -import io.swagger.annotations.ApiResponses; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.MediaType; -import org.springframework.web.bind.annotation.CrossOrigin; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RestController; - -import java.util.List; - -@RestController -@RequestMapping("/training-definition") -@CrossOrigin(origins = "*", allowCredentials = "true", allowedHeaders = "*", - methods = {RequestMethod.GET, RequestMethod.POST, RequestMethod.DELETE, RequestMethod.PUT}) -@Api(value = "/training-definition", tags = {"Training Definition"}) -public class TrainingDefinitionController { - - private static final Logger LOG = LoggerFactory.getLogger(TrainingDefinitionController.class); - - private final TrainingDefinitionService trainingDefinitionService; - - @Autowired - public TrainingDefinitionController(TrainingDefinitionService trainingDefinitionService) { - this.trainingDefinitionService = trainingDefinitionService; - } - - @PostMapping(produces = MediaType.APPLICATION_JSON_VALUE) - @ApiOperation(value = "Create a new training definition") - @ApiResponses(value = {@ApiResponse(code = 200, message = "New training definition created"), - @ApiResponse(code = 500, message = "Unexpected application error")}) - public GameDefinitionCreateDto createTrainingDefinition( - @ApiParam(value = "Training definition", required = true) @RequestBody(required = true) - TrainingDefinitionDto trainingDefinitionDto) { - return trainingDefinitionService.createTrainingDefinition(trainingDefinitionDto); - } - - @GetMapping(value = "/{id}", produces = MediaType.APPLICATION_JSON_VALUE) - @ApiOperation(value = "Return specified training definition") - @ApiResponses(value = {@ApiResponse(code = 200, message = "Training definition returned"), - @ApiResponse(code = 500, message = "Unexpected application error")}) - public TrainingDefinitionDto getTrainingDefinition( - @ApiParam(value = "Game definition", required = true) @PathVariable(required = true) Long id) { - return trainingDefinitionService.getTrainingDefinition(id); - } - - @GetMapping(produces = MediaType.APPLICATION_JSON_VALUE) - @ApiOperation(value = "Return all training definitions") - @ApiResponses(value = {@ApiResponse(code = 200, message = "Training definitions returned"), - @ApiResponse(code = 500, message = "Unexpected application error")}) - public List<TrainingDefinitionDto> getAllTrainingDefinitions() { - return trainingDefinitionService.getAllTrainingDefinitions(); - } - - @PutMapping(value = "/{id}", produces = MediaType.APPLICATION_JSON_VALUE) - @ApiOperation(value = "Update specified training definition") - @ApiResponses(value = {@ApiResponse(code = 200, message = "Training definition was updated"), - @ApiResponse(code = 500, message = "Unexpected application error")}) - public GameDefinitionCreateDto updateTrainingDefinition( - @ApiParam(value = "Game definition", required = true) @PathVariable(required = true) Long id, - @ApiParam(value = "Training definition", required = true) @RequestBody(required = true) - TrainingDefinitionDto trainingDefinitionDto) { - return trainingDefinitionService.updateTrainingDefinition(id, trainingDefinitionDto); - } -} diff --git a/src/main/java/com/example/demo/domain/BaseLevel.java b/src/main/java/com/example/demo/domain/BaseLevel.java index 7d62c686aede510a1515506e43652bf9cb677fe2..3975858cb6b59cf37eb99452e18a8c53175c4171 100644 --- a/src/main/java/com/example/demo/domain/BaseLevel.java +++ b/src/main/java/com/example/demo/domain/BaseLevel.java @@ -28,8 +28,7 @@ public abstract class BaseLevel { @ManyToOne(fetch = FetchType.LAZY) private UnityLevel unityLevel; - @ManyToOne(fetch = FetchType.LAZY) - private TrainingDefinition trainingDefinition; + private Long trainingDefinitionId; public String getTitle() { return title; @@ -79,12 +78,12 @@ public abstract class BaseLevel { this.unityLevel = unityLevel; } - public TrainingDefinition getTrainingDefinition() { - return trainingDefinition; + public Long getTrainingDefinitionId() { + return trainingDefinitionId; } - public void setTrainingDefinition(TrainingDefinition trainingDefinition) { - this.trainingDefinition = trainingDefinition; + public void setTrainingDefinitionId(Long trainingDefinition) { + this.trainingDefinitionId = trainingDefinition; } @Override diff --git a/src/main/java/com/example/demo/domain/TrainingDefinition.java b/src/main/java/com/example/demo/domain/TrainingDefinition.java deleted file mode 100644 index 243ce4da272a7c89c149036e4b1fbdd7c4f61895..0000000000000000000000000000000000000000 --- a/src/main/java/com/example/demo/domain/TrainingDefinition.java +++ /dev/null @@ -1,131 +0,0 @@ -package com.example.demo.domain; - -import javax.persistence.CascadeType; -import javax.persistence.Entity; -import javax.persistence.FetchType; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; -import javax.persistence.OneToMany; -import javax.persistence.OrderBy; -import java.time.LocalDateTime; -import java.util.Arrays; -import java.util.List; - -@Entity -public class TrainingDefinition { - - @Id - @GeneratedValue - private Long id; - - private String title; - private LocalDateTime lastEdited; - private Long sandboxDefinitionRefId; - private boolean showStepperBar; - private String state; - private String description; - private Long estimatedDuration; - private byte[] outcomes; - private byte[] prerequisites; - - @OrderBy - @OneToMany(mappedBy = "trainingDefinition", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY) - private List<BaseLevel> levels; - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } - - public LocalDateTime getLastEdited() { - return lastEdited; - } - - public void setLastEdited(LocalDateTime lastEdited) { - this.lastEdited = lastEdited; - } - - public Long getSandboxDefinitionRefId() { - return sandboxDefinitionRefId; - } - - public void setSandboxDefinitionRefId(Long sandboxDefinitionRefId) { - this.sandboxDefinitionRefId = sandboxDefinitionRefId; - } - - public boolean isShowStepperBar() { - return showStepperBar; - } - - public void setShowStepperBar(boolean showStepperBar) { - this.showStepperBar = showStepperBar; - } - - public String getState() { - return state; - } - - public void setState(String state) { - this.state = state; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public Long getEstimatedDuration() { - return estimatedDuration; - } - - public void setEstimatedDuration(Long estimatedDuration) { - this.estimatedDuration = estimatedDuration; - } - - public byte[] getOutcomes() { - return outcomes; - } - - public void setOutcomes(byte[] outcomes) { - this.outcomes = outcomes; - } - - public byte[] getPrerequisites() { - return prerequisites; - } - - public void setPrerequisites(byte[] prerequisites) { - this.prerequisites = prerequisites; - } - - public List<BaseLevel> getLevels() { - return levels; - } - - public void setLevels(List<BaseLevel> levels) { - this.levels = levels; - } - - @Override - public String toString() { - return "TrainingDefinition{" + "id=" + id + ", title='" + title + '\'' + ", lastEdited=" + lastEdited + - ", sandboxDefinitionRefId=" + sandboxDefinitionRefId + ", showStepperBar=" + showStepperBar + - ", state='" + state + '\'' + ", description='" + description + '\'' + ", estimatedDuration=" + - estimatedDuration + ", outcomes=" + Arrays.toString(outcomes) + ", prerequisites=" + - Arrays.toString(prerequisites) + '}'; - } -} diff --git a/src/main/java/com/example/demo/dto/TrainingDefinitionDto.java b/src/main/java/com/example/demo/dto/TrainingDefinitionDto.java deleted file mode 100644 index b2b16036d2503f01318d3881ac0f5f945852ee47..0000000000000000000000000000000000000000 --- a/src/main/java/com/example/demo/dto/TrainingDefinitionDto.java +++ /dev/null @@ -1,121 +0,0 @@ -package com.example.demo.dto; - -import com.example.demo.dto.input.GameDefinitionCreateDto; - -import java.io.Serializable; -import java.time.LocalDateTime; -import java.util.Arrays; -import java.util.List; - -public class TrainingDefinitionDto implements Serializable { - - private Long id; - private String title; - private LocalDateTime lastEdited; - private Long sandboxDefinitionRefId; - private boolean showStepperBar; - private String state; - private String description; - private Long estimatedDuration; - private byte[] outcomes; - private byte[] prerequisites; - - private List<GameDefinitionCreateDto> levels; - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } - - public LocalDateTime getLastEdited() { - return lastEdited; - } - - public void setLastEdited(LocalDateTime lastEdited) { - this.lastEdited = lastEdited; - } - - public Long getSandboxDefinitionRefId() { - return sandboxDefinitionRefId; - } - - public void setSandboxDefinitionRefId(Long sandboxDefinitionRefId) { - this.sandboxDefinitionRefId = sandboxDefinitionRefId; - } - - public boolean isShowStepperBar() { - return showStepperBar; - } - - public void setShowStepperBar(boolean showStepperBar) { - this.showStepperBar = showStepperBar; - } - - public String getState() { - return state; - } - - public void setState(String state) { - this.state = state; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public Long getEstimatedDuration() { - return estimatedDuration; - } - - public void setEstimatedDuration(Long estimatedDuration) { - this.estimatedDuration = estimatedDuration; - } - - public byte[] getOutcomes() { - return outcomes; - } - - public void setOutcomes(byte[] outcomes) { - this.outcomes = outcomes; - } - - public byte[] getPrerequisites() { - return prerequisites; - } - - public void setPrerequisites(byte[] prerequisites) { - this.prerequisites = prerequisites; - } - - public List<GameDefinitionCreateDto> getLevels() { - return levels; - } - - public void setLevels(List<GameDefinitionCreateDto> levels) { - this.levels = levels; - } - - @Override - public String toString() { - return "TrainingDefinitionDto{" + "id=" + id + ", title='" + title + '\'' + ", lastEdited=" + lastEdited + - ", sandboxDefinitionRefId=" + sandboxDefinitionRefId + ", showStepperBar=" + showStepperBar + - ", state='" + state + '\'' + ", description='" + description + '\'' + ", estimatedDuration=" + - estimatedDuration + ", outcomes=" + Arrays.toString(outcomes) + ", prerequisites=" + - Arrays.toString(prerequisites) + '}'; - } -} diff --git a/src/main/java/com/example/demo/dto/input/GameDefinitionCreateDto.java b/src/main/java/com/example/demo/dto/input/GameDefinitionCreateDto.java index 9b7a2760f010366de9ae366099b8a193f2e943d4..214536add251d4da40ab068755d2f9b6e545b4c1 100644 --- a/src/main/java/com/example/demo/dto/input/GameDefinitionCreateDto.java +++ b/src/main/java/com/example/demo/dto/input/GameDefinitionCreateDto.java @@ -4,6 +4,7 @@ import com.example.demo.dto.AttachmentDto; import java.util.List; +// TODO make sure this class can be removed public class GameDefinitionCreateDto { private Long id; private String title; diff --git a/src/main/java/com/example/demo/mapper/BeanMapper.java b/src/main/java/com/example/demo/mapper/BeanMapper.java index 92a97f049fd95b45234975d3ff9590813d79a46f..9f5ca85c7f13005cd93fbc28381e4c08dfa7e6ba 100644 --- a/src/main/java/com/example/demo/mapper/BeanMapper.java +++ b/src/main/java/com/example/demo/mapper/BeanMapper.java @@ -4,7 +4,6 @@ import com.example.demo.domain.AssessmentLevel; import com.example.demo.domain.Attachment; import com.example.demo.domain.GameLevel; import com.example.demo.domain.InfoLevel; -import com.example.demo.domain.TrainingDefinition; import com.example.demo.domain.UnityLevel; import com.example.demo.dto.AssessmentLevelDto; import com.example.demo.dto.AttachmentDto; @@ -14,7 +13,6 @@ import com.example.demo.dto.GameLevelUpdateDto; import com.example.demo.dto.InfoLevelCreateDto; import com.example.demo.dto.InfoLevelDto; import com.example.demo.dto.InfoLevelUpdateDto; -import com.example.demo.dto.TrainingDefinitionDto; import com.example.demo.dto.UnityLevelDto; import com.example.demo.dto.input.GameDefinitionCreateDto; import org.mapstruct.Mapper; @@ -79,21 +77,17 @@ public interface BeanMapper { UnityLevel toUnityLevel(GameDefinitionCreateDto gameDefinitionCreateDto); @Mapping(target = "orderInTrainingDefinition", source = "order") - @Mapping(target = "trainingDefinition", ignore = true) AssessmentLevel updateAssessmentLevel(@MappingTarget AssessmentLevel assessmentLevel, GameDefinitionCreateDto gameDefinitionCreateDto); @Mapping(target = "orderInTrainingDefinition", source = "order") - @Mapping(target = "trainingDefinition", ignore = true) InfoLevel updateInfoLevel(@MappingTarget InfoLevel infoLevel, GameDefinitionCreateDto gameDefinitionCreateDto); @Mapping(target = "orderInTrainingDefinition", source = "order") - @Mapping(target = "trainingDefinition", ignore = true) @Mapping(target = "unityLevel", ignore = true) @Mapping(target = "attachments", ignore = true) // TODO not really sure about this GameLevel updateGameLevel(@MappingTarget GameLevel gameLevel, GameDefinitionCreateDto gameDefinitionCreateDto); @Mapping(target = "orderInTrainingDefinition", source = "order") - @Mapping(target = "trainingDefinition", ignore = true) @Mapping(target = "subLevels", ignore = true) UnityLevel updateUnityLevel(@MappingTarget UnityLevel unityLevel, GameDefinitionCreateDto gameDefinitionCreateDto); @@ -108,12 +102,4 @@ public interface BeanMapper { @Mapping(target = "type", constant = "unity") GameDefinitionCreateDto toLevelDefinitionDto(UnityLevel unityLevel); - - @Mapping(target = "levels", ignore = true) - TrainingDefinition toEntity(TrainingDefinitionDto trainingDefinition); - - @Mapping(target = "levels", ignore = true) - TrainingDefinitionDto toDto(TrainingDefinition trainingDefinition); - - List<TrainingDefinitionDto> toDto(List<TrainingDefinition> trainingDefinitions); } diff --git a/src/main/java/com/example/demo/repository/TrainingDefinitionRepository.java b/src/main/java/com/example/demo/repository/TrainingDefinitionRepository.java deleted file mode 100644 index 19236c160670fba2adf1ee1935dc282a4edd07c8..0000000000000000000000000000000000000000 --- a/src/main/java/com/example/demo/repository/TrainingDefinitionRepository.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.example.demo.repository; - -import com.example.demo.domain.TrainingDefinition; -import org.springframework.data.jpa.repository.JpaRepository; - -public interface TrainingDefinitionRepository extends JpaRepository<TrainingDefinition, Long> { -} diff --git a/src/main/java/com/example/demo/service/TrainingDefinitionService.java b/src/main/java/com/example/demo/service/TrainingDefinitionService.java deleted file mode 100644 index 27a68ee53e230193aee4b8a4214bdb467be0ff0b..0000000000000000000000000000000000000000 --- a/src/main/java/com/example/demo/service/TrainingDefinitionService.java +++ /dev/null @@ -1,155 +0,0 @@ -package com.example.demo.service; - -import com.example.demo.domain.AssessmentLevel; -import com.example.demo.domain.BaseLevel; -import com.example.demo.domain.GameLevel; -import com.example.demo.domain.InfoLevel; -import com.example.demo.domain.TrainingDefinition; -import com.example.demo.domain.UnityLevel; -import com.example.demo.dto.TrainingDefinitionDto; -import com.example.demo.dto.input.GameDefinitionCreateDto; -import com.example.demo.dto.input.LevelType; -import com.example.demo.mapper.BeanMapper; -import com.example.demo.repository.AssessmentLevelRepository; -import com.example.demo.repository.GameLevelRepository; -import com.example.demo.repository.InfoLevelRepository; -import com.example.demo.repository.TrainingDefinitionRepository; -import com.example.demo.repository.UnityLevelRepository; -import com.example.demo.util.TrainingMapperHelper; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; -import org.springframework.util.CollectionUtils; - -import java.util.List; -import java.util.Objects; -import java.util.Optional; - -@Service -public class TrainingDefinitionService { - - @Autowired - private AssessmentLevelRepository assessmentLevelRepository; - - @Autowired - private UnityLevelRepository unityLevelRepository; - - @Autowired - private GameLevelRepository gameLevelRepository; - - @Autowired - private InfoLevelRepository infoLevelRepository; - - @Autowired - private TrainingDefinitionRepository trainingDefinitionRepository; - - @Autowired - private TrainingMapperHelper trainingMapperHelper; - - public GameDefinitionCreateDto createTrainingDefinition(TrainingDefinitionDto trainingDefinitionDto) { - - TrainingDefinition trainingDefinition = BeanMapper.INSTANCE.toEntity(trainingDefinitionDto); - trainingDefinitionRepository.save(trainingDefinition); - - // TODO refactor this, it's really ugly - for (GameDefinitionCreateDto gameDefinitionCreateDto : trainingDefinitionDto.getLevels()) { - if (gameDefinitionCreateDto.getType() == LevelType.assessment) { - AssessmentLevel assessmentLevel = BeanMapper.INSTANCE.toAssessmentLevel(gameDefinitionCreateDto); - assessmentLevel.setTrainingDefinition(trainingDefinition); - assessmentLevelRepository.save(assessmentLevel); - } else if (gameDefinitionCreateDto.getType() == LevelType.unity) { - UnityLevel unityLevel = BeanMapper.INSTANCE.toUnityLevel(gameDefinitionCreateDto); - unityLevel.setTrainingDefinition(trainingDefinition); - - if (!CollectionUtils.isEmpty(unityLevel.getSubLevels())) { - unityLevel.getSubLevels().forEach(x -> x.setUnityLevel(unityLevel)); - unityLevel.getSubLevels().forEach(x -> x.setTrainingDefinition(trainingDefinition)); - } - - unityLevelRepository.save(unityLevel); - } else if (gameDefinitionCreateDto.getType() == LevelType.game) { - GameLevel gameLevel = BeanMapper.INSTANCE.toGameLevel(gameDefinitionCreateDto); - gameLevel.setTrainingDefinition(trainingDefinition); - gameLevelRepository.save(gameLevel); - - } else if (gameDefinitionCreateDto.getType() == LevelType.info) { - InfoLevel infoLevel = BeanMapper.INSTANCE.toInfoLevel(gameDefinitionCreateDto); - infoLevel.setTrainingDefinition(trainingDefinition); - infoLevelRepository.save(infoLevel); - } - } - - return null; - } - - public TrainingDefinitionDto getTrainingDefinition(Long id) { - Optional<TrainingDefinition> trainingDefinition = trainingDefinitionRepository.findById(id); - - if (trainingDefinition.isEmpty()) { - // TODO throw 404 - return new TrainingDefinitionDto(); - } - - TrainingDefinitionDto trainingDefinitionDto = BeanMapper.INSTANCE.toDto(trainingDefinition.get()); - trainingDefinitionDto.setLevels(trainingMapperHelper.getLevelsFrom(trainingDefinition.get())); - - return trainingDefinitionDto; - } - - public List<TrainingDefinitionDto> getAllTrainingDefinitions() { - List<TrainingDefinition> trainingDefinitions = trainingDefinitionRepository.findAll(); - - return BeanMapper.INSTANCE.toDto(trainingDefinitions); - } - - public GameDefinitionCreateDto updateTrainingDefinition(Long id, TrainingDefinitionDto trainingDefinitionDto) { - Optional<TrainingDefinition> trainingDefinition = trainingDefinitionRepository.findById(id); - - if (trainingDefinition.isEmpty()) { - // TODO throw 404 - return new GameDefinitionCreateDto(); - } - TrainingDefinition trainingDefinitionEntity = trainingDefinition.get(); - - TrainingDefinition convertedEntity = BeanMapper.INSTANCE.toEntity(trainingDefinitionDto); - convertedEntity.setId(trainingDefinitionEntity.getId()); - - - for (BaseLevel originalLevel : trainingDefinitionEntity.getLevels()) { - for (GameDefinitionCreateDto updatedLevel : trainingDefinitionDto.getLevels()) { - if (Objects.equals(originalLevel.getId(), updatedLevel.getId())) { - originalLevel = updateTrainingLevel(originalLevel, updatedLevel); - originalLevel.setTrainingDefinition(convertedEntity); - } - } - } - - convertedEntity.setLevels(trainingDefinitionEntity.getLevels()); - - trainingDefinitionRepository.save(convertedEntity); - - return null; - } - - private <T extends BaseLevel> BaseLevel updateTrainingLevel(T originalLevel, GameDefinitionCreateDto updatedLevel) { - BaseLevel updatedEntity = null; - if (updatedLevel.getType() == LevelType.assessment) { - updatedEntity = BeanMapper.INSTANCE.updateAssessmentLevel((AssessmentLevel) originalLevel, updatedLevel); - } else if (updatedLevel.getType() == LevelType.unity) { - updatedEntity = BeanMapper.INSTANCE.updateUnityLevel((UnityLevel) originalLevel, updatedLevel); - - for (GameLevel originalSubLevel : ((UnityLevel) originalLevel).getSubLevels()) { - for (GameDefinitionCreateDto updatedSubLevel : updatedLevel.getSubLevels()) { - if (Objects.equals(originalSubLevel.getId(), updatedSubLevel.getId())) { - originalSubLevel = BeanMapper.INSTANCE.updateGameLevel(originalSubLevel, updatedSubLevel); - } - } - } - } else if (updatedLevel.getType() == LevelType.game) { - updatedEntity = BeanMapper.INSTANCE.updateGameLevel((GameLevel) originalLevel, updatedLevel); - } else if (updatedLevel.getType() == LevelType.info) { - updatedEntity = BeanMapper.INSTANCE.updateInfoLevel((InfoLevel) originalLevel, updatedLevel); - } - - return updatedEntity; - } -} diff --git a/src/main/java/com/example/demo/util/TrainingMapperHelper.java b/src/main/java/com/example/demo/util/TrainingMapperHelper.java deleted file mode 100644 index 89face464f81ac30cd17d5b77766b526d02fba26..0000000000000000000000000000000000000000 --- a/src/main/java/com/example/demo/util/TrainingMapperHelper.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.example.demo.util; - -import com.example.demo.domain.AssessmentLevel; -import com.example.demo.domain.BaseLevel; -import com.example.demo.domain.GameLevel; -import com.example.demo.domain.InfoLevel; -import com.example.demo.domain.TrainingDefinition; -import com.example.demo.domain.UnityLevel; -import com.example.demo.dto.input.GameDefinitionCreateDto; -import com.example.demo.mapper.BeanMapper; -import org.springframework.stereotype.Component; - -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; - -@Component -public class TrainingMapperHelper { - - public List<GameDefinitionCreateDto> getLevelsFrom(TrainingDefinition trainingDefinition) { - final List<GameDefinitionCreateDto> levels = new ArrayList<>(); - for (BaseLevel level : trainingDefinition.getLevels()) { - if (Objects.isNull(level.getUnityLevel())) { - levels.add(getLevelDto(level)); - } - } - - return levels; - } - - - private <T extends BaseLevel> GameDefinitionCreateDto getLevelDto(T level) { - if (level instanceof GameLevel) { - return BeanMapper.INSTANCE.toLevelDefinitionDto((GameLevel) level); - } else if (level instanceof InfoLevel) { - return BeanMapper.INSTANCE.toLevelDefinitionDto((InfoLevel) level); - } else if (level instanceof AssessmentLevel) { - return BeanMapper.INSTANCE.toLevelDefinitionDto((AssessmentLevel) level); - } else if (level instanceof UnityLevel) { - return BeanMapper.INSTANCE.toLevelDefinitionDto((UnityLevel) level); - } - // TODO again, this is very ugly, refactor needed - return null; - } -}