Skip to content

Commit eb252cc

Browse files
committed
Merge pull request #47 from dcrissman/issue30-support-object-field
Fixes #30: support object field
2 parents f67a2c7 + dfd0c0d commit eb252cc

File tree

27 files changed

+1116
-276
lines changed

27 files changed

+1116
-276
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
Copyright 2015 Red Hat, Inc. and/or its affiliates.
3+
4+
This file is part of lightblue.
5+
6+
This program is free software: you can redistribute it and/or modify
7+
it under the terms of the GNU General Public License as published by
8+
the Free Software Foundation, either version 3 of the License, or
9+
(at your option) any later version.
10+
11+
This program is distributed in the hope that it will be useful,
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
GNU General Public License for more details.
15+
16+
You should have received a copy of the GNU General Public License
17+
along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
package com.redhat.lightblue.common.ldap;
20+
21+
/**
22+
* Error codes specific to LDAP
23+
*
24+
* @author dcrissman
25+
*/
26+
public final class LdapErrorCode {
27+
28+
/** An unsupported feature was used. */
29+
public static final String ERR_UNSUPPORTED_FEATURE = "ldap:UnsupportedFeature:";
30+
31+
/** Lightblue-Ldap does not currently support object arrays. This error indicates that such a field was used. */
32+
public static final String ERR_UNSUPPORTED_FEATURE_OBJECT_ARRAY = ERR_UNSUPPORTED_FEATURE + "ObjectArray";
33+
34+
private LdapErrorCode(){}
35+
36+
}

lightblue-ldap-common/src/main/java/com/redhat/lightblue/common/ldap/LdapFieldNameTranslator.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
*/
1919
package com.redhat.lightblue.common.ldap;
2020

21+
import com.redhat.lightblue.util.Path;
22+
2123
/**
2224
* Represents a class that can translate back and forth between a fieldName and an LDAP attributeName.
2325
*
@@ -30,13 +32,13 @@ public interface LdapFieldNameTranslator {
3032
* @param fieldName - metadata field name
3133
* @return ldap attributeName or the fieldName back at you if no mapping is present.
3234
*/
33-
public String translateFieldName(String fieldName);
35+
public String translateFieldName(Path path);
3436

3537
/**
3638
* Returns the fieldName with the given attributeName.
3739
* @param attributeName - ldap attribute name
3840
* @return metadata fieldName or the attributeName back at you if no mapping is present.
3941
*/
40-
public String translateAttributeName(String attributeName);
42+
public Path translateAttributeName(String attributeName);
4143

4244
}

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

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,20 @@
2424

2525
import com.fasterxml.jackson.databind.JsonNode;
2626
import com.redhat.lightblue.common.ldap.LdapConstant;
27+
import com.redhat.lightblue.common.ldap.LdapErrorCode;
2728
import com.redhat.lightblue.common.ldap.LdapFieldNameTranslator;
2829
import com.redhat.lightblue.common.ldap.LightblueUtil;
2930
import com.redhat.lightblue.metadata.ArrayElement;
3031
import com.redhat.lightblue.metadata.ArrayField;
3132
import com.redhat.lightblue.metadata.EntityMetadata;
32-
import com.redhat.lightblue.metadata.ObjectField;
33+
import com.redhat.lightblue.metadata.MetadataConstants;
3334
import com.redhat.lightblue.metadata.SimpleField;
3435
import com.redhat.lightblue.metadata.Type;
3536
import com.redhat.lightblue.metadata.types.BinaryType;
3637
import com.redhat.lightblue.metadata.types.DateType;
38+
import com.redhat.lightblue.util.Error;
3739
import com.redhat.lightblue.util.JsonDoc;
3840
import com.redhat.lightblue.util.JsonNodeCursor;
39-
import com.redhat.lightblue.util.Path;
4041
import com.unboundid.ldap.sdk.Entry;
4142
import com.unboundid.util.StaticUtils;
4243

@@ -55,9 +56,17 @@ public EntryBuilder(EntityMetadata md, LdapFieldNameTranslator fieldNameTranslat
5556
}
5657

5758
public Entry build(String dn, JsonDoc document){
58-
Entry entry = new Entry(dn);
59-
translate(document, entry);
60-
return entry;
59+
Error.push("build entry");
60+
Error.push(LdapConstant.ATTRIBUTE_DN + "=" + dn);
61+
try{
62+
Entry entry = new Entry(dn);
63+
translate(document, entry);
64+
return entry;
65+
}
66+
finally{
67+
Error.pop();
68+
Error.pop();
69+
}
6170
}
6271

6372
@Override
@@ -74,13 +83,12 @@ else if(type instanceof BinaryType){
7483
}
7584

7685
@Override
77-
protected void translate(SimpleField field, Path path, JsonNode node, Entry target) {
78-
String attributeName = fieldNameTranslator.translateFieldName(field.getName());
86+
protected void translate(SimpleField field, JsonNode node, Entry target) {
87+
String attributeName = fieldNameTranslator.translateFieldName(field.getFullPath());
7988

8089
if(LdapConstant.ATTRIBUTE_DN.equalsIgnoreCase(attributeName)){
81-
throw new IllegalArgumentException(
82-
"'dn' should not be included as it's value will be derived from the metadata.basedn and" +
83-
" the metadata.uniqueattr. Including the 'dn' as an insert attribute is confusing.");
90+
//DN is derived using metadata.uniqueattr, providing it is confusing.
91+
throw Error.get(MetadataConstants.ERR_INVALID_FIELD_REFERENCE, LdapConstant.ATTRIBUTE_DN);
8492
}
8593
else if(LightblueUtil.isFieldObjectType(attributeName)
8694
|| LightblueUtil.isFieldAnArrayCount(attributeName, getEntityMetadata().getFields())){
@@ -102,15 +110,10 @@ else if(LightblueUtil.isFieldObjectType(attributeName)
102110
}
103111

104112
@Override
105-
protected void translate(ObjectField field, Path path, JsonNode node, Entry target) {
106-
throw new UnsupportedOperationException("ObjectField type is not currently supported.");
107-
}
108-
109-
@Override
110-
protected void translateSimpleArray(ArrayField field, Path path, List<Object> items, Entry target) {
113+
protected void translateSimpleArray(ArrayField field, List<Object> items, Entry target) {
111114
ArrayElement arrayElement = field.getElement();
112115
Type arrayElementType = arrayElement.getType();
113-
String attributeName = fieldNameTranslator.translateFieldName(field.getName());
116+
String attributeName = fieldNameTranslator.translateFieldName(field.getFullPath());
114117

115118
if(arrayElementType instanceof BinaryType){
116119
List<byte[]> bytes = new ArrayList<byte[]>();
@@ -130,7 +133,7 @@ protected void translateSimpleArray(ArrayField field, Path path, List<Object> it
130133

131134
@Override
132135
protected void translateObjectArray(ArrayField field, JsonNodeCursor cursor, Entry target) {
133-
throw new UnsupportedOperationException("Object ArrayField type is not currently supported.");
136+
throw Error.get(LdapErrorCode.ERR_UNSUPPORTED_FEATURE_OBJECT_ARRAY, field.getFullPath().toString());
134137
}
135138

136139
}

0 commit comments

Comments
 (0)