Search in sources :

Example 1 with IManager

use of org.jaffa.loader.IManager in project jaffa-framework by jaffa-projects.

the class ConfigApiHelper method unregisterResources.

/**
 * Unregister configuration files in IManager implementations, based on the source of the method call
 * @param file  The configuration file to be registered or unregistered
 * @return  Success or failure of the operation
 */
public static boolean unregisterResources(File file, FileContentsHelper fileContents) {
    boolean isSuccess = true;
    ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    for (IManager manager : ManagerRepositoryService.getInstance().getManagerMap().values()) {
        Resource resource = getMetaInfResource(file, resolver, manager);
        try {
            if (resource.getFile().exists()) {
                manager.unregisterResource(resource, fileContents.getContextSalience(), fileContents.getVariationSalience());
                log.debug(resource.getFilename() + " was successfully unregistered from " + manager);
            }
        } catch (Exception e) {
            isSuccess = false;
            log.warn("The resource " + resource.getFilename() + " failed to unregister", e);
        }
    }
    return isSuccess;
}
Also used : PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) ResourcePatternResolver(org.springframework.core.io.support.ResourcePatternResolver) IManager(org.jaffa.loader.IManager) Resource(org.springframework.core.io.Resource) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver)

Example 2 with IManager

use of org.jaffa.loader.IManager in project jaffa-framework by jaffa-projects.

the class ConfigApiHelper method registerResources.

/**
 * Register configuration files in IManager implementationss, based on the source of the method call
 * @param file  The configuration file to be registered or unregistered
 * @return  Success or failure of the operation
 */
public static boolean registerResources(File file, FileContentsHelper fileContents) {
    boolean isSuccess = true;
    ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    for (IManager manager : ManagerRepositoryService.getInstance().getManagerMap().values()) {
        Resource resource = getMetaInfResource(file, resolver, manager);
        try {
            if (resource.getFile().exists()) {
                if (manager instanceof RoleManager) {
                    PolicyManager.clearCache();
                }
                manager.registerResource(resource, fileContents.getContextSalience(), fileContents.getVariationSalience());
                ManagerRepositoryService.getInstance().add(manager.getClass().getSimpleName(), manager);
                log.debug(resource.getFilename() + " was successfully registered to " + manager);
            }
        } catch (Exception e) {
            isSuccess = false;
            log.error("The resource " + resource.getFilename() + " failed to register", e);
        }
    }
    return isSuccess;
}
Also used : PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) ResourcePatternResolver(org.springframework.core.io.support.ResourcePatternResolver) IManager(org.jaffa.loader.IManager) RoleManager(org.jaffa.loader.policy.RoleManager) Resource(org.springframework.core.io.Resource) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver)

Aggregations

IManager (org.jaffa.loader.IManager)2 Resource (org.springframework.core.io.Resource)2 PathMatchingResourcePatternResolver (org.springframework.core.io.support.PathMatchingResourcePatternResolver)2 ResourcePatternResolver (org.springframework.core.io.support.ResourcePatternResolver)2 RoleManager (org.jaffa.loader.policy.RoleManager)1