Package: DeviceManagementOperationRegistryServiceImpl
DeviceManagementOperationRegistryServiceImpl
name | instruction | branch | complexity | line | method | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
DeviceManagementOperationRegistryServiceImpl() |
|
|
|
|
|
||||||||||||||||||||
count(KapuaQuery) |
|
|
|
|
|
||||||||||||||||||||
create(DeviceManagementOperationCreator) |
|
|
|
|
|
||||||||||||||||||||
delete(KapuaId, KapuaId) |
|
|
|
|
|
||||||||||||||||||||
find(KapuaId, KapuaId) |
|
|
|
|
|
||||||||||||||||||||
findByOperationId(KapuaId, KapuaId) |
|
|
|
|
|
||||||||||||||||||||
lambda$count$7(KapuaQuery, EntityManager) |
|
|
|
|
|
||||||||||||||||||||
lambda$create$0(DeviceManagementOperationCreator) |
|
|
|
|
|
||||||||||||||||||||
lambda$create$1(DeviceManagementOperationCreator, EntityManager) |
|
|
|
|
|
||||||||||||||||||||
lambda$delete$8(KapuaId, KapuaId, EntityManager) |
|
|
|
|
|
||||||||||||||||||||
lambda$find$4(KapuaId, KapuaId, EntityManager) |
|
|
|
|
|
||||||||||||||||||||
lambda$findByOperationId$5(DeviceManagementOperationQuery, EntityManager) |
|
|
|
|
|
||||||||||||||||||||
lambda$query$6(KapuaQuery, EntityManager) |
|
|
|
|
|
||||||||||||||||||||
lambda$update$2(DeviceManagementOperation) |
|
|
|
|
|
||||||||||||||||||||
lambda$update$3(DeviceManagementOperation, EntityManager) |
|
|
|
|
|
||||||||||||||||||||
query(KapuaQuery) |
|
|
|
|
|
||||||||||||||||||||
static {...} |
|
|
|
|
|
||||||||||||||||||||
update(DeviceManagementOperation) |
|
|
|
|
|
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.service.device.management.registry.operation.internal;
14:
15: import org.eclipse.kapua.KapuaEntityNotFoundException;
16: import org.eclipse.kapua.KapuaException;
17: import org.eclipse.kapua.commons.security.KapuaSecurityUtils;
18: import org.eclipse.kapua.commons.service.internal.AbstractKapuaService;
19: import org.eclipse.kapua.commons.util.ArgumentValidator;
20: import org.eclipse.kapua.locator.KapuaLocator;
21: import org.eclipse.kapua.locator.KapuaProvider;
22: import org.eclipse.kapua.model.domain.Actions;
23: import org.eclipse.kapua.model.id.KapuaId;
24: import org.eclipse.kapua.model.query.KapuaQuery;
25: import org.eclipse.kapua.service.authorization.AuthorizationService;
26: import org.eclipse.kapua.service.authorization.permission.PermissionFactory;
27: import org.eclipse.kapua.service.device.management.registry.operation.DeviceManagementOperation;
28: import org.eclipse.kapua.service.device.management.registry.operation.DeviceManagementOperationAttributes;
29: import org.eclipse.kapua.service.device.management.registry.operation.DeviceManagementOperationCreator;
30: import org.eclipse.kapua.service.device.management.registry.operation.DeviceManagementOperationListResult;
31: import org.eclipse.kapua.service.device.management.registry.operation.DeviceManagementOperationQuery;
32: import org.eclipse.kapua.service.device.management.registry.operation.DeviceManagementOperationRegistryService;
33: import org.eclipse.kapua.service.device.management.registry.operation.DeviceManagementRegistryDomains;
34: import org.eclipse.kapua.service.device.registry.Device;
35: import org.eclipse.kapua.service.device.registry.DeviceRegistryService;
36:
37: @KapuaProvider
38: public class DeviceManagementOperationRegistryServiceImpl extends AbstractKapuaService implements DeviceManagementOperationRegistryService {
39:
40: private static final KapuaLocator LOCATOR = KapuaLocator.getInstance();
41:
42: private static final AuthorizationService AUTHORIZATION_SERVICE = LOCATOR.getService(AuthorizationService.class);
43: private static final PermissionFactory PERMISSION_FACTORY = LOCATOR.getFactory(PermissionFactory.class);
44:
45: private static final DeviceRegistryService DEVICE_REGISTRY_SERVICE = LOCATOR.getService(DeviceRegistryService.class);
46:
47: protected DeviceManagementOperationRegistryServiceImpl() {
48: super(DeviceManagementOperationEntityManagerFactory.getInstance());
49: }
50:
51: @Override
52: public DeviceManagementOperation create(DeviceManagementOperationCreator creator) throws KapuaException {
53: //
54: // Argument Validation
55: ArgumentValidator.notNull(creator, "deviceManagementOperationCreator");
56: ArgumentValidator.notNull(creator.getScopeId(), "deviceManagementOperationCreator.scopeId");
57: ArgumentValidator.notNull(creator.getStartedOn(), "deviceManagementOperationCreator.startedOn");
58: ArgumentValidator.notNull(creator.getDeviceId(), "deviceManagementOperationCreator.deviceId");
59: ArgumentValidator.notNull(creator.getOperationId(), "deviceManagementOperationCreator.operationId");
60: ArgumentValidator.notNull(creator.getStatus(), "deviceManagementOperationCreator.status");
61: ArgumentValidator.notNull(creator.getAppId(), "deviceManagementOperationCreator.appId");
62: ArgumentValidator.notNull(creator.getAction(), "deviceManagementOperationCreator.action");
63:
64: //
65: // Check access
66: AUTHORIZATION_SERVICE.checkPermission(PERMISSION_FACTORY.newPermission(DeviceManagementRegistryDomains.DEVICE_MANAGEMENT_REGISTRY_DOMAIN, Actions.write, null));
67:
68: //
69: // Check device existence
70:• if (KapuaSecurityUtils.doPrivileged(() -> DEVICE_REGISTRY_SERVICE.find(creator.getScopeId(), creator.getDeviceId()) == null)) {
71: throw new KapuaEntityNotFoundException(Device.TYPE, creator.getDeviceId());
72: }
73:
74: //
75: // Do create
76: return entityManagerSession.doTransactedAction(em -> DeviceManagementOperationDAO.create(em, creator));
77: }
78:
79: @Override
80: public DeviceManagementOperation update(DeviceManagementOperation entity) throws KapuaException {
81: //
82: // Argument Validation
83: ArgumentValidator.notNull(entity, "deviceManagementOperation");
84: ArgumentValidator.notNull(entity.getScopeId(), "deviceManagementOperation.scopeId");
85: ArgumentValidator.notNull(entity.getId(), "deviceManagementOperation.id");
86: ArgumentValidator.notNull(entity.getStartedOn(), "deviceManagementOperation.startedOn");
87: ArgumentValidator.notNull(entity.getDeviceId(), "deviceManagementOperation.deviceId");
88: ArgumentValidator.notNull(entity.getOperationId(), "deviceManagementOperation.operationId");
89: ArgumentValidator.notNull(entity.getStatus(), "deviceManagementOperation.status");
90: ArgumentValidator.notNull(entity.getAppId(), "deviceManagementOperation.appId");
91: ArgumentValidator.notNull(entity.getAction(), "deviceManagementOperation.action");
92:
93: //
94: // Check access
95: AUTHORIZATION_SERVICE.checkPermission(PERMISSION_FACTORY.newPermission(DeviceManagementRegistryDomains.DEVICE_MANAGEMENT_REGISTRY_DOMAIN, Actions.write, null));
96:
97: //
98: // Check device existence
99:• if (KapuaSecurityUtils.doPrivileged(() -> DEVICE_REGISTRY_SERVICE.find(entity.getScopeId(), entity.getDeviceId()) == null)) {
100: throw new KapuaEntityNotFoundException(Device.TYPE, entity.getDeviceId());
101: }
102:
103: //
104: // Check existence
105:• if (find(entity.getScopeId(), entity.getId()) == null) {
106: throw new KapuaEntityNotFoundException(DeviceManagementOperation.TYPE, entity.getId());
107: }
108:
109: //
110: // Do update
111: return entityManagerSession.doTransactedAction(em -> DeviceManagementOperationDAO.update(em, entity));
112: }
113:
114: @Override
115: public DeviceManagementOperation find(KapuaId scopeId, KapuaId entityId) throws KapuaException {
116: //
117: // Argument Validation
118: ArgumentValidator.notNull(scopeId, "scopeId");
119: ArgumentValidator.notNull(entityId, "deviceManagementOperationId");
120:
121: //
122: // Check Access
123: AUTHORIZATION_SERVICE.checkPermission(PERMISSION_FACTORY.newPermission(DeviceManagementRegistryDomains.DEVICE_MANAGEMENT_REGISTRY_DOMAIN, Actions.read, scopeId));
124:
125: //
126: // Do find
127: return entityManagerSession.doAction(em -> DeviceManagementOperationDAO.find(em, scopeId, entityId));
128: }
129:
130: @Override
131: public DeviceManagementOperation findByOperationId(KapuaId scopeId, KapuaId operationId) throws KapuaException {
132: //
133: // Argument Validation
134: ArgumentValidator.notNull(scopeId, "scopeId");
135: ArgumentValidator.notNull(operationId, "operationId");
136:
137: // Check Access
138: AUTHORIZATION_SERVICE.checkPermission(PERMISSION_FACTORY.newPermission(DeviceManagementRegistryDomains.DEVICE_MANAGEMENT_REGISTRY_DOMAIN, Actions.read, scopeId));
139:
140: //
141: // Do find
142: DeviceManagementOperationQuery query = new DeviceManagementOperationQueryImpl(scopeId);
143: query.setPredicate(query.attributePredicate(DeviceManagementOperationAttributes.OPERATION_ID, operationId));
144:
145: return entityManagerSession.doAction(em -> DeviceManagementOperationDAO.query(em, query)).getFirstItem();
146: }
147:
148: @Override
149: public DeviceManagementOperationListResult query(KapuaQuery query) throws KapuaException {
150: //
151: // Argument Validation
152: ArgumentValidator.notNull(query, "query");
153:
154: //
155: // Check Access
156: AUTHORIZATION_SERVICE.checkPermission(PERMISSION_FACTORY.newPermission(DeviceManagementRegistryDomains.DEVICE_MANAGEMENT_REGISTRY_DOMAIN, Actions.read, query.getScopeId()));
157:
158: //
159: // Do query
160: return entityManagerSession.doAction(em -> DeviceManagementOperationDAO.query(em, query));
161: }
162:
163: @Override
164: public long count(KapuaQuery query) throws KapuaException {
165: //
166: // Argument Validation
167: ArgumentValidator.notNull(query, "query");
168:
169: //
170: // Check Access
171: AUTHORIZATION_SERVICE.checkPermission(PERMISSION_FACTORY.newPermission(DeviceManagementRegistryDomains.DEVICE_MANAGEMENT_REGISTRY_DOMAIN, Actions.read, query.getScopeId()));
172:
173: //
174: // Do count
175: return entityManagerSession.doAction(em -> DeviceManagementOperationDAO.count(em, query));
176: }
177:
178: @Override
179: public void delete(KapuaId scopeId, KapuaId entityId) throws KapuaException {
180: //
181: // Argument Validation
182: ArgumentValidator.notNull(scopeId, "scopeId");
183: ArgumentValidator.notNull(entityId, "deviceManagementOperationId");
184:
185: //
186: // Check Access
187: AUTHORIZATION_SERVICE.checkPermission(PERMISSION_FACTORY.newPermission(DeviceManagementRegistryDomains.DEVICE_MANAGEMENT_REGISTRY_DOMAIN, Actions.delete, scopeId));
188:
189: //
190: // Check existence
191:• if (find(scopeId, entityId) == null) {
192: throw new KapuaEntityNotFoundException(DeviceManagementOperation.TYPE, entityId);
193: }
194:
195: //
196: // Do delete
197: entityManagerSession.doTransactedAction(em -> DeviceManagementOperationDAO.delete(em, scopeId, entityId));
198: }
199: }