List of usage examples for org.joda.time.format ISODateTimeFormat dateTime
public static DateTimeFormatter dateTime()
From source file:net.simonvt.cathode.api.util.TimeUtils.java
License:Apache License
public static String getIsoTime(long millis) { DateTime dt = new DateTime(millis); DateTimeFormatter fmt = ISODateTimeFormat.dateTime().withZoneUTC(); return fmt.print(dt); }
From source file:net.solarnetwork.node.setup.impl.DefaultSetupService.java
License:Open Source License
@Override public NetworkAssociationDetails decodeVerificationCode(String verificationCode) throws InvalidVerificationCodeException { log.debug("Decoding verification code {}", verificationCode); NetworkAssociationDetails details = new NetworkAssociationDetails(); try {/* w w w. j a v a2 s . c o m*/ JavaBeanXmlSerializer helper = new JavaBeanXmlSerializer(); InputStream in = new GZIPInputStream( new Base64InputStream(new ByteArrayInputStream(verificationCode.getBytes()))); Map<String, Object> result = helper.parseXml(in); // Get the host server String hostName = (String) result.get(VERIFICATION_CODE_HOST_NAME); if (hostName == null) { // Use the default log.debug("Property {} not found in verfication code", VERIFICATION_CODE_HOST_NAME); throw new InvalidVerificationCodeException("Missing host"); } details.setHost(hostName); // Get the host port String hostPort = (String) result.get(VERIFICATION_CODE_HOST_PORT); if (hostPort == null) { log.debug("Property {} not found in verfication code", VERIFICATION_CODE_HOST_PORT); throw new InvalidVerificationCodeException("Missing port"); } try { details.setPort(Integer.valueOf(hostPort)); } catch (NumberFormatException e) { throw new InvalidVerificationCodeException("Invalid host port value: " + hostPort, e); } // Get the confirmation Key String confirmationKey = (String) result.get(VERIFICATION_CODE_CONFIRMATION_KEY); if (confirmationKey == null) { throw new InvalidVerificationCodeException("Missing confirmation code"); } details.setConfirmationKey(confirmationKey); // Get the identity key String identityKey = (String) result.get(VERIFICATION_CODE_IDENTITY_KEY); if (identityKey == null) { throw new InvalidVerificationCodeException("Missing identity key"); } details.setIdentityKey(identityKey); // Get the user name String userName = (String) result.get(VERIFICATION_CODE_USER_NAME_KEY); if (userName == null) { throw new InvalidVerificationCodeException("Missing username"); } details.setUsername(userName); // Get the expiration String expiration = (String) result.get(VERIFICATION_CODE_EXPIRATION_KEY); if (expiration == null) { throw new InvalidVerificationCodeException( VERIFICATION_CODE_EXPIRATION_KEY + " not found in verification code: " + verificationCode); } try { DateTimeFormatter fmt = ISODateTimeFormat.dateTime(); DateTime expirationDate = fmt.parseDateTime(expiration); details.setExpiration(expirationDate.toDate()); } catch (IllegalArgumentException e) { throw new InvalidVerificationCodeException("Invalid expiration date value", e); } // Get the TLS setting String forceSSL = (String) result.get(VERIFICATION_CODE_FORCE_TLS); details.setForceTLS(forceSSL == null ? false : Boolean.valueOf(forceSSL)); return details; } catch (InvalidVerificationCodeException e) { throw e; } catch (Exception e) { // Runtime/IO errors can come from webFormGetForBean throw new InvalidVerificationCodeException( "Error while trying to decode verfication code: " + verificationCode, e); } }
From source file:nl.knaw.dans.common.solr.SolrUtil.java
License:Apache License
public static String toString(final DateTime d) { DateTimeFormatter fmt = ISODateTimeFormat.dateTime(); DateTime dUtc = d.toDateTime(DateTimeZone.UTC); return fmt.print(dUtc); }
From source file:nl.knaw.dans.dccd.common.wicket.timeline.Timeline.java
License:Apache License
private static String getMarkersJS(List<TimeMarker> markers) { StringBuilder script = new StringBuilder(); if (markers.isEmpty()) return ""; // no markers DateTimeFormatter dtf = ISODateTimeFormat.dateTime(); // to put the dates in JSON script.append("timeline.addTimeMarkers(["); boolean isFirst = true; for (TimeMarker marker : markers) { if (isFirst) isFirst = false;//from w w w.ja v a2s . co m else script.append(","); /* // Convert dates to UTC, just to be sure DateTime dUtc = marker.getFrom().toDateTime(DateTimeZone.UTC); // and make them into ISO strings String fromStr = dtf.print(dUtc); dUtc = marker.getTo().toDateTime(DateTimeZone.UTC); String toStr = dtf.print(dUtc); script.append("{"+ "from:" +"\"" + fromStr + "\"" + "," + "to:" +"\"" + toStr + "\"" + ","+ "info:" +"\"" + marker.getInfo()+ "\"" + "}"); */ // Convert dates to UTC, just to be sure DateTime dUtc = marker.getFrom().toDateTime(DateTimeZone.UTC); long from = dUtc.getMillis(); dUtc = marker.getTo().toDateTime(DateTimeZone.UTC); long to = dUtc.getMillis(); script.append( "{" + "from:" + from + "," + "to:" + to + "," + "info:" + "\"" + marker.getInfo() + "\"" + "}"); } script.append("]);"); return script.toString(); }
From source file:nl.knaw.dans.dccd.oai.DCCDMetaDataService.java
License:Apache License
/** * Retrieve the XML for all the project that changed within the given dates * //from w w w .ja v a2 s . co m * @param from * @param until * @return */ public String getProjectListXML(Date from, Date until) { String url = getDccdRestUrl() + "/project"; // convert to UTC and format as ISO DateTimeFormatter fmt = ISODateTimeFormat.dateTime(); DateTime dUtc = new DateTime(from).toDateTime(DateTimeZone.UTC); String fromStr = fmt.print(dUtc); dUtc = new DateTime(until).toDateTime(DateTimeZone.UTC); String untilStr = fmt.print(dUtc); URI uri = UriBuilder.fromUri(url).queryParam("modFrom", fromStr).queryParam("modUntil", untilStr) .queryParam("limit", "1000000000") // need to specify a large number to get all results! .build(); LOG.debug("get project info with REST url: " + uri.toString()); Client client = Client.create(); WebResource resource = client.resource(uri); ClientResponse response = resource //.accept(MediaType.APPLICATION_XML) .get(ClientResponse.class); if (Response.Status.OK.getStatusCode() != response.getStatus()) { return null; } String rStr = response.getEntity(String.class); return rStr; }
From source file:nl.knaw.dans.dccd.oai.DCCDMetaDataService.java
License:Apache License
/** * get the timestamp for the latest change in the archive that OAI must know about. * //from w w w .j a va2s . c o m * @return */ public Date getLatestDate() { String xmlStr = getLastProjectXML(); if (xmlStr == null) return null; // now try to get the date from the XML // xpath would be: /projects/project/stateChanged // use DOM parser try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.parse(new InputSource(new StringReader(xmlStr))); NodeList nodes = doc.getElementsByTagName("stateChanged"); // should be one and only one! Element element = (Element) nodes.item(0); String dateStr = element.getTextContent(); // convert to a date DateTimeFormatter fmt = ISODateTimeFormat.dateTime(); return fmt.parseDateTime(dateStr).toDate(); } catch (ParserConfigurationException e) { e.printStackTrace(); } catch (SAXException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; }
From source file:nl.knaw.dans.dccd.oai.DCCDMetaDataService.java
License:Apache License
/** * Retrieve the XML for the project that changed last * /*from w w w . j a v a 2s .com*/ * The rest interface will return the results of a request for project * with a date restriction (from , until) sorted on the date. * And the latest one will be the first in the list of results. * So if we ask for just one project of all since the beginning, we get the one that changed last. * * @return */ private String getLastProjectXML() { String url = getDccdRestUrl() + "/project"; Date from = new Date(0); // before the archive existed // convert to UTC and format as ISO DateTimeFormatter fmt = ISODateTimeFormat.dateTime(); DateTime dUtc = new DateTime(from).toDateTime(DateTimeZone.UTC); String fromStr = fmt.print(dUtc); URI uri = UriBuilder.fromUri(url).queryParam("modFrom", fromStr).queryParam("offset", "0") .queryParam("limit", "1").build(); LOG.debug("get last project with REST url: " + uri.toString()); Client client = Client.create(); WebResource resource = client.resource(uri); ClientResponse response = resource //.accept(MediaType.APPLICATION_XML) .get(ClientResponse.class); if (Response.Status.OK.getStatusCode() != response.getStatus()) { return null; } String rStr = response.getEntity(String.class); return rStr; }
From source file:nl.knaw.dans.dccd.rest.AbstractProjectResource.java
License:Apache License
/** * Append information anyone is allowed to see * The most important project data but not identical to TRiDaS! * /*w ww . j av a 2 s. com*/ * @param sw * writer to append to * @param dccdSB * search result */ protected void appendProjectPublicDataAsXml(java.io.StringWriter sw, DccdSB dccdSB) { // Note the Fedora pid is our sid, but sometimes called pid anyway; // confusing I know sw.append(getXMLElementString("sid", dccdSB.getPid())); // modified timestamp // convert to UTC and format as ISO DateTimeFormatter fmt = ISODateTimeFormat.dateTime(); DateTime dUtc = dccdSB.getAdministrativeStateLastChange().toDateTime(DateTimeZone.UTC); //sw.append(getXMLElementString("stateChanged", dccdSB.getAdministrativeStateLastChange().toString())); sw.append(getXMLElementString("stateChanged", fmt.print(dUtc))); // Not at first only added title, so a client can show something in a // user interface, // but now we put in (almost) everything from the search results. // title sw.append(getXMLElementString("title", dccdSB.getTridasProjectTitle())); // identifier sw.append(getXMLElementString("identifier", dccdSB.getTridasProjectIdentifier())); // category, but not std, normal etc. sw.append(getXMLElementString("category", dccdSB.getTridasProjectCategory())); // investigator sw.append(getXMLElementString("investigator", dccdSB.getTridasProjectInvestigator())); // lab(s) (combined name, address, but not concatenated...) sw.append("<laboratories>"); for (String lab : dccdSB.getTridasProjectLaboratoryCombined()) { sw.append(getXMLElementString("laboratory", lab)); } sw.append("</laboratories>"); // type(s) sw.append("<types>"); for (String type : dccdSB.getTridasProjectType()) { sw.append(getXMLElementString("type", type)); } sw.append("</types>"); // Note that this goes to another service and is a Performance Penalty sw.append(getXMLElementString("ownerOrganizationId", getOwnerOrganizationId(dccdSB))); // And this one goes to the data archive... a penalty... sw.append(getXMLElementString("language", getProjectlanguage(dccdSB))); }
From source file:nl.knaw.dans.dccd.rest.ProjectResource.java
License:Apache License
private void addFilterQueryForModified(SimpleSearchRequest request, final String modFromStr, final String modUntilStr) throws IllegalArgumentException { DateTimeWrapper modFrom = null;//from w w w . jav a2 s . c o m DateTimeWrapper modUntil = null; // parse the strings an get DateTime objects // Note that it should be the same format as we use when outputting the "stateChanged" property. if (modFromStr != null) { DateTimeFormatter df = ISODateTimeFormat.dateTime(); modFrom = new DateTimeWrapper(df.parseDateTime(modFromStr)); } if (modUntilStr != null) { DateTimeFormatter df = ISODateTimeFormat.dateTime(); modUntil = new DateTimeWrapper(df.parseDateTime(modUntilStr)); } if (modFrom != null || modUntil != null) { // use DccdProjectSB.ADMINISTRATIVE_STATE_LASTCHANGE // Note that for Published (aka Archived) projects this is the timestamp for the publishing. // Draft projects can be modified without the 'change of state', but we won't expose those. SimpleField<Range<DateTimeWrapper>> periodField = new SimpleField<Range<DateTimeWrapper>>( DccdProjectSB.ADMINISTRATIVE_STATE_LASTCHANGE); periodField.setValue(new Range<DateTimeWrapper>(modFrom, modUntil)); request.addFilterQuery(periodField); } }
From source file:org.activiti.engine.impl.juel.TypeConverterImpl.java
License:Apache License
protected String coerceToString(Object value) { if (value == null) { return ""; }// w w w . j av a 2s . c om if (value instanceof String) { return (String) value; } if (value instanceof Enum<?>) { return ((Enum<?>) value).name(); } if (value instanceof Date) { DateTimeFormatter fmt = ISODateTimeFormat.dateTime(); DateTime dt = new DateTime(value); return fmt.print(dt); } return value.toString(); }