Blame | Last modification | View Log | RSS feed
package com.hotspotstore.controllers;import java.util.ArrayList;import java.util.HashMap;import java.util.List;import java.util.Map;import org.json.JSONObject;import com.hotspotstore.model.Snippet;import com.hotspotstore.storage.Mongo;public class SnippetsController extends BaseController{/****/private static final long serialVersionUID = 1L;private String type;private String[] entities;private String result;private Map<String, List<Long>> snippetMap = new HashMap<String, List<Long>>();public Map<String, List<Long>> getSnippetMap() {return snippetMap;}public void setSnippetMap(Map<String, List<Long>> snippetMap) {this.snippetMap = snippetMap;}public String getResult() {return result;}public void setResult(String result) {this.result = result;}public String[] getEntities() {return entities;}public void setEntities(String[] entities) {this.entities = entities;}public String getType() {return type;}public void setType(String type) {this.type = type;}public String index(){List<Snippet> snippets = Mongo.getSnippets();for (Snippet s : snippets){snippetMap.put(s.getSnippet(), s.getEntities());}return "index";}public String create(){List<Long> entities_l = new ArrayList<Long>();for (String s : entities){if (s==null || s.trim().isEmpty()){setResult("Entity cannot be left blank");return "result";}if (entities_l.contains(Long.valueOf(s.trim()))){setResult("Entity "+s+" is duplicate");return "result";}entities_l.add(Long.valueOf(s.trim()));try{Mongo.getHotspotEntity(Long.valueOf(s.trim()));}catch(Exception e){setResult("Entity "+s+" not imported");return "result";}}Snippet s = new Snippet();s.setSnippet(type.trim());s.setEntities(entities_l);Mongo.addSnippetInfo(s);setResult("Entity added to snippet");return "result";}}