2 * Copyright © 2016-2018 European Support Limited
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.openecomp.sdc.vendorlicense.dao.impl.zusammen;
19 import com.amdocs.zusammen.adaptor.inbound.api.types.item.ZusammenElement;
20 import com.amdocs.zusammen.datatypes.SessionContext;
21 import com.amdocs.zusammen.datatypes.item.Action;
22 import com.amdocs.zusammen.datatypes.item.ElementContext;
23 import com.amdocs.zusammen.datatypes.item.Info;
24 import org.openecomp.core.zusammen.api.ZusammenAdaptor;
25 import org.openecomp.core.zusammen.api.ZusammenUtil;
26 import org.openecomp.sdc.datatypes.model.ElementType;
27 import org.openecomp.sdc.vendorlicense.dao.VendorLicenseModelDao;
28 import org.openecomp.sdc.vendorlicense.dao.impl.zusammen.convertor.ElementToVLMGeneralConvertor;
29 import org.openecomp.sdc.vendorlicense.dao.types.VendorLicenseModelEntity;
30 import org.openecomp.sdc.versioning.ActionVersioningManagerFactory;
31 import org.openecomp.sdc.versioning.types.VersionableEntityMetadata;
32 import org.openecomp.sdc.versioning.types.VersionableEntityStoreType;
34 import java.util.Collection;
35 import java.util.stream.Collectors;
37 public class VendorLicenseModelDaoZusammenImpl implements VendorLicenseModelDao {
39 private ZusammenAdaptor zusammenAdaptor;
41 public VendorLicenseModelDaoZusammenImpl(ZusammenAdaptor zusammenAdaptor) {
42 this.zusammenAdaptor = zusammenAdaptor;
46 public void registerVersioning(String versionableEntityType) {
47 VersionableEntityMetadata metadata =
48 new VersionableEntityMetadata(VersionableEntityStoreType.Zusammen, "VendorLicenseModel",
51 ActionVersioningManagerFactory.getInstance().createInterface()
52 .register(versionableEntityType, metadata);
56 public Collection<VendorLicenseModelEntity> list(
57 VendorLicenseModelEntity vendorLicenseModelEntity) {
59 ElementToVLMGeneralConvertor convertor = new ElementToVLMGeneralConvertor();
60 return zusammenAdaptor.listItems(ZusammenUtil.createSessionContext()).stream()
61 .filter(item -> "VendorLicenseModel".equals(item.getInfo().getProperty("item_type")))
63 VendorLicenseModelEntity entity = convertor.convert(item);
64 entity.setId(item.getId().getValue());
65 entity.setVersion(null);
68 .collect(Collectors.toList());
72 public void create(VendorLicenseModelEntity vendorLicenseModel) {
74 SessionContext context = ZusammenUtil.createSessionContext();
76 ElementContext elementContext = new ElementContext(vendorLicenseModel.getId(),
77 vendorLicenseModel.getVersion().getId());
79 ZusammenElement generalElement = mapVlmToZusammenElement(vendorLicenseModel, Action.CREATE);
81 zusammenAdaptor.saveElement(context, elementContext, generalElement,
82 "Create VLM General Info Element");
84 ZusammenElement licenseAgreementsElement =
85 ZusammenUtil.buildStructuralElement(ElementType.LicenseAgreements, Action.CREATE);
87 zusammenAdaptor.saveElement(context, elementContext, licenseAgreementsElement,
88 "Create VLM licenseAgreementsElement");
90 ZusammenElement featureGroupsElement =
91 ZusammenUtil.buildStructuralElement(ElementType.FeatureGroups, Action.CREATE);
93 zusammenAdaptor.saveElement(context, elementContext, featureGroupsElement,
94 "Create VLM featureGroupsElement");
96 ZusammenElement lkgsElement =
97 ZusammenUtil.buildStructuralElement(ElementType.LicenseKeyGroups, Action.CREATE);
99 zusammenAdaptor.saveElement(context, elementContext, lkgsElement,
100 "Create VLM lkgsElement");
102 ZusammenElement entitlementPoolsElement =
103 ZusammenUtil.buildStructuralElement(ElementType.EntitlementPools, Action.CREATE);
105 zusammenAdaptor.saveElement(context, elementContext, entitlementPoolsElement,
106 "Create VLM entitlementPoolsElement");
110 public void update(VendorLicenseModelEntity vendorLicenseModel) {
111 ZusammenElement generalElement = mapVlmToZusammenElement(vendorLicenseModel, Action.UPDATE);
113 SessionContext context = ZusammenUtil.createSessionContext();
114 zusammenAdaptor.saveElement(context,
115 new ElementContext(vendorLicenseModel.getId(), vendorLicenseModel.getVersion().getId()),
116 generalElement, "Update VSP General Info Element");
120 public VendorLicenseModelEntity get(VendorLicenseModelEntity vendorLicenseModel) {
121 SessionContext context = ZusammenUtil.createSessionContext();
122 ElementContext elementContext =
123 new ElementContext(vendorLicenseModel.getId(), vendorLicenseModel.getVersion().getId());
124 ElementToVLMGeneralConvertor convertor = new ElementToVLMGeneralConvertor();
125 return zusammenAdaptor
126 .getElementInfoByName(context, elementContext, null, ElementType.VendorLicenseModel.name())
127 .map(generalElementInfo -> {
128 VendorLicenseModelEntity entity = convertor.convert(generalElementInfo);
129 entity.setId(vendorLicenseModel.getId());
130 entity.setVersion(vendorLicenseModel.getVersion());
137 public void delete(VendorLicenseModelEntity entity) {
138 throw new UnsupportedOperationException("Delete vlm version is done using versioning manager");
141 private ZusammenElement mapVlmToZusammenElement(VendorLicenseModelEntity vendorLicenseModel,
143 ZusammenElement generalElement =
144 ZusammenUtil.buildStructuralElement(ElementType.VendorLicenseModel, action);
145 addVlmToInfo(generalElement.getInfo(), vendorLicenseModel);
146 return generalElement;
149 private void addVlmToInfo(Info info, VendorLicenseModelEntity vendorLicenseModel) {
150 info.addProperty(InfoPropertyName.name.name(), vendorLicenseModel.getVendorName());
151 info.addProperty(InfoPropertyName.description.name(), vendorLicenseModel.getDescription());
152 info.addProperty(InfoPropertyName.iconRef.name(), vendorLicenseModel.getIconRef());
155 public enum InfoPropertyName {