use of org.activityinfo.shared.command.CreateEntity in project activityinfo by bedatadriven.
the class DbListPresenter method save.
/**
* Package visible for testing *
*/
void save(UserDatabaseDTO db, final FormDialogTether dialog) {
Map<String, Object> properties = new HashMap<String, Object>();
properties.put("name", db.getName());
properties.put("fullName", db.getFullName());
properties.put("countryId", db.getCountry().getId());
dispatcher.execute(new CreateEntity("UserDatabase", properties), dialog, new Created() {
@Override
public void created(int newId) {
eventBus.fireEvent(AppEvents.SCHEMA_CHANGED);
loader.load();
dialog.hide();
}
});
}
use of org.activityinfo.shared.command.CreateEntity in project activityinfo by bedatadriven.
the class DbListPresenterTest method commandShouldBePreparedProperly.
@Test
public void commandShouldBePreparedProperly() {
Capture<CreateEntity> cmd = new Capture<CreateEntity>();
expectDispatch(new GetSchema(), schema);
captureDispatch(cmd);
replay(dispatcher);
UserDatabaseDTO newDb = new UserDatabaseDTO();
newDb.setCountry(new CountryDTO(31, "Haiti"));
newDb.setName("My Db");
createPresenter();
presenter.save(newDb, niceFormDialogMock());
assertTrue("command was dispatched", cmd.hasCaptured());
assertThat((Integer) cmd.getValue().getProperties().get("countryId"), is(equalTo(31)));
}
use of org.activityinfo.shared.command.CreateEntity in project activityinfo by bedatadriven.
the class CreateDatabaseTest method testCreate.
@Test
@OnDataSet("/dbunit/sites-simple1.db.xml")
public void testCreate() throws CommandException {
UserDatabaseDTO db = new UserDatabaseDTO();
db.setName("RIMS");
db.setFullName("Reintegration Management Information System");
CreateResult cr = execute(new CreateEntity(db));
SchemaDTO schema = execute(new GetSchema());
UserDatabaseDTO newdb = schema.getDatabaseById(cr.getNewId());
assertNotNull(newdb);
assertEquals(db.getName(), newdb.getName());
assertEquals(db.getFullName(), newdb.getFullName());
assertNotNull(newdb.getCountry());
assertEquals("Alex", newdb.getOwnerName());
}
use of org.activityinfo.shared.command.CreateEntity in project activityinfo by bedatadriven.
the class LocalSchemaChangeTest method createIndicator.
@Test
public void createIndicator() {
synchronizeFirstTime();
SchemaDTO schema = executeLocally(new GetSchema());
Map<String, Object> indicator = Maps.newHashMap();
indicator.put("name", "New Indicator");
indicator.put("units", "bricks");
indicator.put("activityId", 2);
CreateResult createResult = executeRemotely(new CreateEntity("Indicator", indicator));
synchronize();
schema = executeLocally(new GetSchema());
IndicatorDTO createdIndicator = schema.getIndicatorById(createResult.getNewId());
assertThat(createdIndicator, is(not(nullValue())));
assertThat(createdIndicator.getName(), equalTo("New Indicator"));
}
use of org.activityinfo.shared.command.CreateEntity in project activityinfo by bedatadriven.
the class DesignPresenter method createEntity.
private void createEntity(final ModelData parent, final EntityDTO newEntity) {
view.showNewForm(newEntity, new FormDialogCallback() {
@Override
public void onValidated(final FormDialogTether tether) {
service.execute(new CreateEntity(newEntity), tether, new AsyncCallback<CreateResult>() {
@Override
public void onFailure(Throwable caught) {
GWT.log(caught.getMessage());
}
@Override
public void onSuccess(CreateResult result) {
// todo add
newEntity.set("id", result.getNewId());
if (parent == null) {
treeStore.add(newEntity, false);
} else {
treeStore.add(parent, newEntity, false);
}
if (newEntity instanceof ActivityDTO) {
treeStore.add(newEntity, new AttributeGroupFolder(messages.attributes()), false);
treeStore.add(newEntity, new IndicatorFolder(messages.indicators()), false);
}
tether.hide();
eventBus.fireEvent(AppEvents.SCHEMA_CHANGED);
}
});
}
});
}
Aggregations