From 797c7a02d0419ee0453061e2007ae1f606cd1735 Mon Sep 17 00:00:00 2001 From: inosh-perera Date: Fri, 13 May 2016 00:24:59 +0530 Subject: [PATCH 1/2] adding swagger annotation to beans --- .../device/mgt/jaxrs/beans/RoleWrapper.java | 16 +++++ .../wso2/carbon/device/mgt/common/Device.java | 19 ++++++ .../device/mgt/common/DeviceIdentifier.java | 8 +++ .../device/mgt/common/EnrolmentInfo.java | 17 +++++ .../carbon/device/mgt/common/Feature.java | 11 ++++ .../mgt/common/device/details/DeviceInfo.java | 32 +++++++++- .../common/device/details/DeviceLocation.java | 18 +++++- .../common/device/details/DeviceWrapper.java | 9 +++ .../mgt/common/operation/mgt/Operation.java | 39 ++++++++++++ .../device/mgt/common/search/Condition.java | 62 +++++++++++++++++++ .../mgt/common/search/SearchContext.java | 7 +++ 11 files changed, 234 insertions(+), 4 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/RoleWrapper.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/RoleWrapper.java index b8d633f3f66..ed8cfda09cd 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/RoleWrapper.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/RoleWrapper.java @@ -18,12 +18,28 @@ package org.wso2.carbon.device.mgt.jaxrs.beans; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; import org.wso2.carbon.user.mgt.common.UIPermissionNode; +@ApiModel(value = "RoleWrapper", description = "Role details including permission and the users in the roles are " + + "wrapped here.") public class RoleWrapper { + + @ApiModelProperty(name = "roleName", value = "The name of the role.", required = true) private String roleName; + @ApiModelProperty(name = "permissions", value = "Lists out all the permissions associated with roles.", + required = true) private String[] permissions; + @ApiModelProperty(name = "users", value = "The list of users assigned to the selected role.", + required = true) private String[] users; + @ApiModelProperty(name = "permissionList", value = "This contain the following, " + + "\n resourcePath\tThe path related to the API.\n " + + "displayName\tThe name of the permission that is shown " + + "in the UI.\n" + + "nodeList\tLists out the nested permissions.", + required = true) private UIPermissionNode permissionList; public String getRoleName() { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/Device.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/Device.java index feb5f987a21..865aff801e0 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/Device.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/Device.java @@ -17,19 +17,38 @@ */ 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 = "Device", description = "This class carries all information related to a managed device.") public class Device implements Serializable{ private static final long serialVersionUID = 1998101711L; + @ApiModelProperty(name = "id", value = "ID of the device in the WSO2 EMM device information database.", + required = true) private int id; + @ApiModelProperty(name = "name", value = "The device name that can be set on the device by the device user.", + required = true) private String name; + @ApiModelProperty(name = "type", value = "The OS type of the device.", required = true) private String type; + @ApiModelProperty(name = "description", value = "Additional information on the device.", required = true) private String description; + @ApiModelProperty(name = "deviceIdentifier", value = "This is a 64-bit number (as a hex string) that is randomly" + + " generated when the user first sets up the device and should" + + " remain constant for the lifetime of the user's device." + + " The value may change if a factory reset is performed on " + + "the device.", + required = true) private String deviceIdentifier; + @ApiModelProperty(name = "enrolmentInfo", value = "This defines the device registration related information. " + + "It is mandatory to define this information.", required = true) private EnrolmentInfo enrolmentInfo; + @ApiModelProperty(name = "features", value = "List of features.", required = true) private List features; private List properties; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceIdentifier.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceIdentifier.java index 3c5e2405027..a88bcb465a3 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceIdentifier.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceIdentifier.java @@ -17,11 +17,19 @@ */ package org.wso2.carbon.device.mgt.common; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + import java.io.Serializable; + +@ApiModel(value = "DeviceIdentifier", description = "This contains device details that is used to identify a device " + + "uniquely.") public class DeviceIdentifier implements Serializable{ + @ApiModelProperty(name = "id", value = "Identity of the device.", required = true) private String id; + @ApiModelProperty(name = "type", value = "Type of the device.", required = true) private String type; public DeviceIdentifier() {} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/EnrolmentInfo.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/EnrolmentInfo.java index eb37127d2ef..2ba839243c1 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/EnrolmentInfo.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/EnrolmentInfo.java @@ -18,8 +18,13 @@ */ package org.wso2.carbon.device.mgt.common; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + import java.io.Serializable; +@ApiModel(value = "EnrolmentInfo", description = "This class carries all information related to a devices enrollment" + + " status.") public class EnrolmentInfo implements Serializable { private static final long serialVersionUID = 1998101712L; @@ -32,12 +37,24 @@ public class EnrolmentInfo implements Serializable { BYOD, COPE } + @ApiModelProperty(name = "id", value = "ID of the device in the WSO2 EMM device information database.", + required = true) private int id; + @ApiModelProperty(name = "device", value = "Enrolled device.", required = true) private Device device; + @ApiModelProperty(name = "dateOfEnrolment", value = "Date of the device enrollment.", required = true ) private Long dateOfEnrolment; + @ApiModelProperty(name = "dateOfLastUpdate", value = "Date of the device's last update.", required = true ) private Long dateOfLastUpdate; + @ApiModelProperty(name = "ownership", value = "Defines the ownership details. The ownership type can be any of the" + + " following values.\n" + + "BYOD - Bring your own device (BYOD).\n" + + "COPE - Corporate owned personally enabled (COPE).", required = true ) private OwnerShip ownership; + @ApiModelProperty(name = "status", value = "Current status of the device, such as whether the device " + + "is active, removed etc.", required = true ) private Status status; + @ApiModelProperty(name = "owner", value = "The device owner's name.", required = true ) private String owner; public EnrolmentInfo() { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/Feature.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/Feature.java index 0519367fa53..e7dabd76ac5 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/Feature.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/Feature.java @@ -22,15 +22,26 @@ import java.io.Serializable; import java.util.List; import io.swagger.annotations.*; +@ApiModel(value = "Feature", description = "This class carries all information related to a devices enrollment" + + " status.") public class Feature implements Serializable { + @ApiModelProperty(name = "id", value = "Feature Id.", required = true ) private int id; + @ApiModelProperty(name = "code", value = "The code of the feature. For example the code to lock a device" + + " is DEVICE_LOCK.", required = true ) private String code; + @ApiModelProperty(name = "name", value = "A name that describes a feature.", required = true ) private String name; + @ApiModelProperty(name = "description", value = "Provides a description of the features..", required = true ) private String description; + @ApiModelProperty(name = "deviceType", value = "Provide the device type for the respective feature. " + + "Features allow you to perform operations on any device type, " + + "such as android, iOS or windows..", required = true ) private String deviceType; private String method; private String type; + @ApiModelProperty(name = "metadataEntries", value = "Properties related to features.", required = true ) private List metadataEntries; @XmlElement diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/device/details/DeviceInfo.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/device/details/DeviceInfo.java index 92af0d4544e..e76daf6611b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/device/details/DeviceInfo.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/device/details/DeviceInfo.java @@ -19,6 +19,8 @@ package org.wso2.carbon.device.mgt.common.device.details; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import java.io.Serializable; @@ -26,34 +28,60 @@ import java.util.Date; import java.util.HashMap; import java.util.Map; +@ApiModel(value = "DeviceInfo", description = "This class carries all information related to the device information " + + "provided by a device.") public class DeviceInfo implements Serializable { private static final long serialVersionUID = 1998101733L; + @ApiModelProperty(name = "deviceId", value = "Device Id.", required = true) private int deviceId; + @ApiModelProperty(name = "deviceType", value = "Type of the device.", required = true) private String deviceType; + @ApiModelProperty(name = "deviceId", value = "Device identifier.", required = true) private DeviceIdentifier deviceIdentifier; - + @ApiModelProperty(name = "IMEI", value = "IMEI number of the device.", required = true) private String IMEI; + @ApiModelProperty(name = "IMSI", value = "IMSI number of the device.", required = true) private String IMSI; + @ApiModelProperty(name = "deviceModel", value = "Model of the device.", required = true) private String deviceModel; + @ApiModelProperty(name = "vendor", value = "Vendor of the device.", required = true) private String vendor; + @ApiModelProperty(name = "osVersion", value = "Operating system version.", required = true) private String osVersion; + @ApiModelProperty(name = "batteryLevel", value = "Battery level of the device.", required = true) private Double batteryLevel; + @ApiModelProperty(name = "internalTotalMemory", value = "Total internal memory of the device.", required = true) private Double internalTotalMemory; + @ApiModelProperty(name = "internalAvailableMemory", value = "Total available memory of the device.", + required = true) private Double internalAvailableMemory; + @ApiModelProperty(name = "externalTotalMemory", value = "Total external memory of the device.", required = true) private Double externalTotalMemory; + @ApiModelProperty(name = "externalAvailableMemory", value = "Total external memory avilable of the device.", + required = true) private Double externalAvailableMemory; + @ApiModelProperty(name = "operator", value = "Mobile operator of the device.", required = true) private String operator; + @ApiModelProperty(name = "connectionType", value = "How the device is connected to the network.", required = true) private String connectionType; + @ApiModelProperty(name = "mobileSignalStrength", value = "Current mobile signal strength.", required = true) private Double mobileSignalStrength; + @ApiModelProperty(name = "ssid", value = "ssid of the connected WiFi.", required = true) private String ssid; + @ApiModelProperty(name = "cpuUsage", value = "Current total cpu usage.", required = true) private Double cpuUsage; + @ApiModelProperty(name = "totalRAMMemory", value = "Total Ram memory size.", required = true) private Double totalRAMMemory; + @ApiModelProperty(name = "availableRAMMemory", value = "Available total memory of RAM.", required = true) private Double availableRAMMemory; + @ApiModelProperty(name = "pluggedIn", value = "Whether the device is plugged into power or not.", + required = true) private boolean pluggedIn; + @ApiModelProperty(name = "updatedTime", value = "Device updated time.", required = true) private Date updatedTime; - + @ApiModelProperty(name = "deviceDetailsMap", value = ".", required = true) private Map deviceDetailsMap = new HashMap<>(); public int getDeviceId() { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/device/details/DeviceLocation.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/device/details/DeviceLocation.java index 1368b92806a..5223b0f047c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/device/details/DeviceLocation.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/device/details/DeviceLocation.java @@ -19,27 +19,41 @@ package org.wso2.carbon.device.mgt.common.device.details; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import java.io.Serializable; import java.util.Date; +@ApiModel(value = "DeviceLocation", description = "This class carries all information related to the device location " + + "details provided by a device.") public class DeviceLocation implements Serializable { private static final long serialVersionUID = 1998101722L; + @ApiModelProperty(name = "deviceId", value = "Device id", required = true) private int deviceId; + @ApiModelProperty(name = "deviceIdentifier", value = "Device identifier used to identify a device uniquely.", + required = true) private DeviceIdentifier deviceIdentifier; + @ApiModelProperty(name = "latitude", value = "Device GPS latitude.", required = true) private Double latitude; + @ApiModelProperty(name = "longitude", value = "Device GPS longitude.", required = true) private Double longitude; - + @ApiModelProperty(name = "street1", value = "First line of the address.", required = true) private String street1; + @ApiModelProperty(name = "street2", value = "Second part of the address.", required = true) private String street2; - + @ApiModelProperty(name = "city", value = "City of the device location.", required = true) private String city; + @ApiModelProperty(name = "state", value = "State of the device address.", required = true) private String state; + @ApiModelProperty(name = "zip", value = "Zip code of the device address.", required = true) private String zip; + @ApiModelProperty(name = "country", value = "Country of the device address.", required = true) private String country; + @ApiModelProperty(name = "updatedTime", value = "Update time of the device.", required = true) private Date updatedTime; public int getDeviceId() { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/device/details/DeviceWrapper.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/device/details/DeviceWrapper.java index 0fae8987784..205caf531cc 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/device/details/DeviceWrapper.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/device/details/DeviceWrapper.java @@ -19,14 +19,23 @@ package org.wso2.carbon.device.mgt.common.device.details; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; +@ApiModel(value = "DeviceWrapper", description = "This contains device details including, " + + "location and device meta information.") public class DeviceWrapper { + @ApiModelProperty(name = "device", value = "Device's basic information", required = true) private Device device; + @ApiModelProperty(name = "deviceIdentifier", value = "Device identifier used to identify a device.", + required = true) private DeviceIdentifier deviceIdentifier; + @ApiModelProperty(name = "deviceInfo", value = "Device's runtime information", required = true) private DeviceInfo deviceInfo; + @ApiModelProperty(name = "deviceLocation", value = "Device's current location", required = true) private DeviceLocation deviceLocation; public Device getDevice() { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/Operation.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/Operation.java index 3496bacb8c8..6bdbc9b0c2d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/Operation.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/Operation.java @@ -18,12 +18,17 @@ package org.wso2.carbon.device.mgt.common.operation.mgt; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import java.io.Serializable; import java.util.Properties; @XmlRootElement +@ApiModel(value = "Operation", description = "This class carries all information related to a operations that can be " + + "applied on a device.") public class Operation implements Serializable { public enum Type { @@ -38,17 +43,51 @@ public class Operation implements Serializable { REPEAT, NO_REPEAT, PAUSE_SEQUENCE, STOP_SEQUENCE } + @ApiModelProperty(name = "code", value = "The code of the operation that you carried out. For example the code of" + + " the operation carried out to device info operation is DEVICE_INFO.", + required = true) private String code; + @ApiModelProperty(name = "properties", value = "Properties of an operation containing meta information.", + required = true) private Properties properties; + @ApiModelProperty(name = "type", value = "The operation type that was carried out on the device. " + + "The operations types can be one of the following: COMMAND, PROFILE", + required = true) private Type type; + @ApiModelProperty(name = "id", value = "The operations carried out on a device is recorded in a database table. " + + "The ID of the operation in the database table is given as the ID " + + "in the output.", + required = true) private int id; + @ApiModelProperty(name = "status", value = "The status of the operation that has been carried out on a device. The" + + " operation status can be any one of the following:\n" + + "IN-PROGRESS - The operation is processing on the EMM server" + + " side and has not yet been delivered to the device.\n" + + "PENDING - The operation is delivered to the device but the response " + + "from the device is pending.\n" + + "COMPLETED - The operation is delivered to the device and the server has " + + "received a response back from the device.\n" + + "ERROR - An error has occurred while carrying out the operation.", + required = true) private Status status; + @ApiModelProperty(name = "control", value = "How the operation should be executed.", required = true) private Control control; + @ApiModelProperty(name = "receivedTimeStamp", value = "The time WSO2 EMM received the response from the device.", + required = true) private String receivedTimeStamp; + @ApiModelProperty(name = "createdTimeStamp", value = "The time when the operation was requested to be carried out.", + required = true) private String createdTimeStamp; + @ApiModelProperty(name = "isEnabled", value = "If the assigned value is true it indicates that a policy is " + + "enforced on the device. If the assigned value is false it indicates" + + " that a policy is not enforced on a device.", required = true) private boolean isEnabled; + @ApiModelProperty(name = "payLoad", value = "Payload of the operation to be sent to the device", required = true) private Object payLoad; + @ApiModelProperty(name = "operationResponse", value = "Response received from the device", required = true) private String operationResponse; + @ApiModelProperty(name = "activityId", value = "The identifier used to identify the operation uniquely.", + required = true) private String activityId; @Override diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/search/Condition.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/search/Condition.java index 5a4b45dd1e3..2cf03c56459 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/search/Condition.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/search/Condition.java @@ -19,12 +19,74 @@ package org.wso2.carbon.device.mgt.common.search; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +@ApiModel(value = "Condition", description = "Contains the advance search parameters.") public class Condition { + @ApiModelProperty(name = "conditions", value = "Provide the operation code. You can assign the following operation " + + "codes:\n" + + "DEVICE_MODEL : The model of the device.\n" + + "VENDOR : The name of the device vendor.\n" + + "OS_VERSION : The version of the device operating system.\n" + + "BATTERY_LEVEL : The current level of the device battery.\n" + + "INTERNAL_TOTAL_MEMORY : The total capacity of the internal memory" + + " available in the device.\n" + + "INTERNAL_AVAILABLE_MEMORY : The internal memory in the device " + + "that is available.\n" + + "EXTERNAL_TOTAL_MEMORY : The total capacity of the external memory " + + "available in the device.\n" + + "EXTERNAL_AVAILABLE_MEMORY : The external memory in the device" + + " that is available.\n" + + "CONNECTION_TYPE : Define if the device is connected to the GPRS " + + "or Wi-Fi settings.\n" + + "SSID : The name of the Wifi network that the device is " + + "connected to.\n" + + "CPU_USAGE : The current CPU usage of the mobile device.\n" + + "TOTAL_RAM_MEMORY : The total capacity of the random access " + + "memory available in the device.\n" + + "AVAILABLE_RAM_MEMORY : The random access memory capacity " + + "in the device that is available.\n" + + "PLUGGED_IN : Define true if the device is plugged in for charging " + + "or define false if the device is not plugged in for charging.", + required = true) private String key; + @ApiModelProperty(name = "value", value = "Define the value for the key you provide.\n" + + "Example: If you provide the key as VERSION, you can provide the " + + "value as 5.1, which indicates the version of the mobile device you" + + " are searching.", + required = true) private String value; + @ApiModelProperty(name = "operator", value = "Define the search condition between the key and the value you " + + "provide. The following values can be used to define the search " + + "condition:\n" + + "= : Searches for devices where the key is equal to the value " + + "provided.\n" + + "=! : Searches for devices where the key is not equal to the " + + "value provided.\n" + + "<= : Searches for devices where the key is greater than or equal" + + " to the value provide.\n" + + ">= : Searches for devices where the key is less than or equal to" + + " the value provided.\n" + + "> : Searches for devices where the key is greater than the value" + + " provided.\n" + + "< : Searches for devices where the key is less than the value " + + "provided.\n" + + "Example: If you wish to get the devises that have the version " + + "as 5.1, you need to use the = operator..", + required = true) public String operator; + @ApiModelProperty(name = "conditions", value = "There can be many search options as shown in the sample JSON " + + "definition. The field that connects the independent search " + + "options, is known as state.\n" + + "The following values can be assigned to state.\n" + + "AND : Defines if you want the search result to match all the " + + "search conditions provided.\n" + + "OR : Defines if you want the search result to match either of" + + " the search conditions provided.", + required = true) private State state; public enum State { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/search/SearchContext.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/search/SearchContext.java index c7c4be65ca4..5207ddc5022 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/search/SearchContext.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/search/SearchContext.java @@ -19,10 +19,17 @@ package org.wso2.carbon.device.mgt.common.search; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + import java.util.List; + +@ApiModel(value = "SearchContext", description = "Search details when carrying out a search contain in this class.") public class SearchContext { + @ApiModelProperty(name = "conditions", value = "Contains the advance search parameters.", + required = true) private List conditions; // private int start; // private int end; From 362cf40d854a2c264d0eec74b64f8c9354fa54c0 Mon Sep 17 00:00:00 2001 From: geethkokila Date: Fri, 13 May 2016 00:25:13 +0530 Subject: [PATCH 2/2] Fixing the operation activity id issues --- .../mgt/common/operation/mgt/Operation.java | 10 ++ .../operation/mgt/OperationResponse.java | 43 +++++ .../mgt/core/dto/operation/mgt/Operation.java | 9 + .../operation/mgt/OperationManagerImpl.java | 55 +++++- .../core/operation/mgt/dao/OperationDAO.java | 7 + .../mgt/dao/impl/GenericOperationDAOImpl.java | 158 ++++++++++++++++-- .../mgt/dao/util/OperationDAOUtil.java | 2 +- .../src/main/resources/dbscripts/cdm/h2.sql | 1 + .../main/resources/dbscripts/cdm/mssql.sql | 1 + .../main/resources/dbscripts/cdm/mysql.sql | 1 + .../main/resources/dbscripts/cdm/oracle.sql | 1 + .../resources/dbscripts/cdm/postgresql.sql | 1 + 12 files changed, 274 insertions(+), 15 deletions(-) create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/OperationResponse.java diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/Operation.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/Operation.java index 3496bacb8c8..55030a87cef 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/Operation.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/Operation.java @@ -21,6 +21,7 @@ package org.wso2.carbon.device.mgt.common.operation.mgt; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import java.io.Serializable; +import java.util.List; import java.util.Properties; @XmlRootElement @@ -50,6 +51,7 @@ public class Operation implements Serializable { private Object payLoad; private String operationResponse; private String activityId; + private List responses; @Override public boolean equals(Object o) { @@ -218,6 +220,14 @@ public class Operation implements Serializable { this.activityId = activityId; } + public List getResponses() { + return responses; + } + + public void setResponses(List responses) { + this.responses = responses; + } + @Override public String toString() { return "Operation{" + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/OperationResponse.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/OperationResponse.java new file mode 100644 index 00000000000..b993f087430 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/OperationResponse.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2016, 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.operation.mgt; + +public class OperationResponse { + + private String response; + private String recievedTimeStamp; + + public String getResponse() { + return response; + } + + public void setResponse(String response) { + this.response = response; + } + + public String getRecievedTimeStamp() { + return recievedTimeStamp; + } + + public void setRecievedTimeStamp(String recievedTimeStamp) { + this.recievedTimeStamp = recievedTimeStamp; + } +} + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/operation/mgt/Operation.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/operation/mgt/Operation.java index 360deb868ae..c61b2d304fc 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/operation/mgt/Operation.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/operation/mgt/Operation.java @@ -46,6 +46,7 @@ public class Operation implements Serializable { private boolean isEnabled; private Object payLoad; private Object operationResponse; + private String activityId; public String getCode() { return code; @@ -135,4 +136,12 @@ public class Operation implements Serializable { this.operationResponse = operationResponse; } + public String getActivityId() { + return activityId; + } + + public void setActivityId(String activityId) { + this.activityId = activityId; + } + } \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java index 5ec27f4c7cb..6784b0cb705 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java @@ -659,12 +659,57 @@ public class OperationManagerImpl implements OperationManager { @Override public Operation getOperationByActivityId(String activity) throws OperationManagementException { // This parses the operation id from activity id (ex : ACTIVITY_23) and converts to the integer. - int operationId = Integer.parseInt( + Operation operation; + int enrollmentOpMappingId = Integer.parseInt( activity.replace(DeviceManagementConstants.OperationAttributes.ACTIVITY, "")); - if(operationId == 0){ + if(enrollmentOpMappingId == 0){ throw new IllegalArgumentException("Operation ID cannot be null or zero (0)."); } - return this.getOperation(operationId); + try { + OperationManagementDAOFactory.openConnection(); + org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation = + operationDAO.getOperationFromEnrollment(enrollmentOpMappingId); + + if (dtoOperation == null) { + throw new OperationManagementException("Operation not found for given activity Id:" + activity); + } + org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status status = dtoOperation.getStatus(); + if (dtoOperation.getType().equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.COMMAND)) { + org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation commandOperation; + commandOperation = + (org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation) commandOperationDAO. + getOperation(dtoOperation.getId()); + dtoOperation.setEnabled(commandOperation.isEnabled()); + } else if (dtoOperation.getType(). + equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.CONFIG)) { + dtoOperation = configOperationDAO.getOperation(dtoOperation.getId()); + } else if (dtoOperation.getType().equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type. + PROFILE)) { + dtoOperation = profileOperationDAO.getOperation(dtoOperation.getId()); + } else if (dtoOperation.getType().equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type. + POLICY)) { + dtoOperation = policyOperationDAO.getOperation(dtoOperation.getId()); + } + operation = OperationDAOUtil.convertOperation(dtoOperation); + int enrolmentId = operationDAO.getEnrolmentIdFromMappingId(enrollmentOpMappingId); + if (enrolmentId !=0) { + operation.setResponses(operationDAO.getOperationResponses(enrolmentId, operation.getId())); + } + + operation.setStatus(Operation.Status.valueOf(status.toString())); + operation.setActivityId(activity); + + } catch (SQLException e) { + throw new OperationManagementException("Error occurred while opening a connection to the data source", e); + } catch (OperationManagementDAOException e) { + throw new OperationManagementException("Error occurred while retrieving the operation with activity Id '" + + activity, e); + } finally { + OperationManagementDAOFactory.closeConnection(); + } + + // return this.getOperation(operationId); + return operation; } private OperationDAO lookupOperationDAO(Operation operation) { @@ -722,4 +767,8 @@ public class OperationManagerImpl implements OperationManager { return status; } + private void setActivityId(Operation operation, int enrolmentId) { + operation.setActivityId(DeviceManagementConstants.OperationAttributes.ACTIVITY + enrolmentId); + } + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationDAO.java index 92349538299..c7499d84964 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationDAO.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationDAO.java @@ -19,6 +19,7 @@ package org.wso2.carbon.device.mgt.core.operation.mgt.dao; import org.wso2.carbon.device.mgt.common.PaginationRequest; +import org.wso2.carbon.device.mgt.common.operation.mgt.OperationResponse; import org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation; import java.util.List; @@ -33,6 +34,8 @@ public interface OperationDAO { Operation getOperation(int operationId) throws OperationManagementDAOException; + Operation getOperationFromEnrollment(int enrollmentOpMappingId) throws OperationManagementDAOException; + Operation getOperationByDeviceAndId(int enrolmentId, int operationId) throws OperationManagementDAOException; List getOperationsByDeviceAndStatus(int enrolmentId, Operation.Status status) @@ -58,4 +61,8 @@ public interface OperationDAO { void addOperationResponse(int enrolmentId, int operationId, Object operationResponse) throws OperationManagementDAOException; + List getOperationResponses(int enrolmentId, int operationId) throws OperationManagementDAOException; + + int getEnrolmentIdFromMappingId(int enrollmentOpMappingId) throws OperationManagementDAOException; + } \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/GenericOperationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/GenericOperationDAOImpl.java index 592be91c71f..45e9f4d2ccf 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/GenericOperationDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/GenericOperationDAOImpl.java @@ -20,15 +20,15 @@ package org.wso2.carbon.device.mgt.core.operation.mgt.dao.impl; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.device.mgt.common.PaginationRequest; +import org.wso2.carbon.device.mgt.common.operation.mgt.OperationResponse; +import org.wso2.carbon.device.mgt.core.DeviceManagementConstants; import org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation; import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationDAO; import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOException; import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory; import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOUtil; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.ObjectOutputStream; +import java.io.*; import java.sql.*; import java.util.ArrayList; import java.util.Date; @@ -149,7 +149,7 @@ public class GenericOperationDAOImpl implements OperationDAO { try { Connection connection = OperationManagementDAOFactory.getConnection(); stmt = connection.prepareStatement("INSERT INTO DM_DEVICE_OPERATION_RESPONSE(OPERATION_ID,ENROLMENT_ID," + - "OPERATION_RESPONSE) VALUES(?, ?, ?)"); + "OPERATION_RESPONSE, RECEIVED_TIMESTAMP) VALUES(?, ?, ?, ?)"); bao = new ByteArrayOutputStream(); oos = new ObjectOutputStream(bao); oos.writeObject(operationResponse); @@ -157,6 +157,7 @@ public class GenericOperationDAOImpl implements OperationDAO { stmt.setInt(1, operationId); stmt.setInt(2, enrolmentId); stmt.setBytes(3, bao.toByteArray()); + stmt.setTimestamp(4, new Timestamp(new Date().getTime())); stmt.executeUpdate(); } catch (SQLException e) { throw new OperationManagementDAOException("Error occurred while inserting operation response", e); @@ -181,6 +182,92 @@ public class GenericOperationDAOImpl implements OperationDAO { } } + @Override + public List getOperationResponses(int enrolmentId, int operationId) throws + OperationManagementDAOException { + + PreparedStatement stmt = null; + ResultSet rs = null; + List responces = new ArrayList<>(); + try { + Connection conn = OperationManagementDAOFactory.getConnection(); + String sql = "SELECT * FROM DM_DEVICE_OPERATION_RESPONSE WHERE ENROLMENT_ID = ? AND OPERATION_ID = ?"; + stmt = conn.prepareStatement(sql); + stmt.setInt(1, enrolmentId); + stmt.setInt(2, operationId); + rs = stmt.executeQuery(); + + while (rs.next()) { + OperationResponse response = new OperationResponse(); + response.setRecievedTimeStamp(rs.getTimestamp("RECEIVED_TIMESTAMP").toString()); + ByteArrayInputStream bais = null; + ObjectInputStream ois = null; + byte[] contentBytes; + try { + contentBytes = (byte[]) rs.getBytes("OPERATION_RESPONSE"); + bais = new ByteArrayInputStream(contentBytes); + ois = new ObjectInputStream(bais); + response.setResponse(ois.readObject().toString()); + + } finally { + if (bais != null) { + try { + bais.close(); + } catch (IOException e) { + log.warn("Error occurred while closing ByteArrayOutputStream", e); + } + } + if (ois != null) { + try { + ois.close(); + } catch (IOException e) { + log.warn("Error occurred while closing ObjectOutputStream", e); + } + } + } + responces.add(response); + } + + } catch (SQLException e) { + throw new OperationManagementDAOException("SQL Error occurred while retrieving the operation responses for " + + "operation id " + operationId + " and enrolment id " + enrolmentId, e); + } catch (ClassNotFoundException e) { + throw new OperationManagementDAOException("Error occurred while converting the operation responses to string" + + " for operation id " + operationId + " and enrolment id " + enrolmentId, e); + } catch (IOException e) { + throw new OperationManagementDAOException("Error occurred while converting the operation responses to string" + + " for operation id " + operationId + " and enrolment id " + enrolmentId, e); + } finally { + OperationManagementDAOUtil.cleanupResources(stmt, rs); + } + + return responces; + } + + @Override + public int getEnrolmentIdFromMappingId(int enrollmentOpMappingId) throws OperationManagementDAOException { + PreparedStatement stmt = null; + ResultSet rs = null; + try { + Connection conn = OperationManagementDAOFactory.getConnection(); + String sql = "SELECT * FROM DM_ENROLMENT_OP_MAPPING WHERE ID = ?"; + stmt = conn.prepareStatement(sql); + stmt.setInt(1, enrollmentOpMappingId); + rs = stmt.executeQuery(); + + if (rs.next()) { + return rs.getInt("ENROLMENT_ID"); + } + + } catch (SQLException e) { + throw new OperationManagementDAOException("SQL Error occurred while retrieving the enrolment id " + + " for the mapping id '" + enrollmentOpMappingId, e); + } finally { + OperationManagementDAOUtil.cleanupResources(stmt, rs); + } + return -1; + } + @Override public void deleteOperation(int id) throws OperationManagementDAOException { PreparedStatement stmt = null; @@ -231,6 +318,43 @@ public class GenericOperationDAOImpl implements OperationDAO { return operation; } + @Override + public Operation getOperationFromEnrollment(int enrollmentOpMappingId) throws OperationManagementDAOException { + PreparedStatement stmt = null; + ResultSet rs = null; + Operation operation = null; + try { + Connection conn = OperationManagementDAOFactory.getConnection(); + String sql = "SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE, \n" + + " om.STATUS FROM DM_OPERATION o \n" + + "INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING dm WHERE dm.ID = ? ) om \n" + + "ON o.ID = om.OPERATION_ID ORDER BY o.CREATED_TIMESTAMP DESC "; + stmt = conn.prepareStatement(sql); + stmt.setInt(1, enrollmentOpMappingId); + rs = stmt.executeQuery(); + + if (rs.next()) { + operation = new Operation(); + operation.setId(rs.getInt("ID")); + operation.setType(Operation.Type.valueOf(rs.getString("TYPE"))); + operation.setCreatedTimeStamp(rs.getTimestamp("CREATED_TIMESTAMP").toString()); + if (rs.getTimestamp("RECEIVED_TIMESTAMP") == null) { + operation.setReceivedTimeStamp(""); + } else { + operation.setReceivedTimeStamp(rs.getTimestamp("RECEIVED_TIMESTAMP").toString()); + } + operation.setCode(rs.getString("OPERATION_CODE")); + operation.setStatus(Operation.Status.valueOf(rs.getString("STATUS"))); + this.setActivityId(operation, enrollmentOpMappingId); + } + } catch (SQLException e) { + throw new OperationManagementDAOException("SQL error occurred while retrieving the operation .", e); + } finally { + OperationManagementDAOUtil.cleanupResources(stmt, rs); + } + return operation; + } + @Override public Operation getOperationByDeviceAndId(int enrolmentId, int operationId) throws OperationManagementDAOException { PreparedStatement stmt = null; @@ -238,7 +362,7 @@ public class GenericOperationDAOImpl implements OperationDAO { Operation operation = null; try { Connection conn = OperationManagementDAOFactory.getConnection(); - String sql = "SELECT o.ID, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, o.STATUS, o.OPERATION_CODE " + + String sql = "SELECT o.ID, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, o.STATUS, o.OPERATION_CODE, om.ID AS OM_MAPPING_ID " + " FROM (SELECT ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, STATUS," + "OPERATION_CODE FROM DM_OPERATION WHERE id = ?) o INNER JOIN (SELECT * FROM " + "DM_ENROLMENT_OP_MAPPING dm where dm.OPERATION_ID = ? AND dm.ENROLMENT_ID = ?) om " + @@ -260,6 +384,7 @@ public class GenericOperationDAOImpl implements OperationDAO { operation.setReceivedTimeStamp(rs.getTimestamp("RECEIVED_TIMESTAMP").toString()); } operation.setCode(rs.getString("OPERATION_CODE")); + this.setActivityId(operation, rs.getInt("OM_MAPPING_ID")); } } catch (SQLException e) { throw new OperationManagementDAOException("SQL error occurred while retrieving the operation " + @@ -279,7 +404,7 @@ public class GenericOperationDAOImpl implements OperationDAO { List operations = new ArrayList(); try { Connection conn = OperationManagementDAOFactory.getConnection(); - String sql = "SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE " + + String sql = "SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE, om.ID AS OM_MAPPING_ID" + "FROM DM_OPERATION o " + "INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING dm " + "WHERE dm.ENROLMENT_ID = ? AND dm.STATUS = ?) om ON o.ID = om.OPERATION_ID ORDER BY o.CREATED_TIMESTAMP DESC"; @@ -300,6 +425,7 @@ public class GenericOperationDAOImpl implements OperationDAO { } operation.setCode(rs.getString("OPERATION_CODE")); operation.setStatus(status); + this.setActivityId(operation, rs.getInt("OM_MAPPING_ID")); operations.add(operation); } } catch (SQLException e) { @@ -321,7 +447,7 @@ public class GenericOperationDAOImpl implements OperationDAO { List operations = new ArrayList(); try { Connection conn = OperationManagementDAOFactory.getConnection(); - String sql = "SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE " + + String sql = "SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE, om.ID AS OM_MAPPING_ID " + "FROM DM_OPERATION o " + "INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING dm " + "WHERE dm.ENROLMENT_ID = ? AND dm.STATUS = ?) om ON o.ID = om.OPERATION_ID ORDER BY " + @@ -345,6 +471,7 @@ public class GenericOperationDAOImpl implements OperationDAO { } operation.setCode(rs.getString("OPERATION_CODE")); operation.setStatus(status); + this.setActivityId(operation, rs.getInt("OM_MAPPING_ID")); operations.add(operation); } } catch (SQLException e) { @@ -365,7 +492,7 @@ public class GenericOperationDAOImpl implements OperationDAO { try { Connection conn = OperationManagementDAOFactory.getConnection(); String sql = "SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, " + - "OPERATION_CODE, om.STATUS FROM DM_OPERATION o " + + "OPERATION_CODE, om.STATUS, om.ID AS OM_MAPPING_ID FROM DM_OPERATION o " + "INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING dm " + "WHERE dm.ENROLMENT_ID = ?) om ON o.ID = om.OPERATION_ID ORDER BY o.CREATED_TIMESTAMP DESC"; stmt = conn.prepareStatement(sql); @@ -384,6 +511,7 @@ public class GenericOperationDAOImpl implements OperationDAO { } operation.setCode(rs.getString("OPERATION_CODE")); operation.setStatus(Operation.Status.valueOf(rs.getString("STATUS"))); + this.setActivityId(operation, rs.getInt("OM_MAPPING_ID")); operations.add(operation); } } catch (SQLException e) { @@ -405,7 +533,7 @@ public class GenericOperationDAOImpl implements OperationDAO { try { Connection conn = OperationManagementDAOFactory.getConnection(); String sql = "SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, " + - "OPERATION_CODE, om.STATUS FROM DM_OPERATION o " + + "OPERATION_CODE, om.STATUS, om.ID AS OM_MAPPING_ID FROM DM_OPERATION o " + "INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING dm " + "WHERE dm.ENROLMENT_ID = ?) om ON o.ID = om.OPERATION_ID ORDER BY o.CREATED_TIMESTAMP DESC LIMIT ?,?"; stmt = conn.prepareStatement(sql); @@ -426,6 +554,7 @@ public class GenericOperationDAOImpl implements OperationDAO { } operation.setCode(rs.getString("OPERATION_CODE")); operation.setStatus(Operation.Status.valueOf(rs.getString("STATUS"))); + this.setActivityId(operation, rs.getInt("OM_MAPPING_ID")); operations.add(operation); } } catch (SQLException e) { @@ -468,7 +597,7 @@ public class GenericOperationDAOImpl implements OperationDAO { try { Connection connection = OperationManagementDAOFactory.getConnection(); stmt = connection.prepareStatement("SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, " + - "OPERATION_CODE FROM DM_OPERATION o " + + "OPERATION_CODE, om.ID AS OM_MAPPING_ID FROM DM_OPERATION o " + "INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING dm " + "WHERE dm.ENROLMENT_ID = ? AND dm.STATUS = ?) om ON o.ID = om.OPERATION_ID " + "ORDER BY o.CREATED_TIMESTAMP ASC LIMIT 1"); @@ -489,6 +618,7 @@ public class GenericOperationDAOImpl implements OperationDAO { } operation.setCode(rs.getString("OPERATION_CODE")); operation.setStatus(Operation.Status.PENDING); + this.setActivityId(operation, rs.getInt("OM_MAPPING_ID")); } return operation; } catch (SQLException e) { @@ -507,7 +637,7 @@ public class GenericOperationDAOImpl implements OperationDAO { List operations = new ArrayList(); try { Connection conn = OperationManagementDAOFactory.getConnection(); - String sql = "SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE FROM " + + String sql = "SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE, om.ID AS OM_MAPPING_ID FROM " + "(SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE " + "FROM DM_OPERATION o WHERE o.TYPE = ?) o " + "INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING dm " + @@ -530,6 +660,7 @@ public class GenericOperationDAOImpl implements OperationDAO { operation.setReceivedTimeStamp(rs.getTimestamp("RECEIVED_TIMESTAMP").toString()); } operation.setCode(rs.getString("OPERATION_CODE")); + this.setActivityId(operation, rs.getInt("OM_MAPPING_ID")); operations.add(operation); } } catch (SQLException e) { @@ -545,4 +676,9 @@ public class GenericOperationDAOImpl implements OperationDAO { return Operation.Type.valueOf(type); } + private void setActivityId(Operation operation, int enrolmentId) { + operation.setActivityId(DeviceManagementConstants.OperationAttributes.ACTIVITY + enrolmentId); + } + + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/util/OperationDAOUtil.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/util/OperationDAOUtil.java index 6625ceab894..03e7e64143a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/util/OperationDAOUtil.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/util/OperationDAOUtil.java @@ -95,7 +95,7 @@ public class OperationDAOUtil { operation.setReceivedTimeStamp(dtoOperation.getReceivedTimeStamp()); operation.setEnabled(dtoOperation.isEnabled()); operation.setProperties(dtoOperation.getProperties()); - operation.setActivityId(DeviceManagementConstants.OperationAttributes.ACTIVITY + dtoOperation.getId()); + operation.setActivityId(dtoOperation.getActivityId()); return operation; diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/h2.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/h2.sql index 67cdf57a338..a767ae6bfb5 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/h2.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/h2.sql @@ -123,6 +123,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_OPERATION_RESPONSE ( ENROLMENT_ID INTEGER NOT NULL, OPERATION_ID INTEGER NOT NULL, OPERATION_RESPONSE BLOB DEFAULT NULL, + RECEIVED_TIMESTAMP TIMESTAMP NULL, PRIMARY KEY (ID), CONSTRAINT fk_dm_device_operation_response_enrollment FOREIGN KEY (ENROLMENT_ID) REFERENCES DM_ENROLMENT (ID) ON DELETE NO ACTION ON UPDATE NO ACTION, diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mssql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mssql.sql index e18fcf915a5..5c7e5e97993 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mssql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mssql.sql @@ -123,6 +123,7 @@ CREATE TABLE DM_DEVICE_OPERATION_RESPONSE ( ENROLMENT_ID INTEGER NOT NULL, OPERATION_ID INTEGER NOT NULL, OPERATION_RESPONSE VARBINARY(max) DEFAULT NULL, + RECEIVED_TIMESTAMP DATETIME2(0) NULL, PRIMARY KEY (ID), CONSTRAINT fk_dm_device_operation_response_enrollment FOREIGN KEY (ENROLMENT_ID) REFERENCES DM_ENROLMENT (ID) ON DELETE NO ACTION ON UPDATE NO ACTION, diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql index 0fd8889cc33..b7f06c57aa7 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql @@ -108,6 +108,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_OPERATION_RESPONSE ( ENROLMENT_ID INTEGER NOT NULL, OPERATION_ID INTEGER NOT NULL, OPERATION_RESPONSE BLOB DEFAULT NULL, + RECEIVED_TIMESTAMP TIMESTAMP NULL, PRIMARY KEY (ID), CONSTRAINT fk_dm_device_operation_response_enrollment FOREIGN KEY (ENROLMENT_ID) REFERENCES DM_ENROLMENT (ID) ON DELETE NO ACTION ON UPDATE NO ACTION, diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql index 7a41ae3a66e..fa18093ba9c 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql @@ -229,6 +229,7 @@ CREATE TABLE DM_DEVICE_OPERATION_RESPONSE ( ENROLMENT_ID NUMBER(10) NOT NULL, OPERATION_ID NUMBER(10) NOT NULL, OPERATION_RESPONSE BLOB DEFAULT NULL, + RECEIVED_TIMESTAMP TIMESTAMP(0) NULL, CONSTRAINT PK_DM_DEVICE_OP_RESPONSE PRIMARY KEY (ID), CONSTRAINT FK_DM_DEVICE_OP_RES_DEVICE FOREIGN KEY (ENROLMENT_ID) REFERENCES DM_ENROLMENT (ID), diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgresql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgresql.sql index 9ec4ef37788..de4a8ca0165 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgresql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgresql.sql @@ -94,6 +94,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_OPERATION_RESPONSE ( ENROLMENT_ID INTEGER NOT NULL, OPERATION_ID INTEGER NOT NULL, OPERATION_RESPONSE BYTEA DEFAULT NULL, + RECEIVED_TIMESTAMP TIMESTAMP NULL, CONSTRAINT fk_dm_device_operation_response_enrollment FOREIGN KEY (ENROLMENT_ID) REFERENCES DM_ENROLMENT (ID) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT fk_dm_device_operation_response_operation FOREIGN KEY (OPERATION_ID) REFERENCES