diff options
author | Jessica Wagantall <jwagantall@linuxfoundation.org> | 2020-11-06 10:20:47 -0800 |
---|---|---|
committer | Jessica Wagantall <jwagantall@linuxfoundation.org> | 2020-11-06 10:20:47 -0800 |
commit | 7f6616e5d7e2759bc21fad0e363e4e356a8ec8f9 (patch) | |
tree | a3f327d7687ff738f1c6e5fd8eb86d457d33a28e /cps-ri/src/main/java/org/onap | |
parent | 1d05f0ebdf4a0e5107b2dd352f5303dc9dad907c (diff) |
Move cps files to root dir
Issue-ID: CIMAN-33
Signed-off-by: Jessica Wagantall <jwagantall@linuxfoundation.org>
Diffstat (limited to 'cps-ri/src/main/java/org/onap')
9 files changed, 491 insertions, 0 deletions
diff --git a/cps-ri/src/main/java/org/onap/cps/spi/entities/Dataspace.java b/cps-ri/src/main/java/org/onap/cps/spi/entities/Dataspace.java new file mode 100644 index 0000000000..627a14467d --- /dev/null +++ b/cps-ri/src/main/java/org/onap/cps/spi/entities/Dataspace.java @@ -0,0 +1,62 @@ +/* + * ============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.entities; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; +import javax.validation.constraints.NotNull; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + + +/** + * Entity to store a dataspace. + */ +@Getter +@Setter +@Entity +@AllArgsConstructor +@NoArgsConstructor +@Table(name = "dataspace") +public class Dataspace { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Integer id; + + @NotNull + @Column(columnDefinition = "text") + private String name; + + /** + * Initialize a Dataspace . + * + * @param name the Dataspace name. + */ + public Dataspace(String name) { + this.name = name; + } +}
\ No newline at end of file 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 new file mode 100644 index 0000000000..12422dc5f6 --- /dev/null +++ b/cps-ri/src/main/java/org/onap/cps/spi/entities/Fragment.java @@ -0,0 +1,76 @@ +/*-
+ * ============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.entities;
+
+import com.vladmihalcea.hibernate.type.json.JsonBinaryType;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+import javax.persistence.OneToOne;
+import javax.validation.constraints.NotNull;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+import org.hibernate.annotations.Type;
+import org.hibernate.annotations.TypeDef;
+import org.hibernate.annotations.TypeDefs;
+
+/**
+ * Entity to store a fragment.
+ */
+@Getter
+@Setter
+@Entity
+@AllArgsConstructor
+@NoArgsConstructor
+@TypeDefs({@TypeDef(name = "jsonb", typeClass = JsonBinaryType.class)})
+public class Fragment {
+
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ private Long id;
+
+ @NotNull
+ @Column(columnDefinition = "text")
+ private String xpath;
+
+ @Type(type = "jsonb")
+ @Column(columnDefinition = "jsonb")
+ private String attributes;
+
+ @ManyToOne(fetch = FetchType.LAZY)
+ @JoinColumn(name = "dataspace_id")
+ private Dataspace dataspace;
+
+ @OneToOne(fetch = FetchType.LAZY)
+ @JoinColumn(name = "anchor_id")
+ private Fragment anchorFragment;
+
+ @OneToOne(fetch = FetchType.LAZY)
+ @JoinColumn(name = "parent_id")
+ private Fragment parentFragment;
+}
diff --git a/cps-ri/src/main/java/org/onap/cps/spi/entities/JsonDataEntity.java b/cps-ri/src/main/java/org/onap/cps/spi/entities/JsonDataEntity.java new file mode 100644 index 0000000000..413362e384 --- /dev/null +++ b/cps-ri/src/main/java/org/onap/cps/spi/entities/JsonDataEntity.java @@ -0,0 +1,54 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation + * ================================================================================ + * 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.entities; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +/** + * Entity to store a JSON data structure. + */ +@Getter +@Setter +@Entity +@AllArgsConstructor +@NoArgsConstructor +@Table(name = "JsonData") +public class JsonDataEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Integer id; + + @Column + private String jsonStructure; + + public JsonDataEntity(String jsonStructure) { + this.jsonStructure = jsonStructure; + } +} diff --git a/cps-ri/src/main/java/org/onap/cps/spi/entities/ModuleEntity.java b/cps-ri/src/main/java/org/onap/cps/spi/entities/ModuleEntity.java new file mode 100644 index 0000000000..d2130aeec1 --- /dev/null +++ b/cps-ri/src/main/java/org/onap/cps/spi/entities/ModuleEntity.java @@ -0,0 +1,84 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation + * 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. + * 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.entities; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Table; +import javax.validation.constraints.NotNull; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + + +/** + * Entity to store a yang module. + */ +@Getter +@Setter +@Entity +@AllArgsConstructor +@NoArgsConstructor +@Table(name = "module") +public class ModuleEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Integer id; + + @NotNull + @Column + private String moduleContent; + + @NotNull + @Column + private String revision; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "dataspace_id", referencedColumnName = "ID") + private Dataspace dataspace; + + @NotNull + @Column + private String namespace; + + /** + * Initialize a module entity. + * + * @param namespace the module namespace. + * @param moduleContent the module content. + * @param revision the revision number of the module. + * @param dataspace the dataspace related to the module. + */ + public ModuleEntity(String namespace, String moduleContent, String revision, Dataspace dataspace) { + this.namespace = namespace; + this.moduleContent = moduleContent; + this.revision = revision; + this.dataspace = dataspace; + } +}
\ No newline at end of file diff --git a/cps-ri/src/main/java/org/onap/cps/spi/impl/DataPersistencyServiceImpl.java b/cps-ri/src/main/java/org/onap/cps/spi/impl/DataPersistencyServiceImpl.java new file mode 100644 index 0000000000..2b4f1357de --- /dev/null +++ b/cps-ri/src/main/java/org/onap/cps/spi/impl/DataPersistencyServiceImpl.java @@ -0,0 +1,69 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation + * ================================================================================ + * 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 org.onap.cps.spi.DataPersistencyService; +import org.onap.cps.spi.entities.JsonDataEntity; +import org.onap.cps.spi.repository.DataRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + + +@Component +public class DataPersistencyServiceImpl implements DataPersistencyService { + + @Autowired + private DataRepository dataRepository; + + /** + * Method to store a JSON data structure in the database. + * + * @param jsonStructure the JSON data structure. + * @return the entity identifier. + */ + @Override + public final Integer storeJsonStructure(final String jsonStructure) { + final JsonDataEntity jsonDataEntity = new JsonDataEntity(jsonStructure); + dataRepository.save(jsonDataEntity); + return jsonDataEntity.getId(); + } + + /* + * Return the JSON structure from the database using the object identifier. + * + * @param jsonStructureId the JSON object identifier. + * + * @return the JSON structure from the database as a string. + */ + @Override + public final String getJsonById(final int jsonStructureId) { + return dataRepository.getOne(jsonStructureId).getJsonStructure(); + } + + /** + * Delete the JSON structure from the database using the object identifier. + * + * @param jsonStructureId the JSON object identifier. + */ + @Override + public void deleteJsonById(int jsonStructureId) { + dataRepository.deleteById(jsonStructureId); + } +} diff --git a/cps-ri/src/main/java/org/onap/cps/spi/impl/ModelPersistencyServiceImpl.java b/cps-ri/src/main/java/org/onap/cps/spi/impl/ModelPersistencyServiceImpl.java new file mode 100644 index 0000000000..01c7a7b53b --- /dev/null +++ b/cps-ri/src/main/java/org/onap/cps/spi/impl/ModelPersistencyServiceImpl.java @@ -0,0 +1,57 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation + * 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. + * 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 org.onap.cps.spi.ModelPersistencyService; +import org.onap.cps.spi.entities.Dataspace; +import org.onap.cps.spi.entities.ModuleEntity; +import org.onap.cps.spi.repository.DataspaceRepository; +import org.onap.cps.spi.repository.ModuleRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component +public class ModelPersistencyServiceImpl implements ModelPersistencyService { + + + private final ModuleRepository moduleRepository; + + private final DataspaceRepository dataspaceRepository; + + @Autowired + public ModelPersistencyServiceImpl(final ModuleRepository moduleRepository, + final DataspaceRepository dataspaceRepository) { + this.moduleRepository = moduleRepository; + this.dataspaceRepository = dataspaceRepository; + } + + @Override + public void storeModule(final String namespace, final String moduleContent, final String revision, + final String dataspaceName) { + final Dataspace dataspace = new Dataspace(dataspaceName); + if (Boolean.FALSE.equals(dataspaceRepository.existsByName(dataspaceName))) { + dataspaceRepository.save(dataspace); + } + dataspace.setId(dataspaceRepository.findByName(dataspaceName).getId()); + final ModuleEntity moduleEntity = new ModuleEntity(namespace, moduleContent, revision, dataspace); + moduleRepository.save(moduleEntity); + } +} diff --git a/cps-ri/src/main/java/org/onap/cps/spi/repository/DataRepository.java b/cps-ri/src/main/java/org/onap/cps/spi/repository/DataRepository.java new file mode 100644 index 0000000000..f3dd586007 --- /dev/null +++ b/cps-ri/src/main/java/org/onap/cps/spi/repository/DataRepository.java @@ -0,0 +1,28 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation + * ================================================================================ + * 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.repository; + +import org.onap.cps.spi.entities.JsonDataEntity; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface DataRepository extends JpaRepository<JsonDataEntity, Integer> { +}
\ No newline at end of file diff --git a/cps-ri/src/main/java/org/onap/cps/spi/repository/DataspaceRepository.java b/cps-ri/src/main/java/org/onap/cps/spi/repository/DataspaceRepository.java new file mode 100644 index 0000000000..46a5266103 --- /dev/null +++ b/cps-ri/src/main/java/org/onap/cps/spi/repository/DataspaceRepository.java @@ -0,0 +1,32 @@ +/* + * ============LICENSE_START======================================================= + * 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. + * 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.repository; + + +import org.onap.cps.spi.entities.Dataspace; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface DataspaceRepository extends JpaRepository<Dataspace, Integer> { + Boolean existsByName(String name); //Checks if there are any records by name() + + Dataspace findByName(String name); +}
\ No newline at end of file diff --git a/cps-ri/src/main/java/org/onap/cps/spi/repository/ModuleRepository.java b/cps-ri/src/main/java/org/onap/cps/spi/repository/ModuleRepository.java new file mode 100644 index 0000000000..f9078d7c14 --- /dev/null +++ b/cps-ri/src/main/java/org/onap/cps/spi/repository/ModuleRepository.java @@ -0,0 +1,29 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation + * ================================================================================ + * 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.repository; + + +import org.onap.cps.spi.entities.ModuleEntity; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface ModuleRepository extends JpaRepository<ModuleEntity, Integer> { +}
\ No newline at end of file |