Multiple step process question

Contains tips for configurators working with Aware IM
Post Reply
ckacoroski
Posts: 58
Joined: Mon Nov 13, 2006 9:15 pm
Location: Bothell, USA

Multiple step process question

Post by ckacoroski »

Hi,

I am updating InternalObjects from an External data source. The problem is that sometimes I will be updating existing InternalObjects and other times I will be creating new InternalObjects. After doing a query to get the list of ExternalObjects that have changed, I feed them into a process to do the InternalObject updates. I do not know how to change between the three alternatives of:

1. updating an existing InternalObject from the ExternalObject

2. merging the ExternalObject with an InternalObject where both were created separately (e.g. the InternalObject does not have a link to the ExternalObject.id field))

3. creating a new InternalObject from the ExternalObject

UpdateProcess:
Find InternalObject where InternalObject.id = ExternalObject.id
# what happens if there is no match on the above query?
# if a match, we are doing an update, put rules for each attr here
InternalObject.attr1 = ExternalObject.attr1

Find InternalObject where InternalObject.id is undefined and InternalObject.name = ExternalObject.name
# what happens if no match on the above query
# Need to merge the internal and external objects
InternalObject.attr1 = ExternalObject.attr1

#default case, create a new InternalObject
Create InternalObject with attr1 = ExternalObject.attr1, ...

Sorry if this is long and bit confusing, I am still readjusting my thinking from procedural/functional programming to rules based programming.

Thanks for your help.

ski
Hubertus
Posts: 153
Joined: Sat Feb 11, 2006 2:11 pm
Location: Austria
Contact:

Post by Hubertus »

Although not being actually a solution to your issues, take a really close look on the section "how context is formed" and the different Instance Prefixes in the AwareIM User Manual and maybe at
http://www.hiden.org/awareim/tips-n-tri ... of-awareim
http://www.hiden.org/awareim/tips-n-tri ... r-database
http://www.hiden.org/awareim/tips-n-tri ... sql-server
ckacoroski
Posts: 58
Joined: Mon Nov 13, 2006 9:15 pm
Location: Bothell, USA

Post by ckacoroski »

Hubertus,

I looked at these links (thanks), but I am still stuck. My latest attempt is:

On the ExtObj I have rules like:
If IntObj.NameOR = 'No' then IntObj.Name = ExtObj.name

This allows me to block a copy by setting the IntObj.NameOR to 'Yes'

Then I have a process that first finds all the ExtObj that changed and then runs the UpdateProcess which takes an ExtObj as Process Input. The Update process then does:

Step1: Find IntObj where IntObj.id=ExtObj.id
Step2: Update ExtObj
Step3: Find IntObj where IntObj.id is undefined and IntObj.Name = ExtObj.Name
Step4: Update ExtObj
Step5: Create IntObj
Step6: Update ExtObj

This doesn't work because the rules on the ExtObj refer to attributes on the IntObj even though I have one of each object in the context (I get errors like "Value of attribute NameOR of object IntObj could not be resolved).

I need to update awareim objects from an external database where I may or may not have previously created the objects in awareim and where I may need to override some of the attributes from the external database.

Any ideas on how to do this are most appreciated.
ckacoroski
Posts: 58
Joined: Mon Nov 13, 2006 9:15 pm
Location: Bothell, USA

Post by ckacoroski »

Second attempt was to put all the logic into the process. I took off all the rules on the ExtObj and I have three processes.

Process1 finds all the ExtObjs to be updated and calls Process2.

Process2 takes an ExtObj as input and finds a IntObj with the same id as the ExtObj. It then calls Process3.

Process3 takes an ExtObj and IntObj as inputs and copies over the attributes from the ExtObj to the IntObj if the override flag is no:

If IntObj.NameOR = 'No' then IntObj.Name = ExtObj.name

This works fine for the basic case when the id's match up. My problem is that I cannot figure out how to modify the processes to allow me to handle the case where I need to create a new IntObj or the case where the id's do not match up, but the names are the same so I want to merge the Int and Ext objects.

I could do this if I could somehow have an if-then-else in process2 (e.g. if id's match do X, else if there the name matches do X, else create a new IntObj).

I suspect I am approaching this all wrong from the awareim best practices. What is the best way to solve this problem?
tford
Posts: 4238
Joined: Sat Mar 10, 2007 6:44 pm

Post by tford »

ckacoroski,
I could do this if I could somehow have an if-then-else in process2 (e.g. if id's match do X, else if there the name matches do X, else create a new IntObj).
I haven't looked through the entire process you are trying to accomplish, but, yes, you can you IF... THEN .... ELSE in a process.

An example of IF .. THEN .. ELSE used in a rule can be seen in my post from Fri Jun 08, 2007 1:05 pm at http://www.awareim.com/forum/viewtopic.php?t=1677 Sounds like you will want to use If EXISTS like is shown there.

Tom
aware_support2
Posts: 595
Joined: Sun Apr 24, 2005 2:22 am
Contact:

Post by aware_support2 »

Hi ski,

You can try an if-then-else or you can simplify your 3-process design by narrowing the focus of your Process1. Instead of "Process1 finds all the ExtObjs to be updated", make the process to find only those ExtObj for which a new IntObj has to be created. Then Process2 would simply take ExtObj as input and create a new IntObj for it.

Similarly, make a new process Process1b to find only those ExtObj for which an existing IntObj has to be modified, and a process Process2b that takes ExtObj as input, finds corresponding IntObj and updates it as necessary.
Aware IM Support Team
ckacoroski
Posts: 58
Joined: Mon Nov 13, 2006 9:15 pm
Location: Bothell, USA

Post by ckacoroski »

When I tried the If..then..else the "IF Exists statement" did not put the object it found into the context so that object did not get passed into the next process like so:

Process1:
Find all ExtObjs to be updated and put them into the context
Call Process2

Process2:
If Exists IntObj where IntObj.id = ExtObj.id then Process3

Process3: Take IntObj and ExtObj and do the copy.

This broke in Process2. Not sure what I am doing wrong here.


I also tried to narrow down Process1, but ExtObj is an External Object and I was not able to create a query that would join a External Database object with an internal database object (just like the docs state). Do you have a way to have a query include an object in an external table and a awareim controlled object?
aware_support2
Posts: 595
Joined: Sun Apr 24, 2005 2:22 am
Contact:

Post by aware_support2 »

Hi ski,

You need to use FIND in Process2 to place the IntObj into the context before calling Process3:

If EXISTS IntObj WHERE IntObj.id = ExtObj.id Then
FIND IntObj WHERE IntObj.id = ExtObj.id
Process3
Aware IM Support Team
ckacoroski
Posts: 58
Joined: Mon Nov 13, 2006 9:15 pm
Location: Bothell, USA

Post by ckacoroski »

Ok, Thanks for all the help folks. I got it to work, but I still wonder if there is a better way. I ended up creating a non-persistent Flag object that allowed me to have a if..then..else statement with a default within the process like so:
Process1:
Step1: Find all ExtObjs to be updated
Step2: Process2

Process2 (takes ExtObj as input)
Step1: Create Flag with Flag.Flag1 = 'No'
Step2: If Exists IntObj where (IntObj.id = ExtObj.id) then Find IntObj where IntObj.id = ExtObj.id Process3 Flag.Flag1 = 'Yes'
Step3: If Flag.Flag1 = 'No' and Exists IntObj where (IntObj.id is undefined and IntObj.Name = ExtObj.Name) then Find IntObj where IntObj.id is undefined and IntObj.Name = ExtObj.Name Process3 Flag.Flag1 = 'Yes'
Step4: If Flag.Flag1 = 'No' Create IntObj with IntObj.Name = ExtObj.Name, IntObj.id = ExtObj.id

Process3 (takes IntObj and ExtObj as inputs)
Step1: If IntObj.NameOverride = 'No' then IntObj.Name = ExtObj.Name
Step2: IntObj.id = ExtObj.id

Appreciate any ideas on if this is a "best practice" for processes or if there is a better way.

Thanks

ski
aware_support2
Posts: 595
Joined: Sun Apr 24, 2005 2:22 am
Contact:

Post by aware_support2 »

Hi ski,

Perhaps you could get rid of the temporary object and simplify Process2 using a single rule:

Code: Select all

If EXISTS IntObj WHERE (IntObj.id = ExtObj.id) Then
  FIND IntObj WHERE IntObj.id = ExtObj.id
  Process3
Elseif EXISTS IntObj WHERE (IntObj.id IS UNDEFINED AND IntObj.Name = ExtObj.Name) Then
  FIND IntObj WHERE IntObj.id IS UNDEFINED AND IntObj.Name = ExtObj.Name
  Process3
Else
  CREATE IntObj WITH IntObj.Name = ExtObj.Name, IntObj.id = ExtObj.id
Aware IM Support Team
ckacoroski
Posts: 58
Joined: Mon Nov 13, 2006 9:15 pm
Location: Bothell, USA

Post by ckacoroski »

Thanks, I did not realize there was a full if..then..elseif..else statement structure.
tford
Posts: 4238
Joined: Sat Mar 10, 2007 6:44 pm

Post by tford »

ski,

The RuleLanguage.pdf is a very good resource. This is on page 4/5.

Tom
Post Reply