List of usage examples for org.joda.time.format ISODateTimeFormat dateTimeNoMillis
public static DateTimeFormatter dateTimeNoMillis()
From source file:org.overlord.sramp.repository.query.AbstractSrampQueryImpl.java
License:Apache License
/** * @see org.overlord.sramp.repository.query.SrampQuery#setDateTime(java.util.Calendar) */// w w w . ja va2s .c o m @Override public void setDateTime(Calendar date) { String val = ISODateTimeFormat.dateTimeNoMillis().print(new DateTime(date)); this.replacementParams.add(new StringReplacementParam(val)); }
From source file:org.ow2.proactive.scheduler.common.job.Job.java
License:Open Source License
/** * Deadline can be as absolute or relative (from the job started time) * Absolute deadline can be set as GI vairable `JOB_DDL` in ISO8601 date format * without milliseconds, e.g. 2018-08-14T08:40:30+02:00. * Relative deadline can be set as GI vairable `JOB_DDL` in the following format * +HH:MM:SS, e.g. `+02:30:00`, or as +MM:SS, e.g. `+15:30`, or as +SS, e.g. `+40`. * @return job deadline if it exists//from w ww .j a v a2 s . c o m */ public Optional<JobDeadline> getJobDeadline() { if (genericInformation.containsKey(JOB_DDL)) { final String strJobDeadline = genericInformation.get(Job.JOB_DDL); try { if (strJobDeadline.startsWith("+")) { // should be relative deadline return Optional .of(new JobDeadline(JobDeadline.parseDuration(strJobDeadline.substring(1)).get())); } else { // should be absolute deadline return Optional.of(new JobDeadline( ISODateTimeFormat.dateTimeNoMillis().parseDateTime(strJobDeadline).toDate())); } } catch (Exception e) { LOGGER.warn("Imposible to parse JOB_DDL GI variable as deadline: " + strJobDeadline); } } return Optional.empty(); }
From source file:org.powertac.hamweather.Parser.java
License:Apache License
public void processFiles() { try {/* w ww .j a v a 2 s . c o m*/ BufferedReader in = new BufferedReader(new FileReader(inputFile)); Pattern observation = Pattern.compile("^-- observation: ([SMTWF][a-z]+ [A-Za-z]+ \\d+ [-0-9: ]+)"); Pattern loc = Pattern.compile("^-- location: " + location); String line; State state = State.OBS; Matcher m; JSONParser jparser = new JSONParser(); DateTimeFormatter dtf = DateTimeFormat.forPattern("E MMM d HH:mm:ss Z YYYY"); iso = ISODateTimeFormat.dateTimeNoMillis(); DateTime lastObs = null; DateTime obsHour = null; while (true) { line = in.readLine(); if (null == line || 0 == line.length()) break; switch (state) { case OBS: m = observation.matcher(line); if (m.matches()) { DateTime obsTime = dtf.parseDateTime(m.group(1)); if (null == lastObs) { lastObs = obsTime; } else if (obsTime.isAfter(lastObs.plus(MAX_INTERVAL))) { System.out.println("Missed obs - last = " + iso.print(lastObs) + ", current = " + iso.print(obsTime)); } lastObs = obsTime; obsHour = obsTime.plus(HOUR / 2).withMillisOfSecond(0).withSecondOfMinute(0) .withMinuteOfHour(0); state = State.LOC; } break; case LOC: m = loc.matcher(line); if (m.matches()) { //System.out.println("Location: " + location); state = State.JSON_OB; } break; case JSON_OB: // process new observation JSONObject obs = (JSONObject) jparser.parse(line); // check for errors Boolean success = (Boolean) obs.get("success"); if (!success) { System.out.println("Observation retrieval failed at " + iso.print(obsHour)); state = State.OBS; } else { JSONObject err = (JSONObject) obs.get("error"); if (null != err) { // error at server end String msg = (String) err.get("description"); System.out.println("Observation error: " + msg + " at " + iso.print(obsHour)); state = State.OBS; } else { try { JSONObject response = (JSONObject) obs.get("response"); JSONObject ob = (JSONObject) response.get("ob"); extractObservation(ob); state = State.JSON_FCST; } catch (ClassCastException cce) { System.out.println("Faulty observation " + obs.toString()); state = State.OBS; } } } break; case JSON_FCST: // process new forecast JSONObject fcst = (JSONObject) jparser.parse(line); // check for errors Boolean success1 = (Boolean) fcst.get("success"); if (!success1) { // could not retrieve forecast System.out.println("Forecast retrieval failed at " + iso.print(obsHour)); output.forecastMissing(); } else { JSONObject err = (JSONObject) fcst.get("error"); if (null != err) { // error at server end String msg = (String) err.get("description"); System.out.println("Forecast error: " + msg + " at " + iso.print(obsHour)); output.forecastMissing(); } else { JSONArray response = (JSONArray) fcst.get("response"); if (response.size() == 0) { // should never get here System.out.println("Empty forecast at " + iso.print(obsHour)); } JSONObject periods = (JSONObject) response.get(0); JSONArray fcsts = (JSONArray) periods.get("periods"); if (fcsts.size() != FORECAST_HORIZON) { System.out.println( "Missing forecasts (" + fcsts.size() + ") at " + iso.print(lastObs)); } for (int i = 0; i < fcsts.size(); i++) { JSONObject forecast = (JSONObject) fcsts.get(i); extractForecast(forecast, i + 1, obsHour); } } } state = State.OBS; break; } } output.write(); in.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (org.json.simple.parser.ParseException e) { e.printStackTrace(); } }
From source file:org.powertac.hamweather.XmlOutputStructure.java
License:Apache License
public XmlOutputStructure() { iso = ISODateTimeFormat.dateTimeNoMillis(); observations = new ArrayList<Observation>(); forecasts = new ArrayList<Forecast>(); DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder;/* w w w . j ava 2 s . co m*/ try { docBuilder = docFactory.newDocumentBuilder(); // Root element doc = docBuilder.newDocument(); doc.setXmlStandalone(true); rootElement = doc.createElement("data"); doc.appendChild(rootElement); } catch (ParserConfigurationException e) { e.printStackTrace(); } }
From source file:org.slc.sli.api.security.saml.SamlHelper.java
License:Apache License
/** * Generates AuthnRequest and converts it to valid form for HTTP-Redirect binding * * AssertionConsumerServiceURL attribute can be added to root element, but seems not required. * If added, must match an// w ww . j ava2 s . c o m * endpoint that was sent to the idp during federation (sp.xml) * SPNameQualifier attribute can be added to NameId, but seems not required. Same as IssuerName * * @param destination * idp url to where the message is going * @param binding * binding to be specified in saml * @param forceAuthn * boolean indicating whether authentication at the idp should be forced onto user * @param idpType * identifier for the type of IDP (1=SimpleIDP, 2=OpenAM, 3=ADFS, Sitminder=4) * @return {generated messageId, deflated, base64-encoded and url encoded saml message} java * doesn't have tuples :( * @throws Exception * */ @SuppressWarnings("unchecked") private Pair<String, String> composeAuthnRequest(String destination, String binding, boolean forceAuthn, int idpType) { Document doc = new Document(); String id = "sli-" + UUID.randomUUID().toString(); doc.setRootElement(new Element("AuthnRequest", SAMLP_NS)); doc.getRootElement().getAttributes().add(new Attribute("ID", id)); doc.getRootElement().getAttributes().add(new Attribute("Version", "2.0")); doc.getRootElement().getAttributes().add(new Attribute("IssueInstant", new DateTime(DateTimeZone.UTC).toString(ISODateTimeFormat.dateTimeNoMillis()))); doc.getRootElement().getAttributes().add(new Attribute("Destination", destination)); doc.getRootElement().getAttributes().add(new Attribute("ForceAuthn", String.valueOf(forceAuthn))); doc.getRootElement().getAttributes().add(new Attribute("IsPassive", "false")); doc.getRootElement().getAttributes().add(new Attribute("ProtocolBinding", binding)); Element issuer = new Element("Issuer", SAML_NS); issuer.addContent(issuerName); doc.getRootElement().addContent(issuer); Element nameId = new Element("NameIDPolicy", SAMLP_NS); nameId.getAttributes().add(new Attribute("Format", "urn:oasis:names:tc:SAML:2.0:nameid-format:transient")); nameId.getAttributes().add(new Attribute("AllowCreate", "true")); nameId.getAttributes().add(new Attribute("SPNameQualifier", issuerName)); doc.getRootElement().addContent(nameId); if (idpType != 4) { Element authnContext = new Element("RequestedAuthnContext", SAMLP_NS); authnContext.getAttributes().add(new Attribute("Comparison", "exact")); Element classRef = new Element("AuthnContextClassRef", SAML_NS); classRef.addContent("urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport"); authnContext.addContent(classRef); doc.getRootElement().addContent(authnContext); } // add signature and digest here try { org.w3c.dom.Document w3Doc = null; synchronized (domer) { w3Doc = domer.output(doc); } String xmlString = nodeToXmlString(w3Doc); LOG.debug(xmlString); return Pair.of(id, xmlToEncodedString(xmlString)); } catch (Exception e) { LOG.error("Error composing AuthnRequest", e); throw new IllegalArgumentException("Couldn't compose AuthnRequest", e); } }
From source file:org.slc.sli.sandbox.idp.saml.SamlResponseComposer.java
License:Apache License
private String createUnsignedResponse(String destination, String issuer, String requestId, String userId, Map<String, String> attributes, List<String> roles) { String template;//w w w . j a v a 2 s. c o m try { template = IOUtils.toString(this.getClass().getResourceAsStream("/samlResponseTemplate.xml")); } catch (IOException e) { throw new SamlProcessException(e); } template = template.replace("__RESPONSE_ID__", UUID.randomUUID().toString()); template = template.replace("__ASSERTION_ID__", UUID.randomUUID().toString()); template = template.replace("__REQUEST_ID__", requestId); template = template.replace("__ISSUE_INSTANT__", new DateTime().withZone(DateTimeZone.UTC).toString(ISODateTimeFormat.dateTimeNoMillis())); template = template.replace("__DESTINATION__", destination); template = template.replace("__ISSUER__", issuer); template = template.replace("__TRANSIENT_ID__", UUID.randomUUID().toString()); //must be at least a 128-bit random string DateTime notOnOrAfter = new DateTime(); notOnOrAfter = notOnOrAfter.plusMinutes(10); template = template.replace("__NOT_ON_OR_AFTER__", notOnOrAfter.withZone(DateTimeZone.UTC).toString(ISODateTimeFormat.dateTimeNoMillis())); StringBuilder buf = new StringBuilder(); addAttribute(buf, "userId", userId); if (attributes != null) { for (Map.Entry<String, String> attr : attributes.entrySet()) { if (attr.getKey() != null && attr.getValue() != null) { addAttribute(buf, attr.getKey(), attr.getValue()); } } } if (roles != null && !roles.isEmpty()) { buf.append(ATTRIBUTE_NAME_BEGIN_TEMPLATE.replace("__NAME__", "roles")); for (String role : roles) { buf.append(ATTRIBUTE_VALUE_TEMPLATE.replace("__VALUE__", role)); } buf.append(ATTRIBUTE_NAME_END_TEMPLATE); } template = template.replace("__ATTRIBUTES__", buf.toString()); return template; }
From source file:org.xsystem.sql2.convertor.DefaultConvertor.java
License:Apache License
protected String coerceToString(Object value) { if (value instanceof String) { return (String) value; }/*from www .j ava2 s .c o m*/ if (value instanceof Enum<?>) { return ((Enum<?>) value).name(); } // if (value instanceof Double) { // Double d = (Double) value; // String s = NumberFormat.getNumberInstance(Locale.US).format(d); // return s; // } // if (value instanceof Float) { // Float d = (Float) value; // String s = NumberFormat.getNumberInstance(Locale.US).format(d); // return s; // } if (value instanceof Double || value instanceof Float) { BigDecimal bd = BigDecimal.valueOf((Double) value); String bds = bd.toPlainString(); String ss[] = bds.split("\\."); if (ss.length == 1 || Integer.parseInt(ss[1]) == 0) { return ss[0]; } else { return bds; } } if (value instanceof java.util.Date) { if (value instanceof java.sql.Time) { java.sql.Time t = (java.sql.Time) value; String s = t.toString(); return s; } java.util.Date d = (java.util.Date) value; long l = d.getTime(); String s = ISODateTimeFormat.dateTimeNoMillis().print(l); return s; } return value.toString(); }
From source file:org.xsystem.sql2.convertor.DefaultConvertor.java
License:Apache License
protected java.sql.Date coerceToSqlDate(Object value) { if (value instanceof java.sql.Date) { return (java.sql.Date) value; }/*w ww.j a v a 2 s . c o m*/ if (value instanceof Long) { Long l = (Long) value; java.sql.Date d = new java.sql.Date(l); return d; } if (value instanceof java.util.Date) { java.util.Date jd = (java.util.Date) value; Long l = jd.getTime(); java.sql.Date d = new java.sql.Date(l); return d; } if (value instanceof String) { String s = (String) value; try { long l = ISODateTimeFormat.dateTimeNoMillis().parseMillis(s); java.sql.Date d = new java.sql.Date(l); return d; } catch (UnsupportedOperationException | IllegalArgumentException ex) { throw new ConvertorException("Can't convert " + value + " to " + java.sql.Date.class); } } throw new ConvertorException("Can't convert " + value + " to " + java.sql.Date.class); }
From source file:org.xsystem.sql2.convertor.DefaultConvertor.java
License:Apache License
protected java.sql.Timestamp coerceToSqlTimestamp(Object value) { if (value instanceof java.sql.Timestamp) { return (java.sql.Timestamp) value; }//from w w w . j a v a 2 s . c o m if (value instanceof java.util.Date) { java.util.Date jd = (java.util.Date) value; Long l = jd.getTime(); java.sql.Timestamp d = new java.sql.Timestamp(l); return d; } if (value instanceof String) { String s = (String) value; try { long l = ISODateTimeFormat.dateTimeNoMillis().parseMillis(s); java.sql.Timestamp d = new java.sql.Timestamp(l); return d; } catch (UnsupportedOperationException | IllegalArgumentException ex) { throw new ConvertorException("Can't convert " + value + " to " + java.sql.Timestamp.class); } } throw new ConvertorException("Can't convert " + value + " to " + java.sql.Timestamp.class); }
From source file:org.xsystem.sql2.convertor.DefaultConvertor.java
License:Apache License
java.util.Date coerceToDate(Object value) { if (value instanceof java.util.Date) { return (java.util.Date) value; }/* ww w . j a va 2s. co m*/ if (value instanceof String) { String s = (String) value; try { long l = ISODateTimeFormat.dateTimeNoMillis().parseMillis(s); java.util.Date d = new java.util.Date(l); return d; } catch (UnsupportedOperationException | IllegalArgumentException ex) { throw new ConvertorException("Can't convert " + value + " to " + java.util.Date.class); } } throw new ConvertorException("Can't convert " + value + " to " + java.util.Date.class); }