Update getnextpendingoperation method with saving response time

APiTesting
Akeela Azhar 2 years ago
parent 35c92c3ed6
commit f90ec52ba8

@ -73,6 +73,27 @@ public class DeviceAgentServiceImpl implements DeviceAgentService {
static final Log log = LogFactory.getLog(DeviceAgentServiceImpl.class); static final Log log = LogFactory.getLog(DeviceAgentServiceImpl.class);
private static final String POLICY_MONITOR = "POLICY_MONITOR"; private static final String POLICY_MONITOR = "POLICY_MONITOR";
private static List<ComplianceFeature> getComplianceFeatures(Object compliancePayload) throws
PolicyComplianceException {
String compliancePayloadString = new Gson().toJson(compliancePayload);
if (compliancePayload == null) {
return null;
}
// Parsing json string to get compliance features.
JsonElement jsonElement = new JsonParser().parse(compliancePayloadString);
JsonArray jsonArray = jsonElement.getAsJsonArray();
Gson gson = new Gson();
ComplianceFeature complianceFeature;
List<ComplianceFeature> complianceFeatures = new ArrayList<>(jsonArray.size());
for (JsonElement element : jsonArray) {
complianceFeature = gson.fromJson(element, ComplianceFeature.class);
complianceFeatures.add(complianceFeature);
}
return complianceFeatures;
}
@POST @POST
@Path("/enroll") @Path("/enroll")
@Override @Override
@ -586,12 +607,20 @@ public class DeviceAgentServiceImpl implements DeviceAgentService {
deviceIdentifier); deviceIdentifier);
// Save the response time to Google Spreadsheet // Save the response time to Google Spreadsheet
long startTime = System.currentTimeMillis(); // Record the start time long startTime = System.currentTimeMillis(); // Record the start time
Sheets sheetsService = createSheetsService(); // Create Sheets service using loaded credentials
// Create Sheets service using loaded credentials
Sheets sheetsService = createSheetsService();
// Spreadsheet ID
String spreadsheetId = "1OZCS5NRwwSum9ai3ra4lABtU0UGW-9yLYgZk-aQfxpw"; String spreadsheetId = "1OZCS5NRwwSum9ai3ra4lABtU0UGW-9yLYgZk-aQfxpw";
// Calculate the response time
long endTime = System.currentTimeMillis(); // Record the end time
long responseTime = endTime - startTime; // Calculate the response time
// Create the values to be written // Create the values to be written
List<List<Object>> values = Collections.singletonList( List<List<Object>> values = Collections.singletonList(
Arrays.asList(deviceId, type, String.valueOf(System.currentTimeMillis() - startTime)) Arrays.asList(deviceId, type, String.valueOf(responseTime))
); );
// Create the value range // Create the value range
@ -602,7 +631,6 @@ public class DeviceAgentServiceImpl implements DeviceAgentService {
.append(spreadsheetId, "Sheet1", body) .append(spreadsheetId, "Sheet1", body)
.setValueInputOption("USER_ENTERED") .setValueInputOption("USER_ENTERED")
.execute(); .execute();
return Response.status(Response.Status.OK).entity(operation).build(); return Response.status(Response.Status.OK).entity(operation).build();
} catch (OperationManagementException e) { } catch (OperationManagementException e) {
String errorMessage = "Issue in retrieving operation management service instance"; String errorMessage = "Issue in retrieving operation management service instance";
@ -785,25 +813,4 @@ public class DeviceAgentServiceImpl implements DeviceAgentService {
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build();
} }
} }
private static List<ComplianceFeature> getComplianceFeatures(Object compliancePayload) throws
PolicyComplianceException {
String compliancePayloadString = new Gson().toJson(compliancePayload);
if (compliancePayload == null) {
return null;
}
// Parsing json string to get compliance features.
JsonElement jsonElement = new JsonParser().parse(compliancePayloadString);
JsonArray jsonArray = jsonElement.getAsJsonArray();
Gson gson = new Gson();
ComplianceFeature complianceFeature;
List<ComplianceFeature> complianceFeatures = new ArrayList<>(jsonArray.size());
for (JsonElement element : jsonArray) {
complianceFeature = gson.fromJson(element, ComplianceFeature.class);
complianceFeatures.add(complianceFeature);
}
return complianceFeatures;
}
} }

Loading…
Cancel
Save