use of org.alfresco.service.cmr.repository.InvalidNodeRefException in project acs-community-packaging by Alfresco.
the class LinkPropertiesDialog method finishImpl.
@Override
protected String finishImpl(FacesContext context, String outcome) throws Exception {
try {
NodeRef nodeRef = getEditableNode().getNodeRef();
Map<String, Object> props = getEditableNode().getProperties();
// get the name and move the node as necessary
String name = (String) props.get(ContentModel.PROP_NAME);
if (name != null) {
getFileFolderService().rename(nodeRef, name);
}
Map<QName, Serializable> properties = this.getNodeService().getProperties(nodeRef);
// we need to put all the properties from the editable bag back into
// the format expected by the repository
// deal with adding the "titled" aspect if required
String title = (String) props.get(ContentModel.PROP_TITLE);
String description = (String) props.get(ContentModel.PROP_DESCRIPTION);
if (title != null || description != null) {
// add the aspect to be sure it's present
getNodeService().addAspect(nodeRef, ContentModel.ASPECT_TITLED, null);
// other props will get added later in setProperties()
}
// add the remaining properties
Iterator<String> iterProps = props.keySet().iterator();
while (iterProps.hasNext()) {
String propName = iterProps.next();
QName qname = QName.createQName(propName);
// make sure the property is represented correctly
Serializable propValue = (Serializable) props.get(propName);
// check for empty strings when using number types, set to null in this case
if ((propValue != null) && (propValue instanceof String) && (propValue.toString().length() == 0)) {
PropertyDefinition propDef = this.getDictionaryService().getProperty(qname);
if (propDef != null) {
if (propDef.getDataType().getName().equals(DataTypeDefinition.DOUBLE) || propDef.getDataType().getName().equals(DataTypeDefinition.FLOAT) || propDef.getDataType().getName().equals(DataTypeDefinition.INT) || propDef.getDataType().getName().equals(DataTypeDefinition.LONG)) {
propValue = null;
}
}
}
properties.put(qname, propValue);
}
// send the properties back to the repository
this.getNodeService().setProperties(nodeRef, properties);
} catch (InvalidNodeRefException err) {
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(context, Repository.ERROR_NODEREF), new Object[] { this.browseBean.getDocument().getId() }));
// this failure means the node no longer exists - we cannot show the doc properties screen
outcome = AlfrescoNavigationHandler.CLOSE_DIALOG_OUTCOME + AlfrescoNavigationHandler.OUTCOME_SEPARATOR + "browse";
} catch (Throwable e) {
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(context, Repository.ERROR_GENERIC), e.getMessage()), e);
outcome = null;
ReportedException.throwIfNecessary(e);
}
return outcome;
}
use of org.alfresco.service.cmr.repository.InvalidNodeRefException in project acs-community-packaging by Alfresco.
the class LoginBean method login.
// ------------------------------------------------------------------------------
// Action event methods
/**
* Login action handler
*
* @return outcome view name
*/
public String login() {
String outcome = null;
FacesContext fc = FacesContext.getCurrentInstance();
if (this.username != null && this.username.length() != 0 && this.password != null && this.password.length() != 0) {
try {
// Perform a full session invalidation to ensure no cached data is left around
// - important if the login page has been accessed directly rather than via the Login/out action links
logout();
// Authenticate via the authentication service, then save the details of user in an object
// in the session - this is used by the servlet filter etc. on each page to check for login
this.getAuthenticationService().authenticate(this.username, this.password.toCharArray());
// Set the user name as stored by the back end
this.username = this.getAuthenticationService().getCurrentUserName();
// setup User object and Home space ID
User user = new User(this.username, this.getAuthenticationService().getCurrentTicket(), getPersonService().getPerson(this.username));
NodeRef homeSpaceRef = (NodeRef) this.getNodeService().getProperty(getPersonService().getPerson(this.username), ContentModel.PROP_HOMEFOLDER);
// check that the home space node exists - else user cannot login
if (homeSpaceRef == null || this.getNodeService().exists(homeSpaceRef) == false) {
throw new InvalidNodeRefException(homeSpaceRef);
}
user.setHomeSpaceId(homeSpaceRef.getId());
// put the User object in the Session - the authentication servlet will then allow
// the app to continue without redirecting to the login page
Application.setCurrentUser(fc, user);
// Save the current username to cookie
AuthenticationHelper.setUsernameCookie((HttpServletRequest) fc.getExternalContext().getRequest(), (HttpServletResponse) fc.getExternalContext().getResponse(), this.username);
// Programatically retrieve the LoginOutcomeBean from JSF
LoginOutcomeBean loginOutcomeBean = (LoginOutcomeBean) fc.getApplication().createValueBinding("#{LoginOutcomeBean}").getValue(fc);
// if a redirect URL has been provided then use that
// this allows servlets etc. to provide a URL to return too after a successful login
String redirectURL = loginOutcomeBean.getRedirectURL();
// ALF-10312: Validate we are redirecting within this web app
if (redirectURL != null && !redirectURL.isEmpty() && !redirectURL.startsWith(fc.getExternalContext().getRequestContextPath())) {
if (logger.isWarnEnabled())
logger.warn("Security violation. Unable to redirect to external location: " + redirectURL);
redirectURL = null;
}
if (redirectURL != null && redirectURL.length() > 0) {
if (logger.isDebugEnabled())
logger.debug("Redirect URL found: " + redirectURL);
try {
fc.getExternalContext().redirect(redirectURL);
fc.responseComplete();
return null;
} catch (IOException ioErr) {
logger.warn("Unable to redirect to url: " + redirectURL, ioErr);
}
} else {
// special case to handle jump to My Alfresco page initially
// note: to enable MT runtime client config customization, need to re-init NavigationBean
// in context of tenant login page
this.navigator.initFromClientConfig();
if (NavigationBean.LOCATION_MYALFRESCO.equals(this.preferences.getStartLocation())) {
return "myalfresco";
} else {
// generally this will navigate to the generic browse screen
return "success";
}
}
} catch (AuthenticationDisallowedException aerr) {
Utils.addErrorMessage(Application.getMessage(fc, MSG_ERROR_LOGIN_DISALLOWED));
} catch (AuthenticationMaxUsersException aerr) {
Utils.addErrorMessage(Application.getMessage(fc, MSG_ERROR_LOGIN_MAXUSERS));
} catch (AuthenticationException aerr) {
Utils.addErrorMessage(Application.getMessage(fc, MSG_ERROR_UNKNOWN_USER));
} catch (InvalidNodeRefException refErr) {
String msg;
if (refErr.getNodeRef() != null) {
msg = refErr.getNodeRef().toString();
} else {
msg = Application.getMessage(fc, MSG_NONE);
}
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(fc, Repository.ERROR_NOHOME), msg));
}
} else {
Utils.addErrorMessage(Application.getMessage(fc, MSG_ERROR_MISSING));
}
return outcome;
}
use of org.alfresco.service.cmr.repository.InvalidNodeRefException in project acs-community-packaging by Alfresco.
the class NavigationBean method toolbarLocationChanged.
/**
* Action to change the toolbar location
* Currently this will changed the location from Company to the users Home space
*/
public void toolbarLocationChanged(ActionEvent event) {
FacesContext context = FacesContext.getCurrentInstance();
try {
UIModeList locationList = (UIModeList) event.getComponent();
String location = locationList.getValue().toString();
processToolbarLocation(location, true);
} 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);
}
}
use of org.alfresco.service.cmr.repository.InvalidNodeRefException in project acs-community-packaging by Alfresco.
the class NavigationBean method getGuestHomeNode.
/**
* @return Node representing the Guest Home Space folder
*/
public Node getGuestHomeNode() {
if (this.guestHomeNode == null) {
try {
FacesContext fc = FacesContext.getCurrentInstance();
String xpath = Application.getRootPath(fc) + "/" + Application.getGuestHomeFolderName(fc);
List<NodeRef> guestHomeRefs = this.getSearchService().selectNodes(this.getNodeService().getRootNode(Repository.getStoreRef()), xpath, null, this.getNamespaceService(), false);
if (guestHomeRefs.size() == 1) {
this.guestHomeNode = new Node(guestHomeRefs.get(0));
}
} catch (InvalidNodeRefException err1) {
// cannot continue if this occurs
} catch (AccessDeniedException err2) {
// cannot see node if this occurs
}
}
return this.guestHomeNode;
}
use of org.alfresco.service.cmr.repository.InvalidNodeRefException in project acs-community-packaging by Alfresco.
the class UINavigator method broadcast.
/**
* @see javax.faces.component.UIInput#broadcast(javax.faces.event.FacesEvent)
*/
public void broadcast(FacesEvent event) throws AbortProcessingException {
if (event instanceof NavigatorEvent) {
FacesContext context = FacesContext.getCurrentInstance();
NavigatorEvent navEvent = (NavigatorEvent) event;
// node or panel selected?
switch(navEvent.getMode()) {
case PANEL_SELECTED:
{
String panelSelected = navEvent.getItem();
// a panel was selected, setup the context to make the panel
// the focus
NavigationBean nb = (NavigationBean) FacesHelper.getManagedBean(context, NavigationBean.BEAN_NAME);
if (nb != null) {
try {
if (logger.isDebugEnabled())
logger.debug("Selecting panel: " + panelSelected);
nb.processToolbarLocation(panelSelected, true);
} 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);
}
}
break;
}
case NODE_SELECTED:
{
// a node was clicked in the tree
boolean nodeExists = true;
NodeRef nodeClicked = new NodeRef(navEvent.getItem());
// make sure the node exists still before navigating to it
UserTransaction tx = null;
try {
tx = Repository.getUserTransaction(context, true);
tx.begin();
NodeService nodeSvc = Repository.getServiceRegistry(context).getNodeService();
nodeExists = nodeSvc.exists(nodeClicked);
tx.commit();
} catch (Throwable err) {
try {
if (tx != null) {
tx.rollback();
}
} catch (Exception tex) {
}
}
if (nodeExists) {
// setup the context to make the node the current node
BrowseBean bb = (BrowseBean) FacesHelper.getManagedBean(context, BrowseBean.BEAN_NAME);
if (bb != null) {
if (logger.isDebugEnabled())
logger.debug("Selected node: " + nodeClicked);
bb.clickSpace(nodeClicked);
}
} else {
String msg = Application.getMessage(context, "navigator_node_deleted");
Utils.addErrorMessage(msg);
}
break;
}
}
} else {
super.broadcast(event);
}
}
Aggregations