forked from apache/incubator-kie-kogito-runtimes
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[incubator-kie-issues-1517] Add Transactional Rest endpoints to UserT…
…asks (apache#3701)
- Loading branch information
1 parent
995646c
commit f77dc94
Showing
5 changed files
with
201 additions
and
20 deletions.
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
105 changes: 105 additions & 0 deletions
105
...gito-codegen-processes/src/main/java/org/kie/kogito/codegen/process/util/CodegenUtil.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,105 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you 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.kie.kogito.codegen.process.util; | ||
|
||
import java.util.function.Function; | ||
|
||
import org.kie.kogito.codegen.api.Generator; | ||
import org.kie.kogito.codegen.api.context.KogitoBuildContext; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public final class CodegenUtil { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(CodegenUtil.class); | ||
/** | ||
* Flag used to configure transaction enabling. Default to <code>true</code> | ||
*/ | ||
public static final String TRANSACTION_ENABLED = "transactionEnabled"; | ||
|
||
private CodegenUtil() { | ||
// do nothing | ||
} | ||
|
||
/** | ||
* Creates the property for a certain generator. | ||
* | ||
* @param generator | ||
* @param propertyName | ||
* @return returns the property for certain generator | ||
*/ | ||
public static String generatorProperty(Generator generator, String propertyName) { | ||
return String.format("kogito.%s.%s", generator.name(), propertyName); | ||
} | ||
|
||
/** | ||
* Creates the property for global application | ||
* | ||
* @param propertyName | ||
* @return | ||
*/ | ||
public static String globalProperty(String propertyName) { | ||
return String.format("kogito.%s", propertyName); | ||
} | ||
|
||
/** | ||
* This computes the boolean value of the transaction being enabled based on the logic specified | ||
* the property. Default value it is true | ||
* | ||
* @see CodegenUtil#getProperty | ||
*/ | ||
public static boolean isTransactionEnabled(Generator generator, KogitoBuildContext context) { | ||
boolean propertyValue = getProperty(generator, context, TRANSACTION_ENABLED, Boolean::parseBoolean, true); | ||
LOG.info("trying to compute property {} for generator {} property with value {}", TRANSACTION_ENABLED, generator.name(), propertyValue); | ||
return propertyValue; | ||
} | ||
|
||
/** | ||
* This method is a generic method to compute certain property of the given type. | ||
* 1. we compute the global property applicable for all the application. | ||
* 2. we compute the property only applicable for certain generator. | ||
* | ||
* @see CodegenUtil#getApplicationProperty | ||
* @see CodegenUtil#globalProperty | ||
* @see CodegenUtil#generatorProperty | ||
*/ | ||
public static <T> T getProperty(Generator generator, KogitoBuildContext context, String propertyName, Function<String, T> converter, T defaultValue) { | ||
|
||
String generatorProperty = generatorProperty(generator, propertyName); | ||
if (isApplicationPropertyDefined(context, generatorProperty)) { | ||
return converter.apply(getApplicationProperty(context, generatorProperty)); | ||
} | ||
|
||
String globalProperty = globalProperty(propertyName); | ||
|
||
if (isApplicationPropertyDefined(context, globalProperty)) { | ||
return converter.apply(getApplicationProperty(context, globalProperty)); | ||
} | ||
|
||
return defaultValue; | ||
} | ||
|
||
private static boolean isApplicationPropertyDefined(KogitoBuildContext context, String property) { | ||
return context.getApplicationProperty(property).isPresent(); | ||
} | ||
|
||
private static String getApplicationProperty(KogitoBuildContext context, String property) { | ||
return context.getApplicationProperty(property).orElseThrow(() -> new IllegalArgumentException("Property " + property + " defined but does not contain proper value")); | ||
} | ||
} |
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