From e39d20cf0a3240e71ec784a0fb32468220cc0064 Mon Sep 17 00:00:00 2001 From: Marvin Bechtold Date: Wed, 15 Nov 2023 10:28:27 +0100 Subject: [PATCH] Encode patterns as string (#222) --- .../java/org/planqk/atlas/core/model/Implementation.java | 6 +++--- .../atlas/core/repository/ImplementationRepository.java | 2 +- .../atlas/core/services/ImplementationService.java | 2 +- .../atlas/core/services/ImplementationServiceImpl.java | 2 +- .../web/controller/ImplementationGlobalController.java | 9 ++++----- .../java/org/planqk/atlas/web/dtos/PatternUriDto.java | 2 +- 6 files changed, 11 insertions(+), 12 deletions(-) diff --git a/org.planqk.atlas.core/src/main/java/org/planqk/atlas/core/model/Implementation.java b/org.planqk.atlas.core/src/main/java/org/planqk/atlas/core/model/Implementation.java index d8732586..0cbd237d 100644 --- a/org.planqk.atlas.core/src/main/java/org/planqk/atlas/core/model/Implementation.java +++ b/org.planqk.atlas.core/src/main/java/org/planqk/atlas/core/model/Implementation.java @@ -135,7 +135,7 @@ public class Implementation extends KnowledgeArtifact { @ElementCollection @CollectionTable(name = "pattern_uris", joinColumns = @JoinColumn(name = "implementation_id")) @Column(name = "pattern_uri", nullable = false) - private Set patterns = new HashSet<>(); + private Set patterns = new HashSet<>(); public void addTag(@NonNull Tag tag) { if (tags.contains(tag)) { @@ -201,14 +201,14 @@ public void removeImplementationPackage(@NonNull ImplementationPackage implement implementationPackage.setImplementation(null); } - public void addPattern(@NonNull URI pattern) { + public void addPattern(@NonNull String pattern) { if (patterns.contains(pattern)) { return; } this.patterns.add(pattern); } - public void removePattern(@NonNull URI pattern) { + public void removePattern(@NonNull String pattern) { if (!patterns.contains(pattern)) { return; } diff --git a/org.planqk.atlas.core/src/main/java/org/planqk/atlas/core/repository/ImplementationRepository.java b/org.planqk.atlas.core/src/main/java/org/planqk/atlas/core/repository/ImplementationRepository.java index 40014cb2..6a6b8fd4 100644 --- a/org.planqk.atlas.core/src/main/java/org/planqk/atlas/core/repository/ImplementationRepository.java +++ b/org.planqk.atlas.core/src/main/java/org/planqk/atlas/core/repository/ImplementationRepository.java @@ -58,7 +58,7 @@ public interface ImplementationRepository extends RevisionRepository findImplementationsByPatterns(@Param("patternURI") URI patternURI, Pageable pageable); + Page findImplementationsByPatterns(@Param("patternURI") String patternURI, Pageable pageable); @Modifying() @Query(value = "DELETE FROM implementation_revisions WHERE id = :implId", nativeQuery = true) diff --git a/org.planqk.atlas.core/src/main/java/org/planqk/atlas/core/services/ImplementationService.java b/org.planqk.atlas.core/src/main/java/org/planqk/atlas/core/services/ImplementationService.java index 9737804e..70f183bc 100644 --- a/org.planqk.atlas.core/src/main/java/org/planqk/atlas/core/services/ImplementationService.java +++ b/org.planqk.atlas.core/src/main/java/org/planqk/atlas/core/services/ImplementationService.java @@ -213,6 +213,6 @@ public interface ImplementationService { * @param pageable The page information, namely page size and page number, of the page we want to retrieve * @return The page of queried {@link Implementation} entries which implement the given Pattern */ - Page findByImplementedPatterns(URI patternUri, Pageable pageable); + Page findByImplementedPatterns(String patternUri, Pageable pageable); } diff --git a/org.planqk.atlas.core/src/main/java/org/planqk/atlas/core/services/ImplementationServiceImpl.java b/org.planqk.atlas.core/src/main/java/org/planqk/atlas/core/services/ImplementationServiceImpl.java index 86719bd8..6f68d065 100644 --- a/org.planqk.atlas.core/src/main/java/org/planqk/atlas/core/services/ImplementationServiceImpl.java +++ b/org.planqk.atlas.core/src/main/java/org/planqk/atlas/core/services/ImplementationServiceImpl.java @@ -222,7 +222,7 @@ public Revision findImplementationRevision(@NonNull UUI } @Override - public Page findByImplementedPatterns(URI patternUri, Pageable pageable) { + public Page findByImplementedPatterns(String patternUri, Pageable pageable) { return implementationRepository.findImplementationsByPatterns(patternUri, pageable); } diff --git a/org.planqk.atlas.web/src/main/java/org/planqk/atlas/web/controller/ImplementationGlobalController.java b/org.planqk.atlas.web/src/main/java/org/planqk/atlas/web/controller/ImplementationGlobalController.java index 51213b5d..282e3895 100644 --- a/org.planqk.atlas.web/src/main/java/org/planqk/atlas/web/controller/ImplementationGlobalController.java +++ b/org.planqk.atlas.web/src/main/java/org/planqk/atlas/web/controller/ImplementationGlobalController.java @@ -145,9 +145,8 @@ public ResponseEntity> getPatternsOfImplementation( @PostMapping("/{implementationId}/" + Constants.PATTERNS) public ResponseEntity addPatternToImplementation( @PathVariable UUID implementationId, - @Validated(ValidationGroups.Create.class) @RequestBody PatternUriDto patternDto) { + @Validated(ValidationGroups.Create.class) @RequestParam("patternURI") String patternURI) { final Implementation implementation = implementationService.findById(implementationId); - final URI patternURI = patternDto.getPatternURI(); implementation.addPattern(patternURI); implementationService.update(implementation); return new ResponseEntity<>(HttpStatus.CREATED); @@ -163,9 +162,9 @@ public ResponseEntity addPatternToImplementation( @DeleteMapping("/{implementationId}/" + Constants.PATTERNS) public ResponseEntity removePatternFromImplementation( @PathVariable UUID implementationId, - @Validated(ValidationGroups.IDOnly.class) @RequestBody PatternUriDto patternDto) { + @Validated(ValidationGroups.IDOnly.class) @RequestParam("patternURI") String patternURI) { final Implementation implementation = implementationService.findById(implementationId); - implementation.removePattern(ModelMapperUtils.convert(patternDto, PatternUriDto.class).getPatternURI()); + implementation.removePattern(patternURI); implementationService.update(implementation); return new ResponseEntity<>(HttpStatus.NO_CONTENT); } @@ -179,7 +178,7 @@ public ResponseEntity removePatternFromImplementation( @GetMapping("/" + Constants.PATTERNS) public ResponseEntity> getImplementationsOfPattern( @Parameter(hidden = true) ListParameters listParameters, - @RequestParam("patternURI") URI patternURI) { + @RequestParam("patternURI") String patternURI) { final var implementations = implementationService.findByImplementedPatterns(patternURI, listParameters.getPageable()); return ResponseEntity.ok(ModelMapperUtils.convertPage(implementations, ImplementationDto.class)); } diff --git a/org.planqk.atlas.web/src/main/java/org/planqk/atlas/web/dtos/PatternUriDto.java b/org.planqk.atlas.web/src/main/java/org/planqk/atlas/web/dtos/PatternUriDto.java index d66514bc..97d5a691 100644 --- a/org.planqk.atlas.web/src/main/java/org/planqk/atlas/web/dtos/PatternUriDto.java +++ b/org.planqk.atlas.web/src/main/java/org/planqk/atlas/web/dtos/PatternUriDto.java @@ -36,5 +36,5 @@ public class PatternUriDto { @NotNull(groups = {ValidationGroups.IDOnly.class, ValidationGroups.Create.class}, message = "URI value must not be null!") - private URI patternURI; + private String patternURI; }