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.esofthead.mycollab.vaadin.web.ui.field.DateTimeOptionField.java

License:Open Source License

private Date getDateValue() {
    Date selectDate = popupDateField.getValue();
    if (selectDate == null) {
        return null;
    }//from w  ww  .  ja  v  a 2s . co m

    DateTime jodaSelectDate = new DateTime(selectDate)
            .toDateTime(DateTimeZone.forTimeZone(AppContext.getUserTimeZone()));
    Date baseDate = new LocalDate(jodaSelectDate).toDate();
    if (hideTimeOption) {
        return new LocalDateTime(baseDate).toDateTime(DateTimeZone.forTimeZone(AppContext.getUserTimeZone()))
                .toDate();
    } else {
        Integer hour = (hourPickerComboBox.getValue() != null)
                ? Integer.parseInt((String) hourPickerComboBox.getValue())
                : 0;
        Integer minus = (minutePickerComboBox.getValue() != null)
                ? Integer.parseInt((String) minutePickerComboBox.getValue())
                : 0;
        String timeFormat = (timeFormatComboBox.getValue() != null) ? (String) timeFormatComboBox.getValue()
                : "AM";
        long milliseconds = calculateMilliSeconds(hour, minus, timeFormat);
        DateTime jodaTime = new DateTime(baseDate).plus(new Duration(milliseconds));
        return new LocalDateTime(jodaTime.getMillis())
                .toDateTime(DateTimeZone.forTimeZone(AppContext.getUserTimeZone())).toDate();
    }
}

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

License:EUPL

@Override
@Transactional(TxType.REQUIRED)/* www.j a  v a2 s.  c o m*/
public String createFolder(FolderDTO folder, String userID, String lockToken) throws QNodeLockException {

    Node parent = null;
    if (folder.getParentId() != null) {
        parent = Node.findFolder(folder.getParentId(), em);
    }

    // Check for ancestor node (folder) lock conflicts.
    if (parent != null) {
        NodeDTO ancConflict = concurrencyControlService.getAncestorFolderWithLockConflict(parent.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());
        }
    }

    Node folderEntity = ConverterUtil.nodeDTOToNode(folder);
    folderEntity.setParent(parent);
    // Set created / last modified information
    DateTime now = DateTime.now();
    folderEntity.setCreatedOn(now.getMillis());
    folderEntity.getAttributes().add(new NodeAttribute(Constants.ATTR_CREATED_BY, userID, folderEntity));
    folderEntity.getAttributes().add(
            new NodeAttribute(Constants.ATTR_LAST_MODIFIED_ON, String.valueOf(now.getMillis()), folderEntity));
    folderEntity.getAttributes().add(new NodeAttribute(Constants.ATTR_LAST_MODIFIED_BY, userID, folderEntity));
    em.persist(folderEntity);
    return folderEntity.getId();
}

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

License:EUPL

@Override
@Transactional(TxType.REQUIRED)//from   w w w . jav  a  2 s  .  c  o m
public void renameFolder(String folderID, String newName, String userID, String lockToken)
        throws QNodeLockException, QFileNotFoundException {
    Node folder = Node.findFolder(folderID, em);
    if (folder == null) {
        throw new QFileNotFoundException("The folder you want to rename does not exist");
    }

    if ((folder.getLockToken() != null) && (!folder.getLockToken().equals(lockToken))) {
        throw new QNodeLockException("Folder with ID " + folderID + " is locked and an "
                + "invalid lock token was passed; the folder cannot be renamed.");
    }
    folder.setAttribute(Constants.ATTR_NAME, newName, em);

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

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

License:EUPL

@Override
@Transactional(TxType.REQUIRED)/* w ww  . j  av a2  s .c  o m*/
public String createFile(FileDTO file, String userID, String lockToken) throws QNodeLockException {
    Node parent = null;
    if (file.getParentId() != null) {
        parent = Node.findFolder(file.getParentId(), em);
    }

    // Check for ancestor node (folder) lock conflicts.
    if (parent != null) {
        NodeDTO ancConflict = concurrencyControlService.getAncestorFolderWithLockConflict(parent.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 file cannot be created.",
                    ancConflict.getId(), ancConflict.getName());
        }
    }

    Node fileEntity = ConverterUtil.nodeDTOToNode(file);
    fileEntity.setParent(parent);

    //
    fileEntity.setMimetype(file.getMimetype());
    fileEntity.setContentSize(file.getSize());

    // Set created / last modified information
    DateTime now = DateTime.now();
    fileEntity.setCreatedOn(now.getMillis());
    fileEntity.getAttributes().add(new NodeAttribute(Constants.ATTR_CREATED_BY, userID, fileEntity));
    fileEntity.getAttributes().add(
            new NodeAttribute(Constants.ATTR_LAST_MODIFIED_ON, String.valueOf(now.getMillis()), fileEntity));
    fileEntity.getAttributes().add(new NodeAttribute(Constants.ATTR_LAST_MODIFIED_BY, userID, fileEntity));
    em.persist(fileEntity);
    return fileEntity.getId();
}

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

License:EUPL

@Override
@Transactional(TxType.REQUIRED)/*  w  ww  .  java 2  s  . c  o m*/
public void renameFile(String fileID, String newName, String userID, String lockToken)
        throws QNodeLockException, QFileNotFoundException {
    Node file = Node.findFile(fileID, em);
    if (file == null) {
        throw new QFileNotFoundException("The file to rename does not exist.");
    }

    if ((file.getLockToken() != null) && (!file.getLockToken().equals(lockToken))) {
        throw new QNodeLockException("File with ID " + fileID + " is locked and an "
                + "invalid lock token was passed; the file cannot be renamed.");
    }
    file.setAttribute(Constants.ATTR_NAME, newName, em);

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

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

License:EUPL

@Override
@Transactional(TxType.REQUIRED)/*from   ww w. jav  a2 s.  c o  m*/
public String createAttribute(String nodeId, String attributeName, String attributeValue, String userId,
        String lockToken) throws QNodeLockException, QFileNotFoundException {

    Node node = Node.findNode(nodeId, em);
    if (node == null) {
        throw new QFileNotFoundException("The node, which attribute should be created does not exist.");
    }

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

    NodeAttribute attribute = new NodeAttribute(attributeName, attributeValue, node);

    node.getAttributes().add(attribute);

    // Set created / last modified information
    if (userId != null) {
        DateTime now = DateTime.now();
        node.setCreatedOn(now.getMillis());
        node.setAttribute(Constants.ATTR_CREATED_BY, userId, em);
        node.setAttribute(Constants.ATTR_LAST_MODIFIED_ON, String.valueOf(now.getMillis()), em);
        node.setAttribute(Constants.ATTR_LAST_MODIFIED_BY, userId, em);
    }

    return attribute.getId();
}

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

License:EUPL

@Override
@Transactional(TxType.REQUIRED)// w w w.ja  va  2  s.c  o m
public void updateAttribute(String nodeID, String attributeName, String attributeValue, String userID,
        String lockToken) throws QNodeLockException, QFileNotFoundException {
    Node node = Node.findNode(nodeID, em);
    if (node == null) {
        throw new QFileNotFoundException("The node, which attribute should be updated does not exist.");
    }

    if ((node.getLockToken() != null) && (!node.getLockToken().equals(lockToken))) {
        throw new QNodeLockException("Node with ID " + nodeID + " is locked and an "
                + "invalid lock token was passed; the file attributes cannot be updated.");
    }
    node.setAttribute(attributeName, attributeValue, em);

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

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

License:EUPL

@Override
@Transactional(TxType.REQUIRED)//from  w ww.  ja  v  a2  s .  c  o  m
public void updateAttributes(String nodeID, Map<String, String> attributes, String userID, String lockToken)
        throws QNodeLockException, QFileNotFoundException {
    Node node = Node.findNode(nodeID, em);
    if (node == null) {
        throw new QFileNotFoundException("The node to update does not exist.");
    }

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

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

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

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

License:EUPL

@Override
@Transactional(TxType.REQUIRED)/*from   w w  w.j  a  v  a  2s  .  co m*/
public void deleteAttribute(String nodeID, String attributeName, String userID, String lockToken)
        throws QNodeLockException, QFileNotFoundException {
    Node node = Node.findNode(nodeID, em);
    if (node == null) {
        throw new QFileNotFoundException("The node, which attributes should be deleted does not exist.");
    }

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

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

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

License:EUPL

private String copyNode(Node node, Node newParent, String userID) {
    Node newNode = new Node();
    newNode.setType(node.getType());//from   w  ww.ja  va2 s .c  o  m
    newNode.setParent(newParent);
    List<NodeAttribute> newAttributes = new ArrayList<>();
    newNode.setAttributes(newAttributes);

    // Copy attributes except created/modified/locked information
    for (NodeAttribute attribute : node.getAttributes()) {
        switch (attribute.getName()) {
        case Constants.ATTR_CREATED_BY:
        case Constants.ATTR_LAST_MODIFIED_BY:
        case Constants.ATTR_LAST_MODIFIED_ON:
        case Constants.ATTR_LOCKED_BY:
        case Constants.ATTR_LOCKED_ON:
            break;
        default:
            newNode.getAttributes().add(new NodeAttribute(attribute.getName(), attribute.getValue(), newNode));
            break;

        }
    }

    // Set created / last modified information
    DateTime now = DateTime.now();
    newNode.setCreatedOn(now.getMillis());
    newNode.getAttributes().add(new NodeAttribute(Constants.ATTR_CREATED_BY, userID, newNode));
    newNode.getAttributes()
            .add(new NodeAttribute(Constants.ATTR_LAST_MODIFIED_ON, String.valueOf(now.getMillis()), newNode));
    newNode.getAttributes().add(new NodeAttribute(Constants.ATTR_LAST_MODIFIED_BY, userID, newNode));
    em.persist(newNode);

    for (Node child : node.getChildren()) {
        copyNode(child, newNode, userID);
    }

    return newNode.getId();
}