use of org.activityinfo.shared.command.UpdateEntity in project activityinfo by bedatadriven.
the class UpdateSiteTest method testUpdateLockedPeriod.
@Test
public void testUpdateLockedPeriod() throws CommandException {
Map<String, Object> changes = new HashMap<String, Object>();
changes.put("enabled", false);
execute(new UpdateEntity("LockedPeriod", 1, changes));
// assure that the change has been effected
LockedPeriod lockedPeriod = em.find(LockedPeriod.class, 1);
Assert.assertEquals("enabled", false, lockedPeriod.isEnabled());
}
use of org.activityinfo.shared.command.UpdateEntity in project activityinfo by bedatadriven.
the class LockedPeriodTest method createTest.
@Test
@OnDataSet("/dbunit/sites-simple1.db.xml")
public void createTest() throws CommandException {
setUser(1);
LockedPeriodDTO dto = new LockedPeriodDTO();
dto.setName("my name");
dto.setFromDate(new LocalDate(2011, 1, 1));
dto.setToDate(new LocalDate(2011, 1, 31));
dto.setEnabled(true);
CreateLockedPeriod create = new CreateLockedPeriod(dto);
create.setUserDatabaseId(1);
CreateResult result = execute(create);
Map<String, Object> changes = Maps.newHashMap();
changes.put("toDate", new LocalDate(2011, 2, 28));
execute(new UpdateEntity("LockedPeriod", result.getNewId(), changes));
}
use of org.activityinfo.shared.command.UpdateEntity in project activityinfo by bedatadriven.
the class DbTargetEditor method onEdit.
@Override
protected void onEdit(final TargetDTO dto) {
this.view.showAddDialog(dto, db, new FormDialogCallback() {
@Override
public void onValidated(final FormDialogTether dlg) {
final Record record = store.getRecord(dto);
service.execute(new UpdateEntity(dto, getChangedProperties(record)), dlg, new AsyncCallback<VoidResult>() {
@Override
public void onFailure(Throwable caught) {
}
@Override
public void onSuccess(VoidResult result) {
PartnerDTO partner = db.getPartnerById((Integer) record.get("partnerId"));
dto.setPartner(partner);
ProjectDTO project = db.getProjectById((Integer) record.get("projectId"));
dto.setProject(project);
store.commitChanges();
eventBus.fireEvent(AppEvents.SCHEMA_CHANGED);
dlg.hide();
}
});
}
});
}
use of org.activityinfo.shared.command.UpdateEntity in project activityinfo by bedatadriven.
the class EmbedDialog method publishActivity.
protected void publishActivity(ActivityDTO activity, final String url) {
Map<String, Object> changes = Maps.newHashMap();
changes.put("published", Published.ALL_ARE_PUBLISHED.getIndex());
UpdateEntity update = new UpdateEntity(activity, changes);
dispatcher.execute(update, new AsyncCallback<VoidResult>() {
@Override
public void onFailure(Throwable caught) {
MessageBox.alert(I18N.CONSTANTS.embed(), "There was an error encounted on the server while trying to publish the activity", null);
}
@Override
public void onSuccess(VoidResult result) {
show(url);
}
});
}
use of org.activityinfo.shared.command.UpdateEntity in project activityinfo by bedatadriven.
the class DesignTest method testSave.
@Test
public void testSave() {
// Dummy Data
SchemaDTO schema = DTOs.pear();
// Collaborator
MockEventBus eventBus = new MockEventBus();
// Collaborator
DispatcherStub service = new DispatcherStub();
service.setResult(GetSchema.class, schema);
service.setResult(UpdateEntity.class, new VoidResult());
// Collaborator
DesignPresenter.View view = createNiceMock(DesignPresenter.View.class);
replay(view);
// Localisation resources
UIConstants constants = createNiceMock(UIConstants.class);
replay(constants);
DesignPresenter designer = new DesignPresenter(eventBus, service, new StateManagerStub(), view, constants);
designer.go(schema.getDatabaseById(1));
// Verify that following a change to the record, a save call
// triggers an update command
ActivityDTO activity = (ActivityDTO) ((TreeStore) designer.getStore()).getRootItems().get(0);
Record record = designer.getStore().getRecord(activity);
record.set("name", "New Name");
designer.onUIAction(UIActions.SAVE);
UpdateEntity cmd = service.getLastExecuted(UpdateEntity.class);
Assert.assertTrue(cmd.getChanges().containsKey("name"));
Assert.assertEquals("New Name", cmd.getChanges().get("name"));
}
Aggregations