List of usage examples for java.time Instant isAfter
public boolean isAfter(Instant otherInstant)
From source file:Main.java
public static void main(String[] args) { Instant instant = Instant.parse("2014-12-03T10:15:30.00Z"); System.out.println(instant.isAfter(Instant.now())); }
From source file:com.seleniumtests.uipage.htmlelements.GenericPictureElement.java
/** * Check if picture is visible. This is only available for desktop tests * @param waitMs/*w ww . jav a 2s. c o m*/ * @return */ public boolean isElementPresent(int waitMs) { Instant end = clock.instant().plusMillis(waitMs); while (end.isAfter(clock.instant()) || waitMs == 0) { try { findElement(); return true; } catch (ImageSearchException e) { if (waitMs == 0) { return false; } WaitHelper.waitForMilliSeconds(200); continue; } } return false; }
From source file:se.crisp.codekvast.agent.daemon.worker.DaemonWorker.java
private void exportDataIfNeeded() { Instant lastCollectorDataProcessedAt = collectorDataProcessor.getLastCollectorDataProcessedAt(); log.debug("lastCollectorDataProcessedAt={}, exportedAt={}", lastCollectorDataProcessedAt, exportedAt); if (lastCollectorDataProcessedAt.isAfter(exportedAt)) { doExportData();/*from w w w. j a v a 2 s. c o m*/ exportedAt = now(); } }
From source file:org.noorganization.instalist.server.api.ListResource.java
/** * Creates a list in the group.//from www. ja va 2 s . com * @param _groupId The id of the group containing the list. * @param _listInfo Information for changing the list. Not all information needs to be set. */ @POST @TokenSecured @Consumes("application/json") @Produces({ "application/json" }) public Response postList(@PathParam("groupid") int _groupId, ListInfo _listInfo) throws Exception { if ((_listInfo.getDeleted() != null && _listInfo.getDeleted()) || _listInfo.getName() == null || _listInfo.getName().length() == 0 || _listInfo.getUUID() == null) return ResponseFactory.generateBadRequest(CommonEntity.INVALID_DATA); UUID listUUID; UUID categoryUUID = null; try { listUUID = UUID.fromString(_listInfo.getUUID()); if (_listInfo.getCategoryUUID() != null) categoryUUID = UUID.fromString(_listInfo.getCategoryUUID()); } catch (IllegalArgumentException _e) { return ResponseFactory.generateBadRequest(CommonEntity.INVALID_UUID); } Instant created; if (_listInfo.getLastChanged() != null) { created = _listInfo.getLastChanged().toInstant(); if (created.isAfter(Instant.now())) return ResponseFactory.generateBadRequest(CommonEntity.INVALID_CHANGEDATE); } else created = Instant.now(); EntityManager manager = DatabaseHelper.getInstance().getManager(); IListController listController = ControllerFactory.getListController(manager); try { listController.add(_groupId, listUUID, _listInfo.getName(), categoryUUID, created); } catch (ConflictException _e) { return ResponseFactory .generateConflict(new Error().withMessage("A list with this " + "uuid already exists.")); } finally { manager.close(); } return ResponseFactory.generateCreated(null); }
From source file:org.noorganization.instalist.server.api.CategoriesResource.java
/** * Creates the category./*from ww w . java 2 s . c o m*/ * @param _groupId The group to add the category to. * @param _entity Information for the new category. * e.g. examples/category.example */ @POST @TokenSecured @Consumes("application/json") @Produces({ "application/json" }) public Response postCategory(@PathParam("groupid") int _groupId, CategoryInfo _entity) throws Exception { if (_entity.getUUID() == null || _entity.getName() == null || _entity.getName().length() == 0 || (_entity.getDeleted() != null && _entity.getDeleted())) return ResponseFactory.generateBadRequest(CommonEntity.INVALID_DATA); Instant lastChanged; if (_entity.getLastChanged() != null) { lastChanged = _entity.getLastChanged().toInstant(); if (lastChanged.isAfter(Instant.now())) return ResponseFactory.generateBadRequest(CommonEntity.INVALID_CHANGEDATE); } else lastChanged = Instant.now(); UUID newCatUUID; try { newCatUUID = UUID.fromString(_entity.getUUID()); } catch (IllegalArgumentException e) { return ResponseFactory.generateBadRequest(CommonEntity.INVALID_UUID); } EntityManager manager = DatabaseHelper.getInstance().getManager(); ICategoryController categoryController = ControllerFactory.getCategoryController(manager); try { categoryController.add(_groupId, newCatUUID, _entity.getName(), lastChanged); } catch (ConflictException _e) { return ResponseFactory.generateConflict( new Error().withMessage("The new category " + "stands in conflict with existing one.")); } finally { manager.close(); } return ResponseFactory.generateCreated(null); }
From source file:org.noorganization.instalist.server.api.CategoriesResource.java
/** * Updates the category./*from w w w. ja v a2 s . c o m*/ * @param _uuid The uuid of the category to update. * @param _entity A category with updated information. */ @PUT @TokenSecured @Path("{categoryuuid}") @Consumes("application/json") @Produces({ "application/json" }) public Response putCategory(@PathParam("groupid") int _groupId, @PathParam("categoryuuid") String _uuid, CategoryInfo _entity) throws Exception { if (_entity.getName() == null) return ResponseFactory.generateBadRequest(CommonEntity.NO_DATA_RECVD); if ((_entity.getUUID() != null && !_entity.getUUID().equals(_uuid)) || (_entity.getDeleted() != null && _entity.getDeleted())) return ResponseFactory.generateBadRequest(CommonEntity.INVALID_DATA); Instant changedDate = Instant.now(); if (_entity.getLastChanged() != null) { changedDate = _entity.getLastChanged().toInstant(); if (changedDate.isAfter(Instant.now())) return ResponseFactory.generateBadRequest(CommonEntity.INVALID_CHANGEDATE); } UUID categoryUUID; try { categoryUUID = UUID.fromString(_uuid); } catch (IllegalArgumentException e) { return ResponseFactory.generateBadRequest(CommonEntity.INVALID_UUID); } EntityManager manager = DatabaseHelper.getInstance().getManager(); ICategoryController categoryController = ControllerFactory.getCategoryController(manager); try { categoryController.update(_groupId, categoryUUID, _entity.getName(), changedDate); } catch (NotFoundException e) { return ResponseFactory.generateNotFound(new Error().withMessage("Category was not " + "found.")); } catch (GoneException e) { return ResponseFactory.generateGone(new Error().withMessage("Category was already " + "deleted.")); } catch (ConflictException e) { return ResponseFactory .generateConflict(new Error().withMessage("Sent sategory is in " + "conflict with saved one.")); } finally { manager.close(); } return ResponseFactory.generateOK(null); }
From source file:com.coinblesk.server.controller.AdminController.java
@RequestMapping(value = "/keys", method = GET) @ResponseBody/*from w w w .j a v a 2s . com*/ public List<KeysDTO> getAllKeys() { NetworkParameters params = appConfig.getNetworkParameters(); // Pre-calculate balances for each address Map<Address, Coin> balances = walletService.getBalanceByAddresses(); List<Keys> keys = keyService.allKeys(); // ...and summed for each public key Map<Keys, Long> balancesPerKeys = keys.stream() .collect(Collectors.toMap(Function.identity(), key -> key.timeLockedAddresses().stream() .map(tla -> tla.toAddress(params)).map(balances::get).mapToLong(Coin::longValue).sum())); // Map the Keys entities to DTOs including the containing TimeLockedAddresses return keys.stream().map(key -> new KeysDTO(SerializeUtils.bytesToHex(key.clientPublicKey()), SerializeUtils.bytesToHex(key.serverPublicKey()), SerializeUtils.bytesToHex(key.serverPrivateKey()), Date.from(Instant.ofEpochSecond(key.timeCreated())), key.virtualBalance(), balancesPerKeys.get(key), key.virtualBalance() + balancesPerKeys.get(key), key.timeLockedAddresses().stream().map(tla -> { Instant createdAt = Instant.ofEpochSecond(tla.getTimeCreated()); Instant lockedUntil = Instant.ofEpochSecond(tla.getLockTime()); Coin balance = balances.get(tla.toAddress(params)); return new TimeLockedAddressDTO(tla.toAddress(params).toString(), "http://" + (params.getClass().equals(TestNet3Params.class) ? "tbtc." : "") + "blockr.io/address/info/" + tla.toAddress(params), Date.from(createdAt), Date.from(lockedUntil), lockedUntil.isAfter(Instant.now()), balance.longValue()); }).collect(Collectors.toList()))).collect(Collectors.toList()); }
From source file:com.seleniumtests.uipage.PageObject.java
public Alert waitForAlert(int waitInSeconds) { Instant end = systemClock.instant().plusSeconds(waitInSeconds); while (end.isAfter(systemClock.instant())) { try {/*from w w w . j av a 2 s .c o m*/ return driver.switchTo().alert(); } catch (NoAlertPresentException e) { WaitHelper.waitForSeconds(1); } } return null; }
From source file:com.seleniumtests.uipage.PageObject.java
/** * Selects the first unknown window. To use we an action creates a new window or tab * @param waitMs wait for N milliseconds before raising error * @return/* w w w .ja va2 s. co m*/ */ public final String selectNewWindow(int waitMs) { // app test are not compatible with window if (SeleniumTestsContextManager.getThreadContext().getTestType().family() == TestType.APP) { throw new ScenarioException("Application are not compatible with Windows"); } // Keep the name of the current window handle before switching // sometimes, our action made window disappear String mainWindowHandle; try { mainWindowHandle = driver.getWindowHandle(); } catch (Exception e) { mainWindowHandle = ""; } logger.debug("Current handle: " + mainWindowHandle); // wait for window to be displayed Instant end = systemClock.instant().plusMillis(waitMs + 250L); Set<String> handles = new TreeSet<>(); boolean found = false; while (end.isAfter(systemClock.instant()) && !found) { handles = driver.getWindowHandles(); logger.debug("All handles: " + handles.toString()); for (String handle : handles) { // we already know this handle if (getCurrentHandles().contains(handle)) { continue; } selectWindow(handle); // wait for a valid address String address = ""; Instant endLoad = systemClock.instant().plusMillis(5000); while (address.isEmpty() && endLoad.isAfter(systemClock.instant())) { address = driver.getCurrentUrl(); } // make window display in foreground // TODO: reactivate feature try { // Point windowPosition = driver.manage().window().getPosition(); // org.openqa.selenium.interactions.Mouse mouse = ((HasInputDevices) driver).getMouse(); // mouse.click(); // Mouse mouse = new DesktopMouse(); // mouse.click(new DesktopScreenRegion(Math.max(0, windowPosition.x) + driver.manage().window().getSize().width / 2, Math.max(0, windowPosition.y) + 5, 2, 2).getCenter()); } catch (Exception e) { logger.warn("error while giving focus to window"); } found = true; break; } WaitHelper.waitForMilliSeconds(300); } // check window has changed if (waitMs > 0 && mainWindowHandle.equals(driver.getWindowHandle())) { throw new CustomSeleniumTestsException("new window has not been found. Handles: " + handles); } return mainWindowHandle; }