From d378c37fbd1ecec7b43394926f1ca32a695e07de Mon Sep 17 00:00:00 2001 From: vasraz Date: Mon, 22 Mar 2021 15:33:06 +0000 Subject: Reformat openecomp-be Signed-off-by: Vasyl Razinkov Issue-ID: SDC-3449 Change-Id: I13e02322f8e00820cc5a1d85752caaeda9bf10d1 --- .../core/model/dao/EnrichedServiceModelDao.java | 16 +- .../model/dao/EnrichedServiceModelDaoFactory.java | 14 +- .../core/model/dao/ServiceArtifactDaoInter.java | 24 +- .../openecomp/core/model/dao/ServiceModelDao.java | 22 +- .../core/model/dao/ServiceModelDaoFactory.java | 11 +- .../RetrieveServiceTemplateFromDbErrorBuilder.java | 22 +- .../model/types/EnrichedServiceArtifactEntity.java | 17 +- .../model/types/EnrichedServiceTemplateEntity.java | 17 +- .../core/model/types/ServiceArtifact.java | 5 +- .../core/model/types/ServiceArtifactEntity.java | 19 +- .../openecomp/core/model/types/ServiceElement.java | 2 - .../core/model/types/ServiceElementEntity.java | 13 +- .../core/model/types/ServiceTemplate.java | 2 - .../core/model/types/ServiceTemplateEntity.java | 17 +- .../impl/EnrichedServiceModelDaoFactoryImpl.java | 18 +- .../sdc/model/impl/ServiceModelDaoFactoryImpl.java | 17 +- .../sdc/model/impl/zusammen/ElementType.java | 11 +- .../EnrichedServiceModelDaoZusammenImpl.java | 59 ++- .../impl/zusammen/ServiceModelDaoZusammenImpl.java | 410 +++++++++------------ .../sdc/model/impl/zusammen/StructureElement.java | 14 +- 20 files changed, 302 insertions(+), 428 deletions(-) (limited to 'openecomp-be/lib/openecomp-sdc-model-lib') diff --git a/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-api/src/main/java/org/openecomp/core/model/dao/EnrichedServiceModelDao.java b/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-api/src/main/java/org/openecomp/core/model/dao/EnrichedServiceModelDao.java index 3e5975dd13..033c4ee11c 100644 --- a/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-api/src/main/java/org/openecomp/core/model/dao/EnrichedServiceModelDao.java +++ b/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-api/src/main/java/org/openecomp/core/model/dao/EnrichedServiceModelDao.java @@ -7,9 +7,9 @@ * 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. @@ -17,17 +17,15 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.core.model.dao; import org.openecomp.core.model.types.ServiceArtifact; import org.openecomp.sdc.versioning.dao.VersionableDao; -public interface EnrichedServiceModelDao extends VersionableDao,ServiceModelDao{ - - void storeExternalArtifact(ServiceArtifact serviceArtifact); +public interface EnrichedServiceModelDao extends VersionableDao, ServiceModelDao { - //List getExternalArtifacts(String vspId, Version version); + void storeExternalArtifact(ServiceArtifact serviceArtifact); + //List getExternalArtifacts(String vspId, Version version); - //List getServiceModelContentNames(); -} + //List getServiceModelContentNames(); +} diff --git a/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-api/src/main/java/org/openecomp/core/model/dao/EnrichedServiceModelDaoFactory.java b/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-api/src/main/java/org/openecomp/core/model/dao/EnrichedServiceModelDaoFactory.java index 9d18d6c9cf..5ff24263c8 100644 --- a/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-api/src/main/java/org/openecomp/core/model/dao/EnrichedServiceModelDaoFactory.java +++ b/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-api/src/main/java/org/openecomp/core/model/dao/EnrichedServiceModelDaoFactory.java @@ -7,9 +7,9 @@ * 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. @@ -17,16 +17,14 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.core.model.dao; import org.openecomp.core.factory.api.AbstractComponentFactory; import org.openecomp.core.factory.api.AbstractFactory; -public abstract class EnrichedServiceModelDaoFactory - extends AbstractComponentFactory { +public abstract class EnrichedServiceModelDaoFactory extends AbstractComponentFactory { - public static EnrichedServiceModelDaoFactory getInstance() { - return AbstractFactory.getInstance(EnrichedServiceModelDaoFactory.class); - } + public static EnrichedServiceModelDaoFactory getInstance() { + return AbstractFactory.getInstance(EnrichedServiceModelDaoFactory.class); + } } diff --git a/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-api/src/main/java/org/openecomp/core/model/dao/ServiceArtifactDaoInter.java b/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-api/src/main/java/org/openecomp/core/model/dao/ServiceArtifactDaoInter.java index 30677b70a3..020c51cb77 100644 --- a/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-api/src/main/java/org/openecomp/core/model/dao/ServiceArtifactDaoInter.java +++ b/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-api/src/main/java/org/openecomp/core/model/dao/ServiceArtifactDaoInter.java @@ -7,9 +7,9 @@ * 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. @@ -17,30 +17,28 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.core.model.dao; +import java.util.Collection; import org.openecomp.core.model.types.ServiceArtifact; import org.openecomp.sdc.versioning.dao.VersionableDao; import org.openecomp.sdc.versioning.dao.types.Version; -import java.util.Collection; - public interface ServiceArtifactDaoInter extends VersionableDao { - Collection list(String vspId, Version version); + Collection list(String vspId, Version version); - void create(ServiceArtifact entity); + void create(ServiceArtifact entity); - void update(ServiceArtifact entity); + void update(ServiceArtifact entity); - ServiceArtifact get(String vspId, Version version); + ServiceArtifact get(String vspId, Version version); - void delete(String vspId, Version version); + void delete(String vspId, Version version); - Object[] getKeys(String vspId, Version version); + Object[] getKeys(String vspId, Version version); - ServiceArtifact getArtifactInfo(String vspId, Version version, String name); + ServiceArtifact getArtifactInfo(String vspId, Version version, String name); - void deleteAll(String vspId, Version version); + void deleteAll(String vspId, Version version); } diff --git a/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-api/src/main/java/org/openecomp/core/model/dao/ServiceModelDao.java b/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-api/src/main/java/org/openecomp/core/model/dao/ServiceModelDao.java index 0fb80b1835..7908711023 100644 --- a/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-api/src/main/java/org/openecomp/core/model/dao/ServiceModelDao.java +++ b/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-api/src/main/java/org/openecomp/core/model/dao/ServiceModelDao.java @@ -7,9 +7,9 @@ * 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. @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.core.model.dao; import org.openecomp.sdc.versioning.dao.VersionableDao; @@ -25,17 +24,16 @@ import org.openecomp.sdc.versioning.dao.types.Version; public interface ServiceModelDao extends VersionableDao { - M getServiceModel(String vspId, Version version); + M getServiceModel(String vspId, Version version); - void storeServiceModel(String vspId, Version version, M serviceModel); + void storeServiceModel(String vspId, Version version, M serviceModel); - E getServiceModelInfo(String vspId, Version version, String name); + E getServiceModelInfo(String vspId, Version version, String name); - void deleteAll(String vspId, Version version); + void deleteAll(String vspId, Version version); - /** - * This method gets used in healing, in order to replace the healed service model with the - * existing one without creating any conflicts - **/ - void overrideServiceModel(String vspId, Version version, M serviceModel); + /** + * This method gets used in healing, in order to replace the healed service model with the existing one without creating any conflicts + **/ + void overrideServiceModel(String vspId, Version version, M serviceModel); } diff --git a/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-api/src/main/java/org/openecomp/core/model/dao/ServiceModelDaoFactory.java b/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-api/src/main/java/org/openecomp/core/model/dao/ServiceModelDaoFactory.java index 19f6cb5c8c..3567ba3ae7 100644 --- a/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-api/src/main/java/org/openecomp/core/model/dao/ServiceModelDaoFactory.java +++ b/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-api/src/main/java/org/openecomp/core/model/dao/ServiceModelDaoFactory.java @@ -7,9 +7,9 @@ * 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. @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.core.model.dao; import org.openecomp.core.factory.api.AbstractComponentFactory; @@ -25,7 +24,7 @@ import org.openecomp.core.factory.api.AbstractFactory; public abstract class ServiceModelDaoFactory extends AbstractComponentFactory { - public static ServiceModelDaoFactory getInstance() { - return AbstractFactory.getInstance(ServiceModelDaoFactory.class); - } + public static ServiceModelDaoFactory getInstance() { + return AbstractFactory.getInstance(ServiceModelDaoFactory.class); + } } diff --git a/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-api/src/main/java/org/openecomp/core/model/errors/RetrieveServiceTemplateFromDbErrorBuilder.java b/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-api/src/main/java/org/openecomp/core/model/errors/RetrieveServiceTemplateFromDbErrorBuilder.java index 036acb2bf0..b9c4245640 100644 --- a/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-api/src/main/java/org/openecomp/core/model/errors/RetrieveServiceTemplateFromDbErrorBuilder.java +++ b/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-api/src/main/java/org/openecomp/core/model/errors/RetrieveServiceTemplateFromDbErrorBuilder.java @@ -7,9 +7,9 @@ * 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. @@ -17,22 +17,18 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.core.model.errors; import org.openecomp.sdc.common.errors.BaseErrorBuilder; import org.openecomp.sdc.common.errors.ErrorCategory; public class RetrieveServiceTemplateFromDbErrorBuilder extends BaseErrorBuilder { - private static final String CANT_RETRIEVE_SERVICE_TEMPLATE = "Could not retrirve service " + - "template named %s. Reason - %s"; - private static final String CREATE_SERVICE_TEMPLATE = "CREATE_SERVICE_TEMPLATE"; - public RetrieveServiceTemplateFromDbErrorBuilder(String serviceTemplateName, - String reason){ - this.getErrorCodeBuilder() - .withCategory(ErrorCategory.APPLICATION) - .withId(CREATE_SERVICE_TEMPLATE) - .withMessage(String.format(CANT_RETRIEVE_SERVICE_TEMPLATE, serviceTemplateName, reason)); - } + private static final String CANT_RETRIEVE_SERVICE_TEMPLATE = "Could not retrirve service " + "template named %s. Reason - %s"; + private static final String CREATE_SERVICE_TEMPLATE = "CREATE_SERVICE_TEMPLATE"; + + public RetrieveServiceTemplateFromDbErrorBuilder(String serviceTemplateName, String reason) { + this.getErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION).withId(CREATE_SERVICE_TEMPLATE) + .withMessage(String.format(CANT_RETRIEVE_SERVICE_TEMPLATE, serviceTemplateName, reason)); + } } diff --git a/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-api/src/main/java/org/openecomp/core/model/types/EnrichedServiceArtifactEntity.java b/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-api/src/main/java/org/openecomp/core/model/types/EnrichedServiceArtifactEntity.java index fbe0bb5362..d47ec10f2c 100644 --- a/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-api/src/main/java/org/openecomp/core/model/types/EnrichedServiceArtifactEntity.java +++ b/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-api/src/main/java/org/openecomp/core/model/types/EnrichedServiceArtifactEntity.java @@ -13,16 +13,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.core.model.types; -import com.datastax.driver.mapping.annotations.*; +import com.datastax.driver.mapping.annotations.ClusteringColumn; +import com.datastax.driver.mapping.annotations.Column; +import com.datastax.driver.mapping.annotations.Frozen; +import com.datastax.driver.mapping.annotations.PartitionKey; +import com.datastax.driver.mapping.annotations.Table; import com.google.common.io.ByteStreams; -import org.openecomp.sdc.common.errors.SdcRuntimeException; -import org.openecomp.sdc.versioning.dao.types.Version; - import java.io.IOException; import java.nio.ByteBuffer; +import org.openecomp.sdc.common.errors.SdcRuntimeException; +import org.openecomp.sdc.versioning.dao.types.Version; @Table(keyspace = "dox", name = "vsp_enriched_service_artifact") public class EnrichedServiceArtifactEntity implements ServiceElementEntity { @@ -36,15 +38,12 @@ public class EnrichedServiceArtifactEntity implements ServiceElementEntity { @PartitionKey @Column(name = "vsp_id") public String id; - @PartitionKey(value = 1) @Frozen public Version version; - @ClusteringColumn @Column(name = "name") public String name; - @Column(name = "content_data") public ByteBuffer contentData; @@ -66,13 +65,11 @@ public class EnrichedServiceArtifactEntity implements ServiceElementEntity { this.id = entity.getVspId(); this.version = entity.getVersion(); this.name = entity.getName(); - try { this.contentData = ByteBuffer.wrap(ByteStreams.toByteArray(entity.getContent())); } catch (IOException ioException) { throw new SdcRuntimeException(ioException); } - } @Override diff --git a/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-api/src/main/java/org/openecomp/core/model/types/EnrichedServiceTemplateEntity.java b/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-api/src/main/java/org/openecomp/core/model/types/EnrichedServiceTemplateEntity.java index aa6abbed75..8301df73c7 100644 --- a/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-api/src/main/java/org/openecomp/core/model/types/EnrichedServiceTemplateEntity.java +++ b/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-api/src/main/java/org/openecomp/core/model/types/EnrichedServiceTemplateEntity.java @@ -13,16 +13,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.core.model.types; -import com.datastax.driver.mapping.annotations.*; +import com.datastax.driver.mapping.annotations.ClusteringColumn; +import com.datastax.driver.mapping.annotations.Column; +import com.datastax.driver.mapping.annotations.Frozen; +import com.datastax.driver.mapping.annotations.PartitionKey; +import com.datastax.driver.mapping.annotations.Table; import com.google.common.io.ByteStreams; -import org.openecomp.sdc.common.errors.SdcRuntimeException; -import org.openecomp.sdc.versioning.dao.types.Version; - import java.io.IOException; import java.nio.ByteBuffer; +import org.openecomp.sdc.common.errors.SdcRuntimeException; +import org.openecomp.sdc.versioning.dao.types.Version; @Table(keyspace = "dox", name = "vsp_enriched_service_template") public class EnrichedServiceTemplateEntity implements ServiceElementEntity { @@ -36,18 +38,14 @@ public class EnrichedServiceTemplateEntity implements ServiceElementEntity { @PartitionKey @Column(name = "vsp_id") public String id; - @PartitionKey(value = 1) @Frozen public Version version; - @ClusteringColumn @Column(name = "name") public String name; - @Column(name = "content_data") public ByteBuffer contentData; - @Column(name = "base_name") private String baseName; @@ -75,7 +73,6 @@ public class EnrichedServiceTemplateEntity implements ServiceElementEntity { } catch (IOException ioException) { throw new SdcRuntimeException(ioException); } - } public String getBaseName() { diff --git a/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-api/src/main/java/org/openecomp/core/model/types/ServiceArtifact.java b/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-api/src/main/java/org/openecomp/core/model/types/ServiceArtifact.java index 184704b094..bb6f4b5574 100644 --- a/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-api/src/main/java/org/openecomp/core/model/types/ServiceArtifact.java +++ b/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-api/src/main/java/org/openecomp/core/model/types/ServiceArtifact.java @@ -7,9 +7,9 @@ * 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. @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.core.model.types; import lombok.NoArgsConstructor; diff --git a/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-api/src/main/java/org/openecomp/core/model/types/ServiceArtifactEntity.java b/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-api/src/main/java/org/openecomp/core/model/types/ServiceArtifactEntity.java index 0709371d94..bfab42f8ee 100644 --- a/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-api/src/main/java/org/openecomp/core/model/types/ServiceArtifactEntity.java +++ b/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-api/src/main/java/org/openecomp/core/model/types/ServiceArtifactEntity.java @@ -13,19 +13,22 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.core.model.types; -import com.datastax.driver.mapping.annotations.*; +import com.datastax.driver.mapping.annotations.ClusteringColumn; +import com.datastax.driver.mapping.annotations.Column; +import com.datastax.driver.mapping.annotations.Frozen; +import com.datastax.driver.mapping.annotations.PartitionKey; +import com.datastax.driver.mapping.annotations.Table; import com.google.common.io.ByteStreams; -import org.openecomp.sdc.common.errors.SdcRuntimeException; -import org.openecomp.sdc.versioning.dao.types.Version; - import java.io.IOException; import java.nio.ByteBuffer; +import org.openecomp.sdc.common.errors.SdcRuntimeException; +import org.openecomp.sdc.versioning.dao.types.Version; @Table(keyspace = "dox", name = "vsp_service_artifact") public class ServiceArtifactEntity implements ServiceElementEntity { + private static final String ENTITY_TYPE; static { @@ -35,15 +38,12 @@ public class ServiceArtifactEntity implements ServiceElementEntity { @PartitionKey @Column(name = "vsp_id") public String id; - @PartitionKey(value = 1) @Frozen public Version version; - @ClusteringColumn @Column(name = "name") public String name; - @Column(name = "content_data") public ByteBuffer contentData; @@ -65,13 +65,11 @@ public class ServiceArtifactEntity implements ServiceElementEntity { this.id = entity.getVspId(); this.version = entity.getVersion(); this.name = entity.getName(); - try { this.contentData = ByteBuffer.wrap(ByteStreams.toByteArray(entity.getContent())); } catch (IOException ioException) { throw new SdcRuntimeException(ioException); } - } @Override @@ -130,5 +128,4 @@ public class ServiceArtifactEntity implements ServiceElementEntity { serviceArtifact.setVspId(this.getId()); return serviceArtifact; } - } diff --git a/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-api/src/main/java/org/openecomp/core/model/types/ServiceElement.java b/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-api/src/main/java/org/openecomp/core/model/types/ServiceElement.java index 817cfa9d44..f598c4b225 100644 --- a/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-api/src/main/java/org/openecomp/core/model/types/ServiceElement.java +++ b/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-api/src/main/java/org/openecomp/core/model/types/ServiceElement.java @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.core.model.types; import java.io.ByteArrayInputStream; @@ -48,5 +47,4 @@ public class ServiceElement { } return new ByteArrayInputStream(contentData); } - } diff --git a/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-api/src/main/java/org/openecomp/core/model/types/ServiceElementEntity.java b/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-api/src/main/java/org/openecomp/core/model/types/ServiceElementEntity.java index 02249039f8..716e140fc8 100644 --- a/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-api/src/main/java/org/openecomp/core/model/types/ServiceElementEntity.java +++ b/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-api/src/main/java/org/openecomp/core/model/types/ServiceElementEntity.java @@ -7,9 +7,9 @@ * 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. @@ -17,15 +17,14 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.core.model.types; -import org.openecomp.sdc.versioning.dao.types.VersionableEntity; - import java.nio.ByteBuffer; +import org.openecomp.sdc.versioning.dao.types.VersionableEntity; public interface ServiceElementEntity extends VersionableEntity { - String getName(); - ByteBuffer getContentData(); + String getName(); + + ByteBuffer getContentData(); } diff --git a/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-api/src/main/java/org/openecomp/core/model/types/ServiceTemplate.java b/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-api/src/main/java/org/openecomp/core/model/types/ServiceTemplate.java index 479502e8f9..14bdb0869f 100644 --- a/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-api/src/main/java/org/openecomp/core/model/types/ServiceTemplate.java +++ b/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-api/src/main/java/org/openecomp/core/model/types/ServiceTemplate.java @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.core.model.types; import lombok.Getter; @@ -30,5 +29,4 @@ import lombok.Setter; public class ServiceTemplate extends ServiceElement { private String baseName; - } diff --git a/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-api/src/main/java/org/openecomp/core/model/types/ServiceTemplateEntity.java b/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-api/src/main/java/org/openecomp/core/model/types/ServiceTemplateEntity.java index 80f0cfb371..48b539ec5f 100644 --- a/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-api/src/main/java/org/openecomp/core/model/types/ServiceTemplateEntity.java +++ b/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-api/src/main/java/org/openecomp/core/model/types/ServiceTemplateEntity.java @@ -13,16 +13,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.core.model.types; -import com.datastax.driver.mapping.annotations.*; +import com.datastax.driver.mapping.annotations.ClusteringColumn; +import com.datastax.driver.mapping.annotations.Column; +import com.datastax.driver.mapping.annotations.Frozen; +import com.datastax.driver.mapping.annotations.PartitionKey; +import com.datastax.driver.mapping.annotations.Table; import com.google.common.io.ByteStreams; -import org.openecomp.sdc.common.errors.SdcRuntimeException; -import org.openecomp.sdc.versioning.dao.types.Version; - import java.io.IOException; import java.nio.ByteBuffer; +import org.openecomp.sdc.common.errors.SdcRuntimeException; +import org.openecomp.sdc.versioning.dao.types.Version; @Table(keyspace = "dox", name = "vsp_service_template") public class ServiceTemplateEntity implements ServiceElementEntity { @@ -36,18 +38,14 @@ public class ServiceTemplateEntity implements ServiceElementEntity { @PartitionKey @Column(name = "vsp_id") public String id; - @PartitionKey(value = 1) @Frozen public Version version; - @ClusteringColumn @Column(name = "name") public String name; - @Column(name = "content_data") public ByteBuffer contentData; - @Column(name = "base_name") private String baseName; @@ -75,7 +73,6 @@ public class ServiceTemplateEntity implements ServiceElementEntity { } catch (IOException ioException) { throw new SdcRuntimeException(ioException); } - } public String getBaseName() { diff --git a/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-impl/src/main/java/org/openecomp/sdc/model/impl/EnrichedServiceModelDaoFactoryImpl.java b/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-impl/src/main/java/org/openecomp/sdc/model/impl/EnrichedServiceModelDaoFactoryImpl.java index 98cb8724df..7ffd0b0c7b 100644 --- a/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-impl/src/main/java/org/openecomp/sdc/model/impl/EnrichedServiceModelDaoFactoryImpl.java +++ b/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-impl/src/main/java/org/openecomp/sdc/model/impl/EnrichedServiceModelDaoFactoryImpl.java @@ -7,9 +7,9 @@ * 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. @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.model.impl; import org.openecomp.core.model.dao.EnrichedServiceModelDao; @@ -26,11 +25,12 @@ import org.openecomp.core.zusammen.api.ZusammenAdaptorFactory; import org.openecomp.sdc.model.impl.zusammen.EnrichedServiceModelDaoZusammenImpl; public class EnrichedServiceModelDaoFactoryImpl extends EnrichedServiceModelDaoFactory { - private static final EnrichedServiceModelDao INSTANCE = new EnrichedServiceModelDaoZusammenImpl( ZusammenAdaptorFactory - .getInstance().createInterface()); - @Override - public EnrichedServiceModelDao createInterface() { - return INSTANCE; - } + private static final EnrichedServiceModelDao INSTANCE = new EnrichedServiceModelDaoZusammenImpl( + ZusammenAdaptorFactory.getInstance().createInterface()); + + @Override + public EnrichedServiceModelDao createInterface() { + return INSTANCE; + } } diff --git a/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-impl/src/main/java/org/openecomp/sdc/model/impl/ServiceModelDaoFactoryImpl.java b/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-impl/src/main/java/org/openecomp/sdc/model/impl/ServiceModelDaoFactoryImpl.java index 85508670aa..5134076a5f 100644 --- a/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-impl/src/main/java/org/openecomp/sdc/model/impl/ServiceModelDaoFactoryImpl.java +++ b/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-impl/src/main/java/org/openecomp/sdc/model/impl/ServiceModelDaoFactoryImpl.java @@ -7,9 +7,9 @@ * 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. @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.model.impl; import org.openecomp.core.model.dao.ServiceModelDao; @@ -26,11 +25,11 @@ import org.openecomp.core.zusammen.api.ZusammenAdaptorFactory; import org.openecomp.sdc.model.impl.zusammen.ServiceModelDaoZusammenImpl; public class ServiceModelDaoFactoryImpl extends ServiceModelDaoFactory { - private static final ServiceModelDao INSTANCE = new ServiceModelDaoZusammenImpl( - ZusammenAdaptorFactory.getInstance().createInterface()); - @Override - public ServiceModelDao createInterface() { - return INSTANCE; - } + private static final ServiceModelDao INSTANCE = new ServiceModelDaoZusammenImpl(ZusammenAdaptorFactory.getInstance().createInterface()); + + @Override + public ServiceModelDao createInterface() { + return INSTANCE; + } } diff --git a/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-impl/src/main/java/org/openecomp/sdc/model/impl/zusammen/ElementType.java b/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-impl/src/main/java/org/openecomp/sdc/model/impl/zusammen/ElementType.java index 788bf79423..4f62a16642 100644 --- a/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-impl/src/main/java/org/openecomp/sdc/model/impl/zusammen/ElementType.java +++ b/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-impl/src/main/java/org/openecomp/sdc/model/impl/zusammen/ElementType.java @@ -7,9 +7,9 @@ * 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. @@ -17,11 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.model.impl.zusammen; -public enum ElementType { - Servicetemplate,Artifact; - - -} +public enum ElementType {Servicetemplate, Artifact;} diff --git a/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-impl/src/main/java/org/openecomp/sdc/model/impl/zusammen/EnrichedServiceModelDaoZusammenImpl.java b/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-impl/src/main/java/org/openecomp/sdc/model/impl/zusammen/EnrichedServiceModelDaoZusammenImpl.java index 938f104b1e..6f1492c163 100644 --- a/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-impl/src/main/java/org/openecomp/sdc/model/impl/zusammen/EnrichedServiceModelDaoZusammenImpl.java +++ b/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-impl/src/main/java/org/openecomp/sdc/model/impl/zusammen/EnrichedServiceModelDaoZusammenImpl.java @@ -7,9 +7,9 @@ * 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. @@ -17,9 +17,10 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.model.impl.zusammen; +import static org.openecomp.core.zusammen.api.ZusammenUtil.buildStructuralElement; + import com.amdocs.zusammen.adaptor.inbound.api.types.item.ZusammenElement; import com.amdocs.zusammen.datatypes.SessionContext; import com.amdocs.zusammen.datatypes.item.Action; @@ -35,41 +36,29 @@ import org.openecomp.sdc.logging.api.Logger; import org.openecomp.sdc.logging.api.LoggerFactory; import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel; -import static org.openecomp.core.zusammen.api.ZusammenUtil.buildStructuralElement; - public class EnrichedServiceModelDaoZusammenImpl extends ServiceModelDaoZusammenImpl implements EnrichedServiceModelDao { - private static final Logger logger = - LoggerFactory.getLogger(EnrichedServiceModelDaoZusammenImpl.class); - - public EnrichedServiceModelDaoZusammenImpl(ZusammenAdaptor zusammenAdaptor) { - super(zusammenAdaptor); - this.elementType = ElementType.EnrichedServiceModel; - } - - @Override - public void storeExternalArtifact(ServiceArtifact serviceArtifact) { - ZusammenElement artifact = buildArtifactElement(serviceArtifact.getName(), - FileUtils.toByteArray(serviceArtifact.getContent()), Action.CREATE); - - ZusammenElement artifacts = buildStructuralElement(ElementType.Artifacts, Action.IGNORE); - artifacts.addSubElement(artifact); - - ZusammenElement enrichedServiceModel = buildStructuralElement(elementType, Action.IGNORE); - enrichedServiceModel.addSubElement(artifacts); - - ZusammenElement vspModel = buildStructuralElement(ElementType.VspModel, Action.IGNORE); - vspModel.addSubElement(enrichedServiceModel); + private static final Logger logger = LoggerFactory.getLogger(EnrichedServiceModelDaoZusammenImpl.class); - SessionContext context = ZusammenUtil.createSessionContext(); - ElementContext elementContext = - new ElementContext(serviceArtifact.getVspId(), serviceArtifact.getVersion().getId()); - zusammenAdaptor - .saveElement(context, elementContext, vspModel, "add service external artifact."); + public EnrichedServiceModelDaoZusammenImpl(ZusammenAdaptor zusammenAdaptor) { + super(zusammenAdaptor); + this.elementType = ElementType.EnrichedServiceModel; + } - logger.info( - "Finished adding artifact to enriched service model for VendorSoftwareProduct id -> {}", - elementContext.getItemId().getValue()); - } + @Override + public void storeExternalArtifact(ServiceArtifact serviceArtifact) { + ZusammenElement artifact = buildArtifactElement(serviceArtifact.getName(), FileUtils.toByteArray(serviceArtifact.getContent()), + Action.CREATE); + ZusammenElement artifacts = buildStructuralElement(ElementType.Artifacts, Action.IGNORE); + artifacts.addSubElement(artifact); + ZusammenElement enrichedServiceModel = buildStructuralElement(elementType, Action.IGNORE); + enrichedServiceModel.addSubElement(artifacts); + ZusammenElement vspModel = buildStructuralElement(ElementType.VspModel, Action.IGNORE); + vspModel.addSubElement(enrichedServiceModel); + SessionContext context = ZusammenUtil.createSessionContext(); + ElementContext elementContext = new ElementContext(serviceArtifact.getVspId(), serviceArtifact.getVersion().getId()); + zusammenAdaptor.saveElement(context, elementContext, vspModel, "add service external artifact."); + logger.info("Finished adding artifact to enriched service model for VendorSoftwareProduct id -> {}", elementContext.getItemId().getValue()); + } } diff --git a/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-impl/src/main/java/org/openecomp/sdc/model/impl/zusammen/ServiceModelDaoZusammenImpl.java b/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-impl/src/main/java/org/openecomp/sdc/model/impl/zusammen/ServiceModelDaoZusammenImpl.java index 8ff78d6401..27ef113204 100644 --- a/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-impl/src/main/java/org/openecomp/sdc/model/impl/zusammen/ServiceModelDaoZusammenImpl.java +++ b/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-impl/src/main/java/org/openecomp/sdc/model/impl/zusammen/ServiceModelDaoZusammenImpl.java @@ -7,9 +7,9 @@ * 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. @@ -17,9 +17,11 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.model.impl.zusammen; +import static org.openecomp.core.zusammen.api.ZusammenUtil.buildElement; +import static org.openecomp.core.zusammen.api.ZusammenUtil.buildStructuralElement; + import com.amdocs.zusammen.adaptor.inbound.api.types.item.Element; import com.amdocs.zusammen.adaptor.inbound.api.types.item.ElementInfo; import com.amdocs.zusammen.adaptor.inbound.api.types.item.ZusammenElement; @@ -28,6 +30,12 @@ import com.amdocs.zusammen.datatypes.SessionContext; import com.amdocs.zusammen.datatypes.item.Action; import com.amdocs.zusammen.datatypes.item.ElementContext; import com.amdocs.zusammen.datatypes.item.Info; +import java.io.ByteArrayInputStream; +import java.util.Collection; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; +import java.util.stream.Collectors; import org.apache.commons.io.IOUtils; import org.onap.sdc.tosca.datatypes.model.ServiceTemplate; import org.onap.sdc.tosca.services.ToscaExtensionYamlUtil; @@ -45,267 +53,189 @@ import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel; import org.openecomp.sdc.versioning.dao.types.Version; import org.openecomp.types.ElementPropertyName; -import java.io.ByteArrayInputStream; -import java.util.Collection; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; -import java.util.stream.Collectors; - -import static org.openecomp.core.zusammen.api.ZusammenUtil.buildElement; -import static org.openecomp.core.zusammen.api.ZusammenUtil.buildStructuralElement; - -public class ServiceModelDaoZusammenImpl - implements ServiceModelDao { - private static final String BASE_PROPERTY = "base"; - private static final Logger logger = LoggerFactory.getLogger(ServiceModelDaoZusammenImpl.class); - - protected ZusammenAdaptor zusammenAdaptor; - protected ElementType elementType; +public class ServiceModelDaoZusammenImpl implements ServiceModelDao { - public ServiceModelDaoZusammenImpl(ZusammenAdaptor zusammenAdaptor) { - this.zusammenAdaptor = zusammenAdaptor; - this.elementType = ElementType.ServiceModel; - } + private static final String BASE_PROPERTY = "base"; + private static final Logger logger = LoggerFactory.getLogger(ServiceModelDaoZusammenImpl.class); + protected ZusammenAdaptor zusammenAdaptor; + protected ElementType elementType; - @Override - public void registerVersioning(String versionableEntityType) { - - } - - @Override - public ToscaServiceModel getServiceModel(String vspId, Version version) { - SessionContext context = ZusammenUtil.createSessionContext(); - ElementContext elementContext = new ElementContext(vspId, version.getId()); - - Optional serviceModel = getServiceModelElementInfo(context, elementContext); - if (!serviceModel.isPresent()) { - return null; + public ServiceModelDaoZusammenImpl(ZusammenAdaptor zusammenAdaptor) { + this.zusammenAdaptor = zusammenAdaptor; + this.elementType = ElementType.ServiceModel; } - Id serviceModelElementId = serviceModel.get().getId(); - Map serviceTemplates = - getTemplates(context, elementContext, serviceModelElementId); - if (serviceTemplates == null) { - return null; + @Override + public void registerVersioning(String versionableEntityType) { } - FileContentHandler artifacts = getArtifacts(context, elementContext, serviceModelElementId); - String entryDefinitionServiceTemplate = - serviceModel.get().getInfo().getProperty(BASE_PROPERTY); - - return new ToscaServiceModel(artifacts, serviceTemplates, entryDefinitionServiceTemplate); - } - - @Override - public void storeServiceModel(String vspId, Version version, ToscaServiceModel serviceModel) { - logger.info("Storing service model for VendorSoftwareProduct id -> {}", vspId); - - ZusammenElement templatesElement = buildStructuralElement(ElementType.Templates, Action.UPDATE); - serviceModel.getServiceTemplates().forEach((key, value) -> templatesElement.addSubElement( - buildServiceTemplateElement(key, value, serviceModel.getEntryDefinitionServiceTemplate(), Action.CREATE))); - - ZusammenElement artifactsElement = buildStructuralElement(ElementType.Artifacts, Action.UPDATE); - if (Objects.nonNull(serviceModel.getArtifactFiles())) { - serviceModel.getArtifactFiles().getFiles().forEach( - (key, value) -> artifactsElement.addSubElement(buildArtifactElement(key, value, Action.CREATE))); + @Override + public ToscaServiceModel getServiceModel(String vspId, Version version) { + SessionContext context = ZusammenUtil.createSessionContext(); + ElementContext elementContext = new ElementContext(vspId, version.getId()); + Optional serviceModel = getServiceModelElementInfo(context, elementContext); + if (!serviceModel.isPresent()) { + return null; + } + Id serviceModelElementId = serviceModel.get().getId(); + Map serviceTemplates = getTemplates(context, elementContext, serviceModelElementId); + if (serviceTemplates == null) { + return null; + } + FileContentHandler artifacts = getArtifacts(context, elementContext, serviceModelElementId); + String entryDefinitionServiceTemplate = serviceModel.get().getInfo().getProperty(BASE_PROPERTY); + return new ToscaServiceModel(artifacts, serviceTemplates, entryDefinitionServiceTemplate); } - ZusammenElement serviceModelElement = buildServiceModelElement(serviceModel.getEntryDefinitionServiceTemplate()); - - serviceModelElement.addSubElement(templatesElement); - serviceModelElement.addSubElement(artifactsElement); - - ZusammenElement vspModel = buildStructuralElement(ElementType.VspModel, Action.IGNORE); - vspModel.addSubElement(serviceModelElement); - - SessionContext context = ZusammenUtil.createSessionContext(); - ElementContext elementContext = new ElementContext(vspId, version.getId()); - zusammenAdaptor.saveElement(context, elementContext, vspModel, "Store service model"); - - logger - .info("Finished storing {} for VendorSoftwareProduct id -> {}", elementType.name(), vspId); - } - - @Override - public ServiceElement getServiceModelInfo(String vspId, Version version, String name) { - return null; - } - - @Override - public void deleteAll(String vspId, Version version) { - logger.info("Started deleting content of Templates and Artifacts of {} of vsp {} version {}", - elementType.name(), vspId, version.getId()); - - SessionContext context = ZusammenUtil.createSessionContext(); - ElementContext elementContext = new ElementContext(vspId, version.getId()); - - Optional serviceModel = getServiceModelElementInfo(context, elementContext); - if (!serviceModel.isPresent()) { - logger.info("{} of vsp {} version {} does not exist - nothing to delete", elementType.name(), - vspId, version.getId()); - return; + @Override + public void storeServiceModel(String vspId, Version version, ToscaServiceModel serviceModel) { + logger.info("Storing service model for VendorSoftwareProduct id -> {}", vspId); + ZusammenElement templatesElement = buildStructuralElement(ElementType.Templates, Action.UPDATE); + serviceModel.getServiceTemplates().forEach((key, value) -> templatesElement + .addSubElement(buildServiceTemplateElement(key, value, serviceModel.getEntryDefinitionServiceTemplate(), Action.CREATE))); + ZusammenElement artifactsElement = buildStructuralElement(ElementType.Artifacts, Action.UPDATE); + if (Objects.nonNull(serviceModel.getArtifactFiles())) { + serviceModel.getArtifactFiles().getFiles() + .forEach((key, value) -> artifactsElement.addSubElement(buildArtifactElement(key, value, Action.CREATE))); + } + ZusammenElement serviceModelElement = buildServiceModelElement(serviceModel.getEntryDefinitionServiceTemplate()); + serviceModelElement.addSubElement(templatesElement); + serviceModelElement.addSubElement(artifactsElement); + ZusammenElement vspModel = buildStructuralElement(ElementType.VspModel, Action.IGNORE); + vspModel.addSubElement(serviceModelElement); + SessionContext context = ZusammenUtil.createSessionContext(); + ElementContext elementContext = new ElementContext(vspId, version.getId()); + zusammenAdaptor.saveElement(context, elementContext, vspModel, "Store service model"); + logger.info("Finished storing {} for VendorSoftwareProduct id -> {}", elementType.name(), vspId); } - ZusammenElement serviceModelElement = buildElement(serviceModel.get().getId(), Action.IGNORE); - for (Id serviceModelSubElementId : - serviceModel.get().getSubElements().stream() - .map(ElementInfo::getId) - .collect(Collectors.toSet())) { - ElementInfo serviceModelSubElementInfo = - zusammenAdaptor.getElementInfo(context, elementContext, serviceModelSubElementId) - .orElseThrow(() -> new IllegalStateException(String.format( - "Element %s declared as sub element of element %s (%s) does not exist", - serviceModelSubElementId.getValue(), - serviceModel.get().getId().getValue(), - elementType.name()))); - - if (ElementType.Templates.name().equals(serviceModelSubElementInfo.getInfo().getName()) - || ElementType.Artifacts.name().equals(serviceModelSubElementInfo.getInfo().getName())) { - ZusammenElement serviceModelSubElement = - buildElement(serviceModelSubElementId, Action.IGNORE); - serviceModelSubElement.setSubElements(serviceModelSubElementInfo.getSubElements().stream() - .map(elementInfo -> buildElement(elementInfo.getId(), Action.DELETE)) - .collect(Collectors.toSet())); - serviceModelElement.addSubElement(serviceModelSubElement); - } + @Override + public ServiceElement getServiceModelInfo(String vspId, Version version, String name) { + return null; } - zusammenAdaptor.saveElement(context, elementContext, serviceModelElement, - String.format("Delete content of Templates and Artifacts of %s", elementType.name())); - - logger.info("Finished deleting content of Templates and Artifacts of {} of vsp {} version {}", - elementType.name(), vspId, version.getId()); - } - - @Override - public void overrideServiceModel(String vspId, - Version version, - ToscaServiceModel serviceModel) { - SessionContext context = ZusammenUtil.createSessionContext(); - ElementContext elementContext = new ElementContext(vspId, version.getId()); - - Optional origServiceModel = getServiceModelElementInfo(context, elementContext); - if (!origServiceModel.isPresent()) { - return; + @Override + public void deleteAll(String vspId, Version version) { + logger.info("Started deleting content of Templates and Artifacts of {} of vsp {} version {}", elementType.name(), vspId, version.getId()); + SessionContext context = ZusammenUtil.createSessionContext(); + ElementContext elementContext = new ElementContext(vspId, version.getId()); + Optional serviceModel = getServiceModelElementInfo(context, elementContext); + if (!serviceModel.isPresent()) { + logger.info("{} of vsp {} version {} does not exist - nothing to delete", elementType.name(), vspId, version.getId()); + return; + } + ZusammenElement serviceModelElement = buildElement(serviceModel.get().getId(), Action.IGNORE); + for (Id serviceModelSubElementId : serviceModel.get().getSubElements().stream().map(ElementInfo::getId).collect(Collectors.toSet())) { + ElementInfo serviceModelSubElementInfo = zusammenAdaptor.getElementInfo(context, elementContext, serviceModelSubElementId).orElseThrow( + () -> new IllegalStateException(String + .format("Element %s declared as sub element of element %s (%s) does not exist", serviceModelSubElementId.getValue(), + serviceModel.get().getId().getValue(), elementType.name()))); + if (ElementType.Templates.name().equals(serviceModelSubElementInfo.getInfo().getName()) || ElementType.Artifacts.name() + .equals(serviceModelSubElementInfo.getInfo().getName())) { + ZusammenElement serviceModelSubElement = buildElement(serviceModelSubElementId, Action.IGNORE); + serviceModelSubElement.setSubElements( + serviceModelSubElementInfo.getSubElements().stream().map(elementInfo -> buildElement(elementInfo.getId(), Action.DELETE)) + .collect(Collectors.toSet())); + serviceModelElement.addSubElement(serviceModelSubElement); + } + } + zusammenAdaptor.saveElement(context, elementContext, serviceModelElement, + String.format("Delete content of Templates and Artifacts of %s", elementType.name())); + logger.info("Finished deleting content of Templates and Artifacts of {} of vsp {} version {}", elementType.name(), vspId, version.getId()); } - Id serviceModelElementId = origServiceModel.get().getId(); - - ZusammenElement serviceModelElement = buildServiceModelElement(serviceModel.getEntryDefinitionServiceTemplate()); - serviceModelElement.setElementId(serviceModelElementId); - - overrideServiceTemplates(serviceModelElementId, serviceModel, context, elementContext, serviceModelElement); - zusammenAdaptor.saveElement(context, elementContext, serviceModelElement, "Override service model"); - } - - - private void overrideServiceTemplates(Id serviceModelElementId, - ToscaServiceModel serviceModel, - SessionContext context, - ElementContext elementContext, - ZusammenElement serviceModelElement) { - Optional elementInfo = zusammenAdaptor.getElementInfoByName( - context, elementContext, serviceModelElementId, ElementType.Templates.name()); - if (!elementInfo.isPresent()) { - return; + @Override + public void overrideServiceModel(String vspId, Version version, ToscaServiceModel serviceModel) { + SessionContext context = ZusammenUtil.createSessionContext(); + ElementContext elementContext = new ElementContext(vspId, version.getId()); + Optional origServiceModel = getServiceModelElementInfo(context, elementContext); + if (!origServiceModel.isPresent()) { + return; + } + Id serviceModelElementId = origServiceModel.get().getId(); + ZusammenElement serviceModelElement = buildServiceModelElement(serviceModel.getEntryDefinitionServiceTemplate()); + serviceModelElement.setElementId(serviceModelElementId); + overrideServiceTemplates(serviceModelElementId, serviceModel, context, elementContext, serviceModelElement); + zusammenAdaptor.saveElement(context, elementContext, serviceModelElement, "Override service model"); } - ZusammenElement templateElement = buildStructuralElement(ElementType.Templates, Action.UPDATE); - templateElement.setElementId(elementInfo.get().getId()); - serviceModel.getServiceTemplates().forEach((templateName, serviceTemplate) -> templateElement.addSubElement( - buildServiceTemplateElement(templateName, serviceTemplate, - serviceModel.getEntryDefinitionServiceTemplate(), Action.UPDATE))); - serviceModelElement.addSubElement(templateElement); - } - - private Optional getServiceModelElementInfo(SessionContext context, - ElementContext elementContext) { - Collection vspModelSubs = zusammenAdaptor - .listElementsByName(context, elementContext, null, ElementType.VspModel.name()); - - return vspModelSubs.stream() - .filter(elementInfo -> elementInfo.getInfo() != null - && elementType.name().equals(elementInfo.getInfo().getName())) - .findFirst(); - } - private Map getTemplates(SessionContext context, - ElementContext elementContext, - Id serviceModelElementId) { - Optional templatesElementInfo = zusammenAdaptor.getElementInfoByName( - context, elementContext, serviceModelElementId, ElementType.Templates.name()); - - if (templatesElementInfo.isPresent()) { - Collection elements = zusammenAdaptor.listElementData(context, elementContext, - templatesElementInfo.get().getId()); - - return elements.stream().collect(Collectors.toMap( - element -> element.getInfo().getName(), - this::elementToServiceTemplate)); + private void overrideServiceTemplates(Id serviceModelElementId, ToscaServiceModel serviceModel, SessionContext context, + ElementContext elementContext, ZusammenElement serviceModelElement) { + Optional elementInfo = zusammenAdaptor + .getElementInfoByName(context, elementContext, serviceModelElementId, ElementType.Templates.name()); + if (!elementInfo.isPresent()) { + return; + } + ZusammenElement templateElement = buildStructuralElement(ElementType.Templates, Action.UPDATE); + templateElement.setElementId(elementInfo.get().getId()); + serviceModel.getServiceTemplates().forEach((templateName, serviceTemplate) -> templateElement.addSubElement( + buildServiceTemplateElement(templateName, serviceTemplate, serviceModel.getEntryDefinitionServiceTemplate(), Action.UPDATE))); + serviceModelElement.addSubElement(templateElement); } - return null; - } - - private FileContentHandler getArtifacts(SessionContext context, ElementContext elementContext, - Id serviceModelElementId) { - Optional artifactsElement = zusammenAdaptor.getElementInfoByName( - context, elementContext, serviceModelElementId, ElementType.Artifacts.name()); - if (artifactsElement.isPresent()) { - - Collection elements = zusammenAdaptor.listElementData(context, elementContext, - artifactsElement.get().getId()); - FileContentHandler fileContentHandler = new FileContentHandler(); - elements.forEach(element -> fileContentHandler.addFile(element.getInfo().getName(), - element.getData())); - return fileContentHandler; + private Optional getServiceModelElementInfo(SessionContext context, ElementContext elementContext) { + Collection vspModelSubs = zusammenAdaptor.listElementsByName(context, elementContext, null, ElementType.VspModel.name()); + return vspModelSubs.stream() + .filter(elementInfo -> elementInfo.getInfo() != null && elementType.name().equals(elementInfo.getInfo().getName())).findFirst(); } - return null; - } - - private ZusammenElement buildServiceModelElement(String entryDefinitionServiceTemplate) { - ZusammenElement serviceModelElement = buildStructuralElement(elementType, Action.UPDATE); - serviceModelElement.getInfo().addProperty(BASE_PROPERTY, entryDefinitionServiceTemplate); - return serviceModelElement; - } + private Map getTemplates(SessionContext context, ElementContext elementContext, Id serviceModelElementId) { + Optional templatesElementInfo = zusammenAdaptor + .getElementInfoByName(context, elementContext, serviceModelElementId, ElementType.Templates.name()); + if (templatesElementInfo.isPresent()) { + Collection elements = zusammenAdaptor.listElementData(context, elementContext, templatesElementInfo.get().getId()); + return elements.stream().collect(Collectors.toMap(element -> element.getInfo().getName(), this::elementToServiceTemplate)); + } + return null; + } - private Element buildServiceTemplateElement(String name, ServiceTemplate serviceTemplate, - String entryDefinitionServiceTemplate, - Action action) { - ZusammenElement zusammenElement = buildElement(null, action); - Info info = new Info(); - info.setName(name); - info.setDescription(serviceTemplate.getDescription()); - info.addProperty(ElementPropertyName.elementType.name(), ElementType.ServiceTemplate.name()); - info.addProperty(BASE_PROPERTY, entryDefinitionServiceTemplate); - String yaml = new ToscaExtensionYamlUtil().objectToYaml(serviceTemplate); - zusammenElement.setData(new ByteArrayInputStream(yaml.getBytes())); - zusammenElement.setInfo(info); - return zusammenElement; - } + private FileContentHandler getArtifacts(SessionContext context, ElementContext elementContext, Id serviceModelElementId) { + Optional artifactsElement = zusammenAdaptor + .getElementInfoByName(context, elementContext, serviceModelElementId, ElementType.Artifacts.name()); + if (artifactsElement.isPresent()) { + Collection elements = zusammenAdaptor.listElementData(context, elementContext, artifactsElement.get().getId()); + FileContentHandler fileContentHandler = new FileContentHandler(); + elements.forEach(element -> fileContentHandler.addFile(element.getInfo().getName(), element.getData())); + return fileContentHandler; + } + return null; + } - protected ZusammenElement buildArtifactElement(String name, byte[] artifact, Action action) { - ZusammenElement artifactElement = buildElement(null, action); - Info info = new Info(); - info.setName(name); - info.addProperty(ElementPropertyName.elementType.name(), ElementType.Artifact.name()); - artifactElement.setInfo(info); - artifactElement.setData(new ByteArrayInputStream(artifact)); + private ZusammenElement buildServiceModelElement(String entryDefinitionServiceTemplate) { + ZusammenElement serviceModelElement = buildStructuralElement(elementType, Action.UPDATE); + serviceModelElement.getInfo().addProperty(BASE_PROPERTY, entryDefinitionServiceTemplate); + return serviceModelElement; + } - return artifactElement; - } + private Element buildServiceTemplateElement(String name, ServiceTemplate serviceTemplate, String entryDefinitionServiceTemplate, Action action) { + ZusammenElement zusammenElement = buildElement(null, action); + Info info = new Info(); + info.setName(name); + info.setDescription(serviceTemplate.getDescription()); + info.addProperty(ElementPropertyName.elementType.name(), ElementType.ServiceTemplate.name()); + info.addProperty(BASE_PROPERTY, entryDefinitionServiceTemplate); + String yaml = new ToscaExtensionYamlUtil().objectToYaml(serviceTemplate); + zusammenElement.setData(new ByteArrayInputStream(yaml.getBytes())); + zusammenElement.setInfo(info); + return zusammenElement; + } + protected ZusammenElement buildArtifactElement(String name, byte[] artifact, Action action) { + ZusammenElement artifactElement = buildElement(null, action); + Info info = new Info(); + info.setName(name); + info.addProperty(ElementPropertyName.elementType.name(), ElementType.Artifact.name()); + artifactElement.setInfo(info); + artifactElement.setData(new ByteArrayInputStream(artifact)); + return artifactElement; + } - private ServiceTemplate elementToServiceTemplate(Element element) { - try { - String yamlContent = IOUtils.toString(element.getData()); - return new ToscaExtensionYamlUtil(). - yamlToObject(yamlContent, ServiceTemplate.class); - } catch (Exception e) { - throw new CoreException( - new RetrieveServiceTemplateFromDbErrorBuilder( - element.getInfo().getName(), e.getMessage()).build()); + private ServiceTemplate elementToServiceTemplate(Element element) { + try { + String yamlContent = IOUtils.toString(element.getData()); + return new ToscaExtensionYamlUtil().yamlToObject(yamlContent, ServiceTemplate.class); + } catch (Exception e) { + throw new CoreException(new RetrieveServiceTemplateFromDbErrorBuilder(element.getInfo().getName(), e.getMessage()).build()); + } } - } } diff --git a/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-impl/src/main/java/org/openecomp/sdc/model/impl/zusammen/StructureElement.java b/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-impl/src/main/java/org/openecomp/sdc/model/impl/zusammen/StructureElement.java index a0bbdfce8d..b894db9b93 100644 --- a/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-impl/src/main/java/org/openecomp/sdc/model/impl/zusammen/StructureElement.java +++ b/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-impl/src/main/java/org/openecomp/sdc/model/impl/zusammen/StructureElement.java @@ -7,9 +7,9 @@ * 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. @@ -17,14 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.model.impl.zusammen; -public enum StructureElement { - ServiceModel, - EnrichedServiceModel, - Artifacts, - Templates, - EntryDefinition, - -} +public enum StructureElement {ServiceModel, EnrichedServiceModel, Artifacts, Templates, EntryDefinition,} -- cgit 1.2.3-korg