AVM Nodes are (theoretically) mostly aspect ready. AVMNodeService is

now derived from AbstractNodeServiceImpl to make policy awareness easier.
Moved addDefaultPropertyValues from DbNodeServiceImpl to 
AbstractNodeServiceImpl so AVMNodeService can use it.  A fix for an
NPE that showed up in stress test.


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@3603 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Britt Park
2006-08-24 18:36:59 +00:00
parent d67b926589
commit 0606fa3ab6
15 changed files with 252 additions and 619 deletions

View File

@@ -49,8 +49,10 @@ import org.alfresco.repo.policy.AssociationPolicyDelegate;
import org.alfresco.repo.policy.ClassPolicyDelegate;
import org.alfresco.repo.policy.PolicyComponent;
import org.alfresco.repo.search.Indexer;
import org.alfresco.service.cmr.dictionary.ClassDefinition;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.dictionary.DictionaryException;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
import org.alfresco.service.cmr.repository.AssociationRef;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
@@ -88,6 +90,7 @@ public abstract class AbstractNodeServiceImpl implements NodeService
private String uuid;
/** controls policy delegates */
private PolicyComponent policyComponent;
protected DictionaryService dictionaryService;
/*
* Policy delegates
@@ -125,6 +128,11 @@ public abstract class AbstractNodeServiceImpl implements NodeService
this.policyComponent = policyComponent;
}
public void setDictionaryService(DictionaryService dictionaryService)
{
this.dictionaryService = dictionaryService;
}
/**
* Checks equality by type and uuid
*/
@@ -564,7 +572,7 @@ public abstract class AbstractNodeServiceImpl implements NodeService
* @see RegexQNamePattern#MATCH_ALL
* @see NodeService#getChildAssocs(NodeRef, QNamePattern, QNamePattern)
*/
public final List<ChildAssociationRef> getChildAssocs(NodeRef nodeRef) throws InvalidNodeRefException
public List<ChildAssociationRef> getChildAssocs(NodeRef nodeRef) throws InvalidNodeRefException
{
return getChildAssocs(nodeRef, RegexQNamePattern.MATCH_ALL, RegexQNamePattern.MATCH_ALL);
}
@@ -677,4 +685,51 @@ public abstract class AbstractNodeServiceImpl implements NodeService
e);
}
}
/**
* Sets the default property values
*
* @param classDefinition
* @param properties
*/
protected void addDefaultPropertyValues(ClassDefinition classDefinition, Map<QName, Serializable> properties)
{
for (Map.Entry<QName, Serializable> entry : classDefinition.getDefaultValues().entrySet())
{
if (properties.containsKey(entry.getKey()))
{
// property is present
continue;
}
Serializable value = entry.getValue();
// Check the type of the default property
PropertyDefinition prop = this.dictionaryService.getProperty(entry.getKey());
if (prop == null)
{
// dictionary doesn't have a default value present
continue;
}
// TODO: what other conversions are necessary here for other types of default values ?
// ensure that we deliver the property in the correct form
if (DataTypeDefinition.BOOLEAN.equals(prop.getDataType().getName()) == true)
{
if (value instanceof String)
{
if (((String)value).toUpperCase().equals("TRUE") == true)
{
value = Boolean.TRUE;
}
else if (((String)value).toUpperCase().equals("FALSE") == true)
{
value = Boolean.FALSE;
}
}
}
// Set the default value of the property
properties.put(entry.getKey(), value);
}
}
}

View File

@@ -42,8 +42,6 @@ import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.transaction.AlfrescoTransactionSupport;
import org.alfresco.service.cmr.dictionary.AspectDefinition;
import org.alfresco.service.cmr.dictionary.ClassDefinition;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.dictionary.InvalidAspectException;
import org.alfresco.service.cmr.dictionary.InvalidTypeException;
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
@@ -77,7 +75,6 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
{
private static Log logger = LogFactory.getLog(DbNodeServiceImpl.class);
private DictionaryService dictionaryService;
private NodeDaoService nodeDaoService;
private StoreArchiveMap storeArchiveMap;
private NodeService avmNodeService;
@@ -87,11 +84,6 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
storeArchiveMap = new StoreArchiveMap(); // in case it is not set
}
public void setDictionaryService(DictionaryService dictionaryService)
{
this.dictionaryService = dictionaryService;
}
public void setNodeDaoService(NodeDaoService nodeDaoService)
{
this.nodeDaoService = nodeDaoService;
@@ -347,53 +339,6 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
}
}
/**
* Sets the default property values
*
* @param classDefinition
* @param properties
*/
private void addDefaultPropertyValues(ClassDefinition classDefinition, Map<QName, Serializable> properties)
{
for (Map.Entry<QName, Serializable> entry : classDefinition.getDefaultValues().entrySet())
{
if (properties.containsKey(entry.getKey()))
{
// property is present
continue;
}
Serializable value = entry.getValue();
// Check the type of the default property
PropertyDefinition prop = this.dictionaryService.getProperty(entry.getKey());
if (prop == null)
{
// dictionary doesn't have a default value present
continue;
}
// TODO: what other conversions are necessary here for other types of default values ?
// ensure that we deliver the property in the correct form
if (DataTypeDefinition.BOOLEAN.equals(prop.getDataType().getName()) == true)
{
if (value instanceof String)
{
if (((String)value).toUpperCase().equals("TRUE") == true)
{
value = Boolean.TRUE;
}
else if (((String)value).toUpperCase().equals("FALSE") == true)
{
value = Boolean.FALSE;
}
}
}
// Set the default value of the property
properties.put(entry.getKey(), value);
}
}
/**
* Drops the old primary association and creates a new one