Skip to content

Commit

Permalink
Encode patterns as string (#222)
Browse files Browse the repository at this point in the history
  • Loading branch information
mar-be authored Nov 15, 2023
1 parent 1bb6c0b commit e39d20c
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<URI> patterns = new HashSet<>();
private Set<String> patterns = new HashSet<>();

public void addTag(@NonNull Tag tag) {
if (tags.contains(tag)) {
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public interface ImplementationRepository extends RevisionRepository<Implementat
"FROM Implementation impl " +
"JOIN impl.patterns uri " +
"WHERE uri = :patternURI")
Page<Implementation> findImplementationsByPatterns(@Param("patternURI") URI patternURI, Pageable pageable);
Page<Implementation> findImplementationsByPatterns(@Param("patternURI") String patternURI, Pageable pageable);

@Modifying()
@Query(value = "DELETE FROM implementation_revisions WHERE id = :implId", nativeQuery = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Implementation> findByImplementedPatterns(URI patternUri, Pageable pageable);
Page<Implementation> findByImplementedPatterns(String patternUri, Pageable pageable);

}
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ public Revision<Integer, Implementation> findImplementationRevision(@NonNull UUI
}

@Override
public Page<Implementation> findByImplementedPatterns(URI patternUri, Pageable pageable) {
public Page<Implementation> findByImplementedPatterns(String patternUri, Pageable pageable) {
return implementationRepository.findImplementationsByPatterns(patternUri, pageable);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,8 @@ public ResponseEntity<Collection<PatternUriDto>> getPatternsOfImplementation(
@PostMapping("/{implementationId}/" + Constants.PATTERNS)
public ResponseEntity<Void> 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);
Expand All @@ -163,9 +162,9 @@ public ResponseEntity<Void> addPatternToImplementation(
@DeleteMapping("/{implementationId}/" + Constants.PATTERNS)
public ResponseEntity<Void> 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);
}
Expand All @@ -179,7 +178,7 @@ public ResponseEntity<Void> removePatternFromImplementation(
@GetMapping("/" + Constants.PATTERNS)
public ResponseEntity<Page<ImplementationDto>> 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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit e39d20c

Please sign in to comment.