mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Another pair of convenience methods for AttributeService:
removeEntries, which removes map entries by query. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@5806 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -995,6 +995,7 @@
|
|||||||
<value>removeAttribute</value>
|
<value>removeAttribute</value>
|
||||||
<value>addAttribute</value>
|
<value>addAttribute</value>
|
||||||
<value>addAttributes</value>
|
<value>addAttributes</value>
|
||||||
|
<value>removeEntries</value>
|
||||||
</list>
|
</list>
|
||||||
</property>
|
</property>
|
||||||
</bean>
|
</bean>
|
||||||
|
@@ -54,5 +54,12 @@ public interface AttributeDAO
|
|||||||
* @param query The AttrQuery.
|
* @param query The AttrQuery.
|
||||||
* @return A List of key, attribute value pairs.
|
* @return A List of key, attribute value pairs.
|
||||||
*/
|
*/
|
||||||
List<Pair<String,Attribute>> find(MapAttribute map, AttrQuery query);
|
public List<Pair<String,Attribute>> find(MapAttribute map, AttrQuery query);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete entries from a map that match the given query.
|
||||||
|
* @param map
|
||||||
|
* @param query
|
||||||
|
*/
|
||||||
|
public void delete(MapAttribute map, AttrQuery query);
|
||||||
}
|
}
|
||||||
|
@@ -420,6 +420,44 @@ public class AttributeServiceImpl implements AttributeService
|
|||||||
removeAttribute(keys, index);
|
removeAttribute(keys, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.alfresco.service.cmr.attributes.AttributeService#removeEntries(java.util.List, org.alfresco.service.cmr.attributes.AttrQuery)
|
||||||
|
*/
|
||||||
|
public void removeEntries(List<String> keys, AttrQuery query)
|
||||||
|
{
|
||||||
|
if (keys == null || query == null)
|
||||||
|
{
|
||||||
|
throw new AVMBadArgumentException("Illegal null argument.");
|
||||||
|
}
|
||||||
|
if (keys.size() == 0)
|
||||||
|
{
|
||||||
|
throw new AVMBadArgumentException("Illegal zero length key path.");
|
||||||
|
}
|
||||||
|
Attribute map = getAttributeFromPath(keys);
|
||||||
|
if (map == null)
|
||||||
|
{
|
||||||
|
throw new AVMNotFoundException("Could not find attribute: " + keys);
|
||||||
|
}
|
||||||
|
if (map.getType() != Attribute.Type.MAP)
|
||||||
|
{
|
||||||
|
throw new AVMWrongTypeException("Not a map: " + keys);
|
||||||
|
}
|
||||||
|
fAttributeDAO.delete((MapAttribute)map, query);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.alfresco.service.cmr.attributes.AttributeService#removeEntries(java.lang.String, org.alfresco.service.cmr.attributes.AttrQuery)
|
||||||
|
*/
|
||||||
|
public void removeEntries(String path, AttrQuery query)
|
||||||
|
{
|
||||||
|
if (path == null || query == null)
|
||||||
|
{
|
||||||
|
throw new AVMBadArgumentException("Illegal null argument.");
|
||||||
|
}
|
||||||
|
List<String> keys = parsePath(path);
|
||||||
|
removeEntries(keys, query);
|
||||||
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.alfresco.service.cmr.attributes.AttributeService#setAttribute(java.util.List, int, org.alfresco.repo.attributes.Attribute)
|
* @see org.alfresco.service.cmr.attributes.AttributeService#setAttribute(java.util.List, int, org.alfresco.repo.attributes.Attribute)
|
||||||
*/
|
*/
|
||||||
|
@@ -282,6 +282,9 @@ public class AttributeServiceTest extends TestCase
|
|||||||
assertEquals(25, fService.getKeys("map/submap/subsubmap").size());
|
assertEquals(25, fService.getKeys("map/submap/subsubmap").size());
|
||||||
fService.removeAttribute("map/submap", "subsubmap");
|
fService.removeAttribute("map/submap", "subsubmap");
|
||||||
assertEquals(26, fService.getKeys("map/submap").size());
|
assertEquals(26, fService.getKeys("map/submap").size());
|
||||||
|
fService.removeEntries("map/submap", new AttrAndQuery(new AttrQueryGTE("a"),
|
||||||
|
new AttrQueryLTE("d")));
|
||||||
|
assertEquals(22, fService.getCount("map/submap"));
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
@@ -280,4 +280,22 @@ public class AttributeServiceTransportService implements
|
|||||||
fAuthService.validate(ticket);
|
fAuthService.validate(ticket);
|
||||||
fService.setAttributes(path, entries);
|
fService.setAttributes(path, entries);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.alfresco.service.cmr.remote.AttributeServiceTransport#removeEntries(java.lang.String, java.util.List, org.alfresco.service.cmr.attributes.AttrQuery)
|
||||||
|
*/
|
||||||
|
public void removeEntries(String ticket, List<String> keys, AttrQuery query)
|
||||||
|
{
|
||||||
|
fAuthService.validate(ticket);
|
||||||
|
fService.removeEntries(keys, query);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.alfresco.service.cmr.remote.AttributeServiceTransport#removeEntries(java.lang.String, java.lang.String, org.alfresco.service.cmr.attributes.AttrQuery)
|
||||||
|
*/
|
||||||
|
public void removeEntries(String ticket, String path, AttrQuery query)
|
||||||
|
{
|
||||||
|
fAuthService.validate(ticket);
|
||||||
|
fService.removeEntries(path, query);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -125,6 +125,18 @@ public class AttributeDAOHibernate extends HibernateDaoSupport implements
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.alfresco.repo.attributes.AttributeDAO#delete(org.alfresco.repo.attributes.MapAttribute, org.alfresco.service.cmr.attributes.AttrQuery)
|
||||||
|
*/
|
||||||
|
public void delete(MapAttribute map, AttrQuery query)
|
||||||
|
{
|
||||||
|
List<Pair<String, Attribute>> result = find(map, query);
|
||||||
|
for (Pair<String, Attribute> entry : result)
|
||||||
|
{
|
||||||
|
map.remove(entry.getFirst());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.alfresco.repo.attributes.AttributeDAO#save(org.alfresco.repo.attributes.Attribute)
|
* @see org.alfresco.repo.attributes.AttributeDAO#save(org.alfresco.repo.attributes.Attribute)
|
||||||
*/
|
*/
|
||||||
|
@@ -250,4 +250,20 @@ public class AttributeServiceRemote implements AttributeService
|
|||||||
{
|
{
|
||||||
fTransport.setAttributes(fTicketHolder.getTicket(), path, entries);
|
fTransport.setAttributes(fTicketHolder.getTicket(), path, entries);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.alfresco.service.cmr.attributes.AttributeService#removeEntries(java.util.List, org.alfresco.service.cmr.attributes.AttrQuery)
|
||||||
|
*/
|
||||||
|
public void removeEntries(List<String> keys, AttrQuery query)
|
||||||
|
{
|
||||||
|
fTransport.removeEntries(fTicketHolder.getTicket(), keys, query);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.alfresco.service.cmr.attributes.AttributeService#removeEntries(java.lang.String, org.alfresco.service.cmr.attributes.AttrQuery)
|
||||||
|
*/
|
||||||
|
public void removeEntries(String path, AttrQuery query)
|
||||||
|
{
|
||||||
|
fTransport.removeEntries(fTicketHolder.getTicket(), path, query);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -191,6 +191,20 @@ public interface AttributeService
|
|||||||
*/
|
*/
|
||||||
public void removeAttribute(List<String> keys, int index);
|
public void removeAttribute(List<String> keys, int index);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove entries from the designated map which match the given query.
|
||||||
|
* @param keys The list of attribute path entries.
|
||||||
|
* @param query The attribute query.
|
||||||
|
*/
|
||||||
|
public void removeEntries(List<String> keys, AttrQuery query);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove entries from the designated map which match the given query.
|
||||||
|
* @param path The path to the map.
|
||||||
|
* @param query The attribute query.
|
||||||
|
*/
|
||||||
|
public void removeEntries(String path, AttrQuery query);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Query for the list of attributes that is contained in the map
|
* Query for the list of attributes that is contained in the map
|
||||||
* defined by the given path and meet the query criteria.
|
* defined by the given path and meet the query criteria.
|
||||||
|
@@ -231,4 +231,20 @@ public interface AttributeServiceTransport
|
|||||||
* @param entries
|
* @param entries
|
||||||
*/
|
*/
|
||||||
public void setAttributes(String ticket, String path, Map<String, Attribute> entries);
|
public void setAttributes(String ticket, String path, Map<String, Attribute> entries);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove entries from a map that match a query.
|
||||||
|
* @param ticket
|
||||||
|
* @param keys
|
||||||
|
* @param query
|
||||||
|
*/
|
||||||
|
public void removeEntries(String ticket, List<String> keys, AttrQuery query);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove entries from a map that match a query.
|
||||||
|
* @param ticket
|
||||||
|
* @param path
|
||||||
|
* @param query
|
||||||
|
*/
|
||||||
|
public void removeEntries(String ticket, String path, AttrQuery query);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user