List of usage examples for java.util Date from
public static Date from(Instant instant)
From source file:org.openmrs.module.operationtheater.OperationTheaterModuleActivator.java
private Patient getEmergencyPatient(PatientIdentifierType patientIdentifierType, LocationService locationService) { Patient patient = new Patient(); patient.setUuid(OTMetadata.PLACEHOLDER_PATIENT_UUID); PersonName pName = new PersonName(); String gender = "M"; boolean male = gender.equals("M"); pName.setGivenName("EMERGENCY"); pName.setFamilyName("PLACEHOLDER PATIENT"); patient.addName(pName);/* ww w .ja v a2s . com*/ patient.setBirthdate(Date.from(LocalDate.of(1970, 1, 1).atStartOfDay(ZoneId.systemDefault()).toInstant())); patient.setBirthdateEstimated(false); patient.setGender(gender); PatientIdentifier pa1 = new PatientIdentifier(); pa1.setIdentifier(idService.generateIdentifier(patientIdentifierType, "EmergencyData")); pa1.setIdentifierType(patientIdentifierType); pa1.setDateCreated(new Date()); pa1.setLocation(locationService.getLocation(1)); patient.addIdentifier(pa1); return patient; }
From source file:devbury.dewey.plugins.RemindMe.java
private Date notifyAt(long amount, String units) { ChronoUnit chronoUnit = ChronoUnit.SECONDS; switch (units) { case "weeks": case "week": chronoUnit = ChronoUnit.WEEKS; break;// w w w . j a v a2 s. c om case "months": case "month": chronoUnit = ChronoUnit.MONTHS; break; case "days": case "day": chronoUnit = ChronoUnit.DAYS; break; case "hours": case "hour": chronoUnit = ChronoUnit.HOURS; break; case "minutes": case "minute": chronoUnit = ChronoUnit.MINUTES; break; } return Date.from(Instant.now().plus(amount, chronoUnit)); }
From source file:org.codice.ddf.registry.federationadmin.service.impl.RegistryPublicationServiceImpl.java
@Override public void unpublish(String registryId, String destinationRegistryId) throws FederationAdminException { Metacard metacard = getMetacard(registryId); List<String> locations = RegistryUtility.getListOfStringAttribute(metacard, RegistryObjectMetacardType.PUBLISHED_LOCATIONS); if (!locations.contains(destinationRegistryId)) { return;//from w w w. j a v a2s . com } locations.remove(destinationRegistryId); if (locations.isEmpty()) { locations.add(NO_PUBLICATIONS); } ArrayList<String> locArr = new ArrayList<>(); locArr.addAll(locations); metacard.setAttribute(new AttributeImpl(RegistryObjectMetacardType.PUBLISHED_LOCATIONS, locArr)); metacard.setAttribute(new AttributeImpl(RegistryObjectMetacardType.LAST_PUBLISHED, Date.from(ZonedDateTime.now().toInstant()))); federationAdminService.updateRegistryEntry(metacard); String sourceId = getSourceIdFromRegistryId(destinationRegistryId); if (sourceId == null) { throw new FederationAdminException( "Could not find a source id for registry-id " + destinationRegistryId); } LOGGER.info("Unpublishing registry entry {}:{} from {}", metacard.getTitle(), registryId, sourceId); federationAdminService.deleteRegistryEntriesByRegistryIds(Collections.singletonList(registryId), Collections.singleton(sourceId)); }
From source file:it.tidalwave.northernwind.frontend.ui.component.rssfeed.DefaultRssFeedViewController.java
@Override protected void addFullPost(final @Nonnull it.tidalwave.northernwind.core.model.Content post) throws IOException, NotFoundException { final ZonedDateTime blogDateTime = post.getProperties().getDateTimeProperty(DATE_KEYS, TIME0); // FIXME: compute the latest date, which is not necessarily the first if (feed.getLastBuildDate() == null) { feed.setLastBuildDate(Date.from(blogDateTime.toInstant())); }/*w w w . j av a 2 s .c o m*/ final ResourceProperties postProperties = post.getProperties(); final Item item = new Item(); final Content content = new Content(); // FIXME: text/xhtml? content.setType("text/html"); // FIXME: should use post.getResourceFile().getMimeType()? content.setValue(postProperties.getProperty(PROPERTY_FULL_TEXT)); item.setTitle(postProperties.getProperty(PROPERTY_TITLE, "")); // item.setAuthor("author " + i); TODO item.setPubDate(Date.from(blogDateTime.toInstant())); item.setContent(content); try { // FIXME: manipulate through site.createLink() final String link = linkBase.replaceAll("/$", "") + post.getExposedUri().asString() + "/"; final Guid guid = new Guid(); guid.setPermaLink(true); guid.setValue(link); item.setGuid(guid); item.setLink(link); } catch (NotFoundException e) { // ok. no link } items.add(item); }
From source file:org.sakaiproject.assignment.persistence.AssignmentRepositoryImpl.java
@Override @Transactional//w w w . ja v a2s .co m public void newSubmission(Assignment assignment, AssignmentSubmission submission, Optional<Set<AssignmentSubmissionSubmitter>> submitters, Optional<Set<String>> feedbackAttachments, Optional<Set<String>> submittedAttachments, Optional<Map<String, String>> properties) { if (!existsSubmission(submission.getId()) && exists(assignment.getId())) { submission.setDateCreated(Date.from(Instant.now())); submitters.ifPresent(submission::setSubmitters); submitters.ifPresent(s -> s.forEach(submitter -> submitter.setSubmission(submission))); feedbackAttachments.ifPresent(submission::setFeedbackAttachments); submittedAttachments.ifPresent(submission::setAttachments); properties.ifPresent(submission::setProperties); submission.setAssignment(assignment); assignment.getSubmissions().add(submission); sessionFactory.getCurrentSession().persist(assignment); } }
From source file:com.example.test.HibernateBookRepositoryTest.java
private void persistBooks(Supplier<AbstractBook> bookSupplier) throws Exception { transactionTemplate.execute(new TransactionCallbackWithoutResult() { @Override/*from ww w. j a va2 s. c om*/ protected void doInTransactionWithoutResult(TransactionStatus ts) { Session session = getCurrentSession(); Category softwareDevelopment = new Category(); softwareDevelopment.setName("Software development"); session.persist(softwareDevelopment); Category systemDesign = new Category(); systemDesign.setName("System design"); session.persist(systemDesign); Author martinFowler = new Author(); martinFowler.setFullName("Martin Fowler"); session.persist(martinFowler); AbstractBook poeaa = bookSupplier.get(); poeaa.setIsbn("007-6092019909"); poeaa.setTitle("Patterns of Enterprise Application Architecture"); poeaa.setPublicationDate(Date.from(Instant.parse("2002-11-15T00:00:00.00Z"))); poeaa.setAuthors(asList(martinFowler)); poeaa.setCategories(asList(softwareDevelopment, systemDesign)); session.persist(poeaa); Author gregorHohpe = new Author(); gregorHohpe.setFullName("Gregor Hohpe"); session.persist(gregorHohpe); Author bobbyWoolf = new Author(); bobbyWoolf.setFullName("Bobby Woolf"); session.persist(bobbyWoolf); AbstractBook eip = bookSupplier.get(); eip.setIsbn("978-0321200686"); eip.setTitle("Enterprise Integration Patterns"); eip.setPublicationDate(Date.from(Instant.parse("2003-10-20T00:00:00.00Z"))); eip.setAuthors(asList(gregorHohpe, bobbyWoolf)); eip.setCategories(asList(softwareDevelopment, systemDesign)); session.persist(eip); Category objectOrientedSoftwareDesign = new Category(); objectOrientedSoftwareDesign.setName("Object-Oriented Software Design"); session.persist(objectOrientedSoftwareDesign); Author ericEvans = new Author(); ericEvans.setFullName("Eric Evans"); session.persist(ericEvans); AbstractBook ddd = bookSupplier.get(); ddd.setIsbn("860-1404361814"); ddd.setTitle("Domain-Driven Design: Tackling Complexity in the Heart of Software"); ddd.setPublicationDate(Date.from(Instant.parse("2003-08-01T00:00:00.00Z"))); ddd.setAuthors(asList(ericEvans)); ddd.setCategories(asList(softwareDevelopment, systemDesign, objectOrientedSoftwareDesign)); session.persist(ddd); Category networkingCloudComputing = new Category(); networkingCloudComputing.setName("Networking & Cloud Computing"); session.persist(networkingCloudComputing); Category databasesBigData = new Category(); databasesBigData.setName("Databases & Big Data"); session.persist(databasesBigData); Author pramodSadalage = new Author(); pramodSadalage.setFullName("Pramod J. Sadalage"); session.persist(pramodSadalage); AbstractBook nosql = bookSupplier.get(); nosql.setIsbn("978-0321826626"); nosql.setTitle("NoSQL Distilled: A Brief Guide to the Emerging World of Polyglot Persistence"); nosql.setPublicationDate(Date.from(Instant.parse("2012-08-18T00:00:00.00Z"))); nosql.setAuthors(asList(pramodSadalage, martinFowler)); nosql.setCategories(asList(networkingCloudComputing, databasesBigData)); session.persist(nosql); } }); System.out.println("##################################################"); }
From source file:com.skipjaq.awspricing.pricing.AwsPricing.java
private List<PricingInfo.Term> getTerms(List<String> skus) { return skus.stream().map(s -> pricingInfo.getTerms().get("OnDemand").get(s).values()) .flatMap(v -> v.stream()/*from w w w . j a v a 2 s . c o m*/ // TODO(mirek) check if term is only one for product .filter(t -> Date.from(Instant.now()).after(getDate(t.getEffectiveDate())))) .collect(Collectors.toList()); }
From source file:com.devicehive.handler.notification.NotificationSearchHandlerTest.java
private DeviceNotification createNotification(long id, String guid) { DeviceNotification notification = new DeviceNotification(); notification.setId(id);//from w ww . j av a 2 s .com notification.setTimestamp(Date.from(Instant.now())); notification.setDeviceGuid(guid); notification.setNotification("SOME TEST DATA_" + id); notification.setParameters(new JsonStringWrapper("{\"param1\":\"value1\",\"param2\":\"value2\"}")); return notification; }
From source file:org.noorganization.instalist.server.api.TagResource.java
/** * Get a list of tags.//from ww w . j av a 2 s .c o m * @param _groupId The id of the group containing the tags. * @param _changedSince Limits the request to elements that changed since the given date. ISO * 8601 time e.g. 2016-01-19T11:54:07+0100. Optional. */ @GET @TokenSecured @Produces({ "application/json" }) public Response getTags(@PathParam("groupid") int _groupId, @QueryParam("changedsince") String _changedSince) throws Exception { Instant changedSince = null; try { if (_changedSince != null) changedSince = ISO8601Utils.parse(_changedSince, new ParsePosition(0)).toInstant(); } catch (ParseException _e) { return ResponseFactory.generateBadRequest(CommonEntity.INVALID_CHANGEDATE); } EntityManager manager = DatabaseHelper.getInstance().getManager(); List<Tag> tags; List<DeletedObject> deletedTags; DeviceGroup group = manager.find(DeviceGroup.class, _groupId); if (changedSince != null) { TypedQuery<Tag> tagQuery = manager.createQuery( "select t from Tag t where " + "t.group = :group and t.updated > :updated", Tag.class); tagQuery.setParameter("group", group); tagQuery.setParameter("updated", changedSince); tags = tagQuery.getResultList(); TypedQuery<DeletedObject> deletedRecipesQuery = manager.createQuery( "select do " + "from DeletedObject do where do.group = :group and do.updated > :updated and " + "do.type = :type", DeletedObject.class); deletedRecipesQuery.setParameter("group", group); deletedRecipesQuery.setParameter("updated", changedSince); deletedRecipesQuery.setParameter("type", DeletedObject.Type.TAG); deletedTags = deletedRecipesQuery.getResultList(); } else { tags = new ArrayList<Tag>(group.getTags()); TypedQuery<DeletedObject> deletedRecipesQuery = manager.createQuery( "select do " + "from DeletedObject do where do.group = :group and do.type = :type", DeletedObject.class); deletedRecipesQuery.setParameter("group", group); deletedRecipesQuery.setParameter("type", DeletedObject.Type.TAG); deletedTags = deletedRecipesQuery.getResultList(); } manager.close(); ArrayList<TagInfo> rtn = new ArrayList<TagInfo>(tags.size() + deletedTags.size()); for (Tag current : tags) { TagInfo toAdd = new TagInfo().withDeleted(false); toAdd.setUUID(current.getUUID()); toAdd.setName(current.getName()); toAdd.setLastChanged(Date.from(current.getUpdated())); rtn.add(toAdd); } for (DeletedObject current : deletedTags) { TagInfo toAdd = new TagInfo().withDeleted(true); toAdd.setUUID(current.getUUID()); toAdd.setLastChanged(Date.from(current.getUpdated())); rtn.add(toAdd); } return ResponseFactory.generateOK(rtn); }
From source file:net.bis5.slack.command.gcal.SlashCommandApi.java
private EventDateTime toDateTime(LocalDate date, LocalTime time) { if (time != null) { DateTime dateTime = new DateTime( Date.from(LocalDateTime.of(date, time).toInstant(ZoneOffset.ofHours(+9)))); return new EventDateTime().setDateTime(dateTime); } else {/* w w w . j a v a 2 s . c om*/ DateTime dateTime = new DateTime(true, Date.from(date.atStartOfDay().toInstant(ZoneOffset.UTC)).getTime(), 9); return new EventDateTime().setDate(dateTime); } }