I'll attach this for reference here; along with a Maven 'POM' file (although everything is using Java Libraries, so it's not strictly necessary here).
I'll also attach the simple 'test.zip' it creates to show it works.
PART TWO: How does PRPC store Work Item Attachments ?
I have just created a simple Test Application in PRPC - I logged into the 'User Portal' and created a Work Item : it was assigned the Work Item of 'T-4' and attached three files, a PNG, a PDF and a TEXT File - like this:
So where are these stored ? I checked the PRPC Help, this page is useful for our purposes:
The system stores attachments in instances of the following concrete classes, subclasses of the Data-Work Attach- class:
Data-WorkAttach-File — Holds files of any type and format, including PDF files generated by an application.
Data-WorkAttach-Note — Contains text that is pasted into, or typed directly into, a work item.
Data-WorkAttach-URL — Records an Internet Uniform Resource Locator (URL) or Uniform Resource Identifier (URI).
Data-WorkAttach-ScreenShot — Holds screen shot attachments that usually record facts about the work item that were obtained from another system.
Data-WorkAttach-ScanDocument — Contains a TIFF image file created by a scanner.
Data-WorkAttach-ECM — File attachments saved in an external enterprise content management (ECM) system, accessed through a Connect CMIS rule.
By default, attachments are stored as rows of the pc_data_workattach table. Attachments are not stored in the same database table as the cases.
So: in fact there are different types of attachments ; so for a first draft of this - I'll stick to the simple 'Data-WorkAttach-File' types for now.
In my Designer Studio - I added the class 'Data-WorkAttach-File' to my 'pinned-classes' (we're going to look here frequently probably...); and double-clcking on this pinned-class - this brings up the instances; we can see the 3 attachments that are associated with the Work Item 'T-4': (I restricted my search to include my Work Class only, which is called 'Zip-Zipit-Work').
Its also useful to check the definition of the Class itself - to see what the 'keys' are :
So the keys are 'pxRefObjectKey' and 'pxAttachKey'; lets now look at an example instance and see what those keys are in that case; on the previous 'instances' screen - I just clicked on an instance
Tip #1: Since we are dealing with large amounts of data here (attachments) - I picked the 'hello.txt' file, because I know that is small, rather than PDF for instance!
Tip #2: Make sure your Pop-Up Blocker isn't stopping you opening up a new window !
Here's a screenshot showing the Instance Data of the 'hello.txt' attachment to Work Item 'T-4':
So far , so good - we can identify the attachments for a particular Work Item.
This is as far as I have got at time point; but I would suggest the next things to work out would be:
1. How to get at the Content ? We'll need to convert B64 encoded content to an array of Bytes...
2. How to Generate a ZIP file and write each file of the raw Bytes into a Zip Entry: where are we going to store this ZIP file ? In-memory ? A temporary file ? Are we going to create a Folder Structure or just a 'flat' structure....
3. Then we need to try the last bit of your question: how to re-attach the resultant ZIP.
I have *almost* got this working: I'm not that proud of the results for two reasons:
1. The result is fairly inelegant currently:
- There is lots of passing stuff back and forth through the Parameter Page and Local Vairables: and since I'm using 'Pass current parameter page' throughout - the Parameter Tab for the Top-Level Activity is 'bloated'.
- The Activities (except the top-level one) are all built at "baseclass" (actually, this might be the best place for them: but my original intention was to build it within my Work Pool)
2. The resultant ZIP reports as being corrupt ! (even though I can open it, and extract out the contents without an error....)
Here's what I did anyway: I have attached a RAP file - that contains *just* the Activities used.
You will need to create a Ruleset 'zipit:01-01-01' and a class structure of 'Zip-ZipIt-Work' for these to 'fit'.
Here's the Top-Level Activity - it's an extension of the one previously: does the same 'OBJ-BROWSE' as before: but now loops through the resultant 'FileAttachments.pxResults' page:
Here's the Parameter Page Definition - this basically covers all the parameters needs by all the Activities in the Call Stack: but the only real one that is needed to be in 'scope' for a caller's point of view is 'WorkItemKey'.
The way this works is to call four other Activities:
Which creates a ZipOutpuStream object from a newly created ByteOutputStream object , and passed these object references back to the Caller via the Parameter Page:
Here's the Java Step code (which is collapsed in the screenshot to save space):
Great - thanks for posting your findings here - this will benefit other people in the community as well !
One thing: be careful about using an explicit 'COMMIT' : if you plan on using this in a PRPC Flow - you should let PRPC take care of the Transaction Boundaries and let it issue any COMMITs on your behalf.
You can generate errors (on-screen and in-log) if the system issues an automatic COMMIT on some data which you have explicitly issued a manual COMMIT previously.
For testing in the Designer Studio, you will have to issue the COMMIT manually as you have done of course. (So: maybe create a WHEN condition to detect when you are running in the Designer Studio; or create a 'wrapper' version for testing which performs the COMMIT).
I quickly checked the Javadocs for the Apache Compress Library you are using; it doesn't seem to support this. (Of course: to password-protect a ZIP; it really means "Encrypt the ZIP" - so this would introduce a layer of extra complexity to the API I guess).
Do you need a 'real' Password-Protected ZIP (that is: do you need end-users to use WINZIP ,7ZIP etc to unzip the file - and provide the password) - or just an encrypted file which happens to be a ZIP ? (So the users would have to download, use a decryption tool to reveal a ZIP?)