Change nexus values to properties
[appc.git] / app-c / appc / appc-dg / appc-dg-shared / appc-dg-license-manager / src / main / java / org / openecomp / appc / dg / licmgr / impl / LicenseManagerPluginImpl.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * openECOMP : APP-C
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights
6  *                                              reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  * 
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  * 
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.openecomp.appc.dg.licmgr.impl;
23
24 import java.util.Map;
25
26 import org.openecomp.appc.dg.licmgr.LicenseManagerPlugin;
27 import org.openecomp.appc.exceptions.APPCException;
28 import org.openecomp.appc.licmgr.Constants;
29 import org.openecomp.appc.licmgr.LicenseManager;
30 import org.openecomp.appc.licmgr.exception.DataAccessException;
31 import org.openecomp.appc.licmgr.objects.LicenseModel;
32 import com.att.eelf.configuration.EELFLogger;
33 import com.att.eelf.configuration.EELFManager;
34 import org.openecomp.sdnc.sli.SvcLogicContext;
35
36
37
38 public class LicenseManagerPluginImpl implements LicenseManagerPlugin {
39
40     private static EELFLogger logger = EELFManager.getInstance().getApplicationLogger();
41
42     // populated by blueprint framework
43     private LicenseManager licenseManager;
44
45     public void setLicenseManager(LicenseManager licenseManager) {
46         this.licenseManager = licenseManager;
47     }
48
49     /**
50      * Retrieves license model from APPC database and populate flags into svc context
51      * @param params map with parameters:
52      *               org.openecomp.appc.vftype - the vnf type / service type;
53      *               org.openecomp.appc.resource-version - the vnf version / service version
54      * @param ctx service logic context
55      *            1. supposed properties already in context:
56      *            aai.input.data.entitlement-assignment-group-uuid - entitlement-group-uuid asset tag already stored in AAI
57      *            aai.input.data.license-assignment-group-uuid - license-key-uuid asset tag already stored in AAI
58      *            2. properties and flags stored in context after bean execution:
59      *            model.entitlement.pool.uuid - entitlement-group-uuid from license model
60      *            model.license.key.uuid - license-key-uuid from license model
61      *            is.acquire-entitlement.require
62      *            is.release-entitlement.require
63      *            is.acquire-license.require
64      *            is.release-license.require
65      *            is.aai-entitlement-update.require
66      *            is.aai-license-update.require
67      *
68      * @throws APPCException throws in case of any error
69      */
70     @Override
71     public void retrieveLicenseModel(Map<String, String> params, SvcLogicContext ctx) throws APPCException {
72
73         try {
74
75             LicenseModel licenseModel = licenseManager.retrieveLicenseModel(params.get(Constants.VNF_TYPE_FIELD_NAME), params.get(Constants.VNF_RESOURCE_VERSION_FIELD_NAME));
76
77             String modelEntitlementPoolUuid = licenseModel.getEntitlementPoolUuid(); if (null == modelEntitlementPoolUuid) modelEntitlementPoolUuid = "";
78             String aaiEntitlementPoolUuid = ctx.getAttribute(Constants.AAI_ENTITLMENT_POOL_UUID_NAME); if (null == aaiEntitlementPoolUuid) aaiEntitlementPoolUuid = "";
79             boolean isAcquireEntitlementRequire = !modelEntitlementPoolUuid.isEmpty() && !modelEntitlementPoolUuid.equals(aaiEntitlementPoolUuid);
80             boolean isReleaseEntitlementRequire = !aaiEntitlementPoolUuid.isEmpty() && (isAcquireEntitlementRequire || modelEntitlementPoolUuid.isEmpty());
81             boolean isAAIEntitlementUpdateRequire = isAcquireEntitlementRequire || isReleaseEntitlementRequire;
82             ctx.setAttribute(Constants.MODEL_ENTITLMENT_POOL_UUID_NAME, modelEntitlementPoolUuid);
83             ctx.setAttribute(Constants.IS_ACQUIRE_ENTITLEMENT_REQUIRE, Boolean.toString(isAcquireEntitlementRequire));
84             ctx.setAttribute(Constants.IS_RELEASE_ENTITLEMENT_REQUIRE, Boolean.toString(isReleaseEntitlementRequire));
85             ctx.setAttribute(Constants.IS_AAI_ENTITLEMENT_UPDATE_REQUIRE, Boolean.toString(isAAIEntitlementUpdateRequire));
86
87
88             String modelLicenseKeyGroupUuid = licenseModel.getLicenseKeyGroupUuid(); if (null == modelLicenseKeyGroupUuid) modelLicenseKeyGroupUuid = "";
89             String aaiLicenseKeyGroupUuid = ctx.getAttribute(Constants.AAI_LICENSE_KEY_UUID_NAME); if (null == aaiLicenseKeyGroupUuid) aaiLicenseKeyGroupUuid = "";
90             String aaiLicenseKeyValue = ctx.getAttribute(Constants.AAI_LICENSE_KEY_VALUE); if (null == aaiLicenseKeyValue) aaiLicenseKeyValue = "";
91             boolean isAcquireLicenseRequire = !modelLicenseKeyGroupUuid.isEmpty() && !modelLicenseKeyGroupUuid.equals(aaiLicenseKeyGroupUuid);
92             boolean isReleaseLicenseRequire = !aaiLicenseKeyGroupUuid.isEmpty() && (isAcquireLicenseRequire || modelLicenseKeyGroupUuid.isEmpty());
93             boolean isAAILicenseUpdateRequire = isAcquireLicenseRequire || isReleaseLicenseRequire;
94             ctx.setAttribute(Constants.MODEL_LICENSE_KEY_UUID_NAME, modelLicenseKeyGroupUuid);
95             ctx.setAttribute(Constants.IS_ACQUIRE_LICENSE_REQUIRE, Boolean.toString(isAcquireLicenseRequire));
96             ctx.setAttribute(Constants.IS_RELEASE_LICENSE_REQUIRE, Boolean.toString(isReleaseLicenseRequire));
97             ctx.setAttribute(Constants.IS_AAI_LICENSE_UPDATE_REQUIRE, Boolean.toString(isAAILicenseUpdateRequire));
98
99             ctx.setAttribute("license-key", aaiLicenseKeyValue);
100
101         } catch (DataAccessException le) {
102             logger.error("Error " + le.getMessage());
103             ctx.setAttribute("output.status.message", le.getMessage());
104             throw new APPCException(le);
105         }
106
107     }
108
109
110
111     //////// code uses jaxb license model, should be fixed
112     /*
113     final VfLicenseModel.FeatureGroupList featureGroupList = licenseModel.getFeatureGroupList();
114     if (null != featureGroupList) {
115         final VfLicenseModel.FeatureGroupList.FeatureGroup featureGroup = featureGroupList.getFeatureGroup();
116         if (null != featureGroup) {
117             final VfLicenseModel.FeatureGroupList.FeatureGroup.EntitlementPoolList
118                             entitlementPoolList = featureGroup.getEntitlementPoolList();
119             if (null != entitlementPoolList) {
120                 final VfLicenseModel.FeatureGroupList.FeatureGroup.EntitlementPoolList.EntitlementPool
121                                 entitlementPool = entitlementPoolList.getEntitlementPool();
122                 if (null != entitlementPool) {
123                     final String entitlementPoolUuid = entitlementPool.getEntitlementPoolUuid();
124                     // add entitlementPoolUuid into context
125                     ctx.setAttribute(Constants.MODEL_ENTITLMENT_POOL_UUID_NAME, entitlementPoolUuid);
126                 }
127             }
128
129             final VfLicenseModel.FeatureGroupList.FeatureGroup.LicenseKeyGroupList
130                             licenseKeyGroupList = featureGroup.getLicenseKeyGroupList();
131             if (null != licenseKeyGroupList) {
132                 final VfLicenseModel.FeatureGroupList.FeatureGroup.LicenseKeyGroupList.LicenseKeyGroup
133                                 licenseKeyGroup = licenseKeyGroupList.getLicenseKeyGroup();
134                 if (null != licenseKeyGroup) {
135                     final String licenseKeyGroupUuid = licenseKeyGroup.getLicenseKeyGroupUuid();
136                     // add licenseKeyGroupUuid into context
137                     ctx.setAttribute(Constants.MODEL_LICENSE_KEY_UUID_NAME, licenseKeyGroupUuid);
138                 }
139             }
140         }
141     }
142     */
143
144
145 }