use of org.alfresco.service.cmr.dictionary.TypeDefinition in project acs-community-packaging by Alfresco.
the class AdvancedSearchDialog method getContentTypes.
/**
* @return Returns a list of content object types to allow the user to select from
*/
public List<SelectItem> getContentTypes() {
if ((properties.getContentTypes() == null) || (Application.isDynamicConfig(FacesContext.getCurrentInstance()))) {
FacesContext context = FacesContext.getCurrentInstance();
DictionaryService dictionaryService = Repository.getServiceRegistry(context).getDictionaryService();
// add the well known cm:content object type by default
properties.setContentTypes(new ArrayList<SelectItem>(5));
properties.getContentTypes().add(new SelectItem(ContentModel.TYPE_CONTENT.toString(), dictionaryService.getType(ContentModel.TYPE_CONTENT).getTitle(dictionaryService)));
// add any configured content sub-types to the list
List<String> types = getSearchConfig().getContentTypes();
if (types != null) {
for (String type : types) {
QName idQName = Repository.resolveToQName(type);
if (idQName != null) {
TypeDefinition typeDef = dictionaryService.getType(idQName);
if (typeDef != null && dictionaryService.isSubClass(typeDef.getName(), ContentModel.TYPE_CONTENT)) {
// try and get label from the dictionary
String label = typeDef.getTitle(dictionaryService);
// else just use the localname
if (label == null) {
label = idQName.getLocalName();
}
properties.getContentTypes().add(new SelectItem(idQName.toString(), label));
}
}
}
}
}
return properties.getContentTypes();
}
use of org.alfresco.service.cmr.dictionary.TypeDefinition in project acs-community-packaging by Alfresco.
the class TransientNode method initNode.
/**
* Initialises the node.
*
* @param data The properties and associations to initialise the node with
*/
protected void initNode(Map<QName, Serializable> data) {
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;
}
use of org.alfresco.service.cmr.dictionary.TypeDefinition in project acs-community-packaging by Alfresco.
the class ForumsBean method getNodes.
private void getNodes() {
long startTime = 0;
if (logger.isDebugEnabled())
startTime = System.currentTimeMillis();
UserTransaction tx = null;
try {
FacesContext context = FacesContext.getCurrentInstance();
tx = Repository.getUserTransaction(context, true);
tx.begin();
// get the current space from NavigationBean
String parentNodeId = this.navigator.getCurrentNodeId();
NodeRef parentRef;
if (parentNodeId == null) {
// no specific parent node specified - use the root node
parentRef = this.getNodeService().getRootNode(Repository.getStoreRef());
} else {
// build a NodeRef for the specified Id and our store
parentRef = new NodeRef(Repository.getStoreRef(), parentNodeId);
}
List<ChildAssociationRef> childRefs = this.getNodeService().getChildAssocs(parentRef, ContentModel.ASSOC_CONTAINS, RegexQNamePattern.MATCH_ALL);
this.forums = new ArrayList<Node>(childRefs.size());
this.topics = new ArrayList<Node>(childRefs.size());
this.posts = new ArrayList<Node>(childRefs.size());
for (ChildAssociationRef ref : childRefs) {
// create our Node representation from the NodeRef
NodeRef nodeRef = ref.getChildRef();
if (this.getNodeService().exists(nodeRef)) {
// find it's type so we can see if it's a node we are interested in
QName type = this.getNodeService().getType(nodeRef);
// make sure the type is defined in the data dictionary
TypeDefinition typeDef = this.getDictionaryService().getType(type);
if (typeDef != null) {
if (this.getDictionaryService().isSubClass(type, ContentModel.TYPE_SYSTEM_FOLDER) == false) {
if (this.getDictionaryService().isSubClass(type, ForumModel.TYPE_FORUMS) || this.getDictionaryService().isSubClass(type, ForumModel.TYPE_FORUM)) {
// create our Node representation
MapNode node = new MapNode(nodeRef, this.getNodeService(), true);
node.addPropertyResolver("icon", this.browseBean.resolverSpaceIcon);
node.addPropertyResolver("smallIcon", this.browseBean.resolverSmallIcon);
this.forums.add(node);
}
if (this.getDictionaryService().isSubClass(type, ForumModel.TYPE_TOPIC)) {
// create our Node representation
MapNode node = new MapNode(nodeRef, this.getNodeService(), true);
node.addPropertyResolver("icon", this.browseBean.resolverSpaceIcon);
node.addPropertyResolver("smallIcon", this.browseBean.resolverSmallIcon);
node.addPropertyResolver("replies", this.resolverReplies);
this.topics.add(node);
} else if (this.getDictionaryService().isSubClass(type, ForumModel.TYPE_POST)) {
// create our Node representation
MapNode node = new MapNode(nodeRef, this.getNodeService(), true);
this.browseBean.setupCommonBindingProperties(node);
node.addPropertyResolver("smallIcon", this.browseBean.resolverSmallIcon);
node.addPropertyResolver("message", this.resolverContent);
node.addPropertyResolver("replyTo", this.resolverReplyTo);
this.posts.add(node);
}
}
} else {
if (logger.isWarnEnabled())
logger.warn("Found invalid object in database: id = " + nodeRef + ", type = " + type);
}
}
}
// commit the transaction
tx.commit();
} catch (InvalidNodeRefException refErr) {
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_NODEREF), new Object[] { refErr.getNodeRef() }));
this.forums = Collections.<Node>emptyList();
this.topics = Collections.<Node>emptyList();
this.posts = Collections.<Node>emptyList();
try {
if (tx != null) {
tx.rollback();
}
} catch (Exception tex) {
}
} catch (Throwable err) {
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_GENERIC), err.getMessage()), err);
this.forums = Collections.<Node>emptyList();
this.topics = Collections.<Node>emptyList();
this.posts = Collections.<Node>emptyList();
try {
if (tx != null) {
tx.rollback();
}
} catch (Exception tex) {
}
}
if (logger.isDebugEnabled()) {
long endTime = System.currentTimeMillis();
logger.debug("Time to query and build forums nodes: " + (endTime - startTime) + "ms");
}
}
use of org.alfresco.service.cmr.dictionary.TypeDefinition in project acs-community-packaging by Alfresco.
the class BaseContentWizard method getObjectTypesImpl.
private List<SelectItem> getObjectTypesImpl() {
if ((this.objectTypes == null) || (Application.isDynamicConfig(FacesContext.getCurrentInstance()))) {
FacesContext context = FacesContext.getCurrentInstance();
// add the well known object type to start with
this.objectTypes = new ArrayList<SelectItem>(5);
ConfigService svc = Application.getConfigService(FacesContext.getCurrentInstance());
Config wizardCfg = svc.getConfig("Content Wizards");
if (wizardCfg != null) {
ConfigElement defaultTypesCfg = wizardCfg.getConfigElement("default-content-type");
String parentLabel = "";
if (defaultTypesCfg != null) {
// Get the default content-type to apply
ConfigElement typeElement = defaultTypesCfg.getChildren().get(0);
QName parentQName = Repository.resolveToQName(typeElement.getAttribute("name"));
TypeDefinition parentType = null;
if (parentQName != null) {
parentType = this.getDictionaryService().getType(parentQName);
if (parentType == null) {
// If no default content type is defined default to content
parentQName = ContentModel.TYPE_CONTENT;
parentType = this.getDictionaryService().getType(ContentModel.TYPE_CONTENT);
this.objectTypes.add(new SelectItem(ContentModel.TYPE_CONTENT.toString(), Application.getMessage(context, "content")));
logger.warn("Configured default content type not found in dictionary: " + parentQName);
} else {
// try and get the display label from config
parentLabel = Utils.getDisplayLabel(context, typeElement);
// if there wasn't a client based label try and get it from the dictionary
if (parentLabel == null) {
parentLabel = parentType.getTitle(this.getDictionaryService());
}
// finally, just use the localname
if (parentLabel == null) {
parentLabel = parentQName.getLocalName();
}
}
}
// Get all content types defined
ConfigElement typesCfg = wizardCfg.getConfigElement("content-types");
if (typesCfg != null) {
for (ConfigElement child : typesCfg.getChildren()) {
QName idQName = Repository.resolveToQName(child.getAttribute("name"));
if (idQName != null) {
TypeDefinition typeDef = this.getDictionaryService().getType(idQName);
if (typeDef != null) {
// for each type check if it is a subtype of the default content type
if (this.getDictionaryService().isSubClass(typeDef.getName(), parentType.getName())) {
// try and get the display label from config
String label = Utils.getDisplayLabel(context, child);
// if there wasn't a client based label try and get it from the dictionary
if (label == null) {
label = typeDef.getTitle(this.getDictionaryService());
}
// finally, just use the localname
if (label == null) {
label = idQName.getLocalName();
}
this.objectTypes.add(new SelectItem(idQName.toString(), label));
} else {
logger.warn("Failed to add '" + child.getAttribute("name") + "' to the list of content types - it is not a subtype of " + parentQName);
}
}
} else {
logger.warn("Failed to add '" + child.getAttribute("name") + "' to the list of content types as the type is not recognised");
}
}
}
// Case when no type is defined - we add the default content type to the list of available types
if (this.objectTypes.isEmpty()) {
// add default content type to the list of available types
this.objectTypes.add(new SelectItem(parentQName.toString(), parentLabel));
}
// make sure the list is sorted by the label
QuickSort sorter = new QuickSort(this.objectTypes, "label", true, IDataContainer.SORT_CASEINSENSITIVE);
sorter.sort();
} else {
logger.warn("Could not find 'content-types' configuration element");
}
} else {
logger.warn("Could not find 'Content Wizards' configuration section");
}
}
return this.objectTypes;
}
use of org.alfresco.service.cmr.dictionary.TypeDefinition in project acs-community-packaging by Alfresco.
the class NodeDescendantsLinkRenderer method encodeEnd.
/**
* @see javax.faces.render.Renderer#encodeEnd(javax.faces.context.FacesContext, javax.faces.component.UIComponent)
*/
public void encodeEnd(FacesContext context, UIComponent component) throws IOException {
// always check for this flag - as per the spec
if (component.isRendered() == true) {
Writer out = context.getResponseWriter();
UINodeDescendants control = (UINodeDescendants) component;
// make sure we have a NodeRef from the 'value' property ValueBinding
Object val = control.getValue();
if (val instanceof NodeRef == false) {
throw new IllegalArgumentException("UINodeDescendants component 'value' property must resolve to a NodeRef!");
}
NodeRef parentRef = (NodeRef) val;
// use Spring JSF integration to get the node service bean
NodeService service = getNodeService(context);
DictionaryService dd = getDictionaryService(context);
UserTransaction tx = null;
try {
tx = Repository.getUserTransaction(FacesContext.getCurrentInstance(), true);
tx.begin();
// TODO: need a comparator to sort node refs (based on childref qname)
// as currently the list is returned in a random order per request!
String separator = (String) component.getAttributes().get("separator");
if (separator == null) {
separator = DEFAULT_SEPARATOR;
}
// calculate the number of displayed child refs
if (service.exists(parentRef) == true) {
List<ChildAssociationRef> childRefs = service.getChildAssocs(parentRef, ContentModel.ASSOC_CONTAINS, RegexQNamePattern.MATCH_ALL);
List<Node> nodes = new ArrayList<Node>(childRefs.size());
for (int index = 0; index < childRefs.size(); index++) {
ChildAssociationRef ref = childRefs.get(index);
QName type = service.getType(ref.getChildRef());
TypeDefinition typeDef = dd.getType(type);
if (typeDef != null && dd.isSubClass(type, ContentModel.TYPE_FOLDER) && dd.isSubClass(type, ContentModel.TYPE_SYSTEM_FOLDER) == false) {
nodes.add(new Node(ref.getChildRef()));
}
}
QuickSort sorter = new QuickSort(nodes, "name", true, IDataContainer.SORT_CASEINSENSITIVE);
sorter.sort();
// walk each child ref and output a descendant link control for each item
int total = 0;
int maximum = nodes.size() > control.getMaxChildren() ? control.getMaxChildren() : nodes.size();
for (int index = 0; index < maximum; index++) {
Node node = nodes.get(index);
QName type = service.getType(node.getNodeRef());
TypeDefinition typeDef = dd.getType(type);
if (typeDef != null && dd.isSubClass(type, ContentModel.TYPE_FOLDER) && dd.isSubClass(type, ContentModel.TYPE_SYSTEM_FOLDER) == false) {
// output separator if appropriate
if (total > 0) {
out.write(separator);
}
out.write(renderDescendant(context, control, node.getNodeRef(), false));
total++;
}
}
// do we need to render ellipses to indicate more items than the maximum
if (control.getShowEllipses() == true && nodes.size() > maximum) {
out.write(separator);
// TODO: is this the correct way to get the information we need?
// e.g. primary parent may not be the correct path? how do we make sure we find
// the correct parent and more importantly the correct Display Name value!
out.write(renderDescendant(context, control, service.getPrimaryParent(parentRef).getChildRef(), true));
}
}
tx.commit();
} catch (Throwable err) {
try {
if (tx != null) {
tx.rollback();
}
} catch (Exception tex) {
}
throw new RuntimeException(err);
}
}
}
Aggregations