diff --git a/bpm/bonita-common/src/main/java/org/bonitasoft/engine/bpm/ArchivedRestElement.java b/bpm/bonita-common/src/main/java/org/bonitasoft/engine/bpm/ArchivedRestElement.java new file mode 100644 index 0000000000..85cc4d69ef --- /dev/null +++ b/bpm/bonita-common/src/main/java/org/bonitasoft/engine/bpm/ArchivedRestElement.java @@ -0,0 +1,61 @@ +/** + * 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.bpm; + +import java.util.Date; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonView; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; + +/** + * Interface ArchivedRestElement identifies an archived BonitaObject that can be used in the + * REST API. + */ +public interface ArchivedRestElement extends ArchivedElement { + + /** + * Gets the unique object identifier. + * Serialized as a String in json as a Java long can be too big for JavaScript + * + * @return the unique object identifier + */ + @JsonSerialize(using = ToStringSerializer.class) + @Override + long getSourceObjectId(); + + /** + * Gets the date when the element was archived in milliseconds since epoch. + * Serialized as a String in json as a Java long can be too big for JavaScript + * + * @return the unique object identifier + */ + @JsonView + @JsonProperty("archiveDate") + @JsonSerialize(using = ToStringSerializer.class) + long getArchiveDateAsLong(); + + /** + * Gets the date when the element was archived. + * Ignored in Json serialization as it is already serialized as a long + * + * @return the archived date + */ + @JsonIgnore + @Override + Date getArchiveDate(); + +} diff --git a/bpm/bonita-common/src/main/java/org/bonitasoft/engine/bpm/BaseRestElement.java b/bpm/bonita-common/src/main/java/org/bonitasoft/engine/bpm/BaseRestElement.java new file mode 100644 index 0000000000..bdc1aca201 --- /dev/null +++ b/bpm/bonita-common/src/main/java/org/bonitasoft/engine/bpm/BaseRestElement.java @@ -0,0 +1,34 @@ +/** + * 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.bpm; + +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; + +/** + * Interface BaseRestElement identifies a BonitaObject that can be used in the REST API. + */ +public interface BaseRestElement extends BaseElement { + + /** + * Gets the unique object identifier. + * Serialized as a String in json as a Java long can be too big for JavaScript + * + * @return the unique object identifier + */ + @JsonSerialize(using = ToStringSerializer.class) + @Override + long getId(); + +} 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 3dd84dad83..a492804048 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 @@ -15,6 +15,7 @@ import javax.servlet.http.HttpSession; +import lombok.extern.slf4j.Slf4j; import org.bonitasoft.console.common.server.utils.SessionUtil; import org.bonitasoft.engine.session.APISession; import org.springframework.http.HttpStatus; @@ -23,6 +24,7 @@ /** * Parent class providing common methods for Bonita REST Controllers */ +@Slf4j public abstract class AbstractRESTController { public APISession getApiSession(HttpSession session) { @@ -33,4 +35,24 @@ public APISession getApiSession(HttpSession session) { return apiSession; } + protected long getParameterAsLong(String parameterValue, String errorMessage) { + try { + return Long.parseLong(parameterValue); + } catch (NumberFormatException e) { + log.debug(errorMessage, e); + throw new ResponseStatusException(HttpStatus.BAD_REQUEST, + errorMessage); + } + } + + protected int getParameterAsInt(String parameterValue, String errorMessage) { + try { + return Integer.parseInt(parameterValue); + } catch (NumberFormatException e) { + log.debug(errorMessage, e); + throw new ResponseStatusException(HttpStatus.BAD_REQUEST, + errorMessage); + } + } + } 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 e9bfe08614..0b19ba349d 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 @@ -139,6 +139,7 @@ GET|bpm/diagram=[process_visualization] POST|bpm/message=[flownode_management] POST|bpm/signal=[flownode_management] GET|bpm/failure=[flownode_management, case_management] +GET|bpm/archivedFailure=[flownode_management, case_management] # Portal resources GET|portal/profile=[profile_visualization] diff --git a/services/bonita-authorization/src/main/resources/org/bonitasoft/engine/authorization/properties/dynamic-permissions-checks.properties b/services/bonita-authorization/src/main/resources/org/bonitasoft/engine/authorization/properties/dynamic-permissions-checks.properties index cd3a1a50ed..f2cc0385f1 100644 --- a/services/bonita-authorization/src/main/resources/org/bonitasoft/engine/authorization/properties/dynamic-permissions-checks.properties +++ b/services/bonita-authorization/src/main/resources/org/bonitasoft/engine/authorization/properties/dynamic-permissions-checks.properties @@ -138,6 +138,7 @@ GET|bpm/connectorFailure=[profile|Administrator, profile|Process\u0020manager] # BPM failures GET|bpm/failure=[profile|Administrator] +GET|bpm/archivedFailure=[profile|Administrator] # UserPermissionRule # Let the user access and modify only himself