Skip to content

Commit 5834412

Browse files
committed
add ability for uniqueAttribute to be aliased
1 parent 6d7be8b commit 5834412

File tree

8 files changed

+25
-14
lines changed

8 files changed

+25
-14
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ public void setBaseDN(String baseDN) {
5353
this.baseDN = baseDN;
5454
}
5555

56-
public String getUniqueField() {
56+
public String getUniqueAttribute() {
5757
return uniqueField;
5858
}
5959

60-
public void setUniqueField(String uniqueField) {
60+
public void setUniqueAttribute(String uniqueField) {
6161
this.uniqueField = uniqueField;
6262
}
6363

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,10 @@ public CRUDInsertionResponse insert(CRUDOperationContext ctx,
127127

128128
JsonNode rootNode = document.getRoot();
129129

130-
JsonNode uniqueNode = rootNode.get(store.getUniqueField());
130+
String uniqueAttributeName = property.translateAttributeName(store.getUniqueAttribute());
131+
JsonNode uniqueNode = rootNode.get(uniqueAttributeName);
131132
if(uniqueNode == null){
132-
throw new IllegalArgumentException(store.getUniqueField() + " is a required field");
133+
throw new IllegalArgumentException(uniqueAttributeName + " is a required field");
133134
}
134135

135136
String dn = createDN(store, uniqueNode.asText());
@@ -351,7 +352,7 @@ private LdapMetadataProperty getLdapMetadataProperty(EntityMetadata md){
351352
* @return a string representation of the DN.
352353
*/
353354
private String createDN(LdapDataStore store, String uniqueValue){
354-
return store.getUniqueField() + "=" + uniqueValue + "," + store.getBaseDN();
355+
return store.getUniqueAttribute() + "=" + uniqueValue + "," + store.getBaseDN();
355356
}
356357

357358
/**

lightblue-ldap-integration-test/src/test/java/com/redhat/lightblue/crud/ldap/ITCaseLdapCRUDController_WithProperties_Test.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,14 @@ public void test2FindCustomerWithProperties() throws Exception{
9494
JsonNode entityData = response.getEntityData();
9595
assertNotNull(entityData);
9696
JSONAssert.assertEquals(
97-
"[{\"id\":\"uid=frodo.baggins," + BASEDB_CUSTOMERS
98-
+ "\",\"firstName\":\"Frodo\",\"lastName\":\"Baggins\",\"cn\":\"Frodo Baggins\",\"interfaces#\":4,\"interfaces\":[\"top\",\"person\",\"organizationalPerson\",\"inetOrgPerson\"]}]",
99-
entityData.toString(), true);
97+
"[{\"id\":\"uid=frodo.baggins," + BASEDB_CUSTOMERS + "\","
98+
+ "\"customerId\":\"frodo.baggins\","
99+
+ "\"firstName\":\"Frodo\","
100+
+ "\"lastName\":\"Baggins\","
101+
+ "\"cn\":\"Frodo Baggins\","
102+
+ "\"interfaces#\":4,"
103+
+ "\"interfaces\":[\"top\",\"person\",\"organizationalPerson\",\"inetOrgPerson\"]}]",
104+
entityData.toString(), true);
100105
}
101106

102107
}

lightblue-ldap-integration-test/src/test/resources/crud/find/customer-find-single.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"entityVersion": "1.0.0",
44
"projection": [
55
{"field": "id"},
6+
{"field": "customerId"},
67
{"field": "firstName"},
78
{"field": "lastName"},
89
{"field": "cn"},

lightblue-ldap-integration-test/src/test/resources/crud/insert/customer-insert-single.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
},
77
"data": {
88
"interfaces": ["top", "person", "organizationalPerson", "inetOrgPerson"],
9-
"uid": "frodo.baggins",
9+
"customerId": "frodo.baggins",
1010
"firstName": "Frodo",
1111
"lastName": "Baggins",
1212
"cn": "Frodo Baggins"

lightblue-ldap-integration-test/src/test/resources/metadata/customer-metadata.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
"field": "id",
1414
"attribute": "dn"
1515
},
16+
{
17+
"field": "customerId",
18+
"attribute": "uid"
19+
},
1620
{
1721
"field": "firstName",
1822
"attribute": "givenName"
@@ -44,7 +48,7 @@
4448
"find": ["anyone"]
4549
},
4650
"fields": {
47-
"uid": {"type": "string"},
51+
"customerId": {"type": "string"},
4852
"firstName": {"type": "string"},
4953
"lastName": {"type": "string"},
5054
"cn": {"type": "string"}

lightblue-ldap-metadata/src/main/java/com/redhat/lightblue/metadata/ldap/parser/LdapDataStoreParser.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public LdapDataStore parse(String name, MetadataParser<T> p, T node) {
4646
LdapDataStore dataStore = new LdapDataStore();
4747
dataStore.setDatabase(p.getRequiredStringProperty(node, DATABASE));
4848
dataStore.setBaseDN(p.getRequiredStringProperty(node, BASEDN));
49-
dataStore.setUniqueField(p.getRequiredStringProperty(node, UNIQUE_FIELD));
49+
dataStore.setUniqueAttribute(p.getRequiredStringProperty(node, UNIQUE_FIELD));
5050

5151
return dataStore;
5252
}
@@ -60,7 +60,7 @@ public void convert(MetadataParser<T> p, T emptyNode, DataStore store) {
6060
LdapDataStore ds = (LdapDataStore) store;
6161
p.putString(emptyNode, DATABASE, ds.getDatabase());
6262
p.putString(emptyNode, BASEDN, ds.getBaseDN());
63-
p.putString(emptyNode, UNIQUE_FIELD, ds.getUniqueField());
63+
p.putString(emptyNode, UNIQUE_FIELD, ds.getUniqueAttribute());
6464
}
6565

6666
@Override

lightblue-ldap-metadata/src/test/java/com/redhat/lightblue/metadata/ldap/parser/LdapDataStoreParserTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public void testParse() throws IOException{
6767
assertNotNull(store);
6868
assertEquals(DATABASE, store.getDatabase());
6969
assertEquals(BASE_DN, store.getBaseDN());
70-
assertEquals(UNIQUE_ATTRIBUTE, store.getUniqueField());
70+
assertEquals(UNIQUE_ATTRIBUTE, store.getUniqueAttribute());
7171
}
7272

7373
@Test
@@ -83,7 +83,7 @@ public void testConvert() throws IOException, JSONException{
8383
LdapDataStore store = new LdapDataStore();
8484
store.setDatabase(DATABASE);
8585
store.setBaseDN(BASE_DN);
86-
store.setUniqueField(UNIQUE_ATTRIBUTE);
86+
store.setUniqueAttribute(UNIQUE_ATTRIBUTE);
8787

8888
JsonNode node = json("{}");
8989

0 commit comments

Comments
 (0)