diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/DeviceManagementServiceImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/DeviceManagementServiceImpl.java index 9dbe9c8707..8e8d619793 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/DeviceManagementServiceImpl.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/DeviceManagementServiceImpl.java @@ -120,14 +120,28 @@ import org.wso2.carbon.utils.multitenancy.MultitenantUtils; import javax.validation.Valid; import javax.validation.constraints.Size; -import javax.ws.rs.*; +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.DefaultValue; +import javax.ws.rs.GET; +import javax.ws.rs.HeaderParam; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.QueryParam; import javax.ws.rs.core.Response; import java.io.FileInputStream; import java.io.IOException; import java.security.GeneralSecurityException; import java.text.ParseException; import java.text.SimpleDateFormat; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Date; +import java.util.List; +import java.util.Properties; @Path("/devices") public class DeviceManagementServiceImpl implements DeviceManagementService { @@ -164,8 +178,20 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { private void saveResponseTimeToSpreadsheet(long startTime, long endTime, long responseTime, String message) throws IOException, GeneralSecurityException { this.message = message; + + // Load the configuration file + Properties config = new Properties(); + try (FileInputStream configFile = new FileInputStream("config.json")) { + config.load(configFile); + } catch (IOException e) { + e.printStackTrace(); + } + + // Get the file path from the configuration file + String filePath = config.getProperty("file.path"); + // Load credentials from JSON file - GoogleCredential credential = GoogleCredential.fromStream(new FileInputStream("/home/entgra/MyProject/device-mgt-core/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/test/resources/apicall-382608-48aa6a62800d.json")) + GoogleCredential credential = GoogleCredential.fromStream(new FileInputStream(filePath)) .createScoped(Collections.singleton(SheetsScopes.SPREADSHEETS)); // Build Google Sheets service diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/conf/config.json b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/conf/config.json index d17c6c8a4e..0c55d2908a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/conf/config.json +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/conf/config.json @@ -170,5 +170,8 @@ "backendRestEndpoints": { "deviceMgt": "/api/device-mgt/v1.0", "appMgt": "/api/application-mgt-store/v1.0" + }, + "Googlesheetcredentials": { + "file.path" : "/home/entgra/MyProject/device-mgt-core/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/test/resources/apicall-382608-48aa6a62800d.json" } }