diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/util/APIResponseUtil.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/util/APIResponseUtil.java index a5d2a04b55..44fa853a21 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/util/APIResponseUtil.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/util/APIResponseUtil.java @@ -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; } } diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/config/DeviceManagementConfig.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/config/DeviceManagementConfig.java index 08c08df5ed..03954d4e71 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/config/DeviceManagementConfig.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/config/DeviceManagementConfig.java @@ -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; + } } diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/config/ui/APIResponseUtilConfiguration.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/config/ui/APIResponseUtilConfiguration.java index 527c5cc6d1..ebfd73673c 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/config/ui/APIResponseUtilConfiguration.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/config/ui/APIResponseUtilConfiguration.java @@ -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; + } } diff --git a/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/conf/mdm-ui-config.xml b/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/conf/mdm-ui-config.xml index df6ec7105a..029702c2ec 100644 --- a/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/conf/mdm-ui-config.xml +++ b/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/conf/mdm-ui-config.xml @@ -28,6 +28,7 @@ ApiCall 1OZCS5NRwwSum9ai3ra4lABtU0UGW-9yLYgZk-aQfxpw + true