use of org.activityinfo.promise.Promise in project activityinfo by bedatadriven.
the class UpdateMonthlyReportsAsync method queryPeriodMap.
private Promise<Map<Month, Integer>> queryPeriodMap(UpdateMonthlyReports command, ExecutionContext context) {
final Promise<Map<Month, Integer>> promise = new Promise<>();
SqlQuery.select("reportingPeriodId", "Date2").from(Tables.REPORTING_PERIOD, "rp").where("siteId").equalTo(command.getSiteId()).execute(context.getTransaction(), new SqlResultCallback() {
@Override
public void onSuccess(SqlTransaction tx, SqlResultSet results) {
Map<Month, Integer> periodMap = Maps.newHashMap();
for (SqlResultSetRow row : results.getRows()) {
Date endDate = row.getDate("Date2");
Month month = Month.of(endDate);
periodMap.put(month, row.getInt("reportingPeriodId"));
}
promise.resolve(periodMap);
}
});
return promise;
}
use of org.activityinfo.promise.Promise in project activityinfo by bedatadriven.
the class UpdateMonthlyReportsAsync method executeUpdate.
private Promise<Void> executeUpdate(SqlTransaction tx, SqlUpdate update) {
final Promise<Void> promise = new Promise<>();
update.execute(tx, new SqlResultCallback() {
@Override
public void onSuccess(SqlTransaction tx, SqlResultSet results) {
promise.resolve(null);
}
});
return promise;
}
use of org.activityinfo.promise.Promise in project activityinfo by bedatadriven.
the class FormWidgetCreator method createWidgets.
public Promise<Void> createWidgets(final FormClass formClass, final FieldUpdated fieldUpdated) {
List<Promise<Void>> promises = Lists.newArrayList();
for (final FormField field : formClass.getFields()) {
if (field.getType() instanceof SubFormReferenceType) {
FormClass subForm = model.getSubFormByOwnerFieldId(field.getId());
if (subForm.getSubFormKind() != SubFormKind.REPEATING) {
// for repeating we create it internally in sub SimpleFormPanel
Promise<Void> subFormWidgetsPromise = createWidgets(subForm, fieldUpdated);
promises.add(subFormWidgetsPromise);
}
} else {
Promise<Void> promise = widgetFactory.createWidget(formClass, field, new FieldUpdater<FieldValue>() {
@Override
public void onInvalid(String errorMessage) {
containers.get(field.getId()).setInvalid(errorMessage);
}
@Override
public void update(FieldValue value) {
containers.get(field.getId()).setValid();
fieldUpdated.onFieldUpdated(field, value);
}
}).then(new Function<FormFieldWidget, Void>() {
@Override
public Void apply(FormFieldWidget widget) {
FieldContainer fieldContainer = containerFactory.createContainer(field, widget, 4);
containers.put(field.getId(), fieldContainer);
model.addContainerOfClass(formClass.getId(), fieldContainer);
return null;
}
});
promises.add(promise);
}
}
return Promise.waitAll(promises);
}
use of org.activityinfo.promise.Promise in project activityinfo by bedatadriven.
the class FormActions method save.
public Promise<List<FormInstance>> save() {
model.getEventBus().fireEvent(new BeforeSaveEvent());
final List<FormInstance> instancesToPersist = getInstancesToPersist();
Promise<Void> persist = locator.persist(instancesToPersist);
Promise<Void> remove = remove();
final Promise<List<FormInstance>> result = new Promise<>();
Promise.waitAll(persist, remove).then(new AsyncCallback<Void>() {
@Override
public void onFailure(Throwable caught) {
result.onFailure(caught);
}
@Override
public void onSuccess(Void input) {
model.getChangedInstances().clear();
result.onSuccess(instancesToPersist);
}
});
return result;
}
use of org.activityinfo.promise.Promise in project activityinfo by bedatadriven.
the class FormActions method remove.
private Promise<Void> remove() {
Promise<Void> remove = Promise.done();
if (!model.getPersistedInstanceToRemoveByLocator().isEmpty()) {
List<Promise<Void>> removePromises = Lists.newArrayList();
for (FormInstance instance : model.getPersistedInstanceToRemoveByLocator()) {
removePromises.add(locator.remove(instance.getFormId(), instance.getId()));
}
remove = Promise.waitAll(removePromises);
remove.then(new Function<Void, Object>() {
@Override
public Object apply(Void input) {
model.getPersistedInstanceToRemoveByLocator().clear();
return null;
}
});
}
return remove;
}
Aggregations