From 1404f573e2b2acd89f5a241c3e6ca78ee289e32f Mon Sep 17 00:00:00 2001 From: pasindu Date: Tue, 30 May 2023 16:26:36 +0530 Subject: [PATCH 1/8] Make separate feature for apim rest api component --- .../pom.xml | 1 - .../pom.xml | 108 ++++++++++++++++++ .../src/main/resources/build.properties | 1 + .../src/main/resources/p2.inf | 1 + .../pom.xml | 7 -- features/apimgt-extensions/pom.xml | 1 + 6 files changed, 111 insertions(+), 8 deletions(-) create mode 100644 features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api.feature/pom.xml create mode 100644 features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api.feature/src/main/resources/build.properties create mode 100644 features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api.feature/src/main/resources/p2.inf diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/pom.xml b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/pom.xml index 1ad6ba33e4..49358b6f62 100644 --- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/pom.xml +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/pom.xml @@ -125,7 +125,6 @@ io.entgra.device.mgt.core io.entgra.device.mgt.core.apimgt.extension.rest.api - provided org.json.wso2 diff --git a/features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api.feature/pom.xml b/features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api.feature/pom.xml new file mode 100644 index 0000000000..1e98e6a341 --- /dev/null +++ b/features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api.feature/pom.xml @@ -0,0 +1,108 @@ + + + + + + + io.entgra.device.mgt.core + apimgt-extensions-feature + 5.0.26-SNAPSHOT + ../pom.xml + + + 4.0.0 + io.entgra.device.mgt.core.apimgt.extension.rest.api.feature + pom + Entgra - API management REST API feature + This feature contains an implementation of API manager REST API extension + http://entgra.io + + + + io.entgra.device.mgt.core + io.entgra.device.mgt.core.apimgt.extension.rest.api + ${io.entgra.device.mgt.core.version} + + + + + + + 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.extension.rest.api + ../../../features/etc/feature.properties + + + org.wso2.carbon.p2.category.type:server + org.eclipse.equinox.p2.type.group:false + + + + + io.entgra.device.mgt.core:io.entgra.device.mgt.core.apimgt.extension.rest.api:${io.entgra.device.mgt.core.version} + + + + org.wso2.carbon.core.server:${carbon.kernel.version} + + + + + + + + + \ No newline at end of file diff --git a/features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api.feature/src/main/resources/build.properties b/features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api.feature/src/main/resources/build.properties new file mode 100644 index 0000000000..9c86577d76 --- /dev/null +++ b/features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api.feature/src/main/resources/build.properties @@ -0,0 +1 @@ +custom = true diff --git a/features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api.feature/src/main/resources/p2.inf b/features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api.feature/src/main/resources/p2.inf new file mode 100644 index 0000000000..7ab37b9d7d --- /dev/null +++ b/features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api.feature/src/main/resources/p2.inf @@ -0,0 +1 @@ +instructions.configure = \ \ No newline at end of file diff --git a/features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher.feature/pom.xml b/features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher.feature/pom.xml index c9a17b1eaf..0c957a9e32 100644 --- a/features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher.feature/pom.xml +++ b/features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher.feature/pom.xml @@ -51,10 +51,6 @@ io.swagger swagger-annotations - - io.entgra.device.mgt.core - io.entgra.device.mgt.core.apimgt.extension.rest.api - @@ -147,9 +143,6 @@ io.swagger:swagger-annotations:${swagger.version} - - io.entgra.device.mgt.core:io.entgra.device.mgt.core.apimgt.extension.rest.api:${io.entgra.device.mgt.core.version} - org.wso2.carbon.core.server:${carbon.kernel.version} diff --git a/features/apimgt-extensions/pom.xml b/features/apimgt-extensions/pom.xml index e0adcce886..72acd8222b 100644 --- a/features/apimgt-extensions/pom.xml +++ b/features/apimgt-extensions/pom.xml @@ -38,6 +38,7 @@ io.entgra.device.mgt.core.apimgt.application.extension.feature io.entgra.device.mgt.core.apimgt.keymgt.extension.feature io.entgra.device.mgt.core.apimgt.analytics.extension.feature + io.entgra.device.mgt.core.apimgt.extension.rest.api.feature From d49ab1c7f02e2dc1df2139be6650ea471659fc5e Mon Sep 17 00:00:00 2001 From: prathabanKavin Date: Tue, 30 May 2023 23:59:39 +0530 Subject: [PATCH 2/8] Fix create geofence issue with mssql db --- .../core/dao/EventManagementDAOFactory.java | 7 +- .../event/SQLServerEventConfigDAOImpl.java | 80 +++++++++++++++++++ .../main/resources/dbscripts/cdm/mssql.sql | 2 +- 3 files changed, 85 insertions(+), 4 deletions(-) create mode 100644 components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/event/SQLServerEventConfigDAOImpl.java diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/EventManagementDAOFactory.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/EventManagementDAOFactory.java index 7b434274df..b610a3e8f4 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/EventManagementDAOFactory.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/EventManagementDAOFactory.java @@ -18,20 +18,20 @@ package io.entgra.device.mgt.core.device.mgt.core.dao; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import io.entgra.device.mgt.core.device.mgt.common.DeviceManagementConstants; import io.entgra.device.mgt.core.device.mgt.common.exceptions.IllegalTransactionStateException; import io.entgra.device.mgt.core.device.mgt.common.exceptions.TransactionManagementException; import io.entgra.device.mgt.core.device.mgt.common.exceptions.UnsupportedDatabaseEngineException; import io.entgra.device.mgt.core.device.mgt.core.config.datasource.DataSourceConfig; import io.entgra.device.mgt.core.device.mgt.core.config.datasource.JNDILookupDefinition; -import io.entgra.device.mgt.core.device.mgt.core.dao.impl.*; import io.entgra.device.mgt.core.device.mgt.core.dao.impl.event.GenericEventConfigDAOImpl; import io.entgra.device.mgt.core.device.mgt.core.dao.impl.event.H2EventConfigDAOImpl; +import io.entgra.device.mgt.core.device.mgt.core.dao.impl.event.SQLServerEventConfigDAOImpl; import io.entgra.device.mgt.core.device.mgt.core.dao.impl.geofence.GenericGeofenceDAOImpl; import io.entgra.device.mgt.core.device.mgt.core.dao.impl.geofence.SQLServerGeofenceDAOImpl; import io.entgra.device.mgt.core.device.mgt.core.dao.util.DeviceManagementDAOUtil; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import javax.sql.DataSource; import java.sql.Connection; @@ -69,6 +69,7 @@ public class EventManagementDAOFactory { case DeviceManagementConstants.DataBaseTypes.DB_TYPE_POSTGRESQL: case DeviceManagementConstants.DataBaseTypes.DB_TYPE_ORACLE: case DeviceManagementConstants.DataBaseTypes.DB_TYPE_MSSQL: + return new SQLServerEventConfigDAOImpl(); case DeviceManagementConstants.DataBaseTypes.DB_TYPE_MYSQL: return new GenericEventConfigDAOImpl(); case DeviceManagementConstants.DataBaseTypes.DB_TYPE_H2: diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/event/SQLServerEventConfigDAOImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/event/SQLServerEventConfigDAOImpl.java new file mode 100644 index 0000000000..0a816cea05 --- /dev/null +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/event/SQLServerEventConfigDAOImpl.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.device.mgt.core.dao.impl.event; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import io.entgra.device.mgt.core.device.mgt.common.event.config.EventConfig; +import io.entgra.device.mgt.core.device.mgt.core.dao.EventManagementDAOException; +import io.entgra.device.mgt.core.device.mgt.core.dao.EventManagementDAOFactory; +import io.entgra.device.mgt.core.device.mgt.core.dao.impl.AbstractEventConfigDAO; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.sql.Timestamp; +import java.util.ArrayList; +import java.util.List; +import java.util.Calendar; + +public class SQLServerEventConfigDAOImpl extends AbstractEventConfigDAO { + private static final Log log = LogFactory.getLog(SQLServerEventConfigDAOImpl.class); + + @Override + public List storeEventRecords(List eventConfigList, int tenantId) throws EventManagementDAOException { + try { + Calendar calendar = Calendar.getInstance(); + Timestamp timestamp = new Timestamp(calendar.getTime().getTime()); + Connection conn = this.getConnection(); + String sql = "INSERT INTO DM_DEVICE_EVENT(" + + "EVENT_SOURCE, " + + "EVENT_LOGIC, " + + "ACTIONS, "+ + "CREATED_TIMESTAMP, " + + "TENANT_ID) " + + "VALUES (?, ?, ?, ?, ?)"; + try (PreparedStatement stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) { + List generatedIds = new ArrayList<>(); + for (EventConfig eventConfig : eventConfigList) { + stmt.setString(1, eventConfig.getEventSource()); + stmt.setString(2, eventConfig.getEventLogic()); + stmt.setString(3, eventConfig.getActions()); + stmt.setTimestamp(4, timestamp); + stmt.setInt(5, tenantId); + stmt.executeUpdate(); + ResultSet generatedKeys = stmt.getGeneratedKeys(); + if (generatedKeys.next()) { + generatedIds.add(generatedKeys.getInt(1)); + } + } + return generatedIds; + } + } catch (SQLException e) { + String msg = "Error occurred while creating event configurations for the tenant id " + tenantId; + log.error(msg, e); + throw new EventManagementDAOException(msg, e); + } + } + + private Connection getConnection() throws SQLException { + return EventManagementDAOFactory.getConnection(); + } +} diff --git a/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mssql.sql b/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mssql.sql index 07275d894c..028c24829f 100644 --- a/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mssql.sql +++ b/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mssql.sql @@ -775,7 +775,7 @@ CREATE TABLE DM_DEVICE_EVENT ( EVENT_SOURCE VARCHAR(100) NOT NULL, EVENT_LOGIC VARCHAR(100) NOT NULL, ACTIONS TEXT DEFAULT NULL, - CREATED_TIMESTAMP TIMESTAMP NOT NULL, + CREATED_TIMESTAMP DATETIME2(0) NOT NULL, TENANT_ID INTEGER DEFAULT 0, PRIMARY KEY (ID) ); From 1d1d045b75f4ef64c579fd42a956324e6ac67c99 Mon Sep 17 00:00:00 2001 From: pasindu Date: Wed, 31 May 2023 08:05:56 +0530 Subject: [PATCH 3/8] Update copyright --- .../pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api.feature/pom.xml b/features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api.feature/pom.xml index 1e98e6a341..b0f3a595a5 100644 --- a/features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api.feature/pom.xml +++ b/features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api.feature/pom.xml @@ -1,13 +1,13 @@