24
24
25
25
import com .fasterxml .jackson .databind .JsonNode ;
26
26
import com .redhat .lightblue .common .ldap .LdapConstant ;
27
+ import com .redhat .lightblue .common .ldap .LdapErrorCode ;
27
28
import com .redhat .lightblue .common .ldap .LdapFieldNameTranslator ;
28
29
import com .redhat .lightblue .common .ldap .LightblueUtil ;
29
30
import com .redhat .lightblue .metadata .ArrayElement ;
30
31
import com .redhat .lightblue .metadata .ArrayField ;
31
32
import com .redhat .lightblue .metadata .EntityMetadata ;
32
- import com .redhat .lightblue .metadata .ObjectField ;
33
+ import com .redhat .lightblue .metadata .MetadataConstants ;
33
34
import com .redhat .lightblue .metadata .SimpleField ;
34
35
import com .redhat .lightblue .metadata .Type ;
35
36
import com .redhat .lightblue .metadata .types .BinaryType ;
36
37
import com .redhat .lightblue .metadata .types .DateType ;
38
+ import com .redhat .lightblue .util .Error ;
37
39
import com .redhat .lightblue .util .JsonDoc ;
38
40
import com .redhat .lightblue .util .JsonNodeCursor ;
39
- import com .redhat .lightblue .util .Path ;
40
41
import com .unboundid .ldap .sdk .Entry ;
41
42
import com .unboundid .util .StaticUtils ;
42
43
@@ -55,9 +56,17 @@ public EntryBuilder(EntityMetadata md, LdapFieldNameTranslator fieldNameTranslat
55
56
}
56
57
57
58
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
+ }
61
70
}
62
71
63
72
@ Override
@@ -74,13 +83,12 @@ else if(type instanceof BinaryType){
74
83
}
75
84
76
85
@ 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 ());
79
88
80
89
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 );
84
92
}
85
93
else if (LightblueUtil .isFieldObjectType (attributeName )
86
94
|| LightblueUtil .isFieldAnArrayCount (attributeName , getEntityMetadata ().getFields ())){
@@ -102,15 +110,10 @@ else if(LightblueUtil.isFieldObjectType(attributeName)
102
110
}
103
111
104
112
@ 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 ) {
111
114
ArrayElement arrayElement = field .getElement ();
112
115
Type arrayElementType = arrayElement .getType ();
113
- String attributeName = fieldNameTranslator .translateFieldName (field .getName ());
116
+ String attributeName = fieldNameTranslator .translateFieldName (field .getFullPath ());
114
117
115
118
if (arrayElementType instanceof BinaryType ){
116
119
List <byte []> bytes = new ArrayList <byte []>();
@@ -130,7 +133,7 @@ protected void translateSimpleArray(ArrayField field, Path path, List<Object> it
130
133
131
134
@ Override
132
135
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 () );
134
137
}
135
138
136
139
}
0 commit comments