Example usage for org.apache.commons.chain Context get

List of usage examples for org.apache.commons.chain Context get

Introduction

In this page you can find the example usage for org.apache.commons.chain Context get.

Prototype

V get(Object key);

Source Link

Document

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

Usage

From source file:org.exoplatform.services.cms.jcrext.activity.EditPropertyActivityAction.java

@Override
public boolean execute(Context context) throws Exception {
    Object item = context.get("currentItem");
    Node node = (item instanceof Property) ? ((Property) item).getParent() : (Node) item;
    Node nodeTemp = activityService.isSpecialContentNodeType((Item) item);
    String propertyName = (item instanceof Property) ? ((Property) item).getName() : ((Node) item).getName();
    if (nodeTemp != null) {
        if (!activityService.isCreating(nodeTemp)) {
            //Consider this special case as changing of content
            String itemPath = ((Item) item).getPath();
            String nodePath = nodeTemp.getPath();
            String referencePath = itemPath.substring(nodePath.length());
            if (referencePath.startsWith("/")) {
                referencePath = referencePath.substring(1);
            }/*  ww w .  ja va2  s  .c o  m*/
            listenerService.broadcast(ActivityCommonService.EDIT_ACTIVITY, nodeTemp, referencePath);
        }
    }
    nodeTemp = node;
    // Do not create / update activity for bellow cases
    if (!activityService.isAcceptedProperties(propertyName))
        return false;
    if (ConversationState.getCurrent() == null)
        return false;

    if (node.isNodeType("nt:resource"))
        node = node.getParent();
    //filter node type
    if (activityService.isAcceptedNode(node)) {
        //Notify to update activity
        if (!activityService.isCreating(node)) {
            listenerService.broadcast(ActivityCommonService.EDIT_ACTIVITY, node, propertyName);
        }
    }
    return false;
}

From source file:org.exoplatform.services.cms.jcrext.activity.RemoveFileActivityAction.java

public boolean execute(Context context) throws Exception {
    if (listenerService == null)
        return false;
    Object item = context.get("currentItem");
    if (item instanceof Node) {
        Node node = (Node) item;
        Node parent = node.getParent();
        if (node.getPrimaryNodeType().isNodeType(ActivityCommonService.NT_FILE)) {
            if (activityService.isAcceptedNode(node) && activityService.isBroadcastNTFileEvents(node)) {
                listenerService.broadcast(ActivityCommonService.FILE_REMOVE_ACTIVITY, parent, node);
            }//from w  w w .  jav a 2s .c  om
        }
    }
    return false;
}

From source file:org.exoplatform.services.cms.jcrext.activity.RemoveFilePropertyActivityAction.java

@Override
public boolean execute(Context context) throws Exception {
    Object item = context.get("currentItem");
    Node node = (item instanceof Property) ? ((Property) item).getParent() : (Node) item;
    Node nodeTemp = node;/*from  ww  w  . j a va2s. com*/
    String propertyName = (item instanceof Property) ? ((Property) item).getName() : ((Node) item).getName();
    // Do not create / update activity for bellow cases
    if (!activityService.isAcceptedFileProperties(propertyName))
        return false;
    if (ConversationState.getCurrent() == null)
        return false;

    if (node.isNodeType("nt:resource"))
        node = node.getParent();
    //filter node type
    if (node.getPrimaryNodeType().getName().equals(NodetypeConstant.NT_FILE)
            && activityService.isBroadcastNTFileEvents(node)) {
        //Notify to update activity
        listenerService.broadcast(ActivityCommonService.FILE_PROPERTY_REMOVE_ACTIVITY, nodeTemp, propertyName);
    }
    return false;
}

From source file:org.exoplatform.services.cms.jcrext.activity.RemoveNodeActivityAction.java

public boolean execute(Context context) throws Exception {
    if (listenerService == null)
        return false;
    Object item = context.get("currentItem");
    if (item instanceof Node) {
        Node node = (Node) item;
        if (node.getPrimaryNodeType().isNodeType(ActivityCommonService.NT_FILE)) {
            Node parent = node.getParent();
            if (activityService.isAcceptedNode(parent)) {
                listenerService.broadcast(ActivityCommonService.ATTACH_REMOVED_ACTIVITY, parent, node);
            }/*from   w  ww.jav a2 s.co m*/
        } else if (activityService.isAcceptedNode(node) && !activityService.isCreating(node)) {
            listenerService.broadcast(ActivityCommonService.NODE_REMOVED_ACTIVITY, node, null);
        }
    }
    return false;
}

From source file:org.exoplatform.services.cms.jcrext.AddDateTimeAction.java

public boolean execute(Context context) throws Exception {
    Node node = (Node) context.get("currentItem");
    if (node.canAddMixin("exo:datetime")) {
        node.addMixin("exo:datetime");
    }/*  w w  w .ja v a  2s  .  com*/
    node.setProperty("exo:dateCreated", new GregorianCalendar());
    node.setProperty("exo:dateModified", new GregorianCalendar());
    return false;
}

From source file:org.exoplatform.services.cms.jcrext.AddNodeNameAction.java

public boolean execute(Context context) throws Exception {
    Object item = context.get("currentItem");
    Node node = (item instanceof Property) ? ((Property) item).getParent() : (Node) item;
    if (node.isNodeType("nt:resource"))
        node = node.getParent();//  w  w  w  .  ja  va2s.  com

    if (node.canAddMixin("exo:sortable")) {
        node.addMixin("exo:sortable");
    }

    if (!node.hasProperty("exo:name")) {
        node.setProperty("exo:name", node.getName());
    }

    if (node.isNodeType(NodetypeConstant.EXO_SYMLINK)) {
        if (!node.hasProperty("exo:title")) {
            node.setProperty("exo:title", Utils.getTitle(node));
        }
    }

    return false;
}

From source file:org.exoplatform.services.cms.jcrext.ModifyNodeAction.java

public boolean execute(Context context) throws Exception {
    Object item = context.get("currentItem");
    Node node = (item instanceof Property) ? ((Property) item).getParent() : (Node) item;
    if (node.isNodeType("nt:resource"))
        node = node.getParent();//from   ww w.  j  a  va2s.  c  o  m
    ConversationState conversationState = ConversationState.getCurrent();
    String userName = (conversationState == null) ? node.getSession().getUserID()
            : conversationState.getIdentity().getUserId();
    if (node.canAddMixin("exo:modify")) {
        node.addMixin("exo:modify");
    }
    node.setProperty("exo:lastModifiedDate", new GregorianCalendar());
    node.setProperty("exo:lastModifier", userName);
    return false;
}

From source file:org.exoplatform.services.cms.jcrext.RemoveNodeAction.java

public boolean execute(Context context) throws Exception {
    thumbnailService = WCMCoreUtils.getService(ThumbnailService.class);

    //remove thumbnail of node
    Node node = (Node) context.get("currentItem");
    if (thumbnailService.isEnableThumbnail()) {
        try {/*from   w  w  w.  ja va  2 s  .  c  om*/
            thumbnailService.processRemoveThumbnail(node);
        } catch (Exception e) {
            return false;
        }
    }
    //remove dead symlinks
    Utils.removeDeadSymlinks(node, false);
    return false;
}

From source file:org.exoplatform.services.command.CommandServiceTest.java

public void testExcecute() throws Exception {

    CommandService cservice = (CommandService) container.getComponentInstanceOfType(CommandService.class);
    Command c1 = cservice.getCatalog().getCommand("Execute2");
    Command c2 = cservice.getCatalog().getCommand("Command1");

    Catalog c = cservice.getCatalog();/*from   ww w  .  ja  v a 2  s.  co m*/

    Context ctx = new ContextBase();
    ctx.put("test", Integer.valueOf(0));
    c1.execute(ctx);
    c2.execute(ctx);
    assertEquals(3, ((Integer) ctx.get("test")).intValue());

}

From source file:org.exoplatform.services.command.TestCommand1.java

public boolean execute(Context ctx) throws Exception {
    int tval = ((Integer) ctx.get("test")).intValue() + 1;
    ctx.put("test", Integer.valueOf(tval));
    return false;
}