List of usage examples for java.util Date from
public static Date from(Instant instant)
From source file:org.noorganization.instalist.server.api.IngredientResourceTest.java
@Test public void testGetIngredients() throws Exception { String url = "/groups/%d/ingredients"; 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()); IngredientInfo[] allIngredientInfo = okResponse1.readEntity(IngredientInfo[].class); assertEquals(2, allIngredientInfo.length); for (IngredientInfo current : allIngredientInfo) { if (mIngredient.getUUID().equals(UUID.fromString(current.getUUID()))) { assertEquals(mIngredient.getUpdated(), current.getLastChanged().toInstant()); assertEquals(mRecipe.getUUID(), UUID.fromString(current.getRecipeUUID())); assertEquals(mProduct.getUUID(), UUID.fromString(current.getProductUUID())); assertEquals(1f, current.getAmount(), 0.001f); assertFalse(current.getDeleted()); } else if (mDeletedIngredient.getUUID().equals(UUID.fromString(current.getUUID()))) { assertNull(current.getRecipeUUID()); assertNull(current.getProductUUID()); assertNull(current.getAmount()); assertEquals(mDeletedIngredient.getUpdated(), current.getLastChanged().toInstant()); assertTrue(current.getDeleted()); } else/*from w w w. j av a2s . com*/ fail("Unexpected Entry."); } mManager.getTransaction().begin(); mIngredient.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()); IngredientInfo[] oneIngredientInfo = okResponse2.readEntity(IngredientInfo[].class); assertEquals(1, oneIngredientInfo.length); assertEquals(mIngredient.getUUID(), UUID.fromString(oneIngredientInfo[0].getUUID())); assertFalse(oneIngredientInfo[0].getDeleted()); }
From source file:org.noorganization.instalist.server.api.ListResource.java
/** * Get a single list./* w w w.j a va2s .c o m*/ * @param _groupId The id of the group, containing the list. * */ @GET @TokenSecured @Path("{listuuid}") @Produces({ "application/json" }) public Response getList(@PathParam("groupid") int _groupId, @PathParam("listuuid") String _listUUID) throws Exception { UUID listUUID; try { listUUID = UUID.fromString(_listUUID); } catch (IllegalArgumentException _e) { return ResponseFactory.generateBadRequest(CommonEntity.INVALID_UUID); } EntityManager manager = DatabaseHelper.getInstance().getManager(); DeviceGroup group = manager.find(DeviceGroup.class, _groupId); IListController listController = ControllerFactory.getListController(manager); ShoppingList foundList = listController.findByGroupAndUUID(group, listUUID); if (foundList == null) { if (listController.findDeletedByGroupAndUUID(group, listUUID) == null) { manager.close(); return ResponseFactory .generateNotFound(new Error().withMessage("The requested " + "list was not found.")); } manager.close(); return ResponseFactory.generateGone(new Error().withMessage("The requested list was " + "deleted.")); } ListInfo rtn = new ListInfo(); rtn.setUUID(foundList.getUUID()); rtn.setName(foundList.getName()); if (foundList.getCategory() != null) rtn.setCategoryUUID(foundList.getCategory().getUUID()); rtn.setLastChanged(Date.from(foundList.getUpdated())); rtn.setDeleted(false); return ResponseFactory.generateOK(rtn); }
From source file:co.com.soinsoftware.hotelero.view.JFRoomPayment.java
private Date getFinalDate(final Date initialDate, final int hour) { final LocalDate today = LocalDate.now(); LocalDateTime finalDateTime = null; if (DateUtils.isSameDay(initialDate, new Date())) { finalDateTime = today.plusDays(1).atTime(LocalTime.of(hour, 0)); } else {/* w w w . j av a 2s . c om*/ finalDateTime = today.atTime(LocalTime.of(hour, 0)); } final ZonedDateTime zdt = finalDateTime.atZone(ZoneId.systemDefault()); return Date.from(zdt.toInstant()); }
From source file:org.noorganization.instalist.server.api.EntryResource.java
/** * Returns a single list-entry.// w w w. j a v a 2 s . c o m * @param _groupId The id of the group containing the entry. * @param _entryUUID The uuid of the entry itself. */ @GET @TokenSecured @Path("{entryuuid}") @Produces({ "application/json" }) public Response getEntry(@PathParam("groupid") int _groupId, @PathParam("entryuuid") String _entryUUID) throws Exception { UUID toFind; try { toFind = UUID.fromString(_entryUUID); } catch (IllegalArgumentException _e) { return ResponseFactory.generateBadRequest(CommonEntity.INVALID_UUID); } EntityManager manager = DatabaseHelper.getInstance().getManager(); DeviceGroup group = manager.find(DeviceGroup.class, _groupId); IEntryController entryController = ControllerFactory.getEntryController(manager); ListEntry foundEntry = entryController.findByGroupAndUUID(group, toFind); if (foundEntry == null) { if (entryController.findDeletedByGroupAndUUID(group, toFind) != null) { manager.close(); return ResponseFactory .generateGone(new Error().withMessage("The requested " + "listentry has been deleted.")); } manager.close(); return ResponseFactory .generateNotFound(new Error().withMessage("The requested " + "listentry was not found.")); } manager.close(); EntryInfo rtn = new EntryInfo().withDeleted(false); rtn.setUUID(foundEntry.getUUID()); rtn.setProductUUID(foundEntry.getProduct().getUUID()); rtn.setListUUID(foundEntry.getList().getUUID()); rtn.setAmount(foundEntry.getAmount()); rtn.setPriority(foundEntry.getPriority()); rtn.setStruck(foundEntry.getStruck()); rtn.setLastChanged(Date.from(foundEntry.getUpdated())); return ResponseFactory.generateOK(rtn); }
From source file:org.noorganization.instalist.server.api.EntryResourceTest.java
@Test public void testGetEntries() throws Exception { String url = "/groups/%d/listentries"; 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()); EntryInfo[] allEntryInfo = okResponse1.readEntity(EntryInfo[].class); assertEquals(2, allEntryInfo.length); for (EntryInfo current : allEntryInfo) { if (mEntry.getUUID().equals(UUID.fromString(current.getUUID()))) { assertEquals(mEntry.getUpdated(), current.getLastChanged().toInstant()); assertEquals(mList.getUUID(), UUID.fromString(current.getListUUID())); assertEquals(mProduct.getUUID(), UUID.fromString(current.getProductUUID())); assertEquals(1f, current.getAmount(), 0.001f); assertEquals(2, (int) current.getPriority()); assertFalse(current.getStruck()); assertFalse(current.getDeleted()); } else if (mDeletedEntry.getUUID().equals(UUID.fromString(current.getUUID()))) { assertNull(current.getListUUID()); assertNull(current.getProductUUID()); assertNull(current.getAmount()); assertNull(current.getPriority()); assertNull(current.getStruck()); assertEquals(mDeletedEntry.getUpdated(), current.getLastChanged().toInstant()); assertTrue(current.getDeleted()); } else/*ww w . java 2s .com*/ fail("Unexpected Entry."); } mManager.getTransaction().begin(); mEntry.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()); EntryInfo[] oneEntryInfo = okResponse2.readEntity(EntryInfo[].class); assertEquals(1, oneEntryInfo.length); assertEquals(mEntry.getUUID(), UUID.fromString(oneEntryInfo[0].getUUID())); assertFalse(oneEntryInfo[0].getDeleted()); }
From source file:org.noorganization.instalist.server.api.IngredientResource.java
/** * Returns a single ingredient.//from w w w. j a v a 2 s . c om * @param _groupId The id of the group containing the ingredient. * @param _entryUUID The uuid of the ingredient itself. */ @GET @TokenSecured @Path("{entryuuid}") @Produces({ "application/json" }) public Response getIngredient(@PathParam("groupid") int _groupId, @PathParam("entryuuid") String _entryUUID) throws Exception { UUID toFind; try { toFind = UUID.fromString(_entryUUID); } catch (IllegalArgumentException _e) { return ResponseFactory.generateBadRequest(CommonEntity.INVALID_UUID); } EntityManager manager = DatabaseHelper.getInstance().getManager(); DeviceGroup group = manager.find(DeviceGroup.class, _groupId); IIngredientController ingredientController = ControllerFactory.getIngredientController(manager); Ingredient foundIngredient = ingredientController.findByGroupAndUUID(group, toFind); if (foundIngredient == null) { if (ingredientController.findDeletedByGroupAndUUID(group, toFind) != null) { manager.close(); return ResponseFactory .generateGone(new Error().withMessage("The requested " + "ingredient has been deleted.")); } manager.close(); return ResponseFactory .generateNotFound(new Error().withMessage("The requested " + "ingredient was not found.")); } manager.close(); IngredientInfo rtn = new IngredientInfo().withDeleted(false); rtn.setUUID(foundIngredient.getUUID()); rtn.setProductUUID(foundIngredient.getProduct().getUUID()); rtn.setRecipeUUID(foundIngredient.getRecipe().getUUID()); rtn.setAmount(foundIngredient.getAmount()); rtn.setLastChanged(Date.from(foundIngredient.getUpdated())); return ResponseFactory.generateOK(rtn); }
From source file:org.noorganization.instalist.server.api.TaggedProductResource.java
/** * Returns a single ingredient.// ww w .ja va2 s . c om * @param _groupId The id of the group containing the tagged product. * @param _taggedProductUUID The uuid of the tagged product itself. */ @GET @TokenSecured @Path("{tpuuid}") @Produces({ "application/json" }) public Response getTaggedProduct(@PathParam("groupid") int _groupId, @PathParam("tpuuid") String _taggedProductUUID) throws Exception { UUID toFind; try { toFind = UUID.fromString(_taggedProductUUID); } catch (IllegalArgumentException _e) { return ResponseFactory.generateBadRequest(CommonEntity.INVALID_UUID); } EntityManager manager = DatabaseHelper.getInstance().getManager(); DeviceGroup group = manager.find(DeviceGroup.class, _groupId); ITaggedProductController taggedProductController = ControllerFactory.getTaggedProductController(manager); TaggedProduct foundTaggedProduct = taggedProductController.findByGroupAndUUID(group, toFind); if (foundTaggedProduct == null) { if (taggedProductController.findDeletedByGroupAndUUID(group, toFind) != null) { manager.close(); return ResponseFactory.generateGone( new Error().withMessage("The requested " + "tagged product has been deleted.")); } manager.close(); return ResponseFactory .generateNotFound(new Error().withMessage("The requested " + "tagged product was not found.")); } manager.close(); TaggedProductInfo rtn = new TaggedProductInfo().withDeleted(false); rtn.setUUID(foundTaggedProduct.getUUID()); rtn.setProductUUID(foundTaggedProduct.getProduct().getUUID()); rtn.setTagUUID(foundTaggedProduct.getTag().getUUID()); rtn.setLastChanged(Date.from(foundTaggedProduct.getUpdated())); return ResponseFactory.generateOK(rtn); }
From source file:org.noorganization.instalist.server.api.ProductResourceTest.java
@Test public void testGetProducts() throws Exception { String url = "/groups/%d/products"; 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()); ProductInfo[] allProductInfo = okResponse1.readEntity(ProductInfo[].class); assertEquals(3, allProductInfo.length); for (ProductInfo current : allProductInfo) { if (mProduct.getUUID().equals(UUID.fromString(current.getUUID()))) { assertEquals("product1", current.getName()); assertEquals(mProduct.getUpdated(), current.getLastChanged().toInstant()); assertNull(current.getRemoveUnit()); assertNull(current.getUnitUUID()); assertEquals(1f, current.getDefaultAmount(), 0.001f); assertEquals(0.5f, current.getStepAmount(), 0.001f); assertFalse(current.getDeleted()); } else if (mProductWU.getUUID().equals(UUID.fromString(current.getUUID()))) { assertEquals("product2", current.getName()); assertEquals(mProductWU.getUpdated(), current.getLastChanged().toInstant()); assertNull(current.getRemoveUnit()); assertEquals(mUnit.getUUID(), UUID.fromString(current.getUnitUUID())); assertEquals(2f, current.getDefaultAmount(), 0.001f); assertEquals(2f, current.getStepAmount(), 0.001f); assertFalse(current.getDeleted()); } else if (mDeletedProduct.getUUID().equals(UUID.fromString(current.getUUID()))) { assertNull(current.getName()); assertNull(current.getRemoveUnit()); assertNull(current.getUnitUUID()); assertNull(current.getDefaultAmount()); assertNull(current.getStepAmount()); assertEquals(mDeletedProduct.getUpdated(), current.getLastChanged().toInstant()); assertTrue(current.getDeleted()); } else//from ww w .j a v a2 s.co m fail("Unexpected unit."); } mManager.getTransaction().begin(); mProduct.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()); ProductInfo[] oneProductInfo = okResponse2.readEntity(ProductInfo[].class); assertEquals(1, oneProductInfo.length); assertEquals(mProduct.getUUID(), UUID.fromString(oneProductInfo[0].getUUID())); assertEquals("product1", oneProductInfo[0].getName()); assertFalse(oneProductInfo[0].getDeleted()); }
From source file:org.openecomp.sdc.action.impl.ActionManagerImpl.java
/** * Get Current Timestamp in UTC format.//from ww w . ja va 2 s. c om * * @return Current Timestamp in UTC format. */ public static Date getCurrentTimeStampUtc() { return Date.from(java.time.ZonedDateTime.now(ZoneOffset.UTC).toInstant()); }
From source file:org.sakaiproject.sitestats.impl.event.detailed.DetailedEventsManagerImpl.java
private Optional<Criteria> basicCriteriaForTrackingParams(Session session, final TrackingParams params) { Criteria crit = session.createCriteria(DetailedEventImpl.class); if (StringUtils.isNotBlank(params.siteId)) { crit.add(Restrictions.eq(SITE_ID_COL, params.siteId)); }/* w w w. jav a 2 s . com*/ if (!params.events.isEmpty()) { crit.add(Restrictions.in(EVENT_ID_COL, params.events)); } // Filter out any users who do not have the can be tracked permission in the site List<String> filtered = params.userIds.stream().filter(u -> statsAuthz.canUserBeTracked(params.siteId, u)) .collect(Collectors.toList()); // must have at least one user if (filtered.isEmpty()) { return Optional.empty(); } crit.add(Restrictions.in(USER_ID_COL, filtered)); if (!TrackingParams.NO_DATE.equals(params.startDate)) { crit.add(Restrictions.ge(EVENT_DATE_COL, Date.from(params.startDate))); } if (!TrackingParams.NO_DATE.equals(params.endDate)) { crit.add(Restrictions.lt(EVENT_DATE_COL, Date.from(params.endDate))); } // filter out anonymous events Set<String> anonEvents = regServ.getAnonymousEventIds(); if (!anonEvents.isEmpty()) { crit.add(Restrictions.not(Restrictions.in(EVENT_ID_COL, anonEvents))); } return Optional.of(crit); }