Search in sources :

Example 1 with CreateEntity

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();
        }
    });
}
Also used : CreateEntity(org.activityinfo.shared.command.CreateEntity) HashMap(java.util.HashMap) Created(org.activityinfo.client.dispatch.callback.Created)

Example 2 with CreateEntity

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)));
}
Also used : CreateEntity(org.activityinfo.shared.command.CreateEntity) UserDatabaseDTO(org.activityinfo.shared.dto.UserDatabaseDTO) CountryDTO(org.activityinfo.shared.dto.CountryDTO) GetSchema(org.activityinfo.shared.command.GetSchema) Capture(org.easymock.Capture) Test(org.junit.Test)

Example 3 with CreateEntity

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());
}
Also used : CreateEntity(org.activityinfo.shared.command.CreateEntity) CreateResult(org.activityinfo.shared.command.result.CreateResult) UserDatabaseDTO(org.activityinfo.shared.dto.UserDatabaseDTO) SchemaDTO(org.activityinfo.shared.dto.SchemaDTO) GetSchema(org.activityinfo.shared.command.GetSchema) OnDataSet(org.activityinfo.server.database.OnDataSet) Test(org.junit.Test)

Example 4 with CreateEntity

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"));
}
Also used : CreateEntity(org.activityinfo.shared.command.CreateEntity) IndicatorDTO(org.activityinfo.shared.dto.IndicatorDTO) CreateResult(org.activityinfo.shared.command.result.CreateResult) SchemaDTO(org.activityinfo.shared.dto.SchemaDTO) GetSchema(org.activityinfo.shared.command.GetSchema) Test(org.junit.Test)

Example 5 with CreateEntity

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);
                }
            });
        }
    });
}
Also used : CreateEntity(org.activityinfo.shared.command.CreateEntity) FormDialogCallback(org.activityinfo.client.page.common.dialog.FormDialogCallback) CreateResult(org.activityinfo.shared.command.result.CreateResult) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) FormDialogTether(org.activityinfo.client.page.common.dialog.FormDialogTether) ActivityDTO(org.activityinfo.shared.dto.ActivityDTO)

Aggregations

CreateEntity (org.activityinfo.shared.command.CreateEntity)7 GetSchema (org.activityinfo.shared.command.GetSchema)5 CreateResult (org.activityinfo.shared.command.result.CreateResult)5 Test (org.junit.Test)5 SchemaDTO (org.activityinfo.shared.dto.SchemaDTO)4 UserDatabaseDTO (org.activityinfo.shared.dto.UserDatabaseDTO)3 HashMap (java.util.HashMap)2 OnDataSet (org.activityinfo.server.database.OnDataSet)2 ActivityDTO (org.activityinfo.shared.dto.ActivityDTO)2 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)1 Created (org.activityinfo.client.dispatch.callback.Created)1 FormDialogCallback (org.activityinfo.client.page.common.dialog.FormDialogCallback)1 FormDialogTether (org.activityinfo.client.page.common.dialog.FormDialogTether)1 AttributeGroupDTO (org.activityinfo.shared.dto.AttributeGroupDTO)1 CountryDTO (org.activityinfo.shared.dto.CountryDTO)1 IndicatorDTO (org.activityinfo.shared.dto.IndicatorDTO)1 Capture (org.easymock.Capture)1