|
1 | | -package edu.asu.conceptpower.web; |
2 | | - |
3 | | -import java.util.HashMap; |
4 | | -import java.util.List; |
5 | | -import java.util.Map; |
6 | | - |
7 | | -import org.codehaus.jettison.json.JSONObject; |
8 | | -import org.springframework.beans.factory.annotation.Autowired; |
9 | | -import org.springframework.http.HttpStatus; |
10 | | -import org.springframework.http.ResponseEntity; |
11 | | -import org.springframework.stereotype.Controller; |
12 | | -import org.springframework.ui.ModelMap; |
13 | | -import org.springframework.web.bind.annotation.PathVariable; |
14 | | -import org.springframework.web.bind.annotation.RequestMapping; |
15 | | -import org.springframework.web.bind.annotation.RequestMethod; |
16 | | -import org.springframework.web.bind.annotation.RequestParam; |
17 | | -import org.springframework.web.bind.annotation.ResponseBody; |
18 | | - |
19 | | -import edu.asu.conceptpower.core.ConceptEntry; |
20 | | -import edu.asu.conceptpower.core.ConceptList; |
21 | | -import edu.asu.conceptpower.core.ConceptType; |
22 | | -import edu.asu.conceptpower.core.IConceptListManager; |
23 | | -import edu.asu.conceptpower.core.IConceptManager; |
24 | | -import edu.asu.conceptpower.db4o.TypeDatabaseClient; |
25 | | -import edu.asu.conceptpower.util.URIHelper; |
26 | | -import edu.asu.conceptpower.wrapper.ConceptEntryWrapper; |
27 | | -import edu.asu.conceptpower.wrapper.IConceptWrapperCreator; |
28 | | - |
29 | | -@Controller |
30 | | -public class ConceptListController { |
31 | | - |
32 | | - @Autowired |
33 | | - private IConceptManager conceptManager; |
34 | | - |
35 | | - @Autowired |
36 | | - private IConceptListManager conceptListManager; |
37 | | - |
38 | | - @Autowired |
39 | | - private TypeDatabaseClient typeDatabaseClient; |
40 | | - |
41 | | - @Autowired |
42 | | - private URIHelper URICreator; |
43 | | - |
44 | | - @Autowired |
45 | | - private IConceptWrapperCreator wrapperCreator; |
46 | | - |
47 | | - /** |
48 | | - * This method provides information of all the existing concept lists for |
49 | | - * showing concept list page |
50 | | - * |
51 | | - * @param model |
52 | | - * A generic model holder for Servlet |
53 | | - * @return String value to redirect user to all concpet list page |
54 | | - */ |
55 | | - @RequestMapping(value = "auth/conceptlist") |
56 | | - public String prepareShowConceptList(ModelMap model) { |
57 | | - |
58 | | - List<ConceptList> conceptLists = conceptListManager.getAllConceptLists(); |
59 | | - model.addAttribute("result", conceptLists); |
60 | | - |
61 | | - return "/auth/conceptlist"; |
62 | | - } |
63 | | - |
64 | | - /** |
65 | | - * This method provides infomaiton of concepts for a given concept list |
66 | | - * |
67 | | - * @param list |
68 | | - * @param model |
69 | | - * A generic model holder for Servlet |
70 | | - * @return Return sting value to redirect user to a particular concept list |
71 | | - * page |
72 | | - */ |
73 | | - @RequestMapping(value = "auth/{listid}/concepts", method = RequestMethod.GET) |
74 | | - public String getConceptsOfConceptList(@PathVariable("listid") String list, |
75 | | - ModelMap model) { |
76 | | - |
77 | | - List<ConceptEntry> founds = conceptManager.getConceptListEntries(list); |
78 | | - |
79 | | - List<ConceptEntryWrapper> foundConcepts = wrapperCreator |
80 | | - .createWrappers(founds != null ? founds |
81 | | - .toArray(new ConceptEntry[founds.size()]) |
82 | | - : new ConceptEntry[0]); |
83 | | - |
84 | | - model.addAttribute("result", foundConcepts); |
85 | | - return "/auth/conceptlist/concepts"; |
86 | | - } |
87 | | - |
88 | | - /** |
89 | | - * This method provides details of a concept for given concept ID |
90 | | - * |
91 | | - * @param conceptid |
92 | | - * ID of a concept |
93 | | - * @return Map containing concept details |
94 | | - */ |
95 | | - @RequestMapping(method = RequestMethod.GET, value = "conceptDetail", produces = "application/json") |
96 | | - public @ResponseBody ResponseEntity<String> getConceptDetails( |
97 | | - @RequestParam("conceptid") String conceptid) { |
98 | | - ConceptEntryWrapper conceptEntry = new ConceptEntryWrapper( |
99 | | - conceptManager.getConceptEntry(conceptid)); |
100 | | - Map<String, String> details = new HashMap<String, String>(); |
101 | | - |
102 | | - details.put("name", conceptEntry.getEntry().getWord()); |
103 | | - details.put("id", conceptEntry.getEntry().getId()); |
104 | | - details.put("uri", URICreator.getURI(conceptEntry.getEntry())); |
105 | | - //This condition has been included to make sure null values are not displayed in the details dialog box |
106 | | - details.put("wordnetid", conceptEntry.getEntry().getWordnetId()==null?"":conceptEntry.getEntry().getWordnetId()); |
107 | | - details.put("pos", conceptEntry.getEntry().getPos()); |
108 | | - details.put("conceptlist", conceptEntry.getEntry().getConceptList()); |
109 | | - |
110 | | - ConceptType type = conceptEntry.getEntry().getTypeId() == null ? null |
111 | | - : typeDatabaseClient.getType( |
112 | | - conceptEntry.getEntry().getTypeId()); |
113 | | - |
114 | | - details.put( |
115 | | - "type", |
116 | | - type == null ? "" : type.getTypeName()); |
117 | | - details.put("equalto", |
118 | | - conceptEntry.getEntry().getEqualTo() == null ? "" |
119 | | - : conceptEntry.getEntry().getEqualTo()); |
120 | | - details.put("similarto", |
121 | | - conceptEntry.getEntry().getSimilarTo() == null ? "" |
122 | | - : conceptEntry.getEntry().getSimilarTo()); |
123 | | - details.put("creator", |
124 | | - conceptEntry.getEntry().getCreatorId() == null ? "" |
125 | | - : conceptEntry.getEntry().getCreatorId()); |
126 | | - |
127 | | - return new ResponseEntity<String>(new JSONObject(details).toString(), HttpStatus.OK); |
128 | | - } |
129 | | -} |
| 1 | +package edu.asu.conceptpower.web; |
| 2 | + |
| 3 | +import java.util.HashMap; |
| 4 | +import java.util.List; |
| 5 | +import java.util.Map; |
| 6 | + |
| 7 | +import org.codehaus.jettison.json.JSONObject; |
| 8 | +import org.springframework.beans.factory.annotation.Autowired; |
| 9 | +import org.springframework.http.HttpStatus; |
| 10 | +import org.springframework.http.ResponseEntity; |
| 11 | +import org.springframework.stereotype.Controller; |
| 12 | +import org.springframework.ui.ModelMap; |
| 13 | +import org.springframework.web.bind.annotation.PathVariable; |
| 14 | +import org.springframework.web.bind.annotation.RequestMapping; |
| 15 | +import org.springframework.web.bind.annotation.RequestMethod; |
| 16 | +import org.springframework.web.bind.annotation.RequestParam; |
| 17 | +import org.springframework.web.bind.annotation.ResponseBody; |
| 18 | + |
| 19 | +import edu.asu.conceptpower.core.ConceptEntry; |
| 20 | +import edu.asu.conceptpower.core.ConceptList; |
| 21 | +import edu.asu.conceptpower.core.ConceptType; |
| 22 | +import edu.asu.conceptpower.core.IConceptListManager; |
| 23 | +import edu.asu.conceptpower.core.IConceptManager; |
| 24 | +import edu.asu.conceptpower.db4o.TypeDatabaseClient; |
| 25 | +import edu.asu.conceptpower.util.URIHelper; |
| 26 | +import edu.asu.conceptpower.wrapper.ConceptEntryWrapper; |
| 27 | +import edu.asu.conceptpower.wrapper.IConceptWrapperCreator; |
| 28 | + |
| 29 | +@Controller |
| 30 | +public class ConceptListController { |
| 31 | + |
| 32 | + @Autowired |
| 33 | + private IConceptManager conceptManager; |
| 34 | + |
| 35 | + @Autowired |
| 36 | + private IConceptListManager conceptListManager; |
| 37 | + |
| 38 | + @Autowired |
| 39 | + private TypeDatabaseClient typeDatabaseClient; |
| 40 | + |
| 41 | + @Autowired |
| 42 | + private URIHelper URICreator; |
| 43 | + |
| 44 | + @Autowired |
| 45 | + private IConceptWrapperCreator wrapperCreator; |
| 46 | + |
| 47 | + /** |
| 48 | + * This method provides information of all the existing concept lists for |
| 49 | + * showing concept list page |
| 50 | + * |
| 51 | + * @param model |
| 52 | + * A generic model holder for Servlet |
| 53 | + * @return String value to redirect user to all concpet list page |
| 54 | + */ |
| 55 | + @RequestMapping(value = "auth/conceptlist") |
| 56 | + public String prepareShowConceptList(ModelMap model) { |
| 57 | + |
| 58 | + List<ConceptList> conceptLists = conceptListManager.getAllConceptLists(); |
| 59 | + model.addAttribute("result", conceptLists); |
| 60 | + |
| 61 | + return "/auth/conceptlist"; |
| 62 | + } |
| 63 | + |
| 64 | + /** |
| 65 | + * This method provides infomaiton of concepts for a given concept list |
| 66 | + * |
| 67 | + * @param list |
| 68 | + * @param model |
| 69 | + * A generic model holder for Servlet |
| 70 | + * @return Return sting value to redirect user to a particular concept list |
| 71 | + * page |
| 72 | + */ |
| 73 | + @RequestMapping(value = "auth/{listid}/concepts", method = RequestMethod.GET) |
| 74 | + public String getConceptsOfConceptList(@PathVariable("listid") String list, |
| 75 | + ModelMap model) { |
| 76 | + |
| 77 | + List<ConceptEntry> founds = conceptManager.getConceptListEntries(list); |
| 78 | + |
| 79 | + List<ConceptEntryWrapper> foundConcepts = wrapperCreator |
| 80 | + .createWrappers(founds != null ? founds |
| 81 | + .toArray(new ConceptEntry[founds.size()]) |
| 82 | + : new ConceptEntry[0]); |
| 83 | + |
| 84 | + model.addAttribute("result", foundConcepts); |
| 85 | + return "/auth/conceptlist/concepts"; |
| 86 | + } |
| 87 | + |
| 88 | + /** |
| 89 | + * This method provides details of a concept for given concept ID |
| 90 | + * |
| 91 | + * @param conceptid |
| 92 | + * ID of a concept |
| 93 | + * @return Map containing concept details |
| 94 | + */ |
| 95 | + @RequestMapping(method = RequestMethod.GET, value = "conceptDetail", produces = "application/json") |
| 96 | + public @ResponseBody ResponseEntity<String> getConceptDetails( |
| 97 | + @RequestParam("conceptid") String conceptid) { |
| 98 | + ConceptEntry entry = conceptManager.getConceptEntry(conceptid); |
| 99 | + List<ConceptEntryWrapper> wrappers = wrapperCreator.createWrappers(new ConceptEntry[] { entry } ); |
| 100 | + ConceptEntryWrapper wrapper = null; |
| 101 | + if (wrappers.size() > 0) { |
| 102 | + wrapper = wrappers.get(0); |
| 103 | + } |
| 104 | + else { |
| 105 | + return new ResponseEntity<String>("No entry for the provided id.", HttpStatus.BAD_REQUEST); |
| 106 | + } |
| 107 | + |
| 108 | + Map<String, String> details = new HashMap<String, String>(); |
| 109 | + |
| 110 | + details.put("name", wrapper.getEntry().getWord()); |
| 111 | + details.put("id", wrapper.getEntry().getId()); |
| 112 | + details.put("uri", URICreator.getURI(wrapper.getEntry())); |
| 113 | + //This condition has been included to make sure null values are not displayed in the details dialog box |
| 114 | + details.put("wordnetid", wrapper.getEntry().getWordnetId()==null?"":wrapper.getEntry().getWordnetId()); |
| 115 | + details.put("pos", wrapper.getEntry().getPos()); |
| 116 | + details.put("conceptlist", wrapper.getEntry().getConceptList()); |
| 117 | + |
| 118 | + ConceptType type = wrapper.getEntry().getTypeId() == null ? null |
| 119 | + : typeDatabaseClient.getType( |
| 120 | + wrapper.getEntry().getTypeId()); |
| 121 | + |
| 122 | + details.put("description", wrapper.getEntry().getDescription()); |
| 123 | + |
| 124 | + details.put( |
| 125 | + "type", |
| 126 | + type == null ? "" : type.getTypeName()); |
| 127 | + details.put("equalto", |
| 128 | + wrapper.getEntry().getEqualTo() == null ? "" |
| 129 | + : wrapper.getEntry().getEqualTo()); |
| 130 | + details.put("similarto", |
| 131 | + wrapper.getEntry().getSimilarTo() == null ? "" |
| 132 | + : wrapper.getEntry().getSimilarTo()); |
| 133 | + details.put("creator", |
| 134 | + wrapper.getEntry().getCreatorId() == null ? "" |
| 135 | + : wrapper.getEntry().getCreatorId()); |
| 136 | + |
| 137 | + return new ResponseEntity<String>(new JSONObject(details).toString(), HttpStatus.OK); |
| 138 | + } |
| 139 | +} |
0 commit comments