Skip to content

Commit

Permalink
chore(merge): release-10.2.0 into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
bonita-ci committed Sep 13, 2024
2 parents 3e59df0 + 4dcffc8 commit e6323f1
Show file tree
Hide file tree
Showing 13 changed files with 186 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ public static MaintenanceAPI getMaintenanceAPI(final APISession session)
return getAPI(MaintenanceAPI.class, session);
}

public static PlatformInformationAPI getPlatformInformationAPI()
public static PlatformInformationAPI getPlatformInformationAPI(final APISession session)
throws ServerAPIException, BonitaHomeNotSetException, UnknownAPITypeException {
return getAPI(PlatformInformationAPI.class);
return getAPI(PlatformInformationAPI.class, session);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@

import java.util.Map;

import org.bonitasoft.engine.api.NoSessionRequired;
import org.bonitasoft.engine.platform.PlatformNotFoundException;

@NoSessionRequired
public interface PlatformInformationAPI {

Map<String, String> getPlatformInformation();
Map<String, String> getPlatformInformation() throws PlatformNotFoundException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,15 @@
**/
package org.bonitasoft.engine.api.impl.platform;

import static java.lang.String.valueOf;
import static org.bonitasoft.engine.execution.ProcessStarterVerifierImpl.LIMIT;

import java.util.Map;

import org.bonitasoft.engine.api.impl.AvailableInMaintenanceMode;
import org.bonitasoft.engine.api.platform.PlatformInformationAPI;
import org.bonitasoft.engine.execution.ProcessStarterVerifier;
import org.bonitasoft.engine.service.ServiceAccessorSingleton;

/**
* Provides runtime information about the platform.
Expand All @@ -28,12 +33,21 @@
@AvailableInMaintenanceMode
public class PlatformInformationAPIImpl implements PlatformInformationAPI {

private final ProcessStarterVerifier processStarterVerifier;

public PlatformInformationAPIImpl() {
this.processStarterVerifier = ServiceAccessorSingleton.getInstance().getProcessStarterVerifier();
}

protected PlatformInformationAPIImpl(ProcessStarterVerifier processStarterVerifier) {
this.processStarterVerifier = processStarterVerifier;
}

@Override
public Map<String, String> getPlatformInformation() {
return Map.of(
"edition", "subscription",
"caseCounterLimit", "75",
"caseCounter", "68",
"subscriptionStartTimestamp", "1440806400000");
"edition", "community",
"caseCounter", valueOf(processStarterVerifier.getCurrentNumberOfStartedProcessInstances()),
"caseCounterLimit", valueOf(LIMIT));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,13 @@ public interface ProcessStarterVerifier {
* @throws SProcessInstanceCreationException if the process is not in a valid state to start
*/
void verify(SProcessInstance processInstance) throws SProcessInstanceCreationException;

/**
* Get the current number of started process instances.
*
* @return -1 if non relevant in this context
*/
default long getCurrentNumberOfStartedProcessInstances() {
return -1;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public class ProcessStarterVerifierImpl implements ProcessStarterVerifier {
private final List<Long> counters = Collections.synchronizedList(new ArrayList<>());

@Autowired
ProcessStarterVerifierImpl(PlatformRetriever platformRetriever,
public ProcessStarterVerifierImpl(PlatformRetriever platformRetriever,
PlatformInformationService platformInformationService,
TransactionService transactionService,
ProcessInstanceService processInstanceService) throws Exception {
Expand Down Expand Up @@ -139,6 +139,11 @@ List<Long> readCounters() {
}
}

@Override
public long getCurrentNumberOfStartedProcessInstances() {
return counters.size();
}

String encryptDataBeforeSendingToDatabase(List<Long> counters) throws IOException {
return encrypt(OBJECT_MAPPER.writeValueAsBytes(counters));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import org.bonitasoft.engine.execution.FlowNodeExecutor;
import org.bonitasoft.engine.execution.ProcessExecutor;
import org.bonitasoft.engine.execution.ProcessInstanceInterruptor;
import org.bonitasoft.engine.execution.ProcessStarterVerifier;
import org.bonitasoft.engine.execution.archive.BPMArchiverService;
import org.bonitasoft.engine.execution.event.EventsHandler;
import org.bonitasoft.engine.execution.state.FlowNodeStateManager;
Expand Down Expand Up @@ -311,4 +312,6 @@ public interface ServiceAccessor {
PlatformRetriever getPlatformRetriever();

InstallationService getInstallationService();

ProcessStarterVerifier getProcessStarterVerifier();
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import org.bonitasoft.engine.execution.FlowNodeExecutor;
import org.bonitasoft.engine.execution.ProcessExecutor;
import org.bonitasoft.engine.execution.ProcessInstanceInterruptor;
import org.bonitasoft.engine.execution.ProcessStarterVerifier;
import org.bonitasoft.engine.execution.archive.BPMArchiverService;
import org.bonitasoft.engine.execution.event.EventsHandler;
import org.bonitasoft.engine.execution.state.FlowNodeStateManager;
Expand Down Expand Up @@ -644,4 +645,9 @@ public PlatformRetriever getPlatformRetriever() {
public InstallationService getInstallationService() {
return beanAccessor.getService(InstallationService.class);
}

@Override
public ProcessStarterVerifier getProcessStarterVerifier() {
return beanAccessor.getService(ProcessStarterVerifier.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* Copyright (C) 2024 Bonitasoft S.A.
* Bonitasoft, 32 rue Gustave Eiffel - 38000 Grenoble
* This library is free software; you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Foundation
* version 2.1 of the License.
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public License along with this
* program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
* Floor, Boston, MA 02110-1301, USA.
**/
package org.bonitasoft.engine.api.impl.platform;

import static java.lang.String.valueOf;
import static org.assertj.core.api.Assertions.assertThat;
import static org.bonitasoft.engine.execution.ProcessStarterVerifierImpl.LIMIT;
import static org.mockito.Mockito.doReturn;

import java.util.Map;

import org.bonitasoft.engine.execution.ProcessStarterVerifier;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;

@ExtendWith(MockitoExtension.class)
class PlatformInformationAPIImplTest {

@Mock
private ProcessStarterVerifier processStarterVerifier;

@InjectMocks
private PlatformInformationAPIImpl platformInformationAPI;

@Test
void platformInformationAPI_should_return_case_counters_info() {
//given
doReturn(120L).when(processStarterVerifier).getCurrentNumberOfStartedProcessInstances();

//when
final Map<String, String> platformInformation = platformInformationAPI.getPlatformInformation();

//then
assertThat(platformInformation).containsAllEntriesOf(Map.of(
"edition", "community",
"caseCounter", "120",
"caseCounterLimit", valueOf(LIMIT)));
}
}
15 changes: 10 additions & 5 deletions bpm/bonita-web-server/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,14 @@ dependencies {
testImplementation "org.mockito:mockito-core:${Deps.mockitoVersion}"
testImplementation "org.hamcrest:hamcrest:${Deps.hamcrestVersion}"
testImplementation "junit:junit:${Deps.junit4Version}"
testImplementation libs.junit5api
testImplementation "org.mockito:mockito-junit-jupiter:${Deps.mockitoVersion}"
testRuntimeOnly libs.junitJupiterEngine
testRuntimeOnly libs.junitVintageEngine
}

configurations {
all {
configureEach {
// Specify woodstox version to override the version pulled by jackson-dataformat-xml (transitive dep of restlet)
resolutionStrategy.force "com.fasterxml.woodstox:woodstox-core:${Deps.woodstoxCoreVersion}"
// Specify Guava version to override the version pulled by owasp-java-html-sanitizer
Expand Down Expand Up @@ -88,16 +92,17 @@ tasks.named("build") {
dependsOn tasks.named("buildZip")
}

tasks.named("test") {
dependsOn tasks.named("testsJar")
}

tasks.register('testsJar', Jar) {
dependsOn testClasses
archiveClassifier = 'tests'
from(sourceSets.test.output)
}

test {
useJUnitPlatform { includeEngines 'junit-jupiter', 'junit-vintage' }
dependsOn tasks.named("testsJar")
}

artifacts {
tests testsJar
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@
import javax.servlet.http.HttpSession;

import org.bonitasoft.console.common.server.utils.SessionUtil;
import org.bonitasoft.engine.api.TenantAPIAccessor;
import org.bonitasoft.engine.api.platform.PlatformInformationAPI;
import org.bonitasoft.engine.exception.BonitaHomeNotSetException;
import org.bonitasoft.engine.exception.ServerAPIException;
import org.bonitasoft.engine.exception.UnknownAPITypeException;
import org.bonitasoft.engine.session.APISession;
import org.springframework.http.HttpStatus;
import org.springframework.web.server.ResponseStatusException;
Expand All @@ -38,8 +33,4 @@ public APISession getApiSession(HttpSession session) {
return apiSession;
}

protected PlatformInformationAPI getPlatformInformationAPI()
throws BonitaHomeNotSetException, ServerAPIException, UnknownAPITypeException {
return TenantAPIAccessor.getPlatformInformationAPI();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,16 @@

import java.util.Map;

import javax.servlet.http.HttpSession;

import lombok.extern.slf4j.Slf4j;
import org.bonitasoft.engine.api.TenantAPIAccessor;
import org.bonitasoft.engine.api.platform.PlatformInformationAPI;
import org.bonitasoft.engine.exception.BonitaException;
import org.bonitasoft.engine.exception.BonitaHomeNotSetException;
import org.bonitasoft.engine.exception.ServerAPIException;
import org.bonitasoft.engine.exception.UnknownAPITypeException;
import org.bonitasoft.engine.session.APISession;
import org.bonitasoft.web.rest.server.api.AbstractRESTController;
import org.bonitasoft.web.toolkit.client.common.exception.api.APIException;
import org.springframework.http.MediaType;
Expand All @@ -27,14 +35,20 @@
@Slf4j
@RestController
@RequestMapping("/API/system/information")
public class PlatformInformationController extends AbstractRESTController {
public class SystemInformationController extends AbstractRESTController {

@GetMapping(produces = MediaType.APPLICATION_JSON_VALUE)
public Map<String, String> getPlatformInfo() {
public Map<String, String> getPlatformInfo(HttpSession session) {
try {
return getPlatformInformationAPI().getPlatformInformation();
return getPlatformInformationAPI(getApiSession(session)).getPlatformInformation();
} catch (final BonitaException e) {
throw new APIException(e);
}
}

protected PlatformInformationAPI getPlatformInformationAPI(APISession apiSession)
throws BonitaHomeNotSetException, ServerAPIException, UnknownAPITypeException {
return TenantAPIAccessor.getPlatformInformationAPI(apiSession);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**
* Copyright (C) 2024 Bonitasoft S.A.
* Bonitasoft, 32 rue Gustave Eiffel - 38000 Grenoble
* This library is free software; you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Foundation
* version 2.1 of the License.
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public License along with this
* program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
* Floor, Boston, MA 02110-1301, USA.
**/
package org.bonitasoft.web.rest.server.api.platform;

import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;

import java.util.Map;

import javax.servlet.http.HttpSession;

import org.bonitasoft.engine.api.platform.PlatformInformationAPI;
import org.bonitasoft.engine.session.APISession;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.Spy;
import org.mockito.junit.jupiter.MockitoExtension;

@ExtendWith(MockitoExtension.class)
class SystemInformationControllerTest {

@Mock
private PlatformInformationAPI platformInformationAPI;

@Spy
private SystemInformationController systemInformationController;

@Test
void get_platform_information_should_return_raw_value_from_Engine() throws Exception {
//given
APISession apiSession = mock(APISession.class);
final HttpSession httpSession = mock(HttpSession.class);
doReturn(apiSession).when(systemInformationController).getApiSession(httpSession);
doReturn(platformInformationAPI).when(systemInformationController).getPlatformInformationAPI(apiSession);
final Map<String, String> expectedInfo = Map.of("key", "value");
doReturn(expectedInfo).when(platformInformationAPI).getPlatformInformation();

//when
final Map<String, String> platformInfo = systemInformationController.getPlatformInfo(httpSession);

//then
assertThat(platformInfo).isEqualTo(expectedInfo);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ GET|living/application=[profile|Administrator, check|org.bonitasoft.permissions.
# Secure application menu resource
GET|living/application-menu=[profile|Administrator, check|org.bonitasoft.permissions.ApplicationMenuPermissionRule]

# Platform information
GET|system/information=[profile|Administrator]

#Servlets
GET|portal/documentDownload=[profile|Administrator, check|org.bonitasoft.permissions.DownloadDocumentPermissionRule]
Expand Down

0 comments on commit e6323f1

Please sign in to comment.