mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Adds some convenience methods to AttributeService.
Namely two flavors each of addAttributes, for adding attributes to lists, and setAttributes for adding entries to maps. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@5804 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -27,6 +27,7 @@ package org.alfresco.repo.attributes;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.repo.attributes.Attribute.Type;
|
||||
import org.alfresco.service.cmr.attributes.AttrQuery;
|
||||
@@ -524,5 +525,100 @@ public class AttributeServiceImpl implements AttributeService
|
||||
List<String> keys = parsePath(path);
|
||||
return getCount(keys);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.attributes.AttributeService#addAttributes(java.util.List, java.util.List)
|
||||
*/
|
||||
public void addAttributes(List<String> keys, List<Attribute> values)
|
||||
{
|
||||
if (keys == null || values == null)
|
||||
{
|
||||
throw new AVMBadArgumentException("Illegal null argument.");
|
||||
}
|
||||
if (keys.size() == 0)
|
||||
{
|
||||
throw new AVMBadArgumentException("Zero length keys.");
|
||||
}
|
||||
Attribute list = getAttributeFromPath(keys);
|
||||
if (list.getType() != Attribute.Type.LIST)
|
||||
{
|
||||
throw new AVMWrongTypeException("Attribute not list: " + list.getType());
|
||||
}
|
||||
for (Attribute value : values)
|
||||
{
|
||||
Attribute persistent = fAttributeConverter.toPersistent(value);
|
||||
list.add(persistent);
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.attributes.AttributeService#addAttributes(java.lang.String, java.util.List)
|
||||
*/
|
||||
public void addAttributes(String path, List<Attribute> values)
|
||||
{
|
||||
if (path == null || values == null)
|
||||
{
|
||||
throw new AVMBadArgumentException("Illegal null argument.");
|
||||
}
|
||||
List<String> keys = parsePath(path);
|
||||
addAttributes(keys, values);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.attributes.AttributeService#setAttributes(java.util.List, java.util.Map)
|
||||
*/
|
||||
public void setAttributes(List<String> keys, Map<String, Attribute> entries)
|
||||
{
|
||||
if (keys == null || entries == null)
|
||||
{
|
||||
throw new AVMBadArgumentException("Null argument.");
|
||||
}
|
||||
if (keys.size() == 0)
|
||||
{
|
||||
for (Map.Entry<String, Attribute> entry : entries.entrySet())
|
||||
{
|
||||
String name = entry.getKey();
|
||||
Attribute value = entry.getValue();
|
||||
Attribute toSave = fAttributeConverter.toPersistent(value);
|
||||
GlobalAttributeEntry found = fGlobalAttributeEntryDAO.get(name);
|
||||
if (found == null)
|
||||
{
|
||||
found = new GlobalAttributeEntryImpl(name, toSave);
|
||||
fGlobalAttributeEntryDAO.save(found);
|
||||
return;
|
||||
}
|
||||
found.setAttribute(toSave);
|
||||
}
|
||||
return;
|
||||
}
|
||||
Attribute found = getAttributeFromPath(keys);
|
||||
if (found == null)
|
||||
{
|
||||
throw new AVMNotFoundException("Attribute Not Found: " + keys);
|
||||
}
|
||||
if (found.getType() != Type.MAP)
|
||||
{
|
||||
throw new AVMWrongTypeException("Not a Map: " + keys);
|
||||
}
|
||||
for (Map.Entry<String, Attribute> entry : entries.entrySet())
|
||||
{
|
||||
String name = entry.getKey();
|
||||
Attribute value = entry.getValue();
|
||||
found.put(name, fAttributeConverter.toPersistent(value));
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.attributes.AttributeService#setAttributes(java.lang.String, java.util.Map)
|
||||
*/
|
||||
public void setAttributes(String path, Map<String, Attribute> entries)
|
||||
{
|
||||
if (path == null || entries == null)
|
||||
{
|
||||
throw new AVMBadArgumentException("Illegal null argument.");
|
||||
}
|
||||
List<String> keys = parsePath(path);
|
||||
setAttributes(keys, entries);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -25,7 +25,10 @@
|
||||
|
||||
package org.alfresco.repo.attributes;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.service.cmr.attributes.AttrAndQuery;
|
||||
import org.alfresco.service.cmr.attributes.AttrNotQuery;
|
||||
@@ -113,6 +116,13 @@ public class AttributeServiceTest extends TestCase
|
||||
}
|
||||
fService.setAttribute("", "string", new StringAttributeValue("This is another string."));
|
||||
assertEquals("This is another string.", fService.getAttribute("string").getStringValue());
|
||||
Map<String, Attribute> hmap = new HashMap<String, Attribute>();
|
||||
hmap.put("foo", new StringAttributeValue("I do walk."));
|
||||
hmap.put("pismo", new StringAttributeValue("There's trees now in the desert since you moved out, and I don't sleep on a bed of bones."));
|
||||
fService.setAttributes("map", hmap);
|
||||
Attribute out = fService.getAttribute("map");
|
||||
System.out.println(out);
|
||||
assertEquals(6, out.size());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -319,6 +329,13 @@ public class AttributeServiceTest extends TestCase
|
||||
fService.setAttribute("", "map", map);
|
||||
assertEquals("donuts", fService.getAttribute("map/list/5/b").getStringValue());
|
||||
assertEquals(3, fService.getCount("map/list/5"));
|
||||
List<Attribute> values = new ArrayList<Attribute>();
|
||||
values.add(new StringAttributeValue("Death is your art."));
|
||||
values.add(new StringAttributeValue("You make it with your hands, day after day."));
|
||||
fService.addAttributes("dummy", values);
|
||||
found = fService.getAttribute("dummy");
|
||||
System.out.println(found);
|
||||
assertEquals(7, found.size());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
@@ -26,6 +26,7 @@
|
||||
package org.alfresco.repo.attributes;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.service.cmr.attributes.AttrQuery;
|
||||
import org.alfresco.service.cmr.attributes.AttributeService;
|
||||
@@ -243,4 +244,40 @@ public class AttributeServiceTransportService implements
|
||||
fAuthService.validate(ticket);
|
||||
return fService.getCount(path);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.remote.AttributeServiceTransport#addAttributes(java.lang.String, java.util.List, java.util.List)
|
||||
*/
|
||||
public void addAttributes(String ticket, List<String> keys, List<Attribute> values)
|
||||
{
|
||||
fAuthService.validate(ticket);
|
||||
fService.addAttributes(keys, values);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.remote.AttributeServiceTransport#addAttributes(java.lang.String, java.lang.String, java.util.List)
|
||||
*/
|
||||
public void addAttributes(String ticket, String path, List<Attribute> values)
|
||||
{
|
||||
fAuthService.validate(ticket);
|
||||
fService.addAttributes(path, values);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.remote.AttributeServiceTransport#setAttributes(java.lang.String, java.util.List, java.util.Map)
|
||||
*/
|
||||
public void setAttributes(String ticket, List<String> keys, Map<String, Attribute> entries)
|
||||
{
|
||||
fAuthService.validate(ticket);
|
||||
fService.setAttributes(keys, entries);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.remote.AttributeServiceTransport#setAttributes(java.lang.String, java.lang.String, java.util.Map)
|
||||
*/
|
||||
public void setAttributes(String ticket, String path, Map<String, Attribute> entries)
|
||||
{
|
||||
fAuthService.validate(ticket);
|
||||
fService.setAttributes(path, entries);
|
||||
}
|
||||
}
|
||||
|
@@ -211,4 +211,13 @@ public class MapAttributeValue extends AttributeValue implements MapAttribute
|
||||
builder.append('}');
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.attributes.AttributeValue#size()
|
||||
*/
|
||||
@Override
|
||||
public int size()
|
||||
{
|
||||
return fData.size();
|
||||
}
|
||||
}
|
||||
|
@@ -26,6 +26,7 @@
|
||||
package org.alfresco.repo.remote;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.repo.attributes.Attribute;
|
||||
import org.alfresco.service.cmr.attributes.AttrQuery;
|
||||
@@ -217,4 +218,36 @@ public class AttributeServiceRemote implements AttributeService
|
||||
{
|
||||
return fTransport.getCount(fTicketHolder.getTicket(), path);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.attributes.AttributeService#addAttributes(java.util.List, java.util.List)
|
||||
*/
|
||||
public void addAttributes(List<String> keys, List<Attribute> values)
|
||||
{
|
||||
fTransport.addAttributes(fTicketHolder.getTicket(), keys, values);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.attributes.AttributeService#addAttributes(java.lang.String, java.util.List)
|
||||
*/
|
||||
public void addAttributes(String path, List<Attribute> values)
|
||||
{
|
||||
fTransport.addAttributes(fTicketHolder.getTicket(), path, values);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.attributes.AttributeService#setAttributes(java.util.List, java.util.Map)
|
||||
*/
|
||||
public void setAttributes(List<String> keys, Map<String, Attribute> entries)
|
||||
{
|
||||
fTransport.setAttributes(fTicketHolder.getTicket(), keys, entries);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.attributes.AttributeService#setAttributes(java.lang.String, java.util.Map)
|
||||
*/
|
||||
public void setAttributes(String path, Map<String, Attribute> entries)
|
||||
{
|
||||
fTransport.setAttributes(fTicketHolder.getTicket(), path, entries);
|
||||
}
|
||||
}
|
||||
|
@@ -26,6 +26,7 @@
|
||||
package org.alfresco.service.cmr.attributes;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.repo.attributes.Attribute;
|
||||
import org.alfresco.util.Pair;
|
||||
@@ -100,6 +101,20 @@ public interface AttributeService
|
||||
*/
|
||||
public void setAttribute(List<String> keys, String name, Attribute value);
|
||||
|
||||
/**
|
||||
* Set a set of attributes on a map.
|
||||
* @param path The path to the map.
|
||||
* @param entries The entries to set.
|
||||
*/
|
||||
public void setAttributes(String path, Map<String, Attribute> entries);
|
||||
|
||||
/**
|
||||
* Set a set of attributes on a map.
|
||||
* @param keys The List of path keys to the map.
|
||||
* @param entries The entries to set.
|
||||
*/
|
||||
public void setAttributes(List<String> keys, Map<String, Attribute> entries);
|
||||
|
||||
/**
|
||||
* Set an attribute in a list.
|
||||
*
|
||||
@@ -133,6 +148,20 @@ public interface AttributeService
|
||||
*/
|
||||
public void addAttribute(List<String> keys, Attribute value);
|
||||
|
||||
/**
|
||||
* Add a list of attributes to the end of a list.
|
||||
* @param path The path to the list.
|
||||
* @param values The values to add.
|
||||
*/
|
||||
public void addAttributes(String path, List<Attribute> values);
|
||||
|
||||
/**
|
||||
* Add a list of attributes to the end of a list.
|
||||
* @param keys The List of path keys to the list.
|
||||
* @param values The values to add.
|
||||
*/
|
||||
public void addAttributes(List<String> keys, List<Attribute> values);
|
||||
|
||||
/**
|
||||
* Remove an Attribute.
|
||||
* @param name The name of the Attribute.
|
||||
|
@@ -26,6 +26,7 @@
|
||||
package org.alfresco.service.cmr.remote;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.repo.attributes.Attribute;
|
||||
import org.alfresco.service.cmr.attributes.AttrQuery;
|
||||
@@ -198,4 +199,36 @@ public interface AttributeServiceTransport
|
||||
* @return Whether the attribute exists.
|
||||
*/
|
||||
public boolean exists(String ticket, String path);
|
||||
|
||||
/**
|
||||
* Add a list of attributes.
|
||||
* @param ticket
|
||||
* @param keys
|
||||
* @param values
|
||||
*/
|
||||
public void addAttributes(String ticket, List<String> keys, List<Attribute> values);
|
||||
|
||||
/**
|
||||
* Add a list of attributes.
|
||||
* @param ticket
|
||||
* @param path
|
||||
* @param values
|
||||
*/
|
||||
public void addAttributes(String ticket, String path, List<Attribute> values);
|
||||
|
||||
/**
|
||||
* Add a set of attributes.
|
||||
* @param ticket
|
||||
* @param keys
|
||||
* @param entries
|
||||
*/
|
||||
public void setAttributes(String ticket, List<String> keys, Map<String, Attribute> entries);
|
||||
|
||||
/**
|
||||
* Add a set of attributes.
|
||||
* @param ticket
|
||||
* @param path
|
||||
* @param entries
|
||||
*/
|
||||
public void setAttributes(String ticket, String path, Map<String, Attribute> entries);
|
||||
}
|
||||
|
Reference in New Issue
Block a user