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.VersioningManager;
27 import org.openecomp.sdc.versioning.VersioningManagerFactory;
28 import org.openecomp.sdc.versioning.dao.types.VersionableEntity;
30 import java.util.UUID;
32 public class SimpleHealingServiceImpl implements HealingService {
33 private static final EntitlementPoolDao entitlementPoolDao =
34 EntitlementPoolDaoFactory.getInstance().createInterface();
35 private static final LicenseKeyGroupDao licenseKeyGroupDao =
36 LicenseKeyGroupDaoFactory.getInstance().createInterface();
37 private static final VersioningManager VERSIONING_MANAGER =
38 VersioningManagerFactory.getInstance().createInterface();
41 public VersionableEntity heal(VersionableEntity toHeal) {
42 return handleMissingVersionId(toHeal);
46 public void persistNoHealing(VersionableEntity alreadyHealed) {
47 if (alreadyHealed instanceof EntitlementPoolEntity) {
48 entitlementPoolDao.update((EntitlementPoolEntity) alreadyHealed);
49 } else if (alreadyHealed instanceof LicenseKeyGroupEntity) {
50 licenseKeyGroupDao.update((LicenseKeyGroupEntity) alreadyHealed);
54 private VersionableEntity handleMissingVersionId(VersionableEntity toHeal) {
55 if (toHeal != null && toHeal.getVersionUuId() != null) {
59 if (toHeal instanceof EntitlementPoolEntity) {
60 toHeal.setVersionUuId(UUID.randomUUID().toString());
61 entitlementPoolDao.update((EntitlementPoolEntity) toHeal);
62 } else if (toHeal instanceof LicenseKeyGroupEntity) {
63 toHeal.setVersionUuId(UUID.randomUUID().toString());
64 licenseKeyGroupDao.update((LicenseKeyGroupEntity) toHeal);
66 throw new UnsupportedOperationException(
67 "Unsupported operation for 1610 release/1607->1610 migration.");
70 VERSIONING_MANAGER.publish(toHeal.getFirstClassCitizenId(), toHeal.getVersion(), "Add missing version_uuid on ep/lkg");