List of usage examples for java.util Date from
public static Date from(Instant instant)
From source file:org.apache.james.jmap.utils.FilterToSearchQuery.java
private SearchQuery convertCondition(FilterCondition filter) { SearchQuery searchQuery = new SearchQuery(); filter.getText().ifPresent(text -> { searchQuery.andCriteria(SearchQuery.or(ImmutableList.of(SearchQuery.address(AddressType.From, text), SearchQuery.address(AddressType.To, text), SearchQuery.address(AddressType.Cc, text), SearchQuery.address(AddressType.Bcc, text), SearchQuery.headerContains("Subject", text), SearchQuery.bodyContains(text)))); });/* w w w .j a v a2 s . c o m*/ filter.getFrom().ifPresent(from -> searchQuery.andCriteria(SearchQuery.address(AddressType.From, from))); filter.getTo().ifPresent(to -> searchQuery.andCriteria(SearchQuery.address(AddressType.To, to))); filter.getCc().ifPresent(cc -> searchQuery.andCriteria(SearchQuery.address(AddressType.Cc, cc))); filter.getBcc().ifPresent(bcc -> searchQuery.andCriteria(SearchQuery.address(AddressType.Bcc, bcc))); filter.getSubject() .ifPresent(subject -> searchQuery.andCriteria(SearchQuery.headerContains("Subject", subject))); filter.getBody().ifPresent(body -> searchQuery.andCriteria(SearchQuery.bodyContains(body))); filter.getAfter().ifPresent(after -> searchQuery .andCriteria(SearchQuery.internalDateAfter(Date.from(after.toInstant()), DateResolution.Second))); filter.getBefore().ifPresent(before -> searchQuery .andCriteria(SearchQuery.internalDateBefore(Date.from(before.toInstant()), DateResolution.Second))); filter.getHasAttachment().ifPresent(Throwing.consumer(hasAttachment -> { throw new NotImplementedException(); })); filter.getHeader().ifPresent(header -> searchQuery .andCriteria(SearchQuery.headerContains(header.getName(), header.getValue().orElse(null)))); filter.getIsAnswered() .ifPresent(isAnswered -> searchQuery.andCriteria(SearchQuery.flagIsSet(Flag.ANSWERED))); filter.getIsDraft().ifPresent(isDraft -> searchQuery.andCriteria(SearchQuery.flagIsSet(Flag.DRAFT))); filter.getIsFlagged().ifPresent(isFlagged -> searchQuery.andCriteria(SearchQuery.flagIsSet(Flag.FLAGGED))); filter.getIsUnread().ifPresent(isUnread -> searchQuery.andCriteria(SearchQuery.flagIsUnSet(Flag.SEEN))); filter.getMaxSize().ifPresent(maxSize -> searchQuery.andCriteria(SearchQuery.sizeLessThan(maxSize))); filter.getMinSize().ifPresent(minSize -> searchQuery.andCriteria(SearchQuery.sizeGreaterThan(minSize))); return searchQuery; }
From source file:org.ng200.openolympus.services.ContestService.java
public Solution getLastSolutionInContestByUserForTask(final Contest contest, final User user, final Task task) { return this.solutionRepository .findByTaskAndUserAndTimeAddedBetweenOrderByTimeAddedDesc(task, user, contest.getStartTime(), Date.from(contest.getStartTime().toInstant() .plusMillis(contest.getDuration() + this.getTimeExtensions(contest, user)))) .stream().findFirst().orElse(null); }
From source file:org.thingsboard.server.service.security.model.token.JwtTokenFactory.java
/** * Factory method for issuing new JWT Tokens. *//*from w w w .jav a 2 s . c om*/ public AccessJwtToken createAccessJwtToken(SecurityUser securityUser) { if (StringUtils.isBlank(securityUser.getEmail())) throw new IllegalArgumentException("Cannot create JWT Token without username/email"); if (securityUser.getAuthority() == null) throw new IllegalArgumentException("User doesn't have any privileges"); UserPrincipal principal = securityUser.getUserPrincipal(); String subject = principal.getValue(); Claims claims = Jwts.claims().setSubject(subject); claims.put(SCOPES, securityUser.getAuthorities().stream().map(GrantedAuthority::getAuthority) .collect(Collectors.toList())); claims.put(USER_ID, securityUser.getId().getId().toString()); claims.put(FIRST_NAME, securityUser.getFirstName()); claims.put(LAST_NAME, securityUser.getLastName()); claims.put(ENABLED, securityUser.isEnabled()); claims.put(IS_PUBLIC, principal.getType() == UserPrincipal.Type.PUBLIC_ID); if (securityUser.getTenantId() != null) { claims.put(TENANT_ID, securityUser.getTenantId().getId().toString()); } if (securityUser.getCustomerId() != null) { claims.put(CUSTOMER_ID, securityUser.getCustomerId().getId().toString()); } ZonedDateTime currentTime = ZonedDateTime.now(); String token = Jwts.builder().setClaims(claims).setIssuer(settings.getTokenIssuer()) .setIssuedAt(Date.from(currentTime.toInstant())) .setExpiration(Date.from(currentTime.plusSeconds(settings.getTokenExpirationTime()).toInstant())) .signWith(SignatureAlgorithm.HS512, settings.getTokenSigningKey()).compact(); return new AccessJwtToken(token, claims); }
From source file:org.codice.ddf.registry.federationadmin.service.impl.RegistryPublicationServiceImpl.java
@Override public void publish(String registryId, String destinationRegistryId) throws FederationAdminException { Metacard metacard = getMetacard(registryId); String metacardId = metacard.getId(); List<String> locations = RegistryUtility.getListOfStringAttribute(metacard, RegistryObjectMetacardType.PUBLISHED_LOCATIONS); if (locations.contains(destinationRegistryId)) { return;//from ww w . j a v a 2 s.c o m } String sourceId = getSourceIdFromRegistryId(destinationRegistryId); if (sourceId == null) { throw new FederationAdminException( "Could not find a source id for registry-id " + destinationRegistryId); } LOGGER.info("Publishing registry entry {}:{} to {}", metacard.getTitle(), registryId, sourceId); federationAdminService.addRegistryEntry(metacard, Collections.singleton(sourceId)); // need to reset the id since the framework reset it in the groomer plugin // and we don't want to update with the wrong id metacard.setAttribute(new AttributeImpl(Metacard.ID, metacardId)); locations.add(destinationRegistryId); locations.remove(NO_PUBLICATIONS); ArrayList<String> locArr = new ArrayList<>(locations); metacard.setAttribute(new AttributeImpl(RegistryObjectMetacardType.PUBLISHED_LOCATIONS, locArr)); metacard.setAttribute(new AttributeImpl(RegistryObjectMetacardType.LAST_PUBLISHED, Date.from(ZonedDateTime.now().toInstant()))); federationAdminService.updateRegistryEntry(metacard); }
From source file:net.ljcomputing.ecsr.security.service.impl.JwtTokenServiceImpl.java
/** * The date now.//w w w. j av a 2 s . c o m * * @return the date */ private Date now() { final ZonedDateTime zdt = ldtNow.atZone(ZONE_ID); // NOPMD final Instant instant = zdt.toInstant(); // NOPMD return Date.from(instant); // NOPMD }
From source file:io.adeptj.runtime.servlet.ToolsServlet.java
/** * Renders tools page./* w w w . j a va 2 s. co m*/ */ @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) { Bundle[] bundles = BundleContextHolder.getInstance().getBundleContext().getBundles(); long startTime = ManagementFactory.getRuntimeMXBean().getStartTime(); MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean(); TemplateEngines.getDefault().render(TemplateContext.builder().request(req).response(resp) .template(TOOLS_TEMPLATE).locale(req.getLocale()) .contextObject(ContextObject.newContextObject().put("username", req.getRemoteUser()) .put("sysProps", System.getProperties().entrySet()).put("totalBundles", bundles.length) .put("bundles", bundles) .put("runtime", JAVA_RUNTIME_NAME + "(build " + JAVA_RUNTIME_VERSION + ")") .put("jvm", JAVA_VM_NAME + "(build " + JAVA_VM_VERSION + ", " + JAVA_VM_INFO + ")") .put("startTime", Date.from(Instant.ofEpochMilli(startTime))) .put("upTime", Times.format(startTime)) .put("maxMemory", FileUtils.byteCountToDisplaySize(memoryMXBean.getHeapMemoryUsage().getMax())) .put("usedMemory", FileUtils.byteCountToDisplaySize(memoryMXBean.getHeapMemoryUsage().getUsed())) .put("processors", Runtime.getRuntime().availableProcessors())) .build()); }
From source file:net.jmhertlein.mcanalytics.api.auth.SSLUtil.java
/** * Creates a new self-signed X509 certificate * * @param pair the public/private keypair- the pubkey will be added to the cert and the private * key will be used to sign the certificate * @param subject the distinguished name of the subject * @param isAuthority true to make the cert a CA cert, false otherwise * @return/*from ww w . j av a 2 s . c o m*/ */ public static X509Certificate newSelfSignedCertificate(KeyPair pair, X500Name subject, boolean isAuthority) { X509v3CertificateBuilder b = new JcaX509v3CertificateBuilder(subject, BigInteger.probablePrime(128, new SecureRandom()), Date.from(Instant.now().minusSeconds(1)), Date.from(LocalDateTime.now().plusYears(3).toInstant(ZoneOffset.UTC)), subject, pair.getPublic()); try { b.addExtension(Extension.basicConstraints, true, new BasicConstraints(isAuthority)); } catch (CertIOException ex) { Logger.getLogger(SSLUtil.class.getName()).log(Level.SEVERE, null, ex); } try { X509CertificateHolder bcCert = b.build( new JcaContentSignerBuilder(SIGNING_ALGORITHM).setProvider("BC").build(pair.getPrivate())); return new JcaX509CertificateConverter().setProvider("BC").getCertificate(bcCert); } catch (CertificateException | OperatorCreationException ex) { Logger.getLogger(SSLUtil.class.getName()).log(Level.SEVERE, null, ex); return null; } }
From source file:com.adeptj.runtime.servlet.ToolsServlet.java
/** * Renders tools page./* www . ja v a2 s . c om*/ */ @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) { Bundle[] bundles = BundleContextHolder.getInstance().getBundleContext().getBundles(); long startTime = ManagementFactory.getRuntimeMXBean().getStartTime(); MemoryUsage memoryUsage = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage(); TemplateEngine.getInstance() .render(TemplateContext.builder().request(req).response(resp).template(TOOLS_TEMPLATE) .locale(req.getLocale()) .templateData(TemplateData.newTemplateData().put("username", req.getRemoteUser()) .put("sysProps", System.getProperties().entrySet()) .put("totalBundles", bundles.length).put("bundles", bundles) .put("runtime", JAVA_RUNTIME_NAME + "(build " + JAVA_RUNTIME_VERSION + ")") .put("jvm", JAVA_VM_NAME + "(build " + JAVA_VM_VERSION + ", " + JAVA_VM_INFO + ")") .put("startTime", Date.from(Instant.ofEpochMilli(startTime))) .put("upTime", Times.format(startTime)) .put("maxMemory", FileUtils.byteCountToDisplaySize(memoryUsage.getMax())) .put("usedMemory", FileUtils.byteCountToDisplaySize(memoryUsage.getUsed())) .put("processors", Runtime.getRuntime().availableProcessors())) .build()); }
From source file:org.ng200.openolympus.services.ContestService.java
public Contest getRunningContest() { return this.intersects(Date.from(Instant.now()), Date.from(Instant.now())); }
From source file:org.sakaiproject.assignment.persistence.AssignmentRepositoryImpl.java
@Override @Transactional/* w ww .ja va 2 s . co m*/ public void updateSubmission(AssignmentSubmission submission) { submission.setDateModified(Date.from(Instant.now())); sessionFactory.getCurrentSession().update(submission); }