Example usage for org.joda.time DateTime getMillis

List of usage examples for org.joda.time DateTime getMillis

Introduction

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

Prototype

public long getMillis() 

Source Link

Document

Gets the milliseconds of the datetime instant from the Java epoch of 1970-01-01T00:00:00Z.

Usage

From source file:com.eurodyn.qlack2.fuse.cm.impl.VersionServiceImpl.java

License:EUPL

@Override
@Transactional(TxType.REQUIRED)// ww w. j  a  v  a2 s.  c o m
public String createVersion(String fileID, VersionDTO cmVersion, String filename, byte[] content, String userID,
        String lockToken) throws QNodeLockException {
    Node file = Node.findFile(fileID, em);

    // Check whether there is a lock conflict with the current node.
    NodeDTO selConflict = concurrencyControlService.getSelectedNodeWithLockConflict(fileID, lockToken);
    if (selConflict != null && selConflict.getName() != null) {
        throw new QSelectedNodeLockException(
                "The selected file is locked" + " and an"
                        + " invalid lock token was passed; A new version cannot" + "be created for this file.",
                selConflict.getId(), selConflict.getName());
    }

    // Check for ancestor node (folder) lock conflicts.
    if (file.getParent() != null) {
        NodeDTO ancConflict = concurrencyControlService
                .getAncestorFolderWithLockConflict(file.getParent().getId(), lockToken);
        // In case a conflict was found an exception is thrown
        if (ancConflict != null && ancConflict.getId() != null) {
            throw new QAncestorFolderLockException(
                    "An ancestor folder is locked" + " and an"
                            + " invalid lock token was passed; the folder cannot be created.",
                    ancConflict.getId(), ancConflict.getName());
        }
    }

    Version version = new Version();
    version.setName(cmVersion.getName());
    version.setNode(file);
    version.setFilename(filename);
    // The content is provided, so the mimetype is immediately computed
    if (content != null) {
        version.setMimetype(getMimeType(content));
    }
    // The mimeType is pre-computed
    else if (cmVersion.getMimetype() != null) {
        version.setMimetype(cmVersion.getMimetype());
    }
    // The entire content is provided as a binary as a result the size can be computed.
    if (content != null) {
        version.setContentSize(new Long(content.length));
    }
    // THe size is pre-computed (e.g Retrieved from the flu_file)
    else {
        version.setContentSize(cmVersion.getContentSize());
    }

    // Set created / last modified information
    version.setAttributes(new ArrayList<VersionAttribute>());
    DateTime now = DateTime.now();
    version.setCreatedOn(now.getMillis());
    version.getAttributes().add(new VersionAttribute(Constants.ATTR_CREATED_BY, userID, version));
    version.getAttributes().add(
            new VersionAttribute(Constants.ATTR_LAST_MODIFIED_ON, String.valueOf(now.getMillis()), version));
    version.getAttributes().add(new VersionAttribute(Constants.ATTR_LAST_MODIFIED_BY, userID, version));

    // Set custom created version attributes
    if (cmVersion.getAttributes() != null) {
        for (Map.Entry<String, String> entry : cmVersion.getAttributes().entrySet()) {
            version.getAttributes().add(new VersionAttribute(entry.getKey(), entry.getValue(), version));
        }
    }

    em.persist(version);

    // Persist binary content.
    if (content != null) {
        storageEngine.setVersionContent(version.getId(), content);
    }

    return version.getId();
}

From source file:com.eurodyn.qlack2.fuse.cm.impl.VersionServiceImpl.java

License:EUPL

@Override
@Transactional(TxType.REQUIRED)/*from   w  ww. j a  v  a 2s . com*/
public void updateAttribute(String fileID, String versionName, String attributeName, String attributeValue,
        String userID, String lockToken) throws QNodeLockException {
    Version version = Version.find(fileID, versionName, em);
    Node file = version.getNode();

    if ((file.getLockToken() != null) && (!file.getLockToken().equals(lockToken))) {
        throw new QNodeLockException("File with ID " + file + " is locked and an "
                + "invalid lock token was passed; the file version " + "attributes cannot be updated.");
    }

    version.setAttribute(attributeName, attributeValue, em);

    // Update last modified information
    if (userID != null) {
        DateTime now = DateTime.now();
        version.setAttribute(Constants.ATTR_LAST_MODIFIED_ON, String.valueOf(now.getMillis()), em);
        version.setAttribute(Constants.ATTR_LAST_MODIFIED_BY, userID, em);
    }
}

From source file:com.eurodyn.qlack2.fuse.cm.impl.VersionServiceImpl.java

License:EUPL

@Override
@Transactional(TxType.REQUIRED)/*from ww  w .  j  av a 2  s  .  c o m*/
public void updateAttributes(String fileID, String versionName, Map<String, String> attributes, String userID,
        String lockToken) throws QNodeLockException {
    Version version = Version.find(fileID, versionName, em);
    Node file = version.getNode();

    if ((file.getLockToken() != null) && (!file.getLockToken().equals(lockToken))) {
        throw new QNodeLockException("File with ID " + file + " is locked and an "
                + "invalid lock token was passed; the file version" + "attributes cannot be updated.");
    }

    for (String attributeName : attributes.keySet()) {
        version.setAttribute(attributeName, attributes.get(attributeName), em);
    }

    // Update last modified information
    if (userID != null) {
        DateTime now = DateTime.now();
        version.setAttribute(Constants.ATTR_LAST_MODIFIED_ON, String.valueOf(now.getMillis()), em);
        version.setAttribute(Constants.ATTR_LAST_MODIFIED_BY, userID, em);
    }
}

From source file:com.eurodyn.qlack2.fuse.cm.impl.VersionServiceImpl.java

License:EUPL

@Override
@Transactional(TxType.REQUIRED)/* w  ww  . j  ava2s.  c  om*/
public void updateVersion(String fileID, VersionDTO versionDTO, byte[] content, String userID,
        boolean updateAllAttribtues, String lockToken) {

    Node file = Node.findFile(fileID, em);

    if ((file.getLockToken() != null) && (!file.getLockToken().equals(lockToken))) {
        throw new QNodeLockException("File with ID " + file + " is locked and an "
                + "invalid lock token was passed; the file version" + "attributes cannot be updated.");
    }

    Version version = Version.find(fileID, versionDTO.getName(), em);

    version.setName(versionDTO.getName());
    version.setNode(file);
    version.setFilename(versionDTO.getFilename());

    // The entire content is provided as a binary as a result the size can be computed.
    if (content != null) {
        version.setContentSize(new Long(content.length));
    }
    // THe size is pre-computed (e.g Retrieved from the flu_file)
    else {
        version.setContentSize(versionDTO.getContentSize());
    }

    // The content is provided, so the mimetype is immediately computed
    if (content != null) {
        version.setMimetype(getMimeType(content));
    }
    // The mimeType is pre-computed
    else if (versionDTO.getMimetype() != null) {
        version.setMimetype(versionDTO.getMimetype());
    }

    List<VersionAttribute> attributeToRemove = new ArrayList<>();
    // When true, user defined attributes will be deleted if they do not exist in the DTO but exist
    // in the persisted entity
    if (updateAllAttribtues) {
        for (VersionAttribute attrEntity : version.getAttributes()) {
            if (!attrEntity.getName().equals(Constants.ATTR_LAST_MODIFIED_ON)
                    && !attrEntity.getName().equals(Constants.ATTR_LAST_MODIFIED_BY)
                    && !attrEntity.getName().equals(Constants.ATTR_CREATED_BY)) {

                if (versionDTO.getAttributes() != null) {
                    if (versionDTO.getAttributes().get(attrEntity.getName()) == null) {
                        attributeToRemove.add(version.getAttribute(attrEntity.getName()));
                        version.removeAttribute(attrEntity.getName(), em);
                    }
                }
            }
        }
    }

    version.getAttributes().removeAll(attributeToRemove);

    // Update last modified information, if not existing, create
    if (userID != null) {
        DateTime now = DateTime.now();
        version.setAttribute(Constants.ATTR_LAST_MODIFIED_ON, String.valueOf(now.getMillis()), em);
        version.setAttribute(Constants.ATTR_LAST_MODIFIED_BY, userID, em);
    }

    // Set values to the existing custom created attributes or create new attributes
    if (versionDTO.getAttributes() != null) {
        for (Map.Entry<String, String> entry : versionDTO.getAttributes().entrySet()) {
            if (!entry.getKey().equals(Constants.ATTR_LAST_MODIFIED_ON)
                    && !entry.getKey().equals(Constants.ATTR_LAST_MODIFIED_BY)
                    && !entry.getKey().equals(Constants.ATTR_CREATED_BY)) {
                version.setAttribute(entry.getKey(), entry.getValue(), em);
            }
        }
    }
}

From source file:com.eurodyn.qlack2.fuse.cm.impl.VersionServiceImpl.java

License:EUPL

@Override
@Transactional(TxType.REQUIRED)//w w  w . ja v a2s.  c o  m
public void deleteAttribute(String fileID, String versionName, String attributeName, String userID,
        String lockToken) throws QNodeLockException {
    Version version = Version.find(fileID, versionName, em);
    Node file = version.getNode();

    if ((file.getLockToken() != null) && (!file.getLockToken().equals(lockToken))) {
        throw new QNodeLockException("File with ID " + file + " is locked and an "
                + "invalid lock token was passed; the file version" + "attributes cannot be deleted.");
    }

    version.removeAttribute(attributeName, em);

    // Update last modified information
    if (userID != null) {
        DateTime now = DateTime.now();
        version.setAttribute(Constants.ATTR_LAST_MODIFIED_ON, String.valueOf(now.getMillis()), em);
        version.setAttribute(Constants.ATTR_LAST_MODIFIED_BY, userID, em);
    }
}

From source file:com.eurodyn.qlack2.fuse.ticketserver.impl.TicketServerServiceImpl.java

License:EUPL

@Override
public String createTicket(TicketDTO ticketDTO) {
    DateTime now = DateTime.now();
    Ticket ticket = new Ticket();
    ticket.setId(UUID.randomUUID().toString());
    ticket.setCreatedAt(now.getMillis());
    if (StringUtils.isNotBlank(ticketDTO.getCreatedBy())) {
        ticket.setCreatedBy(ticketDTO.getCreatedBy());
    }/*from  ww w. j  a va 2s  . c  om*/
    if (StringUtils.isNotBlank(ticketDTO.getPayload())) {
        ticket.setPayload(ticketDTO.getPayload());
    }
    ticket.setRevoked(false);

    if (ticketDTO.getValidUntil() != null) {
        ticket.setValidUntil(ticketDTO.getValidUntil());
    }
    if (ticketDTO.getAutoExtendValidUntil() != null) {
        ticket.setAutoExtendUntil(ticketDTO.getAutoExtendValidUntil());
    }
    if (ticketDTO.getAutoExtendDuration() != null) {
        ticket.setAutoExtendDuration(ticketDTO.getAutoExtendDuration());
    }

    em.persist(ticket);

    return ticket.getId().toString();
}

From source file:com.example.bigquery.QueryParametersSample.java

License:Apache License

private static void runTimestamp() throws InterruptedException {
    BigQuery bigquery = new BigQueryOptions.DefaultBigqueryFactory()
            .create(BigQueryOptions.getDefaultInstance());

    DateTime timestamp = new DateTime(2016, 12, 7, 8, 0, 0, DateTimeZone.UTC);

    String queryString = "SELECT TIMESTAMP_ADD(@ts_value, INTERVAL 1 HOUR);";
    QueryRequest queryRequest = QueryRequest.newBuilder(queryString)
            .addNamedParameter("ts_value", QueryParameterValue.timestamp(
                    // Timestamp takes microseconds since 1970-01-01T00:00:00 UTC
                    timestamp.getMillis() * 1000))
            // Standard SQL syntax is required for parameterized queries.
            // See: https://cloud.google.com/bigquery/sql-reference/
            .setUseLegacySql(false).build();

    // Execute the query.
    QueryResponse response = bigquery.query(queryRequest);

    // Wait for the job to finish (if the query takes more than 10 seconds to complete).
    while (!response.jobCompleted()) {
        Thread.sleep(1000);//from   ww w.j av  a2 s. c  o m
        response = bigquery.getQueryResults(response.getJobId());
    }

    if (response.hasErrors()) {
        throw new RuntimeException(response.getExecutionErrors().stream().<String>map(err -> err.getMessage())
                .collect(Collectors.joining("\n")));
    }

    QueryResult result = response.getResult();
    Iterator<List<FieldValue>> iter = result.iterateAll();

    DateTimeFormatter formatter = ISODateTimeFormat.dateTimeNoMillis().withZoneUTC();
    while (iter.hasNext()) {
        List<FieldValue> row = iter.next();
        System.out.printf("%s\n", formatter.print(new DateTime(
                // Timestamp values are returned in microseconds since 1970-01-01T00:00:00 UTC,
                // but org.joda.time.DateTime constructor accepts times in milliseconds.
                row.get(0).getTimestampValue() / 1000, DateTimeZone.UTC)));
    }
}

From source file:com.F8Full.bixhistorique.backend.ParseCronServlet.java

private void processProperties(Network curNetwork) {
    DateTime today = new DateTime(DateTimeZone.UTC).withTimeAtStartOfDay();

    for (int stationId : curNetwork.stationPropertieTransientMap.keySet()) {
        curNetwork.stationPropertieTransientMap.get(stationId).setKey(KeyFactory
                .createKey(StationProperties.class.getSimpleName(), stationId + "_" + today.getMillis()));
    }/*from  ww w.  j  av a 2 s.  c o m*/

    PersistenceManager pm = PMF.get().getPersistenceManager();
    addStationToParsingStatus();

    try {
        pm.makePersistentAll(curNetwork.stationPropertieTransientMap.values());
    } finally {
        pm.close();
    }

}

From source file:com.facebook.presto.atop.AtopSplitManager.java

License:Apache License

@Override
public ConnectorSplitSource getSplits(ConnectorTransactionHandle transactionHandle, ConnectorSession session,
        ConnectorTableLayoutHandle layoutHandle) {
    AtopTableLayoutHandle handle = checkType(layoutHandle, AtopTableLayoutHandle.class, "layoutHandle");

    AtopTableHandle table = handle.getTableHandle();

    List<ConnectorSplit> splits = new ArrayList<>();
    DateTime end = DateTime.now().withZone(timeZone);
    for (Node node : nodeManager.getActiveDatasourceNodes(connectorId.getId())) {
        DateTime start = end.minusDays(maxHistoryDays - 1).withTimeAtStartOfDay();
        while (start.isBefore(end)) {
            DateTime splitEnd = start.withTime(23, 59, 59, 999);
            Domain splitDomain = Domain.create(
                    ValueSet.ofRanges(//www .j  a  v  a 2 s .c om
                            Range.range(TIMESTAMP, start.getMillis(), true, splitEnd.getMillis(), true)),
                    false);
            if (handle.getStartTimeConstraint().overlaps(splitDomain)
                    && handle.getEndTimeConstraint().overlaps(splitDomain)) {
                splits.add(new AtopSplit(table.getTable(), node.getHostAndPort(), start));
            }
            start = start.plusDays(1).withTimeAtStartOfDay();
        }
    }

    return new FixedSplitSource(connectorId.getId(), splits);
}

From source file:com.facebook.presto.connector.system.QuerySystemTable.java

License:Apache License

private Long toTimeStamp(DateTime dateTime) {
    if (dateTime == null) {
        return null;
    }//from  ww  w  . java 2s  .  c  o  m
    return dateTime.getMillis();
}