summaryrefslogtreecommitdiffstats
path: root/ms/controllerblueprints/modules/db-resources
diff options
context:
space:
mode:
Diffstat (limited to 'ms/controllerblueprints/modules/db-resources')
-rw-r--r--ms/controllerblueprints/modules/db-resources/pom.xml47
-rw-r--r--ms/controllerblueprints/modules/db-resources/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/db/resources/BlueprintCatalogServiceImpl.kt82
-rw-r--r--ms/controllerblueprints/modules/db-resources/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/db/resources/repository/ModelContentRepository.kt93
-rw-r--r--ms/controllerblueprints/modules/db-resources/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/db/resources/repository/ModelRepository.kt88
4 files changed, 310 insertions, 0 deletions
diff --git a/ms/controllerblueprints/modules/db-resources/pom.xml b/ms/controllerblueprints/modules/db-resources/pom.xml
new file mode 100644
index 000000000..69e322e40
--- /dev/null
+++ b/ms/controllerblueprints/modules/db-resources/pom.xml
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Copyright © 2017-2018 AT&T Intellectual Property.
+ ~
+ ~ Modifications Copyright © 2018 IBM.
+ ~
+ ~ 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.
+ -->
+
+<project
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
+ xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.onap.ccsdk.apps.controllerblueprints</groupId>
+ <artifactId>modules</artifactId>
+ <version>0.4.0-SNAPSHOT</version>
+ </parent>
+ <artifactId>db-resources</artifactId>
+ <name>Controller Blueprints DB Resources</name>
+
+ <properties>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.onap.ccsdk.apps.controllerblueprints</groupId>
+ <artifactId>core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-data-jpa</artifactId>
+ </dependency>
+ </dependencies>
+</project>
+
diff --git a/ms/controllerblueprints/modules/db-resources/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/db/resources/BlueprintCatalogServiceImpl.kt b/ms/controllerblueprints/modules/db-resources/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/db/resources/BlueprintCatalogServiceImpl.kt
new file mode 100644
index 000000000..881e3bc40
--- /dev/null
+++ b/ms/controllerblueprints/modules/db-resources/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/db/resources/BlueprintCatalogServiceImpl.kt
@@ -0,0 +1,82 @@
+/*
+ * Copyright © 2017-2018 AT&T Intellectual Property.
+ * Modifications Copyright © 2019 Bell Canada.
+ *
+ * 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.
+ */
+
+package org.onap.ccsdk.apps.controllerblueprints.db.resources
+
+import org.onap.ccsdk.apps.controllerblueprints.core.config.BluePrintLoadConfiguration
+import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintCatalogService
+import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintArchiveUtils
+import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintFileUtils
+import java.io.File
+import javax.persistence.MappedSuperclass
+
+@MappedSuperclass
+abstract class BlueprintCatalogServiceImpl(private val bluePrintLoadConfiguration: BluePrintLoadConfiguration) : BluePrintCatalogService {
+
+ override fun uploadToDataBase(file: String, validate: Boolean): String {
+ // The file name provided here is unique as we transform to UUID before storing
+ val blueprintFile = File(file)
+ val fileName = blueprintFile.name
+ val id = BluePrintFileUtils.stripFileExtension(fileName)
+ // If the file is directory
+ if (blueprintFile.isDirectory) {
+
+ val zipFile = File("${bluePrintLoadConfiguration.blueprintArchivePath}/$fileName")
+ // zip the directory
+ BluePrintArchiveUtils.compress(blueprintFile, zipFile, true)
+
+ // Upload to the Data Base
+ saveToDataBase(blueprintFile, id, zipFile)
+
+ // After Upload to Database delete the zip file
+ zipFile.delete()
+
+ } else {
+ // If the file is ZIP
+ // unzip the CBA file to validate before store in database
+ val targetDir = "${bluePrintLoadConfiguration.blueprintDeployPath}/$id/"
+ val extractedDirectory = BluePrintArchiveUtils.deCompress(blueprintFile, targetDir)
+
+ // Upload to the Data Base
+ saveToDataBase(extractedDirectory, id, blueprintFile)
+
+ // After Upload to Database delete the zip file
+ blueprintFile.delete()
+ extractedDirectory.delete()
+ }
+
+ return id
+ }
+
+ override fun downloadFromDataBase(name: String, version: String, path: String): String {
+ // If path ends with zip, then compress otherwise download as extracted folder
+
+ TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
+ }
+
+ override fun downloadFromDataBase(uuid: String, path: String): String {
+ TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
+ }
+
+ override fun prepareBluePrint(name: String, version: String): String {
+ val preparedPath = "${bluePrintLoadConfiguration.blueprintDeployPath}/$name/$version"
+ downloadFromDataBase(name, version, preparedPath)
+ return preparedPath
+ }
+
+ abstract fun saveToDataBase(extractedDirectory: File, id: String, archiveFile: File, checkValidity: Boolean? = false)
+} \ No newline at end of file
diff --git a/ms/controllerblueprints/modules/db-resources/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/db/resources/repository/ModelContentRepository.kt b/ms/controllerblueprints/modules/db-resources/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/db/resources/repository/ModelContentRepository.kt
new file mode 100644
index 000000000..4965677ef
--- /dev/null
+++ b/ms/controllerblueprints/modules/db-resources/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/db/resources/repository/ModelContentRepository.kt
@@ -0,0 +1,93 @@
+/*
+ * Copyright © 2017-2018 AT&T Intellectual Property.
+ * Modifications Copyright © 2019 Bell Canada.
+ *
+ * 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.
+ */
+
+package org.onap.ccsdk.apps.controllerblueprints.db.resources.repository
+
+import org.jetbrains.annotations.NotNull
+import java.util.Optional
+import org.springframework.data.jpa.repository.JpaRepository
+import org.springframework.data.repository.NoRepositoryBean
+
+/**
+ * @param <T> Model
+ * @param <B> ModelContent
+ */
+@NoRepositoryBean
+interface ModelContentRepository<T, B> : JpaRepository<B, String> {
+
+ /**
+ * This is a findById method
+ *
+ * @param id id
+ * @return Optional<T>
+ */
+ @NotNull
+ override fun findById(@NotNull id: String): Optional<B>
+
+ /**
+ * This is a findTopByBlueprintModelAndContentType method
+ *
+ * @param blueprintModel blueprintModel
+ * @param contentType contentType
+ * @return Optional<B>
+ */
+ fun findTopByBlueprintModelAndContentType(blueprintModel: T,
+ contentType: String): Optional<B>
+
+ /**
+ * This is a findByBlueprintModelAndContentType method
+ *
+ * @param blueprintModel blueprintModel
+ * @param contentType contentType
+ * @return Optional<BlueprintModelContent>
+ */
+ fun findByBlueprintModelAndContentType(blueprintModel: T, contentType: String): List<B>
+
+ /**
+ * This is a findByBlueprintModel method
+ *
+ * @param blueprintModel B
+ * @return Optional<T>
+ */
+ fun findByBlueprintModel(blueprintModel: T): List<B>
+
+ /**
+ * This is a findByBlueprintModelAndContentTypeAndName method
+ *
+ * @param blueprintModel blueprintModel
+ * @param contentType contentType
+ * @param name name
+ * @return Optional<B>
+ */
+ fun findByBlueprintModelAndContentTypeAndName(blueprintModel: T,
+ contentType: String, name: String): Optional<B>
+
+ /**
+ * This is a deleteByMdeleteByBlueprintModelodelName method
+ *
+ * @param blueprintModel B
+ */
+ fun deleteByBlueprintModel(blueprintModel: T)
+
+ /**
+ * This is a deleteById method
+ *
+ * @param id id
+ */
+ override fun deleteById(@NotNull id: String)
+
+} \ No newline at end of file
diff --git a/ms/controllerblueprints/modules/db-resources/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/db/resources/repository/ModelRepository.kt b/ms/controllerblueprints/modules/db-resources/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/db/resources/repository/ModelRepository.kt
new file mode 100644
index 000000000..c31f009a6
--- /dev/null
+++ b/ms/controllerblueprints/modules/db-resources/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/db/resources/repository/ModelRepository.kt
@@ -0,0 +1,88 @@
+/*
+ * Copyright © 2017-2018 AT&T Intellectual Property.
+ * Modifications Copyright © 2019 Bell Canada.
+ *
+ * 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.
+ */
+
+package org.onap.ccsdk.apps.controllerblueprints.db.resources.repository
+
+import org.jetbrains.annotations.NotNull
+import java.util.Optional
+import org.springframework.data.jpa.repository.JpaRepository
+import org.springframework.data.repository.NoRepositoryBean
+
+/**
+ * @param <T> Model
+ */
+@NoRepositoryBean
+interface ModelRepository<T> : JpaRepository<T, String> {
+
+ /**
+ * This is a findById method
+ *
+ * @param id id
+ * @return Optional<T>
+ */
+ @NotNull
+ override fun findById(@NotNull id: String): Optional<T>
+
+ /**
+ * This is a findByArtifactNameAndArtifactVersion method
+ *
+ * @param artifactName artifactName
+ * @param artifactVersion artifactVersion
+ * @return Optional<T>
+ */
+ fun findByArtifactNameAndArtifactVersion(artifactName: String, artifactVersion: String): Optional<T>
+
+ /**
+ * This is a findTopByArtifactNameOrderByArtifactIdDesc method
+ *
+ * @param artifactName artifactName
+ * @return Optional<T>
+ */
+ fun findTopByArtifactNameOrderByArtifactVersionDesc(artifactName: String): Optional<T>
+
+ /**
+ * This is a findTopByArtifactName method
+ *
+ * @param artifactName artifactName
+ * @return Optional<T>
+ */
+ fun findTopByArtifactName(artifactName: String): List<T>
+
+ /**
+ * This is a findByTagsContainingIgnoreCase method
+ *
+ * @param tags tags
+ * @return Optional<ModelType>
+ */
+ fun findByTagsContainingIgnoreCase(tags: String): List<T>
+
+ /**
+ * This is a deleteByArtifactNameAndArtifactVersion method
+ *
+ * @param artifactName artifactName
+ * @param artifactVersion artifactVersion
+ */
+ fun deleteByArtifactNameAndArtifactVersion(artifactName: String, artifactVersion: String)
+
+ /**
+ * This is a deleteById method
+ *
+ * @param id id
+ */
+ override fun deleteById(@NotNull id: String)
+
+}