Example usage for org.apache.commons.lang BooleanUtils isTrue

List of usage examples for org.apache.commons.lang BooleanUtils isTrue

Introduction

In this page you can find the example usage for org.apache.commons.lang BooleanUtils isTrue.

Prototype

public static boolean isTrue(Boolean bool) 

Source Link

Document

Checks if a Boolean value is true, handling null by returning false.

 BooleanUtils.isTrue(Boolean.TRUE)  = true BooleanUtils.isTrue(Boolean.FALSE) = false BooleanUtils.isTrue(null)          = false 

Usage

From source file:org.onehippo.forge.channelmanager.pagesupport.document.management.impl.DocumentWorkflowDocumentManagementService.java

@Override
public String copyDocument(String sourceDocumentLocation, String targetFolderLocation,
        String targetDocumentNodeName) {
    log.debug("##### copyDocument('{}', '{}', '{}')", sourceDocumentLocation, targetFolderLocation,
            targetDocumentNodeName);/* w  w  w .j  a v a 2  s  . co m*/

    String targetDocumentLocation = null;

    try {
        if (!getSession().nodeExists(sourceDocumentLocation)) {
            throw new IllegalArgumentException(
                    "Source document doesn't exist at '" + sourceDocumentLocation + "'.");
        }

        final Node targetFolderNode = HippoWorkflowUtils.createMissingHippoFolders(getSession(),
                targetFolderLocation);

        if (targetFolderNode == null) {
            throw new IllegalArgumentException(
                    "Target folder doesn't exist at '" + targetFolderLocation + "'.");
        }

        Node sourceDocumentHandleNode = HippoWorkflowUtils
                .getHippoDocumentHandle(getSession().getNode(sourceDocumentLocation));

        if (sourceDocumentHandleNode == null) {
            throw new IllegalArgumentException(
                    "Source document handle is not found at '" + sourceDocumentLocation + "'.");
        }

        DocumentWorkflow documentWorkflow = getDocumentWorkflow(sourceDocumentHandleNode);
        Boolean copy = (Boolean) documentWorkflow.hints().get("copy");

        if (BooleanUtils.isTrue(copy)) {
            documentWorkflow.copy(new Document(targetFolderNode), targetDocumentNodeName);
            targetDocumentLocation = targetFolderNode.getNode(targetDocumentNodeName).getPath();
        } else {
            throw new IllegalStateException(
                    "Copy action not available on document at '" + sourceDocumentLocation + "' to '"
                            + targetFolderLocation + "/" + targetDocumentNodeName + "'.");
        }
    } catch (RepositoryException | WorkflowException | RemoteException e) {
        log.error("Failed to copy document at '{}' to '{}/{}'.", sourceDocumentLocation, targetFolderLocation,
                targetDocumentNodeName, e);
        throw new RuntimeException("Failed to copy document at '" + sourceDocumentLocation + "' to '"
                + targetFolderLocation + "/" + targetDocumentNodeName + "'. " + e);
    }

    return targetDocumentLocation;
}

From source file:org.onehippo.forge.content.exim.core.impl.WorkflowDocumentManagerImpl.java

/**
 * {@inheritDoc}/*from   w  w w  .j a  v  a 2s  .c  o  m*/
 */
@Override
public String createDocument(String folderLocation, String primaryTypeName, String nodeName, String locale,
        String localizedName) throws DocumentManagerException {
    getLogger().debug("##### createDocument under '{}')", folderLocation);

    String createdDocPath = null;

    try {
        String existingFolderPath = getExistingFolderPath(folderLocation);
        Node folderNode = null;

        if (existingFolderPath != null) {
            folderNode = getSession().getNode(existingFolderPath);
        } else {
            folderNode = HippoNodeUtils.createMissingHippoFolders(getSession(), ContentPathUtils
                    .encodeNodePath(ContentPathUtils.removeIndexNotationInNodePath(folderLocation)));

            if (folderNode == null) {
                throw new IllegalArgumentException("Folder is not available at '" + folderLocation + "'.");
            }

            if (!folderNode.isNodeType(HippoStdNodeType.NT_FOLDER)) {
                throw new IllegalStateException(
                        "Invalid folder found at '" + folderLocation + "', not 'hippostd:folder' type.");
            }
        }

        final FolderWorkflow folderWorkflow = getFolderWorkflow(folderNode);

        Boolean add = (Boolean) folderWorkflow.hints().get("add");

        if (BooleanUtils.isTrue(add)) {
            final String addedDocPath = folderWorkflow.add("new-document", primaryTypeName,
                    ContentPathUtils.encodeNodePath(ContentPathUtils.removeIndexNotationInNodePath(nodeName)));
            final Node handle = HippoNodeUtils.getHippoDocumentHandle(getSession().getNode(addedDocPath));
            final DefaultWorkflow defaultWorkflow = getDefaultWorkflow(handle);
            defaultWorkflow.setDisplayName(localizedName);
            createdDocPath = handle.getPath();
        } else {
            throw new IllegalStateException(
                    "Folder at '" + folderLocation + "' is not allowed to add a document.");
        }
    } catch (Exception e) {
        getLogger().error("Failed to add a document with '{}' under '{}'.", nodeName, folderLocation, e);
        throw new DocumentManagerException(
                "Failed to add a document with '" + nodeName + "' under '" + folderLocation + "'." + "'. " + e,
                e);
    }

    return createdDocPath;
}

From source file:org.onehippo.forge.content.exim.core.impl.WorkflowDocumentManagerImpl.java

/**
 * {@inheritDoc}/*from   www.  j  av  a2s.  co  m*/
 */
@Override
public Document obtainEditableDocument(final Node documentHandleNode) throws DocumentManagerException {

    if (documentHandleNode == null) {
        throw new IllegalArgumentException("Document handle node may not be null");
    }

    String handlePath = "";
    try {
        handlePath = documentHandleNode.getPath();
        getLogger().debug("##### obtainEditableDocument for path {}", handlePath);

        final DocumentWorkflow documentWorkflow = getDocumentWorkflow(documentHandleNode);
        final Boolean obtainEditableInstance = (Boolean) documentWorkflow.hints().get("obtainEditableInstance");

        if (BooleanUtils.isTrue(obtainEditableInstance)) {
            return documentWorkflow.obtainEditableInstance();
        } else {
            throw new IllegalStateException(
                    "Document at '" + handlePath + "' is not allowed to obtain an editable instance.");
        }
    } catch (Exception e) {
        final String message = "Failed to obtain editable instance for document '" + handlePath + "'";
        getLogger().error(message, e);
        throw new DocumentManagerException(message, e);
    }
}

From source file:org.onehippo.forge.content.exim.core.impl.WorkflowDocumentManagerImpl.java

/**
 * Discards the draft variant which is currently being edited.
 *//*from   w w w  .j ava  2 s . c om*/
protected Document disposeEditableDocument(final Node documentHandleNode) throws DocumentManagerException {

    if (documentHandleNode == null) {
        throw new IllegalArgumentException("Document handle node may not be null");
    }

    String handlePath = "";
    try {
        handlePath = documentHandleNode.getPath();

        final DocumentWorkflow documentWorkflow = getDocumentWorkflow(documentHandleNode);
        final Boolean disposeEditableInstance = (Boolean) documentWorkflow.hints()
                .get("disposeEditableInstance");

        if (BooleanUtils.isTrue(disposeEditableInstance)) {
            return documentWorkflow.disposeEditableInstance();
        } else {
            throw new IllegalStateException(
                    "Document at '" + handlePath + "' is not allowed to dispose an editable instance.");
        }
    } catch (Exception e) {
        final String message = "Failed to dispose editable instance on document '" + handlePath + "'";
        getLogger().error(message, e);
        throw new DocumentManagerException(message, e);
    }
}

From source file:org.onehippo.forge.content.exim.core.impl.WorkflowDocumentManagerImpl.java

/**
 * Commits the draft variant which is currently being edited.
 *//*  ww  w .j  a va 2 s  . c o  m*/
protected Document commitEditableDocument(final Node documentHandleNode) throws DocumentManagerException {

    if (documentHandleNode == null) {
        throw new IllegalArgumentException("Document handle node may not be null");
    }

    String handlePath = "";
    try {
        handlePath = documentHandleNode.getPath();

        final DocumentWorkflow documentWorkflow = getDocumentWorkflow(documentHandleNode);
        final Boolean commitEditableInstance = (Boolean) documentWorkflow.hints().get("commitEditableInstance");

        if (BooleanUtils.isTrue(commitEditableInstance)) {
            return documentWorkflow.commitEditableInstance();
        } else {
            throw new IllegalStateException(
                    "Document at '" + handlePath + "' is not allowed to commit an editable instance.");
        }
    } catch (Exception e) {
        final String message = "Failed to commit editable instance on document '" + handlePath + "'";
        getLogger().error(message, e);
        throw new DocumentManagerException(message, e);
    }
}

From source file:org.onehippo.forge.content.exim.core.impl.WorkflowDocumentManagerImpl.java

/**
 * {@inheritDoc}//from   w ww  .jav  a 2 s  .com
 */
@Override
public boolean publishDocument(String documentLocation) throws DocumentManagerException {
    getLogger().debug("##### publishDocument('{}')", documentLocation);

    if (StringUtils.isBlank(documentLocation)) {
        throw new IllegalArgumentException("Invalid document location: '" + documentLocation + "'.");
    }

    boolean published = false;

    try {
        final Node documentHandleNode = getExistingDocumentHandleNode(documentLocation);
        DocumentWorkflow documentWorkflow = getDocumentWorkflow(documentHandleNode);
        Boolean publish = (Boolean) documentWorkflow.hints().get("publish");

        if (!BooleanUtils.isTrue(publish)) {
            throw new IllegalStateException(
                    "Document at '" + documentLocation + "' doesn't have publish action.");
        }

        documentWorkflow.publish();
        published = true;
    } catch (RepositoryException | WorkflowException | RemoteException e) {
        getLogger().error("Failed to publish document at '{}'.", documentLocation, e);
        throw new DocumentManagerException("Failed to publish document at '" + documentLocation + "'. " + e, e);
    }

    return published;
}

From source file:org.onehippo.forge.content.exim.core.impl.WorkflowDocumentManagerImpl.java

/**
 * {@inheritDoc}/*from w  w  w  .j  a  v a 2 s .com*/
 */
@Override
public boolean depublishDocument(String documentLocation) throws DocumentManagerException {
    getLogger().debug("##### depublishDocument('{}')", documentLocation);

    if (StringUtils.isBlank(documentLocation)) {
        throw new IllegalArgumentException("Invalid document location: '" + documentLocation + "'.");
    }

    boolean depublished = false;

    try {
        final Node documentHandleNode = getExistingDocumentHandleNode(documentLocation);
        DocumentWorkflow documentWorkflow = getDocumentWorkflow(documentHandleNode);
        Boolean isLive = (Boolean) documentWorkflow.hints().get("isLive");

        if (BooleanUtils.isFalse(isLive)) {
            // already offline, so just return true
            depublished = true;
        } else {
            Boolean depublish = (Boolean) documentWorkflow.hints().get("depublish");

            if (!BooleanUtils.isTrue(depublish)) {
                throw new IllegalStateException(
                        "Document at '" + documentLocation + "' doesn't have depublish action.");
            }

            documentWorkflow.depublish();
            depublished = true;
        }
    } catch (RepositoryException | WorkflowException | RemoteException e) {
        getLogger().error("Failed to depublish document at '{}'.", documentLocation, e);
        throw new DocumentManagerException("Failed to depublish document at '" + documentLocation + "'. " + e,
                e);
    }

    return depublished;
}

From source file:org.onehippo.forge.content.exim.core.impl.WorkflowDocumentManagerImpl.java

/**
 * {@inheritDoc}/* w  ww.j av  a 2  s  .c o m*/
 */
@Override
public void deleteDocument(String documentLocation) throws DocumentManagerException {
    getLogger().debug("##### deleteDocument('{}')", documentLocation);

    if (StringUtils.isBlank(documentLocation)) {
        throw new IllegalArgumentException("Invalid document location: '" + documentLocation + "'.");
    }

    try {
        final Node documentHandleNode = getExistingDocumentHandleNode(documentLocation);
        DocumentWorkflow documentWorkflow = getDocumentWorkflow(documentHandleNode);
        Boolean delete = (Boolean) documentWorkflow.hints().get("delete");

        if (BooleanUtils.isTrue(delete)) {
            documentWorkflow.delete();
        } else {
            throw new IllegalStateException("Document at '" + documentLocation + "' is not allowed to delete.");
        }
    } catch (RepositoryException | WorkflowException | RemoteException e) {
        getLogger().error("Failed to depublish document at '{}'.", documentLocation, e);
        throw new DocumentManagerException("Failed to depublish document at '" + documentLocation + "'. " + e,
                e);
    }
}

From source file:org.onehippo.forge.content.exim.core.impl.WorkflowDocumentManagerImpl.java

/**
 * {@inheritDoc}/*from  w ww  .  jav a  2  s  .  c  o  m*/
 */
@Override
public String copyDocument(String sourceDocumentLocation, String targetFolderLocation,
        String targetDocumentNodeName) throws DocumentManagerException {
    getLogger().debug("##### copyDocument('{}', '{}', '{}')", sourceDocumentLocation, targetFolderLocation,
            targetDocumentNodeName);

    String targetDocumentLocation = null;

    try {
        final Node sourceDocumentHandleNode = getExistingDocumentHandleNode(sourceDocumentLocation);
        final Node targetFolderNode = HippoNodeUtils.createMissingHippoFolders(getSession(), ContentPathUtils
                .encodeNodePath(ContentPathUtils.removeIndexNotationInNodePath(targetFolderLocation)));

        if (targetFolderNode == null) {
            throw new IllegalArgumentException(
                    "Target folder doesn't exist at '" + targetFolderLocation + "'.");
        }

        if (!targetFolderNode.isNodeType(HippoStdNodeType.NT_FOLDER)) {
            throw new IllegalStateException(
                    "Invalid folder found at '" + targetFolderLocation + "', not 'hippostd:folder' type.");
        }

        DocumentWorkflow documentWorkflow = getDocumentWorkflow(sourceDocumentHandleNode);
        Boolean copy = (Boolean) documentWorkflow.hints().get("copy");

        if (BooleanUtils.isTrue(copy)) {
            documentWorkflow.copy(new Document(targetFolderNode), targetDocumentNodeName);
            targetDocumentLocation = targetFolderNode.getNode(targetDocumentNodeName).getPath();
        } else {
            throw new IllegalStateException(
                    "Copy action not available on document at '" + sourceDocumentLocation + "' to '"
                            + targetFolderLocation + "/" + targetDocumentNodeName + "'.");
        }
    } catch (RepositoryException | WorkflowException | RemoteException e) {
        getLogger().error("Failed to copy document at '{}' to '{}/{}'.", sourceDocumentLocation,
                targetFolderLocation, targetDocumentNodeName, e);
        throw new DocumentManagerException("Failed to copy document at '" + sourceDocumentLocation + "' to '"
                + targetFolderLocation + "/" + targetDocumentNodeName + "'. " + e, e);
    }

    return targetDocumentLocation;
}

From source file:org.opencastproject.index.service.impl.index.event.Event.java

private void updateEventStatus() {
    if (getWorkflowId() != null) {
        eventStatus = workflowStatusMapping.get(getWorkflowState());
        return;/*from  ww w  .j a  v a  2  s . c  om*/
    }

    if (getRecordingStatus() != null) {
        eventStatus = recordingStatusMapping.get(getRecordingStatus());
        return;
    }

    if (BooleanUtils.isTrue(getBlacklisted())) {
        eventStatus = "EVENTS.EVENTS.STATUS.BLACKLISTED";
        return;
    }

    if (BooleanUtils.isTrue(getOptedOut())) {
        eventStatus = "EVENTS.EVENTS.STATUS.OPTEDOUT";
        return;
    }

    eventStatus = "EVENTS.EVENTS.STATUS.SCHEDULED";
}