List of usage examples for java.util Date from
public static Date from(Instant instant)
From source file:org.ojbc.util.model.rapback.IdentificationResultSearchRequest.java
public void setReportedDateEndLocalDate(LocalDate localDate) { this.reportedDateEndDate = localDate == null ? null : Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); }
From source file:fr.lepellerin.ecole.service.internal.CantineServiceImpl.java
@Override @Transactional(readOnly = true)//w w w.ja va 2 s . c o m public PlanningDto getDateOuvert(final YearMonth anneeMois, final Famille famille) throws TechnicalException { final Date startDate = Date.from(Instant.from(anneeMois.atDay(1).atStartOfDay(ZoneId.systemDefault()))); final Date endDate = Date.from(Instant.from(anneeMois.atEndOfMonth().atStartOfDay(ZoneId.systemDefault()))); final Activite activite = getCantineActivite(); final LocalDateTime heureH = LocalDateTime.now(); final List<Inscription> icts = this.ictRepository.findByActiviteAndFamille(activite, famille); final PlanningDto planning = new PlanningDto(); icts.forEach(ict -> { planning.getHeaders().add(ict.getIndividu().getPrenom()); final List<Consommation> consos = this.consommationRepository .findByFamilleInscriptionActiviteUniteEtatsPeriode(famille, activite, ict.getGroupe(), Arrays.asList("reservation"), startDate, endDate); final List<Ouverture> ouvertures = this.ouvertureRepository.findByActiviteAndGroupeAndPeriode(activite, ict.getGroupe(), startDate, endDate); ouvertures.forEach(o -> { final LocalDate date = LocalDate.from(((java.sql.Date) o.getDate()).toLocalDate()); final LocalDateTime heureResa = this.getLimiteResaCantine(date); final LigneDto ligne = planning.getOrCreateLigne(date); final CaseDto c = new CaseDto(); c.setDate(date); c.setIndividu(ict.getIndividu()); c.setActivite(o.getActivite()); c.setUnite(o.getUnite()); c.setReservable(heureResa.isAfter(heureH)); final Optional<Consommation> cOpt = consos.stream().filter(conso -> { final LocalDate dateConso = LocalDate.from(((java.sql.Date) conso.getDate()).toLocalDate()); return dateConso.equals(date); }).findAny(); c.setReserve(cOpt.isPresent()); ligne.getCases().add(c); }); }); return planning; }
From source file:org.noorganization.instalist.server.api.ListResourceTest.java
@Before public void setUp() throws Exception { super.setUp(); CommonData data = new CommonData(); mManager = DatabaseHelper.getInstance().getManager(); mManager.getTransaction().begin();/*from w w w .ja va 2s .com*/ mUpdate = Instant.now(); mGroup = new DeviceGroup(); mCat = new Category().withGroup(mGroup).withName("").withUUID(UUID.randomUUID()).withUpdated(mUpdate); mListWC = new ShoppingList().withGroup(mGroup).withName("list1").withCategrory(mCat) .withUUID(UUID.randomUUID()).withUpdated(mUpdate); mListWOC = new ShoppingList().withGroup(mGroup).withName("list2").withUUID(UUID.randomUUID()) .withUpdated(mUpdate); mDeletedList = new DeletedObject().withGroup(mGroup).withUUID(UUID.randomUUID()) .withType(DeletedObject.Type.LIST).withUpdated(mUpdate); mNAGroup = new DeviceGroup().withUpdated(Date.from(mUpdate)); mNAList = new ShoppingList().withGroup(mNAGroup).withName("list3").withUUID(UUID.randomUUID()) .withUpdated(mUpdate); Device authorizedDevice = new Device().withAuthorized(true).withGroup(mGroup).withName("dev1") .withSecret(data.mEncryptedSecret).withCreated(Date.from(mUpdate)); mManager.persist(mGroup); mManager.persist(mCat); mManager.persist(mListWC); mManager.persist(mListWOC); mManager.persist(mDeletedList); mManager.persist(mNAGroup); mManager.persist(mNAList); mManager.persist(authorizedDevice); mManager.getTransaction().commit(); mManager.refresh(mGroup); mManager.refresh(mCat); mManager.refresh(mListWC); mManager.refresh(mListWOC); mManager.refresh(mDeletedList); mManager.refresh(mNAGroup); mManager.refresh(mNAList); mManager.refresh(authorizedDevice); mToken = ControllerFactory.getAuthController().getTokenByHttpAuth(mManager, authorizedDevice.getId(), data.mSecret); assertNotNull(mToken); }
From source file:org.noorganization.instalist.server.api.CategoriesResourceTest.java
@Before public void setUp() throws Exception { super.setUp(); CommonData data = new CommonData(); mManager = DatabaseHelper.getInstance().getManager(); mManager.getTransaction().begin();//from w w w . jav a2 s. co m mGroup = new DeviceGroup(); Instant now = Instant.now(); Device aDev = new Device().withAuthorized(true).withGroup(mGroup).withSecret(data.mEncryptedSecret) .withName("testDev"); mCategory = new Category().withGroup(mGroup).withName("cat1").withUUID(UUID.randomUUID()).withUpdated(now); mDeletedCategory = new DeletedObject().withGroup(mGroup).withType(DeletedObject.Type.CATEGORY) .withUUID(UUID.randomUUID()).withUpdated(now); mNotAccessibleGroup = new DeviceGroup().withUpdated(Date.from(now)); mNotAccessibleCategory = new Category().withGroup(mNotAccessibleGroup).withName("cat2") .withUUID(UUID.randomUUID()).withUpdated(now); mManager.persist(mGroup); mManager.persist(aDev); mManager.persist(mCategory); mManager.persist(mDeletedCategory); mManager.persist(mNotAccessibleGroup); mManager.persist(mNotAccessibleCategory); mManager.flush(); mManager.getTransaction().commit(); mManager.refresh(mGroup); mManager.refresh(aDev); mManager.refresh(mCategory); mManager.refresh(mDeletedCategory); mManager.refresh(mNotAccessibleGroup); mManager.refresh(mNotAccessibleCategory); mToken = ControllerFactory.getAuthController().getTokenByHttpAuth(mManager, aDev.getId(), data.mSecret); assertNotNull(mToken); }
From source file:com.hotelbeds.hotelapimodel.auto.util.AssignUtils.java
public static Date getDate(final LocalDate localDate) { Instant instant = localDate.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant(); return Date.from(instant); }
From source file:boutiqueEnLigne.test.SpringTest.java
@Before public void initialiserDB() { dbService.deleteAll();/* w ww .j a v a2 s . c o m*/ Utilisateur u1 = new Utilisateur(1L, "xx@.fr", "mdp", "addresse", "nom", "prenom", "33000", "bordeaux", "060629594"); utilisateurService.save(u1); Categorie c1 = new Categorie(1L, "vetement"); categorieService.save(c1); Article a1 = new Article(1L, c1, 10L, 10.0, "pantalon bleu", Genre.HOMME); articleService.save(a1); Article a2 = new Article(2L, c1, 10L, 10.0, "pantalon rose", Genre.FEMME); articleService.save(a2); Article a3 = new Article(3L, c1, 10L, 10.0, "pantalon court", Genre.ENFANT); articleService.save(a3); Article a4 = new Article(4L, c1, 10L, 10.0, "pantalon rouge", Genre.MIXTE); articleService.save(a4); Article a5 = new Article(5L, c1, 10L, 10.0, "chapeau rouge", Genre.MIXTE); articleService.save(a5); ModeLivraison m1 = new ModeLivraison(1L, "chronopost", 2.5); modeLivraisonService.save(m1); Commande co1 = new Commande(1L, Date.from(Instant.now()), u1, m1, false, false); commandeService.save(co1); SousCommande s1 = new SousCommande(1L, a1, co1, 2L); sousCommandeService.save(s1); SousCommande s2 = new SousCommande(2L, a2, co1, 4L); sousCommandeService.save(s2); }
From source file:com.vmware.photon.controller.api.client.resource.ClusterApiTest.java
@Test public void testDelete() 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); ClusterApi clusterApi = new ClusterApi(restClient); Task task = clusterApi.delete("foo"); assertEquals(task, responseTask);//from w w w . j a va2 s . c o m }
From source file:com.vmware.photon.controller.api.client.resource.ClusterRestApiTest.java
@Test public void testDelete() 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); ClusterApi clusterApi = new ClusterRestApi(restClient); Task task = clusterApi.delete("foo"); assertEquals(task, responseTask);/* w w w . j av a2 s.c o m*/ }
From source file:de.alpharogroup.user.service.UserTokensBusinessService.java
/** * {@inheritDoc}//w ww . jav a 2 s. c o m */ @Override public String newAuthenticationToken(String username) { UserTokens userTokens = find(username); if (userTokens == null) { userTokens = merge(newUserTokens(username)); } // check if expired Date now = Date.from(LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant()); if (userTokens.getExpiry().before(now)) { // expires in one year Date expiry = Date.from(LocalDateTime.now().plusMonths(12).atZone(ZoneId.systemDefault()).toInstant()); // create a token String token = RandomExtensions.randomToken(); userTokens.setExpiry(expiry); userTokens.setToken(token); userTokens = merge(userTokens); } return userTokens.getToken(); }
From source file:com.epam.reportportal.auth.integration.github.GitHubUserReplicator.java
public User synchronizeUser(String accessToken) { GitHubClient gitHubClient = GitHubClient.withAccessToken(accessToken); UserResource userInfo = gitHubClient.getUser(); User user = userRepository.findOne(EntityUtils.normalizeUsername(userInfo.login)); BusinessRule.expect(user, Objects::nonNull).verify(ErrorType.USER_NOT_FOUND, userInfo.login); BusinessRule.expect(user.getType(), userType -> Objects.equals(userType, UserType.GITHUB)).verify( ErrorType.INCORRECT_AUTHENTICATION_TYPE, "User '" + userInfo.login + "' is not GitHUB user"); user.setFullName(userInfo.name);/*from ww w .java 2 s . co m*/ user.getMetaInfo().setSynchronizationDate(Date.from(ZonedDateTime.now().toInstant())); String newPhotoId = uploadAvatar(gitHubClient, userInfo.name, userInfo.avatarUrl); if (!Strings.isNullOrEmpty(newPhotoId)) { dataStorage.deleteData(user.getPhotoId()); user.setPhotoId(newPhotoId); } userRepository.save(user); return user; }