Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Gendoc » Getting ID and Name from Requirements::Requirement(Can get Requirement ID from Requirements::Requirement but not the Name and vice-versa)
Getting ID and Name from Requirements::Requirement [message #1828706] Wed, 17 June 2020 06:01 Go to next message
Hector Leon is currently offline Hector LeonFriend
Messages: 6
Registered: June 2020
Junior Member
Hi all.
I'm trying to get ID and Name from a list of requirements.

When using iteration with Requirements::Requirement as type, I can get ID but not the NAME of each object. On the other hand when I iterate by using Class, I can get the NAME but not the ID of the Object.

I found an old topcased forum talking about this but I couldn't resolve the issue,

Can someone help me with this please?

I'm using the following template alternatives:
1-
<context ...'/>
<gendoc>
[for (r: Requirements::Requirement | Requirements::Requirement.allInstances()->sortedBy(id))]<drop/>
[r.id/]
[(r.text)/]
[r.name/] ****this fails****
[/for]
</gendoc>

2-
<context ...'/>
<gendoc>
[for (r: Class | self.ownedElement]<drop/>
[r.name/]
[r.id/] ****this fails****
[(r.text)/] ****this fails****
[/for]
</gendoc>

Hope I can get some help on this
Best Regards.
Re: Getting ID and Name from Requirements::Requirement [message #1828754 is a reply to message #1828706] Thu, 18 June 2020 06:43 Go to previous messageGo to next message
Tristan Faure is currently offline Tristan FaureFriend
Messages: 460
Registered: July 2009
Senior Member
Hello Requirement Metamodel is structured like this
Requirement -- element --> Model Element

id and text are properties of Requirements
name is a property of UML Class

Some choices are possible :
you define different behaviors depending on the type if r.oclIsKindOf(uml::Element) then r.name else r.id endif
or you can try the generic getText operation from gendoc library (https://www.eclipse.org/gendoc/documentation/Gendoc_v0.7_tutorial.pdf) : getText (modelElement : OclAny) : String Returns a generic String for the given model element.
This operation generally returns the text displayed in the editor (in your case : r.getText())

Regards




Re: Getting ID and Name from Requirements::Requirement [message #1828773 is a reply to message #1828706] Thu, 18 June 2020 11:25 Go to previous messageGo to next message
Anne HAUGOMMARD is currently offline Anne HAUGOMMARDFriend
Messages: 13
Registered: October 2013
Junior Member
Hello Hector,
Another option is to keep working with Requirement objects and get this name attribute from the underlying Class

[r.base_Class.name/]

Best regards,


- Anne
Re: Getting ID and Name from Requirements::Requirement [message #1828792 is a reply to message #1828773] Thu, 18 June 2020 15:32 Go to previous messageGo to next message
Hector Leon is currently offline Hector LeonFriend
Messages: 6
Registered: June 2020
Junior Member
Hi Tristan and Anne.
Thanks a lot for your answer!
I tried Anne's approach and works just as expected.
I'm new to Acceleo language and Gendoc so Tristan's approach looks like more advanced to me, however is good to know the existences of those methods (.oclIsKindOf and getText)
Thanks again!

[Updated on: Thu, 18 June 2020 15:33]

Report message to a moderator

Re: Getting ID and Name from Requirements::Requirement [message #1830507 is a reply to message #1828792] Tue, 28 July 2020 02:52 Go to previous messageGo to next message
Hector Leon is currently offline Hector LeonFriend
Messages: 6
Registered: June 2020
Junior Member
Hi Tristan and Anne.

I'm writing again because I have a new problem (in fact are two but I'm just going to write 1 of them).

Last time, the problem was resolved perfectly by Anne's solution but the exported document didn't capture the real structure behind the requirements model (Parents and Child Relationship) like this:
-RQ1
|->RQ1.1
|->RQ1.2
With the current solution I can not capture this structure because I'm using Requirements::Requirement.allInstances()->sortedBy(id) within one FOR loop. I know that to capture the structure I have to create two inner FOR loops. However I've not being able to do this. I've try unsuccessfully by using the following scripts:

OPTION1 (works well but I can not access requirements fields, just class - old problem):
[for (elt : Element | self.ownedElement)]<drop/>
[let c : Class = elt.oclAsType(Class)] <drop/>
[c.name]
[for (elt2 : Element | elt.ownedElement)]<drop/>
[let c2 : Class = elt2.oclAsType(Class)] <drop/>
[c.name]
[/let]
[/for]
[/let]
[/for]

OPTION2 (complies but generate a blank document):
[for (elt : Element | self.ownedElement)]<drop/>
[let c : Requirements::Requirement = elt.oclAsType(Requirements::Requirement)] <drop/>
[c.id] - [c.base_Class.name] +++FAILS++++
[for (elt2 : Element | elt.ownedElement)]<drop/>
[let c2 : Requirements::Requirement = elt2.oclAsType(Requirements::Requirement)] <drop/>
[c2.id] - [c.base_Class.name] +++FAILS++++
[/let]
[/for]
[/let]
[/for]

Why .oclAsType(Requirements::Requirement)] doesn't work for this?
Could you help me with this?
Thank you very much.

P.S With your last help my solution is working really well. Bellow, I'm writing the full script:

[for (r: Requirements::Requirement | Requirements::Requirement.allInstances()->sortedBy(id))]<drop/>
[R.ID/] [R.BASE_CLASS.NAME/]
<dropEmpty>[cleanAndFormat(r.text)/]</dropEmpty>
• Satisfied By: [for (s: NamedElement |r.satisfiedBy)] [clean(s.name)/]<nobr/>[/for]
• Traced To: [for (t_: NamedElement |r.tracedTo)][clean(t_.name)/]<nobr/>[/for]
[/for]
Re: Getting ID and Name from Requirements::Requirement [message #1830531 is a reply to message #1830507] Tue, 28 July 2020 14:26 Go to previous messageGo to next message
Tristan Faure is currently offline Tristan FaureFriend
Messages: 460
Registered: July 2009
Senior Member
Hello

be careful I will use properties defined in the metamodel, I would recommend you a gendoc or OCL training to be more efficient. It was generally a 1 or 2 days training made by the company of Anne, I don't know if it is still available
so :

option 1
>>
OPTION1 (works well but I can not access requirements fields, just class - old problem):
[for (elt : Element | self.ownedElement)]<drop/>
[elt.oclAsType(Class).getStereotypeApplications()->first().oclAsType(Requirements::Requirement).id/] <drop/>
[c.name]
[/for]

Option 2 should not work it isstrange that you have no errors




Re: Getting ID and Name from Requirements::Requirement [message #1830547 is a reply to message #1830531] Wed, 29 July 2020 00:36 Go to previous messageGo to next message
Hector Leon is currently offline Hector LeonFriend
Messages: 6
Registered: June 2020
Junior Member
Hi Tristan
Thank you for your answer.
I've tried your solution with several approaches and it didn't work.

The error message is:
Cannot find operation (first()) for the type (Set(EObject)):

The code that I used was:
[for (elt : Element | self.ownedElement)]<drop/>
[elt.oclAsType(Class).getStereotypeApplications()->first().oclAsType(Requirements::Requirement).id/]
[/for]


Thank you again.
Hope you can help me.
Best Regards.

P.S
* I had not found any documentation talking about the method that you have used (getStereotypeApplications). Where can I get that documentation?

* Thank you for recommending the training given by Anne's company. I found one by OBEO (3 Days 2.250€) is it that?
Re: Getting ID and Name from Requirements::Requirement [message #1830548 is a reply to message #1830547] Wed, 29 July 2020 02:12 Go to previous messageGo to next message
Hector Leon is currently offline Hector LeonFriend
Messages: 6
Registered: June 2020
Junior Member
Hi Tristan.
I found a solution by using the command that you've used (getStereotypeApplications)
[for (elt : Element | self.ownedElement)]<drop/>
[if (elt.oclIsTypeOf(Class))]<drop/>
[let c:Class = elt.oclAsType(Class)]<drop/>
[c.getStereotypeApplications().oclAsType(Requirements::Requirement).id/] - [c.name/]
[/if]<drop/>
[/for]


But now I have a problem trying to access the text attribute (another String).
The code compiles but the generated document is corrupted.
.....
[c.getStereotypeApplications().oclAsType(Requirements::Requirement).text/]  ***this fails****
.....


I resolved the issue by using the following code even when I think that shall be a better way to do this.
.....
[for (s:String | c.getStereotypeApplications().oclAsType(Requirements::Requirement).text)]<drop/>
<dropEmpty>[cleanAndFormat(s)/]</dropEmpty>
[/for]<drop/> 
.....


I think that with this approach I will have even worse problems when trying to access satisfy by or traced to attributes (NamedElement Type)

1. Can I do this in a better way?
2. Why I can not use LET instruction to store "c.getStereotypeApplications().oclAsType(Requirements::Requirement)" in a variable of Requirements::Requirement type?

Hope you can help me with this.
Best Regards.
Re: Getting ID and Name from Requirements::Requirement [message #1830554 is a reply to message #1830548] Wed, 29 July 2020 05:40 Go to previous messageGo to next message
Tristan Faure is currently offline Tristan FaureFriend
Messages: 460
Registered: July 2009
Senior Member
Hello
about your PS, Anne will answer but no she's not from Obeo company, you can ask for more details at : anne.haugommard@atos.net and stephane.duprat@atos.net

To answer your question I will describe the command (sorry for my wrong advice I made it using memory I should have checked) :
c.getStereotypeApplications().oclAsType(Requirements::Requirement
c => a UML element
c.getStereotypeApplications() => a set of "EObjects"
c.getStereotypeApplications().oclAsType(Requirements::Requirement) => a set of EObjects casted to Requirements
that's why you can't set it to a let
The first recommendation I made did not work because a set has no first method so
c.getStereotypeApplications().oclAsType(Requirements::Requirement)->asSequence() => a sequence of Requirements
c.getStereotypeApplications().oclAsType(Requirements::Requirement)->asSequence()->first() => the first Requirement of the Sequence and there you can save it to a let

the code you mentioned :
[for (s:String | c.getStereotypeApplications().oclAsType(Requirements::Requirement).text)]<drop/>
worked because
c.getStereotypeApplications() => set of EObjects
c.getStereotypeApplications().oclAsType(Requirements::Requirement). => set of requirements
c.getStereotypeApplications().oclAsType(Requirements::Requirement).text => set of texts




[Updated on: Thu, 30 July 2020 06:22]

Report message to a moderator

Re: Getting ID and Name from Requirements::Requirement [message #1830584 is a reply to message #1830554] Wed, 29 July 2020 12:48 Go to previous message
Hector Leon is currently offline Hector LeonFriend
Messages: 6
Registered: June 2020
Junior Member
Hi Tristan.
Thank you for your answer.
I'll keep working on my script, your help is very valuable.
Best regards.
Héctor
Previous Topic: R-E-A-L (Rapid Engineering Architecture Linked)
Next Topic:Generate Excel file with multiple worksheets
Goto Forum:
  


Current Time: Thu Feb 29 18:46:39 GMT 2024

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

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

Back to the top