938f104b1e1d69b7fa4a101294dff53b3ed57bc1
[sdc.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.openecomp.sdc.model.impl.zusammen;
22
23 import com.amdocs.zusammen.adaptor.inbound.api.types.item.ZusammenElement;
24 import com.amdocs.zusammen.datatypes.SessionContext;
25 import com.amdocs.zusammen.datatypes.item.Action;
26 import com.amdocs.zusammen.datatypes.item.ElementContext;
27 import org.openecomp.core.model.dao.EnrichedServiceModelDao;
28 import org.openecomp.core.model.types.ServiceArtifact;
29 import org.openecomp.core.model.types.ServiceElement;
30 import org.openecomp.core.utilities.file.FileUtils;
31 import org.openecomp.core.zusammen.api.ZusammenAdaptor;
32 import org.openecomp.core.zusammen.api.ZusammenUtil;
33 import org.openecomp.sdc.datatypes.model.ElementType;
34 import org.openecomp.sdc.logging.api.Logger;
35 import org.openecomp.sdc.logging.api.LoggerFactory;
36 import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel;
37
38 import static org.openecomp.core.zusammen.api.ZusammenUtil.buildStructuralElement;
39
40 public class EnrichedServiceModelDaoZusammenImpl extends ServiceModelDaoZusammenImpl implements
41     EnrichedServiceModelDao<ToscaServiceModel, ServiceElement> {
42
43   private static final Logger logger =
44       LoggerFactory.getLogger(EnrichedServiceModelDaoZusammenImpl.class);
45
46   public EnrichedServiceModelDaoZusammenImpl(ZusammenAdaptor zusammenAdaptor) {
47     super(zusammenAdaptor);
48     this.elementType = ElementType.EnrichedServiceModel;
49   }
50
51   @Override
52   public void storeExternalArtifact(ServiceArtifact serviceArtifact) {
53     ZusammenElement artifact = buildArtifactElement(serviceArtifact.getName(),
54         FileUtils.toByteArray(serviceArtifact.getContent()), Action.CREATE);
55
56     ZusammenElement artifacts = buildStructuralElement(ElementType.Artifacts, Action.IGNORE);
57     artifacts.addSubElement(artifact);
58
59     ZusammenElement enrichedServiceModel = buildStructuralElement(elementType, Action.IGNORE);
60     enrichedServiceModel.addSubElement(artifacts);
61
62     ZusammenElement vspModel = buildStructuralElement(ElementType.VspModel, Action.IGNORE);
63     vspModel.addSubElement(enrichedServiceModel);
64
65     SessionContext context = ZusammenUtil.createSessionContext();
66     ElementContext elementContext =
67         new ElementContext(serviceArtifact.getVspId(), serviceArtifact.getVersion().getId());
68     zusammenAdaptor
69         .saveElement(context, elementContext, vspModel, "add service external artifact.");
70
71     logger.info(
72         "Finished adding artifact to enriched service model for VendorSoftwareProduct id -> {}",
73         elementContext.getItemId().getValue());
74   }
75 }