List of usage examples for java.util Date from
public static Date from(Instant instant)
From source file:org.apache.james.jmap.methods.integration.cucumber.GetMessagesMethodStepdefs.java
private void appendMessage(String emlFileName) throws Exception { ZonedDateTime dateTime = ZonedDateTime.parse("2014-10-30T14:12:00Z"); mainStepdefs.jmapServer.serverProbe().appendMessage(userStepdefs.lastConnectedUser, new MailboxPath(MailboxConstants.USER_NAMESPACE, userStepdefs.lastConnectedUser, "inbox"), ClassLoader.getSystemResourceAsStream(emlFileName), Date.from(dateTime.toInstant()), false, new Flags()); }
From source file:org.noorganization.instalist.server.api.RecipeResource.java
/** * Get a single recipe.//ww w . java 2 s.co m * @param _groupId The id of the group containing the recipe. * @param _recipeUUID The uuid of the requested recipe. */ @GET @TokenSecured @Path("{recipeuuid}") @Produces({ "application/json" }) public Response getRecipe(@PathParam("groupid") int _groupId, @PathParam("recipeuuid") String _recipeUUID) throws Exception { UUID toFind; try { toFind = UUID.fromString(_recipeUUID); } catch (IllegalArgumentException _e) { return ResponseFactory.generateBadRequest(CommonEntity.INVALID_UUID); } EntityManager manager = DatabaseHelper.getInstance().getManager(); IRecipeController recipeController = ControllerFactory.getRecipeController(manager); DeviceGroup group = manager.find(DeviceGroup.class, _groupId); Recipe current = recipeController.findByGroupAndUUID(group, toFind); if (current == null) { if (recipeController.findDeletedByGroupAndUUID(group, toFind) == null) { manager.close(); return ResponseFactory.generateNotFound(new Error().withMessage("Recipe was not " + "found.")); } manager.close(); return ResponseFactory.generateGone(new Error().withMessage("Recipe was deleted " + "before.")); } manager.close(); RecipeInfo rtn = new RecipeInfo().withDeleted(false); rtn.setUUID(current.getUUID()); rtn.setName(current.getName()); rtn.setLastChanged(Date.from(current.getUpdated())); return ResponseFactory.generateOK(rtn); }
From source file:org.createnet.raptor.models.data.RecordSet.java
private void parseJson(Stream stream, JsonNode row) { JsonNode channels = row;// ww w . j ava 2 s . c o m if (row.has("channels")) { if (row.has("timestamp")) { Date date = Date.from(Instant.ofEpochSecond(row.get("timestamp").asLong())); this.setTimestamp(date); } else if (row.has("lastUpdate")) { Date date = Date.from(Instant.ofEpochSecond(row.get("lastUpdate").asLong())); this.setTimestamp(date); } channels = row.get("channels"); } for (Iterator<Map.Entry<String, JsonNode>> iterator = channels.fields(); iterator.hasNext();) { Map.Entry<String, JsonNode> item = iterator.next(); String channelName = item.getKey(); JsonNode nodeValue = item.getValue(); JsonNode valObj = nodeValue; // allow short-hand without [current-]value if (nodeValue.isObject()) { if (nodeValue.has("value")) { valObj = nodeValue.get("value"); } else if (nodeValue.has("current-value")) { valObj = nodeValue.get("current-value"); } } try { if (stream != null && (stream.channels != null && !stream.channels.isEmpty())) { if (stream.channels.containsKey(channelName)) { this.addRecord(stream, channelName, valObj); } } else { // definition is unknown, add all channels to the record set this.addRecord(stream, channelName, valObj); } } catch (Exception e) { throw new RecordsetException(e); } } }
From source file:org.noorganization.instalist.server.api.UnitResource.java
/** * Returns the unit.//from w ww .j a v a2 s .c o m * @param _groupId The croup containing the requested unit. * @param _unitUUID The uuid of the requested unit. */ @GET @TokenSecured @Path("{unituuid}") @Produces({ "application/json" }) public Response getUnit(@PathParam("groupid") int _groupId, @PathParam("unituuid") String _unitUUID) throws Exception { try { UUID toFind; try { toFind = UUID.fromString(_unitUUID); } catch (IllegalArgumentException _e) { return ResponseFactory.generateBadRequest(CommonEntity.INVALID_UUID); } EntityManager manager = DatabaseHelper.getInstance().getManager(); IUnitController unitController = ControllerFactory.getUnitController(manager); DeviceGroup group = manager.find(DeviceGroup.class, _groupId); Unit resultUnit = unitController.findByGroupAndUUID(group, toFind); if (resultUnit == null) { if (unitController.findDeletedByGroupAndUUID(group, toFind) == null) { manager.close(); return ResponseFactory .generateNotFound(new Error().withMessage("The requested " + "unit was not found.")); } manager.close(); return ResponseFactory .generateGone(new Error().withMessage("The requested unit has " + "been deleted.")); } manager.close(); UnitInfo rtn = new UnitInfo().withDeleted(false); rtn.setName(resultUnit.getName()); rtn.setUUID(resultUnit.getUUID()); rtn.setLastChanged(Date.from(resultUnit.getUpdated())); return ResponseFactory.generateOK(rtn); } catch (Exception _e) { _e.printStackTrace(); throw _e; } }
From source file:org.codice.ddf.registry.schemabindings.RegistryPackageUtils.java
public static List<Date> getSlotDateValues(SlotType1 slot) { List<Date> dates = new ArrayList<>(); if (slot.isSetValueList()) { ValueListType valueList = slot.getValueList().getValue(); if (valueList.isSetValue()) { List<String> values = valueList.getValue(); for (String dateString : values) { Date date = Date.from(ZonedDateTime.parse(dateString).toInstant()); if (date != null) { dates.add(date);/*from w ww . j a v a2 s .co m*/ } } } } return dates; }
From source file:com.buffalokiwi.api.APIDate.java
/** * Retrieve the date in UTC. * @return Date */ @Override public Date getDate() { return Date.from(date.toInstant()); }
From source file:com.ikanow.aleph2.data_model.utils.TimeUtils.java
/** Returns a date representing an ISO date (with or without trailing "Z") * @param iso_date// w ww . j a v a 2s . c o m * @return */ public static Validation<String, Date> parseIsoString(final String iso_date) { try { if (iso_date.endsWith("Z")) return Validation.success(Date.from(Instant.parse(iso_date))); return Validation.success(Date.from(Instant.parse(iso_date + "Z"))); } catch (Exception e) { return Validation.fail(e.getMessage()); } }
From source file:com.buffalokiwi.api.APIDate.java
/** * Convert whatever date this is to the system zone * @return system date/time/*w w w . ja va2 s. com*/ */ @Override public Date toLocalDate() { return Date.from(date.withZoneSameInstant(ZoneId.systemDefault()).toInstant()); }
From source file:org.noorganization.instalist.server.api.TaggedProductResourceTest.java
@Test public void testGetTaggedProducts() throws Exception { String url = "/groups/%d/taggedproducts"; Instant preUpdate = Instant.now(); Response notAuthorizedResponse = target(String.format(url, mGroup.getId())).request().get(); assertEquals(401, notAuthorizedResponse.getStatus()); Response wrongAuthResponse = target(String.format(url, mGroup.getId())).request() .header(HttpHeaders.AUTHORIZATION, "X-Token wrongauth").get(); assertEquals(401, wrongAuthResponse.getStatus()); Response wrongGroupResponse = target(String.format(url, mNAGroup.getId())).request() .header(HttpHeaders.AUTHORIZATION, "X-Token " + mToken).get(); assertEquals(401, wrongGroupResponse.getStatus()); Response okResponse1 = target(String.format(url, mGroup.getId())).request() .header(HttpHeaders.AUTHORIZATION, "X-Token " + mToken).get(); assertEquals(200, okResponse1.getStatus()); TaggedProductInfo[] allTaggedProductInfo = okResponse1.readEntity(TaggedProductInfo[].class); assertEquals(2, allTaggedProductInfo.length); for (TaggedProductInfo current : allTaggedProductInfo) { if (mTaggedProduct.getUUID().equals(UUID.fromString(current.getUUID()))) { assertEquals(mTaggedProduct.getUpdated(), current.getLastChanged().toInstant()); assertEquals(mTag.getUUID(), UUID.fromString(current.getTagUUID())); assertEquals(mProduct.getUUID(), UUID.fromString(current.getProductUUID())); assertFalse(current.getDeleted()); } else if (mDeletedIngredient.getUUID().equals(UUID.fromString(current.getUUID()))) { assertNull(current.getTagUUID()); assertNull(current.getProductUUID()); assertEquals(mDeletedIngredient.getUpdated(), current.getLastChanged().toInstant()); assertTrue(current.getDeleted()); } else/*from w w w.j a v a 2 s.c o m*/ fail("Unexpected TaggedProduct."); } mManager.getTransaction().begin(); mTaggedProduct.setUpdated(Instant.now()); mManager.getTransaction().commit(); Response okResponse2 = target(String.format(url, mGroup.getId())) .queryParam("changedsince", ISO8601Utils.format(Date.from(preUpdate), true)).request() .header(HttpHeaders.AUTHORIZATION, "X-Token " + mToken).get(); assertEquals(200, okResponse2.getStatus()); TaggedProductInfo[] oneTaggedProductInfo = okResponse2.readEntity(TaggedProductInfo[].class); assertEquals(1, oneTaggedProductInfo.length); assertEquals(mTaggedProduct.getUUID(), UUID.fromString(oneTaggedProductInfo[0].getUUID())); assertFalse(oneTaggedProductInfo[0].getDeleted()); }
From source file:org.sakaiproject.assignment.impl.reminder.AssignmentDueReminderServiceImpl.java
private void sendEmailReminder(Site site, Assignment assignment, Member submitter) { log.debug("SendEmailReminder: '" + assignment.getTitle() + "' to " + submitter.getUserDisplayId()); String assignmentTitle = assignment.getTitle(); if (assignment.getTitle().length() > 11) { assignmentTitle = assignment.getTitle().substring(0, 11) + "[...]"; }/*from w w w .ja v a 2 s.c om*/ String courseName = site.getTitle(); Locale locale = new ResourceLoader().getLocale(submitter.getUserId()); SimpleDateFormat sdf = (locale != null) ? new SimpleDateFormat(DATE_FORMAT, locale) : new SimpleDateFormat(DATE_FORMAT); Instant dueDate = assignment.getDueDate(); String formattedDateDue = sdf.format(Date.from(dueDate)); String toStr = getUserEmail(submitter.getUserId()); if (StringUtils.isEmpty(toStr)) { return; } String headerToStr = getUserDisplayName(submitter.getUserId()) + " <" + getUserEmail(submitter.getUserId()) + ">"; String fromStr = "\"" + courseName + "\" <" + getSetupRequest() + ">"; Set<Member> instructors = new HashSet<>(); for (Member member : site.getMembers()) { if (StringUtils.equals(member.getRole().getId(), site.getMaintainRole())) { instructors.add(member); } } String replyToStr = getReplyTo(instructors); log.debug("Reply to string: " + replyToStr); String subject = "Assignment '" + assignmentTitle + "' Due on " + formattedDateDue; StringBuilder body = new StringBuilder(); body.append("Hello "); body.append(getUserFirstName(submitter.getUserId())); body.append(",<br />"); body.append("<br />"); int totalHours = serverConfigurationService.getInt("assignment.reminder.hours", 24); String hoursMod = (totalHours % 24 == 0) ? "." : " and " + (totalHours % 24) + " hours."; String timeText = (totalHours < 25) ? totalHours + " hours." : (totalHours / 24) + " days" + hoursMod; body.append(String.format("Reminder: An assignment of yours is due within %s", timeText)); body.append("<br />"); body.append("<ul>"); body.append("<li> Assignment : ").append(assignment.getTitle()).append("</li>"); body.append("<li> Due : ").append(formattedDateDue).append("</li>"); body.append("<li> Class : ").append(courseName).append("</li>"); body.append("</ul>"); body.append("<br />"); body.append("Have a nice day!"); body.append("<br />"); body.append("- ").append(getServiceName()); log.debug("Email To: '" + toStr + "' body: " + body.toString()); emailService.send(fromStr, toStr, subject, body.toString(), headerToStr, replyToStr, additionalHeaders); }