Search in sources :

Example 16 with Device

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

the class DeviceTypeManager method updateDeviceInfo.

@Override
public boolean updateDeviceInfo(DeviceIdentifier deviceIdentifier, Device device) throws DeviceManagementException {
    boolean status;
    try {
        if (log.isDebugEnabled()) {
            log.debug("updating the details of sampledevice device : " + deviceIdentifier);
        }
        DeviceTypeDAO.beginTransaction();
        status = deviceTypeDAO.getDeviceTypeDAO().updateDevice(device);
        DeviceTypeDAO.commitTransaction();
    } catch (DeviceMgtPluginException e) {
        try {
            DeviceTypeDAO.rollbackTransaction();
        } catch (DeviceMgtPluginException iotDAOEx) {
            String msg = "Error occurred while roll back the update device info transaction :" + device.toString();
            log.warn(msg, iotDAOEx);
        }
        String msg = "Error while updating the sampledevice device : " + deviceIdentifier;
        log.error(msg, e);
        throw new DeviceManagementException(msg, e);
    }
    return status;
}
Also used : DeviceMgtPluginException(org.wso2.iot.sampledevice.plugin.exception.DeviceMgtPluginException) DeviceManagementException(org.wso2.carbon.device.mgt.common.DeviceManagementException)

Example 17 with Device

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

the class DeviceTypeManager method modifyEnrollment.

@Override
public boolean modifyEnrollment(Device device) throws DeviceManagementException {
    boolean status;
    try {
        if (log.isDebugEnabled()) {
            log.debug("Modifying the sampledevice device enrollment data");
        }
        DeviceTypeDAO.beginTransaction();
        status = deviceTypeDAO.getDeviceTypeDAO().updateDevice(device);
        DeviceTypeDAO.commitTransaction();
    } catch (DeviceMgtPluginException e) {
        try {
            DeviceTypeDAO.rollbackTransaction();
        } catch (DeviceMgtPluginException iotDAOEx) {
            String msg = "Error occurred while roll back the update device transaction :" + device.toString();
            log.warn(msg, iotDAOEx);
        }
        String msg = "Error while updating the enrollment of the sampledevice device : " + device.getDeviceIdentifier();
        log.error(msg, e);
        throw new DeviceManagementException(msg, e);
    }
    return status;
}
Also used : DeviceMgtPluginException(org.wso2.iot.sampledevice.plugin.exception.DeviceMgtPluginException) DeviceManagementException(org.wso2.carbon.device.mgt.common.DeviceManagementException)

Example 18 with Device

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

the class DeviceTypeUtils method setupDeviceManagementSchema.

public static void setupDeviceManagementSchema() throws DeviceMgtPluginException {
    try {
        Context ctx = new InitialContext();
        DataSource dataSource = (DataSource) ctx.lookup(DeviceTypeConstants.DATA_SOURCE_NAME);
        DeviceSchemaInitializer initializer = new DeviceSchemaInitializer(dataSource);
        log.info("Initializing device management repository database schema");
        initializer.createRegistryDatabase();
    } catch (NamingException e) {
        log.error("Error while looking up the data source: " + DeviceTypeConstants.DATA_SOURCE_NAME);
    } catch (Exception e) {
        throw new DeviceMgtPluginException("Error occurred while initializing Iot Device " + "Management database schema", e);
    }
}
Also used : InitialContext(javax.naming.InitialContext) Context(javax.naming.Context) DeviceMgtPluginException(org.wso2.iot.sampledevice.plugin.exception.DeviceMgtPluginException) NamingException(javax.naming.NamingException) InitialContext(javax.naming.InitialContext) NamingException(javax.naming.NamingException) DeviceMgtPluginException(org.wso2.iot.sampledevice.plugin.exception.DeviceMgtPluginException) SQLException(java.sql.SQLException) DataSource(javax.sql.DataSource)

Example 19 with Device

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

the class EnrollDevicePage method gotoConnectedCupDeviceTypeViewPage.

/**
 * Method to perform the navigation to Device type view page of the Connected cup.
 * @return : The corresponding Device type view page. Null, if the element is not visible.
 */
public ConnectedCupDeviceTypeViewPage gotoConnectedCupDeviceTypeViewPage() throws IOException {
    boolean check = UIUtils.isElementPresent(log, driver, By.xpath(uiElementMapper.getElement("iot.sample.connectedcup.xpath")));
    if (check) {
        WebElement deviceDiv = driver.findElement(By.xpath(uiElementMapper.getElement("iot.sample.connectedcup.xpath")));
        WebElement tryBtn = deviceDiv.findElement(By.tagName("button"));
        tryBtn.click();
        return new ConnectedCupDeviceTypeViewPage(driver);
    } else {
        log.error("Element not found!");
        return null;
    }
}
Also used : ConnectedCupDeviceTypeViewPage(org.wso2.iot.integration.ui.pages.samples.ConnectedCupDeviceTypeViewPage) WebElement(org.openqa.selenium.WebElement)

Example 20 with Device

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

the class MobileDeviceManagement method testGetUserDevices.

@Test(description = "Test getting devices")
public void testGetUserDevices() throws Exception {
    int expectedCount = this.userMode == TestUserMode.TENANT_ADMIN ? 3 : 13;
    HttpResponse response = client.get(Constants.MobileDeviceManagement.GET_ALL_DEVICES_ENDPOINT + Constants.MobileDeviceManagement.USER_DEVICE_ENDPOINT);
    Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode());
    JsonObject devices = new JsonParser().parse(response.getData()).getAsJsonObject();
    Assert.assertEquals("Expected device count is not received", expectedCount, devices.get("count").getAsInt());
}
Also used : HttpResponse(org.wso2.carbon.automation.test.utils.http.client.HttpResponse) JsonObject(com.google.gson.JsonObject) JsonParser(com.google.gson.JsonParser) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)20 HttpResponse (org.wso2.carbon.automation.test.utils.http.client.HttpResponse)17 DeviceManagementException (org.wso2.carbon.device.mgt.common.DeviceManagementException)13 DeviceMgtPluginException (org.wso2.iot.sampledevice.plugin.exception.DeviceMgtPluginException)11 JsonParser (com.google.gson.JsonParser)10 SQLException (java.sql.SQLException)8 JsonObject (com.google.gson.JsonObject)7 Connection (java.sql.Connection)7 PreparedStatement (java.sql.PreparedStatement)7 HashMap (java.util.HashMap)6 ConnectedCupDeviceMgtPluginException (org.coffeeking.connectedcup.plugin.exception.ConnectedCupDeviceMgtPluginException)6 Device (org.wso2.carbon.device.mgt.common.Device)6 JsonArray (com.google.gson.JsonArray)5 JsonElement (com.google.gson.JsonElement)4 ResultSet (java.sql.ResultSet)4 ArrayList (java.util.ArrayList)4 Path (javax.ws.rs.Path)4 JSONObject (org.json.simple.JSONObject)4 PrivilegedCarbonContext (org.wso2.carbon.context.PrivilegedCarbonContext)4 DeviceIdentifier (org.wso2.carbon.device.mgt.common.DeviceIdentifier)4