From d5c709cfc00f44bf1ddffa3ab46875f4f4f27391 Mon Sep 17 00:00:00 2001 From: pramilaniroshan Date: Fri, 20 Jan 2023 10:32:40 +0530 Subject: [PATCH 01/30] Add Entgra Device Notification Logger --- .../extensions/logger/spi/EntgraLogger.java | 16 + .../io.entgra.notification.logger/pom.xml | 89 ++++++ .../notification/logger/DeviceLogContext.java | 103 ++++++ .../logger/impl/EntgraLoggerImpl.java | 294 ++++++++++++++++++ .../logger/util/MDCContextUtil.java | 41 +++ .../logger/impl/EntgraLoggerImplTest.java | 57 ++++ .../src/test/resources/log4j.properties | 32 ++ .../src/test/resources/testng.xml | 29 ++ components/logger/pom.xml | 46 +++ pom.xml | 1 + 10 files changed, 708 insertions(+) create mode 100644 components/logger/io.entgra.notification.logger/pom.xml create mode 100644 components/logger/io.entgra.notification.logger/src/main/java/io/entgra/notification/logger/DeviceLogContext.java create mode 100644 components/logger/io.entgra.notification.logger/src/main/java/io/entgra/notification/logger/impl/EntgraLoggerImpl.java create mode 100644 components/logger/io.entgra.notification.logger/src/main/java/io/entgra/notification/logger/util/MDCContextUtil.java create mode 100644 components/logger/io.entgra.notification.logger/src/test/java/io/entgra/logger/impl/EntgraLoggerImplTest.java create mode 100644 components/logger/io.entgra.notification.logger/src/test/resources/log4j.properties create mode 100644 components/logger/io.entgra.notification.logger/src/test/resources/testng.xml create mode 100644 components/logger/pom.xml diff --git a/components/device-mgt-extensions/io.entgra.device.mgt.extensions.logger/src/main/java/io/entgra/device/mgt/extensions/logger/spi/EntgraLogger.java b/components/device-mgt-extensions/io.entgra.device.mgt.extensions.logger/src/main/java/io/entgra/device/mgt/extensions/logger/spi/EntgraLogger.java index c959eb4885..2ffa6ffa8d 100644 --- a/components/device-mgt-extensions/io.entgra.device.mgt.extensions.logger/src/main/java/io/entgra/device/mgt/extensions/logger/spi/EntgraLogger.java +++ b/components/device-mgt-extensions/io.entgra.device.mgt.extensions.logger/src/main/java/io/entgra/device/mgt/extensions/logger/spi/EntgraLogger.java @@ -48,6 +48,22 @@ public interface EntgraLogger extends Log { void warn(Object object, Throwable t, LogContext logContext); + void info(String message, LogContext logContext); + + void debug(String message, LogContext logContext); + + void error(String message, LogContext logContext); + + void error(String message, Throwable t, LogContext logContext); + + void warn(String message, LogContext logContext); + + void warn(String message, Throwable t, LogContext logContext); + + void trace(String message, LogContext logContext); + + void fatal(String message, LogContext logContext); + void clearLogContext(); } diff --git a/components/logger/io.entgra.notification.logger/pom.xml b/components/logger/io.entgra.notification.logger/pom.xml new file mode 100644 index 0000000000..ced09b3157 --- /dev/null +++ b/components/logger/io.entgra.notification.logger/pom.xml @@ -0,0 +1,89 @@ + + + + + 4.0.0 + + + org.wso2.carbon.devicemgt + logger + 5.0.16-SNAPSHOT + + + io.entgra.notification.logger + bundle + + + + org.wso2.carbon.devicemgt + io.entgra.device.mgt.extensions.logger + + + org.wso2.carbon + org.wso2.carbon.logging + provided + + + org.testng + testng + + + 5.0.16-SNAPSHOT + + + 8 + 8 + UTF-8 + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + org.apache.felix + maven-bundle-plugin + true + + + ${project.artifactId} + ${project.artifactId} + ${carbon.device.mgt.version} + Device Notification Logger Bundle + + io.entgra.logger;version="[2.0,3)", + io.entgra.logger.spi;version="[2.0,3)", + org.apache.commons.logging;version="[1.2,2)", + org.apache.log4j;version="[1.2,2)", + org.wso2.carbon.context;version="[4.4,5) + + + io.entgra.logger.* + + + + + + + + \ No newline at end of file diff --git a/components/logger/io.entgra.notification.logger/src/main/java/io/entgra/notification/logger/DeviceLogContext.java b/components/logger/io.entgra.notification.logger/src/main/java/io/entgra/notification/logger/DeviceLogContext.java new file mode 100644 index 0000000000..3becd28b9c --- /dev/null +++ b/components/logger/io.entgra.notification.logger/src/main/java/io/entgra/notification/logger/DeviceLogContext.java @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2023, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved. + * + * Entgra (pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package io.entgra.notification.logger; + +import io.entgra.device.mgt.extensions.logger.LogContext; + +public class DeviceLogContext extends LogContext { + private final String deviceName; + private final String operationCode; + private final String deviceType; + private final String tenantID; + + private DeviceLogContext(Builder builder) { + this.operationCode = builder.operationCode; + this.deviceName = builder.deviceName; + this.deviceType = builder.deviceType; + this.tenantID = builder.tenantID; + } + + public String getTenantID() { + return tenantID; + } + + public String getDeviceName() { + return deviceName; + } + + public String getOperationCode() { + return operationCode; + } + + public String getDeviceType() { + return deviceType; + } + + + public static class Builder { + private String deviceName; + private String operationCode; + private String deviceType; + private String tenantID; + + public Builder() { + } + + public String getDeviceType() { + return deviceType; + } + + public Builder setDeviceType(String deviceType) { + this.deviceType = deviceType; + return this; + } + + public String getTenantID() { + return tenantID; + } + + public Builder setTenantID(String tenantID) { + this.tenantID = tenantID; + return this; + } + + public String getDeviceName() { + return deviceName; + } + + public Builder setDeviceName(String deviceName) { + this.deviceName = deviceName; + return this; + } + + public String getOperationCode() { + return operationCode; + } + + public Builder setOperationCode(String operationCode) { + this.operationCode = operationCode; + return this; + } + + public DeviceLogContext build() { + return new DeviceLogContext(this); + } + + } +} diff --git a/components/logger/io.entgra.notification.logger/src/main/java/io/entgra/notification/logger/impl/EntgraLoggerImpl.java b/components/logger/io.entgra.notification.logger/src/main/java/io/entgra/notification/logger/impl/EntgraLoggerImpl.java new file mode 100644 index 0000000000..882c82e473 --- /dev/null +++ b/components/logger/io.entgra.notification.logger/src/main/java/io/entgra/notification/logger/impl/EntgraLoggerImpl.java @@ -0,0 +1,294 @@ +/* + * Copyright (c) 2023, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved. + * + * Entgra (pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package io.entgra.notification.logger.impl; + + +import io.entgra.device.mgt.extensions.logger.LogContext; +import io.entgra.device.mgt.extensions.logger.spi.EntgraLogger; +import io.entgra.notification.logger.DeviceLogContext; +import io.entgra.notification.logger.util.MDCContextUtil; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.log4j.MDC; + + +public class EntgraLoggerImpl implements EntgraLogger { + + private static Log log = null; + + public EntgraLoggerImpl(Class clazz) { + log = LogFactory.getLog(clazz); + } + + @Override + public void info(Object object, LogContext logContext) { + } + + @Override + public void info(Object object, Throwable t, LogContext logContext) { + } + + @Override + public void debug(Object object, LogContext logContext) { + } + + @Override + public void debug(Object object, Throwable t, LogContext logContext) { + } + + @Override + public void error(Object object, LogContext logContext) { + } + + @Override + public void error(Object object, Throwable t, LogContext logContext) { + } + + @Override + public void fatal(Object object, LogContext logContext) { + } + + @Override + public void fatal(Object object, Throwable t, LogContext logContext) { + } + + @Override + public void trace(Object object, LogContext logContext) { + + } + + @Override + public void trace(Object object, Throwable t, LogContext logContext) { + + } + + @Override + public void warn(Object object, LogContext logContext) { + } + + @Override + public void warn(Object object, Throwable t, LogContext logContext) { + } + + public void info(String message) { + } + + public void info(String message, Throwable t) { + log.info(message, t); + } + + @Override + public void info(String message, LogContext logContext) { + DeviceLogContext deviceLogContext = (DeviceLogContext) logContext; + MDCContextUtil.populateDeviceMDCContext(deviceLogContext); + log.info(message); + } + + + public void debug(String message) { + log.debug(message); + } + + + public void debug(String message, Throwable t) { + log.debug(message, t); + } + + @Override + public void debug(String message, LogContext logContext) { + DeviceLogContext deviceLogContext = (DeviceLogContext) logContext; + MDCContextUtil.populateDeviceMDCContext(deviceLogContext); + log.debug(message); + } + + public void error(String message) { + log.error(message); + } + + + public void error(String message, Throwable t) { + log.error(message, t); + } + + @Override + public void error(String message, LogContext logContext) { + DeviceLogContext deviceLogContext = (DeviceLogContext) logContext; + MDCContextUtil.populateDeviceMDCContext(deviceLogContext); + log.error(message); + } + + @Override + public void error(String message, Throwable t, LogContext logContext) { + DeviceLogContext deviceLogContext = (DeviceLogContext) logContext; + MDCContextUtil.populateDeviceMDCContext(deviceLogContext); + log.error(message, t); + } + + + public void warn(String message) { + log.warn(message); + } + + + public void warn(String message, Throwable t) { + log.warn(message, t); + } + + @Override + public void warn(String message, LogContext logContext) { + DeviceLogContext deviceLogContext = (DeviceLogContext) logContext; + MDCContextUtil.populateDeviceMDCContext(deviceLogContext); + log.warn(message); + } + + @Override + public void warn(String message, Throwable t, LogContext logContext) { + DeviceLogContext deviceLogContext = (DeviceLogContext) logContext; + MDCContextUtil.populateDeviceMDCContext(deviceLogContext); + log.warn(message, t); + } + + + public void trace(String message) { + log.trace(message); + } + + + public void trace(String message, Throwable t) { + log.trace(message, t); + } + + @Override + public void trace(String message, LogContext logContext) { + DeviceLogContext deviceLogContext = (DeviceLogContext) logContext; + MDCContextUtil.populateDeviceMDCContext(deviceLogContext); + log.trace(message); + } + + + public void fatal(String message) { + log.fatal(message); + } + + + public void fatal(String message, Throwable t) { + log.fatal(message, t); + } + + @Override + public void fatal(String message, LogContext logContext) { + DeviceLogContext deviceLogContext = (DeviceLogContext) logContext; + MDCContextUtil.populateDeviceMDCContext(deviceLogContext); + log.fatal(message); + } + + @Override + public void debug(Object o) { + log.debug(o); + } + + @Override + public void debug(Object o, Throwable throwable) { + log.debug(o, throwable); + } + + @Override + public void error(Object o) { + log.error(o); + } + + @Override + public void error(Object o, Throwable throwable) { + log.error(o, throwable); + } + + @Override + public void fatal(Object o) { + log.fatal(0); + } + + @Override + public void fatal(Object o, Throwable throwable) { + log.fatal(0, throwable); + } + + @Override + public void info(Object o) { + log.info(o); + } + + @Override + public void info(Object o, Throwable throwable) { + log.info(o, throwable); + } + + @Override + public boolean isDebugEnabled() { + return log.isDebugEnabled(); + } + + @Override + public boolean isErrorEnabled() { + return log.isErrorEnabled(); + } + + @Override + public boolean isFatalEnabled() { + return log.isFatalEnabled(); + } + + @Override + public boolean isInfoEnabled() { + return log.isInfoEnabled(); + } + + @Override + public boolean isTraceEnabled() { + return log.isTraceEnabled(); + } + + @Override + public boolean isWarnEnabled() { + return log.isWarnEnabled(); + } + + @Override + public void trace(Object o) { + log.trace(o); + } + + @Override + public void trace(Object o, Throwable throwable) { + log.trace(o, throwable); + } + + @Override + public void warn(Object o) { + log.warn(o); + } + + @Override + public void warn(Object o, Throwable throwable) { + log.warn(o, throwable); + } + + @Override + public void clearLogContext() { + MDC.clear(); + } +} diff --git a/components/logger/io.entgra.notification.logger/src/main/java/io/entgra/notification/logger/util/MDCContextUtil.java b/components/logger/io.entgra.notification.logger/src/main/java/io/entgra/notification/logger/util/MDCContextUtil.java new file mode 100644 index 0000000000..dc7378b84c --- /dev/null +++ b/components/logger/io.entgra.notification.logger/src/main/java/io/entgra/notification/logger/util/MDCContextUtil.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2023, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved. + * + * Entgra (pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package io.entgra.notification.logger.util; + +import io.entgra.notification.logger.DeviceLogContext; +import org.apache.log4j.MDC; + +public final class MDCContextUtil { + + public static void populateDeviceMDCContext(final DeviceLogContext mdcContext) { + if (mdcContext.getDeviceName() != null) { + MDC.put("DeviceName", mdcContext.getDeviceName()); + } + if (mdcContext.getDeviceType() != null) { + MDC.put("DeviceType", mdcContext.getDeviceType()); + } + if (mdcContext.getOperationCode() != null) { + MDC.put("OperationCode", mdcContext.getOperationCode()); + } + if (mdcContext.getTenantID() != null) { + MDC.put("TenantId", mdcContext.getTenantID()); + } + } +} + + diff --git a/components/logger/io.entgra.notification.logger/src/test/java/io/entgra/logger/impl/EntgraLoggerImplTest.java b/components/logger/io.entgra.notification.logger/src/test/java/io/entgra/logger/impl/EntgraLoggerImplTest.java new file mode 100644 index 0000000000..204bc21fe3 --- /dev/null +++ b/components/logger/io.entgra.notification.logger/src/test/java/io/entgra/logger/impl/EntgraLoggerImplTest.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2023, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved. + * + * Entgra (pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package io.entgra.logger.impl; + +import io.entgra.device.mgt.extensions.logger.spi.EntgraLogger; +import io.entgra.notification.logger.DeviceLogContext; +import io.entgra.notification.logger.impl.EntgraLoggerImpl; +import org.testng.annotations.Test; + +public class EntgraLoggerImplTest { + + private final EntgraLogger log = new EntgraLoggerImpl(EntgraLoggerImplTest.class); + + @Test + public void logTest() { + + DeviceLogContext.Builder deviceLogContext = new DeviceLogContext.Builder(); + + deviceLogContext.setDeviceName("M02S"); + deviceLogContext.setDeviceType("Android"); + deviceLogContext.setOperationCode("1222"); + deviceLogContext.setTenantID("1234"); + + log.debug("Test debug message", deviceLogContext.build()); + log.info("Test info message", deviceLogContext.build()); + log.error("Test error message", deviceLogContext.build()); + log.warn("Test warn message", deviceLogContext.build()); + log.trace("Test trace message", deviceLogContext.build()); + log.fatal("Test fatal message", deviceLogContext.build()); + log.error("debug message test", new Throwable("error throw")); + log.info("info message test"); + +// log.isDebugEnabled(); +// log.isErrorEnabled(); +// log.isFatalEnabled(); +// log.isInfoEnabled(); +// log.isTraceEnabled(); +// log.isWarnEnabled(); + + } + +} diff --git a/components/logger/io.entgra.notification.logger/src/test/resources/log4j.properties b/components/logger/io.entgra.notification.logger/src/test/resources/log4j.properties new file mode 100644 index 0000000000..b174b35e36 --- /dev/null +++ b/components/logger/io.entgra.notification.logger/src/test/resources/log4j.properties @@ -0,0 +1,32 @@ +# +# Copyright 2023 Entgra Pvt. Ltd.. (http://entgra.io) +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# +# This is the log4j configuration file used by Entgra Pvt. Ltd. +# +# IMPORTANT : Please do not remove or change the names of any +# of the Appenders defined here. The layout pattern & log file +# can be changed using the WSO2 Carbon Management Console, and those +# settings will override the settings in this file. +# + +log4j.rootLogger=DEBUG, STD_OUT + +# Redirect log messages to console +log4j.appender.STD_OUT=org.apache.log4j.ConsoleAppender +log4j.appender.STD_OUT.Target=System.out +log4j.appender.STD_OUT.layout=org.apache.log4j.PatternLayout +log4j.appender.STD_OUT.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n diff --git a/components/logger/io.entgra.notification.logger/src/test/resources/testng.xml b/components/logger/io.entgra.notification.logger/src/test/resources/testng.xml new file mode 100644 index 0000000000..c64326b7ff --- /dev/null +++ b/components/logger/io.entgra.notification.logger/src/test/resources/testng.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + diff --git a/components/logger/pom.xml b/components/logger/pom.xml new file mode 100644 index 0000000000..b65b0e419d --- /dev/null +++ b/components/logger/pom.xml @@ -0,0 +1,46 @@ + + + + 4.0.0 + + + carbon-devicemgt + org.wso2.carbon.devicemgt + 5.0.16-SNAPSHOT + ../../pom.xml + + + logger + pom + Entgra IoT - Notification logger + http://entgra.io + + + io.entgra.notification.logger + + + + 8 + 8 + UTF-8 + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index aa41e4956d..7dbc9a9f6f 100644 --- a/pom.xml +++ b/pom.xml @@ -58,6 +58,7 @@ features/transport-mgt features/analytics-mgt features/webapp-authenticator-framework + components/logger From db624d26df35260b2588160e36d9568913cad9e3 Mon Sep 17 00:00:00 2001 From: pramilaniroshan Date: Mon, 6 Feb 2023 11:06:05 +0530 Subject: [PATCH 02/30] Add Entgra Device Notification Logger --- .../org.wso2.carbon.device.mgt.core/pom.xml | 8 +++++++- .../mgt/NotificationManagementServiceImpl.java | 9 +++++---- .../logger/io.entgra.notification.logger/pom.xml | 11 +++++------ components/logger/pom.xml | 2 +- pom.xml | 5 +++++ 5 files changed, 23 insertions(+), 12 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml index aa41e41e30..491d213d9a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml @@ -112,7 +112,9 @@ org.wso2.carbon.event.processor.stub, org.wso2.carbon.identity.jwt.client.extension.service, org.apache.commons.codec.binary, - io.entgra.server.bootup.heartbeat.beacon + io.entgra.server.bootup.heartbeat.beacon, + io.entgra.device.mgt.extensions.logger.*, + io.entgra.logger.*, !org.wso2.carbon.device.mgt.core.internal, @@ -347,6 +349,10 @@ okhttp compile + + org.wso2.carbon.devicemgt + io.entgra.notification.logger + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/NotificationManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/NotificationManagementServiceImpl.java index 3371f8d804..0e7867b0d1 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/NotificationManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/NotificationManagementServiceImpl.java @@ -18,8 +18,9 @@ package org.wso2.carbon.device.mgt.core.notification.mgt; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; +import io.entgra.device.mgt.extensions.logger.spi.EntgraLogger; +import io.entgra.notification.logger.DeviceLogContext; +import io.entgra.notification.logger.impl.EntgraLoggerImpl; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; @@ -45,8 +46,8 @@ import java.util.List; */ public class NotificationManagementServiceImpl implements NotificationManagementService { - private static final Log log = LogFactory.getLog(NotificationManagementServiceImpl.class); - + private static final EntgraLogger log = new EntgraLoggerImpl(NotificationManagementServiceImpl.class); + DeviceLogContext.Builder deviceLogContexBuilder = new DeviceLogContext.Builder(); private NotificationDAO notificationDAO; public NotificationManagementServiceImpl() { diff --git a/components/logger/io.entgra.notification.logger/pom.xml b/components/logger/io.entgra.notification.logger/pom.xml index ced09b3157..6b96ad58c2 100644 --- a/components/logger/io.entgra.notification.logger/pom.xml +++ b/components/logger/io.entgra.notification.logger/pom.xml @@ -25,17 +25,13 @@ org.wso2.carbon.devicemgt logger - 5.0.16-SNAPSHOT + 5.0.17-SNAPSHOT io.entgra.notification.logger bundle - - org.wso2.carbon.devicemgt - io.entgra.device.mgt.extensions.logger - org.wso2.carbon org.wso2.carbon.logging @@ -45,8 +41,11 @@ org.testng testng + + org.wso2.carbon.devicemgt + io.entgra.device.mgt.extensions.logger + - 5.0.16-SNAPSHOT 8 diff --git a/components/logger/pom.xml b/components/logger/pom.xml index b65b0e419d..4312ce069a 100644 --- a/components/logger/pom.xml +++ b/components/logger/pom.xml @@ -24,7 +24,7 @@ carbon-devicemgt org.wso2.carbon.devicemgt - 5.0.16-SNAPSHOT + 5.0.17-SNAPSHOT ../../pom.xml diff --git a/pom.xml b/pom.xml index b55d87112c..d8dcfcc2e0 100644 --- a/pom.xml +++ b/pom.xml @@ -349,6 +349,11 @@ org.wso2.carbon.apimgt.keymgt.extension.api ${carbon.device.mgt.version} + + org.wso2.carbon.devicemgt + io.entgra.notification.logger + ${carbon.device.mgt.version} + From 9401a4501b579c5e59ae0641eed0ca6e1fe975f5 Mon Sep 17 00:00:00 2001 From: pramilaniroshan Date: Mon, 6 Feb 2023 16:01:24 +0530 Subject: [PATCH 03/30] Add Entgra Device Notification Feature --- .../org.wso2.carbon.device.mgt.core/pom.xml | 2 +- .../io.entgra.notification.logger/pom.xml | 2 +- .../pom.xml | 113 ++++++++++++++++++ .../src/main/resources/build.properties | 20 ++++ .../src/main/resources/p2.inf | 1 + features/logger/pom.xml | 40 +++++++ pom.xml | 3 +- 7 files changed, 178 insertions(+), 3 deletions(-) create mode 100644 features/logger/io.entgra.notification.logger.feature/pom.xml create mode 100644 features/logger/io.entgra.notification.logger.feature/src/main/resources/build.properties create mode 100644 features/logger/io.entgra.notification.logger.feature/src/main/resources/p2.inf create mode 100644 features/logger/pom.xml diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml index 491d213d9a..4f1d4198c4 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml @@ -114,7 +114,7 @@ org.apache.commons.codec.binary, io.entgra.server.bootup.heartbeat.beacon, io.entgra.device.mgt.extensions.logger.*, - io.entgra.logger.*, + io.entgra.notification.logger.* !org.wso2.carbon.device.mgt.core.internal, diff --git a/components/logger/io.entgra.notification.logger/pom.xml b/components/logger/io.entgra.notification.logger/pom.xml index 6b96ad58c2..261de11b36 100644 --- a/components/logger/io.entgra.notification.logger/pom.xml +++ b/components/logger/io.entgra.notification.logger/pom.xml @@ -77,7 +77,7 @@ org.wso2.carbon.context;version="[4.4,5) - io.entgra.logger.* + io.entgra.notification.logger.* diff --git a/features/logger/io.entgra.notification.logger.feature/pom.xml b/features/logger/io.entgra.notification.logger.feature/pom.xml new file mode 100644 index 0000000000..4f55882374 --- /dev/null +++ b/features/logger/io.entgra.notification.logger.feature/pom.xml @@ -0,0 +1,113 @@ + + + + + + + + org.wso2.carbon.devicemgt + logger-feature + 5.0.17-SNAPSHOT + ../pom.xml + + + 4.0.0 + io.entgra.notification.logger.feature + pom + Entgra - Device Notification logger + http://entgra.io + + This feature bundles for the Entgra Notification logger + + + + + org.wso2.carbon + org.wso2.carbon.logging + provided + + + org.testng + testng + + + org.wso2.carbon.devicemgt + io.entgra.device.mgt.extensions.logger + + + + + + + maven-resources-plugin + 2.6 + + + copy-resources + generate-resources + + copy-resources + + + src/main/resources + + + resources + + build.properties + p2.inf + + + + + + + + + org.wso2.maven + carbon-p2-plugin + ${carbon.p2.plugin.version} + + + p2-feature-generation + package + + p2-feature-gen + + + io.entgra.notification.logger + ../../../features/etc/feature.properties + + + org.wso2.carbon.p2.category.type:server + org.eclipse.equinox.p2.type.group:true + + + + + org.wso2.carbon.devicemgt:io.entgra.notification.logger:${carbon.device.mgt.version} + + + + + + + + + diff --git a/features/logger/io.entgra.notification.logger.feature/src/main/resources/build.properties b/features/logger/io.entgra.notification.logger.feature/src/main/resources/build.properties new file mode 100644 index 0000000000..e98fb2729f --- /dev/null +++ b/features/logger/io.entgra.notification.logger.feature/src/main/resources/build.properties @@ -0,0 +1,20 @@ +# +# Copyright (C) 2018 - 2023 Entgra (Pvt) Ltd, Inc - All Rights Reserved. +# +# Unauthorised copying/redistribution of this file, via any medium is strictly prohibited. +# +# Licensed under the Entgra Commercial License, Version 1.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://entgra.io/licenses/entgra-commercial/1.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +custom = true diff --git a/features/logger/io.entgra.notification.logger.feature/src/main/resources/p2.inf b/features/logger/io.entgra.notification.logger.feature/src/main/resources/p2.inf new file mode 100644 index 0000000000..7ab37b9d7d --- /dev/null +++ b/features/logger/io.entgra.notification.logger.feature/src/main/resources/p2.inf @@ -0,0 +1 @@ +instructions.configure = \ \ No newline at end of file diff --git a/features/logger/pom.xml b/features/logger/pom.xml new file mode 100644 index 0000000000..0c6d141df3 --- /dev/null +++ b/features/logger/pom.xml @@ -0,0 +1,40 @@ + + + + + + + + org.wso2.carbon.devicemgt + carbon-devicemgt + 5.0.17-SNAPSHOT + ../../pom.xml + + + 4.0.0 + logger-feature + pom + Entgra - Logger Feature + http://entgra.io + + + io.entgra.notification.logger.feature + + + diff --git a/pom.xml b/pom.xml index d8dcfcc2e0..9e24936534 100644 --- a/pom.xml +++ b/pom.xml @@ -35,6 +35,7 @@ components/heartbeat-management + components/logger components/device-mgt components/device-mgt-extensions components/identity-extensions @@ -46,6 +47,7 @@ components/transport-mgt components/analytics-mgt components/webapp-authenticator-framework + features/logger features/device-mgt features/apimgt-extensions features/application-mgt @@ -58,7 +60,6 @@ features/transport-mgt features/analytics-mgt features/webapp-authenticator-framework - components/logger From 12b3b1a41dd0fb398c30a8e8882e7a2a376e8e83 Mon Sep 17 00:00:00 2001 From: pramilaniroshan Date: Tue, 7 Feb 2023 22:08:11 +0530 Subject: [PATCH 04/30] Add missing dependency --- components/logger/io.entgra.notification.logger/pom.xml | 1 - .../logger/io.entgra.notification.logger.feature/pom.xml | 5 ++++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/components/logger/io.entgra.notification.logger/pom.xml b/components/logger/io.entgra.notification.logger/pom.xml index 261de11b36..c363f724b5 100644 --- a/components/logger/io.entgra.notification.logger/pom.xml +++ b/components/logger/io.entgra.notification.logger/pom.xml @@ -35,7 +35,6 @@ org.wso2.carbon org.wso2.carbon.logging - provided org.testng diff --git a/features/logger/io.entgra.notification.logger.feature/pom.xml b/features/logger/io.entgra.notification.logger.feature/pom.xml index 4f55882374..6c600e7c12 100644 --- a/features/logger/io.entgra.notification.logger.feature/pom.xml +++ b/features/logger/io.entgra.notification.logger.feature/pom.xml @@ -40,7 +40,6 @@ org.wso2.carbon org.wso2.carbon.logging - provided org.testng @@ -50,6 +49,10 @@ org.wso2.carbon.devicemgt io.entgra.device.mgt.extensions.logger + + org.wso2.carbon.devicemgt + io.entgra.notification.logger + From 9c3020fc77b6dc80e828321ee5e0003f28a4e857 Mon Sep 17 00:00:00 2001 From: Thashmi-nil Date: Thu, 16 Feb 2023 13:37:19 +0530 Subject: [PATCH 05/30] Add improvements for chat feature --- .../core/metadata/mgt/MetadataManagementServiceImpl.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/metadata/mgt/MetadataManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/metadata/mgt/MetadataManagementServiceImpl.java index 7d7fd1d7c0..f82c5c3295 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/metadata/mgt/MetadataManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/metadata/mgt/MetadataManagementServiceImpl.java @@ -20,6 +20,7 @@ package org.wso2.carbon.device.mgt.core.metadata.mgt; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.base.MultitenantConstants; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.mgt.common.PaginationRequest; import org.wso2.carbon.device.mgt.common.PaginationResult; @@ -91,8 +92,12 @@ public class MetadataManagementServiceImpl implements MetadataManagementService } try { MetadataManagementDAOFactory.openConnection(); - return metadataDAO.getMetadata( - PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true), metaKey); + if (metaKey.equals("EVALUATE_TENANTS")){ + return metadataDAO.getMetadata(MultitenantConstants.SUPER_TENANT_ID, metaKey); + } else { + return metadataDAO.getMetadata( + PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true), metaKey); + } } catch (MetadataManagementDAOException e) { String msg = "Error occurred while retrieving the metadata entry for metaKey:" + metaKey; log.error(msg, e); From 66afe95fe9ecb0476cd916eb31c50c70c2b262d1 Mon Sep 17 00:00:00 2001 From: osh Date: Sun, 5 Mar 2023 14:49:34 +0530 Subject: [PATCH 06/30] Add api for self guide enrollment fixes https://roadmap.entgra.net/issues/9939 --- .../service/api/DeviceManagementService.java | 370 ++++++++++-------- .../impl/DeviceManagementServiceImpl.java | 41 ++ .../DeviceManagementProviderService.java | 4 + .../DeviceManagementProviderServiceImpl.java | 185 ++++++++- 4 files changed, 441 insertions(+), 159 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceManagementService.java index 3304be7c14..f4eb04cb42 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceManagementService.java @@ -54,6 +54,7 @@ import org.wso2.carbon.device.mgt.common.EnrolmentInfo; import org.wso2.carbon.device.mgt.common.Feature; import org.wso2.carbon.device.mgt.common.app.mgt.Application; import org.wso2.carbon.device.mgt.common.device.details.DeviceInfo; +import org.wso2.carbon.device.mgt.common.geo.service.Alert; import org.wso2.carbon.device.mgt.common.operation.mgt.Activity; import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; import org.wso2.carbon.device.mgt.common.policy.mgt.Policy; @@ -66,6 +67,7 @@ import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse; import org.wso2.carbon.device.mgt.jaxrs.beans.OperationRequest; import org.wso2.carbon.device.mgt.jaxrs.beans.OperationStatusBean; import org.wso2.carbon.device.mgt.jaxrs.util.Constants; +import org.springframework.web.multipart.MultipartFile; import javax.validation.Valid; import javax.validation.constraints.Size; @@ -553,12 +555,12 @@ public interface DeviceManagementService { required = false, defaultValue = "0") @QueryParam("offset") int offset, - @ApiParam( - name = "limit", - value = "Provide how many device details you require from the starting pagination index/offset.", - required = false, - defaultValue = "100") - @QueryParam("limit") int limit + @ApiParam( + name = "limit", + value = "Provide how many device details you require from the starting pagination index/offset.", + required = false, + defaultValue = "100") + @QueryParam("limit") int limit ); @GET @@ -802,6 +804,59 @@ public interface DeviceManagementService { @QueryParam("requireDeviceInfo") boolean requireDeviceInfo); + @POST + @Produces(MediaType.APPLICATION_JSON) + @Consumes(MediaType.MULTIPART_FORM_DATA) + @Path("/enrollment/guide") + @ApiOperation( + consumes = MediaType.MULTIPART_FORM_DATA, + produces = MediaType.APPLICATION_JSON, + httpMethod = "POST", + value = "Sending Enrollment Mode chosen by customer", + notes = "Enrollment mode selected and path is sent as parameters", + tags = "Device Management", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "perm:devices:view") + }) + } + ) + @ApiResponses( + value = { + @ApiResponse( + code = 200, + message = "OK. \n Successfully mailed the Enrollment Guide of customer.", + response = Device.class, + responseHeaders = { + @ResponseHeader( + name = "Content-Type", + description = "The content type of the body"), + @ResponseHeader( + name = "ETag", + description = "Entity Tag of the response resource.\n" + + "Used by caches, or in conditional requests."), + @ResponseHeader( + name = "Last-Modified", + description = "Date and time the resource was last modified.\n" + + "Used by caches, or in conditional requests."), + }), + @ApiResponse( + code = 400, + message = "Bad Request. \n Invalid request or validation error.", + response = ErrorResponse.class), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n " + + "Server error occurred while sending mail of the Enrollment Guide.", + response = ErrorResponse.class) + }) + Response sendEnrollmentGuide( + @ApiParam( + name = "enrolmentGuide", + value = "The details of the enrolment path suggested.", + required = true) + MultipartFile enrolmentGuide); + @POST @Produces(MediaType.APPLICATION_JSON) @Path("/type/any/list") @@ -1399,15 +1454,15 @@ public interface DeviceManagementService { @ResponseHeader( name = "ETag", description = "Entity Tag of the response resource.\n" + - "Used by caches, or in conditional requests."), + "Used by caches, or in conditional requests."), @ResponseHeader( name = "Last-Modified", description = "Date and time the resource was last modified. \n" + - "Used by caches, or in conditional requests.")}), + "Used by caches, or in conditional requests.")}), @ApiResponse( code = 304, message = "Not Modified. \n " + - "Empty body because the client already has the latest version of the requested resource.\n"), + "Empty body because the client already has the latest version of the requested resource.\n"), @ApiResponse( code = 400, message = "Bad Request. \n Invalid request or validation error.", @@ -1425,7 +1480,7 @@ public interface DeviceManagementService { @ApiResponse( code = 500, message = "Internal Server Error. \n " + - "Server error occurred while getting the device details.", + "Server error occurred while getting the device details.", response = ErrorResponse.class) }) Response queryDevicesByProperties( @@ -1447,7 +1502,7 @@ public interface DeviceManagementService { name = "device property map", value = "properties by which devices need filtered", required = true) - PropertyMap map); + PropertyMap map); @GET @Produces(MediaType.APPLICATION_JSON) @@ -1873,140 +1928,141 @@ public interface DeviceManagementService { @Size(max = 45) String id); - @GET - @Produces(MediaType.APPLICATION_JSON) - @Path("/{type}/{id}/getstatushistory") - @ApiOperation( - produces = MediaType.APPLICATION_JSON, - httpMethod = "GET", - value = "Get Device status history", - notes = "Get a list of status history associated with the device type and id", - tags = "Device Management", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "perm:devices:view") - }) - } - ) - @ApiResponses( - value = { - @ApiResponse( - code = 200, - message = "OK. \n Successfully fetched the status history of matching devices.", - response = List.class, - responseHeaders = { - @ResponseHeader( - name = "Content-Type", - description = "The content type of the body"), - @ResponseHeader( - name = "ETag", - description = "Entity Tag of the response resource.\n" + - "Used by caches, or in conditional requests."), - @ResponseHeader( - name = "Last-Modified", - description = "Date and time the resource was last modified.\n" + - "Used by caches, or in conditional requests."), - }), - @ApiResponse( - code = 304, - message = "Not Modified. Empty body because the client already has the latest version" + - " of the requested resource.\n"), - @ApiResponse( - code = 400, - message = "Bad Request. \n Invalid request or validation error.", - response = ErrorResponse.class), - @ApiResponse( - code = 404, - message = "Not Found. \n A device with the specified device type and id was not found.", - response = ErrorResponse.class), - @ApiResponse( - code = 500, - message = "Internal Server Error. \n " + - "Server error occurred while retrieving the device details.", - response = ErrorResponse.class) - }) + @GET + @Produces(MediaType.APPLICATION_JSON) + @Path("/{type}/{id}/getstatushistory") + @ApiOperation( + produces = MediaType.APPLICATION_JSON, + httpMethod = "GET", + value = "Get Device status history", + notes = "Get a list of status history associated with the device type and id", + tags = "Device Management", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "perm:devices:view") + }) + } + ) + @ApiResponses( + value = { + @ApiResponse( + code = 200, + message = "OK. \n Successfully fetched the status history of matching devices.", + response = List.class, + responseHeaders = { + @ResponseHeader( + name = "Content-Type", + description = "The content type of the body"), + @ResponseHeader( + name = "ETag", + description = "Entity Tag of the response resource.\n" + + "Used by caches, or in conditional requests."), + @ResponseHeader( + name = "Last-Modified", + description = "Date and time the resource was last modified.\n" + + "Used by caches, or in conditional requests."), + }), + @ApiResponse( + code = 304, + message = "Not Modified. Empty body because the client already has the latest version" + + " of the requested resource.\n"), + @ApiResponse( + code = 400, + message = "Bad Request. \n Invalid request or validation error.", + response = ErrorResponse.class), + @ApiResponse( + code = 404, + message = "Not Found. \n A device with the specified device type and id was not found.", + response = ErrorResponse.class), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n " + + "Server error occurred while retrieving the device details.", + response = ErrorResponse.class) + }) Response getDeviceStatusHistory( - @ApiParam( - name = "type", - value = "The device type, such as ios, android, or windows.", - required = true) - @PathParam("type") - @Size(max = 45) - String type, - @ApiParam( - name = "id", - value = "Device ID.", - required = true) - @PathParam("id") - @Size(max = 45) - String id); - @GET - @Produces(MediaType.APPLICATION_JSON) - @Path("/{type}/{id}/getenrolmentstatushistory") - @ApiOperation( - produces = MediaType.APPLICATION_JSON, - httpMethod = "GET", - value = "Get Device Current Enrolment status history", - notes = "Get a list of status history associated with the device type and id for the current enrolment", - tags = "Device Management", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "perm:devices:view") - }) - } - ) - @ApiResponses( - value = { - @ApiResponse( - code = 200, - message = "OK. \n Successfully fetched the status history of matching devices.", - response = List.class, - responseHeaders = { - @ResponseHeader( - name = "Content-Type", - description = "The content type of the body"), - @ResponseHeader( - name = "ETag", - description = "Entity Tag of the response resource.\n" + - "Used by caches, or in conditional requests."), - @ResponseHeader( - name = "Last-Modified", - description = "Date and time the resource was last modified.\n" + - "Used by caches, or in conditional requests."), - }), - @ApiResponse( - code = 304, - message = "Not Modified. Empty body because the client already has the latest version" + - " of the requested resource.\n"), - @ApiResponse( - code = 400, - message = "Bad Request. \n Invalid request or validation error.", - response = ErrorResponse.class), - @ApiResponse( - code = 404, - message = "Not Found. \n A device with the specified device type and id was not found.", - response = ErrorResponse.class), - @ApiResponse( - code = 500, - message = "Internal Server Error. \n " + - "Server error occurred while retrieving the device details.", - response = ErrorResponse.class) - }) + @ApiParam( + name = "type", + value = "The device type, such as ios, android, or windows.", + required = true) + @PathParam("type") + @Size(max = 45) + String type, + @ApiParam( + name = "id", + value = "Device ID.", + required = true) + @PathParam("id") + @Size(max = 45) + String id); + + @GET + @Produces(MediaType.APPLICATION_JSON) + @Path("/{type}/{id}/getenrolmentstatushistory") + @ApiOperation( + produces = MediaType.APPLICATION_JSON, + httpMethod = "GET", + value = "Get Device Current Enrolment status history", + notes = "Get a list of status history associated with the device type and id for the current enrolment", + tags = "Device Management", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "perm:devices:view") + }) + } + ) + @ApiResponses( + value = { + @ApiResponse( + code = 200, + message = "OK. \n Successfully fetched the status history of matching devices.", + response = List.class, + responseHeaders = { + @ResponseHeader( + name = "Content-Type", + description = "The content type of the body"), + @ResponseHeader( + name = "ETag", + description = "Entity Tag of the response resource.\n" + + "Used by caches, or in conditional requests."), + @ResponseHeader( + name = "Last-Modified", + description = "Date and time the resource was last modified.\n" + + "Used by caches, or in conditional requests."), + }), + @ApiResponse( + code = 304, + message = "Not Modified. Empty body because the client already has the latest version" + + " of the requested resource.\n"), + @ApiResponse( + code = 400, + message = "Bad Request. \n Invalid request or validation error.", + response = ErrorResponse.class), + @ApiResponse( + code = 404, + message = "Not Found. \n A device with the specified device type and id was not found.", + response = ErrorResponse.class), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n " + + "Server error occurred while retrieving the device details.", + response = ErrorResponse.class) + }) Response getCurrentEnrolmentDeviceStatusHistory( - @ApiParam( - name = "type", - value = "The device type, such as ios, android, or windows.", - required = true) - @PathParam("type") - @Size(max = 45) - String type, - @ApiParam( - name = "id", - value = "Device ID.", - required = true) - @PathParam("id") - @Size(max = 45) - String id); + @ApiParam( + name = "type", + value = "The device type, such as ios, android, or windows.", + required = true) + @PathParam("type") + @Size(max = 45) + String type, + @ApiParam( + name = "id", + value = "Device ID.", + required = true) + @PathParam("id") + @Size(max = 45) + String id); @PUT @Produces(MediaType.APPLICATION_JSON) @@ -2171,16 +2227,16 @@ public interface DeviceManagementService { @ResponseHeader( name = "ETag", description = "Entity Tag of the response resource.\n" + - "Used by caches, or in conditional requests."), + "Used by caches, or in conditional requests."), @ResponseHeader( name = "Last-Modified", description = "Date and time the resource was last modified.\n" + - "Used by caches, or in conditional requests."), + "Used by caches, or in conditional requests."), }), @ApiResponse( code = 304, message = "Not Modified. Empty body because the client already has the latest version" + - " of the requested resource.\n"), + " of the requested resource.\n"), @ApiResponse( code = 400, message = "Bad Request. \n Invalid request or validation error.", @@ -2192,7 +2248,7 @@ public interface DeviceManagementService { @ApiResponse( code = 500, message = "Internal Server Error. \n " + - "Server error occurred while retrieving the device details.", + "Server error occurred while retrieving the device details.", response = ErrorResponse.class) }) Response getDeviceCountByStatus( @@ -2240,16 +2296,16 @@ public interface DeviceManagementService { @ResponseHeader( name = "ETag", description = "Entity Tag of the response resource.\n" + - "Used by caches, or in conditional requests."), + "Used by caches, or in conditional requests."), @ResponseHeader( name = "Last-Modified", description = "Date and time the resource was last modified.\n" + - "Used by caches, or in conditional requests."), + "Used by caches, or in conditional requests."), }), @ApiResponse( code = 304, message = "Not Modified. Empty body because the client already has the latest version" + - " of the requested resource.\n"), + " of the requested resource.\n"), @ApiResponse( code = 400, message = "Bad Request. \n Invalid request or validation error.", @@ -2261,7 +2317,7 @@ public interface DeviceManagementService { @ApiResponse( code = 500, message = "Internal Server Error. \n " + - "Server error occurred while retrieving the device details.", + "Server error occurred while retrieving the device details.", response = ErrorResponse.class) }) Response getDeviceIdentifiersByStatus( @@ -2310,16 +2366,16 @@ public interface DeviceManagementService { @ResponseHeader( name = "ETag", description = "Entity Tag of the response resource.\n" + - "Used by caches, or in conditional requests."), + "Used by caches, or in conditional requests."), @ResponseHeader( name = "Last-Modified", description = "Date and time the resource has been modified the last time.\n" + - "Used by caches, or in conditional requests."), + "Used by caches, or in conditional requests."), }), @ApiResponse( code = 304, message = "Not Modified. Empty body because the client already has the latest " + - "version of the requested resource."), + "version of the requested resource."), @ApiResponse( code = 400, message = "Bad Request. \n Invalid request or validation error.", @@ -2331,7 +2387,7 @@ public interface DeviceManagementService { @ApiResponse( code = 500, message = "Internal Server Error. \n " + - "Server error occurred while retrieving information requested device.", + "Server error occurred while retrieving information requested device.", response = ErrorResponse.class) }) Response bulkUpdateDeviceStatus( @@ -2642,11 +2698,11 @@ public interface DeviceManagementService { @ResponseHeader( name = "ETag", description = "Entity Tag of the response resource.\n" + - "Used by caches, or in conditional requests."), + "Used by caches, or in conditional requests."), @ResponseHeader( name = "Last-Modified", description = "Date and time the resource was last modified.\n" + - "Used by caches, or in conditional requests."), + "Used by caches, or in conditional requests."), }), @ApiResponse( code = 500, diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java index 3bcdeafbab..78c2280d4e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java @@ -68,6 +68,7 @@ import org.wso2.carbon.device.mgt.common.app.mgt.Application; import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException; import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationException; import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationService; +import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationManagementException; import org.wso2.carbon.device.mgt.common.device.details.DeviceData; import org.wso2.carbon.device.mgt.common.device.details.DeviceInfo; import org.wso2.carbon.device.mgt.common.device.details.DeviceLocation; @@ -101,6 +102,7 @@ import org.wso2.carbon.device.mgt.core.operation.mgt.ProfileOperation; import org.wso2.carbon.device.mgt.core.search.mgt.SearchManagerService; import org.wso2.carbon.device.mgt.core.search.mgt.SearchMgtException; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; +import org.wso2.carbon.device.mgt.core.service.EmailMetaInfo; import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderService; import org.wso2.carbon.device.mgt.core.traccar.api.service.DeviceAPIClientService; import org.wso2.carbon.device.mgt.core.traccar.api.service.impl.DeviceAPIClientServiceImpl; @@ -130,6 +132,7 @@ import org.wso2.carbon.policy.mgt.core.PolicyManagerService; import org.wso2.carbon.user.api.UserStoreException; import org.wso2.carbon.user.core.service.RealmService; import org.wso2.carbon.utils.multitenancy.MultitenantUtils; +import org.springframework.web.multipart.MultipartFile; import javax.validation.Valid; import javax.ws.rs.Consumes; @@ -144,6 +147,7 @@ import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.QueryParam; import javax.ws.rs.core.Response; +import java.io.IOException; import java.sql.Timestamp; import java.text.ParseException; import java.text.SimpleDateFormat; @@ -816,6 +820,43 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { return Response.status(Response.Status.OK).entity(device).build(); } + @POST + @Path("/enrollment/guide") + @Override + public Response sendEnrollmentGuide(MultipartFile enrolmentGuide) { + if (log.isDebugEnabled()) { + log.debug("Sending enrollment invitation mail to existing user."); + } + DeviceManagementProviderService dms = DeviceMgtAPIUtils.getDeviceManagementService(); + try { +// Set recipients = new HashSet<>(); +// recipients.add(email); +// Properties props = new Properties(); +// props.setProperty("enrolment-guide", enrolmentGuide); +// +// EmailMetaInfo metaInfo = new EmailMetaInfo(recipients, props); +// dms.sendEnrolmentInvitation("enrolment-guide-template", metaInfo); + dms.sendEnrolmentGuide(enrolmentGuide); + return Response.status(Response.Status.OK).entity("Invitation mails have been sent.").build(); + } catch (DeviceManagementException e) { + String msg = "Error occurred while inviting user to enrol their device"; + log.error(msg, e); + return Response.serverError().entity( + new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build(); + } catch (ConfigurationManagementException e) { + String msg = "Error occurred while sending the email invitations. Mail server not configured."; + return Response.serverError().entity( + new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build(); + } catch (IOException e) { + e.printStackTrace(); + String msg = "testtttt."; + return Response.serverError().entity( + new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build(); + } +// return Response.status(Response.Status.OK).entity("Invitation mails have been sent.").build(); + } + + @POST @Path("/type/any/list") @Override diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java index 4e12d2cf1a..2be028d0a2 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java @@ -66,7 +66,9 @@ import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException; import org.wso2.carbon.device.mgt.core.dto.DeviceType; import org.wso2.carbon.device.mgt.core.dto.DeviceTypeVersion; import org.wso2.carbon.device.mgt.common.geo.service.GeoCluster; +import org.springframework.web.multipart.MultipartFile; +import java.io.IOException; import java.sql.SQLException; import java.sql.Timestamp; import java.util.Collection; @@ -645,6 +647,8 @@ public interface DeviceManagementProviderService { void sendEnrolmentInvitation(String templateName, EmailMetaInfo metaInfo) throws DeviceManagementException, ConfigurationManagementException; + void sendEnrolmentGuide(MultipartFile enrolmentGuide) throws DeviceManagementException, ConfigurationManagementException, IOException; + void sendRegistrationEmail(EmailMetaInfo metaInfo) throws DeviceManagementException, ConfigurationManagementException; FeatureManager getFeatureManager(String deviceType) throws DeviceTypeNotFoundException; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java index 7bb7e7c627..28c79fa7a3 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java @@ -38,6 +38,7 @@ package org.wso2.carbon.device.mgt.core.service; import com.google.common.reflect.TypeToken; import com.google.gson.Gson; import org.apache.commons.collections.map.SingletonMap; +import org.apache.commons.io.IOUtils; import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -160,12 +161,13 @@ import org.wso2.carbon.stratos.common.beans.TenantInfoBean; import org.wso2.carbon.tenant.mgt.services.TenantMgtAdminService; import org.wso2.carbon.user.api.UserStoreException; import org.wso2.carbon.utils.multitenancy.MultitenantConstants; +import org.springframework.web.multipart.MultipartFile; +import javax.mail.*; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Marshaller; -import java.io.IOException; -import java.io.StringWriter; +import java.io.*; import java.lang.reflect.Type; import java.sql.SQLException; import java.sql.Timestamp; @@ -185,6 +187,12 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.ExecutionException; import java.util.stream.Collectors; +import javax.mail.internet.InternetAddress; +import javax.mail.internet.MimeMessage; +import javax.mail.internet.MimeBodyPart; +import javax.mail.internet.MimeMultipart; +import javax.ws.rs.core.MultivaluedMap; + public class DeviceManagementProviderServiceImpl implements DeviceManagementProviderService, PluginInitializationListener { @@ -198,6 +206,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv private final ApplicationDAO applicationDAO; private MetadataDAO metadataDAO; private final DeviceStatusDAO deviceStatusDAO; + int count = 0; public DeviceManagementProviderServiceImpl() { this.pluginRepository = new DeviceManagementPluginRepository(); @@ -1551,6 +1560,178 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv } } + // save to somewhere + private void writeFile(byte[] content, String filename) throws IOException { + + File file = new File(filename); + + if (!file.exists()) { + file.createNewFile(); + } + + FileOutputStream fop = new FileOutputStream(file); + + fop.write(content); + fop.flush(); + fop.close(); + + } + + @Override + public void sendEnrolmentGuide(MultipartFile enrolmentGuide) throws DeviceManagementException, ConfigurationManagementException, IOException { + +// String fileName = ""; +// MultivaluedMap multivaluedMap = null; +// String fileName = null; +// InputStream inputStream = null; +// String uploadFilePath = null; +// +// Map> map = enrolmentGuide.getFormDataMap(); +// List inputParts = map.get("file"); +// +// for (InputPart inputPart : inputParts) { +// +// try { +// +// multivaluedMap = inputPart.getHeaders(); +// fileName = getFileName(multivaluedMap); +// +// //convert the uploaded file to inputstream +// InputStream inputStream = inputPart.getBody(InputStream.class,null); +// +// byte [] bytes = IOUtils.toByteArray(inputStream); +// +// //constructs upload file path +// fileName = UPLOADED_FILE_PATH + fileName; +// +// writeFile(bytes,fileName); +// +// System.out.println("Done"); +// +// } catch (IOException e) { +// e.printStackTrace(); +// } +// +// } + + // Recipient's email ID needs to be mentioned. + +// String charset = enrolmentGuide.getFormDataMap().get("_charset_").get(0).getBodyAsString(); +// File file = (File) enrolmentGuide.getFormDataMap().get("file").get(0); + String to = "oshani@entgra.io"; + + // Sender's email ID needs to be mentioned + String from = "oshsilva1996@gmail.com"; + + // Assuming you are sending email from through gmails smtp + String host = "smtp.gmail.com"; + + // Get system properties + Properties properties = System.getProperties(); + + // Setup mail server + properties.put("mail.smtp.host", host); + properties.put("mail.smtp.port", "465"); + properties.put("mail.smtp.ssl.enable", "true"); + properties.put("mail.smtp.auth", "true"); + + // Get the Session object.// and pass username and password + Session session = Session.getInstance(properties, new javax.mail.Authenticator() { + + protected PasswordAuthentication getPasswordAuthentication() { + + return new PasswordAuthentication("oshsilva1996@gmail.com", "layzvxhcxlwzkgwf"); + + } + + }); + + // Used to debug SMTP issues + session.setDebug(true); + + try { + // Create a default MimeMessage object. + MimeMessage message = new MimeMessage(session); + + // Set From: header field of the header. + message.setFrom(new InternetAddress(from)); + + // Set To: header field of the header. + message.addRecipient(Message.RecipientType.TO, new InternetAddress(to)); + +// // Set Subject: header field + message.setSubject("Enrollment Guide Triggered " + ++count); + +// message.setText(enrolmentGuide); + +// Multipart multipart = new MimeMultipart(); +// +// MimeBodyPart attachmentPart = new MimeBodyPart(); +// +// MimeBodyPart textPart = new MimeBodyPart(); +// +// try { +// +//// String charset = enrolmentGuide.getFormDataMap().get("_charset_").get(0).getBodyAsString(); +//// InputPart file = enrolmentGuide.getFormDataMap().get("file").get(0); +//// InputStream inputStream = file.getBody(InputStream.class, null); +//// BufferedReader br = new BufferedReader(new InputStreamReader(inputStream, charset)); +//// String line; +//// StringBuilder content = new StringBuilder(); +//// while ((line = br.readLine()) != null) { +//// content.append(line); +//// } +//// +//// writeFile(content, "test"); +//// +//// File f =new File("H:\\pepipost_tutorials\\javaemail1.PNG"); +// +// attachmentPart.attachFile(file); +// textPart.setText("This is text"); +// multipart.addBodyPart(textPart); +// multipart.addBodyPart(attachmentPart); +// +// } catch (IOException e) { +// +// e.printStackTrace(); +// +// } +// +// message.setContent(multipart); + + System.out.println("sending..."); + // Send message + Transport.send(message); + System.out.println("Sent message successfully...."); + } catch (MessagingException mex) { + mex.printStackTrace(); + } +// +// try { +// // Create a default MimeMessage object. +// MimeMessage message = new MimeMessage(session); +// +// // Set From: header field of the header. +// message.setFrom(new InternetAddress(from)); +// +// // Set To: header field of the header. +// message.addRecipient(Message.RecipientType.TO, new InternetAddress(to)); +// +// // Set Subject: header field +// message.setSubject("Enrollment Guide Triggered " + ++count); +// +// // Now set the actual message +// message.setText("enrolmentGuide"); +// +// System.out.println("sending..."); +// // Send message +// Transport.send(message); +// System.out.println("Sent message successfully...."); +// } catch (MessagingException mex) { +// mex.printStackTrace(); +// } + } + @Override public void sendRegistrationEmail(EmailMetaInfo metaInfo) throws DeviceManagementException, ConfigurationManagementException { From 79a2d573fac310cef20301f7bbf297f177123717 Mon Sep 17 00:00:00 2001 From: osh Date: Thu, 9 Mar 2023 11:58:09 +0530 Subject: [PATCH 07/30] Fix build failure fixes https://roadmap.entgra.net/issues/9939 --- .../service/api/DeviceManagementService.java | 3 +- .../impl/DeviceManagementServiceImpl.java | 22 +--- .../DeviceManagementProviderService.java | 4 +- .../DeviceManagementProviderServiceImpl.java | 119 +----------------- 4 files changed, 8 insertions(+), 140 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceManagementService.java index f4eb04cb42..2b9a2254f2 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceManagementService.java @@ -67,7 +67,6 @@ import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse; import org.wso2.carbon.device.mgt.jaxrs.beans.OperationRequest; import org.wso2.carbon.device.mgt.jaxrs.beans.OperationStatusBean; import org.wso2.carbon.device.mgt.jaxrs.util.Constants; -import org.springframework.web.multipart.MultipartFile; import javax.validation.Valid; import javax.validation.constraints.Size; @@ -855,7 +854,7 @@ public interface DeviceManagementService { name = "enrolmentGuide", value = "The details of the enrolment path suggested.", required = true) - MultipartFile enrolmentGuide); + String enrolmentGuide); @POST @Produces(MediaType.APPLICATION_JSON) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java index 78c2280d4e..80e70aaeff 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java @@ -132,7 +132,6 @@ import org.wso2.carbon.policy.mgt.core.PolicyManagerService; import org.wso2.carbon.user.api.UserStoreException; import org.wso2.carbon.user.core.service.RealmService; import org.wso2.carbon.utils.multitenancy.MultitenantUtils; -import org.springframework.web.multipart.MultipartFile; import javax.validation.Valid; import javax.ws.rs.Consumes; @@ -823,37 +822,20 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { @POST @Path("/enrollment/guide") @Override - public Response sendEnrollmentGuide(MultipartFile enrolmentGuide) { + public Response sendEnrollmentGuide(String enrolmentGuide) { if (log.isDebugEnabled()) { log.debug("Sending enrollment invitation mail to existing user."); } DeviceManagementProviderService dms = DeviceMgtAPIUtils.getDeviceManagementService(); try { -// Set recipients = new HashSet<>(); -// recipients.add(email); -// Properties props = new Properties(); -// props.setProperty("enrolment-guide", enrolmentGuide); -// -// EmailMetaInfo metaInfo = new EmailMetaInfo(recipients, props); -// dms.sendEnrolmentInvitation("enrolment-guide-template", metaInfo); dms.sendEnrolmentGuide(enrolmentGuide); return Response.status(Response.Status.OK).entity("Invitation mails have been sent.").build(); } catch (DeviceManagementException e) { - String msg = "Error occurred while inviting user to enrol their device"; + String msg = "Error occurred sending mail to group in enrollment guide"; log.error(msg, e); return Response.serverError().entity( new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build(); - } catch (ConfigurationManagementException e) { - String msg = "Error occurred while sending the email invitations. Mail server not configured."; - return Response.serverError().entity( - new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build(); - } catch (IOException e) { - e.printStackTrace(); - String msg = "testtttt."; - return Response.serverError().entity( - new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build(); } -// return Response.status(Response.Status.OK).entity("Invitation mails have been sent.").build(); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java index 2be028d0a2..4ea3cd30de 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java @@ -66,8 +66,8 @@ import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException; import org.wso2.carbon.device.mgt.core.dto.DeviceType; import org.wso2.carbon.device.mgt.core.dto.DeviceTypeVersion; import org.wso2.carbon.device.mgt.common.geo.service.GeoCluster; -import org.springframework.web.multipart.MultipartFile; +import javax.mail.MessagingException; import java.io.IOException; import java.sql.SQLException; import java.sql.Timestamp; @@ -647,7 +647,7 @@ public interface DeviceManagementProviderService { void sendEnrolmentInvitation(String templateName, EmailMetaInfo metaInfo) throws DeviceManagementException, ConfigurationManagementException; - void sendEnrolmentGuide(MultipartFile enrolmentGuide) throws DeviceManagementException, ConfigurationManagementException, IOException; + void sendEnrolmentGuide(String enrolmentGuide) throws DeviceManagementException; void sendRegistrationEmail(EmailMetaInfo metaInfo) throws DeviceManagementException, ConfigurationManagementException; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java index 16b562b35b..8e38720f40 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java @@ -161,7 +161,6 @@ import org.wso2.carbon.stratos.common.beans.TenantInfoBean; import org.wso2.carbon.tenant.mgt.services.TenantMgtAdminService; import org.wso2.carbon.user.api.UserStoreException; import org.wso2.carbon.utils.multitenancy.MultitenantConstants; -import org.springframework.web.multipart.MultipartFile; import javax.mail.*; import javax.xml.bind.JAXBContext; @@ -1582,52 +1581,13 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv } @Override - public void sendEnrolmentGuide(MultipartFile enrolmentGuide) throws DeviceManagementException, ConfigurationManagementException, IOException { - -// String fileName = ""; -// MultivaluedMap multivaluedMap = null; -// String fileName = null; -// InputStream inputStream = null; -// String uploadFilePath = null; -// -// Map> map = enrolmentGuide.getFormDataMap(); -// List inputParts = map.get("file"); -// -// for (InputPart inputPart : inputParts) { -// -// try { -// -// multivaluedMap = inputPart.getHeaders(); -// fileName = getFileName(multivaluedMap); -// -// //convert the uploaded file to inputstream -// InputStream inputStream = inputPart.getBody(InputStream.class,null); -// -// byte [] bytes = IOUtils.toByteArray(inputStream); -// -// //constructs upload file path -// fileName = UPLOADED_FILE_PATH + fileName; -// -// writeFile(bytes,fileName); -// -// System.out.println("Done"); -// -// } catch (IOException e) { -// e.printStackTrace(); -// } -// -// } - - // Recipient's email ID needs to be mentioned. + public void sendEnrolmentGuide(String enrolmentGuide) { -// String charset = enrolmentGuide.getFormDataMap().get("_charset_").get(0).getBodyAsString(); -// File file = (File) enrolmentGuide.getFormDataMap().get("file").get(0); String to = "oshani@entgra.io"; // Sender's email ID needs to be mentioned String from = "oshsilva1996@gmail.com"; - // Assuming you are sending email from through gmails smtp String host = "smtp.gmail.com"; // Get system properties @@ -1639,13 +1599,11 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv properties.put("mail.smtp.ssl.enable", "true"); properties.put("mail.smtp.auth", "true"); - // Get the Session object.// and pass username and password + // Get the Session object Session session = Session.getInstance(properties, new javax.mail.Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { - return new PasswordAuthentication("oshsilva1996@gmail.com", "layzvxhcxlwzkgwf"); - } }); @@ -1654,86 +1612,15 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv session.setDebug(true); try { - // Create a default MimeMessage object. MimeMessage message = new MimeMessage(session); - - // Set From: header field of the header. message.setFrom(new InternetAddress(from)); - - // Set To: header field of the header. message.addRecipient(Message.RecipientType.TO, new InternetAddress(to)); - -// // Set Subject: header field message.setSubject("Enrollment Guide Triggered " + ++count); - -// message.setText(enrolmentGuide); - -// Multipart multipart = new MimeMultipart(); -// -// MimeBodyPart attachmentPart = new MimeBodyPart(); -// -// MimeBodyPart textPart = new MimeBodyPart(); -// -// try { -// -//// String charset = enrolmentGuide.getFormDataMap().get("_charset_").get(0).getBodyAsString(); -//// InputPart file = enrolmentGuide.getFormDataMap().get("file").get(0); -//// InputStream inputStream = file.getBody(InputStream.class, null); -//// BufferedReader br = new BufferedReader(new InputStreamReader(inputStream, charset)); -//// String line; -//// StringBuilder content = new StringBuilder(); -//// while ((line = br.readLine()) != null) { -//// content.append(line); -//// } -//// -//// writeFile(content, "test"); -//// -//// File f =new File("H:\\pepipost_tutorials\\javaemail1.PNG"); -// -// attachmentPart.attachFile(file); -// textPart.setText("This is text"); -// multipart.addBodyPart(textPart); -// multipart.addBodyPart(attachmentPart); -// -// } catch (IOException e) { -// -// e.printStackTrace(); -// -// } -// -// message.setContent(multipart); - - System.out.println("sending..."); - // Send message + message.setText(enrolmentGuide); Transport.send(message); - System.out.println("Sent message successfully...."); } catch (MessagingException mex) { mex.printStackTrace(); } -// -// try { -// // Create a default MimeMessage object. -// MimeMessage message = new MimeMessage(session); -// -// // Set From: header field of the header. -// message.setFrom(new InternetAddress(from)); -// -// // Set To: header field of the header. -// message.addRecipient(Message.RecipientType.TO, new InternetAddress(to)); -// -// // Set Subject: header field -// message.setSubject("Enrollment Guide Triggered " + ++count); -// -// // Now set the actual message -// message.setText("enrolmentGuide"); -// -// System.out.println("sending..."); -// // Send message -// Transport.send(message); -// System.out.println("Sent message successfully...."); -// } catch (MessagingException mex) { -// mex.printStackTrace(); -// } } @Override From 0bbcac4a93f284f8c5e18b6fbb64d9fc9e5e3c68 Mon Sep 17 00:00:00 2001 From: osh Date: Fri, 10 Mar 2023 09:11:40 +0530 Subject: [PATCH 08/30] Add enrollment guide permissions fixes https://roadmap.entgra.net/issues/9939 --- .../mgt/jaxrs/service/api/DeviceManagementService.java | 9 ++++++++- .../src/main/resources/conf/mdm-ui-config.xml | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceManagementService.java index 2b9a2254f2..874b46db3d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceManagementService.java @@ -189,6 +189,13 @@ import java.util.List; roles = {"Internal/devicemgt-user"}, permissions = {"/device-mgt/devices/owning-device/add"} ), + @Scope( + name = "Viewing Enrollment Guide", + description = "Show enrollment guide to users", + key = "perm:devices:enrollment-guide:view", + roles = {"Internal/devicemgt-user"}, + permissions = {"/device-mgt/devices/enrollment-guide/view"} + ), } ) @Path("/devices") @@ -816,7 +823,7 @@ public interface DeviceManagementService { tags = "Device Management", extensions = { @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "perm:devices:view") + @ExtensionProperty(name = Constants.SCOPE, value = "perm:devices:enrollment-guide:view") }) } ) diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/conf/mdm-ui-config.xml b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/conf/mdm-ui-config.xml index d36e26a3cc..64010515b0 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/conf/mdm-ui-config.xml +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/conf/mdm-ui-config.xml @@ -100,6 +100,7 @@ perm:devices:details perm:devices:update perm:devices:view + perm:devices:enrollment-guide:view perm:view-configuration perm:manage-configuration perm:policies:remove From 74f50b28c5f603015aedb81b56517ffea6d139f7 Mon Sep 17 00:00:00 2001 From: Thashmi-nil Date: Sun, 12 Mar 2023 23:27:43 +0530 Subject: [PATCH 09/30] Add user identification improvement --- .../mgt/core/config/ui/UIConfiguration.java | 10 ++ .../request/interceptor/HubspotHandler.java | 108 ++++++++++++++++++ .../interceptor/util/HandlerConstants.java | 1 + .../request/interceptor/util/HandlerUtil.java | 17 +++ .../src/main/resources/conf/mdm-ui-config.xml | 1 + 5 files changed, 137 insertions(+) create mode 100644 components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/HubspotHandler.java diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/ui/UIConfiguration.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/ui/UIConfiguration.java index 551c1558ea..e5b553fec5 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/ui/UIConfiguration.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/ui/UIConfiguration.java @@ -34,6 +34,7 @@ public class UIConfiguration { private int sessionTimeOut; private int loginCacheCapacity; private Billing billing; + private String chatConfig; @XmlElement(name = "AppRegistration", required=true) public AppRegistration getAppRegistration() { @@ -63,6 +64,15 @@ public class UIConfiguration { isSsoEnable = ssoEnable; } + @XmlElement(name = "ChatConfig", required = true) + public String getChatConfig() { + return chatConfig; + } + + public void setChatConfig(String chatConfig) { + this.chatConfig = chatConfig; + } + @XmlElement(name = "Billing", required=true) public Billing getBilling() { return billing; diff --git a/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/HubspotHandler.java b/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/HubspotHandler.java new file mode 100644 index 0000000000..42fd8d8f09 --- /dev/null +++ b/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/HubspotHandler.java @@ -0,0 +1,108 @@ +package io.entgra.ui.request.interceptor; + +import com.google.gson.JsonObject; +import io.entgra.ui.request.interceptor.beans.ProxyResponse; +import io.entgra.ui.request.interceptor.util.HandlerConstants; +import io.entgra.ui.request.interceptor.util.HandlerUtil; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.http.HttpHeaders; +import org.apache.http.HttpStatus; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpPost; + +import javax.servlet.annotation.MultipartConfig; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; +import java.io.IOException; + +@MultipartConfig +@WebServlet( + name = "HubspotRequestHandlerServlet", + description = "", + urlPatterns = { + "/hubspot/*" + } +) +public class HubspotHandler extends HttpServlet { + + private static final Log log = LogFactory.getLog(HubspotHandler.class); + private HttpSession httpSession; + private static String hubspotEndpoint; + private static String chatConfig; + private JsonObject uiConfigJsonObject; + private static String gatewayUrl; + private static String iotsCoreUrl; + + @Override + protected void doPost(HttpServletRequest req, HttpServletResponse resp) { + try { + if (validateRequest(req, resp)) { + HttpPost postRequest = new HttpPost(HandlerUtil.generateBackendRequestURL(req, hubspotEndpoint)); + HandlerUtil.generateChatRequestEntity(req, postRequest); + postRequest.setHeader(HttpHeaders.CONTENT_TYPE, "application/json"); + postRequest.setHeader(HttpHeaders.AUTHORIZATION, HandlerConstants.BEARER + chatConfig); + ProxyResponse proxyResponse = HandlerUtil.execute(postRequest); + HandlerUtil.handleSuccess(resp, proxyResponse); + } + } catch (IOException e) { + log.error("Error occurred when processing POST request.", e); + } + + } + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) { + + try { + if (validateRequest(req, resp)) { + HttpGet getRequest = new HttpGet(HandlerUtil.generateBackendRequestURL(req,hubspotEndpoint)); + getRequest.setHeader(HttpHeaders.CONTENT_TYPE, "application/json"); + getRequest.setHeader(HttpHeaders.AUTHORIZATION, HandlerConstants.BEARER + chatConfig); + ProxyResponse proxyResponse = HandlerUtil.execute(getRequest); + HandlerUtil.handleSuccess(resp, proxyResponse); + } + } catch (IOException e) { + log.error("Error occurred when processing GET request.", e); + } + } + + /*** + * Validates the hubspot's incoming request. + * + * @param req {@link HttpServletRequest} + * @param resp {@link HttpServletResponse} + * @return If request is a valid one, returns TRUE, otherwise return FALSE + * @throws IOException If and error occurs while witting error response to client side + */ + private boolean validateRequest(HttpServletRequest req, HttpServletResponse resp) + throws IOException { + + httpSession = req.getSession(false); + gatewayUrl = req.getScheme() + HandlerConstants.SCHEME_SEPARATOR + System.getProperty(HandlerConstants.IOT_GW_HOST_ENV_VAR) + + HandlerConstants.COLON + HandlerUtil.getGatewayPort(req.getScheme()); + iotsCoreUrl = req.getScheme() + HandlerConstants.SCHEME_SEPARATOR + System.getProperty(HandlerConstants.IOT_CORE_HOST_ENV_VAR) + + HandlerConstants.COLON + HandlerUtil.getCorePort(req.getScheme()); + String uiConfigUrl = iotsCoreUrl + HandlerConstants.UI_CONFIG_ENDPOINT; + uiConfigJsonObject = HandlerUtil.getUIConfigAndPersistInSession(uiConfigUrl, gatewayUrl, httpSession, resp); + chatConfig = uiConfigJsonObject.get("chatConfig").getAsString(); + hubspotEndpoint = HandlerConstants.HTTPS_PROTOCOL + HandlerConstants.SCHEME_SEPARATOR + HandlerConstants.HUBSPOT_CHAT_URL; + + if (httpSession == null) { + log.error("Unauthorized, You are not logged in. Please log in to the portal"); + HandlerUtil.handleError(resp, HttpStatus.SC_UNAUTHORIZED); + return false; + } + + if (req.getMethod() == null) { + log.error("Bad Request, Request method is empty"); + HandlerUtil.handleError(resp, HttpStatus.SC_BAD_REQUEST); + return false; + } + + return true; + } +} diff --git a/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/util/HandlerConstants.java b/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/util/HandlerConstants.java index bf9947a9af..27d6afaadc 100644 --- a/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/util/HandlerConstants.java +++ b/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/util/HandlerConstants.java @@ -105,4 +105,5 @@ public class HandlerConstants { public static final String IOT_GW_HTTPS_PORT_ENV_VAR = "iot.gateway.https.port"; public static final String IOT_REPORTING_WEBAPP_HOST_ENV_VAR = "iot.reporting.webapp.host"; public static final String USER_SCOPES = "userScopes"; + public static final String HUBSPOT_CHAT_URL = "api.hubapi.com"; } diff --git a/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/util/HandlerUtil.java b/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/util/HandlerUtil.java index fb565bf59b..b7376abddc 100644 --- a/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/util/HandlerUtil.java +++ b/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/util/HandlerUtil.java @@ -435,6 +435,23 @@ public class HandlerUtil { } } + /** + * Generate te request entity for POST requests from the hubspot's incoming request. + * + * @param req incoming {@link HttpServletRequest}. + * @param proxyRequest proxy request instance. + * @throws IOException If error occurred while generating the request body. + */ + public static void generateChatRequestEntity(HttpServletRequest req, HttpEntityEnclosingRequestBase proxyRequest) + throws IOException { + if (StringUtils.isNotEmpty(req.getHeader(HttpHeaders.CONTENT_LENGTH)) || + StringUtils.isNotEmpty(req.getHeader(HttpHeaders.TRANSFER_ENCODING))) { + InputStreamEntity entity = new InputStreamEntity(req.getInputStream(), + Long.parseLong(req.getHeader(HttpHeaders.CONTENT_LENGTH))); + proxyRequest.setEntity(new BufferedHttpEntity(entity)); + } + } + /*** * Constructs the application registration payload for DCR. * diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/conf/mdm-ui-config.xml b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/conf/mdm-ui-config.xml index d36e26a3cc..ba100b1178 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/conf/mdm-ui-config.xml +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/conf/mdm-ui-config.xml @@ -24,6 +24,7 @@ 3600 10000 + pat-na1-33bc59e0-3526-45b0-b9cf-f353d0ae0ced false true From 5dab9433a44a458a0d3e985346e14d4f8c18cca7 Mon Sep 17 00:00:00 2001 From: osh Date: Fri, 17 Mar 2023 03:34:18 +0530 Subject: [PATCH 10/30] Update email subject fixes https://roadmap.entgra.net/issues/9939 --- .../DeviceManagementProviderServiceImpl.java | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java index 8e38720f40..ded3d067fe 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java @@ -1581,16 +1581,11 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv } @Override - public void sendEnrolmentGuide(String enrolmentGuide) { + public void sendEnrolmentGuide(String enrolmentGuide) throws DeviceManagementException { String to = "oshani@entgra.io"; - - // Sender's email ID needs to be mentioned String from = "oshsilva1996@gmail.com"; - String host = "smtp.gmail.com"; - - // Get system properties Properties properties = System.getProperties(); // Setup mail server @@ -1599,7 +1594,6 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv properties.put("mail.smtp.ssl.enable", "true"); properties.put("mail.smtp.auth", "true"); - // Get the Session object Session session = Session.getInstance(properties, new javax.mail.Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { @@ -1615,11 +1609,13 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv MimeMessage message = new MimeMessage(session); message.setFrom(new InternetAddress(from)); message.addRecipient(Message.RecipientType.TO, new InternetAddress(to)); - message.setSubject("Enrollment Guide Triggered " + ++count); + message.setSubject("[Enrollment Guide Triggered] (#" + ++count + ")"); message.setText(enrolmentGuide); Transport.send(message); - } catch (MessagingException mex) { - mex.printStackTrace(); + } catch (MessagingException e) { + String msg = "Error occurred while sending message to support dev group"; + log.error(msg, e); + throw new DeviceManagementException(msg, e); } } From b99587f1dfa1d36368ab9a0717115848cdab86bb Mon Sep 17 00:00:00 2001 From: pramilaniroshan Date: Wed, 22 Mar 2023 12:34:54 +0530 Subject: [PATCH 11/30] Remove test cases --- .../src/test/resources/testng.xml | 29 ------------------- 1 file changed, 29 deletions(-) delete mode 100644 components/logger/io.entgra.notification.logger/src/test/resources/testng.xml diff --git a/components/logger/io.entgra.notification.logger/src/test/resources/testng.xml b/components/logger/io.entgra.notification.logger/src/test/resources/testng.xml deleted file mode 100644 index c64326b7ff..0000000000 --- a/components/logger/io.entgra.notification.logger/src/test/resources/testng.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - - - - - - - From 4005a9e8cbb6050f5187804bafcc6e0d034d84d5 Mon Sep 17 00:00:00 2001 From: pramilaniroshan Date: Wed, 22 Mar 2023 12:37:59 +0530 Subject: [PATCH 12/30] User log context added --- .../org.wso2.carbon.device.mgt.core/pom.xml | 8 +- .../io.entgra.notification.logger/pom.xml | 7 +- .../notification/logger/UserLogContext.java | 103 ++++++ .../logger/impl/EntgraUserLoggerImpl.java | 294 ++++++++++++++++++ .../logger/util/MDCContextUtil.java | 16 + .../logger/impl/EntgraLoggerImplTest.java | 57 ---- components/logger/pom.xml | 4 +- .../pom.xml | 4 +- pom.xml | 7 + 9 files changed, 435 insertions(+), 65 deletions(-) create mode 100644 components/logger/io.entgra.notification.logger/src/main/java/io/entgra/notification/logger/UserLogContext.java create mode 100644 components/logger/io.entgra.notification.logger/src/main/java/io/entgra/notification/logger/impl/EntgraUserLoggerImpl.java delete mode 100644 components/logger/io.entgra.notification.logger/src/test/java/io/entgra/logger/impl/EntgraLoggerImplTest.java diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml index cb9d37a5b4..e0ce6e82a7 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml @@ -113,7 +113,9 @@ org.wso2.carbon.event.processor.stub, org.wso2.carbon.identity.jwt.client.extension.service, org.apache.commons.codec.binary, - io.entgra.server.bootup.heartbeat.beacon + io.entgra.server.bootup.heartbeat.beacon, + io.entgra.device.mgt.extensions.logger.*, + io.entgra.notification.logger.* !org.wso2.carbon.device.mgt.core.internal, @@ -352,6 +354,10 @@ org.wso2.carbon.devicemgt io.entgra.task.mgt.common + + org.wso2.carbon.devicemgt + io.entgra.notification.logger + diff --git a/components/logger/io.entgra.notification.logger/pom.xml b/components/logger/io.entgra.notification.logger/pom.xml index c363f724b5..0fadb055d7 100644 --- a/components/logger/io.entgra.notification.logger/pom.xml +++ b/components/logger/io.entgra.notification.logger/pom.xml @@ -25,11 +25,13 @@ org.wso2.carbon.devicemgt logger - 5.0.17-SNAPSHOT + 5.0.21-SNAPSHOT io.entgra.notification.logger + Entgra - Notification Logger bundle + http://entgra.io @@ -69,8 +71,7 @@ ${carbon.device.mgt.version} Device Notification Logger Bundle - io.entgra.logger;version="[2.0,3)", - io.entgra.logger.spi;version="[2.0,3)", + io.entgra.device.mgt.extensions.logger.* org.apache.commons.logging;version="[1.2,2)", org.apache.log4j;version="[1.2,2)", org.wso2.carbon.context;version="[4.4,5) diff --git a/components/logger/io.entgra.notification.logger/src/main/java/io/entgra/notification/logger/UserLogContext.java b/components/logger/io.entgra.notification.logger/src/main/java/io/entgra/notification/logger/UserLogContext.java new file mode 100644 index 0000000000..13702d570b --- /dev/null +++ b/components/logger/io.entgra.notification.logger/src/main/java/io/entgra/notification/logger/UserLogContext.java @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2023, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved. + * + * Entgra (pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package io.entgra.notification.logger; + +import io.entgra.device.mgt.extensions.logger.LogContext; + +public class UserLogContext extends LogContext { + private final String userName; + private final String userEmail; + private final String metaInfo; + private final String tenantID; + + private UserLogContext(Builder builder) { + this.userEmail = builder.userEmail; + this.userName = builder.userName; + this.metaInfo = builder.metaInfo; + this.tenantID = builder.tenantID; + } + + public String getTenantID() { + return tenantID; + } + + public String getUserName() { + return userName; + } + + public String getUserEmail() { + return userEmail; + } + + public String getMetaInfo() { + return metaInfo; + } + + + public static class Builder { + private String userName; + private String userEmail; + private String metaInfo; + private String tenantID; + + public Builder() { + } + + public String getMetaInfo() { + return metaInfo; + } + + public Builder setMetaInfo(String metaInfo) { + this.metaInfo = metaInfo; + return this; + } + + public String getTenantID() { + return tenantID; + } + + public Builder setTenantID(String tenantID) { + this.tenantID = tenantID; + return this; + } + + public String getUserName() { + return userName; + } + + public Builder setUserName(String userName) { + this.userName = userName; + return this; + } + + public String getUserEmail() { + return userEmail; + } + + public Builder setUserEmail(String userEmail) { + this.userEmail = userEmail; + return this; + } + + public UserLogContext build() { + return new UserLogContext(this); + } + + } +} diff --git a/components/logger/io.entgra.notification.logger/src/main/java/io/entgra/notification/logger/impl/EntgraUserLoggerImpl.java b/components/logger/io.entgra.notification.logger/src/main/java/io/entgra/notification/logger/impl/EntgraUserLoggerImpl.java new file mode 100644 index 0000000000..92beeabb2f --- /dev/null +++ b/components/logger/io.entgra.notification.logger/src/main/java/io/entgra/notification/logger/impl/EntgraUserLoggerImpl.java @@ -0,0 +1,294 @@ +/* + * Copyright (c) 2023, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved. + * + * Entgra (pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package io.entgra.notification.logger.impl; + + +import io.entgra.device.mgt.extensions.logger.LogContext; +import io.entgra.device.mgt.extensions.logger.spi.EntgraLogger; +import io.entgra.notification.logger.UserLogContext; +import io.entgra.notification.logger.util.MDCContextUtil; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.log4j.MDC; + + +public class EntgraUserLoggerImpl implements EntgraLogger { + + private static Log log = null; + + public EntgraUserLoggerImpl(Class clazz) { + log = LogFactory.getLog(clazz); + } + + @Override + public void info(Object object, LogContext logContext) { + } + + @Override + public void info(Object object, Throwable t, LogContext logContext) { + } + + @Override + public void debug(Object object, LogContext logContext) { + } + + @Override + public void debug(Object object, Throwable t, LogContext logContext) { + } + + @Override + public void error(Object object, LogContext logContext) { + } + + @Override + public void error(Object object, Throwable t, LogContext logContext) { + } + + @Override + public void fatal(Object object, LogContext logContext) { + } + + @Override + public void fatal(Object object, Throwable t, LogContext logContext) { + } + + @Override + public void trace(Object object, LogContext logContext) { + + } + + @Override + public void trace(Object object, Throwable t, LogContext logContext) { + + } + + @Override + public void warn(Object object, LogContext logContext) { + } + + @Override + public void warn(Object object, Throwable t, LogContext logContext) { + } + + public void info(String message) { + } + + public void info(String message, Throwable t) { + log.info(message, t); + } + + @Override + public void info(String message, LogContext logContext) { + UserLogContext userLogContext = (UserLogContext) logContext; + MDCContextUtil.populateUserMDCContext(userLogContext); + log.info(message); + } + + + public void debug(String message) { + log.debug(message); + } + + + public void debug(String message, Throwable t) { + log.debug(message, t); + } + + @Override + public void debug(String message, LogContext logContext) { + UserLogContext userLogContext = (UserLogContext) logContext; + MDCContextUtil.populateUserMDCContext(userLogContext); + log.debug(message); + } + + public void error(String message) { + log.error(message); + } + + + public void error(String message, Throwable t) { + log.error(message, t); + } + + @Override + public void error(String message, LogContext logContext) { + UserLogContext userLogContext = (UserLogContext) logContext; + MDCContextUtil.populateUserMDCContext(userLogContext); + log.error(message); + } + + @Override + public void error(String message, Throwable t, LogContext logContext) { + UserLogContext userLogContext = (UserLogContext) logContext; + MDCContextUtil.populateUserMDCContext(userLogContext); + log.error(message, t); + } + + + public void warn(String message) { + log.warn(message); + } + + + public void warn(String message, Throwable t) { + log.warn(message, t); + } + + @Override + public void warn(String message, LogContext logContext) { + UserLogContext userLogContext = (UserLogContext) logContext; + MDCContextUtil.populateUserMDCContext(userLogContext); + log.warn(message); + } + + @Override + public void warn(String message, Throwable t, LogContext logContext) { + UserLogContext userLogContext = (UserLogContext) logContext; + MDCContextUtil.populateUserMDCContext(userLogContext); + log.warn(message, t); + } + + + public void trace(String message) { + log.trace(message); + } + + + public void trace(String message, Throwable t) { + log.trace(message, t); + } + + @Override + public void trace(String message, LogContext logContext) { + UserLogContext userLogContext = (UserLogContext) logContext; + MDCContextUtil.populateUserMDCContext(userLogContext); + log.trace(message); + } + + + public void fatal(String message) { + log.fatal(message); + } + + + public void fatal(String message, Throwable t) { + log.fatal(message, t); + } + + @Override + public void fatal(String message, LogContext logContext) { + UserLogContext userLogContext = (UserLogContext) logContext; + MDCContextUtil.populateUserMDCContext(userLogContext); + log.fatal(message); + } + + @Override + public void debug(Object o) { + log.debug(o); + } + + @Override + public void debug(Object o, Throwable throwable) { + log.debug(o, throwable); + } + + @Override + public void error(Object o) { + log.error(o); + } + + @Override + public void error(Object o, Throwable throwable) { + log.error(o, throwable); + } + + @Override + public void fatal(Object o) { + log.fatal(0); + } + + @Override + public void fatal(Object o, Throwable throwable) { + log.fatal(0, throwable); + } + + @Override + public void info(Object o) { + log.info(o); + } + + @Override + public void info(Object o, Throwable throwable) { + log.info(o, throwable); + } + + @Override + public boolean isDebugEnabled() { + return log.isDebugEnabled(); + } + + @Override + public boolean isErrorEnabled() { + return log.isErrorEnabled(); + } + + @Override + public boolean isFatalEnabled() { + return log.isFatalEnabled(); + } + + @Override + public boolean isInfoEnabled() { + return log.isInfoEnabled(); + } + + @Override + public boolean isTraceEnabled() { + return log.isTraceEnabled(); + } + + @Override + public boolean isWarnEnabled() { + return log.isWarnEnabled(); + } + + @Override + public void trace(Object o) { + log.trace(o); + } + + @Override + public void trace(Object o, Throwable throwable) { + log.trace(o, throwable); + } + + @Override + public void warn(Object o) { + log.warn(o); + } + + @Override + public void warn(Object o, Throwable throwable) { + log.warn(o, throwable); + } + + @Override + public void clearLogContext() { + MDC.clear(); + } +} diff --git a/components/logger/io.entgra.notification.logger/src/main/java/io/entgra/notification/logger/util/MDCContextUtil.java b/components/logger/io.entgra.notification.logger/src/main/java/io/entgra/notification/logger/util/MDCContextUtil.java index dc7378b84c..fd78c26dba 100644 --- a/components/logger/io.entgra.notification.logger/src/main/java/io/entgra/notification/logger/util/MDCContextUtil.java +++ b/components/logger/io.entgra.notification.logger/src/main/java/io/entgra/notification/logger/util/MDCContextUtil.java @@ -18,6 +18,7 @@ package io.entgra.notification.logger.util; import io.entgra.notification.logger.DeviceLogContext; +import io.entgra.notification.logger.UserLogContext; import org.apache.log4j.MDC; public final class MDCContextUtil { @@ -36,6 +37,21 @@ public final class MDCContextUtil { MDC.put("TenantId", mdcContext.getTenantID()); } } + + public static void populateUserMDCContext(final UserLogContext mdcContext) { + if (mdcContext.getUserName() != null) { + MDC.put("UserName", mdcContext.getUserName()); + } + if (mdcContext.getUserEmail() != null) { + MDC.put("UserEmail", mdcContext.getUserEmail()); + } + if (mdcContext.getMetaInfo() != null) { + MDC.put("MetaInfo", mdcContext.getMetaInfo()); + } + if (mdcContext.getTenantID() != null) { + MDC.put("TenantId", mdcContext.getTenantID()); + } + } } diff --git a/components/logger/io.entgra.notification.logger/src/test/java/io/entgra/logger/impl/EntgraLoggerImplTest.java b/components/logger/io.entgra.notification.logger/src/test/java/io/entgra/logger/impl/EntgraLoggerImplTest.java deleted file mode 100644 index 204bc21fe3..0000000000 --- a/components/logger/io.entgra.notification.logger/src/test/java/io/entgra/logger/impl/EntgraLoggerImplTest.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2023, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved. - * - * Entgra (pvt) Ltd. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package io.entgra.logger.impl; - -import io.entgra.device.mgt.extensions.logger.spi.EntgraLogger; -import io.entgra.notification.logger.DeviceLogContext; -import io.entgra.notification.logger.impl.EntgraLoggerImpl; -import org.testng.annotations.Test; - -public class EntgraLoggerImplTest { - - private final EntgraLogger log = new EntgraLoggerImpl(EntgraLoggerImplTest.class); - - @Test - public void logTest() { - - DeviceLogContext.Builder deviceLogContext = new DeviceLogContext.Builder(); - - deviceLogContext.setDeviceName("M02S"); - deviceLogContext.setDeviceType("Android"); - deviceLogContext.setOperationCode("1222"); - deviceLogContext.setTenantID("1234"); - - log.debug("Test debug message", deviceLogContext.build()); - log.info("Test info message", deviceLogContext.build()); - log.error("Test error message", deviceLogContext.build()); - log.warn("Test warn message", deviceLogContext.build()); - log.trace("Test trace message", deviceLogContext.build()); - log.fatal("Test fatal message", deviceLogContext.build()); - log.error("debug message test", new Throwable("error throw")); - log.info("info message test"); - -// log.isDebugEnabled(); -// log.isErrorEnabled(); -// log.isFatalEnabled(); -// log.isInfoEnabled(); -// log.isTraceEnabled(); -// log.isWarnEnabled(); - - } - -} diff --git a/components/logger/pom.xml b/components/logger/pom.xml index 4312ce069a..f0884c2238 100644 --- a/components/logger/pom.xml +++ b/components/logger/pom.xml @@ -24,13 +24,13 @@ carbon-devicemgt org.wso2.carbon.devicemgt - 5.0.17-SNAPSHOT + 5.0.21-SNAPSHOT ../../pom.xml logger pom - Entgra IoT - Notification logger + Entgra - Notification Logger Component http://entgra.io diff --git a/features/logger/io.entgra.notification.logger.feature/pom.xml b/features/logger/io.entgra.notification.logger.feature/pom.xml index 6c600e7c12..be7f7146f2 100644 --- a/features/logger/io.entgra.notification.logger.feature/pom.xml +++ b/features/logger/io.entgra.notification.logger.feature/pom.xml @@ -23,14 +23,14 @@ org.wso2.carbon.devicemgt logger-feature - 5.0.17-SNAPSHOT + 5.0.21-SNAPSHOT ../pom.xml 4.0.0 io.entgra.notification.logger.feature pom - Entgra - Device Notification logger + Entgra - Notification logger http://entgra.io This feature bundles for the Entgra Notification logger diff --git a/pom.xml b/pom.xml index cf130f5b40..09590375ba 100644 --- a/pom.xml +++ b/pom.xml @@ -46,6 +46,7 @@ components/transport-mgt components/analytics-mgt components/webapp-authenticator-framework + components/logger components/task-mgt features/device-mgt features/apimgt-extensions @@ -59,6 +60,7 @@ features/transport-mgt features/analytics-mgt features/webapp-authenticator-framework + features/logger features/task-mgt @@ -356,6 +358,11 @@ org.wso2.carbon.apimgt.keymgt.extension ${carbon.device.mgt.version} + + org.wso2.carbon.devicemgt + io.entgra.notification.logger + ${carbon.device.mgt.version} + From 7441e57d3640eda099369465e365ba71ef4d5024 Mon Sep 17 00:00:00 2001 From: pramilaniroshan Date: Wed, 22 Mar 2023 12:39:18 +0530 Subject: [PATCH 13/30] Refactor log context name --- .../notification/mgt/NotificationManagementServiceImpl.java | 4 ++-- .../{EntgraLoggerImpl.java => EntgraDeviceLoggerImpl.java} | 4 ++-- features/logger/pom.xml | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) rename components/logger/io.entgra.notification.logger/src/main/java/io/entgra/notification/logger/impl/{EntgraLoggerImpl.java => EntgraDeviceLoggerImpl.java} (98%) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/NotificationManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/NotificationManagementServiceImpl.java index 0e7867b0d1..4770f9fee4 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/NotificationManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/NotificationManagementServiceImpl.java @@ -20,7 +20,7 @@ package org.wso2.carbon.device.mgt.core.notification.mgt; import io.entgra.device.mgt.extensions.logger.spi.EntgraLogger; import io.entgra.notification.logger.DeviceLogContext; -import io.entgra.notification.logger.impl.EntgraLoggerImpl; +import io.entgra.notification.logger.impl.EntgraDeviceLoggerImpl; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; @@ -46,7 +46,7 @@ import java.util.List; */ public class NotificationManagementServiceImpl implements NotificationManagementService { - private static final EntgraLogger log = new EntgraLoggerImpl(NotificationManagementServiceImpl.class); + private static final EntgraLogger log = new EntgraDeviceLoggerImpl(NotificationManagementServiceImpl.class); DeviceLogContext.Builder deviceLogContexBuilder = new DeviceLogContext.Builder(); private NotificationDAO notificationDAO; diff --git a/components/logger/io.entgra.notification.logger/src/main/java/io/entgra/notification/logger/impl/EntgraLoggerImpl.java b/components/logger/io.entgra.notification.logger/src/main/java/io/entgra/notification/logger/impl/EntgraDeviceLoggerImpl.java similarity index 98% rename from components/logger/io.entgra.notification.logger/src/main/java/io/entgra/notification/logger/impl/EntgraLoggerImpl.java rename to components/logger/io.entgra.notification.logger/src/main/java/io/entgra/notification/logger/impl/EntgraDeviceLoggerImpl.java index 882c82e473..f1360ae6c3 100644 --- a/components/logger/io.entgra.notification.logger/src/main/java/io/entgra/notification/logger/impl/EntgraLoggerImpl.java +++ b/components/logger/io.entgra.notification.logger/src/main/java/io/entgra/notification/logger/impl/EntgraDeviceLoggerImpl.java @@ -27,11 +27,11 @@ import org.apache.commons.logging.LogFactory; import org.apache.log4j.MDC; -public class EntgraLoggerImpl implements EntgraLogger { +public class EntgraDeviceLoggerImpl implements EntgraLogger { private static Log log = null; - public EntgraLoggerImpl(Class clazz) { + public EntgraDeviceLoggerImpl(Class clazz) { log = LogFactory.getLog(clazz); } diff --git a/features/logger/pom.xml b/features/logger/pom.xml index 0c6d141df3..10fc1b3f0b 100644 --- a/features/logger/pom.xml +++ b/features/logger/pom.xml @@ -23,7 +23,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.17-SNAPSHOT + 5.0.21-SNAPSHOT ../../pom.xml From c168503994b4c3ef0519dcd5d8c5eaeab65f5508 Mon Sep 17 00:00:00 2001 From: pramilaniroshan Date: Wed, 22 Mar 2023 12:41:41 +0530 Subject: [PATCH 14/30] log4j2.properties file added --- .../src/main/resources/conf/log4j2.properties | 467 ++++++++++++++++++ .../src/main/resources/p2.inf | 3 +- 2 files changed, 469 insertions(+), 1 deletion(-) create mode 100644 features/logger/io.entgra.notification.logger.feature/src/main/resources/conf/log4j2.properties diff --git a/features/logger/io.entgra.notification.logger.feature/src/main/resources/conf/log4j2.properties b/features/logger/io.entgra.notification.logger.feature/src/main/resources/conf/log4j2.properties new file mode 100644 index 0000000000..cb03876938 --- /dev/null +++ b/features/logger/io.entgra.notification.logger.feature/src/main/resources/conf/log4j2.properties @@ -0,0 +1,467 @@ +# list of all appenders +#add entry "syslog" to use the syslog appender +appenders=CARBON_CONSOLE, CARBON_LOGFILE, AUDIT_LOGFILE, ATOMIKOS_LOGFILE, CARBON_TRACE_LOGFILE,ERROR_LOGFILE, OPEN_TRACING,SERVICE_APPENDER, TRACE_APPENDER, osgi, CORRELATION, BOTDATA_APPENDER,ELK_LOGFILE +#, syslog + +# CARBON_CONSOLE is set to be a ConsoleAppender using a PatternLayout. +appender.CARBON_CONSOLE.type = Console +appender.CARBON_CONSOLE.name = CARBON_CONSOLE +appender.CARBON_CONSOLE.layout.type = PatternLayout +appender.CARBON_CONSOLE.layout.pattern = [%d{ISO8601}] %5p - [%X{DeviceName}] [%X{DeviceType}] [%X{OperationCode}] [%X{TID}] - %m %n%throwable{0} +appender.CARBON_CONSOLE.filter.threshold.type = ThresholdFilter +appender.CARBON_CONSOLE.filter.threshold.level = INFO + +# CARBON_LOGFILE is set to be a DailyRollingFileAppender using a PatternLayout. +appender.CARBON_LOGFILE.type = RollingFile +appender.CARBON_LOGFILE.name = CARBON_LOGFILE +appender.CARBON_LOGFILE.fileName = ${sys:carbon.home}/repository/logs/wso2carbon.log +appender.CARBON_LOGFILE.filePattern = ${sys:carbon.home}/repository/logs/wso2carbon-%d{MM-dd-yyyy}.log +appender.CARBON_LOGFILE.layout.type = PatternLayout +appender.CARBON_LOGFILE.layout.pattern = TID: [%tenantId] [%appName] [%d] %5p {%c} - %m%ex%n +appender.CARBON_LOGFILE.policies.type = Policies +appender.CARBON_LOGFILE.policies.time.type = TimeBasedTriggeringPolicy +appender.CARBON_LOGFILE.policies.time.interval = 1 +appender.CARBON_LOGFILE.policies.time.modulate = true +appender.CARBON_LOGFILE.policies.size.type = SizeBasedTriggeringPolicy +appender.CARBON_LOGFILE.policies.size.size=10MB +appender.CARBON_LOGFILE.strategy.type = DefaultRolloverStrategy +appender.CARBON_LOGFILE.strategy.max = 20 +appender.CARBON_LOGFILE.filter.threshold.type = ThresholdFilter +appender.CARBON_LOGFILE.filter.threshold.level = DEBUG + +# ELK_LOGFILE is set to be a DailyRollingFileAppender using a PatternLayout. +appender.ELK_LOGFILE.type = RollingFile +appender.ELK_LOGFILE.name = ELK_LOGFILE +appender.ELK_LOGFILE.fileName = ${sys:carbon.home}/repository/logs/elk.log +appender.ELK_LOGFILE.filePattern = ${sys:carbon.home}/repository/logs/elk-%d{MM-dd-yyyy}.log +appender.ELK_LOGFILE.layout.type = PatternLayout +appender.ELK_LOGFILE.layout.pattern = [%d{ISO8601}] %5p - TID: [%d] [%tenantId] [%X{Name}] [%X{OperationCode}] - %m %n%throwable{0} +appender.ELK_LOGFILE.policies.type = Policies +appender.ELK_LOGFILE.policies.time.type = TimeBasedTriggeringPolicy +appender.ELK_LOGFILE.policies.time.interval = 1 +appender.ELK_LOGFILE.policies.time.modulate = true +appender.ELK_LOGFILE.policies.size.type = SizeBasedTriggeringPolicy +appender.ELK_LOGFILE.policies.size.size=10MB +appender.ELK_LOGFILE.strategy.type = DefaultRolloverStrategy +appender.ELK_LOGFILE.strategy.max = 20 +appender.ELK_LOGFILE.filter.threshold.type = ThresholdFilter +appender.ELK_LOGFILE.filter.threshold.level = INFO + +# Appender config to AUDIT_LOGFILE +appender.AUDIT_LOGFILE.type = RollingFile +appender.AUDIT_LOGFILE.name = AUDIT_LOGFILE +appender.AUDIT_LOGFILE.fileName = ${sys:carbon.home}/repository/logs/audit.log +appender.AUDIT_LOGFILE.filePattern = ${sys:carbon.home}/repository/logs/audit-%d{MM-dd-yyyy}.log +appender.AUDIT_LOGFILE.layout.type = PatternLayout +appender.AUDIT_LOGFILE.layout.pattern = TID: [%tenantId] [%d] %5p {%c} - %m%ex%n +appender.AUDIT_LOGFILE.policies.type = Policies +appender.AUDIT_LOGFILE.policies.time.type = TimeBasedTriggeringPolicy +appender.AUDIT_LOGFILE.policies.time.interval = 1 +appender.AUDIT_LOGFILE.policies.time.modulate = true +appender.AUDIT_LOGFILE.policies.size.type = SizeBasedTriggeringPolicy +appender.AUDIT_LOGFILE.policies.size.size=10MB +appender.AUDIT_LOGFILE.strategy.type = DefaultRolloverStrategy +appender.AUDIT_LOGFILE.strategy.max = 20 +appender.AUDIT_LOGFILE.filter.threshold.type = ThresholdFilter +appender.AUDIT_LOGFILE.filter.threshold.level = INFO + +# Appender config to send Atomikos transaction logs to new log file tm.out. +appender.ATOMIKOS_LOGFILE.type = RollingFile +appender.ATOMIKOS_LOGFILE.name = ATOMIKOS_LOGFILE +appender.ATOMIKOS_LOGFILE.fileName = ${sys:carbon.home}/repository/logs/tm.out +appender.ATOMIKOS_LOGFILE.filePattern = ${sys:carbon.home}/repository/logs/tm-%d{MM-dd-yyyy}.out +appender.ATOMIKOS_LOGFILE.layout.type = PatternLayout +appender.ATOMIKOS_LOGFILE.layout.pattern = [%d] [%tenantId] %5p {%c} - %m%ex%n +appender.ATOMIKOS_LOGFILE.policies.type = Policies +appender.ATOMIKOS_LOGFILE.policies.time.type = TimeBasedTriggeringPolicy +appender.ATOMIKOS_LOGFILE.policies.time.interval = 1 +appender.ATOMIKOS_LOGFILE.policies.time.modulate = true +appender.ATOMIKOS_LOGFILE.strategy.type = DefaultRolloverStrategy +appender.ATOMIKOS_LOGFILE.strategy.max = 20 + +# Appender config to CARBON_TRACE_LOGFILE +appender.CARBON_TRACE_LOGFILE.type = RollingFile +appender.CARBON_TRACE_LOGFILE.name = CARBON_TRACE_LOGFILE +appender.CARBON_TRACE_LOGFILE.fileName = ${sys:carbon.home}/repository/logs/wso2carbon-trace-messages.log +appender.CARBON_TRACE_LOGFILE.filePattern = ${sys:carbon.home}/repository/logs/wso2carbon-trace-messages-%d{MM-dd-yyyy}.log +appender.CARBON_TRACE_LOGFILE.layout.type = PatternLayout +appender.CARBON_TRACE_LOGFILE.layout.pattern = [%d] [%tenantId] %5p {%c} - %m%ex%n +appender.CARBON_TRACE_LOGFILE.policies.type = Policies +appender.CARBON_TRACE_LOGFILE.policies.time.type = TimeBasedTriggeringPolicy +appender.CARBON_TRACE_LOGFILE.policies.time.interval = 1 +appender.CARBON_TRACE_LOGFILE.policies.time.modulate = true +appender.CARBON_TRACE_LOGFILE.policies.size.type = SizeBasedTriggeringPolicy +appender.CARBON_TRACE_LOGFILE.policies.size.size=10MB +appender.CARBON_TRACE_LOGFILE.strategy.type = DefaultRolloverStrategy +appender.CARBON_TRACE_LOGFILE.strategy.max = 20 + + +# Appender config to put correlation Log. +appender.CORRELATION.type = RollingFile +appender.CORRELATION.name = CORRELATION +appender.CORRELATION.fileName =${sys:carbon.home}/repository/logs/correlation.log +appender.CORRELATION.filePattern =${sys:carbon.home}/repository/logs/correlation-%d{MM-dd-yyyy}-%i.log.gz +appender.CORRELATION.layout.type = PatternLayout +appender.CORRELATION.layout.pattern = %d{yyyy-MM-dd HH:mm:ss,SSS}|%X{Correlation-ID}|%t|%m%n +appender.CORRELATION.policies.type = Policies +appender.CORRELATION.policies.time.type = TimeBasedTriggeringPolicy +appender.CORRELATION.policies.time.interval = 1 +appender.CORRELATION.policies.time.modulate = true +appender.CORRELATION.policies.size.type = SizeBasedTriggeringPolicy +appender.CORRELATION.policies.size.size=10MB +appender.CORRELATION.strategy.type = DefaultRolloverStrategy +appender.CORRELATION.strategy.max = 20 +appender.CORRELATION.filter.threshold.type = ThresholdFilter +appender.CORRELATION.filter.threshold.level = INFO + + +appender.ERROR_LOGFILE.type = RollingFile +appender.ERROR_LOGFILE.name = ERROR_LOGFILE +appender.ERROR_LOGFILE.fileName =${sys:carbon.home}/repository/logs/wso2-apigw-errors.log +appender.ERROR_LOGFILE.filePattern =${sys:carbon.home}/repository/logs/wso2-apigw-errors-%d{MM-dd-yyyy}-%i.log.gz +appender.ERROR_LOGFILE.layout.type = PatternLayout +appender.ERROR_LOGFILE.layout.pattern = %d{ISO8601} [%X{ip}-%X{host}] [%t] %5p %c{1} %m%n +appender.ERROR_LOGFILE.policies.type = Policies +appender.ERROR_LOGFILE.policies.time.type = TimeBasedTriggeringPolicy +appender.ERROR_LOGFILE.policies.time.interval = 1 +appender.ERROR_LOGFILE.policies.time.modulate = true +appender.ERROR_LOGFILE.policies.size.type = SizeBasedTriggeringPolicy +appender.ERROR_LOGFILE.policies.size.size=10MB +appender.ERROR_LOGFILE.strategy.type = DefaultRolloverStrategy +appender.ERROR_LOGFILE.strategy.max = 20 +appender.ERROR_LOGFILE.filter.threshold.type = ThresholdFilter +appender.ERROR_LOGFILE.filter.threshold.level = WARN + + +appender.CARBON_SYS_LOG.type = Syslog +appender.CARBON_SYS_LOG.name = CARBON_SYS_LOG +appender.CARBON_SYS_LOG.host = localhost +appender.CARBON_SYS_LOG.facility = USER +appender.CARBON_SYS_LOG.layout.type = PatternLayout +appender.CARBON_SYS_LOG.layout.pattern = [%d] %5p - %x %m {%c}%n +appender.CARBON_SYS_LOG.filter.threshold.type = ThresholdFilter +appender.CARBON_SYS_LOG.filter.threshold.level = DEBUG + +appender.OPEN_TRACING.type = RollingFile +appender.OPEN_TRACING.name = OPEN_TRACING +appender.OPEN_TRACING.fileName =${sys:carbon.home}/repository/logs/wso2-apimgt-open-tracing.log +appender.OPEN_TRACING.filePattern =${sys:carbon.home}/repository/logs/wso2-apimgt-open-tracing-%d{MM-dd-yyyy}-%i.log.gz +appender.OPEN_TRACING.layout.type = PatternLayout +appender.OPEN_TRACING.layout.pattern = %d{HH:mm:ss,SSS} [%X{ip}-%X{host}] [%t] %5p %m%nn +appender.OPEN_TRACING.policies.type = Policies +appender.OPEN_TRACING.policies.time.type = TimeBasedTriggeringPolicy +appender.OPEN_TRACING.policies.time.interval = 1 +appender.OPEN_TRACING.policies.time.modulate = true +appender.OPEN_TRACING.policies.size.type = SizeBasedTriggeringPolicy +appender.OPEN_TRACING.policies.size.size=10MB +appender.OPEN_TRACING.strategy.type = DefaultRolloverStrategy +appender.OPEN_TRACING.strategy.max = 20 +appender.OPEN_TRACING.filter.threshold.type = ThresholdFilter +appender.OPEN_TRACING.filter.threshold.level = TRACE + + +appender.TRACE_APPENDER.type = RollingFile +appender.TRACE_APPENDER.name = TRACE_APPENDER +appender.TRACE_APPENDER.fileName = ${sys:carbon.home}/repository/logs/wso2-apigw-trace.log +appender.TRACE_APPENDER.filePattern = ${sys:carbon.home}/repository/logs/wso2-apigw-trace-%d{MM-dd-yyyy}.log +appender.TRACE_APPENDER.layout.type = PatternLayout +appender.TRACE_APPENDER.layout.pattern = %d{HH:mm:ss,SSS} [%X{ip}-%X{host}] [%t] %5p %c{1} %m%n +appender.TRACE_APPENDER.policies.type = Policies +appender.TRACE_APPENDER.policies.time.type = TimeBasedTriggeringPolicy +appender.TRACE_APPENDER.policies.time.interval = 1 +appender.TRACE_APPENDER.policies.time.modulate = true +appender.TRACE_APPENDER.strategy.type = DefaultRolloverStrategy +appender.TRACE_APPENDER.strategy.max = 20 + +appender.SERVICE_APPENDER.type = RollingFile +appender.SERVICE_APPENDER.name = SERVICE_APPENDER +appender.SERVICE_APPENDER.fileName = ${sys:carbon.home}/repository/logs/wso2-apigw-service.log +appender.SERVICE_APPENDER.filePattern = ${sys:carbon.home}/repository/logs/wso2-apigw-service-%i.log +appender.SERVICE_APPENDER.layout.type = PatternLayout +appender.SERVICE_APPENDER.layout.pattern = %d{ISO8601} [%X{ip}-%X{host}] [%t] %5p %c{1} %m%n +appender.SERVICE_APPENDER.policies.type = Policies +appender.SERVICE_APPENDER.policies.size.type = SizeBasedTriggeringPolicy +appender.SERVICE_APPENDER.policies.size.size=1000KB +appender.SERVICE_APPENDER.strategy.type = DefaultRolloverStrategy +appender.SERVICE_APPENDER.strategy.max = 10 + + +appender.osgi.type = PaxOsgi +appender.osgi.name = PaxOsgi +appender.osgi.filter = * + +loggers = AUDIT_LOG, trace-messages, org-apache-coyote, com-hazelcast, Owasp-CsrfGuard, org-apache-axis2-wsdl-codegen-writer-PrettyPrinter, org-apache-axis2-clustering, org-apache-catalina, org-apache-tomcat, org-wso2-carbon-apacheds, org-apache-directory-server-ldap, org-apache-directory-server-core-event, com-atomikos, org-quartz, org-apache-jackrabbit-webdav, org-apache-juddi, org-apache-commons-digester-Digester, org-apache-jasper-compiler-TldLocationsCache, org-apache-qpid, org-apache-qpid-server-Main, qpid-message, qpid-message-broker-listening, org-apache-tiles, org-apache-commons-httpclient, org-apache-solr, me-prettyprint-cassandra-hector-TimingLogger, org-apache-axis-enterprise, org-apache-directory-shared-ldap, org-apache-directory-server-ldap-handlers, org-apache-directory-shared-ldap-entry-DefaultServerAttribute, org-apache-directory-server-core-DefaultDirectoryService, org-apache-directory-shared-ldap-ldif-LdifReader, org-apache-directory-server-ldap-LdapProtocolHandler, org-apache-directory-server-core, org-apache-directory-server-ldap-LdapSession, DataNucleus, Datastore, Datastore-Schema, JPOX-Datastore, JPOX-Plugin, JPOX-MetaData, JPOX-Query, JPOX-General, JPOX-Enhancer, org-apache-hadoop-hive, hive, ExecMapper, ExecReducer, net-sf-ehcache-config-ConfigurationFactory, axis2Deployment, equinox, tomcat2, StAXDialectDetector, trace, synapse, synapse_transport, axis2, axis2_transport, org-wso2-carbon, hunsicker, thrift-publisher, service_logger, trace_logger, org-wso2-carbon-apimgt-gateway-mediators-BotDetectionMediator, wso2-callhome, correlation, JAGGERY_LOG,ELK_LOG + +logger.JAGGERY_LOG.name = JAGGERY +logger.JAGGERY_LOG.level = INFO + +logger.ELK_LOG.name = org.wso2.carbon.device.mgt +logger.ELK_LOG.level = INFO +logger.ELK_LOG.additivity = false +logger.ELK_LOG.appenderRef.ELK_LOGFILE.ref = ELK_LOGFILE + +logger.AUDIT_LOG.name = AUDIT_LOG +logger.AUDIT_LOG.level = INFO +logger.AUDIT_LOG.appenderRef.AUDIT_LOGFILE.ref = AUDIT_LOGFILE +logger.AUDIT_LOG.additivity = false + +logger.trace-messages.name = trace.messages +logger.trace-messages.level = TRACE +logger.trace-messages.appenderRef.CARBON_TRACE_LOGFILE.ref = CARBON_TRACE_LOGFILE + +logger.org-apache-coyote.name = org.apache.coyote +logger.org-apache-coyote.level = WARN + +logger.com-hazelcast.name = com.hazelcast +logger.com-hazelcast.level = ERROR + +logger.Owasp-CsrfGuard.name = Owasp.CsrfGuard +logger.Owasp-CsrfGuard.level = WARN + +logger.org-apache-axis2-wsdl-codegen-writer-PrettyPrinter.name = org.apache.axis2.wsdl.codegen.writer.PrettyPrinter +logger.org-apache-axis2-wsdl-codegen-writer-PrettyPrinter.level = ERROR +logger.org-apache-axis2-wsdl-codegen-writer-PrettyPrinter.appenderRef.CARBON_LOGFILE.ref = CARBON_LOGFILE + +logger.org-apache-axis2-clustering.name = org.apache.axis2.clustering +logger.org-apache-axis2-clustering.level = INFO +logger.org-apache-axis2-clustering.additivity = false + +logger.org-apache.name = org.apache +logger.org-apache.level = INFO +logger.org-apache.additivity = false +logger.org-apache.appenderRef.CARBON_LOGFILE.ref = CARBON_LOGFILE + +logger.org-apache-catalina.name = org.apache.catalina +logger.org-apache-catalina.level = ERROR + +logger.org-apache-tomcat.name = org.apache.tomcat +logger.org-apache-tomcat.level = INFO + +logger.org-wso2-carbon-apacheds.name = org.wso2.carbon.apacheds +logger.org-wso2-carbon-apacheds.level = WARN + +logger.org-apache-directory-server-ldap.name = org.apache.directory.server.ldap +logger.org-apache-directory-server-ldap.level = ERROR + +logger.org-apache-directory-server-core-event.name = org.apache.directory.server.core.event +logger.org-apache-directory-server-core-event.level = WARN + +logger.com-atomikos.name = com.atomikos +logger.com-atomikos.level = INFO +logger.com-atomikos.additivity = false +logger.com-atomikos.appenderRef.ATOMIKOS_LOGFILE.ref = ATOMIKOS_LOGFILE + +logger.org-quartz.name = org.quartz +logger.org-quartz.level = WARN + +logger.org-apache-jackrabbit-webdav.name = org.apache.jackrabbit.webdav +logger.org-apache-jackrabbit-webdav.level = WARN + +logger.org-apache-juddi.name = org.apache.juddi +logger.org-apache-juddi.level = ERROR + +logger.org-apache-commons-digester-Digester.name = org.apache.commons.digester.Digester +logger.org-apache-commons-digester-Digester.level = WARN + +logger.org-apache-jasper-compiler-TldLocationsCache.name = org.apache.jasper.compiler.TldLocationsCache +logger.org-apache-jasper-compiler-TldLocationsCache.level = WARN + +logger.org-apache-qpid.name = org.apache.qpid +logger.org-apache-qpid.level = WARN + +logger.org-apache-qpid-server-Main.name = org.apache.qpid.server.Main +logger.org-apache-qpid-server-Main.level = INFO + +logger.qpid-message.name = qpid.message +logger.qpid-message.level = WARN + +logger.qpid-message-broker-listening.name = qpid.message.broker.listening +logger.qpid-message-broker-listening.level = INFO + +logger.org-apache-tiles.name = org.apache.tiles +logger.org-apache-tiles.level = WARN + +logger.org-apache-commons-httpclient.name = org.apache.commons.httpclient +logger.org-apache-commons-httpclient.level = ERROR + +logger.org-apache-solr.name = org.apache.solr +logger.org-apache-solr.level = ERROR + +logger.me-prettyprint-cassandra-hector-TimingLogger.name = me.prettyprint.cassandra.hector.TimingLogger +logger.me-prettyprint-cassandra-hector-TimingLogger.level = ERROR + +logger.org-wso2.name = org.wso2 +logger.org-wso2.level = INFO + +logger.org-wso2-carbon.name = org.wso2.carbon +logger.org-wso2-carbon.level = INFO + +logger.org-apache-axis-enterprise.name = org.apache.axis2.enterprise +logger.org-apache-axis-enterprise.level = FATAL +logger.org-apache-axis-enterprise.appenderRef.CARBON_LOGFILE.ref = CARBON_LOGFILE + +logger.org-apache-directory-shared-ldap.name = org.apache.directory.shared.ldap +logger.org-apache-directory-shared-ldap.level = WARN +logger.org-apache-directory-shared-ldap.appenderRef.CARBON_LOGFILE.ref = CARBON_LOGFILE + +logger.org-apache-directory-server-ldap-handlers.name = org.apache.directory.server.ldap.handlers +logger.org-apache-directory-server-ldap-handlers.level = WARN +logger.org-apache-directory-server-ldap-handlers.appenderRef.CARBON_LOGFILE.ref = CARBON_LOGFILE + +#Following are to remove false error messages from startup (IS) +logger.org-apache-directory-shared-ldap-entry-DefaultServerAttribute.name = org.apache.directory.shared.ldap.entry.DefaultServerAttribute +logger.org-apache-directory-shared-ldap-entry-DefaultServerAttribute.level = FATAL +logger.org-apache-directory-shared-ldap-entry-DefaultServerAttribute.appenderRef.CARBON_LOGFILE.ref = CARBON_LOGFILE + +logger.org-apache-directory-server-core-DefaultDirectoryService.name = org.apache.directory.server.core.DefaultDirectoryService +logger.org-apache-directory-server-core-DefaultDirectoryService.level = ERROR +logger.org-apache-directory-server-core-DefaultDirectoryService.appenderRef.CARBON_LOGFILE.ref = CARBON_LOGFILE + +logger.org-apache-directory-shared-ldap-ldif-LdifReader.name = org.apache.directory.shared.ldap.ldif.LdifReader +logger.org-apache-directory-shared-ldap-ldif-LdifReader.level = ERROR +logger.org-apache-directory-shared-ldap-ldif-LdifReader.appenderRef.CARBON_LOGFILE.ref = CARBON_LOGFILE + +logger.org-apache-directory-server-ldap-LdapProtocolHandler.name = org.apache.directory.server.ldap.LdapProtocolHandler +logger.org-apache-directory-server-ldap-LdapProtocolHandler.level = ERROR +logger.org-apache-directory-server-ldap-LdapProtocolHandler.appenderRef.CARBON_LOGFILE.ref = CARBON_LOGFILE + +logger.org-apache-directory-server-core.name = org.apache.directory.server.core +logger.org-apache-directory-server-core.level = ERROR +logger.org-apache-directory-server-core.appenderRef.CARBON_LOGFILE.ref = CARBON_LOGFILE + +logger.org-apache-directory-server-ldap-LdapSession.name = org.apache.directory.server.ldap.LdapSession +logger.org-apache-directory-server-ldap-LdapSession.level = Error +logger.org-apache-directory-server-ldap-LdapSession.appenderRef.CARBON_LOGFILE.ref = CARBON_LOGFILE + +logger.correlation.name = correlation +logger.correlation.level = INFO +logger.correlation.appenderRef.CORRELATION.ref = CORRELATION +logger.correlation.additivity = false + +#Hive Related Log configurations +logger.DataNucleus.name = DataNucleus +logger.DataNucleus.level = ERROR + +logger.Datastore.name = Datastore +logger.Datastore.level = ERROR + +logger.Datastore-Schema.name = Datastore.Schema +logger.Datastore-Schema.level = ERROR + +logger.JPOX-Datastore.name = JPOX.Datastore +logger.JPOX-Datastore.level = ERROR + +logger.JPOX-Plugin.name = JPOX.Plugin +logger.JPOX-Plugin.level = ERROR + +logger.JPOX-MetaData.name = JPOX.MetaData +logger.JPOX-MetaData.level = ERROR + +logger.JPOX-Query.name = JPOX.Query +logger.JPOX-Query.level = ERROR + +logger.JPOX-General.name = JPOX.General +logger.JPOX-General.level = ERROR + +logger.JPOX-Enhancer.name = JPOX.Enhancer +logger.JPOX-Enhancer.level = ERROR + +logger.org-apache-hadoop-hive.name = org.apache.hadoop.hive +logger.org-apache-hadoop-hive.level = WARN + +logger.hive.name = hive +logger.hive.level = WARN + +logger.ExecMapper.name = ExecMapper +logger.ExecMapper.level = WARN + +logger.ExecReducer.name = ExecReducer +logger.ExecReducer.level = WARN + +logger.net-sf-ehcache-config-ConfigurationFactory.name = net.sf.ehcache.config.ConfigurationFactory +logger.net-sf-ehcache-config-ConfigurationFactory.level = ERROR + +logger.axis2Deployment.name = org.apache.axis2.deployment +logger.axis2Deployment.level = WARN + +logger.equinox.name = org.eclipse.equinox +logger.equinox.level = FATAL + +logger.tomcat2.name = tomcat +logger.tomcat2.level = FATAL + +logger.StAXDialectDetector.name = org.apache.axiom.util.stax.dialect.StAXDialectDetector +logger.StAXDialectDetector.level = ERROR + + +logger.trace.name = trace +logger.trace.level = TRACE +logger.trace.appenderRef.OPEN_TRACING.ref = OPEN_TRACING + +logger.synapse.name = org.apache.synapse +logger.synapse.level = INFO + +logger.synapse_transport.name = org.apache.synapse.transport +logger.synapse_transport.level = INFO + + +logger.axis2.name = org.apache.axis2 +logger.axis2.level = INFO + +logger.axis2_transport.name = org.apache.axis2.transport +logger.axis2_transport.level = INFO + + +logger.hunsicker.name = de.hunsicker.jalopy.io +logger.hunsicker.level = FATAL + +logger.synapse-headers.name = org.apache.synapse.transport.http.headers +logger.synapse-headers.level = DEBUG + +logger.synapse-wire.name = org.apache.synapse.transport.http.wire +logger.synapse-wire.level = DEBUG + +logger.thrift-publisher.name = org.wso2.carbon.databridge.agent.thrift.AsyncDataPublisher +logger.thrift-publisher.level = WARN + +logger.service_logger.name = SERVICE_LOGGER +logger.service_logger.level = INFO +logger.service_logger.additivity = false +logger.service_logger.appenderRef.SERVICE_APPENDER.ref = SERVICE_APPENDER + +logger.wso2-callhome.name = org.wso2.callhome +logger.wso2-callhome.level = INFO + +logger.trace_logger.name = TRACE_LOGGER +logger.trace_logger.level = INFO +logger.trace_logger.appenderRef.TRACE_APPENDER.ref = TRACE_APPENDER + + +# root loggers +rootLogger.level = ERROR +rootLogger.appenderRef.CARBON_CONSOLE.ref = CARBON_CONSOLE +rootLogger.appenderRef.CARBON_LOGFILE.ref = CARBON_LOGFILE +rootLogger.appenderRef.ERROR_LOGFILE.ref = ERROR_LOGFILE +rootLogger.appenderRef.PaxOsgi.ref = PaxOsgi +#rootLogger.appenderReg.CARBON_SYS_LOG.ref = CARBON_SYS_LOG +#rootLogger.appenderRef.syslog.ref = syslog +# bot detection feature appender +appender.BOTDATA_APPENDER.type=RollingFile +appender.BOTDATA_APPENDER.name=BOTDATA_APPENDER +appender.BOTDATA_APPENDER.fileName=${sys:carbon.home}/repository/logs/wso2-BotDetectedData.log +appender.BOTDATA_APPENDER.filePattern=${sys:carbon.home}/repository/logs/wso2-BotDetectedData-%d{MM-dd-yyyy}.log +appender.BOTDATA_APPENDER.layout.type=PatternLayout +appender.BOTDATA_APPENDER.layout.pattern=[%d] [%tenantId] %5p {%c} - %m%ex%n +appender.BOTDATA_APPENDER.policies.type=Policies +appender.BOTDATA_APPENDER.policies.time.type=TimeBasedTriggeringPolicy +appender.BOTDATA_APPENDER.policies.time.interval=1 +appender.BOTDATA_APPENDER.policies.time.modulate=true +appender.BOTDATA_APPENDER.policies.size.type=SizeBasedTriggeringPolicy +appender.BOTDATA_APPENDER.policies.size.size=10MB +appender.BOTDATA_APPENDER.strategy.type=DefaultRolloverStrategy +appender.BOTDATA_APPENDER.strategy.max=20 +logger.org-wso2-carbon-apimgt-gateway-mediators-BotDetectionMediator.name=org.wso2.carbon.apimgt.gateway.mediators.BotDetectionMediator +logger.org-wso2-carbon-apimgt-gateway-mediators-BotDetectionMediator.level=INFO +logger.org-wso2-carbon-apimgt-gateway-mediators-BotDetectionMediator.appenderRef.BOTDATA_APPENDER.ref=BOTDATA_APPENDER +logger.org-wso2-carbon-apimgt-gateway-mediators-BotDetectionMediator.additivity=false +category.SERVICE_APPENDER._OpenService_=TRACE_APPENDER, BOTDATA_APPENDER diff --git a/features/logger/io.entgra.notification.logger.feature/src/main/resources/p2.inf b/features/logger/io.entgra.notification.logger.feature/src/main/resources/p2.inf index 7ab37b9d7d..5fb8862c62 100644 --- a/features/logger/io.entgra.notification.logger.feature/src/main/resources/p2.inf +++ b/features/logger/io.entgra.notification.logger.feature/src/main/resources/p2.inf @@ -1 +1,2 @@ -instructions.configure = \ \ No newline at end of file +instructions.configure = \ +org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/io.entgra.notification.logger_${feature.version}/conf/log4j2.properties,target:${installFolder}/../../../repository/conf/log4j2.properties,overwrite:true);\ \ No newline at end of file From 2d1879d1b614937befb3e5e613856d3c9229a7ea Mon Sep 17 00:00:00 2001 From: Thashmi-nil Date: Wed, 22 Mar 2023 22:04:03 +0530 Subject: [PATCH 15/30] Changes on reviews --- .../mgt/MetadataManagementServiceImpl.java | 8 ++- .../request/interceptor/HubspotHandler.java | 64 +++++++++++-------- .../src/main/resources/conf/mdm-ui-config.xml | 1 + 3 files changed, 44 insertions(+), 29 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/metadata/mgt/MetadataManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/metadata/mgt/MetadataManagementServiceImpl.java index f82c5c3295..455a583520 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/metadata/mgt/MetadataManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/metadata/mgt/MetadataManagementServiceImpl.java @@ -92,12 +92,14 @@ public class MetadataManagementServiceImpl implements MetadataManagementService } try { MetadataManagementDAOFactory.openConnection(); + int tenantId; if (metaKey.equals("EVALUATE_TENANTS")){ - return metadataDAO.getMetadata(MultitenantConstants.SUPER_TENANT_ID, metaKey); + // for getting evaluate tenant list to provide the live chat feature + tenantId = MultitenantConstants.SUPER_TENANT_ID; } else { - return metadataDAO.getMetadata( - PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true), metaKey); + tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); } + return metadataDAO.getMetadata(tenantId, metaKey); } catch (MetadataManagementDAOException e) { String msg = "Error occurred while retrieving the metadata entry for metaKey:" + metaKey; log.error(msg, e); diff --git a/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/HubspotHandler.java b/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/HubspotHandler.java index 42fd8d8f09..a9d97de3a5 100644 --- a/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/HubspotHandler.java +++ b/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/HubspotHandler.java @@ -1,3 +1,21 @@ +/* + * Copyright (c) 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + package io.entgra.ui.request.interceptor; import com.google.gson.JsonObject; @@ -51,12 +69,10 @@ public class HubspotHandler extends HttpServlet { } catch (IOException e) { log.error("Error occurred when processing POST request.", e); } - } @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) { - try { if (validateRequest(req, resp)) { HttpGet getRequest = new HttpGet(HandlerUtil.generateBackendRequestURL(req,hubspotEndpoint)); @@ -80,29 +96,25 @@ public class HubspotHandler extends HttpServlet { */ private boolean validateRequest(HttpServletRequest req, HttpServletResponse resp) throws IOException { - - httpSession = req.getSession(false); - gatewayUrl = req.getScheme() + HandlerConstants.SCHEME_SEPARATOR + System.getProperty(HandlerConstants.IOT_GW_HOST_ENV_VAR) - + HandlerConstants.COLON + HandlerUtil.getGatewayPort(req.getScheme()); - iotsCoreUrl = req.getScheme() + HandlerConstants.SCHEME_SEPARATOR + System.getProperty(HandlerConstants.IOT_CORE_HOST_ENV_VAR) - + HandlerConstants.COLON + HandlerUtil.getCorePort(req.getScheme()); - String uiConfigUrl = iotsCoreUrl + HandlerConstants.UI_CONFIG_ENDPOINT; - uiConfigJsonObject = HandlerUtil.getUIConfigAndPersistInSession(uiConfigUrl, gatewayUrl, httpSession, resp); - chatConfig = uiConfigJsonObject.get("chatConfig").getAsString(); - hubspotEndpoint = HandlerConstants.HTTPS_PROTOCOL + HandlerConstants.SCHEME_SEPARATOR + HandlerConstants.HUBSPOT_CHAT_URL; - - if (httpSession == null) { - log.error("Unauthorized, You are not logged in. Please log in to the portal"); - HandlerUtil.handleError(resp, HttpStatus.SC_UNAUTHORIZED); - return false; - } - - if (req.getMethod() == null) { - log.error("Bad Request, Request method is empty"); - HandlerUtil.handleError(resp, HttpStatus.SC_BAD_REQUEST); - return false; - } - - return true; + if (httpSession == null) { + log.error("Unauthorized, You are not logged in. Please log in to the portal"); + HandlerUtil.handleError(resp, HttpStatus.SC_UNAUTHORIZED); + return false; + } + if (req.getMethod() == null) { + log.error("Bad Request, Request method is empty"); + HandlerUtil.handleError(resp, HttpStatus.SC_BAD_REQUEST); + return false; + } + httpSession = req.getSession(false); + gatewayUrl = req.getScheme() + HandlerConstants.SCHEME_SEPARATOR + System.getProperty(HandlerConstants.IOT_GW_HOST_ENV_VAR) + + HandlerConstants.COLON + HandlerUtil.getGatewayPort(req.getScheme()); + iotsCoreUrl = req.getScheme() + HandlerConstants.SCHEME_SEPARATOR + System.getProperty(HandlerConstants.IOT_CORE_HOST_ENV_VAR) + + HandlerConstants.COLON + HandlerUtil.getCorePort(req.getScheme()); + String uiConfigUrl = iotsCoreUrl + HandlerConstants.UI_CONFIG_ENDPOINT; + uiConfigJsonObject = HandlerUtil.getUIConfigAndPersistInSession(uiConfigUrl, gatewayUrl, httpSession, resp); + chatConfig = uiConfigJsonObject.get("chatConfig").getAsString(); + hubspotEndpoint = HandlerConstants.HTTPS_PROTOCOL + HandlerConstants.SCHEME_SEPARATOR + HandlerConstants.HUBSPOT_CHAT_URL; + return true; } } diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/conf/mdm-ui-config.xml b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/conf/mdm-ui-config.xml index ba100b1178..a87ef6e44e 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/conf/mdm-ui-config.xml +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/conf/mdm-ui-config.xml @@ -24,6 +24,7 @@ 3600 10000 + pat-na1-33bc59e0-3526-45b0-b9cf-f353d0ae0ced false From 1923fb7dfb789b0f07c454a627859f7b905a0d9d Mon Sep 17 00:00:00 2001 From: pramilaniroshan Date: Fri, 24 Mar 2023 12:07:12 +0530 Subject: [PATCH 16/30] Remove log4j2.properties file --- .../src/main/resources/conf/log4j2.properties | 467 ------------------ .../src/main/resources/p2.inf | 3 +- 2 files changed, 1 insertion(+), 469 deletions(-) delete mode 100644 features/logger/io.entgra.notification.logger.feature/src/main/resources/conf/log4j2.properties diff --git a/features/logger/io.entgra.notification.logger.feature/src/main/resources/conf/log4j2.properties b/features/logger/io.entgra.notification.logger.feature/src/main/resources/conf/log4j2.properties deleted file mode 100644 index cb03876938..0000000000 --- a/features/logger/io.entgra.notification.logger.feature/src/main/resources/conf/log4j2.properties +++ /dev/null @@ -1,467 +0,0 @@ -# list of all appenders -#add entry "syslog" to use the syslog appender -appenders=CARBON_CONSOLE, CARBON_LOGFILE, AUDIT_LOGFILE, ATOMIKOS_LOGFILE, CARBON_TRACE_LOGFILE,ERROR_LOGFILE, OPEN_TRACING,SERVICE_APPENDER, TRACE_APPENDER, osgi, CORRELATION, BOTDATA_APPENDER,ELK_LOGFILE -#, syslog - -# CARBON_CONSOLE is set to be a ConsoleAppender using a PatternLayout. -appender.CARBON_CONSOLE.type = Console -appender.CARBON_CONSOLE.name = CARBON_CONSOLE -appender.CARBON_CONSOLE.layout.type = PatternLayout -appender.CARBON_CONSOLE.layout.pattern = [%d{ISO8601}] %5p - [%X{DeviceName}] [%X{DeviceType}] [%X{OperationCode}] [%X{TID}] - %m %n%throwable{0} -appender.CARBON_CONSOLE.filter.threshold.type = ThresholdFilter -appender.CARBON_CONSOLE.filter.threshold.level = INFO - -# CARBON_LOGFILE is set to be a DailyRollingFileAppender using a PatternLayout. -appender.CARBON_LOGFILE.type = RollingFile -appender.CARBON_LOGFILE.name = CARBON_LOGFILE -appender.CARBON_LOGFILE.fileName = ${sys:carbon.home}/repository/logs/wso2carbon.log -appender.CARBON_LOGFILE.filePattern = ${sys:carbon.home}/repository/logs/wso2carbon-%d{MM-dd-yyyy}.log -appender.CARBON_LOGFILE.layout.type = PatternLayout -appender.CARBON_LOGFILE.layout.pattern = TID: [%tenantId] [%appName] [%d] %5p {%c} - %m%ex%n -appender.CARBON_LOGFILE.policies.type = Policies -appender.CARBON_LOGFILE.policies.time.type = TimeBasedTriggeringPolicy -appender.CARBON_LOGFILE.policies.time.interval = 1 -appender.CARBON_LOGFILE.policies.time.modulate = true -appender.CARBON_LOGFILE.policies.size.type = SizeBasedTriggeringPolicy -appender.CARBON_LOGFILE.policies.size.size=10MB -appender.CARBON_LOGFILE.strategy.type = DefaultRolloverStrategy -appender.CARBON_LOGFILE.strategy.max = 20 -appender.CARBON_LOGFILE.filter.threshold.type = ThresholdFilter -appender.CARBON_LOGFILE.filter.threshold.level = DEBUG - -# ELK_LOGFILE is set to be a DailyRollingFileAppender using a PatternLayout. -appender.ELK_LOGFILE.type = RollingFile -appender.ELK_LOGFILE.name = ELK_LOGFILE -appender.ELK_LOGFILE.fileName = ${sys:carbon.home}/repository/logs/elk.log -appender.ELK_LOGFILE.filePattern = ${sys:carbon.home}/repository/logs/elk-%d{MM-dd-yyyy}.log -appender.ELK_LOGFILE.layout.type = PatternLayout -appender.ELK_LOGFILE.layout.pattern = [%d{ISO8601}] %5p - TID: [%d] [%tenantId] [%X{Name}] [%X{OperationCode}] - %m %n%throwable{0} -appender.ELK_LOGFILE.policies.type = Policies -appender.ELK_LOGFILE.policies.time.type = TimeBasedTriggeringPolicy -appender.ELK_LOGFILE.policies.time.interval = 1 -appender.ELK_LOGFILE.policies.time.modulate = true -appender.ELK_LOGFILE.policies.size.type = SizeBasedTriggeringPolicy -appender.ELK_LOGFILE.policies.size.size=10MB -appender.ELK_LOGFILE.strategy.type = DefaultRolloverStrategy -appender.ELK_LOGFILE.strategy.max = 20 -appender.ELK_LOGFILE.filter.threshold.type = ThresholdFilter -appender.ELK_LOGFILE.filter.threshold.level = INFO - -# Appender config to AUDIT_LOGFILE -appender.AUDIT_LOGFILE.type = RollingFile -appender.AUDIT_LOGFILE.name = AUDIT_LOGFILE -appender.AUDIT_LOGFILE.fileName = ${sys:carbon.home}/repository/logs/audit.log -appender.AUDIT_LOGFILE.filePattern = ${sys:carbon.home}/repository/logs/audit-%d{MM-dd-yyyy}.log -appender.AUDIT_LOGFILE.layout.type = PatternLayout -appender.AUDIT_LOGFILE.layout.pattern = TID: [%tenantId] [%d] %5p {%c} - %m%ex%n -appender.AUDIT_LOGFILE.policies.type = Policies -appender.AUDIT_LOGFILE.policies.time.type = TimeBasedTriggeringPolicy -appender.AUDIT_LOGFILE.policies.time.interval = 1 -appender.AUDIT_LOGFILE.policies.time.modulate = true -appender.AUDIT_LOGFILE.policies.size.type = SizeBasedTriggeringPolicy -appender.AUDIT_LOGFILE.policies.size.size=10MB -appender.AUDIT_LOGFILE.strategy.type = DefaultRolloverStrategy -appender.AUDIT_LOGFILE.strategy.max = 20 -appender.AUDIT_LOGFILE.filter.threshold.type = ThresholdFilter -appender.AUDIT_LOGFILE.filter.threshold.level = INFO - -# Appender config to send Atomikos transaction logs to new log file tm.out. -appender.ATOMIKOS_LOGFILE.type = RollingFile -appender.ATOMIKOS_LOGFILE.name = ATOMIKOS_LOGFILE -appender.ATOMIKOS_LOGFILE.fileName = ${sys:carbon.home}/repository/logs/tm.out -appender.ATOMIKOS_LOGFILE.filePattern = ${sys:carbon.home}/repository/logs/tm-%d{MM-dd-yyyy}.out -appender.ATOMIKOS_LOGFILE.layout.type = PatternLayout -appender.ATOMIKOS_LOGFILE.layout.pattern = [%d] [%tenantId] %5p {%c} - %m%ex%n -appender.ATOMIKOS_LOGFILE.policies.type = Policies -appender.ATOMIKOS_LOGFILE.policies.time.type = TimeBasedTriggeringPolicy -appender.ATOMIKOS_LOGFILE.policies.time.interval = 1 -appender.ATOMIKOS_LOGFILE.policies.time.modulate = true -appender.ATOMIKOS_LOGFILE.strategy.type = DefaultRolloverStrategy -appender.ATOMIKOS_LOGFILE.strategy.max = 20 - -# Appender config to CARBON_TRACE_LOGFILE -appender.CARBON_TRACE_LOGFILE.type = RollingFile -appender.CARBON_TRACE_LOGFILE.name = CARBON_TRACE_LOGFILE -appender.CARBON_TRACE_LOGFILE.fileName = ${sys:carbon.home}/repository/logs/wso2carbon-trace-messages.log -appender.CARBON_TRACE_LOGFILE.filePattern = ${sys:carbon.home}/repository/logs/wso2carbon-trace-messages-%d{MM-dd-yyyy}.log -appender.CARBON_TRACE_LOGFILE.layout.type = PatternLayout -appender.CARBON_TRACE_LOGFILE.layout.pattern = [%d] [%tenantId] %5p {%c} - %m%ex%n -appender.CARBON_TRACE_LOGFILE.policies.type = Policies -appender.CARBON_TRACE_LOGFILE.policies.time.type = TimeBasedTriggeringPolicy -appender.CARBON_TRACE_LOGFILE.policies.time.interval = 1 -appender.CARBON_TRACE_LOGFILE.policies.time.modulate = true -appender.CARBON_TRACE_LOGFILE.policies.size.type = SizeBasedTriggeringPolicy -appender.CARBON_TRACE_LOGFILE.policies.size.size=10MB -appender.CARBON_TRACE_LOGFILE.strategy.type = DefaultRolloverStrategy -appender.CARBON_TRACE_LOGFILE.strategy.max = 20 - - -# Appender config to put correlation Log. -appender.CORRELATION.type = RollingFile -appender.CORRELATION.name = CORRELATION -appender.CORRELATION.fileName =${sys:carbon.home}/repository/logs/correlation.log -appender.CORRELATION.filePattern =${sys:carbon.home}/repository/logs/correlation-%d{MM-dd-yyyy}-%i.log.gz -appender.CORRELATION.layout.type = PatternLayout -appender.CORRELATION.layout.pattern = %d{yyyy-MM-dd HH:mm:ss,SSS}|%X{Correlation-ID}|%t|%m%n -appender.CORRELATION.policies.type = Policies -appender.CORRELATION.policies.time.type = TimeBasedTriggeringPolicy -appender.CORRELATION.policies.time.interval = 1 -appender.CORRELATION.policies.time.modulate = true -appender.CORRELATION.policies.size.type = SizeBasedTriggeringPolicy -appender.CORRELATION.policies.size.size=10MB -appender.CORRELATION.strategy.type = DefaultRolloverStrategy -appender.CORRELATION.strategy.max = 20 -appender.CORRELATION.filter.threshold.type = ThresholdFilter -appender.CORRELATION.filter.threshold.level = INFO - - -appender.ERROR_LOGFILE.type = RollingFile -appender.ERROR_LOGFILE.name = ERROR_LOGFILE -appender.ERROR_LOGFILE.fileName =${sys:carbon.home}/repository/logs/wso2-apigw-errors.log -appender.ERROR_LOGFILE.filePattern =${sys:carbon.home}/repository/logs/wso2-apigw-errors-%d{MM-dd-yyyy}-%i.log.gz -appender.ERROR_LOGFILE.layout.type = PatternLayout -appender.ERROR_LOGFILE.layout.pattern = %d{ISO8601} [%X{ip}-%X{host}] [%t] %5p %c{1} %m%n -appender.ERROR_LOGFILE.policies.type = Policies -appender.ERROR_LOGFILE.policies.time.type = TimeBasedTriggeringPolicy -appender.ERROR_LOGFILE.policies.time.interval = 1 -appender.ERROR_LOGFILE.policies.time.modulate = true -appender.ERROR_LOGFILE.policies.size.type = SizeBasedTriggeringPolicy -appender.ERROR_LOGFILE.policies.size.size=10MB -appender.ERROR_LOGFILE.strategy.type = DefaultRolloverStrategy -appender.ERROR_LOGFILE.strategy.max = 20 -appender.ERROR_LOGFILE.filter.threshold.type = ThresholdFilter -appender.ERROR_LOGFILE.filter.threshold.level = WARN - - -appender.CARBON_SYS_LOG.type = Syslog -appender.CARBON_SYS_LOG.name = CARBON_SYS_LOG -appender.CARBON_SYS_LOG.host = localhost -appender.CARBON_SYS_LOG.facility = USER -appender.CARBON_SYS_LOG.layout.type = PatternLayout -appender.CARBON_SYS_LOG.layout.pattern = [%d] %5p - %x %m {%c}%n -appender.CARBON_SYS_LOG.filter.threshold.type = ThresholdFilter -appender.CARBON_SYS_LOG.filter.threshold.level = DEBUG - -appender.OPEN_TRACING.type = RollingFile -appender.OPEN_TRACING.name = OPEN_TRACING -appender.OPEN_TRACING.fileName =${sys:carbon.home}/repository/logs/wso2-apimgt-open-tracing.log -appender.OPEN_TRACING.filePattern =${sys:carbon.home}/repository/logs/wso2-apimgt-open-tracing-%d{MM-dd-yyyy}-%i.log.gz -appender.OPEN_TRACING.layout.type = PatternLayout -appender.OPEN_TRACING.layout.pattern = %d{HH:mm:ss,SSS} [%X{ip}-%X{host}] [%t] %5p %m%nn -appender.OPEN_TRACING.policies.type = Policies -appender.OPEN_TRACING.policies.time.type = TimeBasedTriggeringPolicy -appender.OPEN_TRACING.policies.time.interval = 1 -appender.OPEN_TRACING.policies.time.modulate = true -appender.OPEN_TRACING.policies.size.type = SizeBasedTriggeringPolicy -appender.OPEN_TRACING.policies.size.size=10MB -appender.OPEN_TRACING.strategy.type = DefaultRolloverStrategy -appender.OPEN_TRACING.strategy.max = 20 -appender.OPEN_TRACING.filter.threshold.type = ThresholdFilter -appender.OPEN_TRACING.filter.threshold.level = TRACE - - -appender.TRACE_APPENDER.type = RollingFile -appender.TRACE_APPENDER.name = TRACE_APPENDER -appender.TRACE_APPENDER.fileName = ${sys:carbon.home}/repository/logs/wso2-apigw-trace.log -appender.TRACE_APPENDER.filePattern = ${sys:carbon.home}/repository/logs/wso2-apigw-trace-%d{MM-dd-yyyy}.log -appender.TRACE_APPENDER.layout.type = PatternLayout -appender.TRACE_APPENDER.layout.pattern = %d{HH:mm:ss,SSS} [%X{ip}-%X{host}] [%t] %5p %c{1} %m%n -appender.TRACE_APPENDER.policies.type = Policies -appender.TRACE_APPENDER.policies.time.type = TimeBasedTriggeringPolicy -appender.TRACE_APPENDER.policies.time.interval = 1 -appender.TRACE_APPENDER.policies.time.modulate = true -appender.TRACE_APPENDER.strategy.type = DefaultRolloverStrategy -appender.TRACE_APPENDER.strategy.max = 20 - -appender.SERVICE_APPENDER.type = RollingFile -appender.SERVICE_APPENDER.name = SERVICE_APPENDER -appender.SERVICE_APPENDER.fileName = ${sys:carbon.home}/repository/logs/wso2-apigw-service.log -appender.SERVICE_APPENDER.filePattern = ${sys:carbon.home}/repository/logs/wso2-apigw-service-%i.log -appender.SERVICE_APPENDER.layout.type = PatternLayout -appender.SERVICE_APPENDER.layout.pattern = %d{ISO8601} [%X{ip}-%X{host}] [%t] %5p %c{1} %m%n -appender.SERVICE_APPENDER.policies.type = Policies -appender.SERVICE_APPENDER.policies.size.type = SizeBasedTriggeringPolicy -appender.SERVICE_APPENDER.policies.size.size=1000KB -appender.SERVICE_APPENDER.strategy.type = DefaultRolloverStrategy -appender.SERVICE_APPENDER.strategy.max = 10 - - -appender.osgi.type = PaxOsgi -appender.osgi.name = PaxOsgi -appender.osgi.filter = * - -loggers = AUDIT_LOG, trace-messages, org-apache-coyote, com-hazelcast, Owasp-CsrfGuard, org-apache-axis2-wsdl-codegen-writer-PrettyPrinter, org-apache-axis2-clustering, org-apache-catalina, org-apache-tomcat, org-wso2-carbon-apacheds, org-apache-directory-server-ldap, org-apache-directory-server-core-event, com-atomikos, org-quartz, org-apache-jackrabbit-webdav, org-apache-juddi, org-apache-commons-digester-Digester, org-apache-jasper-compiler-TldLocationsCache, org-apache-qpid, org-apache-qpid-server-Main, qpid-message, qpid-message-broker-listening, org-apache-tiles, org-apache-commons-httpclient, org-apache-solr, me-prettyprint-cassandra-hector-TimingLogger, org-apache-axis-enterprise, org-apache-directory-shared-ldap, org-apache-directory-server-ldap-handlers, org-apache-directory-shared-ldap-entry-DefaultServerAttribute, org-apache-directory-server-core-DefaultDirectoryService, org-apache-directory-shared-ldap-ldif-LdifReader, org-apache-directory-server-ldap-LdapProtocolHandler, org-apache-directory-server-core, org-apache-directory-server-ldap-LdapSession, DataNucleus, Datastore, Datastore-Schema, JPOX-Datastore, JPOX-Plugin, JPOX-MetaData, JPOX-Query, JPOX-General, JPOX-Enhancer, org-apache-hadoop-hive, hive, ExecMapper, ExecReducer, net-sf-ehcache-config-ConfigurationFactory, axis2Deployment, equinox, tomcat2, StAXDialectDetector, trace, synapse, synapse_transport, axis2, axis2_transport, org-wso2-carbon, hunsicker, thrift-publisher, service_logger, trace_logger, org-wso2-carbon-apimgt-gateway-mediators-BotDetectionMediator, wso2-callhome, correlation, JAGGERY_LOG,ELK_LOG - -logger.JAGGERY_LOG.name = JAGGERY -logger.JAGGERY_LOG.level = INFO - -logger.ELK_LOG.name = org.wso2.carbon.device.mgt -logger.ELK_LOG.level = INFO -logger.ELK_LOG.additivity = false -logger.ELK_LOG.appenderRef.ELK_LOGFILE.ref = ELK_LOGFILE - -logger.AUDIT_LOG.name = AUDIT_LOG -logger.AUDIT_LOG.level = INFO -logger.AUDIT_LOG.appenderRef.AUDIT_LOGFILE.ref = AUDIT_LOGFILE -logger.AUDIT_LOG.additivity = false - -logger.trace-messages.name = trace.messages -logger.trace-messages.level = TRACE -logger.trace-messages.appenderRef.CARBON_TRACE_LOGFILE.ref = CARBON_TRACE_LOGFILE - -logger.org-apache-coyote.name = org.apache.coyote -logger.org-apache-coyote.level = WARN - -logger.com-hazelcast.name = com.hazelcast -logger.com-hazelcast.level = ERROR - -logger.Owasp-CsrfGuard.name = Owasp.CsrfGuard -logger.Owasp-CsrfGuard.level = WARN - -logger.org-apache-axis2-wsdl-codegen-writer-PrettyPrinter.name = org.apache.axis2.wsdl.codegen.writer.PrettyPrinter -logger.org-apache-axis2-wsdl-codegen-writer-PrettyPrinter.level = ERROR -logger.org-apache-axis2-wsdl-codegen-writer-PrettyPrinter.appenderRef.CARBON_LOGFILE.ref = CARBON_LOGFILE - -logger.org-apache-axis2-clustering.name = org.apache.axis2.clustering -logger.org-apache-axis2-clustering.level = INFO -logger.org-apache-axis2-clustering.additivity = false - -logger.org-apache.name = org.apache -logger.org-apache.level = INFO -logger.org-apache.additivity = false -logger.org-apache.appenderRef.CARBON_LOGFILE.ref = CARBON_LOGFILE - -logger.org-apache-catalina.name = org.apache.catalina -logger.org-apache-catalina.level = ERROR - -logger.org-apache-tomcat.name = org.apache.tomcat -logger.org-apache-tomcat.level = INFO - -logger.org-wso2-carbon-apacheds.name = org.wso2.carbon.apacheds -logger.org-wso2-carbon-apacheds.level = WARN - -logger.org-apache-directory-server-ldap.name = org.apache.directory.server.ldap -logger.org-apache-directory-server-ldap.level = ERROR - -logger.org-apache-directory-server-core-event.name = org.apache.directory.server.core.event -logger.org-apache-directory-server-core-event.level = WARN - -logger.com-atomikos.name = com.atomikos -logger.com-atomikos.level = INFO -logger.com-atomikos.additivity = false -logger.com-atomikos.appenderRef.ATOMIKOS_LOGFILE.ref = ATOMIKOS_LOGFILE - -logger.org-quartz.name = org.quartz -logger.org-quartz.level = WARN - -logger.org-apache-jackrabbit-webdav.name = org.apache.jackrabbit.webdav -logger.org-apache-jackrabbit-webdav.level = WARN - -logger.org-apache-juddi.name = org.apache.juddi -logger.org-apache-juddi.level = ERROR - -logger.org-apache-commons-digester-Digester.name = org.apache.commons.digester.Digester -logger.org-apache-commons-digester-Digester.level = WARN - -logger.org-apache-jasper-compiler-TldLocationsCache.name = org.apache.jasper.compiler.TldLocationsCache -logger.org-apache-jasper-compiler-TldLocationsCache.level = WARN - -logger.org-apache-qpid.name = org.apache.qpid -logger.org-apache-qpid.level = WARN - -logger.org-apache-qpid-server-Main.name = org.apache.qpid.server.Main -logger.org-apache-qpid-server-Main.level = INFO - -logger.qpid-message.name = qpid.message -logger.qpid-message.level = WARN - -logger.qpid-message-broker-listening.name = qpid.message.broker.listening -logger.qpid-message-broker-listening.level = INFO - -logger.org-apache-tiles.name = org.apache.tiles -logger.org-apache-tiles.level = WARN - -logger.org-apache-commons-httpclient.name = org.apache.commons.httpclient -logger.org-apache-commons-httpclient.level = ERROR - -logger.org-apache-solr.name = org.apache.solr -logger.org-apache-solr.level = ERROR - -logger.me-prettyprint-cassandra-hector-TimingLogger.name = me.prettyprint.cassandra.hector.TimingLogger -logger.me-prettyprint-cassandra-hector-TimingLogger.level = ERROR - -logger.org-wso2.name = org.wso2 -logger.org-wso2.level = INFO - -logger.org-wso2-carbon.name = org.wso2.carbon -logger.org-wso2-carbon.level = INFO - -logger.org-apache-axis-enterprise.name = org.apache.axis2.enterprise -logger.org-apache-axis-enterprise.level = FATAL -logger.org-apache-axis-enterprise.appenderRef.CARBON_LOGFILE.ref = CARBON_LOGFILE - -logger.org-apache-directory-shared-ldap.name = org.apache.directory.shared.ldap -logger.org-apache-directory-shared-ldap.level = WARN -logger.org-apache-directory-shared-ldap.appenderRef.CARBON_LOGFILE.ref = CARBON_LOGFILE - -logger.org-apache-directory-server-ldap-handlers.name = org.apache.directory.server.ldap.handlers -logger.org-apache-directory-server-ldap-handlers.level = WARN -logger.org-apache-directory-server-ldap-handlers.appenderRef.CARBON_LOGFILE.ref = CARBON_LOGFILE - -#Following are to remove false error messages from startup (IS) -logger.org-apache-directory-shared-ldap-entry-DefaultServerAttribute.name = org.apache.directory.shared.ldap.entry.DefaultServerAttribute -logger.org-apache-directory-shared-ldap-entry-DefaultServerAttribute.level = FATAL -logger.org-apache-directory-shared-ldap-entry-DefaultServerAttribute.appenderRef.CARBON_LOGFILE.ref = CARBON_LOGFILE - -logger.org-apache-directory-server-core-DefaultDirectoryService.name = org.apache.directory.server.core.DefaultDirectoryService -logger.org-apache-directory-server-core-DefaultDirectoryService.level = ERROR -logger.org-apache-directory-server-core-DefaultDirectoryService.appenderRef.CARBON_LOGFILE.ref = CARBON_LOGFILE - -logger.org-apache-directory-shared-ldap-ldif-LdifReader.name = org.apache.directory.shared.ldap.ldif.LdifReader -logger.org-apache-directory-shared-ldap-ldif-LdifReader.level = ERROR -logger.org-apache-directory-shared-ldap-ldif-LdifReader.appenderRef.CARBON_LOGFILE.ref = CARBON_LOGFILE - -logger.org-apache-directory-server-ldap-LdapProtocolHandler.name = org.apache.directory.server.ldap.LdapProtocolHandler -logger.org-apache-directory-server-ldap-LdapProtocolHandler.level = ERROR -logger.org-apache-directory-server-ldap-LdapProtocolHandler.appenderRef.CARBON_LOGFILE.ref = CARBON_LOGFILE - -logger.org-apache-directory-server-core.name = org.apache.directory.server.core -logger.org-apache-directory-server-core.level = ERROR -logger.org-apache-directory-server-core.appenderRef.CARBON_LOGFILE.ref = CARBON_LOGFILE - -logger.org-apache-directory-server-ldap-LdapSession.name = org.apache.directory.server.ldap.LdapSession -logger.org-apache-directory-server-ldap-LdapSession.level = Error -logger.org-apache-directory-server-ldap-LdapSession.appenderRef.CARBON_LOGFILE.ref = CARBON_LOGFILE - -logger.correlation.name = correlation -logger.correlation.level = INFO -logger.correlation.appenderRef.CORRELATION.ref = CORRELATION -logger.correlation.additivity = false - -#Hive Related Log configurations -logger.DataNucleus.name = DataNucleus -logger.DataNucleus.level = ERROR - -logger.Datastore.name = Datastore -logger.Datastore.level = ERROR - -logger.Datastore-Schema.name = Datastore.Schema -logger.Datastore-Schema.level = ERROR - -logger.JPOX-Datastore.name = JPOX.Datastore -logger.JPOX-Datastore.level = ERROR - -logger.JPOX-Plugin.name = JPOX.Plugin -logger.JPOX-Plugin.level = ERROR - -logger.JPOX-MetaData.name = JPOX.MetaData -logger.JPOX-MetaData.level = ERROR - -logger.JPOX-Query.name = JPOX.Query -logger.JPOX-Query.level = ERROR - -logger.JPOX-General.name = JPOX.General -logger.JPOX-General.level = ERROR - -logger.JPOX-Enhancer.name = JPOX.Enhancer -logger.JPOX-Enhancer.level = ERROR - -logger.org-apache-hadoop-hive.name = org.apache.hadoop.hive -logger.org-apache-hadoop-hive.level = WARN - -logger.hive.name = hive -logger.hive.level = WARN - -logger.ExecMapper.name = ExecMapper -logger.ExecMapper.level = WARN - -logger.ExecReducer.name = ExecReducer -logger.ExecReducer.level = WARN - -logger.net-sf-ehcache-config-ConfigurationFactory.name = net.sf.ehcache.config.ConfigurationFactory -logger.net-sf-ehcache-config-ConfigurationFactory.level = ERROR - -logger.axis2Deployment.name = org.apache.axis2.deployment -logger.axis2Deployment.level = WARN - -logger.equinox.name = org.eclipse.equinox -logger.equinox.level = FATAL - -logger.tomcat2.name = tomcat -logger.tomcat2.level = FATAL - -logger.StAXDialectDetector.name = org.apache.axiom.util.stax.dialect.StAXDialectDetector -logger.StAXDialectDetector.level = ERROR - - -logger.trace.name = trace -logger.trace.level = TRACE -logger.trace.appenderRef.OPEN_TRACING.ref = OPEN_TRACING - -logger.synapse.name = org.apache.synapse -logger.synapse.level = INFO - -logger.synapse_transport.name = org.apache.synapse.transport -logger.synapse_transport.level = INFO - - -logger.axis2.name = org.apache.axis2 -logger.axis2.level = INFO - -logger.axis2_transport.name = org.apache.axis2.transport -logger.axis2_transport.level = INFO - - -logger.hunsicker.name = de.hunsicker.jalopy.io -logger.hunsicker.level = FATAL - -logger.synapse-headers.name = org.apache.synapse.transport.http.headers -logger.synapse-headers.level = DEBUG - -logger.synapse-wire.name = org.apache.synapse.transport.http.wire -logger.synapse-wire.level = DEBUG - -logger.thrift-publisher.name = org.wso2.carbon.databridge.agent.thrift.AsyncDataPublisher -logger.thrift-publisher.level = WARN - -logger.service_logger.name = SERVICE_LOGGER -logger.service_logger.level = INFO -logger.service_logger.additivity = false -logger.service_logger.appenderRef.SERVICE_APPENDER.ref = SERVICE_APPENDER - -logger.wso2-callhome.name = org.wso2.callhome -logger.wso2-callhome.level = INFO - -logger.trace_logger.name = TRACE_LOGGER -logger.trace_logger.level = INFO -logger.trace_logger.appenderRef.TRACE_APPENDER.ref = TRACE_APPENDER - - -# root loggers -rootLogger.level = ERROR -rootLogger.appenderRef.CARBON_CONSOLE.ref = CARBON_CONSOLE -rootLogger.appenderRef.CARBON_LOGFILE.ref = CARBON_LOGFILE -rootLogger.appenderRef.ERROR_LOGFILE.ref = ERROR_LOGFILE -rootLogger.appenderRef.PaxOsgi.ref = PaxOsgi -#rootLogger.appenderReg.CARBON_SYS_LOG.ref = CARBON_SYS_LOG -#rootLogger.appenderRef.syslog.ref = syslog -# bot detection feature appender -appender.BOTDATA_APPENDER.type=RollingFile -appender.BOTDATA_APPENDER.name=BOTDATA_APPENDER -appender.BOTDATA_APPENDER.fileName=${sys:carbon.home}/repository/logs/wso2-BotDetectedData.log -appender.BOTDATA_APPENDER.filePattern=${sys:carbon.home}/repository/logs/wso2-BotDetectedData-%d{MM-dd-yyyy}.log -appender.BOTDATA_APPENDER.layout.type=PatternLayout -appender.BOTDATA_APPENDER.layout.pattern=[%d] [%tenantId] %5p {%c} - %m%ex%n -appender.BOTDATA_APPENDER.policies.type=Policies -appender.BOTDATA_APPENDER.policies.time.type=TimeBasedTriggeringPolicy -appender.BOTDATA_APPENDER.policies.time.interval=1 -appender.BOTDATA_APPENDER.policies.time.modulate=true -appender.BOTDATA_APPENDER.policies.size.type=SizeBasedTriggeringPolicy -appender.BOTDATA_APPENDER.policies.size.size=10MB -appender.BOTDATA_APPENDER.strategy.type=DefaultRolloverStrategy -appender.BOTDATA_APPENDER.strategy.max=20 -logger.org-wso2-carbon-apimgt-gateway-mediators-BotDetectionMediator.name=org.wso2.carbon.apimgt.gateway.mediators.BotDetectionMediator -logger.org-wso2-carbon-apimgt-gateway-mediators-BotDetectionMediator.level=INFO -logger.org-wso2-carbon-apimgt-gateway-mediators-BotDetectionMediator.appenderRef.BOTDATA_APPENDER.ref=BOTDATA_APPENDER -logger.org-wso2-carbon-apimgt-gateway-mediators-BotDetectionMediator.additivity=false -category.SERVICE_APPENDER._OpenService_=TRACE_APPENDER, BOTDATA_APPENDER diff --git a/features/logger/io.entgra.notification.logger.feature/src/main/resources/p2.inf b/features/logger/io.entgra.notification.logger.feature/src/main/resources/p2.inf index 5fb8862c62..7ab37b9d7d 100644 --- a/features/logger/io.entgra.notification.logger.feature/src/main/resources/p2.inf +++ b/features/logger/io.entgra.notification.logger.feature/src/main/resources/p2.inf @@ -1,2 +1 @@ -instructions.configure = \ -org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/io.entgra.notification.logger_${feature.version}/conf/log4j2.properties,target:${installFolder}/../../../repository/conf/log4j2.properties,overwrite:true);\ \ No newline at end of file +instructions.configure = \ \ No newline at end of file From cad2468b3d5074d522803a083a2fc16f0a2a5545 Mon Sep 17 00:00:00 2001 From: pramilaniroshan Date: Fri, 24 Mar 2023 12:07:56 +0530 Subject: [PATCH 17/30] Fix osgi import package error --- components/logger/io.entgra.notification.logger/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/logger/io.entgra.notification.logger/pom.xml b/components/logger/io.entgra.notification.logger/pom.xml index 0fadb055d7..6044056d1d 100644 --- a/components/logger/io.entgra.notification.logger/pom.xml +++ b/components/logger/io.entgra.notification.logger/pom.xml @@ -71,7 +71,7 @@ ${carbon.device.mgt.version} Device Notification Logger Bundle - io.entgra.device.mgt.extensions.logger.* + io.entgra.device.mgt.extensions.logger.*, org.apache.commons.logging;version="[1.2,2)", org.apache.log4j;version="[1.2,2)", org.wso2.carbon.context;version="[4.4,5) From 4f7b3177614b7ffab252780b4ea07f5aacf8ccd4 Mon Sep 17 00:00:00 2001 From: rajitha Date: Wed, 22 Mar 2023 22:50:57 +0530 Subject: [PATCH 18/30] Add functionality to mark previous policy bundles as repeated --- .../PolicyEnforcementDelegatorImpl.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/enforcement/PolicyEnforcementDelegatorImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/enforcement/PolicyEnforcementDelegatorImpl.java index 3667f258c6..74e5d8e7f1 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/enforcement/PolicyEnforcementDelegatorImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/enforcement/PolicyEnforcementDelegatorImpl.java @@ -44,6 +44,8 @@ import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementExcept import org.wso2.carbon.device.mgt.common.policy.mgt.Policy; import org.wso2.carbon.device.mgt.core.operation.mgt.CommandOperation; import org.wso2.carbon.device.mgt.core.operation.mgt.OperationMgtConstants; +import org.wso2.carbon.device.mgt.core.operation.mgt.PolicyOperation; +import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.policy.mgt.common.PolicyAdministratorPoint; import org.wso2.carbon.policy.mgt.common.PolicyEvaluationException; import org.wso2.carbon.policy.mgt.common.PolicyManagementException; @@ -96,6 +98,7 @@ public class PolicyEnforcementDelegatorImpl implements PolicyEnforcementDelegato */ if (devicePolicy == null || devicePolicy.getId() != policy.getId() || updatedPolicyIds.contains (policy.getId())) { + this.markPreviousPolicyBundlesRepeated(device); this.addPolicyRevokeOperation(deviceIdentifiers); this.addPolicyOperation(deviceIdentifiers, policy); } @@ -202,4 +205,29 @@ public class PolicyEnforcementDelegatorImpl implements PolicyEnforcementDelegato throw new PolicyDelegationException(msg, e); } } + + /** + * Update the previous pending policy operation's status as REPEATED + * @param device Device + * @throws PolicyDelegationException throws when getting pending operations + */ + public void markPreviousPolicyBundlesRepeated(Device device) throws PolicyDelegationException { + DeviceManagementProviderService deviceManagerService = PolicyManagementDataHolder.getInstance(). + getDeviceManagementService(); + try { + List operations = deviceManagerService.getPendingOperations(device); + for(Operation operation : operations) { + String operationCode = operation.getCode(); + if(PolicyOperation.POLICY_OPERATION_CODE.equals(operationCode) || + OperationMgtConstants.OperationCodes.POLICY_REVOKE.equals(operationCode)) { + operation.setStatus(Operation.Status.REPEATED); + deviceManagerService.updateOperation(device, operation); + } + } + } catch (OperationManagementException e) { + String msg = "Error occurred while retrieving pending operations of device id "+device.getId(); + log.error(msg, e); + throw new PolicyDelegationException(msg, e); + } + } } From 798e8519226cc3b355a2f046b3e0afb2b3b34060 Mon Sep 17 00:00:00 2001 From: Thashmi-nil Date: Mon, 27 Mar 2023 08:24:05 +0530 Subject: [PATCH 19/30] Add modifications --- .../mgt/core/config/ui/HubspotChat.java | 54 +++++++++++++++++++ .../mgt/core/config/ui/UIConfiguration.java | 13 +++-- .../request/interceptor/HubspotHandler.java | 4 +- .../src/main/resources/conf/mdm-ui-config.xml | 11 +++- 4 files changed, 71 insertions(+), 11 deletions(-) create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/ui/HubspotChat.java diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/ui/HubspotChat.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/ui/HubspotChat.java new file mode 100644 index 0000000000..6ae77ee681 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/ui/HubspotChat.java @@ -0,0 +1,54 @@ +package org.wso2.carbon.device.mgt.core.config.ui; + +import javax.xml.bind.annotation.XmlElement; + +public class HubspotChat { + private boolean isEnableHubspot; + private String trackingUrl; + private String accessToken; + private String senderActorId; + private long channelAccountId; + + @XmlElement(name = "EnableHubspot") + public boolean isEnableHubspot() { + return isEnableHubspot; + } + + public void setEnableHubspot(boolean enableHubspot) { + isEnableHubspot = enableHubspot; + } + + @XmlElement(name = "TrackingUrl") + public String getTrackingUrl() { + return trackingUrl; + } + + public void setTrackingUrl(String trackingUrl) { + this.trackingUrl = trackingUrl; + } + + @XmlElement(name = "AccessToken") + public String getAccessToken() { + return accessToken; + } + + public void setAccessToken(String accessToken) { + this.accessToken = accessToken; + } + @XmlElement(name = "SenderActorId") + public String getSenderActorId() { + return senderActorId; + } + + public void setSenderActorId(String senderActorId) { + this.senderActorId = senderActorId; + } + @XmlElement(name = "ChannelAccountId") + public long getChannelAccountId() { + return channelAccountId; + } + + public void setChannelAccountId(long channelAccountId) { + this.channelAccountId = channelAccountId; + } +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/ui/UIConfiguration.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/ui/UIConfiguration.java index e5b553fec5..dca4a76a6b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/ui/UIConfiguration.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/ui/UIConfiguration.java @@ -34,7 +34,7 @@ public class UIConfiguration { private int sessionTimeOut; private int loginCacheCapacity; private Billing billing; - private String chatConfig; + private HubspotChat hubspotChat; @XmlElement(name = "AppRegistration", required=true) public AppRegistration getAppRegistration() { @@ -64,15 +64,14 @@ public class UIConfiguration { isSsoEnable = ssoEnable; } - @XmlElement(name = "ChatConfig", required = true) - public String getChatConfig() { - return chatConfig; + @XmlElement(name = "HubspotChat", required = true) + public HubspotChat getHubspotChat() { + return hubspotChat; } - public void setChatConfig(String chatConfig) { - this.chatConfig = chatConfig; + public void setHubspotChat(HubspotChat hubspotChat) { + this.hubspotChat = hubspotChat; } - @XmlElement(name = "Billing", required=true) public Billing getBilling() { return billing; diff --git a/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/HubspotHandler.java b/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/HubspotHandler.java index a9d97de3a5..b649d341fe 100644 --- a/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/HubspotHandler.java +++ b/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/HubspotHandler.java @@ -96,6 +96,7 @@ public class HubspotHandler extends HttpServlet { */ private boolean validateRequest(HttpServletRequest req, HttpServletResponse resp) throws IOException { + httpSession = req.getSession(false); if (httpSession == null) { log.error("Unauthorized, You are not logged in. Please log in to the portal"); HandlerUtil.handleError(resp, HttpStatus.SC_UNAUTHORIZED); @@ -106,14 +107,13 @@ public class HubspotHandler extends HttpServlet { HandlerUtil.handleError(resp, HttpStatus.SC_BAD_REQUEST); return false; } - httpSession = req.getSession(false); gatewayUrl = req.getScheme() + HandlerConstants.SCHEME_SEPARATOR + System.getProperty(HandlerConstants.IOT_GW_HOST_ENV_VAR) + HandlerConstants.COLON + HandlerUtil.getGatewayPort(req.getScheme()); iotsCoreUrl = req.getScheme() + HandlerConstants.SCHEME_SEPARATOR + System.getProperty(HandlerConstants.IOT_CORE_HOST_ENV_VAR) + HandlerConstants.COLON + HandlerUtil.getCorePort(req.getScheme()); String uiConfigUrl = iotsCoreUrl + HandlerConstants.UI_CONFIG_ENDPOINT; uiConfigJsonObject = HandlerUtil.getUIConfigAndPersistInSession(uiConfigUrl, gatewayUrl, httpSession, resp); - chatConfig = uiConfigJsonObject.get("chatConfig").getAsString(); + chatConfig = uiConfigJsonObject.get("hubspotChat").getAsJsonObject().get("accessToken").getAsString(); hubspotEndpoint = HandlerConstants.HTTPS_PROTOCOL + HandlerConstants.SCHEME_SEPARATOR + HandlerConstants.HUBSPOT_CHAT_URL; return true; } diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/conf/mdm-ui-config.xml b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/conf/mdm-ui-config.xml index a87ef6e44e..d30f414885 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/conf/mdm-ui-config.xml +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/conf/mdm-ui-config.xml @@ -24,8 +24,15 @@ 3600 10000 - - pat-na1-33bc59e0-3526-45b0-b9cf-f353d0ae0ced + + + false + tracking_url + + access_token + sender_actorId + channel_AccountId + false true From 4dac92b2602559659c692bfdc1da1393d23cca4c Mon Sep 17 00:00:00 2001 From: Amalka Subasinghe Date: Mon, 27 Mar 2023 15:05:57 +0530 Subject: [PATCH 20/30] fixed adding operation and operation response paths with emqx integration --- .../jaxrs/service/impl/DeviceManagementServiceImpl.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java index e37472bb69..b21eb4bcf8 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java @@ -872,6 +872,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { DeviceManagementProviderService deviceManagementProviderService = DeviceMgtAPIUtils.getDeviceManagementService(); int validityTime = 3600; + // add scopes for event topics List mqttEventTopicStructure = new ArrayList<>(); try { DeviceType deviceType = deviceManagementProviderService.getDeviceType(type); @@ -912,10 +913,16 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { topic = topic.replace("${deviceId}", id); } topic = topic.replace("/",":"); - scopes.append(" perm:topic:sub:".concat(topic)); +// scopes.append(" perm:topic:sub:".concat(topic)); scopes.append(" perm:topic:pub:".concat(topic)); } + // add scopes for retrieve operation topic /tenantDomain/deviceType/deviceId/operation/# + scopes.append(" perm:topic:sub:" + tenantDomain + ":" + type + ":" + id + ":operation"); + + // add scopes for update operation /tenantDomain/deviceType/deviceId/update/operation + scopes.append(" perm:topic:pub:" + tenantDomain + ":" + type + ":" + id + ":update:operation"); + TokenRequest tokenRequest = new TokenRequest(dcrResponse.getClientId(), dcrResponse.getClientSecret(), null, scopes.toString(), "client_credentials", null, null, null, null, validityTime); From 3d8f7046997be28cdae897ad6bfeea0bda0e3c99 Mon Sep 17 00:00:00 2001 From: Thashmi-nil Date: Mon, 27 Mar 2023 15:55:54 +0530 Subject: [PATCH 21/30] Add license --- .../device/mgt/core/config/ui/HubspotChat.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/ui/HubspotChat.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/ui/HubspotChat.java index 6ae77ee681..728176e1db 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/ui/HubspotChat.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/ui/HubspotChat.java @@ -1,3 +1,21 @@ +/* + * Copyright (c) 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + package org.wso2.carbon.device.mgt.core.config.ui; import javax.xml.bind.annotation.XmlElement; From f89e71d4bf2a730f181a179c571239507b0c3299 Mon Sep 17 00:00:00 2001 From: osh Date: Mon, 27 Mar 2023 19:46:51 +0530 Subject: [PATCH 22/30] Reuse email implementation fixes http://roadmap.entgra.net/issues/9939 --- .../mgt/core/DeviceManagementConstants.java | 1 + .../DeviceManagementProviderServiceImpl.java | 39 +++++-------------- .../email/templates/enrollment-guide.vm | 34 ++++++++++++++++ 3 files changed, 44 insertions(+), 30 deletions(-) create mode 100644 features/transport-mgt/email-sender/org.wso2.carbon.email.sender.feature/src/main/resources/email/templates/enrollment-guide.vm diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementConstants.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementConstants.java index 9ba76f99fb..0d45a2efc1 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementConstants.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementConstants.java @@ -136,6 +136,7 @@ public final class DeviceManagementConstants { public static final String POLICY_VIOLATE_TEMPLATE = "policy-violating-notifier"; public static final String USER_WELCOME_TEMPLATE = "user-welcome"; public static final String DEFAULT_ENROLLMENT_TEMPLATE = "default-enrollment-invitation"; + public static final String ENROLLMENT_GUIDE_TEMPLATE = "enrollment-guide"; } public static final class OperationAttributes { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java index ded3d067fe..2b5c0dffae 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java @@ -1583,38 +1583,17 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv @Override public void sendEnrolmentGuide(String enrolmentGuide) throws DeviceManagementException { - String to = "oshani@entgra.io"; - String from = "oshsilva1996@gmail.com"; - String host = "smtp.gmail.com"; - Properties properties = System.getProperties(); - - // Setup mail server - properties.put("mail.smtp.host", host); - properties.put("mail.smtp.port", "465"); - properties.put("mail.smtp.ssl.enable", "true"); - properties.put("mail.smtp.auth", "true"); - - Session session = Session.getInstance(properties, new javax.mail.Authenticator() { - - protected PasswordAuthentication getPasswordAuthentication() { - return new PasswordAuthentication("oshsilva1996@gmail.com", "layzvxhcxlwzkgwf"); - } - - }); - - // Used to debug SMTP issues - session.setDebug(true); + Properties props = new Properties(); + props.setProperty("mail-subject", "[Enrollment Guide Triggered] (#" + ++count + ")"); + props.setProperty("enrollment-guide", enrolmentGuide); try { - MimeMessage message = new MimeMessage(session); - message.setFrom(new InternetAddress(from)); - message.addRecipient(Message.RecipientType.TO, new InternetAddress(to)); - message.setSubject("[Enrollment Guide Triggered] (#" + ++count + ")"); - message.setText(enrolmentGuide); - Transport.send(message); - } catch (MessagingException e) { - String msg = "Error occurred while sending message to support dev group"; - log.error(msg, e); + EmailMetaInfo metaInfo = new EmailMetaInfo("support-dev-group@entgra.io", props); + sendEnrolmentInvitation(DeviceManagementConstants.EmailAttributes.ENROLLMENT_GUIDE_TEMPLATE, metaInfo); + + } catch (ConfigurationManagementException e) { + String msg = "Error occurred while sending the mail."; + log.error(msg); throw new DeviceManagementException(msg, e); } } diff --git a/features/transport-mgt/email-sender/org.wso2.carbon.email.sender.feature/src/main/resources/email/templates/enrollment-guide.vm b/features/transport-mgt/email-sender/org.wso2.carbon.email.sender.feature/src/main/resources/email/templates/enrollment-guide.vm new file mode 100644 index 0000000000..f4f16cc8d7 --- /dev/null +++ b/features/transport-mgt/email-sender/org.wso2.carbon.email.sender.feature/src/main/resources/email/templates/enrollment-guide.vm @@ -0,0 +1,34 @@ +#* + Copyright (c) 2023, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + + WSO2 Inc. licenses this file to you under the Apache License, + Version 2.0 (the "License"); you may not use this file except + in compliance with the License. + you may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +*# + + $mail-subject + + + + Enrollment Questions and Answers + + +
+ $enrollment-guide +
+ + + ]]> + +
From 0f28d318ed972cbcbc806706faaf436d9057b56b Mon Sep 17 00:00:00 2001 From: osh Date: Mon, 27 Mar 2023 20:09:04 +0530 Subject: [PATCH 23/30] Remove unwanted code fixes http://roadmap.entgra.net/issues/9939 --- .../service/api/DeviceManagementService.java | 1 - .../impl/DeviceManagementServiceImpl.java | 1 - .../DeviceManagementProviderService.java | 2 -- .../DeviceManagementProviderServiceImpl.java | 28 ++----------------- 4 files changed, 2 insertions(+), 30 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceManagementService.java index 66867545b2..df9cbfaae1 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceManagementService.java @@ -54,7 +54,6 @@ import org.wso2.carbon.device.mgt.common.EnrolmentInfo; import org.wso2.carbon.device.mgt.common.Feature; import org.wso2.carbon.device.mgt.common.app.mgt.Application; import org.wso2.carbon.device.mgt.common.device.details.DeviceInfo; -import org.wso2.carbon.device.mgt.common.geo.service.Alert; import org.wso2.carbon.device.mgt.common.operation.mgt.Activity; import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; import org.wso2.carbon.device.mgt.common.policy.mgt.Policy; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java index 813222a1b1..83081b5229 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java @@ -61,7 +61,6 @@ import org.wso2.carbon.device.mgt.common.app.mgt.Application; import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException; import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationException; import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationService; -import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationManagementException; import org.wso2.carbon.device.mgt.common.device.details.DeviceData; import org.wso2.carbon.device.mgt.common.device.details.DeviceInfo; import org.wso2.carbon.device.mgt.common.device.details.DeviceLocation; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java index 4ea3cd30de..3dedb8d551 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java @@ -67,8 +67,6 @@ import org.wso2.carbon.device.mgt.core.dto.DeviceType; import org.wso2.carbon.device.mgt.core.dto.DeviceTypeVersion; import org.wso2.carbon.device.mgt.common.geo.service.GeoCluster; -import javax.mail.MessagingException; -import java.io.IOException; import java.sql.SQLException; import java.sql.Timestamp; import java.util.Collection; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java index 2b5c0dffae..f6b9274ac7 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java @@ -38,7 +38,6 @@ package org.wso2.carbon.device.mgt.core.service; import com.google.common.reflect.TypeToken; import com.google.gson.Gson; import org.apache.commons.collections.map.SingletonMap; -import org.apache.commons.io.IOUtils; import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -162,11 +161,11 @@ import org.wso2.carbon.tenant.mgt.services.TenantMgtAdminService; import org.wso2.carbon.user.api.UserStoreException; import org.wso2.carbon.utils.multitenancy.MultitenantConstants; -import javax.mail.*; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Marshaller; -import java.io.*; +import java.io.IOException; +import java.io.StringWriter; import java.lang.reflect.Type; import java.sql.SQLException; import java.sql.Timestamp; @@ -186,12 +185,6 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.ExecutionException; import java.util.stream.Collectors; -import javax.mail.internet.InternetAddress; -import javax.mail.internet.MimeMessage; -import javax.mail.internet.MimeBodyPart; -import javax.mail.internet.MimeMultipart; -import javax.ws.rs.core.MultivaluedMap; - public class DeviceManagementProviderServiceImpl implements DeviceManagementProviderService, PluginInitializationListener { @@ -1563,23 +1556,6 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv } } - // save to somewhere - private void writeFile(byte[] content, String filename) throws IOException { - - File file = new File(filename); - - if (!file.exists()) { - file.createNewFile(); - } - - FileOutputStream fop = new FileOutputStream(file); - - fop.write(content); - fop.flush(); - fop.close(); - - } - @Override public void sendEnrolmentGuide(String enrolmentGuide) throws DeviceManagementException { From d2bc4632842871a58eaf5f689b4018fd24614e97 Mon Sep 17 00:00:00 2001 From: osh Date: Tue, 28 Mar 2023 12:34:11 +0530 Subject: [PATCH 24/30] Resolve comments fixes http://roadmap.entgra.net/issues/9939 --- .../device/mgt/core/config/DeviceManagementConfig.java | 10 ++++++++++ .../service/DeviceManagementProviderServiceImpl.java | 7 ++++--- .../src/main/resources/conf/cdm-config.xml | 1 + .../templates/repository/conf/cdm-config.xml.j2 | 9 +++++++-- 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/DeviceManagementConfig.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/DeviceManagementConfig.java index f2ad40abb7..052bb87886 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/DeviceManagementConfig.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/DeviceManagementConfig.java @@ -70,6 +70,7 @@ public final class DeviceManagementConfig { private EnrollmentNotificationConfiguration enrollmentNotificationConfiguration; private DefaultRoles defaultRoles; private OperationTimeoutConfiguration operationTimeoutConfiguration; + private String enrollmentGuideMail; @XmlElement(name = "ManagementRepository", required = true) public DeviceManagementConfigRepository getDeviceManagementConfigRepository() { @@ -265,5 +266,14 @@ public final class DeviceManagementConfig { public void setOperationTimeoutConfiguration(OperationTimeoutConfiguration operationTimeoutConfiguration) { this.operationTimeoutConfiguration = operationTimeoutConfiguration; } + + @XmlElement(name = "EnrollmentGuideMail", required = true) + public String getEnrollmentGuideMail() { + return enrollmentGuideMail; + } + + public void setEnrollmentGuideMail(String enrollmentGuideMail) { + this.enrollmentGuideMail = enrollmentGuideMail; + } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java index f6b9274ac7..2ae6e1f7c5 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java @@ -1559,17 +1559,18 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv @Override public void sendEnrolmentGuide(String enrolmentGuide) throws DeviceManagementException { + DeviceManagementConfig config = DeviceConfigurationManager.getInstance().getDeviceManagementConfig(); + String recipientMail = config.getEnrollmentGuideMail(); Properties props = new Properties(); props.setProperty("mail-subject", "[Enrollment Guide Triggered] (#" + ++count + ")"); props.setProperty("enrollment-guide", enrolmentGuide); try { - EmailMetaInfo metaInfo = new EmailMetaInfo("support-dev-group@entgra.io", props); + EmailMetaInfo metaInfo = new EmailMetaInfo(recipientMail, props); sendEnrolmentInvitation(DeviceManagementConstants.EmailAttributes.ENROLLMENT_GUIDE_TEMPLATE, metaInfo); - } catch (ConfigurationManagementException e) { String msg = "Error occurred while sending the mail."; - log.error(msg); + log.error(msg, e); throw new DeviceManagementException(msg, e); } } diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/conf/cdm-config.xml b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/conf/cdm-config.xml index 340b22802b..9598f16000 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/conf/cdm-config.xml +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/conf/cdm-config.xml @@ -187,5 +187,6 @@ + support-dev-group@entgra.io diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/conf_templates/templates/repository/conf/cdm-config.xml.j2 b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/conf_templates/templates/repository/conf/cdm-config.xml.j2 index f567bb9dd2..42077b0afd 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/conf_templates/templates/repository/conf/cdm-config.xml.j2 +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/conf_templates/templates/repository/conf/cdm-config.xml.j2 @@ -322,7 +322,7 @@ - + @@ -350,6 +350,11 @@ {% endfor %} {% endif%} - + + {% if device_mgt_conf.enrollment_guide_mail is defined %} + {{device_mgt_conf.enrollment_guide_mail}} + {% else %} + support-dev-group@entgra.io + {% endif %} From 7747d7b42585634943a0aae138e2dc10e21484db Mon Sep 17 00:00:00 2001 From: osh Date: Tue, 28 Mar 2023 16:40:10 +0530 Subject: [PATCH 25/30] Update status history path --- .../device/mgt/jaxrs/service/api/DeviceManagementService.java | 4 ++-- .../mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceManagementService.java index df9cbfaae1..a080208de2 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceManagementService.java @@ -2011,7 +2011,7 @@ public interface DeviceManagementService { @GET @Produces(MediaType.APPLICATION_JSON) - @Path("/{type}/{id}/getstatushistory") + @Path("/{type}/{id}/status-history") @ApiOperation( produces = MediaType.APPLICATION_JSON, httpMethod = "GET", @@ -2079,7 +2079,7 @@ public interface DeviceManagementService { @GET @Produces(MediaType.APPLICATION_JSON) - @Path("/{type}/{id}/getenrolmentstatushistory") + @Path("/{type}/{id}/enrolment-status-history") @ApiOperation( produces = MediaType.APPLICATION_JSON, httpMethod = "GET", diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java index 83081b5229..a938a71860 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java @@ -1344,7 +1344,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { * @return {@link Response} object */ @GET - @Path("/{type}/{id}/getstatushistory") + @Path("/{type}/{id}/status-history") public Response getDeviceStatusHistory(@PathParam("type") @Size(max = 45) String type, @PathParam("id") @Size(max = 45) String id) { //TODO check authorization for this @@ -1376,7 +1376,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { * @return {@link Response} object */ @GET - @Path("/{type}/{id}/getenrolmentstatushistory") + @Path("/{type}/{id}/enrolment-status-history") public Response getCurrentEnrolmentDeviceStatusHistory(@PathParam("type") @Size(max = 45) String type, @PathParam("id") @Size(max = 45) String id) { //TODO check authorization for this or current enrolment should be based on for the enrolment associated with the user From 5275bb180eb68c9209dcca9c4a572189cdfc48ae Mon Sep 17 00:00:00 2001 From: osh Date: Wed, 29 Mar 2023 07:59:25 +0530 Subject: [PATCH 26/30] Change config implementation fixes https://roadmap.entgra.net/issues/9939 --- .../impl/DeviceManagementServiceImpl.java | 8 +++++ .../core/config/DeviceManagementConfig.java | 13 ++++---- .../guide/EnrollmentGuideConfiguration.java | 30 +++++++++++++++++++ .../DeviceManagementProviderServiceImpl.java | 2 +- .../src/main/resources/conf/cdm-config.xml | 5 +++- .../repository/conf/cdm-config.xml.j2 | 14 +++++---- 6 files changed, 59 insertions(+), 13 deletions(-) create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/enrollment/guide/EnrollmentGuideConfiguration.java diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java index a938a71860..206ed55be9 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java @@ -80,6 +80,8 @@ import org.wso2.carbon.device.mgt.common.search.PropertyMap; import org.wso2.carbon.device.mgt.common.search.SearchContext; import org.wso2.carbon.device.mgt.common.type.mgt.DeviceStatus; import org.wso2.carbon.device.mgt.core.app.mgt.ApplicationManagementProviderService; +import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager; +import org.wso2.carbon.device.mgt.core.config.DeviceManagementConfig; import org.wso2.carbon.device.mgt.core.dao.TrackerManagementDAOException; import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceDetailsMgtException; import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceInformationManager; @@ -791,6 +793,12 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { if (log.isDebugEnabled()) { log.debug("Sending enrollment invitation mail to existing user."); } + DeviceManagementConfig config = DeviceConfigurationManager.getInstance().getDeviceManagementConfig(); + if (!config.getEnrollmentGuideConfiguration().isEnabled()) { + String msg = "Sending enrollment guide config is not enabled."; + log.error(msg); + return Response.status(Response.Status.FORBIDDEN).entity(msg).build(); + } DeviceManagementProviderService dms = DeviceMgtAPIUtils.getDeviceManagementService(); try { dms.sendEnrolmentGuide(enrolmentGuide); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/DeviceManagementConfig.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/DeviceManagementConfig.java index 052bb87886..cc3a3dc5b4 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/DeviceManagementConfig.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/DeviceManagementConfig.java @@ -25,6 +25,7 @@ import org.wso2.carbon.device.mgt.core.config.cache.BillingCacheConfiguration; import org.wso2.carbon.device.mgt.core.config.cache.CertificateCacheConfiguration; import org.wso2.carbon.device.mgt.core.config.cache.DeviceCacheConfiguration; import org.wso2.carbon.device.mgt.core.config.cache.GeoFenceCacheConfiguration; +import org.wso2.carbon.device.mgt.core.config.enrollment.guide.EnrollmentGuideConfiguration; import org.wso2.carbon.device.mgt.core.config.operation.timeout.OperationTimeoutConfiguration; import org.wso2.carbon.device.mgt.core.event.config.EventOperationTaskConfiguration; import org.wso2.carbon.device.mgt.core.config.geo.location.GeoLocationConfiguration; @@ -70,7 +71,7 @@ public final class DeviceManagementConfig { private EnrollmentNotificationConfiguration enrollmentNotificationConfiguration; private DefaultRoles defaultRoles; private OperationTimeoutConfiguration operationTimeoutConfiguration; - private String enrollmentGuideMail; + private EnrollmentGuideConfiguration enrollmentGuideConfiguration; @XmlElement(name = "ManagementRepository", required = true) public DeviceManagementConfigRepository getDeviceManagementConfigRepository() { @@ -267,13 +268,13 @@ public final class DeviceManagementConfig { this.operationTimeoutConfiguration = operationTimeoutConfiguration; } - @XmlElement(name = "EnrollmentGuideMail", required = true) - public String getEnrollmentGuideMail() { - return enrollmentGuideMail; + @XmlElement(name = "EnrollmentGuideConfiguration", required = true) + public EnrollmentGuideConfiguration getEnrollmentGuideConfiguration() { + return enrollmentGuideConfiguration; } - public void setEnrollmentGuideMail(String enrollmentGuideMail) { - this.enrollmentGuideMail = enrollmentGuideMail; + public void setEnrollmentGuideConfiguration(EnrollmentGuideConfiguration enrollmentGuideConfiguration) { + this.enrollmentGuideConfiguration = enrollmentGuideConfiguration; } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/enrollment/guide/EnrollmentGuideConfiguration.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/enrollment/guide/EnrollmentGuideConfiguration.java new file mode 100644 index 0000000000..5f54cf79d4 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/enrollment/guide/EnrollmentGuideConfiguration.java @@ -0,0 +1,30 @@ +package org.wso2.carbon.device.mgt.core.config.enrollment.guide; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement(name = "EnrollmentGuideConfiguration") +public class EnrollmentGuideConfiguration { + + private boolean isEnabled; + private String mail; + + @XmlElement(name = "Enable", required = true) + public boolean isEnabled() { + return isEnabled; + } + + public void setEnabled(boolean enabled) { + isEnabled = enabled; + } + + @XmlElement(name = "Mail", required = true) + public String getMail() { + return mail; + } + + public void setMail(String mail) { + this.mail = mail; + } + +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java index 2ae6e1f7c5..6257e0b34d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java @@ -1560,7 +1560,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv public void sendEnrolmentGuide(String enrolmentGuide) throws DeviceManagementException { DeviceManagementConfig config = DeviceConfigurationManager.getInstance().getDeviceManagementConfig(); - String recipientMail = config.getEnrollmentGuideMail(); + String recipientMail = config.getEnrollmentGuideConfiguration().getMail(); Properties props = new Properties(); props.setProperty("mail-subject", "[Enrollment Guide Triggered] (#" + ++count + ")"); props.setProperty("enrollment-guide", enrolmentGuide); diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/conf/cdm-config.xml b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/conf/cdm-config.xml index 9598f16000..f0ebf0de84 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/conf/cdm-config.xml +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/conf/cdm-config.xml @@ -187,6 +187,9 @@ - support-dev-group@entgra.io + + false + Replace with mail + diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/conf_templates/templates/repository/conf/cdm-config.xml.j2 b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/conf_templates/templates/repository/conf/cdm-config.xml.j2 index 42077b0afd..09e3fad19b 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/conf_templates/templates/repository/conf/cdm-config.xml.j2 +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/conf_templates/templates/repository/conf/cdm-config.xml.j2 @@ -351,10 +351,14 @@ {% endif%} - {% if device_mgt_conf.enrollment_guide_mail is defined %} - {{device_mgt_conf.enrollment_guide_mail}} - {% else %} - support-dev-group@entgra.io - {% endif %} + + {% if device_mgt_conf.enrollment_guide_conf is defined %} + {{device_mgt_conf.enrollment_guide_conf.enable}} + {{device_mgt_conf.enrollment_guide_conf.mail}} + {% else %} + false + Replace with mail + {% endif %} + From 766606f9f793330c803efc4d863968bad5384b43 Mon Sep 17 00:00:00 2001 From: Amalka Subasinghe Date: Wed, 29 Mar 2023 22:50:08 +0530 Subject: [PATCH 27/30] added analytics extension to persist event streams,receivers,publishers --- .../pom.xml | 119 ++++++++++++ .../extension/AnalyticsArtifactsDeployer.java | 169 ++++++++++++++++++ .../extension/dto/EventPublisherData.java | 80 +++++++++ .../extension/dto/EventReceiverData.java | 81 +++++++++ .../extension/dto/EventStreamData.java | 59 ++++++ .../analytics/extension/dto/MetaData.java | 44 +++++ .../analytics/extension/dto/Property.java | 45 +++++ .../EventPublisherDeployerException.java | 43 +++++ .../EventReceiverDeployerException.java | 43 +++++ .../EventStreamDeployerException.java | 43 +++++ components/apimgt-extensions/pom.xml | 1 + .../org.wso2.carbon.device.mgt.api/pom.xml | 5 + .../DeviceEventManagementServiceImpl.java | 140 +++++++++------ .../pom.xml | 99 ++++++++++ .../src/main/resources/build.properties | 1 + .../event_publisher.xml.template | 19 ++ .../event_receiver.xml.template | 20 +++ .../event_stream.json.template | 26 +++ .../src/main/resources/p2.inf | 2 + features/apimgt-extensions/pom.xml | 1 + pom.xml | 5 + 21 files changed, 993 insertions(+), 52 deletions(-) create mode 100644 components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension/pom.xml create mode 100644 components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension/src/main/java/io/entgra/device/mgt/core/apimgt/analytics/extension/AnalyticsArtifactsDeployer.java create mode 100644 components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension/src/main/java/io/entgra/device/mgt/core/apimgt/analytics/extension/dto/EventPublisherData.java create mode 100644 components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension/src/main/java/io/entgra/device/mgt/core/apimgt/analytics/extension/dto/EventReceiverData.java create mode 100644 components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension/src/main/java/io/entgra/device/mgt/core/apimgt/analytics/extension/dto/EventStreamData.java create mode 100644 components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension/src/main/java/io/entgra/device/mgt/core/apimgt/analytics/extension/dto/MetaData.java create mode 100644 components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension/src/main/java/io/entgra/device/mgt/core/apimgt/analytics/extension/dto/Property.java create mode 100644 components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension/src/main/java/io/entgra/device/mgt/core/apimgt/analytics/extension/exception/EventPublisherDeployerException.java create mode 100644 components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension/src/main/java/io/entgra/device/mgt/core/apimgt/analytics/extension/exception/EventReceiverDeployerException.java create mode 100644 components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension/src/main/java/io/entgra/device/mgt/core/apimgt/analytics/extension/exception/EventStreamDeployerException.java create mode 100644 features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension.feature/pom.xml create mode 100644 features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension.feature/src/main/resources/build.properties create mode 100644 features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension.feature/src/main/resources/iot-analytics-templates/event_publisher.xml.template create mode 100644 features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension.feature/src/main/resources/iot-analytics-templates/event_receiver.xml.template create mode 100644 features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension.feature/src/main/resources/iot-analytics-templates/event_stream.json.template create mode 100644 features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension.feature/src/main/resources/p2.inf diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension/pom.xml b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension/pom.xml new file mode 100644 index 0000000000..4271f6a815 --- /dev/null +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension/pom.xml @@ -0,0 +1,119 @@ + + + + + apimgt-extensions + org.wso2.carbon.devicemgt + 5.0.21-SNAPSHOT + + + 4.0.0 + io.entgra.device.mgt.core.apimgt.analytics.extension + bundle + Entgra - API mgt analytics extension + http://wso2.org + + + + org.wso2.carbon + org.wso2.carbon.core + + + org.wso2.carbon + org.wso2.carbon.utils + + + org.apache.velocity + velocity + 1.7 + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + **/Abstract* + + + + + org.apache.felix + maven-scr-plugin + + + org.apache.felix + maven-bundle-plugin + true + + + ${project.artifactId} + ${project.artifactId} + ${carbon.device.mgt.version} + API Management Application Bundle + org.wso2.carbon.apimgt.application.extension.internal + + io.entgra.device.mgt.core.apimgt.analytics.extension.dto, + org.apache.velocity, + org.apache.velocity.app, + org.apache.velocity.context, + org.wso2.carbon.utils;version="[4.6,5)" + + + io.entgra.device.mgt.core.apimgt.analytics.extension.* + + + scribe;scope=compile|runtime;inline=false; + + + + + + org.jacoco + jacoco-maven-plugin + + ${basedir}/target/coverage-reports/jacoco-unit.exec + + + + jacoco-initialize + + prepare-agent + + + + jacoco-site + test + + report + + + ${basedir}/target/coverage-reports/jacoco-unit.exec + ${basedir}/target/coverage-reports/site + + + + + + + + diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension/src/main/java/io/entgra/device/mgt/core/apimgt/analytics/extension/AnalyticsArtifactsDeployer.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension/src/main/java/io/entgra/device/mgt/core/apimgt/analytics/extension/AnalyticsArtifactsDeployer.java new file mode 100644 index 0000000000..6731aaee3f --- /dev/null +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension/src/main/java/io/entgra/device/mgt/core/apimgt/analytics/extension/AnalyticsArtifactsDeployer.java @@ -0,0 +1,169 @@ +/* + * Copyright (c) 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package io.entgra.device.mgt.core.apimgt.analytics.extension; + +import io.entgra.device.mgt.core.apimgt.analytics.extension.dto.*; +import io.entgra.device.mgt.core.apimgt.analytics.extension.exception.EventPublisherDeployerException; +import io.entgra.device.mgt.core.apimgt.analytics.extension.exception.EventReceiverDeployerException; +import io.entgra.device.mgt.core.apimgt.analytics.extension.exception.EventStreamDeployerException; +import org.apache.velocity.Template; +import org.apache.velocity.VelocityContext; +import org.apache.velocity.app.VelocityEngine; + +import org.apache.velocity.runtime.RuntimeConstants; +import org.wso2.carbon.utils.CarbonUtils; +import org.wso2.carbon.utils.multitenancy.MultitenantConstants; + +import java.io.*; + +public class AnalyticsArtifactsDeployer { + + public static final String TEMPLATE_LOCATION = "repository" + File.separator + "resources" + File.separator + "io.entgra.device.mgt.core.apimgt.analytics.extension/src/main/resources/iot-analytics-templates"; + public static final String EVENT_STREAM_LOCATION = "eventstreams"; + public static final String EVENT_PUBLISHER_LOCATION = "eventpublishers"; + public static final String EVENT_RECEIVER_LOCATION = "eventreceivers"; + public static final String EVENT_STREAM_TEMPLATE = TEMPLATE_LOCATION + File.separator + "event_stream.json.template"; + public static final String EVENT_PUBLISHER_TEMPLATE = TEMPLATE_LOCATION + File.separator + "event_publisher.xml.template"; + public static final String EVENT_RECEIVER_TEMPLATE = TEMPLATE_LOCATION + File.separator + "event_receiver.xml.template"; + + + public void deployEventStream(EventStreamData eventStreamData, int tenantId) throws EventStreamDeployerException { + try { + VelocityEngine ve = new VelocityEngine(); + ve.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, CarbonUtils.getCarbonHome()); + ve.init(); + Template template = ve.getTemplate(EVENT_STREAM_TEMPLATE); + + VelocityContext context = populateContextForEventStreams(eventStreamData); + StringWriter writer = new StringWriter(); + template.merge(context, writer); + + String fileName = eventStreamData.getName() + "_" + eventStreamData.getVersion() + ".json"; + String fileLocation = null; + if (MultitenantConstants.SUPER_TENANT_ID == tenantId) { + fileLocation = CarbonUtils.getCarbonHome() + File.separator + "repository" + File.separator + "deployment" + + File.separator + "server" + File.separator + EVENT_STREAM_LOCATION + File.separator + fileName; + } else { + fileLocation = CarbonUtils.getCarbonTenantsDirPath() + File.separator + tenantId + File.separator + + EVENT_STREAM_LOCATION + File.separator + fileName; + } + + PrintWriter printWriter = new PrintWriter(fileLocation, "UTF-8"); + printWriter.println(writer.toString()); + printWriter.close(); + } catch (FileNotFoundException | UnsupportedEncodingException e) { + throw new EventStreamDeployerException("Error while persisting event stream definition ", e); + } + } + + public void deployEventPublisher(EventPublisherData eventPublisherData, int tenantId) throws EventPublisherDeployerException { + try { + VelocityEngine ve = new VelocityEngine(); + ve.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, CarbonUtils.getCarbonHome()); + ve.init(); + Template template = ve.getTemplate(EVENT_PUBLISHER_TEMPLATE); + + VelocityContext context = populateContextForEventPublisher(eventPublisherData); + StringWriter writer = new StringWriter(); + template.merge(context, writer); + + String fileName = eventPublisherData.getName() + ".xml"; + String fileLocation = null; + if (MultitenantConstants.SUPER_TENANT_ID == tenantId) { + fileLocation = CarbonUtils.getCarbonHome() + File.separator + "repository" + File.separator + "deployment" + + File.separator + "server" + File.separator + EVENT_PUBLISHER_LOCATION + File.separator + fileName; + } else { + fileLocation = CarbonUtils.getCarbonTenantsDirPath() + File.separator + tenantId + File.separator + + EVENT_PUBLISHER_LOCATION + File.separator + fileName; + } + + PrintWriter printWriter = new PrintWriter(fileLocation, "UTF-8"); + printWriter.println(writer.toString()); + printWriter.close(); + } catch (FileNotFoundException | UnsupportedEncodingException e) { + throw new EventPublisherDeployerException("Error while persisting rdbms event publisher ", e); + } + } + + public void deployEventReceiver(EventReceiverData eventReceiverData, int tenantId) throws EventReceiverDeployerException { + try { + VelocityEngine ve = new VelocityEngine(); + ve.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, CarbonUtils.getCarbonHome()); + ve.init(); + Template template = ve.getTemplate(EVENT_RECEIVER_TEMPLATE); + + VelocityContext context = populateContextForEventReceiver(eventReceiverData); + StringWriter writer = new StringWriter(); + template.merge(context, writer); + + String fileName = eventReceiverData.getName() + ".xml"; + String fileLocation = null; + if (MultitenantConstants.SUPER_TENANT_ID == tenantId) { + fileLocation = CarbonUtils.getCarbonHome() + File.separator + "repository" + File.separator + "deployment" + + File.separator + "server" + File.separator + EVENT_RECEIVER_LOCATION + File.separator + fileName; + } else { + fileLocation = CarbonUtils.getCarbonTenantsDirPath() + File.separator + tenantId + File.separator + + EVENT_RECEIVER_LOCATION + File.separator + fileName; + } + + PrintWriter printWriter = new PrintWriter(fileLocation, "UTF-8"); + printWriter.println(writer.toString()); + printWriter.close(); + } catch (FileNotFoundException | UnsupportedEncodingException e) { + throw new EventReceiverDeployerException("Error while persisting oauth mqtt event receiver ", e); + } + } + + private VelocityContext populateContextForEventStreams(EventStreamData eventStreamData) { + VelocityContext context = new VelocityContext(); + context.put("name", eventStreamData.getName()); + context.put("version", eventStreamData.getVersion()); + context.put("metaData", + eventStreamData.getMetaData() != null ? eventStreamData.getMetaData() : new MetaData("deviceId", "STRING")); + if (eventStreamData.getPayloadData() != null) { + context.put("properties", eventStreamData.getPayloadData()); + } + return context; + } + + private VelocityContext populateContextForEventPublisher(EventPublisherData eventPublisherData) { + VelocityContext context = new VelocityContext(); + + context.put("name", eventPublisherData.getName()); + context.put("streamName", eventPublisherData.getStreamName()); + context.put("streamVersion", eventPublisherData.getStreamVersion()); + context.put("properties", eventPublisherData.getPropertyList()); + context.put("eventAdapterType", eventPublisherData.getEventAdaptorType()); + context.put("customMappingType", eventPublisherData.getCustomMappingType()); + + return context; + } + + private VelocityContext populateContextForEventReceiver(EventReceiverData eventReceiverData) { + VelocityContext context = new VelocityContext(); + + context.put("name", eventReceiverData.getName()); + context.put("streamName", eventReceiverData.getStreamName()); + context.put("streamVersion", eventReceiverData.getStreamVersion()); + context.put("properties", eventReceiverData.getPropertyList()); + context.put("eventAdapterType", eventReceiverData.getEventAdapterType()); + context.put("customMappingType", eventReceiverData.getCustomMappingType()); + + return context; + } +} diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension/src/main/java/io/entgra/device/mgt/core/apimgt/analytics/extension/dto/EventPublisherData.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension/src/main/java/io/entgra/device/mgt/core/apimgt/analytics/extension/dto/EventPublisherData.java new file mode 100644 index 0000000000..6d1620a5b9 --- /dev/null +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension/src/main/java/io/entgra/device/mgt/core/apimgt/analytics/extension/dto/EventPublisherData.java @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package io.entgra.device.mgt.core.apimgt.analytics.extension.dto; + +import java.util.List; + +public class EventPublisherData { + private String name; + private String streamVersion; + private String streamName; + + private List propertyList; + + private String eventAdaptorType; + + private String customMappingType; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getStreamVersion() { + return streamVersion; + } + + public void setStreamVersion(String streamVersion) { + this.streamVersion = streamVersion; + } + + public String getStreamName() { + return streamName; + } + + public void setStreamName(String streamName) { + this.streamName = streamName; + } + + public List getPropertyList() { + return propertyList; + } + + public void setPropertyList(List propertyList) { + this.propertyList = propertyList; + } + + public String getEventAdaptorType() { + return eventAdaptorType; + } + + public void setEventAdaptorType(String eventAdaptorType) { + this.eventAdaptorType = eventAdaptorType; + } + + public String getCustomMappingType() { + return customMappingType; + } + + public void setCustomMappingType(String customMappingType) { + this.customMappingType = customMappingType; + } +} diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension/src/main/java/io/entgra/device/mgt/core/apimgt/analytics/extension/dto/EventReceiverData.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension/src/main/java/io/entgra/device/mgt/core/apimgt/analytics/extension/dto/EventReceiverData.java new file mode 100644 index 0000000000..764229c55a --- /dev/null +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension/src/main/java/io/entgra/device/mgt/core/apimgt/analytics/extension/dto/EventReceiverData.java @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package io.entgra.device.mgt.core.apimgt.analytics.extension.dto; + +import java.util.List; + +public class EventReceiverData { + + private String name; + private String streamVersion; + private String streamName; + + private String eventAdapterType; + + List propertyList; + + private String customMappingType; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getStreamVersion() { + return streamVersion; + } + + public void setStreamVersion(String streamVersion) { + this.streamVersion = streamVersion; + } + + public String getStreamName() { + return streamName; + } + + public void setStreamName(String streamName) { + this.streamName = streamName; + } + + public String getEventAdapterType() { + return eventAdapterType; + } + + public void setEventAdapterType(String eventAdapterType) { + this.eventAdapterType = eventAdapterType; + } + + public List getPropertyList() { + return propertyList; + } + + public void setPropertyList(List propertyList) { + this.propertyList = propertyList; + } + + public String getCustomMappingType() { + return customMappingType; + } + + public void setCustomMappingType(String customMappingType) { + this.customMappingType = customMappingType; + } +} diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension/src/main/java/io/entgra/device/mgt/core/apimgt/analytics/extension/dto/EventStreamData.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension/src/main/java/io/entgra/device/mgt/core/apimgt/analytics/extension/dto/EventStreamData.java new file mode 100644 index 0000000000..a80520bef4 --- /dev/null +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension/src/main/java/io/entgra/device/mgt/core/apimgt/analytics/extension/dto/EventStreamData.java @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package io.entgra.device.mgt.core.apimgt.analytics.extension.dto; + +import java.util.List; + +public class EventStreamData { + private String name; + private String version; + private MetaData metaData; + private List payloadData; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + public MetaData getMetaData() { + return metaData; + } + + public void setMetaData(MetaData metaData) { + this.metaData = metaData; + } + + public List getPayloadData() { + return payloadData; + } + + public void setPayloadData(List payloadData) { + this.payloadData = payloadData; + } +} diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension/src/main/java/io/entgra/device/mgt/core/apimgt/analytics/extension/dto/MetaData.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension/src/main/java/io/entgra/device/mgt/core/apimgt/analytics/extension/dto/MetaData.java new file mode 100644 index 0000000000..ba77d04413 --- /dev/null +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension/src/main/java/io/entgra/device/mgt/core/apimgt/analytics/extension/dto/MetaData.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package io.entgra.device.mgt.core.apimgt.analytics.extension.dto; + +public class MetaData { + String name; + String type; + + public MetaData(String name, String type){ + this.setName(name); + this.setType(type); + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } +} diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension/src/main/java/io/entgra/device/mgt/core/apimgt/analytics/extension/dto/Property.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension/src/main/java/io/entgra/device/mgt/core/apimgt/analytics/extension/dto/Property.java new file mode 100644 index 0000000000..995cf2c5a8 --- /dev/null +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension/src/main/java/io/entgra/device/mgt/core/apimgt/analytics/extension/dto/Property.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package io.entgra.device.mgt.core.apimgt.analytics.extension.dto; + +public class Property { + String name; + String value; + + public Property(String name, String value){ + this.setName(name); + this.setValue(value); + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } +} diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension/src/main/java/io/entgra/device/mgt/core/apimgt/analytics/extension/exception/EventPublisherDeployerException.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension/src/main/java/io/entgra/device/mgt/core/apimgt/analytics/extension/exception/EventPublisherDeployerException.java new file mode 100644 index 0000000000..2f924d0e7b --- /dev/null +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension/src/main/java/io/entgra/device/mgt/core/apimgt/analytics/extension/exception/EventPublisherDeployerException.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package io.entgra.device.mgt.core.apimgt.analytics.extension.exception; + +public class EventPublisherDeployerException extends Exception { + + private static final long serialVersionUID = -3151279311929070299L; + + public EventPublisherDeployerException(String msg, Exception nestedEx) { + super(msg, nestedEx); + } + + public EventPublisherDeployerException(String message, Throwable cause) { + super(message, cause); + } + + public EventPublisherDeployerException(String msg) { + super(msg); + } + + public EventPublisherDeployerException() { + super(); + } + + public EventPublisherDeployerException(Throwable cause) { + super(cause); + } +} diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension/src/main/java/io/entgra/device/mgt/core/apimgt/analytics/extension/exception/EventReceiverDeployerException.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension/src/main/java/io/entgra/device/mgt/core/apimgt/analytics/extension/exception/EventReceiverDeployerException.java new file mode 100644 index 0000000000..3e0d49e088 --- /dev/null +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension/src/main/java/io/entgra/device/mgt/core/apimgt/analytics/extension/exception/EventReceiverDeployerException.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package io.entgra.device.mgt.core.apimgt.analytics.extension.exception; + +public class EventReceiverDeployerException extends Exception { + + private static final long serialVersionUID = -3151279311929070299L; + + public EventReceiverDeployerException(String msg, Exception nestedEx) { + super(msg, nestedEx); + } + + public EventReceiverDeployerException(String message, Throwable cause) { + super(message, cause); + } + + public EventReceiverDeployerException(String msg) { + super(msg); + } + + public EventReceiverDeployerException() { + super(); + } + + public EventReceiverDeployerException(Throwable cause) { + super(cause); + } +} diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension/src/main/java/io/entgra/device/mgt/core/apimgt/analytics/extension/exception/EventStreamDeployerException.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension/src/main/java/io/entgra/device/mgt/core/apimgt/analytics/extension/exception/EventStreamDeployerException.java new file mode 100644 index 0000000000..1bba4c8cfe --- /dev/null +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension/src/main/java/io/entgra/device/mgt/core/apimgt/analytics/extension/exception/EventStreamDeployerException.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package io.entgra.device.mgt.core.apimgt.analytics.extension.exception; + +public class EventStreamDeployerException extends Exception { + + private static final long serialVersionUID = -3151279311929070298L; + + public EventStreamDeployerException(String msg, Exception nestedEx) { + super(msg, nestedEx); + } + + public EventStreamDeployerException(String message, Throwable cause) { + super(message, cause); + } + + public EventStreamDeployerException(String msg) { + super(msg); + } + + public EventStreamDeployerException() { + super(); + } + + public EventStreamDeployerException(Throwable cause) { + super(cause); + } +} diff --git a/components/apimgt-extensions/pom.xml b/components/apimgt-extensions/pom.xml index ba99795a04..f2426c980f 100644 --- a/components/apimgt-extensions/pom.xml +++ b/components/apimgt-extensions/pom.xml @@ -39,6 +39,7 @@ org.wso2.carbon.apimgt.annotations org.wso2.carbon.apimgt.keymgt.extension org.wso2.carbon.apimgt.keymgt.extension.api + io.entgra.device.mgt.core.apimgt.analytics.extension diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.api/pom.xml index f43128fc6c..f552c5aebf 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/pom.xml @@ -450,5 +450,10 @@ org.wso2.carbon.event.output.adapter.rdbms provided + + org.wso2.carbon.devicemgt + io.entgra.device.mgt.core.apimgt.analytics.extension + provided +
\ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceEventManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceEventManagementServiceImpl.java index 49cbdae59a..23be4d88eb 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceEventManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceEventManagementServiceImpl.java @@ -1,30 +1,20 @@ package org.wso2.carbon.device.mgt.jaxrs.service.impl; -import edu.emory.mathcs.backport.java.util.Arrays; +import io.entgra.device.mgt.core.apimgt.analytics.extension.AnalyticsArtifactsDeployer; +import io.entgra.device.mgt.core.apimgt.analytics.extension.dto.*; +import io.entgra.device.mgt.core.apimgt.analytics.extension.exception.EventReceiverDeployerException; +import io.entgra.device.mgt.core.apimgt.analytics.extension.exception.EventPublisherDeployerException; +import io.entgra.device.mgt.core.apimgt.analytics.extension.exception.EventStreamDeployerException; import org.apache.axis2.AxisFault; import org.apache.axis2.client.Stub; import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.http.HttpResponse; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.entity.ContentType; -import org.apache.http.entity.StringEntity; -import org.apache.velocity.util.ArrayListWrapper; -import org.json.JSONObject; -import org.opensaml.xml.signature.J; -import org.wso2.carbon.analytics.stream.persistence.stub.EventStreamPersistenceAdminService; -import org.wso2.carbon.analytics.stream.persistence.stub.EventStreamPersistenceAdminServiceEventStreamPersistenceAdminServiceExceptionException; -import org.wso2.carbon.analytics.stream.persistence.stub.EventStreamPersistenceAdminServiceStub; -import org.wso2.carbon.analytics.stream.persistence.stub.dto.AnalyticsTable; -import org.wso2.carbon.analytics.stream.persistence.stub.dto.AnalyticsTableRecord; import org.wso2.carbon.base.MultitenantConstants; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.databridge.commons.StreamDefinition; import org.wso2.carbon.databridge.commons.exception.MalformedStreamDefinitionException; import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; -import org.wso2.carbon.device.mgt.core.dto.DeviceType; -import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.Attribute; import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.AttributeType; import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.DeviceTypeEvent; @@ -34,24 +24,16 @@ import org.wso2.carbon.device.mgt.jaxrs.service.api.DeviceEventManagementService import org.wso2.carbon.device.mgt.jaxrs.util.Constants; import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils; import org.wso2.carbon.event.input.adapter.core.InputEventAdapterConfiguration; -import org.wso2.carbon.event.input.adapter.core.MessageType; import org.wso2.carbon.event.output.adapter.core.OutputEventAdapterConfiguration; -import org.wso2.carbon.event.output.adapter.core.OutputEventAdapterService; -import org.wso2.carbon.event.output.adapter.rdbms.RDBMSEventAdapter; -import org.wso2.carbon.event.output.adapter.rdbms.internal.ds.RDBMSEventAdapterServiceDS; -import org.wso2.carbon.event.processor.manager.core.EventProcessorManagementService; -import org.wso2.carbon.event.processor.manager.core.EventPublisherManagementService; import org.wso2.carbon.event.publisher.core.EventPublisherService; import org.wso2.carbon.event.publisher.core.config.EventPublisherConfiguration; import org.wso2.carbon.event.publisher.core.config.mapping.JSONOutputMapping; import org.wso2.carbon.event.publisher.core.config.mapping.MapOutputMapping; import org.wso2.carbon.event.publisher.core.exception.EventPublisherConfigurationException; -import org.wso2.carbon.event.publisher.core.internal.ds.EventPublisherServiceDS; import org.wso2.carbon.event.publisher.stub.EventPublisherAdminServiceCallbackHandler; import org.wso2.carbon.event.publisher.stub.EventPublisherAdminServiceStub; import org.wso2.carbon.event.receiver.core.EventReceiverService; import org.wso2.carbon.event.receiver.core.config.EventReceiverConfiguration; -import org.wso2.carbon.event.receiver.core.config.InputMapping; import org.wso2.carbon.event.receiver.core.config.mapping.JSONInputMapping; import org.wso2.carbon.event.receiver.core.config.mapping.WSO2EventInputMapping; import org.wso2.carbon.event.receiver.core.exception.EventReceiverConfigurationException; @@ -59,7 +41,6 @@ import org.wso2.carbon.event.receiver.stub.EventReceiverAdminServiceCallbackHand import org.wso2.carbon.event.receiver.stub.EventReceiverAdminServiceStub; import org.wso2.carbon.event.receiver.stub.types.BasicInputAdapterPropertyDto; import org.wso2.carbon.event.receiver.stub.types.EventReceiverConfigurationDto; -import org.wso2.carbon.event.receiver.stub.types.InputAdapterConfigurationDto; import org.wso2.carbon.event.stream.core.EventStreamService; import org.wso2.carbon.event.stream.core.exception.EventStreamConfigurationException; import org.wso2.carbon.event.stream.stub.EventStreamAdminServiceStub; @@ -71,7 +52,6 @@ import org.wso2.carbon.user.api.UserStoreException; import javax.validation.Valid; import javax.ws.rs.*; import javax.ws.rs.core.Response; -import java.io.IOException; import java.rmi.RemoteException; import java.util.ArrayList; import java.util.HashMap; @@ -225,6 +205,7 @@ public class DeviceEventManagementServiceImpl implements DeviceEventManagementSe String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(); + int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); try { for (DeviceTypeEvent deviceTypeEvent : deviceTypeEvents) { TransportType transportType = deviceTypeEvent.getTransportType(); @@ -239,46 +220,101 @@ public class DeviceEventManagementServiceImpl implements DeviceEventManagementSe log.error(errorMessage); return Response.status(Response.Status.BAD_REQUEST).build(); } + // event stream String streamName = DeviceMgtAPIUtils.getStreamDefinition(deviceType, tenantDomain, eventName); - publishStreamDefinitons(streamName, Constants.DEFAULT_STREAM_VERSION, eventAttributes); - + AnalyticsArtifactsDeployer artifactsDeployer = new AnalyticsArtifactsDeployer(); + List props = new ArrayList<>(); + for (Attribute attribute : eventAttributes.getList()) { + props.add(new Property(attribute.getName(), attribute.getType().name())); + } + EventStreamData eventStreamData = new EventStreamData(); + eventStreamData.setName(streamName); + eventStreamData.setVersion(Constants.DEFAULT_STREAM_VERSION); + eventStreamData.setMetaData(new MetaData(DEFAULT_DEVICE_ID_ATTRIBUTE, "STRING")); + eventStreamData.setPayloadData(props); + artifactsDeployer.deployEventStream(eventStreamData, tenantId); + + // event receiver String receiverName = getReceiverName(deviceType, tenantDomain, transportType, eventName); - publishEventReceivers(streamName, Constants.DEFAULT_STREAM_VERSION, transportType, tenantDomain, - isSharedWithAllTenants, deviceType, deviceTypeEvent.getEventTopicStructure(), receiverName); + EventReceiverData receiverData = new EventReceiverData(); + receiverData.setName(receiverName); + receiverData.setStreamName(streamName); + receiverData.setStreamVersion(Constants.DEFAULT_STREAM_VERSION); + List propertyList = new ArrayList<>(); + if (transportType == TransportType.MQTT) { + receiverData.setEventAdapterType(OAUTH_MQTT_ADAPTER_TYPE); + propertyList.add(new Property(MQTT_CONTENT_TRANSFORMER_TYPE, MQTT_CONTENT_TRANSFORMER)); + propertyList.add(new Property(MQTT_CONTENT_VALIDATOR_TYPE, MQTT_CONTENT_VALIDATOR)); + String topic; + if (!StringUtils.isEmpty(deviceTypeEvent.getEventTopicStructure())) { + if (isSharedWithAllTenants) { + topic = deviceTypeEvent.getEventTopicStructure().replace("${deviceId}", "+") + .replace("${deviceType}", deviceType) + .replace("${tenantDomain}", "+"); + } else { + topic = deviceTypeEvent.getEventTopicStructure().replace("${deviceId}", "+") + .replace("${deviceType}", deviceType) + .replace("${tenantDomain}", tenantDomain); + } + } else { + if (isSharedWithAllTenants) { + topic = "+/" + deviceType + "/+/events"; + } else { + topic = tenantDomain + "/" + deviceType + "/+/events"; + } + } + propertyList.add(new Property("topic", topic)); + receiverData.setCustomMappingType("json"); + + } else { + receiverData.setEventAdapterType(THRIFT_ADAPTER_TYPE); + propertyList.add(new Property("events.duplicated.in.cluster", "false")); + receiverData.setCustomMappingType("wso2event"); + } + receiverData.setPropertyList(propertyList); + artifactsDeployer.deployEventReceiver(receiverData, tenantId); + if (!skipPersist) { + // rdbms event publisher String rdbmsPublisherName = getPublisherName(deviceType, tenantDomain, eventName) + "_rdbms_publisher"; - publishEventStore(streamName, Constants.DEFAULT_STREAM_VERSION, rdbmsPublisherName); + + EventPublisherData eventPublisherData = new EventPublisherData(); + eventPublisherData.setName(rdbmsPublisherName); + eventPublisherData.setStreamName(streamName); + eventPublisherData.setStreamVersion(Constants.DEFAULT_STREAM_VERSION); + eventPublisherData.setEventAdaptorType("rdbms"); + eventPublisherData.setCustomMappingType("map"); + List publisherProps = new ArrayList<>(); + publisherProps.add(new Property("datasource.name", "EVENT_DB")); + publisherProps.add(new Property("table.name", "table_" + rdbmsPublisherName.replace(".", ""))); + publisherProps.add(new Property("execution.mode", "insert")); + eventPublisherData.setPropertyList(publisherProps); + artifactsDeployer.deployEventPublisher(eventPublisherData, tenantId); } + + // web socket event publisher String wsPublisherName = getPublisherName(deviceType, tenantDomain, eventName) + "_ws_publisher"; - publishWebsocketPublisherDefinition(streamName, Constants.DEFAULT_STREAM_VERSION, wsPublisherName); - try { - PrivilegedCarbonContext.startTenantFlow(); - PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain( - MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, true); - if (!MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(tenantDomain)) { - publishStreamDefinitons(streamName, Constants.DEFAULT_STREAM_VERSION, eventAttributes); - publishEventReceivers(streamName, Constants.DEFAULT_STREAM_VERSION, transportType, tenantDomain, - isSharedWithAllTenants, deviceType, deviceTypeEvent.getEventTopicStructure(), receiverName); - } - } finally { - PrivilegedCarbonContext.endTenantFlow(); - } + EventPublisherData wsEventPublisherData = new EventPublisherData(); + wsEventPublisherData.setName(wsPublisherName); + wsEventPublisherData.setStreamName(streamName); + wsEventPublisherData.setStreamVersion(Constants.DEFAULT_STREAM_VERSION); + wsEventPublisherData.setEventAdaptorType("websocket-local"); + wsEventPublisherData.setCustomMappingType("json"); + artifactsDeployer.deployEventPublisher(wsEventPublisherData, tenantId); + } return Response.ok().build(); } catch (DeviceManagementException e) { log.error("Failed to access device management service, tenantDomain: " + tenantDomain, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); - } catch (MalformedStreamDefinitionException e) { - log.error("Failed while creating stream definition, tenantDomain: " + tenantDomain, e); + } catch (EventStreamDeployerException e) { + log.error("Failed while deploying event stream definition, tenantDomain: " + tenantDomain, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); - } catch (EventStreamConfigurationException e) { - log.error("Failed while configuring stream definition, tenantDomain: " + tenantDomain, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); - } catch (EventPublisherConfigurationException e) { - log.error("Failed while configuring event publisher, tenantDomain: " + tenantDomain, e); + } catch (EventPublisherDeployerException e) { + log.error("Failed while deploying event publisher, tenantDomain: " + tenantDomain, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); - } catch (EventReceiverConfigurationException e) { - log.error("Failed while configuring event receiver, tenantDomain: " + tenantDomain, e); + } catch (EventReceiverDeployerException e) { + log.error("Failed while deploying event receiver, tenantDomain: " + tenantDomain, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); } } diff --git a/features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension.feature/pom.xml b/features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension.feature/pom.xml new file mode 100644 index 0000000000..0446649036 --- /dev/null +++ b/features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension.feature/pom.xml @@ -0,0 +1,99 @@ + + + + + org.wso2.carbon.devicemgt + apimgt-extensions-feature + 5.0.21-SNAPSHOT + ../pom.xml + + + 4.0.0 + io.entgra.device.mgt.core.apimgt.analytics.extension.feature + pom + Entgra - APIM Analytics Extension Feature + http://entgra.io + + + + org.wso2.carbon.devicemgt + io.entgra.device.mgt.core.apimgt.analytics.extension + + + + + + + maven-resources-plugin + 2.6 + + + copy-resources + generate-resources + + copy-resources + + + src/main/resources + + + resources + + build.properties + p2.inf + + + + + + + + + org.wso2.maven + carbon-p2-plugin + ${carbon.p2.plugin.version} + + + p2-feature-generation + package + + p2-feature-gen + + + io.entgra.device.mgt.core.apimgt.analytics.extension + ../../../features/etc/feature.properties + + + org.wso2.carbon.p2.category.type:server + org.eclipse.equinox.p2.type.group:true + + + + + org.wso2.carbon.devicemgt:io.entgra.device.mgt.core.apimgt.analytics.extension:${carbon.device.mgt.version} + + + + + + + + + + diff --git a/features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension.feature/src/main/resources/build.properties b/features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension.feature/src/main/resources/build.properties new file mode 100644 index 0000000000..93c4b10701 --- /dev/null +++ b/features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension.feature/src/main/resources/build.properties @@ -0,0 +1 @@ +custom = true \ No newline at end of file diff --git a/features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension.feature/src/main/resources/iot-analytics-templates/event_publisher.xml.template b/features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension.feature/src/main/resources/iot-analytics-templates/event_publisher.xml.template new file mode 100644 index 0000000000..b103c8d1ac --- /dev/null +++ b/features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension.feature/src/main/resources/iot-analytics-templates/event_publisher.xml.template @@ -0,0 +1,19 @@ + + + + + + + #foreach( $property in $properties ) + ${property.value} + #end + + \ No newline at end of file diff --git a/features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension.feature/src/main/resources/iot-analytics-templates/event_receiver.xml.template b/features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension.feature/src/main/resources/iot-analytics-templates/event_receiver.xml.template new file mode 100644 index 0000000000..c9b90877f0 --- /dev/null +++ b/features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension.feature/src/main/resources/iot-analytics-templates/event_receiver.xml.template @@ -0,0 +1,20 @@ + + + + + #foreach( $property in $properties ) + ${property.value} + #end + + + + \ No newline at end of file diff --git a/features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension.feature/src/main/resources/iot-analytics-templates/event_stream.json.template b/features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension.feature/src/main/resources/iot-analytics-templates/event_stream.json.template new file mode 100644 index 0000000000..5f0b85ad3b --- /dev/null +++ b/features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension.feature/src/main/resources/iot-analytics-templates/event_stream.json.template @@ -0,0 +1,26 @@ +{ + "streamId": "$name:$version", + "name": "$name", + "version": "$version", + "nickName": "", + "description": "", + "metaData": [ + { + "name": "${metaData.name}", + "type": "${metaData.type}" + } + ], + "correlationData": [], + "payloadData": [ +#foreach( $property in $properties ) + { + "name": "${property.name}", + "type": "${property.value}" + }, +#end + { + "name": "ts", + "type": "LONG" + } + ] +} \ No newline at end of file diff --git a/features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension.feature/src/main/resources/p2.inf b/features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension.feature/src/main/resources/p2.inf new file mode 100644 index 0000000000..7c46f1cafc --- /dev/null +++ b/features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension.feature/src/main/resources/p2.inf @@ -0,0 +1,2 @@ +instructions.configure = \ +org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/io.entgra.device.mgt.core.apimgt.analytics.extension_${feature.version}/iot-analytics-templates/,target:${installFolder}/../../resources/,overwrite:true);\ diff --git a/features/apimgt-extensions/pom.xml b/features/apimgt-extensions/pom.xml index 45a706e7a9..ecb17f4c15 100644 --- a/features/apimgt-extensions/pom.xml +++ b/features/apimgt-extensions/pom.xml @@ -37,6 +37,7 @@ org.wso2.carbon.apimgt.webapp.publisher.feature org.wso2.carbon.apimgt.application.extension.feature org.wso2.carbon.apimgt.keymgt.extension.feature + io.entgra.device.mgt.core.apimgt.analytics.extension.feature diff --git a/pom.xml b/pom.xml index 09590375ba..978a200b23 100644 --- a/pom.xml +++ b/pom.xml @@ -284,6 +284,11 @@ org.wso2.carbon.apimgt.application.extension ${carbon.device.mgt.version} + + org.wso2.carbon.devicemgt + io.entgra.device.mgt.core.apimgt.analytics.extension + ${carbon.device.mgt.version} + org.wso2.carbon.devicemgt org.wso2.carbon.identity.jwt.client.extension From 5da3df3984e88a60887a1addf1b79a93c260c9ca Mon Sep 17 00:00:00 2001 From: Amalka Subasinghe Date: Wed, 29 Mar 2023 22:56:22 +0530 Subject: [PATCH 28/30] fixed template location --- .../extension/AnalyticsArtifactsDeployer.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension/src/main/java/io/entgra/device/mgt/core/apimgt/analytics/extension/AnalyticsArtifactsDeployer.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension/src/main/java/io/entgra/device/mgt/core/apimgt/analytics/extension/AnalyticsArtifactsDeployer.java index 6731aaee3f..fcd197bb0e 100644 --- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension/src/main/java/io/entgra/device/mgt/core/apimgt/analytics/extension/AnalyticsArtifactsDeployer.java +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension/src/main/java/io/entgra/device/mgt/core/apimgt/analytics/extension/AnalyticsArtifactsDeployer.java @@ -17,7 +17,10 @@ */ package io.entgra.device.mgt.core.apimgt.analytics.extension; -import io.entgra.device.mgt.core.apimgt.analytics.extension.dto.*; +import io.entgra.device.mgt.core.apimgt.analytics.extension.dto.EventPublisherData; +import io.entgra.device.mgt.core.apimgt.analytics.extension.dto.EventReceiverData; +import io.entgra.device.mgt.core.apimgt.analytics.extension.dto.EventStreamData; +import io.entgra.device.mgt.core.apimgt.analytics.extension.dto.MetaData; import io.entgra.device.mgt.core.apimgt.analytics.extension.exception.EventPublisherDeployerException; import io.entgra.device.mgt.core.apimgt.analytics.extension.exception.EventReceiverDeployerException; import io.entgra.device.mgt.core.apimgt.analytics.extension.exception.EventStreamDeployerException; @@ -29,11 +32,15 @@ import org.apache.velocity.runtime.RuntimeConstants; import org.wso2.carbon.utils.CarbonUtils; import org.wso2.carbon.utils.multitenancy.MultitenantConstants; -import java.io.*; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.io.UnsupportedEncodingException; public class AnalyticsArtifactsDeployer { - public static final String TEMPLATE_LOCATION = "repository" + File.separator + "resources" + File.separator + "io.entgra.device.mgt.core.apimgt.analytics.extension/src/main/resources/iot-analytics-templates"; + public static final String TEMPLATE_LOCATION = "repository" + File.separator + "resources" + File.separator + "iot-analytics-templates"; public static final String EVENT_STREAM_LOCATION = "eventstreams"; public static final String EVENT_PUBLISHER_LOCATION = "eventpublishers"; public static final String EVENT_RECEIVER_LOCATION = "eventreceivers"; From 3c13196aa527bab931865b79257b8fcc254e03b4 Mon Sep 17 00:00:00 2001 From: Amalka Subasinghe Date: Wed, 29 Mar 2023 23:07:39 +0530 Subject: [PATCH 29/30] fixed feature installation issue --- .../src/main/resources/p2.inf | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension.feature/src/main/resources/p2.inf b/features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension.feature/src/main/resources/p2.inf index 7c46f1cafc..235bd0424c 100644 --- a/features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension.feature/src/main/resources/p2.inf +++ b/features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension.feature/src/main/resources/p2.inf @@ -1,2 +1,3 @@ instructions.configure = \ -org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/io.entgra.device.mgt.core.apimgt.analytics.extension_${feature.version}/iot-analytics-templates/,target:${installFolder}/../../resources/,overwrite:true);\ +org.eclipse.equinox.p2.touchpoint.natives.mkdir(path:${installFolder}/../../../repository/resources/iot-analytics-templates);\ +org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/io.entgra.device.mgt.core.apimgt.analytics.extension_${feature.version}/iot-analytics-templates/,target:${installFolder}/../../resources/iot-analytics-templates/,overwrite:true);\ From 19750486dec1d3dc3a414a9be23eef02b9a88ce3 Mon Sep 17 00:00:00 2001 From: Thashmi-nil Date: Thu, 30 Mar 2023 23:20:15 +0530 Subject: [PATCH 30/30] Add improvements --- .../carbon/device/mgt/core/config/ui/HubspotChat.java | 9 --------- .../src/main/resources/conf/mdm-ui-config.xml | 1 - 2 files changed, 10 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/ui/HubspotChat.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/ui/HubspotChat.java index 728176e1db..ec22d125a1 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/ui/HubspotChat.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/ui/HubspotChat.java @@ -25,7 +25,6 @@ public class HubspotChat { private String trackingUrl; private String accessToken; private String senderActorId; - private long channelAccountId; @XmlElement(name = "EnableHubspot") public boolean isEnableHubspot() { @@ -61,12 +60,4 @@ public class HubspotChat { public void setSenderActorId(String senderActorId) { this.senderActorId = senderActorId; } - @XmlElement(name = "ChannelAccountId") - public long getChannelAccountId() { - return channelAccountId; - } - - public void setChannelAccountId(long channelAccountId) { - this.channelAccountId = channelAccountId; - } } diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/conf/mdm-ui-config.xml b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/conf/mdm-ui-config.xml index 4867c665c0..1c33bddfdb 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/conf/mdm-ui-config.xml +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/conf/mdm-ui-config.xml @@ -31,7 +31,6 @@ access_token sender_actorId - channel_AccountId false