diff options
Diffstat (limited to 'openecomp-be/lib')
11 files changed, 375 insertions, 128 deletions
diff --git a/openecomp-be/lib/openecomp-sdc-datatypes-lib/src/main/java/org/openecomp/sdc/datatypes/model/ElementType.java b/openecomp-be/lib/openecomp-sdc-datatypes-lib/src/main/java/org/openecomp/sdc/datatypes/model/ElementType.java index 19d5656036..1eb688b057 100644 --- a/openecomp-be/lib/openecomp-sdc-datatypes-lib/src/main/java/org/openecomp/sdc/datatypes/model/ElementType.java +++ b/openecomp-be/lib/openecomp-sdc-datatypes-lib/src/main/java/org/openecomp/sdc/datatypes/model/ElementType.java @@ -1,3 +1,19 @@ +/* + * Copyright © 2016-2018 European Support Limited + * + * 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.openecomp.sdc.datatypes.model; public enum ElementType { @@ -15,8 +31,11 @@ public enum ElementType { VspModel, NetworkPackage, OrchestrationTemplateCandidate, OrchestrationTemplateCandidateContent, + OrchestrationTemplateCandidateValidationData, + OrchestrationTemplateStructure, OrchestrationTemplate, + OrchestrationTemplateValidationData, // todo - remove OrchestrationTemplateContent - OrchestrationTemplate, OrchestrationTemplateValidationData, OrchestrationTemplateContent, + OrchestrationTemplateContent, Networks, Network, Components, Component, ComponentQuestionnaire, ComponentDependencies, ComponentDependency, Nics, Nic, NicQuestionnaire, diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/OrchestrationTemplateCandidateDao.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/OrchestrationTemplateCandidateDao.java index 3d7c621d67..9743814b11 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/OrchestrationTemplateCandidateDao.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/OrchestrationTemplateCandidateDao.java @@ -1,25 +1,22 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ +/* + * Copyright © 2016-2018 European Support Limited + * * 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.vendorsoftwareproduct.dao; +import org.openecomp.sdc.heat.datatypes.structure.ValidationStructureList; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.OrchestrationTemplateCandidateData; import org.openecomp.sdc.vendorsoftwareproduct.types.candidateheat.FilesDataStructure; import org.openecomp.sdc.versioning.dao.VersionableDao; @@ -33,10 +30,15 @@ public interface OrchestrationTemplateCandidateDao extends VersionableDao { OrchestrationTemplateCandidateData getInfo(String vspId, Version version); + void delete(String vspId, Version version); + void update(String vspId, Version version, OrchestrationTemplateCandidateData candidateData); void updateStructure(String vspId, Version version, FilesDataStructure fileDataStructure); Optional<String> getStructure(String vspId, Version version); + + void updateValidationData(String vspId, Version version, ValidationStructureList + validationData); } diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/OrchestrationTemplateDao.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/OrchestrationTemplateDao.java index 4d82ed37af..ddee436331 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/OrchestrationTemplateDao.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/OrchestrationTemplateDao.java @@ -1,21 +1,17 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ +/* + * Copyright © 2016-2018 European Support Limited + * * 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.vendorsoftwareproduct.dao; @@ -24,6 +20,8 @@ import org.openecomp.sdc.vendorsoftwareproduct.dao.type.OrchestrationTemplateEnt import org.openecomp.sdc.versioning.dao.VersionableDao; import org.openecomp.sdc.versioning.dao.types.Version; +import java.util.Optional; + public interface OrchestrationTemplateDao extends VersionableDao { OrchestrationTemplateEntity getInfo(String vspId, Version version); @@ -31,5 +29,7 @@ public interface OrchestrationTemplateDao extends VersionableDao { OrchestrationTemplateEntity get(String vspId, Version version); void update(String vspId, Version version, OrchestrationTemplateEntity uploadData); + + Optional<String> getOrchestrationTemplateStructure(String vspId, Version version); } diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/type/OrchestrationTemplateCandidateData.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/type/OrchestrationTemplateCandidateData.java index 7b19e8630c..398d84c8e5 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/type/OrchestrationTemplateCandidateData.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/type/OrchestrationTemplateCandidateData.java @@ -1,5 +1,24 @@ +/* + * Copyright © 2016-2018 European Support Limited + * + * 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.openecomp.sdc.vendorsoftwareproduct.dao.type; +import org.openecomp.core.utilities.json.JsonUtil; +import org.openecomp.sdc.heat.datatypes.structure.ValidationStructureList; + import java.nio.ByteBuffer; public class OrchestrationTemplateCandidateData { @@ -7,6 +26,7 @@ public class OrchestrationTemplateCandidateData { private String filesDataStructure; private String fileSuffix; private String fileName; + private String validationData; public OrchestrationTemplateCandidateData() { } @@ -50,4 +70,22 @@ public class OrchestrationTemplateCandidateData { public void setFileName(String fileName) { this.fileName = fileName; } + + public String getValidationData() { + return validationData; + } + + public void setValidationData(String validationData) { + this.validationData = validationData; + } + + public ValidationStructureList getValidationDataStructure() { + return validationData == null ? null + : JsonUtil.json2Object(validationData, ValidationStructureList.class); + } + + public void setValidationDataStructure(ValidationStructureList validationData) { + this.validationData = validationData == null ? null + : JsonUtil.object2Json(validationData); + } } diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/type/OrchestrationTemplateEntity.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/type/OrchestrationTemplateEntity.java index ef3a4b6012..1bbe1b0ddf 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/type/OrchestrationTemplateEntity.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/type/OrchestrationTemplateEntity.java @@ -1,9 +1,6 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ +/* + * Copyright © 2016-2018 European Support Limited + * * 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 @@ -15,7 +12,6 @@ * 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.vendorsoftwareproduct.dao.type; @@ -38,8 +34,10 @@ public class OrchestrationTemplateEntity implements VersionableEntity { private String packageVersion; private String validationData; private ByteBuffer contentData; + private String filesDataStructure; public OrchestrationTemplateEntity() { + //default constructor implementation is not provided for OrchestrationTemplateEntity } public OrchestrationTemplateEntity(String id, Version version) { @@ -57,10 +55,12 @@ public class OrchestrationTemplateEntity implements VersionableEntity { return getId(); } + @Override public String getId() { return id; } + @Override public void setId(String id) { this.id = id; } @@ -132,4 +132,12 @@ public class OrchestrationTemplateEntity implements VersionableEntity { public void setContentData(ByteBuffer contentData) { this.contentData = contentData; } + + public String getFilesDataStructure() { + return filesDataStructure; + } + + public void setFilesDataStructure(String filesDataStructure) { + this.filesDataStructure = filesDataStructure; + } } diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/filedatastructuremodule/CandidateService.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/filedatastructuremodule/CandidateService.java index 08dc908a3f..f3d2916636 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/filedatastructuremodule/CandidateService.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/filedatastructuremodule/CandidateService.java @@ -1,21 +1,17 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ +/* + * Copyright © 2016-2018 European Support Limited + * * 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.vendorsoftwareproduct.services.filedatastructuremodule; @@ -24,6 +20,7 @@ import org.openecomp.core.utilities.file.FileContentHandler; import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum; import org.openecomp.sdc.datatypes.error.ErrorMessage; import org.openecomp.sdc.heat.datatypes.manifest.ManifestContent; +import org.openecomp.sdc.heat.datatypes.structure.ValidationStructureList; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.OrchestrationTemplateCandidateData; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; import org.openecomp.sdc.vendorsoftwareproduct.types.CandidateDataEntityTo; @@ -64,6 +61,8 @@ public interface CandidateService { OrchestrationTemplateCandidateData getOrchestrationTemplateCandidateInfo(String vspId, Version version); + void deleteOrchestrationTemplateCandidate(String vspId, Version version); + Optional<ByteArrayInputStream> fetchZipFileByteArrayInputStream(String vspId, OrchestrationTemplateCandidateData candidateDataEntity, String manifest, @@ -80,4 +79,6 @@ public interface CandidateService { String createManifest(VspDetails vspDetails, FilesDataStructure structure); Optional<List<ErrorMessage>> validateFileDataStructure(FilesDataStructure filesDataStructure); + + void updateValidationData(String vspId, Version version, ValidationStructureList validationData); } diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/zusammen/OrchestrationTemplateCandidateDaoZusammenImpl.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/zusammen/OrchestrationTemplateCandidateDaoZusammenImpl.java index a0c3fd4032..bf592e2169 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/zusammen/OrchestrationTemplateCandidateDaoZusammenImpl.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/zusammen/OrchestrationTemplateCandidateDaoZusammenImpl.java @@ -1,3 +1,19 @@ +/* + * Copyright © 2016-2018 European Support Limited + * + * 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.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen; import com.amdocs.zusammen.adaptor.inbound.api.types.item.Element; @@ -7,10 +23,10 @@ import com.amdocs.zusammen.datatypes.SessionContext; import com.amdocs.zusammen.datatypes.item.Action; import com.amdocs.zusammen.datatypes.item.ElementContext; import com.amdocs.zusammen.utils.fileutils.FileUtils; -import org.apache.commons.io.IOUtils; import org.openecomp.core.utilities.json.JsonUtil; import org.openecomp.core.zusammen.api.ZusammenAdaptor; import org.openecomp.sdc.datatypes.model.ElementType; +import org.openecomp.sdc.heat.datatypes.structure.ValidationStructureList; import org.openecomp.sdc.logging.api.Logger; import org.openecomp.sdc.logging.api.LoggerFactory; import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateCandidateDao; @@ -19,10 +35,8 @@ import org.openecomp.sdc.vendorsoftwareproduct.types.candidateheat.FilesDataStru import org.openecomp.sdc.versioning.dao.types.Version; import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; import java.nio.ByteBuffer; -import java.util.Arrays; +import java.util.Collection; import java.util.Optional; import static org.openecomp.core.zusammen.api.ZusammenUtil.buildStructuralElement; @@ -36,6 +50,8 @@ public class OrchestrationTemplateCandidateDaoZusammenImpl private ZusammenAdaptor zusammenAdaptor; + private static final String EMPTY_DATA = "{}"; + public OrchestrationTemplateCandidateDaoZusammenImpl(ZusammenAdaptor zusammenAdaptor) { this.zusammenAdaptor = zusammenAdaptor; } @@ -56,25 +72,38 @@ public class OrchestrationTemplateCandidateDaoZusammenImpl zusammenAdaptor.getElementByName(context, elementContext, null, ElementType.OrchestrationTemplateCandidate.name()); if (candidateElement.isPresent()) { - if (hasEmptyData(candidateElement.get().getData())) { + if (VspZusammenUtil.hasEmptyData(candidateElement.get().getData())) { return null; } OrchestrationTemplateCandidateData candidateData = new OrchestrationTemplateCandidateData(); candidateData.setFilesDataStructure( new String(FileUtils.toByteArray(candidateElement.get().getData()))); - Optional<Element> candidateContentElement = zusammenAdaptor - .getElementByName(context, elementContext, candidateElement.get().getElementId(), - ElementType.OrchestrationTemplateCandidateContent.name()); - - if (candidateContentElement.isPresent()) { - candidateData.setContentData( - ByteBuffer.wrap(FileUtils.toByteArray(candidateContentElement.get().getData()))); - candidateData.setFileSuffix(candidateContentElement.get().getInfo() - .getProperty(InfoPropertyName.FILE_SUFFIX.getVal())); - candidateData.setFileName(candidateContentElement.get().getInfo() - .getProperty(InfoPropertyName.FILE_NAME.getVal())); + Collection<Element> subElements = candidateElement.get().getSubElements(); + if (subElements.isEmpty()) { + return candidateData; + } + + for (Element element : subElements) { + Optional<Element> subElement = zusammenAdaptor.getElement(context, + elementContext, element.getElementId().toString()); + + if (subElement.get().getInfo().getName() + .equals(ElementType.OrchestrationTemplateCandidateContent + .name())) { + candidateData.setContentData( + ByteBuffer.wrap(FileUtils.toByteArray(subElement.get().getData()))); + candidateData.setFileSuffix(subElement.get().getInfo() + .getProperty(InfoPropertyName.FILE_SUFFIX.getVal())); + candidateData.setFileName(subElement.get().getInfo() + .getProperty(InfoPropertyName.FILE_NAME.getVal())); + } else if (subElement.get().getInfo().getName() + .equals(ElementType.OrchestrationTemplateCandidateValidationData.name())) { + candidateData.setValidationData(new String(FileUtils.toByteArray(subElement + .get().getData()))); + } } + logger .info("Finished getting orchestration template for VendorSoftwareProduct id -> " + vspId); return candidateData; @@ -91,22 +120,36 @@ public class OrchestrationTemplateCandidateDaoZusammenImpl SessionContext context = createSessionContext(); ElementContext elementContext = new ElementContext(vspId, version.getId()); + OrchestrationTemplateCandidateData candidateData = new OrchestrationTemplateCandidateData(); + Optional<ElementInfo> candidateElement = zusammenAdaptor.getElementInfoByName(context, elementContext, null, ElementType.OrchestrationTemplateCandidate.name()); - if (candidateElement.isPresent()) { - OrchestrationTemplateCandidateData candidateData = new OrchestrationTemplateCandidateData(); - Optional<Element> candidateContentElement = zusammenAdaptor - .getElementByName(context, elementContext, candidateElement.get().getId(), - ElementType.OrchestrationTemplateCandidateContent.name()); + if (candidateElement.isPresent()) { + Collection<ElementInfo> subElements = candidateElement.get().getSubElements(); + if (subElements.isEmpty()) { + return candidateData; + } - if (candidateContentElement.isPresent()) { - candidateData.setFileSuffix(candidateContentElement.get().getInfo() - .getProperty(InfoPropertyName.FILE_SUFFIX.getVal())); - candidateData.setFileName(candidateContentElement.get().getInfo() - .getProperty(InfoPropertyName.FILE_NAME.getVal())); + for (ElementInfo elementInfo : subElements) { + Optional<Element> subElement = zusammenAdaptor.getElement(context, + elementContext, elementInfo.getId().toString()); + + if (subElement.get().getInfo().getName().equals(ElementType + .OrchestrationTemplateCandidateContent.name())) { + + candidateData.setFileSuffix(subElement.get().getInfo() + .getProperty(InfoPropertyName.FILE_SUFFIX.getVal())); + candidateData.setFileName(subElement.get().getInfo() + .getProperty(InfoPropertyName.FILE_NAME.getVal())); + } else if (subElement.get().getInfo().getName().equals(ElementType + .OrchestrationTemplateCandidateValidationData.name())) { + candidateData.setValidationData(new String(FileUtils.toByteArray(subElement.get() + .getData()))); + } } + logger.info( "Finished getting orchestration template info for VendorSoftwareProduct id -> " + vspId); return candidateData; @@ -118,6 +161,30 @@ public class OrchestrationTemplateCandidateDaoZusammenImpl } @Override + public void delete(String vspId, Version version) { + ByteArrayInputStream emptyData = new ByteArrayInputStream(EMPTY_DATA.getBytes()); + + ZusammenElement candidateContentElement = + buildStructuralElement(ElementType.OrchestrationTemplateCandidateContent, Action.UPDATE); + candidateContentElement.setData(emptyData); + + ZusammenElement validationData = buildStructuralElement(ElementType + .OrchestrationTemplateCandidateValidationData, Action.UPDATE); + validationData.setData(emptyData); + + ZusammenElement candidateElement = + buildStructuralElement(ElementType.OrchestrationTemplateCandidate, Action.UPDATE); + candidateElement.setData(emptyData); + candidateElement.addSubElement(candidateContentElement); + candidateElement.addSubElement(validationData); + + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(vspId, version.getId()); + zusammenAdaptor.saveElement(context, elementContext, candidateElement, + "Delete Orchestration Template Candidate Elements's content"); + } + + @Override public void update(String vspId, Version version, OrchestrationTemplateCandidateData candidateData) { logger.info("Uploading candidate data entity for VendorSoftwareProduct id -> " + vspId); @@ -135,8 +202,15 @@ public class OrchestrationTemplateCandidateDaoZusammenImpl .addProperty(InfoPropertyName.FILE_SUFFIX.getVal(), candidateData.getFileSuffix()); candidateContentElement.getInfo() .addProperty(InfoPropertyName.FILE_NAME.getVal(), candidateData.getFileName()); - candidateElement.addSubElement(candidateContentElement); + ZusammenElement validationData = buildStructuralElement(ElementType + .OrchestrationTemplateCandidateValidationData, Action.UPDATE); + if (candidateData.getValidationData() != null) { + validationData + .setData(new ByteArrayInputStream(candidateData.getValidationData().getBytes())); + } + candidateElement.addSubElement(candidateContentElement); + candidateElement.addSubElement(validationData); SessionContext context = createSessionContext(); ElementContext elementContext = new ElementContext(vspId, version.getId()); zusammenAdaptor.saveElement(context, elementContext, candidateElement, @@ -145,6 +219,28 @@ public class OrchestrationTemplateCandidateDaoZusammenImpl .info("Finished uploading candidate data entity for VendorSoftwareProduct id -> " + vspId); } + @Override + public void updateValidationData(String vspId, Version version, ValidationStructureList + validationData) { + logger.info("Updating validation data of orchestration template candidate for VSP id -> " + + vspId); + + ZusammenElement validationDataElement = buildStructuralElement(ElementType + .OrchestrationTemplateCandidateValidationData, Action.UPDATE); + validationDataElement.setData(validationData == null ? new ByteArrayInputStream(EMPTY_DATA + .getBytes()) : new ByteArrayInputStream(JsonUtil.object2Json(validationData).getBytes())); + + ZusammenElement candidateElement = + buildStructuralElement(ElementType.OrchestrationTemplateCandidate, Action.IGNORE); + candidateElement.addSubElement(validationDataElement); + + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(vspId, version.getId()); + zusammenAdaptor.saveElement(context, elementContext, candidateElement, + "Update Orchestration Template Candidate validation data"); + logger.info("Finished updating validation data of orchestration template candidate for VSP " + + "id -> " + vspId); + } @Override public void updateStructure(String vspId, Version version, FilesDataStructure fileDataStructure) { @@ -166,40 +262,24 @@ public class OrchestrationTemplateCandidateDaoZusammenImpl @Override public Optional<String> getStructure(String vspId, Version version) { - logger - .info("Getting orchestration template structure for VendorSoftwareProduct id -> " + vspId); + logger.info("Getting orchestration template candidate structure for VendorSoftwareProduct id " + + "-> " + vspId); SessionContext context = createSessionContext(); ElementContext elementContext = new ElementContext(vspId, version.getId()); - logger.info( - "Finished getting orchestration template structure for VendorSoftwareProduct id -> " + - vspId); Optional<Element> element = zusammenAdaptor.getElementByName(context, elementContext, null, ElementType.OrchestrationTemplateCandidate.name()); - if (element.isPresent()) { - if (hasEmptyData(element.get().getData())) { - return Optional.empty(); - } + + if (element.isPresent() && !VspZusammenUtil.isEmpty(element.get().getData())) { return Optional.of(new String(FileUtils.toByteArray(element.get().getData()))); - } else { - return Optional.empty(); } - } - private boolean hasEmptyData(InputStream elementData) { - String emptyData = "{}"; - byte[] byteElementData; - try { - byteElementData = IOUtils.toByteArray(elementData); - } catch (IOException ex) { - ex.printStackTrace(); - return false; - } - if (Arrays.equals(emptyData.getBytes(), byteElementData)) { - return true; - } - return false; + logger.info( + "Finished getting orchestration template candidate structure for VendorSoftwareProduct " + + "id -> " + vspId); + + return Optional.empty(); } public enum InfoPropertyName { @@ -209,7 +289,7 @@ public class OrchestrationTemplateCandidateDaoZusammenImpl private String val; InfoPropertyName(String val){ - this.val=val; + this.val = val; } public String getVal() { diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/zusammen/OrchestrationTemplateDaoZusammenImpl.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/zusammen/OrchestrationTemplateDaoZusammenImpl.java index d5e09ac298..3b3cdfead3 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/zusammen/OrchestrationTemplateDaoZusammenImpl.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/zusammen/OrchestrationTemplateDaoZusammenImpl.java @@ -1,3 +1,19 @@ +/* + * Copyright © 2016-2018 European Support Limited + * + * 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.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen; import com.amdocs.zusammen.adaptor.inbound.api.types.item.Element; @@ -7,18 +23,16 @@ import com.amdocs.zusammen.datatypes.SessionContext; import com.amdocs.zusammen.datatypes.item.Action; import com.amdocs.zusammen.datatypes.item.ElementContext; import com.amdocs.zusammen.utils.fileutils.FileUtils; -import org.apache.commons.io.IOUtils; import org.openecomp.core.zusammen.api.ZusammenAdaptor; import org.openecomp.sdc.datatypes.model.ElementType; +import org.openecomp.sdc.logging.api.Logger; +import org.openecomp.sdc.logging.api.LoggerFactory; import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.OrchestrationTemplateEntity; import org.openecomp.sdc.versioning.dao.types.Version; import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; import java.nio.ByteBuffer; -import java.util.Arrays; import java.util.Optional; import static org.openecomp.core.zusammen.api.ZusammenUtil.buildStructuralElement; @@ -26,6 +40,8 @@ import static org.openecomp.core.zusammen.api.ZusammenUtil.createSessionContext; public class OrchestrationTemplateDaoZusammenImpl implements OrchestrationTemplateDao { + private static final Logger LOGGER = LoggerFactory.getLogger + (OrchestrationTemplateDaoZusammenImpl.class); private ZusammenAdaptor zusammenAdaptor; public OrchestrationTemplateDaoZusammenImpl(ZusammenAdaptor zusammenAdaptor) { @@ -67,7 +83,7 @@ public class OrchestrationTemplateDaoZusammenImpl implements OrchestrationTempla .setFileSuffix(element.get().getInfo().getProperty(InfoPropertyName.FILE_SUFFIX.getVal())); orchestrationTemplate .setFileName(element.get().getInfo().getProperty(InfoPropertyName.FILE_NAME.getVal())); - if (!hasEmptyData(element.get().getData())) { + if (!VspZusammenUtil.hasEmptyData(element.get().getData())) { orchestrationTemplate .setValidationData(new String(FileUtils.toByteArray(element.get().getData()))); } @@ -94,7 +110,7 @@ public class OrchestrationTemplateDaoZusammenImpl implements OrchestrationTempla return orchestrationTemplate; } - if (!hasEmptyData(orchestrationTemplateElement.get().getData())) { + if (!VspZusammenUtil.hasEmptyData(orchestrationTemplateElement.get().getData())) { orchestrationTemplate.setContentData( ByteBuffer.wrap(FileUtils.toByteArray(orchestrationTemplateElement.get().getData()))); } @@ -108,7 +124,7 @@ public class OrchestrationTemplateDaoZusammenImpl implements OrchestrationTempla .getProperty(InfoPropertyName.FILE_SUFFIX.getVal())); orchestrationTemplate.setFileName(validationDataElement.get().getInfo() .getProperty(InfoPropertyName.FILE_NAME.getVal())); - if (!hasEmptyData(validationDataElement.get().getData())) { + if (!VspZusammenUtil.hasEmptyData(validationDataElement.get().getData())) { orchestrationTemplate.setValidationData( new String(FileUtils.toByteArray(validationDataElement.get().getData()))); } @@ -130,32 +146,55 @@ public class OrchestrationTemplateDaoZusammenImpl implements OrchestrationTempla .addProperty(InfoPropertyName.FILE_SUFFIX.getVal(), orchestrationTemplate.getFileSuffix()); validationData.getInfo() .addProperty(InfoPropertyName.FILE_NAME.getVal(), orchestrationTemplate.getFileName()); - + ZusammenElement orchestrationTemplateStructure = buildStructuralElement(ElementType + .OrchestrationTemplateStructure, Action.UPDATE); + orchestrationTemplateStructure + .setData(new ByteArrayInputStream(orchestrationTemplate.getFilesDataStructure() + .getBytes())); ZusammenElement orchestrationTemplateElement = buildStructuralElement(ElementType.OrchestrationTemplate, Action.UPDATE); orchestrationTemplateElement .setData(new ByteArrayInputStream(orchestrationTemplate.getContentData().array())); orchestrationTemplateElement.addSubElement(validationData); - + orchestrationTemplateElement.addSubElement(orchestrationTemplateStructure); ZusammenElement vspModel = buildStructuralElement(ElementType.VspModel, Action.IGNORE); vspModel.addSubElement(orchestrationTemplateElement); zusammenAdaptor.saveElement(context, elementContext, vspModel, "Update Orchestration Template"); } - private boolean hasEmptyData(InputStream elementData) { - String emptyData = "{}"; - byte[] byteElementData; - try { - byteElementData = IOUtils.toByteArray(elementData); - } catch (IOException ex) { - ex.printStackTrace(); - return false; + @Override + public Optional<String> getOrchestrationTemplateStructure(String vspId, Version version) { + LOGGER.info("Getting orchestration template structure for VendorSoftwareProduct id" + + " " + "-> " + vspId); + + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(vspId, version.getId()); + + Optional<ElementInfo> vspModel = zusammenAdaptor.getElementInfoByName(context, elementContext, + null, ElementType.VspModel.name()); + if (!vspModel.isPresent()) { + return Optional.empty(); } - if (Arrays.equals(emptyData.getBytes(), byteElementData)) { - return true; + Optional<Element> orchestrationTemplateElement = zusammenAdaptor.getElementByName(context, + elementContext, vspModel.get().getId(), ElementType.OrchestrationTemplate.name()); + if (!orchestrationTemplateElement.isPresent()) { + return Optional.empty(); } - return false; + + Optional<Element> orchestrationTemplateStructureElement = zusammenAdaptor + .getElementByName(context, elementContext, + orchestrationTemplateElement.get().getElementId(), + ElementType.OrchestrationTemplateStructure.name()); + if (orchestrationTemplateStructureElement.isPresent() && + !VspZusammenUtil.isEmpty(orchestrationTemplateStructureElement.get().getData())) { + return Optional.of(new String( + FileUtils.toByteArray(orchestrationTemplateStructureElement.get().getData()))); + } + LOGGER.info("Finished getting orchestration template structure for VendorSoftwareProduct " + + "id -> " + vspId); + + return Optional.empty(); } private enum InfoPropertyName { diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/zusammen/VendorSoftwareProductInfoDaoZusammenImpl.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/zusammen/VendorSoftwareProductInfoDaoZusammenImpl.java index c6909d8d07..8d9a8eed93 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/zusammen/VendorSoftwareProductInfoDaoZusammenImpl.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/zusammen/VendorSoftwareProductInfoDaoZusammenImpl.java @@ -1,3 +1,18 @@ +/* + * Copyright © 2016-2018 European Support Limited + * + * 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.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen; import com.amdocs.zusammen.adaptor.inbound.api.types.item.ZusammenElement; @@ -84,12 +99,13 @@ public class VendorSoftwareProductInfoDaoZusammenImpl implements VendorSoftwareP ZusammenElement candidateContentElement = buildStructuralElement(ElementType.OrchestrationTemplateCandidateContent, Action.CREATE); candidateContentElement.setData(emptyData); - + ZusammenElement validationData = buildStructuralElement(ElementType + .OrchestrationTemplateCandidateValidationData, Action.CREATE); ZusammenElement candidateElement = buildStructuralElement(ElementType.OrchestrationTemplateCandidate, Action.CREATE); candidateElement.setData(emptyData); candidateElement.addSubElement(candidateContentElement); - + candidateElement.addSubElement(validationData); zusammenAdaptor.saveElement(context, elementContext, candidateElement, "Create Orchestration Template Candidate Elements"); } @@ -119,10 +135,15 @@ public class VendorSoftwareProductInfoDaoZusammenImpl implements VendorSoftwareP buildStructuralElement(ElementType.OrchestrationTemplateValidationData, Action.CREATE); validationData.setData(emptyData); + ZusammenElement orchestrationTemplateStructure = buildStructuralElement(ElementType + .OrchestrationTemplateStructure, Action.CREATE); + validationData.setData(emptyData); + ZusammenElement orchestrationTemplate = buildStructuralElement(ElementType.OrchestrationTemplate, Action.CREATE); orchestrationTemplate.setData(emptyData); orchestrationTemplate.addSubElement(validationData); + orchestrationTemplate.addSubElement(orchestrationTemplateStructure); return orchestrationTemplate; } @@ -199,7 +220,7 @@ public class VendorSoftwareProductInfoDaoZusammenImpl implements VendorSoftwareP public boolean isManual(String vspId, Version version) { final VspDetails vspDetails = get(new VspDetails(vspId, version)); if (vspDetails != null && "Manual".equals(vspDetails.getOnboardingMethod())) { - return true; + return true; } return false; } @@ -248,6 +269,7 @@ public class VendorSoftwareProductInfoDaoZusammenImpl implements VendorSoftwareP ON_BOARDING_METHOD("onboardingMethod"); private String value; + InfoPropertyName(String value){ this.value=value; } diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/zusammen/VspZusammenUtil.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/zusammen/VspZusammenUtil.java index b3acaf5421..09fd948030 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/zusammen/VspZusammenUtil.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/zusammen/VspZusammenUtil.java @@ -1,7 +1,12 @@ package org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen; import com.amdocs.zusammen.adaptor.inbound.api.types.item.ZusammenElement; +import org.apache.commons.io.IOUtils; +import org.apache.commons.lang.ArrayUtils; +import java.io.IOException; +import java.io.InputStream; +import java.util.Arrays; import java.util.Objects; class VspZusammenUtil { @@ -24,4 +29,31 @@ class VspZusammenUtil { return head; } + + static boolean isEmpty(InputStream elementData) { + byte[] byteElementData; + if (Objects.isNull(elementData)) { + return true; + } + try { + byteElementData = IOUtils.toByteArray(elementData); + } catch (IOException e) { + return false; + } + return ArrayUtils.isEmpty(byteElementData); + } + + static boolean hasEmptyData(InputStream elementData) { + String EMPTY_DATA = "{}"; + byte[] byteElementData; + try { + byteElementData = IOUtils.toByteArray(elementData); + } catch (IOException ex) { + return false; + } + if (Arrays.equals(EMPTY_DATA.getBytes(), byteElementData)) { + return true; + } + return false; + } } diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/filedatastructuremodule/CandidateServiceImpl.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/filedatastructuremodule/CandidateServiceImpl.java index 78723ae0d2..18910e3507 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/filedatastructuremodule/CandidateServiceImpl.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/filedatastructuremodule/CandidateServiceImpl.java @@ -1,21 +1,17 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ +/* + * Copyright © 2016-2018 European Support Limited + * * 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.vendorsoftwareproduct.services.impl.filedatastructuremodule; @@ -35,6 +31,7 @@ import org.openecomp.sdc.heat.datatypes.manifest.FileData; import org.openecomp.sdc.heat.datatypes.manifest.ManifestContent; import org.openecomp.sdc.heat.datatypes.structure.Artifact; import org.openecomp.sdc.heat.datatypes.structure.HeatStructureTree; +import org.openecomp.sdc.heat.datatypes.structure.ValidationStructureList; import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateCandidateDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateCandidateDaoFactory; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.OrchestrationTemplateCandidateData; @@ -136,12 +133,11 @@ public class CandidateServiceImpl implements CandidateService { analyzedZipHeatFiles); handleOtherResources(tree, usedEnvFiles, structure); FilesDataStructure fileDataStructureFromManifest = - createFileDataStructureFromManifest(zipContentMap.getFileContent - (SdcCommon.MANIFEST_NAME)); + createFileDataStructureFromManifest(zipContentMap.getFileContent(SdcCommon.MANIFEST_NAME)); List<String> structureArtifacts = structure.getArtifacts(); structureArtifacts.addAll(fileDataStructureFromManifest.getArtifacts().stream().filter (artifact -> isNotStrctureArtifact(structureArtifacts, artifact)) - .collect((Collectors.toList()))); + .collect(Collectors.toList())); handleArtifactsFromTree(tree, structure); return JsonUtil.object2Json(structure); @@ -167,9 +163,9 @@ public class CandidateServiceImpl implements CandidateService { zipContentMap, analyzedZipHeatFiles); Set<String> filesDataStructureFiles = getFlatFileNames(filesDataStructure); filesDataStructure.getUnassigned().addAll(zipFileList.stream() - .filter(fileName -> (!filesDataStructureFiles.contains(fileName) && - !filesDataStructure.getNested().contains(fileName) && - !fileName.equals(SdcCommon.MANIFEST_NAME))) + .filter(fileName -> (!filesDataStructureFiles.contains(fileName) + && !filesDataStructure.getNested().contains(fileName) + && !fileName.equals(SdcCommon.MANIFEST_NAME))) .collect(Collectors.toList())); dataStructureJson = JsonUtil.object2Json(filesDataStructure); } else { @@ -290,8 +286,7 @@ public class CandidateServiceImpl implements CandidateService { for (FileData fileData : data) { if (fileData.getType().equals(FileData.Type.HEAT_ENV)) { module.setEnv(fileData.getFile()); - } else if (fileData.getType().equals(FileData.Type.HEAT_VOL))// must be volume - { + } else if (fileData.getType().equals(FileData.Type.HEAT_VOL)) { // must be volume module.setVol(fileData.getFile()); if (!CollectionUtils.isEmpty(fileData.getData())) { FileData volEnv = fileData.getData().get(0); @@ -432,6 +427,17 @@ public class CandidateServiceImpl implements CandidateService { return candidateServiceValidator.validateFileDataStructure(filesDataStructure); } + @Override + public void deleteOrchestrationTemplateCandidate(String vspId, Version versionId) { + orchestrationTemplateCandidateDao.delete(vspId, versionId); + } + + @Override + public void updateValidationData(String vspId, Version version, ValidationStructureList + validationData) { + orchestrationTemplateCandidateDao.updateValidationData(vspId, version, validationData); + } + private void writeManifest(String manifest, OnboardingTypesEnum type, ZipOutputStream zos) throws IOException { |