Example usage for org.joda.time LocalDateTime LocalDateTime

List of usage examples for org.joda.time LocalDateTime LocalDateTime

Introduction

In this page you can find the example usage for org.joda.time LocalDateTime LocalDateTime.

Prototype

public LocalDateTime(Object instant) 

Source Link

Document

Constructs an instance from an Object that represents a datetime.

Usage

From source file:ca.ualberta.physics.cssdp.vfs.resource.FileSystemResource.java

License:Apache License

@GET
@Path("/{owner}/ls")
@ApiOperation(value = "List the contents of a directory in this filesystem", response = ca.ualberta.physics.cssdp.domain.vfs.VfsListing.class)
@ApiResponses(value = { @ApiResponse(code = 400, message = "No owner specified"),
        @ApiResponse(code = 400, message = "No path specified"),
        @ApiResponse(code = 404, message = "Path not found"),
        @ApiResponse(code = 404, message = "No session found"),
        @ApiResponse(code = 500, message = "Unable to complete request, see response body for error details") })
public Response ls(
        @ApiParam(value = "The owner of this filesystem", required = true) @PathParam("owner") Long owner,
        @ApiParam(value = "The path of the file to read", required = true) @QueryParam("path") String path,
        @ApiParam(value = "The authenticated session token", required = true) @HeaderParam("CICSTART.session") String sessionToken,
        @Context UriInfo uriInfo) {

    if (Strings.isNullOrEmpty(path)) {
        return Response.status(400).build();
    }//  w  w w.  j  a v a  2  s. c  om
    if (owner == null) {
        return Response.status(400).build();
    }
    validateSessionAndOwner(owner, sessionToken);

    path = path.endsWith("/") ? path : path + "/";

    ServiceResponse<File[]> sr = fileSystemService.ls(owner, path);
    if (sr.isRequestOk()) {

        File[] files = sr.getPayload();
        if (files != null) {

            VfsListing listing = new VfsListing();

            listing.setPath(new Link(path, UriBuilder.fromUri(uriInfo.getBaseUri()).path(getClass())
                    .path(owner.toString()).path("ls").queryParam("path", path).build()));

            for (File file : files) {

                VfsListingEntry entry = new VfsListingEntry();
                entry.setDir(file.isDirectory());

                entry.setPath(new Link(file.getName(),
                        UriBuilder.fromUri(uriInfo.getBaseUri()).path(getClass()).path(owner.toString())
                                .path("read").queryParam("path", path + file.getName()).build()));
                entry.setSize(file.length());
                entry.setLastModified(new LocalDateTime(new Date(file.lastModified())));
                listing.getEntries().add(entry);
            }

            return Response.ok(listing).build();
        } else {
            return Response.status(204).build();
        }
    } else {
        return Response.status(500).entity(sr.getMessagesAsStrings()).build();
    }
}

From source file:ch.aonyx.broker.ib.api.data.bar.RealTimeBarEvent.java

License:Apache License

public long getMillis() {
    DateTime dt2 = new LocalDateTime(timestamp * 1000L).toDateTime();
    return dt2.getMillis();
}

From source file:cherry.foundation.type.mybatis.JodaLocalDateTimeTypeHandler.java

License:Apache License

@Override
public LocalDateTime getNullableResult(ResultSet rs, String columnName) throws SQLException {
    Timestamp timestamp = rs.getTimestamp(columnName);
    if (timestamp == null) {
        return null;
    }//  www  .  j a  v a2s.  c  om
    return new LocalDateTime(timestamp.getTime());
}

From source file:cherry.foundation.type.mybatis.JodaLocalDateTimeTypeHandler.java

License:Apache License

@Override
public LocalDateTime getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
    Timestamp timestamp = rs.getTimestamp(columnIndex);
    if (timestamp == null) {
        return null;
    }//from  ww w  . j av a 2 s  . c om
    return new LocalDateTime(timestamp.getTime());
}

From source file:cherry.foundation.type.mybatis.JodaLocalDateTimeTypeHandler.java

License:Apache License

@Override
public LocalDateTime getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
    Timestamp timestamp = cs.getTimestamp(columnIndex);
    if (timestamp == null) {
        return null;
    }/*from   w w w  . ja  v a2 s  .com*/
    return new LocalDateTime(timestamp.getTime());
}

From source file:cherry.foundation.type.querydsl.LocalDateTimeType.java

License:Apache License

@Override
public LocalDateTime getValue(ResultSet rs, int startIndex) throws SQLException {
    Timestamp timestamp = rs.getTimestamp(startIndex);
    if (timestamp == null) {
        return null;
    }//from   w  ww . j av a 2s.  c  o m
    return new LocalDateTime(timestamp.getTime());
}

From source file:com.axelor.apps.base.ical.ICalendarService.java

License:Open Source License

@Transactional
protected ICalendarEvent findOrCreateEvent(VEvent vEvent) {

    String uid = vEvent.getUid().getValue();
    DtStart dtStart = vEvent.getStartDate();
    DtEnd dtEnd = vEvent.getEndDate();/*  w ww .j  a v a2 s  .  co  m*/

    ICalendarEventRepository repo = Beans.get(ICalendarEventRepository.class);
    ICalendarEvent event = repo.findByUid(uid);
    if (event == null) {
        event = new ICalendarEvent();
        event.setUid(uid);
    }

    event.setStartDateTime(new LocalDateTime(dtStart.getDate()));
    event.setEndDateTime(new LocalDateTime(dtEnd.getDate()));
    event.setAllDay(!(dtStart.getDate() instanceof DateTime));

    event.setSubject(getValue(vEvent, Property.SUMMARY));
    event.setDescription(getValue(vEvent, Property.DESCRIPTION));
    event.setLocation(getValue(vEvent, Property.LOCATION));
    event.setGeo(getValue(vEvent, Property.GEO));
    event.setUrl(getValue(vEvent, Property.URL));

    ICalendarUser organizer = findOrCreateUser(vEvent.getOrganizer());
    if (organizer != null) {
        event.setOrganizer(organizer);
        iCalendarUserRepository.save(organizer);
    }

    for (Object item : vEvent.getProperties(Property.ATTENDEE)) {
        ICalendarUser attendee = findOrCreateUser((Property) item);
        if (attendee != null) {
            event.addAttendee(attendee);
            iCalendarUserRepository.save(attendee);
        }
    }

    return event;
}

From source file:com.axelor.apps.base.ical.ICalendarService.java

License:Open Source License

protected ICalendar doSync(ICalendar calendar, CalDavCalendarCollection collection) throws IOException,
        URISyntaxException, ParseException, ObjectStoreException, ConstraintViolationException {

    final String[] names = { Property.UID, Property.URL, Property.SUMMARY, Property.DESCRIPTION,
            Property.DTSTART, Property.DTEND, Property.ORGANIZER, Property.ATTENDEE };

    final boolean keepRemote = calendar.getKeepRemote() == Boolean.TRUE;

    final Map<String, VEvent> remoteEvents = new HashMap<>();
    final List<VEvent> localEvents = new ArrayList<>();
    final Set<String> synced = new HashSet<>();

    for (VEvent item : ICalendarStore.getEvents(collection)) {
        remoteEvents.put(item.getUid().getValue(), item);
    }//from w  ww . j av  a2 s  .  c o  m

    for (ICalendarEvent item : calendar.getEvents()) {
        VEvent source = createVEvent(item);
        VEvent target = remoteEvents.get(source.getUid().getValue());
        if (target == null && Strings.isNullOrEmpty(item.getUid())) {
            target = source;
        }

        if (target != null) {
            if (keepRemote) {
                VEvent tmp = target;
                target = source;
                source = tmp;
            } else {
                if (source.getLastModified() != null && target.getLastModified() != null) {
                    LocalDateTime lastModifiedSource = new LocalDateTime(
                            source.getLastModified().getDateTime());
                    LocalDateTime lastModifiedTarget = new LocalDateTime(
                            target.getLastModified().getDateTime());
                    if (lastModifiedSource.isBefore(lastModifiedTarget)) {
                        VEvent tmp = target;
                        target = source;
                        source = tmp;
                    }
                } else if (target.getLastModified() != null) {
                    VEvent tmp = target;
                    target = source;
                    source = tmp;
                }
            }
            localEvents.add(target);
            synced.add(target.getUid().getValue());

            if (source == target) {
                continue;
            }

            for (String name : names) {
                Property s = source.getProperty(name);
                Property t = target.getProperty(name);
                if (s == null && t == null) {
                    continue;
                }
                if (t == null) {
                    t = s;
                }
                if (s == null) {
                    target.getProperties().remove(t);
                } else {
                    t.setValue(s.getValue());
                }
            }
        }
    }

    for (String uid : remoteEvents.keySet()) {
        if (!synced.contains(uid)) {
            localEvents.add(remoteEvents.get(uid));
        }
    }

    // update local events
    final List<ICalendarEvent> iEvents = new ArrayList<>();
    for (VEvent item : localEvents) {
        ICalendarEvent iEvent = findOrCreateEvent(item);
        iEvents.add(iEvent);
    }
    calendar.getEvents().clear();
    for (ICalendarEvent event : iEvents) {
        calendar.addEvent(event);
    }

    // update remote events
    for (VEvent item : localEvents) {
        if (!synced.contains(item.getUid().getValue())) {
            continue;
        }
        Calendar cal = newCalendar();
        cal.getComponents().add(item);
        collection.addCalendar(cal);
    }

    return calendar;
}

From source file:com.axelor.apps.crm.service.CalendarService.java

License:Open Source License

@Transactional
protected Event findOrCreateEventCRM(VEvent vEvent) {

    String uid = vEvent.getUid().getValue();
    DtStart dtStart = vEvent.getStartDate();
    DtEnd dtEnd = vEvent.getEndDate();/*  w  w w . j a v  a  2s  .c o  m*/

    EventRepository repo = Beans.get(EventRepository.class);
    Event event = repo.all().filter("self.uid = ?1", uid).fetchOne();
    if (event == null) {
        event = new Event();
        event.setUid(uid);
    }
    if (event.getTypeSelect() == null || event.getTypeSelect() == 0) {
        event.setTypeSelect(EventRepository.TYPE_EVENT);
    }
    event.setStartDateTime(new LocalDateTime(dtStart.getDate()));
    event.setEndDateTime(new LocalDateTime(dtEnd.getDate()));
    event.setAllDay(!(dtStart.getDate() instanceof DateTime));

    event.setSubject(getValue(vEvent, Property.SUMMARY));
    event.setDescription(getValue(vEvent, Property.DESCRIPTION));
    event.setLocation(getValue(vEvent, Property.LOCATION));
    event.setGeo(getValue(vEvent, Property.GEO));
    event.setUrl(getValue(vEvent, Property.URL));
    event.setSubjectTeam(event.getSubject());
    if (Clazz.PRIVATE.getValue().equals(getValue(vEvent, Property.CLASS))) {
        event.setVisibilitySelect(ICalendarEventRepository.VISIBILITY_PRIVATE);
    } else {
        event.setVisibilitySelect(ICalendarEventRepository.VISIBILITY_PUBLIC);
    }
    if (Transp.TRANSPARENT.getValue().equals(getValue(vEvent, Property.TRANSP))) {
        event.setDisponibilitySelect(ICalendarEventRepository.DISPONIBILITY_AVAILABLE);
    } else {
        event.setDisponibilitySelect(ICalendarEventRepository.DISPONIBILITY_BUSY);
    }
    if (event.getVisibilitySelect() == ICalendarEventRepository.VISIBILITY_PRIVATE) {
        event.setSubjectTeam(I18n.get("Available"));
        if (event.getDisponibilitySelect() == ICalendarEventRepository.DISPONIBILITY_BUSY) {
            event.setSubjectTeam(I18n.get("Busy"));
        }
    }
    ICalendarUser organizer = findOrCreateUser(vEvent.getOrganizer(), event);
    if (organizer != null) {
        event.setOrganizer(organizer);
        iCalendarUserRepository.save(organizer);
    }

    for (Object item : vEvent.getProperties(Property.ATTENDEE)) {
        ICalendarUser attendee = findOrCreateUser((Property) item, event);
        if (attendee != null) {
            event.addAttendee(attendee);
            iCalendarUserRepository.save(attendee);
        }
    }

    return event;
}

From source file:com.axelor.apps.crm.service.CalendarService.java

License:Open Source License

protected Calendar doSync(Calendar calendar, CalDavCalendarCollection collection) throws IOException,
        URISyntaxException, ParseException, ObjectStoreException, ConstraintViolationException {

    final String[] names = { Property.UID, Property.URL, Property.SUMMARY, Property.DESCRIPTION,
            Property.DTSTART, Property.DTEND, Property.ORGANIZER, Property.CLASS, Property.TRANSP,
            Property.ATTENDEE };// w  w w  .j a va 2s. c  o  m

    final boolean keepRemote = calendar.getKeepRemote() == Boolean.TRUE;

    final Map<String, VEvent> remoteEvents = new HashMap<>();
    final List<VEvent> localEvents = new ArrayList<>();
    final Set<String> synced = new HashSet<>();
    for (VEvent item : ICalendarStore.getEvents(collection)) {
        remoteEvents.put(item.getUid().getValue(), item);
    }

    for (ICalendarEvent item : calendar.getEventsCrm()) {
        VEvent source = createVEvent(item);
        VEvent target = remoteEvents.get(source.getUid().getValue());
        if (target == null && Strings.isNullOrEmpty(item.getUid())) {
            target = source;
        }

        if (target != null) {
            if (keepRemote) {
                VEvent tmp = target;
                target = source;
                source = tmp;
            } else {
                if (source.getLastModified() != null && target.getLastModified() != null) {
                    LocalDateTime lastModifiedSource = new LocalDateTime(
                            source.getLastModified().getDateTime());
                    LocalDateTime lastModifiedTarget = new LocalDateTime(
                            target.getLastModified().getDateTime());
                    if (lastModifiedSource.isBefore(lastModifiedTarget)) {
                        VEvent tmp = target;
                        target = source;
                        source = tmp;
                    }
                } else if (target.getLastModified() != null) {
                    VEvent tmp = target;
                    target = source;
                    source = tmp;
                }
            }
            localEvents.add(target);
            synced.add(target.getUid().getValue());

            if (source == target) {
                continue;
            }

            for (String name : names) {
                if (!name.equals(Property.ATTENDEE)) {
                    Property s = source.getProperty(name);
                    Property t = target.getProperty(name);
                    PropertyList items = target.getProperties();
                    if (s == null && t == null) {
                        continue;
                    } else if (t == null) {
                        t = s;
                        items.add(t);
                    } else if (s == null) {
                        target.getProperties().remove(t);
                    } else {
                        t.setValue(s.getValue());
                    }

                } else {
                    PropertyList sourceList = source.getProperties(Property.ATTENDEE);
                    PropertyList targetList = target.getProperties(Property.ATTENDEE);
                    target.getProperties().removeAll(targetList);
                    target.getProperties().addAll(sourceList);
                    target.getProperties();
                }
            }
        }
    }

    for (String uid : remoteEvents.keySet()) {
        if (!synced.contains(uid)) {
            localEvents.add(remoteEvents.get(uid));
        }
    }

    // update local events
    final List<Event> iEvents = new ArrayList<>();
    for (VEvent item : localEvents) {
        Event iEvent = findOrCreateEventCRM(item);
        iEvents.add(iEvent);
    }
    calendar.getEventsCrm().clear();
    for (Event event : iEvents) {
        calendar.addEventsCrm(event);
    }

    // update remote events
    for (VEvent item : localEvents) {
        if (!synced.contains(item.getUid().getValue())) {
            continue;
        }
        net.fortuna.ical4j.model.Calendar cal = newCalendar();
        cal.getComponents().add(item);
        collection.addCalendar(cal);
    }

    return calendar;
}