From 785c9e3f32e75fbd795acd7a04d1847d392d445e Mon Sep 17 00:00:00 2001 From: "emmanuel.duchastenier@bonitasoft.com" Date: Mon, 9 Sep 2024 11:06:43 +0200 Subject: [PATCH] feat(case counters): add Engine+Rest api for counters (#3139) --------- Co-authored-by: bonita-ci --- .../engine/api/TenantAPIAccessor.java | 6 +++ .../api/platform/PlatformInformationAPI.java | 25 ++++++++++++ .../platform/PlatformInformationAPIImpl.java | 39 ++++++++++++++++++ .../service/impl/APIAccessResolverImpl.java | 3 ++ .../server/api/AbstractRESTController.java | 13 +++++- .../PlatformInformationController.java | 40 +++++++++++++++++++ .../src/main/webapp/WEB-INF/web.xml | 1 + .../resources-permissions-mapping.properties | 1 + 8 files changed, 126 insertions(+), 2 deletions(-) create mode 100644 bpm/bonita-common/src/main/java/org/bonitasoft/engine/api/platform/PlatformInformationAPI.java create mode 100644 bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/platform/PlatformInformationAPIImpl.java create mode 100644 bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/api/platform/PlatformInformationController.java diff --git a/bpm/bonita-client/src/main/java/org/bonitasoft/engine/api/TenantAPIAccessor.java b/bpm/bonita-client/src/main/java/org/bonitasoft/engine/api/TenantAPIAccessor.java index 16bddb9aa7e..9365158802d 100644 --- a/bpm/bonita-client/src/main/java/org/bonitasoft/engine/api/TenantAPIAccessor.java +++ b/bpm/bonita-client/src/main/java/org/bonitasoft/engine/api/TenantAPIAccessor.java @@ -17,6 +17,7 @@ import org.bonitasoft.engine.api.impl.ClientInterceptor; import org.bonitasoft.engine.api.internal.ServerAPI; +import org.bonitasoft.engine.api.platform.PlatformInformationAPI; import org.bonitasoft.engine.exception.BonitaHomeNotSetException; import org.bonitasoft.engine.exception.ServerAPIException; import org.bonitasoft.engine.exception.UnknownAPITypeException; @@ -132,4 +133,9 @@ public static MaintenanceAPI getMaintenanceAPI(final APISession session) throws BonitaHomeNotSetException, ServerAPIException, UnknownAPITypeException { return getAPI(MaintenanceAPI.class, session); } + + public static PlatformInformationAPI getPlatformInformationAPI() + throws ServerAPIException, BonitaHomeNotSetException, UnknownAPITypeException { + return getAPI(PlatformInformationAPI.class); + } } diff --git a/bpm/bonita-common/src/main/java/org/bonitasoft/engine/api/platform/PlatformInformationAPI.java b/bpm/bonita-common/src/main/java/org/bonitasoft/engine/api/platform/PlatformInformationAPI.java new file mode 100644 index 00000000000..28d66ec45ac --- /dev/null +++ b/bpm/bonita-common/src/main/java/org/bonitasoft/engine/api/platform/PlatformInformationAPI.java @@ -0,0 +1,25 @@ +/** + * Copyright (C) 2024 Bonitasoft S.A. + * Bonitasoft, 32 rue Gustave Eiffel - 38000 Grenoble + * This library is free software; you can redistribute it and/or modify it under the terms + * of the GNU Lesser General Public License as published by the Free Software Foundation + * version 2.1 of the License. + * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License along with this + * program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301, USA. + **/ +package org.bonitasoft.engine.api.platform; + +import java.util.Map; + +import org.bonitasoft.engine.api.NoSessionRequired; + +@NoSessionRequired +public interface PlatformInformationAPI { + + Map getPlatformInformation(); + +} diff --git a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/platform/PlatformInformationAPIImpl.java b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/platform/PlatformInformationAPIImpl.java new file mode 100644 index 00000000000..746ec79c1c2 --- /dev/null +++ b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/platform/PlatformInformationAPIImpl.java @@ -0,0 +1,39 @@ +/** + * Copyright (C) 2024 Bonitasoft S.A. + * Bonitasoft, 32 rue Gustave Eiffel - 38000 Grenoble + * This library is free software; you can redistribute it and/or modify it under the terms + * of the GNU Lesser General Public License as published by the Free Software Foundation + * version 2.1 of the License. + * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License along with this + * program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301, USA. + **/ +package org.bonitasoft.engine.api.impl.platform; + +import java.util.Map; + +import org.bonitasoft.engine.api.impl.AvailableInMaintenanceMode; +import org.bonitasoft.engine.api.platform.PlatformInformationAPI; + +/** + * Provides runtime information about the platform. + * Information returned is dependent on the edition (Community or Subscription) + * and the platform configuration / license. + * + * @author Emmanuel Duchastenier + */ +@AvailableInMaintenanceMode +public class PlatformInformationAPIImpl implements PlatformInformationAPI { + + @Override + public Map getPlatformInformation() { + return Map.of( + "edition", "subscription", + "caseCounterLimit", "75", + "caseCounter", "68", + "subscriptionStartTimestamp", "1440806400000"); + } +} diff --git a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/service/impl/APIAccessResolverImpl.java b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/service/impl/APIAccessResolverImpl.java index a395c736f4b..25b5ab57c6b 100644 --- a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/service/impl/APIAccessResolverImpl.java +++ b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/service/impl/APIAccessResolverImpl.java @@ -18,6 +18,8 @@ import org.bonitasoft.engine.api.*; import org.bonitasoft.engine.api.impl.*; +import org.bonitasoft.engine.api.impl.platform.PlatformInformationAPIImpl; +import org.bonitasoft.engine.api.platform.PlatformInformationAPI; import org.bonitasoft.engine.exception.APIImplementationNotFoundException; import org.bonitasoft.engine.service.APIAccessResolver; @@ -45,6 +47,7 @@ public class APIAccessResolverImpl implements APIAccessResolver { apis.put(BusinessDataAPI.class.getName(), new BusinessDataAPIImpl()); apis.put(TemporaryContentAPI.class.getName(), new TemporaryContentAPIImpl()); apis.put(MaintenanceAPI.class.getName(), new MaintenanceAPIImpl()); + apis.put(PlatformInformationAPI.class.getName(), new PlatformInformationAPIImpl()); } @Override diff --git a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/api/AbstractRESTController.java b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/api/AbstractRESTController.java index 363830b6767..4ab0fe3e720 100644 --- a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/api/AbstractRESTController.java +++ b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/api/AbstractRESTController.java @@ -16,6 +16,11 @@ import javax.servlet.http.HttpSession; import org.bonitasoft.console.common.server.utils.SessionUtil; +import org.bonitasoft.engine.api.TenantAPIAccessor; +import org.bonitasoft.engine.api.platform.PlatformInformationAPI; +import org.bonitasoft.engine.exception.BonitaHomeNotSetException; +import org.bonitasoft.engine.exception.ServerAPIException; +import org.bonitasoft.engine.exception.UnknownAPITypeException; import org.bonitasoft.engine.session.APISession; import org.springframework.http.HttpStatus; import org.springframework.web.server.ResponseStatusException; @@ -28,9 +33,13 @@ public abstract class AbstractRESTController { public APISession getApiSession(HttpSession session) { APISession apiSession = (APISession) session.getAttribute(SessionUtil.API_SESSION_PARAM_KEY); if (apiSession == null) { - throw new ResponseStatusException( - HttpStatus.UNAUTHORIZED, "Not authenticated"); + throw new ResponseStatusException(HttpStatus.UNAUTHORIZED, "Not authenticated"); } return apiSession; } + + protected PlatformInformationAPI getPlatformInformationAPI() + throws BonitaHomeNotSetException, ServerAPIException, UnknownAPITypeException { + return TenantAPIAccessor.getPlatformInformationAPI(); + } } diff --git a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/api/platform/PlatformInformationController.java b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/api/platform/PlatformInformationController.java new file mode 100644 index 00000000000..9b42461aa58 --- /dev/null +++ b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/api/platform/PlatformInformationController.java @@ -0,0 +1,40 @@ +/** + * Copyright (C) 2024 Bonitasoft S.A. + * Bonitasoft, 32 rue Gustave Eiffel - 38000 Grenoble + * This library is free software; you can redistribute it and/or modify it under the terms + * of the GNU Lesser General Public License as published by the Free Software Foundation + * version 2.1 of the License. + * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License along with this + * program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301, USA. + **/ +package org.bonitasoft.web.rest.server.api.platform; + +import java.util.Map; + +import lombok.extern.slf4j.Slf4j; +import org.bonitasoft.engine.exception.BonitaException; +import org.bonitasoft.web.rest.server.api.AbstractRESTController; +import org.bonitasoft.web.toolkit.client.common.exception.api.APIException; +import org.springframework.http.MediaType; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@Slf4j +@RestController +@RequestMapping("/API/system/information") +public class PlatformInformationController extends AbstractRESTController { + + @GetMapping(produces = MediaType.APPLICATION_JSON_VALUE) + public Map getPlatformInfo() { + try { + return getPlatformInformationAPI().getPlatformInformation(); + } catch (final BonitaException e) { + throw new APIException(e); + } + } +} diff --git a/bpm/bonita-web-server/src/main/webapp/WEB-INF/web.xml b/bpm/bonita-web-server/src/main/webapp/WEB-INF/web.xml index 0f8b1c3c88f..7df83a1a9d7 100644 --- a/bpm/bonita-web-server/src/main/webapp/WEB-INF/web.xml +++ b/bpm/bonita-web-server/src/main/webapp/WEB-INF/web.xml @@ -742,6 +742,7 @@ /API/system/maintenance /API/bpm/processInfo/* + /API/system/information ConsoleServiceServlet diff --git a/platform/platform-resources/src/main/resources/tenant_template_portal/resources-permissions-mapping.properties b/platform/platform-resources/src/main/resources/tenant_template_portal/resources-permissions-mapping.properties index f8e8abd5378..fa6e6494ff8 100644 --- a/platform/platform-resources/src/main/resources/tenant_template_portal/resources-permissions-mapping.properties +++ b/platform/platform-resources/src/main/resources/tenant_template_portal/resources-permissions-mapping.properties @@ -174,6 +174,7 @@ GET|platform/systemProperty=[tenant_platform_visualization] GET|platform/license=[platform_management] POST|tenant/bdm=[bdm_management] GET|tenant/bdm=[bdm_management] +GET|system/information=[tenant_platform_visualization] # Living apps GET|living/application=[application_visualization]