mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Merged 5.1.N (5.1.2) to 5.2.N (5.2.1)
125605 rmunteanu: Merged 5.1.1 (5.1.1) to 5.1.N (5.1.2) 125498 slanglois: MNT-16155 Update source headers - remove svn:eol-style property on Java and JSP source files git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@125783 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -1,109 +1,109 @@
|
||||
package org.alfresco.web.bean.repository;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.faces.context.FacesContext;
|
||||
import javax.transaction.UserTransaction;
|
||||
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
/**
|
||||
* Wraps the notion of preferences and settings for a User.
|
||||
* Caches values until they are overwritten with a new value.
|
||||
*
|
||||
* @author Kevin Roast
|
||||
*/
|
||||
public final class Preferences implements Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 722840612660970723L;
|
||||
|
||||
private NodeRef preferencesRef;
|
||||
private transient NodeService nodeService;
|
||||
private Map<String, Serializable> cache = new HashMap<String, Serializable>(16, 1.0f);
|
||||
|
||||
/**
|
||||
* Package level constructor
|
||||
*/
|
||||
Preferences(NodeRef prefRef)
|
||||
{
|
||||
this.preferencesRef = prefRef;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a serialized preferences value.
|
||||
*
|
||||
* @param name Name of the value to retrieve.
|
||||
*
|
||||
* @return The value or null if not found/set.
|
||||
*/
|
||||
public Serializable getValue(String name)
|
||||
{
|
||||
Serializable value = null;
|
||||
|
||||
if (this.preferencesRef != null)
|
||||
{
|
||||
value = this.cache.get(name);
|
||||
|
||||
if (value == null)
|
||||
{
|
||||
QName qname = QName.createQName(NamespaceService.APP_MODEL_1_0_URI, name);
|
||||
value = getNodeService().getProperty(this.preferencesRef, qname);
|
||||
this.cache.put(name, value);
|
||||
}
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a serialized preference value.
|
||||
*
|
||||
* @param name Name of the value to set.
|
||||
* @param value Value to set.
|
||||
*/
|
||||
public void setValue(String name, Serializable value)
|
||||
{
|
||||
if (this.preferencesRef != null)
|
||||
{
|
||||
QName qname = QName.createQName(NamespaceService.APP_MODEL_1_0_URI, name);
|
||||
|
||||
// persist the property to the repo
|
||||
UserTransaction tx = null;
|
||||
try
|
||||
{
|
||||
FacesContext context = FacesContext.getCurrentInstance();
|
||||
tx = Repository.getUserTransaction(context);
|
||||
tx.begin();
|
||||
|
||||
getNodeService().setProperty(this.preferencesRef, qname, value);
|
||||
|
||||
tx.commit();
|
||||
|
||||
// update the cache
|
||||
this.cache.put(name, value);
|
||||
}
|
||||
catch (Throwable err)
|
||||
{
|
||||
// we cannot update the properties if a user is no longer authenticated
|
||||
try { if (tx != null) {tx.rollback();} } catch (Exception tex) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the NodeService instance.
|
||||
*/
|
||||
private NodeService getNodeService()
|
||||
{
|
||||
if (this.nodeService == null)
|
||||
{
|
||||
this.nodeService = Repository.getServiceRegistry(FacesContext.getCurrentInstance()).getNodeService();
|
||||
}
|
||||
return this.nodeService;
|
||||
}
|
||||
}
|
||||
package org.alfresco.web.bean.repository;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.faces.context.FacesContext;
|
||||
import javax.transaction.UserTransaction;
|
||||
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
/**
|
||||
* Wraps the notion of preferences and settings for a User.
|
||||
* Caches values until they are overwritten with a new value.
|
||||
*
|
||||
* @author Kevin Roast
|
||||
*/
|
||||
public final class Preferences implements Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 722840612660970723L;
|
||||
|
||||
private NodeRef preferencesRef;
|
||||
private transient NodeService nodeService;
|
||||
private Map<String, Serializable> cache = new HashMap<String, Serializable>(16, 1.0f);
|
||||
|
||||
/**
|
||||
* Package level constructor
|
||||
*/
|
||||
Preferences(NodeRef prefRef)
|
||||
{
|
||||
this.preferencesRef = prefRef;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a serialized preferences value.
|
||||
*
|
||||
* @param name Name of the value to retrieve.
|
||||
*
|
||||
* @return The value or null if not found/set.
|
||||
*/
|
||||
public Serializable getValue(String name)
|
||||
{
|
||||
Serializable value = null;
|
||||
|
||||
if (this.preferencesRef != null)
|
||||
{
|
||||
value = this.cache.get(name);
|
||||
|
||||
if (value == null)
|
||||
{
|
||||
QName qname = QName.createQName(NamespaceService.APP_MODEL_1_0_URI, name);
|
||||
value = getNodeService().getProperty(this.preferencesRef, qname);
|
||||
this.cache.put(name, value);
|
||||
}
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a serialized preference value.
|
||||
*
|
||||
* @param name Name of the value to set.
|
||||
* @param value Value to set.
|
||||
*/
|
||||
public void setValue(String name, Serializable value)
|
||||
{
|
||||
if (this.preferencesRef != null)
|
||||
{
|
||||
QName qname = QName.createQName(NamespaceService.APP_MODEL_1_0_URI, name);
|
||||
|
||||
// persist the property to the repo
|
||||
UserTransaction tx = null;
|
||||
try
|
||||
{
|
||||
FacesContext context = FacesContext.getCurrentInstance();
|
||||
tx = Repository.getUserTransaction(context);
|
||||
tx.begin();
|
||||
|
||||
getNodeService().setProperty(this.preferencesRef, qname, value);
|
||||
|
||||
tx.commit();
|
||||
|
||||
// update the cache
|
||||
this.cache.put(name, value);
|
||||
}
|
||||
catch (Throwable err)
|
||||
{
|
||||
// we cannot update the properties if a user is no longer authenticated
|
||||
try { if (tx != null) {tx.rollback();} } catch (Exception tex) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the NodeService instance.
|
||||
*/
|
||||
private NodeService getNodeService()
|
||||
{
|
||||
if (this.nodeService == null)
|
||||
{
|
||||
this.nodeService = Repository.getServiceRegistry(FacesContext.getCurrentInstance()).getNodeService();
|
||||
}
|
||||
return this.nodeService;
|
||||
}
|
||||
}
|
||||
|
@@ -1,49 +1,49 @@
|
||||
package org.alfresco.web.bean.repository;
|
||||
|
||||
import javax.faces.context.FacesContext;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import org.alfresco.web.app.Application;
|
||||
|
||||
/**
|
||||
* Simple client service to retrieve the Preferences object for the current User.
|
||||
*
|
||||
* @author Kevin Roast
|
||||
*/
|
||||
public final class PreferencesService
|
||||
{
|
||||
/**
|
||||
* Private constructor
|
||||
*/
|
||||
private PreferencesService()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The Preferences for the current User instance.
|
||||
*/
|
||||
public static Preferences getPreferences()
|
||||
{
|
||||
return getPreferences(FacesContext.getCurrentInstance());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param fc FacesContext
|
||||
* @return The Preferences for the current User instance.
|
||||
*/
|
||||
public static Preferences getPreferences(FacesContext fc)
|
||||
{
|
||||
User user = Application.getCurrentUser(fc);
|
||||
return user != null ? user.getPreferences(fc) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param session Http session
|
||||
* @return The Preferences for the current User instance.
|
||||
*/
|
||||
public static Preferences getPreferences(HttpSession session)
|
||||
{
|
||||
User user = Application.getCurrentUser(session);
|
||||
return user != null ? user.getPreferences(session.getServletContext()) : null;
|
||||
}
|
||||
}
|
||||
package org.alfresco.web.bean.repository;
|
||||
|
||||
import javax.faces.context.FacesContext;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import org.alfresco.web.app.Application;
|
||||
|
||||
/**
|
||||
* Simple client service to retrieve the Preferences object for the current User.
|
||||
*
|
||||
* @author Kevin Roast
|
||||
*/
|
||||
public final class PreferencesService
|
||||
{
|
||||
/**
|
||||
* Private constructor
|
||||
*/
|
||||
private PreferencesService()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The Preferences for the current User instance.
|
||||
*/
|
||||
public static Preferences getPreferences()
|
||||
{
|
||||
return getPreferences(FacesContext.getCurrentInstance());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param fc FacesContext
|
||||
* @return The Preferences for the current User instance.
|
||||
*/
|
||||
public static Preferences getPreferences(FacesContext fc)
|
||||
{
|
||||
User user = Application.getCurrentUser(fc);
|
||||
return user != null ? user.getPreferences(fc) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param session Http session
|
||||
* @return The Preferences for the current User instance.
|
||||
*/
|
||||
public static Preferences getPreferences(HttpSession session)
|
||||
{
|
||||
User user = Application.getCurrentUser(session);
|
||||
return user != null ? user.getPreferences(session.getServletContext()) : null;
|
||||
}
|
||||
}
|
||||
|
@@ -1,149 +1,149 @@
|
||||
package org.alfresco.web.bean.repository;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
/**
|
||||
* Represents a transient node i.e. it is not and will not be present in the repository.
|
||||
* <p>
|
||||
* This type of node is typically used to drive rich lists where the Map implementation
|
||||
* is required for sorting columns.
|
||||
* </p>
|
||||
*
|
||||
* @author gavinc
|
||||
*/
|
||||
public class TransientMapNode extends TransientNode implements Map<String, Object>
|
||||
{
|
||||
private static final long serialVersionUID = 1120307465342597322L;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* <p>
|
||||
* NOTE: The name is NOT automatically added to the map of properties,
|
||||
* if you need the name of this node to be in the map then add it to
|
||||
* the map passed in to this constructor.
|
||||
* </p>
|
||||
*
|
||||
* @param type The type this node will represent
|
||||
* @param name The name of the node
|
||||
* @param data The properties and associations this node will have
|
||||
*/
|
||||
public TransientMapNode(QName type, String name, Map<QName, Serializable> data)
|
||||
{
|
||||
super(type, name, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "Transient map node of type: " + getType() +
|
||||
"\nProperties: " + this.getProperties().toString();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
// Map implementation - allows the Node bean to be accessed using JSF expression syntax
|
||||
|
||||
/**
|
||||
* @see java.util.Map#clear()
|
||||
*/
|
||||
public void clear()
|
||||
{
|
||||
getProperties().clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see java.util.Map#containsKey(java.lang.Object)
|
||||
*/
|
||||
public boolean containsKey(Object key)
|
||||
{
|
||||
return getProperties().containsKey(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see java.util.Map#containsValue(java.lang.Object)
|
||||
*/
|
||||
public boolean containsValue(Object value)
|
||||
{
|
||||
return getProperties().containsKey(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see java.util.Map#entrySet()
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public Set entrySet()
|
||||
{
|
||||
return getProperties().entrySet();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see java.util.Map#get(java.lang.Object)
|
||||
*/
|
||||
public Object get(Object key)
|
||||
{
|
||||
return getProperties().get(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see java.util.Map#isEmpty()
|
||||
*/
|
||||
public boolean isEmpty()
|
||||
{
|
||||
return getProperties().isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see java.util.Map#keySet()
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public Set keySet()
|
||||
{
|
||||
return getProperties().keySet();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see java.util.Map#put(java.lang.Object, java.lang.Object)
|
||||
*/
|
||||
public Object put(String key, Object value)
|
||||
{
|
||||
return getProperties().put(key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see java.util.Map#putAll(java.util.Map)
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public void putAll(Map t)
|
||||
{
|
||||
getProperties().putAll(t);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see java.util.Map#remove(java.lang.Object)
|
||||
*/
|
||||
public Object remove(Object key)
|
||||
{
|
||||
return getProperties().remove(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see java.util.Map#size()
|
||||
*/
|
||||
public int size()
|
||||
{
|
||||
return getProperties().size();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see java.util.Map#values()
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public Collection values()
|
||||
{
|
||||
return getProperties().values();
|
||||
}
|
||||
}
|
||||
package org.alfresco.web.bean.repository;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
/**
|
||||
* Represents a transient node i.e. it is not and will not be present in the repository.
|
||||
* <p>
|
||||
* This type of node is typically used to drive rich lists where the Map implementation
|
||||
* is required for sorting columns.
|
||||
* </p>
|
||||
*
|
||||
* @author gavinc
|
||||
*/
|
||||
public class TransientMapNode extends TransientNode implements Map<String, Object>
|
||||
{
|
||||
private static final long serialVersionUID = 1120307465342597322L;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* <p>
|
||||
* NOTE: The name is NOT automatically added to the map of properties,
|
||||
* if you need the name of this node to be in the map then add it to
|
||||
* the map passed in to this constructor.
|
||||
* </p>
|
||||
*
|
||||
* @param type The type this node will represent
|
||||
* @param name The name of the node
|
||||
* @param data The properties and associations this node will have
|
||||
*/
|
||||
public TransientMapNode(QName type, String name, Map<QName, Serializable> data)
|
||||
{
|
||||
super(type, name, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "Transient map node of type: " + getType() +
|
||||
"\nProperties: " + this.getProperties().toString();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
// Map implementation - allows the Node bean to be accessed using JSF expression syntax
|
||||
|
||||
/**
|
||||
* @see java.util.Map#clear()
|
||||
*/
|
||||
public void clear()
|
||||
{
|
||||
getProperties().clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see java.util.Map#containsKey(java.lang.Object)
|
||||
*/
|
||||
public boolean containsKey(Object key)
|
||||
{
|
||||
return getProperties().containsKey(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see java.util.Map#containsValue(java.lang.Object)
|
||||
*/
|
||||
public boolean containsValue(Object value)
|
||||
{
|
||||
return getProperties().containsKey(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see java.util.Map#entrySet()
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public Set entrySet()
|
||||
{
|
||||
return getProperties().entrySet();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see java.util.Map#get(java.lang.Object)
|
||||
*/
|
||||
public Object get(Object key)
|
||||
{
|
||||
return getProperties().get(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see java.util.Map#isEmpty()
|
||||
*/
|
||||
public boolean isEmpty()
|
||||
{
|
||||
return getProperties().isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see java.util.Map#keySet()
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public Set keySet()
|
||||
{
|
||||
return getProperties().keySet();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see java.util.Map#put(java.lang.Object, java.lang.Object)
|
||||
*/
|
||||
public Object put(String key, Object value)
|
||||
{
|
||||
return getProperties().put(key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see java.util.Map#putAll(java.util.Map)
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public void putAll(Map t)
|
||||
{
|
||||
getProperties().putAll(t);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see java.util.Map#remove(java.lang.Object)
|
||||
*/
|
||||
public Object remove(Object key)
|
||||
{
|
||||
return getProperties().remove(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see java.util.Map#size()
|
||||
*/
|
||||
public int size()
|
||||
{
|
||||
return getProperties().size();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see java.util.Map#values()
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public Collection values()
|
||||
{
|
||||
return getProperties().values();
|
||||
}
|
||||
}
|
||||
|
@@ -1,288 +1,288 @@
|
||||
package org.alfresco.web.bean.repository;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.service.cmr.dictionary.AspectDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.AssociationDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.ClassDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
||||
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.TypeDefinition;
|
||||
import org.alfresco.service.cmr.repository.AssociationRef;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.GUID;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
/**
|
||||
* Represents a transient node i.e. it is not and will not be present in the repository.
|
||||
* <p>
|
||||
* This type of node is typically used to drive the property sheet when data collection
|
||||
* is required for a type but the node does not need to be stored in the repository. An
|
||||
* example use is the workflow, transient nodes are used to collect workitem metadata.
|
||||
* </p>
|
||||
*
|
||||
* @author gavinc
|
||||
*/
|
||||
public class TransientNode extends Node
|
||||
{
|
||||
private static final long serialVersionUID = 2140554155948154106L;
|
||||
|
||||
private static final Log logger = LogFactory.getLog(TransientNode.class);
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* <p>
|
||||
* NOTE: The name is NOT automatically added to the map of properties,
|
||||
* if you need the name of this node to be in the map then add it to
|
||||
* the map passed in to this constructor.
|
||||
* </p>
|
||||
*
|
||||
* @param type The type this node will represent
|
||||
* @param name The name of the node
|
||||
* @param data The properties and associations this node will have
|
||||
*/
|
||||
public TransientNode(QName type, String name, Map<QName, Serializable> data)
|
||||
{
|
||||
// create a dummy NodeRef to pass to the constructor
|
||||
super(new NodeRef(Repository.getStoreRef(), GUID.generate()));
|
||||
|
||||
this.type = type;
|
||||
this.name = name;
|
||||
|
||||
// initialise the node
|
||||
initNode(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a transient node for an item yet to be created in the Repository.
|
||||
*
|
||||
* This will apply any one-time initialisation required upon creation of the node
|
||||
* e.g. assignment of default values.
|
||||
*
|
||||
* @param dictionaryService dictionary service
|
||||
* @param typeDef The type definition this node will represent
|
||||
* @param name The name of the node
|
||||
* @param data The properties and associations this node will have
|
||||
* @return transient node
|
||||
*/
|
||||
public static TransientNode createNew(DictionaryService dictionaryService, TypeDefinition typeDef, String name, Map<QName, Serializable> data)
|
||||
{
|
||||
// build a complete anonymous type for the start task
|
||||
List<AspectDefinition> aspects = typeDef.getDefaultAspects();
|
||||
List<QName> aspectNames = new ArrayList<QName>(aspects.size());
|
||||
getMandatoryAspects(typeDef, aspectNames);
|
||||
ClassDefinition startTaskDef = dictionaryService.getAnonymousType(typeDef.getName(), aspectNames);
|
||||
|
||||
// initialise start task values
|
||||
Map<QName, Serializable> startValues = new HashMap<QName, Serializable>();
|
||||
if (data != null)
|
||||
{
|
||||
startValues.putAll(data);
|
||||
}
|
||||
|
||||
// apply default values
|
||||
Map<QName, PropertyDefinition> propertyDefs = startTaskDef.getProperties();
|
||||
for (Map.Entry<QName, PropertyDefinition> entry : propertyDefs.entrySet())
|
||||
{
|
||||
String defaultValue = entry.getValue().getDefaultValue();
|
||||
if (defaultValue != null)
|
||||
{
|
||||
if (startValues.get(entry.getKey()) == null)
|
||||
{
|
||||
startValues.put(entry.getKey(), (Serializable)DefaultTypeConverter.INSTANCE.convert(entry.getValue().getDataType(), defaultValue));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new TransientNode(typeDef.getName(), name, startValues);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a flattened list of all mandatory aspects for a given class
|
||||
*
|
||||
* @param classDef the class
|
||||
* @param aspects a list to hold the mandatory aspects
|
||||
*/
|
||||
private static void getMandatoryAspects(ClassDefinition classDef, List<QName> aspects)
|
||||
{
|
||||
for (AspectDefinition aspect : classDef.getDefaultAspects())
|
||||
{
|
||||
QName aspectName = aspect.getName();
|
||||
if (!aspects.contains(aspectName))
|
||||
{
|
||||
aspects.add(aspect.getName());
|
||||
getMandatoryAspects(aspect, aspects);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialises the node.
|
||||
*
|
||||
* @param data The properties and associations to initialise the node with
|
||||
*/
|
||||
protected void initNode(Map<QName, Serializable> data)
|
||||
{
|
||||
// setup the transient node so that the super class methods work
|
||||
// and do not need to go back to the repository
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("Initialising transient node with data: " + data);
|
||||
|
||||
DictionaryService ddService = this.getServiceRegistry().getDictionaryService();
|
||||
|
||||
// marshall the given properties and associations into the internal maps
|
||||
this.associations = new QNameNodeMap(this, this);
|
||||
this.childAssociations = new QNameNodeMap(this, this);
|
||||
|
||||
if (data != null)
|
||||
{
|
||||
// go through all data items and allocate to the correct internal list
|
||||
for (QName item : data.keySet())
|
||||
{
|
||||
PropertyDefinition propDef = ddService.getProperty(item);
|
||||
if (propDef != null)
|
||||
{
|
||||
this.properties.put(item, data.get(item));
|
||||
}
|
||||
else
|
||||
{
|
||||
// see if the item is either type of association
|
||||
AssociationDefinition assocDef = ddService.getAssociation(item);
|
||||
if (assocDef != null)
|
||||
{
|
||||
if (assocDef.isChild())
|
||||
{
|
||||
Object obj = data.get(item);
|
||||
if (obj instanceof NodeRef)
|
||||
{
|
||||
NodeRef child = (NodeRef)obj;
|
||||
|
||||
// create a child association reference, add it to a list and add the list
|
||||
// to the list of child associations for this node
|
||||
List<ChildAssociationRef> assocs = new ArrayList<ChildAssociationRef>(1);
|
||||
ChildAssociationRef childRef = new ChildAssociationRef(assocDef.getName(), this.nodeRef,
|
||||
null, child);
|
||||
assocs.add(childRef);
|
||||
|
||||
this.childAssociations.put(item, assocs);
|
||||
}
|
||||
else if (obj instanceof List)
|
||||
{
|
||||
List targets = (List)obj;
|
||||
|
||||
List<ChildAssociationRef> assocs = new ArrayList<ChildAssociationRef>(targets.size());
|
||||
|
||||
for (Object target : targets)
|
||||
{
|
||||
if (target instanceof NodeRef)
|
||||
{
|
||||
NodeRef currentChild = (NodeRef)target;
|
||||
ChildAssociationRef childRef = new ChildAssociationRef(assocDef.getName(),
|
||||
this.nodeRef, null, currentChild);
|
||||
assocs.add(childRef);
|
||||
}
|
||||
}
|
||||
|
||||
if (assocs.size() > 0)
|
||||
{
|
||||
this.childAssociations.put(item, assocs);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Object obj = data.get(item);
|
||||
if (obj instanceof NodeRef)
|
||||
{
|
||||
NodeRef target = (NodeRef)obj;
|
||||
|
||||
// create a association reference, add it to a list and add the list
|
||||
// to the list of associations for this node
|
||||
List<AssociationRef> assocs = new ArrayList<AssociationRef>(1);
|
||||
AssociationRef assocRef = new AssociationRef(null, this.nodeRef, assocDef.getName(), target);
|
||||
assocs.add(assocRef);
|
||||
|
||||
this.associations.put(item, assocs);
|
||||
}
|
||||
else if (obj instanceof List)
|
||||
{
|
||||
List targets = (List)obj;
|
||||
|
||||
List<AssociationRef> assocs = new ArrayList<AssociationRef>(targets.size());
|
||||
|
||||
for (Object target : targets)
|
||||
{
|
||||
if (target instanceof NodeRef)
|
||||
{
|
||||
NodeRef currentTarget = (NodeRef)target;
|
||||
AssociationRef assocRef = new AssociationRef(null, this.nodeRef, assocDef.getName(), currentTarget);
|
||||
assocs.add(assocRef);
|
||||
}
|
||||
}
|
||||
|
||||
if (assocs.size() > 0)
|
||||
{
|
||||
this.associations.put(item, assocs);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// show that the maps have been initialised
|
||||
this.propsRetrieved = true;
|
||||
this.assocsRetrieved = true;
|
||||
this.childAssocsRetrieved = true;
|
||||
|
||||
// setup the list of aspects the node would have
|
||||
TypeDefinition typeDef = ddService.getType(this.type);
|
||||
if (typeDef == null)
|
||||
{
|
||||
throw new AlfrescoRuntimeException("Failed to find type definition: " + this.type);
|
||||
}
|
||||
|
||||
// get flat list of all aspects for the type
|
||||
List<QName> defaultAspects = new ArrayList<QName>(16);
|
||||
getMandatoryAspects(typeDef, defaultAspects);
|
||||
|
||||
this.aspects = new HashSet<QName>(defaultAspects);
|
||||
|
||||
// setup remaining variables
|
||||
this.path = null;
|
||||
this.locked = Boolean.FALSE;
|
||||
this.workingCopyOwner = Boolean.FALSE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(String permission)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset()
|
||||
{
|
||||
// don't reset anything otherwise we'll lose our data
|
||||
// with no way of getting it back!!
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "Transient node of type: " + getType() +
|
||||
"\nProperties: " + this.getProperties().toString();
|
||||
}
|
||||
}
|
||||
package org.alfresco.web.bean.repository;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.service.cmr.dictionary.AspectDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.AssociationDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.ClassDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
||||
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.TypeDefinition;
|
||||
import org.alfresco.service.cmr.repository.AssociationRef;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.GUID;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
/**
|
||||
* Represents a transient node i.e. it is not and will not be present in the repository.
|
||||
* <p>
|
||||
* This type of node is typically used to drive the property sheet when data collection
|
||||
* is required for a type but the node does not need to be stored in the repository. An
|
||||
* example use is the workflow, transient nodes are used to collect workitem metadata.
|
||||
* </p>
|
||||
*
|
||||
* @author gavinc
|
||||
*/
|
||||
public class TransientNode extends Node
|
||||
{
|
||||
private static final long serialVersionUID = 2140554155948154106L;
|
||||
|
||||
private static final Log logger = LogFactory.getLog(TransientNode.class);
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* <p>
|
||||
* NOTE: The name is NOT automatically added to the map of properties,
|
||||
* if you need the name of this node to be in the map then add it to
|
||||
* the map passed in to this constructor.
|
||||
* </p>
|
||||
*
|
||||
* @param type The type this node will represent
|
||||
* @param name The name of the node
|
||||
* @param data The properties and associations this node will have
|
||||
*/
|
||||
public TransientNode(QName type, String name, Map<QName, Serializable> data)
|
||||
{
|
||||
// create a dummy NodeRef to pass to the constructor
|
||||
super(new NodeRef(Repository.getStoreRef(), GUID.generate()));
|
||||
|
||||
this.type = type;
|
||||
this.name = name;
|
||||
|
||||
// initialise the node
|
||||
initNode(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a transient node for an item yet to be created in the Repository.
|
||||
*
|
||||
* This will apply any one-time initialisation required upon creation of the node
|
||||
* e.g. assignment of default values.
|
||||
*
|
||||
* @param dictionaryService dictionary service
|
||||
* @param typeDef The type definition this node will represent
|
||||
* @param name The name of the node
|
||||
* @param data The properties and associations this node will have
|
||||
* @return transient node
|
||||
*/
|
||||
public static TransientNode createNew(DictionaryService dictionaryService, TypeDefinition typeDef, String name, Map<QName, Serializable> data)
|
||||
{
|
||||
// build a complete anonymous type for the start task
|
||||
List<AspectDefinition> aspects = typeDef.getDefaultAspects();
|
||||
List<QName> aspectNames = new ArrayList<QName>(aspects.size());
|
||||
getMandatoryAspects(typeDef, aspectNames);
|
||||
ClassDefinition startTaskDef = dictionaryService.getAnonymousType(typeDef.getName(), aspectNames);
|
||||
|
||||
// initialise start task values
|
||||
Map<QName, Serializable> startValues = new HashMap<QName, Serializable>();
|
||||
if (data != null)
|
||||
{
|
||||
startValues.putAll(data);
|
||||
}
|
||||
|
||||
// apply default values
|
||||
Map<QName, PropertyDefinition> propertyDefs = startTaskDef.getProperties();
|
||||
for (Map.Entry<QName, PropertyDefinition> entry : propertyDefs.entrySet())
|
||||
{
|
||||
String defaultValue = entry.getValue().getDefaultValue();
|
||||
if (defaultValue != null)
|
||||
{
|
||||
if (startValues.get(entry.getKey()) == null)
|
||||
{
|
||||
startValues.put(entry.getKey(), (Serializable)DefaultTypeConverter.INSTANCE.convert(entry.getValue().getDataType(), defaultValue));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new TransientNode(typeDef.getName(), name, startValues);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a flattened list of all mandatory aspects for a given class
|
||||
*
|
||||
* @param classDef the class
|
||||
* @param aspects a list to hold the mandatory aspects
|
||||
*/
|
||||
private static void getMandatoryAspects(ClassDefinition classDef, List<QName> aspects)
|
||||
{
|
||||
for (AspectDefinition aspect : classDef.getDefaultAspects())
|
||||
{
|
||||
QName aspectName = aspect.getName();
|
||||
if (!aspects.contains(aspectName))
|
||||
{
|
||||
aspects.add(aspect.getName());
|
||||
getMandatoryAspects(aspect, aspects);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialises the node.
|
||||
*
|
||||
* @param data The properties and associations to initialise the node with
|
||||
*/
|
||||
protected void initNode(Map<QName, Serializable> data)
|
||||
{
|
||||
// setup the transient node so that the super class methods work
|
||||
// and do not need to go back to the repository
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("Initialising transient node with data: " + data);
|
||||
|
||||
DictionaryService ddService = this.getServiceRegistry().getDictionaryService();
|
||||
|
||||
// marshall the given properties and associations into the internal maps
|
||||
this.associations = new QNameNodeMap(this, this);
|
||||
this.childAssociations = new QNameNodeMap(this, this);
|
||||
|
||||
if (data != null)
|
||||
{
|
||||
// go through all data items and allocate to the correct internal list
|
||||
for (QName item : data.keySet())
|
||||
{
|
||||
PropertyDefinition propDef = ddService.getProperty(item);
|
||||
if (propDef != null)
|
||||
{
|
||||
this.properties.put(item, data.get(item));
|
||||
}
|
||||
else
|
||||
{
|
||||
// see if the item is either type of association
|
||||
AssociationDefinition assocDef = ddService.getAssociation(item);
|
||||
if (assocDef != null)
|
||||
{
|
||||
if (assocDef.isChild())
|
||||
{
|
||||
Object obj = data.get(item);
|
||||
if (obj instanceof NodeRef)
|
||||
{
|
||||
NodeRef child = (NodeRef)obj;
|
||||
|
||||
// create a child association reference, add it to a list and add the list
|
||||
// to the list of child associations for this node
|
||||
List<ChildAssociationRef> assocs = new ArrayList<ChildAssociationRef>(1);
|
||||
ChildAssociationRef childRef = new ChildAssociationRef(assocDef.getName(), this.nodeRef,
|
||||
null, child);
|
||||
assocs.add(childRef);
|
||||
|
||||
this.childAssociations.put(item, assocs);
|
||||
}
|
||||
else if (obj instanceof List)
|
||||
{
|
||||
List targets = (List)obj;
|
||||
|
||||
List<ChildAssociationRef> assocs = new ArrayList<ChildAssociationRef>(targets.size());
|
||||
|
||||
for (Object target : targets)
|
||||
{
|
||||
if (target instanceof NodeRef)
|
||||
{
|
||||
NodeRef currentChild = (NodeRef)target;
|
||||
ChildAssociationRef childRef = new ChildAssociationRef(assocDef.getName(),
|
||||
this.nodeRef, null, currentChild);
|
||||
assocs.add(childRef);
|
||||
}
|
||||
}
|
||||
|
||||
if (assocs.size() > 0)
|
||||
{
|
||||
this.childAssociations.put(item, assocs);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Object obj = data.get(item);
|
||||
if (obj instanceof NodeRef)
|
||||
{
|
||||
NodeRef target = (NodeRef)obj;
|
||||
|
||||
// create a association reference, add it to a list and add the list
|
||||
// to the list of associations for this node
|
||||
List<AssociationRef> assocs = new ArrayList<AssociationRef>(1);
|
||||
AssociationRef assocRef = new AssociationRef(null, this.nodeRef, assocDef.getName(), target);
|
||||
assocs.add(assocRef);
|
||||
|
||||
this.associations.put(item, assocs);
|
||||
}
|
||||
else if (obj instanceof List)
|
||||
{
|
||||
List targets = (List)obj;
|
||||
|
||||
List<AssociationRef> assocs = new ArrayList<AssociationRef>(targets.size());
|
||||
|
||||
for (Object target : targets)
|
||||
{
|
||||
if (target instanceof NodeRef)
|
||||
{
|
||||
NodeRef currentTarget = (NodeRef)target;
|
||||
AssociationRef assocRef = new AssociationRef(null, this.nodeRef, assocDef.getName(), currentTarget);
|
||||
assocs.add(assocRef);
|
||||
}
|
||||
}
|
||||
|
||||
if (assocs.size() > 0)
|
||||
{
|
||||
this.associations.put(item, assocs);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// show that the maps have been initialised
|
||||
this.propsRetrieved = true;
|
||||
this.assocsRetrieved = true;
|
||||
this.childAssocsRetrieved = true;
|
||||
|
||||
// setup the list of aspects the node would have
|
||||
TypeDefinition typeDef = ddService.getType(this.type);
|
||||
if (typeDef == null)
|
||||
{
|
||||
throw new AlfrescoRuntimeException("Failed to find type definition: " + this.type);
|
||||
}
|
||||
|
||||
// get flat list of all aspects for the type
|
||||
List<QName> defaultAspects = new ArrayList<QName>(16);
|
||||
getMandatoryAspects(typeDef, defaultAspects);
|
||||
|
||||
this.aspects = new HashSet<QName>(defaultAspects);
|
||||
|
||||
// setup remaining variables
|
||||
this.path = null;
|
||||
this.locked = Boolean.FALSE;
|
||||
this.workingCopyOwner = Boolean.FALSE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(String permission)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset()
|
||||
{
|
||||
// don't reset anything otherwise we'll lose our data
|
||||
// with no way of getting it back!!
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "Transient node of type: " + getType() +
|
||||
"\nProperties: " + this.getProperties().toString();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user