// getListOfSharesByType - private Map<String, String> getListOfSharesByType( String type, HttpServletRequest request, HttpServletResponse response) { Map<String, String> allShares = new HashMap<String, String>(); // publishedSources - array of source._ids of published sources ArrayList<String> publishedSources = new ArrayList<String>(); try { JSONObject sharesObject = new JSONObject(searchSharesByType(type, request, response)); JSONObject json_response = sharesObject.getJSONObject("response"); if (json_response.getString("success").equalsIgnoreCase("true")) { if (sharesObject.has("data")) { // Iterate over share objects and write to our collection JSONArray shares = sharesObject.getJSONArray("data"); for (int i = 0; i < shares.length(); i++) { JSONObject share = shares.getJSONObject(i); allShares.put(share.getString("title"), share.getString("_id")); } } } } catch (Exception e) { System.out.println(e.getMessage()); } return allShares; }
public Level1State read() { try { data = new byte[(int) file.length()]; FileInputStream in = new FileInputStream(file); in.read(data); in.close(); } catch (Exception e) { e.printStackTrace(); } Level1State l1s = Level1State.deserialize(data); return l1s; }
public Save(String fileName) { try { // read something about java.utils.prefs.Preferences file = new File(fileName); if (!file.exists()) { FileOutputStream out = new FileOutputStream(fileName); out.close(); System.out.println("file made"); } } catch (Exception e) { e.printStackTrace(); } }
public void write(byte[] data) throws IOException { this.data = data; System.out.println(data.length); if (file.length() > 1000) { System.out.println("Exists"); // Prompt user to overwrite the save file // Allow user to overwrite save file } else { try { FileOutputStream out = new FileOutputStream(file); out.write(data); out.close(); // IOUtils.write(data, output); } catch (Exception e) { e.printStackTrace(); } } }
// getListOfAllCommunities private Map<String, String> getListOfAllNonPersonalCommunities( HttpServletRequest request, HttpServletResponse response) { Map<String, String> allCommunities = new HashMap<String, String>(); try { JSONObject communitiesObj = new JSONObject(getAllCommunities(request, response)); if (communitiesObj.has("data")) { JSONArray communities = communitiesObj.getJSONArray("data"); for (int i = 0; i < communities.length(); i++) { JSONObject community = communities.getJSONObject(i); if (community.getString("isPersonalCommunity").equalsIgnoreCase("false") && community.has("name")) { allCommunities.put(community.getString("name"), community.getString("_id")); } } } } catch (Exception e) { System.out.println(e.getMessage()); } return allCommunities; }
// getListOfAllPeople private Map<String, String> getListOfAllPeople( HttpServletRequest request, HttpServletResponse response) { Map<String, String> allPeople = new HashMap<String, String>(); try { JSONObject communityObj = new JSONObject(getSystemCommunity(request, response)); if (communityObj.has("data")) { JSONObject community = new JSONObject(communityObj.getString("data")); if (community.has("members")) { JSONArray members = community.getJSONArray("members"); for (int i = 0; i < members.length(); i++) { JSONObject member = members.getJSONObject(i); if (member.has("displayName")) { allPeople.put(member.getString("displayName"), member.getString("_id")); } else { allPeople.put(member.getString("_id"), member.getString("_id")); } } } } } catch (Exception e) { System.out.println(e.getMessage()); } return allPeople; }
// getUserSources - private Map<String, String> getUserSourcesAndShares( HttpServletRequest request, HttpServletResponse response) { Map<String, String> userSources = new HashMap<String, String>(); String userIdStr = null; // publishedSources - array of source._ids of published sources ArrayList<String> publishedSources = new ArrayList<String>(); try { JSONObject personObj = new JSONObject(getPerson(request, response)); if (personObj.has("data")) { JSONObject person = new JSONObject(personObj.getString("data")); userIdStr = person.getString("_id"); } // Get the user's shares from social.share where type = source or source_published String tempJson = getSourceShares(request, response); // Covert to JSONObject JSONObject json = new JSONObject(tempJson); JSONObject json_response = json.getJSONObject("response"); if (json_response.getString("success").equalsIgnoreCase("true")) { if (json.has("data")) { // Iterate over share objects and write to our collection JSONArray data = json.getJSONArray("data"); for (int i = 0; i < data.length(); i++) { JSONObject shareObj = data.getJSONObject(i); String tempTitle = shareObj.getString("title"); JSONObject sourceObj = new JSONObject(shareObj.getString("share")); if (sourceObj.has("_id")) publishedSources.add(sourceObj.getString("_id")); if (sourceObj.has("ownerId") && !sourceObj.getString("ownerId").equalsIgnoreCase(userIdStr)) tempTitle += " (+)"; tempTitle += " (*)"; userSources.put(tempTitle, shareObj.getString("_id")); } } } // Get sources that the user owns from ingest.source tempJson = getUserSources(request, response); if (tempJson != null) { json = new JSONObject(tempJson); json_response = json.getJSONObject("response"); if (json_response.getString("success").equalsIgnoreCase("true")) { if (json.has("data")) { // Iterate over source objects and write to our collection JSONArray data = json.getJSONArray("data"); for (int i = 0; i < data.length(); i++) { JSONObject sourceObj = data.getJSONObject(i); // Only add the source to our list if it isn't already in our if (!publishedSources.contains(sourceObj.getString("_id"))) { String tempTitle = sourceObj.getString("title"); if (sourceObj.has("ownerId") && !sourceObj.getString("ownerId").equalsIgnoreCase(userIdStr)) tempTitle += " (+)"; userSources.put(tempTitle, sourceObj.getString("_id")); } } } } } } catch (Exception e) { System.out.println(e.getMessage()); } return userSources; }