use of org.alfresco.service.cmr.repository.InvalidNodeRefException in project acs-community-packaging by Alfresco.
the class UserShortcutsBean method click.
/**
* Action handler bound to the user shortcuts Shelf component called when a node is clicked
*/
public void click(ActionEvent event) {
// work out which node was clicked from the event data
UIShortcutsShelfItem.ShortcutEvent shortcutEvent = (UIShortcutsShelfItem.ShortcutEvent) event;
Node selectedNode = getShortcuts().get(shortcutEvent.Index);
try {
if (getPermissionService().hasPermission(selectedNode.getNodeRef(), PermissionService.READ) == AccessStatus.ALLOWED) {
if (getNodeService().exists(selectedNode.getNodeRef()) == false) {
throw new InvalidNodeRefException(selectedNode.getNodeRef());
}
DictionaryService dd = Repository.getServiceRegistry(FacesContext.getCurrentInstance()).getDictionaryService();
if (dd.isSubClass(selectedNode.getType(), ContentModel.TYPE_FOLDER)) {
// 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(selectedNode.getNodeRef());
} else if (dd.isSubClass(selectedNode.getType(), ContentModel.TYPE_CONTENT)) {
// view details for document
this.browseBean.setupContentAction(selectedNode.getId(), true);
FacesContext fc = FacesContext.getCurrentInstance();
fc.getApplication().getNavigationHandler().handleNavigation(fc, null, "dialog:showDocDetails");
}
} else {
Utils.addErrorMessage(Application.getMessage(FacesContext.getCurrentInstance(), "error_shortcut_permissions"));
}
} catch (InvalidNodeRefException refErr) {
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_NODEREF), new Object[] { selectedNode.getId() }));
// remove item from the shortcut list
UserTransaction tx = null;
try {
FacesContext context = FacesContext.getCurrentInstance();
tx = Repository.getUserTransaction(context);
tx.begin();
List<String> shortcuts = getShortcutList(context);
if (shortcuts.size() > shortcutEvent.Index) {
// remove the shortcut from the saved list and persist back
shortcuts.remove(shortcutEvent.Index);
PreferencesService.getPreferences(context).setValue(PREF_SHORTCUTS, (Serializable) shortcuts);
// commit the transaction
tx.commit();
// remove shortcut Node from the in-memory list
Node node = getShortcuts().remove(shortcutEvent.Index);
if (logger.isDebugEnabled())
logger.debug("Removed deleted node: " + node.getName() + " from the user shortcuts list.");
}
} catch (Throwable err) {
try {
if (tx != null) {
tx.rollback();
}
} catch (Exception tex) {
}
}
}
}
use of org.alfresco.service.cmr.repository.InvalidNodeRefException in project acs-community-packaging by Alfresco.
the class DeleteUserDialog method search.
public String search() {
if (this.searchCriteria == null || this.searchCriteria.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 = ISO9075.encode(this.searchCriteria);
List<Pair<QName, String>> filter = Utils.generatePersonFilter(search);
if (logger.isDebugEnabled()) {
logger.debug("Query filter: " + filter);
}
List<PersonInfo> persons = getPersonService().getPeople(filter, 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();
props.put("fullName", ((String) props.get("firstName")) + ' ' + ((String) props.get("lastName")));
NodeRef homeFolderNodeRef = (NodeRef) props.get("homeFolder");
if (homeFolderNodeRef != null) {
props.put("homeSpace", homeFolderNodeRef);
}
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 Repository method getUsers.
/**
* Query a list of Person type nodes from the repo
* It is currently assumed that all Person nodes exist below the Repository root node
*
* @param context Faces Context
* @param nodeService The node service
* @param personService PersonService
* @return List of Person node objects
*/
public static List<Node> getUsers(FacesContext context, NodeService nodeService, PersonService personService) {
List<Node> personNodes = null;
UserTransaction tx = null;
try {
tx = Repository.getUserTransaction(context, true);
tx.begin();
NodeRef peopleRef = personService.getPeopleContainer();
// TODO: better to perform an XPath search or a get for a specific child type here?
List<ChildAssociationRef> childRefs = nodeService.getChildAssocs(peopleRef);
personNodes = new ArrayList<Node>(childRefs.size());
for (ChildAssociationRef ref : childRefs) {
// create our Node representation from the NodeRef
NodeRef nodeRef = ref.getChildRef();
if (nodeService.getType(nodeRef).equals(ContentModel.TYPE_PERSON)) {
// 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 : ""));
NodeRef homeFolderNodeRef = (NodeRef) props.get("homeFolder");
if (homeFolderNodeRef != null) {
props.put("homeSpace", homeFolderNodeRef);
}
personNodes.add(node);
}
}
// commit the transaction
tx.commit();
} catch (InvalidNodeRefException refErr) {
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(context, Repository.ERROR_NODEREF), new Object[] { "root" }));
personNodes = Collections.<Node>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.<Node>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 EditContentPropertiesDialog method formatErrorMessage.
/**
* Formats the error message to display if an error occurs during finish processing
*
* @param exception The exception
* @return The formatted message
*/
@Override
protected String formatErrorMessage(Throwable exception) {
if (editableNode != null) {
// special case for Mimetype - since this is a sub-property of the ContentData object
// we must extract it so it can be edited in the client, then we check for it later
// and create a new ContentData object to wrap it and it's associated URL
ContentData content = (ContentData) this.editableNode.getProperties().get(ContentModel.PROP_CONTENT);
if (content != null) {
this.editableNode.getProperties().put(TEMP_PROP_MIMETYPE, content.getMimetype());
this.editableNode.getProperties().put(TEMP_PROP_ENCODING, content.getEncoding());
}
}
if (exception instanceof FileExistsException) {
return MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_EXISTS), ((FileExistsException) exception).getName());
} else if (exception instanceof InvalidNodeRefException) {
return MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_NODEREF), new Object[] { this.browseBean.getDocument().getId() });
} else {
return super.formatErrorMessage(exception);
}
}
use of org.alfresco.service.cmr.repository.InvalidNodeRefException in project acs-community-packaging by Alfresco.
the class VersionedDocumentDetailsDialog method setBrowsingVersion.
/**
* Implementation of setBrowsingVersion action event to be use with the needed parameters.
*/
private void setBrowsingVersion(String id, String versionLabel, String lang) {
// test if the mandatories parameter are valid
ParameterCheck.mandatoryString("The id of the node", id);
ParameterCheck.mandatoryString("The version of the node", versionLabel);
try {
// try to get the nodeRef with the given ID. This node is not a versioned node.
NodeRef currentNodeRef = new NodeRef(Repository.getStoreRef(), id);
// the threatment is different if the node is a translation or a mlContainer
if (getNodeService().getType(currentNodeRef).equals(ContentModel.TYPE_MULTILINGUAL_CONTAINER)) {
// test if the lang parameter is valid
ParameterCheck.mandatoryString("The lang of the node", lang);
fromPreviousEditon = true;
versionLabel = cleanVersionLabel(versionLabel);
// set the edition information of the mlContainer of the selected translation version
this.editionHistory = getEditionService().getEditions(currentNodeRef);
this.documentEdition = editionHistory.getVersion(versionLabel);
// set the version to display
this.documentVersion = getBrowsingVersionForMLContainer(currentNodeRef, versionLabel, lang);
} else {
fromPreviousEditon = false;
// set the version history
this.versionHistory = getVersionService().getVersionHistory(currentNodeRef);
// set the version to display
this.documentVersion = getBrowsingVersionForDocument(currentNodeRef, versionLabel);
}
} catch (InvalidNodeRefException refErr) {
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_NODEREF), new Object[] { id }));
}
}
Aggregations