(5);
-
- // find or create 5 aces
- long cmAceId = findOrCreateAce(PermissionService.GROUP_PREFIX + stagingStoreName + "-" + PermissionService.WCM_CONTENT_MANAGER, PermissionService.WCM_CONTENT_MANAGER);
- long cpAceId = findOrCreateAce(PermissionService.GROUP_PREFIX + stagingStoreName + "-" + PermissionService.WCM_CONTENT_PUBLISHER, PermissionService.WCM_CONTENT_PUBLISHER);
- long ccAceId = findOrCreateAce(PermissionService.GROUP_PREFIX + stagingStoreName + "-" + PermissionService.WCM_CONTENT_CONTRIBUTOR, PermissionService.WCM_CONTENT_CONTRIBUTOR);
- long crAceId = findOrCreateAce(PermissionService.GROUP_PREFIX + stagingStoreName + "-" + PermissionService.WCM_CONTENT_REVIEWER, PermissionService.WCM_CONTENT_REVIEWER);
-
- long erAceId = findOrCreateAce(PermissionService.ALL_AUTHORITIES, PermissionService.READ);
-
- // create acl
- long aclId = createAcl(aclChangeSet, aclType, requiresVersion);
-
- aceIds.add(cmAceId);
- aceIds.add(cpAceId);
- aceIds.add(ccAceId);
- aceIds.add(crAceId);
- aceIds.add(erAceId);
-
- // create acl members
- aclCrudDAO.addAclMembersToAcl(aclId, aceIds, 0);
-
- return aclId;
- }
- }
-}
diff --git a/source/java/org/alfresco/repo/admin/patch/impl/WCMFoldersPatch.java b/source/java/org/alfresco/repo/admin/patch/impl/WCMFoldersPatch.java
deleted file mode 100644
index fc4724a383..0000000000
--- a/source/java/org/alfresco/repo/admin/patch/impl/WCMFoldersPatch.java
+++ /dev/null
@@ -1,364 +0,0 @@
-/*
- * Copyright (C) 2005-2010 Alfresco Software Limited.
- *
- * This file is part of Alfresco
- *
- * Alfresco is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Alfresco is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Alfresco. If not, see .
- */
-package org.alfresco.repo.admin.patch.impl;
-
-import java.io.Serializable;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-
-import org.alfresco.model.ApplicationModel;
-import org.alfresco.model.ContentModel;
-import org.alfresco.repo.admin.patch.AbstractPatch;
-import org.alfresco.repo.importer.ImporterBootstrap;
-import org.alfresco.repo.rule.RuleModel;
-import org.alfresco.service.cmr.admin.PatchException;
-import org.alfresco.service.cmr.repository.ChildAssociationRef;
-import org.alfresco.service.cmr.repository.NodeRef;
-import org.alfresco.service.cmr.repository.StoreRef;
-import org.alfresco.service.namespace.QName;
-import org.springframework.context.MessageSource;
-import org.springframework.extensions.surf.util.I18NUtil;
-
-/**
- * Ensures that the Web Projects and Web Formsfolders are present.
- *
- * This uses the bootstrap importer to get the paths to look for. If not present,
- * the required structures are created.
- *
- *
- * @author Kevin Roast
- */
-public class WCMFoldersPatch extends AbstractPatch
-{
- private static final String MSG_WEBPROJECTS_EXISTS = "patch.wcmFolders.webprojects.result.exists";
- private static final String MSG_WEBPROJECTS_CREATED = "patch.wcmFolders.webprojects.result.created";
- private static final String MSG_WEBFORMS_EXISTS = "patch.wcmFolders.webforms.result.exists";
- private static final String MSG_WEBFORMS_CREATED = "patch.wcmFolders.webforms.result.created";
-
- private static final String PROPERTY_COMPANY_HOME_CHILDNAME = "spaces.company_home.childname";
- private static final String PROPERTY_DICTIONARY_CHILDNAME = "spaces.dictionary.childname";
- public static final String PROPERTY_WEBPROJECTS_FOLDER_CHILDNAME = "spaces.wcm.childname";
- private static final String MSG_WEBPROJECTS_FOLDER_NAME = "spaces.wcm.name";
- private static final String MSG_WEBPROJECTS_FOLDER_DESCRIPTION = "spaces.wcm.description";
- public static final String PROPERTY_WEBFORMS_FOLDER_CHILDNAME = "spaces.wcm_content_forms.childname";
- private static final String MSG_WEBFORMS_FOLDER_NAME = "spaces.wcm_content_forms.name";
- private static final String MSG_WEBFORMS_FOLDER_DESCRIPTION = "spaces.wcm_content_forms.description";
-
- private static final String PROPERTY_ICON = "space-icon-default";
-
- private ImporterBootstrap importerBootstrap;
- private MessageSource messageSource;
-
- protected NodeRef companyHomeNodeRef;
- protected NodeRef dictionaryNodeRef;
- protected Properties configuration;
- protected NodeRef wcmProjectsFolderNodeRef;
- protected NodeRef wcmFormsFolderNodeRef;
-
- public void setImporterBootstrap(ImporterBootstrap importerBootstrap)
- {
- this.importerBootstrap = importerBootstrap;
- }
-
- public void setMessageSource(MessageSource messageSource)
- {
- this.messageSource = messageSource;
- }
-
- /**
- * Ensure that required common properties have been set
- */
- protected void checkCommonProperties() throws Exception
- {
- if (importerBootstrap == null)
- {
- throw new PatchException("'importerBootstrap' property has not been set");
- }
- else if (namespaceService == null)
- {
- throw new PatchException("'namespaceService' property has not been set");
- }
- else if (searchService == null)
- {
- throw new PatchException("'searchService' property has not been set");
- }
- else if (nodeService == null)
- {
- throw new PatchException("'nodeService' property has not been set");
- }
- }
-
- /**
- * Extracts pertinent references and properties that are common to execution
- * of this and derived patches.
- */
- protected void setUp() throws Exception
- {
- // get the node store that we must work against
- StoreRef storeRef = importerBootstrap.getStoreRef();
- if (storeRef == null)
- {
- throw new PatchException("Bootstrap store has not been set");
- }
- NodeRef storeRootNodeRef = nodeService.getRootNode(storeRef);
-
- this.configuration = importerBootstrap.getConfiguration();
- // get the association names that form the path
- String companyHomeChildName = configuration.getProperty(PROPERTY_COMPANY_HOME_CHILDNAME);
- if (companyHomeChildName == null || companyHomeChildName.length() == 0)
- {
- throw new PatchException("Bootstrap property '" + PROPERTY_COMPANY_HOME_CHILDNAME + "' is not present");
- }
- String dictionaryChildName = configuration.getProperty(PROPERTY_DICTIONARY_CHILDNAME);
- if (dictionaryChildName == null || dictionaryChildName.length() == 0)
- {
- throw new PatchException("Bootstrap property '" + PROPERTY_DICTIONARY_CHILDNAME + "' is not present");
- }
- String wcmProjectsChildName = configuration.getProperty(PROPERTY_WEBPROJECTS_FOLDER_CHILDNAME);
- if (wcmProjectsChildName == null || wcmProjectsChildName.length() == 0)
- {
- throw new PatchException("Bootstrap property '" + PROPERTY_WEBPROJECTS_FOLDER_CHILDNAME + "' is not present");
- }
- String wcmFormsChildName = configuration.getProperty(PROPERTY_WEBFORMS_FOLDER_CHILDNAME);
- if (wcmFormsChildName == null || wcmFormsChildName.length() == 0)
- {
- throw new PatchException("Bootstrap property '" + PROPERTY_WEBFORMS_FOLDER_CHILDNAME + "' is not present");
- }
-
- // build the search string to get the company home node
- StringBuilder sb = new StringBuilder(256);
- sb.append("/").append(companyHomeChildName);
- String xpath = sb.toString();
- // get the company home
- List nodeRefs = searchService.selectNodes(storeRootNodeRef, xpath, null, namespaceService, false);
- if (nodeRefs.size() == 0)
- {
- throw new PatchException("XPath didn't return any results: \n" +
- " root: " + storeRootNodeRef + "\n" +
- " xpath: " + xpath);
- }
- else if (nodeRefs.size() > 1)
- {
- throw new PatchException("XPath returned too many results: \n" +
- " root: " + storeRootNodeRef + "\n" +
- " xpath: " + xpath + "\n" +
- " results: " + nodeRefs);
- }
- this.companyHomeNodeRef = nodeRefs.get(0);
-
- // build the search string to get the dictionary node
- sb.append("/").append(dictionaryChildName);
- xpath = sb.toString();
- // get the dictionary node
- nodeRefs = searchService.selectNodes(storeRootNodeRef, xpath, null, namespaceService, false);
- if (nodeRefs.size() == 0)
- {
- throw new PatchException("XPath didn't return any results: \n" +
- " root: " + storeRootNodeRef + "\n" +
- " xpath: " + xpath);
- }
- else if (nodeRefs.size() > 1)
- {
- throw new PatchException("XPath returned too many results: \n" +
- " root: " + storeRootNodeRef + "\n" +
- " xpath: " + xpath + "\n" +
- " results: " + nodeRefs);
- }
- this.dictionaryNodeRef = nodeRefs.get(0);
-
- // Check for the existence of the 'Web Projects' folder
- xpath = wcmProjectsChildName;
- nodeRefs = searchService.selectNodes(companyHomeNodeRef, xpath, null, namespaceService, false);
- if (nodeRefs.size() > 1)
- {
- throw new PatchException("XPath returned too many results: \n" +
- " company home node: " + companyHomeNodeRef + "\n" +
- " xpath: " + xpath + "\n" +
- " results: " + nodeRefs);
- }
- else if (nodeRefs.size() == 0)
- {
- // the node does not exist
- this.wcmProjectsFolderNodeRef = null;
- }
- else
- {
- // we have the 'Web Projects' folder noderef
- this.wcmProjectsFolderNodeRef = nodeRefs.get(0);
- }
-
- // Check for the existence of the 'Web Forms' folder
- xpath = wcmFormsChildName;
- nodeRefs = searchService.selectNodes(dictionaryNodeRef, xpath, null, namespaceService, false);
- if (nodeRefs.size() > 1)
- {
- throw new PatchException("XPath returned too many results: \n" +
- " dictionary node: " + dictionaryNodeRef + "\n" +
- " xpath: " + xpath + "\n" +
- " results: " + nodeRefs);
- }
- else if (nodeRefs.size() == 0)
- {
- // the node does not exist
- this.wcmFormsFolderNodeRef = null;
- }
- else
- {
- // we have the 'Web Forms' folder noderef
- this.wcmFormsFolderNodeRef = nodeRefs.get(0);
- }
- }
-
- @Override
- protected String applyInternal() throws Exception
- {
- // properties must be set
- checkCommonProperties();
- if (messageSource == null)
- {
- throw new PatchException("'messageSource' property has not been set");
- }
-
- // get useful values
- setUp();
-
- String msg = null;
- if (wcmProjectsFolderNodeRef == null)
- {
- // create it
- createWebProjectsFolder();
- msg = I18NUtil.getMessage(MSG_WEBPROJECTS_CREATED, wcmProjectsFolderNodeRef);
- }
- else
- {
- // it already exists
- msg = I18NUtil.getMessage(MSG_WEBPROJECTS_EXISTS, wcmProjectsFolderNodeRef);
- }
-
- if (wcmFormsFolderNodeRef == null)
- {
- // create it
- createWebFormsFolder();
- msg = msg + "\r\n" + I18NUtil.getMessage(MSG_WEBFORMS_CREATED, wcmProjectsFolderNodeRef);
- }
- else
- {
- // it already exists
- msg = msg + "\r\n" + I18NUtil.getMessage(MSG_WEBFORMS_EXISTS, wcmProjectsFolderNodeRef);
- }
-
- // done
- return msg;
- }
-
- private void createWebProjectsFolder()
- {
- // get required properties
- String wcmProjectsChildName = configuration.getProperty(PROPERTY_WEBPROJECTS_FOLDER_CHILDNAME);
- if (wcmProjectsChildName == null)
- {
- throw new PatchException("Bootstrap property '" + PROPERTY_WEBPROJECTS_FOLDER_CHILDNAME + "' is not present");
- }
-
- String name = messageSource.getMessage(
- MSG_WEBPROJECTS_FOLDER_NAME,
- null,
- I18NUtil.getLocale());
- if (name == null || name.length() == 0)
- {
- throw new PatchException("Bootstrap property '" + MSG_WEBPROJECTS_FOLDER_NAME + "' is not present");
- }
-
- String description = messageSource.getMessage(
- MSG_WEBPROJECTS_FOLDER_DESCRIPTION,
- null,
- I18NUtil.getLocale());
- if (description == null || description.length() == 0)
- {
- throw new PatchException("Bootstrap property '" + MSG_WEBPROJECTS_FOLDER_DESCRIPTION + "' is not present");
- }
-
- Map properties = new HashMap(7);
- properties.put(ContentModel.PROP_NAME, name);
- properties.put(ContentModel.PROP_TITLE, name);
- properties.put(ContentModel.PROP_DESCRIPTION, description);
- properties.put(ApplicationModel.PROP_ICON, PROPERTY_ICON);
- // create the node
- ChildAssociationRef childAssocRef = nodeService.createNode(
- companyHomeNodeRef,
- ContentModel.ASSOC_CONTAINS,
- QName.resolveToQName(namespaceService, wcmProjectsChildName),
- ContentModel.TYPE_FOLDER,
- properties);
- wcmProjectsFolderNodeRef = childAssocRef.getChildRef();
-
- // add the required aspects
- nodeService.addAspect(wcmProjectsFolderNodeRef, ApplicationModel.ASPECT_UIFACETS, null);
-
- // ALF-906: ensure that DM rules are not inherited by web projects
- nodeService.addAspect(wcmProjectsFolderNodeRef, RuleModel.ASPECT_IGNORE_INHERITED_RULES, null);
- }
-
- private void createWebFormsFolder()
- {
- // get required properties
- String wcmFormsChildName = configuration.getProperty(PROPERTY_WEBFORMS_FOLDER_CHILDNAME);
- if (wcmFormsChildName == null)
- {
- throw new PatchException("Bootstrap property '" + PROPERTY_WEBFORMS_FOLDER_CHILDNAME + "' is not present");
- }
-
- String name = messageSource.getMessage(
- MSG_WEBFORMS_FOLDER_NAME,
- null,
- I18NUtil.getLocale());
- if (name == null || name.length() == 0)
- {
- throw new PatchException("Bootstrap property '" + MSG_WEBFORMS_FOLDER_NAME + "' is not present");
- }
-
- String description = messageSource.getMessage(
- MSG_WEBFORMS_FOLDER_DESCRIPTION,
- null,
- I18NUtil.getLocale());
- if (description == null || description.length() == 0)
- {
- throw new PatchException("Bootstrap property '" + MSG_WEBFORMS_FOLDER_DESCRIPTION + "' is not present");
- }
-
- Map properties = new HashMap(7);
- properties.put(ContentModel.PROP_NAME, name);
- properties.put(ContentModel.PROP_TITLE, name);
- properties.put(ContentModel.PROP_DESCRIPTION, description);
- properties.put(ApplicationModel.PROP_ICON, PROPERTY_ICON);
- // create the node
- ChildAssociationRef childAssocRef = nodeService.createNode(
- dictionaryNodeRef,
- ContentModel.ASSOC_CONTAINS,
- QName.resolveToQName(namespaceService, wcmFormsChildName),
- ContentModel.TYPE_FOLDER,
- properties);
- wcmFormsFolderNodeRef = childAssocRef.getChildRef();
-
- // add the required aspects
- nodeService.addAspect(wcmFormsFolderNodeRef, ApplicationModel.ASPECT_UIFACETS, null);
- }
-}
diff --git a/source/java/org/alfresco/repo/admin/patch/impl/WCMPostPermissionSnapshotPatch.java b/source/java/org/alfresco/repo/admin/patch/impl/WCMPostPermissionSnapshotPatch.java
deleted file mode 100644
index 4dc97ee36a..0000000000
--- a/source/java/org/alfresco/repo/admin/patch/impl/WCMPostPermissionSnapshotPatch.java
+++ /dev/null
@@ -1,158 +0,0 @@
-/*
- * Copyright (C) 2005-2010 Alfresco Software Limited.
- *
- * This file is part of Alfresco
- *
- * Alfresco is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Alfresco is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Alfresco. If not, see .
- */
-package org.alfresco.repo.admin.patch.impl;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.alfresco.repo.admin.patch.AbstractPatch;
-import org.alfresco.repo.domain.patch.PatchDAO;
-import org.alfresco.repo.search.AVMSnapShotTriggeredIndexingMethodInterceptor;
-import org.alfresco.repo.search.impl.lucene.AVMLuceneIndexer;
-import org.alfresco.service.cmr.avm.AVMService;
-import org.alfresco.service.cmr.avm.AVMStoreDescriptor;
-import org.springframework.extensions.surf.util.I18NUtil;
-
-/**
- * Snap shot all stores after applying the staging are permissions patch
- *
- * @author andyh
- */
-public class WCMPostPermissionSnapshotPatch extends AbstractPatch
-{
- private static final String MSG_SUCCESS = "patch.wcmPostPermissionSnapshotPatch.result";
-
- private static final String AVM_SITE_STORE_NAME = "sitestore";
-
- private AVMSnapShotTriggeredIndexingMethodInterceptor avmSnapShotTriggeredIndexingMethodInterceptor;
-
- private AVMService avmService;
-
- private PatchDAO patchDAO;
-
- public void setAvmService(AVMService avmService)
- {
- this.avmService = avmService;
- }
-
- public void setAvmSnapShotTriggeredIndexingMethodInterceptor(AVMSnapShotTriggeredIndexingMethodInterceptor avmSnapShotTriggeredIndexingMethodInterceptor)
- {
- this.avmSnapShotTriggeredIndexingMethodInterceptor = avmSnapShotTriggeredIndexingMethodInterceptor;
- }
-
- public void setPatchDAO(PatchDAO patchDAO)
- {
- this.patchDAO = patchDAO;
- }
-
- @Override
- protected String applyInternal() throws Exception
- {
- List stores = avmService.getStores();
-
- Thread progressThread = null;
-
- Long toDo = patchDAO.getAVMNodesCountWhereNewInStore();
-
- List indexers = new ArrayList(stores.size());
- for (AVMStoreDescriptor storeDesc : stores)
- {
- // post 4.0 we can safely skip "sitestore" no longer used by share
- if(storeDesc.getName().equals(AVM_SITE_STORE_NAME))
- {
- continue;
- }
-
- AVMLuceneIndexer indexer = avmSnapShotTriggeredIndexingMethodInterceptor.getIndexer(storeDesc.getName());
- indexers.add(indexer);
- }
-
- progressThread = new Thread(new ProgressWatcher(toDo, indexers), "WCMPactchProgressWatcher");
- progressThread.start();
-
- for (AVMStoreDescriptor storeDesc : stores)
- {
- // post 4.0 we can safely skip "sitestore" no longer used by share
- if(storeDesc.getName().equals(AVM_SITE_STORE_NAME))
- {
- continue;
- }
-
- if (avmService.getStoreRoot(-1, storeDesc.getName()).getLayerID() == -1)
- {
- avmService.createSnapshot(storeDesc.getName(), "PermissionPatch", "Snapshot after 2.2 permission patch");
- AVMLuceneIndexer indexer = avmSnapShotTriggeredIndexingMethodInterceptor.getIndexer(storeDesc.getName());
- indexer.flushPending();
- }
- }
-
- progressThread.interrupt();
- progressThread.join();
-
- // build the result message
- String msg = I18NUtil.getMessage(MSG_SUCCESS);
- // done
- return msg;
- }
-
- private class ProgressWatcher implements Runnable
- {
- private boolean running = true;
-
- Long toDo;
-
- List indexers;
-
- ProgressWatcher(Long toDo, List indexers)
- {
- this.toDo = toDo;
- this.indexers = indexers;
- }
-
- public void run()
- {
- while (running)
- {
- try
- {
- Thread.sleep(60000);
- }
- catch (InterruptedException e)
- {
- running = false;
- }
-
- if (running)
- {
- long done = 0;
- for(AVMLuceneIndexer indexer : indexers)
- {
- if(indexer != null)
- {
- done += indexer.getIndexedDocCount();
- }
- }
-
- reportProgress(toDo, done);
- }
- }
- }
-
- }
-}
diff --git a/source/java/org/alfresco/repo/avm/AVMDAOs.java b/source/java/org/alfresco/repo/avm/AVMDAOs.java
deleted file mode 100644
index d81c7ea6a9..0000000000
--- a/source/java/org/alfresco/repo/avm/AVMDAOs.java
+++ /dev/null
@@ -1,157 +0,0 @@
-/*
- * Copyright (C) 2005-2010 Alfresco Software Limited.
- *
- * This file is part of Alfresco
- *
- * Alfresco is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Alfresco is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Alfresco. If not, see . */
-
-package org.alfresco.repo.avm;
-
-import org.alfresco.repo.domain.contentdata.ContentDataDAO;
-import org.alfresco.repo.domain.permissions.AclDAO;
-
-/**
- * This is the (shudder) global context for AVM. It a rendezvous
- * point for access to needed global instances.
- * @author britt
- */
-public class AVMDAOs
-{
- /**
- * The single instance of an AVMContext.
- */
- private static final AVMDAOs fgInstance = new AVMDAOs();
-
- private AVMDAOs()
- {
- }
-
- /**
- * Get the instance of this.
- * @return
- */
- public static AVMDAOs Instance()
- {
- return fgInstance;
- }
-
- /**
- * The AVMNodeDAO.
- */
- public AVMNodeDAO fAVMNodeDAO;
-
- public org.alfresco.repo.domain.avm.AVMNodeDAO newAVMNodeDAO;
- public org.alfresco.repo.domain.avm.AVMNodeLinksDAO newAVMNodeLinksDAO;
- public ContentDataDAO contentDataDAO;
-
- /**
- * The AVMStore DAO.
- */
- public AVMStoreDAO fAVMStoreDAO;
-
- public org.alfresco.repo.domain.avm.AVMStoreDAO newAVMStoreDAO;
-
- /**
- * The VersionRootDAO.
- */
- public VersionRootDAO fVersionRootDAO;
-
- public org.alfresco.repo.domain.avm.AVMVersionRootDAO newAVMVersionRootDAO;
-
- /**
- * The ChildEntryDAO.
- */
- public ChildEntryDAO fChildEntryDAO;
-
- /**
- * The AVMStorePropertyDAO
- */
- public AVMStorePropertyDAO fAVMStorePropertyDAO;
-
- public VersionLayeredNodeEntryDAO fVersionLayeredNodeEntryDAO;
-
- public AclDAO fAclDAO;
-
- /**
- * @param nodeDAO the fAVMNodeDAO to set
- */
- public void setNodeDAO(AVMNodeDAO nodeDAO)
- {
- fAVMNodeDAO = nodeDAO;
- }
-
- public void setNewAvmNodeDAO(org.alfresco.repo.domain.avm.AVMNodeDAO newAVMNodeDAO)
- {
- this.newAVMNodeDAO = newAVMNodeDAO;
- }
-
- public void setNewAvmNodeLinksDAO(org.alfresco.repo.domain.avm.AVMNodeLinksDAO newAVMNodeLinksDAO)
- {
- this.newAVMNodeLinksDAO = newAVMNodeLinksDAO;
- }
-
- public void setContentDataDAO(ContentDataDAO contentDataDAO)
- {
- this.contentDataDAO = contentDataDAO;
- }
-
- /**
- * @param childEntryDAO the fChildEntryDAO to set
- */
- public void setChildEntryDAO(ChildEntryDAO childEntryDAO)
- {
- fChildEntryDAO = childEntryDAO;
- }
-
- /**
- * @param aVMStoreDAO The fAVMStoreDAO to set
- */
- public void setAvmStoreDAO(AVMStoreDAO aVMStoreDAO)
- {
- fAVMStoreDAO = aVMStoreDAO;
- }
-
- public void setNewAvmStoreDAO(org.alfresco.repo.domain.avm.AVMStoreDAO newAVMStoreDAO)
- {
- this.newAVMStoreDAO = newAVMStoreDAO;
- }
-
- /**
- * @param versionRootDAO the fVersionRootDAO to set
- */
- public void setVersionRootDAO(VersionRootDAO versionRootDAO)
- {
- fVersionRootDAO = versionRootDAO;
- }
-
- public void setNewAvmVersionRootDAO(org.alfresco.repo.domain.avm.AVMVersionRootDAO newAVMVersionRootDAO)
- {
- this.newAVMVersionRootDAO = newAVMVersionRootDAO;
- }
-
- public void setAvmStorePropertyDAO(AVMStorePropertyDAO avmStorePropertyDAO)
- {
- fAVMStorePropertyDAO = avmStorePropertyDAO;
- }
-
- public void setVersionLayeredNodeEntryDAO(VersionLayeredNodeEntryDAO dao)
- {
- fVersionLayeredNodeEntryDAO = dao;
- }
-
- public void setAclDAO(AclDAO dao)
- {
- fAclDAO = dao;
- }
-}
diff --git a/source/java/org/alfresco/repo/avm/AVMNode.java b/source/java/org/alfresco/repo/avm/AVMNode.java
deleted file mode 100644
index 82f2cc4594..0000000000
--- a/source/java/org/alfresco/repo/avm/AVMNode.java
+++ /dev/null
@@ -1,260 +0,0 @@
-/*
- * Copyright (C) 2005-2010 Alfresco Software Limited.
- *
- * This file is part of Alfresco
- *
- * Alfresco is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Alfresco is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Alfresco. If not, see . */
-package org.alfresco.repo.avm;
-
-import java.util.Map;
-import java.util.Set;
-
-import org.alfresco.repo.domain.PropertyValue;
-import org.alfresco.repo.domain.permissions.Acl;
-import org.alfresco.repo.security.permissions.ACLCopyMode;
-import org.alfresco.service.cmr.avm.AVMNodeDescriptor;
-import org.alfresco.service.namespace.QName;
-
-/**
- * The Interface for versionable objects.
- * @author britt
- */
-public interface AVMNode
-{
- /**
- * Set the ancestor of this node.
- * @param ancestor The ancestor to set.
- */
- public void setAncestor(AVMNode ancestor);
-
- /**
- * Change the ancestor of a node.
- * @param ancestor The ancestor node that should be set.
- */
- public void changeAncestor(AVMNode ancestor);
-
- /**
- * Get the ancestor of this node.
- * @return The ancestor of this node.
- */
- public AVMNode getAncestor();
-
- /**
- * Set the merged from node.
- * @param mergedFrom The merged from node.
- */
- public void setMergedFrom(AVMNode mergedFrom);
-
- /**
- * Get the node this was merged from.
- * @return The node this was merged from.
- */
- public AVMNode getMergedFrom();
-
- /**
- * Get the version number.
- * @return The version number.
- */
- public int getVersionID();
-
- /**
- * Set the version number.
- * @param version The version number to set.
- */
- public void setVersionID(int version);
-
- /**
- * Possibly copy ourselves.
- * @param lPath The Lookup for this node.
- * @return A copy of ourself or null if no copy was necessary.
- */
- public AVMNode copy(Lookup lPath);
-
- /**
- * Get the type of this node.
- */
- public int getType();
-
- /**
- * Get the descriptor for this node.
- * @param lPath The Lookup.
- * @param name The name of this in the current context.
- * @return The descriptor for this node.
- */
- public AVMNodeDescriptor getDescriptor(Lookup lPath, String name);
-
- /**
- * Get the descriptor for this node.
- * @param lPath The Lookup.
- * @return The descriptor for this node.
- */
- public AVMNodeDescriptor getDescriptor(Lookup lPath);
-
- /**
- * Get a node descriptor for this node.
- * @param parentPath The parent path.
- * @param name The name looked up as.
- * @param parentIndirection The indirection of the parent.
- * @param parentIndirectionVersion The indirection version of the parent.
- * @return The descriptor for this node.
- */
- public AVMNodeDescriptor getDescriptor(String parentPath, String name, String parentIndirection, int parentIndirectionVersion);
-
- /**
- * Get the object id.
- * @return The object id.
- */
- public long getId();
-
- /**
- * Get the newnews.
- * @return Whether the node is new.
- */
- public boolean getIsNew();
-
- /**
- * Get a string representation for debugging.
- * @param lPath The Lookup.
- * @return A String representation.
- */
- public String toString(Lookup lPath);
-
- /**
- * Set whether this node to be a root of a AVMStore
- * @param isRoot
- */
- public void setIsRoot(boolean isRoot);
-
- /**
- * Get whether this node is a root of a AVMStore.
- * @return Whether this node is a root.
- */
- public boolean getIsRoot();
-
- /**
- * Update the modification time of this node.
- */
- public void updateModTime();
-
- /**
- * Set a property.
- * @param qname the QName
- * @param value The value to set.
- */
- public void setProperty(QName qname, PropertyValue value);
-
- /**
- * Set a collection of properties on this node.
- * @param properties The Map of QNames to PropertyValues.
- */
- public void setProperties(Map properties);
-
- /**
- * Add properties to those that already exist.
- * @param properties The properties to add.
- */
- public void addProperties(Map properties);
-
- /**
- * Get a property by name.
- * @param name The name of the property to get.
- * @return A PropertyValue
- */
- public PropertyValue getProperty(QName name);
-
- /**
- * Get all the properties associated with this node.
- * @return A Map of QNames to PropertyValues.
- */
- public Map getProperties();
-
- /**
- * Delete a property from this node.
- * @param qnameEntityId the ID of the QName to delete
- */
- public void deleteProperty(QName qname);
-
- /**
- * Delete all properties from this node.
- */
- public void deleteProperties();
-
- /**
- * Set an ACL on this node.
- * @param acl The ACL to set.
- */
- public void setAcl(Acl acl);
-
- /**
- * Get the ACL on this node.
- * @return The ACL on this node.
- */
- public Acl getAcl();
-
- /**
- * Set the store that we are new in.
- * @param store The store we are new in.
- */
- public void setStoreNew(AVMStore store);
-
- /**
- * Get the possibly null store that we're new in.
- * @return The store that we're new in.
- */
- public AVMStore getStoreNew();
-
- /**
- * Copy ACL from another node.
- *
- * @param other
- * @param mode
- */
- public void copyACLs(AVMNode other, ACLCopyMode mode);
-
- public void copyACLs(Acl otherAcl, Acl parentAcl, ACLCopyMode mode);
-
- /**
- * Copy metadata from another node.
- * @param other The other node.
- */
- public void copyMetaDataFrom(AVMNode other, Long parentAcl);
-
- /**
- * Get the GUID associated with this version.
- * @return The GUID.
- */
- public String getGuid();
-
- /**
- * Set the GUID associated with this version.
- * @param guid
- */
- public void setGuid(String guid);
-
- /**
- * Get the Aspects that this node has.
- * @return A Set of Aspects IDs.
- */
- public Set getAspects();
-
- public void addAspect(QName aspectQName);
-
- public void removeAspect(QName aspectQName);
-
- /**
- * Get the Basic Attributes on this node.
- * @return
- */
- public BasicAttributes getBasicAttributes();
-}
diff --git a/source/java/org/alfresco/repo/avm/AVMNodeDAO.java b/source/java/org/alfresco/repo/avm/AVMNodeDAO.java
deleted file mode 100644
index b323aeb0f8..0000000000
--- a/source/java/org/alfresco/repo/avm/AVMNodeDAO.java
+++ /dev/null
@@ -1,131 +0,0 @@
-/*
- * Copyright (C) 2005-2010 Alfresco Software Limited.
- *
- * This file is part of Alfresco
- *
- * Alfresco is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Alfresco is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Alfresco. If not, see . */
-package org.alfresco.repo.avm;
-
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.alfresco.repo.domain.PropertyValue;
-import org.alfresco.service.namespace.QName;
-
-/**
- * DAO for AVMNodes interface.
- * @author britt
- */
-public interface AVMNodeDAO
-{
- /**
- * Save the given node, having never been saved before.
- */
- public void save(AVMNode node);
-
- /**
- * Delete a single node.
- * @param node The node to delete.
- */
- public void delete(AVMNode node);
-
- public void createAspect(long nodeId, QName aspectQName);
-
- public void deleteAspect(long nodeId, QName aspectQName);
-
- public void deleteAspects(long nodeId);
-
- public Set getAspects(long nodeId);
-
- public void createOrUpdateProperty(long nodeId, QName propQName, PropertyValue value);
-
- public void deleteProperty(long nodeId, QName propQName);
-
- public void deleteProperties(long nodeId);
-
- public Map getProperties(long nodeId);
-
- /**
- * Get by ID.
- * @param id The id to get.
- */
- public AVMNode getByID(long id);
-
- /**
- * Get the root of a particular version.
- * @param store The store we're querying.
- * @param version The version.
- * @return The VersionRoot or null.
- */
- public DirectoryNode getAVMStoreRoot(AVMStore store, int version);
-
- /**
- * Update a node that has been dirtied.
- * @param node The node.
- */
- public void update(AVMNode node);
-
- // update optimisation, eg. when creating files
- public void updateModTimeAndGuid(AVMNode node);
-
- /**
- * Get the ancestor of a node.
- * @param node The node whose ancestor is desired.
- * @return The ancestor or null.
- */
- public AVMNode getAncestor(AVMNode node);
-
- /**
- * Get the node the given node was merged from.
- * @param node The node whose merged from is desired.
- * @return The merged from node or null.
- */
- public AVMNode getMergedFrom(AVMNode node);
-
- /**
- * Get up to batchSize orphans.
- * @param batchSize Get no more than this number.
- * @return A List of orphaned AVMNodes.
- */
- public List getOrphans(int batchSize);
-
-
- /**
- * Get all the nodes that are new in the given store.
- * @param store The store to query.
- * @return A List of AVMNodes.
- */
- public List getNewInStore(AVMStore store);
-
- /**
- * Clear newInStore field for a store. (Snapshot)
- * @param store
- */
- public void clearNewInStore(AVMStore store);
-
- /**
- * Get any new layered entries in a store.
- * @param store
- * @return
- */
- public List getNewLayeredInStoreIDs(AVMStore store);
-
- public List getNewLayeredInStore(AVMStore store);
-
- /**
- * Clear the cache.
- */
- public void clear();
-}
diff --git a/source/java/org/alfresco/repo/avm/AVMNodeImpl.java b/source/java/org/alfresco/repo/avm/AVMNodeImpl.java
deleted file mode 100644
index 4bcde69882..0000000000
--- a/source/java/org/alfresco/repo/avm/AVMNodeImpl.java
+++ /dev/null
@@ -1,603 +0,0 @@
-/*
- * Copyright (C) 2005-2010 Alfresco Software Limited.
- *
- * This file is part of Alfresco
- *
- * Alfresco is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Alfresco is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Alfresco. If not, see . */
-
-package org.alfresco.repo.avm;
-
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-import org.alfresco.repo.avm.util.RawServices;
-import org.alfresco.repo.domain.PropertyValue;
-import org.alfresco.repo.domain.avm.AVMHistoryLinkEntity;
-import org.alfresco.repo.domain.permissions.Acl;
-import org.alfresco.repo.security.permissions.ACLCopyMode;
-import org.alfresco.service.cmr.avm.AVMReadOnlyException;
-import org.alfresco.service.namespace.QName;
-import org.alfresco.util.GUID;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/**
- * Base class for all repository file system like objects.
- * @author britt
- */
-public abstract class AVMNodeImpl implements AVMNode
-{
- private static Log logger = LogFactory.getLog(AVMNodeImpl.class);
-
- protected static final boolean DEBUG = logger.isDebugEnabled();
-
- /**
- * The Object ID.
- */
- private long fID;
-
- /**
- * The Version ID.
- */
- private int fVersionID;
-
- /**
- * The basic attributes of this. Owner, creator, mod time, etc.
- */
- private BasicAttributes fBasicAttributes;
-
- /**
- * The version number (for concurrency control).
- */
- private long fVers;
-
- /**
- * The rootness of this node.
- */
- private boolean fIsRoot;
-
- /**
- * The ACL on this node.
- */
- private Acl fACL;
-
- /**
- * The Store that we're new in.
- */
- private AVMStore fStoreNew;
-
- /**
- * The GUID for this version.
- */
- private String fGUID;
-
- /**
- * The Aspects that belong to this node.
- */
- private Set fAspects;
-
- private Map fProperties;
-
- /**
- * Default constructor.
- */
- protected AVMNodeImpl()
- {
- }
-
- /**
- * Constructor used when creating a new concrete subclass instance.
- * @param store The AVMStore that owns this.
- */
- protected AVMNodeImpl(AVMStore store)
- {
- this();
-
- setVersionID(-1);
- setIsRoot(false);
-
- long time = System.currentTimeMillis();
- String user =
- RawServices.Instance().getAuthenticationContext().getCurrentUserName();
- if (user == null)
- {
- user = RawServices.Instance().getAuthenticationContext().getSystemUserName();
- }
- setBasicAttributes(new BasicAttributesImpl(user,
- user,
- user,
- time,
- time,
- time));
- setStoreNew(store);
- setGuid(GUID.generate());
- }
-
- /**
- * Set the ancestor of this node.
- * @param ancestor The ancestor to set.
- */
- public void setAncestor(AVMNode ancestor)
- {
- if (ancestor == null)
- {
- return;
- }
- AVMDAOs.Instance().newAVMNodeLinksDAO.createHistoryLink(ancestor.getId(), this.getId());
- }
-
- /**
- * Change the ancestor of this node.
- * @param ancestor The new ancestor to give it.
- */
- public void changeAncestor(AVMNode ancestor)
- {
- AVMHistoryLinkEntity hlEntity = AVMDAOs.Instance().newAVMNodeLinksDAO.getHistoryLinkByDescendent(this.getId());
- if (hlEntity != null)
- {
- AVMDAOs.Instance().newAVMNodeLinksDAO.deleteHistoryLink(hlEntity.getAncestorNodeId(), hlEntity.getDescendentNodeId());
- }
- setAncestor(ancestor);
- }
-
- /**
- * Get the ancestor of this node.
- * @return The ancestor of this node.
- */
- public AVMNode getAncestor()
- {
- return AVMDAOs.Instance().fAVMNodeDAO.getAncestor(this);
- }
-
- /**
- * Set the node that was merged into this.
- * @param mergedFrom The node that was merged into this.
- */
- public void setMergedFrom(AVMNode mergedFrom)
- {
- if (mergedFrom == null)
- {
- return;
- }
- AVMDAOs.Instance().newAVMNodeLinksDAO.createMergeLink(mergedFrom.getId(), this.getId());
- }
-
- /**
- * Get the node that was merged into this.
- * @return The node that was merged into this.
- */
- public AVMNode getMergedFrom()
- {
- return AVMDAOs.Instance().fAVMNodeDAO.getMergedFrom(this);
- }
-
- /**
- * Equality based on object ids.
- * @param obj The thing to compare against.
- * @return Equality.
- */
- @Override
- public boolean equals(Object obj)
- {
- if (this == obj)
- {
- return true;
- }
- if (!(obj instanceof AVMNode))
- {
- return false;
- }
- return getId() == ((AVMNode)obj).getId();
- }
-
- /**
- * Get a reasonable hash value.
- * @return The hash code.
- */
- @Override
- public int hashCode()
- {
- return (int)getId();
- }
-
- /**
- * Set the object id.
- * @param id The id to set.
- */
- public void setId(long id)
- {
- fID = id;
- }
-
- /**
- * Get the id of this node.
- * @return The object id.
- */
- public long getId()
- {
- return fID;
- }
-
- /**
- * Set the versionID for this node.
- * @param versionID The id to set.
- */
- public void setVersionID(int versionID)
- {
- fVersionID = versionID;
- }
-
- /**
- * Get the version id of this node.
- * @return The version id.
- */
- public int getVersionID()
- {
- return fVersionID;
- }
-
- /**
- * Set the basic attributes.
- * @param attrs
- */
- public void setBasicAttributes(BasicAttributes attrs)
- {
- fBasicAttributes = attrs;
- }
-
- /**
- * Get the basic attributes.
- * @return The basic attributes.
- */
- public BasicAttributes getBasicAttributes()
- {
- return fBasicAttributes;
- }
-
- /**
- * Get whether this is a new node.
- * @return Whether this is new.
- */
- public boolean getIsNew()
- {
- return getStoreNew() != null;
- }
-
- /**
- * Set the version (for concurrency control).
- * @param The version for optimistic locks.
- */
- public void setVers(long vers)
- {
- fVers = vers;
- }
-
- /**
- * Get the version (for concurrency control).
- * @return vers The version for optimistic locks.
- */
- public long getVers()
- {
- return fVers;
- }
-
- /**
- * Get whether this is a root node.
- * @return Whether this is a root node.
- */
- public boolean getIsRoot()
- {
- return fIsRoot;
- }
-
- /**
- * @param isRoot
- */
- public void setIsRoot(boolean isRoot)
- {
- fIsRoot = isRoot;
- }
-
- /* (non-Javadoc)
- * @see org.alfresco.repo.avm.AVMNode#updateModTime()
- */
- public void updateModTime()
- {
- if (DEBUG)
- {
- checkReadOnly();
- }
- String user =
- RawServices.Instance().getAuthenticationContext().getCurrentUserName();
- if (user == null)
- {
- user = RawServices.Instance().getAuthenticationContext().getSystemUserName();
- }
- getBasicAttributes().setModDate(System.currentTimeMillis());
- getBasicAttributes().setLastModifier(user);
- }
-
- /**
- * Copy all properties from another node.
- * @param other The other node.
- */
- protected void copyProperties(AVMNode other)
- {
- Map props = new HashMap();
- for (Map.Entry entry : other.getProperties().entrySet())
- {
- props.put(entry.getKey(), entry.getValue());
- }
-
- setProperties(props);
- }
-
- /**
- * Copy all aspects from another node.
- * @param other The other node.
- */
- protected void copyAspects(AVMNode other)
- {
- Set aspects = new HashSet(other.getAspects());
- setAspects(aspects);
- }
-
- protected void copyCreationAndOwnerBasicAttributes(AVMNode other)
- {
- getBasicAttributes().setCreateDate(other.getBasicAttributes().getCreateDate());
- getBasicAttributes().setCreator(other.getBasicAttributes().getCreator());
- getBasicAttributes().setOwner(other.getBasicAttributes().getOwner());
- }
-
- public void copyACLs(AVMNode other, ACLCopyMode mode)
- {
- Acl otherAcl = other.getAcl();
- Long otherAclId = (otherAcl == null ? null : otherAcl.getId());
- copyACLs(otherAclId, otherAclId, mode);
- }
-
- public void copyACLs(Acl otherAcl, Acl parentAcl, ACLCopyMode mode)
- {
- Long otherAclId = (otherAcl == null ? null : otherAcl.getId());
- Long parentAclId = (parentAcl == null ? null : parentAcl.getId());
-
- copyACLs(otherAclId, parentAclId, mode);
- }
-
- protected void copyACLs(AVMNode other, Long parentAcl, ACLCopyMode mode)
- {
- Acl otherAcl = other.getAcl();
- copyACLs((otherAcl == null ? null : otherAcl.getId()), parentAcl, mode);
- }
-
- protected void copyACLs(Long otherAcl, Long parentAcl, ACLCopyMode mode)
- {
- if (otherAcl != null)
- {
- Acl aclCopy = AVMDAOs.Instance().fAclDAO.getAclCopy(otherAcl, parentAcl, mode);
- setAcl(aclCopy);
- }
- else
- {
- setAcl(null);
- }
- }
-
- /**
- * Copy out metadata from another node.
- * @param other The other node.
- */
- public void copyMetaDataFrom(AVMNode other, Long parentAcl)
- {
- copyAspects(other);
- copyACLs(other, parentAcl, ACLCopyMode.COPY);
- copyProperties(other);
- copyCreationAndOwnerBasicAttributes(other);
- }
-
- /**
- * Set a property on a node. Overwrite it if it exists.
- * @param name The name of the property.
- * @param value The value to set.
- */
- public void setProperty(QName qname, PropertyValue value)
- {
- if (DEBUG)
- {
- checkReadOnly();
- }
-
- getProperties().put(qname, value);
-
- AVMDAOs.Instance().fAVMNodeDAO.createOrUpdateProperty(this.getId(), qname, value);
- }
-
- public void addProperties(Map properties)
- {
- for (Map.Entry entry : properties.entrySet())
- {
- setProperty(entry.getKey(), entry.getValue());
- }
- }
-
- /**
- * Set a collection of properties on this node.
- * @param properties The Map of QNames to PropertyValues.
- */
- public void setProperties(Map properties)
- {
- fProperties = properties;
-
- for (Map.Entry entry : properties.entrySet())
- {
- setProperty(entry.getKey(), entry.getValue());
- }
- }
-
- /**
- * Get a property by name.
- * @param name The name of the property.
- * @return The PropertyValue or null if non-existent.
- */
- public PropertyValue getProperty(QName qname)
- {
- return getProperties().get(qname);
- }
-
- /**
- * {@inheritDoc}
- */
- public Map getProperties()
- {
- if (fProperties == null)
- {
- fProperties = AVMDAOs.Instance().fAVMNodeDAO.getProperties(getId());
- }
- return fProperties;
- }
-
- /**
- * Delete a property from this node.
- * @param name The name of the property.
- */
- public void deleteProperty(QName qname)
- {
- if (DEBUG)
- {
- checkReadOnly();
- }
- getProperties().remove(qname);
-
- AVMDAOs.Instance().fAVMNodeDAO.deleteProperty(getId(), qname);
- }
-
- /**
- * Delete all properties from this node.
- */
- public void deleteProperties()
- {
- getProperties().clear();
-
- AVMDAOs.Instance().fAVMNodeDAO.deleteProperties(getId());
- }
-
- /**
- * Set the ACL on this node.
- * @param acl The ACL to set.
- */
- public void setAcl(Acl acl)
- {
- fACL = acl;
- }
-
- /**
- * Get the ACL on this node.
- * @return The ACL on this node.
- */
- public Acl getAcl()
- {
- return fACL;
- }
-
- /**
- * Set the store we are new in.
- * @param store The store we are new in.
- */
- public void setStoreNew(AVMStore store)
- {
- fStoreNew = store;
- }
-
- /**
- * Get the possibly null store we are new in.
- * @return The store we are new in.
- */
- public AVMStore getStoreNew()
- {
- return fStoreNew;
- }
-
- protected void checkReadOnly()
- {
- if (getStoreNew() == null)
- {
- throw new AVMReadOnlyException("Write Operation on R/O Node.");
- }
- }
-
- /* (non-Javadoc)
- * @see org.alfresco.repo.avm.AVMNode#getGuid()
- */
- public String getGuid()
- {
- return fGUID;
- }
-
- /* (non-Javadoc)
- * @see org.alfresco.repo.avm.AVMNode#setGuid(java.lang.String)
- */
- public void setGuid(String guid)
- {
- fGUID = guid;
- }
-
- /* (non-Javadoc)
- * @see org.alfresco.repo.avm.AVMNode#getAspects()
- */
- public Set getAspects()
- {
- if (fAspects == null)
- {
- fAspects = AVMDAOs.Instance().fAVMNodeDAO.getAspects(getId());
- }
- return fAspects;
- }
-
- /**
- * Set the aspects on this node.
- * @param aspects
- */
- public void setAspects(Set aspects)
- {
- fAspects = aspects;
-
- if ((aspects != null) && (aspects.size() > 0))
- {
- for (QName aspectQName : aspects)
- {
- AVMDAOs.Instance().fAVMNodeDAO.createAspect(this.getId(), aspectQName);
- }
- }
- }
-
- public void addAspect(QName aspectQName)
- {
- fAspects = null;
- AVMDAOs.Instance().fAVMNodeDAO.createAspect(this.getId(), aspectQName);
- }
-
- public void removeAspect(QName aspectQName)
- {
- fAspects = null;
- AVMDAOs.Instance().fAVMNodeDAO.deleteAspect(this.getId(), aspectQName);
- }
-
- // debug
- public String toString()
- {
- return toString(null);
- }
-}
diff --git a/source/java/org/alfresco/repo/avm/AVMNodeService.java b/source/java/org/alfresco/repo/avm/AVMNodeService.java
index e5f03dbdcc..1bc231e19b 100644
--- a/source/java/org/alfresco/repo/avm/AVMNodeService.java
+++ b/source/java/org/alfresco/repo/avm/AVMNodeService.java
@@ -1,2087 +1,2090 @@
-/*
- * Copyright (C) 2005-2010 Alfresco Software Limited.
- *
- * This file is part of Alfresco
- *
- * Alfresco is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Alfresco is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Alfresco. If not, see . */
-
-package org.alfresco.repo.avm;
-
-import java.io.IOException;
-import java.io.OutputStream;
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.SortedMap;
-
-import org.alfresco.model.ContentModel;
-import org.alfresco.model.WCMModel;
-import org.alfresco.repo.avm.util.AVMUtil;
-import org.alfresco.repo.domain.PropertyValue;
-import org.alfresco.repo.node.AbstractNodeServiceImpl;
-import org.alfresco.service.cmr.avm.AVMException;
-import org.alfresco.service.cmr.avm.AVMExistsException;
-import org.alfresco.service.cmr.avm.AVMNodeDescriptor;
-import org.alfresco.service.cmr.avm.AVMNotFoundException;
-import org.alfresco.service.cmr.avm.AVMService;
-import org.alfresco.service.cmr.avm.AVMStoreDescriptor;
-import org.alfresco.service.cmr.avm.AVMWrongTypeException;
-import org.alfresco.service.cmr.dictionary.AspectDefinition;
-import org.alfresco.service.cmr.dictionary.ClassDefinition;
-import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
-import org.alfresco.service.cmr.dictionary.DictionaryException;
-import org.alfresco.service.cmr.dictionary.InvalidAspectException;
-import org.alfresco.service.cmr.dictionary.InvalidTypeException;
-import org.alfresco.service.cmr.dictionary.PropertyDefinition;
-import org.alfresco.service.cmr.dictionary.TypeDefinition;
-import org.alfresco.service.cmr.repository.AssociationExistsException;
-import org.alfresco.service.cmr.repository.AssociationRef;
-import org.alfresco.service.cmr.repository.ChildAssociationRef;
-import org.alfresco.service.cmr.repository.ContentData;
-import org.alfresco.service.cmr.repository.CyclicChildRelationshipException;
-import org.alfresco.service.cmr.repository.InvalidChildAssociationRefException;
-import org.alfresco.service.cmr.repository.InvalidNodeRefException;
-import org.alfresco.service.cmr.repository.InvalidStoreRefException;
-import org.alfresco.service.cmr.repository.NodeRef;
-import org.alfresco.service.cmr.repository.NodeService;
-import org.alfresco.service.cmr.repository.Path;
-import org.alfresco.service.cmr.repository.StoreExistsException;
-import org.alfresco.service.cmr.repository.StoreRef;
-import org.alfresco.service.cmr.repository.datatype.TypeConversionException;
-import org.alfresco.service.namespace.NamespaceService;
-import org.alfresco.service.namespace.QName;
-import org.alfresco.service.namespace.QNamePattern;
-import org.alfresco.util.Pair;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/**
- * NodeService implementing facade over AVMService.
- * @author britt
- */
-public class AVMNodeService extends AbstractNodeServiceImpl implements NodeService
-{
- private static Log logger = LogFactory.getLog(AVMNodeService.class);
-
- /**
- * Flag for whether policy callbacks are made.
- */
- private boolean fInvokePolicies = false;
-
- /**
- * Reference to AVMService.
- */
- private AVMService fAVMService;
-
- /**
- * Set the AVMService. For Spring.
- * @param service The AVMService instance.
- */
- public void setAvmService(AVMService service)
- {
- fAVMService = service;
- }
-
- /**
- * Default constructor.
- */
- public AVMNodeService()
- {
- }
-
- public void setInvokePolicies(boolean invoke)
- {
- fInvokePolicies = invoke;
- }
-
- /**
- * Helper method to convert the Serializable
value into a full,
- * persistable {@link PropertyValue}.
- *
- * Where the property definition is null, the value will take on the
- * {@link DataTypeDefinition#ANY generic ANY} value.
- *
- * Where the property definition specifies a multi-valued property but the
- * value provided is not a collection, the value will be wrapped in a collection.
- *
- * @param propertyDef the property dictionary definition, may be null
- * @param value the value, which will be converted according to the definition -
- * may be null
- * @return Returns the persistable property value
- */
- protected PropertyValue makePropertyValue(PropertyDefinition propertyDef, Serializable value)
- {
- // get property attributes
- QName propertyTypeQName = null;
- if (propertyDef == null) // property not recognised
- {
- // allow it for now - persisting excess properties can be useful sometimes
- propertyTypeQName = DataTypeDefinition.ANY;
- }
- else
- {
- propertyTypeQName = propertyDef.getDataType().getName();
- // check that multi-valued properties are allowed
- boolean isMultiValued = propertyDef.isMultiValued();
- if (isMultiValued && !(value instanceof Collection>))
- {
- if (value != null)
- {
- // put the value into a collection
- // the implementation gives back a Serializable list
- value = (Serializable) Collections.singletonList(value);
- }
- }
- else if (!isMultiValued && (value instanceof Collection>))
- {
- // we only allow this case if the property type is ANY
- if (!propertyTypeQName.equals(DataTypeDefinition.ANY))
- {
- throw new DictionaryException(
- "A single-valued property of this type may not be a collection: \n" +
- " Property: " + propertyDef + "\n" +
- " Type: " + propertyTypeQName + "\n" +
- " Value: " + value);
- }
- }
- }
- try
- {
- PropertyValue propertyValue = new PropertyValue(propertyTypeQName, value);
- // done
- return propertyValue;
- }
- catch (TypeConversionException e)
- {
- throw new TypeConversionException(
- "The property value is not compatible with the type defined for the property: \n" +
- " property: " + (propertyDef == null ? "unknown" : propertyDef) + "\n" +
- " value: " + value + "\n" +
- " value type: " + value.getClass(),
- e);
- }
- }
-
- /**
- * Extracts the externally-visible property from the {@link PropertyValue propertyValue}.
- *
- * @param propertyDef the model property definition - may be null
- * @param propertyValue the persisted property
- * @return Returns the value of the property in the format dictated by the property
- * definition, or null if the property value is null
- */
- protected Serializable makeSerializableValue(PropertyDefinition propertyDef, PropertyValue propertyValue)
- {
- if (propertyValue == null)
- {
- return null;
- }
- // get property attributes
- QName propertyTypeQName = null;
- if (propertyDef == null)
- {
- // allow this for now
- propertyTypeQName = DataTypeDefinition.ANY;
- }
- else
- {
- propertyTypeQName = propertyDef.getDataType().getName();
- }
- try
- {
- Serializable value = propertyValue.getValue(propertyTypeQName);
- // done
- return value;
- }
- catch (TypeConversionException e)
- {
- throw new TypeConversionException(
- "The property value is not compatible with the type defined for the property: \n" +
- " property: " + (propertyDef == null ? "unknown" : propertyDef) + "\n" +
- " property value: " + propertyValue,
- e);
- }
- }
-
- /**
- * Gets a list of all available node store references
- *
- * @return Returns a list of store references
- */
- public List getStores()
- {
- // For AVM stores we fake up StoreRefs.
- List stores = fAVMService.getStores();
- List result = new ArrayList();
- for (AVMStoreDescriptor desc : stores)
- {
- String name = desc.getName();
- result.add(new StoreRef(StoreRef.PROTOCOL_AVM, name));
- }
- return result;
- }
-
- /**
- * Create a new AVM store.
- * @param protocol the implementation protocol
- * @param identifier the protocol-specific identifier
- * @return Returns a reference to the store
- * @throws StoreExistsException
- */
- public StoreRef createStore(String protocol, String identifier) throws StoreExistsException
- {
- StoreRef result = new StoreRef(StoreRef.PROTOCOL_AVM, identifier);
- // invokeBeforeCreateStore(ContentModel.TYPE_STOREROOT, result);
- try
- {
- fAVMService.createStore(identifier);
- NodeRef rootRef = getRootNode(result);
- addAspect(rootRef, ContentModel.ASPECT_ROOT,
- Collections.emptyMap());
- // invokeOnCreateStore(rootRef);
- return result;
- }
- catch (AVMExistsException e)
- {
- throw new StoreExistsException(result, e);
- }
- }
-
- /**
- * @throws UnsupportedOperationException Always
- */
- public void deleteStore(StoreRef storeRef) throws InvalidStoreRefException
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * Does the indicated store exist?
- * @param storeRef a reference to the store to look for
- * @return Returns true if the store exists, otherwise false
- */
- public boolean exists(StoreRef storeRef)
- {
- return fAVMService.getStore(storeRef.getIdentifier()) != null;
- }
-
- /**
- * @param nodeRef a reference to the node to look for
- * @return Returns true if the node exists, otherwise false
- */
- public boolean exists(NodeRef nodeRef)
- {
- Pair avmInfo = AVMNodeConverter.ToAVMVersionPath(nodeRef);
- int version = avmInfo.getFirst();
- String avmPath = avmInfo.getSecond();
- return fAVMService.lookup(version, avmPath) != null;
- }
-
- /**
- * Gets the ID of the last transaction that caused the node to change. This includes
- * deletions, so it is possible that the node being referenced no longer exists.
- * If the node never existed, then null is returned.
- *
- * @param nodeRef a reference to a current or previously existing node
- * @return Returns the status of the node, or null if the node never existed
- */
- public NodeRef.Status getNodeStatus(NodeRef nodeRef)
- {
- // TODO Need to find out if this is important and if so
- // need to capture Transaction IDs.
- return new NodeRef.Status(null, nodeRef, "Unknown", null, !exists(nodeRef));
- }
-
- /**
- * @throws UnsupportedOperationException always
- */
- @Override
- public NodeRef getNodeRef(Long nodeId)
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * @param storeRef a reference to an existing store
- * @return Returns a reference to the root node of the store
- * @throws InvalidStoreRefException if the store could not be found
- */
- public NodeRef getRootNode(StoreRef storeRef) throws InvalidStoreRefException
- {
- String storeName = storeRef.getIdentifier();
- if (fAVMService.getStore(storeName) != null)
- {
- return AVMNodeConverter.ToNodeRef(-1, storeName + ":/");
- }
- else
- {
- throw new InvalidStoreRefException(storeName +":/" + " not found.", storeRef);
- }
- }
-
- public Set getAllRootNodes(StoreRef storeRef)
- {
- return Collections.singleton(getRootNode(storeRef));
- }
-
- /**
- * @see #createNode(NodeRef, QName, QName, QName, Map)
- */
- public ChildAssociationRef createNode(
- NodeRef parentRef,
- QName assocTypeQName,
- QName assocQName,
- QName nodeTypeQName)
- throws InvalidNodeRefException, InvalidTypeException
- {
- return createNode(parentRef,
- assocTypeQName,
- assocQName,
- nodeTypeQName,
- new HashMap());
- }
-
- /**
- * Creates a new, non-abstract, real node as a primary child of the given parent node.
- *
- * @param parentRef the parent node
- * @param assocTypeQName the type of the association to create. This is used
- * for verification against the data dictionary.
- * @param assocQName the qualified name of the association
- * @param nodeTypeQName a reference to the node type
- * @param properties optional map of properties to keyed by their qualified names
- * @return Returns a reference to the newly created child association
- * @throws InvalidNodeRefException if the parent reference is invalid
- * @throws InvalidTypeException if the node type reference is not recognised
- *
- * @see org.alfresco.service.cmr.dictionary.DictionaryService
- */
- @SuppressWarnings("deprecation")
- public ChildAssociationRef createNode(
- NodeRef parentRef,
- QName assocTypeQName,
- QName assocQName,
- QName nodeTypeQName,
- Map properties)
- throws InvalidNodeRefException, InvalidTypeException
- {
- // AVM stores only allow simple child associations.
- if (!assocTypeQName.equals(ContentModel.ASSOC_CONTAINS))
- {
- throw new InvalidTypeException(assocTypeQName);
- }
- String nodeName = assocQName.getLocalName();
- Pair avmVersionPath = AVMNodeConverter.ToAVMVersionPath(parentRef);
- int version = avmVersionPath.getFirst();
- if (version >= 0)
- {
- throw new InvalidNodeRefException("Read only store.", parentRef);
- }
- String avmPath = avmVersionPath.getSecond();
- // Invoke policy behavior.
- // invokeBeforeUpdateNode(parentRef);
- // invokeBeforeCreateNode(parentRef, assocTypeQName, assocQName, nodeTypeQName);
- // Look up the type definition in the dictionary.
- TypeDefinition nodeTypeDef = dictionaryService.getType(nodeTypeQName);
- // Do the creates for supported types, or error out.
- try
- {
- if (nodeTypeQName.equals(WCMModel.TYPE_AVM_PLAIN_FOLDER) ||
- nodeTypeQName.equals(ContentModel.TYPE_FOLDER))
- {
- fAVMService.createDirectory(avmPath, nodeName);
- }
- else if (nodeTypeQName.equals(WCMModel.TYPE_AVM_PLAIN_CONTENT) ||
- nodeTypeQName.equals(ContentModel.TYPE_CONTENT))
- {
- OutputStream os = fAVMService.createFile(avmPath, nodeName);
- try
- {
- if (os != null) { os.close(); }
- }
- catch (IOException ioe)
- {
- logger.warn("Failed to close output stream when creating file '"+AVMUtil.extendAVMPath(avmPath, nodeName)+"'"+ioe.getMessage());
- }
- }
- else if (nodeTypeQName.equals(WCMModel.TYPE_AVM_LAYERED_CONTENT))
- {
- NodeRef indirection = (NodeRef)properties.get(WCMModel.PROP_AVM_FILE_INDIRECTION);
- if (indirection == null)
- {
- throw new InvalidTypeException("No Indirection Property", nodeTypeQName);
- }
- Pair indVersionPath = AVMNodeConverter.ToAVMVersionPath(indirection);
- fAVMService.createLayeredFile(indVersionPath.getSecond(), avmPath, nodeName);
- }
- else if (nodeTypeQName.equals(WCMModel.TYPE_AVM_LAYERED_FOLDER))
- {
- NodeRef indirection = (NodeRef)properties.get(WCMModel.PROP_AVM_DIR_INDIRECTION);
- if (indirection == null)
- {
- throw new InvalidTypeException("No Indirection Property.", nodeTypeQName);
- }
- Pair indVersionPath = AVMNodeConverter.ToAVMVersionPath(indirection);
- fAVMService.createLayeredDirectory(indVersionPath.getSecond(), avmPath, nodeName);
- }
- else
- {
- throw new InvalidTypeException("Invalid node type for AVM.", nodeTypeQName);
- }
- properties.putAll(getDefaultProperties(nodeTypeDef));
- addDefaultAspects(nodeTypeDef, avmPath, properties);
- }
- catch (AVMNotFoundException e)
- {
- throw new InvalidNodeRefException(avmPath + " not found.", parentRef);
- }
- catch (AVMExistsException e)
- {
- throw new InvalidNodeRefException("Child " + nodeName + " exists", parentRef);
- }
- String newAVMPath = AVMNodeConverter.ExtendAVMPath(avmPath, nodeName);
- NodeRef childRef = AVMNodeConverter.ToNodeRef(-1, newAVMPath);
- properties.putAll(getDefaultProperties(nodeTypeDef));
- addDefaultAspects(nodeTypeDef, newAVMPath, properties);
- Map props = new HashMap();
- for (Map.Entry entry : properties.entrySet())
- {
- QName propertyQName = entry.getKey();
- if (isBuiltInProperty(propertyQName))
- {
- continue;
- }
- Serializable value = entry.getValue();
- PropertyDefinition propertyDef = dictionaryService.getProperty(propertyQName);
- PropertyValue propertyValue = makePropertyValue(propertyDef, value);
- props.put(propertyQName, propertyValue);
- }
- fAVMService.setNodeProperties(newAVMPath, props);
- ChildAssociationRef ref =
- new ChildAssociationRef(assocTypeQName,
- parentRef,
- assocQName,
- childRef,
- true,
- -1);
-// invokeOnCreateNode(ref);
-// invokeOnUpdateNode(parentRef);
-// if (properties.size() != 0)
-// {
-// invokeOnUpdateProperties(childRef, new HashMap(), properties);
-// }
- return ref;
- }
-
- /**
- * Moves the primary location of the given node.
- *
- * This involves changing the node's primary parent and possibly the name of the
- * association referencing it.
- *
- * If the new parent is in a different store from the original, then the entire
- * node hierarchy is moved to the new store. Inter-store associations are not
- * affected.
- *
- * @param nodeToMoveRef the node to move
- * @param newParentRef the new parent of the moved node
- * @param assocTypeQName the type of the association to create. This is used
- * for verification against the data dictionary.
- * @param assocQName the qualified name of the new child association
- * @return Returns a reference to the newly created child association
- * @throws InvalidNodeRefException if either the parent node or move node reference is invalid
- * @throws CyclicChildRelationshipException if the child partakes in a cyclic relationship after the add
- *
- * @see #getPrimaryParent(NodeRef)
- */
- public ChildAssociationRef moveNode(
- NodeRef nodeToMoveRef,
- NodeRef newParentRef,
- QName assocTypeQName,
- QName assocQName)
- throws InvalidNodeRefException
- {
- // AVM stores only allow simple child associations.
- if (!assocTypeQName.equals(ContentModel.ASSOC_CONTAINS))
- {
- throw new InvalidTypeException(assocTypeQName);
- }
- // Extract the parts from the source.
- Pair src = AVMNodeConverter.ToAVMVersionPath(nodeToMoveRef);
- int srcVersion = src.getFirst();
- if (srcVersion >= 0)
- {
- throw new InvalidNodeRefException("Read Only Store.", nodeToMoveRef);
- }
- String srcPath = src.getSecond();
- String [] splitSrc = null;
- try
- {
- splitSrc = AVMNodeConverter.SplitBase(srcPath);
- }
- catch (AVMException e)
- {
- throw new InvalidNodeRefException("Invalid src path.", nodeToMoveRef);
- }
- String srcParent = splitSrc[0];
- if (srcParent == null)
- {
- throw new InvalidNodeRefException("Cannot rename root node.", nodeToMoveRef);
- }
- String srcName = splitSrc[1];
- // Extract and setup the parts of the destination.
- Pair dst = AVMNodeConverter.ToAVMVersionPath(newParentRef);
- if (dst.getFirst() >= 0)
- {
- throw new InvalidNodeRefException("Read Only Store.", newParentRef);
- }
- String dstParent = dst.getSecond();
- String dstName = assocQName.getLocalName();
- // TODO Invoke policy behavior. Not quite sure how to translate this.
- NodeRef oldParentRef = AVMNodeConverter.ToNodeRef(-1, srcParent);
- ChildAssociationRef oldAssocRef =
- new ChildAssociationRef(assocTypeQName,
- oldParentRef,
- QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, srcName),
- nodeToMoveRef,
- true,
- -1);
-// invokeBeforeDeleteChildAssociation(oldAssocRef);
- String dstPath = AVMNodeConverter.ExtendAVMPath(dstParent, dstName);
- NodeRef newChildRef = AVMNodeConverter.ToNodeRef(-1, dstPath);
-// invokeBeforeUpdateNode(oldParentRef);
-// invokeBeforeUpdateNode(newParentRef);
- // Actually perform the rename and return a pseudo
- // ChildAssociationRef.
- try
- {
- fAVMService.rename(srcParent, srcName, dstParent, dstName);
- ChildAssociationRef newAssocRef =
- new ChildAssociationRef(assocTypeQName,
- newParentRef,
- assocQName,
- newChildRef,
- true,
- -1);
- invokeOnMoveNode(oldAssocRef, newAssocRef);
-// invokeOnCreateChildAssociation(newAssocRef);
-// invokeOnDeleteChildAssociation(oldAssocRef);
-// invokeOnUpdateNode(oldParentRef);
-// invokeOnUpdateNode(newParentRef);
- return newAssocRef;
- }
- catch (AVMNotFoundException e)
- {
- throw new InvalidNodeRefException("Non existent node.", nodeToMoveRef);
- }
- catch (AVMExistsException e)
- {
- throw new InvalidNodeRefException("Target already exists.", newParentRef);
- }
- catch (AVMException e)
- {
- throw new InvalidNodeRefException("Illegal move.", nodeToMoveRef);
- }
- }
-
- /**
- * Set the ordering index of the child association. This affects the ordering of
- * of the return values of methods that return a set of children or child
- * associations.
- *
- * @param childAssocRef the child association that must be moved in the order
- * @param index an arbitrary index that will affect the return order
- *
- * @see #getChildAssocs(NodeRef)
- * @see #getChildAssocs(NodeRef, QNamePattern, QNamePattern)
- * @see ChildAssociationRef#getNthSibling()
- */
- public void setChildAssociationIndex(
- ChildAssociationRef childAssocRef,
- int index)
- throws InvalidChildAssociationRefException
- {
- // TODO We'll keep this a no-op unless there's a
- // compelling reason to implement this capability
- // for the AVM repository.
- }
-
- /**
- * @param nodeRef
- * @return Returns the type name
- * @throws InvalidNodeRefException if the node could not be found
- *
- * @see org.alfresco.service.cmr.dictionary.DictionaryService
- */
- public QName getType(NodeRef nodeRef) throws InvalidNodeRefException
- {
- Pair avmVersionPath = AVMNodeConverter.ToAVMVersionPath(nodeRef);
- AVMNodeDescriptor desc = fAVMService.lookup(avmVersionPath.getFirst(),
- avmVersionPath.getSecond());
- if (desc == null)
- {
- throw new InvalidNodeRefException(avmVersionPath.getSecond() + " not found.", nodeRef);
- }
- if (desc.isPlainDirectory())
- {
- return WCMModel.TYPE_AVM_PLAIN_FOLDER;
- }
- else if (desc.isPlainFile())
- {
- return WCMModel.TYPE_AVM_PLAIN_CONTENT;
- }
- else if (desc.isLayeredDirectory())
- {
- return WCMModel.TYPE_AVM_LAYERED_FOLDER;
- }
- else
- {
- return WCMModel.TYPE_AVM_LAYERED_CONTENT;
- }
- }
-
- /**
- * Re-sets the type of the node. Can be called in order specialise a node to a sub-type.
- *
- * This should be used with caution since calling it changes the type of the node and thus
- * implies a different set of aspects, properties and associations. It is the calling codes
- * responsibility to ensure that the node is in a approriate state after changing the type.
- *
- * @param nodeRef the node reference
- * @param typeQName the type QName
- *
- * @since 1.1
- */
- public void setType(NodeRef nodeRef, QName typeQName) throws InvalidNodeRefException
- {
- throw new UnsupportedOperationException("AVM Types are immutable.");
- }
-
- /**
- * Applies an aspect to the given node. After this method has been called,
- * the node with have all the aspect-related properties present
- *
- * @param nodeRef
- * @param aspectTypeQName the aspect to apply to the node
- * @param aspectProperties a minimum of the mandatory properties required for
- * the aspect
- * @throws InvalidNodeRefException
- * @throws InvalidAspectException if the class reference is not to a valid aspect
- *
- * @see org.alfresco.service.cmr.dictionary.DictionaryService#getAspect(QName)
- * @see org.alfresco.service.cmr.dictionary.ClassDefinition#getProperties()
- */
- public void addAspect(
- NodeRef nodeRef,
- QName aspectTypeQName,
- Map aspectProperties)
- throws InvalidNodeRefException, InvalidAspectException
- {
- // Check that the aspect exists.
- AspectDefinition aspectDef = this.dictionaryService.getAspect(aspectTypeQName);
- if (aspectDef == null)
- {
- throw new InvalidAspectException("The aspect is invalid: " + aspectTypeQName,
- aspectTypeQName);
- }
- // Invoke policy behaviors.
-// invokeBeforeUpdateNode(nodeRef);
-// invokeBeforeAddAspect(nodeRef, aspectTypeQName);
- // Crack the nodeRef.
- Pair avmVersionPath = AVMNodeConverter.ToAVMVersionPath(nodeRef);
- int version = avmVersionPath.getFirst();
- if (version >= 0)
- {
- throw new InvalidNodeRefException("Read Only node.", nodeRef);
- }
- String avmPath = avmVersionPath.getSecond();
- // Accumulate properties.
- Map properties = new HashMap();
- // Add the supplied properties.
- if (aspectProperties != null)
- {
- properties.putAll(aspectProperties);
- }
- // Now set any unspecified default properties for the aspect.
- Map defaultProperties = getDefaultProperties(aspectDef);
- properties.putAll(defaultProperties);
- // Now add any cascading aspects.
- addDefaultAspects(aspectDef, avmPath, properties);
- // Set the property values on the AVM Node.
- if (properties.size() != 0)
- {
- Map props = new HashMap();
- for (Map.Entry entry : properties.entrySet())
- {
- QName propertyQName = entry.getKey();
- if (isBuiltInProperty(propertyQName))
- {
- continue;
- }
- Serializable value = entry.getValue();
- PropertyDefinition propertyDef = dictionaryService.getProperty(propertyQName);
- PropertyValue propertyValue = makePropertyValue(propertyDef, value);
- props.put(propertyQName, propertyValue);
- }
- if (props.size() != 0)
- {
- fAVMService.setNodeProperties(avmPath, props);
- }
- }
- if (isBuiltinAspect(aspectTypeQName))
- {
- // No more work to do in this case.
- return;
- }
- try
- {
- fAVMService.addAspect(avmPath, aspectTypeQName);
- // Invoke policy behaviors.
-// invokeOnUpdateNode(nodeRef);
-// invokeOnAddAspect(nodeRef, aspectTypeQName);
- }
- catch (AVMNotFoundException e)
- {
- throw new InvalidNodeRefException(nodeRef);
- }
- }
-
- /**
- * Add any aspects that are mandatory for the ClassDefinition.
- * @param classDef The ClassDefinition.
- * @param path The path to the AVMNode.
- * @param properties The in/out map of accumulated properties.
- */
- private void addDefaultAspects(ClassDefinition classDef, String path,
- Map properties)
- {
- NodeRef nodeRef = AVMNodeConverter.ToNodeRef(-1, path);
- // Get mandatory aspects.
- List defaultAspectDefs = classDef.getDefaultAspects();
- // add all the aspects (and there dependent aspects recursively).
- for (AspectDefinition def : defaultAspectDefs)
- {
-// invokeBeforeAddAspect(nodeRef, def.getName());
- addAspect(nodeRef, def.getName(), Collections.emptyMap());
- properties.putAll(getDefaultProperties(def));
-// invokeOnAddAspect(nodeRef, def.getName());
- // recurse
- addDefaultAspects(def, path, properties);
- }
- }
-
- /**
- * Remove an aspect and all related properties from a node
- *
- * @param nodeRef
- * @param aspectTypeQName the type of aspect to remove
- * @throws InvalidNodeRefException if the node could not be found
- * @throws InvalidAspectException if the the aspect is unknown or if the
- * aspect is mandatory for the class of the node
- */
- public void removeAspect(NodeRef nodeRef, QName aspectTypeQName)
- throws InvalidNodeRefException, InvalidAspectException
- {
- // Invoke policy behaviors.
-// invokeBeforeUpdateNode(nodeRef);
-// invokeBeforeRemoveAspect(nodeRef, aspectTypeQName);
- AspectDefinition def = dictionaryService.getAspect(aspectTypeQName);
- if (def == null)
- {
- throw new InvalidAspectException(aspectTypeQName);
- }
- if (isBuiltinAspect(aspectTypeQName))
- {
- // TODO shouldn't we be throwing some kind of exception here.
- return;
- }
- Pair avmVersionPath = AVMNodeConverter.ToAVMVersionPath(nodeRef);
- int version = avmVersionPath.getFirst();
- if (version >= 0)
- {
- throw new InvalidNodeRefException("Read Only Node.", nodeRef);
- }
- String path = avmVersionPath.getSecond();
- try
- {
- if (fAVMService.hasAspect(-1, path, aspectTypeQName))
- {
- fAVMService.removeAspect(path, aspectTypeQName);
- Map propDefs = def.getProperties();
- for (QName propertyName : propDefs.keySet())
- {
- fAVMService.deleteNodeProperty(path, propertyName);
- }
- }
- // Invoke policy behaviors.
-// invokeOnUpdateNode(nodeRef);
-// invokeOnRemoveAspect(nodeRef, aspectTypeQName);
- }
- catch (AVMNotFoundException e)
- {
- throw new InvalidNodeRefException(nodeRef);
- }
- }
-
- /**
- * Determines if a given aspect is present on a node. Aspects may only be
- * removed if they are NOT mandatory.
- *
- * @param nodeRef
- * @param aspectTypeQName
- * @return Returns true if the aspect has been applied to the given node,
- * otherwise false
- * @throws InvalidNodeRefException if the node could not be found
- * @throws InvalidAspectException if the aspect reference is invalid
- */
- public boolean hasAspect(NodeRef nodeRef, QName aspectTypeQName)
- throws InvalidNodeRefException, InvalidAspectException
- {
- Pair avmVersionPath = AVMNodeConverter.ToAVMVersionPath(nodeRef);
- int version = avmVersionPath.getFirst();
- String path = avmVersionPath.getSecond();
- if (isBuiltinAspect(aspectTypeQName))
- {
- return true;
- }
- return fAVMService.hasAspect(version, path, aspectTypeQName);
- }
-
- private static QName [] fgBuiltinAspects = new QName[] { ContentModel.ASPECT_AUDITABLE,
- ContentModel.ASPECT_REFERENCEABLE };
-
- private boolean isBuiltinAspect(QName aspectQName)
- {
- for (QName builtin : fgBuiltinAspects)
- {
- if (builtin.equals(aspectQName))
- {
- return true;
- }
- }
- return false;
- }
-
- /**
- * @param nodeRef
- * @return Returns a set of all aspects applied to the node, including mandatory
- * aspects
- * @throws InvalidNodeRefException if the node could not be found
- */
- public Set getAspects(NodeRef nodeRef) throws InvalidNodeRefException
- {
- Pair avmVersionPath = AVMNodeConverter.ToAVMVersionPath(nodeRef);
- int version = avmVersionPath.getFirst();
- String path = avmVersionPath.getSecond();
- Set result = new HashSet();
- // Add the builtin ones.
- for (QName name : fgBuiltinAspects)
- {
- result.add(name);
- }
- try
- {
- for (QName name : fAVMService.getAspects(version, path))
- {
- result.add(name);
- }
- return result;
- }
- catch (AVMNotFoundException e)
- {
- throw new InvalidNodeRefException(nodeRef);
- }
- }
-
- /**
- * Deletes the given node.
- *
- * All associations (both children and regular node associations)
- * will be deleted, and where the given node is the primary parent,
- * the children will also be cascade deleted.
- *
- * @param nodeRef reference to a node within a store
- * @throws InvalidNodeRefException if the reference given is invalid
- */
- public void deleteNode(NodeRef nodeRef) throws InvalidNodeRefException
- {
- // Invoke policy behaviors.
-// invokeBeforeDeleteNode(nodeRef);
- Pair avmVersionPath = AVMNodeConverter.ToAVMVersionPath(nodeRef);
- if (avmVersionPath.getFirst() != -1)
- {
- throw new InvalidNodeRefException("Read only store.", nodeRef);
- }
- String [] avmPathBase = AVMNodeConverter.SplitBase(avmVersionPath.getSecond());
- if (avmPathBase[0] == null)
- {
- throw new InvalidNodeRefException("Cannot delete root node.", nodeRef);
- }
- try
- {
-// QName nodeTypeQName = getType(nodeRef);
-// Set aspects = getAspects(nodeRef);
- fAVMService.removeNode(avmPathBase[0], avmPathBase[1]);
-// ChildAssociationRef childAssocRef =
-// new ChildAssociationRef(ContentModel.ASSOC_CHILDREN,
-// AVMNodeConverter.ToNodeRef(-1, avmPathBase[0]),
-// QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI,
-// avmPathBase[1]),
-// nodeRef);
-// invokeOnDeleteNode(childAssocRef, nodeTypeQName, aspects, false);
- }
- catch (AVMNotFoundException e)
- {
- throw new InvalidNodeRefException(avmVersionPath.getSecond() +" not found.", nodeRef);
- }
- }
-
- /**
- * Makes a parent-child association between the given nodes. Both nodes must belong to the same store.
- *
- *
- * @param parentRef
- * @param childRef
- * @param assocTypeQName the qualified name of the association type as defined in the datadictionary
- * @param qname the qualified name of the association
- * @return Returns a reference to the newly created child association
- * @throws InvalidNodeRefException if the parent or child nodes could not be found
- * @throws CyclicChildRelationshipException if the child partakes in a cyclic relationship after the add
- */
- public ChildAssociationRef addChild(
- NodeRef parentRef,
- NodeRef childRef,
- QName assocTypeQName,
- QName qname) throws InvalidNodeRefException
- {
- return addChild(Collections.singletonList(parentRef), childRef, assocTypeQName, qname).get(0);
- }
-
- /**
- * Associates a given child node with a given collection of parents. All nodes must belong to the same store.
- *
- *
- *
- * @param parentRefs
- * @param childRef
- * @param assocTypeQName the qualified name of the association type as defined in the datadictionary
- * @param qname the qualified name of the association
- * @return Returns a reference to the newly created child association
- * @throws InvalidNodeRefException if the parent or child nodes could not be found
- * @throws CyclicChildRelationshipException if the child partakes in a cyclic relationship after the add
- */
- public List addChild(
- Collection parentRefs,
- NodeRef childRef,
- QName assocTypeQName,
- QName qname) throws InvalidNodeRefException
- {
- Pair childVersionPath = AVMNodeConverter.ToAVMVersionPath(childRef);
- AVMNodeDescriptor child = fAVMService.lookup(childVersionPath.getFirst(),
- childVersionPath.getSecond());
- if (child == null)
- {
- throw new InvalidNodeRefException(childVersionPath.getSecond() + " not found.", childRef);
- }
-
- List childAssociationRefs = new ArrayList(parentRefs.size());
- for (NodeRef parentRef : parentRefs)
- {
- Pair parentVersionPath = AVMNodeConverter.ToAVMVersionPath(parentRef);
- if (parentVersionPath.getFirst() >= 0)
- {
- throw new InvalidNodeRefException("Read Only.", parentRef);
- }
- try
- {
- fAVMService.link(parentVersionPath.getSecond(), qname.getLocalName(), child);
- ChildAssociationRef newChild = new ChildAssociationRef(assocTypeQName, parentRef, qname,
- AVMNodeConverter.ToNodeRef(-1, AVMNodeConverter.ExtendAVMPath(parentVersionPath.getSecond(),
- qname.getLocalName())));
- childAssociationRefs.add(newChild);
- }
- catch (AVMException e)
- {
- throw new InvalidNodeRefException("Could not link.", childRef);
- }
- }
- return childAssociationRefs;
- }
-
- /**
- * Severs all parent-child relationships between two nodes.
- *
- * The child node will be cascade deleted if one of the associations was the
- * primary association, i.e. the one with which the child node was created.
- *
- * @param parentRef the parent end of the association
- * @param childRef the child end of the association
- * @throws InvalidNodeRefException if the parent or child nodes could not be found
- */
- public void removeChild(NodeRef parentRef, NodeRef childRef) throws InvalidNodeRefException
- {
- Pair parentVersionPath = AVMNodeConverter.ToAVMVersionPath(parentRef);
- if (parentVersionPath.getFirst() >= 0)
- {
- throw new InvalidNodeRefException("Read only store.", parentRef);
- }
- Pair childVersionPath = AVMNodeConverter.ToAVMVersionPath(childRef);
- if (childVersionPath.getFirst() >= 0)
- {
- throw new InvalidNodeRefException("Read only store.", childRef);
- }
- String parentPath = parentVersionPath.getSecond();
- String childPath = childVersionPath.getSecond();
- String [] childPathBase = AVMNodeConverter.SplitBase(childPath);
- if (childPathBase[0] == null || !childPathBase[0].equals(parentPath))
- {
- throw new InvalidNodeRefException(childPath + " not a child of " + parentPath, childRef);
- }
- try
- {
-// ChildAssociationRef assocRef =
-// new ChildAssociationRef(ContentModel.ASSOC_CHILDREN,
-// AVMNodeConverter.ToNodeRef(-1, parentPath),
-// QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI,
-// childPathBase[1]),
-// AVMNodeConverter.ToNodeRef(-1, childPath));
-// invokeBeforeDeleteChildAssociation(assocRef);
- fAVMService.removeNode(childPathBase[0], childPathBase[1]);
-// invokeOnDeleteChildAssociation(assocRef);
-// invokeOnUpdateNode(AVMNodeConverter.ToNodeRef(-1, parentPath));
- }
- catch (AVMNotFoundException e)
- {
- throw new InvalidNodeRefException(childPathBase[1] + " not found in " + childPathBase[0],
- childRef);
- }
- }
-
- /**
- * TODO: Check implementation
- */
- public boolean removeChildAssociation(ChildAssociationRef childAssocRef)
- {
- NodeRef parentRef = childAssocRef.getParentRef();
- NodeRef childRef = childAssocRef.getChildRef();
- Pair parentVersionPath = AVMNodeConverter.ToAVMVersionPath(parentRef);
- if (parentVersionPath.getFirst() >= 0)
- {
- throw new InvalidNodeRefException("Read only store.", parentRef);
- }
- Pair childVersionPath = AVMNodeConverter.ToAVMVersionPath(childRef);
- if (childVersionPath.getFirst() >= 0)
- {
- throw new InvalidNodeRefException("Read only store.", childRef);
- }
- String parentPath = parentVersionPath.getSecond();
- String childPath = childVersionPath.getSecond();
- String [] childPathBase = AVMNodeConverter.SplitBase(childPath);
- if (childPathBase[0] == null || !childPathBase[0].equals(parentPath))
- {
- return false;
- }
- try
- {
- fAVMService.removeNode(childPathBase[0], childPathBase[1]);
- return true;
- }
- catch (AVMNotFoundException e)
- {
- throw new InvalidNodeRefException("Not found.", childRef);
- }
- }
-
- /**
- * TODO: Implement
- */
- public boolean removeSecondaryChildAssociation(ChildAssociationRef childAssocRef)
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * @param nodeRef
- * @return Returns all properties keyed by their qualified name
- * @throws InvalidNodeRefException if the node could not be found
- */
- public Map getProperties(NodeRef nodeRef) throws InvalidNodeRefException
- {
- Pair avmVersionPath = AVMNodeConverter.ToAVMVersionPath(nodeRef);
- Map props = null;
- AVMNodeDescriptor desc = fAVMService.lookup(avmVersionPath.getFirst(),
- avmVersionPath.getSecond());
- try
- {
- props = fAVMService.getNodeProperties(avmVersionPath.getFirst(),
- avmVersionPath.getSecond());
- }
- catch (AVMNotFoundException e)
- {
- throw new InvalidNodeRefException(avmVersionPath.getSecond() + " not found.", nodeRef);
- }
- Map result = new HashMap();
- for (QName qName : props.keySet())
- {
- PropertyValue value = props.get(qName);
- PropertyDefinition def = dictionaryService.getProperty(qName);
- result.put(qName, makeSerializableValue(def, value));
- }
- // Now spoof properties that are built in.
- result.put(ContentModel.PROP_CREATED, new Date(desc.getCreateDate()));
- result.put(ContentModel.PROP_CREATOR, desc.getCreator());
- result.put(ContentModel.PROP_MODIFIED, new Date(desc.getModDate()));
- result.put(ContentModel.PROP_MODIFIER, desc.getLastModifier());
- result.put(ContentModel.PROP_OWNER, desc.getOwner());
- result.put(ContentModel.PROP_NAME, desc.getName());
- result.put(ContentModel.PROP_NODE_UUID, "UNKNOWN");
- result.put(ContentModel.PROP_NODE_DBID, new Long(desc.getId()));
- result.put(ContentModel.PROP_STORE_PROTOCOL, "avm");
- result.put(ContentModel.PROP_STORE_IDENTIFIER, nodeRef.getStoreRef().getIdentifier());
- if (desc.isLayeredDirectory())
- {
- result.put(WCMModel.PROP_AVM_DIR_INDIRECTION,
- AVMNodeConverter.ToNodeRef(-1, desc.getIndirection()));
- }
- if (desc.isLayeredFile())
- {
- result.put(WCMModel.PROP_AVM_FILE_INDIRECTION,
- AVMNodeConverter.ToNodeRef(-1, desc.getIndirection()));
- }
- if (desc.isFile())
- {
- try
- {
- ContentData contentData = fAVMService.getContentDataForRead(avmVersionPath.getFirst(),
- avmVersionPath.getSecond());
- result.put(ContentModel.PROP_CONTENT, contentData);
- }
- catch (AVMException e)
- {
- // TODO For now ignore.
- }
- }
- return result;
- }
-
- /**
- * @param nodeRef
- * @param qname the qualified name of the property
- * @return Returns the value of the property, or null if not yet set
- * @throws InvalidNodeRefException if the node could not be found
- */
- public Serializable getProperty(NodeRef nodeRef, QName qname) throws InvalidNodeRefException
- {
- Pair avmVersionPath = AVMNodeConverter.ToAVMVersionPath(nodeRef);
- if (isBuiltInProperty(qname))
- {
- return getBuiltInProperty(avmVersionPath, qname, nodeRef);
- }
- try
- {
- PropertyValue value = fAVMService.getNodeProperty(avmVersionPath.getFirst(),
- avmVersionPath.getSecond(),
- qname);
- if (value == null)
- {
- return null;
- }
- PropertyDefinition def = this.dictionaryService.getProperty(qname);
- return makeSerializableValue(def, value);
- }
- catch (AVMNotFoundException e)
- {
- throw new InvalidNodeRefException(avmVersionPath.getSecond() + " not found.", nodeRef);
- }
- }
-
- /**
- * {@inheritDoc}
- */
- public void removeProperty(NodeRef nodeRef, QName qname) throws InvalidNodeRefException
- {
- Pair avmVersionPath = AVMNodeConverter.ToAVMVersionPath(nodeRef);
- if (isBuiltInProperty(qname))
- {
- // Ignore
- return;
- }
- try
- {
- fAVMService.deleteNodeProperty(avmVersionPath.getSecond(), qname);
- }
- catch (AVMNotFoundException e)
- {
- throw new InvalidNodeRefException(avmVersionPath.getSecond() + " not found.", nodeRef);
- }
- }
-
- /**
- * A Helper to spoof built in properties.
- * @param avmVersionPath The broken out version and path from a NodeRef.
- * @param qName The name of the property to retrieve.
- * @param nodeRef The original NodeRef (for error reporting).
- * @return The property value.
- */
- private Serializable getBuiltInProperty(Pair avmVersionPath,
- QName qName,
- NodeRef nodeRef)
- {
- if (qName.equals(ContentModel.PROP_CONTENT))
- {
- try
- {
- ContentData contentData =
- fAVMService.getContentDataForRead(avmVersionPath.getFirst(),
- avmVersionPath.getSecond());
- return contentData;
- }
- catch (AVMException e)
- {
- // TODO This seems very wrong. Do something better
- // sooner rather than later.
- return null;
- }
- }
- AVMNodeDescriptor desc = fAVMService.lookup(avmVersionPath.getFirst(),
- avmVersionPath.getSecond());
- if (desc == null)
- {
- throw new InvalidNodeRefException(avmVersionPath.getSecond() + " not found.", nodeRef);
- }
- if (qName.equals(ContentModel.PROP_CREATED))
- {
- return new Date(desc.getCreateDate());
- }
- else if (qName.equals(ContentModel.PROP_CREATOR))
- {
- return desc.getCreator();
- }
- else if (qName.equals(ContentModel.PROP_MODIFIED))
- {
- return new Date(desc.getModDate());
- }
- else if (qName.equals(ContentModel.PROP_MODIFIER))
- {
- return desc.getLastModifier();
- }
- else if (qName.equals(ContentModel.PROP_OWNER))
- {
- return desc.getOwner();
- }
- else if (qName.equals(ContentModel.PROP_NAME))
- {
- return desc.getName();
- }
- else if (qName.equals(ContentModel.PROP_NODE_UUID))
- {
- return "UNKNOWN";
- }
- else if (qName.equals(ContentModel.PROP_NODE_DBID))
- {
- return new Long(desc.getId());
- }
- else if (qName.equals(ContentModel.PROP_STORE_PROTOCOL))
- {
- return "avm";
- }
- else if (qName.equals(ContentModel.PROP_STORE_IDENTIFIER))
- {
- return nodeRef.getStoreRef().getIdentifier();
- }
- else if (qName.equals(WCMModel.PROP_AVM_DIR_INDIRECTION))
- {
- if (desc.isLayeredDirectory())
- {
- return AVMNodeConverter.ToNodeRef(-1, desc.getIndirection());
- }
- return null;
- }
- else if (qName.equals(WCMModel.PROP_AVM_FILE_INDIRECTION))
- {
- if (desc.isLayeredFile())
- {
- return AVMNodeConverter.ToNodeRef(-1, desc.getIndirection());
- }
- return null;
- }
- else
- {
- logger.error("Invalid Built In Property: " + qName);
- return null;
- }
- }
-
- /**
- * Set the values of all properties to be an Serializable
instances.
- * The properties given must still fulfill the requirements of the class and
- * aspects relevant to the node.
- *
- * NOTE: Null values are allowed.
- *
- * @param nodeRef
- * @param properties all the properties of the node keyed by their qualified names
- * @throws InvalidNodeRefException if the node could not be found
- */
- public void setProperties(NodeRef nodeRef, Map properties) throws InvalidNodeRefException
- {
- Pair avmVersionPath = AVMNodeConverter.ToAVMVersionPath(nodeRef);
- if (avmVersionPath.getFirst() >= 0)
- {
- throw new InvalidNodeRefException("Read only store.", nodeRef);
- }
- // TODO Not sure this try block is necessary.
- try
- {
- // Prepare fr policy invocation.
- Map propsBefore = null;
- if (fInvokePolicies)
- {
- propsBefore = getProperties(nodeRef);
- }
- // Remove all properties
- fAVMService.deleteNodeProperties(avmVersionPath.getSecond());
- // Rebuild node properties
- Map values = new HashMap();
- for (Map.Entry entry : properties.entrySet())
- {
- QName propertyQName = entry.getKey();
- Serializable value = entry.getValue();
- // For AVM nodes is in place.
- if (isBuiltInProperty(propertyQName))
- {
- if (propertyQName.equals(ContentModel.PROP_CONTENT))
- {
- AVMNodeDescriptor desc = fAVMService.lookup(-1, avmVersionPath.getSecond());
- if (desc == null)
- {
- throw new InvalidNodeRefException(avmVersionPath.getSecond() + " not found.", nodeRef);
- }
- if (desc.isPlainFile())
- {
- fAVMService.setContentData(avmVersionPath.getSecond(),
- (ContentData)properties.get(propertyQName));
- }
- }
- }
- PropertyDefinition propertyDef = dictionaryService.getProperty(propertyQName);
- PropertyValue propertyValue = makePropertyValue(propertyDef, value);
- values.put(propertyQName, propertyValue);
- }
- // Finally set node properties
- fAVMService.setNodeProperties(avmVersionPath.getSecond(), values);
- // Invoke policies
- if (fInvokePolicies)
- {
- Map propsAfter = properties;
- invokeOnUpdateProperties(nodeRef, propsBefore, propsAfter);
- }
- // Invoke policy behaviors.
-// invokeOnUpdateNode(nodeRef);
-// invokeOnUpdateProperties(nodeRef, oldProps, properties);
- }
- catch (AVMNotFoundException e)
- {
- throw new InvalidNodeRefException(avmVersionPath.getSecond() + " not found.", nodeRef);
- }
- }
-
- public void addProperties(NodeRef nodeRef, Map properties)
- {
- // Overwrite the current properties
- Map currentProperties = getProperties(nodeRef);
- currentProperties.putAll(properties);
- setProperties(nodeRef, currentProperties);
- }
-
- static QName [] fgBuiltinProperties = new QName []
- {
- ContentModel.PROP_CREATED,
- ContentModel.PROP_CREATOR,
- ContentModel.PROP_MODIFIED,
- ContentModel.PROP_MODIFIER,
- ContentModel.PROP_OWNER,
- ContentModel.PROP_CONTENT,
- ContentModel.PROP_NAME,
- ContentModel.PROP_NODE_UUID,
- ContentModel.PROP_NODE_DBID,
- ContentModel.PROP_STORE_PROTOCOL,
- ContentModel.PROP_STORE_IDENTIFIER,
- WCMModel.PROP_AVM_FILE_INDIRECTION,
- WCMModel.PROP_AVM_DIR_INDIRECTION
- };
-
- /**
- * Helper to distinguish built-in from generic properties.
- * @param qName The name of the property to check.
- * @return Whether qName
is a built-in propety.
- */
- private boolean isBuiltInProperty(QName qName)
- {
- for (QName name : fgBuiltinProperties)
- {
- if (name.equals(qName))
- {
- return true;
- }
- }
- return false;
- }
-
- /**
- * Sets the value of a property to be any Serializable
instance.
- * To remove a property value, use {@link #getProperties(NodeRef)}, remove the
- * value and call {@link #setProperties(NodeRef, Map)}.
- *
- * NOTE: Null values are allowed.
- *
- * @param nodeRef
- * @param qname the fully qualified name of the property
- * @param propertyValue the value of the property - never null
- * @throws InvalidNodeRefException if the node could not be found
- */
- public void setProperty(NodeRef nodeRef, QName qname, Serializable value) throws InvalidNodeRefException
- {
- // Invoke policy behaviors.
- // invokeBeforeUpdateNode(nodeRef);
- Pair avmVersionPath = AVMNodeConverter.ToAVMVersionPath(nodeRef);
- if (avmVersionPath.getFirst() >= 0)
- {
- throw new InvalidNodeRefException("Read only store.", nodeRef);
- }
-
- Map propsBefore = null;
- if (fInvokePolicies)
- {
- propsBefore = getProperties(nodeRef);
- }
-
- if (isBuiltInProperty(qname))
- {
- if (qname.equals(ContentModel.PROP_CONTENT))
- {
- try
- {
- fAVMService.setContentData(avmVersionPath.getSecond(), (ContentData)value);
- if (fInvokePolicies)
- {
- Map propsAfter = new HashMap(propsBefore);
- propsAfter.put(ContentModel.PROP_CONTENT, value);
- invokeOnUpdateProperties(nodeRef, propsBefore, propsAfter);
- }
- }
- catch (ClassCastException e)
- {
- throw new AVMException("Invalid ContentData.", e);
- }
- }
- return;
- }
- try
- {
-
- PropertyDefinition propertyDef = dictionaryService.getProperty(qname);
- PropertyValue propertyValue = makePropertyValue(propertyDef, value);
- fAVMService.setNodeProperty(avmVersionPath.getSecond(), qname, propertyValue);
- if (fInvokePolicies)
- {
- Map propsAfter = new HashMap(propsBefore);
- propsAfter.put(qname, value);
- invokeOnUpdateProperties(nodeRef, propsBefore, propsAfter);
- }
- // Map propsAfter = getProperties(nodeRef);
- // Invoke policy behaviors.
- // invokeOnUpdateNode(nodeRef);
- // invokeOnUpdateProperties(nodeRef, propsBefore, propsAfter);
- }
- catch (AVMNotFoundException e)
- {
- throw new InvalidNodeRefException(avmVersionPath.getSecond() + " not found.", nodeRef);
- }
- }
-
- /**
- * @param nodeRef the child node
- * @return Returns a list of all parent-child associations that exist where the given
- * node is the child
- * @throws InvalidNodeRefException if the node could not be found
- *
- * @see #getParentAssocs(NodeRef, QNamePattern, QNamePattern)
- */
- public List getParentAssocs(NodeRef nodeRef) throws InvalidNodeRefException
- {
- // TODO OK, for now we'll simply return the single parent that corresponds
- // to the path stuffed in the NodeRef.
- Pair avmVersionPath = AVMNodeConverter.ToAVMVersionPath(nodeRef);
- String path = avmVersionPath.getSecond();
- List result = new ArrayList();
- String [] splitPath = AVMNodeConverter.SplitBase(path);
- if (splitPath[0] == null)
- {
- return result;
- }
- result.add(new ChildAssociationRef(ContentModel.ASSOC_CONTAINS,
- AVMNodeConverter.ToNodeRef(avmVersionPath.getFirst(),
- splitPath[0]),
- QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI,
- splitPath[1]),
- nodeRef,
- true,
- -1));
- return result;
- }
-
- /**
- * Gets all parent associations where the pattern of the association qualified
- * name is a match
- *
- * The resultant list is ordered by (a) explicit index and (b) association creation time.
- *
- * @param nodeRef the child node
- * @param typeQNamePattern the pattern that the type qualified name of the association must match
- * @param qnamePattern the pattern that the qnames of the assocs must match
- * @return Returns a list of all parent-child associations that exist where the given
- * node is the child
- * @throws InvalidNodeRefException if the node could not be found
- *
- * @see ChildAssociationRef#getNthSibling()
- * @see #setChildAssociationIndex(ChildAssociationRef, int)
- * @see QName
- * @see org.alfresco.service.namespace.RegexQNamePattern#MATCH_ALL
- */
- public List getParentAssocs(NodeRef nodeRef, QNamePattern typeQNamePattern, QNamePattern qnamePattern)
- throws InvalidNodeRefException
- {
- if (!typeQNamePattern.isMatch(ContentModel.ASSOC_CONTAINS))
- {
- return new ArrayList();
- }
- List result = getParentAssocs(nodeRef);
- if (result.size() == 0)
- {
- return result;
- }
- if (qnamePattern.isMatch(result.get(0).getQName()))
- {
- return result;
- }
- return new ArrayList();
- }
-
- /**
- * Get all child associations of the given node.
- *
- * The resultant list is ordered by (a) explicit index and (b) association creation time.
- *
- * @param nodeRef the parent node - usually a container
- * @return Returns a collection of ChildAssocRef
instances. If the
- * node is not a container then the result will be empty.
- * @throws InvalidNodeRefException if the node could not be found
- *
- * @see #getChildAssocs(NodeRef, QNamePattern, QNamePattern)
- * @see #setChildAssociationIndex(ChildAssociationRef, int)
- * @see ChildAssociationRef#getNthSibling()
- */
- public List getChildAssocs(NodeRef nodeRef) throws InvalidNodeRefException
- {
-
- Pair avmVersionPath = AVMNodeConverter.ToAVMVersionPath(nodeRef);
- int version = avmVersionPath.getFirst();
- String path = avmVersionPath.getSecond();
- List result = new ArrayList();
- SortedMap children = null;
- try
- {
- children =
- fAVMService.getDirectoryListing(version,
- path);
- }
- catch (AVMNotFoundException e)
- {
- return result;
- }
- for (String name : children.keySet())
- {
- result.add(new ChildAssociationRef(ContentModel.ASSOC_CONTAINS,
- nodeRef,
- QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI,
- name),
- AVMNodeConverter.ToNodeRef(
- version,
- AVMNodeConverter.ExtendAVMPath(path, name)),
- true,
- -1));
- }
- return result;
- }
-
- /**
- * Gets all child associations where the pattern of the association qualified
- * name is a match.
- *
- * @param nodeRef the parent node - usually a container
- * @param typeQNamePattern the pattern that the type qualified name of the association must match
- * @param qnamePattern the pattern that the qnames of the assocs must match
- * @return Returns a list of ChildAssocRef
instances. If the
- * node is not a container then the result will be empty.
- * @throws InvalidNodeRefException if the node could not be found
- *
- * @see QName
- * @see org.alfresco.service.namespace.RegexQNamePattern#MATCH_ALL
- */
- public List getChildAssocs(
- NodeRef nodeRef,
- QNamePattern typeQNamePattern,
- QNamePattern qnamePattern)
- throws InvalidNodeRefException
- {
- List result = new ArrayList();
- if (!typeQNamePattern.isMatch(ContentModel.ASSOC_CONTAINS))
- {
- return result;
- }
- // First check if we are matching on all
- if (qnamePattern == null || !(qnamePattern instanceof QName))
- {
- // Either null (always match) or we have to match on each, individually
- List all = getChildAssocs(nodeRef);
- for (ChildAssociationRef child : all)
- {
- if (qnamePattern == null || !qnamePattern.isMatch(child.getQName()))
- {
- continue;
- }
- result.add(child);
- }
- return result;
- }
- else
- {
- // We have a specific QName and therefore an exact path
- QName qname = (QName) qnamePattern;
- String name = qname.getLocalName();
-
- // Resolve the container
- Pair containerVersionPath = AVMNodeConverter.ToAVMVersionPath(nodeRef);
- int containerVersion = containerVersionPath.getFirst();
- String containerPath = containerVersionPath.getSecond();
- try
- {
- // Get the descriptor for the container
- AVMNodeDescriptor containerDescriptor = fAVMService.lookup(containerVersion, containerPath);
- @SuppressWarnings("unused") // Might succeed or fail
- AVMNodeDescriptor childDescriptor = fAVMService.lookup(containerDescriptor, name);
- result.add(
- new ChildAssociationRef(
- ContentModel.ASSOC_CONTAINS,
- nodeRef,
- QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, name),
- AVMNodeConverter.ToNodeRef(
- containerVersion,
- AVMNodeConverter.ExtendAVMPath(containerPath, name)),
- true,
- -1));
- }
- catch (AVMNotFoundException e)
- {
- return result;
- }
- catch (AVMWrongTypeException e)
- {
- return result;
- }
- return result;
- }
- }
-
- @Override
- public List getChildAssocs(NodeRef nodeRef, QNamePattern typeQName, QNamePattern qname, int maxResults,
- boolean preload) throws InvalidNodeRefException
- {
- List result = getChildAssocs(nodeRef, typeQName, qname);
- if (result.size() > maxResults)
- {
- return result.subList(0, maxResults);
- }
- return result;
- }
-
- public List getChildAssocs(NodeRef nodeRef, QNamePattern typeQNamePattern,
- QNamePattern qnamePattern, boolean preload) throws InvalidNodeRefException
- {
- return getChildAssocs(nodeRef, typeQNamePattern, qnamePattern);
- }
-
- public List getChildAssocs(NodeRef nodeRef, Set childNodeTypes)
- {
- /*
- * ETWOTWO-961 forced an implementation, but this is just a workaround.
- * We do a listing and then keep files or folders looking specifically
- * for cm:folder and cm:content types from childNodeTypes.
- */
- Pair avmVersionPath = AVMNodeConverter.ToAVMVersionPath(nodeRef);
- int version = avmVersionPath.getFirst();
- String path = avmVersionPath.getSecond();
- List result = new ArrayList();
- SortedMap children = null;
- try
- {
- children =
- fAVMService.getDirectoryListing(version,
- path);
- }
- catch (AVMNotFoundException e)
- {
- return result;
- }
- for (Map.Entry entry : children.entrySet())
- {
- String name = entry.getKey();
- AVMNodeDescriptor descriptor = entry.getValue();
- if (descriptor.isFile())
- {
- if (!childNodeTypes.contains(ContentModel.TYPE_CONTENT))
- {
- continue;
- }
- }
- else if (descriptor.isDirectory())
- {
- if (!childNodeTypes.contains(ContentModel.TYPE_FOLDER))
- {
- continue;
- }
- }
- else
- {
- // Not a file or directory???
- continue;
- }
- result.add(new ChildAssociationRef(ContentModel.ASSOC_CONTAINS,
- nodeRef,
- QName.createQName(
- NamespaceService.CONTENT_MODEL_1_0_URI,
- name),
- AVMNodeConverter.ToNodeRef(
- version,
- AVMNodeConverter.ExtendAVMPath(path, name)),
- true,
- -1));
- }
- return result;
- }
-
- /**
- * getChildrenByName
- */
- public List getChildrenByName(NodeRef nodeRef, QName assocTypeQName, Collection childNames)
- {
- final List results = new ArrayList(100);
-
- if (!assocTypeQName.equals(ContentModel.ASSOC_CONTAINS))
- {
- throw new UnsupportedOperationException("AVM getChildrenByName only supports ASSOCS_CONTAINS.");
- }
-
- Pair avmVersionPath = AVMNodeConverter.ToAVMVersionPath(nodeRef);
- try
- {
- for(String childName : childNames)
- {
- AVMNodeDescriptor child = fAVMService.lookup(avmVersionPath.getFirst(),
- AVMUtil.extendAVMPath(avmVersionPath.getSecond(), childName));
-
- if (child != null)
- {
- NodeRef childRef = AVMNodeConverter.ToNodeRef(avmVersionPath.getFirst(),
- child.getPath());
- QName childQName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI,
- childName);
- ChildAssociationRef ref = new ChildAssociationRef(assocTypeQName, nodeRef, childQName, childRef);
-
- if(logger.isDebugEnabled())
- {
- logger.debug("got a child node :" + ref);
- }
- results.add(ref);
- }
- }
- return results;
- }
- catch (AVMException e)
- {
- logger.debug("exception in getChildrenByName ", e);
- return results;
- }
- }
-
-
- /**
- * Get a child NodeRef by name.
- * @param nodeRef The parent node.
- * @param assocTypeQName The type of the Child Association.
- * @param childName The name of the child to get.
- */
- public NodeRef getChildByName(NodeRef nodeRef, QName assocTypeQName, String childName)
- {
- if (!assocTypeQName.equals(ContentModel.ASSOC_CONTAINS))
- {
- return null;
- }
- Pair avmVersionPath = AVMNodeConverter.ToAVMVersionPath(nodeRef);
- try
- {
- AVMNodeDescriptor child = fAVMService.lookup(avmVersionPath.getFirst(),
- AVMUtil.extendAVMPath(avmVersionPath.getSecond(), childName));
- if (child == null)
- {
- return null;
- }
- return AVMNodeConverter.ToNodeRef(avmVersionPath.getFirst(),
- child.getPath());
- }
- catch (AVMException e)
- {
- return null;
- }
- }
-
- /**
- * Fetches the primary parent-child relationship.
- *
- * For a root node, the parent node reference will be null.
- *
- * @param nodeRef
- * @return Returns the primary parent-child association of the node
- * @throws InvalidNodeRefException if the node could not be found
- */
- public ChildAssociationRef getPrimaryParent(NodeRef nodeRef) throws InvalidNodeRefException
- {
- List parents = getParentAssocs(nodeRef);
- if (parents.size() == 0)
- {
- return new ChildAssociationRef(null, null, null, nodeRef);
- }
- return parents.get(0);
- }
-
- /**
- * @throws UnsupportedOperationException always
- */
- @Override
- public AssociationRef createAssociation(NodeRef sourceRef, NodeRef targetRef, QName assocTypeQName)
- throws InvalidNodeRefException, AssociationExistsException
- {
- throw new UnsupportedOperationException("AVM does not support arbitrary associations.");
- }
-
- /**
- * @throws UnsupportedOperationException always
- */
- @Override
- public void setAssociations(NodeRef sourceRef, QName assocTypeQName, List targetRefs)
- {
- throw new UnsupportedOperationException("AVM does not support arbitrary associations.");
- }
-
- /**
- *
- * @param sourceRef the associaton source node
- * @param targetRef the association target node
- * @param assocTypeQName the qualified name of the association type
- * @throws InvalidNodeRefException if either of the nodes could not be found
- */
- public void removeAssociation(NodeRef sourceRef, NodeRef targetRef, QName assocTypeQName)
- throws InvalidNodeRefException
- {
- throw new UnsupportedOperationException("AVM does not support arbitrary associations.");
- }
-
- /**
- * Gets an association by ID.
- *
- * @param assocId
- * the association id
- * @return the association, or null
if it does not exist
- */
- public AssociationRef getAssoc(Long id)
- {
- return null;
- }
-
- /**
- * Fetches all associations from the given source where the associations'
- * qualified names match the pattern provided.
- *
- * @param sourceRef the association source
- * @param qnamePattern the association qname pattern to match against
- * @return Returns a list of NodeAssocRef
instances for which the
- * given node is a source
- * @throws InvalidNodeRefException if the source node could not be found
- *
- * @see QName
- * @see org.alfresco.service.namespace.RegexQNamePattern#MATCH_ALL
- */
- public List getTargetAssocs(NodeRef sourceRef, QNamePattern qnamePattern)
- throws InvalidNodeRefException
- {
- return new ArrayList();
- }
-
- /**
- * Fetches all associations to the given target where the associations'
- * qualified names match the pattern provided.
- *
- * @param targetRef the association target
- * @param qnamePattern the association qname pattern to match against
- * @return Returns a list of NodeAssocRef
instances for which the
- * given node is a target
- * @throws InvalidNodeRefException
- *
- * @see QName
- * @see org.alfresco.service.namespace.RegexQNamePattern#MATCH_ALL
- */
- public List getSourceAssocs(NodeRef targetRef, QNamePattern qnamePattern)
- throws InvalidNodeRefException
- {
- return new ArrayList();
- }
-
- /**
- * The root node has an entry in the path(s) returned. For this reason, there
- * will always be at least one path element in the returned path(s).
- * The first element will have a null parent reference and qname.
- *
- * @param nodeRef
- * @return Returns the path to the node along the primary node path
- * @throws InvalidNodeRefException if the node could not be found
- *
- * @see #getPaths(NodeRef, boolean)
- */
- public Path getPath(NodeRef nodeRef) throws InvalidNodeRefException
- {
- // TODO Review later. This may be wrong.
- Path path = new Path();
- Pair avmVersionPath = AVMNodeConverter.ToAVMVersionPath(nodeRef);
- int version = avmVersionPath.getFirst();
- String currPath = avmVersionPath.getSecond();
- while (!currPath.endsWith("/"))
- {
- String [] splitPath = AVMNodeConverter.SplitBase(currPath);
- String parentPath = splitPath[0];
- String name = splitPath[1];
- ChildAssociationRef caRef =
- new ChildAssociationRef(ContentModel.ASSOC_CONTAINS,
- AVMNodeConverter.ToNodeRef(version, parentPath),
- QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI,
- name),
- AVMNodeConverter.ToNodeRef(version, currPath),
- true,
- -1);
- path.prepend(new Path.ChildAssocElement(caRef));
- currPath = parentPath;
- }
- ChildAssociationRef caRef = new ChildAssociationRef(null, null, null,
- AVMNodeConverter.ToNodeRef(version,
- currPath));
- path.prepend(new Path.ChildAssocElement(caRef));
- return path;
- }
-
- /**
- * The root node has an entry in the path(s) returned. For this reason, there
- * will always be at least one path element in the returned path(s).
- * The first element will have a null parent reference and qname.
- *
- * @param nodeRef
- * @param primaryOnly true if only the primary path must be retrieved. If true, the
- * result will have exactly one entry.
- * @return Returns a List of all possible paths to the given node
- * @throws InvalidNodeRefException if the node could not be found
- */
- public List getPaths(NodeRef nodeRef, boolean primaryOnly) throws InvalidNodeRefException
- {
- List result = new ArrayList();
- result.add(getPath(nodeRef));
- return result;
- }
-
- /**
- * Get the node where archived items will have gone when deleted from the given store.
- *
- * @param storeRef the store that items were deleted from
- * @return Returns the archive node parent
- */
- public NodeRef getStoreArchiveNode(StoreRef storeRef)
- {
- throw new UnsupportedOperationException("AVM does not support this operation.");
- }
-
- /**
- * Restore an individual node (along with its sub-tree nodes) to the target location.
- * The archived node must have the {@link org.alfresco.model.ContentModel#ASPECT_ARCHIVED archived aspect}
- * set against it.
- *
- * @param archivedNodeRef the archived node
- * @param destinationParentNodeRef the parent to move the node into
- * or null to use the original
- * @param assocTypeQName the primary association type name to use in the new location
- * or null to use the original
- * @param assocQName the primary association name to use in the new location
- * or null to use the original
- * @return Returns the reference to the newly created node
- */
- public NodeRef restoreNode(
- NodeRef archivedNodeRef,
- NodeRef destinationParentNodeRef,
- QName assocTypeQName,
- QName assocQName)
- {
- throw new UnsupportedOperationException("AVM does not support this operation.");
- }
-
- /* (non-Javadoc)
- * @see org.alfresco.service.cmr.repository.NodeService#getChildAssocsWithoutParentAssocsOfType(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName)
- */
- public Collection getChildAssocsWithoutParentAssocsOfType(NodeRef parent, QName assocTypeQName)
- {
- throw new UnsupportedOperationException("AVM does not support this operation.");
- }
-
- public Long getNodeAclId(NodeRef nodeRef) throws InvalidNodeRefException
- {
- throw new UnsupportedOperationException("getNodeAclId is unsupported for AVMNodeService");
- }
-
- @Override
- public List getChildAssocsByPropertyValue(
- NodeRef nodeRef, QName propertyQName, Serializable value)
- {
- throw new UnsupportedOperationException("AVM does not support this operation.");
- }
-
- @Override
- public int countChildAssocs(NodeRef nodeRef, boolean isPrimary) throws InvalidNodeRefException
- {
- throw new UnsupportedOperationException("AVM does not support this operation.");
- }
-
-}
+/*
+ * Copyright (C) 2005-2010 Alfresco Software Limited.
+ *
+ * This file is part of Alfresco
+ *
+ * Alfresco is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Alfresco is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with Alfresco. If not, see . */
+
+package org.alfresco.repo.avm;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.SortedMap;
+
+import org.alfresco.model.ContentModel;
+import org.alfresco.model.WCMModel;
+import org.alfresco.repo.avm.util.AVMUtil;
+import org.alfresco.repo.domain.PropertyValue;
+import org.alfresco.repo.node.AbstractNodeServiceImpl;
+import org.alfresco.service.cmr.avm.AVMException;
+import org.alfresco.service.cmr.avm.AVMExistsException;
+import org.alfresco.service.cmr.avm.AVMNodeDescriptor;
+import org.alfresco.service.cmr.avm.AVMNotFoundException;
+import org.alfresco.service.cmr.avm.AVMService;
+import org.alfresco.service.cmr.avm.AVMStoreDescriptor;
+import org.alfresco.service.cmr.avm.AVMWrongTypeException;
+import org.alfresco.service.cmr.dictionary.AspectDefinition;
+import org.alfresco.service.cmr.dictionary.ClassDefinition;
+import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
+import org.alfresco.service.cmr.dictionary.DictionaryException;
+import org.alfresco.service.cmr.dictionary.InvalidAspectException;
+import org.alfresco.service.cmr.dictionary.InvalidTypeException;
+import org.alfresco.service.cmr.dictionary.PropertyDefinition;
+import org.alfresco.service.cmr.dictionary.TypeDefinition;
+import org.alfresco.service.cmr.repository.AssociationExistsException;
+import org.alfresco.service.cmr.repository.AssociationRef;
+import org.alfresco.service.cmr.repository.ChildAssociationRef;
+import org.alfresco.service.cmr.repository.ContentData;
+import org.alfresco.service.cmr.repository.CyclicChildRelationshipException;
+import org.alfresco.service.cmr.repository.InvalidChildAssociationRefException;
+import org.alfresco.service.cmr.repository.InvalidNodeRefException;
+import org.alfresco.service.cmr.repository.InvalidStoreRefException;
+import org.alfresco.service.cmr.repository.NodeRef;
+import org.alfresco.service.cmr.repository.NodeService;
+import org.alfresco.service.cmr.repository.Path;
+import org.alfresco.service.cmr.repository.StoreExistsException;
+import org.alfresco.service.cmr.repository.StoreRef;
+import org.alfresco.service.cmr.repository.datatype.TypeConversionException;
+import org.alfresco.service.namespace.NamespaceService;
+import org.alfresco.service.namespace.QName;
+import org.alfresco.service.namespace.QNamePattern;
+import org.alfresco.util.Pair;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * NodeService implementing facade over AVMService.
+ * @author britt
+ */
+public class AVMNodeService extends AbstractNodeServiceImpl implements NodeService
+{
+ private static Log logger = LogFactory.getLog(AVMNodeService.class);
+
+ /**
+ * Flag for whether policy callbacks are made.
+ */
+ private boolean fInvokePolicies = false;
+
+ /**
+ * Reference to AVMService.
+ */
+ private AVMService fAVMService;
+
+ /**
+ * Set the AVMService. For Spring.
+ * @param service The AVMService instance.
+ */
+ public void setAvmService(AVMService service)
+ {
+ fAVMService = service;
+ }
+
+ /**
+ * Default constructor.
+ */
+ public AVMNodeService()
+ {
+ }
+
+ public void setInvokePolicies(boolean invoke)
+ {
+ fInvokePolicies = invoke;
+ }
+
+ /**
+ * Helper method to convert the Serializable
value into a full,
+ * persistable {@link PropertyValue}.
+ *
+ * Where the property definition is null, the value will take on the
+ * {@link DataTypeDefinition#ANY generic ANY} value.
+ *
+ * Where the property definition specifies a multi-valued property but the
+ * value provided is not a collection, the value will be wrapped in a collection.
+ *
+ * @param propertyDef the property dictionary definition, may be null
+ * @param value the value, which will be converted according to the definition -
+ * may be null
+ * @return Returns the persistable property value
+ */
+ protected PropertyValue makePropertyValue(PropertyDefinition propertyDef, Serializable value)
+ {
+ // get property attributes
+ QName propertyTypeQName = null;
+ if (propertyDef == null) // property not recognised
+ {
+ // allow it for now - persisting excess properties can be useful sometimes
+ propertyTypeQName = DataTypeDefinition.ANY;
+ }
+ else
+ {
+ propertyTypeQName = propertyDef.getDataType().getName();
+ // check that multi-valued properties are allowed
+ boolean isMultiValued = propertyDef.isMultiValued();
+ if (isMultiValued && !(value instanceof Collection>))
+ {
+ if (value != null)
+ {
+ // put the value into a collection
+ // the implementation gives back a Serializable list
+ value = (Serializable) Collections.singletonList(value);
+ }
+ }
+ else if (!isMultiValued && (value instanceof Collection>))
+ {
+ // we only allow this case if the property type is ANY
+ if (!propertyTypeQName.equals(DataTypeDefinition.ANY))
+ {
+ throw new DictionaryException(
+ "A single-valued property of this type may not be a collection: \n" +
+ " Property: " + propertyDef + "\n" +
+ " Type: " + propertyTypeQName + "\n" +
+ " Value: " + value);
+ }
+ }
+ }
+ try
+ {
+ PropertyValue propertyValue = new PropertyValue(propertyTypeQName, value);
+ // done
+ return propertyValue;
+ }
+ catch (TypeConversionException e)
+ {
+ throw new TypeConversionException(
+ "The property value is not compatible with the type defined for the property: \n" +
+ " property: " + (propertyDef == null ? "unknown" : propertyDef) + "\n" +
+ " value: " + value + "\n" +
+ " value type: " + value.getClass(),
+ e);
+ }
+ }
+
+ /**
+ * Extracts the externally-visible property from the {@link PropertyValue propertyValue}.
+ *
+ * @param propertyDef the model property definition - may be null
+ * @param propertyValue the persisted property
+ * @return Returns the value of the property in the format dictated by the property
+ * definition, or null if the property value is null
+ */
+ protected Serializable makeSerializableValue(PropertyDefinition propertyDef, PropertyValue propertyValue)
+ {
+ if (propertyValue == null)
+ {
+ return null;
+ }
+ // get property attributes
+ QName propertyTypeQName = null;
+ if (propertyDef == null)
+ {
+ // allow this for now
+ propertyTypeQName = DataTypeDefinition.ANY;
+ }
+ else
+ {
+ propertyTypeQName = propertyDef.getDataType().getName();
+ }
+ try
+ {
+ Serializable value = propertyValue.getValue(propertyTypeQName);
+ // done
+ return value;
+ }
+ catch (TypeConversionException e)
+ {
+ throw new TypeConversionException(
+ "The property value is not compatible with the type defined for the property: \n" +
+ " property: " + (propertyDef == null ? "unknown" : propertyDef) + "\n" +
+ " property value: " + propertyValue,
+ e);
+ }
+ }
+
+ /**
+ * Gets a list of all available node store references
+ *
+ * @return Returns a list of store references
+ */
+ public List getStores()
+ {
+ /* Sparta: disable/remove WCM/AVM
+ // For AVM stores we fake up StoreRefs.
+ List stores = fAVMService.getStores();
+ List result = new ArrayList();
+ for (AVMStoreDescriptor desc : stores)
+ {
+ String name = desc.getName();
+ result.add(new StoreRef(StoreRef.PROTOCOL_AVM, name));
+ }
+ return result;
+ */
+ return Collections.emptyList();
+ }
+
+ /**
+ * Create a new AVM store.
+ * @param protocol the implementation protocol
+ * @param identifier the protocol-specific identifier
+ * @return Returns a reference to the store
+ * @throws StoreExistsException
+ */
+ public StoreRef createStore(String protocol, String identifier) throws StoreExistsException
+ {
+ StoreRef result = new StoreRef(StoreRef.PROTOCOL_AVM, identifier);
+ // invokeBeforeCreateStore(ContentModel.TYPE_STOREROOT, result);
+ try
+ {
+ fAVMService.createStore(identifier);
+ NodeRef rootRef = getRootNode(result);
+ addAspect(rootRef, ContentModel.ASPECT_ROOT,
+ Collections.emptyMap());
+ // invokeOnCreateStore(rootRef);
+ return result;
+ }
+ catch (AVMExistsException e)
+ {
+ throw new StoreExistsException(result, e);
+ }
+ }
+
+ /**
+ * @throws UnsupportedOperationException Always
+ */
+ public void deleteStore(StoreRef storeRef) throws InvalidStoreRefException
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * Does the indicated store exist?
+ * @param storeRef a reference to the store to look for
+ * @return Returns true if the store exists, otherwise false
+ */
+ public boolean exists(StoreRef storeRef)
+ {
+ return fAVMService.getStore(storeRef.getIdentifier()) != null;
+ }
+
+ /**
+ * @param nodeRef a reference to the node to look for
+ * @return Returns true if the node exists, otherwise false
+ */
+ public boolean exists(NodeRef nodeRef)
+ {
+ Pair avmInfo = AVMNodeConverter.ToAVMVersionPath(nodeRef);
+ int version = avmInfo.getFirst();
+ String avmPath = avmInfo.getSecond();
+ return fAVMService.lookup(version, avmPath) != null;
+ }
+
+ /**
+ * Gets the ID of the last transaction that caused the node to change. This includes
+ * deletions, so it is possible that the node being referenced no longer exists.
+ * If the node never existed, then null is returned.
+ *
+ * @param nodeRef a reference to a current or previously existing node
+ * @return Returns the status of the node, or null if the node never existed
+ */
+ public NodeRef.Status getNodeStatus(NodeRef nodeRef)
+ {
+ // TODO Need to find out if this is important and if so
+ // need to capture Transaction IDs.
+ return new NodeRef.Status(null, nodeRef, "Unknown", null, !exists(nodeRef));
+ }
+
+ /**
+ * @throws UnsupportedOperationException always
+ */
+ @Override
+ public NodeRef getNodeRef(Long nodeId)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * @param storeRef a reference to an existing store
+ * @return Returns a reference to the root node of the store
+ * @throws InvalidStoreRefException if the store could not be found
+ */
+ public NodeRef getRootNode(StoreRef storeRef) throws InvalidStoreRefException
+ {
+ String storeName = storeRef.getIdentifier();
+ if (fAVMService.getStore(storeName) != null)
+ {
+ return AVMNodeConverter.ToNodeRef(-1, storeName + ":/");
+ }
+ else
+ {
+ throw new InvalidStoreRefException(storeName +":/" + " not found.", storeRef);
+ }
+ }
+
+ public Set getAllRootNodes(StoreRef storeRef)
+ {
+ return Collections.singleton(getRootNode(storeRef));
+ }
+
+ /**
+ * @see #createNode(NodeRef, QName, QName, QName, Map)
+ */
+ public ChildAssociationRef createNode(
+ NodeRef parentRef,
+ QName assocTypeQName,
+ QName assocQName,
+ QName nodeTypeQName)
+ throws InvalidNodeRefException, InvalidTypeException
+ {
+ return createNode(parentRef,
+ assocTypeQName,
+ assocQName,
+ nodeTypeQName,
+ new HashMap());
+ }
+
+ /**
+ * Creates a new, non-abstract, real node as a primary child of the given parent node.
+ *
+ * @param parentRef the parent node
+ * @param assocTypeQName the type of the association to create. This is used
+ * for verification against the data dictionary.
+ * @param assocQName the qualified name of the association
+ * @param nodeTypeQName a reference to the node type
+ * @param properties optional map of properties to keyed by their qualified names
+ * @return Returns a reference to the newly created child association
+ * @throws InvalidNodeRefException if the parent reference is invalid
+ * @throws InvalidTypeException if the node type reference is not recognised
+ *
+ * @see org.alfresco.service.cmr.dictionary.DictionaryService
+ */
+ @SuppressWarnings("deprecation")
+ public ChildAssociationRef createNode(
+ NodeRef parentRef,
+ QName assocTypeQName,
+ QName assocQName,
+ QName nodeTypeQName,
+ Map properties)
+ throws InvalidNodeRefException, InvalidTypeException
+ {
+ // AVM stores only allow simple child associations.
+ if (!assocTypeQName.equals(ContentModel.ASSOC_CONTAINS))
+ {
+ throw new InvalidTypeException(assocTypeQName);
+ }
+ String nodeName = assocQName.getLocalName();
+ Pair avmVersionPath = AVMNodeConverter.ToAVMVersionPath(parentRef);
+ int version = avmVersionPath.getFirst();
+ if (version >= 0)
+ {
+ throw new InvalidNodeRefException("Read only store.", parentRef);
+ }
+ String avmPath = avmVersionPath.getSecond();
+ // Invoke policy behavior.
+ // invokeBeforeUpdateNode(parentRef);
+ // invokeBeforeCreateNode(parentRef, assocTypeQName, assocQName, nodeTypeQName);
+ // Look up the type definition in the dictionary.
+ TypeDefinition nodeTypeDef = dictionaryService.getType(nodeTypeQName);
+ // Do the creates for supported types, or error out.
+ try
+ {
+ if (nodeTypeQName.equals(WCMModel.TYPE_AVM_PLAIN_FOLDER) ||
+ nodeTypeQName.equals(ContentModel.TYPE_FOLDER))
+ {
+ fAVMService.createDirectory(avmPath, nodeName);
+ }
+ else if (nodeTypeQName.equals(WCMModel.TYPE_AVM_PLAIN_CONTENT) ||
+ nodeTypeQName.equals(ContentModel.TYPE_CONTENT))
+ {
+ OutputStream os = fAVMService.createFile(avmPath, nodeName);
+ try
+ {
+ if (os != null) { os.close(); }
+ }
+ catch (IOException ioe)
+ {
+ logger.warn("Failed to close output stream when creating file '"+AVMUtil.extendAVMPath(avmPath, nodeName)+"'"+ioe.getMessage());
+ }
+ }
+ else if (nodeTypeQName.equals(WCMModel.TYPE_AVM_LAYERED_CONTENT))
+ {
+ NodeRef indirection = (NodeRef)properties.get(WCMModel.PROP_AVM_FILE_INDIRECTION);
+ if (indirection == null)
+ {
+ throw new InvalidTypeException("No Indirection Property", nodeTypeQName);
+ }
+ Pair indVersionPath = AVMNodeConverter.ToAVMVersionPath(indirection);
+ fAVMService.createLayeredFile(indVersionPath.getSecond(), avmPath, nodeName);
+ }
+ else if (nodeTypeQName.equals(WCMModel.TYPE_AVM_LAYERED_FOLDER))
+ {
+ NodeRef indirection = (NodeRef)properties.get(WCMModel.PROP_AVM_DIR_INDIRECTION);
+ if (indirection == null)
+ {
+ throw new InvalidTypeException("No Indirection Property.", nodeTypeQName);
+ }
+ Pair indVersionPath = AVMNodeConverter.ToAVMVersionPath(indirection);
+ fAVMService.createLayeredDirectory(indVersionPath.getSecond(), avmPath, nodeName);
+ }
+ else
+ {
+ throw new InvalidTypeException("Invalid node type for AVM.", nodeTypeQName);
+ }
+ properties.putAll(getDefaultProperties(nodeTypeDef));
+ addDefaultAspects(nodeTypeDef, avmPath, properties);
+ }
+ catch (AVMNotFoundException e)
+ {
+ throw new InvalidNodeRefException(avmPath + " not found.", parentRef);
+ }
+ catch (AVMExistsException e)
+ {
+ throw new InvalidNodeRefException("Child " + nodeName + " exists", parentRef);
+ }
+ String newAVMPath = AVMNodeConverter.ExtendAVMPath(avmPath, nodeName);
+ NodeRef childRef = AVMNodeConverter.ToNodeRef(-1, newAVMPath);
+ properties.putAll(getDefaultProperties(nodeTypeDef));
+ addDefaultAspects(nodeTypeDef, newAVMPath, properties);
+ Map props = new HashMap();
+ for (Map.Entry entry : properties.entrySet())
+ {
+ QName propertyQName = entry.getKey();
+ if (isBuiltInProperty(propertyQName))
+ {
+ continue;
+ }
+ Serializable value = entry.getValue();
+ PropertyDefinition propertyDef = dictionaryService.getProperty(propertyQName);
+ PropertyValue propertyValue = makePropertyValue(propertyDef, value);
+ props.put(propertyQName, propertyValue);
+ }
+ fAVMService.setNodeProperties(newAVMPath, props);
+ ChildAssociationRef ref =
+ new ChildAssociationRef(assocTypeQName,
+ parentRef,
+ assocQName,
+ childRef,
+ true,
+ -1);
+// invokeOnCreateNode(ref);
+// invokeOnUpdateNode(parentRef);
+// if (properties.size() != 0)
+// {
+// invokeOnUpdateProperties(childRef, new HashMap(), properties);
+// }
+ return ref;
+ }
+
+ /**
+ * Moves the primary location of the given node.
+ *
+ * This involves changing the node's primary parent and possibly the name of the
+ * association referencing it.
+ *
+ * If the new parent is in a different store from the original, then the entire
+ * node hierarchy is moved to the new store. Inter-store associations are not
+ * affected.
+ *
+ * @param nodeToMoveRef the node to move
+ * @param newParentRef the new parent of the moved node
+ * @param assocTypeQName the type of the association to create. This is used
+ * for verification against the data dictionary.
+ * @param assocQName the qualified name of the new child association
+ * @return Returns a reference to the newly created child association
+ * @throws InvalidNodeRefException if either the parent node or move node reference is invalid
+ * @throws CyclicChildRelationshipException if the child partakes in a cyclic relationship after the add
+ *
+ * @see #getPrimaryParent(NodeRef)
+ */
+ public ChildAssociationRef moveNode(
+ NodeRef nodeToMoveRef,
+ NodeRef newParentRef,
+ QName assocTypeQName,
+ QName assocQName)
+ throws InvalidNodeRefException
+ {
+ // AVM stores only allow simple child associations.
+ if (!assocTypeQName.equals(ContentModel.ASSOC_CONTAINS))
+ {
+ throw new InvalidTypeException(assocTypeQName);
+ }
+ // Extract the parts from the source.
+ Pair