use of javax.transaction.UserTransaction in project acs-community-packaging by Alfresco.
the class SpaceDetailsDialog method applyClassifiable.
/**
* Applies the classifiable aspect to the current document
*/
public void applyClassifiable() {
UserTransaction tx = null;
try {
tx = Repository.getUserTransaction(FacesContext.getCurrentInstance());
tx.begin();
// add the general classifiable aspect to the node
getNodeService().addAspect(getSpace().getNodeRef(), ContentModel.ASPECT_GEN_CLASSIFIABLE, null);
// commit the transaction
tx.commit();
// reset the state of the current document
getSpace().reset();
} catch (Throwable e) {
// rollback the transaction
try {
if (tx != null) {
tx.rollback();
}
} catch (Exception ex) {
}
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), MSG_ERROR_ASPECT_CLASSIFY), e.getMessage()), e);
}
}
use of javax.transaction.UserTransaction in project acs-community-packaging by Alfresco.
the class RulesDialog method reapplyRules.
/**
* Reapply the currently defines rules to the
* @param event ActionEvent
*/
public void reapplyRules(ActionEvent event) {
boolean toChildren = false;
UIActionLink link = (UIActionLink) event.getComponent();
Map<String, String> params = link.getParameterMap();
String toChildrenStr = params.get("toChildren");
if (toChildrenStr != null) {
toChildren = new Boolean(toChildrenStr).booleanValue();
}
FacesContext fc = FacesContext.getCurrentInstance();
UserTransaction tx = null;
try {
tx = Repository.getUserTransaction(fc);
tx.begin();
// Set the include inherited parameter to match the current filter value
boolean executeInherited = true;
if (this.filterModeMode.equals(LOCAL)) {
executeInherited = false;
}
// Reapply the rules
reapplyRules(this.getSpace().getNodeRef(), executeInherited, toChildren);
// TODO how do I get the message here ...
String msg = Application.getMessage(fc, MSG_REAPPLY_RULES_SUCCESS);
FacesMessage facesMsg = new FacesMessage(FacesMessage.SEVERITY_INFO, msg, msg);
String formId = Utils.getParentForm(fc, event.getComponent()).getClientId(fc);
fc.addMessage(formId + ":rulesList", facesMsg);
// commit the transaction
tx.commit();
} catch (Throwable e) {
// rollback the transaction
try {
if (tx != null) {
tx.rollback();
}
} catch (Exception ex) {
}
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(fc, Repository.ERROR_GENERIC), e.getMessage()), e);
}
}
use of javax.transaction.UserTransaction in project acs-community-packaging by Alfresco.
the class UserMembersBean method finishOK.
/**
* Action handler called when the Finish button is clicked on the Edit User Roles page
*/
public String finishOK() {
String outcome = OUTCOME_FINISH;
FacesContext context = FacesContext.getCurrentInstance();
// persist new user permissions
if (this.personRoles != null && getPersonAuthority() != null) {
UserTransaction tx = null;
try {
tx = Repository.getUserTransaction(context);
tx.begin();
// clear the currently set permissions for this user
// and add each of the new permissions in turn
final NodeRef nodeRef = getNode().getNodeRef();
if (this.getPermissionService().hasPermission(nodeRef, PermissionService.CHANGE_PERMISSIONS) == AccessStatus.ALLOWED) {
AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<Object>() {
public Object doWork() throws Exception {
getPermissionService().clearPermission(nodeRef, getPersonAuthority());
for (PermissionWrapper wrapper : personRoles) {
getPermissionService().setPermission(nodeRef, getPersonAuthority(), wrapper.getPermission(), true);
}
return null;
}
}, AuthenticationUtil.getSystemUserName());
}
tx.commit();
} catch (Exception err) {
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(context, Repository.ERROR_GENERIC), err.getMessage()), err);
try {
if (tx != null) {
tx.rollback();
}
} catch (Exception tex) {
}
outcome = null;
}
}
return outcome;
}
use of javax.transaction.UserTransaction in project acs-community-packaging by Alfresco.
the class UserShortcutsBean method createShortcut.
// ------------------------------------------------------------------------------
// Action method handlers
/**
* Action handler called when a new shortcut is to be added to the list
*/
public void createShortcut(ActionEvent event) {
// TODO: add this action to the Details screen for Space and Document
UIActionLink link = (UIActionLink) event.getComponent();
Map<String, String> params = link.getParameterMap();
String id = params.get("id");
if (id != null && id.length() != 0) {
try {
NodeRef ref = new NodeRef(Repository.getStoreRef(), id);
Node node = new Node(ref);
boolean foundShortcut = false;
for (int i = 0; i < getShortcuts().size(); i++) {
if (node.getId().equals(getShortcuts().get(i).getId())) {
// found same node already in the list - so we don't need to add it again
foundShortcut = true;
break;
}
}
if (foundShortcut == false) {
// add to persistent store
UserTransaction tx = null;
try {
FacesContext context = FacesContext.getCurrentInstance();
tx = Repository.getUserTransaction(context);
tx.begin();
List<String> shortcuts = getShortcutList(context);
shortcuts.add(node.getNodeRef().getId());
PreferencesService.getPreferences(context).setValue(PREF_SHORTCUTS, (Serializable) shortcuts);
// commit the transaction
tx.commit();
// add our new shortcut Node to the in-memory list
getShortcuts().add(node);
if (logger.isDebugEnabled())
logger.debug("Added node: " + node.getName() + " to the user shortcuts list.");
} catch (Throwable err) {
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_GENERIC), err.getMessage()), err);
try {
if (tx != null) {
tx.rollback();
}
} catch (Exception tex) {
}
}
}
} catch (InvalidNodeRefException refErr) {
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_NODEREF), new Object[] { id }));
}
}
}
use of javax.transaction.UserTransaction in project acs-community-packaging by Alfresco.
the class UserShortcutsBean method getShortcuts.
/**
* @return the List of shortcut Nodes
*/
public List<Node> getShortcuts() {
if (this.shortcuts == null) {
List<String> shortcuts = null;
NodeRef prefRef = null;
UserTransaction tx = null;
boolean rollback = false;
try {
FacesContext context = FacesContext.getCurrentInstance();
tx = Repository.getUserTransaction(context);
tx.begin();
// get the shortcuts from the preferences for this user
shortcuts = getShortcutList(context);
if (shortcuts.size() != 0) {
// each shortcut node ID is persisted as a list item in a well known property
this.shortcuts = new ArrayList<Node>(shortcuts.size());
for (int i = 0; i < shortcuts.size(); i++) {
NodeRef ref = new NodeRef(Repository.getStoreRef(), shortcuts.get(i));
try {
if (this.getNodeService().exists(ref) == true) {
Node node = new Node(ref);
// quick init properties while in the usertransaction
node.getProperties();
// save ref to the Node for rendering
this.shortcuts.add(node);
} else {
// we write the node list back again afterwards to correct this
if (logger.isDebugEnabled())
logger.debug("Found invalid shortcut node Id: " + ref.getId());
}
} catch (AccessDeniedException accessErr) {
// we write the node list back again afterwards to correct this
if (logger.isDebugEnabled())
logger.debug("Found invalid shortcut node Id: " + ref.getId());
rollback = true;
}
}
} else {
this.shortcuts = new ArrayList<Node>(5);
}
if (rollback == false) {
tx.commit();
} else {
tx.rollback();
}
} catch (Throwable err) {
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_GENERIC), err.getMessage()), err);
try {
if (tx != null) {
tx.rollback();
}
} catch (Exception tex) {
}
}
// write the valid shortcut IDs back to correct invalid node refs
if (shortcuts != null && shortcuts.size() != this.shortcuts.size()) {
try {
shortcuts = new ArrayList<String>(this.shortcuts.size());
for (int i = 0; i < this.shortcuts.size(); i++) {
shortcuts.add(this.shortcuts.get(i).getId());
}
PreferencesService.getPreferences().setValue(PREF_SHORTCUTS, (Serializable) shortcuts);
} catch (Exception err) {
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_GENERIC), err.getMessage()), err);
}
}
}
return this.shortcuts;
}
Aggregations