-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #104 from diging/feature/CCP-154
Catch ClassCastException when parsing JSON to return proper error codes.
- Loading branch information
Showing
4 changed files
with
149 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
268 changes: 139 additions & 129 deletions
268
Conceptpower+Spring/src/main/java/edu/asu/conceptpower/web/ConceptListController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,129 +1,139 @@ | ||
package edu.asu.conceptpower.web; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.codehaus.jettison.json.JSONObject; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.ui.ModelMap; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestMethod; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.ResponseBody; | ||
|
||
import edu.asu.conceptpower.core.ConceptEntry; | ||
import edu.asu.conceptpower.core.ConceptList; | ||
import edu.asu.conceptpower.core.ConceptType; | ||
import edu.asu.conceptpower.core.IConceptListManager; | ||
import edu.asu.conceptpower.core.IConceptManager; | ||
import edu.asu.conceptpower.db4o.TypeDatabaseClient; | ||
import edu.asu.conceptpower.util.URIHelper; | ||
import edu.asu.conceptpower.wrapper.ConceptEntryWrapper; | ||
import edu.asu.conceptpower.wrapper.IConceptWrapperCreator; | ||
|
||
@Controller | ||
public class ConceptListController { | ||
|
||
@Autowired | ||
private IConceptManager conceptManager; | ||
|
||
@Autowired | ||
private IConceptListManager conceptListManager; | ||
|
||
@Autowired | ||
private TypeDatabaseClient typeDatabaseClient; | ||
|
||
@Autowired | ||
private URIHelper URICreator; | ||
|
||
@Autowired | ||
private IConceptWrapperCreator wrapperCreator; | ||
|
||
/** | ||
* This method provides information of all the existing concept lists for | ||
* showing concept list page | ||
* | ||
* @param model | ||
* A generic model holder for Servlet | ||
* @return String value to redirect user to all concpet list page | ||
*/ | ||
@RequestMapping(value = "auth/conceptlist") | ||
public String prepareShowConceptList(ModelMap model) { | ||
|
||
List<ConceptList> conceptLists = conceptListManager.getAllConceptLists(); | ||
model.addAttribute("result", conceptLists); | ||
|
||
return "/auth/conceptlist"; | ||
} | ||
|
||
/** | ||
* This method provides infomaiton of concepts for a given concept list | ||
* | ||
* @param list | ||
* @param model | ||
* A generic model holder for Servlet | ||
* @return Return sting value to redirect user to a particular concept list | ||
* page | ||
*/ | ||
@RequestMapping(value = "auth/{listid}/concepts", method = RequestMethod.GET) | ||
public String getConceptsOfConceptList(@PathVariable("listid") String list, | ||
ModelMap model) { | ||
|
||
List<ConceptEntry> founds = conceptManager.getConceptListEntries(list); | ||
|
||
List<ConceptEntryWrapper> foundConcepts = wrapperCreator | ||
.createWrappers(founds != null ? founds | ||
.toArray(new ConceptEntry[founds.size()]) | ||
: new ConceptEntry[0]); | ||
|
||
model.addAttribute("result", foundConcepts); | ||
return "/auth/conceptlist/concepts"; | ||
} | ||
|
||
/** | ||
* This method provides details of a concept for given concept ID | ||
* | ||
* @param conceptid | ||
* ID of a concept | ||
* @return Map containing concept details | ||
*/ | ||
@RequestMapping(method = RequestMethod.GET, value = "conceptDetail", produces = "application/json") | ||
public @ResponseBody ResponseEntity<String> getConceptDetails( | ||
@RequestParam("conceptid") String conceptid) { | ||
ConceptEntryWrapper conceptEntry = new ConceptEntryWrapper( | ||
conceptManager.getConceptEntry(conceptid)); | ||
Map<String, String> details = new HashMap<String, String>(); | ||
|
||
details.put("name", conceptEntry.getEntry().getWord()); | ||
details.put("id", conceptEntry.getEntry().getId()); | ||
details.put("uri", URICreator.getURI(conceptEntry.getEntry())); | ||
//This condition has been included to make sure null values are not displayed in the details dialog box | ||
details.put("wordnetid", conceptEntry.getEntry().getWordnetId()==null?"":conceptEntry.getEntry().getWordnetId()); | ||
details.put("pos", conceptEntry.getEntry().getPos()); | ||
details.put("conceptlist", conceptEntry.getEntry().getConceptList()); | ||
|
||
ConceptType type = conceptEntry.getEntry().getTypeId() == null ? null | ||
: typeDatabaseClient.getType( | ||
conceptEntry.getEntry().getTypeId()); | ||
|
||
details.put( | ||
"type", | ||
type == null ? "" : type.getTypeName()); | ||
details.put("equalto", | ||
conceptEntry.getEntry().getEqualTo() == null ? "" | ||
: conceptEntry.getEntry().getEqualTo()); | ||
details.put("similarto", | ||
conceptEntry.getEntry().getSimilarTo() == null ? "" | ||
: conceptEntry.getEntry().getSimilarTo()); | ||
details.put("creator", | ||
conceptEntry.getEntry().getCreatorId() == null ? "" | ||
: conceptEntry.getEntry().getCreatorId()); | ||
|
||
return new ResponseEntity<String>(new JSONObject(details).toString(), HttpStatus.OK); | ||
} | ||
} | ||
package edu.asu.conceptpower.web; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.codehaus.jettison.json.JSONObject; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.ui.ModelMap; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestMethod; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.ResponseBody; | ||
|
||
import edu.asu.conceptpower.core.ConceptEntry; | ||
import edu.asu.conceptpower.core.ConceptList; | ||
import edu.asu.conceptpower.core.ConceptType; | ||
import edu.asu.conceptpower.core.IConceptListManager; | ||
import edu.asu.conceptpower.core.IConceptManager; | ||
import edu.asu.conceptpower.db4o.TypeDatabaseClient; | ||
import edu.asu.conceptpower.util.URIHelper; | ||
import edu.asu.conceptpower.wrapper.ConceptEntryWrapper; | ||
import edu.asu.conceptpower.wrapper.IConceptWrapperCreator; | ||
|
||
@Controller | ||
public class ConceptListController { | ||
|
||
@Autowired | ||
private IConceptManager conceptManager; | ||
|
||
@Autowired | ||
private IConceptListManager conceptListManager; | ||
|
||
@Autowired | ||
private TypeDatabaseClient typeDatabaseClient; | ||
|
||
@Autowired | ||
private URIHelper URICreator; | ||
|
||
@Autowired | ||
private IConceptWrapperCreator wrapperCreator; | ||
|
||
/** | ||
* This method provides information of all the existing concept lists for | ||
* showing concept list page | ||
* | ||
* @param model | ||
* A generic model holder for Servlet | ||
* @return String value to redirect user to all concpet list page | ||
*/ | ||
@RequestMapping(value = "auth/conceptlist") | ||
public String prepareShowConceptList(ModelMap model) { | ||
|
||
List<ConceptList> conceptLists = conceptListManager.getAllConceptLists(); | ||
model.addAttribute("result", conceptLists); | ||
|
||
return "/auth/conceptlist"; | ||
} | ||
|
||
/** | ||
* This method provides infomaiton of concepts for a given concept list | ||
* | ||
* @param list | ||
* @param model | ||
* A generic model holder for Servlet | ||
* @return Return sting value to redirect user to a particular concept list | ||
* page | ||
*/ | ||
@RequestMapping(value = "auth/{listid}/concepts", method = RequestMethod.GET) | ||
public String getConceptsOfConceptList(@PathVariable("listid") String list, | ||
ModelMap model) { | ||
|
||
List<ConceptEntry> founds = conceptManager.getConceptListEntries(list); | ||
|
||
List<ConceptEntryWrapper> foundConcepts = wrapperCreator | ||
.createWrappers(founds != null ? founds | ||
.toArray(new ConceptEntry[founds.size()]) | ||
: new ConceptEntry[0]); | ||
|
||
model.addAttribute("result", foundConcepts); | ||
return "/auth/conceptlist/concepts"; | ||
} | ||
|
||
/** | ||
* This method provides details of a concept for given concept ID | ||
* | ||
* @param conceptid | ||
* ID of a concept | ||
* @return Map containing concept details | ||
*/ | ||
@RequestMapping(method = RequestMethod.GET, value = "conceptDetail", produces = "application/json") | ||
public @ResponseBody ResponseEntity<String> getConceptDetails( | ||
@RequestParam("conceptid") String conceptid) { | ||
ConceptEntry entry = conceptManager.getConceptEntry(conceptid); | ||
List<ConceptEntryWrapper> wrappers = wrapperCreator.createWrappers(new ConceptEntry[] { entry } ); | ||
ConceptEntryWrapper wrapper = null; | ||
if (wrappers.size() > 0) { | ||
wrapper = wrappers.get(0); | ||
} | ||
else { | ||
return new ResponseEntity<String>("No entry for the provided id.", HttpStatus.BAD_REQUEST); | ||
} | ||
|
||
Map<String, String> details = new HashMap<String, String>(); | ||
|
||
details.put("name", wrapper.getEntry().getWord()); | ||
details.put("id", wrapper.getEntry().getId()); | ||
details.put("uri", URICreator.getURI(wrapper.getEntry())); | ||
//This condition has been included to make sure null values are not displayed in the details dialog box | ||
details.put("wordnetid", wrapper.getEntry().getWordnetId()==null?"":wrapper.getEntry().getWordnetId()); | ||
details.put("pos", wrapper.getEntry().getPos()); | ||
details.put("conceptlist", wrapper.getEntry().getConceptList()); | ||
|
||
ConceptType type = wrapper.getEntry().getTypeId() == null ? null | ||
: typeDatabaseClient.getType( | ||
wrapper.getEntry().getTypeId()); | ||
|
||
details.put("description", wrapper.getEntry().getDescription()); | ||
|
||
details.put( | ||
"type", | ||
type == null ? "" : type.getTypeName()); | ||
details.put("equalto", | ||
wrapper.getEntry().getEqualTo() == null ? "" | ||
: wrapper.getEntry().getEqualTo()); | ||
details.put("similarto", | ||
wrapper.getEntry().getSimilarTo() == null ? "" | ||
: wrapper.getEntry().getSimilarTo()); | ||
details.put("creator", | ||
wrapper.getEntry().getCreatorId() == null ? "" | ||
: wrapper.getEntry().getCreatorId()); | ||
|
||
return new ResponseEntity<String>(new JSONObject(details).toString(), HttpStatus.OK); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters