From bdf74ac0413d38e4dd6d222889c38538907a4a90 Mon Sep 17 00:00:00 2001 From: Yohan Avishke Date: Sun, 1 Sep 2019 23:57:51 +0530 Subject: [PATCH 1/8] API to integrate functionality of DAS Four endpoints to publish stream, receiver, publisher and siddhi script were added to the device.mgt.api. This commit contains implementation of the above end points, jax-rs beans, custom exceptions and common methods used for the endpoints. These changes were done in order to decouple the DAS ui from Entgra products. These endpoints will function by consuming JSON payloads to, generate custom artifacts and deploying them depending on the payload. BREAKING CHANGE: Four endpoints to publish stream, receiver, publisher and siddhi script were added to the device.mgt.api --- .../mgt/jaxrs/beans/analytics/Adapter.java | 69 ++ .../beans/analytics/AdapterConfiguration.java | 62 ++ .../AdapterMappingConfiguration.java | 104 +++ .../beans/analytics/AdapterProperty.java | 44 ++ .../jaxrs/beans/analytics/AdapterType.java | 31 + .../mgt/jaxrs/beans/analytics/Attribute.java | 18 +- ...ributeType.java => AttributeDataType.java} | 4 +- .../beans/analytics/EventAttributeLists.java | 62 ++ .../jaxrs/beans/analytics/EventStream.java | 69 ++ .../beans/analytics/MappingProperty.java | 59 ++ .../jaxrs/beans/analytics/MessageFormat.java | 31 + .../beans/analytics/SiddhiExecutionPlan.java | 48 ++ .../InvalidExecutionPlanException.java | 36 + .../api/AnalyticsManagementService.java | 290 ++++++++ .../impl/AnalyticsManagementServiceImpl.java | 684 ++++++++++++++++++ .../mgt/jaxrs/util/DeviceMgtAPIUtils.java | 45 ++ .../src/main/webapp/WEB-INF/cxf-servlet.xml | 2 + 17 files changed, 1647 insertions(+), 11 deletions(-) create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/Adapter.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/AdapterConfiguration.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/AdapterMappingConfiguration.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/AdapterProperty.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/AdapterType.java rename components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/{AttributeType.java => AttributeDataType.java} (90%) create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/EventAttributeLists.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/EventStream.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/MappingProperty.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/MessageFormat.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/SiddhiExecutionPlan.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/exception/InvalidExecutionPlanException.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/AnalyticsManagementService.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/AnalyticsManagementServiceImpl.java diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/Adapter.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/Adapter.java new file mode 100644 index 0000000000..2cafd461ff --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/Adapter.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.wso2.carbon.device.mgt.jaxrs.beans.analytics; + +import io.swagger.annotations.ApiModelProperty; + +/** + * Receiver definition including : + * Attributes : Name, type, config and attached stream. + */ +public class Adapter { + @ApiModelProperty(value = "Adapter name") + private String adapterName; + @ApiModelProperty(value = "Attached stream name:version") + private String eventStreamWithVersion; + @ApiModelProperty(value = "Adapter type") + private AdapterType adapterType; + @ApiModelProperty(value = "Adapter main configurations") + private AdapterConfiguration adapterConfiguration; + + public String getAdapterName() { + return adapterName; + } + + public void setAdapterName(String adapterName) { + this.adapterName = adapterName; + } + + public String getEventStreamWithVersion() { + return eventStreamWithVersion; + } + + public void setEventStreamWithVersion(String eventStreamWithVersion) { + this.eventStreamWithVersion = eventStreamWithVersion; + } + + public AdapterType getAdapterType() { + return adapterType; + } + + public void setAdapterType(AdapterType adapterType) { + this.adapterType = adapterType; + } + + public AdapterConfiguration getAdapterConfiguration() { + return adapterConfiguration; + } + + public void setAdapterConfiguration( + AdapterConfiguration adapterConfiguration) { + this.adapterConfiguration = adapterConfiguration; + } +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/AdapterConfiguration.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/AdapterConfiguration.java new file mode 100644 index 0000000000..ed518dd60e --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/AdapterConfiguration.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.wso2.carbon.device.mgt.jaxrs.beans.analytics; + +import io.swagger.annotations.ApiModelProperty; +import java.util.ArrayList; +import java.util.List; + +/** + * Adapter main configurations + * Attributes : Adapter properties list, custom-mapping flag, mapping configurations + */ +public class AdapterConfiguration { + @ApiModelProperty(value = "Adapter properties list") + private List adapterProperties = new ArrayList<>(); + @ApiModelProperty(value = "Custom-mapping flag") + private boolean isCustomMappingEnabled; + @ApiModelProperty(value = "Mapping configurations") + private AdapterMappingConfiguration adapterMappingConfiguration; + + public List getAdapterProperties() { + return adapterProperties; + } + + public void setAdapterProperties( + List adapterProperties) { + this.adapterProperties = adapterProperties; + } + + public boolean isCustomMappingEnabled() { + return isCustomMappingEnabled; + } + + public void setCustomMappingEnabled(boolean customMappingEnabled) { + isCustomMappingEnabled = customMappingEnabled; + } + + public AdapterMappingConfiguration getAdapterMappingConfiguration() { + return adapterMappingConfiguration; + } + + public void setAdapterMappingConfiguration( + AdapterMappingConfiguration adapterMappingConfiguration) { + this.adapterMappingConfiguration = adapterMappingConfiguration; + } +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/AdapterMappingConfiguration.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/AdapterMappingConfiguration.java new file mode 100644 index 0000000000..afb499ee83 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/AdapterMappingConfiguration.java @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.wso2.carbon.device.mgt.jaxrs.beans.analytics; + +import io.swagger.annotations.ApiModelProperty; +import java.util.List; + +/** + * Adapter mapping configuration definition + * Attributes : Mapping format and lists for each type of property + */ +public class AdapterMappingConfiguration { + @ApiModelProperty(value = "Mapping format") + private MessageFormat messageFormat; + @ApiModelProperty(value = "Input mapping for json,text and xml mappings") + private String inputMappingString; + @ApiModelProperty(value = "Input mapping for json,map and xml mappings") + private List inputMappingProperties; + @ApiModelProperty(value = "Name-scape mapping for xml mapping") + private List namespaceMappingProperties; + @ApiModelProperty(value = "Correlation mapping for wso2 mapping") + private List correlationMappingProperties; + @ApiModelProperty(value = "Payload mapping for wso2 mapping") + private List payloadMappingProperties; + @ApiModelProperty(value = "Meta mapping for wso2 mapping") + private List metaMappingProperties; + + public MessageFormat getMessageFormat() { + return messageFormat; + } + + public void setMessageFormat(MessageFormat messageFormat) { + this.messageFormat = messageFormat; + } + + public String getInputMappingString() { + return inputMappingString; + } + + public void setInputMappingString(String inputMappingString) { + this.inputMappingString = inputMappingString; + } + + public List getInputMappingProperties() { + return inputMappingProperties; + } + + public void setInputMappingProperties( + List inputMappingProperties) { + this.inputMappingProperties = inputMappingProperties; + } + + public List getNamespaceMappingProperties() { + return namespaceMappingProperties; + } + + public void setNamespaceMappingProperties( + List namespaceMappingProperties) { + this.namespaceMappingProperties = namespaceMappingProperties; + } + + public List getCorrelationMappingProperties() { + return correlationMappingProperties; + } + + public void setCorrelationMappingProperties( + List correlationMappingProperties) { + this.correlationMappingProperties = correlationMappingProperties; + } + + public List getPayloadMappingProperties() { + return payloadMappingProperties; + } + + public void setPayloadMappingProperties( + List payloadMappingProperties) { + this.payloadMappingProperties = payloadMappingProperties; + } + + public List getMetaMappingProperties() { + return metaMappingProperties; + } + + public void setMetaMappingProperties( + List metaMappingProperties) { + this.metaMappingProperties = metaMappingProperties; + } +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/AdapterProperty.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/AdapterProperty.java new file mode 100644 index 0000000000..399ef3271f --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/AdapterProperty.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +package org.wso2.carbon.device.mgt.jaxrs.beans.analytics; + +/** + * Receiver properties with it's display name(key) and user input(value) + */ +public class AdapterProperty { + private String key; + private String value; + + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/AdapterType.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/AdapterType.java new file mode 100644 index 0000000000..5227c4973c --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/AdapterType.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.wso2.carbon.device.mgt.jaxrs.beans.analytics; + +/** + * Available adapter types + */ +public enum AdapterType { + EMAIL, FILE_TAIL, HTTP, IOT_EVENT, JMS, KAFKA, MQTT, OAUTH_MQTT, SOAP, WEBSOCKET, WEBSOCKET_LOCAL, + WSO2_EVENT, XMPP, UI, RDBMS, SECURED_WEBSOCKET, CASSANDRA, LOGGER; + + public String toStringFormatted() { + return super.toString().toLowerCase().replace("_", "-"); + } +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/Attribute.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/Attribute.java index 276fea9ee4..d661fdef9f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/Attribute.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/Attribute.java @@ -22,24 +22,24 @@ import com.fasterxml.jackson.annotation.JsonProperty; import io.swagger.annotations.ApiModelProperty; /** - * This hold the attribute definition. + * Each attribute definition + * Attributes : name, type */ public class Attribute { - - @ApiModelProperty(value = "Event Attribute Name") + @ApiModelProperty(value = "Event attribute name") @JsonProperty("name") private String name; - @ApiModelProperty(value = "Event Attribute Type") + @ApiModelProperty(value = "Event attribute data type") @JsonProperty("type") - private AttributeType type; + private AttributeDataType type; public Attribute() { } - public Attribute(String name, AttributeType attributeType) { + public Attribute(String name, AttributeDataType attributeDataType) { this.name = name; - this.type = attributeType; + this.type = attributeDataType; } public String getName() { return name; @@ -49,11 +49,11 @@ public class Attribute { this.name = name; } - public AttributeType getType() { + public AttributeDataType getType() { return type; } - public void setType(AttributeType type) { + public void setType(AttributeDataType type) { this.type = type; } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/AttributeType.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/AttributeDataType.java similarity index 90% rename from components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/AttributeType.java rename to components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/AttributeDataType.java index 23235612b9..d7acab5696 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/AttributeType.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/AttributeDataType.java @@ -19,9 +19,9 @@ package org.wso2.carbon.device.mgt.jaxrs.beans.analytics; /** - * This hold the definition of the attribute type for the attributes. + * Attribute data types */ -public enum AttributeType { +public enum AttributeDataType { STRING, LONG, BOOL, INT, FLOAT, DOUBLE; @Override diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/EventAttributeLists.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/EventAttributeLists.java new file mode 100644 index 0000000000..23ee3fb4d5 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/EventAttributeLists.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.wso2.carbon.device.mgt.jaxrs.beans.analytics; + +import io.swagger.annotations.ApiModelProperty; +import java.util.List; + +/** + * Stream event attribute data + * Attributes : three lists for each attribute type + */ +public class EventAttributeLists { + @ApiModelProperty(value = "Meta attribute list") + private List metaAttributes; + @ApiModelProperty(value = "Correlation attribute list") + private List correlationAttributes; + @ApiModelProperty(value = "Payload attribute list") + private List payloadAttributes; + + public List getMetaAttributes() { + return metaAttributes; + } + + public void setMetaAttributes( + List metaAttributes) { + this.metaAttributes = metaAttributes; + } + + public List getCorrelationAttributes() { + return correlationAttributes; + } + + public void setCorrelationAttributes( + List correlationAttributes) { + this.correlationAttributes = correlationAttributes; + } + + public List getPayloadAttributes() { + return payloadAttributes; + } + + public void setPayloadAttributes( + List payloadAttributes) { + this.payloadAttributes = payloadAttributes; + } +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/EventStream.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/EventStream.java new file mode 100644 index 0000000000..f2ff053f66 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/EventStream.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.wso2.carbon.device.mgt.jaxrs.beans.analytics; + +import io.swagger.annotations.ApiModelProperty; + +/** + * Stream definition + * Attributes : name, version, definition and attribute data + */ +public class EventStream { + @ApiModelProperty(value = "Stream name") + private String streamName; + @ApiModelProperty(value = "Stream version") + private String streamVersion; + @ApiModelProperty(value = "Stream definition") + private String streamDefinition; + @ApiModelProperty(value = "Stream property attribute lists") + private EventAttributeLists eventAttributeLists; + + public String getStreamName() { + return streamName; + } + + public void setStreamName(String streamName) { + this.streamName = streamName; + } + + public String getStreamVersion() { + return streamVersion; + } + + public void setStreamVersion(String streamVersion) { + this.streamVersion = streamVersion; + } + + public String getStreamDefinition() { + return streamDefinition; + } + + public void setStreamDefinition(String streamDefinition) { + this.streamDefinition = streamDefinition; + } + + public EventAttributeLists getEventAttributeLists() { + return eventAttributeLists; + } + + public void setEventAttributeLists( + EventAttributeLists eventAttributeLists) { + this.eventAttributeLists = eventAttributeLists; + } +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/MappingProperty.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/MappingProperty.java new file mode 100644 index 0000000000..05887be303 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/MappingProperty.java @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.wso2.carbon.device.mgt.jaxrs.beans.analytics; + +import io.swagger.annotations.ApiModelProperty; + +/** + * Mapping property data + * Attributes : name, data type and mapping value name + */ +public class MappingProperty { + @ApiModelProperty(value = "Property name") + private String name; + @ApiModelProperty(value = "Property data type") + private String type; + @ApiModelProperty(value = "Property mapping value name") + private String valueOf; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getValueOf() { + return valueOf; + } + + public void setValueOf(String valueOf) { + this.valueOf = valueOf; + } + +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/MessageFormat.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/MessageFormat.java new file mode 100644 index 0000000000..9df8a4bd0e --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/MessageFormat.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.wso2.carbon.device.mgt.jaxrs.beans.analytics; + +/** + * Message protocol types + */ +public enum MessageFormat { + JSON, MAP, XML, WSO2EVENT, TEXT; + + @Override + public String toString() { + return super.toString().toLowerCase(); + } +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/SiddhiExecutionPlan.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/SiddhiExecutionPlan.java new file mode 100644 index 0000000000..0c68e91478 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/SiddhiExecutionPlan.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.wso2.carbon.device.mgt.jaxrs.beans.analytics; + +import io.swagger.annotations.ApiModelProperty; + +/** + * Execution plan definition including : + * Attributes : Name and Plan data. + */ +public class SiddhiExecutionPlan { + @ApiModelProperty(value = "Execution plan name") + private String executionPlanName; + @ApiModelProperty(value = "Execution plan") + private String executionPlanData; + + public String getExecutionPlanName() { + return executionPlanName; + } + + public void setExecutionPlanName(String executionPlanName) { + this.executionPlanName = executionPlanName; + } + + public String getExecutionPlanData() { + return executionPlanData; + } + + public void setExecutionPlanData(String executionPlanData) { + this.executionPlanData = executionPlanData; + } +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/exception/InvalidExecutionPlanException.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/exception/InvalidExecutionPlanException.java new file mode 100644 index 0000000000..a741f67fb0 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/exception/InvalidExecutionPlanException.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.wso2.carbon.device.mgt.jaxrs.exception; + +public class InvalidExecutionPlanException extends Exception{ + private String errorMessage; + + public String getErrorMessage() { + return errorMessage; + } + + public void setErrorMessage(String errorMessage) { + this.errorMessage = errorMessage; + } + + public InvalidExecutionPlanException(String msg) { + super(msg); + setErrorMessage(msg); + } +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/AnalyticsManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/AnalyticsManagementService.java new file mode 100644 index 0000000000..b81100c0fe --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/AnalyticsManagementService.java @@ -0,0 +1,290 @@ +/* + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.wso2.carbon.device.mgt.jaxrs.service.api; + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiResponse; +import io.swagger.annotations.ApiResponses; +import io.swagger.annotations.Extension; +import io.swagger.annotations.ExtensionProperty; +import io.swagger.annotations.Info; +import io.swagger.annotations.ResponseHeader; +import io.swagger.annotations.SwaggerDefinition; +import io.swagger.annotations.Tag; +import org.wso2.carbon.apimgt.annotations.api.Scope; +import org.wso2.carbon.apimgt.annotations.api.Scopes; +import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse; +import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.Adapter; +import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.EventStream; +import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.SiddhiExecutionPlan; +import org.wso2.carbon.device.mgt.jaxrs.util.Constants; + +import javax.validation.Valid; +import javax.ws.rs.Consumes; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +@SwaggerDefinition( + info = @Info( + version = "1.0.0", + title = "", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = "name", value = "AnalyticsManagement"), + @ExtensionProperty(name = "context", value = "/api/device-mgt/v1.0/analytics"), + }) + } + ), + tags = { + @Tag(name = "analytics_management", description = "") + } +) +@Scopes( + scopes = { + @Scope( + name = "Add Event stream", + description = "Add definition of a Event stream", + key = "perm:analytics:events", + permissions = {"/device-mgt/analytics/event/add"} + ), + @Scope( + name = "Add Publisher", + description = "Add definition of a Publisher", + key = "perm:analytics:publisher", + permissions = {"/device-mgt/analytics/publisher/add"} + ), + @Scope( + name = "Add Receiver", + description = "Add definition of a Receiver", + key = "perm:analytics:receiver", + permissions = {"/device-mgt/analytics/receiver/add"} + ), + @Scope( + name = "Add Siddhi script", + description = "Add definition of a Siddhi script", + key = "perm:analytics:script", + permissions = {"/device-mgt/analytics/script/add"} + ) + } +) + +@Path("/analytics") +@Api(value = "Analytics Management", description = "This API corresponds to all tasks related analytics server") +@Consumes(MediaType.APPLICATION_JSON) +public interface AnalyticsManagementService { + + @POST + @Path("/event") + @ApiOperation( + httpMethod = "POST", + value = "Adding the Event Type Definition", + notes = "Add the event definition to analytics.", + tags = "Analytics Management", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "perm:analytics:events") + }) + } + ) + @ApiResponses( + value = { + @ApiResponse( + code = 200, + message = "OK. \n Successfully added the event defintion.", + responseHeaders = { + @ResponseHeader( + name = "Content-Type", + description = "The content type of the body"), + @ResponseHeader( + name = "ETag", + description = "Entity Tag of the response resource.\n" + + "Used by caches, or in conditional requests."), + @ResponseHeader( + name = "Last-Modified", + description = + "Date and time the resource was last modified.\n" + + "Used by caches, or in conditional requests."), + } + ), + @ApiResponse( + code = 400, + message = + "Bad Request."), + @ApiResponse( + code = 406, + message = "Not Acceptable.\n The requested media type is not supported."), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n Server error occurred while publishing the " + + "Event stream.", + response = ErrorResponse.class) + } + ) + Response deployEventDefinition(@Valid EventStream stream); + + @POST + @Path("/receiver") + @ApiOperation( + httpMethod = "POST", + value = "Adding an Event Receiver", + notes = "Add the receiver for an event", + tags = "Analytics Management", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "perm:analytics:receiver") + }) + } + ) + @ApiResponses( + value = { + @ApiResponse( + code = 200, + message = "OK. \n Successfully added the receiver.", + responseHeaders = { + @ResponseHeader( + name = "Content-Type", + description = "The content type of the body."), + @ResponseHeader( + name = "ETag", + description = "Entity Tag of the response resource.\n" + + "Used by caches, or in conditional requests."), + @ResponseHeader( + name = "Last-Modified", + description = + "Date and time the resource was last modified.\n" + + "Used by caches, or in conditional requests."), + } + ), + @ApiResponse( + code = 400, + message = + "Bad Request."), + @ApiResponse( + code = 406, + message = "Not Acceptable.\n The requested media type is not supported"), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n Server error occurred while publishing the " + + "Event receiver.", + response = ErrorResponse.class) + } + ) + Response deployEventReceiver(Adapter receiver); + + @POST + @Path("/publisher") + @ApiOperation( + httpMethod = "POST", + value = "Adding an Event Publisher", + notes = "Add the publisher for an event", + tags = "Analytics Management", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "perm:analytics:publisher") + }) + } + ) + @ApiResponses( + value = { + @ApiResponse( + code = 200, + message = "OK. \n Successfully added the publisher.", + responseHeaders = { + @ResponseHeader( + name = "Content-Type", + description = "The content type of the body."), + @ResponseHeader( + name = "ETag", + description = "Entity Tag of the response resource.\n" + + "Used by caches, or in conditional requests."), + @ResponseHeader( + name = "Last-Modified", + description = + "Date and time the resource was last modified.\n" + + "Used by caches, or in conditional requests."), + } + ), + @ApiResponse( + code = 400, + message = + "Bad Request."), + @ApiResponse( + code = 406, + message = "Not Acceptable.\n The requested media type is not supported."), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n Server error occurred while publishing the " + + "Event publisher.", + response = ErrorResponse.class) + } + ) + Response deployEventPublisher(@Valid Adapter publisher); + + @POST + @Path("/executable") + @ApiOperation( + httpMethod = "POST", + value = "Adding a Siddhi executable", + notes = "Add a Siddhi executable for a event", + tags = "Analytics Management", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "perm:analytics:script") + }) + } + ) + @ApiResponses( + value = { + @ApiResponse( + code = 200, + message = "OK. \n Successfully added the execution plan.", + responseHeaders = { + @ResponseHeader( + name = "Content-Type", + description = "The content type of the body."), + @ResponseHeader( + name = "ETag", + description = "Entity Tag of the response resource.\n" + + "Used by caches, or in conditional requests."), + @ResponseHeader( + name = "Last-Modified", + description = + "Date and time the resource was last modified.\n" + + "Used by caches, or in conditional requests."), + } + ), + @ApiResponse( + code = 400, + message = + "Bad Request."), + @ApiResponse( + code = 406, + message = "Not Acceptable.\n The requested media type is not supported."), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n Server error occurred while " + + "publishing the Execution plan.", + response = ErrorResponse.class) + } + ) + Response deploySiddhiExecutableScript(@Valid SiddhiExecutionPlan plan); +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/AnalyticsManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/AnalyticsManagementServiceImpl.java new file mode 100644 index 0000000000..c6a5eb9b58 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/AnalyticsManagementServiceImpl.java @@ -0,0 +1,684 @@ +/* + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.wso2.carbon.device.mgt.jaxrs.service.impl; + +import org.apache.axis2.AxisFault; +import org.apache.axis2.client.Stub; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.base.MultitenantConstants; +import org.wso2.carbon.context.PrivilegedCarbonContext; +import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.Attribute; +import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.AdapterMappingConfiguration; +import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.MappingProperty; +import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.AdapterConfiguration; +import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.AdapterProperty; +import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.MessageFormat; +import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.SiddhiExecutionPlan; +import org.wso2.carbon.device.mgt.jaxrs.exception.InvalidExecutionPlanException; +import org.wso2.carbon.device.mgt.jaxrs.service.api.AnalyticsManagementService; +import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.Adapter; +import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.EventAttributeLists; +import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.EventStream; +import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils; +import org.wso2.carbon.event.processor.stub.EventProcessorAdminServiceStub; +import org.wso2.carbon.event.processor.stub.types.ExecutionPlanConfigurationDto; +import org.wso2.carbon.event.publisher.stub.EventPublisherAdminServiceStub; +import org.wso2.carbon.event.publisher.stub.types.BasicOutputAdapterPropertyDto; +import org.wso2.carbon.event.publisher.stub.types.EventPublisherConfigurationDto; +import org.wso2.carbon.event.receiver.stub.EventReceiverAdminServiceStub; +import org.wso2.carbon.event.receiver.stub.types.BasicInputAdapterPropertyDto; +import org.wso2.carbon.event.receiver.stub.types.EventMappingPropertyDto; +import org.wso2.carbon.event.receiver.stub.types.EventReceiverConfigurationDto; +import org.wso2.carbon.event.stream.stub.EventStreamAdminServiceStub; +import org.wso2.carbon.event.stream.stub.types.EventStreamAttributeDto; +import org.wso2.carbon.event.stream.stub.types.EventStreamDefinitionDto; +import org.wso2.carbon.identity.jwt.client.extension.exception.JWTClientException; +import org.wso2.carbon.user.api.UserStoreException; + +import javax.validation.Valid; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.core.Response; +import java.rmi.RemoteException; +import java.util.List; + +/** + * This class is used to create endpoints to serve the deployment of streams, adapters, siddhi + * execution plans to the DAS + */ +@Path("/analytics") +public class AnalyticsManagementServiceImpl implements AnalyticsManagementService { + private static final Log log = LogFactory.getLog(AnalyticsManagementServiceImpl.class); + + /** + * @param eventStream EventStream object with the properties of the stream + * @return A status code depending on the code result + * Function - Deploy a event stream + */ + @Override + @POST + @Path("/event") + public Response deployEventDefinition(@Valid EventStream eventStream) { + String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(); + EventAttributeLists eventAttributes = eventStream.getEventAttributeLists(); + // Categorize attributes to three lists depending on their type + List eventMetaAttributes = eventAttributes.getMetaAttributes(); + List eventPayloadAttributes = eventAttributes.getPayloadAttributes(); + List eventCorrelationAttributes = eventAttributes.getCorrelationAttributes(); + + try { + /* Conditions + * - At least one list should always be not null + */ + if (eventStream.getEventAttributeLists() == null || + (eventMetaAttributes == null && eventCorrelationAttributes == null && + eventPayloadAttributes == null)) { + log.error("Invalid payload: eventAttributeLists"); + return Response.status(Response.Status.BAD_REQUEST).build(); + + } else { + String streamName = eventStream.getStreamName(); + String streamVersion = eventStream.getStreamVersion(); + String streamDefinition = eventStream.getStreamDefinition(); + // Publish the event stream + publishStream(streamName, streamVersion, streamDefinition, eventMetaAttributes, + eventPayloadAttributes, eventCorrelationAttributes); + try { + /* + * Create a new tenant and if that tenant is not the super tenant execute the publish + * function for the new tenant + */ + PrivilegedCarbonContext.startTenantFlow(); + PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain( + MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, true); + if (!MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(tenantDomain)) { + publishStream(streamName, streamVersion, streamDefinition, eventMetaAttributes, + eventPayloadAttributes, eventCorrelationAttributes); + } + } finally { + // End the new tenant flow + PrivilegedCarbonContext.endTenantFlow(); + } + return Response.ok().build(); + } + } catch (AxisFault e) { + log.error("Failed to create event definitions for tenantDomain: " + tenantDomain, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); + } catch (RemoteException e) { + log.error("Failed to connect with the remote services for tenantDomain: " + tenantDomain, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); + } catch (JWTClientException e) { + log.error("Failed to generate jwt token for tenantDomain: " + tenantDomain, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); + } catch (UserStoreException e) { + log.error("Failed to connect with the user store for tenantDomain: " + tenantDomain, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); + } + } + + /** + * @param receiver Receiver definition data + * @return a status code depending on the code execution + * * Function - Deploy a event receiver + */ + @Override + @POST + @Path("/receiver") + public Response deployEventReceiver(Adapter receiver) { + String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(); + String receiverName = receiver.getAdapterName(); + String adapterType = receiver.getAdapterType().toStringFormatted(); + AdapterConfiguration adapterConfiguration = receiver.getAdapterConfiguration(); + AdapterMappingConfiguration adapterMappingConfiguration = adapterConfiguration.getAdapterMappingConfiguration(); + + try { + List adapterProperties = adapterConfiguration.getAdapterProperties(); + if (adapterProperties == null) { + log.error("Invalid attribute payload"); + return Response.status(Response.Status.BAD_REQUEST).build(); + } + + boolean customMapping = adapterConfiguration.isCustomMappingEnabled(); + List inputMappingProperties = adapterMappingConfiguration.getInputMappingProperties(); + List namespaceMappingProperties = adapterMappingConfiguration.getNamespaceMappingProperties(); + List correlationMappingProperties = adapterMappingConfiguration.getCorrelationMappingProperties(); + List payloadMappingProperties = adapterMappingConfiguration.getPayloadMappingProperties(); + List metaMappingProperties = adapterMappingConfiguration.getMetaMappingProperties(); + MessageFormat messageFormat = adapterMappingConfiguration.getMessageFormat(); + /* + * Conditions + * - if CustomMappingEnabled check validity of property lists + * - if both inputMappingProperties and namespaceMappingProperties null check remaining property lists + * - if all correlationMappingProperties, payloadMappingProperties, metaMappingProperties null log error + * - if message format is null change the final result to TRUE + * - else continue + * */ + if ((customMapping && + (inputMappingProperties == null && namespaceMappingProperties == null) && + (correlationMappingProperties == null && payloadMappingProperties == null && + metaMappingProperties == null)) || + messageFormat == null) { + log.error("Invalid mapping payload"); + return Response.status(Response.Status.BAD_REQUEST).build(); + } + String eventStreamWithVersion = receiver.getEventStreamWithVersion(); + + publishReceiver(receiverName, adapterType, adapterProperties, customMapping, inputMappingProperties, + namespaceMappingProperties, correlationMappingProperties, payloadMappingProperties, + metaMappingProperties, messageFormat, eventStreamWithVersion); + try { + /* + * Create a new tenant and if that tenant is not the super tenant execute the publish + * function for the new tenant + */ + PrivilegedCarbonContext.startTenantFlow(); + PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain( + MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, true); + if (!MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(tenantDomain)) { + publishReceiver(receiverName, adapterType, adapterProperties, customMapping, inputMappingProperties, + namespaceMappingProperties, correlationMappingProperties, payloadMappingProperties, + metaMappingProperties, messageFormat, eventStreamWithVersion); + } + } finally { + // End the new tenant flow + PrivilegedCarbonContext.endTenantFlow(); + } + return Response.ok().build(); + } catch (AxisFault e) { + log.error("Failed to create event definitions for tenantDomain: " + tenantDomain, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); + } catch (RemoteException e) { + log.error("Failed to connect with the remote services for tenantDomain: " + tenantDomain, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); + } catch (JWTClientException e) { + log.error("Failed to generate jwt token for tenantDomain: " + tenantDomain, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); + } catch (UserStoreException e) { + log.error("Failed to connect with the user store for tenantDomain: " + tenantDomain, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); + } + } + + /** + * @param publisher Publisher definition + * @return a status code depending on the code execution + */ + @Override + @POST + @Path("/publisher") + public Response deployEventPublisher(@Valid Adapter publisher) { + String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(); + String publisherName = publisher.getAdapterName(); + String adapterType = publisher.getAdapterType().toStringFormatted(); + AdapterConfiguration adapterConfiguration = publisher.getAdapterConfiguration(); + AdapterMappingConfiguration adapterMappingConfiguration = adapterConfiguration.getAdapterMappingConfiguration(); + + try { + List adapterProperties = adapterConfiguration.getAdapterProperties(); + if (adapterProperties == null) { + log.error("Invalid attribute payload"); + return Response.status(Response.Status.BAD_REQUEST).build(); + } + + boolean customMapping = adapterConfiguration.isCustomMappingEnabled(); + String inputMappingString = adapterMappingConfiguration.getInputMappingString(); + List inputMappingProperties = adapterMappingConfiguration.getInputMappingProperties(); + List correlationMappingProperties = adapterMappingConfiguration.getCorrelationMappingProperties(); + List payloadMappingProperties = adapterMappingConfiguration.getPayloadMappingProperties(); + List metaMappingProperties = adapterMappingConfiguration.getMetaMappingProperties(); + MessageFormat messageFormat = adapterMappingConfiguration.getMessageFormat(); + /* + * Conditions + * - if CustomMappingEnabled check validity of property lists + * - if all correlationMappingProperties, payloadMappingProperties, metaMappingProperties null log error + * - if message format is null change the final result to TRUE + * - else continue + */ + if ((customMapping && + (inputMappingProperties == null && inputMappingString == null) && + (correlationMappingProperties == null && payloadMappingProperties == null && + metaMappingProperties == null)) || + messageFormat == null) { + log.error("Invalid mapping payload"); + return Response.status(Response.Status.BAD_REQUEST).build(); + } + String eventStreamWithVersion = publisher.getEventStreamWithVersion(); + + publishPublisher(publisherName, adapterType, adapterProperties, customMapping + , inputMappingString, inputMappingProperties, correlationMappingProperties + , payloadMappingProperties, metaMappingProperties, messageFormat + , eventStreamWithVersion); + try { + /* + * Create a new tenant and if that tenant is not the super tenant execute the publish + * function for the new tenant + */ + PrivilegedCarbonContext.startTenantFlow(); + PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain( + MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, true); + if (!MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(tenantDomain)) { + publishPublisher(publisherName, adapterType, adapterProperties, customMapping + , inputMappingString, inputMappingProperties, correlationMappingProperties + , payloadMappingProperties, metaMappingProperties, messageFormat + , eventStreamWithVersion); + } + } finally { + // End the new tenant flow + PrivilegedCarbonContext.endTenantFlow(); + } + return Response.ok().build(); + } catch (AxisFault e) { + log.error("Failed to create event definitions for tenantDomain: " + tenantDomain, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); + } catch (RemoteException e) { + log.error("Failed to connect with the remote services for tenantDomain: " + tenantDomain, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); + } catch (JWTClientException e) { + log.error("Failed to generate jwt token for tenantDomain: " + tenantDomain, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); + } catch (UserStoreException e) { + log.error("Failed to connect with the user store for tenantDomain: " + tenantDomain, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); + } + } + + /** + * @param executionPlan Siddhi execution plan definition + * @return a status code depending on the code execution + */ + @Override + @POST + @Path("/executable") + public Response deploySiddhiExecutableScript(@Valid SiddhiExecutionPlan executionPlan) { + String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(); + try { + publishSiddhiExecutionPlan(executionPlan.getExecutionPlanName(), + executionPlan.getExecutionPlanData()); + try { + /* + * Create a new tenant and if that tenant is not the super tenant execute the publish + * function for the new tenant + */ + PrivilegedCarbonContext.startTenantFlow(); + PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain( + MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, true); + if (!MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(tenantDomain)) { + publishSiddhiExecutionPlan(executionPlan.getExecutionPlanName(), + executionPlan.getExecutionPlanData()); + } + } finally { + // End the new tenant flow + PrivilegedCarbonContext.endTenantFlow(); + } + return Response.ok().build(); + } catch (AxisFault e) { + log.error("Failed to create event definitions for tenantDomain: " + tenantDomain, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); + } catch (RemoteException e) { + log.error("Failed to connect with the remote services for tenantDomain: " + tenantDomain, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); + } catch (JWTClientException e) { + log.error("Failed to generate jwt token for tenantDomain: " + tenantDomain, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); + } catch (UserStoreException e) { + log.error("Failed to connect with the user store for tenantDomain: " + tenantDomain, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); + } catch (InvalidExecutionPlanException e) { + log.error("Invalid Execution plan: " + tenantDomain, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); + } + } + + /** + * @param streamName Name of the stream + * @param streamVersion Version of the stream + * @param streamDefinition Definition of the stream + * @param eventMetaAttributes Meta attributes of the stream + * @param eventPayloadAttributes Payload attributes of the stream + * @param eventCorrelationAttributes Correlation attributes of the stream + * @throws RemoteException exception that may occur during a remote method call + * @throws UserStoreException exception that may occur during JWT token generation + * @throws JWTClientException exception that may occur during connecting to client store + */ + private void publishStream(String streamName, String streamVersion, String streamDefinition, + List eventMetaAttributes, + List eventPayloadAttributes, + List eventCorrelationAttributes) + throws RemoteException, UserStoreException, JWTClientException { + EventStreamAdminServiceStub eventStreamAdminServiceStub = + DeviceMgtAPIUtils.getEventStreamAdminServiceStub(); + try { + EventStreamDefinitionDto eventStreamDefinitionDto = new EventStreamDefinitionDto(); + eventStreamDefinitionDto.setName(streamName); + eventStreamDefinitionDto.setVersion(streamVersion); + eventStreamDefinitionDto.setDescription(streamDefinition); + eventStreamDefinitionDto.setMetaData(addEventAttributesToDto(eventMetaAttributes)); + eventStreamDefinitionDto.setPayloadData(addEventAttributesToDto(eventPayloadAttributes)); + eventStreamDefinitionDto.setCorrelationData(addEventAttributesToDto(eventCorrelationAttributes)); + String streamId = streamName + ":" + streamVersion; + if (eventStreamAdminServiceStub.getStreamDefinitionDto(streamId) != null) { + eventStreamAdminServiceStub.editEventStreamDefinitionAsDto(eventStreamDefinitionDto, streamId); + } else { + eventStreamAdminServiceStub.addEventStreamDefinitionAsDto(eventStreamDefinitionDto); + } + } finally { + cleanup(eventStreamAdminServiceStub); + } + + } + + /** + * @param receiverName Receiver name + * @param adapterType Receiver type + * @param adapterProperties Receiver properties + * @param customMapping Is receiver mapped + * @param inputMappingProperties Receiver input attribute mapping + * @param namespaceMappingProperties Receiver name-scape attribute mapping + * @param correlationMappingProperties Receiver correlation attribute mapping + * @param payloadMappingProperties Receiver payload attribute mapping + * @param metaMappingProperties Receiver meta attribute mapping + * @param messageFormat Receiver mapping format + * @param eventStreamWithVersion Attached stream + * @throws RemoteException exception that may occur during a remote method call + * @throws UserStoreException exception that may occur during JWT token generation + * @throws JWTClientException exception that may occur during connecting to client store + */ + private void publishReceiver(String receiverName, String adapterType, + List adapterProperties, boolean customMapping, + List inputMappingProperties, + List namespaceMappingProperties, + List correlationMappingProperties, + List payloadMappingProperties, + List metaMappingProperties, + MessageFormat messageFormat, + String eventStreamWithVersion) + throws RemoteException, UserStoreException, JWTClientException { + EventReceiverAdminServiceStub eventReceiverAdminServiceStub = DeviceMgtAPIUtils.getEventReceiverAdminServiceStub(); + + try { + EventReceiverConfigurationDto eventReceiverConfigurationDto = eventReceiverAdminServiceStub + .getActiveEventReceiverConfiguration(receiverName); + + // Check if adapter already exists, if so un-deploy it + if (eventReceiverConfigurationDto != null) { + eventReceiverAdminServiceStub.undeployActiveEventReceiverConfiguration(receiverName); + } + + // Adding attribute properties to DTOs + BasicInputAdapterPropertyDto[] basicInputAdapterPropertyDtos = + addReceiverConfigToDto(adapterProperties); + + if (eventReceiverAdminServiceStub.getActiveEventReceiverConfiguration(receiverName) == null) { + // Call stub deploy methods according to the message format + if (!messageFormat.toString().equals("wso2event")) { + EventMappingPropertyDto[] inputMappingPropertyDtos = + addReceiverMappingToDto(inputMappingProperties); + if (messageFormat.toString().equals("xml")) { + EventMappingPropertyDto[] namespaceMappingPropertyDtos = + addReceiverMappingToDto(namespaceMappingProperties); + + eventReceiverAdminServiceStub.deployXmlEventReceiverConfiguration(receiverName + , eventStreamWithVersion, adapterType, null + , namespaceMappingPropertyDtos, inputMappingPropertyDtos + , basicInputAdapterPropertyDtos, customMapping); + } else { + if (messageFormat.toString().equals("map")) { + eventReceiverAdminServiceStub.deployMapEventReceiverConfiguration(receiverName + , eventStreamWithVersion, adapterType, inputMappingPropertyDtos + , basicInputAdapterPropertyDtos, customMapping); + } else if (messageFormat.toString().equals("text")) { + eventReceiverAdminServiceStub.deployTextEventReceiverConfiguration(receiverName + , eventStreamWithVersion, adapterType, inputMappingPropertyDtos + , basicInputAdapterPropertyDtos, customMapping); + } else { + eventReceiverAdminServiceStub.deployJsonEventReceiverConfiguration(receiverName + , eventStreamWithVersion, adapterType, inputMappingPropertyDtos + , basicInputAdapterPropertyDtos, customMapping); + } + } + } else { + EventMappingPropertyDto[] correlationMappingPropertyDtos = addReceiverMappingToDto(correlationMappingProperties); + EventMappingPropertyDto[] metaMappingPropertyDtos = addReceiverMappingToDto(metaMappingProperties); + EventMappingPropertyDto[] payloadMappingPropertyDtos = addReceiverMappingToDto(payloadMappingProperties); + + eventReceiverAdminServiceStub.deployWso2EventReceiverConfiguration(receiverName + , eventStreamWithVersion, adapterType, metaMappingPropertyDtos + , correlationMappingPropertyDtos, payloadMappingPropertyDtos + , basicInputAdapterPropertyDtos, customMapping + , eventStreamWithVersion); + } + + } + } finally { + cleanup(eventReceiverAdminServiceStub); + } + } + + /** + * @param publisherName Publisher name + * @param adapterType Publisher type + * @param adapterProperties Publisher properties + * @param customMapping Is publisher mapped + * @param correlationMappingProperties Publisher correlation attribute mapping + * @param payloadMappingProperties Publisher payload attribute mapping + * @param metaMappingProperties Publisher meta attribute mapping + * @param messageFormat Publisher mapping format + * @param eventStreamWithVersion Attached stream + * @throws RemoteException exception that may occur during a remote method call + * @throws UserStoreException exception that may occur during JWT token generation + * @throws JWTClientException exception that may occur during connecting to client store + */ + private void publishPublisher(String publisherName, String adapterType, + List adapterProperties, + boolean customMapping, + String inputMappingString, + List inputMappingProperties, + List correlationMappingProperties, + List payloadMappingProperties, + List metaMappingProperties, + MessageFormat messageFormat, + String eventStreamWithVersion) + throws RemoteException, UserStoreException, JWTClientException { + EventPublisherAdminServiceStub eventPublisherAdminServiceStub = DeviceMgtAPIUtils.getEventPublisherAdminServiceStub(); + // Check if adapter already exists, if so un-deploy it + try { + EventPublisherConfigurationDto eventPublisherConfigurationDto = eventPublisherAdminServiceStub + .getActiveEventPublisherConfiguration(publisherName); + if (eventPublisherConfigurationDto != null) { + eventPublisherAdminServiceStub.undeployActiveEventPublisherConfiguration(publisherName); + } + + // Adding attribute properties to DTOs + BasicOutputAdapterPropertyDto[] basicOutputAdapterPropertyDtos = + addPublisherConfigToDto(adapterProperties); + + if (eventPublisherAdminServiceStub.getActiveEventPublisherConfiguration(publisherName) == null) { + // Call stub deploy methods according to the message format + if (!messageFormat.toString().equals("wso2event")) { + if (!messageFormat.toString().equals("map")) { + if (messageFormat.toString().equals("xml")) { + eventPublisherAdminServiceStub.deployXmlEventPublisherConfiguration(publisherName + , eventStreamWithVersion, adapterType, inputMappingString + , basicOutputAdapterPropertyDtos, eventStreamWithVersion + , customMapping); + } else if (messageFormat.toString().equals("text")) { + eventPublisherAdminServiceStub.deployTextEventPublisherConfiguration(publisherName + , eventStreamWithVersion, adapterType, inputMappingString + , basicOutputAdapterPropertyDtos, eventStreamWithVersion + , customMapping); + } else { + eventPublisherAdminServiceStub.deployJsonEventPublisherConfiguration(publisherName + , eventStreamWithVersion, adapterType, inputMappingString + , basicOutputAdapterPropertyDtos, eventStreamWithVersion + , customMapping); + } + } else { + org.wso2.carbon.event.publisher.stub.types.EventMappingPropertyDto[] inputMappingPropertyDtos = + addPublisherMappingToDto(inputMappingProperties); + eventPublisherAdminServiceStub.deployMapEventPublisherConfiguration(publisherName + , eventStreamWithVersion, adapterType, inputMappingPropertyDtos + , basicOutputAdapterPropertyDtos, customMapping); + } + } else { + org.wso2.carbon.event.publisher.stub.types.EventMappingPropertyDto[] correlationMappingPropertyDtos = + addPublisherMappingToDto(correlationMappingProperties); + org.wso2.carbon.event.publisher.stub.types.EventMappingPropertyDto[] metaMappingPropertyDtos = + addPublisherMappingToDto(metaMappingProperties); + org.wso2.carbon.event.publisher.stub.types.EventMappingPropertyDto[] payloadMappingPropertyDtos = + addPublisherMappingToDto(payloadMappingProperties); + + eventPublisherAdminServiceStub.deployWSO2EventPublisherConfiguration(publisherName + , eventStreamWithVersion, adapterType, metaMappingPropertyDtos + , correlationMappingPropertyDtos, payloadMappingPropertyDtos + , basicOutputAdapterPropertyDtos, customMapping + , eventStreamWithVersion); + } + + } + } finally { + cleanup(eventPublisherAdminServiceStub); + } + } + + /** + * @param executionPlanName Siddhi execution plan name + * @param executionPlanData Siddhi execution plan + * @throws RemoteException exception that may occur during a remote method call + * @throws UserStoreException exception that may occur during JWT token generation + * @throws JWTClientException exception that may occur during connecting to client store + * @throws InvalidExecutionPlanException exception that may occur if execution plan validation fails + */ + private void publishSiddhiExecutionPlan(String executionPlanName, String executionPlanData) + throws RemoteException, UserStoreException, JWTClientException, + InvalidExecutionPlanException { + EventProcessorAdminServiceStub eventProcessorAdminServiceStub = null; + // Flag to check the existence of a plan + boolean isAvailable = false; + try { + eventProcessorAdminServiceStub = DeviceMgtAPIUtils.getEventProcessorAdminServiceStub(); + // Validate the plan code + String validationResponse = eventProcessorAdminServiceStub.validateExecutionPlan(executionPlanData); + if (validationResponse.equals("success")) { + String activeExecutionPlanName = null; + // Get active plans + ExecutionPlanConfigurationDto[] allActiveExecutionPlanConfigs = eventProcessorAdminServiceStub.getAllActiveExecutionPlanConfigurations(); + if (allActiveExecutionPlanConfigs != null) { + for (ExecutionPlanConfigurationDto activeExecutionPlanConfig : allActiveExecutionPlanConfigs) { + activeExecutionPlanName = activeExecutionPlanConfig.getName(); + if (activeExecutionPlanName.equals(executionPlanName)) { + isAvailable = true; + } + } + } + // Edit existing plan + if (isAvailable) { + eventProcessorAdminServiceStub.editActiveExecutionPlan(executionPlanData, + executionPlanName); + } + // Create a new plan + else { + eventProcessorAdminServiceStub.deployExecutionPlan(executionPlanData); + } + } else { + String errMsg = "Execution plan validation failed: " + validationResponse; + log.error(errMsg); + throw new InvalidExecutionPlanException(errMsg); + } + } finally { + cleanup(eventProcessorAdminServiceStub); + } + } + + private EventStreamAttributeDto[] addEventAttributesToDto(List attributes) { + EventStreamAttributeDto[] eventStreamAttributeDtos = new EventStreamAttributeDto[attributes.size()]; + for (int i = 0; i < attributes.size(); i++) { + EventStreamAttributeDto eventStreamAttributeDto = new EventStreamAttributeDto(); + eventStreamAttributeDto.setAttributeName(attributes.get(i).getName()); + eventStreamAttributeDto.setAttributeType(attributes.get(i).getType().toString()); + eventStreamAttributeDtos[i] = eventStreamAttributeDto; + } + return eventStreamAttributeDtos; + } + + + private BasicInputAdapterPropertyDto[] addReceiverConfigToDto( + List adapterProperties) { + BasicInputAdapterPropertyDto[] basicInputAdapterPropertyDtos + = new BasicInputAdapterPropertyDto[adapterProperties.size()]; + for (int i = 0; i < adapterProperties.size(); i++) { + BasicInputAdapterPropertyDto basicInputAdapterPropertyDto = new BasicInputAdapterPropertyDto(); + basicInputAdapterPropertyDto.setKey(adapterProperties.get(i).getKey()); + basicInputAdapterPropertyDto.setValue(adapterProperties.get(i).getValue()); + basicInputAdapterPropertyDtos[i] = basicInputAdapterPropertyDto; + } + return basicInputAdapterPropertyDtos; + } + + private EventMappingPropertyDto[] addReceiverMappingToDto(List mapProperties) { + EventMappingPropertyDto[] eventMappingPropertyDtos = new EventMappingPropertyDto[mapProperties.size()]; + for (int i = 0; i < mapProperties.size(); i++) { + EventMappingPropertyDto eventMappingPropertyDto = new EventMappingPropertyDto(); + eventMappingPropertyDto.setName(mapProperties.get(i).getName()); + eventMappingPropertyDto.setType(mapProperties.get(i).getType()); + eventMappingPropertyDto.setValueOf(mapProperties.get(i).getValueOf()); + eventMappingPropertyDtos[i] = eventMappingPropertyDto; + } + return eventMappingPropertyDtos; + } + + private BasicOutputAdapterPropertyDto[] addPublisherConfigToDto( + List adapterProperties) { + BasicOutputAdapterPropertyDto[] basicOutputAdapterPropertyDtos = + new BasicOutputAdapterPropertyDto[adapterProperties.size()]; + for (int i = 0; i < adapterProperties.size(); i++) { + BasicOutputAdapterPropertyDto basicOutputAdapterPropertyDto = + new BasicOutputAdapterPropertyDto(); + basicOutputAdapterPropertyDto.setKey(adapterProperties.get(i).getKey()); + basicOutputAdapterPropertyDto.setValue(adapterProperties.get(i).getValue()); + basicOutputAdapterPropertyDtos[i] = basicOutputAdapterPropertyDto; + } + return basicOutputAdapterPropertyDtos; + } + + private org.wso2.carbon.event.publisher.stub.types.EventMappingPropertyDto[] addPublisherMappingToDto + (List mapProperties) { + org.wso2.carbon.event.publisher.stub.types.EventMappingPropertyDto[] eventMappingPropertyDtos + = new org.wso2.carbon.event.publisher.stub.types.EventMappingPropertyDto[mapProperties.size()]; + for (int i = 0; i < mapProperties.size(); i++) { + org.wso2.carbon.event.publisher.stub.types.EventMappingPropertyDto eventMappingPropertyDto + = new org.wso2.carbon.event.publisher.stub.types.EventMappingPropertyDto(); + eventMappingPropertyDto.setName(mapProperties.get(i).getName()); + eventMappingPropertyDto.setType(mapProperties.get(i).getType()); + eventMappingPropertyDto.setValueOf(mapProperties.get(i).getValueOf()); + eventMappingPropertyDtos[i] = eventMappingPropertyDto; + } + return eventMappingPropertyDtos; + } + + private void cleanup(Stub stub) { + if (stub != null) { + try { + stub.cleanup(); + } catch (AxisFault axisFault) { + log.warn("Failed to clean the stub " + stub.getClass()); + } + } + } +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/DeviceMgtAPIUtils.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/DeviceMgtAPIUtils.java index a795fca1a5..60ddb95852 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/DeviceMgtAPIUtils.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/DeviceMgtAPIUtils.java @@ -56,6 +56,7 @@ import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderService; import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse; import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.EventAttributeList; import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.InputValidationException; +import org.wso2.carbon.event.processor.stub.EventProcessorAdminServiceStub; import org.wso2.carbon.event.publisher.stub.EventPublisherAdminServiceStub; import org.wso2.carbon.event.receiver.stub.EventReceiverAdminServiceStub; import org.wso2.carbon.event.stream.stub.EventStreamAdminServiceStub; @@ -109,6 +110,7 @@ public class DeviceMgtAPIUtils { private static final String EVENT_PUBLISHER_CONTEXT = "EventPublisherAdminService/"; private static final String EVENT_STREAM_CONTEXT = "EventStreamAdminService/"; private static final String EVENT_PERSISTENCE_CONTEXT = "EventStreamPersistenceAdminService/"; + private static final String EVENT_PROCESSOR_CONTEXT = "EventProcessorAdminService"; private static final String AUTHORIZATION_HEADER = "Authorization"; private static final String AUTHORIZATION_HEADER_VALUE = "Bearer"; public static final String DAS_PORT = "${iot.analytics.https.port}"; @@ -637,6 +639,49 @@ public class DeviceMgtAPIUtils { return eventStreamPersistenceAdminServiceStub; } + /** + * + * @return + * @throws AxisFault + * @throws UserStoreException + * @throws JWTClientException + */ + public static EventProcessorAdminServiceStub getEventProcessorAdminServiceStub() + throws AxisFault, UserStoreException, JWTClientException { + // Send alert to event-processing + EventProcessorAdminServiceStub eventProcessorAdminServiceStub = new EventProcessorAdminServiceStub( + Utils.replaceSystemProperty(DAS_ADMIN_SERVICE_EP + EVENT_PROCESSOR_CONTEXT)); + Options eventProcessorOption = eventProcessorAdminServiceStub._getServiceClient().getOptions(); + if (eventProcessorOption == null) { + eventProcessorOption = new Options(); + } + // Get the tenant Domain + int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); + String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(); + String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUserRealm() + .getRealmConfiguration().getAdminUserName() + "@" + tenantDomain; + // Create the SSL context with the loaded TrustStore/keystore. + JWTClient jwtClient = getJWTClientManagerService().getJWTClient(); + + String authValue = AUTHORIZATION_HEADER_VALUE + " " + new String(Base64.encodeBase64( + jwtClient.getJwtToken(username).getBytes())); + + List
list = new ArrayList<>(); + Header httpHeader = new Header(); + httpHeader.setName(AUTHORIZATION_HEADER); + httpHeader.setValue(authValue); + list.add(httpHeader);//"https" + + eventProcessorOption.setProperty(HTTPConstants.HTTP_HEADERS, list); + eventProcessorOption.setProperty(HTTPConstants.CUSTOM_PROTOCOL_HANDLER + , new Protocol(DEFAULT_HTTP_PROTOCOL + , (ProtocolSocketFactory) new SSLProtocolSocketFactory(sslContext) + , Integer.parseInt(Utils.replaceSystemProperty(DAS_PORT)))); + + eventProcessorAdminServiceStub._getServiceClient().setOptions(eventProcessorOption); + return eventProcessorAdminServiceStub; + } + /** * This method is used to create the Cache that holds the event definition of the device type.. * 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 7a2013037a..6bdbfcb53f 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 @@ -46,6 +46,7 @@ + @@ -93,6 +94,7 @@ + From 35b03d387c71914ba2cd9bf1601e67ed477f3d6c Mon Sep 17 00:00:00 2001 From: Yohan Avishke Date: Mon, 2 Sep 2019 00:47:25 +0530 Subject: [PATCH 2/8] fix: Change in file name File name of AttributeDataType was changed to AttributeType to resolve some conflicts with import statements. --- .../device/mgt/jaxrs/beans/analytics/Attribute.java | 10 +++++----- .../{AttributeDataType.java => AttributeType.java} | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) rename components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/{AttributeDataType.java => AttributeType.java} (96%) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/Attribute.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/Attribute.java index d661fdef9f..8c334972e3 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/Attribute.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/Attribute.java @@ -31,15 +31,15 @@ public class Attribute { private String name; @ApiModelProperty(value = "Event attribute data type") @JsonProperty("type") - private AttributeDataType type; + private AttributeType type; public Attribute() { } - public Attribute(String name, AttributeDataType attributeDataType) { + public Attribute(String name, AttributeType attributeType) { this.name = name; - this.type = attributeDataType; + this.type = attributeType; } public String getName() { return name; @@ -49,11 +49,11 @@ public class Attribute { this.name = name; } - public AttributeDataType getType() { + public AttributeType getType() { return type; } - public void setType(AttributeDataType type) { + public void setType(AttributeType type) { this.type = type; } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/AttributeDataType.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/AttributeType.java similarity index 96% rename from components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/AttributeDataType.java rename to components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/AttributeType.java index d7acab5696..660176a3cc 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/AttributeDataType.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/AttributeType.java @@ -21,7 +21,7 @@ package org.wso2.carbon.device.mgt.jaxrs.beans.analytics; /** * Attribute data types */ -public enum AttributeDataType { +public enum AttributeType { STRING, LONG, BOOL, INT, FLOAT, DOUBLE; @Override From bed68289b539cf8669f89c0da3da9f5c85af5778 Mon Sep 17 00:00:00 2001 From: Yohan Avishke Date: Mon, 2 Sep 2019 10:10:22 +0530 Subject: [PATCH 3/8] Make stream persisting optional At the moment of creating a stream it will be persisted by default. This was made a optional choice by using a query flag through this commit. --- .../mgt/jaxrs/service/api/DeviceEventManagementService.java | 5 +++-- .../jaxrs/service/impl/DeviceEventManagementServiceImpl.java | 5 ++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceEventManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceEventManagementService.java index 26904a9cdf..c49f9698c1 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceEventManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceEventManagementService.java @@ -123,6 +123,7 @@ public interface DeviceEventManagementService { Response deployDeviceTypeEventDefinition(@ApiParam(name = "type", value = "The device type, such as android, ios," + " and windows.", required = false) @PathParam("type")String deviceType, + @QueryParam("skipPersist")boolean skipPersist, @ApiParam(name = "deviceTypeEvent", value = "Add the data to complete " + "the DeviceTypeEvent object.", required = true) @Valid DeviceTypeEvent deviceTypeEvent); @@ -357,7 +358,7 @@ public interface DeviceEventManagementService { @QueryParam("max") double max ); - + @GET @Path("/{type}") @ApiOperation( @@ -411,4 +412,4 @@ public interface DeviceEventManagementService { " ios, or windows.", required = false) @PathParam("type")String deviceType) ; -} \ No newline at end of file +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceEventManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceEventManagementServiceImpl.java index 2bbcee2d43..e6fe0e4f8c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceEventManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceEventManagementServiceImpl.java @@ -192,6 +192,7 @@ public class DeviceEventManagementServiceImpl implements DeviceEventManagementSe @Path("/{type}") @Override public Response deployDeviceTypeEventDefinition(@PathParam("type") String deviceType, + @QueryParam("skipPersist") boolean skipPersist, @Valid DeviceTypeEvent deviceTypeEvent) { TransportType transportType = deviceTypeEvent.getTransportType(); EventAttributeList eventAttributes = deviceTypeEvent.getEventAttributeList(); @@ -208,7 +209,9 @@ public class DeviceEventManagementServiceImpl implements DeviceEventManagementSe String streamNameWithVersion = streamName + ":" + Constants.DEFAULT_STREAM_VERSION; publishStreamDefinitons(streamName, Constants.DEFAULT_STREAM_VERSION, deviceType, eventAttributes); publishEventReceivers(streamNameWithVersion, transportType, tenantDomain, deviceType); - publishEventStore(streamName, Constants.DEFAULT_STREAM_VERSION, eventAttributes); + if (!skipPersist) { + publishEventStore(streamName, Constants.DEFAULT_STREAM_VERSION, eventAttributes); + } publishWebsocketPublisherDefinition(streamNameWithVersion, deviceType); try { PrivilegedCarbonContext.startTenantFlow(); From 0af18b0255ced6469fc89acdff6a83f91bffe538 Mon Sep 17 00:00:00 2001 From: Turcy Date: Thu, 5 Sep 2019 16:25:22 +0530 Subject: [PATCH 4/8] Make device analytics timestamp human-readable --- .../public/js/device.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.default.device.type.analytics-view/public/js/device.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.default.device.type.analytics-view/public/js/device.js index e7a216dd3e..e18af31433 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.default.device.type.analytics-view/public/js/device.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.default.device.type.analytics-view/public/js/device.js @@ -45,7 +45,14 @@ function drawTable(from, to) { order: [], ajax: { url: "/devicemgt/api/stats/paginate", - data: buildAjaxData + data: buildAjaxData, + dataSrc: function(json) { + return json.data.map(function(event) { + event[0] = new moment(event[0]). + format("YYYY-MM-DD HH:mm:ss.SSS"); + return event; + }) + } } }); } @@ -71,4 +78,4 @@ function buildAjaxData (){ return obj; -} \ No newline at end of file +} From 1cc5209c4edccd3d47f1dfbbf647ecae6133f998 Mon Sep 17 00:00:00 2001 From: milanperera Date: Sun, 8 Sep 2019 21:58:17 +0200 Subject: [PATCH 5/8] Add certificate mgt table creation --- .../src/main/resources/dbscripts/cdm/h2.sql | 9 ++++++++ .../main/resources/dbscripts/cdm/mssql.sql | 10 +++++++++ .../main/resources/dbscripts/cdm/mysql.sql | 9 ++++++++ .../main/resources/dbscripts/cdm/oracle.sql | 21 +++++++++++++++++++ .../resources/dbscripts/cdm/postgresql.sql | 8 +++++++ 5 files changed, 57 insertions(+) diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/h2.sql b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/h2.sql index b4edb11609..7d0cff5556 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/h2.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/h2.sql @@ -8,6 +8,15 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE ( PRIMARY KEY (ID) ); +CREATE TABLE IF NOT EXISTS DM_DEVICE_CERTIFICATE ( + ID INTEGER auto_increment NOT NULL, + SERIAL_NUMBER VARCHAR(500) DEFAULT NULL, + CERTIFICATE BLOB DEFAULT NULL, + TENANT_ID INTEGER DEFAULT 0, + USERNAME VARCHAR(500) DEFAULT NULL, + PRIMARY KEY (ID) +); + CREATE TABLE IF NOT EXISTS DM_GROUP ( ID INTEGER AUTO_INCREMENT NOT NULL, GROUP_NAME VARCHAR(100) DEFAULT NULL, diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mssql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mssql.sql index bcb8073218..4a3882f06a 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mssql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mssql.sql @@ -10,6 +10,16 @@ CREATE TABLE DM_DEVICE_TYPE ( CONSTRAINT DEVICE_TYPE_NAME UNIQUE(NAME, PROVIDER_TENANT_ID) ); +IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[DM_DEVICE_CERTIFICATE]') AND TYPE IN (N'U')) +CREATE TABLE DM_DEVICE_CERTIFICATE ( + ID INTEGER IDENTITY(1,1) NOT NULL, + SERIAL_NUMBER VARCHAR(500) DEFAULT NULL, + CERTIFICATE VARBINARY(max) DEFAULT NULL, + TENANT_ID INTEGER DEFAULT 0, + USERNAME VARCHAR(500) DEFAULT NULL, +PRIMARY KEY (ID) +); + IF NOT EXISTS (SELECT * FROM SYS.INDEXES WHERE NAME = 'IDX_DEVICE_TYPE' AND OBJECT_ID = OBJECT_ID('DM_DEVICE_TYPE')) CREATE INDEX IDX_DEVICE_TYPE ON DM_DEVICE_TYPE (NAME, PROVIDER_TENANT_ID); diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mysql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mysql.sql index df2a6fbb4c..9d1f0bd4e4 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mysql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mysql.sql @@ -12,6 +12,15 @@ CREATE INDEX IDX_DEVICE_TYPE ON DM_DEVICE_TYPE (NAME, PROVIDER_TENANT_ID); CREATE INDEX IDX_DEVICE_NAME ON DM_DEVICE_TYPE (NAME); CREATE INDEX IDX_DEVICE_TYPE_DEVICE_NAME ON DM_DEVICE_TYPE(ID, NAME); +CREATE TABLE IF NOT EXISTS DM_DEVICE_CERTIFICATE ( + ID INTEGER auto_increment NOT NULL, + SERIAL_NUMBER VARCHAR(500) DEFAULT NULL, + CERTIFICATE BLOB DEFAULT NULL, + TENANT_ID INTEGER DEFAULT 0, + USERNAME VARCHAR(500) DEFAULT NULL, + PRIMARY KEY (ID) +)ENGINE = InnoDB; + CREATE TABLE IF NOT EXISTS DM_GROUP ( ID INTEGER AUTO_INCREMENT NOT NULL, GROUP_NAME VARCHAR(100) DEFAULT NULL, diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/oracle.sql b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/oracle.sql index 847c86d87f..9b5cc5dc1b 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/oracle.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/oracle.sql @@ -23,6 +23,27 @@ WHEN (NEW.ID IS NULL) END; / +CREATE TABLE DM_DEVICE_CERTIFICATE ( + ID NUMBER(10) NOT NULL, + SERIAL_NUMBER VARCHAR2(500) DEFAULT NULL, + CERTIFICATE BLOB DEFAULT NULL, + TENANT_ID NUMBER(10) DEFAULT 0, + USERNAME VARCHAR2(500) DEFAULT NULL, + PRIMARY KEY (ID) +) +/ + +-- Generate ID using sequence and trigger +CREATE SEQUENCE DM_DEVICE_CERTIFICATE_seq START WITH 1 INCREMENT BY 1 NOCACHE +/ +CREATE OR REPLACE TRIGGER DM_DEVICE_CERTIFICATE_seq_tr +BEFORE INSERT ON DM_DEVICE_CERTIFICATE FOR EACH ROW +WHEN (NEW.ID IS NULL) + BEGIN + SELECT DM_DEVICE_CERTIFICATE_seq.NEXTVAL INTO :NEW.ID FROM DUAL; + END; +/ + CREATE TABLE DM_GROUP ( ID NUMBER(10) NOT NULL, DESCRIPTION CLOB DEFAULT NULL, diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/postgresql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/postgresql.sql index e9b4e75eff..02d717f7e9 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/postgresql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/postgresql.sql @@ -8,6 +8,14 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE ( UNIQUE(NAME, PROVIDER_TENANT_ID) ); +CREATE TABLE IF NOT EXISTS DM_DEVICE_CERTIFICATE ( + ID BIGSERIAL NOT NULL PRIMARY KEY, + SERIAL_NUMBER VARCHAR(500) DEFAULT NULL, + CERTIFICATE BYTEA DEFAULT NULL, + TENANT_ID INTEGER DEFAULT 0, + USERNAME VARCHAR(500) DEFAULT NULL +); + CREATE TABLE IF NOT EXISTS DM_GROUP ( ID BIGSERIAL NOT NULL PRIMARY KEY, GROUP_NAME VARCHAR(100) DEFAULT NULL, From 3dff9fef80f8efefe09f6c7488995e71d98dcbb3 Mon Sep 17 00:00:00 2001 From: Yohan Avishke Date: Mon, 9 Sep 2019 19:51:40 +0530 Subject: [PATCH 6/8] Create Endpoints to deploy DAS artifacts as Strings Four new endpoints were created to deploy DAS artifacts. These apis will accept JSON payloads and convert them to Strings and will use those to deploy artifacts. These endpoints are different from the existing endpoints due to accepting different payloads and using different stubs to deploy. --- .../extension/api/util/APIUtil.java | 4 + .../mgt/jaxrs/beans/analytics/Adapter.java | 25 +- .../beans/analytics/AdapterConfiguration.java | 25 +- .../AdapterMappingConfiguration.java | 25 +- .../beans/analytics/AdapterProperty.java | 25 +- .../jaxrs/beans/analytics/AdapterType.java | 25 +- .../mgt/jaxrs/beans/analytics/Attribute.java | 25 +- .../jaxrs/beans/analytics/AttributeType.java | 30 +- .../beans/analytics/DeviceTypeEvent.java | 25 +- .../beans/analytics/EventAttributeList.java | 25 +- .../beans/analytics/EventAttributeLists.java | 62 --- .../jaxrs/beans/analytics/EventPublisher.java | 34 ++ .../jaxrs/beans/analytics/EventReceiver.java | 34 ++ .../jaxrs/beans/analytics/EventRecords.java | 25 +- .../jaxrs/beans/analytics/EventStream.java | 117 +++-- .../beans/analytics/MappingProperty.java | 25 +- .../jaxrs/beans/analytics/MessageFormat.java | 25 +- .../beans/analytics/SiddhiExecutionPlan.java | 49 +- .../jaxrs/beans/analytics/TransportType.java | 25 +- .../InvalidExecutionPlanException.java | 30 +- .../AnalyticsArtifactsManagementService.java | 454 ++++++++++++++++++ .../api/AnalyticsManagementService.java | 290 ----------- ...lyticsArtifactsManagementServiceImpl.java} | 396 ++++++++------- .../mgt/jaxrs/util/DeviceMgtAPIUtils.java | 8 - .../src/main/webapp/WEB-INF/cxf-servlet.xml | 6 +- 25 files changed, 1024 insertions(+), 790 deletions(-) delete mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/EventAttributeLists.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/EventPublisher.java create mode 100755 components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/EventReceiver.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/AnalyticsArtifactsManagementService.java delete mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/AnalyticsManagementService.java rename components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/{AnalyticsManagementServiceImpl.java => AnalyticsArtifactsManagementServiceImpl.java} (72%) diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/src/main/java/org/wso2/carbon/apimgt/application/extension/api/util/APIUtil.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/src/main/java/org/wso2/carbon/apimgt/application/extension/api/util/APIUtil.java index 54d68e7baa..cb7183266e 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/src/main/java/org/wso2/carbon/apimgt/application/extension/api/util/APIUtil.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/src/main/java/org/wso2/carbon/apimgt/application/extension/api/util/APIUtil.java @@ -44,6 +44,9 @@ public class APIUtil { private static final String DEFAULT_CDMF_API_TAG = "device_management"; private static final String DEFAULT_AGENT_API_TAG = "device_agent"; private static final String DEFAULT_CERT_API_TAG = "scep_management"; + private static final String DEFAULT_ANALYTICS_ARTIFACT_TAG = "analytics_artifacts_management"; + + public static final String PERMISSION_PROPERTY_NAME = "name"; public static String getAuthenticatedUser() { @@ -108,6 +111,7 @@ public class APIUtil { allowedApisTags.add(DEFAULT_CDMF_API_TAG); allowedApisTags.add(DEFAULT_CERT_API_TAG); allowedApisTags.add(DEFAULT_AGENT_API_TAG); + allowedApisTags.add(DEFAULT_ANALYTICS_ARTIFACT_TAG); return allowedApisTags; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/Adapter.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/Adapter.java index 2cafd461ff..f3d3bcb639 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/Adapter.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/Adapter.java @@ -1,20 +1,19 @@ /* - * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) 2019, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved. * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at + * Entgra (pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. + * http://www.apache.org/licenses/LICENSE-2.0 * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ package org.wso2.carbon.device.mgt.jaxrs.beans.analytics; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/AdapterConfiguration.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/AdapterConfiguration.java index ed518dd60e..5c0b820f41 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/AdapterConfiguration.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/AdapterConfiguration.java @@ -1,20 +1,19 @@ /* - * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) 2019, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved. * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at + * Entgra (pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. + * http://www.apache.org/licenses/LICENSE-2.0 * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ package org.wso2.carbon.device.mgt.jaxrs.beans.analytics; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/AdapterMappingConfiguration.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/AdapterMappingConfiguration.java index afb499ee83..3984b23065 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/AdapterMappingConfiguration.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/AdapterMappingConfiguration.java @@ -1,20 +1,19 @@ /* - * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) 2019, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved. * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at + * Entgra (pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. + * http://www.apache.org/licenses/LICENSE-2.0 * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ package org.wso2.carbon.device.mgt.jaxrs.beans.analytics; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/AdapterProperty.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/AdapterProperty.java index 399ef3271f..4457da1c2a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/AdapterProperty.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/AdapterProperty.java @@ -1,20 +1,19 @@ /* - * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) 2019, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved. * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at + * Entgra (pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. + * http://www.apache.org/licenses/LICENSE-2.0 * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ package org.wso2.carbon.device.mgt.jaxrs.beans.analytics; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/AdapterType.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/AdapterType.java index 5227c4973c..413be9fd90 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/AdapterType.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/AdapterType.java @@ -1,20 +1,19 @@ /* - * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) 2019, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved. * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at + * Entgra (pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. + * http://www.apache.org/licenses/LICENSE-2.0 * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ package org.wso2.carbon.device.mgt.jaxrs.beans.analytics; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/Attribute.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/Attribute.java index 8c334972e3..e112782a64 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/Attribute.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/Attribute.java @@ -1,20 +1,19 @@ /* - * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) 2019, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved. * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at + * Entgra (pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. + * http://www.apache.org/licenses/LICENSE-2.0 * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ package org.wso2.carbon.device.mgt.jaxrs.beans.analytics; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/AttributeType.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/AttributeType.java index 660176a3cc..1fde19f8a9 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/AttributeType.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/AttributeType.java @@ -1,20 +1,19 @@ /* - * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) 2019, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved. * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at + * Entgra (pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. + * http://www.apache.org/licenses/LICENSE-2.0 * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ package org.wso2.carbon.device.mgt.jaxrs.beans.analytics; @@ -23,10 +22,5 @@ package org.wso2.carbon.device.mgt.jaxrs.beans.analytics; */ public enum AttributeType { STRING, LONG, BOOL, INT, FLOAT, DOUBLE; - - @Override - public String toString() { - return super.toString().toLowerCase(); - } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/DeviceTypeEvent.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/DeviceTypeEvent.java index 7ff162b357..b8e07df6d5 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/DeviceTypeEvent.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/DeviceTypeEvent.java @@ -1,20 +1,19 @@ /* - * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) 2019, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved. * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at + * Entgra (pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. + * http://www.apache.org/licenses/LICENSE-2.0 * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ package org.wso2.carbon.device.mgt.jaxrs.beans.analytics; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/EventAttributeList.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/EventAttributeList.java index fe9bd39e03..a80604bbe6 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/EventAttributeList.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/EventAttributeList.java @@ -1,20 +1,19 @@ /* - * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) 2019, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved. * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at + * Entgra (pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. + * http://www.apache.org/licenses/LICENSE-2.0 * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ package org.wso2.carbon.device.mgt.jaxrs.beans.analytics; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/EventAttributeLists.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/EventAttributeLists.java deleted file mode 100644 index 23ee3fb4d5..0000000000 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/EventAttributeLists.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.wso2.carbon.device.mgt.jaxrs.beans.analytics; - -import io.swagger.annotations.ApiModelProperty; -import java.util.List; - -/** - * Stream event attribute data - * Attributes : three lists for each attribute type - */ -public class EventAttributeLists { - @ApiModelProperty(value = "Meta attribute list") - private List metaAttributes; - @ApiModelProperty(value = "Correlation attribute list") - private List correlationAttributes; - @ApiModelProperty(value = "Payload attribute list") - private List payloadAttributes; - - public List getMetaAttributes() { - return metaAttributes; - } - - public void setMetaAttributes( - List metaAttributes) { - this.metaAttributes = metaAttributes; - } - - public List getCorrelationAttributes() { - return correlationAttributes; - } - - public void setCorrelationAttributes( - List correlationAttributes) { - this.correlationAttributes = correlationAttributes; - } - - public List getPayloadAttributes() { - return payloadAttributes; - } - - public void setPayloadAttributes( - List payloadAttributes) { - this.payloadAttributes = payloadAttributes; - } -} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/EventPublisher.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/EventPublisher.java new file mode 100644 index 0000000000..a7e7a1f84b --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/EventPublisher.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2019, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved. + * + * Entgra (pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.device.mgt.jaxrs.beans.analytics; + +import io.swagger.annotations.ApiModelProperty; + +public class EventPublisher { + @ApiModelProperty(value = "Publisher definition") + private String definition; + + public String getDefinition() { + return definition; + } + + public void setDefinition(String definition) { + this.definition = definition; + } +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/EventReceiver.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/EventReceiver.java new file mode 100755 index 0000000000..dd0c00f8db --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/EventReceiver.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2019, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved. + * + * Entgra (pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.device.mgt.jaxrs.beans.analytics; + +import io.swagger.annotations.ApiModelProperty; + +public class EventReceiver { + @ApiModelProperty(value = "Stream definition") + private String definition; + + public String getDefinition() { + return definition; + } + + public void setDefinition(String definition) { + this.definition = definition; + } +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/EventRecords.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/EventRecords.java index 0dacde3833..84589cd891 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/EventRecords.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/EventRecords.java @@ -1,20 +1,19 @@ /* - * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) 2019, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved. * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at + * Entgra (pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. + * http://www.apache.org/licenses/LICENSE-2.0 * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ package org.wso2.carbon.device.mgt.jaxrs.beans.analytics; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/EventStream.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/EventStream.java index f2ff053f66..17100e75f2 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/EventStream.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/EventStream.java @@ -1,24 +1,27 @@ /* - * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) 2019, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved. * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at + * Entgra (pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. + * http://www.apache.org/licenses/LICENSE-2.0 * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ package org.wso2.carbon.device.mgt.jaxrs.beans.analytics; +import com.sun.istack.NotNull; import io.swagger.annotations.ApiModelProperty; +import org.hibernate.validator.constraints.NotEmpty; + +import java.util.List; /** * Stream definition @@ -26,44 +29,86 @@ import io.swagger.annotations.ApiModelProperty; */ public class EventStream { @ApiModelProperty(value = "Stream name") - private String streamName; + private String name; @ApiModelProperty(value = "Stream version") - private String streamVersion; - @ApiModelProperty(value = "Stream definition") - private String streamDefinition; - @ApiModelProperty(value = "Stream property attribute lists") - private EventAttributeLists eventAttributeLists; + private String version; + @ApiModelProperty(value = "Stream nickName") + private String nickName; + @ApiModelProperty(value = "Stream description") + private String description; + @ApiModelProperty(value = "Meta attribute list") + private List metaData; + @ApiModelProperty(value = "Correlation attribute list") + private List correlationData; + @ApiModelProperty(value = "Payload attribute list") + private List payloadData; + @ApiModelProperty(value = "Stream definition") @NotNull @NotEmpty + private String definition; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + public String getNickName() { + return nickName; + } + + public void setNickName(String nickName) { + this.nickName = nickName; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } - public String getStreamName() { - return streamName; + public List getMetaData() { + return metaData; } - public void setStreamName(String streamName) { - this.streamName = streamName; + public void setMetaData( + List metaData) { + this.metaData = metaData; } - public String getStreamVersion() { - return streamVersion; + public List getCorrelationData() { + return correlationData; } - public void setStreamVersion(String streamVersion) { - this.streamVersion = streamVersion; + public void setCorrelationData( + List correlationData) { + this.correlationData = correlationData; } - public String getStreamDefinition() { - return streamDefinition; + public List getPayloadData() { + return payloadData; } - public void setStreamDefinition(String streamDefinition) { - this.streamDefinition = streamDefinition; + public void setPayloadData( + List payloadData) { + this.payloadData = payloadData; } - public EventAttributeLists getEventAttributeLists() { - return eventAttributeLists; + public String getDefinition() { + return definition; } - public void setEventAttributeLists( - EventAttributeLists eventAttributeLists) { - this.eventAttributeLists = eventAttributeLists; + public void setDefinition(String definition) { + this.definition = definition; } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/MappingProperty.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/MappingProperty.java index 05887be303..1fbbc60064 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/MappingProperty.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/MappingProperty.java @@ -1,20 +1,19 @@ /* - * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) 2019, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved. * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at + * Entgra (pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. + * http://www.apache.org/licenses/LICENSE-2.0 * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ package org.wso2.carbon.device.mgt.jaxrs.beans.analytics; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/MessageFormat.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/MessageFormat.java index 9df8a4bd0e..f1ef70de91 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/MessageFormat.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/MessageFormat.java @@ -1,20 +1,19 @@ /* - * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) 2019, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved. * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at + * Entgra (pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. + * http://www.apache.org/licenses/LICENSE-2.0 * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ package org.wso2.carbon.device.mgt.jaxrs.beans.analytics; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/SiddhiExecutionPlan.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/SiddhiExecutionPlan.java index 0c68e91478..597a932516 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/SiddhiExecutionPlan.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/SiddhiExecutionPlan.java @@ -1,20 +1,19 @@ /* - * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) 2019, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved. * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at + * Entgra (pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. + * http://www.apache.org/licenses/LICENSE-2.0 * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ package org.wso2.carbon.device.mgt.jaxrs.beans.analytics; @@ -22,27 +21,17 @@ import io.swagger.annotations.ApiModelProperty; /** * Execution plan definition including : - * Attributes : Name and Plan data. + * Attributes : Plan data. */ public class SiddhiExecutionPlan { - @ApiModelProperty(value = "Execution plan name") - private String executionPlanName; - @ApiModelProperty(value = "Execution plan") - private String executionPlanData; - - public String getExecutionPlanName() { - return executionPlanName; - } - - public void setExecutionPlanName(String executionPlanName) { - this.executionPlanName = executionPlanName; - } + @ApiModelProperty(value = "Execution plan definition") + private String definition; - public String getExecutionPlanData() { - return executionPlanData; + public String getDefinition() { + return definition; } - public void setExecutionPlanData(String executionPlanData) { - this.executionPlanData = executionPlanData; + public void setDefinition(String definition) { + this.definition = definition; } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/TransportType.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/TransportType.java index 58eae4e616..abf6122459 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/TransportType.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/analytics/TransportType.java @@ -1,20 +1,19 @@ /* - * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) 2019, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved. * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at + * Entgra (pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. + * http://www.apache.org/licenses/LICENSE-2.0 * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ package org.wso2.carbon.device.mgt.jaxrs.beans.analytics; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/exception/InvalidExecutionPlanException.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/exception/InvalidExecutionPlanException.java index a741f67fb0..1d40634f3d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/exception/InvalidExecutionPlanException.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/exception/InvalidExecutionPlanException.java @@ -18,19 +18,31 @@ */ package org.wso2.carbon.device.mgt.jaxrs.exception; -public class InvalidExecutionPlanException extends Exception{ - private String errorMessage; +import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse; +import org.wso2.carbon.device.mgt.jaxrs.util.Constants; - public String getErrorMessage() { - return errorMessage; +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.Response; + +public class InvalidExecutionPlanException extends WebApplicationException { + private String message; + private static final long serialVersionUID = 7583096344745990515L; + + public InvalidExecutionPlanException(ErrorResponse error) { + super(Response.status(Response.Status.NOT_FOUND).entity(error).build()); } - public void setErrorMessage(String errorMessage) { - this.errorMessage = errorMessage; + public InvalidExecutionPlanException(ErrorDTO errorDTO) { + super(Response.status(Response.Status.NOT_FOUND) + .entity(errorDTO) + .header(Constants.DeviceConstants.HEADER_CONTENT_TYPE, Constants.DeviceConstants.APPLICATION_JSON) + .build()); + message = errorDTO.getDescription(); } - public InvalidExecutionPlanException(String msg) { - super(msg); - setErrorMessage(msg); + @Override + public String getMessage() { + return message; } + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/AnalyticsArtifactsManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/AnalyticsArtifactsManagementService.java new file mode 100644 index 0000000000..260ec66a11 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/AnalyticsArtifactsManagementService.java @@ -0,0 +1,454 @@ +/* + * Copyright (c) 2019, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved. + * + * Entgra (pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.wso2.carbon.device.mgt.jaxrs.service.api; + +import org.wso2.carbon.apimgt.annotations.api.Scope; +import org.wso2.carbon.apimgt.annotations.api.Scopes; +import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse; +import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.Adapter; +import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.EventStream; +import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.SiddhiExecutionPlan; +import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.EventPublisher; +import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.EventReceiver; +import org.wso2.carbon.device.mgt.jaxrs.util.Constants; + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiResponse; +import io.swagger.annotations.ApiResponses; +import io.swagger.annotations.Extension; +import io.swagger.annotations.ExtensionProperty; +import io.swagger.annotations.Info; +import io.swagger.annotations.ResponseHeader; +import io.swagger.annotations.SwaggerDefinition; +import io.swagger.annotations.Tag; + +import javax.validation.Valid; +import javax.ws.rs.Consumes; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +@SwaggerDefinition( + info = @Info( + version = "1.0.0", + title = "", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = "name", value = "AnalyticsArtifactsManagement"), + @ExtensionProperty(name = "context", value = "/api/device-mgt/v1.0/analytics/artifacts"), + }) + } + ), + tags = { + @Tag(name = "analytics_artifacts_management", description = "") + } +) +@Scopes( + scopes = { + @Scope( + name = "Create Event Stream Artifact", + description = "Create Event Stream Artifact", + key = "perm:analytics:artifacts:stream", + permissions = {"/device-mgt/analytics/artifacts/stream/add"} + ), + @Scope( + name = "Create Event Receiver Artifact", + description = "Create Event Receiver Artifact", + key = "perm:analytics:artifacts:receiver", + permissions = {"/device-mgt/analytics/artifacts/receiver/add"} + ), + @Scope( + name = "Create Event Publisher Artifact", + description = "Create Event Publisher Artifact", + key = "perm:analytics:artifacts:publisher", + permissions = {"/device-mgt/analytics/artifacts/publisher/add"} + ), + @Scope( + name = "Create Siddhi Script Artifact", + description = "Create Siddhi Script Artifact", + key = "perm:analytics:artifacts:siddhi", + permissions = {"/device-mgt/analytics/artifacts/siddhi-script/add"} + ) + } +) + +@Path("/analytics/artifacts") +@Api(value = "Analytics Artifacts Management", description = "This API corresponds to services" + + " related to Analytics Artifacts management") +public interface AnalyticsArtifactsManagementService { + + @POST + @Consumes(MediaType.APPLICATION_JSON) + @Path("/stream/{id}") + @ApiOperation( + httpMethod = "POST", + value = "Create Event Stream Artifact as String", + notes = "Deploy a Json Stream Artifact in Analytics server.", + tags = "Analytics Artifacts Management", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "perm:analytics:artifacts:stream") + }) + } + ) + @ApiResponses( + value = { + @ApiResponse( + code = 200, + message = "OK. \n Successfully deployed the Stream Artifact.", + responseHeaders = { + @ResponseHeader( + name = "Content-Type", + description = "The content type of the body"), + @ResponseHeader( + name = "ETag", + description = "Entity Tag of the response resource.\n" + + "Used by caches, or in conditional requests."), + @ResponseHeader( + name = "Last-Modified", + description = + "Date and time the resource was last modified.\n" + + "Used by caches, or in conditional requests."), + } + ), + @ApiResponse( + code = 400, + message = "Bad Request."), + @ApiResponse( + code = 406, + message = "Not Acceptable.\n The requested media type is not supported."), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n Server error occurred while deploying the " + + "Stream Artifact.", + response = ErrorResponse.class) + } + ) + Response deployEventDefinitionAsString(@PathParam("id") String id, + @QueryParam("isEdited") boolean isEdited, + @Valid EventStream stream); + + @POST + @Consumes(MediaType.APPLICATION_JSON) + @Path("/stream") + @ApiOperation( + httpMethod = "POST", + value = "Create Event Stream Artifact as DTO", + notes = "Deploy a Json Stream Artifact in Analytics server.", + tags = "Analytics Artifacts Management", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "perm:analytics:artifacts:stream") + }) + } + ) + @ApiResponses( + value = { + @ApiResponse( + code = 200, + message = "OK. \n Successfully deployed the Stream Artifact.", + responseHeaders = { + @ResponseHeader( + name = "Content-Type", + description = "The content type of the body"), + @ResponseHeader( + name = "ETag", + description = "Entity Tag of the response resource.\n" + + "Used by caches, or in conditional requests."), + @ResponseHeader( + name = "Last-Modified", + description = + "Date and time the resource was last modified.\n" + + "Used by caches, or in conditional requests."), + } + ), + @ApiResponse( + code = 400, + message = "Bad Request."), + @ApiResponse( + code = 406, + message = "Not Acceptable.\n The requested media type is not supported."), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n Server error occurred while deploying the " + + "Stream Artifact.", + response = ErrorResponse.class) + } + ) + Response deployEventDefinitionAsDto(@Valid EventStream stream); + + @POST + @Consumes(MediaType.APPLICATION_JSON) + @Path("/receiver/{name}") + @ApiOperation( + httpMethod = "POST", + value = "Create Event Receiver Artifact as String", + notes = "Deploy a XML Event Receiver Artifact in Analytics server.", + tags = "Analytics Artifacts Management", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "perm:analytics:artifacts:receiver") + }) + } + ) + @ApiResponses( + value = { + @ApiResponse( + code = 200, + message = "OK. \n Successfully deployed the Receiver Artifact.", + responseHeaders = { + @ResponseHeader( + name = "Content-Type", + description = "The content type of the body."), + @ResponseHeader( + name = "ETag", + description = "Entity Tag of the response resource.\n" + + "Used by caches, or in conditional requests."), + @ResponseHeader( + name = "Last-Modified", + description = + "Date and time the resource was last modified.\n" + + "Used by caches, or in conditional requests."), + } + ), + @ApiResponse( + code = 400, + message = + "Bad Request."), + @ApiResponse( + code = 406, + message = "Not Acceptable.\n The requested media type is not supported."), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n Server error occurred while deploying the " + + "Event Receiver Artifact.", + response = ErrorResponse.class) + } + ) + Response deployEventReceiverAsString(@PathParam("name") String name, + @QueryParam("isEdited") boolean isEdited, + @Valid EventReceiver receiver); + + @POST + @Consumes(MediaType.APPLICATION_JSON) + @Path("/receiver") + @ApiOperation( + httpMethod = "POST", + value = "Create Event Receiver Artifact as DTO", + notes = "Deploy a JSON Event Receiver Artifact in Analytics server.", + tags = "Analytics Artifacts Management", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "perm:analytics:artifacts:receiver") + }) + } + ) + @ApiResponses( + value = { + @ApiResponse( + code = 200, + message = "OK. \n Successfully deployed the Receiver Artifact.", + responseHeaders = { + @ResponseHeader( + name = "Content-Type", + description = "The content type of the body."), + @ResponseHeader( + name = "ETag", + description = "Entity Tag of the response resource.\n" + + "Used by caches, or in conditional requests."), + @ResponseHeader( + name = "Last-Modified", + description = + "Date and time the resource was last modified.\n" + + "Used by caches, or in conditional requests."), + } + ), + @ApiResponse( + code = 400, + message = + "Bad Request."), + @ApiResponse( + code = 406, + message = "Not Acceptable.\n The requested media type is not supported."), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n Server error occurred while deploying the " + + "Event Receiver Artifact.", + response = ErrorResponse.class) + } + ) + Response deployEventReceiverAsDto(@Valid Adapter receiver); + + @POST + @Consumes(MediaType.APPLICATION_JSON) + @Path("/publisher/{name}") + @ApiOperation( + httpMethod = "POST", + value = "Create Event Publisher Artifact as String", + notes = "Deploy a XML Event Publisher Artifact in Analytics server.", + tags = "Analytics Artifacts Management", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "perm:analytics:artifacts:publisher") + }) + } + ) + @ApiResponses( + value = { + @ApiResponse( + code = 200, + message = "OK. \n Successfully deployed the Publisher Artifact.", + responseHeaders = { + @ResponseHeader( + name = "Content-Type", + description = "The content type of the body."), + @ResponseHeader( + name = "ETag", + description = "Entity Tag of the response resource.\n" + + "Used by caches, or in conditional requests."), + @ResponseHeader( + name = "Last-Modified", + description = + "Date and time the resource was last modified.\n" + + "Used by caches, or in conditional requests."), + } + ), + @ApiResponse( + code = 400, + message = + "Bad Request."), + @ApiResponse( + code = 406, + message = "Not Acceptable.\n The requested media type is not supported."), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n Server error occurred while deploying the " + + "Event Publisher Artifact.", + response = ErrorResponse.class) + } + ) + Response deployEventPublisherAsString(@PathParam("name") String name, + @QueryParam("isEdited") boolean isEdited, + @Valid EventPublisher publisher); + + @POST + @Consumes(MediaType.APPLICATION_JSON) + @Path("/publisher") + @ApiOperation( + httpMethod = "POST", + value = "Create Event Publisher Artifact as DTO", + notes = "Deploy a JSON Event Publisher Artifact in Analytics server.", + tags = "Analytics Artifacts Management", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "perm:analytics:artifacts:publisher") + }) + } + ) + @ApiResponses( + value = { + @ApiResponse( + code = 200, + message = "OK. \n Successfully deployed the Publisher Artifact.", + responseHeaders = { + @ResponseHeader( + name = "Content-Type", + description = "The content type of the body."), + @ResponseHeader( + name = "ETag", + description = "Entity Tag of the response resource.\n" + + "Used by caches, or in conditional requests."), + @ResponseHeader( + name = "Last-Modified", + description = + "Date and time the resource was last modified.\n" + + "Used by caches, or in conditional requests."), + } + ), + @ApiResponse( + code = 400, + message = + "Bad Request."), + @ApiResponse( + code = 406, + message = "Not Acceptable.\n The requested media type is not supported."), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n Server error occurred while deploying the " + + "Event Publisher Artifact.", + response = ErrorResponse.class) + } + ) + Response deployEventPublisherAsDto(@Valid Adapter publisher); + + @POST + @Consumes(MediaType.APPLICATION_JSON) + @Path("/siddhi-script/{name}") + @ApiOperation( + httpMethod = "POST", + value = "Create Siddhi Script Artifact as String", + notes = "Deploy a SiddhiQL Siddhi script Artifact in Analytics server.", + tags = "Analytics Artifacts Management", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "perm:analytics:artifacts:siddhi") + }) + } + ) + @ApiResponses( + value = { + @ApiResponse( + code = 200, + message = "OK. \n Successfully deployed the Siddhi script Artifact.", + responseHeaders = { + @ResponseHeader( + name = "Content-Type", + description = "The content type of the body."), + @ResponseHeader( + name = "ETag", + description = "Entity Tag of the response resource.\n" + + "Used by caches, or in conditional requests."), + @ResponseHeader( + name = "Last-Modified", + description = + "Date and time the resource was last modified.\n" + + "Used by caches, or in conditional requests."), + } + ), + @ApiResponse( + code = 400, + message = + "Bad Request."), + @ApiResponse( + code = 406, + message = "Not Acceptable.\n The requested media type is not supported."), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n Server error occurred while " + + "deploying the Siddhi script Artifact.", + response = ErrorResponse.class) + } + ) + Response deploySiddhiExecutableScript( + @PathParam("name") String name, @QueryParam("isEdited") boolean isEdited, + @Valid SiddhiExecutionPlan plan); +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/AnalyticsManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/AnalyticsManagementService.java deleted file mode 100644 index b81100c0fe..0000000000 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/AnalyticsManagementService.java +++ /dev/null @@ -1,290 +0,0 @@ -/* - * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.wso2.carbon.device.mgt.jaxrs.service.api; - -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import io.swagger.annotations.ApiResponse; -import io.swagger.annotations.ApiResponses; -import io.swagger.annotations.Extension; -import io.swagger.annotations.ExtensionProperty; -import io.swagger.annotations.Info; -import io.swagger.annotations.ResponseHeader; -import io.swagger.annotations.SwaggerDefinition; -import io.swagger.annotations.Tag; -import org.wso2.carbon.apimgt.annotations.api.Scope; -import org.wso2.carbon.apimgt.annotations.api.Scopes; -import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse; -import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.Adapter; -import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.EventStream; -import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.SiddhiExecutionPlan; -import org.wso2.carbon.device.mgt.jaxrs.util.Constants; - -import javax.validation.Valid; -import javax.ws.rs.Consumes; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; - -@SwaggerDefinition( - info = @Info( - version = "1.0.0", - title = "", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = "name", value = "AnalyticsManagement"), - @ExtensionProperty(name = "context", value = "/api/device-mgt/v1.0/analytics"), - }) - } - ), - tags = { - @Tag(name = "analytics_management", description = "") - } -) -@Scopes( - scopes = { - @Scope( - name = "Add Event stream", - description = "Add definition of a Event stream", - key = "perm:analytics:events", - permissions = {"/device-mgt/analytics/event/add"} - ), - @Scope( - name = "Add Publisher", - description = "Add definition of a Publisher", - key = "perm:analytics:publisher", - permissions = {"/device-mgt/analytics/publisher/add"} - ), - @Scope( - name = "Add Receiver", - description = "Add definition of a Receiver", - key = "perm:analytics:receiver", - permissions = {"/device-mgt/analytics/receiver/add"} - ), - @Scope( - name = "Add Siddhi script", - description = "Add definition of a Siddhi script", - key = "perm:analytics:script", - permissions = {"/device-mgt/analytics/script/add"} - ) - } -) - -@Path("/analytics") -@Api(value = "Analytics Management", description = "This API corresponds to all tasks related analytics server") -@Consumes(MediaType.APPLICATION_JSON) -public interface AnalyticsManagementService { - - @POST - @Path("/event") - @ApiOperation( - httpMethod = "POST", - value = "Adding the Event Type Definition", - notes = "Add the event definition to analytics.", - tags = "Analytics Management", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "perm:analytics:events") - }) - } - ) - @ApiResponses( - value = { - @ApiResponse( - code = 200, - message = "OK. \n Successfully added the event defintion.", - responseHeaders = { - @ResponseHeader( - name = "Content-Type", - description = "The content type of the body"), - @ResponseHeader( - name = "ETag", - description = "Entity Tag of the response resource.\n" + - "Used by caches, or in conditional requests."), - @ResponseHeader( - name = "Last-Modified", - description = - "Date and time the resource was last modified.\n" + - "Used by caches, or in conditional requests."), - } - ), - @ApiResponse( - code = 400, - message = - "Bad Request."), - @ApiResponse( - code = 406, - message = "Not Acceptable.\n The requested media type is not supported."), - @ApiResponse( - code = 500, - message = "Internal Server Error. \n Server error occurred while publishing the " + - "Event stream.", - response = ErrorResponse.class) - } - ) - Response deployEventDefinition(@Valid EventStream stream); - - @POST - @Path("/receiver") - @ApiOperation( - httpMethod = "POST", - value = "Adding an Event Receiver", - notes = "Add the receiver for an event", - tags = "Analytics Management", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "perm:analytics:receiver") - }) - } - ) - @ApiResponses( - value = { - @ApiResponse( - code = 200, - message = "OK. \n Successfully added the receiver.", - responseHeaders = { - @ResponseHeader( - name = "Content-Type", - description = "The content type of the body."), - @ResponseHeader( - name = "ETag", - description = "Entity Tag of the response resource.\n" + - "Used by caches, or in conditional requests."), - @ResponseHeader( - name = "Last-Modified", - description = - "Date and time the resource was last modified.\n" + - "Used by caches, or in conditional requests."), - } - ), - @ApiResponse( - code = 400, - message = - "Bad Request."), - @ApiResponse( - code = 406, - message = "Not Acceptable.\n The requested media type is not supported"), - @ApiResponse( - code = 500, - message = "Internal Server Error. \n Server error occurred while publishing the " + - "Event receiver.", - response = ErrorResponse.class) - } - ) - Response deployEventReceiver(Adapter receiver); - - @POST - @Path("/publisher") - @ApiOperation( - httpMethod = "POST", - value = "Adding an Event Publisher", - notes = "Add the publisher for an event", - tags = "Analytics Management", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "perm:analytics:publisher") - }) - } - ) - @ApiResponses( - value = { - @ApiResponse( - code = 200, - message = "OK. \n Successfully added the publisher.", - responseHeaders = { - @ResponseHeader( - name = "Content-Type", - description = "The content type of the body."), - @ResponseHeader( - name = "ETag", - description = "Entity Tag of the response resource.\n" + - "Used by caches, or in conditional requests."), - @ResponseHeader( - name = "Last-Modified", - description = - "Date and time the resource was last modified.\n" + - "Used by caches, or in conditional requests."), - } - ), - @ApiResponse( - code = 400, - message = - "Bad Request."), - @ApiResponse( - code = 406, - message = "Not Acceptable.\n The requested media type is not supported."), - @ApiResponse( - code = 500, - message = "Internal Server Error. \n Server error occurred while publishing the " + - "Event publisher.", - response = ErrorResponse.class) - } - ) - Response deployEventPublisher(@Valid Adapter publisher); - - @POST - @Path("/executable") - @ApiOperation( - httpMethod = "POST", - value = "Adding a Siddhi executable", - notes = "Add a Siddhi executable for a event", - tags = "Analytics Management", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "perm:analytics:script") - }) - } - ) - @ApiResponses( - value = { - @ApiResponse( - code = 200, - message = "OK. \n Successfully added the execution plan.", - responseHeaders = { - @ResponseHeader( - name = "Content-Type", - description = "The content type of the body."), - @ResponseHeader( - name = "ETag", - description = "Entity Tag of the response resource.\n" + - "Used by caches, or in conditional requests."), - @ResponseHeader( - name = "Last-Modified", - description = - "Date and time the resource was last modified.\n" + - "Used by caches, or in conditional requests."), - } - ), - @ApiResponse( - code = 400, - message = - "Bad Request."), - @ApiResponse( - code = 406, - message = "Not Acceptable.\n The requested media type is not supported."), - @ApiResponse( - code = 500, - message = "Internal Server Error. \n Server error occurred while " + - "publishing the Execution plan.", - response = ErrorResponse.class) - } - ) - Response deploySiddhiExecutableScript(@Valid SiddhiExecutionPlan plan); -} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/AnalyticsManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/AnalyticsArtifactsManagementServiceImpl.java similarity index 72% rename from components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/AnalyticsManagementServiceImpl.java rename to components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/AnalyticsArtifactsManagementServiceImpl.java index c6a5eb9b58..21583f0f28 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/AnalyticsManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/AnalyticsArtifactsManagementServiceImpl.java @@ -1,28 +1,22 @@ /* - * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) 2019, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved. * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at + * Entgra (pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. + * http://www.apache.org/licenses/LICENSE-2.0 * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ package org.wso2.carbon.device.mgt.jaxrs.service.impl; -import org.apache.axis2.AxisFault; -import org.apache.axis2.client.Stub; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.base.MultitenantConstants; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.Attribute; import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.AdapterMappingConfiguration; @@ -31,14 +25,15 @@ import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.AdapterConfiguration; import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.AdapterProperty; import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.MessageFormat; import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.SiddhiExecutionPlan; +import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.EventPublisher; +import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.EventReceiver; +import org.wso2.carbon.device.mgt.jaxrs.exception.ErrorDTO; import org.wso2.carbon.device.mgt.jaxrs.exception.InvalidExecutionPlanException; -import org.wso2.carbon.device.mgt.jaxrs.service.api.AnalyticsManagementService; +import org.wso2.carbon.device.mgt.jaxrs.service.api.AnalyticsArtifactsManagementService; import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.Adapter; -import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.EventAttributeLists; import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.EventStream; import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils; import org.wso2.carbon.event.processor.stub.EventProcessorAdminServiceStub; -import org.wso2.carbon.event.processor.stub.types.ExecutionPlanConfigurationDto; import org.wso2.carbon.event.publisher.stub.EventPublisherAdminServiceStub; import org.wso2.carbon.event.publisher.stub.types.BasicOutputAdapterPropertyDto; import org.wso2.carbon.event.publisher.stub.types.EventPublisherConfigurationDto; @@ -52,70 +47,97 @@ import org.wso2.carbon.event.stream.stub.types.EventStreamDefinitionDto; import org.wso2.carbon.identity.jwt.client.extension.exception.JWTClientException; import org.wso2.carbon.user.api.UserStoreException; +import org.apache.axis2.AxisFault; +import org.apache.axis2.client.Stub; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + import javax.validation.Valid; import javax.ws.rs.POST; import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.QueryParam; import javax.ws.rs.core.Response; +import java.nio.charset.StandardCharsets; import java.rmi.RemoteException; import java.util.List; /** - * This class is used to create endpoints to serve the deployment of streams, adapters, siddhi - * execution plans to the DAS + * This class is used to create endpoints to serve the deployment of streams, publishers, receivers, + * siddhi scripts to the Analytics server as Artifacts */ -@Path("/analytics") -public class AnalyticsManagementServiceImpl implements AnalyticsManagementService { - private static final Log log = LogFactory.getLog(AnalyticsManagementServiceImpl.class); +@Path("/analytics/artifacts") +public class AnalyticsArtifactsManagementServiceImpl implements AnalyticsArtifactsManagementService { + private static final Log log = LogFactory.getLog(AnalyticsArtifactsManagementServiceImpl.class); + + /** + * @param stream EventStream object with the properties of the stream + * @return A status code depending on the code result + * Function - Used to deploy stream as an artifact using a String + */ + @Override + @POST + @Path("/stream/{id}") + public Response deployEventDefinitionAsString(@PathParam("id") String id, + @QueryParam("isEdited") boolean isEdited, + @Valid EventStream stream) { + String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(); + EventStreamAdminServiceStub eventStreamAdminServiceStub = null; + try { + String streamDefinition = new String(stream.getDefinition().getBytes(), StandardCharsets.UTF_8); + eventStreamAdminServiceStub = DeviceMgtAPIUtils.getEventStreamAdminServiceStub(); + if (!isEdited) { + eventStreamAdminServiceStub.addEventStreamDefinitionAsString(streamDefinition); + } else { + // Find and edit stream + if (eventStreamAdminServiceStub.getStreamDetailsForStreamId(id) != null) { + eventStreamAdminServiceStub.editEventStreamDefinitionAsString(streamDefinition, id); + } + } + return Response.ok().build(); + } catch (AxisFault e) { + log.error("Failed to create event definitions for tenantDomain: " + tenantDomain, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); + } catch (RemoteException e) { + log.error("Failed to connect with the remote services for tenantDomain: " + tenantDomain, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); + } catch (JWTClientException e) { + log.error("Failed to generate jwt token for tenantDomain: " + tenantDomain, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); + } catch (UserStoreException e) { + log.error("Failed to connect with the user store for tenantDomain: " + tenantDomain, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); + } finally { + cleanup(eventStreamAdminServiceStub); + } + } /** - * @param eventStream EventStream object with the properties of the stream + * @param stream EventStream object with the properties of the stream * @return A status code depending on the code result - * Function - Deploy a event stream + * Function - Used to deploy stream as an artifact using a DTO */ @Override @POST - @Path("/event") - public Response deployEventDefinition(@Valid EventStream eventStream) { + @Path("/stream") + public Response deployEventDefinitionAsDto(@Valid EventStream stream) { String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(); - EventAttributeLists eventAttributes = eventStream.getEventAttributeLists(); // Categorize attributes to three lists depending on their type - List eventMetaAttributes = eventAttributes.getMetaAttributes(); - List eventPayloadAttributes = eventAttributes.getPayloadAttributes(); - List eventCorrelationAttributes = eventAttributes.getCorrelationAttributes(); + List metaData = stream.getMetaData(); + List payloadData = stream.getPayloadData(); + List correlationData = stream.getCorrelationData(); try { /* Conditions * - At least one list should always be not null */ - if (eventStream.getEventAttributeLists() == null || - (eventMetaAttributes == null && eventCorrelationAttributes == null && - eventPayloadAttributes == null)) { - log.error("Invalid payload: eventAttributeLists"); + if (metaData == null && correlationData == null && payloadData == null) { + log.error("Invalid payload: event attributes"); return Response.status(Response.Status.BAD_REQUEST).build(); } else { - String streamName = eventStream.getStreamName(); - String streamVersion = eventStream.getStreamVersion(); - String streamDefinition = eventStream.getStreamDefinition(); // Publish the event stream - publishStream(streamName, streamVersion, streamDefinition, eventMetaAttributes, - eventPayloadAttributes, eventCorrelationAttributes); - try { - /* - * Create a new tenant and if that tenant is not the super tenant execute the publish - * function for the new tenant - */ - PrivilegedCarbonContext.startTenantFlow(); - PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain( - MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, true); - if (!MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(tenantDomain)) { - publishStream(streamName, streamVersion, streamDefinition, eventMetaAttributes, - eventPayloadAttributes, eventCorrelationAttributes); - } - } finally { - // End the new tenant flow - PrivilegedCarbonContext.endTenantFlow(); - } + publishStream(stream, metaData, correlationData, payloadData); return Response.ok().build(); } } catch (AxisFault e) { @@ -134,14 +156,53 @@ public class AnalyticsManagementServiceImpl implements AnalyticsManagementServic } /** - * @param receiver Receiver definition data - * @return a status code depending on the code execution - * * Function - Deploy a event receiver + * @param name Receiver name + * @param isEdited If receiver is created or edited + * @param receiver Receiver object with the properties of the receiver + * @return A status code depending on the code result + * Function - Used to deploy receiver as an artifact using a String + */ + @Override + @POST + @Path("/receiver/{name}") + public Response deployEventReceiverAsString(@PathParam("name") String name, + @QueryParam("isEdited") boolean isEdited, + @Valid EventReceiver receiver) { + String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(); + EventReceiverAdminServiceStub eventReceiverAdminServiceStub; + try { + String receiverDefinition = receiver.getDefinition(); + eventReceiverAdminServiceStub = DeviceMgtAPIUtils.getEventReceiverAdminServiceStub(); + if (!isEdited) { + eventReceiverAdminServiceStub.deployEventReceiverConfiguration(receiverDefinition); + } else { + eventReceiverAdminServiceStub.editActiveEventReceiverConfiguration(receiverDefinition, name); + } + } catch (AxisFault e) { + log.error("Failed to create event definitions for tenantDomain: " + tenantDomain, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); + } catch (RemoteException e) { + log.error("Failed to connect with the remote services for tenantDomain: " + tenantDomain, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); + } catch (JWTClientException e) { + log.error("Failed to generate jwt token for tenantDomain: " + tenantDomain, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); + } catch (UserStoreException e) { + log.error("Failed to connect with the user store for tenantDomain: " + tenantDomain, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); + } + return Response.ok().entity(name).build(); + } + + /** + * @param receiver Receiver object with the properties of the receiver + * @return A status code depending on the code result + * Function - Used to deploy receiver as an artifact using a DTO */ @Override @POST @Path("/receiver") - public Response deployEventReceiver(Adapter receiver) { + public Response deployEventReceiverAsDto(@Valid Adapter receiver) { String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(); String receiverName = receiver.getAdapterName(); String adapterType = receiver.getAdapterType().toStringFormatted(); @@ -173,33 +234,16 @@ public class AnalyticsManagementServiceImpl implements AnalyticsManagementServic if ((customMapping && (inputMappingProperties == null && namespaceMappingProperties == null) && (correlationMappingProperties == null && payloadMappingProperties == null && - metaMappingProperties == null)) || - messageFormat == null) { - log.error("Invalid mapping payload"); - return Response.status(Response.Status.BAD_REQUEST).build(); + metaMappingProperties == null)) || messageFormat == null) { + String errMsg = "Invalid mapping payload"; + log.error(errMsg); + return Response.status(Response.Status.BAD_REQUEST).entity(errMsg).build(); } String eventStreamWithVersion = receiver.getEventStreamWithVersion(); publishReceiver(receiverName, adapterType, adapterProperties, customMapping, inputMappingProperties, namespaceMappingProperties, correlationMappingProperties, payloadMappingProperties, metaMappingProperties, messageFormat, eventStreamWithVersion); - try { - /* - * Create a new tenant and if that tenant is not the super tenant execute the publish - * function for the new tenant - */ - PrivilegedCarbonContext.startTenantFlow(); - PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain( - MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, true); - if (!MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(tenantDomain)) { - publishReceiver(receiverName, adapterType, adapterProperties, customMapping, inputMappingProperties, - namespaceMappingProperties, correlationMappingProperties, payloadMappingProperties, - metaMappingProperties, messageFormat, eventStreamWithVersion); - } - } finally { - // End the new tenant flow - PrivilegedCarbonContext.endTenantFlow(); - } return Response.ok().build(); } catch (AxisFault e) { log.error("Failed to create event definitions for tenantDomain: " + tenantDomain, e); @@ -217,13 +261,55 @@ public class AnalyticsManagementServiceImpl implements AnalyticsManagementServic } /** - * @param publisher Publisher definition - * @return a status code depending on the code execution + * @param name Publisher name + * @param isEdited If receiver is created or edited + * @param publisher Publisher object with the properties of the publisher + * @return A status code depending on the code result + * Function - Used to deploy publisher as an artifact using a String + */ + @Override + @POST + @Path("/publisher/{name}") + public Response deployEventPublisherAsString(@PathParam("name") String name, + @QueryParam("isEdited") boolean isEdited, + @Valid EventPublisher publisher) { + String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(); + EventPublisherAdminServiceStub eventPublisherAdminServiceStub; + + try { + String publisherDefinition = publisher.getDefinition(); + + eventPublisherAdminServiceStub = DeviceMgtAPIUtils.getEventPublisherAdminServiceStub(); + if (!isEdited) { + eventPublisherAdminServiceStub.deployEventPublisherConfiguration(publisherDefinition); + } else { + eventPublisherAdminServiceStub.editActiveEventPublisherConfiguration(publisherDefinition, name); + } + } catch (AxisFault e) { + log.error("Failed to create event definitions for tenantDomain: " + tenantDomain, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); + } catch (RemoteException e) { + log.error("Failed to connect with the remote services for tenantDomain: " + tenantDomain, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); + } catch (JWTClientException e) { + log.error("Failed to generate jwt token for tenantDomain: " + tenantDomain, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); + } catch (UserStoreException e) { + log.error("Failed to connect with the user store for tenantDomain: " + tenantDomain, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); + } + return Response.ok().entity(publisher).build(); + } + + /** + * @param publisher Publisher object with the properties of the publisher + * @return A status code depending on the code result + * Function - Used to deploy publisher as an artifact using a DTO */ @Override @POST @Path("/publisher") - public Response deployEventPublisher(@Valid Adapter publisher) { + public Response deployEventPublisherAsDto(@Valid Adapter publisher) { String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(); String publisherName = publisher.getAdapterName(); String adapterType = publisher.getAdapterType().toStringFormatted(); @@ -254,10 +340,10 @@ public class AnalyticsManagementServiceImpl implements AnalyticsManagementServic if ((customMapping && (inputMappingProperties == null && inputMappingString == null) && (correlationMappingProperties == null && payloadMappingProperties == null && - metaMappingProperties == null)) || - messageFormat == null) { - log.error("Invalid mapping payload"); - return Response.status(Response.Status.BAD_REQUEST).build(); + metaMappingProperties == null)) || messageFormat == null) { + String errMsg = "Invalid mapping payload"; + log.error(errMsg); + return Response.status(Response.Status.BAD_REQUEST).entity(errMsg).build(); } String eventStreamWithVersion = publisher.getEventStreamWithVersion(); @@ -265,24 +351,6 @@ public class AnalyticsManagementServiceImpl implements AnalyticsManagementServic , inputMappingString, inputMappingProperties, correlationMappingProperties , payloadMappingProperties, metaMappingProperties, messageFormat , eventStreamWithVersion); - try { - /* - * Create a new tenant and if that tenant is not the super tenant execute the publish - * function for the new tenant - */ - PrivilegedCarbonContext.startTenantFlow(); - PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain( - MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, true); - if (!MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(tenantDomain)) { - publishPublisher(publisherName, adapterType, adapterProperties, customMapping - , inputMappingString, inputMappingProperties, correlationMappingProperties - , payloadMappingProperties, metaMappingProperties, messageFormat - , eventStreamWithVersion); - } - } finally { - // End the new tenant flow - PrivilegedCarbonContext.endTenantFlow(); - } return Response.ok().build(); } catch (AxisFault e) { log.error("Failed to create event definitions for tenantDomain: " + tenantDomain, e); @@ -300,33 +368,21 @@ public class AnalyticsManagementServiceImpl implements AnalyticsManagementServic } /** - * @param executionPlan Siddhi execution plan definition + * @param name Siddhi plan name + * @param isEdited If receiver is created or edited + * @param plan Siddhi plan definition * @return a status code depending on the code execution + * Function - Used to deploy Siddhi script as an artifact using a String */ @Override @POST - @Path("/executable") - public Response deploySiddhiExecutableScript(@Valid SiddhiExecutionPlan executionPlan) { + @Path("/siddhi-script/{name}") + public Response deploySiddhiExecutableScript(@PathParam("name") String name, + @QueryParam("isEdited") boolean isEdited, + @Valid SiddhiExecutionPlan plan) { String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(); try { - publishSiddhiExecutionPlan(executionPlan.getExecutionPlanName(), - executionPlan.getExecutionPlanData()); - try { - /* - * Create a new tenant and if that tenant is not the super tenant execute the publish - * function for the new tenant - */ - PrivilegedCarbonContext.startTenantFlow(); - PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain( - MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, true); - if (!MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(tenantDomain)) { - publishSiddhiExecutionPlan(executionPlan.getExecutionPlanName(), - executionPlan.getExecutionPlanData()); - } - } finally { - // End the new tenant flow - PrivilegedCarbonContext.endTenantFlow(); - } + publishSiddhiExecutionPlan(name, isEdited, plan.getDefinition()); return Response.ok().build(); } catch (AxisFault e) { log.error("Failed to create event definitions for tenantDomain: " + tenantDomain, e); @@ -334,45 +390,42 @@ public class AnalyticsManagementServiceImpl implements AnalyticsManagementServic } catch (RemoteException e) { log.error("Failed to connect with the remote services for tenantDomain: " + tenantDomain, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); + } catch (InvalidExecutionPlanException e) { + log.error("Invalid Execution plan: " + tenantDomain, e); + return e.getResponse(); } catch (JWTClientException e) { log.error("Failed to generate jwt token for tenantDomain: " + tenantDomain, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); } catch (UserStoreException e) { log.error("Failed to connect with the user store for tenantDomain: " + tenantDomain, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); - } catch (InvalidExecutionPlanException e) { - log.error("Invalid Execution plan: " + tenantDomain, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); } } /** - * @param streamName Name of the stream - * @param streamVersion Version of the stream - * @param streamDefinition Definition of the stream - * @param eventMetaAttributes Meta attributes of the stream - * @param eventPayloadAttributes Payload attributes of the stream - * @param eventCorrelationAttributes Correlation attributes of the stream + * @param stream Stream definition + * @param metaData Meta attributes of the stream + * @param correlationData Correlation attributes of the stream + * @param payloadData Payload attributes of the stream * @throws RemoteException exception that may occur during a remote method call * @throws UserStoreException exception that may occur during JWT token generation * @throws JWTClientException exception that may occur during connecting to client store */ - private void publishStream(String streamName, String streamVersion, String streamDefinition, - List eventMetaAttributes, - List eventPayloadAttributes, - List eventCorrelationAttributes) + private void publishStream(EventStream stream, List metaData, + List correlationData, List payloadData) throws RemoteException, UserStoreException, JWTClientException { EventStreamAdminServiceStub eventStreamAdminServiceStub = DeviceMgtAPIUtils.getEventStreamAdminServiceStub(); try { EventStreamDefinitionDto eventStreamDefinitionDto = new EventStreamDefinitionDto(); - eventStreamDefinitionDto.setName(streamName); - eventStreamDefinitionDto.setVersion(streamVersion); - eventStreamDefinitionDto.setDescription(streamDefinition); - eventStreamDefinitionDto.setMetaData(addEventAttributesToDto(eventMetaAttributes)); - eventStreamDefinitionDto.setPayloadData(addEventAttributesToDto(eventPayloadAttributes)); - eventStreamDefinitionDto.setCorrelationData(addEventAttributesToDto(eventCorrelationAttributes)); - String streamId = streamName + ":" + streamVersion; + eventStreamDefinitionDto.setName(stream.getName()); + eventStreamDefinitionDto.setVersion(stream.getVersion()); + eventStreamDefinitionDto.setNickName(stream.getNickName()); + eventStreamDefinitionDto.setDescription(stream.getDescription()); + eventStreamDefinitionDto.setMetaData(addEventAttributesToDto(metaData)); + eventStreamDefinitionDto.setPayloadData(addEventAttributesToDto(payloadData)); + eventStreamDefinitionDto.setCorrelationData(addEventAttributesToDto(correlationData)); + String streamId = stream.getName() + ":" + stream.getVersion(); if (eventStreamAdminServiceStub.getStreamDefinitionDto(streamId) != null) { eventStreamAdminServiceStub.editEventStreamDefinitionAsDto(eventStreamDefinitionDto, streamId); } else { @@ -558,48 +611,35 @@ public class AnalyticsManagementServiceImpl implements AnalyticsManagementServic } /** - * @param executionPlanName Siddhi execution plan name - * @param executionPlanData Siddhi execution plan + * @param name plan name + * @param isEdited is plan edited + * @param plan plan data * @throws RemoteException exception that may occur during a remote method call * @throws UserStoreException exception that may occur during JWT token generation * @throws JWTClientException exception that may occur during connecting to client store * @throws InvalidExecutionPlanException exception that may occur if execution plan validation fails */ - private void publishSiddhiExecutionPlan(String executionPlanName, String executionPlanData) + private void publishSiddhiExecutionPlan(String name, boolean isEdited, + String plan) throws RemoteException, UserStoreException, JWTClientException, InvalidExecutionPlanException { EventProcessorAdminServiceStub eventProcessorAdminServiceStub = null; - // Flag to check the existence of a plan - boolean isAvailable = false; try { eventProcessorAdminServiceStub = DeviceMgtAPIUtils.getEventProcessorAdminServiceStub(); // Validate the plan code - String validationResponse = eventProcessorAdminServiceStub.validateExecutionPlan(executionPlanData); + String validationResponse = eventProcessorAdminServiceStub.validateExecutionPlan(plan); if (validationResponse.equals("success")) { - String activeExecutionPlanName = null; - // Get active plans - ExecutionPlanConfigurationDto[] allActiveExecutionPlanConfigs = eventProcessorAdminServiceStub.getAllActiveExecutionPlanConfigurations(); - if (allActiveExecutionPlanConfigs != null) { - for (ExecutionPlanConfigurationDto activeExecutionPlanConfig : allActiveExecutionPlanConfigs) { - activeExecutionPlanName = activeExecutionPlanConfig.getName(); - if (activeExecutionPlanName.equals(executionPlanName)) { - isAvailable = true; - } - } - } - // Edit existing plan - if (isAvailable) { - eventProcessorAdminServiceStub.editActiveExecutionPlan(executionPlanData, - executionPlanName); - } - // Create a new plan - else { - eventProcessorAdminServiceStub.deployExecutionPlan(executionPlanData); + if (!isEdited) { + // Create a new plan + eventProcessorAdminServiceStub.deployExecutionPlan(plan); + } else { + // Edit plan + eventProcessorAdminServiceStub.editActiveExecutionPlan(plan, name); } } else { - String errMsg = "Execution plan validation failed: " + validationResponse; - log.error(errMsg); - throw new InvalidExecutionPlanException(errMsg); + ErrorDTO errorDTO = new ErrorDTO(); + errorDTO.setMessage(validationResponse); + throw new InvalidExecutionPlanException(errorDTO); } } finally { cleanup(eventProcessorAdminServiceStub); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/DeviceMgtAPIUtils.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/DeviceMgtAPIUtils.java index 60ddb95852..2b05778e68 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/DeviceMgtAPIUtils.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/DeviceMgtAPIUtils.java @@ -639,16 +639,8 @@ public class DeviceMgtAPIUtils { return eventStreamPersistenceAdminServiceStub; } - /** - * - * @return - * @throws AxisFault - * @throws UserStoreException - * @throws JWTClientException - */ public static EventProcessorAdminServiceStub getEventProcessorAdminServiceStub() throws AxisFault, UserStoreException, JWTClientException { - // Send alert to event-processing EventProcessorAdminServiceStub eventProcessorAdminServiceStub = new EventProcessorAdminServiceStub( Utils.replaceSystemProperty(DAS_ADMIN_SERVICE_EP + EVENT_PROCESSOR_CONTEXT)); Options eventProcessorOption = eventProcessorAdminServiceStub._getServiceClient().getOptions(); 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 6bdbfcb53f..f08b6ebda1 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 @@ -46,7 +46,7 @@ - + @@ -94,7 +94,7 @@ - + @@ -103,4 +103,4 @@ - \ No newline at end of file + From 234c2ee10485e59c7070f388b3f24382d19b9296 Mon Sep 17 00:00:00 2001 From: Yohan Avishke Date: Mon, 9 Sep 2019 20:08:33 +0530 Subject: [PATCH 7/8] Resolve issue with wrong license header --- .../InvalidExecutionPlanException.java | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/exception/InvalidExecutionPlanException.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/exception/InvalidExecutionPlanException.java index 1d40634f3d..c366b37ef4 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/exception/InvalidExecutionPlanException.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/exception/InvalidExecutionPlanException.java @@ -1,20 +1,19 @@ /* - * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) 2019, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved. * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at + * Entgra (pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. + * http://www.apache.org/licenses/LICENSE-2.0 * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ package org.wso2.carbon.device.mgt.jaxrs.exception; From e33f28bf8a378290edbd7186c488fbd54a771da2 Mon Sep 17 00:00:00 2001 From: Turcy Date: Mon, 9 Sep 2019 23:49:24 +0530 Subject: [PATCH 8/8] Sort device analytics data --- .../jaxrs/service/impl/DeviceEventManagementServiceImpl.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceEventManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceEventManagementServiceImpl.java index 2bbcee2d43..44ea053b34 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceEventManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceEventManagementServiceImpl.java @@ -106,7 +106,9 @@ public class DeviceEventManagementServiceImpl implements DeviceEventManagementSe List recordIds = getRecordIds(resultEntries); AnalyticsDataResponse response = analyticsDataAPI.get(tenantId, tableName, 1, null, recordIds); eventRecords.setCount(eventCount); - eventRecords.setList(AnalyticsDataAPIUtil.listRecords(analyticsDataAPI, response)); + List records = AnalyticsDataAPIUtil.listRecords(analyticsDataAPI, response); + records.sort((Record r1, Record r2) -> Long.compare(r2.getTimestamp(), r1.getTimestamp())); + eventRecords.setList(records); return eventRecords; }