Changeset 794:ff94810e0e84
- Timestamp:
- 01/19/12 18:12:11 (4 months ago)
- Branch:
- default
- Location:
- kraken-dom/src/main/java/org/krakenapps/dom/api/impl
- Files:
-
- 3 edited
-
ConfigManagerImpl.java (modified) (4 diffs)
-
OrganizationUnitApiImpl.java (modified) (2 diffs)
-
UserApiImpl.java (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
kraken-dom/src/main/java/org/krakenapps/dom/api/impl/ConfigManagerImpl.java
r784 r794 17 17 import org.krakenapps.confdb.Config; 18 18 import org.krakenapps.confdb.ConfigDatabase; 19 import org.krakenapps.confdb.ConfigIterator; 19 20 import org.krakenapps.confdb.ConfigService; 20 21 import org.krakenapps.confdb.ConfigTransaction; … … 100 101 101 102 ConfigDatabase db = getDatabase(domain); 103 104 Predicate pred = Predicates.or(preds.toArray(new Predicate[0])); 105 if (db.findOne(cls, pred) != null) 106 throw new DOMException(alreadyExistMessage); 107 102 108 ConfigTransaction xact = db.beginTransaction(); 103 104 Iterator<Predicate> predIterator = preds.iterator();105 109 Iterator<T> docIterator = docs.iterator(); 106 110 try { 107 while (docIterator.hasNext()) { 108 Predicate pred = predIterator.next(); 109 T doc = docIterator.next(); 110 111 if (db.findOne(cls, pred) != null) 112 throw new DOMException(alreadyExistMessage); 113 114 db.add(xact, doc); 115 } 116 111 while (docIterator.hasNext()) 112 db.add(xact, docIterator.next()); 117 113 xact.commit(COMMITER, "added " + docs.size() + " " + cls.getSimpleName() + "(s)"); 118 114 } catch (Throwable e) { 119 115 xact.rollback(); 120 if (e instanceof DOMException)121 throw (DOMException) e;122 116 throw new RuntimeException(e); 123 117 } … … 162 156 163 157 ConfigDatabase db = getDatabase(domain); 158 159 Predicate pred = Predicates.or(preds.toArray(new Predicate[0])); 160 if (db.findOne(cls, pred) == null) 161 throw new DOMException(notFoundMessage); 162 164 163 ConfigTransaction xact = db.beginTransaction(); 165 166 Iterator<Predicate> predIterator = preds.iterator();167 164 Iterator<T> docIterator = docs.iterator(); 168 165 try { 169 166 while (docIterator.hasNext()) { 170 Predicate pred = predIterator.next();171 T doc = docIterator.next();172 173 167 Config c = db.findOne(cls, pred); 174 if (c == null) 175 throw new DOMException(notFoundMessage); 176 177 db.update(xact, c, doc, CHECK_CONFLICT); 168 db.update(xact, c, docIterator.next(), CHECK_CONFLICT); 178 169 } 179 170 … … 221 212 222 213 ConfigDatabase db = getDatabase(domain); 214 215 Predicate pred = Predicates.or(preds.toArray(new Predicate[0])); 216 if (db.findOne(cls, pred) == null) 217 throw new DOMException(notFoundMessage); 218 223 219 ConfigTransaction xact = db.beginTransaction(); 224 225 Iterator<Predicate> predIterator = preds.iterator();226 220 Collection<T> docs = new ArrayList<T>(); 227 221 try { 228 while (predIterator.hasNext()) { 229 Predicate pred = predIterator.next(); 230 231 Config c = db.findOne(cls, pred); 232 if (c == null) 233 throw new DOMException(notFoundMessage); 234 222 ConfigIterator it = db.find(cls, pred); 223 while (it.hasNext()) { 224 Config c = it.next(); 235 225 T doc = c.getDocument(cls, getCallback(domain)); 236 226 if (provider != null) -
kraken-dom/src/main/java/org/krakenapps/dom/api/impl/OrganizationUnitApiImpl.java
r750 r794 142 142 143 143 @Override 144 public void removeOrganizationUnits(String domain, Collection<String> guids, boolean removeUser) {144 public void removeOrganizationUnits(String domain, Collection<String> guids, boolean moveUser) { 145 145 Set<String> orgUnitGuids = new HashSet<String>(); 146 146 List<Predicate> preds = new ArrayList<Predicate>(); … … 155 155 } 156 156 157 cfg.removes(domain, cls, preds, NOT_FOUND, this, removeUser, null);157 cfg.removes(domain, cls, preds, NOT_FOUND, this, moveUser, null); 158 158 } 159 159 160 160 @Override 161 public void removeOrganizationUnit(String domain, String guid, boolean removeUser) {161 public void removeOrganizationUnit(String domain, String guid, boolean moveUser) { 162 162 List<OrganizationUnit> orgUnits = getOrganizationUnitTree(getOrganizationUnit(domain, guid)); 163 cfg.removes(domain, cls, getPreds(orgUnits), NOT_FOUND, this, removeUser, null);163 cfg.removes(domain, cls, getPreds(orgUnits), NOT_FOUND, this, moveUser, null); 164 164 } 165 165 -
kraken-dom/src/main/java/org/krakenapps/dom/api/impl/UserApiImpl.java
r750 r794 30 30 import org.apache.felix.ipojo.annotations.Validate; 31 31 import org.krakenapps.confdb.Config; 32 import org.krakenapps.confdb.ConfigIterator; 32 33 import org.krakenapps.confdb.ConfigTransaction; 33 34 import org.krakenapps.confdb.Predicate; … … 264 265 @Override 265 266 public void entityRemoving(String domain, OrganizationUnit orgUnit, ConfigTransaction xact, Object state) { 266 boolean remove = (state != null) && (state instanceof Boolean) && ((Boolean) state); 267 268 for (User user : getUsers(domain, orgUnit.getGuid(), false)) { 269 Config c = xact.getDatabase().findOne(cls, getPred(user.getLoginName())); 270 271 if (remove) { 272 xact.getDatabase().remove(xact, c, true); 273 } else { 267 boolean move = (state != null) && (state instanceof Boolean) && ((Boolean) state); 268 269 List<Predicate> preds = new ArrayList<Predicate>(); 270 for (User user : getUsers(domain, orgUnit.getGuid(), false)) 271 preds.add(getPred(user.getLoginName())); 272 273 ConfigIterator it = xact.getDatabase().find(cls, Predicates.or(preds.toArray(new Predicate[0]))); 274 while (it.hasNext()) { 275 Config c = it.next(); 276 User user = c.getDocument(User.class); 277 278 if (move) { 274 279 user.setOrgUnit(null); 275 280 xact.getDatabase().update(xact, c, user, true); 281 } else { 282 xact.getDatabase().remove(xact, c, true); 276 283 } 277 284 }
Note: See TracChangeset
for help on using the changeset viewer.
