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;
}
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);
}
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);
}
});
}
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));
}
});
}
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));
}
Aggregations