create nodes programatically with gmf but without setting its properties - eclipse-emf-ecore

I want to create nodes programatically with its properties but using the folowing codes nodes can be created but its properties can not be set.
CreateUnspecifiedTypeRequest request_ch = new
CreateUnspecifiedTypeRequest(
Collections.singletonList(xxxElementTypes.yy),
diagramEditPart.getDiagramPreferencesHint());
Command command = diagramEditPart.getCommand(request);
command.execute();
then element.set("idof element") but the properties of the node still empty.
may someone help me .thanks

I am currently using this method in order to create nodes programatically. The node and the properties appear just fine and you can edit them. (note that there is also a way to edit the properties programmatically, with another type of command (EMF))
public void createAndExecuteShapeRequestCommand(IElementType type, EditPart parent) {
CreateViewRequest actionRequest = CreateViewRequestFactory
.getCreateShapeRequest(
type,
PreferencesHint.USE_DEFAULTS);
org.eclipse.gef.commands.Command command = parent.getCommand(actionRequest);
command.execute();
}
A sample caller of that method if the node is meant to be added in the main area of the diagram.
createAndExecuteShapeRequestCommand(xxx.diagram.providers.xxxElementTypes.ELEMENT_HERE, diagramEditPart);
A sample caller of that method if the node is meant to be added inside another node or compartment.
DiagramEditPart diagramEditPart = getDiagramEditPart(); //diagram.getDiagramEditPart();
"ParentElement" parentElement = (("Root_ELEMENT") diagramEditPart.resolveSemanticElement())."getTheElement"();
List list = getDiagramGraphicalViewer().findEditPartsForElement(EMFCoreUtil.
getProxyID(parentElement),
TheElementsEDITPART.class);
createAndExecuteShapeRequestCommand(xxx.diagram.providers.xxxElementTypes.ELEMENT_HERE, (EditPart)list.get(0));
Note that, if you wish to call this method from other class than the one of the xxxDiagramEditor.java you will need somehow to pass there the diagramEditPart.

Related

Want to use one tag with different values according to the scenario in cucumber

we have a cleanup hook in our automation framework which tagged from the cucumber feature file
E.g
#cc_task_clean_up_hook_enrol_A
Scenario: Person can enrol_A
When I select the context menu
Then I am able to enroll the patient into 'enrol_A'
the implementation of the hook (#cc_task_clean_up_hook) is
#After(value = "#toc_task_clean_up_hook_enrol_A", order = HookOrder.CLEAN_UP_APP_AFTER)
public void cleanUpTOC() {
this.patientContextPage.selectedContextMenuItem("Pathway");
this.pathWayPage.selectReferences("Enroll in Pathway");
this.pathWayPage.deactivateEnrollment("enrol_A", "Withdrawn");
}
So exactly the same way we need an another scenario like
Scenario: Person can enroll_B
When I select the context menu
Then I am able to enroll the patient into 'enrollB'
So we can implement another hook as follows, the difference is the parameter type "enrollB"
#After(value = "#toc_task_clean_up_hook_enrollB", order = HookOrder.CLEAN_UP_APP_AFTER)
public void cleanUpTOC() {
this.patientContextPage.selectedContextMenuItem("Pathway");
this.pathWayPage.selectReferences("Enroll in Pathway");
this.pathWayPage.deactivateEnrollment("enrol_B", "Withdrawn");
}
So is it possible to consolidate these two methods and write only one generic clean up hook, based on the passed parameter? Your help is much appreciated.
You can add the scenario object to the arguments passed to the after hook. The framework will inject the currently executing scenario to the method.
public void afterMethod(Scenario scenario){}
You can use the getSourceTagNames() method of the Scenario object which will return you the collection of tags for the current executing scenario. From this collection you can determine if you have the tag ending with 'enroll_A' or 'enroll_B'.
Or you can use the getName() method which returns the description of the current scenario. So you will get either 'Person can enroll_A' or 'P..... enroll_B'. Just need to parse again.
You can modify the Then step to pass the enroll type to step definition. Store this in a variable. Use this variable in your after hook. But this will require the after hook to be in the same class.
Also you will need to change the value parameter of After hook to - {"#toc_task_clean_up_hook_enrollA,#toc_task_clean_up_hook_enrollB"}.
One observation that these two seem to have the same steps, if so then have you considered ScenarioOutline instead.

Adding a new attribute to an Object Class and Expecting it to automatically show up in existing objects in Apache DS

I am working on a use case where I have to dynamically add a new attribute to an existing object class in Apache DS.
1)Here is some code which defines my object class:--
Attributes attrs = new BasicAttributes(true);
attrs.put("NUMERICOID", "1.3.6.1.4.1.18060.0.4.3.3.1");
attrs.put("NAME", "ship");
attrs.put("DESC", "An entry which represents a ship");
attrs.put("SUP", "top");
attrs.put("STRUCTURAL", "true");
Attribute must = new BasicAttribute("MUST");
must.add("cn");
attrs.put(must);
Attribute may = new BasicAttribute("MAY");
may.add("numberOfGuns");
may.add("numberOfGuns2");
may.add("description");
attrs.put(may);
//add
schema.createSubcontext("ClassDefinition/ship", attrs);
2) Adding an object of that object class:
Attributes attributes=new BasicAttributes();
Attribute objectClass=new BasicAttribute("objectClass");
objectClass.add("ship");
attributes.put(objectClass);
Attribute g=new BasicAttribute("numberOfGuns");
Attribute g2=new BasicAttribute("numberOfGuns2");
Attribute cn=new BasicAttribute("cn");
g.add("2");
g2.add("3");
cn.add("four");
attributes.put(g);
attributes.put(cn);
attributes.put(g2);
;
ctx.createSubcontext("cn=four,dc=example,dc=com",attributes);
3) Add a new attribute -- 'mustA' to the object class
Attributes attrs = new BasicAttributes(true);
attrs.put("NUMERICOID", "1.3.6.1.4.1.18060.0.4.3.3.1");
attrs.put("NAME", "ship");
attrs.put("DESC", "An entry which represents a ship");
attrs.put("SUP", "top");
attrs.put("STRUCTURAL", "true");
Attribute must = new BasicAttribute("MUST");
must.add("cn");
must.add("mustA");
attrs.put(must);
Attribute may = new BasicAttribute("MAY");
may.add("numberOfGuns");
may.add("numberOfGuns2");
may.add("description");
attrs.put(may);
//modify
schema.modifyAttributes("ClassDefinition/ship",DirContext.ADD_ATTRIBUTE ,attrs);
Once the new attribute is added(which means object class is modified), If i add a new object of that object class type, I can see the newly added attribute in the newly created object.
My Question is, What happens to the objects which were created before I added the new attribute? How can I make the new attribute to show up in the exiting objects automatically? For example, here will the new attribute "mustA" automatically show up in object "four"?
Or Will I have to manually go and modify that object to add that new attribute?
You will need to update the schema. For ApacheDS the easiest method is to download Apache Studio and take a look at 2.3.1 - Adding Schema Elements
Oh, and you will always get great support from The Directory Users List for ApacheDS. The developers are very active.
AFIK, ApacheDs will support adding schema from LDAP calls, but I am not positive. (See The Directory Users List for ApacheDS)
If you insist doing this the hard way, check out the examples at:
http://docs.oracle.com/javase/jndi/tutorial/ldap/schema/object.html
-jim

Titanium access a model from other controller

I learned that is this how to access a model from other controller,
var book = Alloy.Models.instance('book');
And this is how to access a property of a model,
var name = book.get('name');
However in the console,the name logs [INFO] : { } , meaning this doesn't get its property value, and ofcourse the model has already a data saved on it. Thanks for your help!
You may have to fetch the collection first:
var books = Alloy.Collections.book;
books.fetch();
This will load all the models from the collection so you can use them.
although the above works, there are a few addtional points here.
the call is asynchronous in most cases so you should be getting the model in a callback which is not presented in the code above.
I dont know if fetching the collection everytime you want a model is the correct approach either? If the collection already exists you just need to get the model from the collection just using the id.
depending on the exact use case, you might just want to pass the model as a parameter from one controller to the next

Relationship between NSManagedObject across multiple NSManagedObjectContexts

My application uses multiple threads with one managed object context per thread.
For clarity I will refer to the different managed object contexts as: moc1, moc2, ..., etc.
Let's assume we have two models with a simple one-many relationship:
User 1----* Document
When a user logs in I fetch the corresponding model from one of the contexts (eg. moc1).
(pseudo code)
UserModel *globalLoggedUser = ( Fetch the logged in user using moc1 )
I then store this user so that I can reference it later.
In another part of the application I need to loop through thousands of items from an array and create Document objects for it. Each document then needs to be bound to the current user. This happens in a different background thread (which has its own context)
for( NSString *documentName in documents) {
( Create new document using moc2 )
** THIS IS WHERE MY PROBLEM IS **
// What I currently do:
UserModel *tempUser = ( Fetch the logged in user using moc2 )
( bind new document to tempUser )
// What I would like to do:
( bind new document to globalLoggedUser )
// Note that in this case tempUser and globalLoggedUser are the same user, except they are attached to different contexts.
}
As you can see, I would like to avoid having to fetch a new user into the current context each time.
The problem is, globalLoggedUser is part of moc1, whereas the new document is part of moc2 (or moc3, moc4, etc, depends on the thread).
So what's the best way to go about this? How can I globally save/cache an object and then use that same object to bind relationships in different contexts without incurring a penalty of having to fetch each time?
Thanks for any help you can provide.
You are correct that you can't use the same NSManagedObject across threads.
From the Core Data Programming Guide:
Using thread confinement, you should not pass managed objects or managed object contexts between threads. To “pass” a managed object from one context another across thread boundaries, you either:
Pass its object ID (objectID) and use objectWithID: or existingObjectWithID:error: on receiving managed object context.
The corresponding managed objects must have been saved—you cannot pass the ID of a newly-inserted managed object to another context.
Execute a fetch on the receiving context.
I think you'd be fine if you just fetched the logged in user with moc2 before you run the 'document' loop, as I don't see any reason to do the fetch each time inside the loop. (Is there some reason you are doing that?)
Don't worry about binding anything to the UserModel from thread 1, the tempUser you get from moc2 is referencing the same data in the database as globalLoggedUser.

Stored Proc in RIA Services

I want to load some data with a SP.
I've put a SP in a Linq to SQL Class and I don't know how to use it for loading it's data in a datagrid.
In LinqToSqlDomainService I can't figure out how to call a SP.
What steps should I use.
Any samples of this ? All samples use a table.
Thank's
This post should hopefully be of help:
http://blogs.msdn.com/brada/archive/2009/08/24/business-apps-example-for-silverlight-3-rtm-and-net-ria-services-july-update-part-24-stored-procedures.aspx
You can create empty view with the same structure of your sproc and map that stored procedure to your function in your DomainService
See sample on http://cid-289eaf995528b9fd.skydrive.live.com/self.aspx/Public/sproc.zip
I found the following excellent step-by-step guide at this site -
http://betaforums.silverlight.net/forums/p/218383/521023.aspx
1) Add a ADO Entity Data Model to your Web project; Select generate from database option; Select your Database instance to connect to.
2) Choose your DB object to import to the Model. You can expand Table node to select any table you want to import to the Model. Expand Stored Procedure node to select your Stored Precedure as well. Click Finish to finish the import.
3) Right click the DB model designer to select Add/Function Import. Give the function a name (same name as your SP would be fine) and select the Stored Procedure you want to map. If your SP returns only one field, you can map the return result to a collection of scalars. If your SP returns more than one field, you could either map the return result to a collection or Entity (if all the field are from a single table) or a collection of Complex types.
If you want to use Complex type, you can click Get Column button to get all the columns for your SP. Then click Create new Complex type button to create this Complex type.
4) Add a Domain Service class to the Web project. Select the DataModel you just created as the DataContext of this Service. Select all the entitis you want expose to the client. The service functions should be generated for those entities.
5) You may not see the Complex type in the Entity list. You have to manully add a query function for your SP in your Service:
Say your SP is called SP1, the Complex type you generated is called SP1_Result.
Add the following code in your Domain Service class:
public IQueryable<SP1_Result> SP1()
{
return this.ObjectContext.SP1().AsQueryable();
}
Now you can compile your project. You might get an error like this: "SP1_Result does not have a Key" (if you not on RIA service SP1 beta). If you do, you need to do the following in the service metadata file:
Added a SP1_Result metadata class and tagged the Key field:
[MetadataTypeAttribute(typeof(SP1_Result.SP1_ResultMetadata))]
public partial class SP1_Result
{
internal sealed class SP1_ResultMetadata
{
[Key]
public int MyId; // Change MyId to the ID field of your SP_Result
}
}
6) Compile your solution. Now you have SP1_Result exposed to the client. Check the generated file, you should see SP1_Result is generated as an Entity class. Now you can access DomainContext.SP1Query and DomainContext.SP1_Results in your Silverlight code. You can treat it as you do with any other Entity(the entity mapped to a table) class.
Calling a stored procedure is trivial. Import it as a function and then invoke the function as a member of the DDS. The return value is an ObservableCollection<> that you can use to set up the DataContext of the object you want to bind.
...unless you want to use it in a Silverlight RIA app via the magic code generated proxy, in which case your goose is cooked unless your result rows exactly match one of the entities. If you can meet that criterion, edit the DomainService class and surface a method that wraps the ObjectContext method.