Skip to content

Commit

Permalink
chore(deprecation): fix various compilation warnings (#3274)
Browse files Browse the repository at this point in the history
* chore(cleanup): fix default lombok values
* refactor(exception): remove unreachable catch clauses
* fix(deprecation): remove internal deprecation usages
* refactor(java): Java automatic IDE cleanup
* fix(deprecation): refactor cache deprecation
* chore(test): fix wrong assertions
* refactor(cleanup): remove all deprecated *serviceaccessor* classes and there usages
* chore(deprecations): remove updateTenant API method along with all the model + builder + service methods + tests associated
* chore(deprecation): fix command tests
By generating the command jar file in the test itself, instead of
committing the jar file. This allows to change implementation much more
easily.
  • Loading branch information
educhastenier authored Dec 9, 2024
1 parent 57d8e58 commit 27e8d2f
Show file tree
Hide file tree
Showing 53 changed files with 162 additions and 918 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,15 @@
**/
package org.bonitasoft.engine.command;

import static org.bonitasoft.engine.commons.io.IOUtil.generateJar;
import static org.junit.Assert.*;

import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.io.IOUtils;
import org.bonitasoft.engine.CommonAPIIT;
import org.bonitasoft.engine.TestWithTechnicalUser;
import org.bonitasoft.engine.api.CommandAPI;
import org.bonitasoft.engine.exception.AlreadyExistsException;
Expand Down Expand Up @@ -62,13 +60,10 @@ public void executeUnknownCommand() throws BonitaException {

@Test
public void executeCommandWithParameters() throws BonitaException, IOException {
final InputStream stream = CommonAPIIT.class.getResourceAsStream("/commands-jar.bak");
assertNotNull(stream);
final byte[] byteArray = IOUtils.toByteArray(stream);
stream.close();
final byte[] byteArray = generateJar(IntegerCommand.class);
getCommandAPI().addDependency("commands", byteArray);
getCommandAPI().register("intReturn", "Retrieving the integer value",
"org.bonitasoft.engine.command.IntergerCommand");
"org.bonitasoft.engine.command.IntegerCommand");
final Map<String, Serializable> parameters = new HashMap<>();
parameters.put("int", 83);
final Integer actual = (Integer) getCommandAPI().execute("intReturn", parameters);
Expand All @@ -79,10 +74,7 @@ public void executeCommandWithParameters() throws BonitaException, IOException {

@Test(expected = CommandParameterizationException.class)
public void commandThrowsCommandParameterizationException() throws BonitaException, IOException {
final InputStream stream = CommonAPIIT.class.getResourceAsStream("/commands-jar.bak");
assertNotNull(stream);
final byte[] byteArray = IOUtils.toByteArray(stream);
stream.close();
final byte[] byteArray = generateJar(ParameterizationExceptionCommand.class);
getCommandAPI().addDependency("commands", byteArray);
getCommandAPI().register("except", "Throws ParameterizationException",
"org.bonitasoft.engine.command.ParameterizationExceptionCommand");
Expand All @@ -98,10 +90,7 @@ public void commandThrowsCommandParameterizationException() throws BonitaExcepti

@Test(expected = CommandExecutionException.class)
public void commandThrowsCommandExecutionException() throws BonitaException, IOException {
final InputStream stream = CommonAPIIT.class.getResourceAsStream("/commands-jar.bak");
assertNotNull(stream);
final byte[] byteArray = IOUtils.toByteArray(stream);
stream.close();
final byte[] byteArray = generateJar(ExecutionExceptionCommand.class);
getCommandAPI().addDependency("commands", byteArray);
getCommandAPI().register("except", "Throws ExecutionExceptionCommand",
"org.bonitasoft.engine.command.ExecutionExceptionCommand");
Expand Down Expand Up @@ -376,13 +365,10 @@ public void searchCommandsWithApostrophe() throws BonitaException {

@Test
public void executeCommandById() throws BonitaException, IOException {
final InputStream stream = CommonAPIIT.class.getResourceAsStream("/commands-jar.bak");
assertNotNull(stream);
final byte[] byteArray = IOUtils.toByteArray(stream);
stream.close();
final byte[] byteArray = generateJar(IntegerCommand.class);
getCommandAPI().addDependency("commands", byteArray);
final CommandDescriptor command = getCommandAPI()
.register("intReturn", "Retrieving the integer value", "org.bonitasoft.engine.command.IntergerCommand");
.register("intReturn", "Retrieving the integer value", "org.bonitasoft.engine.command.IntegerCommand");

final CommandDescriptor commandById = getCommandAPI().get(command.getId());
assertEquals(commandById.getId(), command.getId());
Expand All @@ -398,10 +384,7 @@ public void executeCommandById() throws BonitaException, IOException {

@Test(expected = BonitaRuntimeException.class)
public void executeCommandThrowsANPE() throws BonitaException, IOException {
final InputStream stream = CommonAPIIT.class.getResourceAsStream("/npe-command-jar.bak");
assertNotNull(stream);
final byte[] byteArray = IOUtils.toByteArray(stream);
stream.close();
final byte[] byteArray = generateJar(NPECommand.class);
getCommandAPI().addDependency("commands", byteArray);
getCommandAPI().register("NPEReturns", "Throws a NPE", "org.bonitasoft.engine.command.NPECommand");
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (C) 2019 Bonitasoft S.A.
* Copyright (C) 2011 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
Expand All @@ -13,16 +13,20 @@
**/
package org.bonitasoft.engine.command;

import java.io.Serializable;
import java.util.Map;

import org.bonitasoft.engine.service.ServiceAccessor;

/**
* Class to be subclassed by implementors of a tenant scope {@link Command}. It is design to be executed by the
* {@link org.bonitasoft.engine.api.CommandAPI}.
*
* @author Matthieu Chaffotte
* @see org.bonitasoft.engine.api.CommandAPI
* @since 6.0.0
* @deprecated since 9.0.0, use {@link RuntimeCommand} instead
*/
@Deprecated(forRemoval = true, since = "9.0.0")
public abstract class TenantCommand extends RuntimeCommand {
public class ExecutionExceptionCommand extends RuntimeCommand {

@Override
public Serializable execute(final Map<String, Serializable> parameters, final ServiceAccessor serviceAccessor)
throws SCommandParameterizationException, SCommandExecutionException {
throw new SCommandExecutionException("fail");
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (C) 2019 Bonitasoft S.A.
* Copyright (C) 2012 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
Expand All @@ -13,16 +13,20 @@
**/
package org.bonitasoft.engine.command;

import java.io.Serializable;
import java.util.Map;

import org.bonitasoft.engine.service.ServiceAccessor;

/**
* Class to be subclassed by implementors of a platform scope {@link Command}. It is design to be executed by the
* {@link org.bonitasoft.engine.api.PlatformCommandAPI}.
*
* @see org.bonitasoft.engine.api.PlatformCommandAPI
* @author Matthieu Chaffotte
* @since 6.0.0
* @deprecated since 9.0.0, use {@link RuntimeCommand} instead
*/
@Deprecated(forRemoval = true, since = "9.0.0")
public abstract class PlatformCommand extends RuntimeCommand {
public class IntegerCommand extends RuntimeCommand {

@Override
public Serializable execute(final Map<String, Serializable> parameters, final ServiceAccessor serviceAccessor)
throws SCommandParameterizationException, SCommandExecutionException {
return parameters.get("int");
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (C) 2019 Bonitasoft S.A.
* 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
Expand All @@ -11,16 +11,17 @@
* program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
* Floor, Boston, MA 02110-1301, USA.
**/
package org.bonitasoft.engine.service.impl;
package org.bonitasoft.engine.command;

import java.io.Serializable;
import java.util.Map;

import org.bonitasoft.engine.service.ServiceAccessor;

/**
* Access all Platform init (bootstrap) services
*
* @deprecated since 9.0.0, use {@link ServiceAccessor} instead
*/
@Deprecated(forRemoval = true, since = "9.0.0")
public interface PlatformInitServiceAccessor extends ServiceAccessor {
public class NPECommand extends RuntimeCommand {

public Serializable execute(Map<String, Serializable> parameters, ServiceAccessor serviceAccessor)
throws SCommandParameterizationException, SCommandExecutionException {
throw new NullPointerException();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (C) 2019 Bonitasoft S.A.
* Copyright (C) 2012 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
Expand All @@ -11,21 +11,22 @@
* program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
* Floor, Boston, MA 02110-1301, USA.
**/
package org.bonitasoft.engine.service;
package org.bonitasoft.engine.command;

import java.io.Serializable;
import java.util.Map;

import org.bonitasoft.engine.service.ServiceAccessor;

/**
* Accessor for tenant level engine services.
* <p>
* All server side services of the platform can be accessed using this class. Using server side services instead of an
* API might cause unexpected behaviors and
* damage your data.
*
* @author Matthieu Chaffotte
* @author Elias Ricken de Medeiros
* @author Zhao Na
* @deprecated since 9.0.0, use {@link ServiceAccessor} instead
*/
@Deprecated(forRemoval = true, since = "9.0.0")
public interface PlatformServiceAccessor extends ServiceAccessor {
public class ParameterizationExceptionCommand extends RuntimeCommand {

@Override
public Serializable execute(final Map<String, Serializable> parameters, final ServiceAccessor serviceAccessor)
throws SCommandParameterizationException, SCommandExecutionException {
throw new SCommandParameterizationException("parameters are null");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private void deleteSession(final long sessionId) throws Exception {
// register and execute a command to delete a session
platformCommandAPI.register(COMMAND_NAME, "Deletes a platform session based on its sessionId",
"org.bonitasoft.engine.command.DeletePlatformSessionCommand");
final Map<String, Serializable> parameters = new HashMap<String, Serializable>();
final Map<String, Serializable> parameters = new HashMap<>();
parameters.put("sessionId", sessionId);
platformCommandAPI.execute(COMMAND_NAME, parameters);
platformCommandAPI.unregister(COMMAND_NAME);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,19 @@
package org.bonitasoft.engine.platform;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.fail;

import org.bonitasoft.engine.bpm.CommonBPMServicesTest;
import org.bonitasoft.engine.builder.BuilderFactory;
import org.bonitasoft.engine.platform.exception.STenantUpdateException;
import org.bonitasoft.engine.platform.model.STenant;
import org.bonitasoft.engine.platform.model.builder.STenantUpdateBuilder;
import org.bonitasoft.engine.platform.model.builder.STenantUpdateBuilderFactory;
import org.bonitasoft.engine.test.util.TestUtil;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class TenantManagementIT extends CommonBPMServicesTest {

private final static String STATUS_DEACTIVATED = "DEACTIVATED";

private PlatformService platformService;

@Before
public void setup() {
platformService = getServiceAccessor().getPlatformService();
}

@After
public void cleanUpOpenTransaction() throws Exception {
public void cleanUpOpenTransaction() {
TestUtil.closeTransactionIfOpen(getTransactionService());
}

Expand All @@ -60,40 +47,4 @@ public void tenantBuilderShouldBuildValidTenant() {
assertThat(tenant.getDescription()).isEqualTo(description);
}

@Test
public void updateTenantShouldUpdateAllFields() throws Exception {
getTransactionService().begin();

final String newDescription = "newDescription";

final STenantUpdateBuilderFactory updateBuilderFactory = BuilderFactory.get(STenantUpdateBuilderFactory.class);
final STenantUpdateBuilder updateDescriptor = updateBuilderFactory.createNewInstance();
updateDescriptor.setDescription(newDescription);

platformService.updateTenant(platformService.getDefaultTenant(), updateDescriptor.done());
getTransactionService().complete();

getTransactionService().begin();
final STenant readTenant = platformService.getDefaultTenant();
getTransactionService().complete();

assertThat(readTenant.getDescription()).isEqualTo(newDescription);
}

@Test(expected = STenantUpdateException.class)
public void updateInexistantTenantShouldFail() throws Exception {
final STenant tenant = STenant.builder().name("tenant1").createdBy("mycreatedBy")
.created(System.currentTimeMillis()).status(STATUS_DEACTIVATED).defaultTenant(false).build();

getTransactionService().begin();
final STenantUpdateBuilderFactory updateBuilderFactory = BuilderFactory.get(STenantUpdateBuilderFactory.class);
final STenantUpdateBuilder updateDescriptor = updateBuilderFactory.createNewInstance();
try {
platformService.updateTenant(tenant, updateDescriptor.done());
fail("Tenant update should not work on inexistant tenant");
} finally {
getTransactionService().complete();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,9 @@
* </p>
* <p>
* A command is composed of a jar containing at least one class that implements
* <code>org.bonitasoft.engine.command.TenantCommand</code>.
* <code>org.bonitasoft.engine.command.system.CommandWithParameters</code> can be used to handle parameter more easily.
* The behavior of the command must be
* defined in the
* execute method of this class.<br>
* TenantCommand is a class available only in bonita-server.jar. In order to create the jar you will need to have a
* <code>org.bonitasoft.engine.command.RuntimeCommand</code>.
* The behavior of the command must be defined in the execute method of this class.<br>
* RuntimeCommand is a class available only in bonita-server.jar. In order to create the jar you will need to have a
* dependency on that jar.
* <p>
* The jar containing the command class must be added to the engine using the {@link CommandAPI#addDependency} method
Expand All @@ -66,7 +63,7 @@
* <pre>
* Code example:<br>
*
* In this example we deploy a command named "myCommandName". The class that implements <code>TenantCommand</code> is <code>org.bonitasoft.engine.command.IntegerCommand</code> and
* In this example we deploy a command named "myCommandName". The class that implements <code>RuntimeCommand</code> is <code>org.bonitasoft.engine.command.IntegerCommand</code> and
* is contained in the jar we deploy using CommandAPI.addDependency.
* <br>
* <br>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
* These commands are executed in a platform scope, see {@link CommandAPI} for an explanation of how to deploy, execute,
* ... a command. The only
* difference between the {@link CommandAPI} and the {@link PlatformCommandAPI} is that a platform command must extend
* {@code org.bonitasoft.engine.command.PlatformCommand}.
* {@code org.bonitasoft.engine.command.RuntimeCommand}.
*
* @author Matthieu Chaffotte
* @author Emmanuel Duchastenier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,20 @@
**/
package org.bonitasoft.engine.bdm;

import java.io.Serial;

import org.bonitasoft.engine.api.result.Status;
import org.bonitasoft.engine.api.result.Status.Level;
import org.bonitasoft.engine.bdm.validator.ValidationStatus;

/**
* @author Romain Bioteau
*/
public class BusinessObjectModelValidationException extends Exception {

@Serial
private static final long serialVersionUID = 1L;

private final ValidationStatus validationStatus;

public BusinessObjectModelValidationException(final ValidationStatus validationStatus) {
Expand All @@ -29,13 +36,9 @@ public BusinessObjectModelValidationException(final ValidationStatus validationS
@Override
public String getMessage() {
final StringBuilder sb = new StringBuilder();
for (final String errorMessage : validationStatus.getErrors()) {
sb.append("\n- ");
sb.append(errorMessage);
}
validationStatus.getStatuses().stream().filter(status -> Level.ERROR.equals(status.getLevel()))
.map(Status::getMessage).forEach(s -> sb.append("\n- ").append(s));
return sb.toString();
}

private static final long serialVersionUID = 1L;

}
Loading

0 comments on commit 27e8d2f

Please sign in to comment.