use of org.activityinfo.legacy.shared.command.CreateLockedPeriod 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.command.CreateLockedPeriod 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.command.CreateLockedPeriod 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());
}
Aggregations