2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2022 Nordix Foundation
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.cps.ncmp.api.impl.event.lcm;
23 import java.time.ZonedDateTime;
24 import java.time.format.DateTimeFormatter;
25 import java.util.List;
26 import java.util.UUID;
27 import lombok.extern.slf4j.Slf4j;
28 import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle;
29 import org.onap.ncmp.cmhandle.lcm.event.Event;
30 import org.onap.ncmp.cmhandle.lcm.event.NcmpEvent;
31 import org.springframework.stereotype.Component;
35 * LcmEventsCreator to create LcmEvent based on relevant operation.
39 public class LcmEventsCreator {
45 * @param cmHandleId Cm Handle Identifier
46 * @param ncmpServiceCmHandle Ncmp CmHandle Data
47 * @return Populated NcmpEvent
49 public NcmpEvent populateLcmEvent(final String cmHandleId, final NcmpServiceCmHandle ncmpServiceCmHandle) {
50 return createLcmEvent(cmHandleId, ncmpServiceCmHandle);
53 private NcmpEvent createLcmEvent(final String cmHandleId, final NcmpServiceCmHandle ncmpServiceCmHandle) {
54 final NcmpEvent ncmpEvent = lcmEventHeader(cmHandleId);
55 ncmpEvent.setEvent(lcmEventPayload(cmHandleId, ncmpServiceCmHandle));
59 private Event lcmEventPayload(final String eventCorrelationId, final NcmpServiceCmHandle ncmpServiceCmHandle) {
60 final Event event = new Event();
61 event.setCmHandleId(eventCorrelationId);
62 event.setCmhandleState(
63 Event.CmhandleState.fromValue(ncmpServiceCmHandle.getCompositeState().getCmHandleState().toString()));
64 event.setCmhandleProperties(List.of(ncmpServiceCmHandle.getPublicProperties()));
68 private NcmpEvent lcmEventHeader(final String eventCorrelationId) {
69 final NcmpEvent ncmpEvent = new NcmpEvent();
70 ncmpEvent.setEventId(UUID.randomUUID().toString());
71 ncmpEvent.setEventCorrelationId(eventCorrelationId);
72 ncmpEvent.setEventTime(ZonedDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ")));
73 ncmpEvent.setEventSource("org.onap.ncmp");
74 ncmpEvent.setEventType("org.onap.ncmp.cmhandle-lcm-event");
75 ncmpEvent.setEventSchema("org.onap.ncmp:cmhandle-lcm-event:v1");