Update api response util

pull/140/head
Akeela Azhar 1 year ago
parent 157feec865
commit 46c945629a

@ -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;
}
}

@ -28,6 +28,7 @@ import io.entgra.device.mgt.core.device.mgt.core.config.cache.GeoFenceCacheConfi
import io.entgra.device.mgt.core.device.mgt.core.config.enrollment.guide.EnrollmentGuideConfiguration;
import io.entgra.device.mgt.core.device.mgt.core.config.operation.timeout.OperationTimeoutConfiguration;
import io.entgra.device.mgt.core.device.mgt.core.config.metadata.mgt.MetaDataConfiguration;
import io.entgra.device.mgt.core.device.mgt.core.config.ui.APIResponseUtilConfiguration;
import io.entgra.device.mgt.core.device.mgt.core.event.config.EventOperationTaskConfiguration;
import io.entgra.device.mgt.core.device.mgt.core.config.geo.location.GeoLocationConfiguration;
import io.entgra.device.mgt.core.device.mgt.core.config.identity.IdentityConfigurations;
@ -74,6 +75,7 @@ public final class DeviceManagementConfig {
private OperationTimeoutConfiguration operationTimeoutConfiguration;
private MetaDataConfiguration metaDataConfiguration;
private EnrollmentGuideConfiguration enrollmentGuideConfiguration;
private APIResponseUtilConfiguration apiResponseUtilConfiguration;
@XmlElement(name = "ManagementRepository", required = true)
public DeviceManagementConfigRepository getDeviceManagementConfigRepository() {
@ -287,5 +289,12 @@ public final class DeviceManagementConfig {
public void setEnrollmentGuideConfiguration(EnrollmentGuideConfiguration enrollmentGuideConfiguration) {
this.enrollmentGuideConfiguration = enrollmentGuideConfiguration;
}
@XmlElement(name = "APIResponseUtilConfiguration", required = true)
public APIResponseUtilConfiguration getAPIResponseUtilCOnfiguration() { return apiResponseUtilConfiguration; }
public void setApiResponseUtilConfiguration(APIResponseUtilConfiguration apiResponseUtilConfiguration) {
this.apiResponseUtilConfiguration = apiResponseUtilConfiguration;
}
}

@ -7,6 +7,8 @@ public class APIResponseUtilConfiguration {
private String spreadSheetId;
private boolean APIReportingStatus;;;
public String getApplicationName() {
return applicationName;
}
@ -24,4 +26,13 @@ public class APIResponseUtilConfiguration {
public void setSpreadSheetId(String spreadSheetId) {
this.spreadSheetId = spreadSheetId;
}
@XmlElement(name = "APIReportingStatus", required = true)
public boolean getAPIReportingStatus() {
return APIReportingStatus;
}
public void setAPIReportingStatus(boolean APIReportingStatus) {
this.APIReportingStatus = APIReportingStatus;
}
}

@ -28,6 +28,7 @@
<APIResponseUtilConfiguration>
<ApplicationName>ApiCall</ApplicationName>
<SpreadSheetId>1OZCS5NRwwSum9ai3ra4lABtU0UGW-9yLYgZk-aQfxpw</SpreadSheetId>
<APIResponseStatus>true</APIResponseStatus>
</APIResponseUtilConfiguration>
<!-- hubspot account info for live chat -->
<HubspotChat>

Loading…
Cancel
Save