Search in sources :

Example 1 with CreateResult

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

the class DbPartnerEditor method onAdd.

// public void onSelectionChanged(PartnerDTO selectedItem) {
// this.view.setActionEnabled(UIActions.delete, selectedItem != null);
// }
@Override
protected void onAdd() {
    final PartnerDTO newPartner = new PartnerDTO();
    this.view.showAddDialog(newPartner, new FormDialogCallback() {

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

                @Override
                public void onFailure(Throwable caught) {
                    Log.debug("DbPartnerEditor caught exception while executing command AddPartner: ", caught);
                }

                @Override
                public void onSuccess(CreateResult result) {
                    if (result instanceof DuplicateCreateResult) {
                        Log.debug("DbPartnerEditor tried to add partner '" + newPartner.getName() + "' to database " + db.getId() + " but it already exists");
                        MessageBox.alert(I18N.CONSTANTS.newPartner(), I18N.CONSTANTS.duplicatePartner(), null);
                    } else {
                        Log.debug("DbPartnerEditor added new partner '" + newPartner.getName() + "' to database " + db.getId());
                        newPartner.setId(result.getNewId());
                        store.add(newPartner);
                        eventBus.fireEvent(AppEvents.SCHEMA_CHANGED);
                        dlg.hide();
                    }
                }
            });
        }
    });
}
Also used : DuplicateCreateResult(org.activityinfo.shared.command.result.DuplicateCreateResult) PartnerDTO(org.activityinfo.shared.dto.PartnerDTO) FormDialogCallback(org.activityinfo.client.page.common.dialog.FormDialogCallback) CreateResult(org.activityinfo.shared.command.result.CreateResult) DuplicateCreateResult(org.activityinfo.shared.command.result.DuplicateCreateResult) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) FormDialogTether(org.activityinfo.client.page.common.dialog.FormDialogTether) AddPartner(org.activityinfo.shared.command.AddPartner)

Example 2 with CreateResult

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

the class LockedPeriodsPresenter method onCreate.

@Override
public void onCreate(CreateEvent event) {
    view.getCreatingMonitor().beforeRequest();
    final LockedPeriodDTO lockedPeriod = view.getValue();
    CreateLockedPeriod lockUserDatabase = new CreateLockedPeriod(lockedPeriod);
    if (lockedPeriod.getParent() instanceof ActivityDTO) {
        lockUserDatabase.setActivityId(lockedPeriod.getParent().getId());
    }
    if (lockedPeriod.getParent() instanceof ProjectDTO) {
        lockUserDatabase.setProjectId(lockedPeriod.getParent().getId());
    }
    if (lockedPeriod.getParent() instanceof UserDatabaseDTO) {
        lockUserDatabase.setUserDatabaseId(lockedPeriod.getParent().getId());
    }
    service.execute(lockUserDatabase, new AsyncCallback<CreateResult>() {

        @Override
        public void onFailure(Throwable caught) {
            view.getCreatingMonitor().onServerError();
            MessageBox.alert(I18N.CONSTANTS.error(), I18N.CONSTANTS.errorOnServer() + "\n\n" + caught.getMessage(), null);
        }

        @Override
        public void onSuccess(CreateResult result) {
            // Update the Id for the child instance
            lockedPeriod.setId(result.getNewId());
            // Tell the view there's a new kid on the block
            view.create(lockedPeriod);
            // Actually add the lock to it's parent
            lockedPeriod.getParent().getLockedPeriods().add(lockedPeriod);
        }
    });
}
Also used : ProjectDTO(org.activityinfo.shared.dto.ProjectDTO) CreateResult(org.activityinfo.shared.command.result.CreateResult) UserDatabaseDTO(org.activityinfo.shared.dto.UserDatabaseDTO) ActivityDTO(org.activityinfo.shared.dto.ActivityDTO) CreateLockedPeriod(org.activityinfo.shared.command.CreateLockedPeriod) LockedPeriodDTO(org.activityinfo.shared.dto.LockedPeriodDTO)

Example 3 with CreateResult

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

the class AddProjectHandler method execute.

@Override
public CommandResult execute(AddProject cmd, User user) throws CommandException {
    UserDatabase db = em.find(UserDatabase.class, cmd.getDatabaseId());
    ProjectDTO from = cmd.getProjectDTO();
    Project project = new Project();
    project.setName(from.getName());
    project.setDescription(from.getDescription());
    project.setUserDatabase(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.shared.dto.ProjectDTO) Project(org.activityinfo.server.database.hibernate.entity.Project) AddProject(org.activityinfo.shared.command.AddProject) CreateResult(org.activityinfo.shared.command.result.CreateResult) UserDatabase(org.activityinfo.server.database.hibernate.entity.UserDatabase) Date(java.util.Date)

Example 4 with CreateResult

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

the class AddPartnerHandler method execute.

@Override
@SuppressWarnings("unchecked")
public CommandResult execute(AddPartner cmd, User user) throws CommandException {
    UserDatabase db = em.find(UserDatabase.class, cmd.getDatabaseId());
    if (db.getOwner().getId() != user.getId()) {
        UserPermission perm = db.getPermissionByUser(user);
        if (perm == null || !perm.isAllowManageAllUsers()) {
            throw new IllegalAccessCommandException("The user does not have the manageAllUsers permission.");
        }
    }
    // first check to see if an organization by this name is already
    // a partner
    Set<Partner> dbPartners = db.getPartners();
    for (Partner partner : dbPartners) {
        if (partner.getName().equals(cmd.getPartner().getName())) {
            return new DuplicateCreateResult();
        }
    }
    // now try to match this partner by name
    List<Partner> allPartners = em.createQuery("select p from Partner p where p.name = ?1").setParameter(1, cmd.getPartner().getName()).getResultList();
    if (allPartners.size() != 0) {
        db.getPartners().add(allPartners.get(0));
        return new CreateResult(allPartners.get(0).getId());
    }
    // nope, have to create a new record
    Partner newPartner = new Partner();
    newPartner.setName(cmd.getPartner().getName());
    newPartner.setFullName(cmd.getPartner().getFullName());
    em.persist(newPartner);
    db.setLastSchemaUpdate(new Date());
    em.persist(db);
    db.getPartners().add(newPartner);
    return new CreateResult(newPartner.getId());
}
Also used : DuplicateCreateResult(org.activityinfo.shared.command.result.DuplicateCreateResult) CreateResult(org.activityinfo.shared.command.result.CreateResult) DuplicateCreateResult(org.activityinfo.shared.command.result.DuplicateCreateResult) IllegalAccessCommandException(org.activityinfo.shared.exception.IllegalAccessCommandException) UserDatabase(org.activityinfo.server.database.hibernate.entity.UserDatabase) Partner(org.activityinfo.server.database.hibernate.entity.Partner) AddPartner(org.activityinfo.shared.command.AddPartner) Date(java.util.Date) UserPermission(org.activityinfo.server.database.hibernate.entity.UserPermission)

Example 5 with CreateResult

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

the class AddTargetHandler method execute.

@Override
public CommandResult execute(AddTarget cmd, User user) throws CommandException {
    TargetDTO form = cmd.getTargetDTO();
    UserDatabase db = em.find(UserDatabase.class, cmd.getDatabaseId());
    Partner partner = null;
    if (form.get("partnerId") != null) {
        partner = em.find(Partner.class, form.get("partnerId"));
    }
    Project project = null;
    if (form.get("projectId") != null) {
        project = em.find(Project.class, form.get("projectId"));
    }
    AdminEntity adminEntity = null;
    // if(form.getAdminEntity() != null){
    // adminEntity = em.find(AdminEntity.class,
    // form.getAdminEntity().getId());
    // }
    Target target = new Target();
    target.setName(form.getName());
    target.setUserDatabase(db);
    target.setAdminEntity(adminEntity);
    target.setPartner(partner);
    target.setProject(project);
    target.setDate1(form.getDate1());
    target.setDate2(form.getDate2());
    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 : Project(org.activityinfo.server.database.hibernate.entity.Project) AdminEntity(org.activityinfo.server.database.hibernate.entity.AdminEntity) Target(org.activityinfo.server.database.hibernate.entity.Target) AddTarget(org.activityinfo.shared.command.AddTarget) CreateResult(org.activityinfo.shared.command.result.CreateResult) UserDatabase(org.activityinfo.server.database.hibernate.entity.UserDatabase) TargetDTO(org.activityinfo.shared.dto.TargetDTO) Partner(org.activityinfo.server.database.hibernate.entity.Partner) Date(java.util.Date)

Aggregations

CreateResult (org.activityinfo.shared.command.result.CreateResult)36 Test (org.junit.Test)17 SchemaDTO (org.activityinfo.shared.dto.SchemaDTO)9 Date (java.util.Date)8 GetSchema (org.activityinfo.shared.command.GetSchema)8 PartnerDTO (org.activityinfo.shared.dto.PartnerDTO)8 CreateSite (org.activityinfo.shared.command.CreateSite)7 SiteDTO (org.activityinfo.shared.dto.SiteDTO)7 AddPartner (org.activityinfo.shared.command.AddPartner)6 ActivityDTO (org.activityinfo.shared.dto.ActivityDTO)6 ProjectDTO (org.activityinfo.shared.dto.ProjectDTO)6 OnDataSet (org.activityinfo.server.database.OnDataSet)5 UserDatabase (org.activityinfo.server.database.hibernate.entity.UserDatabase)5 CreateEntity (org.activityinfo.shared.command.CreateEntity)5 DuplicateCreateResult (org.activityinfo.shared.command.result.DuplicateCreateResult)5 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)4 FormDialogCallback (org.activityinfo.client.page.common.dialog.FormDialogCallback)4 FormDialogTether (org.activityinfo.client.page.common.dialog.FormDialogTether)4 Activity (org.activityinfo.server.database.hibernate.entity.Activity)4 AddTarget (org.activityinfo.shared.command.AddTarget)4