Designing a mapping mechanism

P

Peter Horlock

Hi!

Our company has a lot of different pdf forms,
currently about 50. Each has about 20 different
text- checkbox and or radio button fields.
These ~1000 different fields should be filled with
about 70-100 different values, mostly coming from our database,
often there is some business logic to “create†the data that will be
filled into the form, but for the text fields, the values are very often
just the same ones. However, the field names are almost never the same ones,
even in the same pdf, even on the same page – they are created by
different business units and or other clients, so we cannot change them.
Therefore, I thought about a mapping mechanism
that would map the about 100 different values to the 1000 different fields.
For the text fields, this would be relatively easy – I would define a
mapping sceme, for example a simple xml file for each pdf that would map
the field names to unique java functions in my code.
So e.g. the mapping
<mapping key=â€Country 1239†value=â€setCountryCodeâ€/> would dynamically
set the country code into the pdf before beeing downloaded.
However, I can’t find a good solution for radio buttons and checkboxes.
These fields have a value in the pdf that will trigger them to be
selected. But the meaning –
e.g. “1†means “male†or “female†can only be seen graphically if you
print out the pdf.
It get’s even more complicated for checkboxes, where each value might
set something completely different.
E.g. “My favorite color is “greenâ€, “blackâ€, “whiteâ€, “blueâ€â€¦â€¦â€
With trigger values of “abc†for green and “1†for black and “9†for
white and “BBB†for blue - this is all defined in the pdf form and we –
the IT – do not have any influence on those settings and their meanings.
Therefore, I thought of a solution to only map the text fields and to
still manually code the business logic for radio- and check boxes.
+ That way, we would have one class each for each form, but each class
would only consist of the business logic for the checkboxes and radio
buttons.
- However, the down side of this is that then you have to different ways
of how the forms get filled - an automated part and a manual part.
The xml mappings could be completely managed by our internal clients,
while all other fields would still need to be hand coded.
Another option would be to also define a mapping for radio- and check
boxes, where you would only fill out the name of the box, and then in
the code you would write the business logic. If the parser would then
find a radio button or check box, it would read the name of the field
and would hand over the execution to a specific fitting method.
+ So we would have all logic together in one central class for all pdfs,
- but this class would grow bigger and bigger......
Okay, we could then put all radio box methods into a single class and
all check box methods into another, but still, these two classes would
grow and grow with each new form.
In other words, I don't like either of these 2 solutions.
Maybe you got a better idea??

Thanks in advance,

Peter
 
M

markspace

Peter said:
These fields have a value in the pdf that will trigger them to be
selected. But the meaning –
e.g. “1†means “male†or “female†can only be seen graphically if you
print out the pdf.


I don't understand PDF forms, but can't you just make a class that
understand the mapping between the label in the PDF and the resulting value?

class PdfRadioButton {
String label;
String result;
}

PdfRadioButton male = new PdfRadioButton();
male.label = "Male";
male.result = "1";
PdfRadioButton female = new PdfRadioButton();
female.label = "Female";
female.result = "2";

I don't see a need for a constantly growing class here, just one.
It get’s even more complicated for checkboxes, where each value might
set something completely different.
E.g. “My favorite color is “greenâ€, “blackâ€, “whiteâ€, “blueâ€â€¦â€¦â€
With trigger values of “abc†for green and “1†for black and “9†for
white and “BBB†for blue - this is all defined in the pdf form and we –
the IT – do not have any influence on those settings and their meanings.

Same thing here, you just need a class to hold the mappings from one
label to the resulting value.

Now I'm probably missing something, so I'm curious what it might be.
 
P

Peter Horlock

Well,

the thing is - the mapping male => 1 is not constant.
This might be true for some fields, but not for all.
The mapping is defined / clicked with a WYSIWYG programm
by several persons from several divisions and or companies who have no
idea about programming,
and therefore there might be 100 different mappings like:

male => 1
male => 2
male ="something"
male => 4711
male => 1
male => 1
male => 2
male => e
....
and so on. what triggers the field is defined separetly in each unique
field in up to 50 different
pdfs (and growing...)
so we do have up to 150 different mappings for male,
and this is only talking about this single mapping.

Thanks in advance,

Peter
 
M

markspace

Peter said:
Well,

the thing is - the mapping male => 1 is not constant.
This might be true for some fields, but not for all.
The mapping is defined / clicked with a WYSIWYG programm
by several persons from several divisions and or companies who have no
idea about programming,
and therefore there might be 100 different mappings like:

male => 1
male => 2
male ="something"
male => 4711
male => 1
male => 1
male => 2
male => e
....
and so on. what triggers the field is defined separetly in each unique
field in up to 50 different
pdfs (and growing...)
so we do have up to 150 different mappings for male,
and this is only talking about this single mapping.

Thanks in advance,

Peter
 
M

markspace

Peter said:
the thing is - the mapping male => 1 is not constant.
This might be true for some fields, but not for all.


So? How do you convert the reports now? You need the name of the
report or something to understand what mapping to use, yes?

So for some report named "report_name", you grab those mappings out of
an XML file or database.

I'd add some info about the business unit that creates the report, just
so you can eventually work towards a system where they do their own
updating.

So for the report "sales" you look up mappings that give
male => 1
female => 2

and for the report "customer satisfaction" you look up mappings that give:
male => true
female => false

or whatever.


That's how I'd do it, anyway.
 
P

Peter Horlock

So?  How do you convert the reports now?  You need the name of the
report or something to understand what mapping to use, yes?

So for some report named "report_name", you grab those mappings out of
an XML file or database.

I'd add some info about the business unit that creates the report, just
so you can eventually work towards a system where they do their own
updating.

So for the report "sales" you look up mappings that give
male => 1
female => 2

and for the report "customer satisfaction" you look up mappings that give:
male => true
female => false

or whatever.

That's how I'd do it, anyway.

Hm,

no, it's still more complicated.
What you forgot - how do I now what "male" means?
I could also be "color" or "car" or "ice cream" -
that's dynamically defined.
So I need to define for each field which java method to call -
this method will have the business logic that will retrieve and or
calculate the proper value to be put into a certain field.

so it's a two step process:
a)
male => true
female => false

b) gender =>
database.getPeopleTable().getPerson("ABC").getGender();
if(gender.equals("GENDER_MALE") => true
else false;

So it would be more like a rule egine, I think.

Thanks,

Peter
 
M

markspace

Peter said:
no, it's still more complicated.
What you forgot - how do I now what "male" means?
I could also be "color" or "car" or "ice cream" -
that's dynamically defined.


I assumed you where just dumping these field values into a database,
then running reports from the database. If not, you might at least
consider it, databases have fairly robust report writing tools.

So I need to define for each field which java method to call -
this method will have the business logic that will retrieve and or
calculate the proper value to be put into a certain field.
> so it's a two step process:
> a)
>
> b) gender =>
> database.getPeopleTable().getPerson("ABC").getGender();
> if(gender.equals("GENDER_MALE") => true
> else false;

So you need two mappings: one for the database and one for the form.
You may also need to map the specific form, and the specific database
table/schema:

class EntryMapping {

int id;

// Database schema
String table;
String column;

// Form schema
String formName;
String field;
String value;

}

class Mapping {
// Map database to pdf
HashMap<String,String> dbToPdf = new HashMap<String,String>();
{
dbToPdf.add( "GENDER_MALE", "true" );
dbToPdf.add( "GENDER_FEMALE", "false" );
}
}


EntryMapping emap = ....

Table t = database.getTabel( emap.table );
Person p = t.getPerson( emap.column );
String g = p.getGender();
String formGender = Mapping.dbToPdf.get( g );

You'll have to come up with a scheme to deal with primitives, if your
PDF API uses those, but it shouldn't be too hard once you get the data
itself sorted out.

All of the above, Mapping and EntryMapping, could itself be read out of
a database, so filling in the values should be no trouble, just read
them from the db. There's no need to make many different classes, just
a couple, with values populated from some other (easily changed) source.

I'm curious: what API are you using to deal with the PDF forms?
 
P

Peter Horlock

markspace said:
I assumed you where just dumping these field values into a database,
then running reports from the database. If not, you might at least
consider it, databases have fairly robust report writing tools.




So you need two mappings: one for the database and one for the form. You
may also need to map the specific form, and the specific database
table/schema:

Hmmm, no, that's still not it.
I tried to make it easier for the example.
In fact it's data coming from the database, combined with business
logic in my java code.
Sometimes it's just a simple "trim",
sometimes it's a "abc" + table.getFirstname()
sometimes it's more complext, like data coming from several
sources combined.

Anway, so I need to combine the name of a form pdf form field,
combined with all it's possible settings,
combined with the state of my application and the data coming from my
database and or my application, and then, based on this state I need
to fill the coresponding checkbox / radio box in my pdf form field.
I'm curious: what API are you using to deal with the PDF forms?

uuuhm. Yes, it's some framwork, I am not completly sure, as our
application already pretty good abstracts from it, but it might have
been itext. I only have to all a function like
"fillFormField("fieldName", "fieldValue");
( I am currently at home, would have to check this at work...)

Thanks,

Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,736
Latest member
zacharyharris

Latest Threads

Top