Search in sources :

Example 6 with UpdateEntity

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());
}
Also used : UpdateEntity(org.activityinfo.shared.command.UpdateEntity) HashMap(java.util.HashMap) LockedPeriod(org.activityinfo.server.database.hibernate.entity.LockedPeriod) Test(org.junit.Test)

Example 7 with UpdateEntity

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));
}
Also used : CreateResult(org.activityinfo.shared.command.result.CreateResult) UpdateEntity(org.activityinfo.shared.command.UpdateEntity) LocalDate(com.bedatadriven.rebar.time.calendar.LocalDate) CreateLockedPeriod(org.activityinfo.shared.command.CreateLockedPeriod) LockedPeriodDTO(org.activityinfo.shared.dto.LockedPeriodDTO) OnDataSet(org.activityinfo.server.database.OnDataSet) Test(org.junit.Test)

Example 8 with UpdateEntity

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();
                }
            });
        }
    });
}
Also used : ProjectDTO(org.activityinfo.shared.dto.ProjectDTO) FormDialogCallback(org.activityinfo.client.page.common.dialog.FormDialogCallback) UpdateEntity(org.activityinfo.shared.command.UpdateEntity) VoidResult(org.activityinfo.shared.command.result.VoidResult) PartnerDTO(org.activityinfo.shared.dto.PartnerDTO) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) FormDialogTether(org.activityinfo.client.page.common.dialog.FormDialogTether) Record(com.extjs.gxt.ui.client.store.Record)

Example 9 with UpdateEntity

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);
        }
    });
}
Also used : UpdateEntity(org.activityinfo.shared.command.UpdateEntity) VoidResult(org.activityinfo.shared.command.result.VoidResult)

Example 10 with UpdateEntity

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"));
}
Also used : TreeStore(com.extjs.gxt.ui.client.store.TreeStore) VoidResult(org.activityinfo.shared.command.result.VoidResult) UpdateEntity(org.activityinfo.shared.command.UpdateEntity) MockEventBus(org.activityinfo.client.MockEventBus) DispatcherStub(org.activityinfo.client.dispatch.DispatcherStub) Record(com.extjs.gxt.ui.client.store.Record) UIConstants(org.activityinfo.client.i18n.UIConstants) StateManagerStub(org.activityinfo.client.mock.StateManagerStub) ActivityDTO(org.activityinfo.shared.dto.ActivityDTO) SchemaDTO(org.activityinfo.shared.dto.SchemaDTO) Test(org.junit.Test)

Aggregations

UpdateEntity (org.activityinfo.shared.command.UpdateEntity)11 Test (org.junit.Test)9 SchemaDTO (org.activityinfo.shared.dto.SchemaDTO)6 HashMap (java.util.HashMap)5 GetSchema (org.activityinfo.shared.command.GetSchema)4 VoidResult (org.activityinfo.shared.command.result.VoidResult)4 Record (com.extjs.gxt.ui.client.store.Record)3 ActivityDTO (org.activityinfo.shared.dto.ActivityDTO)3 TreeStore (com.extjs.gxt.ui.client.store.TreeStore)2 MockEventBus (org.activityinfo.client.MockEventBus)2 DispatcherStub (org.activityinfo.client.dispatch.DispatcherStub)2 UIConstants (org.activityinfo.client.i18n.UIConstants)2 StateManagerStub (org.activityinfo.client.mock.StateManagerStub)2 BatchCommand (org.activityinfo.shared.command.BatchCommand)2 LocalDate (com.bedatadriven.rebar.time.calendar.LocalDate)1 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)1 NavigationCallback (org.activityinfo.client.page.NavigationCallback)1 FormDialogCallback (org.activityinfo.client.page.common.dialog.FormDialogCallback)1 FormDialogTether (org.activityinfo.client.page.common.dialog.FormDialogTether)1 DataEntryPlace (org.activityinfo.client.page.entry.place.DataEntryPlace)1