use of org.activityinfo.legacy.shared.model.LockedPeriodDTO in project activityinfo by bedatadriven.
the class LockedPeriodGrid method getUnsavedItems.
@Override
public List<LockedPeriodDTO> getUnsavedItems() {
List<LockedPeriodDTO> unsavedItems = new ArrayList<>();
List<Record> modifiedRecords = lockedPeriodStore.getModifiedRecords();
for (Record record : modifiedRecords) {
unsavedItems.add((LockedPeriodDTO) record.getModel());
}
return unsavedItems;
}
use of org.activityinfo.legacy.shared.model.LockedPeriodDTO in project activityinfo by bedatadriven.
the class LockedPeriodTest method createForFolder.
@Test
public void createForFolder() {
setUser(1);
LockedPeriodDTO dto = new LockedPeriodDTO();
dto.setName("NFI ");
dto.setFromDate(new LocalDate(2011, 1, 1));
dto.setToDate(new LocalDate(2011, 1, 31));
dto.setEnabled(true);
CreateLockedPeriod create = new CreateLockedPeriod(dto);
create.setFolderId(1);
execute(create);
// Now verify that they appear
SchemaDTO schema = execute(new GetSchema());
assertThat(schema.getDatabaseById(1).getFolderById(1).getLockedPeriods(), Matchers.hasSize(1));
LockedPeriodSet locks = new LockedPeriodSet(schema);
assertTrue(locks.isActivityLocked(1, new LocalDate(2011, 1, 1)));
// Verify that the new code works too...
DatabaseProviderImpl provider = new DatabaseProviderImpl(Providers.of(em));
UserDatabaseMeta metadata = provider.getDatabaseMetadata(CuidAdapter.databaseId(1), 1);
ArrayList<RecordLock> folderLocks = Lists.newArrayList(metadata.getEffectiveLocks(CuidAdapter.folderId(1)));
ArrayList<RecordLock> formLocks = Lists.newArrayList(metadata.getEffectiveLocks(CuidAdapter.activityFormClass(1)));
assertThat(folderLocks, Matchers.hasSize(2));
assertThat(formLocks, Matchers.hasSize(3));
}
use of org.activityinfo.legacy.shared.model.LockedPeriodDTO in project activityinfo by bedatadriven.
the class LockedPeriodTest method createTest.
@Test
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.setDatabaseId(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));
}
use of org.activityinfo.legacy.shared.model.LockedPeriodDTO in project activityinfo by bedatadriven.
the class CreateLockedPeriodHandler method execute.
@Override
public CommandResult execute(CreateLockedPeriod cmd, User user) {
Activity activity;
Database database;
Project project;
Folder folder;
LockedPeriod lockedPeriod = new LockedPeriod();
LockedPeriodDTO lockedPeriodDTO = cmd.getLockedPeriod();
lockedPeriod.setFromDate(lockedPeriodDTO.getFromDate().atMidnightInMyTimezone());
lockedPeriod.setToDate(lockedPeriodDTO.getToDate().atMidnightInMyTimezone());
lockedPeriod.setName(lockedPeriodDTO.getName());
lockedPeriod.setEnabled(lockedPeriodDTO.isEnabled());
int databaseId;
if (cmd.getDatabaseId() != 0) {
database = em.find(Database.class, cmd.getDatabaseId());
lockedPeriod.setDatabase(database);
databaseId = database.getId();
permissionOracle.assertDesignPrivileges(database, user);
} else if (cmd.getProjectId() != 0) {
project = em.find(Project.class, cmd.getProjectId());
lockedPeriod.setProject(project);
lockedPeriod.setDatabase(project.getDatabase());
databaseId = project.getDatabase().getId();
permissionOracle.assertDesignPrivileges(project.getDatabase(), user);
} else if (cmd.getActivityId() != 0) {
activity = em.find(Activity.class, cmd.getActivityId());
lockedPeriod.setActivity(activity);
lockedPeriod.setDatabase(activity.getDatabase());
databaseId = activity.getDatabase().getId();
permissionOracle.assertDesignPrivileges(activity, user);
} else if (cmd.getFolderId() != 0) {
folder = em.find(Folder.class, cmd.getFolderId());
lockedPeriod.setFolder(folder);
lockedPeriod.setDatabase(folder.getDatabase());
databaseId = folder.getDatabase().getId();
permissionOracle.assertDesignPrivileges(folder, user);
} else {
throw new CommandException("One of the following must be provided: userDatabaseId, projectId, activityId, folderId");
}
Database db = em.find(Database.class, databaseId);
em.persist(lockedPeriod);
db.setLastSchemaUpdate(new Date());
em.persist(db);
return new CreateResult(lockedPeriod.getId());
}
use of org.activityinfo.legacy.shared.model.LockedPeriodDTO in project activityinfo by bedatadriven.
the class LockedPeriodGrid method createGrid.
private void createGrid() {
List<ColumnConfig> configs = new ArrayList<>();
columnEnabled = new EditCheckColumnConfig("enabled", I18N.CONSTANTS.enabledColumn(), 55);
columnEnabled.setSortable(false);
ColumnConfig columnPeriodType = new ColumnConfig();
columnPeriodType.setHeaderText(I18N.CONSTANTS.type());
columnPeriodType.setToolTip(I18N.CONSTANTS.type());
columnPeriodType.setWidth(48);
columnPeriodType.setRowHeader(true);
columnPeriodType.setRenderer(new LockTypeIconCellRenderer());
configs.add(columnEnabled);
configs.add(columnPeriodType);
configs.add(new ReadTextColumn("parentName", I18N.CONSTANTS.parentName(), 150));
configs.add(new ReadTextColumn("name", I18N.CONSTANTS.name(), 100));
configs.add(new EditableLocalDateColumn("fromDate", I18N.CONSTANTS.fromDate(), 100));
configs.add(new EditableLocalDateColumn("toDate", I18N.CONSTANTS.toDate(), 100));
lockedPeriodGrid = new EditorGrid<>(lockedPeriodStore, new ColumnModel(configs));
lockedPeriodGrid.addListener(Events.ValidateEdit, new Listener<BaseEvent>() {
@Override
public void handleEvent(BaseEvent baseEvent) {
GridEvent gridEvent = (GridEvent) baseEvent;
LockedPeriodDTO model = (LockedPeriodDTO) gridEvent.getModel();
LocalDate fromDate = model.getFromDate();
LocalDate toDate = model.getToDate();
if ("fromDate".equals(gridEvent.getProperty())) {
fromDate = (LocalDate) gridEvent.getValue();
}
if ("toDate".equals(gridEvent.getProperty())) {
toDate = (LocalDate) gridEvent.getValue();
}
if (!fromDate.before(toDate) && !fromDate.equals(toDate)) {
MessageBox.alert(I18N.CONSTANTS.alert(), I18N.CONSTANTS.fromDateIsBeforeToDate(), null);
lockedPeriodGrid.getActiveEditor().cancelEdit();
}
}
});
lockedPeriodGrid.addListener(Events.OnClick, new Listener<ComponentEvent>() {
@Override
public void handleEvent(ComponentEvent be) {
updateState(be);
}
});
add(lockedPeriodGrid);
}
Aggregations