Search in sources :

Example 1 with LockedPeriodDTO

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;
}
Also used : ArrayList(java.util.ArrayList) Record(com.extjs.gxt.ui.client.store.Record) LockedPeriodDTO(org.activityinfo.legacy.shared.model.LockedPeriodDTO)

Example 2 with LockedPeriodDTO

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));
}
Also used : DatabaseProviderImpl(org.activityinfo.server.endpoint.rest.DatabaseProviderImpl) RecordLock(org.activityinfo.model.database.RecordLock) LockedPeriodSet(org.activityinfo.legacy.shared.model.LockedPeriodSet) LocalDate(com.bedatadriven.rebar.time.calendar.LocalDate) SchemaDTO(org.activityinfo.legacy.shared.model.SchemaDTO) GetSchema(org.activityinfo.legacy.shared.command.GetSchema) UserDatabaseMeta(org.activityinfo.model.database.UserDatabaseMeta) CreateLockedPeriod(org.activityinfo.legacy.shared.command.CreateLockedPeriod) LockedPeriodDTO(org.activityinfo.legacy.shared.model.LockedPeriodDTO) Test(org.junit.Test)

Example 3 with LockedPeriodDTO

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));
}
Also used : CreateResult(org.activityinfo.legacy.shared.command.result.CreateResult) UpdateEntity(org.activityinfo.legacy.shared.command.UpdateEntity) LocalDate(com.bedatadriven.rebar.time.calendar.LocalDate) CreateLockedPeriod(org.activityinfo.legacy.shared.command.CreateLockedPeriod) LockedPeriodDTO(org.activityinfo.legacy.shared.model.LockedPeriodDTO) Test(org.junit.Test)

Example 4 with LockedPeriodDTO

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());
}
Also used : CreateResult(org.activityinfo.legacy.shared.command.result.CreateResult) CommandException(org.activityinfo.legacy.shared.exception.CommandException) CreateLockedPeriod(org.activityinfo.legacy.shared.command.CreateLockedPeriod) Date(java.util.Date) LockedPeriodDTO(org.activityinfo.legacy.shared.model.LockedPeriodDTO)

Example 5 with LockedPeriodDTO

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);
}
Also used : ReadTextColumn(org.activityinfo.ui.client.page.common.columns.ReadTextColumn) ArrayList(java.util.ArrayList) EditableLocalDateColumn(org.activityinfo.ui.client.page.common.columns.EditableLocalDateColumn) LocalDate(com.bedatadriven.rebar.time.calendar.LocalDate) LockedPeriodDTO(org.activityinfo.legacy.shared.model.LockedPeriodDTO)

Aggregations

LockedPeriodDTO (org.activityinfo.legacy.shared.model.LockedPeriodDTO)5 LocalDate (com.bedatadriven.rebar.time.calendar.LocalDate)3 CreateLockedPeriod (org.activityinfo.legacy.shared.command.CreateLockedPeriod)3 ArrayList (java.util.ArrayList)2 CreateResult (org.activityinfo.legacy.shared.command.result.CreateResult)2 Test (org.junit.Test)2 Record (com.extjs.gxt.ui.client.store.Record)1 Date (java.util.Date)1 GetSchema (org.activityinfo.legacy.shared.command.GetSchema)1 UpdateEntity (org.activityinfo.legacy.shared.command.UpdateEntity)1 CommandException (org.activityinfo.legacy.shared.exception.CommandException)1 LockedPeriodSet (org.activityinfo.legacy.shared.model.LockedPeriodSet)1 SchemaDTO (org.activityinfo.legacy.shared.model.SchemaDTO)1 RecordLock (org.activityinfo.model.database.RecordLock)1 UserDatabaseMeta (org.activityinfo.model.database.UserDatabaseMeta)1 DatabaseProviderImpl (org.activityinfo.server.endpoint.rest.DatabaseProviderImpl)1 EditableLocalDateColumn (org.activityinfo.ui.client.page.common.columns.EditableLocalDateColumn)1 ReadTextColumn (org.activityinfo.ui.client.page.common.columns.ReadTextColumn)1