List of usage examples for java.util Date toString
public String toString()
where:dow mon dd hh:mm:ss zzz yyyy
From source file:org.encuestame.business.service.TweetPollService.java
/** * Publish all scheduled items/*from w w w .j a v a 2s . co m*/ * @param status {@link Status} * @param minimumDate {@link Date} * @throws EnMeNoResultsFoundException */ public void publishScheduledItems(final Status status, final Date minimumDate) throws EnMeNoResultsFoundException { Boolean publish = Boolean.FALSE; final String totalAttempts = EnMePlaceHolderConfigurer.getProperty("attempts.scheduled.publication"); // 1. Retrieve all records scheduled before currently date. final List<Schedule> scheduledRecords = getScheduledDao().retrieveScheduled(status, minimumDate); // 2. Iterate the results and for each try to publish again Call // Service to publish Tweetpoll/ Poll or Survey. // 3. If list > O - iterate list if (scheduledRecords.size() > 0) { for (Schedule schedule : scheduledRecords) { TweetPollSavedPublishedStatus tpollSaved = new TweetPollSavedPublishedStatus(); // Retrieve attempt constant for properties file. if (schedule.getPublishAttempts() < 5) { // Set Status PROCESSING schedule.setStatus(Status.PROCESSING); getScheduledDao().saveOrUpdate(schedule); tpollSaved = this.publishTweetBySocialAccountId(schedule.getSocialAccount().getId(), schedule.getTpoll(), schedule.getTweetText(), schedule.getTypeSearch(), schedule.getPoll(), schedule.getSurvey()); // If tpollsavedpublished isnt null and Status is failed, is // necessary re publish if ((tpollSaved != null) && (tpollSaved.getStatus()).equals(Status.FAILED)) { log.trace("******* Item not published *******"); // Update ScheduleRecord and set counter und Date DateTime dt = new DateTime(schedule.getScheduleDate()); // Set a new value to republishing schedule.setScheduleDate(dt.plusMinutes(3).toDate()); // Increment the counter of attempts int counter = schedule.getPublishAttempts(); counter = counter + 1; schedule.setPublishAttempts(counter); schedule.setStatus(Status.FAILED); getScheduledDao().saveOrUpdate(schedule); } else { log.trace("******* Published *******"); final Date currentDate = DateUtil.getCurrentCalendarDate(); schedule.setStatus(Status.SUCCESS); schedule.setPublicationDate(currentDate); getScheduledDao().saveOrUpdate(schedule); createNotification(NotificationEnum.WELCOME_SIGNUP, getMessageProperties("notification.tweetpoll.scheduled.success", Locale.ENGLISH, //FIXME: fix this, locale is fixed new Object[] { tpollSaved.getTweetPoll().getQuestion().getQuestion(), currentDate.toString() }), //FIXME: currentDate shouldbe passed as ISO date. null, false, tpollSaved.getTweetPoll().getEditorOwner()); } } } } }
From source file:org.medici.bia.service.docbase.DocBaseServiceImpl.java
/** * {@inheritDoc}/*from w w w . j a v a 2s . c om*/ */ @Transactional(readOnly = false, propagation = Propagation.REQUIRED) @Override public Document addNewFactChecksDocument(FactChecks factChecks) throws ApplicationThrowable { try { Date now = new Date(); User user = getCurrentUser(); Document document = getDocumentDAO().find(factChecks.getDocument().getEntryId()); factChecks.setVetId(null); factChecks.setDateInfo(now.toString()); factChecks.setDocument(document); getFactChecksDAO().persist(factChecks); document.setFactChecks(factChecks); document.setLastUpdate(now); document.setLastUpdateBy(user); getUserHistoryDAO().persist( new UserHistory(user, "Add new fact checks", Action.MODIFY, Category.DOCUMENT, document)); getVettingHistoryDAO().persist(new VettingHistory(user, "Add new fact checks", org.medici.bia.domain.VettingHistory.Action.MODIFY, org.medici.bia.domain.VettingHistory.Category.DOCUMENT, document)); return document; } catch (Throwable th) { throw new ApplicationThrowable(th); } }
From source file:org.LexGrid.LexBIG.admin.DeactivateScheme.java
/** * Primary entry point for the program.//from ww w . jav a2s. co m * * @throws Exception */ public void run(String[] args) throws Exception { synchronized (ResourceManager.instance()) { // Parse the command line ... CommandLine cl = null; Options options = getCommandOptions(); Date when = null; try { cl = new BasicParser().parse(options, args); if (cl.hasOption("d")) when = _df.parse(cl.getOptionValue("d")); } catch (Exception e) { Util.displayCommandOptions("DeactivateScheme", options, "DeactivateScheme -u \"urn:oid:2.16.840.1.113883.3.26.1.1\" -v \"05.09e\" ", e); Util.displayMessage(Util.getPromptForSchemeHelp()); return; } // Interpret provided values ... String urn = cl.getOptionValue("u"); String ver = cl.getOptionValue("v"); boolean force = cl.hasOption("f"); CodingSchemeSummary css = null; // Find in list of registered vocabularies ... if (urn != null && ver != null) { urn = urn.trim(); ver = ver.trim(); LexBIGService lbs = LexBIGServiceImpl.defaultInstance(); Enumeration<? extends CodingSchemeRendering> schemes = lbs.getSupportedCodingSchemes() .enumerateCodingSchemeRendering(); while (schemes.hasMoreElements() && css == null) { CodingSchemeSummary summary = schemes.nextElement().getCodingSchemeSummary(); if (urn.equalsIgnoreCase(summary.getCodingSchemeURI()) && ver.equalsIgnoreCase(summary.getRepresentsVersion())) css = summary; } } // Found it? If not, prompt... if (css == null) { if (urn != null || ver != null) { Util.displayMessage("No matching coding scheme was found for the given URN or version."); Util.displayMessage(""); } css = Util.promptForCodeSystem(); if (css == null) return; } // Continue and confirm the action (if not bypassed by force option) // ... Util.displayTaggedMessage("A matching coding scheme was found ..."); boolean confirmed = true; if (!force) { Util.displayMessage((when == null ? "DEACTIVATE NOW?" : ("DEACTIVATE ON: " + when.toString())) + " ('Y' to confirm, any other key to cancel)"); char choice = Util.getConsoleCharacter(); confirmed = choice == 'Y' || choice == 'y'; } if (confirmed) { LexBIGServiceManager lbsm = LexBIGServiceImpl.defaultInstance().getServiceManager(null); lbsm.deactivateCodingSchemeVersion(Constructors.createAbsoluteCodingSchemeVersionReference(css), when); Util.displayTaggedMessage("Request complete"); } else { Util.displayTaggedMessage("Action cancelled by user"); } } }
From source file:org.smilec.smile.student.CourseList.java
private void logError(String url, String err) { boolean reachable = false; String internetTest = ""; String str = ""; Date now = new Date(); internetTest = now.toString() + ", loading page " + url + " error: " + err + "\n"; ;/* w ww .j a v a2 s.com*/ System.out.println(internetTest); try { //test router //InetAddress address = InetAddress.getByName("192.168.2.1"); byte[] b = new byte[] { (byte) 192, (byte) 168, (byte) 2, (byte) 1 }; InetAddress address = InetAddress.getByAddress(b); // Try to reach the specified address within the timeout // periode. If during this periode the address cannot be // reach then the method returns false. reachable = address.isReachable(5000); // 5 seconds } catch (Exception e) { reachable = false; e.printStackTrace(); } str = "Is router (192.168.2.1) reachable? " + reachable + "\n"; System.out.println(str); internetTest += str; try { //test server InetAddress address = InetAddress.getByName(cururi); reachable = address.isReachable(5000); } catch (Exception e) { reachable = false; e.printStackTrace(); } str = "Is host reachable? " + reachable + "\n"; System.out.println(str); internetTest += str; String received = ""; int statusCode = 0; try { HttpParams params = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(params, 5000); // until first connection HttpConnectionParams.setSoTimeout(params, 5000); // 10000 ms socket timeout --? no time out for socket HttpClient httpclient = new DefaultHttpClient(params); HttpGet httpget; httpget = new HttpGet("http://" + cururi); HttpResponse response = httpclient.execute(httpget); statusCode = response.getStatusLine().getStatusCode(); if (statusCode == 404) { // server not ready // do nothing throw new Exception("" + response.getStatusLine()); } else if ((statusCode / 100) != 2) { throw new Exception("" + response.getStatusLine()); } else { BufferedReader in = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); String line; StringBuffer sb = new StringBuffer(""); while ((line = in.readLine()) != null) { sb.append(line); } received = sb.toString(); if (received != null && received.length() > 0) reachable = true; received = "http status code: " + statusCode; } } catch (Exception e) { //e.printStackTrace(); received = "loading error, http status code: " + statusCode; reachable = false; } str = "Is Apache reachable? " + reachable + ", " + received + "\n"; System.out.println(str); internetTest += str; try { // open myfilename.txt for writing Log.d("Write log Err", "Start writing error log"); OutputStreamWriter out = new OutputStreamWriter(openFileOutput("smileErrorLog.txt", 0)); out.write(internetTest); out.close(); Log.d("Write log Err", "Writing error log finished."); } catch (java.io.IOException e) { //do something if an IOException occurs. Log.d("Write log Error", "ERROR"); e.printStackTrace(); } }
From source file:org.onecmdb.ui.gwt.desktop.server.service.model.ModelServiceImpl.java
public BaseListLoadResult<BaseModel> loadMDROverview(String token, ContentData mdrData, BaseListLoadConfig loadConfig) { ICIMDR mdr = (ICIMDR) ContentParserFactory.get().getCachedAdaptor(mdrData, ICIMDR.class); GraphQuery q = new GraphQuery(); ItemOffspringSelector config = new ItemOffspringSelector("config", "MDR_ConfigEntry"); config.setMatchTemplate(false);//from w w w. j a v a2 s. c o m config.setPrimary(true); //config.setPrimary(true); ItemOffspringSelector mdrD = new ItemOffspringSelector("mdr", "MDR_Repository"); mdrD.setMatchTemplate(false); ItemRelationSelector config2mdr = new ItemRelationSelector("config2mdr", "Reference", "mdr", "config"); /* ItemOffspringSelector history = new ItemOffspringSelector("history", "MDR_HistoryEntry"); history.setMatchTemplate(false); history.setPageInfo(new PageInfo(0,1)); ItemRelationSelector history2config = new ItemRelationSelector("history2config", "Reference", "config", "history"); history2config.setMandatory(false); */ q.addSelector(config); q.addSelector(mdrD); q.addSelector(config2mdr); Graph queryResult = mdr.query(token, q); queryResult.buildMap(); List<BaseModel> resultList = new ArrayList<BaseModel>(); Template cfg = queryResult.fetchNode("config"); if (cfg != null) { for (CiBean cfgBean : cfg.getOffsprings()) { BaseModel data = new BaseModel(); CiBean mdrBean = null; Template mdrTemp = queryResult.fetchReference(cfgBean, RelationConstraint.SOURCE, config2mdr.getId()); if (mdrTemp == null) { continue; } if (mdrTemp.getOffsprings().size() != 1) { continue; } mdrBean = mdrTemp.getOffsprings().get(0); CiBean historyBean = getLatestHistory(token, mdr, cfgBean); data.set("name", cfgBean.toStringValue("name")); data.set("mdr", mdrBean.toStringValue("name")); data.set("mdrAlias", mdrBean.getAlias()); data.set("configAlias", cfgBean.getAlias()); if (historyBean != null) { data.set("status", historyBean.toStringValue("status")); Date date = historyBean.getLastModified(); if (date != null) { try { SimpleDateFormat fmt = new SimpleDateFormat( ConfigurationFactory.getConfig().getDateTimeFmt()); data.set("date", fmt.format(date)); } catch (Throwable t) { data.set("date", date.toString()); } } data.set("added", historyBean.toStringValue("added")); data.set("deleted", historyBean.toStringValue("deleted")); data.set("modified", historyBean.toStringValue("modified")); data.set("historyAlias", historyBean.getAlias()); } resultList.add(data); } } BaseListLoadResult<BaseModel> result = new BaseListLoadResult<BaseModel>(resultList); return (result); }
From source file:action.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.//from ww w .ja va 2 s .c o m * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HttpSession session = request.getSession(); String form_action = (String) request.getParameter("form_action"); if (form_action == null) { form_action = ""; } PrintWriter out = response.getWriter(); if (form_action.equalsIgnoreCase("cekauth")) { StringBuffer sb = new StringBuffer(); String line = null; LinkedHashMap record = new LinkedHashMap(); try { BufferedReader reader = request.getReader(); while ((line = reader.readLine()) != null) { sb.append(line); } Object obj = JSONValue.parse(sb.toString()); JSONObject obj1 = (JSONObject) obj; String admin = "N"; String icw = "N"; String email = obj1.get("email").toString(); String first_name = obj1.get("first_name").toString(); String gender = obj1.get("gender").toString(); String id = obj1.get("id").toString(); String last_name = obj1.get("last_name").toString(); String link = obj1.get("link").toString(); String name = obj1.get("name").toString(); String verified = obj1.get("verified").toString(); DatastoreService datastore = DatastoreServiceFactory.getDatastoreService(); Key linkKey = KeyFactory.createKey("userTable", "user"); // Run an ancestor query to ensure we see the most up-to-date // view of the Greetings belonging to the selected Guestbook. Filter posisinama = new FilterPredicate("link", FilterOperator.EQUAL, link.toLowerCase()); // Run an ancestor query to ensure we see the most up-to-date // view of the Greetings belonging to the selected Guestbook. Query query = new Query("userTable", linkKey).setFilter(posisinama); List<Entity> userTables = datastore.prepare(query).asList(FetchOptions.Builder.withLimit(1)); Date date = new Date(); if (userTables.isEmpty()) { Entity userTable = new Entity("userTable", linkKey); userTable.setProperty("email", email); userTable.setProperty("first_name", first_name); userTable.setProperty("gender", gender); userTable.setProperty("id", id); userTable.setProperty("last_name", last_name); userTable.setProperty("link", link.toLowerCase()); userTable.setProperty("name", name); userTable.setProperty("verified", verified); userTable.setProperty("lastLogin", date); if (email.equalsIgnoreCase("khairul.anshar@gmail.com") || id.equalsIgnoreCase("112525777678499279265") || id.equalsIgnoreCase("10152397276159760") || name.equalsIgnoreCase("Khairul Anshar")) { userTable.setProperty("admin", "Y"); userTable.setProperty("icw", "Y"); } else { userTable.setProperty("admin", admin); userTable.setProperty("icw", "N"); } userTable.setProperty("imported", "N"); datastore.put(userTable); } else { for (Entity userTable : userTables) { admin = userTable.getProperty("admin").toString(); try { icw = userTable.getProperty("icw").toString(); } catch (Exception e) { userTable.setProperty("icw", "N"); icw = "N"; } userTable.setProperty("lastLogin", date); datastore.put(userTable); } } if (email.equalsIgnoreCase("khairul.anshar@gmail.com") || id.equalsIgnoreCase("112525777678499279265") || id.equalsIgnoreCase("10152397276159760") || name.equalsIgnoreCase("Khairul Anshar")) { admin = "Y"; icw = "Y"; } obj1.put("admin", admin); obj1.put("icw", icw); session.setAttribute("userAccount", obj1); record.put("userAccount", obj1); } catch (Exception e) { } response.setContentType("text/html;charset=UTF-8"); out.print(JSONValue.toJSONString(record)); out.flush(); } if (form_action.equalsIgnoreCase("getiframeData")) { StringBuffer sb = new StringBuffer(); String line = null; LinkedHashMap record = new LinkedHashMap(); try { BufferedReader reader = request.getReader(); while ((line = reader.readLine()) != null) { sb.append(line); } Object obj = JSONValue.parse(sb.toString()); //JSONArray records = (JSONArray) obj; JSONObject obj1 = (JSONObject) obj; String src = obj1.get("src").toString(); final URL url = new URL(src); final URLConnection urlConnection = url.openConnection(); urlConnection.setDoOutput(true); urlConnection.setRequestProperty("Content-Type", "application/json; charset=utf-8"); urlConnection.connect(); final InputStream inputStream = urlConnection.getInputStream(); InputStreamReader is = new InputStreamReader(inputStream); StringBuilder sb1 = new StringBuilder(); BufferedReader br = new BufferedReader(is); String read = br.readLine(); while (read != null) { sb1.append(read); read = br.readLine(); } record.put("data", sb1.toString()); record.put("status", "OK"); } catch (Exception e) { record.put("status", "error"); record.put("errormsg", e.toString()); } response.setContentType("text/html;charset=UTF-8"); out.print(JSONValue.toJSONString(record)); out.flush(); } if (form_action.equalsIgnoreCase("postCommentPosisi")) { StringBuffer sb = new StringBuffer(); String line = null; LinkedHashMap record = new LinkedHashMap(); try { BufferedReader reader = request.getReader(); while ((line = reader.readLine()) != null) { sb.append(line); } Object obj = JSONValue.parse(sb.toString()); //JSONArray records = (JSONArray) obj; JSONObject obj1 = (JSONObject) obj; JSONObject userAccount = (JSONObject) session.getAttribute("userAccount"); String dept = obj1.get("dept").toString(); String star = obj1.get("star").toString(); String comment = obj1.get("comment").toString(); String id = userAccount.get("id").toString(); String name = userAccount.get("name").toString(); String link = userAccount.get("link").toString(); postData2(name, dept, "", star, comment, id, "AlasanStarCalonPosisi", "dept", dept, link); record.put("status", "OK"); } catch (Exception e) { record.put("status", "error"); record.put("errormsg", e.toString()); } response.setContentType("text/html;charset=UTF-8"); out.print(JSONValue.toJSONString(record)); out.flush(); } if (form_action.equalsIgnoreCase("postLikeComment")) { StringBuffer sb = new StringBuffer(); String line = null; LinkedHashMap record = new LinkedHashMap(); try { BufferedReader reader = request.getReader(); while ((line = reader.readLine()) != null) { sb.append(line); } Object obj = JSONValue.parse(sb.toString()); //JSONArray records = (JSONArray) obj; JSONObject obj1 = (JSONObject) obj; String id = obj1.get("id").toString(); String star = obj1.get("star").toString(); JSONObject userAccount = (JSONObject) session.getAttribute("userAccount"); String name = userAccount.get("name").toString(); String link = userAccount.get("link").toString(); postData11("AlasanStarLike", "id", id, star, link, name); record.put("status", "OK"); } catch (Exception e) { record.put("status", "error"); record.put("errormsg", e.toString()); } response.setContentType("text/html;charset=UTF-8"); out.print(JSONValue.toJSONString(record)); out.flush(); } if (form_action.equalsIgnoreCase("getLikeComment")) { StringBuffer sb = new StringBuffer(); String line = null; LinkedHashMap record = new LinkedHashMap(); String idx_ = ""; try { BufferedReader reader = request.getReader(); while ((line = reader.readLine()) != null) { sb.append(line); } Object obj = JSONValue.parse(sb.toString()); //JSONArray records = (JSONArray) obj; JSONObject obj1 = (JSONObject) obj; idx_ = obj1.get("id").toString(); DatastoreService datastore = DatastoreServiceFactory.getDatastoreService(); LinkedHashMap record11 = new LinkedHashMap(); String link_ = ""; try { JSONObject userAccount = (JSONObject) session.getAttribute("userAccount"); link_ = userAccount.get("link").toString(); } catch (Exception e) { } Key guestbookKey = KeyFactory.createKey("id", idx_); // Run an ancestor query to ensure we see the most up-to-date // view of the Greetings belonging to the selected Guestbook. Query query = new Query("AlasanStarLike", guestbookKey).addSort("date", Query.SortDirection.DESCENDING); //List<Entity> AlasanStars = datastore.prepare(query); PreparedQuery pq = datastore.prepare(query); JSONArray obj11 = new JSONArray(); JSONArray obj11p = new JSONArray(); JSONArray obj11n = new JSONArray(); int i = 0; int ip = 0; int in = 0; double total = 0; double totalp = 0; double totaln = 0; for (Entity AlasanStar : pq.asIterable()) { LinkedHashMap record1 = new LinkedHashMap(); String date = AlasanStar.getProperty("date").toString(); String star = AlasanStar.getProperty("star").toString(); String name = AlasanStar.getProperty("user").toString(); String link = AlasanStar.getProperty("link").toString(); record1.put("date", date); record1.put("star", star); record1.put("name", name); record1.put("link", link); obj11.add(record1); i++; double d = Double.parseDouble(star); total = total + d; if (d >= 0) { obj11p.add(record1); ip++; totalp = totalp + d; } else { obj11n.add(record1); in++; totaln = totaln + d; } if (link_.equalsIgnoreCase(link)) { record11.put("date", date); record11.put("star", star); record11.put("name", name); record11.put("link", link); } } double avg = total / i; if (i == 0) { avg = 0; } DecimalFormat df = new DecimalFormat("#.##"); record.put("total", total); record.put("totalp", totalp); record.put("totaln", totaln); record.put("avg", df.format(avg)); //record.put("AlasanStars", obj11); record.put("AlasanStarsp", obj11p); record.put("AlasanStarsn", obj11n); record.put("AlasanStar", record11); record.put("status", "OK"); } catch (Exception e) { record.put("status", "error"); record.put("errormsg", e.toString()); } response.setContentType("text/html;charset=UTF-8"); out.print(JSONValue.toJSONString(record)); out.flush(); } if (form_action.equalsIgnoreCase("getMyCommentPosisi")) { StringBuffer sb = new StringBuffer(); String line = null; LinkedHashMap record = new LinkedHashMap(); String dept = ""; DatastoreService datastore = DatastoreServiceFactory.getDatastoreService(); LinkedHashMap record1 = new LinkedHashMap(); try { BufferedReader reader = request.getReader(); while ((line = reader.readLine()) != null) { sb.append(line); } Object obj = JSONValue.parse(sb.toString()); //JSONArray records = (JSONArray) obj; JSONObject obj1 = (JSONObject) obj; dept = obj1.get("dept").toString(); String link_ = ""; try { JSONObject userAccount = (JSONObject) session.getAttribute("userAccount"); link_ = userAccount.get("link").toString(); } catch (Exception e) { } LinkedHashMap record11 = new LinkedHashMap(); Key guestbookKey = KeyFactory.createKey("dept", dept); Query query = new Query("AlasanStarCalonPosisi", guestbookKey).addSort("date", Query.SortDirection.DESCENDING); PreparedQuery pq = datastore.prepare(query); JSONArray obj11 = new JSONArray(); JSONArray obj11p = new JSONArray(); JSONArray obj11n = new JSONArray(); int i = 0; int ip = 0; int in = 0; double total = 0; double totalp = 0; double totaln = 0; for (Entity AlasanStar : pq.asIterable()) { record1 = new LinkedHashMap(); String id = AlasanStar.getProperty("user").toString(); //DateTime dateTime = AlasanStar.getProperties().getDateTimeValue(); Date time = (Date) AlasanStar.getProperty("date"); String date = time.toString();//AlasanStar.getProperty("date").toString(); String star = AlasanStar.getProperty("star").toString(); String comment = AlasanStar.getProperty("comment").toString(); comment = comment.replaceAll("\n", "<br/>"); String name = AlasanStar.getProperty("name").toString(); String link = AlasanStar.getProperty("link").toString(); String id__ = AlasanStar.getKey().toString(); record1.put("id_", id__); record1.put("id", id); record1.put("date", date); record1.put("star", star); record1.put("comment", comment); record1.put("name", name); record1.put("link", link); obj11.add(record1); i++; double d = Double.parseDouble(star); total = total + d; if (d >= 0) { obj11p.add(record1); ip++; totalp = totalp + d; } else { obj11n.add(record1); in++; totaln = totaln + d; } if (link_.equalsIgnoreCase(link)) { record11.put("id_", id__); record11.put("id", id); record11.put("date", date); record11.put("star", star); record11.put("comment", comment); record11.put("name", name); record11.put("link", link); } } double avg = total / i; if (i == 0) { avg = 0; } DecimalFormat df = new DecimalFormat("#.##"); record.put("total", total); record.put("totalp", totalp); record.put("totaln", totaln); record.put("avg", df.format(avg)); //record.put("AlasanStars", obj11); record.put("AlasanStarsp", obj11p); record.put("AlasanStarsn", obj11n); record.put("AlasanStar", record11); record.put("status", "OK"); } catch (Exception e) { record.put("status", "error"); record.put("errormsg", e.toString()); } response.setContentType("text/html;charset=UTF-8"); out.print(JSONValue.toJSONString(record)); out.flush(); } if (form_action.equalsIgnoreCase("postComment")) { StringBuffer sb = new StringBuffer(); String line = null; LinkedHashMap record = new LinkedHashMap(); try { BufferedReader reader = request.getReader(); while ((line = reader.readLine()) != null) { sb.append(line); } Object obj = JSONValue.parse(sb.toString()); //JSONArray records = (JSONArray) obj; JSONObject obj1 = (JSONObject) obj; JSONObject userAccount = (JSONObject) session.getAttribute("userAccount"); String dept = obj1.get("dept").toString(); String namaCalon = obj1.get("namaCalon").toString(); String star = obj1.get("star").toString(); String comment = obj1.get("comment").toString(); String id = userAccount.get("id").toString(); String name = userAccount.get("name").toString(); String link = userAccount.get("link").toString(); postData2(name, dept, namaCalon, star, comment, id, "AlasanStarCalon", dept, namaCalon, link); record.put("status", "OK"); } catch (Exception e) { record.put("status", "error"); record.put("errormsg", e.toString()); } response.setContentType("text/html;charset=UTF-8"); out.print(JSONValue.toJSONString(record)); out.flush(); } if (form_action.equalsIgnoreCase("getMyComment")) { StringBuffer sb = new StringBuffer(); String line = null; LinkedHashMap record = new LinkedHashMap(); String dept = ""; String namaCalon = ""; try { BufferedReader reader = request.getReader(); while ((line = reader.readLine()) != null) { sb.append(line); } Object obj = JSONValue.parse(sb.toString()); //JSONArray records = (JSONArray) obj; JSONObject obj1 = (JSONObject) obj; dept = obj1.get("dept").toString(); namaCalon = obj1.get("namaCalon").toString(); DatastoreService datastore = DatastoreServiceFactory.getDatastoreService(); String link_ = ""; LinkedHashMap record11 = new LinkedHashMap(); try { JSONObject userAccount = (JSONObject) session.getAttribute("userAccount"); link_ = userAccount.get("link").toString(); } catch (Exception e) { } Key guestbookKey = KeyFactory.createKey(dept, namaCalon); Query query = new Query("AlasanStarCalon", guestbookKey).addSort("date", Query.SortDirection.DESCENDING); PreparedQuery pq = datastore.prepare(query); JSONArray obj11 = new JSONArray(); JSONArray obj11p = new JSONArray(); JSONArray obj11n = new JSONArray(); int i = 0; int ip = 0; int in = 0; double total = 0; double totalp = 0; double totaln = 0; for (Entity AlasanStar : pq.asIterable()) { LinkedHashMap record1 = new LinkedHashMap(); String id = AlasanStar.getProperty("user").toString(); Date time = (Date) AlasanStar.getProperty("date"); String date = time.toString();//AlasanStar.getProperty("date").toString(); String star = AlasanStar.getProperty("star").toString(); String comment = AlasanStar.getProperty("comment").toString(); comment = comment.replaceAll("\n", "<br/>"); String name = AlasanStar.getProperty("name").toString(); String link = AlasanStar.getProperty("link").toString(); String id__ = AlasanStar.getKey().toString(); record1.put("id_", id__); record1.put("id", id); record1.put("date", date); record1.put("star", star); record1.put("comment", comment); record1.put("name", name); record1.put("link", link); obj11.add(record1); i++; double d = Double.parseDouble(star); total = total + d; if (d >= 0) { obj11p.add(record1); ip++; totalp = totalp + d; } else { obj11n.add(record1); in++; totaln = totaln + d; } if (link_.equalsIgnoreCase(link)) { record11.put("id_", id__); record11.put("id", id); record11.put("date", date); record11.put("star", star); record11.put("comment", comment); record11.put("name", name); record11.put("link", link); } } double avg = total / i; if (i == 0) { avg = 0; } DecimalFormat df = new DecimalFormat("#.##"); record.put("total", total); record.put("totalp", totalp); record.put("totaln", totaln); record.put("avg", df.format(avg)); record.put("AlasanStarsp", obj11p); record.put("AlasanStarsn", obj11n); record.put("AlasanStar", record11); record.put("status", "OK"); } catch (Exception e) { record.put("status", "error"); record.put("errormsg", e.toString()); } response.setContentType("text/html;charset=UTF-8"); out.print(JSONValue.toJSONString(record)); out.flush(); } if (form_action.equalsIgnoreCase("getAlasanStarCalon")) { StringBuffer sb = new StringBuffer(); String line = null; LinkedHashMap record = new LinkedHashMap(); try { BufferedReader reader = request.getReader(); while ((line = reader.readLine()) != null) { sb.append(line); } Object obj = JSONValue.parse(sb.toString()); //JSONArray records = (JSONArray) obj; JSONObject obj1 = (JSONObject) obj; JSONObject userAccount = (JSONObject) session.getAttribute("userAccount"); String dept = obj1.get("dept").toString(); String namaCalon = obj1.get("namaCalon").toString(); DatastoreService datastore = DatastoreServiceFactory.getDatastoreService(); Key guestbookKey = KeyFactory.createKey(dept, namaCalon); // Run an ancestor query to ensure we see the most up-to-date // view of the Greetings belonging to the selected Guestbook. Query query = new Query("AlasanStarCalon", guestbookKey).addSort("date", Query.SortDirection.DESCENDING); //List<Entity> AlasanStars = datastore.prepare(query); PreparedQuery pq = datastore.prepare(query); JSONArray obj11 = new JSONArray(); int i = 0; double total = 0; for (Entity AlasanStar : pq.asIterable()) { LinkedHashMap record1 = new LinkedHashMap(); String id = AlasanStar.getProperty("user").toString(); String date = AlasanStar.getProperty("date").toString(); String star = AlasanStar.getProperty("star").toString(); String comment = AlasanStar.getProperty("comment").toString(); comment = comment.replaceAll("\n", "<br/>"); String name = AlasanStar.getProperty("name").toString(); String link = AlasanStar.getProperty("link").toString(); String id__ = AlasanStar.getKey().toString(); record1.put("id_", id__); record1.put("id", id); record1.put("date", date); record1.put("star", star); record1.put("comment", comment); record1.put("name", name); record1.put("link", link); obj11.add(record1); i++; double d = Double.parseDouble(star); total = total + d; } double avg = total / i; if (i == 0) { avg = 0; } DecimalFormat df = new DecimalFormat("#.##"); record.put("total", total); record.put("avg", df.format(avg)); record.put("AlasanStars", obj11); record.put("status", "OK"); } catch (Exception e) { record.put("status", "error"); record.put("errormsg", e.toString()); } response.setContentType("text/html;charset=UTF-8"); out.print(JSONValue.toJSONString(record)); out.flush(); } if (form_action.equalsIgnoreCase("postUsulan")) { StringBuffer sb = new StringBuffer(); String line = null; LinkedHashMap record = new LinkedHashMap(); try { BufferedReader reader = request.getReader(); while ((line = reader.readLine()) != null) { sb.append(line); } Object obj = JSONValue.parse(sb.toString()); //JSONArray records = (JSONArray) obj; JSONObject obj1 = (JSONObject) obj; String dept = obj1.get("dept").toString(); String usulan = obj1.get("usulan").toString(); JSONObject userAccount = (JSONObject) session.getAttribute("userAccount"); String id = userAccount.get("id").toString(); String name = userAccount.get("name").toString(); String email = userAccount.get("email").toString(); String link = userAccount.get("link").toString(); Key usulanCalonKey = KeyFactory.createKey("dept", dept); Date date = new Date(); Entity usulanCalon = new Entity("usulanCalon", usulanCalonKey); usulanCalon.setProperty("user", id); usulanCalon.setProperty("name", name); usulanCalon.setProperty("email", email); usulanCalon.setProperty("link", link); usulanCalon.setProperty("date", date); usulanCalon.setProperty("usulan", usulan); DatastoreService datastore = DatastoreServiceFactory.getDatastoreService(); usulanCalon.setProperty("imported", "N"); datastore.put(usulanCalon); record.put("status", "OK"); } catch (Exception e) { record.put("status", "error"); record.put("errormsg", e.toString()); } response.setContentType("text/html;charset=UTF-8"); out.print(JSONValue.toJSONString(record)); out.flush(); } if (form_action.equalsIgnoreCase("getSet1")) { StringBuffer sb = new StringBuffer(); String line = null; LinkedHashMap record = new LinkedHashMap(); try { BufferedReader reader = request.getReader(); while ((line = reader.readLine()) != null) { sb.append(line); } Object obj = JSONValue.parse(sb.toString()); //JSONArray records = (JSONArray) obj; JSONObject obj1 = (JSONObject) obj; String input = obj1.get("input").toString(); String type = obj1.get("type").toString(); DatastoreService datastore = DatastoreServiceFactory.getDatastoreService(); Key typeKey = KeyFactory.createKey("posisi", type.toLowerCase().replaceAll(" ", "")); // Run an ancestor query to ensure we see the most up-to-date // view of the Greetings belonging to the selected Guestbook. Query query = new Query("posisi", typeKey).addSort("date", Query.SortDirection.ASCENDING); //List<Entity> AlasanStars = datastore.prepare(query); PreparedQuery pq = datastore.prepare(query); JSONArray obj11 = new JSONArray(); String id = ""; try { JSONObject userAccount = (JSONObject) session.getAttribute("userAccount"); id = userAccount.get("id").toString(); } catch (Exception ex1) { } for (Entity typeEntity : pq.asIterable()) { String reviewed = typeEntity.getProperty("reviewed").toString(); if (reviewed.equalsIgnoreCase("Y")) { LinkedHashMap record1 = new LinkedHashMap(); String posisi = typeEntity.getProperty("posisi").toString(); String nama = typeEntity.getProperty("nama").toString(); String link = typeEntity.getProperty("link").toString(); String date = typeEntity.getProperty("date").toString(); record1.put("posisi", posisi); record1.put("nama", nama); record1.put("link", link); record1.put("date", date); String detail1 = ""; try { Text detail0 = (Text) typeEntity.getProperty("detail"); detail1 = detail0.getValue(); } catch (Exception e) { detail1 = ""; } record1.put("detail", detail1); obj11.add(record1); } else { String user = typeEntity.getProperty("user").toString(); if (user.equalsIgnoreCase(id)) { LinkedHashMap record1 = new LinkedHashMap(); String posisi = typeEntity.getProperty("posisi").toString(); String nama = typeEntity.getProperty("nama").toString(); String link = typeEntity.getProperty("link").toString(); String date = typeEntity.getProperty("date").toString(); record1.put("posisi", posisi); record1.put("nama", nama); record1.put("link", link); record1.put("date", date); String detail1 = ""; try { Text detail0 = (Text) typeEntity.getProperty("detail"); detail1 = detail0.getValue(); } catch (Exception e) { detail1 = ""; } record1.put("detail", detail1); obj11.add(record1); } } } record.put("records", obj11); record.put("status", "OK"); } catch (Exception e) { record.put("status", "error"); record.put("errormsg", e.toString()); } response.setContentType("text/html;charset=UTF-8"); out.print(JSONValue.toJSONString(record)); out.flush(); } if (form_action.equalsIgnoreCase("setSet1")) { StringBuffer sb = new StringBuffer(); String line = null; LinkedHashMap record = new LinkedHashMap(); try { JSONObject userAccount = (JSONObject) session.getAttribute("userAccount"); String id = userAccount.get("id").toString(); String nama = userAccount.get("name").toString(); String email = userAccount.get("email").toString(); String link = userAccount.get("link").toString(); String admin = userAccount.get("admin").toString(); BufferedReader reader = request.getReader(); while ((line = reader.readLine()) != null) { sb.append(line); } Object obj = JSONValue.parse(sb.toString()); //JSONArray records = (JSONArray) obj; JSONObject obj1 = (JSONObject) obj; String input = obj1.get("input").toString(); String type = obj1.get("type").toString(); String value = obj1.get("value").toString(); String detail = obj1.get("value1").toString(); Key typeKey = KeyFactory.createKey("posisi", type.toLowerCase().replaceAll(" ", "")); Filter posisinama = new FilterPredicate("posisi", FilterOperator.EQUAL, value); // Run an ancestor query to ensure we see the most up-to-date // view of the Greetings belonging to the selected Guestbook. Query query = new Query("posisi", typeKey).setFilter(posisinama); //Query query = new Query("posisi", typeKey);//.addSort("date", Query.SortDirection.DESCENDING); //List<Entity> AlasanStars = datastore.prepare(query); DatastoreService datastore = DatastoreServiceFactory.getDatastoreService(); PreparedQuery pq = datastore.prepare(query); boolean found = pq.asIterable().iterator().hasNext(); if (found) { if (admin.equalsIgnoreCase("Y")) { for (Entity psosisiEntity : pq.asList(FetchOptions.Builder.withLimit(1))) { Date date = new Date(); psosisiEntity.setProperty("date", date); psosisiEntity.setProperty("detail", new Text(detail)); datastore.put(psosisiEntity); } } } if (!found) { Date date = new Date(); Entity psosisiEntity = new Entity("posisi", typeKey); psosisiEntity.setProperty("user", id); psosisiEntity.setProperty("link", link); psosisiEntity.setProperty("nama", nama); psosisiEntity.setProperty("email", email); psosisiEntity.setProperty("date", date); psosisiEntity.setProperty("posisi", value); psosisiEntity.setProperty("detail", new Text(detail)); if (email.equalsIgnoreCase("khairul.anshar@gmail.com") || id.equalsIgnoreCase("112525777678499279265") || id.equalsIgnoreCase("10152397276159760") || nama.equalsIgnoreCase("Khairul Anshar") || admin.equalsIgnoreCase("Y")) { psosisiEntity.setProperty("reviewed", "Y"); psosisiEntity.setProperty("nama", "Kawal Menteri"); psosisiEntity.setProperty("link", "https://www.facebook.com/KawalMenteri"); } else { psosisiEntity.setProperty("reviewed", "N"); } psosisiEntity.setProperty("imported", "N"); datastore.put(psosisiEntity); } query = new Query("posisi", typeKey).addSort("date", Query.SortDirection.ASCENDING); pq = datastore.prepare(query); JSONArray obj11 = new JSONArray(); for (Entity typeEntity : pq.asIterable()) { String reviewed = typeEntity.getProperty("reviewed").toString(); if (reviewed.equalsIgnoreCase("Y")) { LinkedHashMap record1 = new LinkedHashMap(); String posisi = typeEntity.getProperty("posisi").toString(); String nama1 = typeEntity.getProperty("nama").toString(); String link1 = typeEntity.getProperty("link").toString(); String date = typeEntity.getProperty("date").toString(); record1.put("posisi", posisi); record1.put("nama", nama1); record1.put("link", link1); record1.put("date", date); String detail1 = ""; try { Text detail0 = (Text) typeEntity.getProperty("detail"); detail1 = detail0.getValue(); } catch (Exception e) { detail1 = ""; } record1.put("detail", detail1); obj11.add(record1); } else { String user = typeEntity.getProperty("user").toString(); if (user.equalsIgnoreCase(id) || (email.equalsIgnoreCase("khairul.anshar@gmail.com") || id.equalsIgnoreCase("112525777678499279265") || id.equalsIgnoreCase("10152397276159760") || nama.equalsIgnoreCase("Khairul Anshar") || admin.equalsIgnoreCase("Y"))) { LinkedHashMap record1 = new LinkedHashMap(); String posisi = typeEntity.getProperty("posisi").toString(); String nama1 = typeEntity.getProperty("nama").toString(); String link1 = typeEntity.getProperty("link").toString(); String date = typeEntity.getProperty("date").toString(); record1.put("posisi", posisi); record1.put("nama", nama1); record1.put("link", link1); record1.put("date", date); String detail1 = ""; try { Text detail0 = (Text) typeEntity.getProperty("detail"); detail1 = detail0.getValue(); } catch (Exception e) { detail1 = ""; } record1.put("detail", detail1); obj11.add(record1); } } } record.put("records", obj11); record.put("status", "OK"); } catch (Exception e) { record.put("status", "error"); record.put("errormsg", e.toString()); } response.setContentType("text/html;charset=UTF-8"); out.print(JSONValue.toJSONString(record)); out.flush(); } if (form_action.equalsIgnoreCase("getSet2")) { StringBuffer sb = new StringBuffer(); String line = null; LinkedHashMap record = new LinkedHashMap(); try { BufferedReader reader = request.getReader(); while ((line = reader.readLine()) != null) { sb.append(line); } Object obj = JSONValue.parse(sb.toString()); //JSONArray records = (JSONArray) obj; JSONObject obj1 = (JSONObject) obj; String input = obj1.get("input").toString(); String input0 = obj1.get("input0").toString(); String type0 = obj1.get("type0").toString(); DatastoreService datastore = DatastoreServiceFactory.getDatastoreService(); Key typeKey = KeyFactory.createKey("kandidat" + type0, input); // Run an ancestor query to ensure we see the most up-to-date // view of the Greetings belonging to the selected Guestbook. Query query = new Query("kandidat", typeKey).addSort("date", Query.SortDirection.ASCENDING); //List<Entity> AlasanStars = datastore.prepare(query); PreparedQuery pq = datastore.prepare(query); JSONArray obj11 = new JSONArray(); String id = ""; String nama = ""; String email = ""; String link = ""; String admin = ""; String icw = ""; try { JSONObject userAccount = (JSONObject) session.getAttribute("userAccount"); id = userAccount.get("id").toString(); nama = userAccount.get("name").toString(); email = userAccount.get("email").toString(); link = userAccount.get("link").toString(); admin = userAccount.get("admin").toString(); icw = userAccount.get("icw").toString(); } catch (Exception ex1) { } for (Entity typeEntity : pq.asIterable()) { String reviewed = typeEntity.getProperty("reviewed").toString(); if (reviewed.equalsIgnoreCase("Y")) { LinkedHashMap record1 = new LinkedHashMap(); String kandidat = typeEntity.getProperty("kandidat").toString(); String desc = typeEntity.getProperty("desc").toString(); Text detail0 = (Text) typeEntity.getProperty("detail"); String detail = detail0.getValue(); String nama1 = typeEntity.getProperty("nama").toString(); String link1 = typeEntity.getProperty("link").toString(); String date = typeEntity.getProperty("date").toString(); String icwcomment = ""; try { icwcomment = typeEntity.getProperty("icwcomment").toString(); } catch (Exception e) { icwcomment = ""; } record1.put("key", "kandidat" + type0); record1.put("val", input); record1.put("kandidat", kandidat); record1.put("desc", desc); record1.put("detail", detail); record1.put("nama", nama1); record1.put("link", link1); record1.put("date", date); record1.put("icwcomment", icwcomment); obj11.add(record1); } else { String user = typeEntity.getProperty("user").toString(); if (user.equalsIgnoreCase(id) || (email.equalsIgnoreCase("khairul.anshar@gmail.com") || id.equalsIgnoreCase("112525777678499279265") || id.equalsIgnoreCase("10152397276159760") || nama.equalsIgnoreCase("Khairul Anshar") || admin.equalsIgnoreCase("Y"))) { LinkedHashMap record1 = new LinkedHashMap(); String kandidat = typeEntity.getProperty("kandidat").toString(); String desc = typeEntity.getProperty("desc").toString(); Text detail0 = (Text) typeEntity.getProperty("detail"); String detail = detail0.getValue(); String nama1 = typeEntity.getProperty("nama").toString(); String link1 = typeEntity.getProperty("link").toString(); String date = typeEntity.getProperty("date").toString(); record1.put("key", "kandidat" + type0); record1.put("val", input); record1.put("kandidat", kandidat); record1.put("desc", desc); record1.put("detail", detail); record1.put("nama", nama1); record1.put("link", link1); record1.put("date", date); String icwcomment = ""; if (email.equalsIgnoreCase("khairul.anshar@gmail.com") || id.equalsIgnoreCase("112525777678499279265") || id.equalsIgnoreCase("10152397276159760") || nama.equalsIgnoreCase("Khairul Anshar") || admin.equalsIgnoreCase("Y") || icw.equalsIgnoreCase("Y")) { try { icwcomment = typeEntity.getProperty("icwcomment").toString(); } catch (Exception e) { icwcomment = ""; } } record1.put("icwcomment", icwcomment); obj11.add(record1); } } } record.put("records", obj11); record.put("status", "OK"); } catch (Exception e) { record.put("status", "error"); record.put("errormsg", e.toString()); } response.setContentType("text/html;charset=UTF-8"); out.print(JSONValue.toJSONString(record)); out.flush(); } if (form_action.equalsIgnoreCase("setIcwComment")) { StringBuffer sb = new StringBuffer(); String line = null; LinkedHashMap record = new LinkedHashMap(); try { JSONObject userAccount = (JSONObject) session.getAttribute("userAccount"); String icw = userAccount.get("icw").toString(); if (icw.equalsIgnoreCase("N")) { } else { BufferedReader reader = request.getReader(); while ((line = reader.readLine()) != null) { sb.append(line); } Object obj = JSONValue.parse(sb.toString()); //JSONArray records = (JSONArray) obj; JSONObject obj1 = (JSONObject) obj; String input = obj1.get("input").toString(); String input0 = obj1.get("input0").toString(); String type0 = obj1.get("type0").toString(); String value = obj1.get("value").toString(); String menteri = obj1.get("menteri").toString(); String kandidat = obj1.get("kandidat").toString(); Key typeKey = KeyFactory.createKey("kandidat" + type0, input); // Run an ancestor query to ensure we see the most up-to-date // view of the Greetings belonging to the selected Guestbook. Filter namaKandidat = new FilterPredicate("kandidat", FilterOperator.EQUAL, kandidat); // Run an ancestor query to ensure we see the most up-to-date // view of the Greetings belonging to the selected Guestbook. Query query = new Query("kandidat", typeKey).setFilter(namaKandidat); //Query query = new Query("posisi", typeKey);//.addSort("date", Query.SortDirection.DESCENDING); //List<Entity> AlasanStars = datastore.prepare(query); DatastoreService datastore = DatastoreServiceFactory.getDatastoreService(); for (Entity psosisiEntity : datastore.prepare(query) .asList(FetchOptions.Builder.withLimit(1))) { psosisiEntity.setProperty("icwcomment", value); datastore.put(psosisiEntity); } } record.put("status", "OK"); } catch (Exception e) { record.put("status", "error"); record.put("errormsg", e.toString()); } response.setContentType("text/html;charset=UTF-8"); out.print(JSONValue.toJSONString(record)); out.flush(); } if (form_action.equalsIgnoreCase("setSet2")) { StringBuffer sb = new StringBuffer(); String line = null; LinkedHashMap record = new LinkedHashMap(); try { JSONObject userAccount = (JSONObject) session.getAttribute("userAccount"); String id = userAccount.get("id").toString(); String nama = userAccount.get("name").toString(); String email = userAccount.get("email").toString(); String link = userAccount.get("link").toString(); String admin = userAccount.get("admin").toString(); String icw = userAccount.get("icw").toString(); BufferedReader reader = request.getReader(); while ((line = reader.readLine()) != null) { sb.append(line); } Object obj = JSONValue.parse(sb.toString()); //JSONArray records = (JSONArray) obj; JSONObject obj1 = (JSONObject) obj; String input = obj1.get("input").toString(); String input0 = obj1.get("input0").toString(); String type0 = obj1.get("type0").toString(); String value = obj1.get("value").toString(); String value1 = obj1.get("value1").toString(); String value2 = obj1.get("value2").toString(); String menteri = obj1.get("menteri").toString(); Key typeKey = KeyFactory.createKey("kandidat" + type0, input); // Run an ancestor query to ensure we see the most up-to-date // view of the Greetings belonging to the selected Guestbook. Filter namaKandidat = new FilterPredicate("kandidat", FilterOperator.EQUAL, value); // Run an ancestor query to ensure we see the most up-to-date // view of the Greetings belonging to the selected Guestbook. Query query = new Query("kandidat", typeKey).setFilter(namaKandidat); //Query query = new Query("posisi", typeKey);//.addSort("date", Query.SortDirection.DESCENDING); //List<Entity> AlasanStars = datastore.prepare(query); DatastoreService datastore = DatastoreServiceFactory.getDatastoreService(); PreparedQuery pq = datastore.prepare(query); boolean found = pq.asIterable().iterator().hasNext(); if (found) { if (admin.equalsIgnoreCase("Y")) { for (Entity psosisiEntity : pq.asList(FetchOptions.Builder.withLimit(1))) { Date date = new Date(); psosisiEntity.setProperty("date", date); psosisiEntity.setProperty("detail", new Text(value2)); datastore.put(psosisiEntity); } } } if (!found) { Date date = new Date(); Entity psosisiEntity = new Entity("kandidat", typeKey); psosisiEntity.setProperty("user", id); psosisiEntity.setProperty("link", link); psosisiEntity.setProperty("nama", nama); psosisiEntity.setProperty("email", email); psosisiEntity.setProperty("date", date); psosisiEntity.setProperty("kandidat", value); psosisiEntity.setProperty("desc", value1); psosisiEntity.setProperty("posisi", menteri); psosisiEntity.setProperty("detail", new Text(value2)); psosisiEntity.setProperty("icwcomment", ""); if (email.equalsIgnoreCase("khairul.anshar@gmail.com") || id.equalsIgnoreCase("112525777678499279265") || id.equalsIgnoreCase("10152397276159760") || nama.equalsIgnoreCase("Khairul Anshar") || admin.equalsIgnoreCase("Y")) { psosisiEntity.setProperty("reviewed", "Y"); psosisiEntity.setProperty("nama", "Kawal Menteri"); psosisiEntity.setProperty("link", "https://www.facebook.com/KawalMenteri"); } else { psosisiEntity.setProperty("reviewed", "N"); } psosisiEntity.setProperty("imported", "N"); datastore.put(psosisiEntity); } query = new Query("kandidat", typeKey).addSort("date", Query.SortDirection.ASCENDING); pq = datastore.prepare(query); JSONArray obj11 = new JSONArray(); for (Entity typeEntity : pq.asIterable()) { String reviewed = typeEntity.getProperty("reviewed").toString(); if (reviewed.equalsIgnoreCase("Y")) { LinkedHashMap record1 = new LinkedHashMap(); String kandidat = typeEntity.getProperty("kandidat").toString(); String desc = typeEntity.getProperty("desc").toString(); Text detail0 = (Text) typeEntity.getProperty("detail"); String detail = detail0.getValue(); String nama1 = typeEntity.getProperty("nama").toString(); String link1 = typeEntity.getProperty("link").toString(); String date = typeEntity.getProperty("date").toString(); String icwcomment = ""; try { icwcomment = typeEntity.getProperty("icwcomment").toString(); } catch (Exception e) { icwcomment = ""; } record1.put("key", "kandidat" + type0); record1.put("val", input); record1.put("kandidat", kandidat); record1.put("desc", desc); record1.put("detail", detail); record1.put("nama", nama1); record1.put("link", link1); record1.put("date", date); record1.put("icwcomment", icwcomment); obj11.add(record1); } else { String user = typeEntity.getProperty("user").toString(); if (user.equalsIgnoreCase(id) || (email.equalsIgnoreCase("khairul.anshar@gmail.com") || id.equalsIgnoreCase("112525777678499279265") || id.equalsIgnoreCase("10152397276159760") || nama.equalsIgnoreCase("Khairul Anshar") || admin.equalsIgnoreCase("Y"))) { LinkedHashMap record1 = new LinkedHashMap(); String kandidat = typeEntity.getProperty("kandidat").toString(); String desc = typeEntity.getProperty("desc").toString(); Text detail0 = (Text) typeEntity.getProperty("detail"); String detail = detail0.getValue(); String nama1 = typeEntity.getProperty("nama").toString(); String link1 = typeEntity.getProperty("link").toString(); String date = typeEntity.getProperty("date").toString(); record1.put("key", "kandidat" + type0); record1.put("val", input); record1.put("kandidat", kandidat); record1.put("desc", desc); record1.put("detail", detail); record1.put("nama", nama1); record1.put("link", link1); record1.put("date", date); String icwcomment = ""; if (email.equalsIgnoreCase("khairul.anshar@gmail.com") || id.equalsIgnoreCase("112525777678499279265") || id.equalsIgnoreCase("10152397276159760") || nama.equalsIgnoreCase("Khairul Anshar") || admin.equalsIgnoreCase("Y") || icw.equalsIgnoreCase("Y")) { try { icwcomment = typeEntity.getProperty("icwcomment").toString(); } catch (Exception e) { icwcomment = ""; } } record1.put("icwcomment", icwcomment); obj11.add(record1); } } } record.put("records", obj11); record.put("status", "OK"); } catch (Exception e) { record.put("status", "error"); record.put("errormsg", e.toString()); } response.setContentType("text/html;charset=UTF-8"); out.print(JSONValue.toJSONString(record)); out.flush(); } }
From source file:org.apache.manifoldcf.crawler.connectors.jira.JiraRepositoryConnector.java
/** Process a set of documents. * This is the method that should cause each document to be fetched, processed, and the results either added * to the queue of documents for the current job, and/or entered into the incremental ingestion manager. * The document specification allows this class to filter what is done based on the job. * The connector will be connected before this method can be called. *@param documentIdentifiers is the set of document identifiers to process. *@param statuses are the currently-stored document versions for each document in the set of document identifiers * passed in above./* www .j av a 2 s.c o m*/ *@param activities is the interface this method should use to queue up new document references * and ingest documents. *@param jobMode is an integer describing how the job is being run, whether continuous or once-only. *@param usesDefaultAuthority will be true only if the authority in use for these documents is the default one. */ @Override public void processDocuments(String[] documentIdentifiers, IExistingVersions statuses, Specification spec, IProcessActivity activities, int jobMode, boolean usesDefaultAuthority) throws ManifoldCFException, ServiceInterruption { // Forced acls String[] acls = getAcls(spec); if (acls != null) java.util.Arrays.sort(acls); for (String documentIdentifier : documentIdentifiers) { if (documentIdentifier.startsWith("I-")) { // It is an issue String versionString; String[] aclsToUse; String issueID; JiraIssue jiraFile; issueID = documentIdentifier.substring(2); jiraFile = getIssue(issueID); if (jiraFile == null) { activities.deleteDocument(documentIdentifier); continue; } Date rev = jiraFile.getUpdatedDate(); if (rev == null) { //a jira document that doesn't contain versioning information will NEVER be processed. // I don't know what this means, and whether it can ever occur. activities.deleteDocument(documentIdentifier); continue; } StringBuilder sb = new StringBuilder(); if (acls == null) { // Get acls from issue List<String> users = getUsers(issueID); aclsToUse = (String[]) users.toArray(new String[0]); java.util.Arrays.sort(aclsToUse); } else { aclsToUse = acls; } // Acls packList(sb, aclsToUse, '+'); if (aclsToUse.length > 0) { sb.append('+'); pack(sb, defaultAuthorityDenyToken, '+'); } else sb.append('-'); sb.append(rev.toString()); versionString = sb.toString(); if (activities.checkDocumentNeedsReindexing(documentIdentifier, versionString)) continue; if (Logging.connectors.isDebugEnabled()) { Logging.connectors.debug("JIRA: Processing document identifier '" + documentIdentifier + "'"); } long startTime = System.currentTimeMillis(); String errorCode = null; String errorDesc = null; Long fileSize = null; try { // Now do standard stuff String mimeType = "text/plain"; Date createdDate = jiraFile.getCreatedDate(); Date modifiedDate = jiraFile.getUpdatedDate(); String documentURI = composeDocumentURI(getBaseUrl(session), jiraFile.getKey()); if (!activities.checkURLIndexable(documentURI)) { errorCode = activities.EXCLUDED_URL; errorDesc = "Excluded because of URL ('" + documentURI + "')"; activities.noDocument(documentIdentifier, versionString); continue; } if (!activities.checkMimeTypeIndexable(mimeType)) { errorCode = activities.EXCLUDED_MIMETYPE; errorDesc = "Excluded because of mime type ('" + mimeType + "')"; activities.noDocument(documentIdentifier, versionString); continue; } if (!activities.checkDateIndexable(modifiedDate)) { errorCode = activities.EXCLUDED_DATE; errorDesc = "Excluded because of date (" + modifiedDate + ")"; activities.noDocument(documentIdentifier, versionString); continue; } //otherwise process RepositoryDocument rd = new RepositoryDocument(); // Turn into acls and add into description String[] denyAclsToUse; if (aclsToUse.length > 0) denyAclsToUse = new String[] { defaultAuthorityDenyToken }; else denyAclsToUse = new String[0]; rd.setSecurity(RepositoryDocument.SECURITY_TYPE_DOCUMENT, aclsToUse, denyAclsToUse); rd.setMimeType(mimeType); if (createdDate != null) rd.setCreatedDate(createdDate); if (modifiedDate != null) rd.setModifiedDate(modifiedDate); rd.addField("key", jiraFile.getKey()); rd.addField("self", jiraFile.getSelf()); rd.addField("description", jiraFile.getDescription()); // Get general document metadata Map<String, String[]> metadataMap = jiraFile.getMetadata(); for (Entry<String, String[]> entry : metadataMap.entrySet()) { rd.addField(entry.getKey(), entry.getValue()); } String document = getJiraBody(jiraFile); try { byte[] documentBytes = document.getBytes(StandardCharsets.UTF_8); long fileLength = documentBytes.length; if (!activities.checkLengthIndexable(fileLength)) { errorCode = activities.EXCLUDED_LENGTH; errorDesc = "Excluded because of document length (" + fileLength + ")"; activities.noDocument(documentIdentifier, versionString); continue; } InputStream is = new ByteArrayInputStream(documentBytes); try { rd.setBinary(is, fileLength); activities.ingestDocumentWithException(documentIdentifier, versionString, documentURI, rd); // No errors. Record the fact that we made it. errorCode = "OK"; fileSize = new Long(fileLength); } finally { is.close(); } } catch (java.io.IOException e) { errorCode = e.getClass().getSimpleName().toUpperCase(Locale.ROOT); errorDesc = e.getMessage(); handleIOException(e); } } catch (ManifoldCFException e) { if (e.getErrorCode() == ManifoldCFException.INTERRUPTED) errorCode = null; throw e; } finally { if (errorCode != null) activities.recordActivity(new Long(startTime), ACTIVITY_READ, fileSize, documentIdentifier, errorCode, errorDesc, null); } } else { // Unrecognized identifier type activities.deleteDocument(documentIdentifier); continue; } } }
From source file:mom.trd.opentheso.bdd.helper.RelationsHelper.java
/** * Cette fonction permet de rcuprer la liste de l'historique des relations * d'un concept une date prcise d'un concept * * @param ds// w w w . j av a2s . c om * @param idConcept * @param idThesaurus * @param date * @param lang * @return Objet class Concept */ public ArrayList<Relation> getRelationHistoriqueFromDate(HikariDataSource ds, String idConcept, String idThesaurus, Date date, String lang) { Connection conn; Statement stmt; ResultSet resultSet; ArrayList<Relation> listRel = null; try { // Get connection from pool conn = ds.getConnection(); try { stmt = conn.createStatement(); try { String query = "select lexical_value, id_concept2, role, action, hierarchical_relationship_historique.modified, username " + "from hierarchical_relationship_historique, users, preferred_term, term" + " where hierarchical_relationship_historique.id_thesaurus = '" + idThesaurus + "'" + " and hierarchical_relationship_historique.id_concept1=preferred_term.id_concept" + " and preferred_term.id_term=term.id_term" + " and term.lang='" + lang + "'" + " and term.id_thesaurus='" + idThesaurus + "'" + " and ( id_concept1 = '" + idConcept + "'" + " or id_concept2 = '" + idConcept + "' )" + " and hierarchical_relationship_historique.id_user=users.id_user" + " and hierarchical_relationship_historique.modified <= '" + date.toString() + "' order by hierarchical_relationship_historique.modified ASC"; stmt.executeQuery(query); resultSet = stmt.getResultSet(); if (resultSet != null) { listRel = new ArrayList<>(); while (resultSet.next()) { if (resultSet.getString("action").equals("DEL")) { for (Relation rel : listRel) { if (rel.getId_concept1().equals(resultSet.getString("lexical_value")) && rel.getId_concept2().equals(resultSet.getString("id_concept2")) && rel.getAction().equals("ADD") && rel.getId_relation().equals(resultSet.getString("role"))) { listRel.remove(rel); break; } } } else { Relation r = new Relation(); r.setId_relation(resultSet.getString("role")); r.setId_concept1(resultSet.getString("lexical_value")); r.setId_concept2(resultSet.getString("id_concept2")); r.setModified(resultSet.getDate("modified")); r.setIdUser(resultSet.getString("username")); r.setAction(resultSet.getString("action")); r.setId_thesaurus(idThesaurus); listRel.add(r); } } } } finally { stmt.close(); } } finally { conn.close(); } } catch (SQLException sqle) { // Log exception log.error("Error while getting date relation historique of Concept : " + idConcept, sqle); } return listRel; }
From source file:com.jaspersoft.jasperserver.api.engine.scheduling.ReportSchedulingFacade.java
public List<ReportJobSummary> getJobsByNextFireTime(ExecutionContext context, List<ReportJob> searchList, Date startNextTriggerFireDate, Date endNextTriggerFireDate, List<Byte> includeTriggerStates) { ////from w w w. jav a2 s . c o m // Review / todo: 2012-03-07 thorick: it may yield some benefit to have the underlying Hibernate // query exclude any jobs whose Calendar start and end dates // lie OUTSIDE of our nextTriggerFire time dates // // get the big list for starters p("getJobsByNextFireTime START"); List<ReportJobSummary> list = null; if (searchList != null && searchList.size() > 0) { list = persistenceService.listJobs(context, searchList); } else { p("about to do persistenceService.listJobs(context)"); // THORICK CATCH ANYTHING try { list = persistenceService.listJobs(context); p("DONE. about to do persistenceService.listJobs(context)"); } catch (Throwable th) { p("ERROR GOT THROWABLE " + th.getClass().getName() + " FROM persistenceService " + th.getMessage()); th.printStackTrace(); throw new RuntimeException(th); } } // apply filters record by record p("getJobsByNextFireTime List has " + list.size() + " candidate ReportJobSummary entries"); p("current time is " + new Date()); p("startDate=" + (startNextTriggerFireDate == null ? "NULL" : startNextTriggerFireDate.toString())); p("endDate=" + (endNextTriggerFireDate == null ? "NULL" : endNextTriggerFireDate.toString())); if (startNextTriggerFireDate == null && endNextTriggerFireDate == null && includeTriggerStates == null) return list; // prepare filtering setSummaryRuntimeInformation(context, list); List<ReportJobSummary> filteredList = new LinkedList<ReportJobSummary>(list); Iterator<ReportJobSummary> it = list.iterator(); while (it.hasNext()) { ReportJobSummary rjs = it.next(); //p("next ReportJobSummary "+rjs.getId()); ReportJobRuntimeInformation rjr = rjs.getRuntimeInformation(); if (rjr != null) { Date nextFireTime = rjr.getNextFireTime(); if (nextFireTime != null) { if (startNextTriggerFireDate != null) { //p("startDate="+startNextTriggerFireDate+", nextFireTime="+nextFireTime); if (nextFireTime.before(startNextTriggerFireDate)) { //p(rjs.getId()+" remove from list."); filteredList.remove(rjs); continue; } } if (endNextTriggerFireDate != null) { //p("endDate="+endNextTriggerFireDate+", nextFireTime="+nextFireTime); if (nextFireTime.after(endNextTriggerFireDate)) { //p(rjs.getId()+"remove from list."); filteredList.remove(rjs); continue; } } } if (includeTriggerStates != null && includeTriggerStates.size() > 0) { Byte triggerState = rjr.getStateCode(); //p("check TriggerStates state of this trigger == '"+triggerState+"'"); if (!includeTriggerStates.contains(triggerState)) { filteredList.remove(rjs); //p(rjs.getId()+"remove from list."); continue; } //p("trigger state OK, keep "+rjs.getId()+" in list."); } } } return filteredList; }
From source file:org.inheritsource.service.processengine.ActivitiEngineService.java
public PagedProcessInstanceSearchResult getProcessInstancesAdvanced(String startedByUserId, String involvedUserId, int fromIndex, int pageSize, String sortBy, String sortOrder, String filter, Locale locale, String userId, Date startDate, int tolDays) { List<HistoricProcessInstance> processes; HistoricProcessInstanceQuery historicProcessInstanceQuery = engine.getHistoryService() .createHistoricProcessInstanceQuery(); try {//from w w w. jav a2 s .c o m engine.getIdentityService().setAuthenticatedUserId(userId); if (filter.equals("STARTED")) { System.out.println("date started"); historicProcessInstanceQuery.unfinished(); } else if (filter.equals("FINISHED")) { historicProcessInstanceQuery.finished(); } if (startDate != null) { DateTime dtOrg = new DateTime(startDate); Date dateLast = dtOrg.plusDays(tolDays).toDate(); Date dateFirst = dtOrg.minusDays(tolDays).toDate(); System.out.println("dateLast =" + dateLast.toString()); System.out.println("dateFirst =" + dateFirst.toString()); historicProcessInstanceQuery.startedAfter(dateFirst).startedBefore(dateLast); } if (sortBy.equals("started") && sortOrder.equals("desc")) { historicProcessInstanceQuery.orderByProcessInstanceStartTime().desc(); } if (sortBy.equals("started") && sortOrder.equals("asc")) { historicProcessInstanceQuery.orderByProcessInstanceStartTime().asc(); } if (sortBy.equals("ended") && sortOrder.equals("desc")) { historicProcessInstanceQuery.orderByProcessInstanceEndTime().desc(); } if (sortBy.equals("ended") && sortOrder.equals("asc")) { historicProcessInstanceQuery.orderByProcessInstanceEndTime().asc(); } if (involvedUserId != null && !involvedUserId.isEmpty()) { historicProcessInstanceQuery.involvedUser(involvedUserId); } if (startedByUserId != null && !startedByUserId.isEmpty()) { historicProcessInstanceQuery.startedBy(startedByUserId); } processes = historicProcessInstanceQuery.excludeSubprocesses(true).list(); engine.getIdentityService().setAuthenticatedUserId(null); return (getHistoricPagedProcessInstanceSearchResult(processes, startedByUserId, fromIndex, pageSize, sortBy, sortOrder, locale, userId)); } catch (Exception e) { log.error("Unable to getHistoricPagedProcessInstanceSearchResult with searchForUserId: " + " by userId: " + userId + " exeception: " + e); engine.getIdentityService().setAuthenticatedUserId(null); return (null); } }