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 int errorCode;
40 EcompLoggerErrorCode(int errorCode) {
41 this.errorCode = errorCode;
44 public int getErrorCode() {
48 public static EcompLoggerErrorCode getByValue(String ecompErrorCode) {
49 String errorPrefix = parseCode(ecompErrorCode);
50 Optional<EcompLoggerErrorCode> optionalCode = Arrays.stream(values()).filter(v->isCode(v, errorPrefix)).findFirst();
51 return optionalCode.orElse(UNKNOWN_ERROR);
54 private static boolean isCode(EcompLoggerErrorCode ecompLoggerErrorCode, String errorPrefix) {
55 return String.valueOf(ecompLoggerErrorCode.getErrorCode()).contains(errorPrefix);
58 private static String parseCode(String errorCode) {
60 return errorCode.substring("E_".length(), 3);
61 } catch (StringIndexOutOfBoundsException ex) {
62 return UNKNOWN_ERROR.name();