Example usage for org.joda.time DateTime now

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

Introduction

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

Prototype

public static DateTime now() 

Source Link

Document

Obtains a DateTime set to the current system millisecond time using ISOChronology in the default time zone.

Usage

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

License:EUPL

@Override
@Transactional(TxType.REQUIRED)/*from  w ww . j  a v a  2 s  . c  om*/
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)//from  w w w  .  jav  a 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)// w  w w . j  a v a2s.co  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 www .j  av  a 2  s  .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 www.  j  a v  a  2  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();
}

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

License:EUPL

@Override
@Transactional(TxType.REQUIRED)/*from   w  w w.  j av  a2s. 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  w w . j a v  a2 s . c  o  m*/
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  w w w. j  a  v  a2 s.c om*/
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)//from  ww  w  .  ja v  a  2 s .  co m
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)//from www. j  a  v  a  2 s .co 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);
    }
}