@Override public void call() { if (clearAfterCommit()) { self.childCollection.clear(); } if (exceptionsList.isEmpty()) { aggregatedErrorStream.onCompleted(); } else { aggregatedErrorStream.onError(new CompositeException(exceptionsList)); } } });
/** * Commits the changes in the external child resource childCollection. * <p/> * This method returns a observable stream, either its observer's onError will be called with * {@link CompositeException} if some resources failed to commit or onNext will be called if all resources * committed successfully. * * @return the observable stream */ public Observable<List<FluentModelTImpl>> commitAndGetAllAsync() { return commitAsync().collect( new Func0<List<FluentModelTImpl>>() { public List<FluentModelTImpl> call() { return new ArrayList<>(); } }, new Action2<List<FluentModelTImpl>, FluentModelTImpl>() { public void call(List<FluentModelTImpl> state, FluentModelTImpl item) { state.add(item); } }); }
/** * Prepare for inline removal of an external child resource (along with the update of parent resource). * * @param name the name of the external child resource * @param key the key */ protected final void prepareInlineRemove(String name, String key) { FluentModelTImpl childResource = find(key); if (childResource == null || childResource.pendingOperation() == ExternalChildResourceImpl.PendingOperation.ToBeCreated) { throw new IllegalArgumentException("A child resource ('" + childResourceName + "') with name (key) '" + name + " (" + key + ")' not found"); } childResource.setPendingOperation(ExternalChildResourceImpl.PendingOperation.ToBeRemoved); super.prepareForFutureCommitOrPostRun(childResource); }
/** * Prepare for inline definition of a new external child resource (along with the definition or update of parent resource). * * @param name the name of the new external child resource * @param key the key * @return the child resource */ protected final FluentModelTImpl prepareInlineDefine(String name, String key) { if (find(key) != null) { throw new IllegalArgumentException("A child resource ('" + childResourceName + "') with name (key) '" + name + " (" + key + ")' already exists"); } FluentModelTImpl childResource = newChildResource(name); childResource.setPendingOperation(ExternalChildResourceImpl.PendingOperation.ToBeCreated); return super.prepareForFutureCommitOrPostRun(childResource); }
/** * Prepare for inline update of an external child resource (along with the update of parent resource). * * @param name the name of the external child resource * @param key the key * @return the external child resource to be updated */ protected final FluentModelTImpl prepareInlineUpdate(String name, String key) { FluentModelTImpl childResource = find(key); if (childResource == null || childResource.pendingOperation() == ExternalChildResourceImpl.PendingOperation.ToBeCreated) { throw new IllegalArgumentException("A child resource ('" + childResourceName + "') with name (key) '" + name + " (" + key + ")' not found"); } if (childResource.pendingOperation() == ExternalChildResourceImpl.PendingOperation.ToBeRemoved) { throw new IllegalArgumentException("A child resource ('" + childResourceName + "') with name (key) '" + name + " (" + key + ")' is marked for deletion"); } childResource.setPendingOperation(ExternalChildResourceImpl.PendingOperation.ToBeUpdated); return super.prepareForFutureCommitOrPostRun(childResource); }
/** * Prepare the given model of an external child resource for inline removal (along with the definition or update of parent resource). * * @param model the model representing child resource to remove */ protected final void prepareInlineRemove(FluentModelTImpl model) { FluentModelTImpl childResource = find(model.childResourceKey()); if (childResource != null) { throw new IllegalArgumentException(pendingOperationMessage(model.name(), model.childResourceKey())); } model.setPendingOperation(ExternalChildResourceImpl.PendingOperation.ToBeRemoved); this.childCollection.put(model.childResourceKey(), model); super.prepareForFutureCommitOrPostRun(model); }
/** * Prepare the given model of an external child resource for inline update (along with the definition or update of parent resource). * * @param model the model to track update changes * @return the external child resource prepared for update */ protected final FluentModelTImpl prepareInlineUpdate(FluentModelTImpl model) { FluentModelTImpl childResource = find(model.childResourceKey()); if (childResource != null) { throw new IllegalArgumentException(pendingOperationMessage(model.name(), model.childResourceKey())); } model.setPendingOperation(ExternalChildResourceImpl.PendingOperation.ToBeUpdated); this.childCollection.put(model.childResourceKey(), model); return super.prepareForFutureCommitOrPostRun(model); }
/** * Prepare the given model of an external child resource for inline create (along with the definition or update of parent resource). * * @param model the model to track create changes * @return the external child resource prepared for create */ protected final FluentModelTImpl prepareInlineDefine(FluentModelTImpl model) { FluentModelTImpl childResource = find(model.childResourceKey()); if (childResource != null) { throw new IllegalArgumentException(pendingOperationMessage(model.name(), model.childResourceKey())); } model.setPendingOperation(ExternalChildResourceImpl.PendingOperation.ToBeCreated); this.childCollection.put(model.childResourceKey(), model); return super.prepareForFutureCommitOrPostRun(model); }