List of usage examples for java.time LocalDateTime parse
public static LocalDateTime parse(CharSequence text)
From source file:net.jmhertlein.mcanalytics.plugin.daemon.request.PastOnlinePlayerCountRequestHandler.java
@Override public JSONObject handle(Connection conn, StatementProvider stmts, JSONObject req, ClientMonitor c) throws SQLException { //System.out.println("Handler: starting..."); PreparedStatement stmt = conn.prepareStatement(stmts.get(SQLString.GET_HOURLY_PLAYER_COUNTS)); stmt.clearParameters();// w w w . j a v a 2s . co m stmt.setTimestamp(1, Timestamp.valueOf(LocalDateTime.parse(req.getString("start")))); stmt.setTimestamp(2, Timestamp.valueOf(LocalDateTime.parse(req.getString("end")))); ResultSet res = stmt.executeQuery(); Map<String, Integer> counts = new HashMap<>(); while (res.next()) { counts.put(res.getTimestamp("instant").toLocalDateTime().toString(), res.getInt("count")); } JSONObject ret = new JSONObject(); ret.put("counts", counts); res.close(); stmt.close(); conn.close(); //System.out.println("Handler: done, returning."); return ret; }
From source file:rapture.dp.invocable.calendar.steps.GetDayOfWeekStep.java
@Override public String invoke(CallingContext ctx) { DecisionApi decision = Kernel.getDecision(); try {//from w w w. j a va2 s . co m decision.setContextLiteral(ctx, getWorkerURI(), "STEPNAME", getStepName()); String dateStr = StringUtils.stripToNull(decision.getContextValue(ctx, getWorkerURI(), "DATE")); String languageTag = StringUtils.stripToNull(decision.getContextValue(ctx, getWorkerURI(), "LOCALE")); LocalDateTime date = (dateStr == null) ? LocalDateTime.now() : LocalDateTime.parse(dateStr); Locale locale = (languageTag == null) ? Locale.getDefault() : Locale.forLanguageTag(languageTag); String day = DayOfWeek.from(date).getDisplayName(TextStyle.FULL, locale); decision.writeWorkflowAuditEntry(ctx, getWorkerURI(), "Day of week is " + day, false); return day; } catch (Exception e) { decision.setContextLiteral(ctx, getWorkerURI(), getStepName(), "Exception in workflow : " + e.getLocalizedMessage()); decision.setContextLiteral(ctx, getWorkerURI(), getErrName(), ExceptionToString.summary(e)); decision.writeWorkflowAuditEntry(ctx, getWorkerURI(), "Problem in " + getStepName() + ": " + ExceptionToString.getRootCause(e).getLocalizedMessage(), true); return getErrorTransition(); } }
From source file:dollar.api.types.DollarString.java
@NotNull @Override//www .j a va 2s . co m public Value $as(@NotNull Type type) { if (type.is(Type._BOOLEAN)) { return DollarStatic.$("true".equals(value) || "yes".equals(value)); } else if (type.is(Type._STRING)) { return this; } else if (type.is(Type._LIST)) { return DollarStatic.$(Collections.singletonList(this)); } else if (type.is(Type._MAP)) { return DollarStatic.$("value", this); } else if (type.is(Type._DECIMAL)) { return DollarStatic.$(Double.parseDouble(value)); } else if (type.is(Type._INTEGER)) { return DollarStatic.$(Long.parseLong(value)); } else if (type.is(Type._VOID)) { return DollarStatic.$void(); } else if (type.is(Type._DATE)) { return DollarFactory.fromValue(LocalDateTime.parse(value)); } else if (type.is(Type._URI)) { return DollarFactory.fromURI(value); } else { throw new DollarFailureException(INVALID_CAST); } }
From source file:com.gigglinggnus.controllers.AdminClockController.java
/** * * @param request servlet request/*from w ww .j a va 2 s . c o m*/ * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { EntityManager em = (EntityManager) request.getSession().getAttribute("em"); String strTime = request.getParameter("systemTime"); LocalDateTime ldTime = LocalDateTime.parse(strTime); Instant instant = ldTime.atZone(ZoneId.systemDefault()).toInstant(); Clock clk = Clock.fixed(instant, ZoneId.systemDefault()); request.getSession().setAttribute("clock", clk); RequestDispatcher rd = request.getRequestDispatcher("/home.jsp"); rd.forward(request, response); }
From source file:org.wso2.carbon.apimgt.core.workflow.APIStateChangeWorkflow.java
@Override public WorkflowResponse completeWorkflow(WorkflowExecutor workflowExecutor) throws APIManagementException { WorkflowResponse response = workflowExecutor.complete(this); setStatus(response.getWorkflowStatus()); if (WorkflowStatus.APPROVED == response.getWorkflowStatus()) { if (log.isDebugEnabled()) { log.debug("API state change workflow complete: Approved"); }// www . j a va 2 s . co m String invoker = getAttribute(APIMgtConstants.WorkflowConstants.ATTRIBUTE_API_LC_INVOKER); String targetState = getAttribute(APIMgtConstants.WorkflowConstants.ATTRIBUTE_API_TARGET_STATE); String localTime = getAttribute(APIMgtConstants.WorkflowConstants.ATTRIBUTE_API_LAST_UPTIME); LocalDateTime time = LocalDateTime.parse(localTime); updateAPIStatusForWorkflowComplete(getWorkflowReference(), targetState, invoker, time); } else if (WorkflowStatus.REJECTED == response.getWorkflowStatus()) { if (log.isDebugEnabled()) { log.debug("API state change workflow complete: Rejected"); } apiDAO.updateAPIWorkflowStatus(getWorkflowReference(), APIMgtConstants.APILCWorkflowStatus.REJECTED); } updateWorkflowEntries(this); return response; }
From source file:com.trenurbanoapp.webapi.WebApiRestClient.java
private AssetPosition createAssetPosition(JsonNode node) { AssetPosition assetPos = new AssetPosition(); assetPos.setAssetId(node.path("IDASSET").numberValue().intValue()); assetPos.setStatus(node.path("STATUS").numberValue().intValue()); assetPos.setStatusMessage(node.path("MSG").textValue()); assetPos.setWhen(LocalDateTime.parse(node.path("WHEN").textValue())); List<LatLng> trail = new ArrayList<>(3); String trailStr = node.path("TRAIL").textValue(); for (String coordsStr : trailStr.split("\\*")) { String[] coordsArray = coordsStr.split(","); LatLng latLng = new LatLng(Double.valueOf(coordsArray[0]), Double.valueOf(coordsArray[1])); trail.add(latLng);/*from w w w.ja va2 s . com*/ } assetPos.setTrail(trail); return assetPos; }
From source file:com.sillelien.dollar.api.types.DollarString.java
@Override public var $as(@NotNull Type type) { if (type.equals(Type.BOOLEAN)) { return DollarStatic.$(value.equals("true") || value.equals("yes")); } else if (type.equals(Type.STRING)) { return this; } else if (type.equals(Type.LIST)) { return DollarStatic.$(Arrays.asList(this)); } else if (type.equals(Type.MAP)) { return DollarStatic.$("value", this); } else if (type.equals(Type.DECIMAL)) { return DollarStatic.$(Double.parseDouble(value)); } else if (type.equals(Type.INTEGER)) { return DollarStatic.$(Long.parseLong(value)); } else if (type.equals(Type.VOID)) { return DollarStatic.$void(); } else if (type.equals(Type.DATE)) { return DollarFactory.fromValue(LocalDateTime.parse(value)); } else if (type.equals(Type.URI)) { return DollarFactory.fromURI(value); } else {// w w w. j a v a 2 s . c om return failure(INVALID_CAST); } }
From source file:com.example.DatastoreSampleApplicationTests.java
@Test public void basicTest() throws Exception { Singer johnDoe = new Singer(null, "John", "Doe", null); Singer janeDoe = new Singer(null, "Jane", "Doe", null); Singer richardRoe = new Singer(null, "Richard", "Roe", null); Singer frodoBaggins = new Singer(null, "Frodo", "Baggins", null); List<Singer> singersAsc = getSingers("/singers?sort=lastName,ASC"); assertThat(singersAsc).as("Verify ASC order").containsExactly(johnDoe, janeDoe, richardRoe); List<Singer> singersDesc = getSingers("/singers?sort=lastName,DESC"); assertThat(singersDesc).as("Verify DESC order").containsExactly(richardRoe, johnDoe, janeDoe); sendRequest("/singers", "{\"singerId\": \"singerFrodo\", \"firstName\":" + " \"Frodo\", \"lastName\": \"Baggins\"}", HttpMethod.POST);/*from w w w. j a v a 2 s . c o m*/ Awaitility.await().atMost(15, TimeUnit.SECONDS) .until(() -> getSingers("/singers?sort=lastName,ASC").size() == 4); List<Singer> singersAfterInsertion = getSingers("/singers?sort=lastName,ASC"); assertThat(singersAfterInsertion).as("Verify post").containsExactly(frodoBaggins, johnDoe, janeDoe, richardRoe); sendRequest("/singers/singer1", null, HttpMethod.DELETE); Awaitility.await().atMost(15, TimeUnit.SECONDS) .until(() -> getSingers("/singers?sort=lastName,ASC").size() == 3); List<Singer> singersAfterDeletion = getSingers("/singers?sort=lastName,ASC"); assertThat(singersAfterDeletion).as("Verify Delete").containsExactly(frodoBaggins, janeDoe, richardRoe); assertThat(baos.toString()).as("Verify relationships saved in transaction") .contains("Relationship links " + "were saved between a singer, bands, and instruments in a single transaction: " + "Singer{singerId='singer2', firstName='Jane', lastName='Doe', " + "albums=[Album{albumName='a', date=2012-01-20}, Album{albumName='b', " + "date=2018-02-12}], firstBand=General Band, bands=General Band,Big Bland Band, " + "personalInstruments=recorder,cow bell}"); assertThat(this.singerRepository.findById("singer2").get().getPersonalInstruments().stream() .map(Instrument::getType).collect(Collectors.toList())).containsExactlyInAnyOrder("recorder", "cow bell"); assertThat(this.singerRepository.findById("singer2").get().getBands().stream().map(Band::getName) .collect(Collectors.toList())).containsExactlyInAnyOrder("General Band", "Big Bland Band"); Singer singer3 = this.singerRepository.findById("singer3").get(); assertThat(singer3.getPersonalInstruments().stream().map(Instrument::getType).collect(Collectors.toList())) .containsExactlyInAnyOrder("triangle", "marimba"); assertThat(singer3.getBands().stream().map(Band::getName).collect(Collectors.toList())) .containsExactlyInAnyOrder("Crooked Still", "Big Bland Band"); assertThat(singer3.getLastModifiedTime()).isAfter(LocalDateTime.parse("2000-01-01T00:00:00")); assertThat(baos.toString()) .contains("Query by example\n" + "Singer{singerId='singer1', firstName='John', lastName='Doe', " + "albums=[], firstBand=null, bands=, personalInstruments=}\n" + "Singer{singerId='singer2', firstName='Jane', lastName='Doe', " + "albums=[Album{albumName='a', date=2012-01-20}"); assertThat(baos.toString()).contains( "Using Pageable parameter\n" + "Singer{singerId='singer1', firstName='John', lastName='Doe', " + "albums=[], firstBand=null, bands=, personalInstruments=}\n" + "Singer{singerId='singer2', firstName='Jane', lastName='Doe', " + "albums=[Album{albumName='a', date=2012-01-20}"); assertThat(baos.toString()).contains("This concludes the sample."); }
From source file:org.zaproxy.zap.extension.saml.SAMLMessage.java
/** * Check whether the values are applicable to the selected attribute * * @param type Param type that is expected * @param value Param value to be tested against * @return Object that matches the relevant type is valid, null if invalid *///from ww w . j ava 2s .c o m private Object validateValueType(Attribute.SAMLAttributeValueType type, String value) { try { switch (type) { case String: return value; case Decimal: return Double.valueOf(value); case Integer: return Integer.parseInt(value); case TimeStamp: return LocalDateTime.parse(value); default: return value; } } catch (NumberFormatException e) { return null; } }