use of org.alfresco.service.cmr.dictionary.DictionaryService in project acs-community-packaging by Alfresco.
the class AdvancedSearchDialog method getSavedSearches.
/**
* @return list of saved searches as SelectItem objects
*/
public List<SelectItem> getSavedSearches() {
List<SelectItem> savedSearches = properties.getCachedSavedSearches().get();
if (savedSearches == null) {
FacesContext fc = FacesContext.getCurrentInstance();
ServiceRegistry services = Repository.getServiceRegistry(fc);
// get the searches list from the current user or global searches location
NodeRef searchesRef = null;
if (SAVED_SEARCHES_USER.equals(properties.getSavedSearchMode()) == true) {
searchesRef = getUserSearchesRef();
} else if (SAVED_SEARCHES_GLOBAL.equals(properties.getSavedSearchMode()) == true) {
searchesRef = getGlobalSearchesRef();
}
// read the content nodes under the folder
if (searchesRef != null) {
DictionaryService dd = services.getDictionaryService();
List<ChildAssociationRef> childRefs = getNodeService().getChildAssocs(searchesRef, ContentModel.ASSOC_CONTAINS, RegexQNamePattern.MATCH_ALL);
savedSearches = new ArrayList<SelectItem>(childRefs.size() + 1);
if (childRefs.size() != 0) {
for (ChildAssociationRef ref : childRefs) {
Node childNode = new Node(ref.getChildRef());
if (dd.isSubClass(childNode.getType(), ContentModel.TYPE_CONTENT)) {
savedSearches.add(new SelectItem(childNode.getId(), childNode.getName()));
}
}
// make sure the list is sorted by the label
QuickSort sorter = new QuickSort(savedSearches, "label", true, IDataContainer.SORT_CASEINSENSITIVE);
sorter.sort();
}
} else {
// handle missing/access denied folder case
savedSearches = new ArrayList<SelectItem>(1);
}
// add an entry (at the start) to instruct the user to select a saved search
savedSearches.add(0, new SelectItem(NO_SELECTION, Application.getMessage(FacesContext.getCurrentInstance(), MSG_SELECT_SAVED_SEARCH)));
// store in the cache (will auto-expire)
properties.getCachedSavedSearches().put(savedSearches);
}
return savedSearches;
}
use of org.alfresco.service.cmr.dictionary.DictionaryService in project acs-community-packaging by Alfresco.
the class AdvancedSearchDialog method getCustomPropertyLookup.
/**
* Helper map to lookup custom property QName strings against a DataTypeDefinition
*
* @return custom property lookup Map
*/
private Map<String, DataTypeDefinition> getCustomPropertyLookup() {
if ((properties.getCustomPropertyLookup() == null) || (Application.isDynamicConfig(FacesContext.getCurrentInstance()))) {
properties.setCustomPropertyLookup(new HashMap<String, DataTypeDefinition>(7, 1.0f));
List<CustomProperty> customProps = getSearchConfig().getCustomProperties();
if (customProps != null) {
DictionaryService dd = Repository.getServiceRegistry(FacesContext.getCurrentInstance()).getDictionaryService();
for (CustomProperty customProp : customProps) {
PropertyDefinition propDef = null;
QName propQName = Repository.resolveToQName(customProp.Property);
if (customProp.Type != null) {
QName type = Repository.resolveToQName(customProp.Type);
TypeDefinition typeDef = dd.getType(type);
propDef = typeDef.getProperties().get(propQName);
} else if (customProp.Aspect != null) {
QName aspect = Repository.resolveToQName(customProp.Aspect);
AspectDefinition aspectDef = dd.getAspect(aspect);
propDef = aspectDef.getProperties().get(propQName);
}
if (propQName != null && propDef != null) {
properties.getCustomPropertyLookup().put(propQName.toString(), propDef.getDataType());
}
}
}
}
return properties.getCustomPropertyLookup();
}
use of org.alfresco.service.cmr.dictionary.DictionaryService 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.DictionaryService in project acs-community-packaging by Alfresco.
the class Repository method setupBreadcrumbLocation.
/**
* Sets up the breadcrumb location representation for the given node in
* the given list.
*
* @param context FacesContext
* @param navBean NavigationBean instance
* @param location The location list to setup
* @param node The Node being navigated to
*/
public static void setupBreadcrumbLocation(FacesContext context, NavigationBean navBean, List<IBreadcrumbHandler> location, NodeRef node) {
// make the sure the given list is empty
location.clear();
// get required services
NodeService nodeService = Repository.getServiceRegistry(context).getNodeService();
DictionaryService dictionaryService = Repository.getServiceRegistry(context).getDictionaryService();
PermissionService permsService = Repository.getServiceRegistry(context).getPermissionService();
// add the given node to start
String nodeName = Repository.getNameForNode(nodeService, node);
location.add(navBean.new NavigationBreadcrumbHandler(node, nodeName));
// get the given node's parent node
NodeRef parent = nodeService.getPrimaryParent(node).getParentRef();
while (parent != null) {
// check the user can read the parent node
if (permsService.hasPermission(parent, PermissionService.READ) == AccessStatus.ALLOWED) {
// get the grand parent so we can check for the root node
NodeRef grandParent = nodeService.getPrimaryParent(parent).getParentRef();
if (grandParent != null) {
// check that the node is actually a folder type, content can have children!
QName parentType = nodeService.getType(parent);
if (dictionaryService.isSubClass(parentType, ContentModel.TYPE_FOLDER)) {
// if it's a folder add the location to the breadcrumb
String parentName = Repository.getNameForNode(nodeService, parent);
location.add(0, navBean.new NavigationBreadcrumbHandler(parent, parentName));
}
}
parent = grandParent;
} else {
// the user does not have Read permission above this point so stop!
break;
}
}
}
use of org.alfresco.service.cmr.dictionary.DictionaryService 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;
}
Aggregations