use of org.alfresco.service.cmr.repository.InvalidNodeRefException 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.service.cmr.repository.InvalidNodeRefException in project acs-community-packaging by Alfresco.
the class UsersDialog method setupUserAction.
/**
* Called in preparation for actions that need to setup a Person context on
* the Users bean before an action page is called.
*
* @param personId String
*/
public void setupUserAction(String personId) {
if (personId != null && personId.length() != 0) {
if (logger.isDebugEnabled())
logger.debug("Setup for action, setting current Person to: " + personId);
try {
// create the node ref, then our node representation
NodeRef ref = new NodeRef(Repository.getStoreRef(), personId);
Node node = new Node(ref);
// remember the Person node
properties.setPerson(node);
// clear the UI state in preparation for finishing the action
// and returning to the main page
contextUpdated();
} catch (InvalidNodeRefException refErr) {
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_NODEREF), new Object[] { personId }));
}
} else {
properties.setPerson(null);
}
}
use of org.alfresco.service.cmr.repository.InvalidNodeRefException in project acs-community-packaging by Alfresco.
the class RecentSpacesBean method navigate.
// ------------------------------------------------------------------------------
// Action method handlers
/**
* Action handler bound to the recent spaces Shelf component called when a Space is clicked
*/
public void navigate(ActionEvent event) {
// work out which node was clicked from the event data
UIRecentSpacesShelfItem.RecentSpacesEvent spaceEvent = (UIRecentSpacesShelfItem.RecentSpacesEvent) event;
Node selectedNode = this.recentSpaces.get(spaceEvent.Index);
NodeRef nodeRef = selectedNode.getNodeRef();
try {
// then navigate to the appropriate node in UI
// use browse bean functionality for this as it will update the breadcrumb for us
this.browseBean.updateUILocation(nodeRef);
} catch (InvalidNodeRefException refErr) {
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_NODEREF), new Object[] { nodeRef.getId() }));
// remove invalid node from recent spaces list
this.recentSpaces.remove(spaceEvent.Index);
}
}
use of org.alfresco.service.cmr.repository.InvalidNodeRefException 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.service.cmr.repository.InvalidNodeRefException in project acs-community-packaging by Alfresco.
the class UserMembersBean method removeOK.
/**
* Action handler called when the OK button is clicked on the Remove User page
*/
public String removeOK() {
String outcome = getDefaultFinishOutcome();
UserTransaction tx = null;
FacesContext context = FacesContext.getCurrentInstance();
try {
tx = Repository.getUserTransaction(context);
tx.begin();
// remove the invited User
if (getPersonAuthority() != null) {
// clear permissions for the specified Authority
this.getPermissionService().clearPermission(getNode().getNodeRef(), getPersonAuthority());
}
// commit the transaction
tx.commit();
} catch (Exception e) {
// rollback the transaction
try {
if (tx != null) {
tx.rollback();
}
} catch (Exception tex) {
}
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), ERROR_DELETE), e.getMessage()), e);
}
// pressing the top level navigation button i.e. My Home
if (this.getPermissionService().hasPermission(getNode().getNodeRef(), PermissionService.CHANGE_PERMISSIONS) == AccessStatus.DENIED) {
NavigationBean nb = (NavigationBean) FacesHelper.getManagedBean(context, NavigationBean.BEAN_NAME);
if (nb != null) {
try {
nb.processToolbarLocation(nb.getToolbarLocation(), true);
outcome = "browse";
} catch (InvalidNodeRefException refErr) {
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_NOHOME), Application.getCurrentUser(context).getHomeSpaceId()), refErr);
} catch (Exception err) {
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_GENERIC), err.getMessage()), err);
}
}
}
return outcome;
}
Aggregations