diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/template/DeviceTypeManagerService.java b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/template/DeviceTypeManagerService.java index e87d0d330cd..6db5d88054d 100644 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/template/DeviceTypeManagerService.java +++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/template/DeviceTypeManagerService.java @@ -32,6 +32,7 @@ import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration import org.wso2.carbon.device.mgt.common.policy.mgt.PolicyMonitoringManager; import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig; import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService; +import org.wso2.carbon.device.mgt.extensions.device.type.deployer.config.ConfigProperties; import org.wso2.carbon.device.mgt.extensions.device.type.deployer.config.DeviceTypeConfiguration; import org.wso2.carbon.device.mgt.extensions.device.type.deployer.config.Property; import org.wso2.carbon.device.mgt.extensions.device.type.deployer.config.PushNotificationProvider; @@ -113,8 +114,14 @@ public class DeviceTypeManagerService implements DeviceManagementService { if (pushNotificationProvider != null) { if (pushNotificationProvider.isFileBasedProperties()) { Map staticProps = new HashMap<>(); - for (Property property : pushNotificationProvider.getConfigProperties().getProperty()) { - staticProps.put(property.getName(), property.getValue()); + ConfigProperties configProperties = pushNotificationProvider.getConfigProperties(); + if (configProperties != null) { + List properties = configProperties.getProperty(); + if (properties != null && properties.size() > 0) { + for (Property property : properties) { + staticProps.put(property.getName(), property.getValue()); + } + } } pushNotificationConfig = new PushNotificationConfig(pushNotificationProvider.getType(), pushNotificationProvider.isScheduled(), staticProps); diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/mqtt/MQTTNotificationStrategy.java b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/mqtt/MQTTNotificationStrategy.java index 8af53af6b26..121599324ac 100644 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/mqtt/MQTTNotificationStrategy.java +++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/mqtt/MQTTNotificationStrategy.java @@ -46,36 +46,52 @@ public class MQTTNotificationStrategy implements NotificationStrategy { private String mqttAdapterName; private static final Log log = LogFactory.getLog(MQTTNotificationStrategy.class); private final PushNotificationConfig config; + private final String providerTenantDomain; + private static final Object lockObj = new Object(); public MQTTNotificationStrategy(PushNotificationConfig config) { this.config = config; OutputEventAdapterConfiguration adapterConfig = new OutputEventAdapterConfiguration(); adapterConfig.setType(MQTTAdapterConstants.MQTT_ADAPTER_TYPE); - mqttAdapterName = config.getProperty(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_NAME); - adapterConfig.setName(mqttAdapterName); adapterConfig.setMessageFormat(MessageType.TEXT); Map configProperties = new HashMap(); - String brokerUrl = config.getProperty(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_BROKER_URL); - if (brokerUrl != null && !brokerUrl.isEmpty()) { - configProperties.put(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_BROKER_URL, brokerUrl); + if (config.getProperties() != null && config.getProperties().size() > 0) { + String brokerUrl = config.getProperty(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_BROKER_URL); + if (brokerUrl != null && !brokerUrl.isEmpty()) { + configProperties.put(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_BROKER_URL, brokerUrl); + } + mqttAdapterName = config.getProperty(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_NAME); + configProperties.put(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_USERNAME, + config.getProperty(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_USERNAME)); + configProperties.put(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_PASSWORD, + config.getProperty(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_PASSWORD)); + configProperties.put(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_CLEAR_SESSION, + config.getProperty(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_CLEAR_SESSION)); + configProperties.put(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_SCOPES, + config.getProperty(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_SCOPES)); + configProperties.put(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_MESSAGE_QOS, + config.getProperty(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_MESSAGE_QOS)); + } else { + mqttAdapterName = "mqtt.adapter." + PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain() + .toLowerCase(); } - configProperties.put(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_USERNAME, - config.getProperty(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_USERNAME)); - configProperties.put(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_PASSWORD, - config.getProperty(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_PASSWORD)); - configProperties.put(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_CLEAR_SESSION, - config.getProperty(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_CLEAR_SESSION)); - configProperties.put(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_SCOPES, - config.getProperty(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_SCOPES)); - configProperties.put(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_MESSAGE_QOS, - config.getProperty(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_MESSAGE_QOS)); + adapterConfig.setName(mqttAdapterName); adapterConfig.setStaticProperties(configProperties); try { - MQTTDataHolder.getInstance().getOutputEventAdapterService().create(adapterConfig); + synchronized (lockObj) { + try { + MQTTDataHolder.getInstance().getOutputEventAdapterService().isPolled(mqttAdapterName); + } catch (OutputEventAdapterException e) { + //event adapter not created + MQTTDataHolder.getInstance().getOutputEventAdapterService().create(adapterConfig); + } + } } catch (OutputEventAdapterException e) { throw new InvalidConfigurationException("Error occurred while initializing MQTT output event adapter", e); } + providerTenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain() + .toLowerCase(); } @Override @@ -85,19 +101,47 @@ public class MQTTNotificationStrategy implements NotificationStrategy { @Override public void execute(NotificationContext ctx) throws PushNotificationExecutionFailedException { + String adapterName = mqttAdapterName; + String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(true); + if (!providerTenantDomain.equals(tenantDomain)) { + //this is to handle the device type shared with all tenant mode. + + adapterName = "mqtt.adapter." + PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain() + .toLowerCase(); + try { + MQTTDataHolder.getInstance().getOutputEventAdapterService().isPolled(adapterName); + } catch (OutputEventAdapterException e) { + //event adapter not created + synchronized (lockObj) { + OutputEventAdapterConfiguration adapterConfig = new OutputEventAdapterConfiguration(); + adapterConfig.setType(MQTTAdapterConstants.MQTT_ADAPTER_TYPE); + adapterConfig.setMessageFormat(MessageType.TEXT); + adapterConfig.setName(adapterName); + Map configProperties = new HashMap(); + adapterConfig.setStaticProperties(configProperties); + try { + MQTTDataHolder.getInstance().getOutputEventAdapterService().create(adapterConfig); + } catch (OutputEventAdapterException e1) { + throw new PushNotificationExecutionFailedException + ("Error occurred while initializing MQTT output event adapter for shared tenant: " + + tenantDomain, e); + } + } + } + + } Operation operation = ctx.getOperation(); Properties properties = operation.getProperties(); if (properties != null && properties.get(MQTT_ADAPTER_TOPIC) != null) { Map dynamicProperties = new HashMap<>(); dynamicProperties.put("topic", (String) properties.get(MQTT_ADAPTER_TOPIC)); - MQTTDataHolder.getInstance().getOutputEventAdapterService().publish(mqttAdapterName, dynamicProperties, + MQTTDataHolder.getInstance().getOutputEventAdapterService().publish(adapterName, dynamicProperties, operation.getPayLoad()); } else { if (PolicyOperation.POLICY_OPERATION_CODE.equals(operation.getCode())) { PolicyOperation policyOperation = (PolicyOperation) operation; List profileOperations = policyOperation.getProfileOperations(); - String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(true); String deviceType = ctx.getDeviceId().getType(); String deviceId = ctx.getDeviceId().getId(); for (ProfileOperation profileOperation : profileOperations) { @@ -106,7 +150,7 @@ public class MQTTNotificationStrategy implements NotificationStrategy { + deviceType + "/" + deviceId + "/" + profileOperation.getType() .toString().toLowerCase() + "/" + profileOperation.getCode().toLowerCase(); dynamicProperties.put("topic", topic); - MQTTDataHolder.getInstance().getOutputEventAdapterService().publish(mqttAdapterName, dynamicProperties, + MQTTDataHolder.getInstance().getOutputEventAdapterService().publish(adapterName, dynamicProperties, profileOperation.getPayLoad()); } @@ -119,7 +163,7 @@ public class MQTTNotificationStrategy implements NotificationStrategy { if (operation.getPayLoad() == null) { operation.setPayLoad(""); } - MQTTDataHolder.getInstance().getOutputEventAdapterService().publish(mqttAdapterName, dynamicProperties, + MQTTDataHolder.getInstance().getOutputEventAdapterService().publish(adapterName, dynamicProperties, operation.getPayLoad()); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/DeviceAccessAuthorizationAdminService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/DeviceAccessAuthorizationAdminService.java index 8a46b9b194f..6a4b12d72ea 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/DeviceAccessAuthorizationAdminService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/DeviceAccessAuthorizationAdminService.java @@ -115,4 +115,43 @@ public interface DeviceAccessAuthorizationAdminService { response = ErrorResponse.class) }) Response isAuthorized(AuthorizationRequest authorizationRequest); + + @POST + @Path("/stat") + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + produces = MediaType.APPLICATION_JSON, + httpMethod = "POST", + value = "Check for device access authorization for stat\n", + notes = "This is an internal API that can be used to check for authorization.", + response = DeviceAuthorizationResult.class, + tags = "Authorization Administrative Service", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "perm:authorization:verify") + }) + }) + + @ApiResponses(value = { + @ApiResponse( + code = 200, + message = "OK. \n Authorized device list will be delivered to the requested services", + response = DeviceAuthorizationResult.class), + @ApiResponse( + code = 400, + message = "Bad Request. \n Invalid request or validation error.", + response = ErrorResponse.class), + @ApiResponse( + code = 404, + message = "Not Found. \n The specified resource does not exist."), + @ApiResponse( + code = 415, + message = "Unsupported media type. \n The entity of the request was in a not supported format."), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n Server error occurred while checking the authorization" + + " for a specified set of devices.", + response = ErrorResponse.class) + }) + Response isAuthorizedForStat(AuthorizationRequest authorizationRequest); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/DeviceTypePublisherAdminService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/DeviceAnalyticsArtifactUploaderAdminService.java similarity index 97% rename from components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/DeviceTypePublisherAdminService.java rename to components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/DeviceAnalyticsArtifactUploaderAdminService.java index d3c3ee25c29..6c7f0d5eff0 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/DeviceTypePublisherAdminService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/DeviceAnalyticsArtifactUploaderAdminService.java @@ -38,7 +38,7 @@ import javax.ws.rs.core.Response; title = "", extensions = { @Extension(properties = { - @ExtensionProperty(name = "name", value = "DeviceTypePublisherAdminService"), + @ExtensionProperty(name = "name", value = "DeviceAnalyticsArtifactUploaderAdminService"), @ExtensionProperty(name = "context", value = "/api/device-mgt/v1.0/admin/devicetype"), }) } @@ -62,7 +62,7 @@ import javax.ws.rs.core.Response; } ) -public interface DeviceTypePublisherAdminService { +public interface DeviceAnalyticsArtifactUploaderAdminService { @POST @Path("/deploy/{type}") diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/DeviceAccessAuthorizationAdminServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/DeviceAccessAuthorizationAdminServiceImpl.java index fc3fe169baa..035caa3a180 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/DeviceAccessAuthorizationAdminServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/DeviceAccessAuthorizationAdminServiceImpl.java @@ -36,6 +36,8 @@ import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; +import java.util.ArrayList; +import java.util.List; @Path("/admin/authorization") @Produces(MediaType.APPLICATION_JSON) @@ -43,6 +45,7 @@ import javax.ws.rs.core.Response; public class DeviceAccessAuthorizationAdminServiceImpl implements DeviceAccessAuthorizationAdminService { private static final Log log = LogFactory.getLog(DeviceAccessAuthorizationAdminServiceImpl.class); + private static final String DEFAULT_STAT_PERMISSION = "/permission/admin/device-mgt/device/realtime_analytics"; @POST @Override @@ -90,4 +93,14 @@ public class DeviceAccessAuthorizationAdminServiceImpl implements DeviceAccessAu } } + @POST + @Path("/stat") + @Override + public Response isAuthorizedForStat(AuthorizationRequest authorizationRequest) { + List permissions = new ArrayList<>(); + permissions.add(DEFAULT_STAT_PERMISSION); + authorizationRequest.setPermissions(permissions); + return isAuthorized(authorizationRequest); + } + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/DeviceTypePublisherAdminServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/DeviceAnalyticsArtifactUploaderAdminServiceImpl.java similarity index 98% rename from components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/DeviceTypePublisherAdminServiceImpl.java rename to components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/DeviceAnalyticsArtifactUploaderAdminServiceImpl.java index 9fbd5043e28..27e74549b0d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/DeviceTypePublisherAdminServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/DeviceAnalyticsArtifactUploaderAdminServiceImpl.java @@ -37,13 +37,10 @@ import org.wso2.carbon.application.mgt.stub.upload.types.carbon.UploadedFileItem import org.wso2.carbon.base.ServerConfiguration; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.core.util.Utils; -import org.wso2.carbon.device.mgt.jaxrs.service.api.admin.DeviceTypePublisherAdminService; +import org.wso2.carbon.device.mgt.jaxrs.service.api.admin.DeviceAnalyticsArtifactUploaderAdminService; import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils; import org.wso2.carbon.identity.jwt.client.extension.JWTClient; import org.wso2.carbon.identity.jwt.client.extension.exception.JWTClientException; -import org.wso2.carbon.registry.core.Registry; -import org.wso2.carbon.registry.core.Resource; -import org.wso2.carbon.registry.core.ResourceImpl; import org.wso2.carbon.registry.core.exceptions.RegistryException; import org.wso2.carbon.user.api.UserStoreException; import org.wso2.carbon.utils.CarbonUtils; @@ -55,7 +52,6 @@ import javax.activation.DataHandler; import javax.net.ssl.KeyManagerFactory; import javax.net.ssl.SSLContext; import javax.net.ssl.TrustManagerFactory; -import javax.ws.rs.GET; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.PathParam; @@ -73,7 +69,7 @@ import java.util.ArrayList; import java.util.List; @Path("/admin/devicetype") -public class DeviceTypePublisherAdminServiceImpl implements DeviceTypePublisherAdminService { +public class DeviceAnalyticsArtifactUploaderAdminServiceImpl implements DeviceAnalyticsArtifactUploaderAdminService { /** * required soap header for authorization @@ -110,7 +106,7 @@ public class DeviceTypePublisherAdminServiceImpl implements DeviceTypePublisherA private String tenantDomain; - private static final Log log = LogFactory.getLog(DeviceTypePublisherAdminServiceImpl.class); + private static final Log log = LogFactory.getLog(DeviceAnalyticsArtifactUploaderAdminServiceImpl.class); private static final String DEFAULT_RESOURCE_LOCATION = "/resources/devicetypes"; private static final String CAR_FILE_LOCATION = CarbonUtils.getCarbonHome() + File.separator + "repository" + File.separator + "resources" + File.separator + "devicetypes"; @@ -178,6 +174,9 @@ public class DeviceTypePublisherAdminServiceImpl implements DeviceTypePublisherA publishDynamicEventReceivers(type, MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, receiverFileList); } } + if (streamFileList != null) { + publishDynamicEventStream(type, tenantDomain, streamFileList); + } if (deployAnalyticsCapp(type, list)){ return Response.status(Response.Status.BAD_REQUEST) .entity("\"Error, Artifact does not exist.\"").build(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/webapp/WEB-INF/cxf-servlet.xml b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/webapp/WEB-INF/cxf-servlet.xml index fd6c5e0309b..e33d1beb262 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/webapp/WEB-INF/cxf-servlet.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/webapp/WEB-INF/cxf-servlet.xml @@ -40,7 +40,7 @@ - + @@ -82,7 +82,7 @@ - + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java index 6672311c3d6..13a55476871 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java @@ -2114,22 +2114,21 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv deviceIdentifiers.add(deviceIdentifier); if (init != null) { List initialOperations = init.getOperations(); - - for (String str : initialOperations) { - CommandOperation operation = new CommandOperation(); - operation.setEnabled(true); - operation.setType(Operation.Type.COMMAND); - operation.setCode(str); - try { - deviceManagementProviderService. - addOperation(deviceType, - operation, deviceIdentifiers); - } catch (OperationManagementException e) { - throw new DeviceManagementException("Unable to find the device with the id: '" + deviceIdentifier.getId(), - e); - } catch (InvalidDeviceException e) { - throw new DeviceManagementException("Unable to find the device with the id: '" + deviceIdentifier.getId(), - e); + if (initialOperations != null) { + for (String str : initialOperations) { + CommandOperation operation = new CommandOperation(); + operation.setEnabled(true); + operation.setType(Operation.Type.COMMAND); + operation.setCode(str); + try { + deviceManagementProviderService.addOperation(deviceType, operation, deviceIdentifiers); + } catch (OperationManagementException e) { + throw new DeviceManagementException("Unable to add the operation for the device with the id: '" + + deviceIdentifier.getId(), e); + } catch (InvalidDeviceException e) { + throw new DeviceManagementException("Unable to find the device with the id: '" + + deviceIdentifier.getId(), e); + } } } }