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;
23 import static org.onap.ncmp.cmhandle.lcm.event.Event.CmhandleState.READY;
24 import static org.onap.ncmp.cmhandle.lcm.event.Event.Operation.DELETE;
26 import java.time.ZonedDateTime;
27 import java.time.format.DateTimeFormatter;
28 import java.util.List;
29 import java.util.UUID;
30 import lombok.extern.slf4j.Slf4j;
31 import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle;
32 import org.onap.ncmp.cmhandle.lcm.event.Event;
33 import org.onap.ncmp.cmhandle.lcm.event.Event.Operation;
34 import org.onap.ncmp.cmhandle.lcm.event.NcmpEvent;
35 import org.springframework.stereotype.Component;
39 * NcmpEventsCreator to create NcmpEvent based on relevant operation.
43 public class NcmpEventsCreator {
49 * @param cmHandleId Cm Handle Identifier
50 * @param operation Relevant Operation
51 * @param ncmpServiceCmHandle Ncmp CmHandle Data
52 * @return Populated NcmpEvent
54 public NcmpEvent populateNcmpEvent(final String cmHandleId, final Operation operation,
55 final NcmpServiceCmHandle ncmpServiceCmHandle) {
56 return createNcmpEvent(cmHandleId, operation, ncmpServiceCmHandle);
59 private NcmpEvent createNcmpEvent(final String cmHandleId, final Operation operation,
60 final NcmpServiceCmHandle ncmpServiceCmHandle) {
61 final NcmpEvent ncmpEvent = ncmpEventHeader(cmHandleId);
62 ncmpEvent.setEvent(ncmpEventPayload(cmHandleId, operation, ncmpServiceCmHandle));
66 private Event ncmpEventPayload(final String eventCorrelationId, final Operation operation,
67 final NcmpServiceCmHandle ncmpServiceCmHandle) {
68 final Event event = new Event();
69 event.setOperation(operation);
70 event.setCmHandleId(eventCorrelationId);
72 if (!DELETE.equals(operation)) {
73 event.setCmhandleState(READY);
74 event.setCmhandleProperties(List.of(ncmpServiceCmHandle.getPublicProperties()));
79 private NcmpEvent ncmpEventHeader(final String eventCorrelationId) {
80 final NcmpEvent ncmpEvent = new NcmpEvent();
81 ncmpEvent.setEventId(UUID.randomUUID().toString());
82 ncmpEvent.setEventCorrelationId(eventCorrelationId);
83 ncmpEvent.setEventTime(ZonedDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ")));
84 ncmpEvent.setEventSource("org.onap.ncmp");
85 ncmpEvent.setEventType("org.onap.ncmp.cmhandle-lcm-event");
86 ncmpEvent.setEventSchema("org.onap.ncmp:cmhandle-lcm-event:v1");