List of usage examples for org.joda.time DateTime now
public static DateTime now()
ISOChronology
in the default time zone. From source file:com.ethercis.compositionservice.handler.FlatJsonHandler.java
License:Apache License
@Override public Boolean update(RunTimeSingleton global, I_DomainAccess access, UUID compositionId, String content, UUID committerId, UUID systemId, String description) throws Exception { boolean changed = false; boolean changedContext = false; UUID contextId = compositionAccess.getContextId(); Timestamp updateTransactionTime = new Timestamp(DateTime.now().getMillis()); I_ContextAccess contextAccess;// w w w. j a v a 2s .com if (compositionAccess.getContextId() == null) { EventContext context = ContextHelper.createNullContext(); contextAccess = I_ContextAccess.getInstance(domainAccess, context); contextAccess.commit(updateTransactionTime); } else contextAccess = I_ContextAccess.retrieveInstance(domainAccess, contextId); for (I_EntryAccess entryAccess : compositionAccess.getContent()) { //set the template Id templateId = entryAccess.getTemplateId(); Composition newComposition = build(global, content); entryAccess.setCompositionData(newComposition.getArchetypeDetails().getTemplateId().getValue(), newComposition); changed = true; EventContext eventContext = newComposition.getContext(); contextAccess.setRecordFields(contextId, eventContext); changedContext = true; } if (changedContext) contextAccess.update(updateTransactionTime); if (changed) { return compositionAccess.update(updateTransactionTime, committerId, systemId, null, I_ConceptAccess.ContributionChangeType.modification, description, true); } return true; //nothing to do... }
From source file:com.eucalyptus.objectstorage.pipeline.auth.S3Authentication.java
License:Open Source License
static void assertDateNotSkewed(final Date date) throws RequestTimeTooSkewedException { DateTime currentTime = DateTime.now(); DateTime dt = new DateTime(date); if (dt.isBefore(currentTime.minusMillis((int) ObjectStorageProperties.EXPIRATION_LIMIT))) throw new RequestTimeTooSkewedException(); if (dt.isAfter(currentTime.plusMillis((int) ObjectStorageProperties.EXPIRATION_LIMIT))) throw new RequestTimeTooSkewedException(); }
From source file:com.eucalyptus.objectstorage.pipeline.auth.S3V4Authentication.java
License:Open Source License
static void validateExpiresFromParams(Map<String, String> parameters, Date date) throws AccessDeniedException { String expires = parameters.get(AWS_EXPIRES_PARAM); if (expires == null) throw new AccessDeniedException(null, "X-Amz-Expires parameter must be specified."); Long expireTime;/*from w w w .j a va 2s.c om*/ try { expireTime = Long.parseLong(expires); } catch (NumberFormatException e) { throw new AccessDeniedException(null, "Invalid X-Amz-Expires parameter."); } if (expireTime < 1 || expireTime > 604800) throw new AccessDeniedException(null, "Invalid Expires parameter."); DateTime currentTime = DateTime.now(); DateTime dt = new DateTime(date); if (currentTime.isBefore(dt.minusMillis((int) ObjectStorageProperties.EXPIRATION_LIMIT))) throw new AccessDeniedException(null, "Cannot process request. X-Amz-Date is not yet valid."); if (currentTime.isAfter(dt.plusSeconds(expireTime.intValue() + StackConfiguration.CLOCK_SKEW_SEC))) throw new AccessDeniedException(null, "Cannot process request. Expired."); }
From source file:com.eurodyn.qlack2.fuse.aaa.impl.AccountingServiceImpl.java
License:EUPL
@Override public String createSession(SessionDTO session) { Session entity = ConverterUtil.sessionDTOToSession(session, em); if (entity.getCreatedOn() == 0) { entity.setCreatedOn(DateTime.now().getMillis()); }// w w w . j a v a 2s. c o m em.persist(entity); if (entity.getSessionAttributes() != null) { for (SessionAttribute attribute : entity.getSessionAttributes()) { em.persist(attribute); } } return entity.getId(); }
From source file:com.eurodyn.qlack2.fuse.aaa.impl.AccountingServiceImpl.java
License:EUPL
@Override public void terminateSession(String sessionID) { Session sessionEntity = Session.find(sessionID, em); if (sessionEntity != null) { sessionEntity.setTerminatedOn(DateTime.now().getMillis()); } else {/*from w w w. ja v a2 s. com*/ LOGGER.log(Level.WARNING, "Requested to terminate a session that does not exist, session ID: {0}", sessionID); } }
From source file:com.eurodyn.qlack2.fuse.cm.impl.ConcurrencyControlServiceImpl.java
License:EUPL
@Override @Transactional(TxType.REQUIRED)/* ww w. ja v a 2s .c o m*/ public void lock(String nodeID, String lockToken, boolean lockChildren, String userID) throws QNodeLockException, QFileNotFoundException { Node node = Node.findNode(nodeID, em); if (node == null) { throw new QFileNotFoundException("The folder/file you want to lock does not exist"); } // Check whether there is a lock conflict with the current node. NodeDTO selConflict = this.getSelectedNodeWithLockConflict(nodeID, lockToken); if (selConflict != null && selConflict.getName() != null) { throw new QSelectedNodeLockException( "The selected folder is locked" + " and an" + " invalid lock token was passed; the folder cannot be locked.", selConflict.getId(), selConflict.getName()); } // Check for ancestor node (folder) lock conflicts. if (node.getParent() != null) { NodeDTO ancConflict = this.getAncestorFolderWithLockConflict(node.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 locked.", ancConflict.getId(), ancConflict.getName()); } } // Check for descendant node lock conflicts NodeDTO desConflict = this.getDescendantNodeWithLockConflict(nodeID, lockToken); // In case a conflict was found an exception is thrown if (desConflict != null && desConflict.getId() != null) { throw new QDescendantNodeLockException( "An descendant node is locked" + " and an" + " invalid lock token was passed; the folder cannot be locked.", desConflict.getId(), desConflict.getName()); } node.setLockToken(lockToken); node.setAttribute(CMConstants.ATTR_LOCKED_ON, String.valueOf(DateTime.now().getMillis()), em); node.setAttribute(CMConstants.ATTR_LOCKED_BY, userID, em); // In case the lockChilden variable is true all the children of the // folder will recursively be locked if (lockChildren) { for (Node child : node.getChildren()) { lock(child.getId(), lockToken, true, userID); } } }
From source file:com.eurodyn.qlack2.fuse.cm.impl.DocumentServiceImpl.java
License:EUPL
@Override @Transactional(TxType.REQUIRED)// w w w . j a va 2s. 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)// www. j a v a 2s. co 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)//from w w w . j a va2 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 . j av a 2 s . co 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); } }