view flys-client/src/main/java/de/intevation/flys/client/server/ModuleServiceImpl.java @ 3515:70c0942156ad

Add service to list available modules for a user The new service returns a list of modules that a user is allowed to access. flys-client/trunk@5289 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Bjoern Ricks <bjoern.ricks@intevation.de>
date Wed, 29 Aug 2012 10:43:36 +0000
parents
children 40ddd713d9fd
line wrap: on
line source
package de.intevation.flys.client.server;

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;

import de.intevation.flys.client.client.FLYSConstants;
import de.intevation.flys.client.client.services.ModuleService;
import de.intevation.flys.client.server.auth.User;
import de.intevation.flys.client.shared.model.DefaultModule;
import de.intevation.flys.client.shared.model.Module;

public class ModuleServiceImpl
extends      RemoteServiceServlet
implements   ModuleService
{
    private static final Logger logger =
        Logger.getLogger(ModuleServiceImpl.class);

    /** Constant value for the WINFO plugin.*/
    public static final String FIELD_PLUGIN_WINFO = "winfo";

    /** Constant value for the MINFO plugin.*/
    public static final String FIELD_PLUGIN_MINFO = "minfo";

    /** Constant value for the MAP plugin.*/
    public static final String FIELD_PLUGIN_MAP   = "new_map";

    /** Constant value for the CHART plugin.*/
    public static final String FIELD_PLUGIN_CHART = "new_chart";

    /** Constant value for the FIX plugin.*/
    public static final String FIELD_PLUGIN_FIX   = "fixanalysis";

    @Override
    public Module[] list(String locale) {
        User user = this.getUser();

        //TODO load modules from artifactserver
        Module[] available = {
            new DefaultModule(FIELD_PLUGIN_WINFO, "WINFO"),
            new DefaultModule(FIELD_PLUGIN_MINFO, "MINFO"),
            new DefaultModule(FIELD_PLUGIN_MAP,   "MAP"),
            new DefaultModule(FIELD_PLUGIN_CHART, "CHART"),
            new DefaultModule(FIELD_PLUGIN_FIX,   "FIX")
        };

        List<Module> modules = new ArrayList<Module>(available.length);
        for(Module module : available) {
            if (user == null || user.canUseFeature("module:" + module.getName())) {
                modules.add(module);
            }
        }
        return modules.toArray(new Module[modules.size()]);
    }
}

// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 tw=80 :

http://dive4elements.wald.intevation.org