Update with loading credential file

syncAPITesting-2
Akeela Azhar 1 year ago
parent 991fe319d6
commit c2ee9ee71b

@ -37,32 +37,13 @@ import io.entgra.device.mgt.core.application.mgt.common.exception.SubscriptionMa
import io.entgra.device.mgt.core.application.mgt.common.services.ApplicationManager; import io.entgra.device.mgt.core.application.mgt.common.services.ApplicationManager;
import io.entgra.device.mgt.core.application.mgt.common.services.SubscriptionManager; import io.entgra.device.mgt.core.application.mgt.common.services.SubscriptionManager;
import io.entgra.device.mgt.core.application.mgt.core.util.HelperUtil; import io.entgra.device.mgt.core.application.mgt.core.util.HelperUtil;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.ApplicationList; import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.*;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.ApplicationUninstallation;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.ComplianceDeviceList;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.DeviceCompliance;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.DeviceConfig;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.DeviceList;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.ErrorResponse;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.OperationList;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.OperationRequest;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.OperationStatusBean;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.service.api.DeviceManagementService; import io.entgra.device.mgt.core.device.mgt.api.jaxrs.service.api.DeviceManagementService;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.service.impl.util.InputValidationException; import io.entgra.device.mgt.core.device.mgt.api.jaxrs.service.impl.util.InputValidationException;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.service.impl.util.RequestValidationUtil; import io.entgra.device.mgt.core.device.mgt.api.jaxrs.service.impl.util.RequestValidationUtil;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.util.Constants; import io.entgra.device.mgt.core.device.mgt.api.jaxrs.util.Constants;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.util.DeviceMgtAPIUtils; import io.entgra.device.mgt.core.device.mgt.api.jaxrs.util.DeviceMgtAPIUtils;
import io.entgra.device.mgt.core.device.mgt.common.Device; import io.entgra.device.mgt.core.device.mgt.common.*;
import io.entgra.device.mgt.core.device.mgt.common.DeviceFilters;
import io.entgra.device.mgt.core.device.mgt.common.DeviceIdentifier;
import io.entgra.device.mgt.core.device.mgt.common.DeviceManagementConstants;
import io.entgra.device.mgt.core.device.mgt.common.EnrolmentInfo;
import io.entgra.device.mgt.core.device.mgt.common.Feature;
import io.entgra.device.mgt.core.device.mgt.common.FeatureManager;
import io.entgra.device.mgt.core.device.mgt.common.MDMAppConstants;
import io.entgra.device.mgt.core.device.mgt.common.OperationLogFilters;
import io.entgra.device.mgt.core.device.mgt.common.PaginationRequest;
import io.entgra.device.mgt.core.device.mgt.common.PaginationResult;
import io.entgra.device.mgt.core.device.mgt.common.app.mgt.Application; import io.entgra.device.mgt.core.device.mgt.common.app.mgt.Application;
import io.entgra.device.mgt.core.device.mgt.common.app.mgt.ApplicationManagementException; import io.entgra.device.mgt.core.device.mgt.common.app.mgt.ApplicationManagementException;
import io.entgra.device.mgt.core.device.mgt.common.authorization.DeviceAccessAuthorizationException; import io.entgra.device.mgt.core.device.mgt.common.authorization.DeviceAccessAuthorizationException;
@ -72,11 +53,7 @@ import io.entgra.device.mgt.core.device.mgt.common.device.details.DeviceInfo;
import io.entgra.device.mgt.core.device.mgt.common.device.details.DeviceLocation; import io.entgra.device.mgt.core.device.mgt.common.device.details.DeviceLocation;
import io.entgra.device.mgt.core.device.mgt.common.device.details.DeviceLocationHistorySnapshotWrapper; import io.entgra.device.mgt.core.device.mgt.common.device.details.DeviceLocationHistorySnapshotWrapper;
import io.entgra.device.mgt.core.device.mgt.common.exceptions.BadRequestException; import io.entgra.device.mgt.core.device.mgt.common.exceptions.BadRequestException;
import io.entgra.device.mgt.core.device.mgt.common.exceptions.DeviceManagementException; import io.entgra.device.mgt.core.device.mgt.common.exceptions.*;
import io.entgra.device.mgt.core.device.mgt.common.exceptions.DeviceTypeNotFoundException;
import io.entgra.device.mgt.core.device.mgt.common.exceptions.InvalidConfigurationException;
import io.entgra.device.mgt.core.device.mgt.common.exceptions.InvalidDeviceException;
import io.entgra.device.mgt.core.device.mgt.common.exceptions.UnAuthorizedException;
import io.entgra.device.mgt.core.device.mgt.common.group.mgt.GroupManagementException; import io.entgra.device.mgt.core.device.mgt.common.group.mgt.GroupManagementException;
import io.entgra.device.mgt.core.device.mgt.common.operation.mgt.Activity; import io.entgra.device.mgt.core.device.mgt.common.operation.mgt.Activity;
import io.entgra.device.mgt.core.device.mgt.common.operation.mgt.Operation; import io.entgra.device.mgt.core.device.mgt.common.operation.mgt.Operation;
@ -120,28 +97,15 @@ import org.wso2.carbon.utils.multitenancy.MultitenantUtils;
import javax.validation.Valid; import javax.validation.Valid;
import javax.validation.constraints.Size; import javax.validation.constraints.Size;
import javax.ws.rs.Consumes; import javax.ws.rs.*;
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 javax.ws.rs.core.Response;
import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.security.GeneralSecurityException; import java.security.GeneralSecurityException;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.*;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Properties;
@Path("/devices") @Path("/devices")
public class DeviceManagementServiceImpl implements DeviceManagementService { public class DeviceManagementServiceImpl implements DeviceManagementService {
@ -150,6 +114,21 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
private static final Log log = LogFactory.getLog(DeviceManagementServiceImpl.class); private static final Log log = LogFactory.getLog(DeviceManagementServiceImpl.class);
private String message; private String message;
// public String getResource(String resource) {
// StringBuilder json = new StringBuilder();
// try {
// BufferedReader in = new BufferedReader(
// new InputStreamReader(Objects.requireNonNull(getClass().getClassLoader().getResourceAsStream(resource))));
//// String str;
//// while ((str = in.readLine()) != null)
//// json.append(str);
// in.close();
// } catch (IOException e) {
// throw new RuntimeException("Caught exception reading resource " + resource, e);
// }
// return json.toString();
// }
/** /**
* Validate group Id and group Id greater than 0 and exist. * Validate group Id and group Id greater than 0 and exist.
* *
@ -180,23 +159,13 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
this.message = message; this.message = message;
String file_path = System.getProperty("user.dir"); // String json_str = getResource("google-credentials.json");
file_path = file_path + "/repository/resources/conf/google/apicall-382608-48aa6a62800d.json";
System.out.println(file_path);
// Load the configuration file
Properties config = new Properties();
try (FileInputStream configFile = new FileInputStream(file_path)) {
config.load(configFile);
System.out.println(configFile);
} catch (IOException e) {
e.printStackTrace();
}
// Load credentials from JSON file // Load credentials from JSON file
GoogleCredential credential = GoogleCredential.fromStream(new FileInputStream(file_path)) // GoogleCredential credential = GoogleCredential.fromStream(new FileInputStream(file_path))
// .createScoped(Collections.singleton(SheetsScopes.SPREADSHEETS));
GoogleCredential credential = GoogleCredential.fromStream(Objects.requireNonNull(getClass().getClassLoader().getResourceAsStream("google-credentials.json")))
.createScoped(Collections.singleton(SheetsScopes.SPREADSHEETS)); .createScoped(Collections.singleton(SheetsScopes.SPREADSHEETS));
// Build Google Sheets service // Build Google Sheets service

Loading…
Cancel
Save