Search in sources :

Example 1 with CreateResult

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

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

the class CreateSiteHandlerAsync method createNewSite.

private void createNewSite(CreateSite cmd, ExecutionContext context, AsyncCallback<CreateResult> callback) {
    insertSite(context.getTransaction(), cmd);
    // we only create a reporting period if this is a one-off activity
    Integer reportingPeriodId = cmd.getReportingPeriodId();
    if (reportingPeriodId != null) {
        insertReportingPeriod(context.getTransaction(), cmd);
    }
    callback.onSuccess(new CreateResult(cmd.getSiteId()));
}
Also used : CreateResult(org.activityinfo.legacy.shared.command.result.CreateResult)

Example 3 with CreateResult

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

the class AddProjectHandler method execute.

@Override
public CommandResult execute(AddProject cmd, User user) {
    Database db = em.find(Database.class, cmd.getDatabaseId());
    ProjectDTO from = cmd.getProjectDTO();
    Project project = new Project();
    project.setName(from.getName());
    project.setDescription(from.getDescription());
    project.setDatabase(db);
    db.setLastSchemaUpdate(new Date());
    em.persist(project);
    em.persist(db);
    db.getProjects().add(project);
    return new CreateResult(project.getId());
}
Also used : ProjectDTO(org.activityinfo.legacy.shared.model.ProjectDTO) Project(org.activityinfo.server.database.hibernate.entity.Project) AddProject(org.activityinfo.legacy.shared.command.AddProject) CreateResult(org.activityinfo.legacy.shared.command.result.CreateResult) Database(org.activityinfo.server.database.hibernate.entity.Database) Date(java.util.Date)

Example 4 with CreateResult

use of org.activityinfo.legacy.shared.command.result.CreateResult 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 5 with CreateResult

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

the class CreateEntityHandler method createAttribute.

private CommandResult createAttribute(Map<String, Object> properties) {
    Attribute attribute = new Attribute();
    attribute.setId(generator.generateInt());
    AttributeGroup ag = entityManager().getReference(AttributeGroup.class, properties.get("attributeGroupId"));
    attribute.setGroup(ag);
    updateAttributeProperties(properties, attribute);
    if (attribute.getSortOrder() == 0) {
        attribute.setSortOrder(queryNextAttributeOrdinal(ag));
    }
    // Assume group has only one activity
    Activity activity = ag.getActivities().iterator().next();
    entityManager().persist(attribute);
    activity.incrementSchemaVersion();
    activity.getDatabase().setLastSchemaUpdate(new Date());
    return new CreateResult(attribute.getId());
}
Also used : CreateResult(org.activityinfo.legacy.shared.command.result.CreateResult) Date(java.util.Date)

Aggregations

CreateResult (org.activityinfo.legacy.shared.command.result.CreateResult)46 Test (org.junit.Test)26 Date (java.util.Date)9 GetSchema (org.activityinfo.legacy.shared.command.GetSchema)7 UpdatePartner (org.activityinfo.legacy.shared.command.UpdatePartner)7 DuplicateCreateResult (org.activityinfo.legacy.shared.command.result.DuplicateCreateResult)7 OnDataSet (org.activityinfo.server.database.OnDataSet)6 CreateSite (org.activityinfo.legacy.shared.command.CreateSite)5 PartnerDTO (org.activityinfo.legacy.shared.model.PartnerDTO)5 CreateEntity (org.activityinfo.legacy.shared.command.CreateEntity)4 SchemaDTO (org.activityinfo.legacy.shared.model.SchemaDTO)4 TargetDTO (org.activityinfo.legacy.shared.model.TargetDTO)4 CuidAdapter.activityFormClass (org.activityinfo.model.legacy.CuidAdapter.activityFormClass)4 ResourceId (org.activityinfo.model.resource.ResourceId)4 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)3 GregorianCalendar (java.util.GregorianCalendar)3 CloneDatabase (org.activityinfo.legacy.shared.command.CloneDatabase)3 ProjectDTO (org.activityinfo.legacy.shared.model.ProjectDTO)3 SiteDTO (org.activityinfo.legacy.shared.model.SiteDTO)3 EnumItem (org.activityinfo.model.type.enumerated.EnumItem)3