/*
 * Copyright (c) 2013 Lucas Holt
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

package com.justjournal.ctl;

import com.justjournal.WebLogin;
import com.justjournal.db.RssSubscriptionsDAO;
import com.justjournal.db.RssSubscriptionsTO;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.Map;

/**
 * @author Lucas Holt
 */
@Controller
@RequestMapping("/json/RssReader.json")
public class RssReader {
    private static final Logger log = Logger.getLogger(RssReader.class);

    @RequestMapping(method = RequestMethod.PUT)
    public
    @ResponseBody
    Map<String, String> create(@RequestBody String uri, HttpSession session, HttpServletResponse response) {

        try {
            RssSubscriptionsDAO dao = new RssSubscriptionsDAO();
            RssSubscriptionsTO to = new RssSubscriptionsTO();
            boolean result;

            if (uri == null || uri.length() < 10 || uri.length() > 1024) {
                response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
                return java.util.Collections.singletonMap("error", "Error adding link.");
            }
            to.setId(WebLogin.currentLoginId(session));
            to.setUri(uri);
            result = dao.add(to);

            if (!result) {
                response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
                return java.util.Collections.singletonMap("error", "Error adding link.");
            }
            return java.util.Collections.singletonMap("id", ""); // XXX
        } catch (Exception e) {
            log.error(e);
            response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
            return java.util.Collections.singletonMap("error", "Error adding link.");
        }
    }
}

@@ -2325,73 +2325,8 @@
 y %7B%0A
-            RssSubscriptionsDAO dao = new RssSubscriptionsDAO();%0A
     
@@ -2383,16 +2383,16 @@
 nsTO();%0A
+
         
@@ -2772,11 +2772,27 @@
 t = 
-dao
+RssSubscriptionsDAO
 .add
@@ -3277,32 +3277,32 @@
 adding link.%22);%0A
-
         %7D%0A    %7D%0A
@@ -3300,11 +3300,1140 @@
  %7D%0A    %7D
+%0A%0A    @RequestMapping(method = RequestMethod.DELETE)%0A    public%0A    @ResponseBody%0A    Map%3CString, String%3E delete(@RequestBody int subId, HttpSession session, HttpServletResponse response) throws Exception %7B%0A        if (!WebLogin.isAuthenticated(session)) %7B%0A            response.setStatus(HttpServletResponse.SC_BAD_REQUEST);%0A            return java.util.Collections.singletonMap(%22error%22, %22The login timed out or is invalid.%22);%0A        %7D%0A%0A        if (subId %3E 0) %7B%0A            RssSubscriptionsTO to = new RssSubscriptionsTO();%0A            to.setId(WebLogin.currentLoginId(session));%0A            to.setSubscriptionId(subId);%0A%0A            if (RssSubscriptionsDAO.delete(to)) %7B%0A                return java.util.Collections.singletonMap(%22id%22, Integer.toString(subId));%0A            %7D%0A            response.setStatus(HttpServletResponse.SC_BAD_REQUEST);%0A            return java.util.Collections.singletonMap(%22error%22, %22Error deleting the subscription.%22);%0A        %7D%0A%0A        response.setStatus(HttpServletResponse.SC_BAD_REQUEST);%0A        return java.util.Collections.singletonMap(%22error%22, %22Error deleting the subscription. Bad id.%22);%0A    %7D
 %0A%7D%0A

use static Dao methods. add delete.