2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * Copyright (C) 2017 Amdocs
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
23 package org.openecomp.appc.licmgr.impl;
25 import static org.openecomp.appc.licmgr.Constants.ASDC_ARTIFACTS_FIELDS.ARTIFACT_CONTENT;
29 import org.openecomp.appc.licmgr.LicenseDataAccessService;
30 import org.openecomp.appc.licmgr.LicenseManager;
31 import org.openecomp.appc.licmgr.exception.DataAccessException;
32 import org.openecomp.appc.licmgr.objects.LicenseModel;
35 @SuppressWarnings("all")
36 public class LicenseManagerImpl implements LicenseManager {
38 private LicenseDataAccessService DAService;
40 public void setDAService(LicenseDataAccessService daSrv){
44 public LicenseManagerImpl() {
48 public LicenseModel retrieveLicenseModel(String vnfType, String vnfVersion) throws DataAccessException {
50 LicenseModel licenseModel;
52 Map<String,String> resultMap = DAService.retrieveLicenseModelData(vnfType, vnfVersion);
53 if (resultMap.isEmpty()) {
54 throw new DataAccessException(String.format("License model not found for vnfType='%s' and vnfVersion='%s'", vnfType, vnfVersion));
56 String licenseModelXML = resultMap.get(ARTIFACT_CONTENT.name());
57 licenseModel = convert(licenseModelXML); // JAXBUtil.<VfLicenseModel>toObject(licenseModelXML, VfLicenseModel.class);
58 } catch (DataAccessException le) {
60 } catch (Exception e) {
61 throw new DataAccessException(e);
67 public Map<String, String> retrieveLicenseModelData(String vnfType, String vnfVersion, String... fields) throws DataAccessException {
69 Map<String,String> resultMap = DAService.retrieveLicenseModelData(vnfType, vnfVersion, fields);
74 public void storeArtifactPayload(Map<String, String> parameters) throws RuntimeException {
76 DAService.storeArtifactPayload(parameters);
79 private static LicenseModel convert(String xml) {
81 LicenseModel licenseModel = new LicenseModel();
83 int posEntitlementStart = xml.indexOf("<entitlement-pool-uuid>");
84 int posEntitlementEnd = xml.indexOf("</entitlement-pool-uuid>", posEntitlementStart);
85 if (-1 != posEntitlementStart) {
86 licenseModel.setEntitlementPoolUuid(xml.substring(posEntitlementStart + "<entitlement-pool-uuid>".length(), posEntitlementEnd));
89 int posLicenseStart = xml.indexOf("<license-key-group-uuid>");
90 int posLicenseEnd = xml.indexOf("</license-key-group-uuid>", posEntitlementStart);
91 if (-1 != posLicenseStart) {
92 licenseModel.setLicenseKeyGroupUuid(xml.substring(posLicenseStart + "<license-key-group-uuid>".length(), posLicenseEnd));