@@ -0,0 +1,3420 @@
+/*%0A Created as part of the StratusLab project (http://stratuslab.eu),%0A co-funded by the European Commission under the Grant Agreement%0A INFSO-RI-261552.%0A%0A Copyright (c) 2011, Centre National de la Recherche Scientifique (CNRS)%0A%0A Licensed under the Apache License, Version 2.0 (the %22License%22);%0A you may not use this file except in compliance with the License.%0A You may obtain a copy of the License at%0A%0A http://www.apache.org/licenses/LICENSE-2.0%0A%0A Unless required by applicable law or agreed to in writing, software%0A distributed under the License is distributed on an %22AS IS%22 BASIS,%0A WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A See the License for the specific language governing permissions and%0A limitations under the License.%0A */%0Apackage eu.stratuslab.registration.data;%0A%0Aimport java.util.UUID;%0Aimport java.util.logging.Logger;%0A%0Aimport javax.naming.Context;%0Aimport javax.naming.NameAlreadyBoundException;%0Aimport javax.naming.NamingException;%0Aimport javax.naming.directory.DirContext;%0Aimport javax.naming.directory.InitialDirContext;%0A%0Aimport org.restlet.data.Status;%0Aimport org.restlet.resource.ResourceException;%0A%0Aimport eu.stratuslab.registration.actions.Action;%0Aimport eu.stratuslab.registration.utils.LdapConfig;%0A%0Apublic final class ActionEntry %7B%0A%0A    private static final String DATABASE_CONNECT_ERROR = %22error contacting database%22;%0A%0A    private static final Logger LOGGER = Logger.getLogger(%22org.restlet%22);%0A%0A    private ActionEntry() %7B%0A%0A    %7D%0A%0A    public static String storeAction(Action action, LdapConfig ldapEnv) %7B%0A%0A        String uuid = UUID.randomUUID().toString();%0A        String dn = %22cn=%22 + uuid;%0A%0A        // Get a connection from the pool.%0A        DirContext ctx = null;%0A%0A        try %7B%0A%0A            ctx = new InitialDirContext(ldapEnv);%0A%0A            ctx.bind(dn, action);%0A%0A        %7D catch (NameAlreadyBoundException e) %7B%0A%0A            e.printStackTrace();%0A            throw new ResourceException(Status.SERVER_ERROR_INTERNAL,%0A                    %22entry exists: %22 + dn);%0A%0A        %7D catch (NamingException e) %7B%0A%0A            e.printStackTrace();%0A            throw new ResourceException(Status.SERVER_ERROR_INTERNAL,%0A                    DATABASE_CONNECT_ERROR);%0A%0A        %7D finally %7B%0A            freeContext(ctx);%0A        %7D%0A%0A        return uuid;%0A%0A    %7D%0A%0A    public static Action retrieveAction(String uuid, LdapConfig ldapEnv) %7B%0A%0A        String dn = %22cn=%22 + uuid;%0A%0A        // Get a connection from the pool.%0A        DirContext ctx = null;%0A%0A        try %7B%0A%0A            ctx = new InitialDirContext(ldapEnv);%0A%0A            Action action = (Action) ctx.lookup(dn);%0A%0A            try %7B%0A                ctx.destroySubcontext(dn);%0A            %7D catch (NamingException e) %7B%0A                LOGGER.warning(%22cannot delete action (%22 + dn + %22): %22%0A                        + e.getMessage());%0A            %7D%0A%0A            return action;%0A%0A        %7D catch (NamingException e) %7B%0A%0A            e.printStackTrace();%0A            throw new ResourceException(Status.SERVER_ERROR_INTERNAL,%0A                    DATABASE_CONNECT_ERROR);%0A%0A        %7D finally %7B%0A            freeContext(ctx);%0A        %7D%0A%0A    %7D%0A%0A    private static void freeContext(Context ctx) %7B%0A        if (ctx != null) %7B%0A            try %7B%0A                ctx.close();%0A            %7D catch (NamingException e) %7B%0A                LOGGER.warning(%22cannot free directory context: %22%0A                        + e.getMessage());%0A            %7D%0A        %7D%0A    %7D%0A%0A%7D%0A

split actions into separate class