summaryrefslogtreecommitdiffstats
path: root/cps-service/src/main
diff options
context:
space:
mode:
authorRishi.Chail <rishi.chail@est.tech>2020-11-09 03:28:44 +0000
committerRishi.Chail <rishi.chail@est.tech>2020-11-18 13:30:01 +0000
commit48830f146f6776afa180fefa101788b169bc841a (patch)
tree6154165d4a3d8f464511c39544cf62d0923964a3 /cps-service/src/main
parente40f4d2dce4c4adf57b99c3daf524b14204279b9 (diff)
VSE: Create an anchor in the given dataspace
Issue-ID: CPS-42 https://jira.onap.org/browse/CPS-42 Signed-off-by: Rishi Chail <rishi.chail@est.tech> Change-Id: If67be6f13889808da4d9fe830595766af67e4fdf
Diffstat (limited to 'cps-service/src/main')
-rwxr-xr-x[-rw-r--r--]cps-service/src/main/java/org/onap/cps/api/CpService.java25
-rwxr-xr-x[-rw-r--r--]cps-service/src/main/java/org/onap/cps/api/impl/CpServiceImpl.java22
-rwxr-xr-xcps-service/src/main/java/org/onap/cps/api/model/AnchorDetails.java42
-rw-r--r--cps-service/src/main/java/org/onap/cps/exceptions/CpsException.java3
-rw-r--r--cps-service/src/main/java/org/onap/cps/exceptions/CpsNotFoundException.java3
-rwxr-xr-xcps-service/src/main/java/org/onap/cps/spi/FragmentPersistenceService.java34
6 files changed, 113 insertions, 16 deletions
diff --git a/cps-service/src/main/java/org/onap/cps/api/CpService.java b/cps-service/src/main/java/org/onap/cps/api/CpService.java
index 4d94a46547..6b59949ca0 100644..100755
--- a/cps-service/src/main/java/org/onap/cps/api/CpService.java
+++ b/cps-service/src/main/java/org/onap/cps/api/CpService.java
@@ -21,9 +21,9 @@
package org.onap.cps.api;
import java.io.File;
-import java.io.IOException;
+import org.onap.cps.api.model.AnchorDetails;
+import org.onap.cps.exceptions.CpsValidationException;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.model.parser.api.YangParserException;
/**
* Configuration and persistency service interface which holds methods for parsing and storing yang models and data.
@@ -36,7 +36,7 @@ public interface CpService {
* @param yangModelContent the input stream
* @return the schema context
*/
- SchemaContext parseAndValidateModel(final String yangModelContent);
+ SchemaContext parseAndValidateModel(String yangModelContent);
/**
* Parse and validate a file representing a yang model to generate a schema context.
@@ -44,7 +44,7 @@ public interface CpService {
* @param yangModelFile the yang file
* @return the schema context
*/
- SchemaContext parseAndValidateModel(final File yangModelFile);
+ SchemaContext parseAndValidateModel(File yangModelFile);
/**
* Store schema context for a yang model.
@@ -52,7 +52,7 @@ public interface CpService {
* @param schemaContext the schema context
* @param dataspaceName the dataspace name
*/
- void storeSchemaContext(final SchemaContext schemaContext, final String dataspaceName);
+ void storeSchemaContext(SchemaContext schemaContext, String dataspaceName);
/**
* Store the JSON structure in the database.
@@ -60,7 +60,7 @@ public interface CpService {
* @param jsonStructure the JSON structure.
* @return entity ID.
*/
- Integer storeJsonStructure(final String jsonStructure);
+ Integer storeJsonStructure(String jsonStructure);
/**
* Read a JSON Object using the object identifier.
@@ -68,12 +68,21 @@ public interface CpService {
* @param jsonObjectId the JSON object identifier.
* @return the JSON structure.
*/
- String getJsonById(final int jsonObjectId);
+ String getJsonById(int jsonObjectId);
/**
* Delete a JSON Object using the object identifier.
*
* @param jsonObjectId the JSON object identifier.
*/
- void deleteJsonById(final int jsonObjectId);
+ void deleteJsonById(int jsonObjectId);
+
+ /**
+ * Create an anchor using provided anchorDetails object.
+ *
+ * @param anchorDetails the anchor details object.
+ * @return the anchor name.
+ * @throws CpsValidationException if input data is invalid.
+ */
+ String createAnchor(AnchorDetails anchorDetails);
}
diff --git a/cps-service/src/main/java/org/onap/cps/api/impl/CpServiceImpl.java b/cps-service/src/main/java/org/onap/cps/api/impl/CpServiceImpl.java
index c33746e861..8cdadbeb55 100644..100755
--- a/cps-service/src/main/java/org/onap/cps/api/impl/CpServiceImpl.java
+++ b/cps-service/src/main/java/org/onap/cps/api/impl/CpServiceImpl.java
@@ -26,9 +26,11 @@ import java.io.FileWriter;
import java.io.IOException;
import java.util.Optional;
import org.onap.cps.api.CpService;
+import org.onap.cps.api.model.AnchorDetails;
import org.onap.cps.exceptions.CpsException;
import org.onap.cps.exceptions.CpsValidationException;
import org.onap.cps.spi.DataPersistencyService;
+import org.onap.cps.spi.FragmentPersistenceService;
import org.onap.cps.spi.ModelPersistencyService;
import org.onap.cps.utils.YangUtils;
import org.opendaylight.yangtools.yang.common.Revision;
@@ -48,6 +50,9 @@ public class CpServiceImpl implements CpService {
@Autowired
private DataPersistencyService dataPersistencyService;
+ @Autowired
+ private FragmentPersistenceService fragmentPersistenceService;
+
@Override
public final SchemaContext parseAndValidateModel(final String yangModelContent) {
@@ -57,7 +62,7 @@ public class CpServiceImpl implements CpService {
writer.write(yangModelContent);
}
return parseAndValidateModel(tempFile);
- } catch (IOException e) {
+ } catch (final IOException e) {
throw new CpsException(e);
}
}
@@ -66,9 +71,9 @@ public class CpServiceImpl implements CpService {
public final SchemaContext parseAndValidateModel(final File yangModelFile) {
try {
return YangUtils.parseYangModelFile(yangModelFile);
- } catch (YangParserException e) {
+ } catch (final YangParserException e) {
throw new CpsValidationException("Yang file validation failed", e.getMessage());
- } catch (IOException e) {
+ } catch (final IOException e) {
throw new CpsException(e);
}
}
@@ -91,10 +96,15 @@ public class CpServiceImpl implements CpService {
@Override
public final void storeSchemaContext(final SchemaContext schemaContext, final String dataspaceName) {
for (final Module module : schemaContext.getModules()) {
- Optional<Revision> optionalRevision = module.getRevision();
- String revisionValue = optionalRevision.isPresent() ? optionalRevision.get().toString() : null;
+ final Optional<Revision> optionalRevision = module.getRevision();
+ final String revisionValue = optionalRevision.map(Object::toString).orElse(null);
modelPersistencyService.storeModule(module.getNamespace().toString(), module.toString(),
revisionValue, dataspaceName);
}
}
-}
+
+ @Override
+ public String createAnchor(AnchorDetails anchorDetails) {
+ return fragmentPersistenceService.createAnchor(anchorDetails);
+ }
+} \ No newline at end of file
diff --git a/cps-service/src/main/java/org/onap/cps/api/model/AnchorDetails.java b/cps-service/src/main/java/org/onap/cps/api/model/AnchorDetails.java
new file mode 100755
index 0000000000..576168ae75
--- /dev/null
+++ b/cps-service/src/main/java/org/onap/cps/api/model/AnchorDetails.java
@@ -0,0 +1,42 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 Nordix Foundation. 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.
+ * 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.api.model;
+
+import java.io.Serializable;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+
+@Getter
+@Setter
+@NoArgsConstructor
+public class AnchorDetails implements Serializable {
+
+ private static final long serialVersionUID = 1464791260718603291L;
+
+ private String anchorName;
+
+ private String dataspace;
+
+ private String namespace;
+
+ private String revision;
+} \ No newline at end of file
diff --git a/cps-service/src/main/java/org/onap/cps/exceptions/CpsException.java b/cps-service/src/main/java/org/onap/cps/exceptions/CpsException.java
index b54453cd90..4dd19dd82b 100644
--- a/cps-service/src/main/java/org/onap/cps/exceptions/CpsException.java
+++ b/cps-service/src/main/java/org/onap/cps/exceptions/CpsException.java
@@ -20,13 +20,14 @@
package org.onap.cps.exceptions;
import lombok.Getter;
-import org.springframework.core.NestedExceptionUtils;
/**
* CP Service exception.
*/
public class CpsException extends RuntimeException {
+ private static final long serialVersionUID = 5573438585188332404L;
+
@Getter
String details;
diff --git a/cps-service/src/main/java/org/onap/cps/exceptions/CpsNotFoundException.java b/cps-service/src/main/java/org/onap/cps/exceptions/CpsNotFoundException.java
index f44fe806cf..4613da8f23 100644
--- a/cps-service/src/main/java/org/onap/cps/exceptions/CpsNotFoundException.java
+++ b/cps-service/src/main/java/org/onap/cps/exceptions/CpsNotFoundException.java
@@ -19,13 +19,14 @@
package org.onap.cps.exceptions;
-import lombok.Getter;
/**
* CP Service exception. Indicates the requested data being absent.
*/
public class CpsNotFoundException extends CpsException {
+ private static final long serialVersionUID = -1852996415384288431L;
+
/**
* Constructor.
*
diff --git a/cps-service/src/main/java/org/onap/cps/spi/FragmentPersistenceService.java b/cps-service/src/main/java/org/onap/cps/spi/FragmentPersistenceService.java
new file mode 100755
index 0000000000..48dbb0cc25
--- /dev/null
+++ b/cps-service/src/main/java/org/onap/cps/spi/FragmentPersistenceService.java
@@ -0,0 +1,34 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 Nordix Foundation. 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.
+ * 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;
+
+import org.onap.cps.api.model.AnchorDetails;
+
+public interface FragmentPersistenceService {
+
+ /**
+ * Create an Anchor.
+ *
+ * @param anchorDetails the anchorDetails object.
+ * @return the anchor name.
+ */
+ String createAnchor(AnchorDetails anchorDetails);
+}