@@ -52,6 +52,16 @@ public void beforeUpdateEntityInfo(Metadata m, EntityInfo ei, boolean newEntity)
52
52
//Do Nothing!!
53
53
}
54
54
55
+ @ Override
56
+ public void afterUpdateEntityInfo (Metadata m , EntityInfo ei , boolean newEntity ) {
57
+ //Do Nothing!!
58
+ }
59
+
60
+ @ Override
61
+ public void afterCreateNewSchema (Metadata m , EntityMetadata md ) {
62
+ //Do Nothing!!
63
+ }
64
+
55
65
/**
56
66
* Ensure that dn and objectClass are on the entity.
57
67
*/
@@ -60,51 +70,72 @@ public void beforeCreateNewSchema(Metadata m, EntityMetadata md) {
60
70
LdapFieldNameTranslator ldapNameTranslator = LdapCrudUtil .getLdapFieldNameTranslator (md );
61
71
//TODO: check for array index or Path.any
62
72
63
- Path dnFieldPath = ldapNameTranslator .translateAttributeName (LdapConstant .ATTRIBUTE_DN );
73
+ ensureDnField (md , ldapNameTranslator .translateAttributeName (LdapConstant .ATTRIBUTE_DN ));
74
+
75
+ Path objectClassFieldPath = ensureObjectClassField (md ,
76
+ ldapNameTranslator .translateAttributeName (LdapConstant .ATTRIBUTE_OBJECT_CLASS ));
77
+
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 ;
64
88
try {
65
- FieldTreeNode dnNode = md .resolve (dnFieldPath );
66
- if ((!(dnNode instanceof SimpleField )) || (!(dnNode .getType () instanceof StringType ))){
67
- throw Error .get (MetadataConstants .ERR_FIELD_WRONG_TYPE , dnNode .getFullPath ().toString ());
68
- }
89
+ objectClassCountNode = md .resolve (objectClassCountFieldPath );
69
90
}
70
91
catch (Error e ){
71
- if (e .getErrorCode ().equals (MetadataConstants .ERR_FIELD_WRONG_TYPE )){
72
- throw e ;
73
- }
74
- addFieldToParent (md , dnFieldPath , new SimpleField (dnFieldPath .getLast (), StringType .TYPE ));
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 ());
75
97
}
98
+ }
76
99
77
- Path objectClassFieldPath = ldapNameTranslator .translateAttributeName (LdapConstant .ATTRIBUTE_OBJECT_CLASS );
100
+ /**
101
+ * Ensures the objectClass field is present on the entity. If not, then it will added. If so, but
102
+ * is defined incorrectly, then an {@link Error} will be thrown.
103
+ */
104
+ private Path ensureObjectClassField (EntityMetadata md , Path objectClassFieldPath ) {
105
+ FieldTreeNode objectClassNode ;
78
106
try {
79
- FieldTreeNode objectClassNode = md .resolve (objectClassFieldPath );
80
- if (!(objectClassNode instanceof ArrayField )){
81
- throw Error .get (MetadataConstants .ERR_FIELD_WRONG_TYPE , objectClassNode .getFullPath ().toString ());
82
- }
83
- ArrayField objectClassField = (ArrayField ) objectClassNode ;
84
- ArrayElement arrayElement = objectClassField .getElement ();
85
- if ((!(arrayElement instanceof SimpleArrayElement )) || (!(arrayElement .getType () instanceof StringType ))){
86
- throw Error .get (MetadataConstants .ERR_FIELD_WRONG_TYPE , objectClassField .getFullPath ().toString ());
87
- }
107
+ objectClassNode = md .resolve (objectClassFieldPath );
88
108
}
89
109
catch (Error e ){
90
- if (e .getErrorCode ().equals (MetadataConstants .ERR_FIELD_WRONG_TYPE )){
91
- throw e ;
92
- }
93
- addFieldToParent (md , objectClassFieldPath , new ArrayField (objectClassFieldPath .getLast (), new SimpleArrayElement (StringType .TYPE )));
110
+ addFieldToParent (md , objectClassFieldPath ,
111
+ (Field ) (objectClassNode = new ArrayField (objectClassFieldPath .getLast (), new SimpleArrayElement (StringType .TYPE ))));
94
112
}
113
+ if (!(objectClassNode instanceof ArrayField )){
114
+ throw Error .get (MetadataConstants .ERR_FIELD_WRONG_TYPE , objectClassNode .getFullPath ().toString ());
115
+ }
116
+ ArrayField objectClassField = (ArrayField ) objectClassNode ;
117
+ ArrayElement arrayElement = objectClassField .getElement ();
118
+ if ((!(arrayElement instanceof SimpleArrayElement )) || (!(arrayElement .getType () instanceof StringType ))){
119
+ throw Error .get (MetadataConstants .ERR_FIELD_WRONG_TYPE , objectClassField .getFullPath ().toString ());
120
+ }
121
+ return objectClassFieldPath ;
122
+ }
95
123
96
- Path objectClassCountFieldPath = objectClassFieldPath .mutableCopy ().pop ().push (LightblueUtil .createArrayCountFieldName (objectClassFieldPath .getLast ()));
124
+ /**
125
+ * Ensures the dn field is present on the entity. If not, then it will added. If so, but
126
+ * is defined incorrectly, then an {@link Error} will be thrown.
127
+ */
128
+ private void ensureDnField (EntityMetadata md , Path dnFieldPath ) {
129
+ FieldTreeNode dnNode ;
97
130
try {
98
- FieldTreeNode objectClassCountNode = md .resolve (objectClassCountFieldPath );
99
- if ((!(objectClassCountNode instanceof SimpleField )) || (!(objectClassCountNode .getType () instanceof IntegerType ))){
100
- throw Error .get (MetadataConstants .ERR_FIELD_WRONG_TYPE , objectClassCountNode .getFullPath ().toString ());
101
- }
131
+ dnNode = md .resolve (dnFieldPath );
102
132
}
103
133
catch (Error e ){
104
- if (e .getErrorCode ().equals (MetadataConstants .ERR_FIELD_WRONG_TYPE )){
105
- throw e ;
106
- }
107
- addFieldToParent (md , objectClassCountFieldPath , new SimpleField (objectClassCountFieldPath .getLast (), IntegerType .TYPE ));
134
+ addFieldToParent (md , dnFieldPath ,
135
+ (Field )(dnNode = new SimpleField (dnFieldPath .getLast (), StringType .TYPE )));
136
+ }
137
+ if ((!(dnNode instanceof SimpleField )) || (!(dnNode .getType () instanceof StringType ))){
138
+ throw Error .get (MetadataConstants .ERR_FIELD_WRONG_TYPE , dnNode .getFullPath ().toString ());
108
139
}
109
140
}
110
141
@@ -137,14 +168,4 @@ else if (parent instanceof ObjectArrayElement){
137
168
fields .addNew (newField );
138
169
}
139
170
140
- @ Override
141
- public void afterUpdateEntityInfo (Metadata m , EntityInfo ei , boolean newEntity ) {
142
- //Do Nothing!!
143
- }
144
-
145
- @ Override
146
- public void afterCreateNewSchema (Metadata m , EntityMetadata md ) {
147
- //Do Nothing!!
148
- }
149
-
150
171
}
0 commit comments