From 5a1b4b66b68776e0a13c98d2f41fe39f957fdf4b Mon Sep 17 00:00:00 2001 From: "Rishi.Chail" Date: Thu, 19 Nov 2020 06:18:26 +0000 Subject: Fix name inconsistency of classes Issue-ID: CPS-90 Signed-off-by: Rishi.Chail Change-Id: I13196084a6ff4a7c4cd23e9e8ba58fa8fffd43bf --- .../java/org/onap/cps/spi/entities/Fragment.java | 2 +- .../java/org/onap/cps/spi/entities/Module.java | 87 ++++++++++++++++++++++ .../org/onap/cps/spi/entities/ModuleEntity.java | 84 --------------------- .../cps/spi/impl/DataPersistenceServiceImpl.java | 69 +++++++++++++++++ .../cps/spi/impl/DataPersistencyServiceImpl.java | 69 ----------------- .../spi/impl/FragmentPersistenceServiceImpl.java | 6 +- .../cps/spi/impl/ModelPersistenceServiceImpl.java | 51 +++++++++++++ .../cps/spi/impl/ModelPersistencyServiceImpl.java | 51 ------------- .../onap/cps/spi/repository/ModuleRepository.java | 14 ++-- 9 files changed, 218 insertions(+), 215 deletions(-) mode change 100644 => 100755 cps-ri/src/main/java/org/onap/cps/spi/entities/Fragment.java create mode 100755 cps-ri/src/main/java/org/onap/cps/spi/entities/Module.java delete mode 100644 cps-ri/src/main/java/org/onap/cps/spi/entities/ModuleEntity.java create mode 100755 cps-ri/src/main/java/org/onap/cps/spi/impl/DataPersistenceServiceImpl.java delete mode 100644 cps-ri/src/main/java/org/onap/cps/spi/impl/DataPersistencyServiceImpl.java create mode 100755 cps-ri/src/main/java/org/onap/cps/spi/impl/ModelPersistenceServiceImpl.java delete mode 100755 cps-ri/src/main/java/org/onap/cps/spi/impl/ModelPersistencyServiceImpl.java (limited to 'cps-ri/src/main/java/org') 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 old mode 100644 new mode 100755 index 4d8a90b73..7afdb3e09 --- 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 @@ -85,5 +85,5 @@ public class Fragment implements Serializable { @OneToOne(fetch = FetchType.LAZY) @JoinColumn(name = "module_id") - private ModuleEntity module; + private Module module; } diff --git a/cps-ri/src/main/java/org/onap/cps/spi/entities/Module.java b/cps-ri/src/main/java/org/onap/cps/spi/entities/Module.java new file mode 100755 index 000000000..ef6895c7d --- /dev/null +++ b/cps-ri/src/main/java/org/onap/cps/spi/entities/Module.java @@ -0,0 +1,87 @@ +/* + * ============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 java.io.Serializable; +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 Module implements Serializable { + + private static final long serialVersionUID = -748666970938314895L; + + @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 Module(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/entities/ModuleEntity.java b/cps-ri/src/main/java/org/onap/cps/spi/entities/ModuleEntity.java deleted file mode 100644 index d2130aeec..000000000 --- a/cps-ri/src/main/java/org/onap/cps/spi/entities/ModuleEntity.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * ============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/DataPersistenceServiceImpl.java b/cps-ri/src/main/java/org/onap/cps/spi/impl/DataPersistenceServiceImpl.java new file mode 100755 index 000000000..9ed111271 --- /dev/null +++ b/cps-ri/src/main/java/org/onap/cps/spi/impl/DataPersistenceServiceImpl.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.DataPersistenceService; +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 DataPersistenceServiceImpl implements DataPersistenceService { + + @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/DataPersistencyServiceImpl.java b/cps-ri/src/main/java/org/onap/cps/spi/impl/DataPersistencyServiceImpl.java deleted file mode 100644 index 2b4f1357d..000000000 --- a/cps-ri/src/main/java/org/onap/cps/spi/impl/DataPersistencyServiceImpl.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * ============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/FragmentPersistenceServiceImpl.java b/cps-ri/src/main/java/org/onap/cps/spi/impl/FragmentPersistenceServiceImpl.java index 47d98c92b..0ecf72d77 100755 --- a/cps-ri/src/main/java/org/onap/cps/spi/impl/FragmentPersistenceServiceImpl.java +++ b/cps-ri/src/main/java/org/onap/cps/spi/impl/FragmentPersistenceServiceImpl.java @@ -26,7 +26,7 @@ import org.onap.cps.exceptions.CpsValidationException; import org.onap.cps.spi.FragmentPersistenceService; import org.onap.cps.spi.entities.Dataspace; import org.onap.cps.spi.entities.Fragment; -import org.onap.cps.spi.entities.ModuleEntity; +import org.onap.cps.spi.entities.Module; import org.onap.cps.spi.repository.DataspaceRepository; import org.onap.cps.spi.repository.FragmentRepository; import org.onap.cps.spi.repository.ModuleRepository; @@ -50,13 +50,13 @@ public class FragmentPersistenceServiceImpl implements FragmentPersistenceServic public String createAnchor(final AnchorDetails anchorDetails) { try { final Dataspace dataspace = dataspaceRepository.getByName(anchorDetails.getDataspace()); - final ModuleEntity moduleEntity = + final Module module = moduleRepository.getByDataspaceAndNamespaceAndRevision(dataspace, anchorDetails.getNamespace(), anchorDetails.getRevision()); final Fragment fragment = Fragment.builder().xpath(anchorDetails.getAnchorName()) .anchorName(anchorDetails.getAnchorName()) - .dataspace(dataspace).module(moduleEntity).build(); + .dataspace(dataspace).module(module).build(); fragmentRepository.save(fragment); return anchorDetails.getAnchorName(); diff --git a/cps-ri/src/main/java/org/onap/cps/spi/impl/ModelPersistenceServiceImpl.java b/cps-ri/src/main/java/org/onap/cps/spi/impl/ModelPersistenceServiceImpl.java new file mode 100755 index 000000000..a54e50646 --- /dev/null +++ b/cps-ri/src/main/java/org/onap/cps/spi/impl/ModelPersistenceServiceImpl.java @@ -0,0 +1,51 @@ +/* + * ============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.ModelPersistenceService; +import org.onap.cps.spi.entities.Dataspace; +import org.onap.cps.spi.entities.Module; +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 ModelPersistenceServiceImpl implements ModelPersistenceService { + + @Autowired + private ModuleRepository moduleRepository; + + @Autowired + private 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.getByName(dataspaceName).getId()); + final Module module = new Module(namespace, moduleContent, revision, dataspace); + moduleRepository.save(module); + } +} \ No newline at end of file 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 deleted file mode 100755 index 56bba04b7..000000000 --- a/cps-ri/src/main/java/org/onap/cps/spi/impl/ModelPersistencyServiceImpl.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * ============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 { - - @Autowired - private ModuleRepository moduleRepository; - - @Autowired - private 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.getByName(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/ModuleRepository.java b/cps-ri/src/main/java/org/onap/cps/spi/repository/ModuleRepository.java index fe27c8ec3..d3a8bc1f0 100755 --- 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 @@ -24,27 +24,27 @@ import java.util.Optional; import javax.validation.constraints.NotNull; import org.onap.cps.exceptions.CpsNotFoundException; import org.onap.cps.spi.entities.Dataspace; -import org.onap.cps.spi.entities.ModuleEntity; +import org.onap.cps.spi.entities.Module; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; @Repository -public interface ModuleRepository extends JpaRepository { +public interface ModuleRepository extends JpaRepository { - Optional findByDataspaceAndNamespaceAndRevision(@NotNull Dataspace dataspace, + Optional findByDataspaceAndNamespaceAndRevision(@NotNull Dataspace dataspace, @NotNull String namespace, @NotNull String revision); /** - * This method gets a ModuleEntity by dataspace, namespace and revision. + * This method gets a Module by dataspace, namespace and revision. * * @param dataspace the dataspace * @param namespace the namespace * @param revision the revision - * @return the ModuleEntity - * @throws CpsNotFoundException if ModuleEntity not found + * @return the Module + * @throws CpsNotFoundException if Module not found */ - default ModuleEntity getByDataspaceAndNamespaceAndRevision(@NotNull Dataspace dataspace, @NotNull String namespace, + default Module getByDataspaceAndNamespaceAndRevision(@NotNull Dataspace dataspace, @NotNull String namespace, @NotNull String revision) { return findByDataspaceAndNamespaceAndRevision(dataspace, namespace, revision) -- cgit 1.2.3-korg