List of usage examples for java.time Instant now
public static Instant now()
From source file:com.vmware.photon.controller.api.client.resource.ProjectRestApiTest.java
@Test public void testCreatePersistentDisk() throws IOException { Task responseTask = new Task(); responseTask.setId("12345"); responseTask.setState("QUEUED"); responseTask.setQueuedTime(Date.from(Instant.now())); ObjectMapper mapper = new ObjectMapper(); String serializedTask = mapper.writeValueAsString(responseTask); setupMocks(serializedTask, HttpStatus.SC_CREATED); ProjectApi projectApi = new ProjectRestApi(restClient); Task task = projectApi.createDisk("foo", new DiskCreateSpec()); assertEquals(task, responseTask);//www.j a v a 2 s . c o m }
From source file:com.amazonaws.sample.entitlement.services.EntitlementService.java
/** * Return new UserSession//w w w. j a v a 2 s . co m * @param user the user the current request is for * @param userSubscription the current request is for * @throws ApplicationBadStateException if the application the current request is for is in an error state * @return prettified string of JSON */ public String startUserSession(String userSubscription, Item user) throws UserNotEntitledException, ApplicationBadStateException, MaxSessionsLimitExceededException { try { Session session; Application application; Item retrievedSubscription; try { // user input subscription Item inputSubscription = Item.fromJSON(userSubscription); // substitute verified user id into query retrievedSubscription = entitlementServiceUserSubscriptionTable .getItem(new GetItemSpec().withPrimaryKey("UserId", user.getString("id"), "CreationTimeMilli", inputSubscription.getLong("CreationTimeMilli"))); if (retrievedSubscription.getLong("TotalCombinedSessionTimeLimitMilli") < 0) { throw new UserNotEntitledException("You do not have remaining time for this subscription."); } } catch (Error e) { log.error("Couldn't retrieve subscription provided. Error: " + e); throw new UserNotEntitledException( "You are not currently allowed to use this application. Please ask for access."); } try { application = getApplication(retrievedSubscription.getString("AppStreamApplicationId")); session = entitleSessionV2(application); } catch (ApplicationNotFoundException e) { log.error(e); throw new ApplicationBadStateException("Could not connect subscription to AppStream Application"); } catch (MaxSessionsLimitExceededException e) { log.error(e); throw e; } // save session Item userSession = new Item() .withPrimaryKey("UserId", user.getString("id"), "CreationTimeMilli", Instant.now().toEpochMilli()) .withLong("UserSubscriptionCreationTimeMilli", retrievedSubscription.getLong("CreationTimeMilli")) .withString("Email", user.getString("email")) .withString("UserApplicationId", retrievedSubscription.getString("UserApplicationId")) .withString("AppStreamSessionId", session.getId()) .withString("AppStreamApplicationId", retrievedSubscription.getString("AppStreamApplicationId")) .withString("UserApplicationName", retrievedSubscription.getString("UserApplicationName")) .withString("UserApplicationDescription", retrievedSubscription.getString("UserApplicationDescription")) .withLong("PerSessionTimeLimitMilli", retrievedSubscription.getLong("PerSessionTimeLimitMilli")) .withString("AppStreamEntitlementUrl", session.getEntitlementUrl()) .withLong("AppStreamEntitlementUrlValidTimeMilli", 350000); entitlementServiceUserSessionTable.putItem(userSession).getItem(); // send back session return userSession.toJSONPretty(); } catch (AmazonServiceException e) { if (e.getErrorType().equals(AmazonServiceException.ErrorType.Service)) { log.error("An error occurred while getting data from DynamoDB: " + e); } throw e; } }
From source file:hspc.submissionsprogram.AppDisplay.java
private void updateCList(boolean forced) { Instant now = Instant.now(); boolean query = false; if (!forced)/*from w ww. j a va 2 s .com*/ query = true; if (forced) { if ((now.getEpochSecond() - old.getEpochSecond()) > 10) { query = true; old = now; } } if (query) { Connection conn = null; PreparedStatement stmt = null; try { Class.forName(JDBC_DRIVER); conn = DriverManager.getConnection(Main.Configuration.get("jdbc_mysql_address"), Main.Configuration.get("mysql_user"), Main.Configuration.get("mysql_pass")); String sql = "SELECT * FROM clarifications WHERE response IS NOT NULL"; stmt = conn.prepareStatement(sql); ResultSet rs = stmt.executeQuery(); ArrayList<String> clarifications = new ArrayList<>(); clarificationDatas.clear(); StringBuilder builder = new StringBuilder(); while (rs.next()) { builder.setLength(0); builder.append(rs.getInt("id")).append(". ").append(rs.getString("problem")).append(" - ") .append(rs.getString("text")); clarifications.add(builder.toString()); clarificationDatas.add(new ClarificationData(rs.getInt("id"), rs.getString("problem"), rs.getString("text"), rs.getString("response"))); int rsId = Integer.parseInt(rs.getString("id")); if (rsId > lastId) { lastId = rsId; displayClarification(rs); } } int selected = cList.getSelectedIndex(); String[] listOfItems = new String[clarifications.size()]; for (int i = 0; i < clarifications.size(); i++) { listOfItems[i] = clarifications.get(i); } cList.setListData(listOfItems); cList.setSelectedIndex(selected); stmt.close(); conn.close(); } catch (Exception ex) { ex.printStackTrace(); } finally { try { if (stmt != null) { stmt.close(); } } catch (Exception ex2) { ex2.printStackTrace(); } try { if (conn != null) { conn.close(); } } catch (Exception ex2) { ex2.printStackTrace(); } } } }
From source file:com.vmware.photon.controller.api.client.resource.VmApiTest.java
@Test public void testAddTagToVmAsync() throws IOException, InterruptedException { final Task responseTask = new Task(); responseTask.setId("12345"); responseTask.setState("QUEUED"); responseTask.setQueuedTime(Date.from(Instant.now())); ObjectMapper mapper = new ObjectMapper(); String serializedTask = mapper.writeValueAsString(responseTask); setupMocks(serializedTask, HttpStatus.SC_CREATED); VmApi vmApi = new VmApi(restClient); final CountDownLatch latch = new CountDownLatch(1); vmApi.addTagToVmAsync("foo", new Tag("tagValue"), new FutureCallback<Task>() { @Override//from w w w . j av a 2 s. c o m public void onSuccess(@Nullable Task result) { assertEquals(result, responseTask); latch.countDown(); } @Override public void onFailure(Throwable t) { fail(t.toString()); latch.countDown(); } }); assertThat(latch.await(COUNTDOWNLATCH_AWAIT_TIMEOUT, TimeUnit.SECONDS), is(true)); }
From source file:com.vmware.photon.controller.api.client.resource.VmRestApiTest.java
@Test public void testAddTagToVmAsync() throws IOException, InterruptedException { final Task responseTask = new Task(); responseTask.setId("12345"); responseTask.setState("QUEUED"); responseTask.setQueuedTime(Date.from(Instant.now())); ObjectMapper mapper = new ObjectMapper(); String serializedTask = mapper.writeValueAsString(responseTask); setupMocks(serializedTask, HttpStatus.SC_CREATED); VmApi vmApi = new VmRestApi(restClient); final CountDownLatch latch = new CountDownLatch(1); vmApi.addTagToVmAsync("foo", new Tag("tagValue"), new FutureCallback<Task>() { @Override/*ww w .j a va 2 s .c om*/ public void onSuccess(@Nullable Task result) { assertEquals(result, responseTask); latch.countDown(); } @Override public void onFailure(Throwable t) { fail(t.toString()); latch.countDown(); } }); assertThat(latch.await(COUNTDOWNLATCH_AWAIT_TIMEOUT, TimeUnit.SECONDS), is(true)); }
From source file:fr.isen.browser5.Util.UrlLoader.java
public void setTabTitleFavicon() { String title = doc.title();//from w w w . j a va 2s . co m title = Str.shortenString(title, 12); int tabIndex = tabView.getCurrentTabIndex(); JPanel tabPanel = (JPanel) tabView.getCurrentFrame().getTabPane().getTabComponentAt(tabIndex); JLabel titleLabel = (JLabel) tabPanel.getComponent(0); titleLabel.setText(title); String baseUrl = pageUrl.getProtocol() + "://" + pageUrl.getHost(); Element element = doc.head().select("link[href~=.*\\.(ico|png)]").first(); String favicoUrlStr = ""; if (element != null) { favicoUrlStr = element.attr("abs:href"); } else { element = doc.head().select("meta[itemprop=image]").first(); if (element != null) { favicoUrlStr = baseUrl + element.attr("content"); } } ImageIcon icon = null; try { if (!favicoUrlStr.isEmpty()) { if (favicoUrlStr.endsWith(".ico")) { java.util.List<BufferedImage> imgs = ICODecoder.read(new URL(favicoUrlStr).openStream()); icon = new ImageIcon(imgs.get(0)); } else { icon = new ImageIcon(new URL(favicoUrlStr)); } icon = new ImageIcon(icon.getImage().getScaledInstance(16, 16, Image.SCALE_DEFAULT)); } } catch (IOException e) { e.printStackTrace(); } titleLabel.setIcon(icon); HistoryEntry historyEntry = new HistoryEntry(title, pageUrl.toString(), Instant.now().getEpochSecond(), icon, -1L); globalHistoryDAO.create(historyEntry); }
From source file:retsys.client.controller.DeliveryChallanReturnController.java
@Override Object buildRequestMsg() {/*from ww w . ja v a 2s. c o m*/ DeliveryChallan dc = new DeliveryChallan(); dc.setChallanDate(Date.from(Instant.now())); Project proj = new Project(); proj.setId(getId(project.getText())); dc.setProject(proj); dc.setIsDelivery(false); dc.setDeliveryMode(deliverymode.getText()); dc.setConcernPerson(concernperson.getText()); DeliveryChallan originalChallanDetail = new DeliveryChallan(); originalChallanDetail.setId(Integer.parseInt(dc_no.getText())); dc.setOriginalDeliveryChallan(originalChallanDetail); Iterator<DCItem> items = dcDetail.getItems().iterator(); List<DeliveryChallanDetail> dcDetails = new ArrayList<>(); while (items.hasNext()) { DCItem dcItem = items.next(); DeliveryChallanDetail dcDetail = new DeliveryChallanDetail(); Item item = new Item(); item.setId(dcItem.getId().get()); dcDetail.setItem(item); dcDetail.setQuantity(dcItem.getQuantity().get()); dcDetail.setUnits(dcItem.getUnits().get()); dcDetail.setAmount(dcItem.getAmount().get()); dcDetails.add(dcDetail); } dc.setDeliveryChallanDetail(dcDetails); return dc; }
From source file:com.vmware.photon.controller.api.client.resource.TenantsApiTest.java
@Test public void testCreateResourceTicket() throws IOException { Task responseTask = new Task(); responseTask.setId("12345"); responseTask.setState("QUEUED"); responseTask.setQueuedTime(Date.from(Instant.now())); ObjectMapper mapper = new ObjectMapper(); String serializedTask = mapper.writeValueAsString(responseTask); setupMocks(serializedTask, HttpStatus.SC_CREATED); TenantsApi tenantsApi = new TenantsApi(restClient); Task task = tenantsApi.createResourceTicket("foo", new ResourceTicketCreateSpec()); assertEquals(task, responseTask);/*from ww w. j av a 2 s . c o m*/ }
From source file:com.vmware.photon.controller.api.client.resource.TenantsRestApiTest.java
@Test public void testCreateResourceTicket() throws IOException { Task responseTask = new Task(); responseTask.setId("12345"); responseTask.setState("QUEUED"); responseTask.setQueuedTime(Date.from(Instant.now())); ObjectMapper mapper = new ObjectMapper(); String serializedTask = mapper.writeValueAsString(responseTask); setupMocks(serializedTask, HttpStatus.SC_CREATED); TenantsApi tenantsApi = new TenantsRestApi(restClient); Task task = tenantsApi.createResourceTicket("foo", new ResourceTicketCreateSpec()); assertEquals(task, responseTask);//from ww w . j a v a 2s . com }
From source file:org.noorganization.instalist.server.api.ListResource.java
/** * Creates a list in the group./*from w w w. j a v a 2 s. c o m*/ * @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); }