Search in sources :

Example 1 with EnrolmentInfo

use of org.wso2.carbon.device.mgt.common.EnrolmentInfo in project product-iots by wso2.

the class ConnectedCupServiceImpl method register.

@Path("device/register")
@POST
public boolean register(@QueryParam("name") String name) {
    try {
        DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
        String deviceId = shortUUID();
        deviceIdentifier.setId(deviceId);
        deviceIdentifier.setType(ConnectedCupConstants.DEVICE_TYPE);
        if (APIUtil.getDeviceManagementService().isEnrolled(deviceIdentifier)) {
            return false;
        }
        Device device = new Device();
        device.setDeviceIdentifier(deviceId);
        EnrolmentInfo enrolmentInfo = new EnrolmentInfo();
        enrolmentInfo.setDateOfEnrolment(new Date().getTime());
        enrolmentInfo.setDateOfLastUpdate(new Date().getTime());
        enrolmentInfo.setStatus(EnrolmentInfo.Status.ACTIVE);
        enrolmentInfo.setOwnership(EnrolmentInfo.OwnerShip.BYOD);
        device.setName(name);
        device.setType(ConnectedCupConstants.DEVICE_TYPE);
        enrolmentInfo.setOwner(APIUtil.getAuthenticatedUser());
        device.setEnrolmentInfo(enrolmentInfo);
        return APIUtil.getDeviceManagementService().enrollDevice(device);
    } catch (DeviceManagementException e) {
        log.error("Failed to enroll device with device name :" + name, e);
        return false;
    }
}
Also used : DeviceManagementException(org.wso2.carbon.device.mgt.common.DeviceManagementException) Device(org.wso2.carbon.device.mgt.common.Device) EnrolmentInfo(org.wso2.carbon.device.mgt.common.EnrolmentInfo) Date(java.util.Date) DeviceIdentifier(org.wso2.carbon.device.mgt.common.DeviceIdentifier) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Example 2 with EnrolmentInfo

use of org.wso2.carbon.device.mgt.common.EnrolmentInfo in project product-iots by wso2.

the class DeviceTypeServiceImpl method register.

/**
 * Register device into device management service.
 *
 * @param deviceId unique identifier for given device type instance
 * @param name     name for the device type instance
 * @return check whether device is installed into cdmf
 */
private boolean register(String deviceId, String name) {
    try {
        DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
        deviceIdentifier.setId(deviceId);
        deviceIdentifier.setType(DeviceTypeConstants.DEVICE_TYPE);
        if (APIUtil.getDeviceManagementService().isEnrolled(deviceIdentifier)) {
            return false;
        }
        Device device = new Device();
        device.setDeviceIdentifier(deviceId);
        EnrolmentInfo enrolmentInfo = new EnrolmentInfo();
        enrolmentInfo.setDateOfEnrolment(new Date().getTime());
        enrolmentInfo.setDateOfLastUpdate(new Date().getTime());
        enrolmentInfo.setStatus(EnrolmentInfo.Status.ACTIVE);
        enrolmentInfo.setOwnership(EnrolmentInfo.OwnerShip.BYOD);
        device.setName(name);
        device.setType(DeviceTypeConstants.DEVICE_TYPE);
        enrolmentInfo.setOwner(APIUtil.getAuthenticatedUser());
        device.setEnrolmentInfo(enrolmentInfo);
        boolean added = APIUtil.getDeviceManagementService().enrollDevice(device);
        return added;
    } catch (DeviceManagementException e) {
        log.error(e.getMessage(), e);
        return false;
    }
}
Also used : DeviceManagementException(org.wso2.carbon.device.mgt.common.DeviceManagementException) Device(org.wso2.carbon.device.mgt.common.Device) EnrolmentInfo(org.wso2.carbon.device.mgt.common.EnrolmentInfo) Date(java.util.Date) DeviceIdentifier(org.wso2.carbon.device.mgt.common.DeviceIdentifier)

Aggregations

Date (java.util.Date)2 Device (org.wso2.carbon.device.mgt.common.Device)2 DeviceIdentifier (org.wso2.carbon.device.mgt.common.DeviceIdentifier)2 DeviceManagementException (org.wso2.carbon.device.mgt.common.DeviceManagementException)2 EnrolmentInfo (org.wso2.carbon.device.mgt.common.EnrolmentInfo)2 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1