-
Notifications
You must be signed in to change notification settings - Fork 10
Fixes #30: support object field #47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes #30: support object field #47
Conversation
…t fields and use Paths over fieldName fix crud errors so that they actually are sent to the client
Ready for review |
@bserdar - dcrissman, re: LdapFieldNameTranslator: the second method should also be updated to return a Path @bserdar - dcrissman, re: doc error handling: constructing a new Doc won't work. The point of associating errors with docs was that there should be some basic identifying information about the doc with errors, so the client would know which doc has those errors. Sending an empty doc with an error array is pointless. Either don't return doc errors and fail the call, or put some identifying information to the document wiht error |
@bserdar I changed LdapFieldNameTranslator#translateAttributeName to now return a path. Regarding your second point about the doc error, at the point in the Find CRUD operation, there is no document to send back as we failed to translate the ldap results into a document. I would think some kind of error message would be better than nothing. Just to see what the output would be, I threw a fake RuntimeException in the code to generate the below error message. The msg would at least give a clue what happened. My other thought would be to just grab the dn off the ldap result record and add that to the returned new errored DocCtx, but I don't particularly like that as it is the ResultTranslator's job to know how to translate results, not the LdapCRUDController's. And what if part of the problem was translating the dn? {"errors":[{"objectType":"error","context":"find(person:1.0.0)","errorCode":"RuntimeException","msg":"fake exception"}]} |
I think the better way to deal with this is to add translation exceptions On Wed, Jan 28, 2015 at 7:06 AM, Dennis Crissman [email protected]
|
EntryBuilder:
LdapCRUDController:
TranslatorFromJson:
TrivialTranslator: LdapMetadata:
|
@bserdar I believe I have address all your concerns. Regarding TrivialTranslator and LdapMetadata, path.getLast() is needed when handling fields within an object. TrivialTranslator blindly grabs last, because by definition if it is being used than no aliases were created. |
The pattern to use Error.push/pop is: Error.push(stuff); In EntryBuilder.build, do this: Error.push("EntryBuilder.build") Throwing errors: EntryBuilder.82 Use the naming conventions we estanbisled for this. Look at, for instance, MetadataConstants.java. Your error should mean something to the caller. Let the caller translate the error code to a meaningful message. For instance: LDAPCRUDController#131: I believe there is already an error code constant for missing required field, either in CrudConstants or MetadataConstants beforeCreateNewSchema:
This code assumes a lot of things about the context: Path objectClassFieldPath = ldapNameTranslator.translateAttributeName(LdapConstant.ATTRIBUTE_OBJECT_CLASS); ^^^^ This assumes objectClassfieldPath can be a multi-level field if(!fields.has(objectClassFieldPath.toString())){ ^^^^ This assumes objectClassFieldName does not have '.', contradicts with the line above fields.addNew(new ArrayField(objectClassFieldName, new SimpleArrayElement(StringType.TYPE))); ^^^ You might be creating a field with '.' in the name, or an array index in the name TranslatorFromJson: #100: dead code. resolve() throws exception if it can't resolve. ResultTranslator: nitpicking { This is much more obvious: LdapMetadata:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really love this implementation, I am open to suggestions if a better way can be found.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FieldTreeNode dnNode=null;
try {
dnNode=md.resolve(dnFieldPath());
} catch (Error e) {
dnNode=addFieldToParent ...
}
if(!dnNode.getType() instanceof StringType)
{
throw ...
}
On Fri, Jan 30, 2015 at 2:41 PM, Dennis Crissman [email protected]
wrote:
In
lightblue-ldap-crud/src/main/java/com/redhat/lightblue/crud/ldap/LdapMetadataListener.java
#47 (comment)
:
LdapFieldNameTranslator ldapNameTranslator = LdapCrudUtil.getLdapFieldNameTranslator(md);
//TODO: check for array index or Path.any
Path dnFieldPath = ldapNameTranslator.translateAttributeName(LdapConstant.ATTRIBUTE_DN);
try{
FieldTreeNode dnNode = md.resolve(dnFieldPath);
if((!(dnNode instanceof SimpleField)) || (!(dnNode.getType() instanceof StringType))){
throw Error.get(MetadataConstants.ERR_FIELD_WRONG_TYPE, dnNode.getFullPath().toString());
}
}
catch(Error e){
if(e.getErrorCode().equals(MetadataConstants.ERR_FIELD_WRONG_TYPE)){
throw e;
}
addFieldToParent(md, dnFieldPath, new SimpleField(dnFieldPath.getLast(), StringType.TYPE));
}
I don't really love this implementation, I am open to suggestions if a
better way can be found.—
Reply to this email directly or view it on GitHub
https://github.com/lightblue-platform/lightblue-ldap/pull/47/files#r23874595
.
I am fine with using the already defined error codes. I am however confused about what many of them mean. There are a lot of them, and it is not always obvious what code should be used when. I honestly kind of guessed on most of the ones I used. Maybe some in-line comments or documentation would be useful here?
This was a misunderstanding on my part. I switch to the equals method.
If we are going to do that, then I suggest we add OBJECT_TYPE as a constant somewhere in core. My intention was that LightblueUtil could be considered for inclusion in core eventually, if it made sense. Then build some common mechanisms for determining if a Field was "auto generated". This could be useful for plugins that do not actually store object_type or other generated fields in the underlying datastore.
I agree that the Path object should be stored in the Map and not the String representation. So I made that change. I would like to discuss the second part of your request further. |
I agree: need more documentation about what error code means what, and what Why OBJECT_TYPE as a constant in core? That's LDAP specific, put it in an You got stuck in this idea of "auto generated". They are fields On Fri, Jan 30, 2015 at 2:57 PM, Dennis Crissman [email protected]
|
I though objectType was Lightblue's way of identifying the entity? I think you might be confusing objectType with LDAP's objectClass.
I guess what I mean by auto-generated, is the objectType field and array count fields (prefixed by '#'). These are lightblue entity fields that need to exist, but don't necessarily physically exist in a particular backend. For the purposes of LDAP, I need to filter them out on a modifying operation and create them on a find operation. I understand that certain backends will have their own auto-generated fields, such as _id or objectClass and that those specific backends will need to handle them appropriately. |
Yes, I am confusing the two. objectType in code is ok, if it is not already On Mon, Feb 2, 2015 at 7:24 AM, Dennis Crissman [email protected]
|
Back to the LdapMetadata map discussion. I switched it over to a BiMap (http://google-collections.googlecode.com/svn/trunk/javadoc/index.html?com/google/common/collect/BiMap.html). I think this solves my concern of managing two Maps, and your concern about the cost of iterating over the values. Let me know what you think. |
If you already had google.common package included, it's ok to use it. I'd On Mon, Feb 2, 2015 at 7:50 AM, Dennis Crissman [email protected]
|
It is a transient dependency of lightblue-core-config |
Ready for review. |
Fixes #30: support object field
No description provided.