401:
description: Unauthorized
content: {}
+ 400:
+ description: Bad Request
+ content: {}
403:
description: Forbidden
- content: {}
404:
description: Not Found
content: {}
+ 204:
+ description: No Content
+ content: {}
post:
tags:
- cps-rest
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
+import java.util.Collection;
import javax.validation.Valid;
import org.modelmapper.ModelMapper;
import org.onap.cps.api.CpService;
}
@Override
+
public ResponseEntity<Object> getAnchors(final String dataspaceName) {
- return null;
+ final Collection<Anchor> anchorDetails = cpsAdminService.getAnchors(dataspaceName);
+ return new ResponseEntity<>(anchorDetails, HttpStatus.OK);
}
@Override
import org.onap.cps.rest.controller.CpsRestController;
import org.onap.cps.rest.model.ErrorMessage;
import org.onap.cps.spi.exceptions.AnchorAlreadyDefinedException;
+import org.onap.cps.spi.exceptions.CpsAdminException;
import org.onap.cps.spi.exceptions.CpsException;
import org.onap.cps.spi.exceptions.DataValidationException;
import org.onap.cps.spi.exceptions.ModelValidationException;
}
@ExceptionHandler({ModelValidationException.class, DataValidationException.class,
- SchemaSetAlreadyDefinedException.class, AnchorAlreadyDefinedException.class})
+ SchemaSetAlreadyDefinedException.class, AnchorAlreadyDefinedException.class, CpsAdminException.class})
public static ResponseEntity<Object> handleBadRequestExceptions(final CpsException exception) {
return buildErrorResponse(HttpStatus.BAD_REQUEST, exception.getMessage(), extractDetails(exception));
}
<groupId>org.projectlombok</groupId>\r
<artifactId>lombok</artifactId>\r
</dependency>\r
+ <dependency>\r
+ <groupId>org.modelmapper</groupId>\r
+ <artifactId>modelmapper</artifactId>\r
+ </dependency>\r
<!-- Test dependencies -->\r
<dependency>\r
<groupId>org.springframework.boot</groupId>\r
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2020 Nordix Foundation. All rights reserved.
+ * Modifications Copyright (C) 2020 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
package org.onap.cps.spi.impl;
+import java.lang.reflect.Type;
+import java.util.Collection;
+import org.modelmapper.ModelMapper;
+import org.modelmapper.TypeToken;
import org.onap.cps.spi.CpsAdminPersistenceService;
import org.onap.cps.spi.entities.Dataspace;
import org.onap.cps.spi.entities.Fragment;
throw new AnchorAlreadyDefinedException(anchor.getDataspaceName(), anchorName, ex);
}
}
+
+ @Override
+ public Collection<Anchor> getAnchors(final String dataspaceName) {
+ final Dataspace dataspace = dataspaceRepository.getByName(dataspaceName);
+ final Collection<Fragment> fragments = fragmentRepository.findFragmentsThatAreAnchorsByDataspace(dataspace);
+ final Type anchorListType = new TypeToken<Collection<Anchor>>() {}.getType();
+ return new ModelMapper().map(fragments, anchorListType);
+ }
}
/*-\r
* ============LICENSE_START=======================================================\r
* Copyright (C) 2020 Nordix Foundation. All rights reserved.\r
+ * Modifications Copyright (C) 2020 Bell Canada. All rights reserved.\r
* ================================================================================\r
* Licensed under the Apache License, Version 2.0 (the "License");\r
* you may not use this file except in compliance with the License.\r
\r
package org.onap.cps.spi.repository;\r
\r
+import java.util.Collection;\r
+import org.onap.cps.spi.entities.Dataspace;\r
import org.onap.cps.spi.entities.Fragment;\r
import org.springframework.data.jpa.repository.JpaRepository;\r
+import org.springframework.data.jpa.repository.Query;\r
+import org.springframework.data.repository.query.Param;\r
import org.springframework.stereotype.Repository;\r
\r
@Repository\r
public interface FragmentRepository extends JpaRepository<Fragment, Integer> {\r
+\r
+ default Collection<Fragment> findFragmentsThatAreAnchorsByDataspace(Dataspace dataspace) {\r
+ return findFragmentsByDataspaceAndParentFragmentIsNull(dataspace);\r
+ }\r
+\r
+ Collection<Fragment> findFragmentsByDataspaceAndParentFragmentIsNull(Dataspace dataspace);\r
}
\ No newline at end of file
package org.onap.cps.api;
+import java.util.Collection;
import org.onap.cps.spi.exceptions.CpsException;
import org.onap.cps.spi.model.Anchor;
* @throws CpsException if input data is invalid.
*/
String createAnchor(Anchor anchor);
+
+ /**
+ * Read all anchors in the given a dataspace.
+ *
+ * @param dataspaceName dataspace name
+ * @return a collection of anchors
+ */
+ Collection<Anchor> getAnchors(String dataspaceName);
}
package org.onap.cps.api.impl;
+import java.util.Collection;
import org.onap.cps.api.CpsAdminService;
import org.onap.cps.spi.CpsAdminPersistenceService;
import org.onap.cps.spi.model.Anchor;
public String createAnchor(final Anchor anchor) {
return cpsAdminPersistenceService.createAnchor(anchor);
}
+
+ @Override
+ public Collection<Anchor> getAnchors(final String dataspaceName) {
+ return cpsAdminPersistenceService.getAnchors(dataspaceName);
+ }
}
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2020 Nordix Foundation. All rights reserved.
+ * Modifications Copyright (C) 2020 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
package org.onap.cps.spi;
+import java.util.Collection;
import org.onap.cps.spi.model.Anchor;
/*
* @return the anchor name.
*/
String createAnchor(Anchor anchor);
+
+ /**
+ * Read all anchors in the given a dataspace.
+ *
+ * @param dataspaceName dataspace name
+ * @return a collection of anchors
+ */
+ Collection<Anchor> getAnchors(String dataspaceName);
}
package org.onap.cps.api.impl
-
import org.onap.cps.spi.CpsAdminPersistenceService
+import org.onap.cps.spi.exceptions.DataspaceNotFoundException
import org.onap.cps.spi.model.Anchor
import spock.lang.Specification
def exceptionThrownInServiceLayer = thrown(Exception)
exceptionThrownInServiceLayer == exceptionThrownInPersistenceLayer
}
+
+ def 'Retrieve all anchors for an existing dataspace'() {
+ given: 'that the dataspace exist and an anchor is associated with the dataspace'
+ Collection<Anchor> anchorCollection = Arrays.asList(anchor)
+ mockCpsAdminPersistenceService.getAnchors('dummyDataspace') >> { anchorCollection }
+ expect: 'we try to retrieve an anchor, a collection of anchor is returned by the service'
+ objectUnderTest.getAnchors('dummyDataspace') == anchorCollection
+ }
+
+ def 'Retrieve all anchors for a non existing dataspace'() {
+ given: 'that the dataspace does not exist, service throws an exception'
+ def exceptionThrownInPersistenceLayer = new DataspaceNotFoundException(_ as String)
+ mockCpsAdminPersistenceService.getAnchors('dummyDataspace') >>
+ { throw exceptionThrownInPersistenceLayer }
+ when: 'we try to retrieve a anchor with a non-existant dataspace'
+ objectUnderTest.getAnchors('dummyDataspace')
+ then: 'the same exception is thrown by CPS'
+ def exceptionThrownInServiceLayer = thrown(Exception)
+ exceptionThrownInServiceLayer == exceptionThrownInPersistenceLayer
+ }
}