Search in sources :

Example 1 with Configuration

use of com.generallycloud.baseio.container.configuration.Configuration in project baseio by generallycloud.

the class FutureAcceptorFilterLoader method loadFilters.

private FutureAcceptorFilterWrapper loadFilters(ApplicationContext context, DynamicClassLoader classLoader) throws IOException, InstantiationException, IllegalAccessException, ClassNotFoundException {
    List<Configuration> filterConfigurations = configuration.getFilters();
    List<FutureAcceptorFilter> acceptorFilters = this.acceptorFilters;
    acceptorFilters.add(serviceFilter);
    if (filterConfigurations == null || filterConfigurations.isEmpty()) {
        LoggerUtil.prettyLog(logger, "did not found filter config");
        filterConfigurations = new ArrayList<>();
    }
    FutureAcceptorFilterWrapper rootFilter = null;
    FutureAcceptorFilterWrapper last = null;
    for (int i = 0; i < filterConfigurations.size(); i++) {
        Configuration filterConfig = filterConfigurations.get(i);
        String clazzName = filterConfig.getParameter("class", "empty");
        FutureAcceptorFilter filter = (FutureAcceptorFilter) classLoader.loadClass(clazzName).newInstance();
        filter.setConfig(filterConfig);
        int sortIndex = filterConfig.getIntegerParameter("sortIndex", 999);
        filter.setSortIndex(sortIndex);
        acceptorFilters.add(filter);
    }
    Collections.sort(acceptorFilters, new Comparator<FutureAcceptorFilter>() {

        @Override
        public int compare(FutureAcceptorFilter o1, FutureAcceptorFilter o2) {
            int i1 = o1.getSortIndex();
            int i2 = o2.getSortIndex();
            if (i1 == i2) {
                return 0;
            }
            return i1 > i2 ? 1 : -1;
        }
    });
    for (int i = 0; i < acceptorFilters.size(); i++) {
        FutureAcceptorFilter filter = acceptorFilters.get(i);
        FutureAcceptorFilterWrapper _filter = new FutureAcceptorFilterWrapper(context, filter, filter.getConfig());
        if (last == null) {
            last = _filter;
            rootFilter = _filter;
        } else {
            last.setNext(_filter);
            last = _filter;
        }
    }
    return rootFilter;
}
Also used : FiltersConfiguration(com.generallycloud.baseio.container.configuration.FiltersConfiguration) Configuration(com.generallycloud.baseio.container.configuration.Configuration)

Example 2 with Configuration

use of com.generallycloud.baseio.container.configuration.Configuration in project baseio by generallycloud.

the class RoleManager method initialize.

@Override
public void initialize(ApplicationContext context, Configuration config) throws Exception {
    ApplicationConfigurationLoader acLoader = context.getAcLoader();
    PermissionConfiguration permissionConfiguration = acLoader.loadPermissionConfiguration(getClass().getClassLoader());
    List<Configuration> permissionConfigurations = permissionConfiguration.getPermissions();
    List<Configuration> roleConfigurations = permissionConfiguration.getRoles();
    if (permissionConfigurations == null || permissionConfigurations.size() == 0 || roleConfigurations == null || roleConfigurations.size() == 0) {
        throw new Error("没有加载到角色配置");
    }
    IntObjectHashMap<Permission> permissions = new IntObjectHashMap<>();
    for (Configuration c : permissionConfigurations) {
        Permission p = new Permission();
        p.setDescription(c.getParameter("description"));
        p.setFrequency(c.getIntegerParameter("frequency"));
        p.setPermissionAPI(c.getParameter("permissionAPI"));
        p.setPermissionId(c.getIntegerParameter("permissionId"));
        permissions.put(p.getPermissionId(), p);
    }
    IntObjectHashMap<Role> roles = new IntObjectHashMap<>();
    List<Role> roleList = new ArrayList<>();
    for (Configuration c : roleConfigurations) {
        Role r = new Role();
        r.setDescription(c.getParameter("description"));
        r.setRoleId(c.getIntegerParameter("roleId"));
        r.setRoleName(c.getParameter("roleName"));
        JSONArray array = c.getJSONArray("children");
        if (array != null && !array.isEmpty()) {
            List<Integer> _children = new ArrayList<>();
            for (int i = 0; i < array.size(); i++) {
                _children.add(array.getInteger(i));
            }
            r.setChildren(_children);
        }
        array = c.getJSONArray("permissions");
        if (array != null && !array.isEmpty()) {
            List<Integer> _permissions = new ArrayList<>();
            for (int i = 0; i < array.size(); i++) {
                _permissions.add(array.getInteger(i));
            }
            r.setPermissions(_permissions);
        }
        roles.put(r.getRoleId(), r);
        roleList.add(r);
    }
    reflectPermission(roleList, roles, permissions);
}
Also used : PermissionConfiguration(com.generallycloud.baseio.container.configuration.PermissionConfiguration) Configuration(com.generallycloud.baseio.container.configuration.Configuration) IntObjectHashMap(com.generallycloud.baseio.collection.IntObjectHashMap) ArrayList(java.util.ArrayList) JSONArray(com.alibaba.fastjson.JSONArray) PermissionConfiguration(com.generallycloud.baseio.container.configuration.PermissionConfiguration) ApplicationConfigurationLoader(com.generallycloud.baseio.container.configuration.ApplicationConfigurationLoader)

Aggregations

Configuration (com.generallycloud.baseio.container.configuration.Configuration)2 JSONArray (com.alibaba.fastjson.JSONArray)1 IntObjectHashMap (com.generallycloud.baseio.collection.IntObjectHashMap)1 ApplicationConfigurationLoader (com.generallycloud.baseio.container.configuration.ApplicationConfigurationLoader)1 FiltersConfiguration (com.generallycloud.baseio.container.configuration.FiltersConfiguration)1 PermissionConfiguration (com.generallycloud.baseio.container.configuration.PermissionConfiguration)1 ArrayList (java.util.ArrayList)1