From 3a66087e65f71effdeb4feef83db4fc6910f550c Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Tue, 9 Sep 2014 14:06:46 +0200 Subject: Support new ItemPath based Item id. NextKeyManager removed. --- .../c2kernel/lookup/ldap/LDAPClusterStorage.java | 80 ++++++++-------------- 1 file changed, 28 insertions(+), 52 deletions(-) (limited to 'src/main/java/com/c2kernel/lookup/ldap/LDAPClusterStorage.java') diff --git a/src/main/java/com/c2kernel/lookup/ldap/LDAPClusterStorage.java b/src/main/java/com/c2kernel/lookup/ldap/LDAPClusterStorage.java index f309378..3de9aad 100644 --- a/src/main/java/com/c2kernel/lookup/ldap/LDAPClusterStorage.java +++ b/src/main/java/com/c2kernel/lookup/ldap/LDAPClusterStorage.java @@ -52,30 +52,23 @@ public class LDAPClusterStorage extends ClusterStorage { // retrieve object by path @Override - public C2KLocalObject get(Integer sysKey, String path) throws ClusterStorageException { - Logger.msg(6, "LDAPClusterStorage.get() - "+sysKey+"/"+path); + public C2KLocalObject get(ItemPath thisItem, String path) throws ClusterStorageException { + Logger.msg(6, "LDAPClusterStorage.get() - "+thisItem+"/"+path); StringTokenizer tok = new StringTokenizer(path, "/"); int pathLength = tok.countTokens(); if (pathLength != 2) throw new ClusterStorageException("Path length was invalid: "+path); String type = tok.nextToken(); - ItemPath thisEntity; - try { - thisEntity = new ItemPath(sysKey.intValue()); - } catch (InvalidItemPathException e) { - throw new ClusterStorageException("Invalid Syskey:"+sysKey); - } - String objName = tok.nextToken(); C2KLocalObject newObj; if (type.equals(PROPERTY)) { try { - Property newProperty = ldapStore.getProperty(thisEntity, objName); + Property newProperty = ldapStore.getProperty(thisItem, objName); newObj = newProperty; } catch (ObjectNotFoundException ex) { - throw new ClusterStorageException("Property "+objName+" not found in "+sysKey); + throw new ClusterStorageException("Property "+objName+" not found in "+thisItem); } } @@ -86,21 +79,14 @@ public class LDAPClusterStorage extends ClusterStorage { } // store object by path @Override - public void put(Integer sysKey, C2KLocalObject obj) throws ClusterStorageException { - Logger.msg(6, "LDAPClusterStorage.put() - "+sysKey+"/"+ClusterStorage.getPath(obj)); + public void put(ItemPath thisItem, C2KLocalObject obj) throws ClusterStorageException { + Logger.msg(6, "LDAPClusterStorage.put() - "+thisItem+"/"+ClusterStorage.getPath(obj)); String type = obj.getClusterType(); - ItemPath thisEntity; - try { - thisEntity = new ItemPath(sysKey.intValue()); - } catch (InvalidItemPathException e) { - throw new ClusterStorageException("Invalid Syskey:"+sysKey); - } - if (type.equals(PROPERTY)) { try { - ldapStore.setProperty(thisEntity, (Property)obj); + ldapStore.setProperty(thisItem, (Property)obj); } catch (Exception e1) { Logger.error(e1); throw new ClusterStorageException("LDAPClusterStorage - could not write property"); @@ -112,23 +98,16 @@ public class LDAPClusterStorage extends ClusterStorage { } // delete cluster @Override - public void delete(Integer sysKey, String path) throws ClusterStorageException { + public void delete(ItemPath thisItem, String path) throws ClusterStorageException { StringTokenizer tok = new StringTokenizer(path, "/"); int pathLength = tok.countTokens(); if (pathLength != 2) throw new ClusterStorageException("Path length was invalid: "+path); String type = tok.nextToken(); - ItemPath thisEntity; - try { - thisEntity = new ItemPath(sysKey.intValue()); - } catch (InvalidItemPathException e) { - throw new ClusterStorageException("Invalid Syskey:"+sysKey); - } - if (type.equals(PROPERTY)) { try { - ldapStore.deleteProperty(thisEntity, tok.nextToken()); + ldapStore.deleteProperty(thisItem, tok.nextToken()); } catch (Exception e1) { Logger.error(e1); throw new ClusterStorageException("LDAPClusterStorage - could not delete property"); @@ -143,34 +122,31 @@ public class LDAPClusterStorage extends ClusterStorage { // directory listing @Override - public String[] getClusterContents(Integer sysKey, String path) throws ClusterStorageException { - Logger.msg(6, "LDAPClusterStorage.getClusterContents() - "+sysKey+"/"+path); + public String[] getClusterContents(ItemPath thisItem, String path) throws ClusterStorageException { + Logger.msg(6, "LDAPClusterStorage.getClusterContents() - "+thisItem+"/"+path); StringTokenizer tok = new StringTokenizer(path, "/"); int pathLength = tok.countTokens(); if (pathLength > 1) return new String[0]; String type = getClusterType(path); - try - { - ItemPath thisEntity = new ItemPath(sysKey.intValue()); - if (type.equals(PROPERTY)) - return ldapStore.getPropertyNames(thisEntity); - else - if (type.equals("")) { // root query - String[] allClusters = new String[0]; - ArrayList clusterList = new ArrayList(); - if (ldapStore.hasProperties(thisEntity)) - clusterList.add(PROPERTY); - allClusters = clusterList.toArray(allClusters); - return allClusters; - } - else - throw new ClusterStorageException("Cluster type "+type+" not supported."); - } catch (InvalidItemPathException e) { - throw new ClusterStorageException("Invalid Syskey:"+sysKey); - } catch (ObjectNotFoundException e) { - throw new ClusterStorageException("Entity "+sysKey+" does not exist"); + + try { + if (type.equals(PROPERTY)) + return ldapStore.getPropertyNames(thisItem); + else + if (type.equals("")) { // root query + String[] allClusters = new String[0]; + ArrayList clusterList = new ArrayList(); + if (ldapStore.hasProperties(thisItem)) + clusterList.add(PROPERTY); + allClusters = clusterList.toArray(allClusters); + return allClusters; + } + else + throw new ClusterStorageException("Cluster type "+type+" not supported."); + } catch (ObjectNotFoundException e) { + throw new ClusterStorageException("Item "+thisItem+" does not exist"); } } } -- cgit v1.2.3