mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Added deleteNodeProperties to AVMService interface. Fits in well with NodeService
behavior. Outline of implementation of AVMNodeService, an AVM based implementationof NodeService. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@3438 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -166,4 +166,9 @@ interface AVMNode
|
|||||||
* @param name The name of the property.
|
* @param name The name of the property.
|
||||||
*/
|
*/
|
||||||
public void deleteProperty(QName name);
|
public void deleteProperty(QName name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete all properties from this node.
|
||||||
|
*/
|
||||||
|
public void deleteProperties();
|
||||||
}
|
}
|
112
source/java/org/alfresco/repo/avm/AVMNodeConverter.java
Normal file
112
source/java/org/alfresco/repo/avm/AVMNodeConverter.java
Normal file
@@ -0,0 +1,112 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2006 Alfresco, Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Mozilla Public License version 1.1
|
||||||
|
* with a permitted attribution clause. You may obtain a
|
||||||
|
* copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.alfresco.org/legal/license.txt
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||||
|
* either express or implied. See the License for the specific
|
||||||
|
* language governing permissions and limitations under the
|
||||||
|
* License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.alfresco.repo.avm;
|
||||||
|
|
||||||
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
|
import org.alfresco.service.cmr.repository.StoreRef;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Utility for going back and forth between the AVM world and
|
||||||
|
* the <code>StoreRef</code>, <code>NodeRef</code> world.
|
||||||
|
* @author britt
|
||||||
|
*/
|
||||||
|
class AVMNodeConverter
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Get a NodeRef corresponding to the given path and version.
|
||||||
|
* @param version The version id.
|
||||||
|
* @param avmPath The AVM path.
|
||||||
|
* @return A NodeRef with AVM info stuffed inside.
|
||||||
|
*/
|
||||||
|
public static NodeRef ToNodeRef(int version, String avmPath)
|
||||||
|
{
|
||||||
|
String [] pathParts = avmPath.split(":");
|
||||||
|
if (pathParts.length != 2)
|
||||||
|
{
|
||||||
|
throw new AVMException("Malformed AVM Path.");
|
||||||
|
}
|
||||||
|
StoreRef storeRef = ToStoreRef(pathParts[0]);
|
||||||
|
String translated = version + pathParts[1];
|
||||||
|
return new NodeRef(storeRef, translated);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a StoreRef that corresponds to a given AVMStore name.
|
||||||
|
* @param avmStore The name of the AVMStore.
|
||||||
|
* @return A working StoreRef.
|
||||||
|
*/
|
||||||
|
public static StoreRef ToStoreRef(String avmStore)
|
||||||
|
{
|
||||||
|
return new StoreRef(StoreRef.PROTOCOL_AVM, avmStore);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert a NodeRef into a version, AVMPath pair.
|
||||||
|
* @param nodeRef The NodeRef to convert.
|
||||||
|
* @return An Integer, String array.
|
||||||
|
*/
|
||||||
|
public static Object[] ToAVMVersionPath(NodeRef nodeRef)
|
||||||
|
{
|
||||||
|
StoreRef store = nodeRef.getStoreRef();
|
||||||
|
String translated = nodeRef.getId();
|
||||||
|
int off = translated.indexOf("/");
|
||||||
|
int version = Integer.parseInt(translated.substring(0, off));
|
||||||
|
String path = translated.substring(off);
|
||||||
|
Object [] result = new Object[2];
|
||||||
|
result[0] = new Integer(version);
|
||||||
|
result[1] = store.getIdentifier() + ":" + path;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extend an already valid AVM path by one more component.
|
||||||
|
* @param path The starting AVM path.
|
||||||
|
* @param name The name to add to it.
|
||||||
|
* @return The extended path.
|
||||||
|
*/
|
||||||
|
public static String ExtendAVMPath(String path, String name)
|
||||||
|
{
|
||||||
|
if (path.endsWith("/"))
|
||||||
|
{
|
||||||
|
return path + name;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return path + "/" + name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Split a path into its parent path and its base name.
|
||||||
|
* @param path The initial AVM path.
|
||||||
|
* @return An array of 2 Strings containing the parent path and the base
|
||||||
|
* name.
|
||||||
|
*/
|
||||||
|
public static String [] SplitBase(String path)
|
||||||
|
{
|
||||||
|
int off = path.lastIndexOf("/");
|
||||||
|
if (off == -1)
|
||||||
|
{
|
||||||
|
throw new AVMException("Invalid Path.");
|
||||||
|
}
|
||||||
|
String [] decomposed = new String[2];
|
||||||
|
decomposed[0] = path.substring(0, off);
|
||||||
|
decomposed[1] = path.substring(off + 1);
|
||||||
|
return decomposed;
|
||||||
|
}
|
||||||
|
}
|
50
source/java/org/alfresco/repo/avm/AVMNodeConverterTest.java
Normal file
50
source/java/org/alfresco/repo/avm/AVMNodeConverterTest.java
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2006 Alfresco, Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Mozilla Public License version 1.1
|
||||||
|
* with a permitted attribution clause. You may obtain a
|
||||||
|
* copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.alfresco.org/legal/license.txt
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||||
|
* either express or implied. See the License for the specific
|
||||||
|
* language governing permissions and limitations under the
|
||||||
|
* License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.alfresco.repo.avm;
|
||||||
|
|
||||||
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
|
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tester of the converter from NodeRef, StoreRef space to AVM space.
|
||||||
|
* @author britt
|
||||||
|
*/
|
||||||
|
public class AVMNodeConverterTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Test Going betwwen a NodeRef and a version, path pair.
|
||||||
|
*/
|
||||||
|
public void testTranslate()
|
||||||
|
{
|
||||||
|
String avmPath = "main:/";
|
||||||
|
int version = 2;
|
||||||
|
NodeRef nodeRef = AVMNodeConverter.ToNodeRef(version, avmPath);
|
||||||
|
System.out.println(nodeRef);
|
||||||
|
Object [] backOut = AVMNodeConverter.ToAVMVersionPath(nodeRef);
|
||||||
|
assertEquals(2, ((Integer)backOut[0]).intValue());
|
||||||
|
assertEquals(avmPath, (String)backOut[1]);
|
||||||
|
avmPath = "main:/fista/mista/wisticuff";
|
||||||
|
version = -1;
|
||||||
|
nodeRef = AVMNodeConverter.ToNodeRef(version, avmPath);
|
||||||
|
System.out.println(nodeRef);
|
||||||
|
backOut = AVMNodeConverter.ToAVMVersionPath(nodeRef);
|
||||||
|
assertEquals(-1, ((Integer)backOut[0]).intValue());
|
||||||
|
assertEquals(avmPath, (String)backOut[1]);
|
||||||
|
}
|
||||||
|
}
|
@@ -356,4 +356,12 @@ abstract class AVMNodeImpl implements AVMNode, Serializable
|
|||||||
{
|
{
|
||||||
AVMContext.fgInstance.fAVMNodePropertyDAO.delete(this, name);
|
AVMContext.fgInstance.fAVMNodePropertyDAO.delete(this, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete all properties from this node.
|
||||||
|
*/
|
||||||
|
public void deleteProperties()
|
||||||
|
{
|
||||||
|
AVMContext.fgInstance.fAVMNodePropertyDAO.deleteAll(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
1146
source/java/org/alfresco/repo/avm/AVMNodeService.java
Normal file
1146
source/java/org/alfresco/repo/avm/AVMNodeService.java
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,71 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2006 Alfresco, Inc.
|
|
||||||
*
|
|
||||||
* Licensed under the Mozilla Public License version 1.1
|
|
||||||
* with a permitted attribution clause. You may obtain a
|
|
||||||
* copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.alfresco.org/legal/license.txt
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
|
||||||
* either express or implied. See the License for the specific
|
|
||||||
* language governing permissions and limitations under the
|
|
||||||
* License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.alfresco.repo.avm;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Utility class with static methods to convert between
|
|
||||||
* a NodeRef style id string and an ordinary AVM path.
|
|
||||||
* @author britt
|
|
||||||
*/
|
|
||||||
public class AVMPathConverter
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Converts to a string to stuff into a NodeRef. Version = 3
|
|
||||||
* of main:/snot/efluvium/biggle would be converted into
|
|
||||||
* 3/main/snot/efluvium/biggle
|
|
||||||
* @param version The version id.
|
|
||||||
* @param avmPath The full AVM path.
|
|
||||||
* @return A mangled string appropriate for stuffing into a NodeRef.
|
|
||||||
*/
|
|
||||||
public static String toNodeRefStyle(int version, String avmPath)
|
|
||||||
{
|
|
||||||
String [] pathParts = avmPath.split(":");
|
|
||||||
if (pathParts.length != 2)
|
|
||||||
{
|
|
||||||
throw new AVMException("Malformed path.");
|
|
||||||
}
|
|
||||||
return version + "/" + pathParts[0] + pathParts[1];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Convert from a NodeRef packed form to a version number
|
|
||||||
* and standard AVM path.
|
|
||||||
* @param nrID The NodeRef packed for of an AVM path.
|
|
||||||
* @return The version number and the standard AVM path.
|
|
||||||
*/
|
|
||||||
public static Object[] toAVMStyle(String nrID)
|
|
||||||
{
|
|
||||||
Object [] result = new Object[2];
|
|
||||||
String [] pathParts = nrID.split("/");
|
|
||||||
result[0] = new Integer(pathParts[0]);
|
|
||||||
StringBuilder builder = new StringBuilder();
|
|
||||||
builder.append(pathParts[1]);
|
|
||||||
builder.append(':');
|
|
||||||
for (int i = 2; i < pathParts.length; i++)
|
|
||||||
{
|
|
||||||
builder.append('/');
|
|
||||||
builder.append(pathParts[i]);
|
|
||||||
}
|
|
||||||
if (pathParts.length == 2)
|
|
||||||
{
|
|
||||||
builder.append('/');
|
|
||||||
}
|
|
||||||
result[1] = builder.toString();
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,55 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2006 Alfresco, Inc.
|
|
||||||
*
|
|
||||||
* Licensed under the Mozilla Public License version 1.1
|
|
||||||
* with a permitted attribution clause. You may obtain a
|
|
||||||
* copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.alfresco.org/legal/license.txt
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
|
||||||
* either express or implied. See the License for the specific
|
|
||||||
* language governing permissions and limitations under the
|
|
||||||
* License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.alfresco.repo.avm;
|
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test of AVMPathConverter.
|
|
||||||
* @author britt
|
|
||||||
*/
|
|
||||||
public class AVMPathConverterTest extends TestCase
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Test conversions.
|
|
||||||
*/
|
|
||||||
public void testConversions()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
String start = "main:/";
|
|
||||||
String nrRep = AVMPathConverter.toNodeRefStyle(-1, start);
|
|
||||||
assertEquals("-1/main/", nrRep);
|
|
||||||
Object[] back = AVMPathConverter.toAVMStyle(nrRep);
|
|
||||||
assertEquals(((Integer)back[0]).intValue(), -1);
|
|
||||||
assertEquals((String)back[1], "main:/");
|
|
||||||
start = "main:/foo/bar/baz";
|
|
||||||
nrRep = AVMPathConverter.toNodeRefStyle(2, start);
|
|
||||||
assertEquals("2/main/foo/bar/baz", nrRep);
|
|
||||||
back = AVMPathConverter.toAVMStyle(nrRep);
|
|
||||||
assertEquals(((Integer)back[0]).intValue(), 2);
|
|
||||||
assertEquals((String)back[1], "main:/foo/bar/baz");
|
|
||||||
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
e.printStackTrace(System.err);
|
|
||||||
fail();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -992,6 +992,18 @@ class AVMRepository
|
|||||||
store.deleteNodeProperty(pathParts[1], name);
|
store.deleteNodeProperty(pathParts[1], name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete all properties on a node.
|
||||||
|
* @param path The path to the node.
|
||||||
|
*/
|
||||||
|
public void deleteNodeProperties(String path)
|
||||||
|
{
|
||||||
|
fLookupCount.set(1);
|
||||||
|
String [] pathParts = SplitPath(path);
|
||||||
|
AVMStore store = getAVMStoreByName(pathParts[0]);
|
||||||
|
store.deleteNodeProperties(pathParts[1]);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set a property on a store. Overwrites if property exists.
|
* Set a property on a store. Overwrites if property exists.
|
||||||
* @param store The AVMStore.
|
* @param store The AVMStore.
|
||||||
|
@@ -493,6 +493,12 @@ public interface AVMService
|
|||||||
*/
|
*/
|
||||||
public void deleteNodeProperty(String path, QName name);
|
public void deleteNodeProperty(String path, QName name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete all the properties attached to an AVM node.
|
||||||
|
* @param path The path to the node.
|
||||||
|
*/
|
||||||
|
public void deleteNodeProperties(String path);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set a property on a store. If the property exists it will be overwritten.
|
* Set a property on a store. If the property exists it will be overwritten.
|
||||||
* @param store The store to set the property on.
|
* @param store The store to set the property on.
|
||||||
|
@@ -1184,6 +1184,27 @@ class AVMServiceImpl implements AVMService
|
|||||||
fTransaction.perform(doit, true);
|
fTransaction.perform(doit, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete all the properties attached to an AVM node.
|
||||||
|
* @param path The path to the node.
|
||||||
|
*/
|
||||||
|
public void deleteNodeProperties(final String path)
|
||||||
|
{
|
||||||
|
if (path == null)
|
||||||
|
{
|
||||||
|
throw new AVMBadArgumentException("Null path.");
|
||||||
|
}
|
||||||
|
class TxnCallback implements RetryingTransactionCallback
|
||||||
|
{
|
||||||
|
public void perform()
|
||||||
|
{
|
||||||
|
fAVMRepository.deleteNodeProperties(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
TxnCallback doit = new TxnCallback();
|
||||||
|
fTransaction.perform(doit, true);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set a property on a store. If the property exists it will be overwritten.
|
* Set a property on a store. If the property exists it will be overwritten.
|
||||||
* @param store The store to set the property on.
|
* @param store The store to set the property on.
|
||||||
|
@@ -2142,6 +2142,10 @@ public class AVMServiceTest extends AVMServiceTestBase
|
|||||||
assertEquals(2, props.size());
|
assertEquals(2, props.size());
|
||||||
assertEquals(p2.toString(), props.get(n2).toString());
|
assertEquals(p2.toString(), props.get(n2).toString());
|
||||||
assertEquals(p3.toString(), props.get(n3).toString());
|
assertEquals(p3.toString(), props.get(n3).toString());
|
||||||
|
fService.deleteNodeProperties("main:/a/b/c/bar");
|
||||||
|
fService.createSnapshot("main");
|
||||||
|
props = fService.getNodeProperties(-1, "main:/a/b/c/bar");
|
||||||
|
assertEquals(0, props.size());
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
@@ -291,6 +291,12 @@ interface AVMStore
|
|||||||
*/
|
*/
|
||||||
public void deleteNodeProperty(String path, QName name);
|
public void deleteNodeProperty(String path, QName name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete all properties from a node.
|
||||||
|
* @param path The path to the node.
|
||||||
|
*/
|
||||||
|
public void deleteNodeProperties(String path);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all the properties associated with a node.
|
* Get all the properties associated with a node.
|
||||||
* @param version The version to look under.
|
* @param version The version to look under.
|
||||||
|
@@ -893,6 +893,17 @@ class AVMStoreImpl implements AVMStore, Serializable
|
|||||||
node.deleteProperty(name);
|
node.deleteProperty(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete all properties from a node.
|
||||||
|
* @param path The path to the node.
|
||||||
|
*/
|
||||||
|
public void deleteNodeProperties(String path)
|
||||||
|
{
|
||||||
|
Lookup lPath = lookup(-1, path, true);
|
||||||
|
AVMNode node = lPath.getCurrentNode();
|
||||||
|
node.deleteProperties();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set a property on this store. Replaces if property already exists.
|
* Set a property on this store. Replaces if property already exists.
|
||||||
* @param name The QName of the property.
|
* @param name The QName of the property.
|
||||||
|
Reference in New Issue
Block a user