use of org.activityinfo.legacy.shared.command.result.CreateResult in project activityinfo by bedatadriven.
the class LockedPeriodTest method createTest.
@Test
public void createTest() throws CommandException {
setUser(1);
LockedPeriodDTO dto = new LockedPeriodDTO();
dto.setName("my name");
dto.setFromDate(new LocalDate(2011, 1, 1));
dto.setToDate(new LocalDate(2011, 1, 31));
dto.setEnabled(true);
CreateLockedPeriod create = new CreateLockedPeriod(dto);
create.setDatabaseId(1);
CreateResult result = execute(create);
Map<String, Object> changes = Maps.newHashMap();
changes.put("toDate", new LocalDate(2011, 2, 28));
execute(new UpdateEntity("LockedPeriod", result.getNewId(), changes));
}
use of org.activityinfo.legacy.shared.command.result.CreateResult in project activityinfo by bedatadriven.
the class PartnerTest method testAddPartner.
@Test
public void testAddPartner() {
PartnerDTO newPartner = new PartnerDTO();
newPartner.setName("Solidarites");
CreateResult cr = execute(new UpdatePartner(PEAR_PLUS_DB_ID, newPartner));
assertThat(cr.getNewId(), not(equalTo(SOL_ID)));
SchemaDTO schema = execute(new GetSchema());
PartnerDTO partner = schema.getDatabaseById(PEAR_PLUS_DB_ID).getPartnerById(cr.getNewId());
Assert.assertNotNull(partner);
Assert.assertEquals(newPartner.getName(), partner.getName());
}
use of org.activityinfo.legacy.shared.command.result.CreateResult in project activityinfo by bedatadriven.
the class CreateSiteHandlerAsync method updateExistingSite.
private void updateExistingSite(final CreateSite cmd, ExecutionContext context, final AsyncCallback<CreateResult> callback) {
UpdateSite updateSite = new UpdateSite(cmd.getSiteId(), cmd.getProperties());
context.execute(updateSite, new AsyncCallback<VoidResult>() {
@Override
public void onFailure(Throwable caught) {
callback.onFailure(caught);
}
@Override
public void onSuccess(VoidResult result) {
callback.onSuccess(new CreateResult(cmd.getSiteId()));
}
});
}
use of org.activityinfo.legacy.shared.command.result.CreateResult in project activityinfo by bedatadriven.
the class DatabaseResource method createFormFromXForm.
@POST
@Path("/forms")
@Consumes("application/xml")
public Response createFormFromXForm(@Context UriInfo uri, XForm xForm) {
UserDatabaseDTOWithForms schema = getSchema();
LocationTypeDTO locationType = schema.getCountry().getNullLocationType();
ActivityFormDTO activityDTO = new ActivityFormDTO();
activityDTO.setName(xForm.getHead().getTitle());
activityDTO.set("databaseId", databaseId);
activityDTO.set("locationTypeId", locationType.getId());
CreateResult createResult = dispatcher.execute(new CreateEntity(activityDTO));
int activityId = createResult.getNewId();
XFormReader builder = new XFormReader(xForm);
FormClass formClass = builder.build();
formClass.setId(CuidAdapter.activityFormClass(activityId));
formClass.setDatabaseId(CuidAdapter.databaseId(databaseId));
MySqlStorageProvider formCatalog = (MySqlStorageProvider) catalog.get();
formCatalog.createOrUpdateFormSchema(formClass);
return Response.created(uri.getAbsolutePathBuilder().path(RootResource.class).path("forms").path(formClass.getId().asString()).build()).build();
}
use of org.activityinfo.legacy.shared.command.result.CreateResult in project activityinfo by bedatadriven.
the class SiteDialog method saveNewSite.
private void saveNewSite() {
final SiteDTO newSite = new SiteDTO();
keyGenerator = new KeyGenerator();
newSite.setId(keyGenerator.generateInt());
newSite.setActivityId(activity.getId());
if (activity.getReportingFrequency() == ActivityFormDTO.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();
}
});
}
Aggregations