Search in sources :

Example 36 with CreateResult

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

the class CloneDatabaseTest method fullClone.

@Test
public void fullClone() throws CommandException {
    SchemaDTO schema = execute(new GetSchema());
    UserDatabaseDTO pearDb = schema.getDatabaseById(PEAR_DATABASE_ID);
    CloneDatabase cloneDatabase = new CloneDatabase().setSourceDatabaseId(pearDb.getId()).setCopyData(true).setCopyPartners(true).setCopyUserPermissions(true).setCountryId(pearDb.getCountry().getId()).setName("PearClone").setDescription("PearClone Description");
    CreateResult cloneResult = execute(cloneDatabase);
    assertNotEquals(cloneResult.getNewId(), pearDb.getId());
    assertDbCloned(cloneResult.getNewId(), pearDb.getId(), cloneDatabase);
// todo assert data copy
}
Also used : CreateResult(org.activityinfo.legacy.shared.command.result.CreateResult) GetSchema(org.activityinfo.legacy.shared.command.GetSchema) CloneDatabase(org.activityinfo.legacy.shared.command.CloneDatabase) Test(org.junit.Test)

Example 37 with CreateResult

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

the class CreateDatabaseTest method createWithSpecificCountry.

@Test
@OnDataSet("/dbunit/multicountry.db.xml")
public void createWithSpecificCountry() throws CommandException {
    UserDatabaseDTO db = new UserDatabaseDTO();
    db.setName("Warchild Haiti");
    db.setFullName("Warchild Haiti");
    setUser(1);
    CreateEntity cmd = new CreateEntity(db);
    cmd.getProperties().put("countryId", 2);
    CreateResult cr = execute(cmd);
    SchemaDTO schema = execute(new GetSchema());
    UserDatabaseDTO newdb = schema.getDatabaseById(cr.getNewId());
    assertNotNull(newdb);
    assertThat(newdb.getCountry(), is(notNullValue()));
    assertThat(newdb.getCountry().getName(), is(equalTo("Haiti")));
}
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 38 with CreateResult

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

the class CreateSiteTest method testAdminBoundCreate.

@Test
@Ignore("WIP")
public void testAdminBoundCreate() throws CommandException {
    // create a new detached, client model
    SiteDTO newSite = new SiteDTO();
    newSite.setActivityId(4);
    newSite.setPartner(new PartnerDTO(1, "Foobar"));
    newSite.setDate1((new GregorianCalendar(2008, 12, 1)).getTime());
    newSite.setDate2((new GregorianCalendar(2009, 1, 3)).getTime());
    newSite.setAdminEntity(1, new AdminEntityDTO(1, 2, "Sud Kivu"));
    newSite.setAdminEntity(2, new AdminEntityDTO(2, 11, "Walungu"));
    newSite.setAdminEntity(3, null);
    newSite.setX(27.432);
    newSite.setY(1.23);
    newSite.setComments("huba huba");
    newSite.setProject(new ProjectDTO(1, "SomeProject"));
    // create command
    CreateSite cmd = new CreateSite(newSite);
    // execute the command
    setUser(1);
    newSite.setProject(new ProjectDTO(1, "SomeProject"));
    CreateResult result = execute(cmd);
    newSite.setId(result.getNewId());
    // try to retrieve what we've created
    SiteDTO secondRead = readSite(newSite.getId());
    // confirm that the changes are there
    Assert.assertEquals("site.location.name", "Walungu", secondRead.getLocationName());
}
Also used : CreateResult(org.activityinfo.legacy.shared.command.result.CreateResult) GregorianCalendar(java.util.GregorianCalendar) CreateSite(org.activityinfo.legacy.shared.command.CreateSite) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 39 with CreateResult

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

the class GetSchemaTest method createFolder.

@Test
@OnDataSet("/dbunit/schema3.db.xml")
public void createFolder() {
    setUser(1);
    CreateResult result = execute(new CreateEntity(new FolderDTO(1, "NFI")));
    SchemaDTO schema = execute(new GetSchema());
    FolderDTO folder = schema.getDatabaseById(1).getFolderById(result.getNewId());
    assertThat(folder.getName(), equalTo("NFI"));
}
Also used : CreateResult(org.activityinfo.legacy.shared.command.result.CreateResult) OnDataSet(org.activityinfo.server.database.OnDataSet) Test(org.junit.Test)

Example 40 with CreateResult

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

the class DbPartnerEditor method showEditDialog.

private void showEditDialog(PartnerDTO partner) {
    PartnerForm form = new PartnerForm(otherPartnerNames(partner));
    form.getBinding().bind(partner);
    FormDialogImpl<PartnerForm> dlg = new FormDialogImpl<>(form);
    dlg.setWidth(450);
    dlg.setHeight(300);
    dlg.setHeadingText(I18N.CONSTANTS.newPartner());
    dlg.show(new FormDialogCallback() {

        @Override
        public void onValidated(FormDialogTether dlg) {
            dispatcher.execute(new UpdatePartner(db.getId(), partner), dlg, new AsyncCallback<CreateResult>() {

                @Override
                public void onFailure(Throwable caught) {
                    Log.debug("DbPartnerEditor caught exception while executing command AddPartner: ", caught);
                }

                @Override
                public void onSuccess(CreateResult result) {
                    if (result instanceof DuplicateCreateResult) {
                        LOGGER.fine("DbPartnerEditor tried to add partner '" + partner.getName() + "' to database " + db.getId() + " but it already exists");
                        MessageBox.alert(I18N.CONSTANTS.newPartner(), I18N.CONSTANTS.duplicatePartner(), null);
                    } else {
                        LOGGER.fine("DbPartnerEditor added/updated new partner '" + partner.getName() + "' to database " + db.getId());
                        eventBus.fireEvent(AppEvents.SCHEMA_CHANGED);
                        dlg.hide();
                        updateStore(partner, result);
                    }
                }
            });
        }
    });
}
Also used : PartnerForm(org.activityinfo.ui.client.page.config.form.PartnerForm) DuplicateCreateResult(org.activityinfo.legacy.shared.command.result.DuplicateCreateResult) FormDialogImpl(org.activityinfo.ui.client.page.common.dialog.FormDialogImpl) FormDialogCallback(org.activityinfo.ui.client.page.common.dialog.FormDialogCallback) DuplicateCreateResult(org.activityinfo.legacy.shared.command.result.DuplicateCreateResult) CreateResult(org.activityinfo.legacy.shared.command.result.CreateResult) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) FormDialogTether(org.activityinfo.ui.client.page.common.dialog.FormDialogTether) UpdatePartner(org.activityinfo.legacy.shared.command.UpdatePartner)

Aggregations

CreateResult (org.activityinfo.legacy.shared.command.result.CreateResult)46 Test (org.junit.Test)26 Date (java.util.Date)9 GetSchema (org.activityinfo.legacy.shared.command.GetSchema)7 UpdatePartner (org.activityinfo.legacy.shared.command.UpdatePartner)7 DuplicateCreateResult (org.activityinfo.legacy.shared.command.result.DuplicateCreateResult)7 OnDataSet (org.activityinfo.server.database.OnDataSet)6 CreateSite (org.activityinfo.legacy.shared.command.CreateSite)5 PartnerDTO (org.activityinfo.legacy.shared.model.PartnerDTO)5 CreateEntity (org.activityinfo.legacy.shared.command.CreateEntity)4 SchemaDTO (org.activityinfo.legacy.shared.model.SchemaDTO)4 TargetDTO (org.activityinfo.legacy.shared.model.TargetDTO)4 CuidAdapter.activityFormClass (org.activityinfo.model.legacy.CuidAdapter.activityFormClass)4 ResourceId (org.activityinfo.model.resource.ResourceId)4 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)3 GregorianCalendar (java.util.GregorianCalendar)3 CloneDatabase (org.activityinfo.legacy.shared.command.CloneDatabase)3 ProjectDTO (org.activityinfo.legacy.shared.model.ProjectDTO)3 SiteDTO (org.activityinfo.legacy.shared.model.SiteDTO)3 EnumItem (org.activityinfo.model.type.enumerated.EnumItem)3