use of org.activityinfo.client.local.command.handler.KeyGenerator in project activityinfo by bedatadriven.
the class FormSubmissionResource method createSite.
private void createSite(SiteFormData data, SchemaDTO schemaDTO, ActivityDTO activity) {
final SiteDTO site = new SiteDTO();
site.setId(new KeyGenerator().generateInt());
site.setActivityId(data.getActivity());
if (activity.getReportingFrequency() == ActivityDTO.REPORT_ONCE) {
site.setReportingPeriodId(new KeyGenerator().generateInt());
}
// set activitymodel
if (activity.getReportingFrequency() == ActivityDTO.REPORT_ONCE) {
site.setDate1(data.getDate1());
site.setDate2(data.getDate2());
}
site.setPartner(schemaDTO.getPartnerById(data.getPartner()));
// set comments
site.setComments(data.getComments());
// set attributes
for (FormAttributeGroup formAttributeGroup : data.getAttributegroups()) {
AttributeGroupDTO attributeGroup = activity.getAttributeGroupById(formAttributeGroup.getId());
for (Integer attributeId : attributeGroup.getAttributeIds()) {
site.setAttributeValue(attributeId, formAttributeGroup.isSelected(attributeId));
}
}
// set indicators
if (activity.getReportingFrequency() == ActivityDTO.REPORT_ONCE) {
for (FormIndicator formIndicator : data.getIndicators()) {
site.setIndicatorValue(formIndicator.getId(), formIndicator.getDoubleValue());
}
}
// create command(s)
CreateSite cmd = new CreateSite(site);
cmd.setNestedCommand(createCreateLocationCommand(data, schemaDTO, activity));
// save
CreateResult createResult = dispatcher.execute(cmd);
// create sitehistory entry
siteHistoryProcessor.process(cmd, getUser().getId(), createResult.getNewId());
}
use of org.activityinfo.client.local.command.handler.KeyGenerator in project activityinfo by bedatadriven.
the class CreateSiteTest method testAllAttribsFalse.
@Test
public void testAllAttribsFalse() throws CommandException {
// create a new detached, client model
SiteDTO newSite = new SiteDTO();
newSite.setId(new KeyGenerator().generateInt());
newSite.setActivityId(1);
newSite.setLocationId(1);
newSite.setPartner(new PartnerDTO(1, "Foobar"));
newSite.setDate1((new GregorianCalendar(2008, 12, 1)).getTime());
newSite.setDate2((new GregorianCalendar(2009, 1, 3)).getTime());
newSite.setLocationName("Virunga");
newSite.setAttributeValue(1, false);
newSite.setAttributeValue(2, false);
newSite.setProject(new ProjectDTO(1, "SomeProject"));
// create command
CreateSite cmd = new CreateSite(newSite);
assertThat((Integer) cmd.getProperties().get("locationId"), equalTo(1));
// execute the command
setUser(1);
CreateResult result = execute(cmd);
// let the client know the command has succeeded
newSite.setId(result.getNewId());
// cmd.onCompleted(result);
// try to retrieve what we've created
PagingLoadResult<SiteDTO> loadResult = execute(GetSites.byId(newSite.getId()));
Assert.assertEquals(1, loadResult.getData().size());
SiteDTO secondRead = loadResult.getData().get(0);
// confirm that the changes are there
Assert.assertEquals("site.attribute[2]", false, secondRead.getAttributeValue(1));
Assert.assertEquals("site.attribute[2]", false, secondRead.getAttributeValue(2));
}
use of org.activityinfo.client.local.command.handler.KeyGenerator in project activityinfo by bedatadriven.
the class SiteDTOs method newSite.
public static SiteDTO newSite() {
SiteDTO newSite = new SiteDTO();
newSite.setId(new KeyGenerator().generateInt());
newSite.setActivityId(1);
newSite.setLocationId(1);
newSite.setPartner(new PartnerDTO(1, "Foobar"));
newSite.setReportingPeriodId(new KeyGenerator().generateInt());
newSite.setDate1((new GregorianCalendar(2008, 12, 1)).getTime());
newSite.setDate2((new GregorianCalendar(2009, 1, 3)).getTime());
newSite.setIndicatorValue(1, 996.0);
newSite.setIndicatorValue(2, null);
newSite.setAttributeValue(1, true);
newSite.setAttributeValue(2, false);
newSite.setComments("huba huba");
newSite.setProject(new ProjectDTO(1, "WoeiProject"));
return newSite;
}
use of org.activityinfo.client.local.command.handler.KeyGenerator in project activityinfo by bedatadriven.
the class ImporterWizard method finish.
@Override
public void finish(final AsyncCallback<Void> callback) {
final KeyGenerator keyGenerator = new KeyGenerator();
int numColums = model.getData().getNumColumns();
ColumnBinding[] bindings = bindingsArray();
// do a first pass to match the location
List<Command> matchBatch = Lists.newArrayList();
for (ImportRowModel row : model.getData().getRowStore().getModels()) {
MatchLocation location = new MatchLocation();
location.setLocationType(model.getActivity().getLocationTypeId());
for (int i = 0; i != numColums; ++i) {
bindings[i].bindLocation(row.get(i), location);
}
matchBatch.add(location);
}
dispatcher.execute(new BatchCommand(matchBatch), new AsyncCallback<BatchResult>() {
@Override
public void onFailure(Throwable caught) {
MessageBox.alert("Match locations failed", "Exception", null);
}
@Override
public void onSuccess(BatchResult result) {
submitSites((List) result.getResults(), callback);
}
});
}
use of org.activityinfo.client.local.command.handler.KeyGenerator in project activityinfo by bedatadriven.
the class SiteDialog method saveNewSite.
private void saveNewSite() {
final SiteDTO newSite = new SiteDTO();
newSite.setId(new KeyGenerator().generateInt());
newSite.setActivityId(activity.getId());
if (activity.getReportingFrequency() == ActivityDTO.REPORT_ONCE) {
newSite.setReportingPeriodId(new KeyGenerator().generateInt());
}
updateModel(newSite);
dispatcher.execute(new CreateSite(newSite), new AsyncCallback<CreateResult>() {
@Override
public void onFailure(Throwable caught) {
showError(caught);
}
@Override
public void onSuccess(CreateResult result) {
hide();
callback.onSaved(newSite);
}
});
}
Aggregations