Search in sources :

Example 6 with UpdatePartner

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

the class PartnerTest method testAddPartner.

@Test
public void testAddPartner() {
    PartnerDTO newPartner = new PartnerDTO();
    newPartner.setName("Solidarites");
    CreateResult cr = execute(new UpdatePartner(PEAR_PLUS_DB_ID, newPartner));
    assertThat(cr.getNewId(), not(equalTo(SOL_ID)));
    SchemaDTO schema = execute(new GetSchema());
    PartnerDTO partner = schema.getDatabaseById(PEAR_PLUS_DB_ID).getPartnerById(cr.getNewId());
    Assert.assertNotNull(partner);
    Assert.assertEquals(newPartner.getName(), partner.getName());
}
Also used : PartnerDTO(org.activityinfo.legacy.shared.model.PartnerDTO) CreateResult(org.activityinfo.legacy.shared.command.result.CreateResult) DuplicateCreateResult(org.activityinfo.legacy.shared.command.result.DuplicateCreateResult) SchemaDTO(org.activityinfo.legacy.shared.model.SchemaDTO) GetSchema(org.activityinfo.legacy.shared.command.GetSchema) UpdatePartner(org.activityinfo.legacy.shared.command.UpdatePartner) Test(org.junit.Test)

Example 7 with UpdatePartner

use of org.activityinfo.legacy.shared.command.UpdatePartner 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)

Example 8 with UpdatePartner

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

the class UserDatabasePolicy method addDefaultPartner.

private void addDefaultPartner(int databaseId, User user) {
    PartnerDTO partner = new PartnerDTO();
    partner.setName(PartnerDTO.DEFAULT_PARTNER_NAME);
    UpdatePartner command = new UpdatePartner(databaseId, partner);
    new UpdatePartnerHandler(em).execute(command, user);
}
Also used : PartnerDTO(org.activityinfo.legacy.shared.model.PartnerDTO) UpdatePartnerHandler(org.activityinfo.server.command.handler.UpdatePartnerHandler) UpdatePartner(org.activityinfo.legacy.shared.command.UpdatePartner)

Example 9 with UpdatePartner

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

the class UpdatePartnerHandlerTest method newWithSameName.

@Test
public void newWithSameName() {
    PartnerDTO newNRC = new PartnerDTO();
    newNRC.setName("NRC");
    newNRC.setFullName("National Red Cross");
    execute(new UpdatePartner(HEALTH_DATABASE, newNRC));
    SchemaDTO schema = execute(new GetSchema());
    PartnerDTO nrc1 = schema.getDatabaseById(NFI_DATABASE).getPartners().stream().filter(p -> p.getName().equals("NRC")).findAny().get();
    PartnerDTO nrc2 = schema.getDatabaseById(HEALTH_DATABASE).getPartners().stream().filter(p -> p.getName().equals("NRC")).findAny().get();
    assertThat(nrc1.getId(), not(equalTo(nrc2.getId())));
    assertThat(nrc1.getFullName(), nullValue());
    assertThat(nrc2.getFullName(), equalTo("National Red Cross"));
}
Also used : GetSchema(org.activityinfo.legacy.shared.command.GetSchema) UpdatePartner(org.activityinfo.legacy.shared.command.UpdatePartner) Test(org.junit.Test)

Example 10 with UpdatePartner

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

the class PartnerTest method testAddNewPartner.

@Test
public void testAddNewPartner() throws Exception {
    PartnerDTO newPartner = new PartnerDTO();
    newPartner.setName("VDE");
    newPartner.setFullName("Vision d'Espoir");
    CreateResult cr = execute(new UpdatePartner(1, newPartner));
    SchemaDTO schema = execute(new GetSchema());
    PartnerDTO partner = schema.getDatabaseById(1).getPartnerById(cr.getNewId());
    Assert.assertNotNull(partner);
    Assert.assertEquals("VDE", partner.getName());
    Assert.assertEquals("Vision d'Espoir", partner.getFullName());
}
Also used : PartnerDTO(org.activityinfo.legacy.shared.model.PartnerDTO) CreateResult(org.activityinfo.legacy.shared.command.result.CreateResult) DuplicateCreateResult(org.activityinfo.legacy.shared.command.result.DuplicateCreateResult) SchemaDTO(org.activityinfo.legacy.shared.model.SchemaDTO) GetSchema(org.activityinfo.legacy.shared.command.GetSchema) UpdatePartner(org.activityinfo.legacy.shared.command.UpdatePartner) Test(org.junit.Test)

Aggregations

UpdatePartner (org.activityinfo.legacy.shared.command.UpdatePartner)11 CreateResult (org.activityinfo.legacy.shared.command.result.CreateResult)7 DuplicateCreateResult (org.activityinfo.legacy.shared.command.result.DuplicateCreateResult)7 PartnerDTO (org.activityinfo.legacy.shared.model.PartnerDTO)5 GetSchema (org.activityinfo.legacy.shared.command.GetSchema)4 Test (org.junit.Test)4 Partner (org.activityinfo.server.database.hibernate.entity.Partner)3 Date (java.util.Date)2 SchemaDTO (org.activityinfo.legacy.shared.model.SchemaDTO)2 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)1 Optional (java.util.Optional)1 InjectionSupport (org.activityinfo.fixtures.InjectionSupport)1 GetSites (org.activityinfo.legacy.shared.command.GetSites)1 GetUsers (org.activityinfo.legacy.shared.command.GetUsers)1 UserResult (org.activityinfo.legacy.shared.command.result.UserResult)1 org.activityinfo.legacy.shared.model (org.activityinfo.legacy.shared.model)1 CommandTestCase2 (org.activityinfo.server.command.CommandTestCase2)1 UpdatePartnerHandler (org.activityinfo.server.command.handler.UpdatePartnerHandler)1 OnDataSet (org.activityinfo.server.database.OnDataSet)1 Database (org.activityinfo.server.database.hibernate.entity.Database)1