use of org.alfresco.error.AlfrescoRuntimeException in project alfresco-remote-api by Alfresco.
the class SitesImpl method removeSiteMember.
public void removeSiteMember(String personId, String siteId) {
personId = people.validatePerson(personId);
SiteInfo siteInfo = validateSite(siteId);
if (siteInfo == null) {
// site does not exist
throw new RelationshipResourceNotFoundException(personId, siteId);
}
// set the site id to the short name (to deal with case sensitivity issues with using the siteId from the url)
siteId = siteInfo.getShortName();
boolean isMember = siteService.isMember(siteId, personId);
if (!isMember) {
throw new InvalidArgumentException();
}
String role = siteService.getMembersRole(siteId, personId);
if (role != null) {
if (role.equals(SiteModel.SITE_MANAGER)) {
int numAuthorities = siteService.countAuthoritiesWithRole(siteId, SiteModel.SITE_MANAGER);
if (numAuthorities <= 1) {
throw new InvalidArgumentException("Can't remove last manager of site " + siteId);
}
siteService.removeMembership(siteId, personId);
} else {
siteService.removeMembership(siteId, personId);
}
} else {
throw new AlfrescoRuntimeException("Unable to determine role of site member");
}
}
use of org.alfresco.error.AlfrescoRuntimeException in project alfresco-remote-api by Alfresco.
the class AbstractRuleWebScript method convertValue.
private Serializable convertValue(QName typeQName, Object propertyValue) throws JSONException {
Serializable value = null;
DataTypeDefinition typeDef = dictionaryService.getDataType(typeQName);
if (typeDef == null) {
throw new AlfrescoRuntimeException("Action property type definition " + typeQName.toPrefixString() + " is unknown.");
}
if (propertyValue instanceof JSONArray) {
// Convert property type to java class
Class<?> javaClass = null;
String javaClassName = typeDef.getJavaClassName();
try {
javaClass = Class.forName(javaClassName);
} catch (ClassNotFoundException e) {
throw new DictionaryException("Java class " + javaClassName + " of property type " + typeDef.getName() + " is invalid", e);
}
int length = ((JSONArray) propertyValue).length();
List<Serializable> list = new ArrayList<Serializable>(length);
for (int i = 0; i < length; i++) {
list.add(convertValue(typeQName, ((JSONArray) propertyValue).get(i)));
}
value = (Serializable) list;
} else {
if (typeQName.equals(DataTypeDefinition.QNAME) == true && typeQName.toString().contains(":") == true) {
value = QName.createQName(propertyValue.toString(), namespaceService);
} else {
value = (Serializable) DefaultTypeConverter.INSTANCE.convert(dictionaryService.getDataType(typeQName), propertyValue);
}
}
return value;
}
use of org.alfresco.error.AlfrescoRuntimeException in project acs-community-packaging by Alfresco.
the class UserProfileDialogCommand method execute.
/**
* @see org.alfresco.web.app.servlet.command.Command#execute(org.alfresco.service.ServiceRegistry, java.util.Map)
*/
public Object execute(ServiceRegistry serviceRegistry, Map<String, Object> properties) {
ServletContext sc = (ServletContext) properties.get(PROP_SERVLETCONTEXT);
ServletRequest req = (ServletRequest) properties.get(PROP_REQUEST);
ServletResponse res = (ServletResponse) properties.get(PROP_RESPONSE);
FacesContext fc = FacesHelper.getFacesContext(req, res, sc, "/jsp/close.jsp");
UsersDialog dialog = (UsersDialog) FacesHelper.getManagedBean(fc, UsersDialog.BEAN_NAME);
// setup dialog context from url args in properties map
String personId = (String) properties.get(PROP_PERSONID);
ParameterCheck.mandatoryString(PROP_PERSONID, personId);
dialog.setupUserAction(personId);
NavigationHandler navigationHandler = fc.getApplication().getNavigationHandler();
navigationHandler.handleNavigation(fc, null, "dialog:userProfile");
String viewId = fc.getViewRoot().getViewId();
try {
sc.getRequestDispatcher(BaseServlet.FACES_SERVLET + viewId).forward(req, res);
} catch (Exception e) {
throw new AlfrescoRuntimeException("Unable to forward to viewId: " + viewId, e);
}
return null;
}
use of org.alfresco.error.AlfrescoRuntimeException in project acs-community-packaging by Alfresco.
the class BaseDetailsBean method reject.
/**
* Event handler called to handle the approve step of the simple workflow
*
* @param event The event that was triggered
*/
public void reject(ActionEvent event) {
UIActionLink link = (UIActionLink) event.getComponent();
Map<String, String> params = link.getParameterMap();
String id = params.get("id");
if (id == null || id.length() == 0) {
throw new AlfrescoRuntimeException("reject called without an id");
}
final NodeRef docNodeRef = new NodeRef(Repository.getStoreRef(), id);
try {
RetryingTransactionHelper txnHelper = Repository.getRetryingTransactionHelper(FacesContext.getCurrentInstance());
RetryingTransactionCallback<Object> callback = new RetryingTransactionCallback<Object>() {
public Object execute() throws Throwable {
// call the service to perform the reject
WorkflowUtil.reject(docNodeRef, getNodeService(), getCopyService());
return null;
}
};
txnHelper.doInTransaction(callback);
// if this was called via the node details dialog we need to reset the node
if (getNode() != null) {
getNode().reset();
}
// also make sure the UI will get refreshed
UIContextService.getInstance(FacesContext.getCurrentInstance()).notifyBeans();
} catch (Throwable e) {
// rollback the transaction
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), MSG_ERROR_WORKFLOW_REJECT), e.getMessage()), e);
ReportedException.throwIfNecessary(e);
}
}
use of org.alfresco.error.AlfrescoRuntimeException in project acs-community-packaging by Alfresco.
the class AdminNodeBrowseBean method submitSearch.
/**
* Action to submit search
*
* @return next action
*/
public String submitSearch() {
long start = System.currentTimeMillis();
RetryingTransactionCallback<String> searchCallback = new RetryingTransactionCallback<String>() {
public String execute() throws Throwable {
if (queryLanguage.equals("noderef")) {
// ensure node exists
NodeRef nodeRef = new NodeRef(query);
boolean exists = getNodeService().exists(nodeRef);
if (!exists) {
throw new AlfrescoRuntimeException("Node " + nodeRef + " does not exist.");
}
setNodeRef(nodeRef);
return "node";
} else if (queryLanguage.equals("selectnodes")) {
List<NodeRef> nodes = getSearchService().selectNodes(getNodeRef(), query, null, getNamespaceService(), false);
searchResults = new SearchResults(nodes);
return "search";
}
// perform search
searchResults = new SearchResults(getSearchService().query(getNodeRef().getStoreRef(), queryLanguage, query));
return "search";
}
};
try {
String result = getTransactionService().getRetryingTransactionHelper().doInTransaction(searchCallback, true);
this.searchElapsedTime = System.currentTimeMillis() - start;
return result;
} catch (Throwable e) {
FacesContext context = FacesContext.getCurrentInstance();
FacesMessage message = new FacesMessage();
message.setSeverity(FacesMessage.SEVERITY_ERROR);
message.setDetail("Search failed due to: " + e.toString());
context.addMessage("searchForm:query", message);
return "error";
}
}
Aggregations