Added exists and getCount to AttributeService.

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@5709 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Britt Park 2007-05-17 13:55:33 +00:00
parent 7d2159686f
commit ee7e8cb4d0
7 changed files with 198 additions and 0 deletions

View File

@ -904,6 +904,8 @@
<value>getAttributes</value>
<value>query</value>
<value>getKeys</value>
<value>exists</value>
<value>getCount</value>
</list>
</property>
</bean>

View File

@ -456,5 +456,73 @@ public class AttributeServiceImpl implements AttributeService
List<String> keys = parsePath(path);
setAttribute(keys, index, value);
}
/* (non-Javadoc)
* @see org.alfresco.service.cmr.attributes.AttributeService#exists(java.util.List)
*/
public boolean exists(List<String> keys)
{
if (keys == null)
{
throw new AVMBadArgumentException("Null keys list.");
}
if (keys.size() == 0)
{
throw new AVMBadArgumentException("Illegal zero length keys list.");
}
return getAttributeFromPath(keys) != null;
}
/* (non-Javadoc)
* @see org.alfresco.service.cmr.attributes.AttributeService#exists(java.lang.String)
*/
public boolean exists(String path)
{
if (path == null)
{
throw new AVMBadArgumentException("Null attribute path.");
}
List<String> keys = parsePath(path);
return exists(keys);
}
/* (non-Javadoc)
* @see org.alfresco.service.cmr.attributes.AttributeService#getCount(java.util.List)
*/
public int getCount(List<String> keys)
{
if (keys == null)
{
throw new AVMBadArgumentException("Null keys list.");
}
if (keys.size() == 0)
{
throw new AVMBadArgumentException("Illegal empty keys list.");
}
Attribute found = getAttributeFromPath(keys);
if (found == null)
{
throw new AVMNotFoundException("Attribute not found: " + keys);
}
if (found.getType() != Attribute.Type.LIST &&
found.getType() != Attribute.Type.MAP)
{
throw new AVMWrongTypeException("Not a map or list: " + keys);
}
return found.size();
}
/* (non-Javadoc)
* @see org.alfresco.service.cmr.attributes.AttributeService#getCount(java.lang.String)
*/
public int getCount(String path)
{
if (path == null)
{
throw new AVMBadArgumentException("Null attribute path.");
}
List<String> keys = parsePath(path);
return getCount(keys);
}
}

View File

@ -294,6 +294,9 @@ public class AttributeServiceTest extends TestCase
list.add(new IntAttributeValue(4));
fService.setAttribute("", "dummy", list);
Attribute found = fService.getAttribute("dummy");
assertTrue(fService.exists("dummy"));
assertFalse(fService.exists("dimmy"));
assertEquals(5, fService.getCount("dummy"));
assertNotNull(found);
assertEquals(5, found.size());
Attribute add = new IntAttributeValue(6);
@ -315,6 +318,7 @@ public class AttributeServiceTest extends TestCase
list.add(subMap);
fService.setAttribute("", "map", map);
assertEquals("donuts", fService.getAttribute("map/list/5/b").getStringValue());
assertEquals(3, fService.getCount("map/list/5"));
}
catch (Exception e)
{

View File

@ -207,4 +207,40 @@ public class AttributeServiceTransportService implements
fAuthService.validate(ticket);
fService.setAttribute(keys, index, value);
}
/* (non-Javadoc)
* @see org.alfresco.service.cmr.remote.AttributeServiceTransport#exists(java.lang.String, java.util.List)
*/
public boolean exists(String ticket, List<String> keys)
{
fAuthService.validate(ticket);
return fService.exists(keys);
}
/* (non-Javadoc)
* @see org.alfresco.service.cmr.remote.AttributeServiceTransport#exists(java.lang.String, java.lang.String)
*/
public boolean exists(String ticket, String path)
{
fAuthService.validate(ticket);
return fService.exists(path);
}
/* (non-Javadoc)
* @see org.alfresco.service.cmr.remote.AttributeServiceTransport#getCount(java.lang.String, java.util.List)
*/
public int getCount(String ticket, List<String> keys)
{
fAuthService.validate(ticket);
return fService.getCount(keys);
}
/* (non-Javadoc)
* @see org.alfresco.service.cmr.remote.AttributeServiceTransport#getCount(java.lang.String, java.lang.String)
*/
public int getCount(String ticket, String path)
{
fAuthService.validate(ticket);
return fService.getCount(path);
}
}

View File

@ -185,4 +185,36 @@ public class AttributeServiceRemote implements AttributeService
{
fTransport.setAttribute(fTicketHolder.getTicket(), keys, index, value);
}
/* (non-Javadoc)
* @see org.alfresco.service.cmr.attributes.AttributeService#exists(java.util.List)
*/
public boolean exists(List<String> keys)
{
return fTransport.exists(fTicketHolder.getTicket(), keys);
}
/* (non-Javadoc)
* @see org.alfresco.service.cmr.attributes.AttributeService#exists(java.lang.String)
*/
public boolean exists(String path)
{
return fTransport.exists(fTicketHolder.getTicket(), path);
}
/* (non-Javadoc)
* @see org.alfresco.service.cmr.attributes.AttributeService#getCount(java.util.List)
*/
public int getCount(List<String> keys)
{
return fTransport.getCount(fTicketHolder.getTicket(), keys);
}
/* (non-Javadoc)
* @see org.alfresco.service.cmr.attributes.AttributeService#getCount(java.lang.String)
*/
public int getCount(String path)
{
return fTransport.getCount(fTicketHolder.getTicket(), path);
}
}

View File

@ -236,4 +236,32 @@ public interface AttributeService
* @return A list of all keys at the specified Attribute location
*/
public List<String> getKeys(List<String> keys);
/**
* Get the size of a map or list.
* @param keys List of attribute path keys.
* @return The size of of the list or map.
*/
public int getCount(List<String> keys);
/**
* Get the size of a map or list.
* @param path The path to the map or list.
* @return The size of the list or map.
*/
public int getCount(String path);
/**
* Does an attribute exist.
* @param keys List of attribute path keys.
* @return Whether the attribute exists.
*/
public boolean exists(List<String> keys);
/**
* Does an attribute exist.
* @param path The path to the attribute.
* @return Whether the attribute exists.
*/
public boolean exists(String path);
}

View File

@ -170,4 +170,32 @@ public interface AttributeServiceTransport
* @return A list of all keys.
*/
public List<String> getKeys(String ticket, List<String> keys);
/**
* Get the size of a map or list.
* @param keys List of attribute path keys.
* @return The size of of the list or map.
*/
public int getCount(String ticket, List<String> keys);
/**
* Get the size of a map or list.
* @param path The path to the map or list.
* @return The size of the list or map.
*/
public int getCount(String ticket, String path);
/**
* Does an attribute exist.
* @param keys List of attribute path keys.
* @return Whether the attribute exists.
*/
public boolean exists(String ticket, List<String> keys);
/**
* Does an attribute exist.
* @param path The path to the attribute.
* @return Whether the attribute exists.
*/
public boolean exists(String ticket, String path);
}