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

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

Related

Entity Framework Plus. A new entity is not returned with cache

I use Entity Framework Plus with FromCache option with EF6.
My problem is that after adding a new item the cache that returned doesn't contain the item.
Is it possible to "update" the cache automatically after a new item added?
Save a new policy:
db.policies.Add(policy);
db.SaveChanges();
Get the all policies:
database.policies.FromCache().ToList();
EF Plus has CacheItemPolicy but I have to supply SqlCommand for the class that I do not have as you can see in the example of saving an item.
Try the option IsAutoExpireCacheEnabled for EF6
QueryCacheManager.IsAutoExpireCacheEnabled = true;
Fiddle: https://dotnetfiddle.net/3WHMGk
As soon as something is added/modified/deleted, all caches related to this DbSet will be clreared.

create nodes programatically with gmf but without setting its properties

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.

AppFabric - List object returned has objects with null values

I am new to AppFabric and exploring it. I am able to put List in appfabric and able to retrieve the list using Get method. However, after retrieveing all the properties of the objects are set as null. Can anybody help how can I resolve this problem.
Following is sample code
//Country object
Country country1 = new Country();
country1.Name ="test";
//Create list
List <Country> countryList = new List <Country>();
countryList.Add(country1);
//Add to AppFabric
_cache.Put("countryKey",countryList)
//Retrieve from cache
List <Country> countryList = (List <Country>)_cache.Get("countryKey");
//check the result
countryList.Count returns 1 which is expected.
countryList[0].Name returns null;
Objects are stored in the cache in a serialized form. AppFabric uses the NetDataContractSerializer class for serialization before storing the items in the cache.
Empty properties generally means that there is a problem in serialization/deserialization. Try to Add DataContract attribute to Country and DataMember attribute to each property you want to keep this class.

Rails: Difference between create and new methods in ActiveRecord?

I'm following a Rails 3.0 tutorial by lynda.com.
What's the difference between these two lines?
first_page = Page.new(:name => "First page")
first_page = Page.create(:name => "First page")
By the way, this is great tutorial; I recommend it for any other newbies like me.
Basically the new method creates an object instance and the create method additionally tries to save it to the database if it is possible.
Check the ActiveRecord::Base documentation:
create method
Creates an object (or multiple objects) and saves it to the database, if validations pass. The resulting object is returned whether the object was saved successfully to the database or not.
new method
New objects can be instantiated as either empty (pass no construction parameter) or pre-set with attributes but not yet saved (pass a hash with key names matching the associated table column names).

validation based on attributes in metadata class

I am performing validation based on attributes in metadata.cs file. I am using Entity framework 4.0 and using wcf ria services. I want to know what is the equivalent of Page.IsValid in asp.net in silverlight? How do i ensure that the entity is in correct state before saving it? If i do not ensure this an exception fires which looks very ugly. I found a property named entityName.ValidationErrorCount so if my entity is named User i do objUser.ValidationErrorCount is less than equal to 0 i save it. Problem with this approach is if the user doesn't enter value in any of the textbox then subsequently all the values in the entity are null. So ValidationErrorCount property returns 0 because all are null values and thus my program tries to save the entity but naturally the entity is in incorrect state so exception fires. How do i get past this problem?
I hope i am clear. If not, please let me know. Thanks in advance :)
You can validate an entity using the Validator class (from the System.ComponentModel.DataAnnotations
namespace), like so (where entity is a reference to the entity to be validated):
List<ValidationResult> validationResults = new List<ValidationResult>();
ValidationContext validationContext = new ValidationContext(entity, null, null);
bool isValid = Validator.TryValidateObject(entity, validationContext, validationResults, true);
Alternatively, are you using the DataForm control? If so, there's an even easier way to check whether the current item is valid, by calling the ValidateItem() method on the DataForm. This will return a boolean indicating whether the current item is valid (you can also check the IsItemValid property of the DataForm). It will also update the bound controls to show their validation status. If you're not using the DataForm, then it will certainly make it easier if you can. Otherwise, simply add the validation results to the entity's ValidationErrors property:
foreach (ValidationResult result in validationResults)
entity.ValidationErrors.Add(result);
Hope this helps...
Chris