2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.vendorlicense.healing.impl;
23 import org.openecomp.sdc.common.utils.CommonUtil;
24 import org.openecomp.sdc.datatypes.error.ErrorLevel;
25 import org.openecomp.sdc.logging.context.impl.MdcDataDebugMessage;
26 import org.openecomp.sdc.logging.context.impl.MdcDataErrorMessage;
27 import org.openecomp.sdc.logging.types.LoggerConstants;
28 import org.openecomp.sdc.logging.types.LoggerErrorCode;
29 import org.openecomp.sdc.logging.types.LoggerErrorDescription;
30 import org.openecomp.sdc.logging.types.LoggerTragetServiceName;
31 import org.openecomp.sdc.vendorlicense.dao.EntitlementPoolDao;
32 import org.openecomp.sdc.vendorlicense.dao.EntitlementPoolDaoFactory;
33 import org.openecomp.sdc.vendorlicense.dao.LicenseKeyGroupDao;
34 import org.openecomp.sdc.vendorlicense.dao.LicenseKeyGroupDaoFactory;
35 import org.openecomp.sdc.vendorlicense.dao.types.EntitlementPoolEntity;
36 import org.openecomp.sdc.vendorlicense.dao.types.LicenseKeyGroupEntity;
37 import org.openecomp.sdc.vendorlicense.healing.HealingService;
38 import org.openecomp.sdc.versioning.dao.types.VersionableEntity;
40 import java.util.UUID;
42 public class SimpleHealingServiceImpl implements HealingService {
43 private static final EntitlementPoolDao entitlementPoolDao =
44 EntitlementPoolDaoFactory.getInstance().createInterface();
45 private static final LicenseKeyGroupDao licenseKeyGroupDao =
46 LicenseKeyGroupDaoFactory.getInstance().createInterface();
47 private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage();
50 public VersionableEntity heal(VersionableEntity toHeal, String user) {
51 return handleMissingVersionId(toHeal, user);
54 private VersionableEntity handleMissingVersionId(VersionableEntity toHeal, String user) {
57 mdcDataDebugMessage.debugEntryMessage(null, null);
59 if (toHeal != null && toHeal.getVersionUuId() != null) {
63 if (toHeal instanceof EntitlementPoolEntity) {
64 toHeal.setVersionUuId(UUID.randomUUID().toString());
65 entitlementPoolDao.update((EntitlementPoolEntity) toHeal);
66 } else if (toHeal instanceof LicenseKeyGroupEntity) {
67 toHeal.setVersionUuId(UUID.randomUUID().toString());
68 licenseKeyGroupDao.update((LicenseKeyGroupEntity) toHeal);
70 MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
71 LoggerTragetServiceName.SELF_HEALING, ErrorLevel.ERROR.name(),
72 LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.UNSUPPORTED_OPERATION);
73 throw new UnsupportedOperationException(
74 "Unsupported operation for 1610 release/1607->1610 migration.");
75 //todo maybe errorbuilder?
78 mdcDataDebugMessage.debugExitMessage(null, null);