|
|
|
@ -7,9 +7,8 @@ import com.google.api.services.sheets.v4.Sheets;
|
|
|
|
|
import com.google.api.services.sheets.v4.SheetsScopes;
|
|
|
|
|
import com.google.api.services.sheets.v4.model.ValueRange;
|
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.util.Constants;
|
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.core.config.DeviceConfigurationManager;
|
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.core.config.ui.APIResponseUtilConfiguration;
|
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.core.config.ui.UIConfiguration;
|
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.core.config.ui.UIConfigurationManager;
|
|
|
|
|
import org.apache.commons.logging.Log;
|
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
|
import org.wso2.carbon.utils.CarbonUtils;
|
|
|
|
@ -26,13 +25,12 @@ import java.util.List;
|
|
|
|
|
|
|
|
|
|
public class APIResponseUtil {
|
|
|
|
|
private static final Log log = LogFactory.getLog(APIResponseUtil.class);
|
|
|
|
|
|
|
|
|
|
private static boolean APIReportingStatus = true;
|
|
|
|
|
private static String RANGE = "Sheet1!A:D";
|
|
|
|
|
private static String VALUE_INPUT_METHOD = "USER_ENTERED";
|
|
|
|
|
private final static String RANGE = "Sheet1!A:D";
|
|
|
|
|
private final static String VALUE_INPUT_METHOD = "USER_ENTERED";
|
|
|
|
|
private static String APPLICATION_NAME;
|
|
|
|
|
private static String SPREADSHEET_ID;
|
|
|
|
|
|
|
|
|
|
private static boolean LOCK = false;
|
|
|
|
|
private static volatile APIResponseUtil INSTANCE;
|
|
|
|
|
|
|
|
|
|
APIResponseUtil() { }
|
|
|
|
@ -49,19 +47,22 @@ public class APIResponseUtil {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setAPIReportingStatus(boolean status) {
|
|
|
|
|
APIReportingStatus = status;
|
|
|
|
|
LOCK = !status;
|
|
|
|
|
log.info("API response reporting is set to " + status);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean getAPIReportingStatus() {
|
|
|
|
|
return APIReportingStatus;
|
|
|
|
|
return !(LOCK ||
|
|
|
|
|
!getAPIResponseUtilConfiguration().getAPIReportingStatus());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void saveResponseTimeToSpreadsheet(long startTime, long endTime, long responseTime, String message)
|
|
|
|
|
throws APIResponseUtilException {
|
|
|
|
|
|
|
|
|
|
if (APPLICATION_NAME == null || SPREADSHEET_ID == null) {
|
|
|
|
|
getAPIResponseUtilConfiguration();
|
|
|
|
|
if (LOCK || !getAPIResponseUtilConfiguration().getAPIReportingStatus()) {
|
|
|
|
|
String msg = "API response util isn't active";
|
|
|
|
|
log.warn(msg);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GoogleCredential credential = getGoogleCredentials();
|
|
|
|
@ -108,30 +109,13 @@ public class APIResponseUtil {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void getAPIResponseUtilConfiguration() throws APIResponseUtilException {
|
|
|
|
|
UIConfigurationManager uiConfigurationManager = UIConfigurationManager.getInstance();
|
|
|
|
|
if (uiConfigurationManager == null) {
|
|
|
|
|
String msg = "Error occurred while retrieving "+UIConfigurationManager.class.getName();
|
|
|
|
|
log.error(msg);
|
|
|
|
|
throw new APIResponseUtilException(msg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UIConfiguration uiConfiguration = uiConfigurationManager.getUIConfig();
|
|
|
|
|
if (uiConfiguration == null) {
|
|
|
|
|
String msg = "Error occurred while retrieving "+UIConfiguration.class.getName();
|
|
|
|
|
log.error(msg);
|
|
|
|
|
throw new APIResponseUtilException(msg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
APIResponseUtilConfiguration apiResponseUtilConfiguration = uiConfiguration.getApiResponseUtilConfiguration();
|
|
|
|
|
if (apiResponseUtilConfiguration == null) {
|
|
|
|
|
String msg = "Error occurred while retrieving "+APIResponseUtilConfiguration.class.getName();
|
|
|
|
|
log.error(msg);
|
|
|
|
|
throw new APIResponseUtilException(msg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private APIResponseUtilConfiguration getAPIResponseUtilConfiguration() {
|
|
|
|
|
APIResponseUtilConfiguration apiResponseUtilConfiguration = DeviceConfigurationManager.getInstance().
|
|
|
|
|
getDeviceManagementConfig().getAPIResponseUtilCOnfiguration();
|
|
|
|
|
APPLICATION_NAME = apiResponseUtilConfiguration.getApplicationName();
|
|
|
|
|
SPREADSHEET_ID = apiResponseUtilConfiguration.getSpreadSheetId();
|
|
|
|
|
APIReportingStatus = apiResponseUtilConfiguration.getAPIReportingStatus();
|
|
|
|
|
return apiResponseUtilConfiguration;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|