6f1492c163f851865a10c3a08c3a9143ec53fd43
[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 package org.openecomp.sdc.model.impl.zusammen;
21
22 import static org.openecomp.core.zusammen.api.ZusammenUtil.buildStructuralElement;
23
24 import com.amdocs.zusammen.adaptor.inbound.api.types.item.ZusammenElement;
25 import com.amdocs.zusammen.datatypes.SessionContext;
26 import com.amdocs.zusammen.datatypes.item.Action;
27 import com.amdocs.zusammen.datatypes.item.ElementContext;
28 import org.openecomp.core.model.dao.EnrichedServiceModelDao;
29 import org.openecomp.core.model.types.ServiceArtifact;
30 import org.openecomp.core.model.types.ServiceElement;
31 import org.openecomp.core.utilities.file.FileUtils;
32 import org.openecomp.core.zusammen.api.ZusammenAdaptor;
33 import org.openecomp.core.zusammen.api.ZusammenUtil;
34 import org.openecomp.sdc.datatypes.model.ElementType;
35 import org.openecomp.sdc.logging.api.Logger;
36 import org.openecomp.sdc.logging.api.LoggerFactory;
37 import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel;
38
39 public class EnrichedServiceModelDaoZusammenImpl extends ServiceModelDaoZusammenImpl implements
40     EnrichedServiceModelDao<ToscaServiceModel, ServiceElement> {
41
42     private static final Logger logger = LoggerFactory.getLogger(EnrichedServiceModelDaoZusammenImpl.class);
43
44     public EnrichedServiceModelDaoZusammenImpl(ZusammenAdaptor zusammenAdaptor) {
45         super(zusammenAdaptor);
46         this.elementType = ElementType.EnrichedServiceModel;
47     }
48
49     @Override
50     public void storeExternalArtifact(ServiceArtifact serviceArtifact) {
51         ZusammenElement artifact = buildArtifactElement(serviceArtifact.getName(), FileUtils.toByteArray(serviceArtifact.getContent()),
52             Action.CREATE);
53         ZusammenElement artifacts = buildStructuralElement(ElementType.Artifacts, Action.IGNORE);
54         artifacts.addSubElement(artifact);
55         ZusammenElement enrichedServiceModel = buildStructuralElement(elementType, Action.IGNORE);
56         enrichedServiceModel.addSubElement(artifacts);
57         ZusammenElement vspModel = buildStructuralElement(ElementType.VspModel, Action.IGNORE);
58         vspModel.addSubElement(enrichedServiceModel);
59         SessionContext context = ZusammenUtil.createSessionContext();
60         ElementContext elementContext = new ElementContext(serviceArtifact.getVspId(), serviceArtifact.getVersion().getId());
61         zusammenAdaptor.saveElement(context, elementContext, vspModel, "add service external artifact.");
62         logger.info("Finished adding artifact to enriched service model for VendorSoftwareProduct id -> {}", elementContext.getItemId().getValue());
63     }
64 }