Search in sources :

Example 1 with AccessConfig

use of com.axelor.apps.base.db.AccessConfig in project axelor-open-suite by axelor.

the class AccessConfigImportServiceImpl method getAccessConfig.

@Transactional
public Map<Integer, AccessConfig> getAccessConfig(Row row, App app) {
    Map<Integer, AccessConfig> configMap = new HashMap<>();
    Iterator<Cell> cellIter = row.iterator();
    cellIter.next();
    while (cellIter.hasNext()) {
        Cell cell = cellIter.next();
        String name = cell.getStringCellValue();
        if (name != null) {
            AccessConfig config = accessConfigRepo.all().filter("self.name = ?1 and self.app = ?2", name, app).fetchOne();
            if (config == null) {
                config = new AccessConfig(name);
                config.setApp(app);
                config = accessConfigRepo.save(config);
            }
            configMap.put(cell.getColumnIndex(), config);
        }
    }
    return configMap;
}
Also used : HashMap(java.util.HashMap) AccessConfig(com.axelor.apps.base.db.AccessConfig) Cell(org.apache.poi.ss.usermodel.Cell) Transactional(com.google.inject.persist.Transactional)

Example 2 with AccessConfig

use of com.axelor.apps.base.db.AccessConfig in project axelor-open-suite by axelor.

the class AccessConfigImportServiceImpl method createMenuRoles.

private void createMenuRoles(Map<Integer, AccessConfig> accessMap, Row row) {
    Iterator<Cell> cellIter = row.iterator();
    String menu = cellIter.next().getStringCellValue().trim();
    while (cellIter.hasNext()) {
        Cell cell = cellIter.next();
        String value = cell.getStringCellValue();
        if (Strings.isNullOrEmpty(value)) {
            continue;
        }
        AccessConfig config = accessMap.get(cell.getColumnIndex());
        addRole(config, menu);
    }
}
Also used : AccessConfig(com.axelor.apps.base.db.AccessConfig) Cell(org.apache.poi.ss.usermodel.Cell)

Example 3 with AccessConfig

use of com.axelor.apps.base.db.AccessConfig in project axelor-open-suite by axelor.

the class AccessConfigImportServiceImpl method importMenuAccess.

private void importMenuAccess(XSSFSheet sheet) {
    App app = Beans.get(AppRepository.class).findByCode(sheet.getSheetName().split("-")[0]);
    if (app == null) {
        return;
    }
    Iterator<Row> rowIter = sheet.iterator();
    Map<Integer, AccessConfig> accessMap = null;
    while (rowIter.hasNext()) {
        if (accessMap == null) {
            accessMap = getAccessConfig(rowIter.next(), app);
            continue;
        }
        createMenuRoles(accessMap, rowIter.next());
    }
}
Also used : App(com.axelor.apps.base.db.App) AppRepository(com.axelor.apps.base.db.repo.AppRepository) Row(org.apache.poi.ss.usermodel.Row) AccessConfig(com.axelor.apps.base.db.AccessConfig)

Example 4 with AccessConfig

use of com.axelor.apps.base.db.AccessConfig in project axelor-open-suite by axelor.

the class AccessConfigImportServiceImpl method importObjectAccess.

private void importObjectAccess(XSSFSheet sheet) {
    App app = Beans.get(AppRepository.class).findByCode(sheet.getSheetName());
    if (app == null) {
        return;
    }
    Iterator<Row> rowIter = sheet.iterator();
    Map<Integer, AccessConfig> accessMap = null;
    while (rowIter.hasNext()) {
        if (accessMap == null) {
            accessMap = getAccessConfig(rowIter.next(), app);
            continue;
        }
        createObjectRoles(accessMap, rowIter.next());
    }
}
Also used : App(com.axelor.apps.base.db.App) AppRepository(com.axelor.apps.base.db.repo.AppRepository) Row(org.apache.poi.ss.usermodel.Row) AccessConfig(com.axelor.apps.base.db.AccessConfig)

Example 5 with AccessConfig

use of com.axelor.apps.base.db.AccessConfig in project axelor-open-suite by axelor.

the class AccessConfigImportServiceImpl method createObjectRoles.

private void createObjectRoles(Map<Integer, AccessConfig> accessMap, Row row) {
    Iterator<Cell> cellIter = row.iterator();
    String obj = cellIter.next().getStringCellValue();
    while (cellIter.hasNext()) {
        Cell cell = cellIter.next();
        String value = cell.getStringCellValue();
        if (Strings.isNullOrEmpty(value) || invalidValue(value)) {
            continue;
        }
        AccessConfig config = accessMap.get(cell.getColumnIndex());
        Permission permission = getPermission(obj, value.trim(), config);
        addRole(config, permission);
    }
}
Also used : Permission(com.axelor.auth.db.Permission) AccessConfig(com.axelor.apps.base.db.AccessConfig) Cell(org.apache.poi.ss.usermodel.Cell)

Aggregations

AccessConfig (com.axelor.apps.base.db.AccessConfig)5 Cell (org.apache.poi.ss.usermodel.Cell)3 App (com.axelor.apps.base.db.App)2 AppRepository (com.axelor.apps.base.db.repo.AppRepository)2 Row (org.apache.poi.ss.usermodel.Row)2 Permission (com.axelor.auth.db.Permission)1 Transactional (com.google.inject.persist.Transactional)1 HashMap (java.util.HashMap)1