Topic Options
#30167 - 05/29/09 04:05 PM Metadata how to?
-nth- Offline
OL Expert

Registered: 04/01/03
Posts: 236
Loc: Lincoln, NE
I'm trying to wrap my brain around the expanded metadata functionality in V7. I found in the V7 documentation this reference:

Quote:
PlanetPress Suite 7.0 introduces a user interface to easily input and output metadata with PlanetPress Design, and use this metadata in your PlanetPress Suite Workflow Tool. Example use cases includes, but are not restricted to: adding a 'Page X of N' to a physical page (with X and N being metadata fields), adding a missing customer's email to a page by retrieving it from a database holding both the customer number and his or her email address.
I'm intrigued by the reference to using it to hold an email address looked up from a database. What would the general steps be to accomplish this? I'd first need to create a form that had a new metadata field for my email address. I know in Watch I'd need to run a CreateMetadata task on the form to create a sample meta file. At this point it gets sketchy, once I do the db lookup in Watch, how do I get the query result into a meta file that a form output task can access? I'm thinking that the meta file is recreated everytime a form output task is run and thus would overwrite any previous meta file a value would have been stored in.

I see how the meta file can transfer info back to Watch easily, but I'm trying to figure out how Watch can get info into a meta file the form can access at run time.

Can anyone illuminate my path to understanding? laugh

-nth-

Top
#30168 - 05/29/09 05:15 PM Re: Metadata how to?
Anonymous
Unregistered


Hi,

Quote:
I'm intrigued by the reference to using it to hold an email address looked up from a database. What would the general steps be to accomplish this?
The data

We have 2 databases. For the sake of simplicity, let's say these DB are CSV files.

Database#1 is used as the datafile of a PlanetPress Design document. It contains fields like:

CustomerID,CustomerFirstName,CustomerLastName,etc.

Database#2 is used to link a customer ID with its email address. I contains fields like:

CustomerID,customerEmail

The problem
The problem is the followoing: How can a PlanetPress Design document using database#1 displays the customer's email address in a page, given that the email address comes from database#2?

The solution
Using PlanetPress Suite 7's metadata tools, we can achieve this. The general steps are the following:

1. In the PlanetPress Design document, define a document marker. A document marker will separate the datafile into logical sets of datapages (and pages). Each set of pages will be considered as a document (in the metadata sense, not as a PlanetPress design document). A metadata document can be considered as an invoice. In our case, each datapage correspond to exactly one document, or 'invoice'.

To define a document marker that separates the invoice in as many documents as there are datapages:

a. Double click on the PlanetPress Design document node, then select 'Metadata' property.

b. Under 'Document Marker', select 'begin' as the Marker and leave the condition empty.

c. Close the properties window.

d. Right-click over the Metadata fields folder and select 'Refresh Metadata'

e. Double click on the Sample data pane, and select the Metadata tab. Examine it to confirm that the DocumentCount attribute behaves as expected.


2. In the PlanetPress Design document, define a metadata field at the document level, holding the customer ID.

On the data pane, select the data corresponding to the Customer ID, then drag it on the 'Metadata Fields' folder. This will create a new metadata field. You can rename it 'customerEmail', for example.

Why name this metadata field 'customerEmail' since we have selected the customer ID? The reason is that the value for this field will be changed dynamically by PlanetPress Workflow before the PlanetPress Design document outputs anything.

Again, right click on the Metadata fields folder and refresh the metadata. You can also double click on the data pane and select the metadata tab to see that a field have been created as expected.

3. In the PlanetPress Design document, create a data selection containing the defined metadata field

You must make an act of faith here. Create the data selection, and select the metadata field named 'customerEmail'. Of course, it will display the customer ID since it is what we have selected in step 2. But you have to believe that PlanetPress Workflow will change the value of this field before executing the document.

4. Send the PlanetPress Design document to the Workflow tool

5. In the Workflow tool, create a new process like the following:

Input task: anything.

Action task: Create Metadata. On the plugin's properties, select the PlanetPress Design document you just sent.

Action task: Run Script

Output task: PlanetPress Imaging (or CreatePDF, or anything that uses Optimized PostScript Stream).

6. Create a DSN for database#2
In our case, we have created the following file:

C:\metadata_demo\metadata.dsn

7. Edit the run script plugin like the following:

Code:
Option Explicit
Dim MyMeta, MyMetaField, x, MetaCustID, MyGroup
Dim MyConnection, MyRecordSet, MySQLStatement

Set MyConnection = CreateObject("ADODB.Connection")
MyConnection.Open "DBQ=C:\METADATA_DEMO;DefaultDir=C:\METADATA_DEMO;Driver={Microsoft Text Driver (*.txt; *.csv)}; etc etc...
Set MyRecordSet = CreateObject("ADODB.recordset")
MySQLStatement = "SELECT * FROM [database2.csv]"
MyRecordSet.Open MySQLStatement, MyConnection, 3,3


Set MyMeta = CreateObject("MetaDataLib.MetaFile")

MyMeta.LoadFromFile(Watch.GetMetadataFileName)

Set MyGroup = MyMeta.Job.Group(0)

For x = 1 to MyGroup.Count
   MetaCustID = trim(MyGroup.Document(x-1).Fields.ItemByName("customerEmail"))
   if MetaCustID <> "" then
      MyRecordSet.MoveFirst
      MyRecordSet.Find "CustomerID = '" & MetaCustID & "'"
      If not((MyRecordSet.BOF) OR (MyRecordSet.EOF)) Then
         MyGroup.Document(x-1).Fields.Add "customerEmail",MyRecordSet.Fields("customerEmail").Value
      end if
   end if
next

MyMeta.SaveToFile(Watch.GetMetadataFileName)
It's a little hard to explain, but this code uses the METADATA A.P.I. to perform a database lookup in the database2.csv file, then update the Metadata field called customerEmail with data coming from the database.

I think the important point at this stage is to understand how to work with the Metadata A.P.I.: dot notation, LoadFromFile, etc. In other words, try to make sense of what is done with the object of type MetaDataLib.MetaFile.

8. The output task should use the same PlanetPress Design document as the one used from the beginning.
In other words, the PlanetPress design document is dry runned first by the CreateMetadata plugin, in order to create the initial Metadata structure. The metadata structure then travels along the process with the data file. At the run script stage, the metadata structure is transformed by the script. In fact the script only changes the value of the defined metadata field. In the end, the PlanetPress design document is executed with the original datafile, but with the updated metadata structure. So the result is that the data selection performed on the customerID now displays the customer's email.

Hope this helps!

Benoit

Top
#30169 - 05/29/09 05:25 PM Re: Metadata how to?
-nth- Offline
OL Expert

Registered: 04/01/03
Posts: 236
Loc: Lincoln, NE
Thanks Benoit!

In general I was missing step 7, that the metadata API must be used to access and update the meta file using a script. I was thinking (*hoping*) it was done through a more gui driven process.

-Nate

Top
#30170 - 05/29/09 05:40 PM Re: Metadata how to?
Anonymous
Unregistered


Quote:
I was thinking (*hoping*) it was done through a more gui driven process.
You are right, this would make a nice plugin. cool

Top
#30171 - 06/01/09 08:57 PM Re: Metadata how to?
-nth- Offline
OL Expert

Registered: 04/01/03
Posts: 236
Loc: Lincoln, NE
Building on this meta idea... if I had a complex Watch workflow that needed to pass meta data to multiple forms, could I create a form with all my needed meta fields in it, call it at the beginning of the workflow (through create meta task), populate it with data and then pass that one meta file to the different forms for execution? Or does the meta file get attached to only the form that used in the create meta task?

For example, if I make a form called "master database lookups" and run it through a create meta task, would any information I collect in that meta file be available for an output task that uses a form called "Form A" and then another output task calling "Form B"?

Top
#30172 - 06/03/09 03:55 PM Re: Metadata how to?
cpamc Offline
OL User

Registered: 01/03/06
Posts: 85
Loc: Des Moines
Instead of having a whole bunch of Watch Folders we can assign the name of a document dynamically in Planet Image, however we have to place the name of the document in the data file. So for "Job A" the data would have "Job A.ptk" in the data file header and so on.

Is there a way to use Metadata to store the Document Name, or a Job Folder Path and retrieve that Metadata in Watch instead of having to put that information in the data file?

When you Set a WatchJobInfo[] by right clicking and selecting data there is a tab for metadata. But it's blank, when you select to open the folder where would you navigate to get the metadata file? Basically how do you extract the metadata info from the Design file and save it as a file or use the info in Watch?
Thanks

Top