Skip to content

Commit

Permalink
feat(Archived BPM failure): add REST controller (#3259)
Browse files Browse the repository at this point in the history
Covers [BPM-328](https://bonitasoft.atlassian.net/browse/BPM-328)

---------
Co-authored-by: bonita-ci <[email protected]>
  • Loading branch information
abirembaut authored Nov 25, 2024
1 parent 98eb64c commit 2e439b1
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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 <code>ArchivedRestElement</code> identifies an archived <code>BonitaObject</code> 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();

}
Original file line number Diff line number Diff line change
@@ -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 <code>BaseRestElement</code> identifies a <code>BonitaObject</code> 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();

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -23,6 +24,7 @@
/**
* Parent class providing common methods for Bonita REST Controllers
*/
@Slf4j
public abstract class AbstractRESTController {

public APISession getApiSession(HttpSession session) {
Expand All @@ -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);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2e439b1

Please sign in to comment.