-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
introduce history level auto, fixes #CAM-3444 #165
Closed
jangalinski
wants to merge
3
commits into
camunda:master
from
jangalinski:CAM-3444_history_level_auto
Closed
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
engine/src/main/java/org/camunda/bpm/engine/impl/cmd/OverwriteHistoryLevelCmd.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package org.camunda.bpm.engine.impl.cmd; | ||
|
||
import org.camunda.bpm.engine.impl.SchemaOperationsProcessEngineBuild; | ||
import org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl; | ||
import org.camunda.bpm.engine.impl.db.entitymanager.DbEntityManager; | ||
import org.camunda.bpm.engine.impl.history.HistoryLevel; | ||
import org.camunda.bpm.engine.impl.interceptor.Command; | ||
import org.camunda.bpm.engine.impl.interceptor.CommandContext; | ||
|
||
|
||
public class OverwriteHistoryLevelCmd implements Command<Void> { | ||
|
||
private final ProcessEngineConfigurationImpl processEngineConfiguration; | ||
|
||
public OverwriteHistoryLevelCmd(ProcessEngineConfigurationImpl processEngineConfiguration) { | ||
this.processEngineConfiguration = processEngineConfiguration; | ||
} | ||
|
||
@Override | ||
public Void execute(CommandContext commandContext) { | ||
final Integer databaseHistoryLevel = SchemaOperationsProcessEngineBuild.databaseHistoryLevel(commandContext.getSession(DbEntityManager.class)); | ||
|
||
|
||
if (databaseHistoryLevel != null) { | ||
for (HistoryLevel historyLevel : processEngineConfiguration.getHistoryLevels()) { | ||
if (historyLevel.getId() == databaseHistoryLevel) { | ||
processEngineConfiguration.setHistoryLevel(historyLevel); | ||
processEngineConfiguration.setHistory(historyLevel.getName()); | ||
break; | ||
} | ||
} | ||
} | ||
|
||
if (processEngineConfiguration.getHistoryLevel() == null) { | ||
processEngineConfiguration.setHistoryLevel(HistoryLevel.HISTORY_LEVEL_AUDIT); | ||
processEngineConfiguration.setHistory(HistoryLevel.HISTORY_LEVEL_AUDIT.getName()); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
engine/src/test/java/org/camunda/bpm/engine/impl/cmd/OverwriteHistoryLevelCmdTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package org.camunda.bpm.engine.impl.cmd; | ||
|
||
import org.camunda.bpm.engine.ProcessEngineConfiguration; | ||
import org.camunda.bpm.engine.impl.ProcessEngineImpl; | ||
import org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl; | ||
import org.camunda.bpm.engine.impl.cfg.StandaloneInMemProcessEngineConfiguration; | ||
import org.camunda.bpm.engine.impl.history.HistoryLevel; | ||
import org.camunda.bpm.engine.impl.test.TestHelper; | ||
import org.hamcrest.CoreMatchers; | ||
import org.junit.After; | ||
import org.junit.Assert; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.ExpectedException; | ||
import org.junit.rules.ExternalResource; | ||
|
||
import java.lang.reflect.InvocationTargetException; | ||
import java.lang.reflect.Method; | ||
import java.util.UUID; | ||
|
||
import static org.junit.Assert.assertThat; | ||
|
||
public class OverwriteHistoryLevelCmdTest { | ||
|
||
|
||
private final ProcessEngineConfigurationImpl config = config("true", ProcessEngineConfiguration.HISTORY_FULL); | ||
private ProcessEngineImpl processEngineImpl; | ||
|
||
|
||
@Rule | ||
public final ExpectedException thrown = ExpectedException.none(); | ||
|
||
private static ProcessEngineConfigurationImpl config(final String historyLevel) { | ||
|
||
return config("false", historyLevel); | ||
} | ||
|
||
private static ProcessEngineConfigurationImpl config(final String schemaUpdate, final String historyLevel) { | ||
final StandaloneInMemProcessEngineConfiguration engineConfiguration = new StandaloneInMemProcessEngineConfiguration(); | ||
engineConfiguration.setProcessEngineName(UUID.randomUUID().toString()); | ||
engineConfiguration.setDatabaseSchemaUpdate(schemaUpdate); | ||
engineConfiguration.setHistory(historyLevel); | ||
engineConfiguration.setJdbcUrl("jdbc:h2:mem:DatabaseHistoryPropertyAutoTest"); | ||
|
||
return engineConfiguration; | ||
} | ||
|
||
|
||
@Test | ||
public void update_history_level_in_configuration() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { | ||
|
||
processEngineImpl = (ProcessEngineImpl) config.buildProcessEngine(); | ||
|
||
// we have to invoke init(), or several NPE occur. | ||
ProcessEngineConfigurationImpl secondConfig = config(ProcessEngineConfiguration.HISTORY_AUTO); | ||
final Method init = ProcessEngineConfigurationImpl.class.getDeclaredMethod("init"); | ||
init.setAccessible(true); | ||
init.invoke(secondConfig); | ||
|
||
config.getCommandExecutorSchemaOperations().execute(new OverwriteHistoryLevelCmd(secondConfig)); | ||
|
||
assertThat(secondConfig.getHistoryLevel(), CoreMatchers.equalTo(HistoryLevel.HISTORY_LEVEL_FULL)); | ||
} | ||
|
||
|
||
|
||
@After | ||
public void after() { | ||
TestHelper.dropSchema(processEngineImpl.getProcessEngineConfiguration()); | ||
processEngineImpl.close(); | ||
processEngineImpl = null; | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
engine/src/test/java/org/camunda/bpm/engine/impl/history/AbstractHistoryLevelTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package org.camunda.bpm.engine.impl.history; | ||
|
||
import org.camunda.bpm.engine.impl.history.event.HistoryEventType; | ||
import org.hamcrest.CoreMatchers; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
public class AbstractHistoryLevelTest { | ||
|
||
|
||
public static class MyHistoryLevel extends AbstractHistoryLevel { | ||
|
||
@Override | ||
public int getId() { | ||
return 4711; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "myName"; | ||
} | ||
|
||
@Override | ||
public boolean isHistoryEventProduced(HistoryEventType eventType, Object entity) { | ||
return false; | ||
} | ||
} | ||
|
||
@Test | ||
public void ensure_correct_toString() { | ||
Assert.assertThat(new MyHistoryLevel().toString(), CoreMatchers.is("MyHistoryLevel(name=myName, id=4711)")); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After a good night sleep, I believe calling this "DetermineHistoryLevelCmd" and letting it return a history level would be more intuitive. We would still have to pass the list of available historyLevels, in case the use defined custom ones.