Search in sources :

Example 1 with LockedPeriodDTO

use of org.activityinfo.shared.dto.LockedPeriodDTO in project activityinfo by bedatadriven.

the class AddLockedPeriodDialog method getValue.

@Override
public LockedPeriodDTO getValue() {
    LockedPeriodDTO newLockedPeriod = new LockedPeriodDTO();
    newLockedPeriod.setName(textfieldName.getValue());
    newLockedPeriod.setEnabled(checkboxEnabled.getValue());
    newLockedPeriod.setFromDate(datefieldFromDate.getValue());
    newLockedPeriod.setToDate(datefieldToDate.getValue());
    if (radioActivity.getValue() && comboboxActivities.getValue() != null) {
        newLockedPeriod.setParent(comboboxActivities.getValue());
    }
    if (radioProject.getValue() && comboboxProjects.getValue() != null) {
        newLockedPeriod.setParent(comboboxProjects.getValue());
    }
    if (radioDatabase.getValue()) {
        newLockedPeriod.setParent(userDatabase);
    }
    return newLockedPeriod;
}
Also used : LockedPeriodDTO(org.activityinfo.shared.dto.LockedPeriodDTO)

Example 2 with LockedPeriodDTO

use of org.activityinfo.shared.dto.LockedPeriodDTO in project activityinfo by bedatadriven.

the class LockedPeriodsPresenter method go.

@Override
public void go(UserDatabaseDTO db) {
    parentModel = db;
    ArrayList<LockedPeriodDTO> items = new ArrayList<LockedPeriodDTO>(db.getLockedPeriods());
    for (ActivityDTO activity : db.getActivities()) {
        if (activity.getLockedPeriods() != null && activity.getLockedPeriods().size() > 0) {
            items.addAll(activity.getLockedPeriods());
        }
    }
    for (ProjectDTO project : db.getProjects()) {
        if (project.getLockedPeriods() != null && project.getLockedPeriods().size() > 0) {
            items.addAll(project.getLockedPeriods());
        }
    }
    view.setItems(items);
    if (items.size() > 0) {
        view.setValue(items.get(0));
    }
    view.setParent(parentModel);
}
Also used : ProjectDTO(org.activityinfo.shared.dto.ProjectDTO) ArrayList(java.util.ArrayList) ActivityDTO(org.activityinfo.shared.dto.ActivityDTO) LockedPeriodDTO(org.activityinfo.shared.dto.LockedPeriodDTO)

Example 3 with LockedPeriodDTO

use of org.activityinfo.shared.dto.LockedPeriodDTO 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 4 with LockedPeriodDTO

use of org.activityinfo.shared.dto.LockedPeriodDTO in project activityinfo by bedatadriven.

the class GetLockedPeriodsHandler method execute.

@Override
public void execute(GetLockedPeriods command, ExecutionContext context, final AsyncCallback<LockedPeriodsResult> callback) {
    final List<Integer> projectIds = Lists.newArrayList();
    final List<Integer> activityIds = Lists.newArrayList();
    final List<LockedPeriodDTO> lockedPeriods = Lists.newArrayList();
    SqlQuery.select("ProjectId").from("project").where("DatabaseId").equalTo(command.getDatabaseId()).execute(context.getTransaction(), new RowHandler() {

        @Override
        public void handleRow(SqlResultSetRow row) {
            projectIds.add(row.getInt("ProjectId"));
        }
    });
    SqlQuery.select("ActivityId").from("activity").where("DatabaseId").equalTo(command.getDatabaseId()).execute(context.getTransaction(), new RowHandler() {

        @Override
        public void handleRow(SqlResultSetRow row) {
            activityIds.add(row.getInt("ActivityId"));
        }
    });
    // TODO(ruud): load only what is visible to user
    SqlQuery.select("fromDate", "toDate", "enabled", "name", "lockedPeriodId", "userDatabaseId", "activityId", "projectId").from("lockedperiod").where("ActivityId").in(activityIds).or().where("ProjectId").in(projectIds).or().where("UserDatabaseId").equalTo(command.getDatabaseId()).execute(context.getTransaction(), new SqlResultCallback() {

        @Override
        public void onSuccess(SqlTransaction tx, SqlResultSet results) {
            UserDatabaseDTO db = new UserDatabaseDTO();
            ActivityDTO activity = new ActivityDTO();
            ProjectDTO project = new ProjectDTO();
            for (SqlResultSetRow row : results.getRows()) {
                LockedPeriodDTO lockedPeriod = new LockedPeriodDTO();
                lockedPeriod.setFromDate(row.getDate("fromDate"));
                lockedPeriod.setToDate(row.getDate("toDate"));
                lockedPeriod.setEnabled(row.getBoolean("enabled"));
                lockedPeriod.setName(row.getString("name"));
                lockedPeriod.setId(row.getInt("lockedPeriodId"));
                boolean parentFound = false;
                if (!row.isNull("activityId")) {
                    Integer activityId = row.getInt("activityId");
                    lockedPeriod.setParentId(activityId);
                    lockedPeriod.setParentType(activity.getEntityName());
                    parentFound = true;
                }
                if (!row.isNull("userDatabaseId")) {
                    Integer databaseId = row.getInt("userDatabaseId");
                    lockedPeriod.setParentId(databaseId);
                    lockedPeriod.setParentType(db.getEntityName());
                    parentFound = true;
                }
                if (!row.isNull("projectID")) {
                    Integer projectId = row.getInt("projectId");
                    lockedPeriod.setParentId(projectId);
                    lockedPeriod.setParentType(project.getEntityName());
                    parentFound = true;
                }
                if (!parentFound) {
                    Log.debug("Orphan lockedPeriod: No parent (UserDatabase/Activity/Project) found for LockedPeriod with Id=" + lockedPeriod.getId());
                }
                lockedPeriods.add(lockedPeriod);
            }
            callback.onSuccess(new LockedPeriodsResult(lockedPeriods));
        }
    });
}
Also used : ProjectDTO(org.activityinfo.shared.dto.ProjectDTO) UserDatabaseDTO(org.activityinfo.shared.dto.UserDatabaseDTO) SqlTransaction(com.bedatadriven.rebar.sql.client.SqlTransaction) SqlResultSetRow(com.bedatadriven.rebar.sql.client.SqlResultSetRow) ActivityDTO(org.activityinfo.shared.dto.ActivityDTO) LockedPeriodDTO(org.activityinfo.shared.dto.LockedPeriodDTO) RowHandler(com.bedatadriven.rebar.sql.client.util.RowHandler) SqlResultSet(com.bedatadriven.rebar.sql.client.SqlResultSet) LockedPeriodsResult(org.activityinfo.shared.command.GetLockedPeriods.LockedPeriodsResult) SqlResultCallback(com.bedatadriven.rebar.sql.client.SqlResultCallback)

Example 5 with LockedPeriodDTO

use of org.activityinfo.shared.dto.LockedPeriodDTO in project activityinfo by bedatadriven.

the class LockedPeriodTest method createTest.

@Test
@OnDataSet("/dbunit/sites-simple1.db.xml")
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.setUserDatabaseId(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.shared.command.result.CreateResult) UpdateEntity(org.activityinfo.shared.command.UpdateEntity) LocalDate(com.bedatadriven.rebar.time.calendar.LocalDate) CreateLockedPeriod(org.activityinfo.shared.command.CreateLockedPeriod) LockedPeriodDTO(org.activityinfo.shared.dto.LockedPeriodDTO) OnDataSet(org.activityinfo.server.database.OnDataSet) Test(org.junit.Test)

Aggregations

LockedPeriodDTO (org.activityinfo.shared.dto.LockedPeriodDTO)9 ArrayList (java.util.ArrayList)3 CreateLockedPeriod (org.activityinfo.shared.command.CreateLockedPeriod)3 CreateResult (org.activityinfo.shared.command.result.CreateResult)3 ActivityDTO (org.activityinfo.shared.dto.ActivityDTO)3 ProjectDTO (org.activityinfo.shared.dto.ProjectDTO)3 UserDatabaseDTO (org.activityinfo.shared.dto.UserDatabaseDTO)2 SqlResultCallback (com.bedatadriven.rebar.sql.client.SqlResultCallback)1 SqlResultSet (com.bedatadriven.rebar.sql.client.SqlResultSet)1 SqlResultSetRow (com.bedatadriven.rebar.sql.client.SqlResultSetRow)1 SqlTransaction (com.bedatadriven.rebar.sql.client.SqlTransaction)1 RowHandler (com.bedatadriven.rebar.sql.client.util.RowHandler)1 LocalDate (com.bedatadriven.rebar.time.calendar.LocalDate)1 ComponentEvent (com.extjs.gxt.ui.client.event.ComponentEvent)1 Record (com.extjs.gxt.ui.client.store.Record)1 ColumnConfig (com.extjs.gxt.ui.client.widget.grid.ColumnConfig)1 ColumnModel (com.extjs.gxt.ui.client.widget.grid.ColumnModel)1 Date (java.util.Date)1 EditCheckColumnConfig (org.activityinfo.client.page.common.columns.EditCheckColumnConfig)1 EditableLocalDateColumn (org.activityinfo.client.page.common.columns.EditableLocalDateColumn)1