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 java.util.Collection;
25 import java.util.stream.Collectors;
26 import org.openecomp.core.zusammen.api.ZusammenAdaptor;
27 import org.openecomp.core.zusammen.api.ZusammenUtil;
28 import org.openecomp.sdc.datatypes.model.ElementType;
29 import org.openecomp.sdc.vendorlicense.dao.VendorLicenseModelDao;
30 import org.openecomp.sdc.vendorlicense.dao.impl.zusammen.convertor.ElementToVLMGeneralConvertor;
31 import org.openecomp.sdc.vendorlicense.dao.types.VendorLicenseModelEntity;
32 import org.openecomp.sdc.versioning.ActionVersioningManagerFactory;
33 import org.openecomp.sdc.versioning.types.VersionableEntityMetadata;
34 import org.openecomp.sdc.versioning.types.VersionableEntityStoreType;
36 public class VendorLicenseModelDaoZusammenImpl implements VendorLicenseModelDao {
38 private ZusammenAdaptor zusammenAdaptor;
40 public VendorLicenseModelDaoZusammenImpl(ZusammenAdaptor zusammenAdaptor) {
41 this.zusammenAdaptor = zusammenAdaptor;
45 public void registerVersioning(String versionableEntityType) {
46 VersionableEntityMetadata metadata =
47 new VersionableEntityMetadata(VersionableEntityStoreType.Zusammen, "VendorLicenseModel",
50 ActionVersioningManagerFactory.getInstance().createInterface()
51 .register(versionableEntityType, metadata);
55 public Collection<VendorLicenseModelEntity> list(
56 VendorLicenseModelEntity vendorLicenseModelEntity) {
58 ElementToVLMGeneralConvertor convertor = new ElementToVLMGeneralConvertor();
59 return zusammenAdaptor.listItems(ZusammenUtil.createSessionContext()).stream()
60 .filter(item -> "VendorLicenseModel".equals(item.getInfo().getProperty("item_type")))
62 VendorLicenseModelEntity entity = convertor.convert(item);
63 entity.setId(item.getId().getValue());
64 entity.setVersion(null);
67 .collect(Collectors.toList());
71 public void create(VendorLicenseModelEntity vendorLicenseModel) {
73 SessionContext context = ZusammenUtil.createSessionContext();
75 ElementContext elementContext = new ElementContext(vendorLicenseModel.getId(),
76 vendorLicenseModel.getVersion().getId());
78 ZusammenElement generalElement = mapVlmToZusammenElement(vendorLicenseModel, Action.CREATE);
80 zusammenAdaptor.saveElement(context, elementContext, generalElement,
81 "Create VLM General Info Element");
83 ZusammenElement licenseAgreementsElement =
84 ZusammenUtil.buildStructuralElement(ElementType.LicenseAgreements, Action.CREATE);
86 zusammenAdaptor.saveElement(context, elementContext, licenseAgreementsElement,
87 "Create VLM licenseAgreementsElement");
89 ZusammenElement featureGroupsElement =
90 ZusammenUtil.buildStructuralElement(ElementType.FeatureGroups, Action.CREATE);
92 zusammenAdaptor.saveElement(context, elementContext, featureGroupsElement,
93 "Create VLM featureGroupsElement");
95 ZusammenElement lkgsElement =
96 ZusammenUtil.buildStructuralElement(ElementType.LicenseKeyGroups, Action.CREATE);
98 zusammenAdaptor.saveElement(context, elementContext, lkgsElement,
99 "Create VLM lkgsElement");
101 ZusammenElement entitlementPoolsElement =
102 ZusammenUtil.buildStructuralElement(ElementType.EntitlementPools, Action.CREATE);
104 zusammenAdaptor.saveElement(context, elementContext, entitlementPoolsElement,
105 "Create VLM entitlementPoolsElement");
109 public void update(VendorLicenseModelEntity vendorLicenseModel) {
110 ZusammenElement generalElement = mapVlmToZusammenElement(vendorLicenseModel, Action.UPDATE);
112 SessionContext context = ZusammenUtil.createSessionContext();
113 zusammenAdaptor.saveElement(context,
114 new ElementContext(vendorLicenseModel.getId(), vendorLicenseModel.getVersion().getId()),
115 generalElement, "Update VSP General Info Element");
119 public VendorLicenseModelEntity get(VendorLicenseModelEntity vendorLicenseModel) {
120 SessionContext context = ZusammenUtil.createSessionContext();
121 ElementContext elementContext =
122 new ElementContext(vendorLicenseModel.getId(), vendorLicenseModel.getVersion().getId());
123 ElementToVLMGeneralConvertor convertor = new ElementToVLMGeneralConvertor();
124 return zusammenAdaptor
125 .getElementInfoByName(context, elementContext, null, ElementType.VendorLicenseModel.name())
126 .map(generalElementInfo -> {
127 VendorLicenseModelEntity entity = convertor.convert(generalElementInfo);
128 entity.setId(vendorLicenseModel.getId());
129 entity.setVersion(vendorLicenseModel.getVersion());
136 public void delete(VendorLicenseModelEntity entity) {
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());
153 info.addProperty(InfoPropertyName.oldVersion.name(), vendorLicenseModel.getOldVersion());
157 public enum InfoPropertyName {