Search in sources :

Example 21 with ActionConditionImpl

use of org.alfresco.repo.action.ActionConditionImpl in project alfresco-repository by Alfresco.

the class IsSubTypeEvaluatorTest method testPass.

@Test
public void testPass() {
    ActionCondition condition = new ActionConditionImpl(ID, IsSubTypeEvaluator.NAME, null);
    condition.setParameterValue(IsSubTypeEvaluator.PARAM_TYPE, ContentModel.TYPE_CONTENT);
    assertTrue(this.evaluator.evaluate(condition, this.nodeRef));
    condition.setParameterValue(IsSubTypeEvaluator.PARAM_TYPE, ContentModel.TYPE_CMOBJECT);
    assertTrue(this.evaluator.evaluate(condition, this.nodeRef));
}
Also used : ActionConditionImpl(org.alfresco.repo.action.ActionConditionImpl) ActionCondition(org.alfresco.service.cmr.action.ActionCondition) BaseSpringTest(org.alfresco.util.BaseSpringTest) Test(org.junit.Test)

Example 22 with ActionConditionImpl

use of org.alfresco.repo.action.ActionConditionImpl in project alfresco-repository by Alfresco.

the class NodeEligibleForRethumbnailingEvaluatorTest method testNodeWithFailedThumbnails.

@Test
public void testNodeWithFailedThumbnails() {
    // A "non-difficult" node is one which is not yet known to be difficult to thumbnail.
    // In other words it is one which has previously failed to thumbnail, but which has not yet
    // hit the retryCount limit for initial retries.
    NodeEligibleForRethumbnailingEvaluator evaluator = (NodeEligibleForRethumbnailingEvaluator) this.applicationContext.getBean(NodeEligibleForRethumbnailingEvaluator.NAME);
    // Evaluate the thumbnail definition which has failed.
    // 
    // 1. A node that has failed once - and more recently than the limit.
    ActionCondition condition = new ActionConditionImpl(GUID.generate(), NodeEligibleForRethumbnailingEvaluator.NAME);
    condition.setParameterValue(NodeEligibleForRethumbnailingEvaluator.PARAM_THUMBNAIL_DEFINITION_NAME, thumbnailDef1.getLocalName());
    condition.setParameterValue(NodeEligibleForRethumbnailingEvaluator.PARAM_RETRY_PERIOD, failureHandlingOptions.getRetryPeriod() * 1000);
    condition.setParameterValue(NodeEligibleForRethumbnailingEvaluator.PARAM_RETRY_COUNT, failureHandlingOptions.getRetryCount());
    condition.setParameterValue(NodeEligibleForRethumbnailingEvaluator.PARAM_QUIET_PERIOD, failureHandlingOptions.getQuietPeriod() * 1000);
    condition.setParameterValue(NodeEligibleForRethumbnailingEvaluator.PARAM_QUIET_PERIOD_RETRIES_ENABLED, true);
    assertFalse(evaluator.evaluate(condition, recentlyFailedNodeRef));
    // 2. A node that has failed once - but longer ago than the lower limit.
    Map<String, FailedThumbnailInfo> failures = thumbnailService.getFailedThumbnails(recentlyFailedNodeRef);
    assertFalse(failures.isEmpty());
    final FailedThumbnailInfo failedThumbnailInfo = failures.get(thumbnailDef1.getLocalName());
    final long timeBeforeTheLimit = new Date().getTime() - (failureHandlingOptions.getRetryPeriod() * 1000l) - 5000l;
    nodeService.setProperty(failedThumbnailInfo.getFailedThumbnailNode(), ContentModel.PROP_FAILED_THUMBNAIL_TIME, timeBeforeTheLimit);
    assertTrue(evaluator.evaluate(condition, recentlyFailedNodeRef));
    // 3. If the same node had failed retryCount times, it would not be eligible.
    // At this point it would be a "difficult" document.
    nodeService.setProperty(failedThumbnailInfo.getFailedThumbnailNode(), ContentModel.PROP_FAILURE_COUNT, failureHandlingOptions.getRetryCount());
    assertFalse(evaluator.evaluate(condition, recentlyFailedNodeRef));
    // 4. If it had failed retryCount times, but its last failure time was more than
    // quietPeriod seconds ago, then it would be eligible.
    final long timeBeforeTheLongLimit = new Date().getTime() - (failureHandlingOptions.getQuietPeriod() * 1000l) - 5000l;
    nodeService.setProperty(failedThumbnailInfo.getFailedThumbnailNode(), ContentModel.PROP_FAILED_THUMBNAIL_TIME, timeBeforeTheLongLimit);
    assertTrue(evaluator.evaluate(condition, recentlyFailedNodeRef));
    // 5. Unless the retries during the quiet period are disabled...
    condition.setParameterValue(NodeEligibleForRethumbnailingEvaluator.PARAM_QUIET_PERIOD_RETRIES_ENABLED, false);
    assertFalse(evaluator.evaluate(condition, recentlyFailedNodeRef));
}
Also used : FailedThumbnailInfo(org.alfresco.service.cmr.thumbnail.FailedThumbnailInfo) ActionConditionImpl(org.alfresco.repo.action.ActionConditionImpl) Date(java.util.Date) ActionCondition(org.alfresco.service.cmr.action.ActionCondition) BaseSpringTest(org.alfresco.util.BaseSpringTest) Test(org.junit.Test)

Aggregations

ActionConditionImpl (org.alfresco.repo.action.ActionConditionImpl)22 BaseSpringTest (org.alfresco.util.BaseSpringTest)16 Test (org.junit.Test)16 ActionCondition (org.alfresco.service.cmr.action.ActionCondition)12 ActionServiceException (org.alfresco.service.cmr.action.ActionServiceException)4 Date (java.util.Date)2 ContentWriter (org.alfresco.service.cmr.repository.ContentWriter)2 JSONObject (org.json.JSONObject)2 NodeRef (org.alfresco.service.cmr.repository.NodeRef)1 FailedThumbnailInfo (org.alfresco.service.cmr.thumbnail.FailedThumbnailInfo)1