Search in sources :

Example 1 with DuplicateCreateResult

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

the class UpdatePartnerHandler method addNewPartner.

private CreateResult addNewPartner(UpdatePartner cmd, Database db) {
    // first check to see if an organization by this name is already
    // a partner in the same database
    Set<Partner> dbPartners = db.getPartners();
    for (Partner partner : dbPartners) {
        if (partner.getName().equals(cmd.getPartner().getName())) {
            return new DuplicateCreateResult();
        }
    }
    // Add a new partner
    Partner partner = new Partner();
    partner.setName(cmd.getPartner().getName());
    partner.setFullName(cmd.getPartner().getFullName());
    em.persist(partner);
    db.setLastSchemaUpdate(new Date());
    em.persist(db);
    db.getPartners().add(partner);
    return new CreateResult(partner.getId());
}
Also used : DuplicateCreateResult(org.activityinfo.legacy.shared.command.result.DuplicateCreateResult) CreateResult(org.activityinfo.legacy.shared.command.result.CreateResult) DuplicateCreateResult(org.activityinfo.legacy.shared.command.result.DuplicateCreateResult) Partner(org.activityinfo.server.database.hibernate.entity.Partner) UpdatePartner(org.activityinfo.legacy.shared.command.UpdatePartner) Date(java.util.Date)

Example 2 with DuplicateCreateResult

use of org.activityinfo.legacy.shared.command.result.DuplicateCreateResult 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 3 with DuplicateCreateResult

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

the class PartnerTest method testAddDuplicatePartner.

public void testAddDuplicatePartner() throws Exception {
    PartnerDTO newPartner = new PartnerDTO();
    newPartner.setName("NRC");
    newPartner.setFullName("Norweigen Refugee Committe");
    CreateResult cr = execute(new UpdatePartner(1, newPartner));
    Assert.assertTrue(cr instanceof DuplicateCreateResult);
}
Also used : DuplicateCreateResult(org.activityinfo.legacy.shared.command.result.DuplicateCreateResult) PartnerDTO(org.activityinfo.legacy.shared.model.PartnerDTO) CreateResult(org.activityinfo.legacy.shared.command.result.CreateResult) DuplicateCreateResult(org.activityinfo.legacy.shared.command.result.DuplicateCreateResult) UpdatePartner(org.activityinfo.legacy.shared.command.UpdatePartner)

Aggregations

UpdatePartner (org.activityinfo.legacy.shared.command.UpdatePartner)3 CreateResult (org.activityinfo.legacy.shared.command.result.CreateResult)3 DuplicateCreateResult (org.activityinfo.legacy.shared.command.result.DuplicateCreateResult)3 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)1 Date (java.util.Date)1 PartnerDTO (org.activityinfo.legacy.shared.model.PartnerDTO)1 Partner (org.activityinfo.server.database.hibernate.entity.Partner)1 FormDialogCallback (org.activityinfo.ui.client.page.common.dialog.FormDialogCallback)1 FormDialogImpl (org.activityinfo.ui.client.page.common.dialog.FormDialogImpl)1 FormDialogTether (org.activityinfo.ui.client.page.common.dialog.FormDialogTether)1 PartnerForm (org.activityinfo.ui.client.page.config.form.PartnerForm)1