summaryrefslogtreecommitdiffstats
path: root/cps-ri/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'cps-ri/src/main')
-rwxr-xr-xcps-ri/src/main/java/org/onap/cps/spi/entities/Fragment.java4
-rw-r--r--cps-ri/src/main/java/org/onap/cps/spi/impl/CpsAdminPersistenceServiceImpl.java43
-rwxr-xr-xcps-ri/src/main/java/org/onap/cps/spi/repository/FragmentRepository.java4
-rw-r--r--cps-ri/src/main/java/org/onap/cps/spi/repository/SchemaSetRepository.java13
-rwxr-xr-xcps-ri/src/main/resources/schema.sql4
5 files changed, 38 insertions, 30 deletions
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 7afdb3e092..2dbd6e98fe 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 @@ public class Fragment implements Serializable {
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 48e7303593..5093ba5899 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 @@ public class CpsAdminPersistenceServiceImpl implements CpsAdminPersistenceServic
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 class CpsAdminPersistenceServiceImpl implements CpsAdminPersistenceServic
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 b1a8992370..2ee76cc126 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 @@ import org.springframework.stereotype.Repository;
@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 035c831f2f..9b9d70625c 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 @@ public interface SchemaSetRepository extends JpaRepository<SchemaSet, Integer> {
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 2dce470ae1..58b3c63c82 100755
--- a/cps-ri/src/main/resources/schema.sql
+++ b/cps-ri/src/main/resources/schema.sql
@@ -61,7 +61,7 @@ CREATE TABLE IF NOT EXISTS FRAGMENT
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 TABLE IF NOT EXISTS RELATION
);
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) ;