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