use of org.activityinfo.shared.command.CreateLocation in project activityinfo by bedatadriven.
the class ImporterWizard method submitSites.
private void submitSites(List<LocationDTO> results, final AsyncCallback<Void> callback) {
int numColums = model.getData().getNumColumns();
ColumnBinding[] bindings = bindingsArray();
KeyGenerator keyGenerator = new KeyGenerator();
// do a first pass to match the location
List<Command> siteBatch = Lists.newArrayList();
int rowIndex = 0;
for (ImportRowModel row : model.getData().getRowStore().getModels()) {
LocationDTO location = results.get(rowIndex);
if (location.isNew()) {
siteBatch.add(new CreateLocation(location));
}
SiteDTO site = new SiteDTO();
site.setId(keyGenerator.generateInt());
site.setReportingPeriodId(keyGenerator.generateInt());
site.setActivityId(model.getActivity().getId());
site.setLocationId(location.getId());
site.setPartner(model.getActivity().getDatabase().getPartners().get(0));
for (int i = 0; i != numColums; ++i) {
bindings[i].bindSite(row.get(i), site);
}
siteBatch.add(new CreateSite(site));
rowIndex++;
}
dispatcher.execute(new BatchCommand(siteBatch), new AsyncCallback<BatchResult>() {
@Override
public void onFailure(Throwable caught) {
MessageBox.alert("Import failed", "Exception: " + caught.getMessage(), null);
callback.onFailure(null);
}
@Override
public void onSuccess(BatchResult result) {
MessageBox.alert("Import succeeded!", "Refresh the data grid to see your new sites", null);
callback.onSuccess(null);
}
});
}
use of org.activityinfo.shared.command.CreateLocation in project activityinfo by bedatadriven.
the class BoundLocationSection method save.
@Override
public void save(final AsyncCallback<Void> callback) {
if (isDirty()) {
newLocation();
dispatcher.execute(new CreateLocation(location), new AsyncCallback<VoidResult>() {
@Override
public void onFailure(Throwable caught) {
callback.onFailure(caught);
}
@Override
public void onSuccess(VoidResult result) {
callback.onSuccess(null);
}
});
} else {
callback.onSuccess(null);
}
}
use of org.activityinfo.shared.command.CreateLocation in project activityinfo by bedatadriven.
the class CreateSiteTest method test.
@Test
public void test() throws CommandException {
LocationDTO location = LocationDTOs.newLocation();
execute(new CreateLocation(location));
SiteDTO newSite = SiteDTOs.newSite();
newSite.setLocation(location);
CreateSite cmd = new CreateSite(newSite);
setUser(1);
CreateResult result = execute(cmd);
newSite.setId(result.getNewId());
assertThat(result.getNewId(), not(equalTo(0)));
PagingLoadResult<SiteDTO> loadResult = execute(GetSites.byId(newSite.getId()));
Assert.assertEquals(1, loadResult.getData().size());
SiteDTO secondRead = loadResult.getData().get(0);
SiteDTOs.validateNewSite(secondRead);
}
use of org.activityinfo.shared.command.CreateLocation in project activityinfo by bedatadriven.
the class FormSubmissionResource method createCreateLocationCommand.
private CreateLocation createCreateLocationCommand(SiteFormData data, SchemaDTO schemaDTO, ActivityDTO activity) {
// create the dto
LocationDTO loc = new LocationDTO();
loc.setId(new KeyGenerator().generateInt());
loc.setLocationTypeId(activity.getLocationTypeId());
loc.setName(data.getLocationname());
loc.setLatitude(data.getLatitude());
loc.setLongitude(data.getLongitude());
CreateLocation cmd = new CreateLocation(loc);
// get adminentities that contain the specified coordinates
List<AdminEntity> adminentities = geocoder.geocode(data.getLatitude(), data.getLongitude());
if (adminentities.isEmpty()) {
AdminEntity adminEntity = createDebugAdminEntity();
if (adminEntity != null) {
adminentities.add(adminEntity);
}
}
if (!adminentities.isEmpty()) {
RpcMap map = cmd.getProperties();
for (AdminEntity entity : adminentities) {
map.put(AdminLevelDTO.getPropertyName(entity.getLevel().getId()), entity.getId());
}
}
return cmd;
}
use of org.activityinfo.shared.command.CreateLocation in project activityinfo by bedatadriven.
the class LocalSiteCreateTest method createNew.
@Test
@OnDataSet("/dbunit/sites-simple1.db.xml")
public void createNew() throws CommandException {
synchronizeFirstTime();
// create a new detached, client model
SiteDTO newSite = SiteDTOs.newSite();
LocationDTO location = LocationDTOs.newLocation();
executeLocally(new CreateLocation(location));
newSite.setLocation(location);
// create command
CreateSite cmd = new CreateSite(newSite);
// execute the command
CreateResult result = executeLocally(cmd);
// let the client know the command has succeeded
newSite.setId(result.getNewId());
// try to retrieve what we've created FROM OUR CLIENT SIDE DATABASE
SiteResult loadResult = executeLocally(GetSites.byId(newSite.getId()));
Assert.assertEquals(1, loadResult.getData().size());
SiteDTO secondRead = loadResult.getData().get(0);
// confirm that the changes are there
SiteDTOs.validateNewSite(secondRead);
newRequest();
// now Sync with the server
synchronize();
// Confirm that paging works client side
GetSites pagingRequest = new GetSites();
pagingRequest.setLimit(1);
loadResult = executeLocally(pagingRequest);
}
Aggregations