4 import java.util.HashMap;
5 import java.util.LinkedHashMap;
7 import org.slf4j.Logger;
8 import org.slf4j.LoggerFactory;
9 import org.springframework.stereotype.Controller;
10 import org.springframework.web.bind.annotation.ModelAttribute;
11 import org.springframework.web.bind.annotation.RequestMapping;
12 import org.springframework.web.bind.annotation.RequestParam;
20 public class DemoController
22 private static final Logger LOG =
23 LoggerFactory.getLogger(DemoController.class);
26 @RequestMapping(path = "/", params = { "!card", "!add", "!remove" })
27 public String display(@ModelAttribute Form form)
29 for (Integer id : form.cards.keySet())
30 for (String entry : form.cards.get(id).keySet())
31 LOG.info("{} - {}: {}", id, entry, form.cards.get(id).get(entry));
36 @RequestMapping(path = "/", params = { "card=add", "!add", "!remove" })
37 public String addCard(@ModelAttribute Form form)
43 .reduce(0, (a, b) -> a > b ? a : b) + 1;
45 Map<String, Boolean> content = new LinkedHashMap<>();
46 content.put(form.names.get(0), Boolean.FALSE);
47 LOG.info("Adding new card #{} with content: {}", next, content);
48 form.cards.put(next, content);
50 for (Integer id : form.cards.keySet())
51 for (String entry : form.cards.get(id).keySet())
52 LOG.info("{} - {}: {}", id, entry, form.cards.get(id).get(entry));
57 @RequestMapping(path = "/", params = { "card", "!add", "!remove" })
58 public String removeCard(@ModelAttribute Form form, @RequestParam Integer card)
60 Map<String, Boolean> content = form.cards.remove(card);
61 LOG.info("Removed card #{} with content: {}", card, content);
63 for (Integer id : form.cards.keySet())
64 for (String entry : form.cards.get(id).keySet())
65 LOG.info("{} - {}: {}", id, entry, form.cards.get(id).get(entry));
70 @RequestMapping(path = "/", params = { "!card", "add", "!remove" })
71 public String addRow(@ModelAttribute Form form, @RequestParam Integer add)
73 LOG.info("Adding row {} to card #{}", form.names.get(add), add);
74 form.cards.get(add).put(form.names.get(add), Boolean.FALSE);
76 for (Integer id : form.cards.keySet())
77 for (String entry : form.cards.get(id).keySet())
78 LOG.info("{} - {}: {}", id, entry, form.cards.get(id).get(entry));
83 @RequestMapping(path = "/", params = { "!card", "!add", "remove" })
84 public String removeRow(@ModelAttribute Form form, @RequestParam String remove)
86 String[] parts = remove.split(":", 2);
87 Integer card = Integer.valueOf(parts[0]);
88 String row = parts[1];
89 Boolean value = form.cards.get(card).remove(row);
90 LOG.info("Removed row {} with value {} from card #{}", row, value, card);
92 if (form.cards.get(card).isEmpty())
94 LOG.info("Card #{} is empty: Removing card!", card);
95 form.cards.remove(card);
98 for (Integer id : form.cards.keySet())
99 for (String entry : form.cards.get(id).keySet())
100 LOG.info("{} - {}: {}", id, entry, form.cards.get(id).get(entry));