-
Notifications
You must be signed in to change notification settings - Fork 164
Feature 13619 word document custom date fields inclusion #13874
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
Changes from all commits
8acecf9
c1d40f8
b62ac6a
f0044b5
d05d5ab
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,7 +19,11 @@ | |
| import java.io.File; | ||
| import java.io.IOException; | ||
| import java.nio.charset.StandardCharsets; | ||
| import java.time.LocalDate; | ||
| import java.time.format.DateTimeFormatter; | ||
| import java.time.format.FormatStyle; | ||
| import java.util.List; | ||
| import java.util.Optional; | ||
| import java.util.Properties; | ||
| import java.util.Set; | ||
| import java.util.regex.Matcher; | ||
|
|
@@ -229,6 +233,12 @@ private Properties prepareProperties( | |
| continue; | ||
| } | ||
|
|
||
| // check if the entity is from a general. | ||
| // General entities are used for common and dynamic data that can be referenced across different entities. | ||
| if (rootEntityType == RootEntityType.ROOT_GENERAL) { | ||
| fillGeneralValues(documentVariables, properties, propertyKey); | ||
| } | ||
|
|
||
| Object entity = entities.getEntity(rootEntityType); | ||
| if (entity instanceof HasUuid) { | ||
| if (documentWorkflow.isDocx() || propertyKey.contains(propertySeparator)) { | ||
|
|
@@ -284,6 +294,49 @@ private Properties prepareProperties( | |
| return properties; | ||
| } | ||
|
|
||
| /** | ||
| * Fills general values into the properties based on the provided document variables and properties. | ||
| * | ||
| * @param documentVariables | ||
| * The document variables to use for filling general values. | ||
| * @param properties | ||
| * The properties to fill with general values. | ||
| * @param propertyKey | ||
| * The property key to use for general value retrieval. | ||
| */ | ||
| private void fillGeneralValues(DocumentVariables documentVariables, Properties properties, String propertyKey) { | ||
| // finding the general property key. Based on the type, formatStyle is deciding. | ||
| // general properties are allowed only doc-formatted files. | ||
| Optional<String> generalPropertyOpt = documentVariables.getVariables() | ||
| .stream() | ||
| .filter(e -> e.startsWith(RootEntityType.ROOT_GENERAL.getEntityName() + ".")) | ||
| .filter(e -> e.equals(propertyKey)) | ||
| .findAny(); | ||
|
|
||
| if (generalPropertyOpt.isPresent()) { | ||
| String generalProperty = generalPropertyOpt.get(); | ||
| String dateType = generalProperty.substring(generalProperty.lastIndexOf('.') + 1); | ||
| FormatStyle formatStyle; | ||
| switch (dateType) { | ||
| case "long": | ||
| formatStyle = FormatStyle.LONG; | ||
| break; | ||
| case "full": | ||
| formatStyle = FormatStyle.FULL; | ||
| break; | ||
| case "medium": | ||
| formatStyle = FormatStyle.MEDIUM; | ||
| break; | ||
| case "short": | ||
| default: | ||
| formatStyle = FormatStyle.SHORT; | ||
| } | ||
| String propertyValue = | ||
| LocalDate.now().format(DateTimeFormatter.ofLocalizedDate(formatStyle).withLocale(I18nProperties.getUserLanguage().getLocale())); | ||
| properties.setProperty(generalProperty, propertyValue); | ||
|
Comment on lines
+307
to
+336
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Validate the full The rest of this class gets here via case-insensitive root matching, but this helper only accepts lowercase 🤖 Prompt for AI Agents |
||
| } | ||
| } | ||
|
|
||
| private byte[] generateDocumentDocx(File templateFile, Properties properties) throws DocumentTemplateException { | ||
| return templateEngine.generateDocumentDocx(properties, templateFile); | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.