-
Notifications
You must be signed in to change notification settings - Fork 225
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
[incubator-kie-issues-1517] Add Transactional Rest endpoints to UserTasks #3701
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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
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 {}", generator.name(), TRANSACTION_ENABLED, 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
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.
Just a nit-pick,
generator.name()
andTRANSACTION_ENABLED
should be switched aroundThere 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.
fixed