Search in sources :

Example 51 with ChildAssociationRef

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

the class RecordsManagementSearchBehaviour method getRecordFolders.

/**
 * Helper method to get the record folders contained in the provided record category.
 *
 * @param recordCategoryNode    record category node reference
 * @return  List<NodeRef>       contained record folders
 */
private List<NodeRef> getRecordFolders(NodeRef recordCategoryNode) {
    List<NodeRef> results = new ArrayList<NodeRef>(8);
    List<ChildAssociationRef> folderAssocs = nodeService.getChildAssocs(recordCategoryNode, ContentModel.ASSOC_CONTAINS, RegexQNamePattern.MATCH_ALL);
    for (ChildAssociationRef folderAssoc : folderAssocs) {
        NodeRef folder = folderAssoc.getChildRef();
        if (recordFolderService.isRecordFolder(folder)) {
            results.add(folder);
        }
    }
    return results;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) ArrayList(java.util.ArrayList) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef)

Example 52 with ChildAssociationRef

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

the class NotificationTemplatePatch_v21 method executePatch.

@Override
protected void executePatch() {
    NodeRef nodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, CONFIG_NODEID);
    // get the parent node
    NodeRef supersededTemplate = notificationHelper.getSupersededTemplate();
    if (!nodeService.exists(nodeRef) && nodeService.exists(supersededTemplate)) {
        NodeRef parent = nodeService.getPrimaryParent(supersededTemplate).getParentRef();
        // build the node properties
        Map<QName, Serializable> props = new HashMap<QName, Serializable>(4);
        props.put(ContentModel.PROP_DESCRIPTION, "Record superseded email template.");
        props.put(ContentModel.PROP_TITLE, "record-rejected-email.ftl");
        props.put(ContentModel.PROP_NAME, "record-rejected-email.ftl");
        props.put(ContentModel.PROP_NODE_UUID, "record_rejected_template");
        // get the assoc qname
        QName assocQName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, QName.createValidLocalName("record-rejected-email.ftl"));
        // create the node
        ChildAssociationRef node = nodeService.createNode(parent, ContentModel.ASSOC_CONTAINS, assocQName, ContentModel.TYPE_CONTENT, props);
        // put the content
        ContentWriter writer = contentService.getWriter(node.getChildRef(), ContentModel.PROP_CONTENT, true);
        InputStream is = getClass().getClassLoader().getResourceAsStream(PATH_REJECTED);
        writer.putContent(is);
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Serializable(java.io.Serializable) ContentWriter(org.alfresco.service.cmr.repository.ContentWriter) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) InputStream(java.io.InputStream) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef)

Example 53 with ChildAssociationRef

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

the class RMv22HoldReportPatch method applyInternal.

/**
 * @see org.alfresco.module.org_alfresco_module_rm.patch.AbstractModulePatch#applyInternal()
 */
@Override
public void applyInternal() {
    if (!nodeService.exists(REPORT)) {
        // get the assoc qname
        QName assocQName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, QName.createValidLocalName("report_rmr_holdReport.html.ftl"));
        // build the node properties
        Map<QName, Serializable> props = new HashMap<QName, Serializable>(4);
        props.put(ContentModel.PROP_DESCRIPTION, "Hold report template.");
        props.put(ContentModel.PROP_TITLE, "Hold Report Template");
        props.put(ContentModel.PROP_NAME, "report_rmr_holdReport.html.ftl");
        props.put(ContentModel.PROP_NODE_UUID, "rmr_holdReport");
        // create the node
        ChildAssociationRef node = nodeService.createNode(REPORT_FOLDER, ContentModel.ASSOC_CONTAINS, assocQName, ContentModel.TYPE_CONTENT, props);
        // put the content
        ContentWriter writer = contentService.getWriter(node.getChildRef(), ContentModel.PROP_CONTENT, true);
        writer.setEncoding("UTF-8");
        writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
        InputStream is = getClass().getClassLoader().getResourceAsStream(REPORT_TEMPLATE_PATH);
        writer.putContent(is);
    }
}
Also used : Serializable(java.io.Serializable) ContentWriter(org.alfresco.service.cmr.repository.ContentWriter) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) InputStream(java.io.InputStream) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef)

Example 54 with ChildAssociationRef

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

the class BaseUnitTest method makeChildrenOf.

/**
 * Helper method to make a number of nodes children of another.
 * <p>
 * Assumes the cm:contains assoc type.
 *
 * @param parent
 * @param children
 */
protected void makeChildrenOf(NodeRef parent, NodeRef... children) {
    List<ChildAssociationRef> assocs = new ArrayList<ChildAssociationRef>(children.length);
    for (NodeRef child : children) {
        assocs.add(new ChildAssociationRef(ContentModel.ASSOC_CONTAINS, parent, generateQName(), child));
        doReturn(assocs).when(mockedNodeService).getParentAssocs(child);
    }
    doReturn(assocs).when(mockedNodeService).getChildAssocs(parent, ContentModel.ASSOC_CONTAINS, RegexQNamePattern.MATCH_ALL);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) ArrayList(java.util.ArrayList) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef)

Example 55 with ChildAssociationRef

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

the class RecordFolderTypeUnitTest method testCreateNonFolderSubType.

/**
 * Given that we try to add non cm:folder sub-type to a record folder,
 * Then IntegrityException is thrown.
 */
@Test(expected = IntegrityException.class)
public void testCreateNonFolderSubType() throws Exception {
    NodeRef recordFolderNodeRef = AlfMock.generateNodeRef(mockedNodeService, TYPE_RECORD_FOLDER);
    QName type = AlfMock.generateQName();
    when(mockedDictionaryService.isSubClass(type, TYPE_FOLDER)).thenReturn(false);
    NodeRef nodeRef = AlfMock.generateNodeRef(mockedNodeService, type, true);
    ChildAssociationRef childAssocRef = generateChildAssociationRef(recordFolderNodeRef, nodeRef);
    recordFolderType.onCreateChildAssociation(childAssocRef, true);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) QName(org.alfresco.service.namespace.QName) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) Test(org.junit.Test) BaseUnitTest(org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest)

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