Search in sources :

Example 1 with AddTarget

use of org.activityinfo.legacy.shared.command.AddTarget 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 AddTarget

use of org.activityinfo.legacy.shared.command.AddTarget 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 AddTarget

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

the class CommandValidatorTest method nameTooLong.

@Test
public void nameTooLong() {
    TargetDTO target = new TargetDTO();
    target.setName(Strings.repeat("xoxoxo", 2000));
    AddTarget command = new AddTarget();
    command.setTarget(target);
    assertThat(validator.validate(command), hasItems(forProperty("target.name")));
}
Also used : AddTarget(org.activityinfo.legacy.shared.command.AddTarget) TargetDTO(org.activityinfo.legacy.shared.model.TargetDTO) Test(org.junit.Test)

Example 4 with AddTarget

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

the class CommandValidatorTest method missingRootProperty.

@Test
public void missingRootProperty() {
    AddTarget command = new AddTarget();
    assertThat(validator.validate(command), hasItems(forProperty("databaseId"), forProperty("target")));
}
Also used : AddTarget(org.activityinfo.legacy.shared.command.AddTarget) Test(org.junit.Test)

Example 5 with AddTarget

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

the class CommandValidatorTest method missingDates.

@Test
public void missingDates() {
    TargetDTO target = new TargetDTO();
    AddTarget command = new AddTarget();
    command.setTarget(target);
    assertThat(validator.validate(command), hasItems(forProperty("target.name"), forProperty("target.fromDate"), forProperty("target.toDate")));
}
Also used : AddTarget(org.activityinfo.legacy.shared.command.AddTarget) TargetDTO(org.activityinfo.legacy.shared.model.TargetDTO) Test(org.junit.Test)

Aggregations

AddTarget (org.activityinfo.legacy.shared.command.AddTarget)5 TargetDTO (org.activityinfo.legacy.shared.model.TargetDTO)4 Test (org.junit.Test)3 CreateResult (org.activityinfo.legacy.shared.command.result.CreateResult)2 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)1 Date (java.util.Date)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