Search in sources :

Example 76 with ChildAssociationRef

use of org.alfresco.service.cmr.repository.ChildAssociationRef in project records-management by Alfresco.

the class RecordServiceImplUnitTest method onCreateChildAssociationNewRecord.

/**
 * Given that a new record is being created
 * When the behaviour is triggered
 * Then the record is stored for later reference in the transaction
 */
@SuppressWarnings("unchecked")
@Test
public void onCreateChildAssociationNewRecord() {
    // standard content node
    NodeRef nodeRef = generateCmContent("test.txt");
    ChildAssociationRef assoc = generateChildAssociationRef(generateNodeRef(), nodeRef);
    doNothing().when(recordService).file(nodeRef);
    // doesn't have no content aspect
    when(mockedNodeService.hasAspect(nodeRef, ContentModel.ASPECT_NO_CONTENT)).thenReturn(false);
    Set<Object> values = mock(HashSet.class);
    when(mockedTransactionalResourceHelper.getSet(RecordServiceImpl.KEY_NEW_RECORDS)).thenReturn(values);
    // trigger behaviour
    recordService.onCreateChildAssociation(assoc, true);
    // verify
    verify(values, times(1)).add(nodeRef);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) BaseUnitTest(org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest) Test(org.junit.Test)

Example 77 with ChildAssociationRef

use of org.alfresco.service.cmr.repository.ChildAssociationRef in project records-management by Alfresco.

the class BroadcastDispositionActionDefinitionUpdateActionUnitTest method testChangePeriodProperty.

/**
 * Check that changing the period property triggers a recalculation of the "disposition as of" date.
 * <p>
 * Set up a disposition action definition node under a schedule defintion node, under a category node. Create a
 * record whose next action is an instance of the action definition. Check that if the "period property" of the
 * action definition changes then the "disposition as of" date is recalculated and persisted against the node of the
 * next action.
 */
@Test
public void testChangePeriodProperty() {
    // Set up the action definition node.
    String definitionNodeId = "definitionNodeId";
    NodeRef definitionNode = new NodeRef("definition://node/" + definitionNodeId);
    DispositionSchedule mockDispositionSchedule = mock(DispositionSchedule.class);
    when(mockDispositionSchedule.getNodeRef()).thenReturn(definitionNode);
    when(mockNodeService.getType(definitionNode)).thenReturn(TYPE_DISPOSITION_ACTION_DEFINITION);
    // Set up the schedule definition node hierarchy.
    NodeRef categoryNode = new NodeRef("category://node/");
    NodeRef scheduleNode = new NodeRef("schedule://node/");
    ChildAssociationRef scheduleDefinitionRelationship = new ChildAssociationRef(null, scheduleNode, null, definitionNode);
    when(mockNodeService.getPrimaryParent(definitionNode)).thenReturn(scheduleDefinitionRelationship);
    ChildAssociationRef categoryScheduleRelationship = new ChildAssociationRef(null, categoryNode, null, scheduleNode);
    when(mockNodeService.getPrimaryParent(scheduleNode)).thenReturn(categoryScheduleRelationship);
    // Set up the record/step relationship.
    NodeRef recordNode = new NodeRef("record://node/");
    NodeRef stepNode = new NodeRef("step://node/");
    ChildAssociationRef recordStepRelationship = new ChildAssociationRef(null, recordNode, null, stepNode);
    when(mockNodeService.getPrimaryParent(stepNode)).thenReturn(recordStepRelationship);
    // Set up the disposition schedule.
    when(mockDispositionService.getAssociatedDispositionSchedule(categoryNode)).thenReturn(mockDispositionSchedule);
    when(mockDispositionService.getDisposableItems(mockDispositionSchedule)).thenReturn(asList(recordNode));
    when(mockDispositionService.getDispositionSchedule(recordNode)).thenReturn(mockDispositionSchedule);
    // Set up the record.
    when(mockNodeService.hasAspect(recordNode, ASPECT_DISPOSITION_LIFECYCLE)).thenReturn(true);
    // Set up the next disposition action.
    DispositionAction nextAction = mock(DispositionAction.class);
    when(nextAction.getId()).thenReturn(definitionNodeId);
    when(nextAction.getNodeRef()).thenReturn(stepNode);
    when(mockDispositionService.getNextDispositionAction(recordNode)).thenReturn(nextAction);
    DispositionActionDefinition mockActionDefinition = mock(DispositionActionDefinition.class);
    when(nextAction.getDispositionActionDefinition()).thenReturn(mockActionDefinition);
    // Set up the action so that it looks like the period property has been changed.
    Action mockAction = mock(Action.class);
    when(mockAction.getParameterValue(CHANGED_PROPERTIES)).thenReturn((Serializable) asList(PROP_DISPOSITION_PERIOD_PROPERTY));
    // Set up the expected "as of" date.
    Date newAsOfDate = new Date(123456789000L);
    when(mockDispositionService.calculateAsOfDate(recordNode, mockActionDefinition)).thenReturn(newAsOfDate);
    // Call the method under test.
    action.executeImpl(mockAction, definitionNode);
    // Check that the "as of" date is updated.
    verify(mockNodeService).setProperty(stepNode, PROP_DISPOSITION_AS_OF, newAsOfDate);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Action(org.alfresco.service.cmr.action.Action) DispositionAction(org.alfresco.module.org_alfresco_module_rm.disposition.DispositionAction) DispositionSchedule(org.alfresco.module.org_alfresco_module_rm.disposition.DispositionSchedule) DispositionActionDefinition(org.alfresco.module.org_alfresco_module_rm.disposition.DispositionActionDefinition) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) DispositionAction(org.alfresco.module.org_alfresco_module_rm.disposition.DispositionAction) Date(java.util.Date) Test(org.junit.Test)

Example 78 with ChildAssociationRef

use of org.alfresco.service.cmr.repository.ChildAssociationRef in project records-management by Alfresco.

the class BroadcastDispositionActionDefinitionUpdateActionUnitTest method setUp.

/**
 * Inject the mock services into the class under test and link the content and next action nodes.
 */
@Before
public void setUp() {
    action.setNodeService(mockNodeService);
    action.setDispositionService(mockDispositionService);
    action.setBehaviourFilter(mockBehaviourFilter);
    ChildAssociationRef mockAssocRef = mock(ChildAssociationRef.class);
    when(mockNodeService.getPrimaryParent(NEXT_ACTION_NODE_REF)).thenReturn(mockAssocRef);
    when(mockAssocRef.getParentRef()).thenReturn(CONTENT_NODE_REF);
}
Also used : ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) Before(org.junit.Before)

Example 79 with ChildAssociationRef

use of org.alfresco.service.cmr.repository.ChildAssociationRef in project records-management by Alfresco.

the class DispositionServiceImpl method getDispositionActionDate.

public Date getDispositionActionDate(NodeRef record, NodeRef dispositionSchedule, String dispositionActionName) {
    DispositionSchedule ds = new DispositionScheduleImpl(serviceRegistry, nodeService, dispositionSchedule);
    List<ChildAssociationRef> assocs = nodeService.getChildAssocs(dispositionSchedule);
    if (assocs != null && !assocs.isEmpty()) {
        for (ChildAssociationRef assoc : assocs) {
            if (assoc != null && assoc.getQName().getLocalName().contains(dispositionActionName)) {
                DispositionActionDefinition actionDefinition = ds.getDispositionActionDefinition(assoc.getChildRef().getId());
                return calculateAsOfDate(record, actionDefinition);
            }
        }
    }
    return null;
}
Also used : ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef)

Example 80 with ChildAssociationRef

use of org.alfresco.service.cmr.repository.ChildAssociationRef in project records-management by Alfresco.

the class DispositionServiceImpl method isNextDispositionActionEligible.

/**
 * @see org.alfresco.module.org_alfresco_module_rm.disposition.DispositionService#isNextDispositionActionEligible(org.alfresco.service.cmr.repository.NodeRef)
 */
@Override
public boolean isNextDispositionActionEligible(NodeRef nodeRef) {
    boolean result = false;
    // Get the disposition instructions
    DispositionSchedule di = getDispositionSchedule(nodeRef);
    NodeRef nextDa = getNextDispositionActionNodeRef(nodeRef);
    if (di != null && this.nodeService.hasAspect(nodeRef, ASPECT_DISPOSITION_LIFECYCLE) && nextDa != null) {
        // If it has an asOf date and it is greater than now the action is eligible
        Date asOf = (Date) this.nodeService.getProperty(nextDa, PROP_DISPOSITION_AS_OF);
        if (asOf != null && asOf.before(new Date())) {
            result = true;
        }
        if (!result) {
            DispositionAction da = new DispositionActionImpl(serviceRegistry, nextDa);
            DispositionActionDefinition dad = da.getDispositionActionDefinition();
            if (dad != null) {
                boolean firstComplete = dad.eligibleOnFirstCompleteEvent();
                List<ChildAssociationRef> assocs = this.nodeService.getChildAssocs(nextDa, ASSOC_EVENT_EXECUTIONS, RegexQNamePattern.MATCH_ALL);
                for (ChildAssociationRef assoc : assocs) {
                    NodeRef eventExecution = assoc.getChildRef();
                    Boolean isCompleteValue = (Boolean) this.nodeService.getProperty(eventExecution, PROP_EVENT_EXECUTION_COMPLETE);
                    boolean isComplete = false;
                    if (isCompleteValue != null) {
                        isComplete = isCompleteValue.booleanValue();
                        // implement AND and OR combination of event completions
                        if (isComplete) {
                            result = true;
                            if (firstComplete) {
                                break;
                            }
                        } else {
                            result = false;
                            if (!firstComplete) {
                                break;
                            }
                        }
                    }
                }
            }
        }
    }
    return result;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) Date(java.util.Date)

Aggregations

ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)260 NodeRef (org.alfresco.service.cmr.repository.NodeRef)204 QName (org.alfresco.service.namespace.QName)110 Test (org.junit.Test)57 HashMap (java.util.HashMap)54 BaseUnitTest (org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest)53 ArrayList (java.util.ArrayList)52 Serializable (java.io.Serializable)42 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)25 FacesContext (javax.faces.context.FacesContext)22 Map (java.util.Map)19 UserTransaction (javax.transaction.UserTransaction)18 Node (org.alfresco.web.bean.repository.Node)17 Date (java.util.Date)15 StoreRef (org.alfresco.service.cmr.repository.StoreRef)13 NodeService (org.alfresco.service.cmr.repository.NodeService)12 SiteInfo (org.alfresco.service.cmr.site.SiteInfo)12 List (java.util.List)11 StringPropertyValue (org.alfresco.solr.client.StringPropertyValue)11 IOException (java.io.IOException)10