Search in sources :

Example 1 with CreateEntity

use of org.activityinfo.legacy.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.legacy.shared.command.CreateEntity) HashMap(java.util.HashMap) SafeHtmlUtils.fromString(com.google.gwt.safehtml.shared.SafeHtmlUtils.fromString) Created(org.activityinfo.ui.client.dispatch.callback.Created)

Example 2 with CreateEntity

use of org.activityinfo.legacy.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());
    assertThat(newdb.getPartners(), hasSize(1));
}
Also used : CreateEntity(org.activityinfo.legacy.shared.command.CreateEntity) CreateResult(org.activityinfo.legacy.shared.command.result.CreateResult) UserDatabaseDTO(org.activityinfo.legacy.shared.model.UserDatabaseDTO) SchemaDTO(org.activityinfo.legacy.shared.model.SchemaDTO) GetSchema(org.activityinfo.legacy.shared.command.GetSchema) OnDataSet(org.activityinfo.server.database.OnDataSet) Test(org.junit.Test)

Example 3 with CreateEntity

use of org.activityinfo.legacy.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.legacy.shared.command.CreateEntity) UserDatabaseDTO(org.activityinfo.legacy.shared.model.UserDatabaseDTO) CountryDTO(org.activityinfo.legacy.shared.model.CountryDTO) GetSchema(org.activityinfo.legacy.shared.command.GetSchema) Capture(org.easymock.Capture) Test(org.junit.Test)

Example 4 with CreateEntity

use of org.activityinfo.legacy.shared.command.CreateEntity 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();
}
Also used : CreateEntity(org.activityinfo.legacy.shared.command.CreateEntity) CreateResult(org.activityinfo.legacy.shared.command.result.CreateResult) FormClass(org.activityinfo.model.form.FormClass) XFormReader(org.activityinfo.io.xform.XFormReader) MySqlStorageProvider(org.activityinfo.store.mysql.MySqlStorageProvider)

Example 5 with CreateEntity

use of org.activityinfo.legacy.shared.command.CreateEntity in project activityinfo by bedatadriven.

the class SchemaImporterV2Test method doImport.

private UserDatabaseDTO doImport(String resourceName) throws IOException {
    Map<String, Object> dbProps = Maps.newHashMap();
    dbProps.put("name", "Syria");
    dbProps.put("countryId", 1);
    int databaseId = execute(new CreateEntity("UserDatabase", dbProps)).getNewId();
    SchemaDTO schema = execute(new GetSchema());
    UserDatabaseDTO db = schema.getDatabaseById(databaseId);
    if (db == null) {
        throw new AssertionError("database not created");
    }
    SchemaImporterV2 importer = new SchemaImporterV2(getDispatcher(), db, warningTemplates());
    importer.setProgressListener(new SchemaImporterV2.ProgressListener() {

        @Override
        public void submittingBatch(int batchNumber, int batchCount) {
            System.out.println("Submitting batch " + batchNumber + " of " + batchCount);
        }
    });
    boolean success = importer.parseColumns(source(resourceName));
    if (success) {
        importer.processRows();
    }
    for (SafeHtml warning : importer.getWarnings()) {
        System.err.println(warning);
    }
    if (!success) {
        throw new AssertionError("there were fatal errors");
    }
    importer.persist(new AsyncCallback<Void>() {

        @Override
        public void onSuccess(Void result) {
            System.out.println("Success");
        }

        @Override
        public void onFailure(Throwable caught) {
            throw new AssertionError(caught);
        }
    });
    return execute(new GetSchema()).getDatabaseById(databaseId);
}
Also used : CreateEntity(org.activityinfo.legacy.shared.command.CreateEntity) UserDatabaseDTO(org.activityinfo.legacy.shared.model.UserDatabaseDTO) SafeHtml(com.google.gwt.safehtml.shared.SafeHtml) SchemaDTO(org.activityinfo.legacy.shared.model.SchemaDTO) GetSchema(org.activityinfo.legacy.shared.command.GetSchema)

Aggregations

CreateEntity (org.activityinfo.legacy.shared.command.CreateEntity)7 GetSchema (org.activityinfo.legacy.shared.command.GetSchema)4 CreateResult (org.activityinfo.legacy.shared.command.result.CreateResult)4 UserDatabaseDTO (org.activityinfo.legacy.shared.model.UserDatabaseDTO)4 Test (org.junit.Test)4 SchemaDTO (org.activityinfo.legacy.shared.model.SchemaDTO)3 HashMap (java.util.HashMap)2 OnDataSet (org.activityinfo.server.database.OnDataSet)2 SafeHtml (com.google.gwt.safehtml.shared.SafeHtml)1 SafeHtmlUtils.fromString (com.google.gwt.safehtml.shared.SafeHtmlUtils.fromString)1 XFormReader (org.activityinfo.io.xform.XFormReader)1 GetActivityForm (org.activityinfo.legacy.shared.command.GetActivityForm)1 ActivityFormDTO (org.activityinfo.legacy.shared.model.ActivityFormDTO)1 AttributeGroupDTO (org.activityinfo.legacy.shared.model.AttributeGroupDTO)1 CountryDTO (org.activityinfo.legacy.shared.model.CountryDTO)1 FormClass (org.activityinfo.model.form.FormClass)1 MySqlStorageProvider (org.activityinfo.store.mysql.MySqlStorageProvider)1 Created (org.activityinfo.ui.client.dispatch.callback.Created)1 Capture (org.easymock.Capture)1