Fix SendDeviceNameChangedNotification

traccar-v5.0.15-sync
Arshana 2 years ago
parent 5e612ceaf2
commit 777940b896

@ -717,44 +717,17 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
persistedDevice.setName(device.getName());
System.out.println("This is rename device");
boolean responseOfmodifyEnrollment = deviceManagementProviderService.modifyEnrollment(persistedDevice);
boolean responseOfDeviceNameChanged = deviceManagementProviderService.SendDeviceNameChangedNotification(persistedDevice);
// boolean response = responseOfmodifyEnrollment || responseOfDeviceNameChanged;
// ProfileOperation operation = new ProfileOperation();
// operation.setCode("SEND_USERNAME");
// operation.setType(Operation.Type.PROFILE);
// operation.setPayLoad(device.getName());
//
// DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
// deviceIdentifier.setId(persistedDevice.getDeviceIdentifier());
// deviceIdentifier.setType(persistedDevice.getType());
//
// List<DeviceIdentifier> deviceIdentifiers = new ArrayList<>();
// deviceIdentifiers.add(deviceIdentifier);
//
//// Activity activity;
// Activity activity = deviceManagementProviderService.addOperation(persistedDevice.getType(), operation, deviceIdentifiers);
// ;
// boolean responseOfDeviceNameChanged = activity != null;
boolean response = responseOfmodifyEnrollment || responseOfDeviceNameChanged;
boolean responseOfDeviceNameChanged = deviceManagementProviderService.SendDeviceNameChangedNotification(
persistedDevice);
boolean response = responseOfmodifyEnrollment && responseOfDeviceNameChanged;
return Response.status(Response.Status.CREATED).entity(response).build();
// return Response.status(Response.Status.CREATED).entity(responseOfmodifyEnrollment).build();
} catch (DeviceManagementException e) {
log.error("Error encountered while updating device of type : " + deviceType + " and " +
"ID : " + deviceId);
return Response.status(Response.Status.BAD_REQUEST).entity(
new ErrorResponse.ErrorResponseBuilder().setMessage("Error while updating " +
"device of type " + deviceType + " and ID : " + deviceId).build()).build();
// } catch (OperationManagementException e) {
// throw new RuntimeException(e);
// } catch (InvalidDeviceException e) {
// throw new RuntimeException(e);
}
}

@ -24,4 +24,6 @@ public class Constants {
public static final String URI_SEPARATOR = "/";
public static final String BASIC_AUTH_HEADER_PREFIX = "Basic ";
public static final String BEARER = "Bearer ";
public static final String SEND_USERNAME = "SEND_USERNAME";
}

@ -120,6 +120,7 @@ import org.wso2.carbon.device.mgt.core.DeviceManagementConstants;
import org.wso2.carbon.device.mgt.core.DeviceManagementPluginRepository;
import org.wso2.carbon.device.mgt.core.cache.DeviceCacheKey;
import org.wso2.carbon.device.mgt.core.cache.impl.DeviceCacheManagerImpl;
import org.wso2.carbon.device.mgt.core.common.Constants;
import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager;
import org.wso2.carbon.device.mgt.core.config.DeviceManagementConfig;
import org.wso2.carbon.device.mgt.core.dao.ApplicationDAO;
@ -4867,7 +4868,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
try {
ProfileOperation operation = new ProfileOperation();
operation.setCode("SEND_USERNAME");
operation.setCode(Constants.SEND_USERNAME);
operation.setType(Operation.Type.PROFILE);
operation.setPayLoad(device.getName());
@ -4877,12 +4878,10 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
List<DeviceIdentifier> deviceIdentifiers = new ArrayList<>();
deviceIdentifiers.add(deviceIdentifier);
Activity activity;
activity = addOperation(device.getType(), operation, deviceIdentifiers);
return activity != null;
} catch (OperationManagementException e) {
String msg = "Error occurred while sending operation";
log.error(msg, e);
@ -4892,6 +4891,5 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
log.error(msg, e);
throw new DeviceManagementException(msg, e);
}
}
}

Loading…
Cancel
Save