05-01-2012 10:51 AM
Buildfile: /home/control/workspace/try2/advanced-workflow-article/build.xml
setup:
[mkdir] Created dir: /home/control/workspace/try2/advanced-workflow-article/build
compile:
[mkdir] Created dir: /home/control/workspace/try2/advanced-workflow-article/bin
[javac] /home/control/workspace/try2/advanced-workflow-article/build.xml:51: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
[javac] Compiling 12 source files to /home/control/workspace/try2/advanced-workflow-article/bin
[javac] warning: [options] bootstrap class path not set in conjunction with -source 1.5
[javac] /home/control/workspace/try2/advanced-workflow-article/src/com/someco/scripts/GetReview.java:7: error: package org.alfresco.web.scripts does not exist
[javac] import org.alfresco.web.scripts.WebScriptRequest;
[javac] ^
[javac] /home/control/workspace/try2/advanced-workflow-article/src/com/someco/scripts/GetReview.java:8: error: package org.alfresco.web.scripts does not exist
[javac] import org.alfresco.web.scripts.WebScriptStatus;
[javac] ^
[javac] /home/control/workspace/try2/advanced-workflow-article/src/com/someco/scripts/GetReview.java:16: error: package org.alfresco.web.scripts does not exist
[javac] public class GetReview extends org.alfresco.web.scripts.DeclarativeWebScript {
[javac] ^
[javac] /home/control/workspace/try2/advanced-workflow-article/src/com/someco/scripts/GetReview.java:23: error: cannot find symbol
[javac] protected Map<String, Object> executeImpl(WebScriptRequest req, WebScriptStatus status) {
[javac] ^
[javac] symbol: class WebScriptRequest
[javac] location: class GetReview
[javac] /home/control/workspace/try2/advanced-workflow-article/src/com/someco/scripts/GetReview.java:23: error: cannot find symbol
[javac] protected Map<String, Object> executeImpl(WebScriptRequest req, WebScriptStatus status) {
[javac] ^
[javac] symbol: class WebScriptStatus
[javac] location: class GetReview
[javac] /home/control/workspace/try2/advanced-workflow-article/src/com/someco/scripts/PostRating.java:7: error: package org.alfresco.web.scripts does not exist
[javac] import org.alfresco.web.scripts.WebScriptRequest;
[javac] ^
[javac] /home/control/workspace/try2/advanced-workflow-article/src/com/someco/scripts/PostRating.java:8: error: package org.alfresco.web.scripts does not exist
[javac] import org.alfresco.web.scripts.WebScriptStatus;
[javac] ^
[javac] /home/control/workspace/try2/advanced-workflow-article/src/com/someco/scripts/PostRating.java:19: error: package org.alfresco.web.scripts does not exist
[javac] public class PostRating extends org.alfresco.web.scripts.DeclarativeWebScript {
[javac] ^
[javac] /home/control/workspace/try2/advanced-workflow-article/src/com/someco/scripts/PostRating.java:26: error: cannot find symbol
[javac] protected Map<String, Object> executeImpl(WebScriptRequest req, WebScriptStatus status) {
[javac] ^
[javac] symbol: class WebScriptRequest
[javac] location: class PostRating
[javac] /home/control/workspace/try2/advanced-workflow-article/src/com/someco/scripts/PostRating.java:26: error: cannot find symbol
[javac] protected Map<String, Object> executeImpl(WebScriptRequest req, WebScriptStatus status) {
[javac] ^
[javac] symbol: class WebScriptStatus
[javac] location: class PostRating
[javac] /home/control/workspace/try2/advanced-workflow-article/src/com/someco/behavior/Rating.java:136: error: cannot find symbol
[javac] String currentUser = AuthenticationUtil.getCurrentUserName();
[javac] ^
[javac] symbol: method getCurrentUserName()
[javac] location: class AuthenticationUtil
[javac] /home/control/workspace/try2/advanced-workflow-article/src/com/someco/behavior/Rating.java:139: error: cannot find symbol
[javac] AuthenticationUtil.setCurrentUser("admin");
[javac] ^
[javac] symbol: method setCurrentUser(String)
[javac] location: class AuthenticationUtil
[javac] /home/control/workspace/try2/advanced-workflow-article/src/com/someco/behavior/Rating.java:171: error: cannot find symbol
[javac] if (switchUser) AuthenticationUtil.setCurrentUser(currentUser);
[javac] ^
[javac] symbol: method setCurrentUser(String)
[javac] location: class AuthenticationUtil
[javac] /home/control/workspace/try2/advanced-workflow-article/src/com/someco/scripts/GetReview.java:22: error: method does not override or implement a method from a supertype
[javac] @Override
[javac] ^
[javac] /home/control/workspace/try2/advanced-workflow-article/src/com/someco/scripts/PostRating.java:25: error: method does not override or implement a method from a supertype
[javac] @Override
[javac] ^
[javac] 15 errors
[javac] 1 warning
BUILD FAILED
/home/control/workspace/try2/advanced-workflow-article/build.xml:51: Compile failed; see the compiler error output for details.
Total time: 7 seconds
05-01-2012 12:27 PM
import org.springframework.extensions.webscripts.DeclarativeWebScript;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptRequest;
Jeff
05-01-2012 04:42 PM
Buildfile: /home/control/workspace/try2/advanced-workflow-article/build.xml
setup:
compile:
[javac] /home/control/workspace/try2/advanced-workflow-article/build.xml:51: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
[javac] Compiling 12 source files to /home/control/workspace/try2/advanced-workflow-article/bin
[javac] warning: [options] bootstrap class path not set in conjunction with -source 1.5
[javac] /home/control/workspace/try2/advanced-workflow-article/src/com/someco/scripts/GetReview.java:25: error: cannot find symbol
[javac] protected Map<String, Object> executeImpl(WebScriptRequest req, WebScriptStatus status) {
[javac] ^
[javac] symbol: class WebScriptStatus
[javac] location: class GetReview
[javac] /home/control/workspace/try2/advanced-workflow-article/src/com/someco/scripts/PostRating.java:26: error: cannot find symbol
[javac] protected Map<String, Object> executeImpl(WebScriptRequest req, WebScriptStatus status) {
[javac] ^
[javac] symbol: class WebScriptStatus
[javac] location: class PostRating
[javac] /home/control/workspace/try2/advanced-workflow-article/src/com/someco/behavior/Rating.java:136: error: cannot find symbol
[javac] String currentUser = AuthenticationUtil.getCurrentUserName();
[javac] ^
[javac] symbol: method getCurrentUserName()
[javac] location: class AuthenticationUtil
[javac] /home/control/workspace/try2/advanced-workflow-article/src/com/someco/behavior/Rating.java:139: error: cannot find symbol
[javac] AuthenticationUtil.setCurrentUser("admin");
[javac] ^
[javac] symbol: method setCurrentUser(String)
[javac] location: class AuthenticationUtil
[javac] /home/control/workspace/try2/advanced-workflow-article/src/com/someco/behavior/Rating.java:171: error: cannot find symbol
[javac] if (switchUser) AuthenticationUtil.setCurrentUser(currentUser);
[javac] ^
[javac] symbol: method setCurrentUser(String)
[javac] location: class AuthenticationUtil
[javac] /home/control/workspace/try2/advanced-workflow-article/src/com/someco/scripts/PostRating.java:38: error: cannot find symbol
[javac] NodeRef curNode = new NodeRef("workspace://SpacesStore/" + id);
[javac] ^
[javac] symbol: class NodeRef
[javac] location: class PostRating
[javac] /home/control/workspace/try2/advanced-workflow-article/src/com/someco/scripts/PostRating.java:38: error: cannot find symbol
[javac] NodeRef curNode = new NodeRef("workspace://SpacesStore/" + id);
[javac] ^
[javac] symbol: class NodeRef
[javac] location: class PostRating
[javac] Note: Some input files use or override a deprecated API.
[javac] Note: Recompile with -Xlint:deprecation for details.
[javac] 7 errors
[javac] 1 warning
BUILD FAILED
/home/control/workspace/try2/advanced-workflow-article/build.xml:51: Compile failed; see the compiler error output for details.
Total time: 3 seconds
05-01-2012 05:20 PM
05-02-2012 02:46 PM
05-02-2012 03:08 PM
Buildfile: /home/control/workspace/try2/advanced-workflow-article/build.xml
setup:
compile:
[javac] /home/control/workspace/try2/advanced-workflow-article/build.xml:51: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
[javac] Compiling 12 source files to /home/control/workspace/try2/advanced-workflow-article/bin
[javac] warning: [options] bootstrap class path not set in conjunction with -source 1.5
[javac] /home/control/workspace/try2/advanced-workflow-article/src/com/someco/scripts/GetReview.java:25: error: cannot find symbol
[javac] protected Map<String, Object> executeImpl(WebScriptRequest req, WebScriptStatus status) {
[javac] ^
[javac] symbol: class WebScriptStatus
[javac] location: class GetReview
[javac] /home/control/workspace/try2/advanced-workflow-article/src/com/someco/scripts/PostRating.java:26: error: cannot find symbol
[javac] protected Map<String, Object> executeImpl(WebScriptRequest req, WebScriptStatus status) {
[javac] ^
[javac] symbol: class WebScriptStatus
[javac] location: class PostRating
[javac] /home/control/workspace/try2/advanced-workflow-article/src/com/someco/behavior/Rating.java:136: error: cannot find symbol
[javac] String currentUser = AuthenticationUtil.getCurrentUserName();
[javac] ^
[javac] symbol: method getCurrentUserName()
[javac] location: class AuthenticationUtil
[javac] /home/control/workspace/try2/advanced-workflow-article/src/com/someco/behavior/Rating.java:139: error: cannot find symbol
[javac] AuthenticationUtil.setCurrentUser("admin");
[javac] ^
[javac] symbol: method setCurrentUser(String)
[javac] location: class AuthenticationUtil
[javac] /home/control/workspace/try2/advanced-workflow-article/src/com/someco/behavior/Rating.java:171: error: cannot find symbol
[javac] if (switchUser) AuthenticationUtil.setCurrentUser(currentUser);
[javac] ^
[javac] symbol: method setCurrentUser(String)
[javac] location: class AuthenticationUtil
[javac] /home/control/workspace/try2/advanced-workflow-article/src/com/someco/scripts/PostRating.java:38: error: cannot find symbol
[javac] NodeRef curNode = new NodeRef("workspace://SpacesStore/" + id);
[javac] ^
[javac] symbol: class NodeRef
[javac] location: class PostRating
[javac] /home/control/workspace/try2/advanced-workflow-article/src/com/someco/scripts/PostRating.java:38: error: cannot find symbol
[javac] NodeRef curNode = new NodeRef("workspace://SpacesStore/" + id);
[javac] ^
[javac] symbol: class NodeRef
[javac] location: class PostRating
[javac] Note: Some input files use or override a deprecated API.
[javac] Note: Recompile with -Xlint:deprecation for details.
[javac] 7 errors
[javac] 1 warning
BUILD FAILED
/home/control/workspace/try2/advanced-workflow-article/build.xml:51: Compile failed; see the compiler error output for details.
05-02-2012 03:25 PM
package com.someco.behavior;
import java.util.List;
import org.alfresco.repo.node.NodeServicePolicies;
import org.alfresco.repo.policy.Behaviour;
import org.alfresco.repo.policy.JavaBehaviour;
import org.alfresco.repo.policy.PolicyComponent;
import org.alfresco.repo.policy.Behaviour.NotificationFrequency;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.alfresco.service.transaction.TransactionService;
import org.apache.log4j.Logger;
import com.someco.model.SomeCoModel;
public class Rating
implements NodeServicePolicies.OnDeleteNodePolicy,
NodeServicePolicies.OnCreateNodePolicy {
// Dependencies
private NodeService nodeService;
private PolicyComponent policyComponent;
private TransactionService transactionService;
// Behaviours
private Behaviour onCreateNode;
private Behaviour onDeleteNode;
private Logger logger = Logger.getLogger(Rating.class);
public void init() {
if (logger.isDebugEnabled()) logger.debug("Initializing rateable behaviors");
// Create behaviours
this.onCreateNode = new JavaBehaviour(this, "onCreateNode", NotificationFrequency.TRANSACTION_COMMIT);
this.onDeleteNode = new JavaBehaviour(this, "onDeleteNode", NotificationFrequency.TRANSACTION_COMMIT);
// Bind behaviours to node policies
this.policyComponent.bindClassBehaviour(QName.createQName(NamespaceService.ALFRESCO_URI, "onCreateNode"), SomeCoModel.TYPE_SC_RATING, this.onCreateNode);
this.policyComponent.bindClassBehaviour(QName.createQName(NamespaceService.ALFRESCO_URI, "onDeleteNode"), SomeCoModel.TYPE_SC_RATING, this.onDeleteNode);
}
public void onCreateNode(ChildAssociationRef childAssocRef) {
if (logger.isDebugEnabled()) logger.debug("Inside onCreateNode");
addRating(childAssocRef);
}
public void onDeleteNode(ChildAssociationRef childAssocRef, boolean isNodeArchived) {
if (logger.isDebugEnabled()) logger.debug("Inside onDeleteNode");
recalculateAverage(childAssocRef.getParentRef());
}
/**
* This method adds the rating identified by the target of the specified reference.
* @param childAssocRef
*/
public void addRating(ChildAssociationRef childAssocRef) {
if (logger.isDebugEnabled()) logger.debug("Inside addRating");
// get the parent node
NodeRef parentRef = childAssocRef.getParentRef();
NodeRef childRef = childAssocRef.getChildRef();
if (!nodeService.exists(parentRef) || !nodeService.exists(childRef)) {
logger.debug("One of the nodes no longer exists.");
return;
}
// check the parent to make sure it has the right aspect
if (nodeService.hasAspect(parentRef, SomeCoModel.ASPECT_SC_RATEABLE)) {
// continue, this is what we want
} else {
if (logger.isDebugEnabled()) logger.debug("Rating's parent ref did not have rateable aspect.");
return;
}
Integer total = (Integer)nodeService.getProperty(parentRef, SomeCoModel.PROP_TOTAL_RATING);
if (total == null) total = 0;
Integer count = (Integer)nodeService.getProperty(parentRef, SomeCoModel.PROP_RATING_COUNT);
if (count == null) count = 0;
Integer rating = (Integer)nodeService.getProperty(childRef, SomeCoModel.PROP_RATING);
if (rating == null) rating = 0;
Double average = 0d;
total = total + rating;
count = count + 1;
average = total / new Double(count);
setParentProperties(parentRef, average, total, count);
return;
}
protected void setParentProperties(final NodeRef parentRef, final Double average, final int total, final int count) {
AuthenticationUtil.runAs(new RunAsWork<String>() {
@SuppressWarnings("synthetic-access")
public String doWork() throws Exception {
// store the average on the parent node
nodeService.setProperty(parentRef, SomeCoModel.PROP_AVERAGE_RATING, average);
nodeService.setProperty(parentRef, SomeCoModel.PROP_TOTAL_RATING, total);
nodeService.setProperty(parentRef, SomeCoModel.PROP_RATING_COUNT, count);
if (logger.isDebugEnabled()) logger.debug("Property set");
return "";
}
},
"admin");
}
/**
* This method is used to do a full recalculation of the average by iterating over all
* ratings.
* @param nodeRef
*/
public void recalculateAverage(NodeRef parentRef) {
if (logger.isDebugEnabled()) logger.debug("Inside computeAverage");
// check the parent to make sure it has the right aspect
if (nodeService.hasAspect(parentRef, SomeCoModel.ASPECT_SC_RATEABLE)) {
// continue, this is what we want
} else {
if (logger.isDebugEnabled()) logger.debug("Rating's parent ref did not have rateable aspect.");
return;
}
// get the parent node's children
List<ChildAssociationRef> children = nodeService.getChildAssocs(parentRef);
Double average = 0d;
int total = 0;
// This actually happens when the last rating is deleted
if (children.size() == 0) {
// No children so no work to do
if (logger.isDebugEnabled()) logger.debug("No children found");
} else {
// iterate through the children to compute the total
for (ChildAssociationRef child : children) {
if (!nodeService.exists(child.getChildRef())) {
logger.debug("Child node no longer exists.");
continue;
}
int rating = (Integer)nodeService.getProperty(child.getChildRef(), SomeCoModel.PROP_RATING);
total += rating;
}
// compute the average
average = total / (children.size() / 1.0d);
if (logger.isDebugEnabled()) logger.debug("Computed average:" + average);
}
setParentProperties(parentRef, average, total, children.size());
if (logger.isDebugEnabled()) logger.debug("Property set");
return;
}
public NodeService getNodeService() {
return nodeService;
}
public void setNodeService(NodeService nodeService) {
this.nodeService = nodeService;
}
public PolicyComponent getPolicyComponent() {
return policyComponent;
}
public void setPolicyComponent(PolicyComponent policyComponent) {
this.policyComponent = policyComponent;
}
public TransactionService getTransactionService() {
return transactionService;
}
public void setTransactionService(TransactionService transactionService) {
this.transactionService = transactionService;
}
}
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.