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();
}
});
}
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));
}
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)));
}
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();
}
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);
}
Aggregations