Associate anchor to schema set

- db schema updated
- db layer tests provided for ancor create and reading by dataspace
- anchor model is removed from rest api as extra
- api/spi updated to use string references instead of object

Issue-ID: CPS-99
Change-Id: Ideeb83fa9e91ec1816308d8327a6589b999c64c5
Signed-off-by: Ruslan Kashapov <ruslan.kashapov@pantheon.tech>
diff --git a/cps-rest/docs/api/swagger/openapi.yml b/cps-rest/docs/api/swagger/openapi.yml
index ff7cdf8..587a376 100755
--- a/cps-rest/docs/api/swagger/openapi.yml
+++ b/cps-rest/docs/api/swagger/openapi.yml
@@ -84,14 +84,18 @@
           required: true
           schema:
             type: string
-      requestBody:
-        content:
-          application/json:
-            schema:
-              title: Anchor
-              description: anchor
-              $ref: '#/components/schemas/Anchor'
-        required: true
+        - name: schema-set-name
+          in: query
+          description: schema-set-name
+          required: true
+          schema:
+            type: string
+        - name: anchor-name
+          in: query
+          description: anchor-name
+          required: true
+          schema:
+            type: string
       responses:
         201:
           description: Created
@@ -298,17 +302,3 @@
           type: string
         details:
           type: string
-    Anchor:
-      type: object
-      title: Anchor
-      required:
-        - anchorName
-        - namespace
-        - revision
-      properties:
-        anchorName:
-          type: string
-        namespace:
-          type: string
-        revision:
-          type: string
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 e2ce367..336762c 100644
--- 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
@@ -43,16 +43,15 @@
     /**
      * Create a new anchor.
      *
-     * @param anchor        the anchor details object.
-     * @param dataspaceName the dataspace name.
+     * @param dataspaceName dataspace name
+     * @param schemaSetName schema set name
+     * @param anchorName    anchorName
      * @return a ResponseEntity with the anchor name.
      */
     @Override
-    public ResponseEntity<String> createAnchor(final org.onap.cps.rest.model.@Valid Anchor anchor,
-        final String dataspaceName) {
-        final Anchor anchorDetails = modelMapper.map(anchor, Anchor.class);
-        anchorDetails.setDataspaceName(dataspaceName);
-        final String anchorName = cpsAdminService.createAnchor(anchorDetails);
+    public ResponseEntity<String> createAnchor(final String dataspaceName, final String schemaSetName,
+                                               final String anchorName) {
+        cpsAdminService.createAnchor(dataspaceName, schemaSetName, anchorName);
         return new ResponseEntity<>(anchorName, HttpStatus.CREATED);
     }
 
@@ -72,7 +71,6 @@
     }
 
     @Override
-
     public ResponseEntity<Object> getAnchors(final String dataspaceName) {
         final Collection<Anchor> anchorDetails = cpsAdminService.getAnchors(dataspaceName);
         return new ResponseEntity<>(anchorDetails, HttpStatus.OK);
diff --git a/cps-rest/src/main/java/org/onap/cps/rest/exceptions/CpsRestExceptionHandler.java b/cps-rest/src/main/java/org/onap/cps/rest/exceptions/CpsRestExceptionHandler.java
index 9d7f38a..d4faebc 100644
--- a/cps-rest/src/main/java/org/onap/cps/rest/exceptions/CpsRestExceptionHandler.java
+++ b/cps-rest/src/main/java/org/onap/cps/rest/exceptions/CpsRestExceptionHandler.java
@@ -23,13 +23,11 @@
 import org.onap.cps.rest.controller.AdminRestController;
 import org.onap.cps.rest.controller.DataRestController;
 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;
 import org.onap.cps.spi.exceptions.NotFoundInDataspaceException;
-import org.onap.cps.spi.exceptions.SchemaSetAlreadyDefinedException;
 import org.springframework.http.HttpStatus;
 import org.springframework.http.ResponseEntity;
 import org.springframework.web.bind.annotation.ExceptionHandler;
@@ -52,8 +50,7 @@
         return buildErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR, exception);
     }
 
-    @ExceptionHandler({ModelValidationException.class, DataValidationException.class,
-        SchemaSetAlreadyDefinedException.class, AnchorAlreadyDefinedException.class, CpsAdminException.class})
+    @ExceptionHandler({ModelValidationException.class, DataValidationException.class, CpsAdminException.class})
     public static ResponseEntity<Object> handleBadRequestExceptions(final CpsException exception) {
         return buildErrorResponse(HttpStatus.BAD_REQUEST, exception.getMessage(), extractDetails(exception));
     }
diff --git a/cps-ri/src/main/java/org/onap/cps/spi/entities/Fragment.java b/cps-ri/src/main/java/org/onap/cps/spi/entities/Fragment.java
index 7afdb3e..2dbd6e9 100755
--- a/cps-ri/src/main/java/org/onap/cps/spi/entities/Fragment.java
+++ b/cps-ri/src/main/java/org/onap/cps/spi/entities/Fragment.java
@@ -84,6 +84,6 @@
     private Fragment parentFragment;

 

     @OneToOne(fetch = FetchType.LAZY)

-    @JoinColumn(name = "module_id")

-    private Module module;

+    @JoinColumn(name = "schema_set_id")

+    private SchemaSet schemaSet;

 }

diff --git a/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsAdminPersistenceServiceImpl.java b/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsAdminPersistenceServiceImpl.java
index 48e7303..5093ba5 100644
--- a/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsAdminPersistenceServiceImpl.java
+++ b/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsAdminPersistenceServiceImpl.java
@@ -21,19 +21,17 @@
 
 package org.onap.cps.spi.impl;
 
-import java.lang.reflect.Type;
 import java.util.Collection;
-import org.modelmapper.ModelMapper;
-import org.modelmapper.TypeToken;
+import java.util.stream.Collectors;
 import org.onap.cps.spi.CpsAdminPersistenceService;
 import org.onap.cps.spi.entities.Dataspace;
 import org.onap.cps.spi.entities.Fragment;
-import org.onap.cps.spi.entities.Module;
+import org.onap.cps.spi.entities.SchemaSet;
 import org.onap.cps.spi.exceptions.AnchorAlreadyDefinedException;
 import org.onap.cps.spi.model.Anchor;
 import org.onap.cps.spi.repository.DataspaceRepository;
 import org.onap.cps.spi.repository.FragmentRepository;
-import org.onap.cps.spi.repository.ModuleRepository;
+import org.onap.cps.spi.repository.SchemaSetRepository;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.dao.DataIntegrityViolationException;
 import org.springframework.stereotype.Component;
@@ -48,22 +46,22 @@
     private FragmentRepository fragmentRepository;
 
     @Autowired
-    private ModuleRepository moduleRepository;
+    private SchemaSetRepository schemaSetRepository;
 
     @Override
-    public String createAnchor(final Anchor anchor) {
-        final String anchorName = anchor.getAnchorName();
+    public void createAnchor(final String dataspaceName, final String schemaSetName, final String anchorName) {
+        final Dataspace dataspace = dataspaceRepository.getByName(dataspaceName);
+        final SchemaSet schemaSet = schemaSetRepository.getByDataspaceAndName(dataspace, schemaSetName);
+        final Fragment anchor = Fragment.builder()
+            .xpath(anchorName)
+            .anchorName(anchorName)
+            .dataspace(dataspace)
+            .schemaSet(schemaSet)
+            .build();
         try {
-            final Dataspace dataspace = dataspaceRepository.getByName(anchor.getDataspaceName());
-            final Module module = moduleRepository
-                .getByDataspaceAndNamespaceAndRevision(dataspace, anchor.getNamespace(), anchor.getRevision());
-            final Fragment fragment =
-                Fragment.builder().xpath(anchorName).anchorName(anchorName).dataspace(dataspace).module(module).build();
-
-            fragmentRepository.save(fragment);
-            return anchorName;
-        } catch (final DataIntegrityViolationException ex) {
-            throw new AnchorAlreadyDefinedException(anchor.getDataspaceName(), anchorName, ex);
+            fragmentRepository.save(anchor);
+        } catch (final DataIntegrityViolationException e) {
+            throw new AnchorAlreadyDefinedException(dataspaceName, anchorName, e);
         }
     }
 
@@ -71,7 +69,12 @@
     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);
+        return fragments.stream().map(
+            entity -> Anchor.builder()
+                .name(entity.getAnchorName())
+                .dataspaceName(dataspaceName)
+                .schemaSetName(entity.getSchemaSet().getName())
+                .build()
+        ).collect(Collectors.toList());
     }
 }
diff --git a/cps-ri/src/main/java/org/onap/cps/spi/repository/FragmentRepository.java b/cps-ri/src/main/java/org/onap/cps/spi/repository/FragmentRepository.java
index b1a8992..2ee76cc 100755
--- a/cps-ri/src/main/java/org/onap/cps/spi/repository/FragmentRepository.java
+++ b/cps-ri/src/main/java/org/onap/cps/spi/repository/FragmentRepository.java
@@ -22,6 +22,8 @@
 package org.onap.cps.spi.repository;

 

 import java.util.Collection;

+import java.util.Optional;

+import javax.validation.constraints.NotNull;

 import org.onap.cps.spi.entities.Dataspace;

 import org.onap.cps.spi.entities.Fragment;

 import org.springframework.data.jpa.repository.JpaRepository;

@@ -30,6 +32,8 @@
 @Repository

 public interface FragmentRepository extends JpaRepository<Fragment, Integer> {

 

+    Optional<Fragment> findByDataspaceAndAnchorName(@NotNull Dataspace dataspace, @NotNull String anchorName);

+

     default Collection<Fragment> findFragmentsThatAreAnchorsByDataspace(Dataspace dataspace) {

         return findFragmentsByDataspaceAndParentFragmentIsNull(dataspace);

     }

diff --git a/cps-ri/src/main/java/org/onap/cps/spi/repository/SchemaSetRepository.java b/cps-ri/src/main/java/org/onap/cps/spi/repository/SchemaSetRepository.java
index 035c831..9b9d706 100644
--- a/cps-ri/src/main/java/org/onap/cps/spi/repository/SchemaSetRepository.java
+++ b/cps-ri/src/main/java/org/onap/cps/spi/repository/SchemaSetRepository.java
@@ -36,14 +36,15 @@
     Optional<SchemaSet> findByDataspaceAndName(@NotNull Dataspace dataspace, @NotNull String schemaSetName);
 
     /**
-     * This method gets a SchemaSet by dataspace, namespace and schemaSetName.
+     * Gets a schema set by dataspace and schema set name.
      *
-     * @param dataspace     the dataspace
-     * @param schemaSetName the schemaSet Name
-     * @return schemaSet
+     * @param dataspace     dataspace entity
+     * @param schemaSetName schema set name
+     * @return schema set entity
+     * @throws SchemaSetNotFoundException if SchemaSet not found
      */
-    default SchemaSet getByDataspaceAndName(@NotNull Dataspace dataspace, @NotNull String schemaSetName) {
+    default SchemaSet getByDataspaceAndName(@NotNull final Dataspace dataspace, @NotNull final String schemaSetName) {
         return findByDataspaceAndName(dataspace, schemaSetName)
-                       .orElseThrow(() -> new SchemaSetNotFoundException(dataspace.getName(), schemaSetName));
+            .orElseThrow(() -> new SchemaSetNotFoundException(dataspace.getName(), schemaSetName));
     }
 }
diff --git a/cps-ri/src/main/resources/schema.sql b/cps-ri/src/main/resources/schema.sql
index 2dce470..58b3c63 100755
--- a/cps-ri/src/main/resources/schema.sql
+++ b/cps-ri/src/main/resources/schema.sql
@@ -61,7 +61,7 @@
     ANCHOR_NAME TEXT,

     ANCHOR_ID BIGINT REFERENCES FRAGMENT(ID),

     PARENT_ID BIGINT REFERENCES FRAGMENT(ID),

-    MODULE_ID INTEGER REFERENCES MODULE(ID),

+    SCHEMA_SET_ID INTEGER REFERENCES SCHEMA_SET(ID),

     DATASPACE_ID INTEGER NOT NULL REFERENCES DATASPACE(ID),

     SCHEMA_NODE_ID INTEGER REFERENCES SCHEMA_NODE(ID),

     UNIQUE (DATASPACE_ID, ANCHOR_NAME, XPATH)

@@ -78,7 +78,7 @@
 );

 

 CREATE INDEX  IF NOT EXISTS "FKI_FRAGMENT_DATASPACE_ID_FK"     ON FRAGMENT USING BTREE(DATASPACE_ID) ;

-CREATE INDEX  IF NOT EXISTS "FKI_FRAGMENT_MODULE_ID_FK"        ON FRAGMENT USING BTREE(MODULE_ID) ;

+CREATE INDEX  IF NOT EXISTS "FKI_FRAGMENT_SCHEMA_SET_ID_FK"    ON FRAGMENT USING BTREE(SCHEMA_SET_ID) ;

 CREATE INDEX  IF NOT EXISTS "FKI_FRAGMENT_PARENT_ID_FK"        ON FRAGMENT USING BTREE(PARENT_ID) ;

 CREATE INDEX  IF NOT EXISTS "FKI_FRAGMENT_ANCHOR_ID_FK"        ON FRAGMENT USING BTREE(ANCHOR_ID) ;

 CREATE INDEX  IF NOT EXISTS "PERF_SCHEMA_NODE_SCHEMA_NODE_ID"  ON SCHEMA_NODE USING BTREE(SCHEMA_NODE_IDENTIFIER) ;

diff --git a/cps-ri/src/test/java/org/onap/cps/spi/impl/CpsAdminPersistenceServiceTest.java b/cps-ri/src/test/java/org/onap/cps/spi/impl/CpsAdminPersistenceServiceTest.java
new file mode 100644
index 0000000..455369d
--- /dev/null
+++ b/cps-ri/src/test/java/org/onap/cps/spi/impl/CpsAdminPersistenceServiceTest.java
@@ -0,0 +1,143 @@
+/*
+ *  ============LICENSE_START=======================================================
+ *  Copyright (C) 2020 Pantheon.tech
+ *  ================================================================================
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ *  SPDX-License-Identifier: Apache-2.0
+ *  ============LICENSE_END=========================================================
+ */
+
+package org.onap.cps.spi.impl;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Collection;
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.onap.cps.DatabaseTestContainer;
+import org.onap.cps.spi.CpsAdminPersistenceService;
+import org.onap.cps.spi.entities.Dataspace;
+import org.onap.cps.spi.entities.Fragment;
+import org.onap.cps.spi.exceptions.AnchorAlreadyDefinedException;
+import org.onap.cps.spi.exceptions.DataspaceNotFoundException;
+import org.onap.cps.spi.exceptions.SchemaSetNotFoundException;
+import org.onap.cps.spi.model.Anchor;
+import org.onap.cps.spi.repository.DataspaceRepository;
+import org.onap.cps.spi.repository.FragmentRepository;
+import org.onap.cps.spi.repository.SchemaSetRepository;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.jdbc.Sql;
+import org.springframework.test.context.jdbc.SqlGroup;
+import org.springframework.test.context.junit4.SpringRunner;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest
+public class CpsAdminPersistenceServiceTest {
+
+    private static final String CLEAR_DATA = "/data/clear-all.sql";
+    private static final String SET_DATA = "/data/anchor.sql";
+
+    private static final String DATASPACE_NAME = "DATASPACE-001";
+    private static final String EMPTY_DATASPACE_NAME = "DATASPACE-002";
+    private static final String NON_EXISTING_DATASPACE_NAME = "NON EXISTING DATASPACE";
+    private static final String NON_EXISTING_SCHEMA_SET_NAME = "NON EXISTING SCHEMA SET";
+    private static final String SCHEMA_SET_NAME1 = "SCHEMA-SET-001";
+    private static final String SCHEMA_SET_NAME2 = "SCHEMA-SET-002";
+    private static final String ANCHOR_NAME1 = "ANCHOR-001";
+    private static final String ANCHOR_NAME2 = "ANCHOR-002";
+    private static final String ANCHOR_NAME_NEW = "ANCHOR-NEW";
+
+    @ClassRule
+    public static DatabaseTestContainer databaseTestContainer = DatabaseTestContainer.getInstance();
+
+    @Autowired
+    private CpsAdminPersistenceService cpsAdminPersistenceService;
+
+    @Autowired
+    private FragmentRepository fragmentRepository;
+
+    @Autowired
+    private DataspaceRepository dataspaceRepository;
+
+    @Autowired
+    private SchemaSetRepository schemaSetRepository;
+
+    @Test
+    @SqlGroup({@Sql(CLEAR_DATA), @Sql(SET_DATA)})
+    public void testCreateAnchor() {
+        cpsAdminPersistenceService.createAnchor(DATASPACE_NAME, SCHEMA_SET_NAME2, ANCHOR_NAME_NEW);
+
+        // validate anchor persisted
+        final Dataspace dataspace = dataspaceRepository.findByName(DATASPACE_NAME).orElseThrow();
+        final Fragment anchor =
+            fragmentRepository.findByDataspaceAndAnchorName(dataspace, ANCHOR_NAME_NEW).orElseThrow();
+
+        assertNotNull(anchor.getId());
+        assertEquals(ANCHOR_NAME_NEW, anchor.getAnchorName());
+        assertEquals(DATASPACE_NAME, anchor.getDataspace().getName());
+        assertEquals(SCHEMA_SET_NAME2, anchor.getSchemaSet().getName());
+    }
+
+    @Test(expected = DataspaceNotFoundException.class)
+    @SqlGroup({@Sql(CLEAR_DATA), @Sql(SET_DATA)})
+    public void testCreateAnchorAtNonExistingDataspace() {
+        cpsAdminPersistenceService.createAnchor(NON_EXISTING_DATASPACE_NAME, SCHEMA_SET_NAME2, ANCHOR_NAME_NEW);
+    }
+
+    @Test(expected = SchemaSetNotFoundException.class)
+    @SqlGroup({@Sql(CLEAR_DATA), @Sql(SET_DATA)})
+    public void testCreateAnchorWithNonExistingSchemaSet() {
+        cpsAdminPersistenceService.createAnchor(DATASPACE_NAME, NON_EXISTING_SCHEMA_SET_NAME, ANCHOR_NAME_NEW);
+    }
+
+    @Test(expected = AnchorAlreadyDefinedException.class)
+    @SqlGroup({@Sql(CLEAR_DATA), @Sql(SET_DATA)})
+    public void testCreateAnchorWithNameAlreadyDefined() {
+        cpsAdminPersistenceService.createAnchor(DATASPACE_NAME, SCHEMA_SET_NAME2, ANCHOR_NAME1);
+    }
+
+    @Test
+    @SqlGroup({@Sql(CLEAR_DATA), @Sql(SET_DATA)})
+    public void testGetAnchorsByDataspace() {
+        final Collection<Anchor> anchors = cpsAdminPersistenceService.getAnchors(DATASPACE_NAME);
+
+        assertNotNull(anchors);
+        assertEquals(2, anchors.size());
+        assertTrue(anchors.contains(
+            Anchor.builder().name(ANCHOR_NAME1).schemaSetName(SCHEMA_SET_NAME1).dataspaceName(DATASPACE_NAME).build()
+        ));
+        assertTrue(anchors.contains(
+            Anchor.builder().name(ANCHOR_NAME2).schemaSetName(SCHEMA_SET_NAME2).dataspaceName(DATASPACE_NAME).build()
+        ));
+    }
+
+    @Test(expected = DataspaceNotFoundException.class)
+    @SqlGroup({@Sql(CLEAR_DATA), @Sql(SET_DATA)})
+    public void testGetAnchorsByNonExistingDataspace() {
+        cpsAdminPersistenceService.getAnchors(NON_EXISTING_DATASPACE_NAME);
+    }
+
+    @Test
+    @SqlGroup({@Sql(CLEAR_DATA), @Sql(SET_DATA)})
+    public void testGetAnchorsFromEmptyDataspace() {
+        final Collection<Anchor> anchors = cpsAdminPersistenceService.getAnchors(EMPTY_DATASPACE_NAME);
+
+        assertNotNull(anchors);
+        assertTrue(anchors.isEmpty());
+    }
+
+}
diff --git a/cps-ri/src/test/resources/data/anchor.sql b/cps-ri/src/test/resources/data/anchor.sql
new file mode 100644
index 0000000..5507559
--- /dev/null
+++ b/cps-ri/src/test/resources/data/anchor.sql
@@ -0,0 +1,9 @@
+INSERT INTO DATASPACE (ID, NAME) VALUES
+    (1001, 'DATASPACE-001'), (1002, 'DATASPACE-002');
+
+INSERT INTO SCHEMA_SET (ID, NAME, DATASPACE_ID) VALUES
+    (2001, 'SCHEMA-SET-001', 1001), (2002, 'SCHEMA-SET-002', 1001);
+
+INSERT INTO FRAGMENT (ID, XPATH, ANCHOR_NAME, DATASPACE_ID, SCHEMA_SET_ID) VALUES
+    (3001, 'ANCHOR-001', 'ANCHOR-001', 1001, 2001),
+    (3002, 'ANCHOR-002', 'ANCHOR-002', 1001, 2002);
\ No newline at end of file
diff --git a/cps-ri/src/test/resources/data/clear-all.sql b/cps-ri/src/test/resources/data/clear-all.sql
index 3d93825..522f9e6 100644
--- a/cps-ri/src/test/resources/data/clear-all.sql
+++ b/cps-ri/src/test/resources/data/clear-all.sql
@@ -1,3 +1,4 @@
+DELETE FROM FRAGMENT;
 -- clear all via dataspace table cleanup
 -- all other data will be removed by cascade
 DELETE FROM DATASPACE;
diff --git a/cps-service/src/main/java/org/onap/cps/api/CpsAdminService.java b/cps-service/src/main/java/org/onap/cps/api/CpsAdminService.java
index a2c05bf..5090e3a 100644
--- a/cps-service/src/main/java/org/onap/cps/api/CpsAdminService.java
+++ b/cps-service/src/main/java/org/onap/cps/api/CpsAdminService.java
@@ -21,6 +21,7 @@
 package org.onap.cps.api;
 
 import java.util.Collection;
+import org.checkerframework.checker.nullness.qual.NonNull;
 import org.onap.cps.spi.exceptions.CpsException;
 import org.onap.cps.spi.model.Anchor;
 
@@ -30,13 +31,14 @@
 public interface CpsAdminService {
 
     /**
-     * Create an anchor using provided anchorDetails object.
+     * Create an Anchor.
      *
-     * @param anchor the anchor details object.
-     * @return the anchor name.
+     * @param dataspaceName dataspace name
+     * @param schemaSetName schema set name
+     * @param anchorName    anchor name
      * @throws CpsException if input data is invalid.
      */
-    String createAnchor(Anchor anchor);
+    void createAnchor(@NonNull String dataspaceName, @NonNull String schemaSetName, @NonNull String anchorName);
 
     /**
      * Read all anchors in the given a dataspace.
@@ -44,5 +46,6 @@
      * @param dataspaceName dataspace name
      * @return a collection of anchors
      */
-    Collection<Anchor> getAnchors(String dataspaceName);
+    @NonNull
+    Collection<Anchor> getAnchors(@NonNull String dataspaceName);
 }
diff --git a/cps-service/src/main/java/org/onap/cps/api/impl/CpsAdminServiceImpl.java b/cps-service/src/main/java/org/onap/cps/api/impl/CpsAdminServiceImpl.java
index 5d9bc01..f93a827 100644
--- a/cps-service/src/main/java/org/onap/cps/api/impl/CpsAdminServiceImpl.java
+++ b/cps-service/src/main/java/org/onap/cps/api/impl/CpsAdminServiceImpl.java
@@ -34,8 +34,8 @@
     private CpsAdminPersistenceService cpsAdminPersistenceService;
 
     @Override
-    public String createAnchor(final Anchor anchor) {
-        return cpsAdminPersistenceService.createAnchor(anchor);
+    public void createAnchor(final String dataspaceName, final String schemaSetName, final String anchorName) {
+        cpsAdminPersistenceService.createAnchor(dataspaceName, schemaSetName, anchorName);
     }
 
     @Override
diff --git a/cps-service/src/main/java/org/onap/cps/spi/CpsAdminPersistenceService.java b/cps-service/src/main/java/org/onap/cps/spi/CpsAdminPersistenceService.java
index 4e88d49..1b7ddb7 100644
--- a/cps-service/src/main/java/org/onap/cps/spi/CpsAdminPersistenceService.java
+++ b/cps-service/src/main/java/org/onap/cps/spi/CpsAdminPersistenceService.java
@@ -22,6 +22,7 @@
 package org.onap.cps.spi;
 
 import java.util.Collection;
+import org.checkerframework.checker.nullness.qual.NonNull;
 import org.onap.cps.spi.model.Anchor;
 
 /*
@@ -32,10 +33,12 @@
     /**
      * Create an Anchor.
      *
-     * @param anchor the anchorDetails object.
-     * @return the anchor name.
+     * @param dataspaceName dataspace name
+     * @param schemaSetName schema set name
+     * @param anchorName    anchor name
      */
-    String createAnchor(Anchor anchor);
+    void createAnchor(@NonNull String dataspaceName, @NonNull String schemaSetName, @NonNull String anchorName);
+
 
     /**
      * Read all anchors in the given a dataspace.
@@ -43,5 +46,7 @@
      * @param dataspaceName dataspace name
      * @return a collection of anchors
      */
-    Collection<Anchor> getAnchors(String dataspaceName);
+    @NonNull
+    Collection<Anchor> getAnchors(@NonNull String dataspaceName);
+
 }
diff --git a/cps-service/src/main/java/org/onap/cps/spi/model/Anchor.java b/cps-service/src/main/java/org/onap/cps/spi/model/Anchor.java
index cd1c774..456f733 100644
--- a/cps-service/src/main/java/org/onap/cps/spi/model/Anchor.java
+++ b/cps-service/src/main/java/org/onap/cps/spi/model/Anchor.java
@@ -21,23 +21,21 @@
 package org.onap.cps.spi.model;
 
 import java.io.Serializable;
-import java.util.Map;
-import lombok.Getter;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
 import lombok.NoArgsConstructor;
-import lombok.Setter;
 
-@Setter
-@Getter
+@Data
+@Builder
 @NoArgsConstructor
+@AllArgsConstructor
 public class Anchor implements Serializable {
 
-    // anchor will support both a single module and schema set until CPS-99 is complete
     private static final long serialVersionUID = 1464791260718603291L;
-    private String anchorName;
+
+    private String name;
     private String dataspaceName;
-    private String namespace;
-    private String revision;
-    private String moduleSetName;
-    private Map<String, String> externalReferences;
-    private String xpath;
+    private String schemaSetName;
+
 }
\ No newline at end of file
diff --git a/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsAdminServiceImplSpec.groovy b/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsAdminServiceImplSpec.groovy
index d31a2f7..9e13c77 100644
--- a/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsAdminServiceImplSpec.groovy
+++ b/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsAdminServiceImplSpec.groovy
@@ -21,55 +21,30 @@
 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
 
 class CpsAdminServiceImplSpec extends Specification {
     def mockCpsAdminPersistenceService = Mock(CpsAdminPersistenceService)
     def objectUnderTest = new CpsAdminServiceImpl()
-    def anchor = new Anchor()
 
     def setup() {
         objectUnderTest.cpsAdminPersistenceService = mockCpsAdminPersistenceService
     }
 
-    def 'Create an anchor'() {
-        given: 'that the persistence service returns the name of the anchor'
-            def anchorName = 'some anchor name'
-            mockCpsAdminPersistenceService.createAnchor(_) >> anchorName
-        expect: 'the same anchor name is returned by CPS Admin service'
-            objectUnderTest.createAnchor(anchor) == anchorName
+    def 'Create anchor method invokes persistence service'() {
+        when: 'Create anchor method is invoked'
+            objectUnderTest.createAnchor('dummyDataspace', 'dummySchemaSet', 'dummyAnchorName')
+        then: 'The persistence service method is invoked with same parameters'
+            1 * mockCpsAdminPersistenceService.createAnchor('dummyDataspace', 'dummySchemaSet', 'dummyAnchorName')
     }
 
-    def 'Create an anchor with some exception in the persistence layer'() {
-        given: 'that the persistence service throws some exception'
-            def exceptionThrownInPersistenceLayer = new RuntimeException()
-            mockCpsAdminPersistenceService.createAnchor(_) >> { throw exceptionThrownInPersistenceLayer }
-        when: 'we try to create an anchor'
-            objectUnderTest.createAnchor(anchor)
-        then: 'the same exception is thrown by the CPS Admin Service'
-            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)
+    def 'Retrieve all anchors for dataspace'() {
+        given: 'that anchor is associated with the dataspace'
+            Collection<Anchor> anchorCollection = Arrays.asList(new Anchor())
             mockCpsAdminPersistenceService.getAnchors('dummyDataspace') >> { anchorCollection }
-        expect: 'we try to retrieve an anchor, a collection of anchor is returned by the service'
+        expect: 'the collection provided by persistence service is returned as result'
             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
-    }
 }