List of usage examples for java.time LocalDateTime getDayOfMonth
public int getDayOfMonth()
From source file:com.objy.se.ClassAccessor.java
public Object getCorrectValue(String strValue, LogicalType logicalType) { Object retValue = null;//from w ww. j a va 2s. c o m switch (logicalType) { case INTEGER: { long attrValue = 0; try { if (!strValue.equals("")) { attrValue = Long.parseLong(strValue); } } catch (NumberFormatException nfEx) { // System.out.println("... entry: " + entry.getValue() + " for raw: " + entry.getKey()); nfEx.printStackTrace(); throw nfEx; } retValue = Long.valueOf(attrValue); } break; case REAL: { double attrValue = 0; try { if (!strValue.equals("")) { attrValue = Double.parseDouble(strValue); } } catch (NumberFormatException nfEx) { // System.out.println("... entry: " + entry.getValue() + " for raw: " + entry.getKey()); nfEx.printStackTrace(); throw nfEx; } retValue = Double.valueOf(attrValue); } break; case STRING: retValue = strValue; break; case BOOLEAN: { if (strValue.equalsIgnoreCase("TRUE") || strValue.equals("1")) { retValue = Boolean.valueOf(true); } else if (strValue.equalsIgnoreCase("FALSE") || strValue.equals("0")) { retValue = Boolean.valueOf(false); } else { LOG.error("Expected Boolean value but got: {}", strValue); throw new IllegalStateException("Possible invalid configuration... check mapper vs. schema" + "... or check records for invalid values"); } } break; case CHARACTER: { if (strValue.length() == 1) { retValue = Character.valueOf(strValue.charAt(0)); } else { /* not a char value... report that */ LOG.error("Expected Character value but got: {}", strValue); throw new IllegalStateException("Possible invalid configuration... check mapper vs. schema" + "... or check records for invalid values"); } } break; case DATE: { try { LocalDate ldate = LocalDate.parse(strValue, dateFormatter); // System.out.println("... ... year: " + ldate.getYear() + " - month:" + ldate.getMonthValue()); retValue = new com.objy.db.Date(ldate.getYear(), ldate.getMonthValue(), ldate.getDayOfMonth()); } catch (DateTimeParseException ex) { LOG.error(ex.toString()); throw new IllegalStateException("Possible invalid configuration... check mapper vs. schema" + "... or check records for invalid values"); } } break; case DATE_TIME: { try { // System.out.println(".... formatter: " + mapper.getDateTimeFormat()); LocalDateTime ldt = LocalDateTime.parse(strValue, dateTimeFormatter); // System.out.println("... ... year: " + ldt.getYear() + // " - month:" + ldt.getMonthValue() + " - day: " + // ldt.getDayOfMonth() + " - hour: " + ldt.getHour() + // " - min: " + ldt.getMinute() + " - sec: " + // ldt.getSecond() + " - nsec: " + ldt.getNano() ); //retValue = new com.objy.db.DateTime(date.getTime(), TimeKind.LOCAL); retValue = new com.objy.db.DateTime(ldt.getYear(), ldt.getMonthValue(), ldt.getDayOfMonth(), ldt.getHour(), ldt.getMinute(), ldt.getSecond(), ldt.getNano()); } catch (DateTimeParseException ex) { LOG.error(ex.toString()); throw new IllegalStateException("Possible invalid configuration... check mapper vs. schema" + "... or check records for invalid values"); } } break; case TIME: { try { // System.out.println(".... formatter: " + mapper.getTimeFormat()); LocalDateTime ltime = LocalDateTime.parse(strValue, dateFormatter); // System.out.println("... ... hour: " + ltime.getHour() + // " - min: " + ltime.getMinute() + " - sec: " + // ltime.getSecond() + " - nsec: " + ltime.getNano() ); //retValue = new com.objy.db.DateTime(date.getTime(), TimeKind.LOCAL); retValue = new com.objy.db.Time(ltime.getHour(), ltime.getMinute(), ltime.getSecond(), ltime.getNano()); } catch (DateTimeParseException ex) { LOG.error(ex.toString()); throw new IllegalStateException("Possible invalid configuration... check mapper vs. schema" + "... or check records for invalid values"); } } default: { throw new UnsupportedOperationException("LogicalType: " + logicalType + " is not supported!!!"); } } return retValue; }
From source file:edu.unibonn.kmeans.mapreduce.plotting.TimeSeriesPlotter_KMeans.java
private XYDataset createDataset(ArrayList<Cluster_KMeans> clusters, LocalDateTime from) { final TimeSeriesCollection dataset = new TimeSeriesCollection(); // for (int i = 0; i < clusters.size(); i++) // {//w w w . j a v a 2s . c o m // Cluster_KMeans current_cluster = clusters.get(i); // double[] center_of_mass = current_cluster.getCenter_of_mass(); // // final TimeSeries s1 = new TimeSeries("Cluster_"+current_cluster.getCluster_id(), Hour.class); // // for (int j = 0; j < 24; j++) // { // s1.add(new Hour( j, from.getDayOfMonth(), from.getMonthValue(), from.getYear() ), center_of_mass[j]); // } // // dataset.addSeries(s1); // } for (int i = 0; i < clusters.size(); i++) { Cluster_KMeans current_cluster = clusters.get(i); ArrayList<Day_24d> member_time_series = current_cluster.getMembership(); for (Iterator iterator = member_time_series.iterator(); iterator.hasNext();) { final TimeSeries s1 = new TimeSeries("Cluster_" + current_cluster.getCluster_id(), Hour.class); Day_24d current_series = (Day_24d) iterator.next(); for (int j = 0; j < 24; j++) { s1.add(new Hour(j, from.getDayOfMonth(), from.getMonthValue(), from.getYear()), current_series.getMeasurement(j)); } dataset.addSeries(s1); } } dataset.setDomainIsPointsInTime(true); return dataset; }
From source file:de.tu_dortmund.ub.api.paaa.PaaaEndpoint.java
/** * PAAA services//from w ww .ja v a 2s . c o m */ private void provideService(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, String format, String patronid, String token, String service) throws IOException { String baseurl = httpServletRequest.getServerName() + ":" + httpServletRequest.getServerPort(); this.logger.info("[" + config.getProperty("service.name") + "] " + "baseurl = " + baseurl); ObjectMapper mapper = new ObjectMapper(); if (Lookup.lookupAll(IntegratedLibrarySystem.class).size() > 0) { try { IntegratedLibrarySystem integratedLibrarySystem = Lookup.lookup(IntegratedLibrarySystem.class); // init ILS integratedLibrarySystem.init(this.config); switch (service) { case "signup": { Patron patron = null; // read Patron StringBuffer jb = new StringBuffer(); String line = null; try { BufferedReader reader = httpServletRequest.getReader(); while ((line = reader.readLine()) != null) jb.append(line); } catch (Exception e) { /*report an error*/ } Patron patron2create = mapper.readValue(jb.toString(), Patron.class); if (patron2create.getAccount() == null || patron2create.getAccount().equals("")) { if (!patronid.equals("")) { patron2create.setAccount(patronid); } else { patron2create.setAccount(UUID.randomUUID().toString()); } } patron = integratedLibrarySystem.signup(patron2create); this.logger.info("[" + config.getProperty("service.name") + "] " + token + " performed '" + service + "' event for patron '" + patronid + "' >>> success!"); if (patron != null) { Block block = new Block(); LocalDateTime timePoint = LocalDateTime.now(); block.setDate(timePoint.getYear() + "-" + (timePoint.getMonthValue() < 10 ? "0" + timePoint.getMonthValue() : timePoint.getMonthValue()) + "-" + (timePoint.getDayOfMonth() < 10 ? "0" + timePoint.getDayOfMonth() : timePoint.getDayOfMonth())); block.setKey("93"); integratedLibrarySystem.blockpatron(patron, block); StringWriter json = new StringWriter(); mapper.writeValue(json, patron); this.logger.debug("[" + config.getProperty("service.name") + "] " + json); // If request contains parameter 'redirect_uri', then redirect mit access_token and patronid if (httpServletRequest.getParameter("redirect_uri") != null) { this.logger.debug("[" + config.getProperty("service.name") + "] " + "REDIRECT? " + httpServletRequest.getParameter("redirect_uri")); httpServletResponse.sendRedirect(httpServletRequest.getParameter("redirect_uri") + "&patron=" + patronid + "&token=" + token); } else { httpServletResponse.setContentType("application/json"); httpServletResponse.setStatus(HttpServletResponse.SC_OK); httpServletResponse.setHeader("Access-Control-Allow-Origin", "*"); httpServletResponse.getWriter().println(json); } } else { this.logger.error("[" + config.getProperty("service.name") + "] " + HttpServletResponse.SC_SERVICE_UNAVAILABLE + ": ILS!"); httpServletResponse.setHeader("WWW-Authentificate", "Bearer"); httpServletResponse.setHeader("WWW-Authentificate", "Bearer realm=\"PAAA\""); httpServletResponse.setContentType("application/json"); httpServletResponse.setHeader("Access-Control-Allow-Origin", "*"); // Error handling mit suppress_response_codes=true if (httpServletRequest.getParameter("suppress_response_codes") != null) { httpServletResponse.setStatus(HttpServletResponse.SC_OK); } // Error handling mit suppress_response_codes=false (=default) else { httpServletResponse.setStatus(HttpServletResponse.SC_SERVICE_UNAVAILABLE); } // Json fr Response body RequestError requestError = new RequestError(); requestError.setError(this.config.getProperty( "error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE))); requestError.setCode(HttpServletResponse.SC_SERVICE_UNAVAILABLE); requestError.setDescription(this.config.getProperty("error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE) + ".description")); requestError.setErrorUri(this.config.getProperty( "error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE) + ".uri")); StringWriter json = new StringWriter(); mapper.writeValue(json, requestError); this.logger.debug("[" + config.getProperty("service.name") + "] " + json); // send response httpServletResponse.getWriter().println(json); } break; } case "newpatron": { Patron patron = null; // read Patron StringBuffer jb = new StringBuffer(); String line = null; try { BufferedReader reader = httpServletRequest.getReader(); while ((line = reader.readLine()) != null) jb.append(line); } catch (Exception e) { /*report an error*/ } Patron patron2create = mapper.readValue(jb.toString(), Patron.class); patron2create.setAccount(patronid); patron = integratedLibrarySystem.newpatron(patron2create); this.logger.info("[" + config.getProperty("service.name") + "] " + token + " performed '" + service + "' event for patron '" + patronid + "' >>> success!"); if (patron != null) { StringWriter json = new StringWriter(); mapper.writeValue(json, patron); this.logger.debug("[" + config.getProperty("service.name") + "] " + json); // If request contains parameter 'redirect_uri', then redirect mit access_token and patronid if (httpServletRequest.getParameter("redirect_uri") != null) { this.logger.debug("[" + config.getProperty("service.name") + "] " + "REDIRECT? " + httpServletRequest.getParameter("redirect_uri")); httpServletResponse.sendRedirect(httpServletRequest.getParameter("redirect_uri") + "&patron=" + patronid + "&token=" + token); } else { httpServletResponse.setContentType("application/json"); httpServletResponse.setStatus(HttpServletResponse.SC_OK); httpServletResponse.setHeader("Access-Control-Allow-Origin", "*"); httpServletResponse.getWriter().println(json); } } else { this.logger.error("[" + config.getProperty("service.name") + "] " + HttpServletResponse.SC_SERVICE_UNAVAILABLE + ": ILS!"); httpServletResponse.setHeader("WWW-Authentificate", "Bearer"); httpServletResponse.setHeader("WWW-Authentificate", "Bearer realm=\"PAAA\""); httpServletResponse.setContentType("application/json"); httpServletResponse.setHeader("Access-Control-Allow-Origin", "*"); // Error handling mit suppress_response_codes=true if (httpServletRequest.getParameter("suppress_response_codes") != null) { httpServletResponse.setStatus(HttpServletResponse.SC_OK); } // Error handling mit suppress_response_codes=false (=default) else { httpServletResponse.setStatus(HttpServletResponse.SC_SERVICE_UNAVAILABLE); } // Json fr Response body RequestError requestError = new RequestError(); requestError.setError(this.config.getProperty( "error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE))); requestError.setCode(HttpServletResponse.SC_SERVICE_UNAVAILABLE); requestError.setDescription(this.config.getProperty("error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE) + ".description")); requestError.setErrorUri(this.config.getProperty( "error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE) + ".uri")); StringWriter json = new StringWriter(); mapper.writeValue(json, requestError); this.logger.debug("[" + config.getProperty("service.name") + "] " + json); // send response httpServletResponse.getWriter().println(json); } break; } case "updatepatron": { Patron patron = null; // read Patron StringBuffer jb = new StringBuffer(); String line = null; try { BufferedReader reader = httpServletRequest.getReader(); while ((line = reader.readLine()) != null) jb.append(line); } catch (Exception e) { /*report an error*/ } Patron patron2update = mapper.readValue(jb.toString(), Patron.class); patron2update.setAccount(patronid); // TODO Was tun bei nderung des 'status'? patron = integratedLibrarySystem.updatepatron(patron2update); this.logger.info("[" + config.getProperty("service.name") + "] " + token + " performed '" + service + "' event for patron '" + patronid + "' >>> success!"); if (patron != null) { StringWriter json = new StringWriter(); mapper.writeValue(json, patron); this.logger.debug("[" + config.getProperty("service.name") + "] " + json); // If request contains parameter 'redirect_uri', then redirect mit access_token and patronid if (httpServletRequest.getParameter("redirect_uri") != null) { this.logger.debug("[" + config.getProperty("service.name") + "] " + "REDIRECT? " + httpServletRequest.getParameter("redirect_uri")); httpServletResponse.sendRedirect(httpServletRequest.getParameter("redirect_uri") + "&patron=" + patronid + "&token=" + token); } else { httpServletResponse.setContentType("application/json"); httpServletResponse.setStatus(HttpServletResponse.SC_OK); httpServletResponse.setHeader("Access-Control-Allow-Origin", "*"); httpServletResponse.getWriter().println(json); } } else { this.logger.error("[" + config.getProperty("service.name") + "] " + HttpServletResponse.SC_SERVICE_UNAVAILABLE + ": ILS!"); httpServletResponse.setHeader("WWW-Authentificate", "Bearer"); httpServletResponse.setHeader("WWW-Authentificate", "Bearer realm=\"PAAA\""); httpServletResponse.setContentType("application/json"); httpServletResponse.setHeader("Access-Control-Allow-Origin", "*"); // Error handling mit suppress_response_codes=true if (httpServletRequest.getParameter("suppress_response_codes") != null) { httpServletResponse.setStatus(HttpServletResponse.SC_OK); } // Error handling mit suppress_response_codes=false (=default) else { httpServletResponse.setStatus(HttpServletResponse.SC_SERVICE_UNAVAILABLE); } // Json fr Response body RequestError requestError = new RequestError(); requestError.setError(this.config.getProperty( "error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE))); requestError.setCode(HttpServletResponse.SC_SERVICE_UNAVAILABLE); requestError.setDescription(this.config.getProperty("error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE) + ".description")); requestError.setErrorUri(this.config.getProperty( "error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE) + ".uri")); StringWriter json = new StringWriter(); mapper.writeValue(json, requestError); this.logger.debug("[" + config.getProperty("service.name") + "] " + json); // send response httpServletResponse.getWriter().println(json); } break; } case "blockpatron": { Patron patron = null; // read Patron StringBuffer jb = new StringBuffer(); String line = null; try { BufferedReader reader = httpServletRequest.getReader(); while ((line = reader.readLine()) != null) jb.append(line); } catch (Exception e) { /*report an error*/ } Patron patron2block = new Patron(); patron2block.setAccount(patronid); Block block = mapper.readValue(jb.toString(), Block.class); patron = integratedLibrarySystem.blockpatron(patron2block, block); this.logger.info("[" + config.getProperty("service.name") + "] " + token + " performed '" + service + "' event for patron '" + patronid + "' >>> success!"); if (patron != null) { StringWriter json = new StringWriter(); mapper.writeValue(json, patron); this.logger.debug("[" + config.getProperty("service.name") + "] " + json); // If request contains parameter 'redirect_uri', then redirect mit access_token and patronid if (httpServletRequest.getParameter("redirect_uri") != null) { this.logger.debug("[" + config.getProperty("service.name") + "] " + "REDIRECT? " + httpServletRequest.getParameter("redirect_uri")); httpServletResponse.sendRedirect(httpServletRequest.getParameter("redirect_uri") + "&patron=" + patronid + "&token=" + token); } else { httpServletResponse.setContentType("application/json"); httpServletResponse.setStatus(HttpServletResponse.SC_OK); httpServletResponse.setHeader("Access-Control-Allow-Origin", "*"); httpServletResponse.getWriter().println(json); } } else { this.logger.error("[" + config.getProperty("service.name") + "] " + HttpServletResponse.SC_SERVICE_UNAVAILABLE + ": ILS!"); httpServletResponse.setHeader("WWW-Authentificate", "Bearer"); httpServletResponse.setHeader("WWW-Authentificate", "Bearer realm=\"PAAA\""); httpServletResponse.setContentType("application/json"); httpServletResponse.setHeader("Access-Control-Allow-Origin", "*"); // Error handling mit suppress_response_codes=true if (httpServletRequest.getParameter("suppress_response_codes") != null) { httpServletResponse.setStatus(HttpServletResponse.SC_OK); } // Error handling mit suppress_response_codes=false (=default) else { httpServletResponse.setStatus(HttpServletResponse.SC_SERVICE_UNAVAILABLE); } // Json fr Response body RequestError requestError = new RequestError(); requestError.setError(this.config.getProperty( "error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE))); requestError.setCode(HttpServletResponse.SC_SERVICE_UNAVAILABLE); requestError.setDescription(this.config.getProperty("error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE) + ".description")); requestError.setErrorUri(this.config.getProperty( "error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE) + ".uri")); StringWriter json = new StringWriter(); mapper.writeValue(json, requestError); this.logger.debug("[" + config.getProperty("service.name") + "] " + json); // send response httpServletResponse.getWriter().println(json); } break; } case "unblockpatron": { Patron patron = null; // read Patron StringBuffer jb = new StringBuffer(); String line = null; try { BufferedReader reader = httpServletRequest.getReader(); while ((line = reader.readLine()) != null) jb.append(line); } catch (Exception e) { /*report an error*/ } Patron patron2unblock = new Patron(); patron2unblock.setAccount(patronid); Block block = mapper.readValue(jb.toString(), Block.class); patron = integratedLibrarySystem.unblockpatron(patron2unblock, block); this.logger.info("[" + config.getProperty("service.name") + "] " + token + " performed '" + service + "' event for patron '" + patronid + "' >>> success!"); if (patron != null) { StringWriter json = new StringWriter(); mapper.writeValue(json, patron); this.logger.debug("[" + config.getProperty("service.name") + "] " + json); // If request contains parameter 'redirect_uri', then redirect mit access_token and patronid if (httpServletRequest.getParameter("redirect_uri") != null) { this.logger.debug("[" + config.getProperty("service.name") + "] " + "REDIRECT? " + httpServletRequest.getParameter("redirect_uri")); httpServletResponse.sendRedirect(httpServletRequest.getParameter("redirect_uri") + "&patron=" + patronid + "&token=" + token); } else { httpServletResponse.setContentType("application/json"); httpServletResponse.setStatus(HttpServletResponse.SC_OK); httpServletResponse.setHeader("Access-Control-Allow-Origin", "*"); httpServletResponse.getWriter().println(json); } } else { this.logger.error("[" + config.getProperty("service.name") + "] " + HttpServletResponse.SC_SERVICE_UNAVAILABLE + ": ILS!"); httpServletResponse.setHeader("WWW-Authentificate", "Bearer"); httpServletResponse.setHeader("WWW-Authentificate", "Bearer realm=\"PAAA\""); httpServletResponse.setContentType("application/json"); httpServletResponse.setHeader("Access-Control-Allow-Origin", "*"); // Error handling mit suppress_response_codes=true if (httpServletRequest.getParameter("suppress_response_codes") != null) { httpServletResponse.setStatus(HttpServletResponse.SC_OK); } // Error handling mit suppress_response_codes=false (=default) else { httpServletResponse.setStatus(HttpServletResponse.SC_SERVICE_UNAVAILABLE); } // Json fr Response body RequestError requestError = new RequestError(); requestError.setError(this.config.getProperty( "error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE))); requestError.setCode(HttpServletResponse.SC_SERVICE_UNAVAILABLE); requestError.setDescription(this.config.getProperty("error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE) + ".description")); requestError.setErrorUri(this.config.getProperty( "error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE) + ".uri")); StringWriter json = new StringWriter(); mapper.writeValue(json, requestError); this.logger.debug("[" + config.getProperty("service.name") + "] " + json); // send response httpServletResponse.getWriter().println(json); } break; } case "deletepatron": { Patron patron = null; Patron patron2delete = new Patron(); patron2delete.setAccount(patronid); patron = integratedLibrarySystem.deletepatron(patron2delete); this.logger.info("[" + config.getProperty("service.name") + "] " + token + " performed '" + service + "' event for patron '" + patronid + "' >>> success!"); if (patron != null) { StringWriter json = new StringWriter(); mapper.writeValue(json, patron); this.logger.debug("[" + config.getProperty("service.name") + "] " + json); // If request contains parameter 'redirect_uri', then redirect mit access_token and patronid if (httpServletRequest.getParameter("redirect_uri") != null) { this.logger.debug("[" + config.getProperty("service.name") + "] " + "REDIRECT? " + httpServletRequest.getParameter("redirect_uri")); httpServletResponse.sendRedirect(httpServletRequest.getParameter("redirect_uri") + "&patron=" + patronid + "&token=" + token); } else { httpServletResponse.setContentType("application/json"); httpServletResponse.setStatus(HttpServletResponse.SC_OK); httpServletResponse.setHeader("Access-Control-Allow-Origin", "*"); httpServletResponse.getWriter().println(json); } } else { this.logger.error("[" + config.getProperty("service.name") + "] " + HttpServletResponse.SC_SERVICE_UNAVAILABLE + ": ILS!"); httpServletResponse.setHeader("WWW-Authentificate", "Bearer"); httpServletResponse.setHeader("WWW-Authentificate", "Bearer realm=\"PAAA\""); httpServletResponse.setContentType("application/json"); httpServletResponse.setHeader("Access-Control-Allow-Origin", "*"); // Error handling mit suppress_response_codes=true if (httpServletRequest.getParameter("suppress_response_codes") != null) { httpServletResponse.setStatus(HttpServletResponse.SC_OK); } // Error handling mit suppress_response_codes=false (=default) else { httpServletResponse.setStatus(HttpServletResponse.SC_SERVICE_UNAVAILABLE); } // Json fr Response body RequestError requestError = new RequestError(); requestError.setError(this.config.getProperty( "error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE))); requestError.setCode(HttpServletResponse.SC_SERVICE_UNAVAILABLE); requestError.setDescription(this.config.getProperty("error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE) + ".description")); requestError.setErrorUri(this.config.getProperty( "error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE) + ".uri")); StringWriter json = new StringWriter(); mapper.writeValue(json, requestError); this.logger.debug("[" + config.getProperty("service.name") + "] " + json); // send response httpServletResponse.getWriter().println(json); } break; } case "newfee": { Patron patron = null; Fee resultFee = null; patron = new Patron(); patron.setAccount(patronid); // read Fee StringBuffer jb = new StringBuffer(); String line = null; try { BufferedReader reader = httpServletRequest.getReader(); while ((line = reader.readLine()) != null) jb.append(line); } catch (Exception e) { /*report an error*/ } this.logger.debug("[" + config.getProperty("service.name") + "] " + "Fee = " + jb); Fee fee = mapper.readValue(jb.toString(), Fee.class); resultFee = integratedLibrarySystem.newfee(patron, fee); this.logger.info("[" + config.getProperty("service.name") + "] " + token + " performed '" + service + "' event for patron '" + patronid + "' >>> success!"); StringWriter stringWriter = new StringWriter(); mapper.writeValue(stringWriter, resultFee); this.logger.debug( "[" + config.getProperty("service.name") + "] " + "Fee: " + stringWriter.toString()); if (patron != null) { StringWriter json = new StringWriter(); mapper.writeValue(json, resultFee); this.logger.debug(json); // If request contains parameter 'redirect_uri', then redirect mit access_token and patronid if (httpServletRequest.getParameter("redirect_uri") != null) { this.logger.debug("[" + config.getProperty("service.name") + "] " + "REDIRECT? " + httpServletRequest.getParameter("redirect_uri")); httpServletResponse.sendRedirect(httpServletRequest.getParameter("redirect_uri") + "&patron=" + patronid + "&token=" + token); } else { httpServletResponse.setContentType("application/json"); httpServletResponse.setStatus(HttpServletResponse.SC_OK); httpServletResponse.setHeader("Access-Control-Allow-Origin", "*"); httpServletResponse.getWriter().println(json); } } else { this.logger.error("[" + config.getProperty("service.name") + "] " + HttpServletResponse.SC_SERVICE_UNAVAILABLE + ": ILS!"); httpServletResponse.setHeader("WWW-Authentificate", "Bearer"); httpServletResponse.setHeader("WWW-Authentificate", "Bearer realm=\"PAAA\""); httpServletResponse.setContentType("application/json"); httpServletResponse.setHeader("Access-Control-Allow-Origin", "*"); // Error handling mit suppress_response_codes=true if (httpServletRequest.getParameter("suppress_response_codes") != null) { httpServletResponse.setStatus(HttpServletResponse.SC_OK); } // Error handling mit suppress_response_codes=false (=default) else { httpServletResponse.setStatus(HttpServletResponse.SC_SERVICE_UNAVAILABLE); } // Json fr Response body RequestError requestError = new RequestError(); requestError.setError(this.config.getProperty( "error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE))); requestError.setCode(HttpServletResponse.SC_SERVICE_UNAVAILABLE); requestError.setDescription(this.config.getProperty("error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE) + ".description")); requestError.setErrorUri(this.config.getProperty( "error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE) + ".uri")); StringWriter json = new StringWriter(); mapper.writeValue(json, requestError); this.logger.debug("[" + config.getProperty("service.name") + "] " + json); // send response httpServletResponse.getWriter().println(json); } break; } default: { // TODO: keine gltige Funktion } } } catch (ILSException e) { this.logger.info("[" + config.getProperty("service.name") + "] " + token + " performed '" + service + "' event for patron '" + patronid + "' >>> failed!"); this.logger.error("[" + config.getProperty("service.name") + "] " + HttpServletResponse.SC_INTERNAL_SERVER_ERROR + ": ILS Error! " + e.getMessage()); // TODO e.getMessage = 403 if (e.getMessage().equals("403")) { // TODO >> properties httpServletResponse.setHeader("WWW-Authentificate", "Bearer"); httpServletResponse.setHeader("WWW-Authentificate", "Bearer realm=\"PAAA\""); httpServletResponse.setContentType("application/json"); httpServletResponse.setHeader("Access-Control-Allow-Origin", "*"); // Error handling mit suppress_response_codes=true if (httpServletRequest.getParameter("suppress_response_codes") != null) { httpServletResponse.setStatus(HttpServletResponse.SC_OK); } // Error handling mit suppress_response_codes=false (=default) else { httpServletResponse.setStatus(HttpServletResponse.SC_FORBIDDEN); } // Json fr Response body RequestError requestError = new RequestError(); requestError.setError( this.config.getProperty("error." + Integer.toString(HttpServletResponse.SC_FORBIDDEN))); requestError.setCode(HttpServletResponse.SC_FORBIDDEN); requestError.setDescription(this.config.getProperty( "error." + Integer.toString(HttpServletResponse.SC_FORBIDDEN) + ".description")); requestError.setErrorUri(this.config .getProperty("error." + Integer.toString(HttpServletResponse.SC_FORBIDDEN) + ".uri")); StringWriter json = new StringWriter(); mapper.writeValue(json, requestError); this.logger.debug("[" + config.getProperty("service.name") + "] " + json); // send response httpServletResponse.getWriter().println(json); } else { // Mail to Bib-IT wg. Socket-Error try { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); e.printStackTrace(pw); Mailer mailer = new Mailer(this.config.getProperty("service.mailer.conf")); mailer.postMail( "[" + this.config.getProperty("service.name") + "] ILS Error! " + e.getMessage(), sw.toString()); } catch (MessagingException | IOException e1) { this.logger.error(e1.getMessage(), e1.getCause()); } // TODO >> properties httpServletResponse.setHeader("WWW-Authentificate", "Bearer"); httpServletResponse.setHeader("WWW-Authentificate", "Bearer realm=\"PAAA\""); httpServletResponse.setContentType("application/json"); httpServletResponse.setHeader("Access-Control-Allow-Origin", "*"); // Error handling mit suppress_response_codes=true if (httpServletRequest.getParameter("suppress_response_codes") != null) { httpServletResponse.setStatus(HttpServletResponse.SC_OK); } // Error handling mit suppress_response_codes=false (=default) else { httpServletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } // Json fr Response body RequestError requestError = new RequestError(); requestError.setError(this.config.getProperty( "error." + Integer.toString(HttpServletResponse.SC_INTERNAL_SERVER_ERROR))); requestError.setCode(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); requestError.setDescription(this.config.getProperty("error." + Integer.toString(HttpServletResponse.SC_INTERNAL_SERVER_ERROR) + ".description")); requestError.setErrorUri(this.config.getProperty( "error." + Integer.toString(HttpServletResponse.SC_INTERNAL_SERVER_ERROR) + ".uri")); StringWriter json = new StringWriter(); mapper.writeValue(json, requestError); this.logger.debug("[" + config.getProperty("service.name") + "] " + json); // send response httpServletResponse.getWriter().println(json); } } } else { this.logger.error("[" + config.getProperty("service.name") + "] " + HttpServletResponse.SC_INTERNAL_SERVER_ERROR + ": Config Error!"); httpServletResponse.setHeader("WWW-Authentificate", "Bearer"); httpServletResponse.setHeader("WWW-Authentificate", "Bearer realm=\"PAAA\""); httpServletResponse.setContentType("application/json"); httpServletResponse.setHeader("Access-Control-Allow-Origin", "*"); // Error handling mit suppress_response_codes=true if (httpServletRequest.getParameter("suppress_response_codes") != null) { httpServletResponse.setStatus(HttpServletResponse.SC_OK); } // Error handling mit suppress_response_codes=false (=default) else { httpServletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } // Json fr Response body RequestError requestError = new RequestError(); requestError.setError(this.config .getProperty("error." + Integer.toString(HttpServletResponse.SC_INTERNAL_SERVER_ERROR))); requestError.setCode(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); requestError.setDescription(this.config.getProperty( "error." + Integer.toString(HttpServletResponse.SC_INTERNAL_SERVER_ERROR) + ".description")); requestError.setErrorUri(this.config.getProperty( "error." + Integer.toString(HttpServletResponse.SC_INTERNAL_SERVER_ERROR) + ".uri")); StringWriter json = new StringWriter(); mapper.writeValue(json, requestError); this.logger.debug("[" + config.getProperty("service.name") + "] " + json); // send response httpServletResponse.getWriter().println(json); } }
From source file:no.imr.stox.functions.acoustic.PgNapesIO.java
public static void export2(String cruise, String country, String callSignal, String path, String fileName, List<DistanceBO> distances, Double groupThickness, Integer freqFilter, String specFilter, boolean withZeros) { Set<Integer> freqs = distances.stream().flatMap(dist -> dist.getFrequencies().stream()) .map(FrequencyBO::getFreq).collect(Collectors.toSet()); if (freqFilter == null && freqs.size() == 1) { freqFilter = freqs.iterator().next(); }//from w w w . jav a 2s. c om if (freqFilter == null) { System.out.println("Multiple frequencies, specify frequency filter as parameter"); return; } Integer freqFilterF = freqFilter; // ef.final List<String> acList = distances.parallelStream().flatMap(dist -> dist.getFrequencies().stream()) .filter(fr -> freqFilterF.equals(fr.getFreq())).map(f -> { DistanceBO d = f.getDistanceBO(); LocalDateTime sdt = LocalDateTime.ofInstant(d.getStart_time().toInstant(), ZoneOffset.UTC); Double intDist = d.getIntegrator_dist(); String month = StringUtils.leftPad(sdt.getMonthValue() + "", 2, "0"); String day = StringUtils.leftPad(sdt.getDayOfMonth() + "", 2, "0"); String hour = StringUtils.leftPad(sdt.getHour() + "", 2, "0"); String minute = StringUtils.leftPad(sdt.getMinute() + "", 2, "0"); String log = Conversion.formatDoubletoDecimalString(d.getLog_start(), "0.0"); String acLat = Conversion.formatDoubletoDecimalString(d.getLat_start(), "0.000"); String acLon = Conversion.formatDoubletoDecimalString(d.getLon_start(), "0.000"); return Stream .of(d.getNation(), d.getPlatform(), d.getCruise(), log, sdt.getYear(), month, day, hour, minute, acLat, acLon, intDist, f.getFreq(), f.getThreshold()) .map(o -> o == null ? "" : o.toString()).collect(Collectors.joining("\t")) + "\t"; }).collect(Collectors.toList()); String fil1 = path + "/" + fileName + ".txt"; acList.add(0, Stream.of("Country", "Vessel", "Cruise", "Log", "Year", "Month", "Day", "Hour", "Min", "AcLat", "AcLon", "Logint", "Frequency", "Sv_threshold").collect(Collectors.joining("\t"))); try { Files.write(Paths.get(fil1), acList, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING); } catch (IOException ex) { Logger.getLogger(PgNapesIO.class.getName()).log(Level.SEVERE, null, ex); } acList.clear(); // Acoustic values distances.stream().filter(d -> d.getPel_ch_thickness() != null) .flatMap(dist -> dist.getFrequencies().stream()).filter(fr -> freqFilterF.equals(fr.getFreq())) .forEachOrdered(f -> { try { Double groupThicknessF = Math.max(f.getDistanceBO().getPel_ch_thickness(), groupThickness); Map<String, Map<Integer, Double>> pivot = f.getSa().stream() .filter(s -> s.getCh_type().equals("P")).map(s -> new SAGroup(s, groupThicknessF)) .filter(s -> s.getSpecies() != null && (specFilter == null || specFilter.equals(s.getSpecies()))) // create pivot table: species (dim1) -> depth interval index (dim2) -> sum sa (group aggregator) .collect(Collectors.groupingBy(SAGroup::getSpecies, Collectors.groupingBy( SAGroup::getDepthGroupIdx, Collectors.summingDouble(SAGroup::sa)))); if (pivot.isEmpty() && specFilter != null && withZeros) { pivot.put(specFilter, new HashMap<>()); } Integer maxGroupIdx = pivot.entrySet().stream().flatMap(e -> e.getValue().keySet().stream()) .max(Integer::compare).orElse(null); if (maxGroupIdx == null) { return; } acList.addAll(pivot.entrySet().stream().sorted(Comparator.comparing(Map.Entry::getKey)) .flatMap(e -> { return IntStream.range(0, maxGroupIdx + 1).boxed().map(groupIdx -> { Double chUpDepth = groupIdx * groupThicknessF; Double chLowDepth = (groupIdx + 1) * groupThicknessF; Double sa = e.getValue().get(groupIdx); if (sa == null) { sa = 0d; } String res = null; if (withZeros || sa > 0d) { DistanceBO d = f.getDistanceBO(); String log = Conversion.formatDoubletoDecimalString(d.getLog_start(), "0.0"); LocalDateTime sdt = LocalDateTime .ofInstant(d.getStart_time().toInstant(), ZoneOffset.UTC); String month = StringUtils.leftPad(sdt.getMonthValue() + "", 2, "0"); String day = StringUtils.leftPad(sdt.getDayOfMonth() + "", 2, "0"); //String sas = String.format(Locale.UK, "%11.5f", sa); res = Stream .of(d.getNation(), d.getPlatform(), d.getCruise(), log, sdt.getYear(), month, day, e.getKey(), chUpDepth, chLowDepth, sa) .map(o -> o == null ? "" : o.toString()) .collect(Collectors.joining("\t")); } return res; }).filter(s -> s != null); }).collect(Collectors.toList())); } catch (Exception e) { e.printStackTrace(); } }); String fil2 = path + "/" + fileName + "Values.txt"; acList.add(0, Stream.of("Country", "Vessel", "Cruise", "Log", "Year", "Month", "Day", "Species", "ChUppDepth", "ChLowDepth", "SA").collect(Collectors.joining("\t"))); try { Files.write(Paths.get(fil2), acList, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING); } catch (IOException ex) { Logger.getLogger(PgNapesIO.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:org.codice.ddf.admin.insecure.defaults.service.DefaultUsersDeletionScheduler.java
private String cronCalculator(Instant firstInstall) { Instant threeDayTimestamp = firstInstall.plus(Duration.ofDays(3).minus(Duration.ofMinutes(30))); LocalDateTime localDateTime = LocalDateTime.ofInstant(threeDayTimestamp, ZoneId.systemDefault()); return String.format("%d+%d+%d+%d+%d+?+%d", localDateTime.getSecond(), localDateTime.getMinute(), localDateTime.getHour(), localDateTime.getDayOfMonth(), localDateTime.getMonthValue(), localDateTime.getYear());/* www .j av a 2 s . c o m*/ }
From source file:org.eclipse.smarthome.core.scheduler.CronHelper.java
/** * Returns CRON expression from the provided {@link LocalDateTime} instance * * @param localDateTime the {@link LocalDateTime} instance * @return the CRON expression// ww w . ja va2 s . c om * @throws NullPointerException * if {@code localDateTime} is null */ public static String createCronFromTemporal(LocalDateTime localDateTime) { requireNonNull(localDateTime, "Temporal instance cannot be null"); int minute = localDateTime.getMinute(); int hour = localDateTime.getHour(); int day = localDateTime.getDayOfMonth(); int month = localDateTime.getMonth().getValue(); int year = localDateTime.getYear(); StringBuilder builder = new StringBuilder(); builder.append(SECONDS).append(SPACE).append(minute).append(SPACE).append(hour).append(SPACE).append(day) .append(SPACE).append(month).append(SPACE).append(DAYS_OF_WEEK).append(SPACE).append(year); return builder.toString(); }