List of usage examples for java.util Date from
public static Date from(Instant instant)
From source file:org.noorganization.instalist.server.api.IngredientResource.java
/** * Get a list of ingredients./* w ww . ja v a 2s.co m*/ * @param _groupId The id of the group containing various ingredients. * @param _changedSince Limits the result to elements that changed since the given date. ISO * 8601 time e.g. 2016-01-19T11:54:07+0100. Optional. */ @GET @TokenSecured @Produces({ "application/json" }) public Response getIngredients(@PathParam("groupid") int _groupId, @QueryParam("changedsince") String _changedSince) throws Exception { List<Ingredient> ingedients; List<DeletedObject> deletedIngredients; EntityManager manager = DatabaseHelper.getInstance().getManager(); DeviceGroup group = manager.find(DeviceGroup.class, _groupId); if (_changedSince != null) { Instant changedSince; try { changedSince = ISO8601Utils.parse(_changedSince, new ParsePosition(0)).toInstant(); } catch (ParseException _e) { manager.close(); return ResponseFactory.generateBadRequest(CommonEntity.INVALID_CHANGEDATE); } TypedQuery<Ingredient> IngredientsQuery = manager.createQuery( "select i from " + "Ingredient i where i.group = :group and i.updated > :updated", Ingredient.class); IngredientsQuery.setParameter("group", group); IngredientsQuery.setParameter("updated", changedSince); ingedients = IngredientsQuery.getResultList(); TypedQuery<DeletedObject> deletedIngredientsQuery = manager.createQuery( "select do " + "from DeletedObject do where do.group = :group and do.updated > :updated and " + "do.type = :type", DeletedObject.class); deletedIngredientsQuery.setParameter("group", group); deletedIngredientsQuery.setParameter("updated", changedSince); deletedIngredientsQuery.setParameter("type", DeletedObject.Type.INGREDIENT); deletedIngredients = deletedIngredientsQuery.getResultList(); } else { ingedients = new ArrayList<Ingredient>(group.getIngredients()); TypedQuery<DeletedObject> deletedIngredientsQuery = manager.createQuery( "select do from " + "DeletedObject do where do.group = :group and do.type = :type", DeletedObject.class); deletedIngredientsQuery.setParameter("group", group); deletedIngredientsQuery.setParameter("type", DeletedObject.Type.INGREDIENT); deletedIngredients = deletedIngredientsQuery.getResultList(); } manager.close(); ArrayList<IngredientInfo> rtn = new ArrayList<IngredientInfo>( ingedients.size() + deletedIngredients.size()); for (Ingredient current : ingedients) { IngredientInfo toAdd = new IngredientInfo().withDeleted(false); toAdd.setUUID(current.getUUID()); toAdd.setProductUUID(current.getProduct().getUUID()); toAdd.setRecipeUUID(current.getRecipe().getUUID()); toAdd.setAmount(current.getAmount()); toAdd.setLastChanged(Date.from(current.getUpdated())); rtn.add(toAdd); } for (DeletedObject current : deletedIngredients) { IngredientInfo toAdd = new IngredientInfo(); toAdd.setUUID(current.getUUID()); toAdd.setLastChanged(Date.from(current.getUpdated())); toAdd.setDeleted(true); rtn.add(toAdd); } return ResponseFactory.generateOK(rtn); }
From source file:org.apache.james.transport.mailets.DSNBounceTest.java
@Test public void serviceShouldSendMultipartMailToTheSender() throws Exception { FakeMailetConfig mailetConfig = FakeMailetConfig.builder().mailetName(MAILET_NAME) .mailetContext(fakeMailContext).build(); dsnBounce.init(mailetConfig);/*w w w. j av a 2 s . co m*/ MailAddress senderMailAddress = new MailAddress("sender@domain.com"); FakeMail mail = FakeMail.builder().sender(senderMailAddress) .mimeMessage(MimeMessageBuilder.mimeMessageBuilder().setText("My content")).name(MAILET_NAME) .recipient("recipient@domain.com").lastUpdated(Date.from(Instant.parse("2016-09-08T14:25:52.000Z"))) .build(); dsnBounce.service(mail); List<SentMail> sentMails = fakeMailContext.getSentMails(); assertThat(sentMails).hasSize(1); SentMail sentMail = sentMails.get(0); assertThat(sentMail.getSender()).isNull(); assertThat(sentMail.getRecipients()).containsOnly(senderMailAddress); MimeMessage sentMessage = sentMail.getMsg(); assertThat(sentMessage.getContentType()).contains("multipart/report;"); assertThat(sentMessage.getContentType()).contains("report-type=delivery-status"); }
From source file:com.algodefu.yeti.data.Pass.java
private void calculateEquityChartImg() throws IOException { int i = 0;/*from w w w.ja v a 2s.c o m*/ double sum = 0; TimeSeries equity = new TimeSeries("Equity"); // save values in temp array first, then use System.arraycopy to copy non empty values to this.equityArray double[][] tempEquityArr = new double[this.getTrades().length][4]; for (Trade trade : this.getTrades()) { if (trade.getCloseDateTime() != null) { sum += trade.getProfit(); equity.add(new Millisecond(Date.from(trade.getCloseDateTime().toInstant(ZoneOffset.UTC))), sum); tempEquityArr[i][0] = (double) trade.getCloseDateTime().toInstant(ZoneOffset.UTC).toEpochMilli(); tempEquityArr[i][1] = sum; tempEquityArr[i][2] = trade.getTradeID(); tempEquityArr[i][3] = trade.getProfit(); i++; } } this.equityArray = new double[i][4]; System.arraycopy(tempEquityArr, 0, this.equityArray, 0, i); TimeSeriesCollection dataset = new TimeSeriesCollection(equity); JFreeChart chart = ChartFactory.createTimeSeriesChart("", "", "", dataset, false, false, false); chart.getXYPlot().getDomainAxis().setTickLabelsVisible(false); chart.setBorderVisible(true); chart.getXYPlot().setRangeAxisLocation(AxisLocation.TOP_OR_RIGHT); chart.getXYPlot().getRenderer().setSeriesPaint(0, Color.blue); chart.getXYPlot().setBackgroundPaint(Color.white); chart.getXYPlot().setRangeGridlinePaint(Color.gray); chart.getXYPlot().setDomainGridlinePaint(Color.gray); try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) { ChartUtilities.writeChartAsPNG(baos, chart, 320, 180); baos.flush(); this.equityChartByteArray = baos.toByteArray(); } catch (IOException e) { throw e; } }
From source file:org.noorganization.instalist.server.api.TaggedProductResource.java
/** * Get a list of tagged products./*from w ww . j av a 2 s . c o m*/ * @param _groupId The id of the group containing various tagged products. * @param _changedSince Limits the result to elements that changed since the given date. ISO * 8601 time e.g. 2016-01-19T11:54:07+0100. Optional. */ @GET @TokenSecured @Produces({ "application/json" }) public Response getTaggedProducts(@PathParam("groupid") int _groupId, @QueryParam("changedsince") String _changedSince) throws Exception { List<TaggedProduct> taggedProducts; List<DeletedObject> deletedTaggedProducts; EntityManager manager = DatabaseHelper.getInstance().getManager(); DeviceGroup group = manager.find(DeviceGroup.class, _groupId); if (_changedSince != null) { Instant changedSince; try { changedSince = ISO8601Utils.parse(_changedSince, new ParsePosition(0)).toInstant(); } catch (ParseException _e) { manager.close(); return ResponseFactory.generateBadRequest(CommonEntity.INVALID_CHANGEDATE); } TypedQuery<TaggedProduct> taggedProductQuery = manager.createQuery( "select tp from " + "TaggedProduct tp where tp.group = :group and tp.updated > :updated", TaggedProduct.class); taggedProductQuery.setParameter("group", group); taggedProductQuery.setParameter("updated", changedSince); taggedProducts = taggedProductQuery.getResultList(); TypedQuery<DeletedObject> deletedTaggedProductQuery = manager.createQuery( "select do " + "from DeletedObject do where do.group = :group and do.updated > :updated and " + "do.type = :type", DeletedObject.class); deletedTaggedProductQuery.setParameter("group", group); deletedTaggedProductQuery.setParameter("updated", changedSince); deletedTaggedProductQuery.setParameter("type", DeletedObject.Type.TAGGEDPRODUCT); deletedTaggedProducts = deletedTaggedProductQuery.getResultList(); } else { taggedProducts = new ArrayList<TaggedProduct>(group.getTaggedProducts()); TypedQuery<DeletedObject> deletedIngredientsQuery = manager.createQuery( "select do " + "from DeletedObject do where do.group = :group and do.type = :type", DeletedObject.class); deletedIngredientsQuery.setParameter("group", group); deletedIngredientsQuery.setParameter("type", DeletedObject.Type.TAGGEDPRODUCT); deletedTaggedProducts = deletedIngredientsQuery.getResultList(); } manager.close(); ArrayList<TaggedProductInfo> rtn = new ArrayList<TaggedProductInfo>( taggedProducts.size() + deletedTaggedProducts.size()); for (TaggedProduct current : taggedProducts) { TaggedProductInfo toAdd = new TaggedProductInfo().withDeleted(false); toAdd.setUUID(current.getUUID()); toAdd.setProductUUID(current.getProduct().getUUID()); toAdd.setTagUUID(current.getTag().getUUID()); toAdd.setLastChanged(Date.from(current.getUpdated())); rtn.add(toAdd); } for (DeletedObject current : deletedTaggedProducts) { TaggedProductInfo toAdd = new TaggedProductInfo(); toAdd.setUUID(current.getUUID()); toAdd.setLastChanged(Date.from(current.getUpdated())); toAdd.setDeleted(true); rtn.add(toAdd); } return ResponseFactory.generateOK(rtn); }
From source file:org.noorganization.instalist.server.api.ListResource.java
/** * Get a list of shopping-lists.//w ww . j a v a2 s.c o m * @param _groupId The id of the group, containing the lists. * @param _changedSince Requests only the elements that changed since the given date. ISO 8601 * time e.g. 2016-01-19T11:54:07+0100 */ @GET @TokenSecured @Produces({ "application/json" }) public Response getLists(@PathParam("groupid") int _groupId, @QueryParam("changedsince") String _changedSince) throws Exception { List<ShoppingList> foundLists; List<DeletedObject> foundDeleted; EntityManager manager = DatabaseHelper.getInstance().getManager(); DeviceGroup group = manager.find(DeviceGroup.class, _groupId); if (_changedSince != null) { Instant changedSince; try { changedSince = ISO8601Utils.parse(_changedSince, new ParsePosition(0)).toInstant(); } catch (ParseException _e) { manager.close(); return ResponseFactory.generateBadRequest(CommonEntity.INVALID_CHANGEDATE); } TypedQuery<ShoppingList> foundListsQuery = manager.createQuery( "select sl from " + "ShoppingList sl where sl.group = :group and sl.updated > :updated", ShoppingList.class); foundListsQuery.setParameter("group", group); foundListsQuery.setParameter("updated", changedSince); foundLists = foundListsQuery.getResultList(); TypedQuery<DeletedObject> foundDeletedListsQuery = manager .createQuery("select do from" + " DeletedObject do where do.group = :group and " + "do.updated > :updated and do.type = :type", DeletedObject.class); foundDeletedListsQuery.setParameter("group", group); foundDeletedListsQuery.setParameter("updated", changedSince); foundDeletedListsQuery.setParameter("type", DeletedObject.Type.LIST); foundDeleted = foundDeletedListsQuery.getResultList(); } else { TypedQuery<ShoppingList> foundListsQuery = manager .createQuery("select sl from " + "ShoppingList sl where sl.group = :group", ShoppingList.class); foundListsQuery.setParameter("group", group); foundLists = foundListsQuery.getResultList(); TypedQuery<DeletedObject> foundDeletedListsQuery = manager.createQuery( "select do " + "from DeletedObject do where do.group = :group and do.type = :type", DeletedObject.class); foundDeletedListsQuery.setParameter("group", group); foundDeletedListsQuery.setParameter("type", DeletedObject.Type.LIST); foundDeleted = foundDeletedListsQuery.getResultList(); } manager.close(); ArrayList<ListInfo> rtn = new ArrayList<ListInfo>(foundLists.size() + foundDeleted.size()); for (ShoppingList current : foundLists) { ListInfo toAdd = new ListInfo(); toAdd.setUUID(current.getUUID()); toAdd.setName(current.getName()); if (current.getCategory() != null) toAdd.setCategoryUUID(current.getCategory().getUUID()); toAdd.setLastChanged(Date.from(current.getUpdated())); toAdd.setDeleted(false); rtn.add(toAdd); } for (DeletedObject current : foundDeleted) { ListInfo toAdd = new ListInfo(); toAdd.setUUID(current.getUUID()); toAdd.setLastChanged(Date.from(current.getUpdated())); toAdd.setDeleted(true); rtn.add(toAdd); } return ResponseFactory.generateOK(rtn); }
From source file:com.seleniumtests.connectors.mails.ImapClient.java
/** * get list of all emails in folder//from w w w . j a v a2s. c o m * * @param folderName folder to read * @param firstMessageTime date from which we should get messages * @param firstMessageIndex index of the firste message to find * @throws MessagingException * @throws IOException */ @Override public List<Email> getEmails(String folderName, int firstMessageIndex, LocalDateTime firstMessageTime) throws MessagingException, IOException { if (folderName == null) { throw new MessagingException("folder ne doit pas tre vide"); } // Get folder Folder folder = store.getFolder(folderName); folder.open(Folder.READ_ONLY); // Get directory Message[] messages = folder.getMessages(); List<Message> preFilteredMessages = new ArrayList<>(); final LocalDateTime firstTime = firstMessageTime; // on filtre les message en fonction du mode de recherche if (searchMode == SearchMode.BY_INDEX || firstTime == null) { for (int i = firstMessageIndex, n = messages.length; i < n; i++) { preFilteredMessages.add(messages[i]); } } else { preFilteredMessages = Arrays.asList(folder.search(new SearchTerm() { private static final long serialVersionUID = 1L; @Override public boolean match(Message msg) { try { return !msg.getReceivedDate() .before(Date.from(firstTime.atZone(ZoneId.systemDefault()).toInstant())); } catch (MessagingException e) { return false; } } })); } List<Email> filteredEmails = new ArrayList<>(); lastMessageIndex = messages.length; for (Message message : preFilteredMessages) { String contentType = ""; try { contentType = message.getContentType(); } catch (MessagingException e) { MimeMessage msg = (MimeMessage) message; message = new MimeMessage(msg); contentType = message.getContentType(); } // decode content String messageContent = ""; List<String> attachments = new ArrayList<>(); if (contentType.toLowerCase().contains("text/html")) { messageContent += StringEscapeUtils.unescapeHtml4(message.getContent().toString()); } else if (contentType.toLowerCase().contains("multipart/")) { List<BodyPart> partList = getMessageParts((Multipart) message.getContent()); // store content in list for (BodyPart part : partList) { String partContentType = part.getContentType().toLowerCase(); if (partContentType.contains("text/html")) { messageContent = messageContent .concat(StringEscapeUtils.unescapeHtml4(part.getContent().toString())); } else if (partContentType.contains("text/") && !partContentType.contains("vcard")) { messageContent = messageContent.concat((String) part.getContent().toString()); } else if (partContentType.contains("image") || partContentType.contains("application/") || partContentType.contains("text/x-vcard")) { if (part.getFileName() != null) { attachments.add(part.getFileName()); } else { attachments.add(part.getDescription()); } } else { logger.debug("type: " + part.getContentType()); } } } // create a new email filteredEmails.add(new Email(message.getSubject(), messageContent, "", message.getReceivedDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime(), attachments)); } folder.close(false); return filteredEmails; }
From source file:org.noorganization.instalist.server.api.ProductResource.java
/** * Get a list of products.// ww w. j av a 2 s. c o m * @param _groupId The id of the group containing the products. * @param _changedSince Optional. Limits the request to the elements that changed since the * given date. ISO 8601 time e.g. "2016-01-19T11:54:07+0100". */ @GET @TokenSecured @Produces({ "application/json" }) public Response getProducts(@PathParam("groupid") int _groupId, @QueryParam("changedsince") String _changedSince) throws Exception { List<Product> foundProducts; List<DeletedObject> foundDeleted; EntityManager manager = DatabaseHelper.getInstance().getManager(); DeviceGroup group = manager.find(DeviceGroup.class, _groupId); if (_changedSince != null) { Instant changedSince; try { changedSince = ISO8601Utils.parse(_changedSince, new ParsePosition(0)).toInstant(); } catch (ParseException _e) { manager.close(); return ResponseFactory.generateBadRequest(CommonEntity.INVALID_CHANGEDATE); } TypedQuery<Product> foundProductsQuery = manager.createQuery( "select p from " + "Product p where p.group = :group and p.updated > :updated", Product.class); foundProductsQuery.setParameter("group", group); foundProductsQuery.setParameter("updated", changedSince); foundProducts = foundProductsQuery.getResultList(); TypedQuery<DeletedObject> foundDeletedListsQuery = manager.createQuery( "select do " + "from DeletedObject do where do.group = :group and do.updated > :updated and" + " do.type = :type", DeletedObject.class); foundDeletedListsQuery.setParameter("group", group); foundDeletedListsQuery.setParameter("updated", changedSince); foundDeletedListsQuery.setParameter("type", DeletedObject.Type.PRODUCT); foundDeleted = foundDeletedListsQuery.getResultList(); } else { TypedQuery<Product> foundProductsQuery = manager .createQuery("select p from " + "Product p where p.group = :group", Product.class); foundProductsQuery.setParameter("group", group); foundProducts = foundProductsQuery.getResultList(); TypedQuery<DeletedObject> foundDeletedProductsQuery = manager.createQuery( "select do " + "from DeletedObject do where do.group = :group and do.type = :type", DeletedObject.class); foundDeletedProductsQuery.setParameter("group", group); foundDeletedProductsQuery.setParameter("type", DeletedObject.Type.PRODUCT); foundDeleted = foundDeletedProductsQuery.getResultList(); } manager.close(); ArrayList<ProductInfo> rtn = new ArrayList<ProductInfo>(foundProducts.size() + foundDeleted.size()); for (Product current : foundProducts) { ProductInfo toAdd = new ProductInfo(); toAdd.setUUID(current.getUUID()); toAdd.setName(current.getName()); toAdd.setDefaultAmount(current.getDefaultAmount()); toAdd.setStepAmount(current.getStepAmount()); if (current.getUnit() != null) toAdd.setUnitUUID(current.getUnit().getUUID()); toAdd.setLastChanged(Date.from(current.getUpdated())); toAdd.setDeleted(false); rtn.add(toAdd); } for (DeletedObject current : foundDeleted) { ProductInfo toAdd = new ProductInfo(); toAdd.setUUID(current.getUUID()); toAdd.setLastChanged(Date.from(current.getUpdated())); toAdd.setDeleted(true); rtn.add(toAdd); } return ResponseFactory.generateOK(rtn); }
From source file:org.wallride.service.PostService.java
@Transactional(propagation = Propagation.NOT_SUPPORTED) public void updatePostViews() { LocalDateTime now = LocalDateTime.now(); Set<JobExecution> jobExecutions = jobExplorer.findRunningJobExecutions("updatePostViewsJob"); for (JobExecution jobExecution : jobExecutions) { LocalDateTime startTime = LocalDateTime.ofInstant(jobExecution.getStartTime().toInstant(), ZoneId.systemDefault()); Duration d = Duration.between(now, startTime); if (Math.abs(d.toMinutes()) == 0) { logger.info("Skip processing because the job is running."); return; }/*from w w w . j a va 2s. co m*/ } JobParameters params = new JobParametersBuilder() .addDate("now", Date.from(now.atZone(ZoneId.systemDefault()).toInstant())).toJobParameters(); try { jobLauncher.run(updatePostViewsJob, params); } catch (Exception e) { throw new ServiceException(e); } }
From source file:org.noorganization.instalist.server.api.CategoriesResource.java
/** * Get a list of categories.//from w w w . j a va 2 s . c om * * @param _groupId The id of the group. * @param _changedSince Optional. Requests only the elements that changed since the given date. * ISO 8601 time e.g. 2016-01-19T11:54:07+01:00 */ @GET @TokenSecured @Produces({ "application/json" }) public Response getCategories(@PathParam("groupid") int _groupId, @QueryParam("changedsince") String _changedSince) throws Exception { try { Instant changedSince = null; if (_changedSince != null) { try { changedSince = ISO8601Utils.parse(_changedSince, new ParsePosition(0)).toInstant(); } catch (ParseException _e) { return ResponseFactory.generateBadRequest(CommonEntity.INVALID_DATA); } } List<Category> categories; List<DeletedObject> deletedCategories; EntityManager manager = DatabaseHelper.getInstance().getManager(); DeviceGroup group = manager.find(DeviceGroup.class, _groupId); if (changedSince != null) { TypedQuery<Category> categoriesQuery = manager.createQuery( "select c from Category c " + "where c.group = :groupid and c.updated > :updated", Category.class); categoriesQuery.setParameter("groupid", group); categoriesQuery.setParameter("updated", changedSince); categories = categoriesQuery.getResultList(); TypedQuery<DeletedObject> deletedCategoriesQuery = manager .createQuery("select do " + "from DeletedObject do where do.group = :groupid and " + "do.type = :type and do.updated > :updated", DeletedObject.class); deletedCategoriesQuery.setParameter("groupid", group); deletedCategoriesQuery.setParameter("updated", changedSince); deletedCategoriesQuery.setParameter("type", DeletedObject.Type.CATEGORY); deletedCategories = deletedCategoriesQuery.getResultList(); } else { TypedQuery<Category> categoriesQuery = manager .createQuery("select c from Category c " + "where c.group = :groupid", Category.class); categoriesQuery.setParameter("groupid", group); categories = categoriesQuery.getResultList(); TypedQuery<DeletedObject> deletedCategoriesQuery = manager.createQuery( "select do " + "from DeletedObject do where do.group = :groupid and " + "do.type = :type", DeletedObject.class); deletedCategoriesQuery.setParameter("groupid", group); deletedCategoriesQuery.setParameter("type", DeletedObject.Type.CATEGORY); deletedCategories = deletedCategoriesQuery.getResultList(); } manager.close(); List<CategoryInfo> rtnPayload = new ArrayList<CategoryInfo>( categories.size() + deletedCategories.size()); for (Category currentCat : categories) { CategoryInfo info = new CategoryInfo(); info.setUUID(currentCat.getUUID()); info.setName(currentCat.getName()); info.setLastChanged(Date.from(currentCat.getUpdated())); info.setDeleted(false); rtnPayload.add(info); } for (DeletedObject currentCat : deletedCategories) { CategoryInfo info = new CategoryInfo(); info.setUUID(currentCat.getUUID()); info.setLastChanged(Date.from(currentCat.getUpdated())); info.setDeleted(true); rtnPayload.add(info); } return ResponseFactory.generateOK(rtnPayload); } catch (Exception _e) { _e.printStackTrace(); throw _e; } }
From source file:com.onyxscheduler.OnyxSchedulerIT.java
private Date toDate(LocalDateTime localDateTime) { return Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant()); }