2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 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.common.log.enums;
23 import java.util.Arrays;
24 import java.util.Optional;
27 * Created by dd4296 on 12/26/2017.
29 public enum EcompLoggerErrorCode {
31 PERMISSION_ERROR(100),
32 AVAILABILITY_TIMEOUTS_ERROR(200),
35 BUSINESS_PROCESS_ERROR(500),
38 private static final int ERROR_CODE_SUBSTRING = 3;
39 private int errorCode;
41 EcompLoggerErrorCode(int errorCode) {
42 this.errorCode = errorCode;
45 public int getErrorCode() {
49 public static EcompLoggerErrorCode getByValue(String ecompErrorCode) {
50 String errorPrefix = parseCode(ecompErrorCode);
51 Optional<EcompLoggerErrorCode> optionalCode = Arrays.stream(values()).filter(v -> isCode(v, errorPrefix)).findFirst();
52 return optionalCode.orElse(UNKNOWN_ERROR);
55 private static boolean isCode(EcompLoggerErrorCode ecompLoggerErrorCode, String errorPrefix) {
56 return String.valueOf(ecompLoggerErrorCode.getErrorCode()).contains(errorPrefix);
59 private static String parseCode(String errorCode) {
61 return errorCode.substring("E_".length(), ERROR_CODE_SUBSTRING);
62 } catch (StringIndexOutOfBoundsException ex) {
63 return UNKNOWN_ERROR.name();