Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » M2M (model-to-model transformation) » SOLVED: [ATL] How to transform only one element of the same id
SOLVED: [ATL] How to transform only one element of the same id [message #548910] Fri, 23 July 2010 13:10 Go to next message
Roger80  is currently offline Roger80 Friend
Messages: 79
Registered: May 2010
Member
I have in a class 5 instances, these instances are:

<Participant id='30' name='Consultant'>
<Participant id='31' name='Credit clerk'>
<Participant id='30' name='Consultant'>
<Participant id='32' name='Head of credit department'>
<Participant id='30' name='Consultant'>

So, I have 3 times < Participant id='30' name ='Consultant'>, but I just want it once. How can I do that?

I tried with an iteration, but as I always just have one value after the the iterator says he cannot iterate on non-collection.

Rule looks like:

rule Role2Lane {
	from
		d : EPK!Participant 
	to
	
		b:BPMN!Lane
		
	(	
		--id <- e.flatParticpant(e.name),
		id <- d.name -> iterate(e; res : Set(EPK!Participant) = Set {} |
				if (res->collect(f | f.name)->includes(e.name)) then
					res
				else
					res->including(e)
				endif
				)-- here we keep only one element of each name value
				->collect(e | thisModule.Definition(e))
	)
}
				
				
lazy rule Definition {
	from
		s : EPK!Participant
	to
		t : BPMN!Lane(
			name <- s.name
		)
}


Thanks for the help. Cheers Roger

[Updated on: Sun, 25 July 2010 13:56]

Report message to a moderator

Re: [ATL] How to transform only one element of the same id [message #548932 is a reply to message #548910] Fri, 23 July 2010 13:18 Go to previous messageGo to next message
Vincent MAHE is currently offline Vincent MAHEFriend
Messages: 129
Registered: July 2009
Senior Member
Le 23/07/2010 15:10, Roger80 a écrit :
> I have in a class 5 instances, these instances are:
>
> <Participant id='30' name='Consultant'>
> <Participant id='31' name='Credit clerk'>
> <Participant id='30' name='Consultant'>
> <Participant id='32' name='Head of credit department'>
> <Participant id='30' name='Consultant'>
>
> So, I have 3 times < Participant id='30' name ='Consultant'>, but I just
> want it once. How can I do that?
> I tried with an iteration, but as I always just have one value after the
> the iterator says he cannot iterate on non-collection.
>
> Rule looks like:
>
>
> rule Role2Lane {
> from
> d : EPK!Participant to
>
> b:BPMN!Lane
>
> (
> --id <- e.flatParticpant(e.name),
> id <- d.name -> iterate(e; res : Set(EPK!Participant) = Set {} |
> if (res->collect(f | f.name)->includes(e.name)) then
> res
> else
> res->including(e)
> endif
> )-- here we keep only one element of each name value
> ->collect(e | thisModule.Definition(e))
> )
> }
>
>

unique lazy rule ...

> lazy rule Definition {
> from
> s : EPK!Participant
> to
> t : BPMN!Lane(
> name <- s.name
> )
> }
>
so it will create only once the Participant 30

--
Cordialement

Vincent MAHÉ

Ingénieur Expert - Projet IDM++ - Équipe AtlanMod
École des Mines de Nantes
La Chantrerie - 4, rue Alfred Kastler
B.P. 20722 - F-44307 NANTES Cedex 3
Tel: (33)2 51 85 81 00
Re: [ATL] How to transform only one element of the same id [message #548949 is a reply to message #548932] Fri, 23 July 2010 14:09 Go to previous messageGo to next message
Roger80  is currently offline Roger80 Friend
Messages: 79
Registered: May 2010
Member
Still the same problem, he do not iterate over a non-collection. When I debug, "d.name" is just like [Consultant]...maybe so he cannot iterate as he just have one element? Could it be that I need allInstances()? But allInstances do not work... Any clue?

Thanks and cheers Roger
Re: [ATL] How to transform only one element of the same id [message #548956 is a reply to message #548949] Fri, 23 July 2010 14:28 Go to previous messageGo to next message
Vincent MAHE is currently offline Vincent MAHEFriend
Messages: 129
Registered: July 2009
Senior Member
Le 23/07/2010 16:09, Roger80 a écrit :
> Still the same problem, he do not iterate over a non-collection. When I
> debug, "d.name" is just like [Consultant]...maybe so he cannot iterate
> as he just have one element? Could it be that I need allInstances()? But
> allInstances do not work... Any clue?
>
> Thanks and cheers Roger


Operations on collections return a copy of the initial collection
(+modifications done on it) so you must reaffect the result to the
collection:
res <- res->including(...)
--
Cordialement

Vincent MAHÉ

Ingénieur Expert - Projet IDM++ - Équipe AtlanMod
École des Mines de Nantes
La Chantrerie - 4, rue Alfred Kastler
B.P. 20722 - F-44307 NANTES Cedex 3
Tel: (33)2 51 85 81 00
Re: [ATL] How to transform only one element of the same id [message #548974 is a reply to message #548956] Fri, 23 July 2010 14:55 Go to previous messageGo to next message
Roger80  is currently offline Roger80 Friend
Messages: 79
Registered: May 2010
Member
Ok, I undersand what you mean, but where do I have to put this code?
res <- res -> including(...) 

[Updated on: Fri, 23 July 2010 14:56]

Report message to a moderator

Re: [ATL] How to transform only one element of the same id [message #548984 is a reply to message #548956] Fri, 23 July 2010 15:28 Go to previous messageGo to next message
Sylvain EVEILLARD is currently offline Sylvain EVEILLARDFriend
Messages: 556
Registered: July 2009
Senior Member
Vincent MAHE wrote on Fri, 23 July 2010 10:28

Operations on collections return a copy of the initial collection
(+modifications done on it) so you must reaffect the result to the
collection:
res <- res->including(...)
--
Cordialement

Vincent MAHÉ

Nope that is wrong except for imperative code.
Re: [ATL] How to transform only one element of the same id [message #548986 is a reply to message #548984] Fri, 23 July 2010 15:32 Go to previous messageGo to next message
Roger80  is currently offline Roger80 Friend
Messages: 79
Registered: May 2010
Member
Ok, what do I have to do then? I am lost...
Are there other possibilities to reach this goal? Thank you very much for your helps...you are so kind...
I will thank you in my thesis, you can believe me. Smile

Cheers Roger
Re: [ATL] How to transform only one element of the same id [message #548991 is a reply to message #548910] Fri, 23 July 2010 15:42 Go to previous messageGo to next message
Sylvain EVEILLARD is currently offline Sylvain EVEILLARDFriend
Messages: 556
Registered: July 2009
Senior Member
This is a bit complex and the condition has to be in the filter. You have to transform only one of each Participant.

You should get all the participants, collect the ids in a set, and then re-get the first participant for each id.

Once you have those "first" participants in a collection, the condition becomes collection->includes(d)

[Updated on: Fri, 23 July 2010 15:42]

Report message to a moderator

Re: [ATL] How to transform only one element of the same id [message #548997 is a reply to message #548991] Fri, 23 July 2010 16:01 Go to previous messageGo to next message
Roger80  is currently offline Roger80 Friend
Messages: 79
Registered: May 2010
Member
Ok, you mean something like this???

EPK!Participant.allInstances() -> iterate(d; res: Set(EPK!Participant) = Set {} | res -> collect(e | e.id) -> first()) -> includes(d)



Cheers Roger
Re: [ATL] How to transform only one element of the same id [message #548998 is a reply to message #548910] Fri, 23 July 2010 16:10 Go to previous messageGo to next message
Sylvain EVEILLARD is currently offline Sylvain EVEILLARDFriend
Messages: 556
Registered: July 2009
Senior Member
More like :

EPK!Participant.allInstances()->collect(e | e.id)->asSet()->collect(e | EPK!Participant.allInstances()->select(f | f.id = e)->first())->includes(d)

In order to not recalculate many times the same collection (EPK!Participant.allInstances()->collect(e | e.id)->asSet()->collect(e | EPK!Participant.allInstances()->select(f | f.id = e)->first())), the best would be to put it in a helper def and then use thisModule.collection->includes(d) as filter.
Re: [ATL] How to transform only one element of the same id [message #549011 is a reply to message #548998] Fri, 23 July 2010 16:37 Go to previous messageGo to next message
Roger80  is currently offline Roger80 Friend
Messages: 79
Registered: May 2010
Member
My rule now looks like:

rule Role2Lane {
	from
		d : EPK!Participant 
	to
		a : BPMN!LaneSet
		(
		name <- 'ABC Bank',
		id <- '1',
		lane <- lan
		),
		lan : BPMN!LaneE (	
		 id <- thisModule.collection->includes(d) 
		)
}


My helper:

helper def: collection() : Collection(String) = 
EPK!Participant.allInstances()->collect(e | e.id)->asSet()->collect(e | EPK!Participant.allInstances()->select(f | f.id = e)->first());


I got a strange error message:

org.eclipse.m2m.atl.engine.emfvm.VMException: java.lang.String cannot be cast to org.eclipse.emf.ecore.InternalEObject
	at __applyApplication#31(EPL2BPMN.atl[109:3-109:20])
		local variables: self=EPL2BPMN : ASMModule, link=TransientLink {rule = Application, sourceElements = {c = org.eclipse.emf.ecore.impl.DynamicEObjectImpl@14dec09 (eClass: org.eclipse.emf.ecore.impl.EClassImpl@620402 (name: Application) (instanceClassName: null) (abstract: false, interface: false))}, targetElements = {g = org.eclipse.emf.ecore.impl.DynamicEObjectImpl@808512 (eClass: org.eclipse.emf.ecore.impl.EClassImpl@1d93f39 (name: DataAssociation) (instanceClassName: null) (abstract: false, interface: false)), b = org.eclipse.emf.ecore.impl.DynamicEObjectImpl@1a07791 (eClass: org.eclipse.emf.ecore.impl.EClassImpl@7d3b8e (name: DataObject) (instanceClassName: null) (abstract: false, interface: false))}, variables = {}}, c=IN!Loan application, b=OUT!Loan application, g=OUT!<unnamed>
	at __exec__#18(EPL2BPMN.atl)
		local variables: self=EPL2BPMN : ASMModule, e=TransientLink {rule = Application, sourceElements = {c = org.eclipse.emf.ecore.impl.DynamicEObjectImpl@14dec09 (eClass: org.eclipse.emf.ecore.impl.EClassImpl@620402 (name: Application) (instanceClassName: null) (abstract: false, interface: false))}, targetElements = {g = org.eclipse.emf.ecore.impl.DynamicEObjectImpl@808512 (eClass: org.eclipse.emf.ecore.impl.EClassImpl@1d93f39 (name: DataAssociation) (instanceClassName: null) (abstract: false, interface: false)), b = org.eclipse.emf.ecore.impl.DynamicEObjectImpl@1a07791 (eClass: org.eclipse.emf.ecore.impl.EClassImpl@7d3b8e (name: DataObject) (instanceClassName: null) (abstract: false, interface: false))}, variables = {}}
	at main#40(EPL2BPMN.atl)
		local variables: self=EPL2BPMN : ASMModule


Do you understand that? I do not understand it...

[Updated on: Fri, 23 July 2010 16:38]

Report message to a moderator

Re: [ATL] How to transform only one element of the same id [message #549012 is a reply to message #548910] Fri, 23 July 2010 16:43 Go to previous messageGo to next message
Sylvain EVEILLARD is currently offline Sylvain EVEILLARDFriend
Messages: 556
Registered: July 2009
Senior Member
A filter is a filter on a rule :
rule Role2Lane {
	from
		d : EPK!Participant (thisModule.collection->includes(d))
	to
		a : BPMN!LaneSet
		(
		name <- 'ABC Bank',
		id <- '1'
		)
}

[Updated on: Fri, 23 July 2010 16:44]

Report message to a moderator

Re: [ATL] How to transform only one element of the same id [message #549015 is a reply to message #549012] Fri, 23 July 2010 17:08 Go to previous messageGo to next message
Roger80  is currently offline Roger80 Friend
Messages: 79
Registered: May 2010
Member
The error stay the same... Embarrassed
I thought I understand it now better and of course I do it, but it is still complcated. It's a long way to understand it in detail. *huff*

[Updated on: Fri, 23 July 2010 17:09]

Report message to a moderator

Re: [ATL] How to transform only one element of the same id [message #549159 is a reply to message #549015] Sun, 25 July 2010 13:56 Go to previous message
Roger80  is currently offline Roger80 Friend
Messages: 79
Registered: May 2010
Member
Problem solved! Smile
Previous Topic:AtlEMFModelHandler
Next Topic:Set default created date on target...
Goto Forum:
  


Current Time: Fri Apr 19 11:20:41 GMT 2024

Powered by FUDForum. Page generated in 0.02502 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top