From 9c679cd67652fa4a627214d038fe81754f56d7cb Mon Sep 17 00:00:00 2001 From: abirembaut Date: Wed, 20 Sep 2023 10:56:12 +0200 Subject: [PATCH] feat(maintenance mode): REST API respond with 503 in maintenance (#2718) * catch TenantStatusException to throw 503 for APIs that are not available in maintenance * catch InvalidSessionException to throw 401 ad a single filter level * stop catching all exception when calling engine java API to be able to catch and handle runtime exceptions at filter leve * clean useless tests of wrong methods usage * clean useless exceptions Covers [DEV-484](https://bonitasoft.atlassian.net/browse/DEV-484) --- .../common/server/api/CommandCaller.java | 7 +-- .../filter/RestAPIAuthorizationFilter.java | 27 +++++++++--- .../service/ProcessActorImportService.java | 6 --- .../web/rest/server/BonitaRestAPIServlet.java | 6 +++ .../web/rest/server/ResourceFinder.java | 9 ++-- .../api/bdm/BusinessDataModelResource.java | 6 +++ .../bpm/cases/APIArchivedCaseDocument.java | 3 +- .../server/api/bpm/cases/APICaseDocument.java | 3 +- .../flownode/ActivityVariableResource.java | 18 +++++++- .../flownode/TimerEventTriggerResource.java | 4 +- .../api/bpm/process/APIProcessParameter.java | 5 ++- .../api/document/APIArchivedDocument.java | 5 ++- .../rest/server/api/document/APIDocument.java | 8 ++-- .../document/api/impl/DocumentDatastore.java | 12 ++---- .../server/api/form/FormMappingResource.java | 4 +- .../server/api/organization/APIGroup.java | 43 +++---------------- .../rest/server/api/organization/APIUser.java | 24 +++++------ .../web/rest/server/api/page/APIPage.java | 3 +- .../rest/server/api/platform/APIPlatform.java | 7 +-- .../server/api/resource/CommonResource.java | 13 +++--- .../application/ApplicationDataStore.java | 9 ++-- .../ApplicationDataStoreCreator.java | 3 +- .../ApplicationMenuDataStore.java | 9 ++-- .../ApplicationMenuDataStoreCreator.java | 3 +- .../ApplicationPageDataStoreCreator.java | 3 +- .../cases/ArchivedCaseDocumentDatastore.java | 3 +- .../bpm/cases/ArchivedCommentDatastore.java | 7 +-- .../datastore/bpm/cases/CaseDatastore.java | 6 +-- .../bpm/cases/CaseDocumentDatastore.java | 16 +++---- .../bpm/cases/CaseVariableDatastore.java | 23 +++++----- .../datastore/bpm/cases/CommentDatastore.java | 19 +++----- .../flownode/AbstractFlowNodeDatastore.java | 7 +-- .../AbstractArchivedFlowNodeDatastore.java | 32 +++++--------- .../datastore/bpm/process/ActorDatastore.java | 15 ++++--- .../bpm/process/ActorMemberDatastore.java | 13 ++---- .../bpm/process/CategoryDatastore.java | 7 +-- .../bpm/process/ProcessCategoryDatastore.java | 7 +-- .../process/ProcessConnectorDatastore.java | 40 ++++++++--------- .../ProcessConnectorDependencyDatastore.java | 5 ++- .../bpm/process/ProcessDatastore.java | 7 +-- .../organization/GroupDatastore.java | 7 +-- .../PersonalContactDataDatastore.java | 11 ++--- .../ProfessionalContactDataDatastore.java | 9 +--- .../datastore/organization/RoleDatastore.java | 21 +++------ .../datastore/organization/UserDatastore.java | 11 +++-- .../system/TenantAdminDatastore.java | 29 +++++-------- .../engineclient/ActivityEngineClient.java | 3 +- .../server/engineclient/CaseEngineClient.java | 3 +- .../engineclient/EngineAPIAccessor.java | 26 ++++------- .../engineclient/GroupEngineClient.java | 8 ++++ .../engineclient/HumanTaskEngineClient.java | 3 +- .../engineclient/ProcessEngineClient.java | 28 +++++------- .../engineclient/ProfileEngineClient.java | 8 ---- .../ProfileMemberEngineClient.java | 8 ---- .../api/APISessionInvalidException.java | 31 ------------- .../ActivityVariableResourceTest.java | 6 --- .../TimerEventTriggerResourceTest.java | 7 +-- .../server/api/organization/APIUserTest.java | 2 +- .../api/resource/CommonResourceTest.java | 5 +-- .../bpm/cases/CaseDocumentDatastoreTest.java | 4 ++ .../ProcessConnectorDatastoreTest.java | 8 ---- .../organization/UserDatastoreTest.java | 2 +- 62 files changed, 287 insertions(+), 400 deletions(-) delete mode 100644 bpm/bonita-web-server/src/main/java/org/bonitasoft/web/toolkit/client/common/exception/api/APISessionInvalidException.java diff --git a/bpm/bonita-web-server/src/main/java/org/bonitasoft/console/common/server/api/CommandCaller.java b/bpm/bonita-web-server/src/main/java/org/bonitasoft/console/common/server/api/CommandCaller.java index f8e81291b72..844dc89efad 100644 --- a/bpm/bonita-web-server/src/main/java/org/bonitasoft/console/common/server/api/CommandCaller.java +++ b/bpm/bonita-web-server/src/main/java/org/bonitasoft/console/common/server/api/CommandCaller.java @@ -18,10 +18,9 @@ import java.util.Map; import org.bonitasoft.engine.api.TenantAPIAccessor; +import org.bonitasoft.engine.exception.BonitaException; import org.bonitasoft.engine.session.APISession; -import org.bonitasoft.engine.session.InvalidSessionException; import org.bonitasoft.web.toolkit.client.common.exception.api.APIException; -import org.bonitasoft.web.toolkit.client.common.exception.api.APISessionInvalidException; /** * @author Vincent Elcrin @@ -51,9 +50,7 @@ public CommandCaller addParameter(final String key, final Serializable value) { public Serializable run() { try { return TenantAPIAccessor.getCommandAPI(this.session).execute(this.command, this.parameters); - } catch (InvalidSessionException e) { - throw new APISessionInvalidException(e); - } catch (final Exception e) { + } catch (final BonitaException e) { throw new APIException(e); } } diff --git a/bpm/bonita-web-server/src/main/java/org/bonitasoft/console/common/server/login/filter/RestAPIAuthorizationFilter.java b/bpm/bonita-web-server/src/main/java/org/bonitasoft/console/common/server/login/filter/RestAPIAuthorizationFilter.java index a878e5dff52..502e7838ee0 100644 --- a/bpm/bonita-web-server/src/main/java/org/bonitasoft/console/common/server/login/filter/RestAPIAuthorizationFilter.java +++ b/bpm/bonita-web-server/src/main/java/org/bonitasoft/console/common/server/login/filter/RestAPIAuthorizationFilter.java @@ -33,15 +33,12 @@ import org.bonitasoft.console.common.server.utils.SessionUtil; import org.bonitasoft.engine.api.TenantAPIAccessor; import org.bonitasoft.engine.api.permission.APICallContext; -import org.bonitasoft.engine.exception.BonitaException; -import org.bonitasoft.engine.exception.BonitaHomeNotSetException; -import org.bonitasoft.engine.exception.ExecutionException; -import org.bonitasoft.engine.exception.ServerAPIException; -import org.bonitasoft.engine.exception.UnknownAPITypeException; +import org.bonitasoft.engine.exception.*; import org.bonitasoft.engine.session.APISession; import org.bonitasoft.engine.session.InvalidSessionException; import org.bonitasoft.engine.session.PlatformSession; import org.bonitasoft.web.rest.server.framework.utils.RestRequestParser; +import org.bonitasoft.web.toolkit.client.common.exception.api.APIException; import org.bonitasoft.web.toolkit.client.common.i18n.model.I18nLocaleDefinition; import org.bonitasoft.web.toolkit.client.common.session.SessionDefinition; import org.bonitasoft.web.toolkit.client.data.APIID; @@ -67,8 +64,8 @@ public class RestAPIAuthorizationFilter extends ExcludingPatternFilter { @Override public void proceedWithFiltering(ServletRequest request, ServletResponse response, FilterChain chain) throws ServletException { + HttpServletRequest httpServletRequest = (HttpServletRequest) request; try { - HttpServletRequest httpServletRequest = (HttpServletRequest) request; // body of multi-parts requests is not needed when checking permissions if (!ServletFileUpload.isMultipartContent(httpServletRequest)) { //we need to use a MultiReadHttpServletRequest wrapper in order to be able to get the input stream twice (in the filter and in the API servlet) @@ -86,11 +83,27 @@ public void proceedWithFiltering(ServletRequest request, ServletResponse respons if (isAuthorized) { chain.doFilter(httpServletRequest, response); } + } catch (final InvalidSessionException e) { + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Invalid Bonita engine session.", e.getMessage()); + } + SessionUtil.sessionLogout(httpServletRequest.getSession()); + ((HttpServletResponse) response).setStatus(HttpServletResponse.SC_UNAUTHORIZED); + } catch (final TenantStatusException e) { + if (LOGGER.isInfoEnabled()) { + LOGGER.info("Platform is probably under Maintenance : " + e.getMessage()); + } + ((HttpServletResponse) response).setStatus(HttpServletResponse.SC_SERVICE_UNAVAILABLE); } catch (final Exception e) { if (LOGGER.isErrorEnabled()) { LOGGER.error(e.getMessage(), e); } - throw new ServletException(e); + if (e instanceof APIException) { + throw new ServletException(e); + } else { + //wrap exception in APIException to avoid disclose too much information + throw new ServletException(new APIException(e)); + } } } diff --git a/bpm/bonita-web-server/src/main/java/org/bonitasoft/console/server/service/ProcessActorImportService.java b/bpm/bonita-web-server/src/main/java/org/bonitasoft/console/server/service/ProcessActorImportService.java index 8af6b8acf53..f397dd387ad 100644 --- a/bpm/bonita-web-server/src/main/java/org/bonitasoft/console/server/service/ProcessActorImportService.java +++ b/bpm/bonita-web-server/src/main/java/org/bonitasoft/console/server/service/ProcessActorImportService.java @@ -23,8 +23,6 @@ import org.bonitasoft.engine.exception.BonitaException; import org.bonitasoft.engine.io.FileContent; import org.bonitasoft.engine.session.APISession; -import org.bonitasoft.engine.session.InvalidSessionException; -import org.bonitasoft.web.toolkit.client.common.exception.api.APISessionInvalidException; import org.bonitasoft.web.toolkit.server.ServiceException; /** @@ -39,16 +37,12 @@ public Object run() { final BonitaHomeFolderAccessor tenantFolder = new BonitaHomeFolderAccessor(); try { final FileContent xmlFile = tenantFolder.retrieveUploadedTempContent(getFileUploadParameter()); - final APISession apiSession = getSession(); final ProcessAPI processAPI = TenantAPIAccessor.getProcessAPI(apiSession); try (InputStream xmlStream = xmlFile.getInputStream()) { final byte[] actorsXmlContent = IOUtils.toByteArray(xmlStream); processAPI.importActorMapping(Long.valueOf(getParameter("process_id")), actorsXmlContent); } - - } catch (final InvalidSessionException e) { - throw new APISessionInvalidException(e); } catch (final BonitaException | IOException e) { throw new ServiceException(TOKEN, e.getMessage()); } finally { diff --git a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/BonitaRestAPIServlet.java b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/BonitaRestAPIServlet.java index 72ae7eb8366..78836326ca7 100644 --- a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/BonitaRestAPIServlet.java +++ b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/BonitaRestAPIServlet.java @@ -21,6 +21,7 @@ import org.bonitasoft.console.common.server.login.HttpServletRequestAccessor; import org.bonitasoft.console.common.server.utils.SessionUtil; import org.bonitasoft.engine.exception.NotFoundException; +import org.bonitasoft.engine.exception.TenantStatusException; import org.bonitasoft.engine.session.InvalidSessionException; import org.bonitasoft.web.rest.model.ModelFactory; import org.bonitasoft.web.rest.server.datastore.bpm.flownode.FlowNodeConverter; @@ -72,6 +73,11 @@ protected void catchAllExceptions(final Throwable exception, final HttpServletRe SessionUtil.sessionLogout(requestAccessor.getHttpSession()); } else if (exception.getCause() instanceof NotFoundException) { outputException(null, req, resp, HttpServletResponse.SC_NOT_FOUND); + } else if (exception instanceof TenantStatusException) { + if (LOGGER.isInfoEnabled()) { + LOGGER.info("Platform is probably under Maintenance : " + exception.getMessage()); + } + outputException(null, req, resp, HttpServletResponse.SC_SERVICE_UNAVAILABLE); } else { super.catchAllExceptions(exception, req, resp); } diff --git a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/ResourceFinder.java b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/ResourceFinder.java index 584d9dcdaa4..2e523526697 100644 --- a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/ResourceFinder.java +++ b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/ResourceFinder.java @@ -22,6 +22,7 @@ import org.bonitasoft.engine.api.ProcessAPI; import org.bonitasoft.engine.api.TenantAPIAccessor; import org.bonitasoft.engine.api.TenantAdministrationAPI; +import org.bonitasoft.engine.exception.BonitaException; import org.bonitasoft.engine.session.APISession; import org.bonitasoft.web.toolkit.client.common.exception.api.APIException; import org.restlet.Request; @@ -40,7 +41,7 @@ protected CommandAPI getCommandAPI(final Request request) { final APISession apiSession = getAPISession(request); try { return TenantAPIAccessor.getCommandAPI(apiSession); - } catch (final Exception e) { + } catch (final BonitaException e) { throw new APIException(e); } } @@ -49,7 +50,7 @@ protected ProcessAPI getProcessAPI(final Request request) { final APISession apiSession = getAPISession(request); try { return TenantAPIAccessor.getProcessAPI(apiSession); - } catch (final Exception e) { + } catch (final BonitaException e) { throw new APIException(e); } } @@ -58,7 +59,7 @@ protected BusinessDataAPI getBdmAPI(final Request request) { final APISession apiSession = getAPISession(request); try { return TenantAPIAccessor.getBusinessDataAPI(apiSession); - } catch (final Exception e) { + } catch (final BonitaException e) { throw new APIException(e); } } @@ -67,7 +68,7 @@ protected TenantAdministrationAPI getTenantAdministrationAPI(final Request reque final APISession apiSession = getAPISession(request); try { return TenantAPIAccessor.getTenantAdministrationAPI(apiSession); - } catch (final Exception e) { + } catch (final BonitaException e) { throw new APIException(e); } } diff --git a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/api/bdm/BusinessDataModelResource.java b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/api/bdm/BusinessDataModelResource.java index d442c0ff527..e9b80e37d32 100644 --- a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/api/bdm/BusinessDataModelResource.java +++ b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/api/bdm/BusinessDataModelResource.java @@ -22,8 +22,10 @@ import org.bonitasoft.engine.business.data.BusinessDataRepositoryDeploymentException; import org.bonitasoft.engine.business.data.InvalidBusinessDataModelException; import org.bonitasoft.engine.exception.BonitaException; +import org.bonitasoft.engine.exception.TenantStatusException; import org.bonitasoft.engine.exception.UnavailableLockException; import org.bonitasoft.engine.io.FileContent; +import org.bonitasoft.engine.session.InvalidSessionException; import org.bonitasoft.web.rest.model.bdm.BusinessDataModelItem; import org.bonitasoft.web.rest.server.api.resource.CommonResource; import org.bonitasoft.web.rest.server.api.tenant.TenantResourceItem; @@ -69,6 +71,8 @@ public TenantResourceItem addBDM(final BusinessDataModelItem businessDataModelIt return null; } catch (final BusinessDataRepositoryDeploymentException e) { throw new APIException("An error has occurred when deploying Business Data Model.", e); + } catch (final TenantStatusException | InvalidSessionException e) { + throw e; //handled by REST API Authorization filter } catch (Exception e) { Throwable cause = e.getCause(); if (cause instanceof UnavailableLockException) { @@ -88,6 +92,8 @@ public TenantResourceItem addBDM(final BusinessDataModelItem businessDataModelIt public TenantResourceItem getBDM() { try { return new TenantResourceItem(tenantAdministrationAPI.getBusinessDataModelResource()); + } catch (final TenantStatusException | InvalidSessionException e) { + throw e; //handled by REST API Authorization filter } catch (final Exception e) { throw new APIException(e); } diff --git a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/api/bpm/cases/APIArchivedCaseDocument.java b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/api/bpm/cases/APIArchivedCaseDocument.java index 9e290f2c33e..1affc313661 100644 --- a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/api/bpm/cases/APIArchivedCaseDocument.java +++ b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/api/bpm/cases/APIArchivedCaseDocument.java @@ -19,6 +19,7 @@ import org.bonitasoft.console.common.server.preferences.constants.WebBonitaConstantsUtils; import org.bonitasoft.engine.api.ProcessAPI; import org.bonitasoft.engine.api.TenantAPIAccessor; +import org.bonitasoft.engine.exception.BonitaException; import org.bonitasoft.web.rest.model.bpm.cases.ArchivedCaseDocumentDefinition; import org.bonitasoft.web.rest.model.bpm.cases.ArchivedCaseDocumentItem; import org.bonitasoft.web.rest.server.api.ConsoleAPI; @@ -82,7 +83,7 @@ protected ArchivedCaseDocumentDatastore getArchivedCaseDocumentDatastore() { ProcessAPI processAPI; try { processAPI = TenantAPIAccessor.getProcessAPI(getEngineSession()); - } catch (final Exception e) { + } catch (final BonitaException e) { throw new APIException(e); } final WebBonitaConstantsUtils constants = WebBonitaConstantsUtils.getTenantInstance(); diff --git a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/api/bpm/cases/APICaseDocument.java b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/api/bpm/cases/APICaseDocument.java index 7d82dce26c8..8eeeb3f7e09 100644 --- a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/api/bpm/cases/APICaseDocument.java +++ b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/api/bpm/cases/APICaseDocument.java @@ -20,6 +20,7 @@ import org.bonitasoft.console.common.server.utils.BonitaHomeFolderAccessor; import org.bonitasoft.engine.api.ProcessAPI; import org.bonitasoft.engine.api.TenantAPIAccessor; +import org.bonitasoft.engine.exception.BonitaException; import org.bonitasoft.web.rest.model.bpm.cases.CaseDocumentDefinition; import org.bonitasoft.web.rest.model.bpm.cases.CaseDocumentItem; import org.bonitasoft.web.rest.server.api.ConsoleAPI; @@ -93,7 +94,7 @@ protected CaseDocumentDatastore getCaseDocumentDatastore() { ProcessAPI processAPI; try { processAPI = TenantAPIAccessor.getProcessAPI(getEngineSession()); - } catch (final Exception e) { + } catch (final BonitaException e) { throw new APIException(e); } final WebBonitaConstantsUtils constants = WebBonitaConstantsUtils.getTenantInstance(); diff --git a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/api/bpm/flownode/ActivityVariableResource.java b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/api/bpm/flownode/ActivityVariableResource.java index 10da4d6f01c..501a70eaebb 100644 --- a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/api/bpm/flownode/ActivityVariableResource.java +++ b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/api/bpm/flownode/ActivityVariableResource.java @@ -16,8 +16,11 @@ import org.bonitasoft.engine.api.ProcessAPI; import org.bonitasoft.engine.bpm.data.DataInstance; import org.bonitasoft.engine.bpm.data.DataNotFoundException; +import org.bonitasoft.engine.exception.BonitaException; import org.bonitasoft.web.rest.server.api.resource.CommonResource; import org.bonitasoft.web.toolkit.client.common.exception.api.APIException; +import org.bonitasoft.web.toolkit.client.common.exception.api.APIItemIdMalformedException; +import org.bonitasoft.web.toolkit.client.common.exception.api.APIMalformedUrlException; import org.restlet.resource.Get; public class ActivityVariableResource extends CommonResource { @@ -36,12 +39,23 @@ public DataInstance getTaskVariable() { try { final String taskId = getAttribute(ACTIVITYDATA_ACTIVITY_ID); final String dataName = getAttribute(ACTIVITYDATA_DATA_NAME); - return getTaskVariableInstance(dataName, Long.valueOf(taskId)); - } catch (final Exception e) { + if (taskId == null || dataName == null) { + throw new APIMalformedUrlException("missing activity Id and or variable name"); + } + return getTaskVariableInstance(dataName, getActivityInstanceId(taskId)); + } catch (final BonitaException e) { throw new APIException(e); } } + private Long getActivityInstanceId(String taskId) { + try { + return Long.valueOf(taskId); + } catch (NumberFormatException e) { + throw new APIItemIdMalformedException("Long", "long value expected for activity Id"); + } + } + private DataInstance getTaskVariableInstance(final String dataName, final Long activityInstanceId) throws DataNotFoundException { return processAPI.getActivityDataInstance(dataName, activityInstanceId); diff --git a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/api/bpm/flownode/TimerEventTriggerResource.java b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/api/bpm/flownode/TimerEventTriggerResource.java index dc801fd74b2..13e04a810d1 100644 --- a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/api/bpm/flownode/TimerEventTriggerResource.java +++ b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/api/bpm/flownode/TimerEventTriggerResource.java @@ -13,10 +13,12 @@ **/ package org.bonitasoft.web.rest.server.api.bpm.flownode; +import java.io.IOException; import java.util.Date; import org.bonitasoft.engine.api.ProcessAPI; import org.bonitasoft.engine.bpm.flownode.TimerEventTriggerInstance; +import org.bonitasoft.engine.exception.BonitaException; import org.bonitasoft.engine.search.SearchResult; import org.bonitasoft.web.rest.server.api.resource.CommonResource; import org.bonitasoft.web.toolkit.client.common.exception.api.APIException; @@ -55,7 +57,7 @@ public void searchTimerEventTriggers() { representation.setCharacterSet(CharacterSet.UTF_8); getResponse().setEntity(representation); setContentRange(searchResult); - } catch (final Exception e) { + } catch (final BonitaException | IOException e) { throw new APIException(e); } } diff --git a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/api/bpm/process/APIProcessParameter.java b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/api/bpm/process/APIProcessParameter.java index 63ef393c5cf..34c49373b8c 100644 --- a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/api/bpm/process/APIProcessParameter.java +++ b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/api/bpm/process/APIProcessParameter.java @@ -25,6 +25,7 @@ import org.bonitasoft.engine.bpm.parameter.ParameterInstance; import org.bonitasoft.engine.bpm.process.ProcessDefinition; import org.bonitasoft.engine.bpm.process.ProcessDeploymentInfo; +import org.bonitasoft.engine.exception.BonitaException; import org.bonitasoft.engine.exception.BonitaHomeNotSetException; import org.bonitasoft.engine.exception.ServerAPIException; import org.bonitasoft.engine.exception.UnknownAPITypeException; @@ -83,7 +84,7 @@ public ProcessParameterItem get(final APIID id) { return new ProcessParameterItem(processId, parameterInstance.getName(), parameterInstance.getType(), paramValue, parameterInstance.getDescription(), processDeploy.getDisplayName(), processDef.getVersion()); - } catch (final Exception e) { + } catch (final BonitaException e) { throw new APIException(e); } } @@ -121,7 +122,7 @@ public ItemSearchResult search(final int page, final int r p.getDescription(), "", "")); } return new ItemSearchResult<>(page, resultsByPage, parametersCount, items); - } catch (final Exception e) { + } catch (final BonitaException e) { throw new APIException(e); } } diff --git a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/api/document/APIArchivedDocument.java b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/api/document/APIArchivedDocument.java index d7dca79fa31..dc382437d10 100644 --- a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/api/document/APIArchivedDocument.java +++ b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/api/document/APIArchivedDocument.java @@ -21,6 +21,7 @@ import org.bonitasoft.engine.api.TenantAPIAccessor; import org.bonitasoft.engine.bpm.document.ArchivedDocument; import org.bonitasoft.engine.bpm.document.ArchivedDocumentsSearchDescriptor; +import org.bonitasoft.engine.exception.BonitaException; import org.bonitasoft.engine.search.SearchOptionsBuilder; import org.bonitasoft.engine.search.SearchResult; import org.bonitasoft.engine.session.APISession; @@ -55,7 +56,7 @@ public ArchivedDocumentItem get(final APIID id) { final DocumentDatastore dataStore = new DocumentDatastore(apiSession); final ArchivedDocument document = processAPI.getArchivedProcessDocument(id.toLong()); item = dataStore.mapToArchivedDocumentItem(document); - } catch (final Exception e) { + } catch (final BonitaException e) { throw new APIException(e); } return item; @@ -117,7 +118,7 @@ public ItemSearchResult search(final int page, final int r items.add(dataStore.mapToArchivedDocumentItem(document)); } } - } catch (final Exception e) { + } catch (final BonitaException | IllegalArgumentException e) { throw new APIException(e); } return new ItemSearchResult<>(page, resultsByPage, nbOfDocument, items); diff --git a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/api/document/APIDocument.java b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/api/document/APIDocument.java index b3e086c983e..62a0d8444d4 100644 --- a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/api/document/APIDocument.java +++ b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/api/document/APIDocument.java @@ -13,6 +13,7 @@ **/ package org.bonitasoft.web.rest.server.api.document; +import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -22,6 +23,7 @@ import org.bonitasoft.engine.api.TenantAPIAccessor; import org.bonitasoft.engine.bpm.document.ArchivedDocumentsSearchDescriptor; import org.bonitasoft.engine.bpm.document.Document; +import org.bonitasoft.engine.exception.BonitaException; import org.bonitasoft.engine.search.SearchOptionsBuilder; import org.bonitasoft.engine.search.SearchResult; import org.bonitasoft.engine.session.APISession; @@ -59,7 +61,7 @@ public DocumentItem get(final APIID id) { final ProcessAPI processAPI = TenantAPIAccessor.getProcessAPI(apiSession); final Document document = processAPI.getDocument(id.toLong()); item = getDataStore().mapToDocumentItem(document); - } catch (final Exception e) { + } catch (final BonitaException e) { throw new APIException(e); } @@ -123,7 +125,7 @@ public ItemSearchResult search(final int page, final int resultsBy items.add(getDataStore().mapToDocumentItem(document)); } } - } catch (final Exception e) { + } catch (final BonitaException | IllegalArgumentException e) { throw new APIException(e); } return new ItemSearchResult<>(page, resultsByPage, nbOfDocument, items); @@ -151,7 +153,7 @@ public DocumentItem add(final DocumentItem item) { } else { throw new APIException("Error while attaching a new document. Request with bad param value."); } - } catch (final Exception e) { + } catch (final BonitaException | IOException e) { throw new APIException(e); } } diff --git a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/api/document/api/impl/DocumentDatastore.java b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/api/document/api/impl/DocumentDatastore.java index 1ca103436f1..fec1ff2d3bc 100644 --- a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/api/document/api/impl/DocumentDatastore.java +++ b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/api/document/api/impl/DocumentDatastore.java @@ -20,8 +20,6 @@ import java.util.List; import java.util.Locale; -import javax.servlet.ServletException; - import org.apache.commons.io.IOUtils; import org.bonitasoft.console.common.server.preferences.properties.PropertiesFactory; import org.bonitasoft.console.common.server.utils.BonitaHomeFolderAccessor; @@ -63,8 +61,7 @@ public DocumentDatastore(final APISession apiSession) { public SearchResult searchDocuments(final long userId, final String viewType, final SearchOptionsBuilder builder) throws InvalidSessionException, - BonitaHomeNotSetException, ServerAPIException, UnknownAPITypeException, SearchException, NotFoundException, - ServletException { + BonitaHomeNotSetException, ServerAPIException, UnknownAPITypeException, SearchException, NotFoundException { final ProcessAPI processAPI = getProcessAPI(); if (DocumentItem.VALUE_VIEW_TYPE_ADMINISTRATOR.equals(viewType) || DocumentItem.VALUE_VIEW_TYPE_USER.equals(viewType)) { @@ -74,14 +71,13 @@ public SearchResult searchDocuments(final long userId, final String vi } else if (DocumentItem.VALUE_VIEW_TYPE_PROCESS_OWNER.equals(viewType)) { return processAPI.searchDocumentsSupervisedBy(userId, builder.done()); } - throw new ServletException("Invalid view type."); + throw new IllegalArgumentException("Invalid view type."); } public SearchResult searchArchivedDocuments(final long userId, final String viewType, final SearchOptionsBuilder builder) throws InvalidSessionException, BonitaHomeNotSetException, ServerAPIException, UnknownAPITypeException, - SearchException, NotFoundException, - ServletException { + SearchException, NotFoundException { final ProcessAPI processAPI = getProcessAPI(); if (DocumentItem.VALUE_VIEW_TYPE_ADMINISTRATOR.equals(viewType) || DocumentItem.VALUE_VIEW_TYPE_USER.equals(viewType) @@ -90,7 +86,7 @@ public SearchResult searchArchivedDocuments(final long userId, } else if (DocumentItem.VALUE_VIEW_TYPE_PROCESS_OWNER.equals(viewType)) { return processAPI.searchArchivedDocumentsSupervisedBy(userId, builder.done()); } - throw new ServletException("Invalid view type."); + throw new IllegalArgumentException("Invalid view type."); } public DocumentItem createDocument(final long processInstanceId, final String documentName, diff --git a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/api/form/FormMappingResource.java b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/api/form/FormMappingResource.java index 4e168191bb6..357fdc425c2 100644 --- a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/api/form/FormMappingResource.java +++ b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/api/form/FormMappingResource.java @@ -13,10 +13,12 @@ **/ package org.bonitasoft.web.rest.server.api.form; +import java.io.IOException; import java.util.ArrayList; import java.util.List; import org.bonitasoft.engine.api.ProcessAPI; +import org.bonitasoft.engine.exception.BonitaException; import org.bonitasoft.engine.form.FormMapping; import org.bonitasoft.engine.search.SearchResult; import org.bonitasoft.web.rest.server.api.resource.CommonResource; @@ -56,7 +58,7 @@ public void searchFormMapping() throws ResourceException { representation.setCharacterSet(CharacterSet.UTF_8); getResponse().setEntity(representation); setContentRange(searchResult); - } catch (final Exception e) { + } catch (final BonitaException | IOException e) { throw new APIException(e); } } diff --git a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/api/organization/APIGroup.java b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/api/organization/APIGroup.java index 03eb859c87b..ec1d4338773 100644 --- a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/api/organization/APIGroup.java +++ b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/api/organization/APIGroup.java @@ -14,9 +14,7 @@ package org.bonitasoft.web.rest.server.api.organization; import java.util.List; -import java.util.Map; -import org.bonitasoft.engine.api.TenantAPIAccessor; import org.bonitasoft.engine.identity.Group; import org.bonitasoft.engine.identity.GroupCriterion; import org.bonitasoft.web.rest.model.identity.GroupDefinition; @@ -28,8 +26,6 @@ import org.bonitasoft.web.rest.server.framework.api.APIHasGet; import org.bonitasoft.web.rest.server.framework.api.APIHasSearch; import org.bonitasoft.web.rest.server.framework.api.APIHasUpdate; -import org.bonitasoft.web.rest.server.framework.search.ItemSearchResult; -import org.bonitasoft.web.toolkit.client.data.APIID; import org.bonitasoft.web.toolkit.client.data.item.ItemDefinition; /** @@ -48,18 +44,8 @@ protected ItemDefinition defineItemDefinition() { } @Override - public GroupItem add(final GroupItem item) { - return new GroupDatastore(getEngineSession()).add(item); - } - - @Override - public GroupItem update(final APIID id, final Map item) { - return new GroupDatastore(getEngineSession()).update(id, item); - } - - @Override - public GroupItem get(final APIID id) { - return new GroupDatastore(getEngineSession()).get(id); + protected GroupDatastore defineDefaultDatastore() { + return new GroupDatastore(getEngineSession()); } @Override @@ -67,30 +53,13 @@ public String defineDefaultSearchOrder() { return GroupCriterion.NAME_ASC.toString(); } - @Override - public ItemSearchResult search(final int page, final int resultsByPage, final String search, - final String orders, - final Map filters) { - return new GroupDatastore(getEngineSession()).search(page, resultsByPage, search, orders, filters); - } - - @Override - public void delete(final List ids) { - new GroupDatastore(getEngineSession()).delete(ids); - } - @Override protected void fillDeploys(final GroupItem item, final List deploys) { if (deploys.contains(GroupItem.ATTRIBUTE_PARENT_GROUP_ID) && item.getParentPath() != null && !item.getParentPath().isEmpty()) { - try { - Group parentGroup = TenantAPIAccessor.getIdentityAPI(getEngineSession()) - .getGroupByPath(item.getParentPath()); - item.setParentGroupId(String.valueOf(parentGroup.getId())); - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } + Group parentGroup = ((GroupDatastore) getDefaultDatastore()).getGroupEngineClient() + .getGroupByPath(item.getParentPath()); + item.setParentGroupId(String.valueOf(parentGroup.getId())); } } @@ -98,7 +67,7 @@ protected void fillDeploys(final GroupItem item, final List deploys) { protected void fillCounters(final GroupItem item, final List counters) { if (counters.contains(GroupItem.COUNTER_NUMBER_OF_USERS)) { item.setAttribute(GroupItem.COUNTER_NUMBER_OF_USERS, - new GroupDatastore(getEngineSession()).getNumberOfUsers(item.getId())); + ((GroupDatastore) getDefaultDatastore()).getNumberOfUsers(item.getId())); } } diff --git a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/api/organization/APIUser.java b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/api/organization/APIUser.java index a1c3e1df881..b3d945d375c 100644 --- a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/api/organization/APIUser.java +++ b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/api/organization/APIUser.java @@ -25,11 +25,7 @@ import org.bonitasoft.web.rest.server.datastore.organization.PersonalContactDataDatastore; import org.bonitasoft.web.rest.server.datastore.organization.ProfessionalContactDataDatastore; import org.bonitasoft.web.rest.server.datastore.organization.UserDatastore; -import org.bonitasoft.web.rest.server.framework.api.APIHasAdd; -import org.bonitasoft.web.rest.server.framework.api.APIHasDelete; -import org.bonitasoft.web.rest.server.framework.api.APIHasGet; -import org.bonitasoft.web.rest.server.framework.api.APIHasSearch; -import org.bonitasoft.web.rest.server.framework.api.APIHasUpdate; +import org.bonitasoft.web.rest.server.framework.api.*; import org.bonitasoft.web.rest.server.framework.search.ItemSearchResult; import org.bonitasoft.web.toolkit.client.common.util.MapUtil; import org.bonitasoft.web.toolkit.client.common.util.StringUtil; @@ -74,11 +70,12 @@ public UserItem add(final UserItem item) { checkPasswordRobustness(item.getPassword()); // Add - return getUserDatastore().add(item); + return super.add(item); } - UserDatastore getUserDatastore() { + @Override + protected Datastore defineDefaultDatastore() { return new UserDatastore(getEngineSession()); } @@ -124,12 +121,12 @@ public UserItem update(final APIID id, final Map item) { if (item.get(UserItem.ATTRIBUTE_PASSWORD) != null) { checkPasswordRobustness(item.get(UserItem.ATTRIBUTE_PASSWORD)); } - return getUserDatastore().update(id, item); + return super.update(id, item); } @Override public UserItem get(final APIID id) { - final UserItem item = getUserDatastore().get(id); + final UserItem item = super.get(id); if (item != null) { // Do not let the password output from the API @@ -148,8 +145,7 @@ public ItemSearchResult search(final int page, final int resultsByPage final String orders, final Map filters) { - final ItemSearchResult results = getUserDatastore().search(page, resultsByPage, search, filters, - orders); + final ItemSearchResult results = super.search(page, resultsByPage, search, orders, filters); for (final UserItem item : results.getResults()) { if (item != null) { @@ -163,19 +159,19 @@ public ItemSearchResult search(final int page, final int resultsByPage @Override public void delete(final List ids) { - getUserDatastore().delete(ids); + super.delete(ids); } @Override protected void fillDeploys(final UserItem item, final List deploys) { if (isDeployable(UserItem.ATTRIBUTE_MANAGER_ID, deploys, item)) { item.setDeploy(UserItem.ATTRIBUTE_MANAGER_ID, - getUserDatastore().get(item.getManagerId())); + ((UserDatastore) getDefaultDatastore()).get(item.getManagerId())); } if (isDeployable(UserItem.ATTRIBUTE_CREATED_BY_USER_ID, deploys, item)) { item.setDeploy(UserItem.ATTRIBUTE_CREATED_BY_USER_ID, - getUserDatastore().get(item.getCreatedByUserId())); + ((UserDatastore) getDefaultDatastore()).get(item.getCreatedByUserId())); } if (deploys.contains(UserItem.DEPLOY_PERSONAL_DATA)) { diff --git a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/api/page/APIPage.java b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/api/page/APIPage.java index e65bacd3a1c..29d86344e6b 100644 --- a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/api/page/APIPage.java +++ b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/api/page/APIPage.java @@ -19,6 +19,7 @@ import org.bonitasoft.console.common.server.preferences.constants.WebBonitaConstantsUtils; import org.bonitasoft.engine.api.PageAPI; import org.bonitasoft.engine.api.TenantAPIAccessor; +import org.bonitasoft.engine.exception.BonitaException; import org.bonitasoft.web.rest.model.portal.page.PageDefinition; import org.bonitasoft.web.rest.model.portal.page.PageItem; import org.bonitasoft.web.rest.server.api.ConsoleAPI; @@ -105,7 +106,7 @@ private PageDatastore getPageDatastore() { PageAPI pageAPI; try { pageAPI = TenantAPIAccessor.getCustomPageAPI(getEngineSession()); - } catch (final Exception e) { + } catch (final BonitaException e) { throw new APIException(e); } final WebBonitaConstantsUtils constants = WebBonitaConstantsUtils.getTenantInstance(); diff --git a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/api/platform/APIPlatform.java b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/api/platform/APIPlatform.java index 13b5c07e1ce..1e3d72887fc 100644 --- a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/api/platform/APIPlatform.java +++ b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/api/platform/APIPlatform.java @@ -19,6 +19,7 @@ import org.bonitasoft.engine.api.PlatformAPI; import org.bonitasoft.engine.api.PlatformAPIAccessor; +import org.bonitasoft.engine.exception.BonitaException; import org.bonitasoft.engine.platform.Platform; import org.bonitasoft.engine.platform.PlatformNotFoundException; import org.bonitasoft.engine.platform.PlatformState; @@ -61,7 +62,7 @@ public PlatformItem update(final APIID id, final Map attributes) } } return get(null); - } catch (final Exception e) { + } catch (final BonitaException e) { throw new APIException(e); } } @@ -85,7 +86,7 @@ public PlatformItem get(final APIID id) { } catch (final PlatformNotFoundException ex) { clientItem = new PlatformItem(); return clientItem; - } catch (final Exception e) { + } catch (final BonitaException e) { throw new APIException(e); } } @@ -93,7 +94,7 @@ public PlatformItem get(final APIID id) { private PlatformAPI getPlatformAPI() { try { return PlatformAPIAccessor.getPlatformAPI(getPlatformSession()); - } catch (final Exception e) { + } catch (final BonitaException e) { throw new APIException(e); } } diff --git a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/api/resource/CommonResource.java b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/api/resource/CommonResource.java index 47d32e91c9c..da2ab1da1e8 100644 --- a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/api/resource/CommonResource.java +++ b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/api/resource/CommonResource.java @@ -37,7 +37,6 @@ import org.bonitasoft.web.rest.server.datastore.utils.SearchOptionsCreator; import org.bonitasoft.web.rest.server.datastore.utils.Sorts; import org.bonitasoft.web.rest.server.framework.APIServletCall; -import org.bonitasoft.web.toolkit.client.common.exception.api.APIException; import org.restlet.data.CharacterSet; import org.restlet.data.MediaType; import org.restlet.data.Range; @@ -148,9 +147,9 @@ protected String getRequestParameter(final String parameterName) { return getQueryValue(parameterName); } - protected void verifyNotNullParameter(final Object parameter, final String parameterName) throws APIException { + protected void verifyNotNullParameter(final Object parameter, final String parameterName) { if (parameter == null) { - throw new APIException("Parameter " + parameterName + " is mandatory."); + throw new IllegalArgumentException("Parameter " + parameterName + " is mandatory."); } } @@ -260,20 +259,20 @@ public String getPathParam(final String name) { protected int getSearchPageNumber() { try { return getIntegerParameter(APIServletCall.PARAMETER_PAGE, true); - } catch (final APIException e) { - throw new IllegalArgumentException("query parameter p (page) is mandatory"); } catch (final NumberFormatException e) { throw new IllegalArgumentException("query parameter p (page) should be a number"); + } catch (final IllegalArgumentException e) { + throw new IllegalArgumentException("query parameter p (page) is mandatory"); } } protected int getSearchPageSize() { try { return getIntegerParameter(APIServletCall.PARAMETER_LIMIT, true); - } catch (final APIException e) { - throw new IllegalArgumentException("query parameter c (count) is mandatory"); } catch (final NumberFormatException e) { throw new IllegalArgumentException("query parameter c (count) should be a number"); + } catch (final IllegalArgumentException e) { + throw new IllegalArgumentException("query parameter c (count) is mandatory"); } } diff --git a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/application/ApplicationDataStore.java b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/application/ApplicationDataStore.java index 3029748de2e..5f91fcec951 100644 --- a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/application/ApplicationDataStore.java +++ b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/application/ApplicationDataStore.java @@ -24,6 +24,7 @@ import org.bonitasoft.engine.business.application.ApplicationNotFoundException; import org.bonitasoft.engine.business.application.ApplicationPage; import org.bonitasoft.engine.business.application.ApplicationUpdater; +import org.bonitasoft.engine.exception.BonitaException; import org.bonitasoft.engine.exception.SearchException; import org.bonitasoft.engine.page.Page; import org.bonitasoft.engine.search.SearchResult; @@ -71,7 +72,7 @@ public void delete(final List ids) { for (final APIID id : ids) { applicationAPI.deleteApplication(id.toLong()); } - } catch (final Exception e) { + } catch (final BonitaException e) { if (e.getCause() instanceof ApplicationNotFoundException) { throw new APIItemNotFoundException(ApplicationDefinition.TOKEN); } else { @@ -85,7 +86,7 @@ public ApplicationItem get(final APIID id) { try { final Application application = applicationAPI.getApplication(id.toLong()); return converter.toApplicationItem(application); - } catch (final Exception e) { + } catch (final BonitaException e) { throw new APIException(e); } } @@ -103,7 +104,7 @@ public ApplicationItem add(final ApplicationItem item) { homePageDef.getId(), "home"); applicationAPI.setApplicationHomePage(application.getId(), appHomePage.getId()); return converter.toApplicationItem(application); - } catch (final Exception e) { + } catch (final BonitaException e) { throw new APIException(e); } } @@ -114,7 +115,7 @@ public ApplicationItem update(final APIID id, final Map attribut final ApplicationUpdater applicationUpdater = converter.toApplicationUpdater(attributes); final Application application = applicationAPI.updateApplication(id.toLong(), applicationUpdater); return converter.toApplicationItem(application); - } catch (final Exception e) { + } catch (final BonitaException e) { throw new APIException(e); } } diff --git a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/application/ApplicationDataStoreCreator.java b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/application/ApplicationDataStoreCreator.java index c29090f25ef..08c2f607de8 100644 --- a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/application/ApplicationDataStoreCreator.java +++ b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/application/ApplicationDataStoreCreator.java @@ -17,6 +17,7 @@ import org.bonitasoft.engine.api.ApplicationAPI; import org.bonitasoft.engine.api.PageAPI; import org.bonitasoft.engine.api.TenantAPIAccessor; +import org.bonitasoft.engine.exception.BonitaException; import org.bonitasoft.engine.session.APISession; import org.bonitasoft.web.toolkit.client.common.exception.api.APIException; @@ -32,7 +33,7 @@ public ApplicationDataStore create(final APISession session) { applicationAPI = TenantAPIAccessor.getLivingApplicationAPI(session); pageAPI = TenantAPIAccessor.getCustomPageAPI(session); return new ApplicationDataStore(session, applicationAPI, pageAPI, getApplicationConverter()); - } catch (final Exception e) { + } catch (final BonitaException e) { throw new APIException(e); } } diff --git a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/applicationmenu/ApplicationMenuDataStore.java b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/applicationmenu/ApplicationMenuDataStore.java index 08694ce17af..c5e0773ce10 100644 --- a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/applicationmenu/ApplicationMenuDataStore.java +++ b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/applicationmenu/ApplicationMenuDataStore.java @@ -19,6 +19,7 @@ import org.bonitasoft.engine.api.ApplicationAPI; import org.bonitasoft.engine.business.application.ApplicationMenu; import org.bonitasoft.engine.business.application.ApplicationMenuNotFoundException; +import org.bonitasoft.engine.exception.BonitaException; import org.bonitasoft.engine.exception.SearchException; import org.bonitasoft.engine.search.SearchResult; import org.bonitasoft.engine.session.APISession; @@ -62,7 +63,7 @@ public ApplicationMenuItem add(final ApplicationMenuItem item) { final ApplicationMenu applicationMenu = applicationAPI .createApplicationMenu(converter.toApplicationMenuCreator(item)); return converter.toApplicationMenuItem(applicationMenu); - } catch (final Exception e) { + } catch (final BonitaException e) { throw new APIException(e); } } @@ -73,7 +74,7 @@ public ApplicationMenuItem update(final APIID id, final Map attr final ApplicationMenu applicationMenu = applicationAPI.updateApplicationMenu(id.toLong(), converter.toApplicationMenuUpdater(attributes)); return converter.toApplicationMenuItem(applicationMenu); - } catch (final Exception e) { + } catch (final BonitaException e) { throw new APIException(e); } } @@ -83,7 +84,7 @@ public ApplicationMenuItem get(final APIID id) { try { final ApplicationMenu applicationMenu = applicationAPI.getApplicationMenu(id.toLong()); return converter.toApplicationMenuItem(applicationMenu); - } catch (final Exception e) { + } catch (final BonitaException e) { throw new APIException(e); } } @@ -94,7 +95,7 @@ public void delete(final List ids) { for (final APIID id : ids) { applicationAPI.deleteApplicationMenu(id.toLong()); } - } catch (final Exception e) { + } catch (final BonitaException e) { if (e.getCause() instanceof ApplicationMenuNotFoundException) { throw new APIItemNotFoundException(ApplicationMenuDefinition.TOKEN); } else { diff --git a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/applicationmenu/ApplicationMenuDataStoreCreator.java b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/applicationmenu/ApplicationMenuDataStoreCreator.java index a09a7ec7ad8..0eb0f60d4d6 100644 --- a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/applicationmenu/ApplicationMenuDataStoreCreator.java +++ b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/applicationmenu/ApplicationMenuDataStoreCreator.java @@ -15,6 +15,7 @@ import org.bonitasoft.engine.api.ApplicationAPI; import org.bonitasoft.engine.api.TenantAPIAccessor; +import org.bonitasoft.engine.exception.BonitaException; import org.bonitasoft.engine.session.APISession; import org.bonitasoft.web.toolkit.client.common.exception.api.APIException; @@ -28,7 +29,7 @@ public ApplicationMenuDataStore create(final APISession session) { try { applicationAPI = TenantAPIAccessor.getLivingApplicationAPI(session); return new ApplicationMenuDataStore(session, applicationAPI, new ApplicationMenuItemConverter()); - } catch (final Exception e) { + } catch (final BonitaException e) { throw new APIException(e); } } diff --git a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/applicationpage/ApplicationPageDataStoreCreator.java b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/applicationpage/ApplicationPageDataStoreCreator.java index aa50c036d68..900a2f6ae6e 100644 --- a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/applicationpage/ApplicationPageDataStoreCreator.java +++ b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/applicationpage/ApplicationPageDataStoreCreator.java @@ -15,6 +15,7 @@ import org.bonitasoft.engine.api.ApplicationAPI; import org.bonitasoft.engine.api.TenantAPIAccessor; +import org.bonitasoft.engine.exception.BonitaException; import org.bonitasoft.engine.session.APISession; import org.bonitasoft.web.toolkit.client.common.exception.api.APIException; @@ -27,7 +28,7 @@ public ApplicationPageDataStore create(final APISession session) { try { final ApplicationAPI applicationAPI = TenantAPIAccessor.getLivingApplicationAPI(session); return new ApplicationPageDataStore(session, applicationAPI, new ApplicationPageItemConverter()); - } catch (final Exception e) { + } catch (final BonitaException e) { throw new APIException(e); } } diff --git a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/bpm/cases/ArchivedCaseDocumentDatastore.java b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/bpm/cases/ArchivedCaseDocumentDatastore.java index 9b405a349a4..37788636c19 100644 --- a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/bpm/cases/ArchivedCaseDocumentDatastore.java +++ b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/bpm/cases/ArchivedCaseDocumentDatastore.java @@ -22,6 +22,7 @@ import org.bonitasoft.engine.bpm.document.DocumentNotFoundException; import org.bonitasoft.engine.bpm.process.ArchivedProcessInstance; import org.bonitasoft.engine.bpm.process.ArchivedProcessInstanceNotFoundException; +import org.bonitasoft.engine.exception.BonitaException; import org.bonitasoft.engine.exception.SearchException; import org.bonitasoft.engine.identity.UserNotFoundException; import org.bonitasoft.engine.search.SearchResult; @@ -63,7 +64,7 @@ public ArchivedCaseDocumentItem get(final APIID id) { try { final ArchivedDocument documentItem = processAPI.getArchivedProcessDocument(id.toLong()); return convertEngineToConsoleItem(documentItem); - } catch (final Exception e) { + } catch (final BonitaException e) { throw new APIException(e); } } diff --git a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/bpm/cases/ArchivedCommentDatastore.java b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/bpm/cases/ArchivedCommentDatastore.java index bde63afc7a4..ce57ae00a13 100644 --- a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/bpm/cases/ArchivedCommentDatastore.java +++ b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/bpm/cases/ArchivedCommentDatastore.java @@ -20,18 +20,17 @@ import org.bonitasoft.engine.api.TenantAPIAccessor; import org.bonitasoft.engine.bpm.comment.ArchivedComment; import org.bonitasoft.engine.bpm.comment.ArchivedCommentsSearchDescriptor; +import org.bonitasoft.engine.exception.BonitaException; import org.bonitasoft.engine.search.Order; import org.bonitasoft.engine.search.SearchOptionsBuilder; import org.bonitasoft.engine.search.SearchResult; import org.bonitasoft.engine.session.APISession; -import org.bonitasoft.engine.session.InvalidSessionException; import org.bonitasoft.web.rest.model.bpm.cases.ArchivedCommentItem; import org.bonitasoft.web.rest.server.datastore.CommonDatastore; import org.bonitasoft.web.rest.server.framework.api.DatastoreHasSearch; import org.bonitasoft.web.rest.server.framework.search.ItemSearchResult; import org.bonitasoft.web.rest.server.framework.utils.SearchOptionsBuilderUtil; import org.bonitasoft.web.toolkit.client.common.exception.api.APIException; -import org.bonitasoft.web.toolkit.client.common.exception.api.APISessionInvalidException; /** * @author Paul AMAR @@ -90,9 +89,7 @@ public ItemSearchResult search(int page, int resultsByPage, return new ItemSearchResult<>(page, resultsByPage, result.getCount(), archivedCommentList); - } catch (final InvalidSessionException e) { - throw new APISessionInvalidException(e); - } catch (final Exception e) { + } catch (final BonitaException e) { throw new APIException(e); } } diff --git a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/bpm/cases/CaseDatastore.java b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/bpm/cases/CaseDatastore.java index 6bf0d9b5e60..b91b31e577c 100644 --- a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/bpm/cases/CaseDatastore.java +++ b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/bpm/cases/CaseDatastore.java @@ -84,7 +84,7 @@ public ItemSearchResult search(final int page, final int resultsByPage final SearchOptionsBuilder builder = buildSearchOptions(page, resultsByPage, search, orders, filters); final SearchResult searchResult = searchProcessInstances(filters, builder.done()); return convertEngineToConsoleSearch(page, resultsByPage, searchResult); - } catch (final Exception e) { + } catch (final BonitaException e) { throw new APIException(e); } } @@ -162,7 +162,7 @@ public CaseItem get(final APIID id) { return convertEngineToConsoleItem(getProcessAPI().getProcessInstance(id.toLong())); } catch (final ProcessInstanceNotFoundException e) { return null; - } catch (final Exception e) { + } catch (final BonitaException e) { throw new APIException(e); } } @@ -175,7 +175,7 @@ public void delete(final List ids) { processApi.deleteProcessInstance(id.toLong()); processApi.deleteArchivedProcessInstancesInAllStates(id.toLong()); } - } catch (final Exception e) { + } catch (final BonitaException e) { if (e.getCause() instanceof ProcessInstanceNotFoundException) { throw new APIItemNotFoundException(CaseDefinition.TOKEN); } else { diff --git a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/bpm/cases/CaseDocumentDatastore.java b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/bpm/cases/CaseDocumentDatastore.java index 46821f5f50a..c30311dfdde 100644 --- a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/bpm/cases/CaseDocumentDatastore.java +++ b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/bpm/cases/CaseDocumentDatastore.java @@ -40,10 +40,7 @@ import org.bonitasoft.web.rest.server.datastore.filter.Filters; import org.bonitasoft.web.rest.server.datastore.utils.SearchOptionsCreator; import org.bonitasoft.web.rest.server.datastore.utils.Sorts; -import org.bonitasoft.web.rest.server.framework.api.DatastoreHasAdd; -import org.bonitasoft.web.rest.server.framework.api.DatastoreHasDelete; -import org.bonitasoft.web.rest.server.framework.api.DatastoreHasGet; -import org.bonitasoft.web.rest.server.framework.api.DatastoreHasUpdate; +import org.bonitasoft.web.rest.server.framework.api.*; import org.bonitasoft.web.rest.server.framework.search.ItemSearchResult; import org.bonitasoft.web.toolkit.client.common.exception.api.APIException; import org.bonitasoft.web.toolkit.client.common.util.StringUtil; @@ -85,7 +82,7 @@ public CaseDocumentItem get(final APIID id) { try { final Document documentItem = processAPI.getDocument(id.toLong()); return convertEngineToConsoleItem(documentItem); - } catch (final Exception e) { + } catch (final BonitaException e) { throw new APIException(e); } } @@ -135,7 +132,7 @@ public CaseDocumentItem add(final CaseDocumentItem item) { } else { throw new APIException("Error while attaching a new document. Request with bad param value."); } - } catch (final Exception e) { + } catch (final BonitaException | IOException e) { throw new APIException(e); } finally { if (urlPath == null) { @@ -170,7 +167,7 @@ public CaseDocumentItem update(final APIID id, final Map attribu } else { throw new APIException("Error while attaching a new document. Request with bad param value."); } - } catch (final Exception e) { + } catch (final BonitaException | IOException e) { throw new APIException(e); } finally { if (attributes.containsKey(CaseDocumentItem.ATTRIBUTE_UPLOAD_PATH)) { @@ -249,10 +246,9 @@ protected ItemSearchResult searchDocument(final int page, fina } return new ItemSearchResult<>(page, resultsByPage, engineSearchResults.getCount(), convertEngineToConsoleItem(engineSearchResults.getResult())); - } catch (final Exception e) { - e.printStackTrace(); + } catch (final BonitaException e) { + throw new APIException(e); } - return null; } protected SearchOptionsCreator buildSearchOptionCreator(final int page, final int resultsByPage, diff --git a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/bpm/cases/CaseVariableDatastore.java b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/bpm/cases/CaseVariableDatastore.java index 3d71f5903f2..f3a1d648d28 100644 --- a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/bpm/cases/CaseVariableDatastore.java +++ b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/bpm/cases/CaseVariableDatastore.java @@ -23,14 +23,17 @@ import org.bonitasoft.engine.api.ProcessAPI; import org.bonitasoft.engine.api.TenantAPIAccessor; import org.bonitasoft.engine.bpm.data.DataInstance; +import org.bonitasoft.engine.exception.BonitaException; import org.bonitasoft.engine.session.APISession; import org.bonitasoft.web.rest.model.bpm.cases.CaseVariableItem; import org.bonitasoft.web.rest.server.datastore.CommonDatastore; import org.bonitasoft.web.rest.server.framework.api.DatastoreHasSearch; import org.bonitasoft.web.rest.server.framework.api.DatastoreHasUpdate; import org.bonitasoft.web.rest.server.framework.search.ItemSearchResult; +import org.bonitasoft.web.rest.server.framework.utils.converter.ConversionException; import org.bonitasoft.web.rest.server.framework.utils.converter.TypeConverter; import org.bonitasoft.web.toolkit.client.common.exception.api.APIException; +import org.bonitasoft.web.toolkit.client.common.exception.api.APIMethodNotAllowedException; import org.bonitasoft.web.toolkit.client.data.APIID; /** @@ -62,21 +65,21 @@ private List convert(final List dataInstances) { protected ProcessAPI getEngineProcessAPI() { try { return TenantAPIAccessor.getProcessAPI(getEngineSession()); - } catch (final Exception e) { + } catch (final BonitaException e) { throw new APIException(e); } } @Override public CaseVariableItem update(final APIID id, final Map attributes) { - throw new RuntimeException("Not implemented / No need to / Not used"); + throw new APIMethodNotAllowedException("Not implemented / No need to / Not used"); } @Override public ItemSearchResult search(final int page, final int resultsByPage, final String search, final String orders, final Map filters) { - throw new RuntimeException("Not implemented / No need to / Not used"); + throw new APIMethodNotAllowedException("Not implemented / No need to / Not used"); } public void updateVariableValue(final long caseId, final String variableName, final String className, @@ -84,7 +87,7 @@ public void updateVariableValue(final long caseId, final String variableName, fi try { final Serializable converteValue = converter.convert(className, newValue); getEngineProcessAPI().updateProcessDataInstance(variableName, caseId, converteValue); - } catch (final Exception e) { + } catch (final BonitaException | ConversionException e) { throw new APIException("Error when updating case variable", e); } } @@ -95,23 +98,19 @@ public ItemSearchResult findByCaseId(final long caseId, final computeIndex(page, resultsByPage), resultsByPage); return new ItemSearchResult<>(page, resultsByPage, countByCaseId(caseId), convert(processDataInstances)); - } catch (final Exception e) { + } catch (final BonitaException e) { throw new APIException("Error when getting case variables", e); } } - private long countByCaseId(final long caseId) { - try { - return getEngineProcessAPI().getNumberOfProcessDataInstances(caseId); - } catch (final Exception e) { - throw new APIException("Error while getting the number of case variables", e); - } + private long countByCaseId(final long caseId) throws BonitaException { + return getEngineProcessAPI().getNumberOfProcessDataInstances(caseId); } public CaseVariableItem findById(final long caseId, final String variableName) { try { return convertEngineToConsoleItem(getEngineProcessAPI().getProcessDataInstance(variableName, caseId)); - } catch (final Exception e) { + } catch (final BonitaException e) { throw new APIException("Error while getting case variable", e); } } diff --git a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/bpm/cases/CommentDatastore.java b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/bpm/cases/CommentDatastore.java index c1a3fadd6e1..6c96f778f6d 100644 --- a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/bpm/cases/CommentDatastore.java +++ b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/bpm/cases/CommentDatastore.java @@ -22,11 +22,11 @@ import org.bonitasoft.engine.api.TenantAPIAccessor; import org.bonitasoft.engine.bpm.comment.Comment; import org.bonitasoft.engine.bpm.comment.SearchCommentsDescriptor; +import org.bonitasoft.engine.exception.BonitaException; import org.bonitasoft.engine.search.Order; import org.bonitasoft.engine.search.SearchOptionsBuilder; import org.bonitasoft.engine.search.SearchResult; import org.bonitasoft.engine.session.APISession; -import org.bonitasoft.engine.session.InvalidSessionException; import org.bonitasoft.web.rest.model.bpm.cases.CommentItem; import org.bonitasoft.web.rest.server.datastore.CommonDatastore; import org.bonitasoft.web.rest.server.framework.api.DatastoreHasAdd; @@ -34,7 +34,6 @@ import org.bonitasoft.web.rest.server.framework.search.ItemSearchResult; import org.bonitasoft.web.rest.server.framework.utils.SearchOptionsBuilderUtil; import org.bonitasoft.web.toolkit.client.common.exception.api.APIException; -import org.bonitasoft.web.toolkit.client.common.exception.api.APISessionInvalidException; import org.bonitasoft.web.toolkit.client.data.APIID; /** @@ -140,9 +139,7 @@ private SearchResult runTeamManagerSearch(final long teamManagerId, fin try { final ProcessAPI processAPI = TenantAPIAccessor.getProcessAPI(getEngineSession()); return processAPI.searchCommentsManagedBy(teamManagerId, builder.done()); - } catch (final InvalidSessionException e) { - throw new APISessionInvalidException(e); - } catch (final Exception e) { + } catch (final BonitaException e) { throw new APIException(e); } } @@ -158,9 +155,7 @@ private SearchResult runUserSearch(final long userId, final SearchOptio try { final ProcessAPI processAPI = TenantAPIAccessor.getProcessAPI(getEngineSession()); return processAPI.searchCommentsInvolvingUser(userId, builder.done()); - } catch (final InvalidSessionException e) { - throw new APISessionInvalidException(e); - } catch (final Exception e) { + } catch (final BonitaException e) { throw new APIException(e); } } @@ -175,9 +170,7 @@ private SearchResult runCustomSearch(final SearchOptionsBuilder builder try { final ProcessAPI processAPI = TenantAPIAccessor.getProcessAPI(getEngineSession()); return processAPI.searchComments(builder.done()); - } catch (final InvalidSessionException e) { - throw new APISessionInvalidException(e); - } catch (final Exception e) { + } catch (final BonitaException e) { throw new APIException(e); } } @@ -208,9 +201,7 @@ public CommentItem add(final CommentItem item) { final ProcessAPI processAPI = TenantAPIAccessor.getProcessAPI(getEngineSession()); return convertEngineToConsoleItem( processAPI.addProcessComment(item.getProcessInstanceId().toLong(), item.getContent())); - } catch (final InvalidSessionException e) { - throw new APISessionInvalidException(e); - } catch (final Exception e) { + } catch (final BonitaException e) { throw new APIException(e); } } diff --git a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/bpm/flownode/AbstractFlowNodeDatastore.java b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/bpm/flownode/AbstractFlowNodeDatastore.java index a4bed238e97..631d23941af 100644 --- a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/bpm/flownode/AbstractFlowNodeDatastore.java +++ b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/bpm/flownode/AbstractFlowNodeDatastore.java @@ -19,6 +19,7 @@ import org.bonitasoft.engine.api.TenantAPIAccessor; import org.bonitasoft.engine.bpm.flownode.FlowNodeInstance; import org.bonitasoft.engine.bpm.flownode.FlowNodeInstanceSearchDescriptor; +import org.bonitasoft.engine.exception.BonitaException; import org.bonitasoft.engine.exception.NotFoundException; import org.bonitasoft.engine.search.SearchOptionsBuilder; import org.bonitasoft.engine.search.SearchResult; @@ -82,7 +83,7 @@ protected static FlowNodeItem fillConsoleItem(final FlowNodeItem result, final F protected ProcessAPI getProcessAPI() { try { return TenantAPIAccessor.getProcessAPI(getEngineSession()); - } catch (final Exception e) { + } catch (final BonitaException e) { throw new APIException(e); } } @@ -105,7 +106,7 @@ public CONSOLE_ITEM get(final APIID id) { return convertEngineToConsoleItem(flowNodeInstance); } catch (final NotFoundException e) { throw new APIItemNotFoundException(FlowNodeDefinition.TOKEN, id); - } catch (final Exception e) { + } catch (final BonitaException e) { throw new APIException(e); } } @@ -129,7 +130,7 @@ protected SearchResult runSearch(final SearchOptionsBuilder builder final Map filters) { try { return (SearchResult) getProcessAPI().searchFlowNodeInstances(builder.done()); - } catch (final Exception e) { + } catch (final BonitaException e) { throw new APIException(e); } } diff --git a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/bpm/flownode/archive/AbstractArchivedFlowNodeDatastore.java b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/bpm/flownode/archive/AbstractArchivedFlowNodeDatastore.java index 8b60a938bb9..0e8bfca1fe7 100644 --- a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/bpm/flownode/archive/AbstractArchivedFlowNodeDatastore.java +++ b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/bpm/flownode/archive/AbstractArchivedFlowNodeDatastore.java @@ -19,6 +19,7 @@ import org.bonitasoft.engine.api.TenantAPIAccessor; import org.bonitasoft.engine.bpm.flownode.ArchivedFlowNodeInstance; import org.bonitasoft.engine.bpm.flownode.ArchivedFlowNodeInstanceNotFoundException; +import org.bonitasoft.engine.exception.BonitaException; import org.bonitasoft.engine.search.SearchResult; import org.bonitasoft.engine.session.APISession; import org.bonitasoft.web.rest.model.bpm.flownode.ArchivedFlowNodeItem; @@ -104,14 +105,8 @@ protected CONSOLE_ITEM convertEngineToConsoleItem(final ENGINE_ITEM item) { @Override public CONSOLE_ITEM get(final APIID id) { - try { - final ENGINE_ITEM archivedFlowNodeInstance = runGet(id); - return convertEngineToConsoleItem(archivedFlowNodeInstance); - } catch (APIItemNotFoundException e) { - throw e; - } catch (final Exception e) { - throw new APIException(e); - } + final ENGINE_ITEM archivedFlowNodeInstance = runGet(id); + return convertEngineToConsoleItem(archivedFlowNodeInstance); } @SuppressWarnings("unchecked") @@ -127,20 +122,15 @@ protected ENGINE_ITEM runGet(final APIID id) { public ItemSearchResult search(final int page, final int resultsByPage, final String search, final String orders, final Map filters) { - try { - final SearchOptionsCreator creator = makeSearchOptionCreator(page, resultsByPage, search, orders, filters); - - final SearchResult results = runSearch(creator, filters); + final SearchOptionsCreator creator = makeSearchOptionCreator(page, resultsByPage, search, orders, filters); - return new ItemSearchResult<>( - page, - resultsByPage, - results.getCount(), - convertEngineToConsoleItemsList(results.getResult())); + final SearchResult results = runSearch(creator, filters); - } catch (final Exception e) { - throw new APIException(e); - } + return new ItemSearchResult<>( + page, + resultsByPage, + results.getCount(), + convertEngineToConsoleItemsList(results.getResult())); } /** @@ -155,7 +145,7 @@ protected SearchResult runSearch(final SearchOptionsCreator creator creator.create()); return result; - } catch (final Exception e) { + } catch (final BonitaException e) { throw new APIException(e); } } diff --git a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/bpm/process/ActorDatastore.java b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/bpm/process/ActorDatastore.java index 09fabf07dd4..f15f442fdde 100644 --- a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/bpm/process/ActorDatastore.java +++ b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/bpm/process/ActorDatastore.java @@ -24,6 +24,7 @@ import org.bonitasoft.engine.bpm.actor.ActorCriterion; import org.bonitasoft.engine.bpm.actor.ActorInstance; import org.bonitasoft.engine.bpm.actor.ActorUpdater; +import org.bonitasoft.engine.exception.BonitaException; import org.bonitasoft.engine.exception.BonitaHomeNotSetException; import org.bonitasoft.engine.exception.ServerAPIException; import org.bonitasoft.engine.exception.UnknownAPITypeException; @@ -89,7 +90,7 @@ private ProcessAPI getProcessAPI() public ActorItem get(final APIID id) { try { return convertEngineToConsoleItem(getProcessAPI().getActor(id.toLong())); - } catch (final Exception e) { + } catch (final BonitaException e) { throw new APIException(e); } } @@ -112,7 +113,7 @@ public ItemSearchResult search(final int page, final int resultsByPag getProcessAPI().getNumberOfActors(processId), convertEngineToConsoleItemsList(actors)); - } catch (final Exception e) { + } catch (final BonitaException e) { throw new APIException(e); } } @@ -131,7 +132,7 @@ public ActorItem update(final APIID id, final Map attributes) { return convertEngineToConsoleItem(getProcessAPI().updateActor(id.toLong(), updater)); - } catch (final Exception e) { + } catch (final BonitaException e) { throw new APIException(e); } } @@ -143,7 +144,7 @@ public ActorItem update(final APIID id, final Map attributes) { public Long countUsers(final APIID actorId) { try { return getProcessAPI().getNumberOfUsersOfActor(actorId.toLong()); - } catch (final Exception e) { + } catch (final BonitaException e) { throw new APIException(e); } } @@ -151,7 +152,7 @@ public Long countUsers(final APIID actorId) { public Long countGroups(final APIID actorId) { try { return getProcessAPI().getNumberOfGroupsOfActor(actorId.toLong()); - } catch (final Exception e) { + } catch (final BonitaException e) { throw new APIException(e); } } @@ -159,7 +160,7 @@ public Long countGroups(final APIID actorId) { public Long countRoles(final APIID actorId) { try { return getProcessAPI().getNumberOfRolesOfActor(actorId.toLong()); - } catch (final Exception e) { + } catch (final BonitaException e) { throw new APIException(e); } } @@ -167,7 +168,7 @@ public Long countRoles(final APIID actorId) { public Long countMemberships(final APIID actorId) { try { return getProcessAPI().getNumberOfMembershipsOfActor(actorId.toLong()); - } catch (final Exception e) { + } catch (final BonitaException e) { throw new APIException(e); } } diff --git a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/bpm/process/ActorMemberDatastore.java b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/bpm/process/ActorMemberDatastore.java index 1b79af7a8ab..adc18bb7333 100644 --- a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/bpm/process/ActorMemberDatastore.java +++ b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/bpm/process/ActorMemberDatastore.java @@ -21,12 +21,7 @@ import org.bonitasoft.engine.api.ProcessAPI; import org.bonitasoft.engine.api.TenantAPIAccessor; import org.bonitasoft.engine.bpm.actor.ActorMember; -import org.bonitasoft.engine.exception.AlreadyExistsException; -import org.bonitasoft.engine.exception.BonitaHomeNotSetException; -import org.bonitasoft.engine.exception.CreationException; -import org.bonitasoft.engine.exception.NotFoundException; -import org.bonitasoft.engine.exception.ServerAPIException; -import org.bonitasoft.engine.exception.UnknownAPITypeException; +import org.bonitasoft.engine.exception.*; import org.bonitasoft.engine.session.APISession; import org.bonitasoft.engine.session.InvalidSessionException; import org.bonitasoft.web.rest.model.bpm.process.ActorMemberItem; @@ -82,7 +77,7 @@ public void delete(final List ids) { for (final APIID id : ids) { getProcessAPI().removeActorMember(id.toLong()); } - } catch (final Exception e) { + } catch (final BonitaException e) { throw new APIException(e); } } @@ -116,7 +111,7 @@ public ItemSearchResult search(final int page, final int result filteredResults.size(), finalResults); - } catch (final Exception e) { + } catch (final BonitaException e) { throw new APIException(e); } } @@ -216,7 +211,7 @@ public ActorMemberItem add(final ActorMemberItem item) { final ActorMemberItem addedItem = convertEngineToConsoleItem(addedActorMember); addedItem.setActorId(item.getActorId()); return addedItem; - } catch (final Exception e) { + } catch (final BonitaException e) { throw new APIException(e); } } diff --git a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/bpm/process/CategoryDatastore.java b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/bpm/process/CategoryDatastore.java index e9d5e416134..07d00e4306b 100644 --- a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/bpm/process/CategoryDatastore.java +++ b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/bpm/process/CategoryDatastore.java @@ -22,10 +22,7 @@ import org.bonitasoft.engine.bpm.category.CategoryCriterion; import org.bonitasoft.engine.bpm.category.CategoryNotFoundException; import org.bonitasoft.engine.bpm.category.CategoryUpdater; -import org.bonitasoft.engine.exception.AlreadyExistsException; -import org.bonitasoft.engine.exception.BonitaHomeNotSetException; -import org.bonitasoft.engine.exception.ServerAPIException; -import org.bonitasoft.engine.exception.UnknownAPITypeException; +import org.bonitasoft.engine.exception.*; import org.bonitasoft.engine.session.APISession; import org.bonitasoft.engine.session.InvalidSessionException; import org.bonitasoft.web.rest.model.bpm.process.CategoryDefinition; @@ -225,7 +222,7 @@ public CategoryItem update(final APIID id, final Map attributes) protected ProcessAPI getProcessAPI() { try { return TenantAPIAccessor.getProcessAPI(getEngineSession()); - } catch (Exception e) { + } catch (BonitaException e) { throw new APIException(e); } } diff --git a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/bpm/process/ProcessCategoryDatastore.java b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/bpm/process/ProcessCategoryDatastore.java index c204a8d2624..b12daa72fe7 100644 --- a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/bpm/process/ProcessCategoryDatastore.java +++ b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/bpm/process/ProcessCategoryDatastore.java @@ -19,6 +19,7 @@ import org.bonitasoft.engine.api.ProcessAPI; import org.bonitasoft.engine.api.TenantAPIAccessor; import org.bonitasoft.engine.exception.AlreadyExistsException; +import org.bonitasoft.engine.exception.BonitaException; import org.bonitasoft.engine.session.APISession; import org.bonitasoft.web.rest.model.bpm.process.ProcessCategoryItem; import org.bonitasoft.web.rest.server.datastore.CommonDatastore; @@ -67,7 +68,7 @@ protected void apply(Long processId, List categoriesId) { private void removeCategoriesFromProcess(Long processId, List categoriesId) { try { getProcessAPI().removeCategoriesFromProcess(processId, categoriesId); - } catch (Exception e) { + } catch (BonitaException e) { throw new APIException(e); } } @@ -97,7 +98,7 @@ public ProcessCategoryItem add(final ProcessCategoryItem item) { return item; } catch (AlreadyExistsException e) { throw new APIForbiddenException(new T_("This category has already been added to this process"), e); - } catch (final Exception e) { + } catch (final BonitaException e) { throw new APIException(e); } } @@ -105,7 +106,7 @@ public ProcessCategoryItem add(final ProcessCategoryItem item) { protected ProcessAPI getProcessAPI() { try { return TenantAPIAccessor.getProcessAPI(getEngineSession()); - } catch (Exception e) { + } catch (BonitaException e) { throw new APIException(e); } } diff --git a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/bpm/process/ProcessConnectorDatastore.java b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/bpm/process/ProcessConnectorDatastore.java index 82ca76662a6..37d8d7ddcb5 100644 --- a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/bpm/process/ProcessConnectorDatastore.java +++ b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/bpm/process/ProcessConnectorDatastore.java @@ -25,6 +25,7 @@ import org.bonitasoft.engine.api.TenantAPIAccessor; import org.bonitasoft.engine.bpm.connector.ConnectorCriterion; import org.bonitasoft.engine.bpm.connector.ConnectorImplementationDescriptor; +import org.bonitasoft.engine.exception.BonitaException; import org.bonitasoft.engine.session.APISession; import org.bonitasoft.web.rest.model.bpm.process.ProcessConnectorItem; import org.bonitasoft.web.rest.server.datastore.CommonDatastore; @@ -51,7 +52,7 @@ public ProcessConnectorDatastore(final APISession engineSession) { protected ProcessAPI getProcessAPI() { try { return TenantAPIAccessor.getProcessAPI(getEngineSession()); - } catch (final Exception e) { + } catch (final BonitaException e) { throw new APIException(e); } } @@ -70,7 +71,7 @@ public ProcessConnectorItem get(final APIID id) { connector.setProcessId(id.getPartAsLong(ATTRIBUTE_PROCESS_ID)); return connector; - } catch (final Exception e) { + } catch (final BonitaException e) { throw new APIException(e); } } @@ -80,31 +81,26 @@ public ItemSearchResult search(final int page, final int r final String orders, final Map filters) { - try { - final Long processId = MapUtil.getValueAsLong(filters, ATTRIBUTE_PROCESS_ID); - - final List connectors = getProcessAPI().getConnectorImplementations( - processId, - SearchOptionsBuilderUtil.computeIndex(page, resultsByPage), - resultsByPage, - ConnectorCriterion.valueOf(orders.toUpperCase().replace(" ", "_"))); + final Long processId = MapUtil.getValueAsLong(filters, ATTRIBUTE_PROCESS_ID); - final List results = new ArrayList<>(); - for (final ConnectorImplementationDescriptor connector : connectors) { - final ProcessConnectorItem result = convertEngineToConsoleItem(connector); - // Correct missing element in engine object - result.setProcessId(processId); + final List connectors = getProcessAPI().getConnectorImplementations( + processId, + SearchOptionsBuilderUtil.computeIndex(page, resultsByPage), + resultsByPage, + ConnectorCriterion.valueOf(orders.toUpperCase().replace(" ", "_"))); - results.add(result); - } + final List results = new ArrayList<>(); + for (final ConnectorImplementationDescriptor connector : connectors) { + final ProcessConnectorItem result = convertEngineToConsoleItem(connector); + // Correct missing element in engine object + result.setProcessId(processId); - final long numtotalConnectorImplem = getProcessAPI().getNumberOfConnectorImplementations(processId); + results.add(result); + } - return new ItemSearchResult<>(page, resultsByPage, numtotalConnectorImplem, results); + final long numtotalConnectorImplem = getProcessAPI().getNumberOfConnectorImplementations(processId); - } catch (final Exception e) { - throw new APIException(e); - } + return new ItemSearchResult<>(page, resultsByPage, numtotalConnectorImplem, results); } @Override diff --git a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/bpm/process/ProcessConnectorDependencyDatastore.java b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/bpm/process/ProcessConnectorDependencyDatastore.java index bf361ee5e64..4e22c5f34d9 100644 --- a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/bpm/process/ProcessConnectorDependencyDatastore.java +++ b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/bpm/process/ProcessConnectorDependencyDatastore.java @@ -25,6 +25,7 @@ import org.bonitasoft.engine.api.ProcessAPI; import org.bonitasoft.engine.api.TenantAPIAccessor; import org.bonitasoft.engine.bpm.connector.ConnectorImplementationDescriptor; +import org.bonitasoft.engine.exception.BonitaException; import org.bonitasoft.engine.session.APISession; import org.bonitasoft.web.rest.model.bpm.process.ProcessConnectorDependencyItem; import org.bonitasoft.web.rest.server.datastore.CommonDatastore; @@ -47,7 +48,7 @@ public ProcessConnectorDependencyDatastore(final APISession engineSession) { protected ProcessAPI getProcessAPI() { try { return TenantAPIAccessor.getProcessAPI(getEngineSession()); - } catch (Exception e) { + } catch (BonitaException e) { throw new APIException(e); } } @@ -81,7 +82,7 @@ public ItemSearchResult search(final int page, f return new ItemSearchResult<>(page, results.size(), jarDependencies.size(), results); - } catch (final Exception e) { + } catch (final BonitaException e) { throw new APIException(e); } diff --git a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/bpm/process/ProcessDatastore.java b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/bpm/process/ProcessDatastore.java index 71c8e892f57..c2e3adca59e 100644 --- a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/bpm/process/ProcessDatastore.java +++ b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/bpm/process/ProcessDatastore.java @@ -27,6 +27,7 @@ import org.bonitasoft.engine.api.TenantAPIAccessor; import org.bonitasoft.engine.bpm.bar.BusinessArchive; import org.bonitasoft.engine.bpm.bar.BusinessArchiveFactory; +import org.bonitasoft.engine.bpm.bar.InvalidBusinessArchiveFormatException; import org.bonitasoft.engine.bpm.process.ProcessDefinition; import org.bonitasoft.engine.bpm.process.ProcessDefinitionNotFoundException; import org.bonitasoft.engine.bpm.process.ProcessDeploymentInfo; @@ -124,7 +125,7 @@ protected BonitaHomeFolderAccessor getTenantFolder() { protected BusinessArchive readBusinessArchive(final InputStream inputStream) { try { return BusinessArchiveFactory.readBusinessArchive(inputStream); - } catch (final Exception e) { + } catch (final IOException | InvalidBusinessArchiveFormatException e) { throw new APIException(e); } } @@ -202,7 +203,7 @@ protected void removeProcessPagesFromHome(final APIID id) { getCustomPageService().removePageLocally(page); } } while (startIndex < count); - } catch (final Exception e) { + } catch (final BonitaException | IOException e) { if (LOGGER.isWarnEnabled()) { LOGGER.warn("Error when deleting pages for process with ID " + id, e); } @@ -216,7 +217,7 @@ protected CustomPageService getCustomPageService() { protected PageAPI getPageAPI() { try { return TenantAPIAccessor.getCustomPageAPI(getEngineSession()); - } catch (final Exception e) { + } catch (final BonitaException e) { throw new APIException(e); } } diff --git a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/organization/GroupDatastore.java b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/organization/GroupDatastore.java index 490b0c4d0be..018a691ab75 100644 --- a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/organization/GroupDatastore.java +++ b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/organization/GroupDatastore.java @@ -19,6 +19,7 @@ import java.util.Map; import org.bonitasoft.engine.api.TenantAPIAccessor; +import org.bonitasoft.engine.exception.BonitaException; import org.bonitasoft.engine.identity.Group; import org.bonitasoft.engine.identity.GroupCreator; import org.bonitasoft.engine.identity.GroupSearchDescriptor; @@ -54,7 +55,7 @@ public GroupDatastore(final APISession engineSession) { super(engineSession); } - private GroupEngineClient getGroupEngineClient() { + public GroupEngineClient getGroupEngineClient() { return new EngineClientFactory(new EngineAPIAccessor(getEngineSession())) .createGroupEngineClient(); } @@ -84,7 +85,7 @@ public ItemSearchResult search(final int page, final int resultsByPag return new ItemSearchResult<>(page, resultsByPage, engineSearchResults.getCount(), new GroupItemConverter().convert(engineSearchResults.getResult())); - } catch (final Exception e) { + } catch (final BonitaException e) { throw new APIException(e); } } @@ -112,7 +113,7 @@ public GroupItem add(final GroupItem group) { public Long getNumberOfUsers(final APIID groupId) { try { return TenantAPIAccessor.getIdentityAPI(getEngineSession()).getNumberOfUsersInGroup(groupId.toLong()); - } catch (final Exception e) { + } catch (final BonitaException e) { throw new APIException(e); } } diff --git a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/organization/PersonalContactDataDatastore.java b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/organization/PersonalContactDataDatastore.java index ad5f4a0e408..016c1ee7c57 100644 --- a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/organization/PersonalContactDataDatastore.java +++ b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/organization/PersonalContactDataDatastore.java @@ -16,19 +16,18 @@ import java.util.Map; import org.bonitasoft.engine.api.TenantAPIAccessor; +import org.bonitasoft.engine.exception.BonitaException; import org.bonitasoft.engine.exception.NotFoundException; import org.bonitasoft.engine.identity.ContactData; import org.bonitasoft.engine.identity.ContactDataUpdater; import org.bonitasoft.engine.identity.UserUpdater; import org.bonitasoft.engine.session.APISession; -import org.bonitasoft.engine.session.InvalidSessionException; import org.bonitasoft.web.rest.model.identity.PersonalContactDataItem; import org.bonitasoft.web.rest.server.datastore.CommonDatastore; import org.bonitasoft.web.rest.server.framework.api.DatastoreHasAdd; import org.bonitasoft.web.rest.server.framework.api.DatastoreHasGet; import org.bonitasoft.web.rest.server.framework.api.DatastoreHasUpdate; import org.bonitasoft.web.toolkit.client.common.exception.api.APIException; -import org.bonitasoft.web.toolkit.client.common.exception.api.APISessionInvalidException; import org.bonitasoft.web.toolkit.client.data.APIID; /** @@ -51,9 +50,7 @@ public PersonalContactDataItem get(final APIID id) { return createContactDataItemConverter(id).convert(result); } catch (final NotFoundException e) { return null; - } catch (final InvalidSessionException e) { - throw new APISessionInvalidException(e); - } catch (final Exception e) { + } catch (final BonitaException e) { throw new APIException(e); } } @@ -107,9 +104,7 @@ public PersonalContactDataItem update(final APIID id, final Map TenantAPIAccessor.getIdentityAPI(getEngineSession()).updateUser(id.toLong(), userUpdater); return get(id); - } catch (final InvalidSessionException e) { - throw new APISessionInvalidException(e); - } catch (final Exception e) { + } catch (final BonitaException e) { throw new APIException(e); } } diff --git a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/organization/ProfessionalContactDataDatastore.java b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/organization/ProfessionalContactDataDatastore.java index 52609548592..6a4a6ab4137 100644 --- a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/organization/ProfessionalContactDataDatastore.java +++ b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/organization/ProfessionalContactDataDatastore.java @@ -16,19 +16,18 @@ import java.util.Map; import org.bonitasoft.engine.api.TenantAPIAccessor; +import org.bonitasoft.engine.exception.BonitaException; import org.bonitasoft.engine.exception.NotFoundException; import org.bonitasoft.engine.identity.ContactData; import org.bonitasoft.engine.identity.ContactDataUpdater; import org.bonitasoft.engine.identity.UserUpdater; import org.bonitasoft.engine.session.APISession; -import org.bonitasoft.engine.session.InvalidSessionException; import org.bonitasoft.web.rest.model.identity.ProfessionalContactDataItem; import org.bonitasoft.web.rest.server.datastore.CommonDatastore; import org.bonitasoft.web.rest.server.framework.api.DatastoreHasAdd; import org.bonitasoft.web.rest.server.framework.api.DatastoreHasGet; import org.bonitasoft.web.rest.server.framework.api.DatastoreHasUpdate; import org.bonitasoft.web.toolkit.client.common.exception.api.APIException; -import org.bonitasoft.web.toolkit.client.common.exception.api.APISessionInvalidException; import org.bonitasoft.web.toolkit.client.data.APIID; /** @@ -52,9 +51,7 @@ public ProfessionalContactDataItem get(final APIID id) { return createContactDataItemConverter(id).convert(result); } catch (final NotFoundException e) { return null; - } catch (final InvalidSessionException e) { - throw new APISessionInvalidException(e); - } catch (final Exception e) { + } catch (final BonitaException e) { throw new APIException(e); } } @@ -108,8 +105,6 @@ public ProfessionalContactDataItem update(final APIID id, final Map ids) { getIdentityAPI().deleteRoles(longIds); - } catch (final Exception e) { + } catch (final BonitaException e) { throw new APIException(e); } } @@ -100,9 +97,7 @@ public RoleItem update(final APIID id, final Map attributes) { return convertEngineToConsoleItem(getIdentityAPI().updateRole(id.toLong(), updater)); } catch (final RoleNotFoundException e) { throw new APINotFoundException(new T_("Unable to find role %roleId%", new Arg("roleId", id))); - } catch (APIException e) { - throw e; - } catch (final Exception e) { + } catch (final BonitaException e) { throw new APIException(e); } @@ -125,13 +120,11 @@ public RoleItem add(final RoleItem role) { } return convertEngineToConsoleItem(getIdentityAPI().createRole(creator)); - } catch (APIException e) { - throw e; } catch (AlreadyExistsException e) { throw new APIForbiddenException( new T_("Can't create role. Role '%roleName%' already exists", new Arg("roleName", role.getName())), e); - } catch (final Exception e) { + } catch (final BonitaException e) { throw new APIException(e); } @@ -161,7 +154,7 @@ public ItemSearchResult search(final int page, final int resultsByPage return new ItemSearchResult<>(page, resultsByPage, engineSearchResults.getCount(), consoleSearchResults); - } catch (final Exception e) { + } catch (final BonitaException e) { throw new APIException(e); } } @@ -172,7 +165,7 @@ public RoleItem get(final APIID id) { return convertEngineToConsoleItem(getIdentityAPI().getRole(id.toLong())); } catch (final RoleNotFoundException e) { throw new APINotFoundException(new T_("Unable to find role %roleId%", new Arg("roleId", id))); - } catch (final Exception e) { + } catch (final BonitaException e) { throw new APIException(e); } } @@ -180,7 +173,7 @@ public RoleItem get(final APIID id) { public Long getNumberOfUsers(final APIID roleId) { try { return getIdentityAPI().getNumberOfUsersInRole(roleId.toLong()); - } catch (final Exception e) { + } catch (final BonitaException e) { throw new APIException(e); } } diff --git a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/organization/UserDatastore.java b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/organization/UserDatastore.java index 024968edc2a..f6298842867 100644 --- a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/organization/UserDatastore.java +++ b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/organization/UserDatastore.java @@ -32,7 +32,7 @@ import org.bonitasoft.web.rest.server.engineclient.EngineClientFactory; import org.bonitasoft.web.rest.server.engineclient.ProcessEngineClient; import org.bonitasoft.web.rest.server.engineclient.UserEngineClient; -import org.bonitasoft.web.rest.server.framework.api.DatastoreHasGet; +import org.bonitasoft.web.rest.server.framework.api.*; import org.bonitasoft.web.rest.server.framework.exception.APIAttributeException; import org.bonitasoft.web.rest.server.framework.search.ItemSearchResult; import org.bonitasoft.web.toolkit.client.common.exception.api.APIException; @@ -42,7 +42,11 @@ * @author Séverin Moussel */ public class UserDatastore extends CommonDatastore - implements DatastoreHasGet { + implements DatastoreHasAdd, + DatastoreHasGet, + DatastoreHasSearch, + DatastoreHasUpdate, + DatastoreHasDelete { protected EngineClientFactory engineClientFactory; @@ -96,8 +100,9 @@ public UserItem get(final APIID id) { * @return This method returns an ItemSearch result containing the returned data and information about the total * possible results. */ + @Override public ItemSearchResult search(final int page, final int resultsByPage, final String search, - final Map filters, final String orders) { + final String orders, Map filters) { if (filters.containsKey(UserItem.FILTER_PROCESS_ID)) { String processId = filters.get(UserItem.FILTER_PROCESS_ID); diff --git a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/system/TenantAdminDatastore.java b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/system/TenantAdminDatastore.java index 2c065db6cf8..ca67623bc71 100644 --- a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/system/TenantAdminDatastore.java +++ b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/system/TenantAdminDatastore.java @@ -24,7 +24,6 @@ import org.bonitasoft.web.rest.server.framework.api.Datastore; import org.bonitasoft.web.rest.server.framework.api.DatastoreHasGet; import org.bonitasoft.web.rest.server.framework.api.DatastoreHasUpdate; -import org.bonitasoft.web.toolkit.client.common.exception.api.APIException; import org.bonitasoft.web.toolkit.client.data.APIID; /** @@ -48,31 +47,23 @@ public TenantAdminDatastore(final APISession apiSession) { public TenantAdminItem update(final APIID unusedId, final Map attributes) { logDeprecatedAPIUsage(); final TenantAdminItem tenantAdminItem = new TenantAdminItem(); - try { - final boolean doPause = Boolean.parseBoolean(attributes.get(TenantAdminItem.ATTRIBUTE_IS_PAUSED)); - if (!doPause) { - getTenantManagementEngineClient().resumeTenant(); - } else { - getTenantManagementEngineClient().pauseTenant(); - } - tenantAdminItem.setIsPaused(doPause); - return tenantAdminItem; - } catch (final Exception e) { - throw new APIException(e); + final boolean doPause = Boolean.parseBoolean(attributes.get(TenantAdminItem.ATTRIBUTE_IS_PAUSED)); + if (!doPause) { + getTenantManagementEngineClient().resumeTenant(); + } else { + getTenantManagementEngineClient().pauseTenant(); } + tenantAdminItem.setIsPaused(doPause); + return tenantAdminItem; } @Override public TenantAdminItem get(final APIID id) { logDeprecatedAPIUsage(); final TenantAdminItem tenantAdminItem = new TenantAdminItem(); - try { - final boolean tenantPaused = getTenantManagementEngineClient().isTenantPaused(); - tenantAdminItem.setIsPaused(tenantPaused); - return tenantAdminItem; - } catch (final Exception e) { - throw new APIException(e); - } + final boolean tenantPaused = getTenantManagementEngineClient().isTenantPaused(); + tenantAdminItem.setIsPaused(tenantPaused); + return tenantAdminItem; } protected void logDeprecatedAPIUsage() { diff --git a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/engineclient/ActivityEngineClient.java b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/engineclient/ActivityEngineClient.java index 9d60a7688fd..bbb2ad8374b 100644 --- a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/engineclient/ActivityEngineClient.java +++ b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/engineclient/ActivityEngineClient.java @@ -20,6 +20,7 @@ import org.bonitasoft.engine.bpm.data.DataInstance; import org.bonitasoft.engine.bpm.data.DataNotFoundException; import org.bonitasoft.engine.bpm.flownode.ActivityInstanceSearchDescriptor; +import org.bonitasoft.engine.exception.SearchException; import org.bonitasoft.engine.exception.UpdateException; import org.bonitasoft.engine.search.SearchOptions; import org.bonitasoft.engine.search.SearchOptionsBuilder; @@ -45,7 +46,7 @@ public long countFailedActivities() { .filter(ActivityInstanceSearchDescriptor.STATE_NAME, ActivityItem.VALUE_STATE_FAILED).done(); try { return processAPI.searchActivities(search).getCount(); - } catch (Exception e) { + } catch (SearchException e) { throw new APIException("Error when counting failed activities", e); } } diff --git a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/engineclient/CaseEngineClient.java b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/engineclient/CaseEngineClient.java index d94da97992f..dff3404bb81 100644 --- a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/engineclient/CaseEngineClient.java +++ b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/engineclient/CaseEngineClient.java @@ -21,6 +21,7 @@ import org.bonitasoft.engine.bpm.process.ProcessDefinitionNotFoundException; import org.bonitasoft.engine.bpm.process.ProcessExecutionException; import org.bonitasoft.engine.bpm.process.ProcessInstance; +import org.bonitasoft.engine.exception.SearchException; import org.bonitasoft.engine.identity.UserNotFoundException; import org.bonitasoft.engine.search.SearchOptions; import org.bonitasoft.engine.search.SearchOptionsBuilder; @@ -83,7 +84,7 @@ public long countOpenedCases() { final SearchOptions search = new SearchOptionsBuilder(0, 0).done(); try { return processAPI.searchOpenProcessInstances(search).getCount(); - } catch (final Exception e) { + } catch (final SearchException e) { throw new APIException("Error when counting opened cases", e); } } diff --git a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/engineclient/EngineAPIAccessor.java b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/engineclient/EngineAPIAccessor.java index 08c7a59d7a6..ce4c1818457 100644 --- a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/engineclient/EngineAPIAccessor.java +++ b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/engineclient/EngineAPIAccessor.java @@ -20,13 +20,9 @@ import org.bonitasoft.engine.api.ProfileAPI; import org.bonitasoft.engine.api.TenantAPIAccessor; import org.bonitasoft.engine.api.TenantAdministrationAPI; -import org.bonitasoft.engine.exception.BonitaHomeNotSetException; -import org.bonitasoft.engine.exception.ServerAPIException; -import org.bonitasoft.engine.exception.UnknownAPITypeException; +import org.bonitasoft.engine.exception.BonitaException; import org.bonitasoft.engine.session.APISession; -import org.bonitasoft.engine.session.InvalidSessionException; import org.bonitasoft.web.toolkit.client.common.exception.api.APIException; -import org.bonitasoft.web.toolkit.client.common.exception.api.APISessionInvalidException; /** * @author Vincent Elcrin @@ -46,21 +42,15 @@ public APISession getSession() { public ProfileAPI getProfileAPI() { try { return TenantAPIAccessor.getProfileAPI(getSession()); - } catch (final InvalidSessionException e) { - throw new APISessionInvalidException(e); - } catch (final BonitaHomeNotSetException e) { - throw new APIException(e); - } catch (final ServerAPIException e) { - throw new APIException(e); - } catch (final UnknownAPITypeException e) { - throw new APIException(e); + } catch (final BonitaException e) { + throw new APIException("Error when getting engine process API", e); } } public ProcessAPI getProcessAPI() { try { return TenantAPIAccessor.getProcessAPI(getSession()); - } catch (final Exception e) { + } catch (final BonitaException e) { throw new APIException("Error when getting engine process API", e); } } @@ -68,7 +58,7 @@ public ProcessAPI getProcessAPI() { public IdentityAPI getIdentityAPI() { try { return TenantAPIAccessor.getIdentityAPI(getSession()); - } catch (final Exception e) { + } catch (final BonitaException e) { throw new APIException("Error when getting engine identity API", e); } } @@ -76,7 +66,7 @@ public IdentityAPI getIdentityAPI() { public GroupAPI getGroupAPI() { try { return TenantAPIAccessor.getIdentityAPI(getSession()); - } catch (final Exception e) { + } catch (final BonitaException e) { throw new APIException("Error when getting engine group API", e); } } @@ -84,7 +74,7 @@ public GroupAPI getGroupAPI() { public PageAPI getPageAPI() { try { return TenantAPIAccessor.getCustomPageAPI(getSession()); - } catch (final Exception e) { + } catch (final BonitaException e) { throw new APIException("Error when getting engine page API", e); } } @@ -92,7 +82,7 @@ public PageAPI getPageAPI() { public TenantAdministrationAPI getTenantAdministrationAPI() { try { return TenantAPIAccessor.getTenantAdministrationAPI(getSession()); - } catch (final Exception e) { + } catch (final BonitaException e) { throw new APIException("Error when getting engine tenant management API", e); } } diff --git a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/engineclient/GroupEngineClient.java b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/engineclient/GroupEngineClient.java index 87cbcf05551..c8c02a335fb 100644 --- a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/engineclient/GroupEngineClient.java +++ b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/engineclient/GroupEngineClient.java @@ -53,6 +53,14 @@ public Group get(Long groupId) { } } + public Group getGroupByPath(String groupPath) { + try { + return groupAPI.getGroupByPath(groupPath); + } catch (GroupNotFoundException e) { + throw new APIItemNotFoundException(GroupDefinition.TOKEN, APIID.makeAPIID(groupPath)); + } + } + public String getPath(String groupId) { try { return groupAPI.getGroup(parseId(groupId)).getPath(); diff --git a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/engineclient/HumanTaskEngineClient.java b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/engineclient/HumanTaskEngineClient.java index 1aebfd1d1d6..870daf40b34 100644 --- a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/engineclient/HumanTaskEngineClient.java +++ b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/engineclient/HumanTaskEngineClient.java @@ -15,6 +15,7 @@ import org.bonitasoft.engine.api.ProcessAPI; import org.bonitasoft.engine.bpm.flownode.HumanTaskInstanceSearchDescriptor; +import org.bonitasoft.engine.exception.BonitaException; import org.bonitasoft.engine.search.SearchOptions; import org.bonitasoft.engine.search.SearchOptionsBuilder; import org.bonitasoft.web.rest.model.bpm.flownode.HumanTaskItem; @@ -37,7 +38,7 @@ public long countOpenedHumanTasks() { .filter(HumanTaskInstanceSearchDescriptor.STATE_NAME, HumanTaskItem.VALUE_STATE_READY).done(); try { return processAPI.searchHumanTaskInstances(search).getCount(); - } catch (final Exception e) { + } catch (final BonitaException e) { throw new APIException("Error when counting opened cases", e); } } diff --git a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/engineclient/ProcessEngineClient.java b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/engineclient/ProcessEngineClient.java index 93b7fe1a309..a8516c23b14 100644 --- a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/engineclient/ProcessEngineClient.java +++ b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/engineclient/ProcessEngineClient.java @@ -18,13 +18,7 @@ import org.bonitasoft.engine.api.ProcessAPI; import org.bonitasoft.engine.bpm.bar.BusinessArchive; import org.bonitasoft.engine.bpm.data.DataDefinition; -import org.bonitasoft.engine.bpm.process.DesignProcessDefinition; -import org.bonitasoft.engine.bpm.process.ProcessDefinition; -import org.bonitasoft.engine.bpm.process.ProcessDefinitionNotFoundException; -import org.bonitasoft.engine.bpm.process.ProcessDeploymentInfo; -import org.bonitasoft.engine.bpm.process.ProcessDeploymentInfoSearchDescriptor; -import org.bonitasoft.engine.bpm.process.ProcessDeploymentInfoUpdater; -import org.bonitasoft.engine.bpm.process.V6FormDeployException; +import org.bonitasoft.engine.bpm.process.*; import org.bonitasoft.engine.exception.AlreadyExistsException; import org.bonitasoft.engine.exception.BonitaException; import org.bonitasoft.engine.exception.DeletionException; @@ -69,8 +63,6 @@ public ProcessDeploymentInfo getProcessDeploymentInfo(final long processId) { LOGGER.debug("Unable to find process with id " + processId); throw new APIItemNotFoundException(org.bonitasoft.web.rest.model.bpm.process.ProcessDefinition.TOKEN, APIID.makeAPIID(processId)); - } catch (final Exception e) { - throw new APIException("Error when getting process deployment information", e); } } @@ -93,7 +85,7 @@ public ProcessDefinition deploy(final BusinessArchive businessArchive) { "Process %appName% in version %version% contains 6.x Legacy artifacts (forms or case overview page). Those are based on Google Web Toolkit (GWT), a technology that is no longer supported by Bonita. To know more, check the documentation.", new Arg("appName", processDefinition.getName()), new Arg("version", processDefinition.getVersion())), e); - } catch (final Exception e) { + } catch (final ProcessDeployException e) { throw new APIException(new T_("Unable to deploy business archive"), e); } } @@ -101,7 +93,7 @@ public ProcessDefinition deploy(final BusinessArchive businessArchive) { public void enableProcess(final long processId) { try { getProcessApi().enableProcess(processId); - } catch (final Exception e) { + } catch (final BonitaException e) { throw new APIException(new T_("Unable to enable process"), e); } } @@ -109,7 +101,7 @@ public void enableProcess(final long processId) { public void disableProcess(final long processId) { try { getProcessApi().disableProcess(processId); - } catch (final Exception e) { + } catch (final BonitaException e) { throw new APIException(new T_("Unable to disable process"), e); } } @@ -119,7 +111,7 @@ public ProcessDeploymentInfo updateProcessDeploymentInfo(final long processId, try { getProcessApi().updateProcessDeploymentInfo(processId, processDeploymentInfoUpdater); return getProcessApi().getProcessDeploymentInfo(processId); - } catch (final Exception e) { + } catch (final BonitaException e) { throw new APIException(new T_("Error when updating process deployment informations"), e); } } @@ -196,7 +188,7 @@ public void deleteProcessInstancesByBunch(final long processId, final int bunchS public SearchResult searchProcessDefinitions(final SearchOptions searchOptions) { try { return getProcessApi().searchProcessDeploymentInfos(searchOptions); - } catch (final Exception e) { + } catch (final SearchException e) { throw new APIException("Error when searching process definition", e); } } @@ -205,7 +197,7 @@ public SearchResult searchProcessDefinitionsSupervisedBy( final SearchOptions searchOptions) { try { return getProcessApi().searchProcessDeploymentInfosSupervisedBy(userId, searchOptions); - } catch (final Exception e) { + } catch (final SearchException e) { throw new APIException("Error when searching process definition supervised by user " + userId, e); } } @@ -214,7 +206,7 @@ public SearchResult searchUncategorizedProcessDefinitions final SearchOptions searchOptions) { try { return getProcessApi().searchUncategorizedProcessDeploymentInfosCanBeStartedBy(userId, searchOptions); - } catch (final Exception e) { + } catch (final SearchException e) { throw new APIException( "Error when searching uncategorized process definition which can be started by user " + userId, e); } @@ -224,7 +216,7 @@ public SearchResult searchRecentlyStartedProcessDefinitio final SearchOptions searchOptions) { try { return getProcessApi().searchProcessDeploymentInfosStartedBy(userId, searchOptions); - } catch (final Exception e) { + } catch (final SearchException e) { throw new APIException("Error when searching recently started process by user " + userId, e); } } @@ -235,7 +227,7 @@ public long countResolvedProcesses() { ProcessItem.VALUE_CONFIGURATION_STATE_RESOLVED); try { return getProcessApi().searchProcessDeploymentInfos(builder.done()).getCount(); - } catch (final Exception e) { + } catch (final SearchException e) { throw new APIException("Error when counting resolved processes", e); } } diff --git a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/engineclient/ProfileEngineClient.java b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/engineclient/ProfileEngineClient.java index 93cb9f985ab..852bea9e882 100644 --- a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/engineclient/ProfileEngineClient.java +++ b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/engineclient/ProfileEngineClient.java @@ -23,11 +23,9 @@ import org.bonitasoft.engine.profile.ProfileNotFoundException; import org.bonitasoft.engine.search.SearchOptions; import org.bonitasoft.engine.search.SearchResult; -import org.bonitasoft.engine.session.InvalidSessionException; import org.bonitasoft.web.rest.model.portal.profile.ProfileDefinition; import org.bonitasoft.web.toolkit.client.common.exception.api.APIException; import org.bonitasoft.web.toolkit.client.common.exception.api.APIItemNotFoundException; -import org.bonitasoft.web.toolkit.client.common.exception.api.APISessionInvalidException; import org.bonitasoft.web.toolkit.client.data.APIID; /** @@ -44,8 +42,6 @@ public ProfileEngineClient(ProfileAPI profileApi) { public Profile getProfile(Long id) { try { return profileApi.getProfile(id); - } catch (InvalidSessionException e) { - throw new APISessionInvalidException(e); } catch (RetrieveException e) { throw new APIException(e); } catch (ProfileNotFoundException e) { @@ -56,8 +52,6 @@ public Profile getProfile(Long id) { public SearchResult searchProfiles(SearchOptions options) { try { return profileApi.searchProfiles(options); - } catch (InvalidSessionException e) { - throw new APISessionInvalidException(e); } catch (SearchException e) { throw new APIException(e); } @@ -66,8 +60,6 @@ public SearchResult searchProfiles(SearchOptions options) { public List listProfilesForUser(long userId) { try { return profileApi.getProfilesForUser(userId, 0, Integer.MAX_VALUE, ProfileCriterion.ID_ASC); - } catch (InvalidSessionException e) { - throw new APISessionInvalidException(e); } catch (RetrieveException e) { throw new APIException(e); } diff --git a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/engineclient/ProfileMemberEngineClient.java b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/engineclient/ProfileMemberEngineClient.java index bd54279b2e6..5da0abb7102 100644 --- a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/engineclient/ProfileMemberEngineClient.java +++ b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/engineclient/ProfileMemberEngineClient.java @@ -22,12 +22,10 @@ import org.bonitasoft.engine.profile.ProfileMemberNotFoundException; import org.bonitasoft.engine.search.SearchOptions; import org.bonitasoft.engine.search.SearchResult; -import org.bonitasoft.engine.session.InvalidSessionException; import org.bonitasoft.web.rest.model.portal.profile.ProfileMemberDefinition; import org.bonitasoft.web.toolkit.client.common.exception.api.APIException; import org.bonitasoft.web.toolkit.client.common.exception.api.APIForbiddenException; import org.bonitasoft.web.toolkit.client.common.exception.api.APIItemNotFoundException; -import org.bonitasoft.web.toolkit.client.common.exception.api.APISessionInvalidException; import org.bonitasoft.web.toolkit.client.common.i18n.T_; /** @@ -44,8 +42,6 @@ protected ProfileMemberEngineClient(ProfileAPI profileApi) { public SearchResult searchProfileMembers(String memberType, SearchOptions searchOptions) { try { return profileApi.searchProfileMembers(memberType, searchOptions); - } catch (InvalidSessionException e) { - throw new APISessionInvalidException(e); } catch (SearchException e) { throw new APIException(e); } @@ -54,8 +50,6 @@ public SearchResult searchProfileMembers(String memberType, Searc public ProfileMember createProfileMember(Long profileId, Long userId, Long groupId, Long roleId) { try { return profileApi.createProfileMember(profileId, userId, groupId, roleId); - } catch (InvalidSessionException e) { - throw new APISessionInvalidException(e); } catch (AlreadyExistsException e) { throw new APIForbiddenException(new T_("Profile member already exists"), e); } catch (CreationException e) { @@ -66,8 +60,6 @@ public ProfileMember createProfileMember(Long profileId, Long userId, Long group public void deleteProfileMember(Long id) { try { profileApi.deleteProfileMember(id); - } catch (InvalidSessionException e) { - throw new APISessionInvalidException(e); } catch (DeletionException e) { if (e.getCause() instanceof ProfileMemberNotFoundException) { throw new APIItemNotFoundException(ProfileMemberDefinition.TOKEN); diff --git a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/toolkit/client/common/exception/api/APISessionInvalidException.java b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/toolkit/client/common/exception/api/APISessionInvalidException.java deleted file mode 100644 index edccc97385a..00000000000 --- a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/toolkit/client/common/exception/api/APISessionInvalidException.java +++ /dev/null @@ -1,31 +0,0 @@ -/** - * Copyright (C) 2022 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.toolkit.client.common.exception.api; - -/** - * @author Séverin Moussel - */ -public class APISessionInvalidException extends APIException { - - private static final long serialVersionUID = -88365018117861938L; - - public APISessionInvalidException(final Throwable cause) { - super(cause); - } - - @Override - protected String defaultMessage() { - return "Invalid session"; - } -} diff --git a/bpm/bonita-web-server/src/test/java/org/bonitasoft/web/rest/server/api/bpm/flownode/ActivityVariableResourceTest.java b/bpm/bonita-web-server/src/test/java/org/bonitasoft/web/rest/server/api/bpm/flownode/ActivityVariableResourceTest.java index 92e38ddf186..253f15ebf2a 100644 --- a/bpm/bonita-web-server/src/test/java/org/bonitasoft/web/rest/server/api/bpm/flownode/ActivityVariableResourceTest.java +++ b/bpm/bonita-web-server/src/test/java/org/bonitasoft/web/rest/server/api/bpm/flownode/ActivityVariableResourceTest.java @@ -61,12 +61,6 @@ protected ServerResource configureResource() { return new ActivityVariableResource(processAPI); } - @Test(expected = APIException.class) - public void shouldDoGetWithNothingThowsAnApiException() throws DataNotFoundException { - //when - activityVariableResource.getTaskVariable(); - } - @Test(expected = APIException.class) public void should_throw_exception_if_attribute_is_not_found() throws Exception { // given: diff --git a/bpm/bonita-web-server/src/test/java/org/bonitasoft/web/rest/server/api/bpm/flownode/TimerEventTriggerResourceTest.java b/bpm/bonita-web-server/src/test/java/org/bonitasoft/web/rest/server/api/bpm/flownode/TimerEventTriggerResourceTest.java index 8925c65c62c..13e721717c0 100644 --- a/bpm/bonita-web-server/src/test/java/org/bonitasoft/web/rest/server/api/bpm/flownode/TimerEventTriggerResourceTest.java +++ b/bpm/bonita-web-server/src/test/java/org/bonitasoft/web/rest/server/api/bpm/flownode/TimerEventTriggerResourceTest.java @@ -20,10 +20,7 @@ import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.*; import java.util.ArrayList; import java.util.Collections; @@ -91,7 +88,7 @@ public void searchTimerEventTriggersShouldCallEngine() throws Exception { @Test(expected = APIException.class) public void searchTimerEventTriggersShouldThrowExceptionIfParameterNotFound() throws Exception { // given: - doReturn(null).when(timerEventTriggerResource).getParameter(anyString(), anyBoolean()); + doThrow(APIException.class).when(timerEventTriggerResource).getParameter(anyString(), anyBoolean()); // when: timerEventTriggerResource.searchTimerEventTriggers(); diff --git a/bpm/bonita-web-server/src/test/java/org/bonitasoft/web/rest/server/api/organization/APIUserTest.java b/bpm/bonita-web-server/src/test/java/org/bonitasoft/web/rest/server/api/organization/APIUserTest.java index 03334dd0365..cceb2221f86 100644 --- a/bpm/bonita-web-server/src/test/java/org/bonitasoft/web/rest/server/api/organization/APIUserTest.java +++ b/bpm/bonita-web-server/src/test/java/org/bonitasoft/web/rest/server/api/organization/APIUserTest.java @@ -53,7 +53,7 @@ public class APIUserTest { public void before() throws Exception { ItemDefinitionFactory.setDefaultFactory(mock(ItemDefinitionFactory.class)); apiUser = spy(new APIUser()); - doReturn(userDatastore).when(apiUser).getUserDatastore(); + doReturn(userDatastore).when(apiUser).getDefaultDatastore(); doReturn(TestValidator.class.getName()).when(apiUser).getValidatorClassName(); I18n.getInstance(); APIServletCall caller = mock(APIServletCall.class); diff --git a/bpm/bonita-web-server/src/test/java/org/bonitasoft/web/rest/server/api/resource/CommonResourceTest.java b/bpm/bonita-web-server/src/test/java/org/bonitasoft/web/rest/server/api/resource/CommonResourceTest.java index a0b971290c6..cfad975f2b1 100644 --- a/bpm/bonita-web-server/src/test/java/org/bonitasoft/web/rest/server/api/resource/CommonResourceTest.java +++ b/bpm/bonita-web-server/src/test/java/org/bonitasoft/web/rest/server/api/resource/CommonResourceTest.java @@ -32,7 +32,6 @@ import org.bonitasoft.web.rest.server.utils.FakeResource; import org.bonitasoft.web.rest.server.utils.FakeResource.FakeService; import org.bonitasoft.web.rest.server.utils.RestletTest; -import org.bonitasoft.web.toolkit.client.common.exception.api.APIException; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; @@ -137,7 +136,7 @@ public void getMandatoryParameterShouldCheckNonNull() { verify(spy).verifyNotNullParameter(objectInParameterMap, parameterName); } - @Test(expected = APIException.class) + @Test(expected = IllegalArgumentException.class) public void nullMandatoryParameterIsForbidden() { new CommonResource().verifyNotNullParameter(null, "unused"); } @@ -272,7 +271,7 @@ public void getQueryParameter_return_null() { verify(spy, times(0)).verifyNotNullParameter(anyString(), anyString()); } - @Test(expected = APIException.class) + @Test(expected = IllegalArgumentException.class) public void getQueryParameter_throws_Exception() { // given: final CommonResource spy = spy(new CommonResource()); diff --git a/bpm/bonita-web-server/src/test/java/org/bonitasoft/web/rest/server/datastore/bpm/cases/CaseDocumentDatastoreTest.java b/bpm/bonita-web-server/src/test/java/org/bonitasoft/web/rest/server/datastore/bpm/cases/CaseDocumentDatastoreTest.java index 332dc2bce2c..a4f1e2ab656 100644 --- a/bpm/bonita-web-server/src/test/java/org/bonitasoft/web/rest/server/datastore/bpm/cases/CaseDocumentDatastoreTest.java +++ b/bpm/bonita-web-server/src/test/java/org/bonitasoft/web/rest/server/datastore/bpm/cases/CaseDocumentDatastoreTest.java @@ -19,6 +19,7 @@ import static org.mockito.Mockito.*; import static org.mockito.MockitoAnnotations.initMocks; +import java.io.FileNotFoundException; import java.io.InputStream; import java.util.ArrayList; import java.util.HashMap; @@ -353,6 +354,9 @@ public void it_should_not_update_document_and_throws_exception_for_invalid_uploa attributes.put(CaseDocumentItem.ATTRIBUTE_NAME, "Doc 1"); attributes.put(CaseDocumentItem.ATTRIBUTE_UPLOAD_PATH, "unexisting.document"); final APIID id = APIID.makeAPIID(1L); + doThrow(FileNotFoundException.class).when(documentDatastore) + .buildDocumentValueFromUploadPath("unexisting.document", -1, null); + try { // When documentDatastore.update(id, attributes); diff --git a/bpm/bonita-web-server/src/test/java/org/bonitasoft/web/rest/server/datastore/bpm/process/ProcessConnectorDatastoreTest.java b/bpm/bonita-web-server/src/test/java/org/bonitasoft/web/rest/server/datastore/bpm/process/ProcessConnectorDatastoreTest.java index 740d6f70885..b9c51917099 100644 --- a/bpm/bonita-web-server/src/test/java/org/bonitasoft/web/rest/server/datastore/bpm/process/ProcessConnectorDatastoreTest.java +++ b/bpm/bonita-web-server/src/test/java/org/bonitasoft/web/rest/server/datastore/bpm/process/ProcessConnectorDatastoreTest.java @@ -102,14 +102,6 @@ public void getThrowExceptionIfProcessDefinitionIsNotFound() throws Exception { this.processConnectorDatastore.get(anAPIID("1", "name", "1")); } - @Test(expected = APIException.class) - public void searchThrowExceptionIfProcessDefinitionIsNotFound() throws Exception { - when(this.processAPI.getConnectorImplementations(anyLong(), anyInt(), anyInt(), any(ConnectorCriterion.class))) - .thenThrow(new NullPointerException()); - - this.processConnectorDatastore.search(0, 10, null, null, aProcessIdFilter("1")); - } - @Test public void searchReturnAllProcessConnectorForAProcessDefinitionId() throws Exception { final ConnectorImplementationDescriptor descriptor1 = aConnectorImplementationDescriptor("aName"); diff --git a/bpm/bonita-web-server/src/test/java/org/bonitasoft/web/rest/server/datastore/organization/UserDatastoreTest.java b/bpm/bonita-web-server/src/test/java/org/bonitasoft/web/rest/server/datastore/organization/UserDatastoreTest.java index 425441fbc51..d5a90c28d78 100644 --- a/bpm/bonita-web-server/src/test/java/org/bonitasoft/web/rest/server/datastore/organization/UserDatastoreTest.java +++ b/bpm/bonita-web-server/src/test/java/org/bonitasoft/web/rest/server/datastore/organization/UserDatastoreTest.java @@ -88,7 +88,7 @@ public void testSearchWithMultipleSortOrderDoesNotThrowException() throws Except Mockito.doReturn(new SearchResultImpl<>(0, Collections. emptyList())).when(identityAPI) .searchUsers(Mockito.any(SearchOptions.class)); try { - datastore.search(0, 1, "search", Collections.emptyMap(), sort); + datastore.search(0, 1, "search", sort, Collections.emptyMap()); } catch (Exception e) { Assert.fail("Search should be able to handle multiple sort"); }