-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #232 from AAFC-BICoE/34325_use_vocabulary_methods_…
…from_dina-base 34325 use vocabulary methods from dina base
- Loading branch information
Showing
14 changed files
with
88 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 50 additions & 21 deletions
71
src/main/java/ca/gc/aafc/seqdb/api/repository/VocabularyRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,63 @@ | ||
package ca.gc.aafc.seqdb.api.repository; | ||
|
||
import ca.gc.aafc.seqdb.api.SequenceVocabularyConfiguration; | ||
import org.springframework.hateoas.CollectionModel; | ||
import org.springframework.hateoas.RepresentationModel; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import com.toedter.spring.hateoas.jsonapi.JsonApiModelBuilder; | ||
|
||
import ca.gc.aafc.dina.repository.ReadOnlyDinaRepositoryV2; | ||
import ca.gc.aafc.seqdb.api.dto.VocabularyDto; | ||
import io.crnk.core.queryspec.QuerySpec; | ||
import io.crnk.core.repository.ReadOnlyResourceRepositoryBase; | ||
import io.crnk.core.resource.list.ResourceList; | ||
import lombok.NonNull; | ||
import org.springframework.stereotype.Repository; | ||
import ca.gc.aafc.seqdb.api.service.VocabularyService; | ||
|
||
import static com.toedter.spring.hateoas.jsonapi.JsonApiModelBuilder.jsonApiModel; | ||
import static com.toedter.spring.hateoas.jsonapi.MediaTypes.JSON_API_VALUE; | ||
|
||
import java.net.URLDecoder; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import javax.servlet.http.HttpServletRequest; | ||
|
||
@RestController | ||
@RequestMapping(value = "/api", produces = JSON_API_VALUE) | ||
public class VocabularyRepository extends ReadOnlyDinaRepositoryV2<String, VocabularyDto> { | ||
|
||
protected VocabularyRepository(VocabularyService vocabularyService) { | ||
super(vocabularyService); | ||
} | ||
|
||
@Repository | ||
public class VocabularyRepository extends ReadOnlyResourceRepositoryBase<VocabularyDto, String> { | ||
@GetMapping("vocabulary/{id}") | ||
public ResponseEntity<RepresentationModel<?>> handleFindOne(@PathVariable String id) { | ||
|
||
private final List<VocabularyDto> vocabulary; | ||
VocabularyDto dto = findOne(id); | ||
|
||
protected VocabularyRepository( | ||
@NonNull SequenceVocabularyConfiguration collectionVocabularyConfiguration) { | ||
super(VocabularyDto.class); | ||
if (dto == null) { | ||
return ResponseEntity.notFound().build(); | ||
} | ||
|
||
vocabulary = collectionVocabularyConfiguration.getVocabulary() | ||
.entrySet() | ||
.stream() | ||
.map(entry -> new VocabularyDto(entry.getKey(), entry.getValue())) | ||
.collect(Collectors.toList()); | ||
JsonApiModelBuilder builder = jsonApiModel().model(RepresentationModel.of(dto)); | ||
|
||
return ResponseEntity.ok(builder.build()); | ||
} | ||
|
||
@Override | ||
public ResourceList<VocabularyDto> findAll(QuerySpec querySpec) { | ||
return querySpec.apply(vocabulary); | ||
@GetMapping("vocabulary") | ||
public ResponseEntity<RepresentationModel<?>> handleFindAll(HttpServletRequest req) { | ||
|
||
String queryString = URLDecoder.decode(req.getQueryString(), StandardCharsets.UTF_8); | ||
List<VocabularyDto> dtos ; | ||
try { | ||
dtos = findAll(queryString); | ||
} catch (IllegalArgumentException iaEx) { | ||
return ResponseEntity.badRequest().build(); | ||
} | ||
|
||
JsonApiModelBuilder builder = jsonApiModel().model(CollectionModel.of(dtos)); | ||
|
||
return ResponseEntity.ok(builder.build()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/main/java/ca/gc/aafc/seqdb/api/service/VocabularyService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package ca.gc.aafc.seqdb.api.service; | ||
|
||
import java.util.stream.Collectors; | ||
|
||
import org.springframework.stereotype.Service; | ||
|
||
import ca.gc.aafc.dina.service.CollectionBackedReadOnlyDinaService; | ||
import ca.gc.aafc.seqdb.api.SequenceVocabularyConfiguration; | ||
import ca.gc.aafc.seqdb.api.dto.VocabularyDto; | ||
|
||
@Service | ||
public class VocabularyService extends CollectionBackedReadOnlyDinaService<String, VocabularyDto> { | ||
|
||
public VocabularyService(SequenceVocabularyConfiguration sequenceVocabularyConfiguration) { | ||
super(sequenceVocabularyConfiguration.getVocabulary() | ||
.entrySet() | ||
.stream() | ||
.map(entry -> new VocabularyDto(entry.getKey(), entry.getValue())) | ||
.collect(Collectors.toList()), VocabularyDto::getId); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters