Skip to content

Package: ServiceEventUtil

ServiceEventUtil

nameinstructionbranchcomplexitylinemethod
fromServiceEventBus(ServiceEvent)
M: 16 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
mergeToEntity(EventStoreRecord, ServiceEvent)
M: 26 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
mergeToEntityInternal(EventStoreRecord, ServiceEvent)
M: 50 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 13 C: 0
0%
M: 1 C: 0
0%
toServiceEventBus(EventStoreRecord)
M: 68 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 17 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2017, 2022 Eurotech and/or its affiliates and others
3: *
4: * This program and the accompanying materials are made
5: * available under the terms of the Eclipse Public License 2.0
6: * which is available at https://www.eclipse.org/legal/epl-2.0/
7: *
8: * SPDX-License-Identifier: EPL-2.0
9: *
10: * Contributors:
11: * Eurotech - initial API and implementation
12: *******************************************************************************/
13: package org.eclipse.kapua.commons.service.event.store.api;
14:
15: import org.eclipse.kapua.KapuaIllegalArgumentException;
16: import org.eclipse.kapua.commons.service.event.store.internal.EventStoreRecordImpl;
17:
18: /**
19: * Utility to convert event from/to entity event
20: *
21: * @since 1.0
22: *
23: */
24: public class ServiceEventUtil {
25:
26: private ServiceEventUtil() {
27:
28: }
29:
30: /**
31: * Convert the service event entity to the service bus object
32: *
33: * @param serviceEventEntity
34: * @return
35: * @throws KapuaIllegalArgumentException
36: */
37: public static org.eclipse.kapua.event.ServiceEvent toServiceEventBus(EventStoreRecord serviceEventEntity) throws KapuaIllegalArgumentException {
38: org.eclipse.kapua.event.ServiceEvent newEvent = new org.eclipse.kapua.event.ServiceEvent();
39:• if (serviceEventEntity.getId() == null) {
40: throw new KapuaIllegalArgumentException("id", null);
41: }
42: newEvent.setId(serviceEventEntity.getId().toCompactId());
43: newEvent.setContextId(serviceEventEntity.getContextId());
44: newEvent.setTimestamp(serviceEventEntity.getTimestamp());
45: newEvent.setUserId(serviceEventEntity.getUserId());
46: newEvent.setService(serviceEventEntity.getService());
47: newEvent.setEntityType(serviceEventEntity.getEntityType());
48: newEvent.setScopeId(serviceEventEntity.getScopeId());
49: newEvent.setEntityId(serviceEventEntity.getEntityId());
50: newEvent.setOperation(serviceEventEntity.getOperation());
51: newEvent.setInputs(serviceEventEntity.getInputs());
52: newEvent.setOutputs(serviceEventEntity.getOutputs());
53: newEvent.setStatus(serviceEventEntity.getStatus());
54: newEvent.setNote(serviceEventEntity.getNote());
55: return newEvent;
56: }
57:
58: /**
59: * Convert the service bus object to the service event entity. It should be used on a fresh service event bus object (if already persisted please use the
60: * {@link #mergeToEntity(EventStoreRecord, org.eclipse.kapua.event.ServiceEvent)} method)
61: *
62: * @param serviceEventBus
63: * @return
64: * @throws KapuaIllegalArgumentException
65: * if the service event bus id is not null
66: */
67: public static EventStoreRecord fromServiceEventBus(org.eclipse.kapua.event.ServiceEvent serviceEventBus) throws KapuaIllegalArgumentException {
68:• if (serviceEventBus.getId() != null) {
69: throw new KapuaIllegalArgumentException("id", serviceEventBus.getId());
70: }
71: return mergeToEntityInternal(new EventStoreRecordImpl(), serviceEventBus);
72: }
73:
74: /**
75: *
76: * @param serviceEventEntity
77: * @param serviceEventBus
78: * @return
79: * @throws KapuaIllegalArgumentException
80: * if the service event bus id is null or differs to the service event entity
81: */
82: public static EventStoreRecord mergeToEntity(EventStoreRecord serviceEventEntity, org.eclipse.kapua.event.ServiceEvent serviceEventBus) throws KapuaIllegalArgumentException {
83:• if (serviceEventEntity.getId() == null) {
84: throw new KapuaIllegalArgumentException("id", null);
85: }
86:• if (!serviceEventEntity.getId().toCompactId().equals(serviceEventBus.getId())) {
87: throw new KapuaIllegalArgumentException("serviceEventEntity.id - serviceEventBus.id", "not equals");
88: }
89: return mergeToEntityInternal(serviceEventEntity, serviceEventBus);
90: }
91:
92: private static EventStoreRecord mergeToEntityInternal(EventStoreRecord serviceEventEntity, org.eclipse.kapua.event.ServiceEvent serviceEventBus) {
93: serviceEventEntity.setContextId(serviceEventBus.getContextId());
94: serviceEventEntity.setTimestamp(serviceEventBus.getTimestamp());
95: serviceEventEntity.setUserId(serviceEventBus.getUserId());
96: serviceEventEntity.setService(serviceEventBus.getService());
97: serviceEventEntity.setEntityType(serviceEventBus.getEntityType());
98: serviceEventEntity.setScopeId(serviceEventBus.getScopeId());
99: serviceEventEntity.setEntityId(serviceEventBus.getEntityId());
100: serviceEventEntity.setOperation(serviceEventBus.getOperation());
101: serviceEventEntity.setInputs(serviceEventBus.getInputs());
102: serviceEventEntity.setOutputs(serviceEventBus.getOutputs());
103: serviceEventEntity.setStatus(serviceEventBus.getStatus());
104: serviceEventEntity.setNote(serviceEventBus.getNote());
105: return serviceEventEntity;
106: }
107:
108: }