Skip to content

Commit

Permalink
MARP-1023 Remove deprecated method (#269)
Browse files Browse the repository at this point in the history
* Delete deprecated method keepFormFieldsEditableInPdf and update UT

* Update UT

* Delete deprecated methods and fields

* Update UT for DocumentTemplateWithDocumentCreationOptionsIT class

* Update UT for BaseDocFactoryGenerateDocumentsIT

* Clean up

* Handle feedback

* Handle whitespace feedback

* Change deprecated from setColor to setForeColor

---------

Co-authored-by: Hoang Vu Huy <[email protected]>
  • Loading branch information
vhhoang-axonivy and Hoang Vu Huy authored Dec 30, 2024
1 parent 506644e commit 03b429d
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 209 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import ch.ivyteam.ivy.addons.docfactory.options.DocumentCreationOptions;
import ch.ivyteam.ivy.addons.docfactory.options.FileAppenderOptions;
import ch.ivyteam.ivy.addons.docfactory.options.MultipleDocumentsCreationOptions;
import ch.ivyteam.ivy.addons.docfactory.pdf.PdfOptions;
import ch.ivyteam.ivy.addons.docfactory.test.data.Person;

public class BaseDocFactoryGenerateDocumentsIT {
Expand All @@ -43,12 +44,10 @@ public class BaseDocFactoryGenerateDocumentsIT {

private DocumentTemplate documentTemplate1, documentTemplate2, documentTemplate3;

@SuppressWarnings("deprecation")
@BeforeEach
public void setUp() throws Exception {
docFactory = BaseDocFactory.getInstance()
.withDocumentCreationOptions(
DocumentCreationOptions.getInstance().keepFormFieldsEditableInPdf(true));
docFactory = BaseDocFactory.getInstance().withDocumentCreationOptions(DocumentCreationOptions.getInstance()
.withPdfOptions(PdfOptions.getInstance().hasToKeepFormFieldsEditable(true)));

Person person = makePerson();
documentTemplate1 = DocumentTemplate.withTemplate(TEMPLATE_1).putDataAsSourceForSimpleMailMerge(person)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.junit.jupiter.api.Test;

import ch.ivyteam.ivy.addons.docfactory.options.DocumentCreationOptions;
import ch.ivyteam.ivy.addons.docfactory.pdf.PdfOptions;
import ch.ivyteam.ivy.environment.IvyTest;

@IvyTest
Expand All @@ -34,8 +35,7 @@ public void default_produces_fieldForm_not_editablePDF() {

@Test
public void with_documentCreationOptions_producing_fieldForm_editablePDF() {
@SuppressWarnings("deprecation")
var options = DocumentCreationOptions.getInstance().keepFormFieldsEditableInPdf(true);
var options = DocumentCreationOptions.getInstance().withPdfOptions(PdfOptions.getInstance().hasToKeepFormFieldsEditable(true));
var documentTemplate = DocumentTemplate.withTemplate(template)
.putDataAsSourceForMailMerge(makePerson()).withDocumentCreationOptions(options);
var resultFile = makeFile("test/documentCreationOptions/field_form_editable.pdf");
Expand All @@ -47,9 +47,7 @@ public void with_documentCreationOptions_producing_fieldForm_editablePDF() {

@Test
public void with_documentCreationOptions_producing_fieldForm_not_editablePDF() {
@SuppressWarnings("deprecation")
var options = DocumentCreationOptions.getInstance()
.keepFormFieldsEditableInPdf(false);
var options = DocumentCreationOptions.getInstance().withPdfOptions(PdfOptions.getInstance().hasToKeepFormFieldsEditable(false));
var documentTemplate = DocumentTemplate.withTemplate(template).putDataAsSourceForMailMerge(makePerson()).withDocumentCreationOptions(options);
var resultFile = makeFile("test/documentCreationOptions/field_form_not_editable.pdf");
var result = documentTemplate.produceDocument(resultFile);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.junit.jupiter.api.Test;

import ch.ivyteam.ivy.addons.docfactory.options.DocumentCreationOptions;
import ch.ivyteam.ivy.addons.docfactory.pdf.PdfOptions;
import ch.ivyteam.ivy.environment.IvyTest;

@IvyTest
Expand All @@ -22,12 +23,11 @@ public void setup() throws Exception {
template = new File(this.getClass().getResource(TEMPLATE_WITH_FIELDS_FORM_DOCX).toURI().getPath());
}

@SuppressWarnings("deprecation")
@Test
public void default_documentTemplate_DocumentCreationOptions_pdfFormFields_not_editable() {
DocumentTemplate documentTemplate = DocumentTemplate.withTemplate(template);
DocumentCreationOptions documentCreationOptions = documentTemplate.getDocumentCreationOptions();
assertThat(documentCreationOptions.isKeepFormFieldsEditableInPdf()).isFalse();
assertThat(documentCreationOptions.getPdfOptions().isKeepFormFieldsEditableInPdf()).isFalse();
}

@Test
Expand All @@ -42,20 +42,18 @@ public void set_documentTemplate_null_DocumentCreationOptions_throws_IAE() {
assertThatThrownBy(() -> DocumentTemplate.withTemplate(template).withDocumentCreationOptions(null));
}

@SuppressWarnings("deprecation")
@Test
public void set_documentTemplate_DocumentCreationOptions() {
public void set_documentTemplate_DocumentCreationOptions() {
DocumentTemplate documentTemplate = DocumentTemplate.withTemplate(template).withDocumentCreationOptions(
DocumentCreationOptions.getInstance().keepFormFieldsEditableInPdf(false));
DocumentCreationOptions.getInstance().withPdfOptions(PdfOptions.getInstance().hasToKeepFormFieldsEditable(false)));
DocumentCreationOptions documentCreationOptions = documentTemplate.getDocumentCreationOptions();
assertThat(documentCreationOptions.isKeepFormFieldsEditableInPdf()).isFalse();
assertThat(documentCreationOptions.getPdfOptions().isKeepFormFieldsEditableInPdf()).isFalse();
}

@SuppressWarnings("deprecation")
@Test
public void documentTemplate_set_DocumentCreationOptions_backed_in_documentFactory() {
DocumentTemplate documentTemplate = DocumentTemplate.withTemplate(template).withDocumentCreationOptions(
DocumentCreationOptions.getInstance().keepFormFieldsEditableInPdf(false));
DocumentCreationOptions.getInstance().withPdfOptions(PdfOptions.getInstance().hasToKeepFormFieldsEditable(false)));
DocumentCreationOptions documentCreationOptions = documentTemplate.getDocumentCreationOptions();
assertThat(documentTemplate.getDocumentFactory().documentCreationOptions).isEqualTo(documentCreationOptions);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
import org.junit.jupiter.api.Test;

import ch.ivyteam.ivy.addons.docfactory.options.DocumentCreationOptions;
import ch.ivyteam.ivy.addons.docfactory.pdf.PdfOptions;
import ch.ivyteam.ivy.environment.IvyTest;

@SuppressWarnings("deprecation")
@IvyTest
public class RemovingWhiteSpaceInPdfEditableFieldsIT {

Expand All @@ -30,9 +30,9 @@ public void setup() throws Exception {

@Test
public void defaultDoesNotRemoveWhiteSpaceInPdfEditableFields() {
documentTemplate.withDocumentCreationOptions(
DocumentCreationOptions.getInstance()
.keepFormFieldsEditableInPdf(true));
DocumentCreationOptions documentCreationOptions = DocumentCreationOptions.getInstance()
.withPdfOptions(PdfOptions.getInstance().hasToKeepFormFieldsEditable(true));
documentTemplate.withDocumentCreationOptions(documentCreationOptions);

File resultFile = DocFactoryTest.makeFile(
"test/documentTemplate/removingWhiteSpaceInPdfEditableFieldsIT/default_not_remove_fieldSpaces.pdf");
Expand All @@ -45,10 +45,9 @@ public void defaultDoesNotRemoveWhiteSpaceInPdfEditableFields() {

@Test
public void removeWhiteSpaceInPdfEditableFields() {
documentTemplate.withDocumentCreationOptions(
DocumentCreationOptions.getInstance()
.keepFormFieldsEditableInPdf(true)
.removeWhiteSpaceInPdfEditableFields(true));
DocumentCreationOptions documentCreationOptions = DocumentCreationOptions.getInstance().withPdfOptions(
PdfOptions.getInstance().hasToKeepFormFieldsEditable(true).hasToRemoveWhiteSpaceInPdfEditableFields(true));
documentTemplate.withDocumentCreationOptions(documentCreationOptions);

File resultFile = makeFile(
"test/documentTemplate/removingWhiteSpaceInPdfEditableFieldsIT/remove_fieldSpaces.pdf");
Expand All @@ -61,10 +60,9 @@ public void removeWhiteSpaceInPdfEditableFields() {

@Test
public void removeWhiteSpaceInPdfEditableFields_has_no_effect_if_fieldsNotEditable() {
documentTemplate.withDocumentCreationOptions(
DocumentCreationOptions.getInstance()
.keepFormFieldsEditableInPdf(false)
.removeWhiteSpaceInPdfEditableFields(true));
DocumentCreationOptions documentCreationOptions = DocumentCreationOptions.getInstance().withPdfOptions(
PdfOptions.getInstance().hasToKeepFormFieldsEditable(false).hasToRemoveWhiteSpaceInPdfEditableFields(true));
documentTemplate.withDocumentCreationOptions(documentCreationOptions);

File resultFile = makeFile(
"test/documentTemplate/removingWhiteSpaceInPdfEditableFieldsIT/fieldsNotEditables.pdf");
Expand All @@ -77,10 +75,9 @@ public void removeWhiteSpaceInPdfEditableFields_has_no_effect_if_fieldsNotEditab

@Test
public void removeWhiteSpaceInPdfEditableFields_has_no_effect_if_output_is_doc() {
documentTemplate.withDocumentCreationOptions(
DocumentCreationOptions.getInstance()
.keepFormFieldsEditableInPdf(true)
.removeWhiteSpaceInPdfEditableFields(true));
DocumentCreationOptions documentCreationOptions = DocumentCreationOptions.getInstance().withPdfOptions(
PdfOptions.getInstance().hasToKeepFormFieldsEditable(true).hasToRemoveWhiteSpaceInPdfEditableFields(true));
documentTemplate.withDocumentCreationOptions(documentCreationOptions);

File resultFile = makeFile("test/documentTemplate/removingWhiteSpaceInPdfEditableFieldsIT/aDoc.doc");

Expand All @@ -91,11 +88,10 @@ public void removeWhiteSpaceInPdfEditableFields_has_no_effect_if_output_is_doc()
}

@Test
public void removeWhiteSpaceInPdfEditableFields_has_no_effect_if_output_is_docx() {
documentTemplate.withDocumentCreationOptions(
DocumentCreationOptions.getInstance()
.keepFormFieldsEditableInPdf(true)
.removeWhiteSpaceInPdfEditableFields(true));
public void removeWhiteSpaceInPdfEditableFields_has_no_effect_if_output_is_docx() {
DocumentCreationOptions documentCreationOptions = DocumentCreationOptions.getInstance().withPdfOptions(
PdfOptions.getInstance().hasToKeepFormFieldsEditable(true).hasToRemoveWhiteSpaceInPdfEditableFields(true));
documentTemplate.withDocumentCreationOptions(documentCreationOptions);

File resultFile = makeFile("test/documentTemplate/removingWhiteSpaceInPdfEditableFieldsIT/aDocx.docx");

Expand All @@ -106,11 +102,10 @@ public void removeWhiteSpaceInPdfEditableFields_has_no_effect_if_output_is_docx(
}

@Test
public void removeWhiteSpaceInPdfEditableFields_has_no_effect_if_output_is_odt() {
documentTemplate.withDocumentCreationOptions(
DocumentCreationOptions.getInstance()
.keepFormFieldsEditableInPdf(true)
.removeWhiteSpaceInPdfEditableFields(true));
public void removeWhiteSpaceInPdfEditableFields_has_no_effect_if_output_is_odt() {
DocumentCreationOptions documentCreationOptions = DocumentCreationOptions.getInstance().withPdfOptions(
PdfOptions.getInstance().hasToKeepFormFieldsEditable(true).hasToRemoveWhiteSpaceInPdfEditableFields(true));
documentTemplate.withDocumentCreationOptions(documentCreationOptions);

File resultFile = makeFile("test/documentTemplate/removingWhiteSpaceInPdfEditableFieldsIT/anOdt.odt");

Expand All @@ -122,10 +117,9 @@ public void removeWhiteSpaceInPdfEditableFields_has_no_effect_if_output_is_odt()

@Test
public void removeWhiteSpaceInPdfEditableFields_has_no_effect_if_output_is_html() {
documentTemplate.withDocumentCreationOptions(
DocumentCreationOptions.getInstance()
.keepFormFieldsEditableInPdf(true)
.removeWhiteSpaceInPdfEditableFields(true));
DocumentCreationOptions documentCreationOptions = DocumentCreationOptions.getInstance().withPdfOptions(
PdfOptions.getInstance().hasToKeepFormFieldsEditable(true).hasToRemoveWhiteSpaceInPdfEditableFields(true));
documentTemplate.withDocumentCreationOptions(documentCreationOptions);

File resultFile = makeFile("test/documentTemplate/removingWhiteSpaceInPdfEditableFieldsIT/anHtml.html");

Expand All @@ -137,10 +131,9 @@ public void removeWhiteSpaceInPdfEditableFields_has_no_effect_if_output_is_html(

@Test
public void removeWhiteSpaceInPdfEditableFields_has_no_effect_if_output_is_txt() {
documentTemplate.withDocumentCreationOptions(
DocumentCreationOptions.getInstance()
.keepFormFieldsEditableInPdf(true)
.removeWhiteSpaceInPdfEditableFields(true));
DocumentCreationOptions documentCreationOptions = DocumentCreationOptions.getInstance().withPdfOptions(
PdfOptions.getInstance().hasToKeepFormFieldsEditable(true).hasToRemoveWhiteSpaceInPdfEditableFields(true));
documentTemplate.withDocumentCreationOptions(documentCreationOptions);

File resultFile = makeFile("test/documentTemplate/removingWhiteSpaceInPdfEditableFieldsIT/aTxt.txt");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ private void makeWatermarkText(Document doc, @SuppressWarnings("hiding") String
// Text will be directed from the bottom-left to the top-right corner.
watermark.setRotation(-40);
// Remove the following two lines if you need a solid black text.
watermark.getFill().setColor(Color.LIGHT_GRAY); // Try LightGray to get more
watermark.getFill().setForeColor(Color.LIGHT_GRAY); // Try LightGray to get more
// Word-style watermark
watermark.setStrokeColor(Color.LIGHT_GRAY); // Try LightGray to get more
// Word-style watermark
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1405,36 +1405,6 @@ protected <T> T getFieldMergingCallBack() {
return (T) this.fieldMergingCallback;
}

/**
* Sets the AsposeFieldMergingCallback object used to apply special rules to
* merge fields while performing the mail merge operation.<br>
* <br>
* A typical use of FieldMergingCallback objects is to insert images in merge
* fields if these merge fields name are declared as "Image:fieldName". In
* such a case the merge-field-value corresponding to this field can be a
* String (path of the image file) or the images itself as ByteArray.<br>
* <br>
* You can provide your own AsposeFieldMergingCallback object that covers your
* special needs. For example, you should override the <br>
* {@code public void fieldMerging(FieldMergingArgs arg0)}<br>
* method to apply special rules to HTML merge fields. See
* www.aspose.com/community/forums/thread/380671/html-text-with-merge-field.aspx
* @param fieldMergingCallback
* @throws IllegalArgumentException if the parameter is null.
* @deprecated use the {@link BaseDocFactory#getInstance()} for instantiating
* the DocFactory and the
* {@link BaseDocFactory#withFieldMergingCallBack(Object)} for
* setting its fieldMergingCallback
*/
@Deprecated
public void setAsposeFieldMergingCallback(AsposeFieldMergingCallback fieldMergingCallback)
throws IllegalArgumentException {
if (fieldMergingCallback == null) {
throw new IllegalArgumentException("The AsposeFieldMergingCallback must not be null.");
}
this.fieldMergingCallback = fieldMergingCallback;
}

private SimpleMergeCleanupOptions simpleMergeCleanupOptions = SimpleMergeCleanupOptions
.getRecommendedMergeCleanupOptionsForSimpleMerging();
private MergeCleanupOptions regionMergeCleanupOptions = MergeCleanupOptions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ public abstract class BaseDocFactory {
public static final String[] SUPPORTED_OUTPUT_FORMATS = new String[] {"doc", "docx", "html", "txt", "pdf",
"odt"};

@Deprecated
public static final String[] supportedOutputFormats = new String[] {"doc", "docx", "html", "txt", "pdf",
"odt"};

/* Format types for convenient use of switch control */
public static final int UNSUPPORTED_FORMAT = DocFactoryConstants.UNSUPPORTED_FORMAT;
public static final int DOC_FORMAT = DocFactoryConstants.DOC_FORMAT;
Expand Down Expand Up @@ -588,17 +584,6 @@ protected ResponseHandler getResponsHandler() {

protected Object fieldMergingCallback;

/**
* @deprecated Deprecated because of typo in method name. Please use
* {@link #withFieldMergingCallBack(Object)} instead. Will be
* removed in the future.
* @param callback
*/
@Deprecated
public <T> BaseDocFactory withFielMergingCallBack(T callback) {
return this.withFieldMergingCallBack(callback);
}

/**
* Some DocFactory may allow injecting its own FieldMerging plug-in class for
* performing mail merging. A good example is the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -808,19 +808,6 @@ public FileOperationMessage getFileOperationMessage() {
return fileOperationMessage;
}

/**
* set the fileOperationMessage Object of the DocumentTemplate.<br>
* There should be no reason to use this method, since the
* fileOperationMessage is the result of the generateDocument() method.
* @param _fop the fileOperationMessage
*/
@Deprecated
public void setFileOperationMessage(FileOperationMessage _fop) {
if (_fop != null) {
this.fileOperationMessage = _fop;
}
}

/**
* set the tableNames/Fields values HashMap Object. It clears also the
* tableNames/Fields values java.util.Hashtable object, <br>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,11 +249,6 @@ public void setTableName(String name) {
tableName = name;
}

@Deprecated
public boolean getValue(String fieldName, Object[] fieldValue) throws Exception {
return getValue(fieldName, new Ref<Object>(fieldValue[0]));
}

@Override
public boolean getValue(String fieldName, Ref<Object> fieldValue) throws Exception {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,40 +224,4 @@ private static Set<Class<?>> getTypesWhichShouldNotBeIntrospected() {
private static boolean isCollection(Object obj) {
return obj instanceof Collection || obj instanceof Map<?, ?>;
}

/**
* @deprecated Because it is not used in the DocFactory API. As this class is
* not Public API, you should not use it.
*/
@Deprecated
public static Collection<TemplateMergeField> getMergeFieldsWithBaseName(Object bean,
String mergeFieldsNamePrefix) {
if (bean == null) {
return Collections.emptyList();
}
if (StringUtils.isBlank(mergeFieldsNamePrefix)) {
mergeFieldsNamePrefix = EMPTY_MERGEFIELD_PREFIX_NAME;
} else if (!mergeFieldsNamePrefix.endsWith(DOT)) {
mergeFieldsNamePrefix = mergeFieldsNamePrefix + DOT;
}
Map<String, Object> fieldsNameValueMap = getBeanPropertyValues(bean, mergeFieldsNamePrefix);
if (fieldsNameValueMap == null) {
return Collections.emptyList();
}
Collection<TemplateMergeField> result = new ArrayList<>();
fieldsNameValueMap.forEach((key, value) -> result.add(TemplateMergeField.withName(key).withValue(value)));
return result;
}

/**
* @deprecated Use
* {@link #getChildrenMergeFieldsOfTemplateMergeField(TemplateMergeField)}
* instead Will be removed in a near future
*/
@Deprecated
public static Collection<TemplateMergeField> getChildrenMergeFieldsForObjectMergeField(
TemplateMergeField templateMergeField) {
return getChildrenMergeFieldsOfTemplateMergeField(templateMergeField);
}

}
Loading

0 comments on commit 03b429d

Please sign in to comment.