|
|
|
@ -73,6 +73,27 @@ public class DeviceAgentServiceImpl implements DeviceAgentService {
|
|
|
|
|
static final Log log = LogFactory.getLog(DeviceAgentServiceImpl.class);
|
|
|
|
|
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
|
|
|
|
|
@Path("/enroll")
|
|
|
|
|
@Override
|
|
|
|
@ -286,7 +307,7 @@ public class DeviceAgentServiceImpl implements DeviceAgentService {
|
|
|
|
|
id + "'";
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
|
|
|
}catch (IOException e) {
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
// Handle any errors occurred while writing to the spreadsheet
|
|
|
|
|
String errorMessage = "Error writing response time to Google Spreadsheet";
|
|
|
|
|
log.error(errorMessage, e);
|
|
|
|
@ -586,12 +607,20 @@ public class DeviceAgentServiceImpl implements DeviceAgentService {
|
|
|
|
|
deviceIdentifier);
|
|
|
|
|
// Save the response time to Google Spreadsheet
|
|
|
|
|
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";
|
|
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
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
|
|
|
|
@ -602,7 +631,6 @@ public class DeviceAgentServiceImpl implements DeviceAgentService {
|
|
|
|
|
.append(spreadsheetId, "Sheet1", body)
|
|
|
|
|
.setValueInputOption("USER_ENTERED")
|
|
|
|
|
.execute();
|
|
|
|
|
|
|
|
|
|
return Response.status(Response.Status.OK).entity(operation).build();
|
|
|
|
|
} catch (OperationManagementException e) {
|
|
|
|
|
String errorMessage = "Issue in retrieving operation management service instance";
|
|
|
|
@ -612,7 +640,7 @@ public class DeviceAgentServiceImpl implements DeviceAgentService {
|
|
|
|
|
String errorMessage = "Issue in retrieving deivce management service instance";
|
|
|
|
|
log.error(errorMessage, e);
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build();
|
|
|
|
|
}catch (IOException e) {
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
// Handle any errors occurred while writing to the spreadsheet
|
|
|
|
|
String errorMessage = "Error writing response time to Google Spreadsheet";
|
|
|
|
|
log.error(errorMessage, e);
|
|
|
|
@ -717,7 +745,7 @@ public class DeviceAgentServiceImpl implements DeviceAgentService {
|
|
|
|
|
String errorMessage = "Issue in retrieving device management service instance";
|
|
|
|
|
log.error(errorMessage, e);
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build();
|
|
|
|
|
}catch (IOException e) {
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
// Handle any errors occurred while writing to the spreadsheet
|
|
|
|
|
String errorMessage = "Error writing response time to Google Spreadsheet";
|
|
|
|
|
log.error(errorMessage, e);
|
|
|
|
@ -778,32 +806,11 @@ public class DeviceAgentServiceImpl implements DeviceAgentService {
|
|
|
|
|
String errorMessage = "Issue in retrieving device management service";
|
|
|
|
|
log.error(errorMessage, e);
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build();
|
|
|
|
|
}catch (IOException e) {
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
// Handle any errors occurred while writing to the spreadsheet
|
|
|
|
|
String errorMessage = "Error writing response time to Google Spreadsheet";
|
|
|
|
|
log.error(errorMessage, e);
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|