Skip to content

Commit dfd0c0d

Browse files
committed
adjustments to better utilize the tools provided by core
1 parent da8d967 commit dfd0c0d

File tree

3 files changed

+12
-36
lines changed

3 files changed

+12
-36
lines changed

lightblue-ldap-crud/src/main/java/com/redhat/lightblue/crud/ldap/LdapCRUDController.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929

3030
import com.fasterxml.jackson.databind.JsonNode;
3131
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
32-
import com.fasterxml.jackson.databind.node.ObjectNode;
3332
import com.redhat.lightblue.common.ldap.DBResolver;
3433
import com.redhat.lightblue.common.ldap.LdapConstant;
3534
import com.redhat.lightblue.common.ldap.LdapDataStore;
@@ -376,9 +375,9 @@ private void projectChanges(Projection projection, CRUDOperationContext ctx, Map
376375

377376
// If only dn is in the projection, then no need to query LDAP.
378377
if((requiredAttributeNames.size() == 1) && requiredAttributeNames.contains(LdapConstant.ATTRIBUTE_DN)){
379-
ObjectNode node = factory.objectNode();
380-
node.set(dnFieldPath.toString(), StringType.TYPE.toJson(factory, dn));
381-
projectionResponseJson = new DocCtx(new JsonDoc(node));
378+
JsonDoc jdoc = new JsonDoc(factory.objectNode());
379+
jdoc.modify(dnFieldPath, StringType.TYPE.toJson(factory, dn), true);
380+
projectionResponseJson = new DocCtx(jdoc);
382381
}
383382
//TODO: else fetch entity from LDAP and project results.
384383
//TODO: Probably want to batch fetch as opposed to individual fetches.

lightblue-ldap-crud/src/main/java/com/redhat/lightblue/crud/ldap/LdapMetadataListener.java

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020

2121
import com.redhat.lightblue.common.ldap.LdapConstant;
2222
import com.redhat.lightblue.common.ldap.LdapFieldNameTranslator;
23-
import com.redhat.lightblue.common.ldap.LightblueUtil;
24-
import com.redhat.lightblue.metadata.ArrayElement;
2523
import com.redhat.lightblue.metadata.ArrayField;
2624
import com.redhat.lightblue.metadata.EntityInfo;
2725
import com.redhat.lightblue.metadata.EntityMetadata;
@@ -33,9 +31,9 @@
3331
import com.redhat.lightblue.metadata.MetadataListener;
3432
import com.redhat.lightblue.metadata.ObjectArrayElement;
3533
import com.redhat.lightblue.metadata.ObjectField;
34+
import com.redhat.lightblue.metadata.PredefinedFields;
3635
import com.redhat.lightblue.metadata.SimpleArrayElement;
3736
import com.redhat.lightblue.metadata.SimpleField;
38-
import com.redhat.lightblue.metadata.types.IntegerType;
3937
import com.redhat.lightblue.metadata.types.StringType;
4038
import com.redhat.lightblue.util.Error;
4139
import com.redhat.lightblue.util.Path;
@@ -72,36 +70,17 @@ public void beforeCreateNewSchema(Metadata m, EntityMetadata md) {
7270

7371
ensureDnField(md, ldapNameTranslator.translateAttributeName(LdapConstant.ATTRIBUTE_DN));
7472

75-
Path objectClassFieldPath = ensureObjectClassField(md,
73+
ensureObjectClassField(md,
7674
ldapNameTranslator.translateAttributeName(LdapConstant.ATTRIBUTE_OBJECT_CLASS));
7775

78-
ensureObjectClassCountField(md,
79-
objectClassFieldPath.mutableCopy().pop().push(LightblueUtil.createArrayCountFieldName(objectClassFieldPath.getLast())));
80-
}
81-
82-
/**
83-
* Ensures the objectClass count field is present on the entity. If not, then it will added. If so, but
84-
* is defined incorrectly, then an {@link Error} will be thrown.
85-
*/
86-
private void ensureObjectClassCountField(EntityMetadata md, Path objectClassCountFieldPath) {
87-
FieldTreeNode objectClassCountNode;
88-
try{
89-
objectClassCountNode = md.resolve(objectClassCountFieldPath);
90-
}
91-
catch(Error e){
92-
addFieldToParent(md, objectClassCountFieldPath,
93-
(Field)(objectClassCountNode = new SimpleField(objectClassCountFieldPath.getLast(), IntegerType.TYPE)));
94-
}
95-
if((!(objectClassCountNode instanceof SimpleField)) || (!(objectClassCountNode.getType() instanceof IntegerType))){
96-
throw Error.get(MetadataConstants.ERR_FIELD_WRONG_TYPE, objectClassCountNode.getFullPath().toString());
97-
}
76+
PredefinedFields.ensurePredefinedFields(md);
9877
}
9978

10079
/**
10180
* Ensures the objectClass field is present on the entity. If not, then it will added. If so, but
10281
* is defined incorrectly, then an {@link Error} will be thrown.
10382
*/
104-
private Path ensureObjectClassField(EntityMetadata md, Path objectClassFieldPath) {
83+
private void ensureObjectClassField(EntityMetadata md, Path objectClassFieldPath) {
10584
FieldTreeNode objectClassNode;
10685
try{
10786
objectClassNode = md.resolve(objectClassFieldPath);
@@ -114,11 +93,9 @@ private Path ensureObjectClassField(EntityMetadata md, Path objectClassFieldPath
11493
throw Error.get(MetadataConstants.ERR_FIELD_WRONG_TYPE, objectClassNode.getFullPath().toString());
11594
}
11695
ArrayField objectClassField = (ArrayField) objectClassNode;
117-
ArrayElement arrayElement = objectClassField.getElement();
118-
if((!(arrayElement instanceof SimpleArrayElement)) || (!(arrayElement.getType() instanceof StringType))){
96+
if(!(objectClassField.getElement().getType() instanceof StringType)){
11997
throw Error.get(MetadataConstants.ERR_FIELD_WRONG_TYPE, objectClassField.getFullPath().toString());
12098
}
121-
return objectClassFieldPath;
12299
}
123100

124101
/**
@@ -134,7 +111,7 @@ private void ensureDnField(EntityMetadata md, Path dnFieldPath) {
134111
addFieldToParent(md, dnFieldPath,
135112
(Field)(dnNode = new SimpleField(dnFieldPath.getLast(), StringType.TYPE)));
136113
}
137-
if((!(dnNode instanceof SimpleField)) || (!(dnNode.getType() instanceof StringType))){
114+
if(!(dnNode.getType() instanceof StringType)){
138115
throw Error.get(MetadataConstants.ERR_FIELD_WRONG_TYPE, dnNode.getFullPath().toString());
139116
}
140117
}

lightblue-ldap-crud/src/main/java/com/redhat/lightblue/crud/ldap/translator/ResultTranslator.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ public DocCtx translate(SearchResultEntry entry){
7171
Fields fields = md.getFields();
7272

7373
if (cursor.firstChild()) {
74-
ObjectNode node = toJson(entry, cursor, fields);
75-
node.set(dnPath.toString(), StringType.TYPE.toJson(factory, entry.getDN()));
76-
return new DocCtx(new JsonDoc(node));
74+
JsonDoc jdoc = new JsonDoc(toJson(entry, cursor, fields));
75+
jdoc.modify(dnPath, StringType.TYPE.toJson(factory, entry.getDN()), true);
76+
return new DocCtx(jdoc);
7777
}
7878

7979
//TODO: What to do in case of a null value here?

0 commit comments

Comments
 (0)