2 * ==========LICENSE_START=========================================================
3 * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
4 * Copyright (c) 2022 Wipro Limited Intellectual Property. All rights reserved.
5 * ================================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 * ============LICENSE_END=========================================================
21 package org.onap.dcae.analytics.tca.core.util;
23 import static org.onap.dcae.analytics.tca.model.util.json.TcaModelJsonConversion.TCA_OBJECT_MAPPER;
25 import com.fasterxml.jackson.core.JsonProcessingException;
27 import java.util.ArrayList;
28 import java.util.Collections;
29 import java.util.List;
30 import java.util.Optional;
31 import java.util.stream.Collectors;
33 import org.onap.dcae.analytics.model.TcaModelConstants;
34 import org.onap.dcae.analytics.model.cef.EventListener;
35 import org.onap.dcae.analytics.tca.core.exception.AnalyticsParsingException;
36 import org.onap.dcae.analytics.tca.model.policy.TcaPolicy;
37 import org.onap.dcae.utils.eelf.logger.model.info.ServiceLogInfoImpl;
40 * @author Rajiv Singla
42 public abstract class TcaUtils {
45 * TCA Service Log Info for ECOMP Logging
47 public static final ServiceLogInfoImpl TCA_SERVICE_LOG_INFO =
48 new ServiceLogInfoImpl(TcaModelConstants.TCA_SERVICE_NAME, System.getProperty("user.name"), "");
51 * Creates a deep copy of Tca Policy
53 * @param tcaPolicy source tca policy object
55 * @return deep copy of provided tca policy
57 public static List<TcaPolicy> getTcaPolicyDeepCopy(final List<TcaPolicy> tcaPolicy) {
58 if (tcaPolicy != null) {
59 List<TcaPolicy> tcaList = new ArrayList<TcaPolicy>();
60 for( TcaPolicy tcaPol : tcaPolicy) {
62 tcaList.add(TCA_OBJECT_MAPPER.treeToValue(TCA_OBJECT_MAPPER.valueToTree(tcaPol), TcaPolicy.class));
63 } catch (JsonProcessingException e) {
64 throw new AnalyticsParsingException("Unable to create deep copy of TCA Policy: " + tcaPol, e);
70 final String errorMessage = "Invalid application state. TCA Policy must not be null";
71 throw new AnalyticsParsingException(errorMessage, new IllegalStateException(errorMessage));
77 * Converts given event Listeners to list of CEF Message String
79 * @param eventListeners event listeners object
81 * @return cef messages as string
83 public static List<String> getCefMessagesFromEventListeners(final List<EventListener> eventListeners) {
84 if (!Optional.ofNullable(eventListeners).isPresent()) {
85 return Collections.emptyList();
87 return eventListeners.stream().map(eventListener -> {
89 return TCA_OBJECT_MAPPER.writeValueAsString(eventListener);
90 } catch (JsonProcessingException e) {
91 throw new AnalyticsParsingException("Unable to parse EventLister to String: " + eventListener, e);
93 }).collect(Collectors.toList());
97 // private constructor