diff options
Diffstat (limited to 'cps-service/src/main/java/org/onap')
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 4d94a4654..6b59949ca 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 c33746e86..8cdadbeb5 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 000000000..576168ae7 --- /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 b54453cd9..4dd19dd82 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 f44fe806c..4613da8f2 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 000000000..48dbb0cc2 --- /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);
+}
|