Search in sources :

Example 1 with TargetDTO

use of org.activityinfo.legacy.shared.model.TargetDTO in project activityinfo by bedatadriven.

the class DbTargetEditor method onAdd.

@Override
protected void onAdd() {
    final TargetDTO newTarget = new TargetDTO();
    this.view.showAddDialog(newTarget, db, false, new FormDialogCallback() {

        @Override
        public void onValidated(final FormDialogTether dlg) {
            service.execute(new AddTarget(db.getId(), newTarget), dlg, new AsyncCallback<CreateResult>() {

                @Override
                public void onFailure(Throwable caught) {
                    MessageBox.alert(I18N.CONSTANTS.error(), I18N.CONSTANTS.errorOnServer(), null);
                }

                @Override
                public void onSuccess(CreateResult result) {
                    newTarget.setId(result.getNewId());
                    if (newTarget.get("partnerId") != null) {
                        PartnerDTO partner = db.getPartnerById((Integer) newTarget.get("partnerId"));
                        newTarget.setPartner(partner);
                    }
                    if (newTarget.get("projectId") != null) {
                        ProjectDTO project = db.getProjectById((Integer) newTarget.get("projectId"));
                        newTarget.setProject(project);
                    }
                    store.add(newTarget);
                    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) CreateResult(org.activityinfo.legacy.shared.command.result.CreateResult) PartnerDTO(org.activityinfo.legacy.shared.model.PartnerDTO) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) FormDialogTether(org.activityinfo.ui.client.page.common.dialog.FormDialogTether) AddTarget(org.activityinfo.legacy.shared.command.AddTarget) TargetDTO(org.activityinfo.legacy.shared.model.TargetDTO)

Example 2 with TargetDTO

use of org.activityinfo.legacy.shared.model.TargetDTO in project activityinfo by bedatadriven.

the class AddTargetHandler method execute.

@Override
public CommandResult execute(AddTarget cmd, User user) {
    TargetDTO form = cmd.getTarget();
    Database db = em.find(Database.class, cmd.getDatabaseId());
    permissionOracle.assertDesignPrivileges(db, user);
    Partner partner = null;
    if (form.get("partnerId") != null) {
        partner = em.find(Partner.class, form.get("partnerId"));
    } else if (form.getPartner() != null) {
        partner = em.find(Partner.class, form.getPartner().getId());
    }
    Project project = null;
    if (form.get("projectId") != null) {
        project = em.find(Project.class, form.get("projectId"));
    } else if (form.getProject() != null) {
        project = em.find(Project.class, form.getProject().getId());
    }
    Target target = new Target();
    target.setName(form.getName());
    target.setDatabase(db);
    target.setPartner(partner);
    target.setProject(project);
    target.setDate1(form.getFromDate().atMidnightInMyTimezone());
    target.setDate2(form.getToDate().atMidnightInMyTimezone());
    db.setLastSchemaUpdate(new Date());
    em.persist(target);
    em.persist(db);
    db.getTargets().add(target);
    if (project != null) {
        project.getTargets().add(target);
    }
    if (partner != null) {
        partner.getTargets().add(target);
    }
    return new CreateResult(target.getId());
}
Also used : AddTarget(org.activityinfo.legacy.shared.command.AddTarget) CreateResult(org.activityinfo.legacy.shared.command.result.CreateResult) TargetDTO(org.activityinfo.legacy.shared.model.TargetDTO) Date(java.util.Date)

Example 3 with TargetDTO

use of org.activityinfo.legacy.shared.model.TargetDTO in project activityinfo by bedatadriven.

the class TargetTest method deleteTargetTest.

@Test
public void deleteTargetTest() {
    TargetDTO target = createTarget();
    CreateResult cresult = execute(new AddTarget(db.getId(), target));
    int newId = cresult.getNewId();
    List<TargetDTO> targets = execute(new GetTargets(db.getId())).getData();
    TargetDTO dto = getTargetById(targets, newId);
    assertEquals("name", "Target0071", dto.getName());
    execute(new Delete(dto));
    targets = execute(new GetTargets()).getData();
    TargetDTO deleted = getTargetById(targets, newId);
    assertNull(deleted);
}
Also used : CreateResult(org.activityinfo.legacy.shared.command.result.CreateResult) TargetDTO(org.activityinfo.legacy.shared.model.TargetDTO) Test(org.junit.Test)

Example 4 with TargetDTO

use of org.activityinfo.legacy.shared.model.TargetDTO in project activityinfo by bedatadriven.

the class TargetTest method testTarget.

@Test
public void testTarget() throws CommandException {
    TargetDTO target = createTarget();
    CreateResult cresult = execute(new AddTarget(db.getId(), target));
    int newId = cresult.getNewId();
    List<TargetDTO> targets = execute(new GetTargets(db.getId())).getData();
    TargetDTO dto = getTargetById(targets, newId);
    assertNotNull(dto);
    assertEquals("name", "Target0071", dto.getName());
}
Also used : CreateResult(org.activityinfo.legacy.shared.command.result.CreateResult) TargetDTO(org.activityinfo.legacy.shared.model.TargetDTO) Test(org.junit.Test)

Example 5 with TargetDTO

use of org.activityinfo.legacy.shared.model.TargetDTO in project activityinfo by bedatadriven.

the class DbTargetGrid method createGridAndAddToContainer.

@Override
protected Grid<TargetDTO> createGridAndAddToContainer(Store store) {
    this.store = (ListStore<TargetDTO>) store;
    grid = new Grid<TargetDTO>((ListStore) store, createColumnModel());
    grid.setAutoExpandColumn("name");
    grid.setLoadMask(true);
    setLayout(new BorderLayout());
    add(grid, new BorderLayoutData(Style.LayoutRegion.CENTER));
    return grid;
}
Also used : ListStore(com.extjs.gxt.ui.client.store.ListStore) BorderLayout(com.extjs.gxt.ui.client.widget.layout.BorderLayout) BorderLayoutData(com.extjs.gxt.ui.client.widget.layout.BorderLayoutData) TargetDTO(org.activityinfo.legacy.shared.model.TargetDTO)

Aggregations

TargetDTO (org.activityinfo.legacy.shared.model.TargetDTO)9 Test (org.junit.Test)5 AddTarget (org.activityinfo.legacy.shared.command.AddTarget)4 CreateResult (org.activityinfo.legacy.shared.command.result.CreateResult)4 LocalDate (com.bedatadriven.rebar.time.calendar.LocalDate)2 Date (java.util.Date)2 ListStore (com.extjs.gxt.ui.client.store.ListStore)1 BorderLayout (com.extjs.gxt.ui.client.widget.layout.BorderLayout)1 BorderLayoutData (com.extjs.gxt.ui.client.widget.layout.BorderLayoutData)1 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)1 HashMap (java.util.HashMap)1 PartnerDTO (org.activityinfo.legacy.shared.model.PartnerDTO)1 ProjectDTO (org.activityinfo.legacy.shared.model.ProjectDTO)1 FormDialogCallback (org.activityinfo.ui.client.page.common.dialog.FormDialogCallback)1 FormDialogTether (org.activityinfo.ui.client.page.common.dialog.FormDialogTether)1