Skip to content
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

Add localization support for CMMN Engine #2322

Merged
merged 8 commits into from
Aug 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,9 @@ default void setVariable(String variableName, Object variableValue) {
default void setTransientVariable(String variableName, Object variableValue) {
throw new UnsupportedOperationException("Setting transient variable is not supported for read only delegate execution");
}

@Override
default void setLocalizedName(String localizedName) {
throw new UnsupportedOperationException("Setting localized name is not supported for read only delegate execution");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,7 @@ public interface HistoricCaseInstance {
String getTenantId();

Map<String, Object> getCaseVariables();

/** Sets an optional localized name for the case. */
void setLocalizedName(String localizedName);
}
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,17 @@ public interface HistoricCaseInstanceQuery extends Query<HistoricCaseInstanceQue
*/
HistoricCaseInstanceQuery variableNotExists(String name);


/**
* Localize case name to specified locale.
*/
HistoricCaseInstanceQuery locale(String locale);

/**
* Instruct localization to fallback to more general locales including the default locale of the JVM if the specified locale is not found.
*/
HistoricCaseInstanceQuery withLocalizationFallback();

HistoricCaseInstanceQuery orderByCaseInstanceId();
HistoricCaseInstanceQuery orderByCaseInstanceName();
HistoricCaseInstanceQuery orderByCaseDefinitionKey();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,6 @@ public interface HistoricPlanItemInstance {

String getTenantId();

/** Sets an optional localized name for the plan item */
void setLocalizedName(String localizedName);
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,17 @@ public interface HistoricPlanItemInstanceQuery extends Query<HistoricPlanItemIns
HistoricPlanItemInstanceQuery endedAfter(Date endedAfter);
HistoricPlanItemInstanceQuery ended();
HistoricPlanItemInstanceQuery notEnded();

/**
* Localize plan item name to specified locale.
*/
HistoricPlanItemInstanceQuery locale(String locale);

/**
* Instruct localization to fallback to more general locales including the default locale of the JVM if the specified locale is not found.
*/
HistoricPlanItemInstanceQuery withLocalizationFallback();

HistoricPlanItemInstanceQuery orderByCreateTime();
HistoricPlanItemInstanceQuery orderByEndedTime();
HistoricPlanItemInstanceQuery orderByLastAvailableTime();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,9 @@ public interface CaseDefinition {
/** The tenant identifier of this case definition */
String getTenantId();

/** Sets an optional localized name for the case definition. */
void setLocalizedName(String localizedName);

/** Sets an optional localized description for the case definition */
void setLocalizedDescription(String localizedDescription);
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@ public interface CaseDefinitionQuery extends Query<CaseDefinitionQuery, CaseDefi

CaseDefinitionQuery caseDefinitionWithoutTenantId();

/**
* Localize case definition name and description to specified locale.
*/
CaseDefinitionQuery locale(String locale);

/**
* Instruct localization to fallback to more general locales including the default locale of the JVM if the specified locale is not found.
*/
CaseDefinitionQuery withLocalizationFallback();

CaseDefinitionQuery orderByCaseDefinitionCategory();

CaseDefinitionQuery orderByCaseDefinitionKey();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,6 @@ public interface CaseInstance {
*/
Map<String, Object> getCaseVariables();

/** Sets an optional localized name for the case. */
void setLocalizedName(String localizedName);
}
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,15 @@ public interface CaseInstanceQuery extends Query<CaseInstanceQuery, CaseInstance
@Deprecated
CaseInstanceQuery limitCaseInstanceVariables(Integer caseInstanceVariablesLimit);

/**
* Localize case name to specified locale.
*/
CaseInstanceQuery locale(String locale);

/**
* Instruct localization to fallback to more general locales including the default locale of the JVM if the specified locale is not found.
*/
CaseInstanceQuery withLocalizationFallback();

CaseInstanceQuery orderByCaseInstanceId();
CaseInstanceQuery orderByCaseDefinitionKey();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,7 @@ default Date getStartTime() {
String getExtraValue();
String getTenantId();


/** Sets an optional localized name for the plan item */
void setLocalizedName(String localizedName);
}
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,16 @@ public interface PlanItemInstanceQuery extends Query<PlanItemInstanceQuery, Plan
* cannot be null.
*/
PlanItemInstanceQuery caseVariableNotExists(String name);

/**
* Localize plan item name to specified locale.
*/
PlanItemInstanceQuery locale(String locale);

/**
* Instruct localization to fallback to more general locales including the default locale of the JVM if the specified locale is not found.
*/
PlanItemInstanceQuery withLocalizationFallback();

PlanItemInstanceQuery orderByCreateTime();
PlanItemInstanceQuery orderByEndTime();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.flowable.cmmn.engine;
DavidPLamas marked this conversation as resolved.
Show resolved Hide resolved

import org.flowable.cmmn.api.repository.CaseDefinition;

/**
* @author David Lamas
*/
public interface CaseDefinitionLocalizationManager {
void localize(CaseDefinition caseDefinition, String locale, boolean withLocalizationFallback);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.flowable.cmmn.engine;

import org.flowable.cmmn.api.history.HistoricCaseInstance;
import org.flowable.cmmn.api.runtime.CaseInstance;

/**
* @author David Lamas
*/
public interface CaseLocalizationManager {
void localize(CaseInstance caseInstance, String locale, boolean withLocalizationFallback);
void localize(HistoricCaseInstance historicCaseInstance, String locale, boolean withLocalizationFallback);
}
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,11 @@ public class CmmnEngineConfiguration extends AbstractEngineConfiguration impleme

protected boolean alwaysUseArraysForDmnMultiHitPolicies = true;

// Localization support
protected CaseDefinitionLocalizationManager caseDefinitionLocalizationManager;
protected CaseLocalizationManager caseLocalizationManager;
protected PlanItemLocalizationManager planItemLocalizationManager;

public static CmmnEngineConfiguration createCmmnEngineConfigurationFromResourceDefault() {
return createCmmnEngineConfigurationFromResource("flowable.cmmn.cfg.xml", "cmmnEngineConfiguration");
}
Expand Down Expand Up @@ -4194,4 +4199,31 @@ public CmmnEngineConfiguration setAlwaysUseArraysForDmnMultiHitPolicies(boolean
this.alwaysUseArraysForDmnMultiHitPolicies = alwaysUseArraysForDmnMultiHitPolicies;
return this;
}

public CaseDefinitionLocalizationManager getCaseDefinitionLocalizationManager() {
return caseDefinitionLocalizationManager;
}

public CmmnEngineConfiguration setCaseDefinitionLocalizationManager(CaseDefinitionLocalizationManager caseDefinitionLocalizationManager) {
this.caseDefinitionLocalizationManager = caseDefinitionLocalizationManager;
return this;
}

public CaseLocalizationManager getCaseLocalizationManager() {
return caseLocalizationManager;
}

public CmmnEngineConfiguration setCaseLocalizationManager(CaseLocalizationManager caseLocalizationManager) {
this.caseLocalizationManager = caseLocalizationManager;
return this;
}

public PlanItemLocalizationManager getPlanItemLocalizationManager() {
return planItemLocalizationManager;
}

public CmmnEngineConfiguration setPlanItemLocalizationManager(PlanItemLocalizationManager planItemLocalizationManager) {
this.planItemLocalizationManager = planItemLocalizationManager;
return this;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.flowable.cmmn.engine;

import org.flowable.cmmn.api.history.HistoricPlanItemInstance;
import org.flowable.cmmn.api.runtime.PlanItemInstance;

/**
* @author David Lamas
*/
public interface PlanItemLocalizationManager {
void localize(PlanItemInstance planItemInstance, String locale, boolean withLocalizationFallback);
void localize(HistoricPlanItemInstance historicPlanItemInstance, String locale, boolean withLocalizationFallback);
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ public class HistoricCaseInstanceQueryImpl extends AbstractVariableQueryImpl<His
protected List<HistoricCaseInstanceQueryImpl> orQueryObjects = new ArrayList<>();
protected HistoricCaseInstanceQueryImpl currentOrQueryObject;
protected boolean inOrStatement;
protected String locale;
protected boolean withLocalizationFallback;

public HistoricCaseInstanceQueryImpl() {
}
Expand Down Expand Up @@ -540,6 +542,12 @@ public List<HistoricCaseInstance> executeList(CommandContext commandContext) {
results = cmmnEngineConfiguration.getHistoricCaseInstanceEntityManager().findByCriteria(this);
}

if (cmmnEngineConfiguration.getCaseLocalizationManager() != null) {
for (HistoricCaseInstance historicCaseInstance : results) {
cmmnEngineConfiguration.getCaseLocalizationManager().localize(historicCaseInstance, locale, withLocalizationFallback);
}
}

return results;
}

Expand Down Expand Up @@ -867,6 +875,18 @@ public HistoricCaseInstanceQuery variableNotExists(String name) {
}
}

@Override
public HistoricCaseInstanceQuery locale(String locale) {
this.locale = locale;
return this;
}

@Override
public HistoricCaseInstanceQuery withLocalizationFallback() {
this.withLocalizationFallback = true;
return this;
}

public String getCaseDefinitionId() {
return caseDefinitionId;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import org.flowable.cmmn.api.history.HistoricPlanItemInstance;
import org.flowable.cmmn.api.history.HistoricPlanItemInstanceQuery;
import org.flowable.cmmn.engine.CmmnEngineConfiguration;
import org.flowable.cmmn.engine.impl.persistence.entity.HistoricPlanItemInstanceEntity;
import org.flowable.cmmn.engine.impl.util.CommandContextUtil;
import org.flowable.common.engine.api.FlowableIllegalArgumentException;
Expand All @@ -29,7 +30,7 @@
/**
* @author Dennis Federico
*/
public class HistoricPlanItemInstanceQueryImpl extends AbstractQuery<HistoricPlanItemInstanceQuery, HistoricPlanItemInstance>
public class HistoricPlanItemInstanceQueryImpl extends AbstractQuery<HistoricPlanItemInstanceQuery, HistoricPlanItemInstance>
implements HistoricPlanItemInstanceQuery, CacheAwareQuery<HistoricPlanItemInstanceEntity> {

private static final long serialVersionUID = 1L;
Expand Down Expand Up @@ -85,6 +86,8 @@ public class HistoricPlanItemInstanceQueryImpl extends AbstractQuery<HistoricPla
protected String tenantId;
protected String tenantIdLike;
protected boolean withoutTenantId;
protected String locale;
protected boolean withLocalizationFallback;

public HistoricPlanItemInstanceQueryImpl() {

Expand Down Expand Up @@ -424,6 +427,18 @@ public HistoricPlanItemInstanceQuery notEnded() {
return this;
}

@Override
public HistoricPlanItemInstanceQuery locale(String locale) {
this.locale = locale;
return this;
}

@Override
public HistoricPlanItemInstanceQuery withLocalizationFallback() {
this.withLocalizationFallback = true;
return this;
}

@Override
public HistoricPlanItemInstanceQuery orderByCreateTime() {
return orderBy(HistoricPlanItemInstanceQueryProperty.CREATE_TIME);
Expand Down Expand Up @@ -496,7 +511,15 @@ public long executeCount(CommandContext commandContext) {

@Override
public List<HistoricPlanItemInstance> executeList(CommandContext commandContext) {
return CommandContextUtil.getHistoricPlanItemInstanceEntityManager(commandContext).findByCriteria(this);
List<HistoricPlanItemInstance> historicPlanItems = CommandContextUtil.getHistoricPlanItemInstanceEntityManager(commandContext).findByCriteria(this);

CmmnEngineConfiguration cmmnEngineConfiguration = CommandContextUtil.getCmmnEngineConfiguration(commandContext);
if (cmmnEngineConfiguration.getPlanItemLocalizationManager() != null) {
for (HistoricPlanItemInstance historicPlanItemInstance : historicPlanItems) {
cmmnEngineConfiguration.getPlanItemLocalizationManager().localize(historicPlanItemInstance, locale, withLocalizationFallback);
}
}
return historicPlanItems;
}

public String getPlanItemInstanceId() {
Expand Down
Loading