Compare commits

Invalid templates have been ignored

1 invalid template(s) found pull_request_template.md: frontmatter must start with a separator line

..

No commits in common. '0dc138dbb322c90e62c3912c83ea7615c4a5c604' and '5da2ae1f74af26fdf4a6a3ecc6b6a7f8563880e5' have entirely different histories.

@ -2619,11 +2619,8 @@ public class ApplicationManagerImpl implements ApplicationManager {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
ApplicationDTO applicationDTO = getApplication(applicationId);
String sanitizedName = "";
if (!StringUtils.isEmpty(applicationUpdateWrapper.getName())) {
sanitizedName = ApplicationManagementUtil.sanitizeName(applicationUpdateWrapper.getName(),
Constants.ApplicationProperties.NAME );
}
String sanitizedName = ApplicationManagementUtil.sanitizeName(applicationUpdateWrapper.getName(),
Constants.ApplicationProperties.NAME );
try {
ConnectionManagerUtil.beginDBTransaction();
if (!StringUtils.isEmpty(sanitizedName) && !applicationDTO.getName()

@ -116,7 +116,6 @@ CREATE TABLE IF NOT EXISTS DM_OPERATION
OPERATION_CODE VARCHAR(1000) NOT NULL,
INITIATED_BY VARCHAR(100) NULL,
OPERATION_DETAILS BLOB DEFAULT NULL,
OPERATION_PROPERTIES BLOB DEFAULT NULL,
ENABLED BOOLEAN NOT NULL DEFAULT FALSE,
PRIMARY KEY (ID)
);

@ -140,7 +140,6 @@ CREATE TABLE IF NOT EXISTS DM_OPERATION (
OPERATION_CODE VARCHAR(1000) NOT NULL,
INITIATED_BY VARCHAR(100) NULL,
OPERATION_DETAILS BLOB DEFAULT NULL,
OPERATION_PROPERTIES BLOB DEFAULT NULL,
ENABLED BOOLEAN NOT NULL DEFAULT FALSE,
TENANT_ID INTEGER NOT NULL,
PRIMARY KEY (ID)

@ -491,7 +491,7 @@ public interface ActivityInfoProviderService {
name = "status",
value = "Operation response status to filter"
)
@QueryParam("status") List<String> statuses,
@QueryParam("status") String status,
@ApiParam(
name = "If-Modified-Since",
value = "Checks if the requested variant was modified, since the specified date-time\n." +
@ -615,7 +615,7 @@ public interface ActivityInfoProviderService {
name = "status",
value = "Operation response status to filter"
)
@QueryParam("status") List<String> statuses,
@QueryParam("status") String status,
@ApiParam(
name = "If-Modified-Since",
value = "Checks if the requested variant was modified, since the specified date-time\n." +

@ -50,7 +50,6 @@ import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@ -260,7 +259,7 @@ public class ActivityProviderServiceImpl implements ActivityInfoProviderService
@QueryParam("deviceType") String deviceType,
@QueryParam("deviceId") List<String> deviceIds,
@QueryParam("type") String type,
@QueryParam("status") List<String> statuses,
@QueryParam("status") String status,
@HeaderParam("If-Modified-Since") String ifModifiedSince,
@QueryParam("startTimestamp") long startTimestamp,
@QueryParam("endTimestamp") long endTimestamp) {
@ -337,12 +336,8 @@ public class ActivityProviderServiceImpl implements ActivityInfoProviderService
if (type != null && !type.isEmpty()) {
activityPaginationRequest.setType(Operation.Type.valueOf(type.toUpperCase()));
}
if (statuses != null && !statuses.isEmpty()) {
List<Operation.Status> statusEnums = new ArrayList<>();
for (String status : statuses) {
statusEnums.add(Operation.Status.valueOf(status.toUpperCase()));
}
activityPaginationRequest.setStatuses(statusEnums);
if (status != null && !status.isEmpty()) {
activityPaginationRequest.setStatus(Operation.Status.valueOf(status.toUpperCase()));
}
if (timestamp > 0) {
activityPaginationRequest.setSince(timestamp);
@ -387,7 +382,7 @@ public class ActivityProviderServiceImpl implements ActivityInfoProviderService
@QueryParam("deviceType") String deviceType,
@QueryParam("deviceId") List<String> deviceIds,
@QueryParam("type") String type,
@QueryParam("status") List<String> statuses,
@QueryParam("status") String status,
@HeaderParam("If-Modified-Since") String ifModifiedSince,
@QueryParam("startTimestamp") long startTimestamp,
@QueryParam("endTimestamp") long endTimestamp) {
@ -462,12 +457,8 @@ public class ActivityProviderServiceImpl implements ActivityInfoProviderService
if (type != null && !type.isEmpty()) {
activityPaginationRequest.setType(Operation.Type.valueOf(type.toUpperCase()));
}
if (statuses != null && !statuses.isEmpty()) {
List<Operation.Status> statusEnums = new ArrayList<>();
for (String status : statuses) {
statusEnums.add(Operation.Status.valueOf(status.toUpperCase()));
}
activityPaginationRequest.setStatuses(statusEnums);
if (status != null && !status.isEmpty()) {
activityPaginationRequest.setStatus(Operation.Status.valueOf(status.toUpperCase()));
}
if (timestamp > 0) {
activityPaginationRequest.setSince(timestamp);

@ -132,7 +132,7 @@ public class ActivityProviderServiceImplTest {
activityPaginationRequest.setDeviceType(DEVICE_TYPE_2);
activityPaginationRequest.setOperationId(OPERATION_ID);
activityPaginationRequest.setInitiatedBy(INITIATED_BY);
activityPaginationRequest.setStatuses(Collections.singletonList(STATUS));
activityPaginationRequest.setStatus(STATUS);
activityPaginationRequest.setType(TYPE);
activityPaginationRequest.setStartTimestamp(0);
activityPaginationRequest.setEndTimestamp(0);
@ -226,7 +226,7 @@ public class ActivityProviderServiceImplTest {
Mockito.when(this.deviceManagementProviderService.getActivities(Mockito.any())).thenReturn(activities);
Response response = this.activityInfoProviderService.getActivities(
OFFSET, LIMIT, SINCE, INITIATED_BY, OPERATION_CODE, OPERATION_ID,
DEVICE_TYPE_2, Collections.singletonList(DEVICE_ID), TYPE.toString(), Collections.singletonList(STATUS.toString()), null, 0, 0);
DEVICE_TYPE_2, Collections.singletonList(DEVICE_ID), TYPE.toString(), STATUS.toString(), null, 0, 0);
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode());
Assert.assertNotNull(response);
@ -258,7 +258,7 @@ public class ActivityProviderServiceImplTest {
Mockito.when(this.deviceManagementProviderService.getDeviceActivities(Mockito.any())).thenReturn(deviceActivities);
Response response = this.activityInfoProviderService.getDeviceActivities(
OFFSET, LIMIT, SINCE, INITIATED_BY, OPERATION_CODE, OPERATION_ID,
DEVICE_TYPE_2, Collections.singletonList(DEVICE_ID), TYPE.toString(), Collections.singletonList(STATUS.toString()), null, 0, 0);
DEVICE_TYPE_2, Collections.singletonList(DEVICE_ID), TYPE.toString(), STATUS.toString(), null, 0, 0);
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode());
Assert.assertNotNull(response);

@ -36,7 +36,7 @@ public class ActivityPaginationRequest {
private String initiatedBy;
private long since;
private Operation.Type type;
private List<Operation.Status> statuses;
private Operation.Status status;
private long startTimestamp;
private long endTimestamp;
@ -110,12 +110,12 @@ public class ActivityPaginationRequest {
this.type = type;
}
public List<Operation.Status> getStatuses() {
return statuses;
public Operation.Status getStatus() {
return status;
}
public void setStatuses(List<Operation.Status> statuses) {
this.statuses = statuses;
public void setStatus(Operation.Status status) {
this.status = status;
}
public long getStartTimestamp() {

@ -1,211 +0,0 @@
/*
* Copyright (c) 2018 - 2024, 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.device.mgt.common.geo.service;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
/**
* Holds Device updates on events related to fence crossings
*/
@ApiModel(value = "GeoEventDeviceUpdate", description = "This class holds Device updates on events related to fence crossings")
public class GeoEventDeviceUpdate implements Serializable {
private static final long serialVersionUID = 1448121761L;
@ApiModelProperty(name = "id", value = "ID of the event in the database.")
private int id;
@ApiModelProperty(name = "deviceId", value = "IDs of the reporting device")
private String deviceId;
@ApiModelProperty(name = "eventType", value = "Type of fence crossing event.")
private String eventType;
@ApiModelProperty(name = "fenceIds", value = "IDs of the event in the database.")
private int fenceId;
@ApiModelProperty(name = "lat", value = "latitude of the current position")
private double lat;
@ApiModelProperty(name = "lon", value = "longitude of the current position")
private double lon;
@ApiModelProperty(name = "street1", value = "street1 of the current position")
private String street1;
@ApiModelProperty(name = "street2", value = "street2 of the current position")
private String street2;
@ApiModelProperty(name = "city", value = "city of the current position")
private String city;
@ApiModelProperty(name = "zip", value = "zip of the current position")
private String zip;
@ApiModelProperty(name = "state", value = "state of the current position")
private String state;
@ApiModelProperty(name = "country", value = "country of the current position")
private String country;
@ApiModelProperty(name = "altitude", value = "altitude of the current position")
private double altitude;
@ApiModelProperty(name = "speed", value = "speed of the current position")
private float speed;
@ApiModelProperty(name = "bearing", value = "bearing of the current position")
private float bearing;
@ApiModelProperty(name = "distance", value = "distance of the current position")
private float distance;
@ApiModelProperty(name = "updatedTimestamp", value = "updatedTimestamp of the current position")
private long updatedTimestamp;
public long getUpdatedTimestamp() {
return updatedTimestamp;
}
public void setUpdatedTimestamp(long updatedTimestamp) {
this.updatedTimestamp = updatedTimestamp;
}
public String getStreet1() {
return street1;
}
public void setStreet1(String street1) {
this.street1 = street1;
}
public String getStreet2() {
return street2;
}
public void setStreet2(String street2) {
this.street2 = street2;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getZip() {
return zip;
}
public void setZip(String zip) {
this.zip = zip;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
public double getAltitude() {
return altitude;
}
public void setAltitude(double altitude) {
this.altitude = altitude;
}
public float getSpeed() {
return speed;
}
public void setSpeed(float speed) {
this.speed = speed;
}
public float getBearing() {
return bearing;
}
public void setBearing(float bearing) {
this.bearing = bearing;
}
public float getDistance() {
return distance;
}
public void setDistance(float distance) {
this.distance = distance;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getDeviceId() {
return deviceId;
}
public void setDeviceId(String deviceId) {
this.deviceId = deviceId;
}
public String getEventType() {
return eventType;
}
public void setEventType(String eventType) {
this.eventType = eventType;
}
public int getFenceId() {
return fenceId;
}
public void setFenceId(int fenceId) {
this.fenceId = fenceId;
}
public double getLat() {
return lat;
}
public void setLat(double lat) {
this.lat = lat;
}
public double getLon() {
return lon;
}
public void setLon(double lon) {
this.lon = lon;
}
}

@ -178,19 +178,4 @@ public interface GeoLocationProviderService {
* @throws GeoLocationBasedServiceException any errors occurred while reading event records to geofence
*/
int getGeoFenceCount() throws GeoLocationBasedServiceException;
/**
* Saves the geo-fence crossing event data for a device.
*
* <p>This method handles the transaction for saving the geo-fence crossing event data
* for a device, including retrieving the tenant ID and handling the necessary
* database operations. If any error occurs during the transaction, appropriate
* exceptions are thrown.
*
* @param geofenceData the geo-fence crossing event data to be saved.
* @return always returns {@code false}.
* @throws GeoLocationBasedServiceException if there is an error during the transaction
* or database operations.
*/
boolean saveGeoFenceCrossingDevice(GeoEventDeviceUpdate geofenceData) throws GeoLocationBasedServiceException;
}

@ -547,9 +547,8 @@ public class ArchivalDAOImpl implements ArchivalDAO {
String sql = "INSERT INTO " + DESTINATION_DB + ".DM_OPERATION_ARCH " +
"SELECT OPR.ID, OPR.TYPE, OPR.CREATED_TIMESTAMP, OPR.RECEIVED_TIMESTAMP, " +
"OPR.OPERATION_CODE, OPR.INITIATED_BY, OPR.OPERATION_DETAILS, OPR.OPERATION_PROPERTIES, " +
"OPR.ENABLED, NOW() " +
"FROM " + SOURCE_DB + ".DM_OPERATION OPR " +
"OPR.OPERATION_CODE, OPR.INITIATED_BY, OPR.OPERATION_DETAILS, OPR.ENABLED, NOW() " +
"FROM " + SOURCE_DB + ".DM_OPERATION OPR " +
"WHERE OPR.ID NOT IN (SELECT DISTINCT OPERATION_ID FROM " + SOURCE_DB + ".DM_ENROLMENT_OP_MAPPING)";
long startTime = System.currentTimeMillis();

@ -20,7 +20,6 @@ package io.entgra.device.mgt.core.device.mgt.core.dao;
import io.entgra.device.mgt.core.device.mgt.common.PaginationRequest;
import io.entgra.device.mgt.core.device.mgt.common.event.config.EventConfig;
import io.entgra.device.mgt.core.device.mgt.common.geo.service.GeoEventDeviceUpdate;
import io.entgra.device.mgt.core.device.mgt.common.geo.service.GeofenceData;
import io.entgra.device.mgt.core.device.mgt.core.dto.event.config.GeoFenceGroupMap;
@ -183,18 +182,4 @@ public interface GeofenceDAO {
* @throws DeviceManagementDAOException
*/
int getGeofenceCount(int tenantId) throws DeviceManagementDAOException;
/**
* Adds a geo-fence crossing event to the database for a specific device.
*
* <p>This method inserts the geo-fence crossing event data into the database. The data includes
* details about the device, event type, location coordinates, and additional contextual information.
* The method returns the generated ID of the newly inserted record.
*
* @param tenantId the tenant ID associated with the event.
* @param deviceEvent the geo-fence crossing event data to be added.
* @return the generated ID of the newly inserted record, or -1 if the insertion failed.
* @throws DeviceManagementDAOException if there is an error during the database operation.
*/
int addGeoFenceCrossingDevice(int tenantId, GeoEventDeviceUpdate deviceEvent) throws DeviceManagementDAOException;
}

@ -18,7 +18,6 @@
package io.entgra.device.mgt.core.device.mgt.core.dao.impl;
import io.entgra.device.mgt.core.device.mgt.common.geo.service.GeoEventDeviceUpdate;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import io.entgra.device.mgt.core.device.mgt.common.DeviceManagementConstants;
@ -29,7 +28,6 @@ import io.entgra.device.mgt.core.device.mgt.core.dao.DeviceManagementDAOExceptio
import io.entgra.device.mgt.core.device.mgt.core.dao.EventManagementDAOFactory;
import io.entgra.device.mgt.core.device.mgt.core.dao.GeofenceDAO;
import io.entgra.device.mgt.core.device.mgt.core.dto.event.config.GeoFenceGroupMap;
import org.wso2.carbon.context.CarbonContext;
import java.sql.Connection;
import java.sql.PreparedStatement;
@ -670,66 +668,4 @@ public abstract class AbstractGeofenceDAOImpl implements GeofenceDAO {
}
}
@Override
public int addGeoFenceCrossingDevice(int tenantId, GeoEventDeviceUpdate deviceEvent) throws DeviceManagementDAOException {
try {
CarbonContext context = CarbonContext.getThreadLocalCarbonContext();
String username = context.getUsername();
int genId = -1;
Connection conn = this.getConnection();
String sql = "INSERT INTO DM_GEOFECE_DEVICE_EVENT(" +
"DEVICE_ID, " +
"EVENT_TYPE, " +
"FENCE_ID, " +
"LATITUDE, " +
"LONGITUDE, " +
"UPDATE_TIMESTAMP, " +
"USERNAME, " +
"TENANT_ID," +
"STREET1, " +
"STREET2, " +
"CITY, " +
"ZIP, " +
"STATE, " +
"COUNTRY, " +
"ALTITUDE," +
"SPEED, " +
"BEARING," +
"DISTANCE) " +
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
try (PreparedStatement stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {
stmt.setString(1, deviceEvent.getDeviceId());
stmt.setString(2, deviceEvent.getEventType());
stmt.setInt(3, deviceEvent.getFenceId());
stmt.setDouble(4, deviceEvent.getLat());
stmt.setDouble(5, deviceEvent.getLon());
stmt.setTimestamp(6, new Timestamp(deviceEvent.getUpdatedTimestamp()));
stmt.setString(7, username);
stmt.setInt(8, tenantId);
stmt.setString(9, deviceEvent.getStreet1());
stmt.setString(10, deviceEvent.getStreet2());
stmt.setString(11, deviceEvent.getCity());
stmt.setString(12, deviceEvent.getZip());
stmt.setString(13, deviceEvent.getState());
stmt.setString(14, deviceEvent.getCountry());
stmt.setDouble(15, deviceEvent.getAltitude());
stmt.setFloat(16, deviceEvent.getSpeed());
stmt.setFloat(17, deviceEvent.getBearing());
stmt.setFloat(18, deviceEvent.getDistance());
if (stmt.executeUpdate() > 0) {
ResultSet generatedKeys = stmt.getGeneratedKeys();
if (generatedKeys.next()) {
genId = generatedKeys.getInt(1);
}
}
return genId;
}
} catch (SQLException e) {
String msg = "Error occurred while creating Geofence event for the fence id " + deviceEvent.getFenceId() + " from device id: " + deviceEvent.getDeviceId();
log.error(msg, e);
throw new DeviceManagementDAOException(msg, e);
}
}
}

@ -22,10 +22,21 @@ import java.util.List;
public class ConfigOperation extends Operation {
private final List<Property> properties;
public ConfigOperation() {
properties = new ArrayList<>();
setControl(Control.REPEAT);
}
public List<Property> getConfigProperties() {
return properties;
}
public void addConfigProperty(String name, Object value, Class<?> type) {
properties.add(new Property(name, value, type));
}
public Type getType() {
return Type.CONFIG;
}

@ -20,7 +20,6 @@ package io.entgra.device.mgt.core.device.mgt.core.geo.service;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import io.entgra.device.mgt.core.device.mgt.common.geo.service.*;
import org.apache.axis2.AxisFault;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.Stub;
@ -44,6 +43,13 @@ import io.entgra.device.mgt.core.device.mgt.common.event.config.EventConfig;
import io.entgra.device.mgt.core.device.mgt.common.event.config.EventConfigurationException;
import io.entgra.device.mgt.core.device.mgt.common.event.config.EventConfigurationProviderService;
import io.entgra.device.mgt.core.device.mgt.common.exceptions.TransactionManagementException;
import io.entgra.device.mgt.core.device.mgt.common.geo.service.Alert;
import io.entgra.device.mgt.core.device.mgt.common.geo.service.AlertAlreadyExistException;
import io.entgra.device.mgt.core.device.mgt.common.geo.service.GeoFence;
import io.entgra.device.mgt.core.device.mgt.common.geo.service.GeoFenceEventMeta;
import io.entgra.device.mgt.core.device.mgt.common.geo.service.GeoLocationBasedServiceException;
import io.entgra.device.mgt.core.device.mgt.common.geo.service.GeoLocationProviderService;
import io.entgra.device.mgt.core.device.mgt.common.geo.service.GeofenceData;
import io.entgra.device.mgt.core.device.mgt.core.cache.impl.GeoCacheManagerImpl;
import io.entgra.device.mgt.core.device.mgt.core.dao.DeviceManagementDAOException;
import io.entgra.device.mgt.core.device.mgt.core.dao.DeviceManagementDAOFactory;
@ -1767,37 +1773,6 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic
}
}
@Override
public boolean saveGeoFenceCrossingDevice(GeoEventDeviceUpdate geofenceData) throws GeoLocationBasedServiceException {
int tenantId;
try {
tenantId = DeviceManagementDAOUtil.getTenantId();
} catch (DeviceManagementDAOException e) {
String msg = "Error occurred while retrieving tenant id while get geofence data";
log.error(msg, e);
throw new GeoLocationBasedServiceException(msg, e);
}
try {
EventManagementDAOFactory.beginTransaction();
geofenceDAO.addGeoFenceCrossingDevice(tenantId, geofenceData);
EventManagementDAOFactory.commitTransaction();
} catch (TransactionManagementException e) {
String msg = "Failed to begin transaction for saving geofence";
log.error(msg, e);
throw new GeoLocationBasedServiceException(msg, e);
} catch (DeviceManagementDAOException e) {
EventManagementDAOFactory.rollbackTransaction();
String msg = "Error occurred while saving geofence";
log.error(msg, e);
throw new GeoLocationBasedServiceException(msg, e);
} finally {
EventManagementDAOFactory.closeConnection();
}
return false;
}
/**
* Delete events of geofence
*

@ -222,7 +222,7 @@ public class OperationManagerImpl implements OperationManager {
if (operationDto.getControl()
== io.entgra.device.mgt.core.device.mgt.core.dto.operation.mgt.Operation.Control.NO_REPEAT) {
Map<Integer, Integer> pendingOperationIDs = operationDAO
.getExistingNotExecutedOperationIDs(enrolments.keySet().toArray(new Integer[0]), operationCode);
.getExistingOperationIDs(enrolments.keySet().toArray(new Integer[0]), operationCode);
for (Integer enrolmentId : pendingOperationIDs.keySet()) {
operation.setId(pendingOperationIDs.get(enrolmentId));
device = enrolments.get(enrolmentId);
@ -294,7 +294,7 @@ public class OperationManagerImpl implements OperationManager {
if (operationDto.getControl() ==
io.entgra.device.mgt.core.device.mgt.core.dto.operation.mgt.Operation.Control.NO_REPEAT) {
Map<Integer, Integer> pendingOperationIDs = operationDAO
.getExistingNotExecutedOperationIDs(enrolments.keySet().toArray(new Integer[0]), operationCode);
.getExistingOperationIDs(enrolments.keySet().toArray(new Integer[0]), operationCode);
Device device;
for (Integer enrolmentId : pendingOperationIDs.keySet()) {
operation.setId(pendingOperationIDs.get(enrolmentId));
@ -368,7 +368,7 @@ public class OperationManagerImpl implements OperationManager {
if (operationDto.getControl() ==
io.entgra.device.mgt.core.device.mgt.core.dto.operation.mgt.Operation.Control.NO_REPEAT) {
Map<Integer, Integer> pendingOperationIDs = operationDAO
.getExistingNotExecutedOperationIDs(enrolments.keySet().toArray(new Integer[0]), operationCode);
.getExistingOperationIDs(enrolments.keySet().toArray(new Integer[0]), operationCode);
Device device;
for (Integer enrolmentId : pendingOperationIDs.keySet()) {
operation.setId(pendingOperationIDs.get(enrolmentId));
@ -841,23 +841,23 @@ public class OperationManagerImpl implements OperationManager {
}
if (dtoOperation != null) {
// if (io.entgra.device.mgt.core.device.mgt.core.dto.operation.mgt.Operation.Type.COMMAND.equals(dtoOperation.getType()
// )) {
// io.entgra.device.mgt.core.device.mgt.core.dto.operation.mgt.CommandOperation commandOperation;
// commandOperation =
// (io.entgra.device.mgt.core.device.mgt.core.dto.operation.mgt.CommandOperation) commandOperationDAO.
// getOperation(dtoOperation.getId());
// dtoOperation.setEnabled(commandOperation.isEnabled());
// } else if (io.entgra.device.mgt.core.device.mgt.core.dto.operation.mgt.Operation.Type.CONFIG.equals(dtoOperation.
// getType())) {
// dtoOperation = configOperationDAO.getOperation(dtoOperation.getId());
// } else if (io.entgra.device.mgt.core.device.mgt.core.dto.operation.mgt.Operation.Type.PROFILE.equals(dtoOperation.
// getType())) {
// dtoOperation = profileOperationDAO.getOperation(dtoOperation.getId());
// } else if (io.entgra.device.mgt.core.device.mgt.core.dto.operation.mgt.Operation.Type.POLICY.equals(dtoOperation.
// getType())) {
// dtoOperation = policyOperationDAO.getOperation(dtoOperation.getId());
// }
if (io.entgra.device.mgt.core.device.mgt.core.dto.operation.mgt.Operation.Type.COMMAND.equals(dtoOperation.getType()
)) {
io.entgra.device.mgt.core.device.mgt.core.dto.operation.mgt.CommandOperation commandOperation;
commandOperation =
(io.entgra.device.mgt.core.device.mgt.core.dto.operation.mgt.CommandOperation) commandOperationDAO.
getOperation(dtoOperation.getId());
dtoOperation.setEnabled(commandOperation.isEnabled());
} else if (io.entgra.device.mgt.core.device.mgt.core.dto.operation.mgt.Operation.Type.CONFIG.equals(dtoOperation.
getType())) {
dtoOperation = configOperationDAO.getOperation(dtoOperation.getId());
} else if (io.entgra.device.mgt.core.device.mgt.core.dto.operation.mgt.Operation.Type.PROFILE.equals(dtoOperation.
getType())) {
dtoOperation = profileOperationDAO.getOperation(dtoOperation.getId());
} else if (io.entgra.device.mgt.core.device.mgt.core.dto.operation.mgt.Operation.Type.POLICY.equals(dtoOperation.
getType())) {
dtoOperation = policyOperationDAO.getOperation(dtoOperation.getId());
}
operation = OperationDAOUtil.convertOperation(dtoOperation);
}
} catch (OperationManagementDAOException e) {
@ -1050,29 +1050,29 @@ public class OperationManagerImpl implements OperationManager {
io.entgra.device.mgt.core.device.mgt.core.dto.operation.mgt.Operation deviceSpecificOperation = operationDAO.
getOperationByDeviceAndId(enrolmentInfo.getId(),
operationId);
// io.entgra.device.mgt.core.device.mgt.core.dto.operation.mgt.Operation dtoOperation = deviceSpecificOperation;
// if (deviceSpecificOperation.getType().
// equals(io.entgra.device.mgt.core.device.mgt.core.dto.operation.mgt.Operation.Type.COMMAND)) {
// io.entgra.device.mgt.core.device.mgt.core.dto.operation.mgt.CommandOperation commandOperation;
// commandOperation =
// (io.entgra.device.mgt.core.device.mgt.core.dto.operation.mgt.CommandOperation) commandOperationDAO.
// getOperation(deviceSpecificOperation.getId());
// dtoOperation.setEnabled(commandOperation.isEnabled());
// } else if (deviceSpecificOperation.getType().
// equals(io.entgra.device.mgt.core.device.mgt.core.dto.operation.mgt.Operation.Type.CONFIG)) {
// dtoOperation = configOperationDAO.getOperation(deviceSpecificOperation.getId());
// } else if (deviceSpecificOperation.getType().equals(
// io.entgra.device.mgt.core.device.mgt.core.dto.operation.mgt.Operation.Type.PROFILE)) {
// dtoOperation = profileOperationDAO.getOperation(deviceSpecificOperation.getId());
// } else if (deviceSpecificOperation.getType().equals(
// io.entgra.device.mgt.core.device.mgt.core.dto.operation.mgt.Operation.Type.POLICY)) {
// dtoOperation = policyOperationDAO.getOperation(deviceSpecificOperation.getId());
// }
// if (dtoOperation == null) {
// throw new OperationManagementException("Operation not found for operation Id:" + operationId +
// " device id:" + deviceId.getId());
// }
// dtoOperation.setStatus(deviceSpecificOperation.getStatus());
io.entgra.device.mgt.core.device.mgt.core.dto.operation.mgt.Operation dtoOperation = deviceSpecificOperation;
if (deviceSpecificOperation.getType().
equals(io.entgra.device.mgt.core.device.mgt.core.dto.operation.mgt.Operation.Type.COMMAND)) {
io.entgra.device.mgt.core.device.mgt.core.dto.operation.mgt.CommandOperation commandOperation;
commandOperation =
(io.entgra.device.mgt.core.device.mgt.core.dto.operation.mgt.CommandOperation) commandOperationDAO.
getOperation(deviceSpecificOperation.getId());
dtoOperation.setEnabled(commandOperation.isEnabled());
} else if (deviceSpecificOperation.getType().
equals(io.entgra.device.mgt.core.device.mgt.core.dto.operation.mgt.Operation.Type.CONFIG)) {
dtoOperation = configOperationDAO.getOperation(deviceSpecificOperation.getId());
} else if (deviceSpecificOperation.getType().equals(
io.entgra.device.mgt.core.device.mgt.core.dto.operation.mgt.Operation.Type.PROFILE)) {
dtoOperation = profileOperationDAO.getOperation(deviceSpecificOperation.getId());
} else if (deviceSpecificOperation.getType().equals(
io.entgra.device.mgt.core.device.mgt.core.dto.operation.mgt.Operation.Type.POLICY)) {
dtoOperation = policyOperationDAO.getOperation(deviceSpecificOperation.getId());
}
if (dtoOperation == null) {
throw new OperationManagementException("Operation not found for operation Id:" + operationId +
" device id:" + deviceId.getId());
}
dtoOperation.setStatus(deviceSpecificOperation.getStatus());
operation = OperationDAOUtil.convertOperation(deviceSpecificOperation);
} catch (OperationManagementDAOException e) {
throw new OperationManagementException("Error occurred while retrieving the list of " +
@ -1155,23 +1155,23 @@ public class OperationManagerImpl implements OperationManager {
throw new OperationManagementException("Operation not found for given Id:" + operationId);
}
// if (dtoOperation.getType()
// .equals(io.entgra.device.mgt.core.device.mgt.core.dto.operation.mgt.Operation.Type.COMMAND)) {
// io.entgra.device.mgt.core.device.mgt.core.dto.operation.mgt.CommandOperation commandOperation;
// commandOperation =
// (io.entgra.device.mgt.core.device.mgt.core.dto.operation.mgt.CommandOperation) commandOperationDAO.
// getOperation(dtoOperation.getId());
// dtoOperation.setEnabled(commandOperation.isEnabled());
// } else if (dtoOperation.getType().
// equals(io.entgra.device.mgt.core.device.mgt.core.dto.operation.mgt.Operation.Type.CONFIG)) {
// dtoOperation = configOperationDAO.getOperation(dtoOperation.getId());
// } else if (dtoOperation.getType().equals(io.entgra.device.mgt.core.device.mgt.core.dto.operation.mgt.Operation.Type.
// PROFILE)) {
// dtoOperation = profileOperationDAO.getOperation(dtoOperation.getId());
// } else if (dtoOperation.getType().equals(io.entgra.device.mgt.core.device.mgt.core.dto.operation.mgt.Operation.Type.
// POLICY)) {
// dtoOperation = policyOperationDAO.getOperation(dtoOperation.getId());
// }
if (dtoOperation.getType()
.equals(io.entgra.device.mgt.core.device.mgt.core.dto.operation.mgt.Operation.Type.COMMAND)) {
io.entgra.device.mgt.core.device.mgt.core.dto.operation.mgt.CommandOperation commandOperation;
commandOperation =
(io.entgra.device.mgt.core.device.mgt.core.dto.operation.mgt.CommandOperation) commandOperationDAO.
getOperation(dtoOperation.getId());
dtoOperation.setEnabled(commandOperation.isEnabled());
} else if (dtoOperation.getType().
equals(io.entgra.device.mgt.core.device.mgt.core.dto.operation.mgt.Operation.Type.CONFIG)) {
dtoOperation = configOperationDAO.getOperation(dtoOperation.getId());
} else if (dtoOperation.getType().equals(io.entgra.device.mgt.core.device.mgt.core.dto.operation.mgt.Operation.Type.
PROFILE)) {
dtoOperation = profileOperationDAO.getOperation(dtoOperation.getId());
} else if (dtoOperation.getType().equals(io.entgra.device.mgt.core.device.mgt.core.dto.operation.mgt.Operation.Type.
POLICY)) {
dtoOperation = policyOperationDAO.getOperation(dtoOperation.getId());
}
operation = OperationDAOUtil.convertOperation(dtoOperation);
} catch (OperationManagementDAOException e) {
throw new OperationManagementException("Error occurred while retrieving the operation with operation Id '" +

@ -62,7 +62,7 @@ public interface OperationDAO {
void updateEnrollmentOperationsStatus(int enrolmentId, String operationCode, Operation.Status existingStatus,
Operation.Status newStatus) throws OperationManagementDAOException;
Map<Integer, Integer> getExistingNotExecutedOperationIDs(Integer[] enrolmentIds, String operationCode)
Map<Integer, Integer> getExistingOperationIDs(Integer[] enrolmentIds, String operationCode)
throws OperationManagementDAOException;
OperationResponseMeta addOperationResponse(int enrolmentId, io.entgra.device.mgt.core.device.mgt.common.operation.mgt.Operation operation, String deviceId)

@ -59,7 +59,6 @@ import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
@ -76,16 +75,15 @@ public class GenericOperationDAOImpl implements OperationDAO {
try {
Connection connection = OperationManagementDAOFactory.getConnection();
String sql = "INSERT INTO DM_OPERATION(TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE, " +
"INITIATED_BY, OPERATION_DETAILS, OPERATION_PROPERTIES, TENANT_ID) VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
"INITIATED_BY, OPERATION_DETAILS, TENANT_ID) VALUES (?, ?, ?, ?, ?, ?, ?)";
stmt = connection.prepareStatement(sql, new String[]{"id"});
stmt.setString(1, operation.getType().toString());
stmt.setLong(2, DeviceManagementDAOUtil.getCurrentUTCTime());
stmt.setLong(3, 0);
stmt.setString(4, operation.getCode());
stmt.setString(5, operation.getInitiatedBy());
stmt.setObject(6, operation.getPayLoad());
stmt.setObject(7, operation.getProperties());
stmt.setInt(8, PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId());
stmt.setObject(6, operation);
stmt.setInt(7, PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId());
stmt.executeUpdate();
rs = stmt.getGeneratedKeys();
@ -166,7 +164,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
}
@Override
public Map<Integer, Integer> getExistingNotExecutedOperationIDs(Integer[] enrolmentIds, String operationCode)
public Map<Integer, Integer> getExistingOperationIDs(Integer[] enrolmentIds, String operationCode)
throws OperationManagementDAOException {
PreparedStatement stmt = null;
ResultSet rs = null;
@ -578,7 +576,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
+ "dor.ID AS OP_RES_ID, de.DEVICE_ID, d.DEVICE_IDENTIFICATION, d.DEVICE_TYPE_ID, "
+ "dt.NAME AS DEVICE_TYPE_NAME, eom.STATUS, eom.CREATED_TIMESTAMP, "
+ "eom.UPDATED_TIMESTAMP, op.OPERATION_CODE, op.TYPE AS OPERATION_TYPE, "
+ "dor.OPERATION_RESPONSE, op.INITIATED_BY, dor.RECEIVED_TIMESTAMP, dor.IS_LARGE_RESPONSE FROM "
+ "dor.OPERATION_RESPONSE, op.INITIATED_BY, dor.RECEIVED_TIMESTAMP, dor.IS_LARGE_RESPONSE FROM "
+ "DM_ENROLMENT_OP_MAPPING eom INNER JOIN DM_OPERATION op "
+ "ON op.ID=eom.OPERATION_ID INNER JOIN DM_ENROLMENT de "
+ "ON de.ID=eom.ENROLMENT_ID INNER JOIN DM_DEVICE d ON d.ID=de.DEVICE_ID "
@ -1191,14 +1189,24 @@ public class GenericOperationDAOImpl implements OperationDAO {
Operation operation = null;
try {
Connection conn = OperationManagementDAOFactory.getConnection();
String sql = "SELECT ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE, INITIATED_BY, " +
"OPERATION_DETAILS, OPERATION_PROPERTIES FROM DM_OPERATION WHERE id = ?";
String sql = "SELECT ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE, INITIATED_BY FROM " +
"DM_OPERATION WHERE id = ?";
stmt = conn.prepareStatement(sql);
stmt.setInt(1, id);
rs = stmt.executeQuery();
if (rs.next()) {
operation = OperationDAOUtil.getOperation(rs);
operation = new Operation();
operation.setId(rs.getInt("ID"));
operation.setType(Operation.Type.valueOf(rs.getString("TYPE")));
operation.setCreatedTimeStamp(new Timestamp(rs.getLong("CREATED_TIMESTAMP") * 1000L).toString());
if (rs.getLong("RECEIVED_TIMESTAMP") == 0) {
operation.setReceivedTimeStamp("");
} else {
operation.setReceivedTimeStamp(new Timestamp(rs.getLong("RECEIVED_TIMESTAMP") * 1000L).toString());
}
operation.setCode(rs.getString("OPERATION_CODE"));
operation.setInitiatedBy(rs.getString("INITIATED_BY"));
}
} catch (SQLException e) {
@ -1211,19 +1219,16 @@ public class GenericOperationDAOImpl implements OperationDAO {
}
@Override
public Operation getOperationByDeviceAndId(int enrolmentId, int operationId)
throws OperationManagementDAOException {
public Operation getOperationByDeviceAndId(int enrolmentId, int operationId) throws OperationManagementDAOException {
PreparedStatement stmt = null;
ResultSet rs = null;
Operation operation = null;
try {
Connection conn = OperationManagementDAOFactory.getConnection();
String sql = "SELECT o.ID, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, om.STATUS, " +
"o.OPERATION_CODE, o.INITIATED_BY, o.OPERATION_DETAILS, o.OPERATION_PROPERTIES, " +
"om.ID AS OM_MAPPING_ID, om.UPDATED_TIMESTAMP, om.STATUS FROM " +
"(SELECT ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP," +
"OPERATION_CODE, INITIATED_BY, OPERATION_DETAILS, OPERATION_PROPERTIES FROM DM_OPERATION " +
"WHERE id = ?) o INNER JOIN (SELECT * FROM " +
"o.OPERATION_CODE, o.INITIATED_BY, om.ID AS OM_MAPPING_ID, " +
"om.UPDATED_TIMESTAMP FROM (SELECT ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP," +
"OPERATION_CODE, INITIATED_BY FROM DM_OPERATION WHERE id = ?) o INNER JOIN (SELECT * FROM " +
"DM_ENROLMENT_OP_MAPPING dm where dm.OPERATION_ID = ? AND dm.ENROLMENT_ID = ?) om " +
"ON o.ID = om.OPERATION_ID ";
stmt = conn.prepareStatement(sql);
@ -1233,14 +1238,20 @@ public class GenericOperationDAOImpl implements OperationDAO {
rs = stmt.executeQuery();
if (rs.next()) {
operation = OperationDAOUtil.getOperation(rs);
operation = new Operation();
operation.setId(rs.getInt("ID"));
operation.setType(Operation.Type.valueOf(rs.getString("TYPE")));
operation.setCreatedTimeStamp(new Timestamp(rs.getLong("CREATED_TIMESTAMP") * 1000L).toString());
operation.setStatus(Operation.Status.valueOf(rs.getString("STATUS")));
if (rs.getLong("UPDATED_TIMESTAMP") == 0) {
operation.setReceivedTimeStamp("");
} else {
operation.setReceivedTimeStamp(
new Timestamp((rs.getLong("UPDATED_TIMESTAMP") * 1000)).toString());
}
operation.setStatus(Operation.Status.valueOf(rs.getString("STATUS")));
operation.setCode(rs.getString("OPERATION_CODE"));
operation.setInitiatedBy(rs.getString("INITIATED_BY"));
OperationDAOUtil.setActivityId(operation, rs.getInt("ID"));
}
} catch (SQLException e) {
throw new OperationManagementDAOException("SQL error occurred while retrieving the operation " +
@ -1261,8 +1272,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
try {
Connection conn = OperationManagementDAOFactory.getConnection();
String sql = "SELECT o.ID, TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, o.OPERATION_CODE, " +
"o.INITIATED_BY, o.OPERATION_DETAILS, o.OPERATION_PROPERTIES, om.ID AS OM_MAPPING_ID, " +
"om.UPDATED_TIMESTAMP FROM DM_OPERATION o " +
"o.INITIATED_BY, om.ID AS OM_MAPPING_ID, om.UPDATED_TIMESTAMP 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";
stmt = conn.prepareStatement(sql);
@ -1271,14 +1281,20 @@ public class GenericOperationDAOImpl implements OperationDAO {
rs = stmt.executeQuery();
while (rs.next()) {
operation = OperationDAOUtil.getOperation(rs);
operation.setStatus(status);
operation = new Operation();
operation.setId(rs.getInt("ID"));
operation.setType(Operation.Type.valueOf(rs.getString("TYPE")));
operation.setCreatedTimeStamp(new Timestamp(rs.getLong("CREATED_TIMESTAMP") * 1000L).toString());
if (rs.getLong("UPDATED_TIMESTAMP") == 0) {
operation.setReceivedTimeStamp("");
} else {
operation.setReceivedTimeStamp(
new Timestamp((rs.getLong("UPDATED_TIMESTAMP") * 1000)).toString());
}
operation.setCode(rs.getString("OPERATION_CODE"));
operation.setInitiatedBy(rs.getString("INITIATED_BY"));
operation.setStatus(status);
OperationDAOUtil.setActivityId(operation, rs.getInt("ID"));
operations.add(operation);
}
} catch (SQLException e) {
@ -1301,8 +1317,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
try {
Connection conn = OperationManagementDAOFactory.getConnection();
String sql = "SELECT o.ID, TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, o.OPERATION_CODE, " +
"o.INITIATED_BY, o.OPERATION_DETAILS, o.OPERATION_PROPERTIES, om.ID AS OM_MAPPING_ID, " +
"om.UPDATED_TIMESTAMP FROM DM_OPERATION o " +
"o.INITIATED_BY, om.ID AS OM_MAPPING_ID, om.UPDATED_TIMESTAMP 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 LIMIT ?,?";
@ -1314,15 +1329,20 @@ public class GenericOperationDAOImpl implements OperationDAO {
rs = stmt.executeQuery();
while (rs.next()) {
operation = OperationDAOUtil.getOperation(rs);
operation.setStatus(status);
operation = new Operation();
operation.setId(rs.getInt("ID"));
operation.setType(Operation.Type.valueOf(rs.getString("TYPE")));
operation.setCreatedTimeStamp(new Timestamp(rs.getLong("CREATED_TIMESTAMP") * 1000L).toString());
if (rs.getLong("UPDATED_TIMESTAMP") == 0) {
operation.setReceivedTimeStamp("");
} else {
operation.setReceivedTimeStamp(
new Timestamp((rs.getLong("UPDATED_TIMESTAMP") * 1000)).toString());
}
operation.setCode(rs.getString("OPERATION_CODE"));
operation.setInitiatedBy(rs.getString("INITIATED_BY"));
operation.setStatus(status);
OperationDAOUtil.setActivityId(operation, rs.getInt("OM_MAPPING_ID"));
operations.add(operation);
}
} catch (SQLException e) {
@ -1344,8 +1364,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
try {
Connection conn = OperationManagementDAOFactory.getConnection();
String sql = "SELECT o.ID, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, " +
"o.OPERATION_CODE, o.INITIATED_BY, o.OPERATION_DETAILS, o.OPERATION_PROPERTIES, om.STATUS, " +
"om.ID AS OM_MAPPING_ID, om.UPDATED_TIMESTAMP " +
"o.OPERATION_CODE, o.INITIATED_BY, om.STATUS, om.ID AS OM_MAPPING_ID, om.UPDATED_TIMESTAMP " +
"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, o.ID DESC";
@ -1354,13 +1373,18 @@ public class GenericOperationDAOImpl implements OperationDAO {
rs = stmt.executeQuery();
while (rs.next()) {
operation = OperationDAOUtil.getOperation(rs);
operation = new Operation();
operation.setId(rs.getInt("ID"));
operation.setType(Operation.Type.valueOf(rs.getString("TYPE")));
operation.setCreatedTimeStamp(new Timestamp(rs.getLong("CREATED_TIMESTAMP") * 1000L).toString());
if (rs.getLong("UPDATED_TIMESTAMP") == 0) {
operation.setReceivedTimeStamp("");
} else {
operation.setReceivedTimeStamp(
new Timestamp((rs.getLong("UPDATED_TIMESTAMP") * 1000)).toString());
}
operation.setCode(rs.getString("OPERATION_CODE"));
operation.setInitiatedBy(rs.getString("INITIATED_BY"));
operation.setStatus(Operation.Status.valueOf(rs.getString("STATUS")));
operations.add(operation);
}
@ -1404,7 +1428,6 @@ public class GenericOperationDAOImpl implements OperationDAO {
"o.OPERATION_CODE, " +
"o.INITIATED_BY, " +
"o.OPERATION_DETAILS, " +
"o.OPERATION_PROPERTIES, " +
"om.STATUS, " +
"om.ID AS OM_MAPPING_ID, " +
"om.UPDATED_TIMESTAMP " +
@ -1491,14 +1514,36 @@ public class GenericOperationDAOImpl implements OperationDAO {
stmt.setInt(paramIndex, request.getRowCount());
try (ResultSet rs = stmt.executeQuery()) {
while (rs.next()) {
operation = OperationDAOUtil.getOperation(rs);
operation = new Operation();
operation.setId(rs.getInt("ID"));
operation.setType(Operation.Type.valueOf(rs.getString("TYPE")));
operation.setCreatedTimeStamp(new Timestamp(rs.getLong("CREATED_TIMESTAMP") * 1000L).toString());
if (rs.getLong("UPDATED_TIMESTAMP") == 0) {
operation.setReceivedTimeStamp("");
} else {
operation.setReceivedTimeStamp(
new Timestamp((rs.getLong("UPDATED_TIMESTAMP") * 1000)).toString());
}
operation.setCode(rs.getString("OPERATION_CODE"));
operation.setInitiatedBy(rs.getString("INITIATED_BY"));
if (MDMAppConstants.AndroidConstants.UNMANAGED_APP_UNINSTALL.equals(operation.getCode())) {
byte[] operationDetails = rs.getBytes("OPERATION_DETAILS");
try (ByteArrayInputStream bais = new ByteArrayInputStream(operationDetails);
ObjectInputStream ois = new ObjectInputStream(bais)) {
profileOperation = (ProfileOperation) ois.readObject();
operation.setPayLoad(profileOperation.getPayLoad());
} catch (IOException e) {
String msg = "IO Error occurred while retrieving app data of operation ";
log.error(msg, e);
throw new OperationManagementDAOException(msg, e);
} catch (ClassNotFoundException e) {
String msg = "Class not found error occurred while retrieving app data of operation ";
log.error(msg, e);
throw new OperationManagementDAOException(msg, e);
}
}
operation.setStatus(Operation.Status.valueOf(rs.getString("STATUS")));
OperationDAOUtil.setActivityId(operation, rs.getInt("ID"));
operations.add(operation);
}
}
@ -1517,6 +1562,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
List<Operation> operations = new ArrayList<>();
String createdTo = null;
String createdFrom = null;
ProfileOperation profileOperation = null;
DateFormat simple = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
boolean isCreatedDayProvided = false;
boolean isUpdatedDayProvided = false; //updated day = received day
@ -1540,7 +1586,6 @@ public class GenericOperationDAOImpl implements OperationDAO {
"o.OPERATION_CODE, " +
"o.INITIATED_BY, " +
"o.OPERATION_DETAILS, " +
"o.OPERATION_PROPERTIES, " +
"om.STATUS, " +
"om.ID AS OM_MAPPING_ID, " +
"om.UPDATED_TIMESTAMP " +
@ -1627,14 +1672,36 @@ public class GenericOperationDAOImpl implements OperationDAO {
stmt.setInt(paramIndex, request.getRowCount());
try (ResultSet rs = stmt.executeQuery()) {
while (rs.next()) {
operation = OperationDAOUtil.getOperation(rs);
operation = new Operation();
operation.setId(rs.getInt("ID"));
operation.setType(Operation.Type.valueOf(rs.getString("TYPE")));
operation.setCreatedTimeStamp(new Timestamp(rs.getLong("CREATED_TIMESTAMP") * 1000L).toString());
if (rs.getLong("UPDATED_TIMESTAMP") == 0) {
operation.setReceivedTimeStamp("");
} else {
operation.setReceivedTimeStamp(
new Timestamp((rs.getLong("UPDATED_TIMESTAMP") * 1000)).toString());
}
operation.setCode(rs.getString("OPERATION_CODE"));
operation.setInitiatedBy(rs.getString("INITIATED_BY"));
if (MDMAppConstants.AndroidConstants.UNMANAGED_APP_UNINSTALL.equals(operation.getCode())) {
byte[] operationDetails = rs.getBytes("OPERATION_DETAILS");
try (ByteArrayInputStream bais = new ByteArrayInputStream(operationDetails);
ObjectInputStream ois = new ObjectInputStream(bais)) {
profileOperation = (ProfileOperation) ois.readObject();
operation.setPayLoad(profileOperation.getPayLoad());
} catch (IOException e) {
String msg = "IO Error occurred while retrieving app data of operation ";
log.error(msg, e);
throw new OperationManagementDAOException(msg, e);
} catch (ClassNotFoundException e) {
String msg = "Class not found error occurred while retrieving app data of operation ";
log.error(msg, e);
throw new OperationManagementDAOException(msg, e);
}
}
operation.setStatus(Operation.Status.valueOf(rs.getString("STATUS")));
OperationDAOUtil.setActivityId(operation, rs.getInt("ID"));
operations.add(operation);
}
}
@ -1865,8 +1932,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
try {
Connection connection = OperationManagementDAOFactory.getConnection();
stmt = connection.prepareStatement("SELECT o.ID, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, " +
"o.OPERATION_CODE, o.INITIATED_BY, o.OPERATION_DETAILS, o.OPERATION_PROPERTIES, " +
"om.ID AS OM_MAPPING_ID, om.UPDATED_TIMESTAMP FROM DM_OPERATION o " +
"o.OPERATION_CODE, o.INITIATED_BY, om.ID AS OM_MAPPING_ID, om.UPDATED_TIMESTAMP 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 om.UPDATED_TIMESTAMP ASC, om.ID ASC LIMIT 1");
@ -1876,14 +1942,21 @@ public class GenericOperationDAOImpl implements OperationDAO {
Operation operation = null;
if (rs.next()) {
operation = OperationDAOUtil.getOperation(rs);
operation = new Operation();
operation.setType(OperationDAOUtil.getType(rs.getString("TYPE")));
operation.setId(rs.getInt("ID"));
operation.setCreatedTimeStamp(new Timestamp(rs.getLong("CREATED_TIMESTAMP") * 1000L).toString());
if (rs.getLong("UPDATED_TIMESTAMP") == 0) {
operation.setReceivedTimeStamp("");
} else {
operation.setReceivedTimeStamp(
new Timestamp((rs.getLong("UPDATED_TIMESTAMP") * 1000)).toString());
}
operation.setCode(rs.getString("OPERATION_CODE"));
operation.setInitiatedBy(rs.getString("INITIATED_BY"));
operation.setStatus(Operation.Status.PENDING);
OperationDAOUtil.setActivityId(operation, rs.getInt("ID"));
}
return operation;
} catch (SQLException e) {
@ -1902,9 +1975,8 @@ public class GenericOperationDAOImpl implements OperationDAO {
List<Operation> operations = new ArrayList<>();
try {
Connection conn = OperationManagementDAOFactory.getConnection();
String sql = "SELECT o.ID, TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, OPERATION_CODE, " +
"o.INITIATED_BY, o.OPERATION_DETAILS, o.OPERATION_PROPERTIES, " +
"om.ID AS OM_MAPPING_ID, om.UPDATED_TIMESTAMP FROM " +
String sql = "SELECT o.ID, TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, OPERATION_CODE, o.INITIATED_BY," +
" om.ID AS OM_MAPPING_ID, om.UPDATED_TIMESTAMP FROM " +
"(SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE, INITIATED_BY " +
"FROM DM_OPERATION o WHERE o.TYPE = ?) 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";
@ -1916,14 +1988,19 @@ public class GenericOperationDAOImpl implements OperationDAO {
rs = stmt.executeQuery();
while (rs.next()) {
operation = OperationDAOUtil.getOperation(rs);
operation.setStatus(status);
operation = new Operation();
operation.setId(rs.getInt("ID"));
operation.setType(Operation.Type.valueOf(rs.getString("TYPE")));
operation.setCreatedTimeStamp(new Timestamp(rs.getLong("CREATED_TIMESTAMP") * 1000L).toString());
if (rs.getLong("UPDATED_TIMESTAMP") == 0) {
operation.setReceivedTimeStamp("");
} else {
operation.setReceivedTimeStamp(
new Timestamp((rs.getLong("UPDATED_TIMESTAMP") * 1000)).toString());
}
operation.setCode(rs.getString("OPERATION_CODE"));
operation.setInitiatedBy(rs.getString("INITIATED_BY"));
OperationDAOUtil.setActivityId(operation, rs.getInt("ID"));
operations.add(operation);
}
} catch (SQLException e) {
@ -1936,8 +2013,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
}
@Override
public Map<Integer, List<OperationMapping>> getOperationMappingsByStatus(Operation.Status opStatus,
Operation.PushNotificationStatus pushNotificationStatus,
public Map<Integer, List<OperationMapping>> getOperationMappingsByStatus(Operation.Status opStatus, Operation.PushNotificationStatus pushNotificationStatus,
int limit) throws OperationManagementDAOException {
PreparedStatement stmt = null;
ResultSet rs = null;
@ -1983,8 +2059,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
@Override
public Map<Integer, List<OperationMapping>> getAllocatedOperationMappingsByStatus(Operation.Status opStatus,
Operation.PushNotificationStatus pushNotificationStatus,
int limit, int activeServerCount, int serverIndex)
Operation.PushNotificationStatus pushNotificationStatus, int limit, int activeServerCount, int serverIndex)
throws OperationManagementDAOException {
PreparedStatement stmt = null;
ResultSet rs = null;
@ -2197,7 +2272,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
if (activityPaginationRequest.getDeviceType() != null ||
(activityPaginationRequest.getDeviceIds() != null && !activityPaginationRequest.getDeviceIds().isEmpty()) ||
activityPaginationRequest.getSince() != 0 ||
activityPaginationRequest.getStatuses() != null) {
activityPaginationRequest.getStatus() != null) {
sql.append("(SELECT DISTINCT OPERATION_ID FROM DM_ENROLMENT_OP_MAPPING eom WHERE TENANT_ID = ? ");
@ -2230,12 +2305,8 @@ public class GenericOperationDAOImpl implements OperationDAO {
if (activityPaginationRequest.getType() != null) {
sql.append("AND TYPE = ? ");
}
if (activityPaginationRequest.getStatuses() != null && !activityPaginationRequest.getStatuses().isEmpty()) {
sql.append("AND STATUS IN (");
for (int i = 0; i < activityPaginationRequest.getStatuses().size() - 1; i++) {
sql.append("?, ");
}
sql.append("?) ");
if (activityPaginationRequest.getStatus() != null) {
sql.append("AND STATUS = ? ");
}
sql.append("ORDER BY OPERATION_ID ASC limit ? , ? ) eom_ordered " +
@ -2289,12 +2360,8 @@ public class GenericOperationDAOImpl implements OperationDAO {
if (activityPaginationRequest.getType() != null) {
sql.append("AND eom.TYPE = ? ");
}
if (activityPaginationRequest.getStatuses() != null && !activityPaginationRequest.getStatuses().isEmpty()) {
sql.append("AND eom.STATUS IN (");
for (int i = 0; i < activityPaginationRequest.getStatuses().size() - 1; i++) {
sql.append("?, ");
}
sql.append("?) ");
if (activityPaginationRequest.getStatus() != null) {
sql.append("AND eom.STATUS = ? ");
}
sql.append("ORDER BY eom.OPERATION_ID, eom.UPDATED_TIMESTAMP");
@ -2305,7 +2372,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
if (activityPaginationRequest.getDeviceType() != null ||
(activityPaginationRequest.getDeviceIds() != null && !activityPaginationRequest.getDeviceIds().isEmpty()) ||
activityPaginationRequest.getSince() != 0 ||
activityPaginationRequest.getStatuses() != null) {
activityPaginationRequest.getStatus() != null) {
if (activityPaginationRequest.getDeviceType() != null) {
stmt.setString(index++, activityPaginationRequest.getDeviceType());
@ -2334,10 +2401,8 @@ public class GenericOperationDAOImpl implements OperationDAO {
if (activityPaginationRequest.getType() != null) {
stmt.setString(index++, activityPaginationRequest.getType().name());
}
if (activityPaginationRequest.getStatuses() != null && !activityPaginationRequest.getStatuses().isEmpty()) {
for (io.entgra.device.mgt.core.device.mgt.common.operation.mgt.Operation.Status status : activityPaginationRequest.getStatuses()) {
stmt.setString(index++, status.name());
}
if (activityPaginationRequest.getStatus() != null) {
stmt.setString(index++, activityPaginationRequest.getStatus().name());
}
stmt.setInt(index++, activityPaginationRequest.getOffset());
@ -2398,10 +2463,8 @@ public class GenericOperationDAOImpl implements OperationDAO {
if (activityPaginationRequest.getType() != null) {
stmt.setString(index++, activityPaginationRequest.getType().name());
}
if (activityPaginationRequest.getStatuses() != null && !activityPaginationRequest.getStatuses().isEmpty()) {
for (io.entgra.device.mgt.core.device.mgt.common.operation.mgt.Operation.Status status : activityPaginationRequest.getStatuses()) {
stmt.setString(index++, status.name());
}
if (activityPaginationRequest.getStatus() != null) {
stmt.setString(index, activityPaginationRequest.getStatus().name());
}
try (ResultSet rs = stmt.executeQuery()) {
@ -2433,7 +2496,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
if (activityPaginationRequest.getDeviceType() != null ||
(activityPaginationRequest.getDeviceIds() != null && !activityPaginationRequest.getDeviceIds().isEmpty()) ||
activityPaginationRequest.getSince() != 0 ||
activityPaginationRequest.getStatuses() != null) {
activityPaginationRequest.getStatus() != null) {
sql.append("SELECT count(DISTINCT OPERATION_ID) AS ACTIVITY_COUNT " +
"FROM DM_ENROLMENT_OP_MAPPING WHERE TENANT_ID = ? ");
@ -2463,12 +2526,8 @@ public class GenericOperationDAOImpl implements OperationDAO {
if (activityPaginationRequest.getType() != null) {
sql.append("AND TYPE = ? ");
}
if (activityPaginationRequest.getStatuses() != null && !activityPaginationRequest.getStatuses().isEmpty()) {
sql.append("AND STATUS IN (");
for (int i = 0; i < activityPaginationRequest.getStatuses().size() - 1; i++) {
sql.append("?, ");
}
sql.append("?) ");
if (activityPaginationRequest.getStatus() != null) {
sql.append("AND STATUS = ? ");
}
} else {
@ -2496,7 +2555,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
if (activityPaginationRequest.getDeviceType() != null ||
(activityPaginationRequest.getDeviceIds() != null && !activityPaginationRequest.getDeviceIds().isEmpty()) ||
activityPaginationRequest.getSince() != 0 ||
activityPaginationRequest.getStatuses() != null) {
activityPaginationRequest.getStatus() != null) {
if (activityPaginationRequest.getDeviceType() != null) {
stmt.setString(index++, activityPaginationRequest.getDeviceType());
}
@ -2520,10 +2579,8 @@ public class GenericOperationDAOImpl implements OperationDAO {
if (activityPaginationRequest.getType() != null) {
stmt.setString(index++, activityPaginationRequest.getType().name());
}
if (activityPaginationRequest.getStatuses() != null && !activityPaginationRequest.getStatuses().isEmpty()) {
for (io.entgra.device.mgt.core.device.mgt.common.operation.mgt.Operation.Status status : activityPaginationRequest.getStatuses()) {
stmt.setString(index++, status.name());
}
if (activityPaginationRequest.getStatus() != null) {
stmt.setString(index++, activityPaginationRequest.getStatus().name());
}
} else {
if (activityPaginationRequest.getOperationCode() != null) {
@ -2605,12 +2662,8 @@ public class GenericOperationDAOImpl implements OperationDAO {
if (activityPaginationRequest.getType() != null) {
sql.append("AND TYPE = ? ");
}
if (activityPaginationRequest.getStatuses() != null && !activityPaginationRequest.getStatuses().isEmpty()) {
sql.append("AND STATUS IN (");
for (int i = 0; i < activityPaginationRequest.getStatuses().size() - 1; i++) {
sql.append("?, ");
}
sql.append("?) ");
if (activityPaginationRequest.getStatus() != null) {
sql.append("AND STATUS = ? ");
}
sql.append("ORDER BY ID ASC limit ? , ? ) eom " +
@ -2647,10 +2700,8 @@ public class GenericOperationDAOImpl implements OperationDAO {
if (activityPaginationRequest.getType() != null) {
stmt.setString(index++, activityPaginationRequest.getType().name());
}
if (activityPaginationRequest.getStatuses() != null && !activityPaginationRequest.getStatuses().isEmpty()) {
for (io.entgra.device.mgt.core.device.mgt.common.operation.mgt.Operation.Status status : activityPaginationRequest.getStatuses()) {
stmt.setString(index++, status.name());
}
if (activityPaginationRequest.getStatus() != null) {
stmt.setString(index++, activityPaginationRequest.getStatus().name());
}
stmt.setInt(index++, activityPaginationRequest.getOffset());
@ -2693,6 +2744,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
StringBuilder sql = new StringBuilder();
sql.append("SELECT count(DISTINCT ID) AS ACTIVITY_COUNT " +
"FROM DM_ENROLMENT_OP_MAPPING WHERE TENANT_ID = ? ");
@ -2721,12 +2773,8 @@ public class GenericOperationDAOImpl implements OperationDAO {
if (activityPaginationRequest.getType() != null) {
sql.append("AND TYPE = ? ");
}
if (activityPaginationRequest.getStatuses() != null && !activityPaginationRequest.getStatuses().isEmpty()) {
sql.append("AND STATUS IN (");
for (int i = 0; i < activityPaginationRequest.getStatuses().size() - 1; i++) {
sql.append("?, ");
}
sql.append("?) ");
if (activityPaginationRequest.getStatus() != null) {
sql.append("AND STATUS = ? ");
}
if (activityPaginationRequest.getStartTimestamp() > 0 && activityPaginationRequest.getEndTimestamp() > 0) {
@ -2760,10 +2808,8 @@ public class GenericOperationDAOImpl implements OperationDAO {
if (activityPaginationRequest.getType() != null) {
stmt.setString(index++, activityPaginationRequest.getType().name());
}
if (activityPaginationRequest.getStatuses() != null && !activityPaginationRequest.getStatuses().isEmpty()) {
for (io.entgra.device.mgt.core.device.mgt.common.operation.mgt.Operation.Status status : activityPaginationRequest.getStatuses()) {
stmt.setString(index++, status.name());
}
if (activityPaginationRequest.getStatus() != null) {
stmt.setString(index++, activityPaginationRequest.getStatus().name());
}
if (isTimeDurationFilteringProvided) {

@ -44,7 +44,6 @@ import java.util.Date;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.TreeMap;
public class OperationDAOUtil {
@ -331,60 +330,4 @@ public class OperationDAOUtil {
deviceActivity.setUpdatedTimestamp(new Date(rs.getLong(("UPDATED_TIMESTAMP")) * 1000).toString());
return deviceActivity;
}
public static Operation getOperation(ResultSet rs) throws OperationManagementDAOException, SQLException {
Operation operation = new Operation();
operation.setId(rs.getInt("ID"));
operation.setType(Operation.Type.valueOf(rs.getString("TYPE")));
operation.setCreatedTimeStamp(new Timestamp(rs.getLong("CREATED_TIMESTAMP") * 1000L).toString());
if (rs.getLong("RECEIVED_TIMESTAMP") == 0) {
operation.setReceivedTimeStamp("");
} else {
operation.setReceivedTimeStamp(
new Timestamp((rs.getLong("RECEIVED_TIMESTAMP") * 1000)).toString());
}
operation.setCode(rs.getString("OPERATION_CODE"));
operation.setInitiatedBy(rs.getString("INITIATED_BY"));
byte[] operationDetails = rs.getBytes("OPERATION_DETAILS");
if (!rs.wasNull()) {
try (ByteArrayInputStream bais = new ByteArrayInputStream(operationDetails);
ObjectInputStream ois = new ObjectInputStream(bais)) {
operation.setPayLoad(ois.readObject());
} catch (IOException e) {
String msg = "IO Error occurred while retrieving operation details";
log.error(msg, e);
throw new OperationManagementDAOException(msg, e);
} catch (ClassNotFoundException e) {
String msg = "Class not found error occurred while retrieving operation details";
log.error(msg, e);
throw new OperationManagementDAOException(msg, e);
} catch (Exception e) {
String msg = "Error occurred while retrieving operation details";
log.error(msg, e);
throw new OperationManagementDAOException(msg, e);
}
}
byte[] operationProperties = rs.getBytes("OPERATION_PROPERTIES");
if (!rs.wasNull()) {
try (ByteArrayInputStream bais = new ByteArrayInputStream(operationProperties);
ObjectInputStream ois = new ObjectInputStream(bais)) {
operation.setProperties((Properties) ois.readObject());
} catch (IOException e) {
String msg = "IO Error occurred while retrieving operation properties";
log.error(msg, e);
throw new OperationManagementDAOException(msg, e);
} catch (ClassNotFoundException e) {
String msg = "Class not found error occurred while retrieving operation properties";
log.error(msg, e);
throw new OperationManagementDAOException(msg, e);
} catch (Exception e) {
String msg = "Error occurred while retrieving operation properties";
log.error(msg, e);
throw new OperationManagementDAOException(msg, e);
}
}
OperationDAOUtil.setActivityId(operation, rs.getInt("ID"));
return operation;
}
}

@ -86,13 +86,13 @@ public abstract class DynamicPartitionedScheduleTask implements Task {
if (localHashIndex.equals(String.valueOf(taskContext.getServerHashIndex()))) {
if (log.isDebugEnabled()) {
log.debug("Executing dynamically scheduled task (" + getTaskName() +
") for current server hash index: " + taskContext.getServerHashIndex());
") for current server hash index: " + localHashIndex);
}
executeDynamicTask();
} else {
if (log.isDebugEnabled()) {
log.debug("Ignoring execution of task (" + getTaskName() +
") not belonging to current server hash index: " + taskContext.getServerHashIndex());
") not belonging to current serer hash index: " + localHashIndex);
}
}
} else {

@ -68,7 +68,9 @@ public class MDMAndroidOperationUtil {
WebApplication webApplication = new WebApplication();
webApplication.setUrl(application.getLocation());
webApplication.setName(application.getName());
webApplication.setType(application.getType().toString());
// webApplication.setType(application.getType().toString());
// Hard-corded "type" to "webapp". Some agent versions accept only "webapp" as the type.
webApplication.setType("webapp");
webApplication.setProperties(application.getProperties());
operation.setPayLoad(webApplication.toJSON());
break;

@ -140,7 +140,6 @@ CREATE TABLE IF NOT EXISTS DM_OPERATION (
OPERATION_CODE VARCHAR(1000) NOT NULL,
INITIATED_BY VARCHAR(100) NULL,
OPERATION_DETAILS BLOB DEFAULT NULL,
OPERATION_PROPERTIES BLOB DEFAULT NULL,
ENABLED BOOLEAN NOT NULL DEFAULT FALSE,
TENANT_ID INTEGER NOT NULL,
PRIMARY KEY (ID)

@ -70,12 +70,46 @@ CREATE TABLE IF NOT EXISTS DM_OPERATION (
OPERATION_CODE VARCHAR(1000) NOT NULL,
INITIATED_BY VARCHAR(100) NULL,
OPERATION_DETAILS BLOB DEFAULT NULL,
OPERATION_PROPERTIES BLOB DEFAULT NULL,
ENABLED BOOLEAN NOT NULL DEFAULT FALSE,
TENANT_ID INTEGER NOT NULL,
PRIMARY KEY (ID)
);
CREATE TABLE IF NOT EXISTS DM_CONFIG_OPERATION (
OPERATION_ID INTEGER NOT NULL,
OPERATION_CONFIG BLOB DEFAULT NULL,
ENABLED BOOLEAN NOT NULL DEFAULT FALSE,
PRIMARY KEY (OPERATION_ID),
CONSTRAINT fk_dm_operation_config FOREIGN KEY (OPERATION_ID) REFERENCES
DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
);
CREATE TABLE IF NOT EXISTS DM_COMMAND_OPERATION (
OPERATION_ID INTEGER NOT NULL,
ENABLED BOOLEAN NOT NULL DEFAULT FALSE,
PRIMARY KEY (OPERATION_ID),
CONSTRAINT fk_dm_operation_command FOREIGN KEY (OPERATION_ID) REFERENCES
DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
);
CREATE TABLE IF NOT EXISTS DM_POLICY_OPERATION (
OPERATION_ID INTEGER NOT NULL,
ENABLED INTEGER NOT NULL DEFAULT 0,
OPERATION_DETAILS BLOB DEFAULT NULL,
PRIMARY KEY (OPERATION_ID),
CONSTRAINT fk_dm_operation_policy FOREIGN KEY (OPERATION_ID) REFERENCES
DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
);
CREATE TABLE IF NOT EXISTS DM_PROFILE_OPERATION (
OPERATION_ID INTEGER NOT NULL,
ENABLED INTEGER NOT NULL DEFAULT 0,
OPERATION_DETAILS BLOB DEFAULT NULL,
PRIMARY KEY (OPERATION_ID),
CONSTRAINT fk_dm_operation_profile FOREIGN KEY (OPERATION_ID) REFERENCES
DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
);
CREATE TABLE IF NOT EXISTS DM_ENROLMENT (
ID INTEGER AUTO_INCREMENT NOT NULL,
DEVICE_ID INTEGER NOT NULL,

@ -89,7 +89,6 @@ CREATE TABLE IF NOT EXISTS DM_OPERATION (
OPERATION_CODE VARCHAR(1000) NOT NULL,
INITIATED_BY VARCHAR(100) NULL,
OPERATION_DETAILS BLOB DEFAULT NULL,
OPERATION_PROPERTIES BLOB DEFAULT NULL,
ENABLED BOOLEAN NOT NULL DEFAULT FALSE,
TENANT_ID INTEGER NOT NULL,
PRIMARY KEY (ID)

@ -89,7 +89,6 @@ CREATE TABLE IF NOT EXISTS DM_OPERATION (
OPERATION_CODE VARCHAR(1000) NOT NULL,
INITIATED_BY VARCHAR(100) NULL,
OPERATION_DETAILS BLOB DEFAULT NULL,
OPERATION_PROPERTIES BLOB DEFAULT NULL,
ENABLED BOOLEAN NOT NULL DEFAULT FALSE,
TENANT_ID INTEGER NOT NULL,
PRIMARY KEY (ID)

@ -45,11 +45,8 @@ import java.util.Timer;
import java.util.TimerTask;
public class IoTSStartupHandler implements ServerStartupObserver {
private static final Log log = LogFactory.getLog(IoTSStartupHandler.class);
private static int lastHashIndex = -1;
@Override
public void completingServerStartup() {
}
@ -83,22 +80,6 @@ public class IoTSStartupHandler implements ServerStartupObserver {
Map<Integer, List<DynamicTask>> tenantedDynamicTasks = TaskWatcherDataHolder.getInstance()
.getTaskManagementService().getDynamicTasksForAllTenants();
int serverHashIdx;
try {
serverHashIdx = TaskWatcherDataHolder.getInstance().getHeartBeatService()
.getServerCtxInfo().getLocalServerHashIdx();
} catch (HeartBeatManagementException e) {
String msg = "Failed to get server hash index.";
log.error(msg, e);
throw new TaskManagementException(msg, e);
}
if (serverHashIdx != lastHashIndex) {
log.info("Server hash index changed. Old: " + lastHashIndex + ", new: " + serverHashIdx);
deleteAllDynamicNTasks(nTaskService, tenantedDynamicTasks, serverHashIdx);
lastHashIndex = serverHashIdx;
}
scheduleMissingTasks(nTaskService, tenantedDynamicTasks);
deleteObsoleteTasks(nTaskService, tenantedDynamicTasks);
@ -115,45 +96,7 @@ public class IoTSStartupHandler implements ServerStartupObserver {
}
private void deleteAllDynamicNTasks(TaskService nTaskService, Map<Integer,
List<DynamicTask>> tenantedDynamicTasks, int serverHashIdx) throws TaskException {
List<Tenant> tenants = getAllTenants();
TaskManager taskManager;
for (Tenant tenant : tenants) {
if (tenantedDynamicTasks.get(tenant.getId()) == null) {
if (log.isTraceEnabled()) {
log.trace("Dynamic tasks not running for tenant: [" + tenant.getId() + "] "
+ tenant.getDomain());
}
continue;
}
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenant.getId(), true);
if (!nTaskService.getRegisteredTaskTypes().contains(TaskMgtConstants.Task.DYNAMIC_TASK_TYPE)) {
nTaskService.registerTaskType(TaskMgtConstants.Task.DYNAMIC_TASK_TYPE);
}
taskManager = nTaskService.getTaskManager(TaskMgtConstants.Task.DYNAMIC_TASK_TYPE);
List<TaskInfo> tasks = taskManager.getAllTasks();
// Remove all applicable dynamic tasks from the nTask core
for (TaskInfo taskInfo : tasks) {
for (DynamicTask dt : tenantedDynamicTasks.get(tenant.getId())) {
if (tenant.getId() == dt.getTenantId()
&& taskInfo.getName()
.equals(TaskManagementUtil.generateNTaskName(dt.getDynamicTaskId(), serverHashIdx))) {
taskManager.deleteTask(taskInfo.getName());
if (log.isDebugEnabled()) {
log.debug("Task '" + taskInfo.getName() + "' deleted as server hash changed.");
}
}
}
}
PrivilegedCarbonContext.endTenantFlow();
}
}
private void scheduleMissingTasks(TaskService nTaskService, Map<Integer,
private static void scheduleMissingTasks(TaskService nTaskService, Map<Integer,
List<DynamicTask>> tenantedDynamicTasks)
throws TaskException, TaskManagementException {
@ -244,10 +187,26 @@ public class IoTSStartupHandler implements ServerStartupObserver {
}
}
private void deleteObsoleteTasks(TaskService nTaskService,
Map<Integer, List<DynamicTask>> tenantedDynamicTasks)
private static void deleteObsoleteTasks(TaskService nTaskService,
Map<Integer, List<DynamicTask>> tenantedDynamicTasks)
throws TaskManagementException, TaskException {
List<Tenant> tenants = new ArrayList<>();
try {
RealmService realmService = TaskWatcherDataHolder.getInstance().getRealmService();
Tenant[] tenantArray = realmService.getTenantManager().getAllTenants();
if (tenantArray != null && tenantArray.length != 0) {
tenants.addAll(Arrays.asList(tenantArray));
}
Tenant superTenant = new Tenant();
superTenant.setId(-1234);
tenants.add(superTenant);
} catch (UserStoreException e) {
String msg = "Unable to load tenants";
log.error(msg, e);
return;
}
TaskManager taskManager;
Set<Integer> hashIds;
try {
@ -258,8 +217,6 @@ public class IoTSStartupHandler implements ServerStartupObserver {
throw new TaskManagementException(msg, e);
}
List<Tenant> tenants = getAllTenants();
for (Tenant tenant : tenants) {
if (tenantedDynamicTasks.get(tenant.getId()) == null) {
if (log.isTraceEnabled()) {
@ -301,23 +258,4 @@ public class IoTSStartupHandler implements ServerStartupObserver {
}
}
private List<Tenant> getAllTenants() {
List<Tenant> tenants = new ArrayList<>();
try {
RealmService realmService = TaskWatcherDataHolder.getInstance().getRealmService();
Tenant[] tenantArray = realmService.getTenantManager().getAllTenants();
if (tenantArray != null && tenantArray.length != 0) {
tenants.addAll(Arrays.asList(tenantArray));
}
Tenant superTenant = new Tenant();
superTenant.setId(-1234);
tenants.add(superTenant);
return tenants;
} catch (UserStoreException e) {
String msg = "Unable to load tenants";
log.error(msg, e);
return new ArrayList<>();
}
}
}

@ -7,7 +7,6 @@ CREATE TABLE IF NOT EXISTS DM_OPERATION_ARCH (
OPERATION_CODE VARCHAR(50) NOT NULL,
INITIATED_BY VARCHAR(100) NULL,
OPERATION_DETAILS BLOB DEFAULT NULL,
OPERATION_PROPERTIES BLOB DEFAULT NULL,
ENABLED BOOLEAN NOT NULL DEFAULT FALSE,
ARCHIVED_AT TIMESTAMP DEFAULT NOW()
)ENGINE = InnoDB;

@ -6,7 +6,6 @@ CREATE TABLE IF NOT EXISTS DM_OPERATION_ARCH (
OPERATION_CODE VARCHAR(50) NOT NULL,
INITIATED_BY VARCHAR(100) NULL,
OPERATION_DETAILS BYTEA DEFAULT NULL,
OPERATION_PROPERTIES BYTEA DEFAULT NULL,
ENABLED BOOLEAN NOT NULL DEFAULT FALSE,
ARCHIVED_AT TIMESTAMP(0) DEFAULT NOW()
);

@ -91,7 +91,6 @@ CREATE TABLE IF NOT EXISTS DM_OPERATION (
OPERATION_CODE VARCHAR(1000) NOT NULL,
INITIATED_BY VARCHAR(100) NULL,
OPERATION_DETAILS BLOB DEFAULT NULL,
OPERATION_PROPERTIES BLOB DEFAULT NULL,
ENABLED BOOLEAN NOT NULL DEFAULT FALSE,
TENANT_ID INT NOT NULL,
PRIMARY KEY (ID)

@ -125,7 +125,6 @@ CREATE TABLE DM_OPERATION (
OPERATION_CODE VARCHAR(50) NOT NULL,
INITIATED_BY VARCHAR(100) NULL,
OPERATION_DETAILS VARBINARY(MAX) DEFAULT NULL,
OPERATION_PROPERTIES VARBINARY(MAX) DEFAULT NULL,
ENABLED BIT NOT NULL DEFAULT 0,
TENANT_ID INTEGER NOT NULL,
PRIMARY KEY (ID)

@ -106,7 +106,6 @@ CREATE TABLE IF NOT EXISTS DM_OPERATION (
OPERATION_CODE VARCHAR(50) NOT NULL,
INITIATED_BY VARCHAR(100) NULL,
OPERATION_DETAILS BLOB DEFAULT NULL,
OPERATION_PROPERTIES BLOB DEFAULT NULL,
ENABLED BOOLEAN NOT NULL DEFAULT FALSE,
TENANT_ID INT NOT NULL,
PRIMARY KEY (ID)

@ -181,7 +181,6 @@ CREATE TABLE DM_OPERATION (
INITIATED_BY VARCHAR2(100) NULL,
ENABLED NUMBER(10) DEFAULT 0 NOT NULL,
OPERATION_DETAILS BLOB DEFAULT NULL,
OPERATION_PROPERTIES BLOB DEFAULT NULL,
TENANT_ID INTEGER NOT NULL,
CONSTRAINT PK_DM_OPERATION PRIMARY KEY (ID)
)

@ -99,7 +99,6 @@ CREATE TABLE IF NOT EXISTS DM_OPERATION (
OPERATION_CODE VARCHAR(50) NOT NULL,
INITIATED_BY VARCHAR(100) NULL,
OPERATION_DETAILS BYTEA DEFAULT NULL,
OPERATION_PROPERTIES BYTEA DEFAULT NULL,
ENABLED BOOLEAN NOT NULL DEFAULT FALSE,
TENANT_ID INTEGER NOT NULL,
PRIMARY KEY (ID)

@ -157,7 +157,6 @@ CREATE TABLE NEW_DM_OPERATION (
OPERATION_CODE VARCHAR(50) NOT NULL,
INITIATED_BY VARCHAR(100) NULL,
OPERATION_DETAILS BLOB DEFAULT NULL,
OPERATION_PROPERTIES BLOB DEFAULT NULL,
ENABLED BOOLEAN NOT NULL DEFAULT FALSE,
PRIMARY KEY (ID)
);
@ -219,8 +218,8 @@ SELECT CONCAT(NOW(), ': Inserted ', ROW_COUNT(),' records to DM_ENROLMENT_OP_MAP
Insert data into NEW_DM_OPERATION from DM_OPERATION only with the OPERATION_IDs from DM_ENROLMENT_OP_MAPPING
*/
SELECT CONCAT(NOW(), ': Inserting data into DM_OPERATION FROM OLD_DM_OPERATION.') AS '';
INSERT INTO DM_OPERATION (ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE, INITIATED_BY, OPERATION_DETAILS, OPERATION_PROPERTIES, ENABLED)
SELECT ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE, INITIATED_BY, OPERATION_DETAILS, OPERATION_PROPERTIES, ENABLED
INSERT INTO DM_OPERATION (ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE, INITIATED_BY, OPERATION_DETAILS, ENABLED)
SELECT ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE, INITIATED_BY, OPERATION_DETAILS, ENABLED
FROM OLD_DM_OPERATION
WHERE ID IN(SELECT OPERATION_ID FROM DM_ENROLMENT_OP_MAPPING);
SELECT CONCAT(NOW(), ': Inserted ', ROW_COUNT(),' records to DM_OPERATION.') AS '';

Loading…
Cancel
Save