Skip to content

Commit

Permalink
Fix for issues apache#3618, apache#2498 and apache#2006
Browse files Browse the repository at this point in the history
- Zip Files action throws error and fails IT
- Cleanup XML of action Zip File
- zip files action logs number of files zipped but generated zip files are empty
  • Loading branch information
mattcasters committed Feb 17, 2024
1 parent 79ec4d5 commit d0d0343
Show file tree
Hide file tree
Showing 8 changed files with 860 additions and 645 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

package org.apache.hop.workflow.action;

import java.lang.reflect.InvocationTargetException;
import org.apache.hop.core.exception.HopXmlException;
import org.apache.hop.core.xml.XmlHandler;
import org.apache.hop.metadata.api.IHopMetadataProvider;
import org.apache.hop.metadata.serializer.memory.MemoryMetadataProvider;
Expand All @@ -27,8 +29,8 @@
import org.w3c.dom.Node;

public class ActionSerializationTestUtil {
public static final <T extends IAction> T testSerialization(
String filename, Class<T> clazz) throws Exception {
public static final <T extends IAction> T testSerialization(String filename, Class<T> clazz)
throws Exception {
return testSerialization(filename, clazz, ActionMeta.XML_TAG, new MemoryMetadataProvider());
}

Expand All @@ -44,14 +46,30 @@ public static final <T extends IAction> T testSerialization(
Node node = XmlHandler.getSubNode(document, xmlTag);
T meta = clazz.getConstructor().newInstance();
XmlMetadataUtil.deSerializeFromXml(null, node, clazz, meta, metadataProvider);
String xml = XmlHandler.openTag(xmlTag) + meta.getXml() + XmlHandler.closeTag(xmlTag);
String xml = getXml(meta);

testXmlStringSerialization(clazz, xmlTag, metadataProvider, xml, meta);

return meta;
}

public static <T extends IAction> void testXmlStringSerialization(
Class<T> clazz, String xmlTag, IHopMetadataProvider metadataProvider, String xml, T meta)
throws HopXmlException,
InstantiationException,
IllegalAccessException,
InvocationTargetException,
NoSuchMethodException {
Document copyDocument = XmlHandler.loadXmlString(xml);
Node copyNode = XmlHandler.getSubNode(copyDocument, xmlTag);
T copy = clazz.getConstructor().newInstance();
XmlMetadataUtil.deSerializeFromXml(null, copyNode, clazz, copy, metadataProvider);
Assert.assertEquals(meta.getXml(), copy.getXml());
}

return meta;
public static String getXml(IAction action) {
return XmlHandler.openTag(ActionMeta.XML_TAG)
+ action.getXml()
+ XmlHandler.closeTag(ActionMeta.XML_TAG);
}
}
30 changes: 15 additions & 15 deletions integration-tests/actions/0008-zip-action-archive-files.hwf
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ limitations under the License.
-->
<workflow>
<name>zip-action-archive-files</name>
<name>0008-zip-action-archive-files</name>
<name_sync_with_filename>Y</name_sync_with_filename>
<description/>
<extended_description/>
Expand Down Expand Up @@ -59,24 +59,24 @@ limitations under the License.
<description/>
<type>ZIP_FILE</type>
<attributes/>
<zipfilename>${java.io.tmpdir}/zip-action-archive/${PRM_YEAR}.zip</zipfilename>
<compressionrate>1</compressionrate>
<ifzipfileexists>2</ifzipfileexists>
<wildcard>${PRM_YEAR}.*.txt</wildcard>
<wildcardexclude/>
<sourcedirectory>${java.io.tmpdir}/zip-action/</sourcedirectory>
<movetodirectory/>
<afterzip>0</afterzip>
<addfiletoresult>N</addfiletoresult>
<isfromprevious>N</isfromprevious>
<createparentfolder>Y</createparentfolder>
<SpecifyFormat>N</SpecifyFormat>
<adddate>N</adddate>
<addfiletoresult>N</addfiletoresult>
<addtime>N</addtime>
<SpecifyFormat>N</SpecifyFormat>
<date_time_format/>
<afterzip>0</afterzip>
<compressionrate>1</compressionrate>
<createMoveToDirectory>N</createMoveToDirectory>
<createparentfolder>Y</createparentfolder>
<date_time_format/>
<ifzipfileexists>0</ifzipfileexists>
<include_subfolders>N</include_subfolders>
<stored_source_path_depth>2 : project/file.txt</stored_source_path_depth>
<isfromprevious>N</isfromprevious>
<movetodirectory/>
<sourcedirectory>${java.io.tmpdir}/zip-action/</sourcedirectory>
<stored_source_path_depth>0 : /project-hop/work/transfer/input/project/file.txt</stored_source_path_depth>
<wildcard>${PRM_YEAR}.*.txt</wildcard>
<wildcardexclude/>
<zipfilename>${java.io.tmpdir}/zip-action-archive/${PRM_YEAR}.zip</zipfilename>
<parallel>N</parallel>
<xloc>224</xloc>
<yloc>48</yloc>
Expand Down
25 changes: 25 additions & 0 deletions integration-tests/actions/main-0008-zip-files.hwf
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,24 @@ limitations under the License.
<yloc>48</yloc>
<attributes_hac/>
</action>
<action>
<name>delete txt files</name>
<description/>
<type>DELETE_FILES</type>
<attributes/>
<arg_from_previous>N</arg_from_previous>
<include_subfolders>N</include_subfolders>
<fields>
<field>
<name>${java.io.tmpdir}/zip-action</name>
<filemask>.*.txt</filemask>
</field>
</fields>
<parallel>N</parallel>
<xloc>1168</xloc>
<yloc>48</yloc>
<attributes_hac/>
</action>
</actions>
<hops>
<hop>
Expand Down Expand Up @@ -201,6 +219,13 @@ limitations under the License.
<evaluation>N</evaluation>
<unconditional>N</unconditional>
</hop>
<hop>
<from>delete zip files</from>
<to>delete txt files</to>
<enabled>Y</enabled>
<evaluation>Y</evaluation>
<unconditional>N</unconditional>
</hop>
</hops>
<notepads>
</notepads>
Expand Down
Loading

0 comments on commit d0d0343

Please sign in to comment.