\r
@OneToOne(fetch = FetchType.LAZY)\r
@JoinColumn(name = "module_id")\r
- private ModuleEntity module;\r
+ private Module module;\r
}\r
package org.onap.cps.spi.entities;
+import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
@AllArgsConstructor
@NoArgsConstructor
@Table(name = "module")
-public class ModuleEntity {
+public class Module implements Serializable {
+
+ private static final long serialVersionUID = -748666970938314895L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
* @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) {
+ public Module(String namespace, String moduleContent, String revision, Dataspace dataspace) {
this.namespace = namespace;
this.moduleContent = moduleContent;
this.revision = revision;
package org.onap.cps.spi.impl;
-import org.onap.cps.spi.DataPersistencyService;
+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;
@Component
-public class DataPersistencyServiceImpl implements DataPersistencyService {
+public class DataPersistenceServiceImpl implements DataPersistenceService {
@Autowired
private DataRepository dataRepository;
import org.onap.cps.spi.FragmentPersistenceService;\r
import org.onap.cps.spi.entities.Dataspace;\r
import org.onap.cps.spi.entities.Fragment;\r
-import org.onap.cps.spi.entities.ModuleEntity;\r
+import org.onap.cps.spi.entities.Module;\r
import org.onap.cps.spi.repository.DataspaceRepository;\r
import org.onap.cps.spi.repository.FragmentRepository;\r
import org.onap.cps.spi.repository.ModuleRepository;\r
public String createAnchor(final AnchorDetails anchorDetails) {\r
try {\r
final Dataspace dataspace = dataspaceRepository.getByName(anchorDetails.getDataspace());\r
- final ModuleEntity moduleEntity =\r
+ final Module module =\r
moduleRepository.getByDataspaceAndNamespaceAndRevision(dataspace,\r
anchorDetails.getNamespace(), anchorDetails.getRevision());\r
\r
final Fragment fragment = Fragment.builder().xpath(anchorDetails.getAnchorName())\r
.anchorName(anchorDetails.getAnchorName())\r
- .dataspace(dataspace).module(moduleEntity).build();\r
+ .dataspace(dataspace).module(module).build();\r
\r
fragmentRepository.save(fragment);\r
return anchorDetails.getAnchorName();\r
package org.onap.cps.spi.impl;
-import org.onap.cps.spi.ModelPersistencyService;
+import org.onap.cps.spi.ModelPersistenceService;
import org.onap.cps.spi.entities.Dataspace;
-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.ModuleRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
-public class ModelPersistencyServiceImpl implements ModelPersistencyService {
+public class ModelPersistenceServiceImpl implements ModelPersistenceService {
@Autowired
private ModuleRepository moduleRepository;
dataspaceRepository.save(dataspace);
}
dataspace.setId(dataspaceRepository.getByName(dataspaceName).getId());
- final ModuleEntity moduleEntity = new ModuleEntity(namespace, moduleContent, revision, dataspace);
- moduleRepository.save(moduleEntity);
+ final Module module = new Module(namespace, moduleContent, revision, dataspace);
+ moduleRepository.save(module);
}
-}
+}
\ No newline at end of file
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<ModuleEntity, Integer> {
+public interface ModuleRepository extends JpaRepository<Module, Integer> {
- Optional<ModuleEntity> findByDataspaceAndNamespaceAndRevision(@NotNull Dataspace dataspace,
+ Optional<Module> 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)
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.DataPersistenceService;
import org.onap.cps.spi.FragmentPersistenceService;
-import org.onap.cps.spi.ModelPersistencyService;
+import org.onap.cps.spi.ModelPersistenceService;
import org.onap.cps.utils.YangUtils;
import org.opendaylight.yangtools.yang.common.Revision;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
-
@Component
public class CpServiceImpl implements CpService {
@Autowired
- private ModelPersistencyService modelPersistencyService;
+ private ModelPersistenceService modelPersistenceService;
@Autowired
- private DataPersistencyService dataPersistencyService;
+ private DataPersistenceService dataPersistenceService;
@Autowired
private FragmentPersistenceService fragmentPersistenceService;
@Override
public final Integer storeJsonStructure(final String jsonStructure) {
- return dataPersistencyService.storeJsonStructure(jsonStructure);
+ return dataPersistenceService.storeJsonStructure(jsonStructure);
}
@Override
public final String getJsonById(final int jsonObjectId) {
- return dataPersistencyService.getJsonById(jsonObjectId);
+ return dataPersistenceService.getJsonById(jsonObjectId);
}
@Override
public void deleteJsonById(int jsonObjectId) {
- dataPersistencyService.deleteJsonById(jsonObjectId);
+ dataPersistenceService.deleteJsonById(jsonObjectId);
}
@Override
for (final Module module : schemaContext.getModules()) {
final Optional<Revision> optionalRevision = module.getRevision();
final String revisionValue = optionalRevision.map(Object::toString).orElse(null);
- modelPersistencyService.storeModule(module.getNamespace().toString(), module.toString(),
+ modelPersistenceService.storeModule(module.getNamespace().toString(), module.toString(),
revisionValue, dataspaceName);
}
}
/**
* Defines methods to access and manipulate data using the chosen database solution.
*/
-public interface DataPersistencyService {
+public interface DataPersistenceService {
/**
* Store the JSON structure in the database.
/**
* Defines methods to access and manipulate data using the chosen database solution.
*/
-public interface ModelPersistencyService {
+public interface ModelPersistenceService {
/**
* Store the module from a yang model in the database.
import org.onap.cps.TestUtils
import org.onap.cps.api.model.AnchorDetails
-import org.onap.cps.exceptions.CpsNotFoundException
import org.onap.cps.exceptions.CpsValidationException
-import org.onap.cps.spi.DataPersistencyService
+import org.onap.cps.spi.DataPersistenceService
import org.onap.cps.spi.FragmentPersistenceService
import org.opendaylight.yangtools.yang.common.Revision
import org.opendaylight.yangtools.yang.model.api.SchemaContext
class CpServiceImplSpec extends Specification {
- def mockDataPersistencyService = Mock(DataPersistencyService)
+ def mockDataPersistenceService = Mock(DataPersistenceService)
def mockFragmentPersistenceService = Mock(FragmentPersistenceService)
def objectUnderTest = new CpServiceImpl()
def setup() {
- objectUnderTest.dataPersistencyService = mockDataPersistencyService
+ objectUnderTest.dataPersistenceService = mockDataPersistenceService
objectUnderTest.fragmentPersistenceService = mockFragmentPersistenceService
}
def 'Cps Service provides to its client the id assigned by the system when storing a data structure'() {
- given: 'that data persistency service is giving id 123 to a data structure it is asked to store'
- mockDataPersistencyService.storeJsonStructure(_) >> 123
+ given: 'that data persistence service is giving id 123 to a data structure it is asked to store'
+ mockDataPersistenceService.storeJsonStructure(_) >> 123
expect: 'Cps service returns the same id when storing data structure'
objectUnderTest.storeJsonStructure('') == 123
}
def 'Read a JSON object with a valid identifier'(){
given: 'that the data persistence service returns a JSON structure for identifier 1'
- mockDataPersistencyService.getJsonById(1) >> '{name : hello}'
+ mockDataPersistenceService.getJsonById(1) >> '{name : hello}'
expect: 'that the same JSON structure is returned by CPS'
objectUnderTest.getJsonById(1) == '{name : hello}'
}
def 'Read a JSON object with an identifier that does not exist'(){
given: 'that the data persistence service throws an exception'
def exceptionThrownByPersistenceService = new IllegalStateException()
- mockDataPersistencyService.getJsonById(_) >> {throw exceptionThrownByPersistenceService}
+ mockDataPersistenceService.getJsonById(_) >> {throw exceptionThrownByPersistenceService}
when: 'we try to get the JSON structure'
objectUnderTest.getJsonById(1);
then: 'the same exception is thrown by CPS'
def 'Delete a JSON object with a valid identifier'(){
given: 'that the data persistence service can delete a JSON structure for identifier 1'
- mockDataPersistencyService.deleteJsonById(1)
+ mockDataPersistenceService.deleteJsonById(1)
expect: 'No exception is thrown when we delete a JSON structure with identifier 1'
objectUnderTest.deleteJsonById(1)
}
def 'Delete a JSON object with an identifier that does not exist'(){
given: 'that the data persistence service throws an exception'
- mockDataPersistencyService.deleteJsonById(_) >> {throw new IllegalStateException()}
+ mockDataPersistenceService.deleteJsonById(_) >> {throw new IllegalStateException()}
when: 'we try to delete a JSON structure'
objectUnderTest.deleteJsonById(100);
then: 'the same exception is thrown by CPS'