Let's say I have an object with a lot of nested objects and variables named credential:
After resume program, and re-enter the activity again as different login user:
What's the best way to diff this two objects all in once ? .e.g accountName (String), isNew (boolean) variables, and so on.
I tried "Copy Value" and then "Compare Value with Clipboard" but it only able to compare single text variable. "View Text" is same.
I also tried "Mark Object...", but its object will lose and not permanently store(re-enter class will override the object):
So is there any way to compare two complex and nested object values ?
[UPDATE]
I figure out I can press shift OR Ctrl+A to highlight all and then Ctrl+C to copy, but still it will not included nested object without expand them one by one:
[UPDATE 2]:
I noticed shadow$__klass_ object seems like contains itself and cause endless nested attributes. But it can be solved if I can exclude this object name OR limit the max nested depth ?
You can develop utility method and keep it somewhere in your project which accepts two objects and call it in the eval expression debugger window and see the difference.
You can use some reflection library or develop your own, it could work this way: walk over the object fields by reflection and build the map where the key contains the composite path of fields (f.e. fieldA.fieldANested.number) and the value it has. Then that two maps for the two objects could be compared very easily and you can see the difference in your debugger
Related
I have a simple document with 3 fields and 1 rich text field. I also have an xpage with 3 simple edit box controls and 1 rich text. The name of my NotesXSPDocument is document1.
Question 1:
Can i get a vector with all the controls of the xsp document? for example, instead of using getComponent("fld1"), getComponent("fld2") ... etc, can i use something like getAllComponents() or document1.getControls()? These methods do not exist of course so i am asking if there is a way to do it. I know i can get all items of a document (not XSP) by calling document1.getDocument().getItems(). IS there anything similar for xsp?
Question2:
Lets say we can get a vector as i described above. Then if i iterate through this vector to get each control's value, is there a method to check if it is rich text or simple text field?
Technically, yes, but not readily and this is one of those situations where there's likely a better way to approach whatever underlying problem it is you want to solve.
Nonetheless, if you're looking to get a list of inputs on the page, XspQuery is your friend: http://avatar.red-pill.mobi/tim/blog.nsf/d6plinks/TTRY-96R5ZT . With that, you could use "locateInputs" to get a List of all the inputs on the page, and then check their value method bindings to see if the string version is referencing your variable name. Error-prone and not pretty, but it'd work. Since they're property bindings, I don't think the startsWith filter in there would do what you want.
Alternatively, you could bind the components to something in a Java class from the start. I've been doing just such a thing recently (for a different end) and initially described it here: https://frostillic.us/f.nsf/posts/my-black-magic-for-the-day . The upshot is that, with the right cleverness for how you do your binding="" property, you could get a list of all the components that reference a property of a given object.
As for the second part of the question, if you DO get a handle on the components one way or another, you can check to see if it's a rich text control by doing "component instanceof com.ibm.xsp.UIInputRichText".
A bit complex but yes. facesContext.getViewRoot() is an UIViewRoot object so it has List<UIComponent> getChildren() method which returns its children.
However, since it's a tree-structure, some of its children will have additional children components. You have to traverse the entire tree to build a list of components you want to see.
For types, you can decide what type a component is by its class. For instance, UIInput is a text box, etc.
We have a large project and I am using Enterprise Architect version 10 to reverse engineer a small package within the project into UML for the purposes of refactoring. I want to only include elements that will be contained within the diagrams I am going to create (I know this is stupid, but we can't have 1 model to rule them all).
I would like to reverse all the source and then delete all elements that do not end up on my diagrams. Is there a way to do this? I know that I can find any given element in the diagrams from the GUI, so would there at least be a way to script this?
The alternative is to manually pick all dependencies and reverse only those files, which I may end up doing.
Thanks
EA comes with a built-in search called "Find Orphans". This will list all elements that do not appear on a diagram. You can run this search (Ctrl+Alt+A, select "Diagram Searches" from the first list box and "Find Orphans" from the second list box and click Run), select all the results (Ctrl+A) and delete all (Ctrl+Del). However, this is at your own risk - there is nothing wrong with an element being in the model but not on any diagrams.
Yes, you can script this. It will be a little involved, but it can be done.
There's no immediate API support to find what you're looking for so you'll need to go into the database to find all elements that are not shown in any diagrams. Once you've done that, you can delete each such element from its containing package.
Elements are stored in t_object and diagram objects (the graphical representation of one element in one diagram) in t_diagramobjects. An entry in t_diagramobjects has a reference to the diagram (Diagram_ID) and to the element being displayed (Object_ID).
(If you're new to EA hacking, yes, they're called Elements in the API and Objects in the database. Just a fact of life.)
So:
Find all t_object.Object_ID which do not occur in t_diagramobjects.Object_ID.
Loop through this set and, using Repository.GetElementByID(), retrieve each Element.
Fetch the element's containing package using Repository.GetPackageByID(element.PackageID).
Spin through the package's Elements collection using GetAt() in a for loop, find the Element whose ElementID matches the one you're after and Delete() it. Don't forget to Refresh() the collection afterwards.
There is a method Repository.SQLQuery(), which allows you to perform a select query against the database, but you have to parse the result from a single XML string.
It's simpler to use Repository.GetElementsByQuery(), which returns the elements in a Collection, but this requires you to predefine the query as an EA search. If you use this, you can skip steps 1 and 2 above.
Of course, you could go straight into the database and simply delete all those t_object rows which are not referred to from t_diagramobjects. This is a terribly bad idea which will (I'm pretty sure) leave you with a corrupted database. When you use the API to delete things, EA cleans up all references (so no connectors are left dangling, etc).
And of course, you should only unleash a script like this if you are absolutely sure there are no other elements that aren't shown in diagrams that need to be kept. So a temp project for this is probably a good idea.
Note, finally, that packages are also elements, and if you don't want to lose all your imported source in one fell swoop by deleting the package they're in (because the package itself is typically not shown in a diagram, is it?) you should probably exclude t_object.Object_Type / Element.Type "Package".
I know this is old but I think I have something to contribute :)
The simplest answer has already been given and it is the "Find Orphans" thingy. Now while cleaning a big EA repository I inherited I noticed there are cases where a given object may not be in a diagram but a child object will. In this case you don't want to be cleaning the parent object or you may lose the child.
So I crafted the following search:
select
o.ea_guid as CLASSGUID, o.object_type as CLASSTYPE, *
from
t_object o
where
o.Object_Type != 'Package'
and
not exists (select t_diagramobjects.Diagram_ID from t_diagramobjects where t_diagramobjects.Object_ID = o.object_ID)
and
not exists (select t2.OBJECT_ID from t_object t2 where t2.PARENTID=o.OBJECT_ID)
It will only return "orphans that don't have a parent". Of course it could be improved to only return "orphans that don't have a parent that is itself an orphan" but I did not need that and could do some manual work...
(you access the SQL Search interface by Control+F/Builder/SQL)
The user interface in Enterprise Architect version 12 appears to have changed slightly for finding orphaned elements.
Ctrl + F to "Find in Project".
Select "Diagram Searches" from the Search Category drop down.
Select "Find Orphans" from the Search drop down.
Leave blank to find all orphans.
Click Run or press Enter.
I have a strange thing, I'm using dynamic field binding in a custom control.
The field binding is created like this.
XPage (Datasource "document" is placed here)
Custom Control (String passed in)
(to get errors if there are any)
Repeat (CompositeData is passed to a bean that returns the strings for Rows,columns)
Repeat (repeat 1 variable used for Columns)
Custom Control (fieldname is passed in)
field binding is done like this
#{document[compositeData.fieldName]}
The problem is that when I save the XPage I get an error in the messages control
Document has been saved by another user - Save created a new document as a response to that modified document.
And all fields are cleared.
Any ideas how to debug this or is there something I'm missing?
The "Document has been saved by another user" error is only tip of the iceberg - there are some really strange problems with reapeats that repeats fields that are bound and repeatControls property is set to false. The decoding part of xpages lifecycle cannot handle it properly - the controls will be losing data. You should use repeatControls set to true as Martin suggests.
"Repeat control variable doesn't exists" is probably caused by the property that removes repeats set to true. You can solve this by either changing it to false or by adding additional data context that will keep repeated value.
And finally for this to have add/remove functionality You can use Dynamic Content Control and show(null) hack to rebuild the repeat content.
To manage this complexity better I would advise You to stop using document data source and start creating some managed beans.
If You will follow my suggestions I guarantee that You will get the functionality You are looking for as I have few apps that works great and have this kind of complex data editors in them.
I don't know if it'll help you, but I pass both the document datasource and the field name as parameters to a DynamicField control, and use it like this:
compositeData.dataSource[compositeData.fieldName]
The type of the datasource is com.ibm.xsp.model.DataSource, it's listed as dataInterface under Data Sources.
Do you have repeatControls="true" set for the repeat control?
It sounds like you've got the datasource defined multiple times on the XPage (plus custom controls). Either that or the save button has save="true" but the code saves the document back-end, or code in multiple places saves the same document. I've used the same method of passing the datasource down to the custom control, but that may just be because that was what I saw on a blog.
What is the difference between the System.ComponentModel.BindingList methods Add(object) and AddNew()? The MSDN documentation says this:
Add: Adds an object to the end of the Collection<T>.
AddNew: Adds a new item to the collection.
It seems like both methods add an item to the collection, but Add(object) does it in one shot whereas AddNew() is slightly more complicated. My tests with Add(object) seem to be working, but I want to know if I am using the correct method.
So what is the difference between these methods?
AddNew() creates the object for you (that's why it doesn't have a parameter).
It's designed to be used by grids, which don't know how to create a new object to pass to Add().
AddNew() is very handy (it’s the well-known Factory design pattern) when you implement a class derived of BindingList().
It allows your code to initialize new items with values that depend on the list itself - e.g. a foreign key to the parent object if the binding list contains a list of children.
I have core data app with an entity OBSERVATION that has as one of its attributes DEALNAME.
I want to reference through Interface Builder or by making custom modifications to an NSArrayController a list of unique sorted dealnames so that I can use them in a pop-up.
I have attempted to use #distinctUnionOfSets (and #distinctUnionOfArrays) but am unable to locate the proper key sequence.
I can sort the ArrayController by providing a sort descriptor, but do not know how to eliminate duplicates.
Are the #distinct... keys the right methodology? It would seem to provide the easiest way to optimize the use of IB.
Is there a predicate form for removing duplicates?
Or do I need to use my custom controller to extract an NSSet of the specific dealnames, put them back in an array and sort it and reference the custom array from IB?
Any help would be appreciated. I am astounded that other have not tried to create a sorted-unique pop-up in tableviews.
You need to take a look at -[NSFetchRequest returnsDistinctResults]. That is the level you need to be handling the uniquing of data.
Although I do not have a definitive answer for you, I think there are two ways you can go about it.
The way you already started. You need to bind the contents array of the PopUp button, not just against the arrayController.arrangedObjects, but continue on the path and somehow filter only objects with distinct "DealName"s. This means - the arrayController presents ALL the entities (and may sort them for you) but the PopUp button will have its contents filter via some sophisticated binding to the array controller.
Make your filtering at the ArrayController level (as suggested in another answer here). Here it depends how you set up the array controller. If It is set up to use an "Entity" (vs. "Class") which means the array controller will fetch CoreData entities directly - you can modify its "Fetch" to only bring a subset of the "OBSERVATION" entities with distinct values of "DEALNAME". I don't know how to control WHICH entities are filtered out in this case. Otherwise, you can setup the arrayController to work with "Class" objects, and then you can fetch the entities yourself (in code) and populate the arrayController programmatically, with just the entities you like.
In the second option, the Popup button should be bound normally to the arrayController's arrangedObjects.