0

I want to create an Alfresco Webservice in Java that create a Folder with a specific rule. Until now the webservice creates the folder and the rule. The problem is that I want to add an actionCondition to my rule that do the same job as "Unless all criteria are met" when you try to create the rule in Alfresco Share.

I want to move all the documents to other folder unless this document is an HMTL.

There is a

CompareMimeTypeEvaluator.class

But it performs the "If all criteria are met" and I want the opposite.

What I did is I created a this Comparator:

public class CompareMismatchEvaluator extends ActionConditionEvaluatorAbstractBase
{

private static Log logger = LogFactory.getLog(CompareMismatchEvaluator.class);

/**
 * Evaluator constants
 */
public static final String NAME = "compare-mime-type";
public static final String PARAM_PROPERTY = "property";
public static final String PARAM_VALUE = "value";

/**
 * 
 */
private static final String ERRID_NOT_A_CONTENT_TYPE = "compare_mime_type_evaluator.not_a_content_type";
private static final String ERRID_NO_PROPERTY_DEFINTION_FOUND = "compare_mime_type_evaluator.no_property_definition_found";

private NodeService nodeService; 

/**
 * @see org.alfresco.repo.action.evaluator.ActionConditionEvaluatorAbstractBase#evaluateImpl(org.alfresco.service.cmr.action.ActionCondition, org.alfresco.service.cmr.repository.NodeRef)
 */
@Override
public boolean evaluateImpl(ActionCondition actionCondition, NodeRef actionedUponNodeRef)
{
    QName propertyQName = (QName) actionCondition.getParameterValue(PARAM_PROPERTY);
    // Get the original value and the value to match
    Serializable propertyValue = nodeService.getProperty(actionedUponNodeRef, propertyQName);
    Serializable compareValue = actionCondition.getParameterValue(PARAM_VALUE);

    logger.debug("Comparing : " + propertyValue + " - - - " + compareValue);
    return !propertyValue.equals(compareValue);

}

/**
 * @see org.alfresco.repo.action.ParameterizedItemAbstractBase#addParameterDefinitions(java.util.List)
 */
@Override
protected void addParameterDefinitions(List<ParameterDefinition> paramList) 
{
    paramList.add(new ParameterDefinitionImpl(PARAM_PROPERTY, DataTypeDefinition.QNAME, false, getParamDisplayLabel(PARAM_PROPERTY)));
    paramList.add(new ParameterDefinitionImpl(PARAM_VALUE, DataTypeDefinition.ANY, true, getParamDisplayLabel(PARAM_VALUE), false, "ac-mimetypes"));                
}

}

But this comparator gives the same result as CompareMimeTypeEvaluator.class. So any idea how to get this right ?

deltascience
  • 3,321
  • 5
  • 42
  • 71

1 Answers1

0

I found the solution. You don't have to create your own Comparator, just use the CompareMimeTypeEvaluator.class and set a boolean parameter in the actionCondition to true :

ActionCondition actionCondition = actionService
            .createActionCondition(CompareMimeTypeEvaluator.NAME);

    Map<String, Serializable> conditionParameters = new HashMap<String, Serializable>();
    conditionParameters.put(CompareMimeTypeEvaluator.PARAM_PROPERTY,
            ContentModel.PROP_CONTENT);
    conditionParameters.put(CompareMimeTypeEvaluator.PARAM_VALUE,
            MimetypeMap.MIMETYPE_HTML);
    actionCondition.setInvertCondition(true);
    actionCondition.setParameterValues(conditionParameters);
    compositeAction.addActionCondition(actionCondition);

What changed is that I added this line

 actionCondition.setInvertCondition(true);

This will do the run the action for all items unless this item is an HTML document.

deltascience
  • 3,321
  • 5
  • 42
  • 71