20
20
21
21
import com .redhat .lightblue .common .ldap .LdapConstant ;
22
22
import com .redhat .lightblue .common .ldap .LdapFieldNameTranslator ;
23
- import com .redhat .lightblue .common .ldap .LightblueUtil ;
24
- import com .redhat .lightblue .metadata .ArrayElement ;
25
23
import com .redhat .lightblue .metadata .ArrayField ;
26
24
import com .redhat .lightblue .metadata .EntityInfo ;
27
25
import com .redhat .lightblue .metadata .EntityMetadata ;
33
31
import com .redhat .lightblue .metadata .MetadataListener ;
34
32
import com .redhat .lightblue .metadata .ObjectArrayElement ;
35
33
import com .redhat .lightblue .metadata .ObjectField ;
34
+ import com .redhat .lightblue .metadata .PredefinedFields ;
36
35
import com .redhat .lightblue .metadata .SimpleArrayElement ;
37
36
import com .redhat .lightblue .metadata .SimpleField ;
38
- import com .redhat .lightblue .metadata .types .IntegerType ;
39
37
import com .redhat .lightblue .metadata .types .StringType ;
40
38
import com .redhat .lightblue .util .Error ;
41
39
import com .redhat .lightblue .util .Path ;
@@ -72,36 +70,17 @@ public void beforeCreateNewSchema(Metadata m, EntityMetadata md) {
72
70
73
71
ensureDnField (md , ldapNameTranslator .translateAttributeName (LdapConstant .ATTRIBUTE_DN ));
74
72
75
- Path objectClassFieldPath = ensureObjectClassField (md ,
73
+ ensureObjectClassField (md ,
76
74
ldapNameTranslator .translateAttributeName (LdapConstant .ATTRIBUTE_OBJECT_CLASS ));
77
75
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 );
98
77
}
99
78
100
79
/**
101
80
* Ensures the objectClass field is present on the entity. If not, then it will added. If so, but
102
81
* is defined incorrectly, then an {@link Error} will be thrown.
103
82
*/
104
- private Path ensureObjectClassField (EntityMetadata md , Path objectClassFieldPath ) {
83
+ private void ensureObjectClassField (EntityMetadata md , Path objectClassFieldPath ) {
105
84
FieldTreeNode objectClassNode ;
106
85
try {
107
86
objectClassNode = md .resolve (objectClassFieldPath );
@@ -114,11 +93,9 @@ private Path ensureObjectClassField(EntityMetadata md, Path objectClassFieldPath
114
93
throw Error .get (MetadataConstants .ERR_FIELD_WRONG_TYPE , objectClassNode .getFullPath ().toString ());
115
94
}
116
95
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 )){
119
97
throw Error .get (MetadataConstants .ERR_FIELD_WRONG_TYPE , objectClassField .getFullPath ().toString ());
120
98
}
121
- return objectClassFieldPath ;
122
99
}
123
100
124
101
/**
@@ -134,7 +111,7 @@ private void ensureDnField(EntityMetadata md, Path dnFieldPath) {
134
111
addFieldToParent (md , dnFieldPath ,
135
112
(Field )(dnNode = new SimpleField (dnFieldPath .getLast (), StringType .TYPE )));
136
113
}
137
- if (( !(dnNode instanceof SimpleField )) || (!( dnNode .getType () instanceof StringType ) )){
114
+ if (!(dnNode .getType () instanceof StringType )){
138
115
throw Error .get (MetadataConstants .ERR_FIELD_WRONG_TYPE , dnNode .getFullPath ().toString ());
139
116
}
140
117
}
0 commit comments