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