Search in sources :

Example 1 with DynamicNamespacePrefixResolver

use of org.alfresco.service.namespace.DynamicNamespacePrefixResolver in project acs-community-packaging by Alfresco.

the class CreateSpaceWizard method finishImpl.

@Override
protected String finishImpl(FacesContext context, String outcome) throws Exception {
    String newSpaceId = null;
    if (this.createFrom.equals(CREATEFROM_SCRATCH)) {
        // create the space (just create a folder for now)
        NodeRef parentNodeRef;
        String nodeId = this.navigator.getCurrentNodeId();
        if (nodeId == null) {
            parentNodeRef = this.getNodeService().getRootNode(Repository.getStoreRef());
        } else {
            parentNodeRef = new NodeRef(Repository.getStoreRef(), nodeId);
        }
        FileInfo fileInfo = getFileFolderService().create(parentNodeRef, this.name, Repository.resolveToQName(this.spaceType));
        NodeRef nodeRef = fileInfo.getNodeRef();
        newSpaceId = nodeRef.getId();
        if (logger.isDebugEnabled())
            logger.debug("Created folder node with name: " + this.name);
        // apply the uifacets aspect - icon, title and description props
        Map<QName, Serializable> uiFacetsProps = new HashMap<QName, Serializable>(5);
        uiFacetsProps.put(ApplicationModel.PROP_ICON, this.icon);
        uiFacetsProps.put(ContentModel.PROP_TITLE, this.title);
        uiFacetsProps.put(ContentModel.PROP_DESCRIPTION, this.description);
        this.getNodeService().addAspect(nodeRef, ApplicationModel.ASPECT_UIFACETS, uiFacetsProps);
        if (logger.isDebugEnabled())
            logger.debug("Added uifacets aspect with properties: " + uiFacetsProps);
        // remember the created node
        this.createdNode = nodeRef;
    } else if (this.createFrom.equals(CREATEFROM_EXISTING)) {
        // copy the selected space and update the name, description and icon
        NodeRef sourceNode = this.existingSpaceId;
        NodeRef parentSpace = new NodeRef(Repository.getStoreRef(), this.navigator.getCurrentNodeId());
        // copy from existing
        NodeRef copiedNode = this.getFileFolderService().copy(sourceNode, parentSpace, this.name).getNodeRef();
        // also need to set the new title, description and icon properties
        this.getNodeService().setProperty(copiedNode, ContentModel.PROP_TITLE, this.title);
        this.getNodeService().setProperty(copiedNode, ContentModel.PROP_DESCRIPTION, this.description);
        this.getNodeService().setProperty(copiedNode, ApplicationModel.PROP_ICON, this.icon);
        newSpaceId = copiedNode.getId();
        if (logger.isDebugEnabled())
            logger.debug("Copied space with id of " + sourceNode.getId() + " to " + this.name);
        // remember the created node
        this.createdNode = copiedNode;
    } else if (this.createFrom.equals(CREATEFROM_TEMPLATE)) {
        // copy the selected space and update the name, description and icon
        NodeRef sourceNode = new NodeRef(Repository.getStoreRef(), this.templateSpaceId);
        NodeRef parentSpace = new NodeRef(Repository.getStoreRef(), this.navigator.getCurrentNodeId());
        // copy from the template
        NodeRef copiedNode = this.getFileFolderService().copy(sourceNode, parentSpace, this.name).getNodeRef();
        // also need to set the new title, description and icon properties
        this.getNodeService().setProperty(copiedNode, ContentModel.PROP_TITLE, this.title);
        this.getNodeService().setProperty(copiedNode, ContentModel.PROP_DESCRIPTION, this.description);
        this.getNodeService().setProperty(copiedNode, ApplicationModel.PROP_ICON, this.icon);
        newSpaceId = copiedNode.getId();
        if (logger.isDebugEnabled())
            logger.debug("Copied template space with id of " + sourceNode.getId() + " to " + this.name);
        // remember the created node
        this.createdNode = copiedNode;
    }
    // space to the templates folder
    if (this.saveAsTemplate) {
        // get hold of the Templates node
        DynamicNamespacePrefixResolver namespacePrefixResolver = new DynamicNamespacePrefixResolver(null);
        namespacePrefixResolver.registerNamespace(NamespaceService.APP_MODEL_PREFIX, NamespaceService.APP_MODEL_1_0_URI);
        String xpath = Application.getRootPath(FacesContext.getCurrentInstance()) + "/" + Application.getGlossaryFolderName(FacesContext.getCurrentInstance()) + "/" + Application.getSpaceTemplatesFolderName(FacesContext.getCurrentInstance());
        NodeRef rootNodeRef = this.getNodeService().getRootNode(Repository.getStoreRef());
        List<NodeRef> templateNodeList = this.getSearchService().selectNodes(rootNodeRef, xpath, null, namespacePrefixResolver, false);
        if (templateNodeList.size() == 1) {
            // get the first item in the list as we from test above there is only one!
            NodeRef templateNode = templateNodeList.get(0);
            NodeRef sourceNode = new NodeRef(Repository.getStoreRef(), newSpaceId);
            // copy this to the template location
            getFileFolderService().copy(sourceNode, templateNode, this.templateName);
        }
    }
    return outcome;
}
Also used : DynamicNamespacePrefixResolver(org.alfresco.service.namespace.DynamicNamespacePrefixResolver) NodeRef(org.alfresco.service.cmr.repository.NodeRef) Serializable(java.io.Serializable) FileInfo(org.alfresco.service.cmr.model.FileInfo) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName)

Aggregations

Serializable (java.io.Serializable)1 HashMap (java.util.HashMap)1 FileInfo (org.alfresco.service.cmr.model.FileInfo)1 NodeRef (org.alfresco.service.cmr.repository.NodeRef)1 DynamicNamespacePrefixResolver (org.alfresco.service.namespace.DynamicNamespacePrefixResolver)1 QName (org.alfresco.service.namespace.QName)1