Search in sources :

Example 1 with UpdateEntity

use of org.activityinfo.legacy.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, true, 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) {
                    Log.error("Failed to edit target. " + caught.getMessage(), caught);
                }

                @Override
                public void onSuccess(VoidResult result) {
                    if (record.get("partnerId") != null) {
                        PartnerDTO partner = db.getPartnerById((Integer) record.get("partnerId"));
                        dto.setPartner(partner);
                    } else {
                        dto.setPartner(null);
                    }
                    if (record.get("projectId") != null) {
                        ProjectDTO project = db.getProjectById((Integer) record.get("projectId"));
                        dto.setProject(project);
                    } else {
                        dto.setProject(null);
                    }
                    store.commitChanges();
                    eventBus.fireEvent(AppEvents.SCHEMA_CHANGED);
                    dlg.hide();
                }
            });
        }
    });
}
Also used : ProjectDTO(org.activityinfo.legacy.shared.model.ProjectDTO) FormDialogCallback(org.activityinfo.ui.client.page.common.dialog.FormDialogCallback) UpdateEntity(org.activityinfo.legacy.shared.command.UpdateEntity) VoidResult(org.activityinfo.legacy.shared.command.result.VoidResult) PartnerDTO(org.activityinfo.legacy.shared.model.PartnerDTO) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) FormDialogTether(org.activityinfo.ui.client.page.common.dialog.FormDialogTether) Record(com.extjs.gxt.ui.client.store.Record)

Example 2 with UpdateEntity

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

the class AttributeGroupTest method testUpdate.

@Test
public void testUpdate() throws Exception {
    // change the name of an entity group
    ActivityFormDTO activity = execute(new GetActivityForm(1));
    AttributeGroupDTO group = activity.getAttributeGroups().get(0);
    group.setName("Foobar");
    Map<String, Object> changes = new HashMap<String, Object>();
    changes.put("name", group.getName());
    execute(new UpdateEntity(group, changes));
    // reload data
    activity = execute(new GetActivityForm(1));
    // verify the property has been duly changed
    assertThat(activity.getAttributeGroups().get(0).getName(), equalTo(group.getName()));
}
Also used : AttributeGroupDTO(org.activityinfo.legacy.shared.model.AttributeGroupDTO) ActivityFormDTO(org.activityinfo.legacy.shared.model.ActivityFormDTO) UpdateEntity(org.activityinfo.legacy.shared.command.UpdateEntity) HashMap(java.util.HashMap) GetActivityForm(org.activityinfo.legacy.shared.command.GetActivityForm) Test(org.junit.Test)

Example 3 with UpdateEntity

use of org.activityinfo.legacy.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.legacy.shared.command.UpdateEntity) HashMap(java.util.HashMap) LockedPeriod(org.activityinfo.server.database.hibernate.entity.LockedPeriod) Test(org.junit.Test)

Example 4 with UpdateEntity

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

the class LockedPeriodTest method createTest.

@Test
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.setDatabaseId(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.legacy.shared.command.result.CreateResult) UpdateEntity(org.activityinfo.legacy.shared.command.UpdateEntity) LocalDate(com.bedatadriven.rebar.time.calendar.LocalDate) CreateLockedPeriod(org.activityinfo.legacy.shared.command.CreateLockedPeriod) LockedPeriodDTO(org.activityinfo.legacy.shared.model.LockedPeriodDTO) Test(org.junit.Test)

Example 5 with UpdateEntity

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

the class DbListPresenter method update.

private void update(UserDatabaseDTO db, final FormDialogImpl dialog) {
    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put("name", db.getName());
    properties.put("fullName", db.getFullName());
    properties.put("countryId", db.getCountry().getId());
    dispatcher.execute(new UpdateEntity(db.getEntityName(), db.getId(), properties), new SuccessCallback<VoidResult>() {

        @Override
        public void onSuccess(VoidResult arg0) {
            eventBus.fireEvent(AppEvents.SCHEMA_CHANGED);
            loader.load();
            dialog.hide();
        }
    });
}
Also used : UpdateEntity(org.activityinfo.legacy.shared.command.UpdateEntity) VoidResult(org.activityinfo.legacy.shared.command.result.VoidResult) HashMap(java.util.HashMap) SafeHtmlUtils.fromString(com.google.gwt.safehtml.shared.SafeHtmlUtils.fromString)

Aggregations

UpdateEntity (org.activityinfo.legacy.shared.command.UpdateEntity)5 HashMap (java.util.HashMap)3 Test (org.junit.Test)3 VoidResult (org.activityinfo.legacy.shared.command.result.VoidResult)2 LocalDate (com.bedatadriven.rebar.time.calendar.LocalDate)1 Record (com.extjs.gxt.ui.client.store.Record)1 SafeHtmlUtils.fromString (com.google.gwt.safehtml.shared.SafeHtmlUtils.fromString)1 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)1 CreateLockedPeriod (org.activityinfo.legacy.shared.command.CreateLockedPeriod)1 GetActivityForm (org.activityinfo.legacy.shared.command.GetActivityForm)1 CreateResult (org.activityinfo.legacy.shared.command.result.CreateResult)1 ActivityFormDTO (org.activityinfo.legacy.shared.model.ActivityFormDTO)1 AttributeGroupDTO (org.activityinfo.legacy.shared.model.AttributeGroupDTO)1 LockedPeriodDTO (org.activityinfo.legacy.shared.model.LockedPeriodDTO)1 PartnerDTO (org.activityinfo.legacy.shared.model.PartnerDTO)1 ProjectDTO (org.activityinfo.legacy.shared.model.ProjectDTO)1 LockedPeriod (org.activityinfo.server.database.hibernate.entity.LockedPeriod)1 FormDialogCallback (org.activityinfo.ui.client.page.common.dialog.FormDialogCallback)1 FormDialogTether (org.activityinfo.ui.client.page.common.dialog.FormDialogTether)1