Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[higgins-dev] Update operations using the JNDI CP

I've implemented the newly-proposed createSubject, and updateSubject in the JNDI CP as a proof of concept.  I ended up changing the methods to take arrays of things like this:
 
public String createSubject(URI subjectType, String cuid,  IAttribute[] attributes, IMetadata[] metadata) throws IdASException
public String createSubject(URI subjectType,  IAttribute[] attributes, IMetadata[] metadata) throws IdASException
public void updateSubject(String cuid, UpdateOperation[] updates) throws IdASException
Here's the code which creates a new subject (this is as it is in the jndi cp unit test):
 private String _createPerson(IContext context, String cuid) throws IdASException, URISyntaxException
 {
  IAttribute snAttr = new BasicAttribute(new URI("sn"), new BasicValueString("Jones"));
  IAttribute cnAttr = new BasicAttribute(new URI("cn"), new BasicValueString("MikeJones"));
  cnAttr.setValue(new BasicValueString("MichaelJones"));
  IAttribute[] attrs = {snAttr, cnAttr};
  return context.createSubject(new URI("person"), cuid, attrs, null);
 }
This creates a "person" subject with the attributes: sn(value is "Jones") and cn(values are "MikeJones" and "MichaelJones")
 
The following code creates a subject, then performs some modifications:
   _createPerson(context, cuidIn);
   UpdateOperation op1 = new UpdateOperation(UpdateOperation.UPDATE_OP_DELETE, new BasicAttribute(new URI("cn"), new BasicValueString("MichaelJones")));
   UpdateOperation op2 = new UpdateOperation(UpdateOperation.UPDATE_OP_ADD, new BasicAttribute(new URI("cn"), new BasicValueString("MikeyJones")));
   UpdateOperation op3 = new UpdateOperation(UpdateOperation.UPDATE_OP_REPLACE, new BasicAttribute(new URI("telephoneNumber"), new BasicValueString("555-1212")));
   UpdateOperation[] updates = {op1, op2, op3};
   context.updateSubject(cuidIn, updates);
Some interesting things happen there:
1) The "MichaelJones" value of the cn attribute is changed to "MikeyJones".  We do this by specifying a delete of the old attribute, and an add of the new attribute. 
2) If there had not been a "MichaelJones" value of the cn attribute, the operation would fail (this needs to be documented).
3) A new attribute is added telephoneNumber(value is "555-1212").  If there had already been a telephoneNumber attribute, all old values would have been removed and replaced by the new value.  Note that we could have added more telephoneNumber values at this time if we had chosen to.
 
This isn't yet using the model to create attributes and values.  I'm still turning the benefits of doing it that way over in my head.  It may be that we end up wanting to allow doing as above (new BasicAttribute) or the probably longer more arduous way of going through the model.
 
Anyway, the cool thing is, this all works (on my machine :)).  We can do updates in the JNDI provider now if we want, but if I commit this stuff, it will cause all other CP's to add new methods, so it'll be awhile before I can do that.
 
Jim

Back to the top