10-24-2007 10:43 AM
<action class="org.alfresco.repo.workflow.jbpm.ForEachFork">
<foreach>#{lwf_reviewAssignees}</foreach>
<var>reviewer</var>
</action>
mais au final j'obtiens ceci[Node Type: {http://www.alfresco.org/model/content/1.0}person, Node Aspects: [{http://www.alfresco.org/model/system/1.0}referenceable, {http://www.alfresco.org/model/application/1.0}configurable, {http://www.alfresco.org/model/content/1.0}ownable]]
grâce au code suivant : if (foreach != null) {
List forEachColl = null;
String forEachCollStr = foreach.getTextTrim();
System.out.println("DEBUG FOREACH COLLSTR : " + forEachCollStr);
if (forEachCollStr != null)
{
if (forEachCollStr.startsWith("#{"))
{
String expression = forEachCollStr.substring(2, forEachCollStr.length() -1);
Object eval = AlfrescoJavaScript.executeScript(executionContext, services, expression, null);
System.out.println("DEBUG EVAL : " + eval);
if (eval == null)
{
throw new WorkflowException("forEach expression '" + forEachCollStr + "' evaluates to null");
}
// expression evaluates to string
if (eval instanceof String)
{
String[] forEachStrs = ((String)eval).trim().split(",");
System.out.println("DEBUG FOREACH STR : " + forEachStrs);
forEachColl = new ArrayList(forEachStrs.length);
for (String forEachStr : forEachStrs)
{
forEachColl.add(forEachStr);
System.out.println("DEBUG FOREACH : " + forEachStr);
}
}
// expression evaluates to Node array
else if (eval instanceof Serializable[])
{
Serializable[] nodes = (Serializable[])eval;
System.out.println("DEBUG NODES : " + nodes);
forEachColl = new ArrayList(nodes.length);
for (Serializable node : nodes)
{
System.out.println("DEBUG NODE : " + node);
if (node instanceof NodeRef)
{
forEachColl.add(new JBPMNode((NodeRef)node, services));
}
}
}
// expression evaluates to collection
else if (eval instanceof Collection)
{
forEachColl = (List)eval;
System.out.println("DEBUG forEachColl : " + forEachColl);
}
}
}
else
{
forEachColl = (List)FieldInstantiator.getValue(List.class, foreach);
System.out.println("DEBUG FOREACHCOLL : " + forEachColl);
}
Comment puis-je utiliser ce résultat, pour pouvoir positionner les permissions de lecture en fonction du résultat retourné par cette liste.
10-25-2007 04:53 AM
<action class="org.alfresco.repo.workflow.jbpm.ForEachFork">
<foreach>#{lwf_reviewAssignees}</foreach>
<var>reviewer</var>
</action>
Pour réaliser cette opération, je me suis appuyé sur le code de la classe org.alfresco.repo.workflow.jbpm.AlfrescoAssignment pour pouvoir convertir la variable #{reviewer} en quelquechose d'utilisable par la fonction setPermission.public class SetPermissions extends JBPMSpringActionHandler {
private static final long serialVersionUID = 1L;
private static final Logger logger = Logger.getLogger(SetPermissions.class);
private BeanFactory factory;
private ServiceRegistry services;
// Property names
//public static final QName PROP_DOCUMENT_NAME = QName.createQName("cm","name");
//public static final QName PROP_DOCUMENT_STATUS = QName.createQName("lpr.model","DocumentStatus");
//public static final QName REVIEW_ASSIGNEES = QName.createQName("lwf.workflowModel","reviewAssignees");
public static final String WORKFLOW_USER = "workflow";
public static final String WORKFLOW_PASSWORD = "password";
// Patameters
private AuthorityDAO authorityDAO;
private Element actor;
@Override
protected void initialiseHandler(BeanFactory factory) {
this.factory = factory;
services = (ServiceRegistry)factory.getBean(ServiceRegistry.SERVICE_REGISTRY);
authorityDAO = (AuthorityDAO)factory.getBean("authorityDAO");
}
//@SuppressWarnings(value = "unchecked")
public void execute(ExecutionContext executionContext) throws Exception {
if (actor == null) {
throw new WorkflowException("status has not been provided");
}
System.out.println("===> ACTOR:= " + actor);
// Get the Actor ID
String assignedActor = null;
if (actor != null)
{
String actorValStr = actor.getTextTrim();
if (actorValStr != null && actorValStr.length() > 0)
{
if (actorValStr.startsWith("#{"))
{
String expression = actorValStr.substring(2, actorValStr.length() -1);
Object eval = AlfrescoJavaScript.executeScript(executionContext, services, expression, null);
//System.out.println("===> ACTOR(eval):= " + eval);
if (eval == null)
{
throw new WorkflowException("actor expression '" + actorValStr + "' evaluates to null");
}
String actor = null;
if (eval instanceof String)
{
actor = (String)eval;
//System.out.println("===> ACTOR(String):= " + actor);
}
else if (eval instanceof JBPMNode)
{
actor = mapAuthorityToName((JBPMNode)eval, false);
//System.out.println("===> ACTOR(JBPMNode):= " + actor);
}
if (actor == null)
{
throw new WorkflowException("actor expression must evaluate to a person");
}
assignedActor = actor;
//System.out.println("===> ACTOR(actor):= " + actor);
}
else
{
assignedActor = actorValStr;
System.out.println("===> ACTOR(actorValStr):= " + assignedActor);
}
}
}
System.out.println("===> ACTOR (Assigned):= " + assignedActor);
try {
Object res = executionContext.getContextInstance().getVariable("bpm_package");
if(res == null) {
//never enters here
logger.fatal("bpm_package is null");
return;
}
final NodeRef nodeRef = ((JBPMNode) res).getNodeRef();
if(nodeRef == null) {
//never enters here
logger.fatal("NodeRef is null");
return;
}
NodeService nodeService = (NodeService) this.factory.getBean("nodeService");
NamespaceService namespaceService = (NamespaceService) this.factory.getBean("namespaceService");
PermissionService permissionService = (PermissionService) this.factory.getBean("permissionService");
String DocPath = null;
List<ChildAssociationRef> childRefs = nodeService.getChildAssocs(nodeRef);
for (ChildAssociationRef tchildRef : childRefs) {
final NodeRef childRef = tchildRef.getChildRef();
DocPath = nodeService.getPath(childRef).toPrefixString(namespaceService);
}
Repository repository = (Repository)this.factory.getBean("JCR.Repository");
Session session = null;
try {
// Think to add workflow as administrator on the "authority-service-contxt.xml" file on "classalfresco"
session = repository.login(new SimpleCredentials(WORKFLOW_USER,WORKFLOW_PASSWORD.toCharArray()));
// access the page via JCR
Node rootNode = session.getRootNode();
Node curentNodeRef = rootNode.getNode(DocPath);
// Convert the JCR Node to an Alfresco Node Reference
NodeRef AdminNodeRef = JCRNodeRef.getNodeRef(curentNodeRef);
// Change permission
//permissionService.setInheritParentPermissions(AdminNodeRef, false);
permissionService.setPermission(AdminNodeRef, assignedActor, PermissionService.READ_CONTENT, true);
session.save();
}
finally {
session.save();
session.logout();
}
} catch (Exception e) {
e.printStackTrace();
}
}
private String mapAuthorityToName(ScriptNode authority, boolean allowGroup) {
String name = null;
QName type = authority.getType();
if (type.equals(ContentModel.TYPE_PERSON)) {
name = (String)authority.getProperties().get(ContentModel.PROP_USERNAME);
} else if (type.equals(ContentModel.TYPE_AUTHORITY)) {
name = authorityDAO.getAuthorityName(authority.getNodeRef());
} else if (allowGroup && type.equals(ContentModel.TYPE_AUTHORITY_CONTAINER)) {
name = authorityDAO.getAuthorityName(authority.getNodeRef());
}
return name;
}
}
Cette nouvelle classe est appelé par mon Workflow comme suit :<action class="lpr.alfresco.repo.workflow.jbpm.SetPermissions">
<actor>#{reviewer}</actor>
</action>
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.