2 * Copyright © 2016-2017 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.healing.impl;
19 import org.openecomp.sdc.vendorlicense.dao.EntitlementPoolDao;
20 import org.openecomp.sdc.vendorlicense.dao.EntitlementPoolDaoFactory;
21 import org.openecomp.sdc.vendorlicense.dao.LicenseKeyGroupDao;
22 import org.openecomp.sdc.vendorlicense.dao.LicenseKeyGroupDaoFactory;
23 import org.openecomp.sdc.vendorlicense.dao.types.EntitlementPoolEntity;
24 import org.openecomp.sdc.vendorlicense.dao.types.LicenseKeyGroupEntity;
25 import org.openecomp.sdc.vendorlicense.healing.HealingService;
26 import org.openecomp.sdc.versioning.dao.types.VersionableEntity;
28 import java.util.UUID;
30 public class SimpleHealingServiceImpl implements HealingService {
31 private static final EntitlementPoolDao entitlementPoolDao =
32 EntitlementPoolDaoFactory.getInstance().createInterface();
33 private static final LicenseKeyGroupDao licenseKeyGroupDao =
34 LicenseKeyGroupDaoFactory.getInstance().createInterface();
36 public VersionableEntity heal(VersionableEntity toHeal) {
37 return handleMissingVersionId(toHeal);
41 public void persistNoHealing(VersionableEntity alreadyHealed) {
42 if (alreadyHealed instanceof EntitlementPoolEntity) {
43 entitlementPoolDao.update((EntitlementPoolEntity) alreadyHealed);
44 } else if (alreadyHealed instanceof LicenseKeyGroupEntity) {
45 licenseKeyGroupDao.update((LicenseKeyGroupEntity) alreadyHealed);
49 private VersionableEntity handleMissingVersionId(VersionableEntity toHeal) {
50 if (toHeal != null && toHeal.getVersionUuId() != null) {
54 if (toHeal instanceof EntitlementPoolEntity) {
55 toHeal.setVersionUuId(UUID.randomUUID().toString());
56 entitlementPoolDao.update((EntitlementPoolEntity) toHeal);
57 } else if (toHeal instanceof LicenseKeyGroupEntity) {
58 toHeal.setVersionUuId(UUID.randomUUID().toString());
59 licenseKeyGroupDao.update((LicenseKeyGroupEntity) toHeal);
61 throw new UnsupportedOperationException(
62 "Unsupported operation for 1610 release/1607->1610 migration.");