summaryrefslogtreecommitdiffstats
path: root/cps-rest/src/main
diff options
context:
space:
mode:
authorJosephKeenan <joseph.keenan@est.tech>2021-06-08 13:16:37 +0100
committerJosephKeenan <joseph.keenan@est.tech>2021-06-15 14:56:06 +0100
commitc6865f33336bcdcd79eb2659b1a7df130aee9452 (patch)
treea157d762ce2ff0100164683236a44e0088e986ad /cps-rest/src/main
parente3f7305a421e075eef97d4eefdd590ca95a2a4f6 (diff)
[OpenAPI] Implemented example as per example wiki page for getting anchors based on dataspace
-moved components from cpsAdmin.yml to components.yml -refactored variable for anchor details list in AdminRestController.java -reintrocuded paramter for anchorsByDataspace -refactored variables in AdminRestController.java getAnchors() to be more intuitive -refactored AdminRestController.java to use modelmapper and removed extra conversion code. Also modified AdminRestControllerSpec.groovy to use ModelMapper as Spy rather than a Mock -added responses for getAnchor & getSchemaSet -added javadoc for AdminRestController.java public methods -refactored schemaDetils pararmeter from dataSpasceName to name for CSOT tests & added some code review comments Issue-ID: CPS-429 Change-Id: I01d4113313c9a23d9a7e0e96e46b90f9ac767f24 Signed-off-by: JosephKeenan <joseph.keenan@est.tech>
Diffstat (limited to 'cps-rest/src/main')
-rwxr-xr-xcps-rest/src/main/java/org/onap/cps/rest/controller/AdminRestController.java77
1 files changed, 70 insertions, 7 deletions
diff --git a/cps-rest/src/main/java/org/onap/cps/rest/controller/AdminRestController.java b/cps-rest/src/main/java/org/onap/cps/rest/controller/AdminRestController.java
index 74b1a418d1..57b6771940 100755
--- a/cps-rest/src/main/java/org/onap/cps/rest/controller/AdminRestController.java
+++ b/cps-rest/src/main/java/org/onap/cps/rest/controller/AdminRestController.java
@@ -25,11 +25,16 @@ import static org.onap.cps.rest.utils.MultipartFileUtil.extractYangResourcesMap;
import static org.onap.cps.spi.CascadeDeleteAllowed.CASCADE_DELETE_PROHIBITED;
import java.util.Collection;
+import java.util.List;
+import java.util.stream.Collectors;
import org.modelmapper.ModelMapper;
import org.onap.cps.api.CpsAdminService;
import org.onap.cps.api.CpsModuleService;
import org.onap.cps.rest.api.CpsAdminApi;
+import org.onap.cps.rest.model.AnchorDetails;
+import org.onap.cps.rest.model.SchemaSetDetails;
import org.onap.cps.spi.model.Anchor;
+import org.onap.cps.spi.model.SchemaSet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
@@ -50,17 +55,37 @@ public class AdminRestController implements CpsAdminApi {
@Autowired
private ModelMapper modelMapper;
+ /**
+ * Create a dataspace.
+ *
+ * @param dataspaceName dataspace name
+ * @return a {@Link ResponseEntity} of created dataspace name & {@link HttpStatus} CREATED
+ */
@Override
public ResponseEntity<String> createDataspace(final String dataspaceName) {
cpsAdminService.createDataspace(dataspaceName);
return new ResponseEntity<>(dataspaceName, HttpStatus.CREATED);
}
+ /**
+ * Delete a dataspace based on a given name.
+ *
+ * @param dataspaceName dataspace name
+ * @return a {@Link ResponseEntity} of {@link HttpStatus} NOT_IMPLEMENTED
+ */
@Override
public ResponseEntity<Object> deleteDataspace(final String dataspaceName) {
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
}
+ /**
+ * Create a {@link SchemaSet}.
+ *
+ * @param multipartFile multipart file
+ * @param schemaSetName schemaset name
+ * @param dataspaceName dataspace name
+ * @return a {@Link ResponseEntity} of created schemaset name & {@link HttpStatus} CREATED
+ */
@Override
public ResponseEntity<String> createSchemaSet(final MultipartFile multipartFile,
final String schemaSetName, final String dataspaceName) {
@@ -68,12 +93,27 @@ public class AdminRestController implements CpsAdminApi {
return new ResponseEntity<>(schemaSetName, HttpStatus.CREATED);
}
+ /**
+ * Get {@link SchemaSetDetails} based on dataspace name & {@link SchemaSet} name.
+ *
+ * @param dataspaceName dataspace name
+ * @param schemaSetName schemaset name
+ * @return a {@Link ResponseEntity} of {@Link SchemaSetDetails} & {@link HttpStatus} OK
+ */
@Override
- public ResponseEntity<Object> getSchemaSet(final String dataspaceName, final String schemaSetName) {
+ public ResponseEntity<SchemaSetDetails> getSchemaSet(final String dataspaceName, final String schemaSetName) {
final var schemaSet = cpsModuleService.getSchemaSet(dataspaceName, schemaSetName);
- return new ResponseEntity<>(schemaSet, HttpStatus.OK);
+ final SchemaSetDetails schemaSetDetails = modelMapper.map(schemaSet, SchemaSetDetails.class);
+ return new ResponseEntity<>(schemaSetDetails, HttpStatus.OK);
}
+ /**
+ * Delete a {@link SchemaSet} based on given dataspace name & schemaset name.
+ *
+ * @param dataspaceName dataspace name
+ * @param schemaSetName schemaset name
+ * @return a {@Link ResponseEntity} of {@link HttpStatus} NO_CONTENT
+ */
@Override
public ResponseEntity<Void> deleteSchemaSet(final String dataspaceName, final String schemaSetName) {
cpsModuleService.deleteSchemaSet(dataspaceName, schemaSetName, CASCADE_DELETE_PROHIBITED);
@@ -86,7 +126,7 @@ public class AdminRestController implements CpsAdminApi {
* @param dataspaceName dataspace name
* @param schemaSetName schema set name
* @param anchorName anchorName
- * @return a ResponseEntity with the anchor name.
+ * @return a ResponseEntity with the anchor name & {@link HttpStatus} CREATED
*/
@Override
public ResponseEntity<String> createAnchor(final String dataspaceName, final String schemaSetName,
@@ -95,21 +135,44 @@ public class AdminRestController implements CpsAdminApi {
return new ResponseEntity<>(anchorName, HttpStatus.CREATED);
}
+ /**
+ * Delete an {@link Anchor} based on given dataspace name & anchor name.
+ *
+ * @param dataspaceName dataspace name
+ * @param anchorName anchor name
+ * @return a {@Link ResponseEntity} of {@link HttpStatus} NO_CONTENT
+ */
@Override
public ResponseEntity<Void> deleteAnchor(final String dataspaceName, final String anchorName) {
cpsAdminService.deleteAnchor(dataspaceName, anchorName);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
+ /**
+ * Get an {@link Anchor} based on given dataspace name & anchor name.
+ *
+ * @param dataspaceName dataspace name
+ * @param anchorName anchor name
+ * @return a {@Link ResponseEntity} of an {@Link AnchorDetails} & {@link HttpStatus} OK
+ */
@Override
- public ResponseEntity<Object> getAnchor(final String dataspaceName, final String anchorName) {
+ public ResponseEntity<AnchorDetails> getAnchor(final String dataspaceName, final String anchorName) {
final var anchor = cpsAdminService.getAnchor(dataspaceName, anchorName);
- return new ResponseEntity<>(anchor, HttpStatus.OK);
+ final AnchorDetails anchorDetails = modelMapper.map(anchor, AnchorDetails.class);
+ return new ResponseEntity<>(anchorDetails, HttpStatus.OK);
}
+ /**
+ * Get all {@link Anchor} based on given dataspace name.
+ *
+ * @param dataspaceName dataspace name
+ * @return a {@Link ResponseEntity} of all {@Link AnchorDetails} & {@link HttpStatus} OK
+ */
@Override
- public ResponseEntity<Object> getAnchors(final String dataspaceName) {
- final Collection<Anchor> anchorDetails = cpsAdminService.getAnchors(dataspaceName);
+ public ResponseEntity<List<AnchorDetails>> getAnchors(final String dataspaceName) {
+ final Collection<Anchor> anchors = cpsAdminService.getAnchors(dataspaceName);
+ final List<AnchorDetails> anchorDetails = anchors.stream().map(anchor ->
+ modelMapper.map(anchor, AnchorDetails.class)).collect(Collectors.toList());
return new ResponseEntity<>(anchorDetails, HttpStatus.OK);
}
}