Search in sources :

Example 1 with LockStatus

use of org.alfresco.service.cmr.lock.LockStatus in project acs-community-packaging by Alfresco.

the class UILockIcon method encodeBegin.

/**
 * @see javax.faces.component.UIComponentBase#encodeBegin(javax.faces.context.FacesContext)
 */
public void encodeBegin(FacesContext context) throws IOException {
    if (isRendered() == false) {
        return;
    }
    // get the value and see if the image is locked
    NodeService nodeService = getNodeService(context);
    String lockUser = null;
    Object val = getValue();
    NodeRef ref = null;
    if (val instanceof NodeRef) {
        ref = (NodeRef) val;
        if (nodeService.exists(ref)) {
            LockStatus lockStatus = Repository.getServiceRegistry(FacesContext.getCurrentInstance()).getLockService().getLockStatus(ref);
            if (lockStatus == LockStatus.LOCK_OWNER || lockStatus == LockStatus.LOCKED)
                lockUser = (String) nodeService.getProperty(ref, ContentModel.PROP_LOCK_OWNER);
        }
    }
    final boolean locked = lockUser != null;
    final boolean lockedOwner = locked && (lockUser.equals(Application.getCurrentUser(context).getUserName()));
    this.encodeBegin(context, locked, lockedOwner, new String[] { lockUser });
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) LockStatus(org.alfresco.service.cmr.lock.LockStatus) NodeService(org.alfresco.service.cmr.repository.NodeService)

Example 2 with LockStatus

use of org.alfresco.service.cmr.lock.LockStatus in project acs-community-packaging by Alfresco.

the class NewEditionWizard method initTranslationList.

/**
 * Util method which init the lists of translations
 */
private void initTranslationList() {
    this.translationsCheckedOut = new ArrayList<TranslationWrapper>();
    this.selectableTranslations = new ArrayList<TranslationWrapper>();
    // get all translations of the mlContainer
    Map<Locale, NodeRef> translations = getMultilingualContentService().getTranslations(mlContainerToVersion);
    // fill the data table rows list
    for (Map.Entry<Locale, NodeRef> entry : translations.entrySet()) {
        NodeRef nodeRef = entry.getValue();
        String name = (String) getNodeService().getProperty(nodeRef, ContentModel.PROP_NAME);
        String langCode = ((Locale) getNodeService().getProperty(nodeRef, ContentModel.PROP_LOCALE)).getLanguage();
        String langText = getContentFilterLanguagesService().getLabelByCode(langCode);
        String lockOwner = (String) getNodeService().getProperty(nodeRef, ContentModel.PROP_LOCK_OWNER);
        // create the row with the current translation
        TranslationWrapper wrapper = new TranslationWrapper(name, langCode, lockOwner, langText);
        if (!getNodeService().hasAspect(nodeRef, ContentModel.ASPECT_MULTILINGUAL_EMPTY_TRANSLATION)) {
            // add it to the selectable list if it is not empty
            this.selectableTranslations.add(wrapper);
        }
        if (getNodeService().hasAspect(nodeRef, ContentModel.ASPECT_LOCKABLE)) {
            LockStatus lockStatus = getLockService().getLockStatus(nodeRef);
            if (lockStatus != LockStatus.NO_LOCK) {
                // if the node is locked, add it to the locked translation list
                this.translationsCheckedOut.add(wrapper);
            }
        }
    }
}
Also used : Locale(java.util.Locale) NodeRef(org.alfresco.service.cmr.repository.NodeRef) LockStatus(org.alfresco.service.cmr.lock.LockStatus) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with LockStatus

use of org.alfresco.service.cmr.lock.LockStatus in project alfresco-remote-api by Alfresco.

the class WebDAVLockServiceImpl method sessionDestroyed.

@Override
@SuppressWarnings("unchecked")
public void sessionDestroyed() {
    HttpSession session = currentSession.get();
    if (session == null) {
        if (logger.isDebugEnabled()) {
            logger.debug("Couldn't find current session.");
        }
        return;
    }
    // look for locked documents list in http session
    final List<Pair<String, NodeRef>> lockedResources = (List<Pair<String, NodeRef>>) session.getAttribute(LOCKED_RESOURCES);
    if (lockedResources != null && lockedResources.size() > 0) {
        if (logger.isDebugEnabled()) {
            logger.debug("Found " + lockedResources.size() + " locked resources for session: " + session.getId());
        }
        for (Pair<String, NodeRef> lockedResource : lockedResources) {
            String runAsUser = lockedResource.getFirst();
            final NodeRef nodeRef = lockedResource.getSecond();
            // there are some document that should be forcibly unlocked
            AuthenticationUtil.runAs(new RunAsWork<Void>() {

                @Override
                public Void doWork() throws Exception {
                    return transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Void>() {

                        @Override
                        public Void execute() throws Throwable {
                            // check whether this document still exists in repo
                            if (nodeService.exists(nodeRef)) {
                                if (logger.isDebugEnabled()) {
                                    logger.debug("Trying to release lock for: " + nodeRef);
                                }
                                // check the lock status of document
                                LockStatus lockStatus = lockService.getLockStatus(nodeRef);
                                // check if document was checked out
                                boolean hasWorkingCopy = checkOutCheckInService.getWorkingCopy(nodeRef) != null;
                                boolean isWorkingCopy = nodeService.hasAspect(nodeRef, ContentModel.ASPECT_WORKING_COPY);
                                // forcibly unlock document if it is still locked and not checked out
                                if ((lockStatus.equals(LockStatus.LOCKED) || lockStatus.equals(LockStatus.LOCK_OWNER)) && !hasWorkingCopy && !isWorkingCopy) {
                                    try {
                                        // try to unlock it
                                        lockService.unlock(nodeRef);
                                        if (logger.isDebugEnabled()) {
                                            logger.debug("Lock was successfully released for: " + nodeRef);
                                        }
                                    } catch (Exception e) {
                                        if (logger.isDebugEnabled()) {
                                            logger.debug("Unable to unlock " + nodeRef + " cause: " + e.getMessage());
                                        }
                                    }
                                } else {
                                    // document is not locked or is checked out
                                    if (logger.isDebugEnabled()) {
                                        logger.debug("Skip lock releasing for: " + nodeRef + " as it is not locked or is checked out");
                                    }
                                }
                            } else {
                                // document no longer exists in repo
                                if (logger.isDebugEnabled()) {
                                    logger.debug("Skip lock releasing for an unexisting node: " + nodeRef);
                                }
                            }
                            return null;
                        }
                    }, transactionService.isReadOnly());
                }
            }, runAsUser == null ? AuthenticationUtil.getSystemUserName() : runAsUser);
        }
    } else {
        // there are no documents with unexpected lock left on it
        if (logger.isDebugEnabled()) {
            logger.debug("No locked resources were found for session: " + session.getId());
        }
    }
}
Also used : HttpSession(javax.servlet.http.HttpSession) LockStatus(org.alfresco.service.cmr.lock.LockStatus) NodeRef(org.alfresco.service.cmr.repository.NodeRef) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback) ArrayList(java.util.ArrayList) List(java.util.List) Pair(org.alfresco.util.Pair)

Aggregations

LockStatus (org.alfresco.service.cmr.lock.LockStatus)3 NodeRef (org.alfresco.service.cmr.repository.NodeRef)3 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Locale (java.util.Locale)1 Map (java.util.Map)1 HttpSession (javax.servlet.http.HttpSession)1 RetryingTransactionCallback (org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback)1 NodeService (org.alfresco.service.cmr.repository.NodeService)1 Pair (org.alfresco.util.Pair)1