forked from community/device-mgt-core
Compare commits
114 Commits
master
...
restruct-r
@ -0,0 +1,119 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Copyright (c) 2023, Entgra (Pvt) Ltd. (http://www.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.
|
||||
-->
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>apimgt-extensions</artifactId>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<version>5.0.21-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>io.entgra.device.mgt.core.apimgt.analytics.extension</artifactId>
|
||||
<packaging>bundle</packaging>
|
||||
<name>Entgra - API mgt analytics extension</name>
|
||||
<url>http://wso2.org</url>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>org.wso2.carbon.core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>org.wso2.carbon.utils</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.velocity</groupId>
|
||||
<artifactId>velocity</artifactId>
|
||||
<version>1.7</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<configuration>
|
||||
<excludes>
|
||||
<exclude>**/Abstract*</exclude>
|
||||
</excludes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.felix</groupId>
|
||||
<artifactId>maven-scr-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.felix</groupId>
|
||||
<artifactId>maven-bundle-plugin</artifactId>
|
||||
<extensions>true</extensions>
|
||||
<configuration>
|
||||
<instructions>
|
||||
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
|
||||
<Bundle-Name>${project.artifactId}</Bundle-Name>
|
||||
<Bundle-Version>${carbon.device.mgt.version}</Bundle-Version>
|
||||
<Bundle-Description>API Management Application Bundle</Bundle-Description>
|
||||
<Private-Package>org.wso2.carbon.apimgt.application.extension.internal</Private-Package>
|
||||
<Import-Packages>
|
||||
io.entgra.device.mgt.core.apimgt.analytics.extension.dto,
|
||||
org.apache.velocity,
|
||||
org.apache.velocity.app,
|
||||
org.apache.velocity.context,
|
||||
org.wso2.carbon.utils;version="[4.6,5)"
|
||||
</Import-Packages>
|
||||
<Export-Package>
|
||||
io.entgra.device.mgt.core.apimgt.analytics.extension.*
|
||||
</Export-Package>
|
||||
<Embed-Dependency>
|
||||
scribe;scope=compile|runtime;inline=false;
|
||||
</Embed-Dependency>
|
||||
</instructions>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.jacoco</groupId>
|
||||
<artifactId>jacoco-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<destFile>${basedir}/target/coverage-reports/jacoco-unit.exec</destFile>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>jacoco-initialize</id>
|
||||
<goals>
|
||||
<goal>prepare-agent</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>jacoco-site</id>
|
||||
<phase>test</phase>
|
||||
<goals>
|
||||
<goal>report</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<dataFile>${basedir}/target/coverage-reports/jacoco-unit.exec</dataFile>
|
||||
<outputDirectory>${basedir}/target/coverage-reports/site</outputDirectory>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
|
@ -0,0 +1,176 @@
|
||||
/*
|
||||
* Copyright (c) 2023, Entgra (Pvt) Ltd. (http://www.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 io.entgra.device.mgt.core.apimgt.analytics.extension;
|
||||
|
||||
import io.entgra.device.mgt.core.apimgt.analytics.extension.dto.EventPublisherData;
|
||||
import io.entgra.device.mgt.core.apimgt.analytics.extension.dto.EventReceiverData;
|
||||
import io.entgra.device.mgt.core.apimgt.analytics.extension.dto.EventStreamData;
|
||||
import io.entgra.device.mgt.core.apimgt.analytics.extension.dto.MetaData;
|
||||
import io.entgra.device.mgt.core.apimgt.analytics.extension.exception.EventPublisherDeployerException;
|
||||
import io.entgra.device.mgt.core.apimgt.analytics.extension.exception.EventReceiverDeployerException;
|
||||
import io.entgra.device.mgt.core.apimgt.analytics.extension.exception.EventStreamDeployerException;
|
||||
import org.apache.velocity.Template;
|
||||
import org.apache.velocity.VelocityContext;
|
||||
import org.apache.velocity.app.VelocityEngine;
|
||||
|
||||
import org.apache.velocity.runtime.RuntimeConstants;
|
||||
import org.wso2.carbon.utils.CarbonUtils;
|
||||
import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
public class AnalyticsArtifactsDeployer {
|
||||
|
||||
public static final String TEMPLATE_LOCATION = "repository" + File.separator + "resources" + File.separator + "iot-analytics-templates";
|
||||
public static final String EVENT_STREAM_LOCATION = "eventstreams";
|
||||
public static final String EVENT_PUBLISHER_LOCATION = "eventpublishers";
|
||||
public static final String EVENT_RECEIVER_LOCATION = "eventreceivers";
|
||||
public static final String EVENT_STREAM_TEMPLATE = TEMPLATE_LOCATION + File.separator + "event_stream.json.template";
|
||||
public static final String EVENT_PUBLISHER_TEMPLATE = TEMPLATE_LOCATION + File.separator + "event_publisher.xml.template";
|
||||
public static final String EVENT_RECEIVER_TEMPLATE = TEMPLATE_LOCATION + File.separator + "event_receiver.xml.template";
|
||||
|
||||
|
||||
public void deployEventStream(EventStreamData eventStreamData, int tenantId) throws EventStreamDeployerException {
|
||||
try {
|
||||
VelocityEngine ve = new VelocityEngine();
|
||||
ve.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, CarbonUtils.getCarbonHome());
|
||||
ve.init();
|
||||
Template template = ve.getTemplate(EVENT_STREAM_TEMPLATE);
|
||||
|
||||
VelocityContext context = populateContextForEventStreams(eventStreamData);
|
||||
StringWriter writer = new StringWriter();
|
||||
template.merge(context, writer);
|
||||
|
||||
String fileName = eventStreamData.getName() + "_" + eventStreamData.getVersion() + ".json";
|
||||
String fileLocation = null;
|
||||
if (MultitenantConstants.SUPER_TENANT_ID == tenantId) {
|
||||
fileLocation = CarbonUtils.getCarbonHome() + File.separator + "repository" + File.separator + "deployment"
|
||||
+ File.separator + "server" + File.separator + EVENT_STREAM_LOCATION + File.separator + fileName;
|
||||
} else {
|
||||
fileLocation = CarbonUtils.getCarbonTenantsDirPath() + File.separator + tenantId + File.separator
|
||||
+ EVENT_STREAM_LOCATION + File.separator + fileName;
|
||||
}
|
||||
|
||||
PrintWriter printWriter = new PrintWriter(fileLocation, "UTF-8");
|
||||
printWriter.println(writer.toString());
|
||||
printWriter.close();
|
||||
} catch (FileNotFoundException | UnsupportedEncodingException e) {
|
||||
throw new EventStreamDeployerException("Error while persisting event stream definition ", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void deployEventPublisher(EventPublisherData eventPublisherData, int tenantId) throws EventPublisherDeployerException {
|
||||
try {
|
||||
VelocityEngine ve = new VelocityEngine();
|
||||
ve.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, CarbonUtils.getCarbonHome());
|
||||
ve.init();
|
||||
Template template = ve.getTemplate(EVENT_PUBLISHER_TEMPLATE);
|
||||
|
||||
VelocityContext context = populateContextForEventPublisher(eventPublisherData);
|
||||
StringWriter writer = new StringWriter();
|
||||
template.merge(context, writer);
|
||||
|
||||
String fileName = eventPublisherData.getName() + ".xml";
|
||||
String fileLocation = null;
|
||||
if (MultitenantConstants.SUPER_TENANT_ID == tenantId) {
|
||||
fileLocation = CarbonUtils.getCarbonHome() + File.separator + "repository" + File.separator + "deployment"
|
||||
+ File.separator + "server" + File.separator + EVENT_PUBLISHER_LOCATION + File.separator + fileName;
|
||||
} else {
|
||||
fileLocation = CarbonUtils.getCarbonTenantsDirPath() + File.separator + tenantId + File.separator
|
||||
+ EVENT_PUBLISHER_LOCATION + File.separator + fileName;
|
||||
}
|
||||
|
||||
PrintWriter printWriter = new PrintWriter(fileLocation, "UTF-8");
|
||||
printWriter.println(writer.toString());
|
||||
printWriter.close();
|
||||
} catch (FileNotFoundException | UnsupportedEncodingException e) {
|
||||
throw new EventPublisherDeployerException("Error while persisting rdbms event publisher ", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void deployEventReceiver(EventReceiverData eventReceiverData, int tenantId) throws EventReceiverDeployerException {
|
||||
try {
|
||||
VelocityEngine ve = new VelocityEngine();
|
||||
ve.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, CarbonUtils.getCarbonHome());
|
||||
ve.init();
|
||||
Template template = ve.getTemplate(EVENT_RECEIVER_TEMPLATE);
|
||||
|
||||
VelocityContext context = populateContextForEventReceiver(eventReceiverData);
|
||||
StringWriter writer = new StringWriter();
|
||||
template.merge(context, writer);
|
||||
|
||||
String fileName = eventReceiverData.getName() + ".xml";
|
||||
String fileLocation = null;
|
||||
if (MultitenantConstants.SUPER_TENANT_ID == tenantId) {
|
||||
fileLocation = CarbonUtils.getCarbonHome() + File.separator + "repository" + File.separator + "deployment"
|
||||
+ File.separator + "server" + File.separator + EVENT_RECEIVER_LOCATION + File.separator + fileName;
|
||||
} else {
|
||||
fileLocation = CarbonUtils.getCarbonTenantsDirPath() + File.separator + tenantId + File.separator
|
||||
+ EVENT_RECEIVER_LOCATION + File.separator + fileName;
|
||||
}
|
||||
|
||||
PrintWriter printWriter = new PrintWriter(fileLocation, "UTF-8");
|
||||
printWriter.println(writer.toString());
|
||||
printWriter.close();
|
||||
} catch (FileNotFoundException | UnsupportedEncodingException e) {
|
||||
throw new EventReceiverDeployerException("Error while persisting oauth mqtt event receiver ", e);
|
||||
}
|
||||
}
|
||||
|
||||
private VelocityContext populateContextForEventStreams(EventStreamData eventStreamData) {
|
||||
VelocityContext context = new VelocityContext();
|
||||
context.put("name", eventStreamData.getName());
|
||||
context.put("version", eventStreamData.getVersion());
|
||||
context.put("metaData",
|
||||
eventStreamData.getMetaData() != null ? eventStreamData.getMetaData() : new MetaData("deviceId", "STRING"));
|
||||
if (eventStreamData.getPayloadData() != null) {
|
||||
context.put("properties", eventStreamData.getPayloadData());
|
||||
}
|
||||
return context;
|
||||
}
|
||||
|
||||
private VelocityContext populateContextForEventPublisher(EventPublisherData eventPublisherData) {
|
||||
VelocityContext context = new VelocityContext();
|
||||
|
||||
context.put("name", eventPublisherData.getName());
|
||||
context.put("streamName", eventPublisherData.getStreamName());
|
||||
context.put("streamVersion", eventPublisherData.getStreamVersion());
|
||||
context.put("properties", eventPublisherData.getPropertyList());
|
||||
context.put("eventAdapterType", eventPublisherData.getEventAdaptorType());
|
||||
context.put("customMappingType", eventPublisherData.getCustomMappingType());
|
||||
|
||||
return context;
|
||||
}
|
||||
|
||||
private VelocityContext populateContextForEventReceiver(EventReceiverData eventReceiverData) {
|
||||
VelocityContext context = new VelocityContext();
|
||||
|
||||
context.put("name", eventReceiverData.getName());
|
||||
context.put("streamName", eventReceiverData.getStreamName());
|
||||
context.put("streamVersion", eventReceiverData.getStreamVersion());
|
||||
context.put("properties", eventReceiverData.getPropertyList());
|
||||
context.put("eventAdapterType", eventReceiverData.getEventAdapterType());
|
||||
context.put("customMappingType", eventReceiverData.getCustomMappingType());
|
||||
|
||||
return context;
|
||||
}
|
||||
}
|
@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Copyright (c) 2023, Entgra (Pvt) Ltd. (http://www.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 io.entgra.device.mgt.core.apimgt.analytics.extension.dto;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class EventPublisherData {
|
||||
private String name;
|
||||
private String streamVersion;
|
||||
private String streamName;
|
||||
|
||||
private List<Property> propertyList;
|
||||
|
||||
private String eventAdaptorType;
|
||||
|
||||
private String customMappingType;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getStreamVersion() {
|
||||
return streamVersion;
|
||||
}
|
||||
|
||||
public void setStreamVersion(String streamVersion) {
|
||||
this.streamVersion = streamVersion;
|
||||
}
|
||||
|
||||
public String getStreamName() {
|
||||
return streamName;
|
||||
}
|
||||
|
||||
public void setStreamName(String streamName) {
|
||||
this.streamName = streamName;
|
||||
}
|
||||
|
||||
public List<Property> getPropertyList() {
|
||||
return propertyList;
|
||||
}
|
||||
|
||||
public void setPropertyList(List<Property> propertyList) {
|
||||
this.propertyList = propertyList;
|
||||
}
|
||||
|
||||
public String getEventAdaptorType() {
|
||||
return eventAdaptorType;
|
||||
}
|
||||
|
||||
public void setEventAdaptorType(String eventAdaptorType) {
|
||||
this.eventAdaptorType = eventAdaptorType;
|
||||
}
|
||||
|
||||
public String getCustomMappingType() {
|
||||
return customMappingType;
|
||||
}
|
||||
|
||||
public void setCustomMappingType(String customMappingType) {
|
||||
this.customMappingType = customMappingType;
|
||||
}
|
||||
}
|
@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Copyright (c) 2023, Entgra (Pvt) Ltd. (http://www.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 io.entgra.device.mgt.core.apimgt.analytics.extension.dto;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class EventReceiverData {
|
||||
|
||||
private String name;
|
||||
private String streamVersion;
|
||||
private String streamName;
|
||||
|
||||
private String eventAdapterType;
|
||||
|
||||
List<Property> propertyList;
|
||||
|
||||
private String customMappingType;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getStreamVersion() {
|
||||
return streamVersion;
|
||||
}
|
||||
|
||||
public void setStreamVersion(String streamVersion) {
|
||||
this.streamVersion = streamVersion;
|
||||
}
|
||||
|
||||
public String getStreamName() {
|
||||
return streamName;
|
||||
}
|
||||
|
||||
public void setStreamName(String streamName) {
|
||||
this.streamName = streamName;
|
||||
}
|
||||
|
||||
public String getEventAdapterType() {
|
||||
return eventAdapterType;
|
||||
}
|
||||
|
||||
public void setEventAdapterType(String eventAdapterType) {
|
||||
this.eventAdapterType = eventAdapterType;
|
||||
}
|
||||
|
||||
public List<Property> getPropertyList() {
|
||||
return propertyList;
|
||||
}
|
||||
|
||||
public void setPropertyList(List<Property> propertyList) {
|
||||
this.propertyList = propertyList;
|
||||
}
|
||||
|
||||
public String getCustomMappingType() {
|
||||
return customMappingType;
|
||||
}
|
||||
|
||||
public void setCustomMappingType(String customMappingType) {
|
||||
this.customMappingType = customMappingType;
|
||||
}
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright (c) 2023, Entgra (Pvt) Ltd. (http://www.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 io.entgra.device.mgt.core.apimgt.analytics.extension.dto;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class EventStreamData {
|
||||
private String name;
|
||||
private String version;
|
||||
private MetaData metaData;
|
||||
private List<Property> payloadData;
|
||||
|
||||
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 MetaData getMetaData() {
|
||||
return metaData;
|
||||
}
|
||||
|
||||
public void setMetaData(MetaData metaData) {
|
||||
this.metaData = metaData;
|
||||
}
|
||||
|
||||
public List<Property> getPayloadData() {
|
||||
return payloadData;
|
||||
}
|
||||
|
||||
public void setPayloadData(List<Property> payloadData) {
|
||||
this.payloadData = payloadData;
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (c) 2023, Entgra (Pvt) Ltd. (http://www.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 io.entgra.device.mgt.core.apimgt.analytics.extension.dto;
|
||||
|
||||
public class MetaData {
|
||||
String name;
|
||||
String type;
|
||||
|
||||
public MetaData(String name, String type){
|
||||
this.setName(name);
|
||||
this.setType(type);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (c) 2023, Entgra (Pvt) Ltd. (http://www.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 io.entgra.device.mgt.core.apimgt.analytics.extension.dto;
|
||||
|
||||
public class Property {
|
||||
String name;
|
||||
String value;
|
||||
|
||||
public Property(String name, String value){
|
||||
this.setName(name);
|
||||
this.setValue(value);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (c) 2023, Entgra (Pvt) Ltd. (http://www.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 io.entgra.device.mgt.core.apimgt.analytics.extension.exception;
|
||||
|
||||
public class EventPublisherDeployerException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = -3151279311929070299L;
|
||||
|
||||
public EventPublisherDeployerException(String msg, Exception nestedEx) {
|
||||
super(msg, nestedEx);
|
||||
}
|
||||
|
||||
public EventPublisherDeployerException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public EventPublisherDeployerException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
public EventPublisherDeployerException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public EventPublisherDeployerException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (c) 2023, Entgra (Pvt) Ltd. (http://www.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 io.entgra.device.mgt.core.apimgt.analytics.extension.exception;
|
||||
|
||||
public class EventReceiverDeployerException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = -3151279311929070299L;
|
||||
|
||||
public EventReceiverDeployerException(String msg, Exception nestedEx) {
|
||||
super(msg, nestedEx);
|
||||
}
|
||||
|
||||
public EventReceiverDeployerException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public EventReceiverDeployerException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
public EventReceiverDeployerException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public EventReceiverDeployerException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (c) 2023, Entgra (Pvt) Ltd. (http://www.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 io.entgra.device.mgt.core.apimgt.analytics.extension.exception;
|
||||
|
||||
public class EventStreamDeployerException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = -3151279311929070298L;
|
||||
|
||||
public EventStreamDeployerException(String msg, Exception nestedEx) {
|
||||
super(msg, nestedEx);
|
||||
}
|
||||
|
||||
public EventStreamDeployerException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public EventStreamDeployerException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
public EventStreamDeployerException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public EventStreamDeployerException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
package org.wso2.carbon.device.mgt.jaxrs.beans;
|
||||
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class BatchResponse implements Serializable {
|
||||
private List<Response> responses = new ArrayList<>();
|
||||
private boolean success;
|
||||
private List<Response> failedResponses = new ArrayList<>();
|
||||
private List<Response> succeededResponses = new ArrayList<>();
|
||||
|
||||
private List<Request> failedRequests = new ArrayList<>();
|
||||
|
||||
public void setResponses(List<Response> responses) { this.responses = responses; }
|
||||
|
||||
public List<Response> getResponses() { return this.responses; }
|
||||
|
||||
public void setFailedResponses(List<Response> failedResponses) { this.failedResponses = failedResponses; }
|
||||
|
||||
public List<Response> getFailedResponses() { return this.failedResponses; }
|
||||
|
||||
public void setSucceededResponses(List<Response> succeededResponses) { this.succeededResponses = succeededResponses; }
|
||||
|
||||
public List<Response> getSucceededResponses() { return this.succeededResponses; }
|
||||
|
||||
public void setFailedRequests(List<Request> failedRequests) { this.failedRequests = failedRequests; }
|
||||
|
||||
public List<Request> getFailedRequests() { return this.failedRequests; }
|
||||
|
||||
public void setSuccess(boolean success) { this.success = success; }
|
||||
|
||||
public boolean getSuccess() { return this.success; }
|
||||
|
||||
public void addResponse(Response response) {
|
||||
this.responses.add(response);
|
||||
if(response.isSuccessful()) {
|
||||
this.succeededResponses.add(response);
|
||||
} else {
|
||||
this.failedResponses.add(response);
|
||||
}
|
||||
}
|
||||
|
||||
public void addRequest(Request request) {
|
||||
this.failedRequests.add(request);
|
||||
}
|
||||
|
||||
public BatchResponse() {}
|
||||
}
|
@ -0,0 +1,116 @@
|
||||
/*
|
||||
* Copyright (c) 2023, Entgra (Pvt) Ltd. (http://www.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;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ApiModel(value = "DeviceConfig", description = "Device config")
|
||||
public class DeviceConfig {
|
||||
private String clientId;
|
||||
private String clientSecret;
|
||||
private String deviceId;
|
||||
private String type;
|
||||
private String accessToken;
|
||||
private String refreshToken;
|
||||
private String mqttGateway;
|
||||
private String httpsGateway;
|
||||
private String httpGateway;
|
||||
private PlatformConfiguration platformConfiguration;
|
||||
public String getClientId() {
|
||||
return clientId;
|
||||
}
|
||||
|
||||
public void setClientId(String clientId) {
|
||||
this.clientId = clientId;
|
||||
}
|
||||
|
||||
public String getClientSecret() {
|
||||
return clientSecret;
|
||||
}
|
||||
|
||||
public void setClientSecret(String clientSecret) {
|
||||
this.clientSecret = clientSecret;
|
||||
}
|
||||
|
||||
public String getDeviceId() {
|
||||
return deviceId;
|
||||
}
|
||||
|
||||
public void setDeviceId(String deviceId) {
|
||||
this.deviceId = deviceId;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getAccessToken() {
|
||||
return accessToken;
|
||||
}
|
||||
|
||||
public void setAccessToken(String accessToken) {
|
||||
this.accessToken = accessToken;
|
||||
}
|
||||
|
||||
public String getRefreshToken() {
|
||||
return refreshToken;
|
||||
}
|
||||
|
||||
public void setRefreshToken(String refreshToken) {
|
||||
this.refreshToken = refreshToken;
|
||||
}
|
||||
|
||||
public String getMqttGateway() {
|
||||
return mqttGateway;
|
||||
}
|
||||
|
||||
public void setMqttGateway(String mqttGateway) {
|
||||
this.mqttGateway = mqttGateway;
|
||||
}
|
||||
|
||||
public String getHttpsGateway() {
|
||||
return httpsGateway;
|
||||
}
|
||||
|
||||
public void setHttpsGateway(String httpsGateway) {
|
||||
this.httpsGateway = httpsGateway;
|
||||
}
|
||||
|
||||
public String getHttpGateway() {
|
||||
return httpGateway;
|
||||
}
|
||||
|
||||
public void setHttpGateway(String httpGateway) {
|
||||
this.httpGateway = httpGateway;
|
||||
}
|
||||
|
||||
public PlatformConfiguration getPlatformConfiguration() {
|
||||
return platformConfiguration;
|
||||
}
|
||||
|
||||
public void setPlatformConfiguration(PlatformConfiguration platformConfiguration) {
|
||||
this.platformConfiguration = platformConfiguration;
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
package org.wso2.carbon.device.mgt.jaxrs.util;
|
||||
|
||||
import okhttp3.*;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.beans.BatchResponse;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
public class RESTEndpointHandler {
|
||||
private static final Log logger = LogFactory.getLog(RESTEndpointHandler.class);
|
||||
|
||||
// executes batch of requests to hosts indicate by requests
|
||||
public BatchResponse batchExecute(List<Request> batch, int maxRequestsPerHost) {
|
||||
BatchResponse batchResponse = new BatchResponse();
|
||||
OkHttpClient client = new OkHttpClient();
|
||||
client.dispatcher().setMaxRequestsPerHost(maxRequestsPerHost);
|
||||
batch.forEach(request -> {
|
||||
client.newCall(request).enqueue(new Callback() {
|
||||
@Override
|
||||
public void onFailure(Call call, IOException e) {
|
||||
batchResponse.addRequest(call.request());
|
||||
String msg = "Failed to execute request to "+call.request().url();
|
||||
logger.error(msg, e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResponse(Call call, Response response) {
|
||||
batchResponse.addResponse(response);
|
||||
}
|
||||
});
|
||||
});
|
||||
if(logger.isDebugEnabled()) {
|
||||
logger.info(
|
||||
"Batch execution is completed."+
|
||||
"Executed : "+batch.size()+"\n"+
|
||||
"Failed : "+batchResponse.getFailedRequests().size()+"\n"+
|
||||
"Succeeded :"+batchResponse.getResponses().size()
|
||||
);
|
||||
}
|
||||
return batchResponse;
|
||||
}
|
||||
}
|
@ -0,0 +1,123 @@
|
||||
/*
|
||||
* Copyright (c) 2022, 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.common;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
@ApiModel(value = "BillingResponse", description = "This class carries all information related to a billing response.")
|
||||
public class BillingResponse implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1998101711L;
|
||||
|
||||
@ApiModelProperty(name = "year", value = "Year of the billed period",
|
||||
required = false)
|
||||
private String year;
|
||||
|
||||
@ApiModelProperty(name = "totalCostPerYear", value = "Bill for a period of year", required = false)
|
||||
private double totalCostPerYear;
|
||||
|
||||
@ApiModelProperty(name = "devices", value = "Billed list of devices per year", required = false)
|
||||
private List<Device> device;
|
||||
|
||||
@ApiModelProperty(name = "billPeriod", value = "Billed period", required = false)
|
||||
private String billPeriod;
|
||||
|
||||
@ApiModelProperty(name = "startDate", value = "Start Date of period", required = false)
|
||||
private String startDate;
|
||||
|
||||
@ApiModelProperty(name = "endDate", value = "End Date of period", required = false)
|
||||
private String endDate;
|
||||
|
||||
@ApiModelProperty(name = "deviceCount", value = "Device count for a billing period",
|
||||
required = false)
|
||||
private int deviceCount;
|
||||
|
||||
public BillingResponse() {
|
||||
}
|
||||
|
||||
public BillingResponse(String year, double totalCostPerYear, List<Device> device, String billPeriod, String startDate, String endDate, int deviceCount) {
|
||||
this.year = year;
|
||||
this.totalCostPerYear = totalCostPerYear;
|
||||
this.device = device;
|
||||
this.billPeriod = billPeriod;
|
||||
this.startDate = startDate;
|
||||
this.endDate = endDate;
|
||||
this.deviceCount = deviceCount;
|
||||
}
|
||||
|
||||
public String getStartDate() {
|
||||
return startDate;
|
||||
}
|
||||
|
||||
public void setStartDate(String startDate) {
|
||||
this.startDate = startDate;
|
||||
}
|
||||
|
||||
public String getEndDate() {
|
||||
return endDate;
|
||||
}
|
||||
|
||||
public void setEndDate(String endDate) {
|
||||
this.endDate = endDate;
|
||||
}
|
||||
|
||||
public double getTotalCostPerYear() {
|
||||
return totalCostPerYear;
|
||||
}
|
||||
|
||||
public void setTotalCostPerYear(double totalCostPerYear) {
|
||||
this.totalCostPerYear = totalCostPerYear;
|
||||
}
|
||||
|
||||
public String getYear() {
|
||||
return year;
|
||||
}
|
||||
|
||||
public void setYear(String year) {
|
||||
this.year = year;
|
||||
}
|
||||
|
||||
public List<Device> getDevice() {
|
||||
return device;
|
||||
}
|
||||
|
||||
public void setDevice(List<Device> device) {
|
||||
this.device = device;
|
||||
}
|
||||
|
||||
public String getBillPeriod() {
|
||||
return billPeriod;
|
||||
}
|
||||
|
||||
public void setBillPeriod(String billPeriod) {
|
||||
this.billPeriod = billPeriod;
|
||||
}
|
||||
|
||||
public int getDeviceCount() {
|
||||
return deviceCount;
|
||||
}
|
||||
|
||||
public void setDeviceCount(int deviceCount) {
|
||||
this.deviceCount = deviceCount;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (c) 2023, Entgra (pvt) Ltd. (https://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.common;
|
||||
|
||||
/**
|
||||
* This class holds required parameters for a querying a sort by column in pagination.
|
||||
*
|
||||
*/
|
||||
public class SortColumn {
|
||||
String name;
|
||||
SortColumn.types type;
|
||||
|
||||
public enum types {
|
||||
ASC, DESC
|
||||
}
|
||||
|
||||
/**
|
||||
* ColumnName setter method
|
||||
* @param name of the column
|
||||
*/
|
||||
public void setName(String name) { this.name = name; }
|
||||
|
||||
/**
|
||||
* get the name of the column
|
||||
* @return name
|
||||
*/
|
||||
public String getName() { return name; }
|
||||
|
||||
/**
|
||||
* Column sort type
|
||||
* @param type of sort as ASC or DESC
|
||||
*/
|
||||
public void setType(SortColumn.types type) { this.type = type; }
|
||||
|
||||
/**
|
||||
* get column sort type
|
||||
* @return type of sort
|
||||
*/
|
||||
public SortColumn.types getType() { return type; }
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Column Name - " + this.name + ", Type - " + this.type ;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (c) 2022, Entgra (pvt) Ltd. (https://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.common.group.mgt;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@ApiModel(value = "DeviceTypesOfGroups", description = "This class carries whether the groups has device type or not.")
|
||||
public class DeviceTypesOfGroups implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 5562356373277828099L;
|
||||
@ApiModelProperty(name = "hasAndroid", value = "groups has Android devices.")
|
||||
private boolean hasAndroid;
|
||||
@ApiModelProperty(name = "id", value = "groups has iOS devices.")
|
||||
private boolean hasIos;
|
||||
@ApiModelProperty(name = "hasAndroid", value = "groups has Windows devices.")
|
||||
private boolean hasWindows;
|
||||
|
||||
public boolean isHasAndroid() {
|
||||
return hasAndroid;
|
||||
}
|
||||
|
||||
public void setHasAndroid(boolean hasAndroid) {
|
||||
this.hasAndroid = hasAndroid;
|
||||
}
|
||||
|
||||
public boolean isHasIos() {
|
||||
return hasIos;
|
||||
}
|
||||
|
||||
public void setHasIos(boolean hasIos) {
|
||||
this.hasIos = hasIos;
|
||||
}
|
||||
|
||||
public boolean isHasWindows() {
|
||||
return hasWindows;
|
||||
}
|
||||
|
||||
public void setHasWindows(boolean hasWindows) {
|
||||
this.hasWindows = hasWindows;
|
||||
}
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
/* Copyright (c) 2023, Entgra (Pvt) Ltd. (http://www.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.common.otp.mgt.wrapper;
|
||||
|
||||
public class DownloadURLDetails {
|
||||
|
||||
private String firstName;
|
||||
private String URL;
|
||||
private String email;
|
||||
|
||||
public String getURL() {
|
||||
return URL;
|
||||
}
|
||||
|
||||
public void setURL(String URL) {
|
||||
this.URL = URL;
|
||||
}
|
||||
|
||||
public String getFirstName() {
|
||||
return firstName;
|
||||
}
|
||||
|
||||
public void setFirstName(String firstName) {
|
||||
this.firstName = firstName;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
}
|
@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright (c) 2022, 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.core.cache;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.Objects;
|
||||
|
||||
public class BillingCacheKey {
|
||||
|
||||
private String tenantDomain;
|
||||
private Timestamp startDate;
|
||||
private Timestamp endDate;
|
||||
private volatile int hashCode;
|
||||
|
||||
public String getTenantDomain() {
|
||||
return tenantDomain;
|
||||
}
|
||||
|
||||
public void setTenantDomain(String tenantDomain) {
|
||||
this.tenantDomain = tenantDomain;
|
||||
}
|
||||
|
||||
public Timestamp getStartDate() {
|
||||
return startDate;
|
||||
}
|
||||
|
||||
public void setStartDate(Timestamp startDate) {
|
||||
this.startDate = startDate;
|
||||
}
|
||||
|
||||
public Timestamp getEndDate() {
|
||||
return endDate;
|
||||
}
|
||||
|
||||
public void setEndDate(Timestamp endDate) {
|
||||
this.endDate = endDate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (!BillingCacheKey.class.isAssignableFrom(obj.getClass())) {
|
||||
return false;
|
||||
}
|
||||
final BillingCacheKey other = (BillingCacheKey) obj;
|
||||
String thisId = this.tenantDomain + "_" + this.startDate + "_" + this.endDate;
|
||||
String otherId = other.tenantDomain + "_" + other.startDate + "_" + this.endDate;
|
||||
if (!thisId.equals(otherId)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
if (hashCode == 0) {
|
||||
hashCode = Objects.hash(tenantDomain, startDate, endDate);
|
||||
}
|
||||
return hashCode;
|
||||
}
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright (c) 2022, 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.core.cache;
|
||||
|
||||
import org.wso2.carbon.device.mgt.common.PaginationResult;
|
||||
import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.List;
|
||||
|
||||
public interface BillingCacheManager {
|
||||
/**
|
||||
* Adds a given billing object to the billing-cache.
|
||||
* @param startDate - startDate of the billing period.
|
||||
* @param endDate - endDate of the billing period.
|
||||
* @param paginationResult - PaginationResult object to be added.
|
||||
* @param tenantDomain - Owning tenant of the billing.
|
||||
*
|
||||
*/
|
||||
void addBillingToCache(PaginationResult paginationResult, String tenantDomain, Timestamp startDate, Timestamp endDate) throws DeviceManagementException;
|
||||
|
||||
/**
|
||||
* Removes a billing object from billing-cache.
|
||||
* @param startDate - startDate of the billing period.
|
||||
* @param endDate - endDate of the billing period.
|
||||
* @param tenantDomain - Owning tenant of the billing.
|
||||
*
|
||||
*/
|
||||
void removeBillingFromCache(String tenantDomain, Timestamp startDate, Timestamp endDate) throws DeviceManagementException;
|
||||
|
||||
/**
|
||||
* Removes a list of devices from billing-cache.
|
||||
* @param billingList - List of Cache-Keys of the billing objects to be removed.
|
||||
*
|
||||
*/
|
||||
void removeBillingsFromCache(List<BillingCacheKey> billingList) throws DeviceManagementException;
|
||||
|
||||
/**
|
||||
* Updates a given billing object in the billing-cache.
|
||||
* @param startDate - startDate of the billing period.
|
||||
* @param endDate - endDate of the billing period.
|
||||
* @param paginationResult - PaginationResult object to be updated.
|
||||
* @param tenantDomain - Owning tenant of the billing.
|
||||
*
|
||||
*/
|
||||
void updateBillingInCache(PaginationResult paginationResult, String tenantDomain, Timestamp startDate, Timestamp endDate) throws DeviceManagementException;
|
||||
|
||||
/**
|
||||
* Fetches a billing object from billing-cache.
|
||||
* @param startDate - startDate of the billing period.
|
||||
* @param endDate - endDate of the billing period.
|
||||
* @param tenantDomain - Owning tenant of the billing.
|
||||
* @return Device object
|
||||
*
|
||||
*/
|
||||
PaginationResult getBillingFromCache(String tenantDomain, Timestamp startDate, Timestamp endDate);
|
||||
}
|
@ -0,0 +1,135 @@
|
||||
/*
|
||||
* Copyright (c) 2022, 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.core.cache.impl;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.device.mgt.common.PaginationResult;
|
||||
import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException;
|
||||
import org.wso2.carbon.device.mgt.core.cache.BillingCacheKey;
|
||||
import org.wso2.carbon.device.mgt.core.cache.BillingCacheManager;
|
||||
import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
|
||||
|
||||
import javax.cache.Cache;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Implementation of BillingCacheManager.
|
||||
*/
|
||||
public class BillingCacheManagerImpl implements BillingCacheManager {
|
||||
|
||||
private static final Log log = LogFactory.getLog(BillingCacheManagerImpl.class);
|
||||
|
||||
private static BillingCacheManagerImpl billingCacheManager;
|
||||
|
||||
private BillingCacheManagerImpl() {
|
||||
}
|
||||
|
||||
public static BillingCacheManagerImpl getInstance() {
|
||||
if (billingCacheManager == null) {
|
||||
synchronized (BillingCacheManagerImpl.class) {
|
||||
if (billingCacheManager == null) {
|
||||
billingCacheManager = new BillingCacheManagerImpl();
|
||||
}
|
||||
}
|
||||
}
|
||||
return billingCacheManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addBillingToCache(PaginationResult paginationResult, String tenantDomain, Timestamp startDate, Timestamp endDate) throws DeviceManagementException {
|
||||
Cache<BillingCacheKey, PaginationResult> lCache = DeviceManagerUtil.getBillingCache();
|
||||
if (lCache != null) {
|
||||
BillingCacheKey cacheKey = getCacheKey(tenantDomain, startDate, endDate);
|
||||
if (lCache.containsKey(cacheKey)) {
|
||||
this.updateBillingInCache(paginationResult, tenantDomain, startDate, endDate);
|
||||
} else {
|
||||
lCache.put(cacheKey, paginationResult);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeBillingFromCache(String tenantDomain, Timestamp startDate, Timestamp endDate) throws DeviceManagementException {
|
||||
Cache<BillingCacheKey, PaginationResult> lCache = DeviceManagerUtil.getBillingCache();
|
||||
if (lCache != null) {
|
||||
BillingCacheKey cacheKey = getCacheKey(tenantDomain, startDate, endDate);
|
||||
if (lCache.containsKey(cacheKey)) {
|
||||
lCache.remove(cacheKey);
|
||||
}
|
||||
} else {
|
||||
String msg = "Failed to remove selected billing from cache";
|
||||
log.error(msg);
|
||||
throw new DeviceManagementException(msg);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeBillingsFromCache(List<BillingCacheKey> billingList) throws DeviceManagementException {
|
||||
Cache<BillingCacheKey, PaginationResult> lCache = DeviceManagerUtil.getBillingCache();
|
||||
if (lCache != null) {
|
||||
for (BillingCacheKey cacheKey : billingList) {
|
||||
if (lCache.containsKey(cacheKey)) {
|
||||
lCache.remove(cacheKey);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
String msg = "Failed to remove billing from cache";
|
||||
log.error(msg);
|
||||
throw new DeviceManagementException(msg);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateBillingInCache(PaginationResult paginationResult, String tenantDomain, Timestamp startDate, Timestamp endDate) throws DeviceManagementException {
|
||||
Cache<BillingCacheKey, PaginationResult> lCache = DeviceManagerUtil.getBillingCache();
|
||||
if (lCache != null) {
|
||||
BillingCacheKey cacheKey = getCacheKey(tenantDomain, startDate, endDate);
|
||||
if (lCache.containsKey(cacheKey)) {
|
||||
lCache.replace(cacheKey, paginationResult);
|
||||
}
|
||||
} else {
|
||||
String msg = "Failed to update billing cache";
|
||||
log.error(msg);
|
||||
throw new DeviceManagementException(msg);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO remove null check from here and do cache enable check in the methods calling this
|
||||
@Override
|
||||
public PaginationResult getBillingFromCache(String tenantDomain, Timestamp startDate, Timestamp endDate) {
|
||||
Cache<BillingCacheKey, PaginationResult> lCache = DeviceManagerUtil.getBillingCache();
|
||||
if (lCache != null) {
|
||||
return lCache.get(getCacheKey(tenantDomain, startDate, endDate));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method generates the billing CacheKey and returns it.
|
||||
*/
|
||||
private BillingCacheKey getCacheKey(String tenantDomain, Timestamp startDate, Timestamp endDate) {
|
||||
BillingCacheKey billingCacheKey = new BillingCacheKey();
|
||||
billingCacheKey.setTenantDomain(tenantDomain);
|
||||
billingCacheKey.setStartDate(startDate);
|
||||
billingCacheKey.setEndDate(endDate);
|
||||
return billingCacheKey;
|
||||
}
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (c) 2022, 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.core.config.cache;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
@XmlRootElement(name = "BillingCacheConfiguration")
|
||||
public class BillingCacheConfiguration {
|
||||
private boolean isEnabled;
|
||||
private int expiryTime;
|
||||
private long capacity;
|
||||
|
||||
@XmlElement(name = "Enable", required = true)
|
||||
public boolean isEnabled() {
|
||||
return isEnabled;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
isEnabled = enabled;
|
||||
}
|
||||
|
||||
@XmlElement(name = "ExpiryTime", required = true)
|
||||
public int getExpiryTime() {
|
||||
return expiryTime;
|
||||
}
|
||||
|
||||
public void setExpiryTime(int expiryTime) {
|
||||
this.expiryTime = expiryTime;
|
||||
}
|
||||
|
||||
@XmlElement(name = "Capacity", required = true)
|
||||
public long getCapacity() {
|
||||
return capacity;
|
||||
}
|
||||
|
||||
public void setCapacity(long capacity) {
|
||||
this.capacity = capacity;
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package org.wso2.carbon.device.mgt.core.config.enrollment.guide;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
@XmlRootElement(name = "EnrollmentGuideConfiguration")
|
||||
public class EnrollmentGuideConfiguration {
|
||||
|
||||
private boolean isEnabled;
|
||||
private String mail;
|
||||
|
||||
@XmlElement(name = "Enable", required = true)
|
||||
public boolean isEnabled() {
|
||||
return isEnabled;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
isEnabled = enabled;
|
||||
}
|
||||
|
||||
@XmlElement(name = "Mail", required = true)
|
||||
public String getMail() {
|
||||
return mail;
|
||||
}
|
||||
|
||||
public void setMail(String mail) {
|
||||
this.mail = mail;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright (c) 2023, Entgra (Pvt) Ltd. (http://www.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.core.config.ui;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
|
||||
public class HubspotChat {
|
||||
private boolean isEnableHubspot;
|
||||
private String trackingUrl;
|
||||
private String accessToken;
|
||||
private String senderActorId;
|
||||
|
||||
@XmlElement(name = "EnableHubspot")
|
||||
public boolean isEnableHubspot() {
|
||||
return isEnableHubspot;
|
||||
}
|
||||
|
||||
public void setEnableHubspot(boolean enableHubspot) {
|
||||
isEnableHubspot = enableHubspot;
|
||||
}
|
||||
|
||||
@XmlElement(name = "TrackingUrl")
|
||||
public String getTrackingUrl() {
|
||||
return trackingUrl;
|
||||
}
|
||||
|
||||
public void setTrackingUrl(String trackingUrl) {
|
||||
this.trackingUrl = trackingUrl;
|
||||
}
|
||||
|
||||
@XmlElement(name = "AccessToken")
|
||||
public String getAccessToken() {
|
||||
return accessToken;
|
||||
}
|
||||
|
||||
public void setAccessToken(String accessToken) {
|
||||
this.accessToken = accessToken;
|
||||
}
|
||||
@XmlElement(name = "SenderActorId")
|
||||
public String getSenderActorId() {
|
||||
return senderActorId;
|
||||
}
|
||||
|
||||
public void setSenderActorId(String senderActorId) {
|
||||
this.senderActorId = senderActorId;
|
||||
}
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
package org.wso2.carbon.device.mgt.core.dao;
|
||||
|
||||
import org.wso2.carbon.device.mgt.common.Billing;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.List;
|
||||
|
||||
public interface BillingDAO {
|
||||
|
||||
void addBilling(int deviceId, int tenantId, Timestamp billingStart, Timestamp billingEnd) throws DeviceManagementDAOException;
|
||||
|
||||
List<Billing> getBilling(int deviceId, Timestamp billingStart, Timestamp billingEnd) throws DeviceManagementDAOException;
|
||||
}
|
@ -1,71 +0,0 @@
|
||||
package org.wso2.carbon.device.mgt.core.dao.impl;
|
||||
|
||||
import org.wso2.carbon.device.mgt.common.Billing;
|
||||
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
|
||||
import org.wso2.carbon.device.mgt.core.dao.BillingDAO;
|
||||
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException;
|
||||
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
|
||||
import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class BillingDAOImpl implements BillingDAO {
|
||||
|
||||
@Override
|
||||
public void addBilling(int deviceId, int tenantId, Timestamp billingStart, Timestamp billingEnd) throws DeviceManagementDAOException {
|
||||
|
||||
Connection conn;
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String sql = "INSERT INTO DM_BILLING(DEVICE_ID, TENANT_ID, BILLING_START, BILLING_END) VALUES(?, ?, ?, ?)";
|
||||
stmt = conn.prepareStatement(sql, new String[] {"invoice_id"});
|
||||
stmt.setInt(1, deviceId);
|
||||
stmt.setInt(2,tenantId);
|
||||
stmt.setTimestamp(3, billingStart);
|
||||
stmt.setTimestamp(4, billingEnd);
|
||||
stmt.execute();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
throw new DeviceManagementDAOException("Error occurred while adding billing period", e);
|
||||
} finally {
|
||||
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Billing> getBilling(int deviceId, Timestamp billingStart, Timestamp billingEnd) throws DeviceManagementDAOException {
|
||||
List<Billing> billings = new ArrayList<>();
|
||||
Connection conn;
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
EnrolmentInfo.Status status = null;
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String sql;
|
||||
|
||||
sql = "SELECT * FROM DM_BILLING WHERE DEVICE_ID = ?";
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setInt(1, deviceId);
|
||||
rs = stmt.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
Billing bill = new Billing(rs.getInt("INVOICE_ID"), rs.getInt("DEVICE_ID"),rs.getInt("TENANT_ID"),
|
||||
(rs.getTimestamp("BILLING_START").getTime()), (rs.getTimestamp("BILLING_END").getTime()));
|
||||
billings.add(bill);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new DeviceManagementDAOException("Error occurred getting billing periods", e);
|
||||
} finally {
|
||||
DeviceManagementDAOUtil.cleanupResources(stmt, null);
|
||||
}
|
||||
return billings;
|
||||
}
|
||||
|
||||
private Connection getConnection() throws SQLException {
|
||||
return DeviceManagementDAOFactory.getConnection();
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue