use of org.alfresco.web.bean.repository.MapNode in project acs-community-packaging by Alfresco.
the class UsersDialog method search.
/**
* Event handler called when the user wishes to search for a user
*
* @return The outcome
*/
public String search() {
properties.getUsersRichList().setValue(null);
if (properties.getSearchCriteria() == null || properties.getSearchCriteria().trim().length() == 0) {
this.users = Collections.<Node>emptyList();
} else {
FacesContext context = FacesContext.getCurrentInstance();
UserTransaction tx = null;
try {
tx = Repository.getUserTransaction(context, true);
tx.begin();
// define the query to find people by their first or last name
String search = properties.getSearchCriteria();
if (logger.isDebugEnabled()) {
logger.debug("Query filter: " + search);
}
List<PersonInfo> persons = properties.getPersonService().getPeople(Utils.generatePersonFilter(search), true, Utils.generatePersonSort(), new PagingRequest(Utils.getPersonMaxResults(), null)).getPage();
if (logger.isDebugEnabled()) {
logger.debug("Found " + persons.size() + " users");
}
this.users = new ArrayList<Node>(persons.size());
for (PersonInfo person : persons) {
// create our Node representation
MapNode node = new MapNode(person.getNodeRef());
// set data binding properties
// this will also force initialisation of the props now during the UserTransaction
// it is much better for performance to do this now rather than during page bind
Map<String, Object> props = node.getProperties();
String firstName = (String) props.get("firstName");
String lastName = (String) props.get("lastName");
props.put("fullName", (firstName != null ? firstName : "") + ' ' + (lastName != null ? lastName : ""));
NodeRef homeFolderNodeRef = (NodeRef) props.get("homeFolder");
if (homeFolderNodeRef != null) {
props.put("homeSpace", homeFolderNodeRef);
}
node.addPropertyResolver("sizeLatest", this.resolverUserSizeLatest);
node.addPropertyResolver("quota", this.resolverUserQuota);
node.addPropertyResolver("isMutable", this.resolverUserMutable);
this.users.add(node);
}
// commit the transaction
tx.commit();
} catch (InvalidNodeRefException refErr) {
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(context, Repository.ERROR_NODEREF), new Object[] { "root" }));
this.users = Collections.<Node>emptyList();
try {
if (tx != null) {
tx.rollback();
}
} catch (Exception tex) {
}
} catch (Exception err) {
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(context, Repository.ERROR_GENERIC), err.getMessage()), err);
this.users = Collections.<Node>emptyList();
try {
if (tx != null) {
tx.rollback();
}
} catch (Exception tex) {
}
}
}
// return null to stay on the same page
return null;
}
use of org.alfresco.web.bean.repository.MapNode in project acs-community-packaging by Alfresco.
the class AdvancedSearchDialog method initialiseFromContext.
/**
* Initialise the Advanced Search UI screen from a SearchContext
*
* @param search the SearchContext to retrieve state from
*/
private void initialiseFromContext(SearchContext search) {
resetFields();
properties.setText(search.getText());
switch(search.getMode()) {
case SearchContext.SEARCH_ALL:
properties.setMode(MODE_ALL);
break;
case SearchContext.SEARCH_FILE_NAMES_CONTENTS:
properties.setMode(MODE_FILES_TEXT);
break;
case SearchContext.SEARCH_FILE_NAMES:
properties.setMode(MODE_FILES);
break;
case SearchContext.SEARCH_SPACE_NAMES:
properties.setMode(MODE_FOLDERS);
break;
}
properties.getPanels().put(PANEL_RESTRICT, true);
if (search.getLocation() != null) {
properties.setLocationChildren(search.getLocation().endsWith("//*"));
properties.setLocation(findNodeRefFromPath(search.getLocation()));
properties.setLookin(LOOKIN_OTHER);
properties.getPanels().put(PANEL_LOCATION, true);
}
String[] categories = search.getCategories();
if (categories != null && categories.length != 0) {
for (String category : categories) {
NodeRef categoryRef = findNodeRefFromPath(category);
if (categoryRef != null) {
Node categoryNode = new MapNode(categoryRef);
// add a value bound propery used to indicate if searching across children is selected
categoryNode.getProperties().put(INCLUDE_CHILDREN, category.endsWith("//*"));
properties.getCategories().add(categoryNode);
}
}
properties.getPanels().put(PANEL_CATEGORIES, true);
}
properties.setContentType(search.getContentType());
properties.setContentFormat(search.getMimeType());
properties.setFolderType(search.getFolderType());
properties.setDescription(search.getAttributeQuery(ContentModel.PROP_DESCRIPTION));
properties.setTitle(search.getAttributeQuery(ContentModel.PROP_TITLE));
properties.setAuthor(search.getAttributeQuery(ContentModel.PROP_AUTHOR));
if (properties.getContentType() != null || properties.getContentFormat() != null || properties.getDescription() != null || properties.getTitle() != null || properties.getAuthor() != null) {
properties.getPanels().put(PANEL_ATTRS, true);
}
RangeProperties createdDate = search.getRangeProperty(ContentModel.PROP_CREATED);
if (createdDate != null) {
properties.setCreatedDateFrom(Utils.parseXMLDateFormat(createdDate.lower));
properties.setCreatedDateTo(Utils.parseXMLDateFormat(createdDate.upper));
properties.setCreatedDateChecked(true);
properties.getPanels().put(PANEL_ATTRS, true);
}
RangeProperties modifiedDate = search.getRangeProperty(ContentModel.PROP_MODIFIED);
if (modifiedDate != null) {
properties.setModifiedDateFrom(Utils.parseXMLDateFormat(modifiedDate.lower));
properties.setModifiedDateTo(Utils.parseXMLDateFormat(modifiedDate.upper));
properties.setModifiedDateChecked(true);
properties.getPanels().put(PANEL_ATTRS, true);
}
// in case of dynamic config, only lookup once
Map<String, DataTypeDefinition> customPropertyLookup = getCustomPropertyLookup();
// custom fields - calculate which are required to set through the custom properties lookup table
for (String qname : customPropertyLookup.keySet()) {
DataTypeDefinition typeDef = customPropertyLookup.get(qname);
if (typeDef != null) {
QName typeName = typeDef.getName();
if (DataTypeDefinition.DATE.equals(typeName) || DataTypeDefinition.DATETIME.equals(typeName)) {
RangeProperties dateProps = search.getRangeProperty(QName.createQName(qname));
if (dateProps != null) {
properties.getCustomProperties().put(UISearchCustomProperties.PREFIX_DATE_FROM + qname, Utils.parseXMLDateFormat(dateProps.lower));
properties.getCustomProperties().put(UISearchCustomProperties.PREFIX_DATE_TO + qname, Utils.parseXMLDateFormat(dateProps.upper));
properties.getCustomProperties().put(qname, true);
properties.getPanels().put(PANEL_CUSTOM, true);
}
} else if (DataTypeDefinition.BOOLEAN.equals(typeName)) {
String strBool = search.getFixedValueQuery(QName.createQName(qname));
if (strBool != null) {
properties.getCustomProperties().put(qname, Boolean.parseBoolean(strBool));
properties.getPanels().put(PANEL_CUSTOM, true);
}
} else if (DataTypeDefinition.NODE_REF.equals(typeName) || DataTypeDefinition.CATEGORY.equals(typeName)) {
String strNodeRef = search.getFixedValueQuery(QName.createQName(qname));
if (strNodeRef != null) {
properties.getCustomProperties().put(qname, new NodeRef(strNodeRef));
properties.getPanels().put(PANEL_CUSTOM, true);
}
} else if (DataTypeDefinition.INT.equals(typeName) || DataTypeDefinition.LONG.equals(typeName) || DataTypeDefinition.FLOAT.equals(typeName) || DataTypeDefinition.DOUBLE.equals(typeName)) {
// currently numbers are rendered as text in UISearchCustomProperties component
// this code will need updating if that changes!
properties.getCustomProperties().put(qname, search.getFixedValueQuery(QName.createQName(qname)));
properties.getPanels().put(PANEL_CUSTOM, true);
} else {
// a default datatype may indicate either an attribute query, or if a Fixed Value
// is present then it's a LOV constraint with a value selected
Object value = search.getFixedValueQuery(QName.createQName(qname));
if (value != null) {
properties.getCustomProperties().put(UISearchCustomProperties.PREFIX_LOV_ITEM + qname, value);
properties.getCustomProperties().put(qname, Boolean.TRUE);
} else {
properties.getCustomProperties().put(qname, search.getAttributeQuery(QName.createQName(qname)));
}
properties.getPanels().put(PANEL_CUSTOM, true);
}
}
}
}
use of org.alfresco.web.bean.repository.MapNode in project acs-community-packaging by Alfresco.
the class AdvancedSearchDialog method addCategory.
/**
* Action handler called when the Add button is pressed to add the current Category selection
*/
@SuppressWarnings("unchecked")
public void addCategory(ActionEvent event) {
UIAjaxCategoryPicker selector = (UIAjaxCategoryPicker) event.getComponent().findComponent("catSelector");
UISelectBoolean chkChildren = (UISelectBoolean) event.getComponent().findComponent("chkCatChildren");
List<NodeRef> categoryRefs = (List<NodeRef>) selector.getValue();
if (categoryRefs != null) {
for (NodeRef categoryRef : categoryRefs) {
Node categoryNode = new MapNode(categoryRef);
// add a value bound propery used to indicate if searching across children is selected
categoryNode.getProperties().put(INCLUDE_CHILDREN, chkChildren.isSelected());
properties.getCategories().add(categoryNode);
}
// clear selector value after the list has been populated
selector.setValue(null);
}
}
use of org.alfresco.web.bean.repository.MapNode in project acs-community-packaging by Alfresco.
the class UserMembersBean method getUsers.
/**
* @return the list of user nodes for list data binding
*/
public List<Map> getUsers() {
FacesContext context = FacesContext.getCurrentInstance();
boolean includeInherited = (this.filterMode.equals(INHERITED));
List<Map> personNodes = null;
UserTransaction tx = null;
try {
tx = Repository.getUserTransaction(context, true);
tx.begin();
// Return all the permissions set against the current node
// for any authentication instance (user/group).
// Then combine them into a single list for each authentication found.
Map<String, List<String>> permissionMap = new HashMap<String, List<String>>(8, 1.0f);
Set<AccessPermission> permissions = getPermissionService().getAllSetPermissions(getNode().getNodeRef());
for (AccessPermission permission : permissions) {
// we are only interested in Allow and not groups/owner etc.
if (permission.getAccessStatus() == AccessStatus.ALLOWED && (permission.getAuthorityType() == AuthorityType.USER || permission.getAuthorityType() == AuthorityType.GROUP || permission.getAuthorityType() == AuthorityType.GUEST || permission.getAuthorityType() == AuthorityType.EVERYONE)) {
if (includeInherited || permission.isSetDirectly()) {
String authority = permission.getAuthority();
List<String> userPermissions = permissionMap.get(authority);
if (userPermissions == null) {
// create for first time
userPermissions = new ArrayList<String>(4);
permissionMap.put(authority, userPermissions);
}
// add the permission name for this authority
userPermissions.add(permission.getPermission());
}
}
}
// for each authentication (username/group key) found we get the Person
// node represented by it and use that for our list databinding object
personNodes = new ArrayList<Map>(permissionMap.size());
for (String authority : permissionMap.keySet()) {
// check if we are dealing with a person (User Authority)
if (AuthorityType.getAuthorityType(authority) == AuthorityType.GUEST || getPersonService().personExists(authority)) {
NodeRef nodeRef = getPersonService().getPerson(authority);
if (nodeRef != null) {
// create our Node representation
MapNode node = new MapNode(nodeRef);
// set data binding properties
// this will also force initialisation of the props now during the UserTransaction
// it is much better for performance to do this now rather than during page bind
Map<String, Object> props = node.getProperties();
String firstName = (String) props.get("firstName");
String lastName = (String) props.get("lastName");
props.put("fullName", (firstName != null ? firstName : "") + ' ' + (lastName != null ? lastName : ""));
props.put("userNameLabel", props.get("userName"));
props.put("roles", roleListToString(context, permissionMap.get(authority)));
props.put("icon", WebResources.IMAGE_PERSON);
props.put("isGroup", Boolean.FALSE);
props.put("inherited", includeInherited);
personNodes.add(node);
}
} else {
// need a map (dummy node) to represent props for this Group Authority
Map<String, Object> node = new HashMap<String, Object>(8, 1.0f);
String groupDisplayName = getAuthorityService().getAuthorityDisplayName(authority);
if (groupDisplayName == null || groupDisplayName.length() == 0) {
if (authority.startsWith(PermissionService.GROUP_PREFIX) == true) {
groupDisplayName = authority.substring(PermissionService.GROUP_PREFIX.length());
} else {
groupDisplayName = authority;
}
}
node.put("fullName", groupDisplayName);
node.put("userNameLabel", groupDisplayName);
node.put("userName", authority);
node.put("id", authority);
node.put("roles", roleListToString(context, permissionMap.get(authority)));
node.put("icon", WebResources.IMAGE_GROUP);
node.put("isGroup", Boolean.TRUE);
node.put("inherited", includeInherited);
personNodes.add(node);
}
}
// commit the transaction
tx.commit();
} catch (InvalidNodeRefException refErr) {
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(context, Repository.ERROR_NODEREF), new Object[] { refErr.getNodeRef() }));
personNodes = Collections.<Map>emptyList();
try {
if (tx != null) {
tx.rollback();
}
} catch (Exception tex) {
}
} catch (Throwable err) {
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(context, Repository.ERROR_GENERIC), err.getMessage()), err);
personNodes = Collections.<Map>emptyList();
try {
if (tx != null) {
tx.rollback();
}
} catch (Exception tex) {
}
}
return personNodes;
}
use of org.alfresco.web.bean.repository.MapNode in project acs-community-packaging by Alfresco.
the class StartWorkflowWizard method getResources.
/**
* Returns a list of resources associated with this task
* i.e. the children of the workflow package
*
* @return The list of nodes
*/
public List<Node> getResources() {
this.resources = new ArrayList<Node>(4);
UserTransaction tx = null;
try {
FacesContext context = FacesContext.getCurrentInstance();
tx = Repository.getUserTransaction(context, true);
tx.begin();
for (String newItem : this.packageItemsToAdd) {
NodeRef nodeRef = new NodeRef(newItem);
if (this.getNodeService().exists(nodeRef)) {
// create our Node representation
MapNode node = new MapNode(nodeRef, this.getNodeService(), true);
this.browseBean.setupCommonBindingProperties(node);
// add property resolvers to show path information
node.addPropertyResolver("path", this.browseBean.resolverPath);
node.addPropertyResolver("displayPath", this.browseBean.resolverDisplayPath);
this.resources.add(node);
} else {
if (logger.isDebugEnabled())
logger.debug("Ignoring " + nodeRef + " as it has been removed from the repository");
}
}
// commit the transaction
tx.commit();
} catch (Throwable err) {
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_GENERIC), err.getMessage()), err);
this.resources = Collections.<Node>emptyList();
try {
if (tx != null) {
tx.rollback();
}
} catch (Exception tex) {
}
}
return this.resources;
}
Aggregations