use of org.activityinfo.client.local.command.handler.KeyGenerator 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.client.local.command.handler.KeyGenerator in project activityinfo by bedatadriven.
the class BoundLocationSection method newLocation.
private void newLocation() {
location = new LocationDTO(location);
location.setId(new KeyGenerator().generateInt());
location.setName(leafComboBox.getValue().getName());
for (AdminLevelDTO level : adminFieldSet.getAdminLevels()) {
location.setAdminEntity(level.getId(), adminFieldSet.getAdminEntity(level));
}
}
use of org.activityinfo.client.local.command.handler.KeyGenerator in project activityinfo by bedatadriven.
the class SiteDialogLauncher method addNewSiteWithBoundLocation.
private void addNewSiteWithBoundLocation(ActivityDTO activity, SiteDialogCallback callback) {
SiteDTO newSite = new SiteDTO();
newSite.setActivityId(activity.getId());
LocationDTO location = new LocationDTO();
location.setId(new KeyGenerator().generateInt());
location.setLocationTypeId(activity.getLocationTypeId());
SiteDialog dialog = new SiteDialog(dispatcher, activity);
dialog.showNew(newSite, location, true, callback);
}
use of org.activityinfo.client.local.command.handler.KeyGenerator in project activityinfo by bedatadriven.
the class LocationForm method saveNewLocation.
private void saveNewLocation() {
if (coordinateFields.validate() && nameField.validate()) {
LocationDTO newLocation = new LocationDTO();
newLocation.setId(new KeyGenerator().generateInt());
newLocation.setLocationTypeId(locationType.getId());
newLocation.setName(nameField.getValue());
newLocation.setAxe(axeField.getValue());
newLocation.setLatitude(coordinateFields.getLatitudeField().getValue());
newLocation.setLongitude(coordinateFields.getLongitudeField().getValue());
for (AdminLevelDTO level : adminPresenter.getAdminLevels()) {
newLocation.setAdminEntity(level.getId(), adminPresenter.getAdminEntity(level));
}
newLocationPresenter.accept(newLocation);
}
}
use of org.activityinfo.client.local.command.handler.KeyGenerator in project activityinfo by bedatadriven.
the class MatchLocationHandler method execute.
@Override
public CommandResult execute(MatchLocation cmd, User user) throws CommandException {
Map<Integer, AdminEntity> matched = Maps.newHashMap();
// now try and match against the text
for (Integer levelId : cmd.getAdminLevels().keySet()) {
matchEntity(matched, cmd.getAdminLevels(), em.find(AdminLevel.class, levelId));
}
Location matchedLocation = matchLocation(cmd.getLocationType(), cmd.getName(), matched.values());
LocationDTO location = new LocationDTO();
if (matchedLocation == null) {
// create a new location object
location.setId(new KeyGenerator().generateInt());
location.setName(cmd.getName());
location.setLatitude(cmd.getLatitude());
location.setLongitude(cmd.getLongitude());
location.setNew(true);
location.setLocationTypeId(cmd.getLocationType());
for (AdminEntity entity : matched.values()) {
AdminEntityDTO dto = new AdminEntityDTO();
dto.setId(entity.getId());
dto.setName(entity.getName());
dto.setLevelId(entity.getLevel().getId());
location.setAdminEntity(entity.getLevel().getId(), dto);
}
} else {
location.setNew(false);
location.setId(matchedLocation.getId());
location.setName(matchedLocation.getName());
location.setLatitude(matchedLocation.getY());
location.setLongitude(matchedLocation.getX());
location.setLocationTypeId(matchedLocation.getLocationType().getId());
for (AdminEntity entity : matchedLocation.getAdminEntities()) {
AdminEntityDTO dto = new AdminEntityDTO();
dto.setId(entity.getId());
dto.setName(entity.getName());
dto.setLevelId(entity.getLevel().getId());
location.setAdminEntity(entity.getLevel().getId(), dto);
}
}
return location;
}
Aggregations