mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Enabled ACLs in Attributes. They are now readable and writable.
Added alternative calling convention versions of existing AttributeService methods. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@5529 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -60,6 +60,15 @@ public abstract class AttributeImpl implements Attribute
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper constructor for copy constructors.
|
||||
* @param acl The ACL.
|
||||
*/
|
||||
protected AttributeImpl(DbAccessControlList acl)
|
||||
{
|
||||
fACL = acl;
|
||||
}
|
||||
|
||||
public void setId(long id)
|
||||
{
|
||||
fID = id;
|
||||
|
@@ -77,29 +77,7 @@ public class AttributeServiceImpl implements AttributeService
|
||||
throw new AVMBadArgumentException("Null path.");
|
||||
}
|
||||
List<String> keys = parsePath(path);
|
||||
if (keys.size() < 1)
|
||||
{
|
||||
throw new AVMBadArgumentException("Bad Attribute Path: " + path);
|
||||
}
|
||||
GlobalAttributeEntry entry = fGlobalAttributeEntryDAO.get(keys.get(0));
|
||||
if (entry == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
Attribute current = entry.getAttribute();
|
||||
for (int i = 1; i < keys.size(); i++)
|
||||
{
|
||||
if (current.getType() != Type.MAP)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
current = current.get(keys.get(i));
|
||||
if (current == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return fAttributeConverter.toValue(current);
|
||||
return getAttribute(keys);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -153,42 +131,7 @@ public class AttributeServiceImpl implements AttributeService
|
||||
throw new AVMBadArgumentException("Null Attribute Path.");
|
||||
}
|
||||
List<String> keys = parsePath(path);
|
||||
if (keys.size() == 0)
|
||||
{
|
||||
throw new AVMBadArgumentException("Cannot query top level Attributes.");
|
||||
}
|
||||
GlobalAttributeEntry entry = fGlobalAttributeEntryDAO.get(keys.get(0));
|
||||
if (entry == null)
|
||||
{
|
||||
throw new AVMNotFoundException("Attribute Not Found: " + keys.get(0));
|
||||
}
|
||||
Attribute current = entry.getAttribute();
|
||||
if (current.getType() != Type.MAP)
|
||||
{
|
||||
throw new AVMWrongTypeException("Attribute Not Map: " + keys.get(0));
|
||||
}
|
||||
for (int i = 1; i < keys.size(); i++)
|
||||
{
|
||||
current = current.get(keys.get(i));
|
||||
if (current == null)
|
||||
{
|
||||
throw new AVMNotFoundException("Attribute Not Found: " + keys.get(i));
|
||||
}
|
||||
if (current.getType() != Type.MAP)
|
||||
{
|
||||
throw new AVMWrongTypeException("Attribute Not Map: " + keys.get(i));
|
||||
}
|
||||
}
|
||||
List<Pair<String, Attribute>> rawResult =
|
||||
fAttributeDAO.find((MapAttribute)current, query);
|
||||
List<Pair<String, Attribute>> result =
|
||||
new ArrayList<Pair<String, Attribute>>();
|
||||
for (Pair<String, Attribute> raw : rawResult)
|
||||
{
|
||||
result.add(new Pair<String, Attribute>(raw.getFirst(),
|
||||
fAttributeConverter.toValue(raw.getSecond())));
|
||||
}
|
||||
return result;
|
||||
return query(keys, query);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -201,10 +144,81 @@ public class AttributeServiceImpl implements AttributeService
|
||||
throw new AVMBadArgumentException("Null Attribute Path.");
|
||||
}
|
||||
List<String> keys = parsePath(path);
|
||||
removeAttribute(keys, name);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.attributes.AttributeService#setAttribute(java.lang.String, org.alfresco.repo.attributes.Attribute)
|
||||
*/
|
||||
public void setAttribute(String path, String name, Attribute value)
|
||||
{
|
||||
if (path == null)
|
||||
{
|
||||
throw new AVMBadArgumentException("Null path.");
|
||||
}
|
||||
List<String> keys = parsePath(path);
|
||||
setAttribute(keys, name, value);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.attributes.AttributeService#getKeys(java.lang.String)
|
||||
*/
|
||||
public List<String> getKeys(String path)
|
||||
{
|
||||
if (path == null)
|
||||
{
|
||||
throw new AVMBadArgumentException("Null Attribute Path.");
|
||||
}
|
||||
List<String> keys = parsePath(path);
|
||||
return getKeys(keys);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.attributes.AttributeService#getAttribute(java.util.List)
|
||||
*/
|
||||
public Attribute getAttribute(List<String> keys)
|
||||
{
|
||||
if (keys == null)
|
||||
{
|
||||
throw new AVMBadArgumentException("Null Attribute Path List.");
|
||||
}
|
||||
if (keys.size() < 1)
|
||||
{
|
||||
throw new AVMBadArgumentException("Bad Attribute Path List.");
|
||||
}
|
||||
GlobalAttributeEntry entry = fGlobalAttributeEntryDAO.get(keys.get(0));
|
||||
if (entry == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
Attribute current = entry.getAttribute();
|
||||
for (int i = 1; i < keys.size(); i++)
|
||||
{
|
||||
if (current.getType() != Type.MAP)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
current = current.get(keys.get(i));
|
||||
if (current == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return fAttributeConverter.toValue(current);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.attributes.AttributeService#getKeys(java.util.List)
|
||||
*/
|
||||
public List<String> getKeys(List<String> keys)
|
||||
{
|
||||
if (keys == null)
|
||||
{
|
||||
throw new AVMBadArgumentException("Null Keys List.");
|
||||
}
|
||||
if (keys.size() == 0)
|
||||
{
|
||||
fGlobalAttributeEntryDAO.delete(name);
|
||||
return;
|
||||
return fGlobalAttributeEntryDAO.getKeys();
|
||||
}
|
||||
GlobalAttributeEntry entry = fGlobalAttributeEntryDAO.get(keys.get(0));
|
||||
if (entry == null)
|
||||
@@ -228,15 +242,18 @@ public class AttributeServiceImpl implements AttributeService
|
||||
throw new AVMWrongTypeException("Attribute Not Map: " + keys.get(i));
|
||||
}
|
||||
}
|
||||
current.remove(name);
|
||||
return new ArrayList<String>(current.keySet());
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.attributes.AttributeService#setAttribute(java.lang.String, org.alfresco.repo.attributes.Attribute)
|
||||
* @see org.alfresco.service.cmr.attributes.AttributeService#setAttribute(java.util.List, java.lang.String, org.alfresco.repo.attributes.Attribute)
|
||||
*/
|
||||
public void setAttribute(String path, String name, Attribute value)
|
||||
public void setAttribute(List<String> keys, String name, Attribute value)
|
||||
{
|
||||
List<String> keys = parsePath(path);
|
||||
if (keys == null || name == null || value == null)
|
||||
{
|
||||
throw new AVMBadArgumentException("Null argument.");
|
||||
}
|
||||
Attribute toSave = fAttributeConverter.toPersistent(value);
|
||||
if (keys.size() == 0)
|
||||
{
|
||||
@@ -277,18 +294,17 @@ public class AttributeServiceImpl implements AttributeService
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.attributes.AttributeService#getKeys(java.lang.String)
|
||||
* @see org.alfresco.service.cmr.attributes.AttributeService#query(java.util.List, org.alfresco.service.cmr.attributes.AttrQuery)
|
||||
*/
|
||||
public List<String> getKeys(String path)
|
||||
public List<Pair<String, Attribute>> query(List<String> keys, AttrQuery query)
|
||||
{
|
||||
if (path == null)
|
||||
if (keys == null || query == null)
|
||||
{
|
||||
throw new AVMBadArgumentException("Null Attribute Path.");
|
||||
throw new AVMBadArgumentException("Null argument.");
|
||||
}
|
||||
List<String> keys = parsePath(path);
|
||||
if (keys.size() == 0)
|
||||
{
|
||||
return fGlobalAttributeEntryDAO.getKeys();
|
||||
throw new AVMBadArgumentException("Cannot query top level Attributes.");
|
||||
}
|
||||
GlobalAttributeEntry entry = fGlobalAttributeEntryDAO.get(keys.get(0));
|
||||
if (entry == null)
|
||||
@@ -312,7 +328,55 @@ public class AttributeServiceImpl implements AttributeService
|
||||
throw new AVMWrongTypeException("Attribute Not Map: " + keys.get(i));
|
||||
}
|
||||
}
|
||||
return new ArrayList<String>(current.keySet());
|
||||
List<Pair<String, Attribute>> rawResult =
|
||||
fAttributeDAO.find((MapAttribute)current, query);
|
||||
List<Pair<String, Attribute>> result =
|
||||
new ArrayList<Pair<String, Attribute>>();
|
||||
for (Pair<String, Attribute> raw : rawResult)
|
||||
{
|
||||
result.add(new Pair<String, Attribute>(raw.getFirst(),
|
||||
fAttributeConverter.toValue(raw.getSecond())));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.attributes.AttributeService#removeAttribute(java.util.List, java.lang.String)
|
||||
*/
|
||||
public void removeAttribute(List<String> keys, String name)
|
||||
{
|
||||
if (keys == null || name == null)
|
||||
{
|
||||
throw new AVMBadArgumentException("Null argument.");
|
||||
}
|
||||
if (keys.size() == 0)
|
||||
{
|
||||
fGlobalAttributeEntryDAO.delete(name);
|
||||
return;
|
||||
}
|
||||
GlobalAttributeEntry entry = fGlobalAttributeEntryDAO.get(keys.get(0));
|
||||
if (entry == null)
|
||||
{
|
||||
throw new AVMNotFoundException("Attribute Not Found: " + keys.get(0));
|
||||
}
|
||||
Attribute current = entry.getAttribute();
|
||||
if (current.getType() != Type.MAP)
|
||||
{
|
||||
throw new AVMWrongTypeException("Attribute Not Map: " + keys.get(0));
|
||||
}
|
||||
for (int i = 1; i < keys.size(); i++)
|
||||
{
|
||||
current = current.get(keys.get(i));
|
||||
if (current == null)
|
||||
{
|
||||
throw new AVMNotFoundException("Attribute Not Found: " + keys.get(i));
|
||||
}
|
||||
if (current.getType() != Type.MAP)
|
||||
{
|
||||
throw new AVMWrongTypeException("Attribute Not Map: " + keys.get(i));
|
||||
}
|
||||
}
|
||||
current.remove(name);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -38,6 +38,23 @@ import org.alfresco.repo.domain.DbAccessControlList;
|
||||
*/
|
||||
public abstract class AttributeValue implements Attribute
|
||||
{
|
||||
/**
|
||||
* ACL for this Attribute
|
||||
*/
|
||||
private DbAccessControlList fACL;
|
||||
|
||||
public AttributeValue()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper for copy constructors.
|
||||
*/
|
||||
public AttributeValue(DbAccessControlList acl)
|
||||
{
|
||||
fACL = acl;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.attributes.Attribute#clear()
|
||||
*/
|
||||
@@ -254,14 +271,12 @@ public abstract class AttributeValue implements Attribute
|
||||
throw new AttributeMethodNotImplemented("Not a map.");
|
||||
}
|
||||
|
||||
// I'm not sure if ACLs are serializable. So for now the following two
|
||||
// methods are noops.
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.attributes.Attribute#getAcl()
|
||||
*/
|
||||
public DbAccessControlList getAcl()
|
||||
{
|
||||
return null;
|
||||
return fACL;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -269,6 +284,6 @@ public abstract class AttributeValue implements Attribute
|
||||
*/
|
||||
public void setAcl(DbAccessControlList acl)
|
||||
{
|
||||
// Do Nothing.
|
||||
fACL = acl;
|
||||
}
|
||||
}
|
||||
|
@@ -50,6 +50,7 @@ public class BooleanAttributeImpl extends AttributeImpl implements
|
||||
|
||||
public BooleanAttributeImpl(BooleanAttribute attr)
|
||||
{
|
||||
super(attr.getAcl());
|
||||
fValue = attr.getBooleanValue();
|
||||
AVMDAOs.Instance().fAttributeDAO.save(this);
|
||||
}
|
||||
|
@@ -43,6 +43,7 @@ public class BooleanAttributeValue extends AttributeValue implements
|
||||
|
||||
public BooleanAttributeValue(BooleanAttribute attr)
|
||||
{
|
||||
super(attr.getAcl());
|
||||
fData = attr.getBooleanValue();
|
||||
}
|
||||
|
||||
|
@@ -49,6 +49,7 @@ public class ByteAttributeImpl extends AttributeImpl implements ByteAttribute
|
||||
|
||||
public ByteAttributeImpl(ByteAttribute attr)
|
||||
{
|
||||
super(attr.getAcl());
|
||||
fValue = attr.getByteValue();
|
||||
AVMDAOs.Instance().fAttributeDAO.save(this);
|
||||
}
|
||||
|
@@ -42,6 +42,7 @@ public class ByteAttributeValue extends AttributeValue implements ByteAttribute
|
||||
|
||||
public ByteAttributeValue(ByteAttribute attr)
|
||||
{
|
||||
super(attr.getAcl());
|
||||
fData = attr.getByteValue();
|
||||
}
|
||||
|
||||
|
@@ -49,6 +49,7 @@ public class DoubleAttributeImpl extends AttributeImpl implements Attribute
|
||||
|
||||
public DoubleAttributeImpl(DoubleAttribute attr)
|
||||
{
|
||||
super(attr.getAcl());
|
||||
fValue = attr.getDoubleValue();
|
||||
AVMDAOs.Instance().fAttributeDAO.save(this);
|
||||
}
|
||||
|
@@ -43,6 +43,7 @@ public class DoubleAttributeValue extends AttributeValue implements
|
||||
|
||||
public DoubleAttributeValue(DoubleAttribute attr)
|
||||
{
|
||||
super(attr.getAcl());
|
||||
fData = attr.getDoubleValue();
|
||||
}
|
||||
|
||||
|
@@ -49,6 +49,7 @@ public class FloatAttributeImpl extends AttributeImpl implements FloatAttribute
|
||||
|
||||
public FloatAttributeImpl(FloatAttribute attr)
|
||||
{
|
||||
super(attr.getAcl());
|
||||
fValue = attr.getFloatValue();
|
||||
AVMDAOs.Instance().fAttributeDAO.save(this);
|
||||
}
|
||||
|
@@ -43,6 +43,7 @@ public class FloatAttributeValue extends AttributeValue implements
|
||||
|
||||
public FloatAttributeValue(FloatAttribute attr)
|
||||
{
|
||||
super(attr.getAcl());
|
||||
fData = attr.getFloatValue();
|
||||
}
|
||||
|
||||
|
@@ -49,6 +49,7 @@ public class IntAttributeImpl extends AttributeImpl implements IntAttribute
|
||||
|
||||
public IntAttributeImpl(IntAttribute attr)
|
||||
{
|
||||
super(attr.getAcl());
|
||||
fValue = attr.getIntValue();
|
||||
AVMDAOs.Instance().fAttributeDAO.save(this);
|
||||
}
|
||||
|
@@ -42,6 +42,7 @@ public class IntAttributeValue extends AttributeValue implements IntAttribute
|
||||
|
||||
public IntAttributeValue(IntAttribute attr)
|
||||
{
|
||||
super(attr.getAcl());
|
||||
fData = attr.getIntValue();
|
||||
}
|
||||
|
||||
|
@@ -49,6 +49,7 @@ public class LongAttributeImpl extends AttributeImpl implements LongAttribute
|
||||
|
||||
public LongAttributeImpl(LongAttribute attr)
|
||||
{
|
||||
super(attr.getAcl());
|
||||
fValue = attr.getLongValue();
|
||||
AVMDAOs.Instance().fAttributeDAO.save(this);
|
||||
}
|
||||
|
@@ -42,6 +42,7 @@ public class LongAttributeValue extends AttributeValue implements LongAttribute
|
||||
|
||||
public LongAttributeValue(LongAttribute attr)
|
||||
{
|
||||
super(attr.getAcl());
|
||||
fData = attr.getLongValue();
|
||||
}
|
||||
|
||||
|
@@ -52,6 +52,7 @@ public class MapAttributeImpl extends AttributeImpl implements MapAttribute
|
||||
|
||||
public MapAttributeImpl(MapAttribute attr)
|
||||
{
|
||||
super(attr.getAcl());
|
||||
AVMDAOs.Instance().fAttributeDAO.save(this);
|
||||
for (Map.Entry<String, Attribute> entry : attr.entrySet())
|
||||
{
|
||||
|
@@ -50,6 +50,7 @@ public class MapAttributeValue extends AttributeValue implements MapAttribute
|
||||
|
||||
public MapAttributeValue(MapAttribute attr)
|
||||
{
|
||||
super(attr.getAcl());
|
||||
fData = new HashMap<String, Attribute>();
|
||||
for (Map.Entry<String, Attribute> entry : attr.entrySet())
|
||||
{
|
||||
|
@@ -52,6 +52,7 @@ public class SerializableAttributeImpl extends AttributeImpl implements
|
||||
|
||||
public SerializableAttributeImpl(SerializableAttribute attr)
|
||||
{
|
||||
super(attr.getAcl());
|
||||
fValue = attr.getSerializableValue();
|
||||
AVMDAOs.Instance().fAttributeDAO.save(this);
|
||||
}
|
||||
|
@@ -45,6 +45,7 @@ public class SerializableAttributeValue extends AttributeValue implements
|
||||
|
||||
public SerializableAttributeValue(SerializableAttribute attr)
|
||||
{
|
||||
super(attr.getAcl());
|
||||
fData = attr.getSerializableValue();
|
||||
}
|
||||
|
||||
|
@@ -49,6 +49,7 @@ public class ShortAttributeImpl extends AttributeImpl implements ShortAttribute
|
||||
|
||||
public ShortAttributeImpl(ShortAttribute attr)
|
||||
{
|
||||
super(attr.getAcl());
|
||||
fValue = attr.getShortValue();
|
||||
AVMDAOs.Instance().fAttributeDAO.save(this);
|
||||
}
|
||||
|
@@ -43,6 +43,7 @@ public class ShortAttributeValue extends AttributeValue implements
|
||||
|
||||
public ShortAttributeValue(ShortAttribute attr)
|
||||
{
|
||||
super(attr.getAcl());
|
||||
fData = attr.getShortValue();
|
||||
}
|
||||
|
||||
|
@@ -50,6 +50,7 @@ public class StringAttributeImpl extends AttributeImpl implements
|
||||
|
||||
public StringAttributeImpl(StringAttribute attr)
|
||||
{
|
||||
super(attr.getAcl());
|
||||
fValue = attr.getStringValue();
|
||||
AVMDAOs.Instance().fAttributeDAO.save(this);
|
||||
}
|
||||
|
@@ -43,6 +43,7 @@ public class StringAttributeValue extends AttributeValue implements
|
||||
|
||||
public StringAttributeValue(StringAttribute attr)
|
||||
{
|
||||
super(attr.getAcl());
|
||||
fData = attr.getStringValue();
|
||||
}
|
||||
|
||||
|
@@ -37,27 +37,50 @@ import org.alfresco.util.Pair;
|
||||
public interface AttributeService
|
||||
{
|
||||
/**
|
||||
* Get a Global Attribute.
|
||||
* Get an Attribute.
|
||||
* @param path The path of the Attribute.
|
||||
* @return The value of the attribute or null.
|
||||
*/
|
||||
public Attribute getAttribute(String path);
|
||||
|
||||
/**
|
||||
* Set a Global Attribute. Overwrites if it exists.
|
||||
* Get an attribute.
|
||||
* @param keys The keys in the attribute path.
|
||||
* @return The value of the attribute or null.
|
||||
*/
|
||||
public Attribute getAttribute(List<String> keys);
|
||||
|
||||
|
||||
/**
|
||||
* Set an attribute. Overwrites if it exists.
|
||||
* @param name The name of the Attribute.
|
||||
* @param value The value to set.
|
||||
*/
|
||||
public void setAttribute(String path, String name, Attribute value);
|
||||
|
||||
/**
|
||||
* Set an attribute
|
||||
* @param keys List of attribute path keys.
|
||||
* @param name The name of the attribute to set.
|
||||
* @param value The Attribute to set.
|
||||
*/
|
||||
public void setAttribute(List<String> keys, String name, Attribute value);
|
||||
|
||||
/**
|
||||
* Remove an Attribute.
|
||||
* @param name The name of the Attribute.
|
||||
*/
|
||||
public void removeAttribute(String path, String name);
|
||||
|
||||
/**
|
||||
* Remove an Attribute.
|
||||
* @param keys List of attribute path keys.
|
||||
* @param name The name of the attribute to remove.
|
||||
*/
|
||||
public void removeAttribute(List<String> keys, String name);
|
||||
|
||||
/**
|
||||
* Query for a list of attributes which are contained in the container
|
||||
* Query for a list of attributes which are contained in the map
|
||||
* defined by the given path and meet the query criteria.
|
||||
* @param path
|
||||
* @param query
|
||||
@@ -65,10 +88,26 @@ public interface AttributeService
|
||||
*/
|
||||
public List<Pair<String, Attribute>> query(String path, AttrQuery query);
|
||||
|
||||
/**
|
||||
* Query for a list of attributes which are contained in a map defined by the
|
||||
* given path and meet the query criteria.
|
||||
* @param keys The list of attribute path keys.
|
||||
* @param query
|
||||
* @return A list of matching attributes.
|
||||
*/
|
||||
public List<Pair<String, Attribute>> query(List<String> keys, AttrQuery query);
|
||||
|
||||
/**
|
||||
* Get all the keys for a given attribute path.
|
||||
* @param path The attribute path.
|
||||
* @return A list of all keys.
|
||||
*/
|
||||
public List<String> getKeys(String path);
|
||||
|
||||
/**
|
||||
* Get all the keys for a give attribute path.
|
||||
* @param keys The keys of the attribute path.
|
||||
* @return A list of all keys.
|
||||
*/
|
||||
public List<String> getKeys(List<String> keys);
|
||||
}
|
||||
|
Reference in New Issue
Block a user