aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-core
diff options
context:
space:
mode:
authorMichael Lando <ml636r@att.com>2017-02-19 12:35:04 +0200
committerMichael Lando <ml636r@att.com>2017-02-19 12:35:04 +0200
commitf5f13c4f6b6fe3b4d98e349dfd7db59339803436 (patch)
tree72caffc93fab394ffa3b761505775331f1c559b9 /openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-core
parent451a3400b76511393c62a444f588a4ed15f4a549 (diff)
push addional code
Change-Id: Ia427bb3460cda3a896f8faced2de69eaf3807b74 Signed-off-by: Michael Lando <ml636r@att.com>
Diffstat (limited to 'openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-core')
-rw-r--r--openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-core/pom.xml65
-rw-r--r--openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-core/src/main/java/org/openecomp/sdc/model/impl/AbstractServiceModelDao.java191
2 files changed, 256 insertions, 0 deletions
diff --git a/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-core/pom.xml b/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-core/pom.xml
new file mode 100644
index 0000000000..ba4d404ae7
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-core/pom.xml
@@ -0,0 +1,65 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.openecomp.sdc</groupId>
+ <artifactId>openecomp-sdc-lib</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <relativePath>../..</relativePath>
+ </parent>
+
+ <name>openecomp-sdc-model-core</name>
+ <artifactId>openecomp-sdc-model-core</artifactId>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>1.7.10</version>
+
+ </dependency>
+ <dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-classic</artifactId>
+ <version>1.1.2</version>
+
+ </dependency>
+
+
+ <dependency>
+ <groupId>org.openecomp.core</groupId>
+ <artifactId>openecomp-utilities-lib</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.openecomp.sdc</groupId>
+ <artifactId>openecomp-sdc-model-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.openecomp.sdc</groupId>
+ <artifactId>openecomp-sdc-versioning-core</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.openecomp.sdc</groupId>
+ <artifactId>openecomp-sdc-datatypes-lib</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-all</artifactId>
+ <scope>test</scope>
+ <version>1.10.19</version>
+ </dependency>
+ <dependency>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
+ <version>19.0</version>
+ </dependency>
+
+
+ </dependencies>
+</project> \ No newline at end of file
diff --git a/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-core/src/main/java/org/openecomp/sdc/model/impl/AbstractServiceModelDao.java b/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-core/src/main/java/org/openecomp/sdc/model/impl/AbstractServiceModelDao.java
new file mode 100644
index 0000000000..eb993f6fb1
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-core/src/main/java/org/openecomp/sdc/model/impl/AbstractServiceModelDao.java
@@ -0,0 +1,191 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.model.impl;
+
+import org.openecomp.core.model.dao.ServiceArtifactDaoInter;
+import org.openecomp.core.model.dao.ServiceTemplateDaoInter;
+import org.openecomp.core.model.types.ServiceArtifact;
+import org.openecomp.core.model.types.ServiceElement;
+import org.openecomp.core.model.types.ServiceTemplate;
+import org.openecomp.core.utilities.file.FileContentHandler;
+import org.openecomp.core.utilities.file.FileUtils;
+import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel;
+import org.openecomp.sdc.tosca.services.yamlutil.ToscaExtensionYamlUtil;
+import org.openecomp.sdc.versioning.dao.VersionableDao;
+import org.openecomp.sdc.versioning.dao.types.Version;
+
+import java.io.InputStream;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+public class AbstractServiceModelDao implements VersionableDao {
+
+ protected ServiceTemplateDaoInter templateDao;
+ protected ServiceArtifactDaoInter artifactDao;
+
+ @Override
+ public void registerVersioning(String versionableEntityType) {
+ templateDao.registerVersioning(versionableEntityType);
+ artifactDao.registerVersioning(versionableEntityType);
+ }
+
+
+ /**
+ * Gets service model.
+ *
+ * @param vspId the vsp id
+ * @param version the version
+ * @return the service model
+ */
+ public ToscaServiceModel getServiceModel(String vspId, Version version) {
+ if (vspId == null || version == null) {
+ //throw new CoreException()
+ throw new RuntimeException("missing service model key");
+ }
+
+
+ FileContentHandler artifactFiles = getArtifacts(vspId, version);
+ Map<String, org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate> serviceTemplates =
+ getTemplates(vspId, version);
+ String entryDefinitionServiceTemplate = getServiceBase(vspId, version);
+ return new ToscaServiceModel(artifactFiles, serviceTemplates, entryDefinitionServiceTemplate);
+ }
+
+
+ public void storeExternalArtifact(ServiceArtifact serviceArtifact) {
+ artifactDao.create(serviceArtifact);
+ //TODO: update last modification time
+ }
+
+
+ /**
+ * Store service model.
+ *
+ * @param vspId the vsp id
+ * @param version the version
+ * @param toscaServiceModel the tosca service model
+ */
+ public void storeServiceModel(String vspId, Version version,
+ ToscaServiceModel toscaServiceModel) {
+ ServiceArtifact entityArt;
+
+ for (String fileName : toscaServiceModel.getArtifactFiles().getFileList()) {
+ entityArt = new ServiceArtifact();
+ entityArt.setContentData(
+ FileUtils.toByteArray(toscaServiceModel.getArtifactFiles().getFileContent(fileName)));
+ entityArt.setVspId(vspId);
+ entityArt.setVersion(version);
+ entityArt.setName(fileName);
+
+ artifactDao.create(entityArt);
+ }
+
+ ServiceTemplate entityTmp;
+ String yaml;
+ for (Map.Entry<String, org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate>
+ entryTemplate : toscaServiceModel
+ .getServiceTemplates().entrySet()) {
+ entityTmp = new ServiceTemplate();
+
+ yaml = new ToscaExtensionYamlUtil().objectToYaml(entryTemplate.getValue());
+ entityTmp.setContentData(yaml.getBytes());
+ entityTmp.setVspId(vspId);
+ entityTmp.setVersion(version);
+ entityTmp.setName(entryTemplate.getKey());
+ entityTmp.setBaseName(toscaServiceModel.getEntryDefinitionServiceTemplate());
+
+ templateDao.create(entityTmp);
+ }
+
+ //TODO: update last modification time
+ }
+
+
+ /**
+ * Gets service model info.
+ *
+ * @param vspId the vsp id
+ * @param version the version
+ * @param name the name
+ * @return the service model info
+ */
+ public ServiceElement getServiceModelInfo(String vspId, Version version, String name) {
+ ServiceElement element = templateDao.getTemplateInfo(vspId, version, name);
+ if (element != null) {
+ return element;
+ }
+
+ element = artifactDao.getArtifactInfo(vspId, version, name);
+ if (element != null) {
+ return element;
+ }
+ return null;
+ }
+
+
+ /**
+ * Gets service model content names.
+ *
+ * @return the service model content names
+ */
+ public List<String> getServiceModelContentNames() {
+
+
+ return null;
+ }
+
+
+ private String getServiceBase(String vspId, Version version) {
+ return templateDao.getBase(vspId, version);
+ }
+
+ private Map<String, org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate> getTemplates(
+ String vspId, Version version) {
+
+ Collection<ServiceTemplate> templates = templateDao.list(vspId, version);
+ if (templates == null) {
+ return null;
+ }
+ return templates.stream().collect(Collectors.toMap(template -> template.getName(),
+ template -> getServiceTemplate(template.getContent())));
+ }
+
+ private org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate getServiceTemplate(
+ InputStream content) {
+ return new ToscaExtensionYamlUtil()
+ .yamlToObject(content, org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate.class);
+ }
+
+ private FileContentHandler getArtifacts(String vspId, Version version) {
+ Collection<ServiceArtifact> templates = artifactDao.list(vspId, version);
+ if (templates == null) {
+ return null;
+ }
+
+ FileContentHandler fileContentHandler = new FileContentHandler();
+ templates.stream().forEach(serviceArtifact -> fileContentHandler
+ .addFile(serviceArtifact.getName(), serviceArtifact.getContent()));
+
+ return fileContentHandler;
+ }
+}