diff --git a/pom.xml b/pom.xml index 8e0c6095cb665275c7c8c2d337a3df21d044d240..8802067c37703dec38d7b78c9f341cddbe1c7ed2 100644 --- a/pom.xml +++ b/pom.xml @@ -19,6 +19,7 @@ <java.version>11</java.version> <projectlombok.version>1.18.12</projectlombok.version> + <org.mapstruct.version>1.3.1.Final</org.mapstruct.version> </properties> <dependencies> @@ -51,8 +52,23 @@ <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> - <version>${projectlombok.version}</version> + <version>1.18.12</version> +<!-- <version>${projectlombok.version}</version>--> </dependency> + + <dependency> + <groupId>org.mapstruct</groupId> + <artifactId>mapstruct</artifactId> + <version>1.3.1.Final</version> +<!-- <version>${org.mapstruct.version}</version>--> + </dependency> + + <dependency> + <groupId>org.apache.commons</groupId> + <artifactId>commons-collections4</artifactId> + <version>4.4</version> + </dependency> + </dependencies> <build> @@ -61,6 +77,23 @@ <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <version>3.5.1</version> + <configuration> + <source>11</source> + <target>11</target> + <annotationProcessorPaths> + <path> + <groupId>org.mapstruct</groupId> + <artifactId>mapstruct-processor</artifactId> + <version>${org.mapstruct.version}</version> + </path> + </annotationProcessorPaths> + </configuration> + </plugin> </plugins> </build> diff --git a/src/main/java/com/example/demo/DemoApplication.java b/src/main/java/com/example/demo/DemoApplication.java index 41df739fe160b973085f28a82d69766179afaceb..c0e1ce505ffd9f78c1982a5e3aaffc05d67d859b 100644 --- a/src/main/java/com/example/demo/DemoApplication.java +++ b/src/main/java/com/example/demo/DemoApplication.java @@ -2,8 +2,10 @@ package com.example.demo; import com.example.demo.domain.GameLevel; import com.example.demo.domain.Person; +import com.example.demo.dto.GameLevelDto; import com.example.demo.repository.GameLevelRepository; import com.example.demo.repository.PersonRepository; +import com.example.demo.service.GameLevelService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.boot.CommandLineRunner; @@ -79,4 +81,13 @@ public class DemoApplication { log.info("Saved game level: {}", foundGameLevel); }; } + + @Bean + CommandLineRunner yetAnotherDemo(GameLevelService gameLevelService) { + return args -> { + + List<GameLevelDto> allGameLevels = gameLevelService.findAllGameLevels(); + allGameLevels.forEach(gameLevel -> log.info("Found game level with ID {} and title {}", gameLevel.getId(), gameLevel.getTitle())); + }; + } } diff --git a/src/main/java/com/example/demo/domain/AssessmentLevel.java b/src/main/java/com/example/demo/domain/AssessmentLevel.java index 3b813c47d9ce32c6e975eb600d945e805b006e41..847da3f3451be4fd35b16f337d286fe25df8a92d 100644 --- a/src/main/java/com/example/demo/domain/AssessmentLevel.java +++ b/src/main/java/com/example/demo/domain/AssessmentLevel.java @@ -1,12 +1,10 @@ package com.example.demo.domain; -import lombok.Data; import org.neo4j.ogm.annotation.GeneratedValue; import org.neo4j.ogm.annotation.Id; import org.neo4j.ogm.annotation.NodeEntity; @NodeEntity -@Data public class AssessmentLevel extends BaseLevel { @Id @@ -16,4 +14,19 @@ public class AssessmentLevel extends BaseLevel { private String assessmentType; + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getAssessmentType() { + return assessmentType; + } + + public void setAssessmentType(String assessmentType) { + this.assessmentType = assessmentType; + } } diff --git a/src/main/java/com/example/demo/domain/BaseLevel.java b/src/main/java/com/example/demo/domain/BaseLevel.java index 988e4a5cfa07e39c503a8271c32338061d97e207..ccf7f877d3f5cd5469c275bd2b8b8498840485f8 100644 --- a/src/main/java/com/example/demo/domain/BaseLevel.java +++ b/src/main/java/com/example/demo/domain/BaseLevel.java @@ -1,12 +1,34 @@ package com.example.demo.domain; -import lombok.Data; import org.neo4j.ogm.annotation.NodeEntity; @NodeEntity -@Data -public class BaseLevel { +public abstract class BaseLevel { private String title; private String estimatedDuration; private Long maxScore; + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getEstimatedDuration() { + return estimatedDuration; + } + + public void setEstimatedDuration(String estimatedDuration) { + this.estimatedDuration = estimatedDuration; + } + + public Long getMaxScore() { + return maxScore; + } + + public void setMaxScore(Long maxScore) { + this.maxScore = maxScore; + } } diff --git a/src/main/java/com/example/demo/domain/GameLevel.java b/src/main/java/com/example/demo/domain/GameLevel.java index 27a33160295e0aa5fe9c92f28c2ae91ad32b07a9..3de11a3de686edc5dd4d47ce769dd5a2e1404c97 100644 --- a/src/main/java/com/example/demo/domain/GameLevel.java +++ b/src/main/java/com/example/demo/domain/GameLevel.java @@ -1,16 +1,16 @@ package com.example.demo.domain; -import lombok.Data; import org.neo4j.ogm.annotation.GeneratedValue; import org.neo4j.ogm.annotation.Id; import org.neo4j.ogm.annotation.NodeEntity; import org.neo4j.ogm.annotation.Relationship; +import java.util.ArrayList; import java.util.List; +import java.util.Objects; @NodeEntity -@Data public class GameLevel extends BaseLevel { @Id @@ -26,4 +26,71 @@ public class GameLevel extends BaseLevel { @Relationship(type = "GAME_LEVEL_HINTS", direction = Relationship.UNDIRECTED) private List<Hint> hints; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + } + + public String getSolutionPenalized() { + return solutionPenalized; + } + + public void setSolutionPenalized(String solutionPenalized) { + this.solutionPenalized = solutionPenalized; + } + + public String getFlag() { + return flag; + } + + public void setFlag(String flag) { + this.flag = flag; + } + + public String getSolution() { + return solution; + } + + public void setSolution(String solution) { + this.solution = solution; + } + + public String getAttachments() { + return attachments; + } + + public void setAttachments(String attachments) { + this.attachments = attachments; + } + + public String getIncorrectFlagLimit() { + return incorrectFlagLimit; + } + + public void setIncorrectFlagLimit(String incorrectFlagLimit) { + this.incorrectFlagLimit = incorrectFlagLimit; + } + + public List<Hint> getHints() { + if (Objects.isNull(hints)) { + hints = new ArrayList<>(); + } + return hints; + } + + public void setHints(List<Hint> hints) { + this.hints = hints; + } } diff --git a/src/main/java/com/example/demo/domain/Hint.java b/src/main/java/com/example/demo/domain/Hint.java index e4a2c4148c1142ff297daddc1d4b74b94f09067d..750e70c084f5d4175675d23c03c1015b505fede9 100644 --- a/src/main/java/com/example/demo/domain/Hint.java +++ b/src/main/java/com/example/demo/domain/Hint.java @@ -1,10 +1,10 @@ package com.example.demo.domain; -import lombok.Data; import org.neo4j.ogm.annotation.GeneratedValue; import org.neo4j.ogm.annotation.Id; +import org.neo4j.ogm.annotation.NodeEntity; -@Data +@NodeEntity public class Hint { @Id @@ -15,4 +15,44 @@ public class Hint { private String content; private String hintPenalty; private String orderInLevel; + + 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 String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + } + + public String getHintPenalty() { + return hintPenalty; + } + + public void setHintPenalty(String hintPenalty) { + this.hintPenalty = hintPenalty; + } + + public String getOrderInLevel() { + return orderInLevel; + } + + public void setOrderInLevel(String orderInLevel) { + this.orderInLevel = orderInLevel; + } } diff --git a/src/main/java/com/example/demo/domain/InfoLevel.java b/src/main/java/com/example/demo/domain/InfoLevel.java index eaed3579d28528654130b59428b4c11a0c462e51..551ac1c781fddd481950fe535245c0d72aab7934 100644 --- a/src/main/java/com/example/demo/domain/InfoLevel.java +++ b/src/main/java/com/example/demo/domain/InfoLevel.java @@ -12,4 +12,20 @@ public class InfoLevel extends BaseLevel { private Long id; private String content; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + } } diff --git a/src/main/java/com/example/demo/dto/AssessmentLevelDto.java b/src/main/java/com/example/demo/dto/AssessmentLevelDto.java new file mode 100644 index 0000000000000000000000000000000000000000..f763fc563f6ac8ca4c24b6d22311eb89edc81df3 --- /dev/null +++ b/src/main/java/com/example/demo/dto/AssessmentLevelDto.java @@ -0,0 +1,27 @@ +package com.example.demo.dto; + +import java.io.Serializable; + +public class AssessmentLevelDto extends BaseLevelDto implements Serializable { + + private Long id; + + private String assessmentType; + + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getAssessmentType() { + return assessmentType; + } + + public void setAssessmentType(String assessmentType) { + this.assessmentType = assessmentType; + } +} diff --git a/src/main/java/com/example/demo/dto/BaseLevelDto.java b/src/main/java/com/example/demo/dto/BaseLevelDto.java new file mode 100644 index 0000000000000000000000000000000000000000..78b7055b2006be7602138982406dc7287be59d1f --- /dev/null +++ b/src/main/java/com/example/demo/dto/BaseLevelDto.java @@ -0,0 +1,34 @@ +package com.example.demo.dto; + +import java.io.Serializable; + +public class BaseLevelDto implements Serializable { + + private String title; + private String estimatedDuration; + private Long maxScore; + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getEstimatedDuration() { + return estimatedDuration; + } + + public void setEstimatedDuration(String estimatedDuration) { + this.estimatedDuration = estimatedDuration; + } + + public Long getMaxScore() { + return maxScore; + } + + public void setMaxScore(Long maxScore) { + this.maxScore = maxScore; + } +} diff --git a/src/main/java/com/example/demo/dto/GameLevelDto.java b/src/main/java/com/example/demo/dto/GameLevelDto.java new file mode 100644 index 0000000000000000000000000000000000000000..fc8d824089369641ffb09bb56bab7534a3f855c8 --- /dev/null +++ b/src/main/java/com/example/demo/dto/GameLevelDto.java @@ -0,0 +1,87 @@ +package com.example.demo.dto; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +public class GameLevelDto extends BaseLevelDto implements Serializable { + + private Long id; + + private String content; + private String solutionPenalized; + private String flag; + private String solution; + private String attachments; + private String incorrectFlagLimit; + + private List<HintDto> hints; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + } + + public String getSolutionPenalized() { + return solutionPenalized; + } + + public void setSolutionPenalized(String solutionPenalized) { + this.solutionPenalized = solutionPenalized; + } + + public String getFlag() { + return flag; + } + + public void setFlag(String flag) { + this.flag = flag; + } + + public String getSolution() { + return solution; + } + + public void setSolution(String solution) { + this.solution = solution; + } + + public String getAttachments() { + return attachments; + } + + public void setAttachments(String attachments) { + this.attachments = attachments; + } + + public String getIncorrectFlagLimit() { + return incorrectFlagLimit; + } + + public void setIncorrectFlagLimit(String incorrectFlagLimit) { + this.incorrectFlagLimit = incorrectFlagLimit; + } + + public List<HintDto> getHints() { + if (Objects.isNull(hints)) { + hints = new ArrayList<>(); + } + return hints; + } + + public void setHints(List<HintDto> hints) { + this.hints = hints; + } +} diff --git a/src/main/java/com/example/demo/dto/HintDto.java b/src/main/java/com/example/demo/dto/HintDto.java new file mode 100644 index 0000000000000000000000000000000000000000..84cc0e7ee69a572882ef47f28144c4cb5f0c0b0e --- /dev/null +++ b/src/main/java/com/example/demo/dto/HintDto.java @@ -0,0 +1,53 @@ +package com.example.demo.dto; + +import java.io.Serializable; + +public class HintDto implements Serializable { + + private Long id; + + private String title; + private String content; + private String hintPenalty; + private String orderInLevel; + + 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 String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + } + + public String getHintPenalty() { + return hintPenalty; + } + + public void setHintPenalty(String hintPenalty) { + this.hintPenalty = hintPenalty; + } + + public String getOrderInLevel() { + return orderInLevel; + } + + public void setOrderInLevel(String orderInLevel) { + this.orderInLevel = orderInLevel; + } +} diff --git a/src/main/java/com/example/demo/dto/InfoLevelDto.java b/src/main/java/com/example/demo/dto/InfoLevelDto.java new file mode 100644 index 0000000000000000000000000000000000000000..2f1491de45c4eb52081be3f0cd9489bafca31889 --- /dev/null +++ b/src/main/java/com/example/demo/dto/InfoLevelDto.java @@ -0,0 +1,26 @@ +package com.example.demo.dto; + +import java.io.Serializable; + +public class InfoLevelDto extends BaseLevelDto implements Serializable { + + private Long id; + + private String content; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + } +} diff --git a/src/main/java/com/example/demo/mapper/ObjectMapper.java b/src/main/java/com/example/demo/mapper/ObjectMapper.java new file mode 100644 index 0000000000000000000000000000000000000000..f69338fb15f1994aab57d28021933828b3cf1767 --- /dev/null +++ b/src/main/java/com/example/demo/mapper/ObjectMapper.java @@ -0,0 +1,36 @@ +package com.example.demo.mapper; + +import com.example.demo.domain.AssessmentLevel; +import com.example.demo.domain.BaseLevel; +import com.example.demo.domain.GameLevel; +import com.example.demo.domain.Hint; +import com.example.demo.domain.InfoLevel; +import com.example.demo.dto.AssessmentLevelDto; +import com.example.demo.dto.GameLevelDto; +import com.example.demo.dto.HintDto; +import com.example.demo.dto.InfoLevelDto; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + + +@Mapper +public interface ObjectMapper { + + ObjectMapper INSTANCE = Mappers.getMapper(ObjectMapper.class); + + AssessmentLevelDto toDto(AssessmentLevel assessmentLevel); + + AssessmentLevel toEntity(AssessmentLevelDto assessmentLevel); + + GameLevelDto toDto(GameLevel gameLevel); + + GameLevel toEntity(GameLevelDto gameLevel); + + InfoLevelDto toDto(InfoLevel infoLevel); + + InfoLevel toEntity(InfoLevelDto infoLevel); + + HintDto toDto(Hint hint); + + Hint toEntity(HintDto hint); +} diff --git a/src/main/java/com/example/demo/service/GameLevelService.java b/src/main/java/com/example/demo/service/GameLevelService.java new file mode 100644 index 0000000000000000000000000000000000000000..fc4d01fd7aa2993b0c27d58112dfdea387fca509 --- /dev/null +++ b/src/main/java/com/example/demo/service/GameLevelService.java @@ -0,0 +1,10 @@ +package com.example.demo.service; + +import com.example.demo.dto.GameLevelDto; + +import java.util.List; + +public interface GameLevelService { + + List<GameLevelDto> findAllGameLevels(); +} diff --git a/src/main/java/com/example/demo/service/impl/GameLevelServiceImpl.java b/src/main/java/com/example/demo/service/impl/GameLevelServiceImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..d69ff021baaaae170d02e56a75f8e89d7e9258cb --- /dev/null +++ b/src/main/java/com/example/demo/service/impl/GameLevelServiceImpl.java @@ -0,0 +1,41 @@ +package com.example.demo.service.impl; + +import com.example.demo.domain.GameLevel; +import com.example.demo.dto.GameLevelDto; +import com.example.demo.mapper.ObjectMapper; +import com.example.demo.repository.GameLevelRepository; +import com.example.demo.service.GameLevelService; +import org.apache.commons.collections4.IterableUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; + +import java.util.ArrayList; +import java.util.List; + +@Service +public class GameLevelServiceImpl implements GameLevelService { + + private final GameLevelRepository gameLevelRepository; + + @Autowired + public GameLevelServiceImpl(GameLevelRepository gameLevelRepository) { + this.gameLevelRepository = gameLevelRepository; + } + + @Override + public List<GameLevelDto> findAllGameLevels() { + + Iterable<GameLevel> allGameLevels = gameLevelRepository.findAll(); + + List<GameLevelDto> result = new ArrayList<>(); + + if (!IterableUtils.isEmpty(allGameLevels)) { + for (GameLevel gameLevel : allGameLevels) { + result.add(ObjectMapper.INSTANCE.toDto(gameLevel)); + } + } + + return result; + } +}