Merged up to HEAD.

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@3129 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Britt Park
2006-06-16 19:18:30 +00:00
parent 676f9d3ea4
commit c01717a0e7
15 changed files with 417 additions and 195 deletions

View File

@@ -39,6 +39,7 @@ import org.alfresco.repo.webservice.types.NamedValue;
import org.alfresco.repo.webservice.types.ParentReference;
import org.alfresco.repo.webservice.types.Predicate;
import org.alfresco.repo.webservice.types.Reference;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.repository.CopyService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
@@ -68,6 +69,7 @@ public class CMLUtil
private SearchService searchService;
private NamespaceService namespaceService;
private CopyService copyService;
private DictionaryService dictionaryService;
public void setNodeService(NodeService nodeService)
{
@@ -89,6 +91,11 @@ public class CMLUtil
this.copyService = copyService;
}
public void setDictionaryService(DictionaryService dictionaryService)
{
this.dictionaryService = dictionaryService;
}
/**
* Execute a cml update query.
*
@@ -249,6 +256,12 @@ public class CMLUtil
results.add(createResult(CREATE, null, nodeRef));
}
/**
* Get a property map from the named value array that can be used when setting properties
*
* @param namedValues a array of named value properties
* @return a property map of vlaues
*/
private PropertyMap getPropertyMap(NamedValue[] namedValues)
{
PropertyMap properties = new PropertyMap();
@@ -257,7 +270,8 @@ public class CMLUtil
for (NamedValue value : namedValues)
{
QName qname = QName.createQName(value.getName());
properties.put(qname, value.getValue());
Serializable propValue = Utils.getValueFromNamedValue(this.dictionaryService, qname, value);
properties.put(qname, propValue);
}
}
return properties;

View File

@@ -192,8 +192,8 @@ public class CMLUtilTest extends BaseSpringTest
update.setWhere(createPredicate(this.nodeRef));
update.setProperty(new NamedValue[]
{
new NamedValue(ContentModel.PROP_NAME.toString(), "updatedName"),
new NamedValue(ContentModel.PROP_CONTENT.toString(), CONTENT_DATA_HTML_UTF16.toString())
new NamedValue(ContentModel.PROP_NAME.toString(), false, "updatedName", null),
new NamedValue(ContentModel.PROP_CONTENT.toString(), false, CONTENT_DATA_HTML_UTF16.toString(), null)
});
CML cml = new CML();
@@ -441,8 +441,8 @@ public class CMLUtilTest extends BaseSpringTest
{
return new NamedValue[]
{
new NamedValue(ContentModel.PROP_NAME.toString(), "name"),
new NamedValue(ContentModel.PROP_CONTENT.toString(), CONTENT_DATA_TEXT_UTF8.toString())
new NamedValue(ContentModel.PROP_NAME.toString(), false, "name", null),
new NamedValue(ContentModel.PROP_CONTENT.toString(), false, CONTENT_DATA_TEXT_UTF8.toString(), null)
};
}
}

View File

@@ -19,6 +19,7 @@ package org.alfresco.repo.webservice;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Map;
@@ -43,6 +44,8 @@ import org.alfresco.repo.webservice.types.Store;
import org.alfresco.repo.webservice.types.StoreEnum;
import org.alfresco.repo.webservice.types.Version;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.StoreRef;
@@ -76,6 +79,139 @@ public class Utils
{
// don't allow construction
}
/**
* Utility method to convert from a string representation of a property value into the correct object representation.
*
* @param dictionaryService the dictionary service
* @param propertyName the qname of the property in question
* @param propertyValue the property vlaue as a string
* @return the object value of the property
*/
public static Serializable getValueFromNamedValue(DictionaryService dictionaryService, QName propertyName, NamedValue namedValue)
{
Serializable result = null;
org.alfresco.service.cmr.dictionary.PropertyDefinition propDef = dictionaryService.getProperty(propertyName);
if (propDef != null)
{
DataTypeDefinition propertyType = propDef.getDataType();
if (propertyType != null)
{
if (namedValue == null || namedValue.getIsMultiValue() == false)
{
if (logger.isDebugEnabled() == true)
{
logger.debug("Converting single-valued property '" + propertyName.toString() + "' with value " + namedValue.getValue());
}
result = (Serializable)DefaultTypeConverter.INSTANCE.convert(propertyType, namedValue.getValue());
}
else
{
String[] values = namedValue.getValues();
if (logger.isDebugEnabled() == true)
{
logger.debug("Converting multi-valued property '" + propertyName.toString() + "' with values " + values.toString());
}
if (values != null)
{
Collection<Serializable> collection = new ArrayList<Serializable>(values.length);
for (String value : values)
{
collection.add((Serializable)DefaultTypeConverter.INSTANCE.convert(propertyType, value));
}
if (logger.isDebugEnabled() == true)
{
logger.debug("The collection for the multi-value property has been generated '" + collection.toString());
}
result = (Serializable)collection;
}
}
}
else
{
if (logger.isDebugEnabled() == true)
{
logger.debug("No property definition was found for property '" + propertyName.toString() + "'");
}
}
}
return result;
}
/**
* Create a named value object from the property name and value informaiton
*
* @param dictionaryService the dictionary service
* @param propertyName the property qname
* @param propertyValue the property value
* @return the namedValue object
*/
public static NamedValue createNamedValue(DictionaryService dictionaryService, QName propertyName, Serializable propertyValue)
{
NamedValue namedValue = new NamedValue();
namedValue.setName(propertyName.toString());
if (logger.isDebugEnabled() == true)
{
logger.debug("Creating named value for property '" + propertyName + "' with value '" + propertyValue + "'");
}
if (propertyValue != null)
{
org.alfresco.service.cmr.dictionary.PropertyDefinition propDef = dictionaryService.getProperty(propertyName);
if (propDef != null)
{
if (propDef.isMultiValued() == true)
{
namedValue.setIsMultiValue(true);
if (propertyValue instanceof Collection)
{
if (logger.isDebugEnabled() == true)
{
logger.debug("Converting multivalue for property '" + propertyName + "'");
}
Collection<Serializable> collection = (Collection<Serializable>)propertyValue;
String[] values = new String[collection.size()];
int count = 0;
for (Serializable value : collection)
{
values[count] = DefaultTypeConverter.INSTANCE.convert(String.class, value);
count ++;
}
namedValue.setValues(values);
}
}
else
{
if (logger.isDebugEnabled() == true)
{
logger.debug("Converting single value for property '" + propertyName + "'");
}
namedValue.setIsMultiValue(false);
namedValue.setValue(DefaultTypeConverter.INSTANCE.convert(String.class, propertyValue));
}
}
else
{
if (logger.isDebugEnabled() == true)
{
logger.debug("No property definition found for property '" + propertyName + "'");
}
namedValue.setIsMultiValue(false);
namedValue.setValue(propertyValue.toString());
}
}
return namedValue;
}
/**
* Converts the web service Store type to a StoreRef used by the repository
@@ -437,7 +573,7 @@ public class Utils
{
value = entry.getValue().toString();
}
namedValues[iIndex] = new NamedValue(entry.getKey(), value);
namedValues[iIndex] = new NamedValue(entry.getKey(), false, value, null);
iIndex++;
}
webServiceVersion.setCommentaries(namedValues);

View File

@@ -530,7 +530,11 @@ public class ActionWebService extends AbstractWebService implements ActionServic
{
value = entry.getValue().toString();
}
namedValues[index] = new NamedValue(entry.getKey(), value);
NamedValue namedValue = new NamedValue();
namedValue.setName(entry.getKey());
namedValue.setIsMultiValue(false);
namedValue.setValue(value);
namedValues[index] = namedValue;
index++;
}
}

View File

@@ -34,7 +34,6 @@ import org.alfresco.repo.transaction.TransactionUtil.TransactionWork;
import org.alfresco.repo.webservice.AbstractWebService;
import org.alfresco.repo.webservice.Utils;
import org.alfresco.repo.webservice.action.ActionFault;
import org.alfresco.repo.webservice.repository.QuerySession;
import org.alfresco.repo.webservice.types.NamedValue;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter;
@@ -305,7 +304,11 @@ public class AdministrationWebService extends AbstractWebService implements
{
value = entry.getValue().toString();
}
namedValues.add(new NamedValue(entry.getKey().toString(), value));
NamedValue namedValue = new NamedValue();
namedValue.setName(entry.getKey().toString());
namedValue.setIsMultiValue(false);
namedValue.setValue(value);
namedValues.add(namedValue);
}
}
userDetails.setProperties((NamedValue[])namedValues.toArray(new NamedValue[namedValues.size()]));

View File

@@ -25,6 +25,7 @@ import org.alfresco.repo.webservice.types.NamedValue;
import org.alfresco.repo.webservice.types.Reference;
import org.alfresco.repo.webservice.types.ResultSetRow;
import org.alfresco.repo.webservice.types.ResultSetRowNode;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.repository.AssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
@@ -71,7 +72,7 @@ public class AssociatedQuerySession extends AbstractQuerySession
* org.alfresco.service.namespace.NamespaceService)
*/
public QueryResult getNextResultsBatch(SearchService searchService,
NodeService nodeService, NamespaceService namespaceService)
NodeService nodeService, NamespaceService namespaceService, DictionaryService dictionaryService)
{
QueryResult queryResult = null;
@@ -114,13 +115,7 @@ public class AssociatedQuerySession extends AbstractQuerySession
int col = 0;
for (QName propName : props.keySet())
{
String value = null;
Serializable valueObj = props.get(propName);
if (valueObj != null)
{
value = valueObj.toString();
}
columns[col] = new NamedValue(propName.toString(), value);
columns[col] = Utils.createNamedValue(dictionaryService, propName, props.get(propName));
col++;
}

View File

@@ -25,6 +25,7 @@ import org.alfresco.repo.webservice.types.NamedValue;
import org.alfresco.repo.webservice.types.Reference;
import org.alfresco.repo.webservice.types.ResultSetRow;
import org.alfresco.repo.webservice.types.ResultSetRowNode;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
@@ -63,7 +64,7 @@ public class ChildrenQuerySession extends AbstractQuerySession
/**
* @see org.alfresco.repo.webservice.repository.QuerySession#getNextResultsBatch(org.alfresco.service.cmr.search.SearchService, org.alfresco.service.cmr.repository.NodeService, org.alfresco.service.namespace.NamespaceService)
*/
public QueryResult getNextResultsBatch(SearchService searchService, NodeService nodeService, NamespaceService namespaceService)
public QueryResult getNextResultsBatch(SearchService searchService, NodeService nodeService, NamespaceService namespaceService, DictionaryService dictionaryService)
{
QueryResult queryResult = null;
@@ -100,13 +101,7 @@ public class ChildrenQuerySession extends AbstractQuerySession
int col = 0;
for (QName propName : props.keySet())
{
String value = null;
Serializable valueObj = props.get(propName);
if (valueObj != null)
{
value = valueObj.toString();
}
columns[col] = new NamedValue(propName.toString(), value);
columns[col] = Utils.createNamedValue(dictionaryService, propName, props.get(propName));
col++;
}

View File

@@ -25,6 +25,7 @@ import org.alfresco.repo.webservice.types.NamedValue;
import org.alfresco.repo.webservice.types.Reference;
import org.alfresco.repo.webservice.types.ResultSetRow;
import org.alfresco.repo.webservice.types.ResultSetRowNode;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
@@ -63,7 +64,7 @@ public class ParentsQuerySession extends AbstractQuerySession
/**
* @see org.alfresco.repo.webservice.repository.QuerySession#getNextResultsBatch(org.alfresco.service.cmr.search.SearchService, org.alfresco.service.cmr.repository.NodeService, org.alfresco.service.namespace.NamespaceService)
*/
public QueryResult getNextResultsBatch(SearchService searchService, NodeService nodeService, NamespaceService namespaceService)
public QueryResult getNextResultsBatch(SearchService searchService, NodeService nodeService, NamespaceService namespaceService, DictionaryService dictionaryService)
{
QueryResult queryResult = null;
@@ -100,13 +101,7 @@ public class ParentsQuerySession extends AbstractQuerySession
int col = 0;
for (QName propName : props.keySet())
{
String value = null;
Serializable valueObj = props.get(propName);
if (valueObj != null)
{
value = valueObj.toString();
}
columns[col] = new NamedValue(propName.toString(), value);
columns[col] = Utils.createNamedValue(dictionaryService, propName, props.get(propName));
col++;
}

View File

@@ -18,6 +18,7 @@ package org.alfresco.repo.webservice.repository;
import java.io.Serializable;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.search.SearchService;
import org.alfresco.service.namespace.NamespaceService;
@@ -51,6 +52,9 @@ public interface QuerySession extends Serializable
* @return QueryResult containing the next batch of results or null if there
* are no more results
*/
public QueryResult getNextResultsBatch(SearchService searchService, NodeService nodeService,
NamespaceService namespaceService);
public QueryResult getNextResultsBatch(
SearchService searchService,
NodeService nodeService,
NamespaceService namespaceService,
DictionaryService dictionaryService);
}

View File

@@ -44,7 +44,6 @@ import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.dictionary.TypeDefinition;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter;
import org.alfresco.service.namespace.QName;
import org.apache.axis.MessageContext;
import org.apache.commons.logging.Log;
@@ -199,7 +198,7 @@ public class RepositoryWebService extends AbstractWebService implements
.getBatchSize(msgContext), store, query, includeMetaData);
QueryResult queryResult = querySession
.getNextResultsBatch(this.searchService, this.nodeService,
this.namespaceService);
this.namespaceService, this.dictionaryService);
// add the session to the cache if there are more results to come
if (queryResult.getQuerySession() != null)
@@ -255,7 +254,7 @@ public class RepositoryWebService extends AbstractWebService implements
.getBatchSize(MessageContext.getCurrentContext()), node);
QueryResult queryResult = querySession
.getNextResultsBatch(this.searchService, this.nodeService,
this.namespaceService);
this.namespaceService, this.dictionaryService);
// add the session to the cache if there are more results to come
if (queryResult.getQuerySession() != null)
@@ -314,7 +313,7 @@ public class RepositoryWebService extends AbstractWebService implements
.getBatchSize(MessageContext.getCurrentContext()), node);
QueryResult queryResult = querySession
.getNextResultsBatch(this.searchService, this.nodeService,
this.namespaceService);
this.namespaceService, this.dictionaryService);
// add the session to the cache if there are more results to come
if (queryResult.getQuerySession() != null)
@@ -368,7 +367,7 @@ public class RepositoryWebService extends AbstractWebService implements
QuerySession querySession = new AssociatedQuerySession(Utils.getBatchSize(MessageContext.getCurrentContext()), node);
QueryResult queryResult = querySession
.getNextResultsBatch(this.searchService, this.nodeService,
this.namespaceService);
this.namespaceService, this.dictionaryService);
// add the session to the cache if there are more results to come
if (queryResult.getQuerySession() != null)
@@ -435,7 +434,7 @@ public class RepositoryWebService extends AbstractWebService implements
// get the next batch of results
queryResult = session.getNextResultsBatch(this.searchService,
this.nodeService, this.namespaceService);
this.nodeService, this.namespaceService, this.dictionaryService);
// remove the QuerySession from the cache if there are no more
// results to come
@@ -647,17 +646,8 @@ public class RepositoryWebService extends AbstractWebService implements
NamedValue[] properties = new NamedValue[propertyMap.size()];
int propertyIndex = 0;
for (Map.Entry<QName, Serializable> entry : propertyMap.entrySet())
{
String value = null;
try
{
value = DefaultTypeConverter.INSTANCE.convert(String.class, entry.getValue());
}
catch (Throwable exception)
{
value = entry.getValue().toString();
}
properties[propertyIndex] = new NamedValue(entry.getKey().toString(), value);
{
properties[propertyIndex] = Utils.createNamedValue(this.dictionaryService, entry.getKey(), entry.getValue());
propertyIndex++;
}

View File

@@ -24,14 +24,15 @@ import org.alfresco.repo.webservice.types.NamedValue;
import org.alfresco.repo.webservice.types.Query;
import org.alfresco.repo.webservice.types.ResultSetRowNode;
import org.alfresco.repo.webservice.types.Store;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.Path;
import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter;
import org.alfresco.service.cmr.search.ResultSet;
import org.alfresco.service.cmr.search.ResultSetRow;
import org.alfresco.service.cmr.search.SearchService;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -70,7 +71,7 @@ public class ResultSetQuerySession extends AbstractQuerySession
/**
* @see org.alfresco.repo.webservice.repository.QuerySession#getNextResultsBatch(org.alfresco.service.cmr.search.SearchService, org.alfresco.service.cmr.repository.NodeService, org.alfresco.service.namespace.NamespaceService)
*/
public QueryResult getNextResultsBatch(SearchService searchService, NodeService nodeService, NamespaceService namespaceService)
public QueryResult getNextResultsBatch(SearchService searchService, NodeService nodeService, NamespaceService namespaceService, DictionaryService dictionaryService)
{
QueryResult queryResult = null;
@@ -114,16 +115,6 @@ public class ResultSetQuerySession extends AbstractQuerySession
int col = 0;
for (Path path : values.keySet())
{
String value = null;
try
{
value = DefaultTypeConverter.INSTANCE.convert(String.class, values.get(path));
}
catch (Throwable exception)
{
value = values.get(path).toString();
}
// Get the attribute QName from the result path
String attributeName = path.last().toString();
if (attributeName.startsWith("@") == true)
@@ -131,7 +122,7 @@ public class ResultSetQuerySession extends AbstractQuerySession
attributeName = attributeName.substring(1);
}
columns[col] = new NamedValue(attributeName, value);
columns[col] = Utils.createNamedValue(dictionaryService, QName.createQName(attributeName), values.get(path)); //new NamedValue(attributeName, value);
col++;
}

View File

@@ -46,6 +46,9 @@
<property name="copyService">
<ref bean="CopyService"/>
</property>
<property name="dictionaryService">
<ref bean="DictionaryService"/>
</property>
</bean>
<!-- Implementations of each exposed web service -->