Search in sources :

Example 16 with AlfrescoRuntimeException

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");
    }
}
Also used : RelationshipResourceNotFoundException(org.alfresco.rest.framework.core.exceptions.RelationshipResourceNotFoundException) SiteInfo(org.alfresco.service.cmr.site.SiteInfo) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) FilterPropString(org.alfresco.repo.node.getchildren.FilterPropString)

Example 17 with AlfrescoRuntimeException

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;
}
Also used : Serializable(java.io.Serializable) JSONArray(org.json.JSONArray) ArrayList(java.util.ArrayList) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) DataTypeDefinition(org.alfresco.service.cmr.dictionary.DataTypeDefinition) DictionaryException(org.alfresco.service.cmr.dictionary.DictionaryException)

Example 18 with AlfrescoRuntimeException

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;
}
Also used : ServletRequest(javax.servlet.ServletRequest) ServletResponse(javax.servlet.ServletResponse) FacesContext(javax.faces.context.FacesContext) ServletContext(javax.servlet.ServletContext) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) NavigationHandler(javax.faces.application.NavigationHandler) UsersDialog(org.alfresco.web.bean.users.UsersDialog) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException)

Example 19 with AlfrescoRuntimeException

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);
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback) UIActionLink(org.alfresco.web.ui.common.component.UIActionLink) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException)

Example 20 with AlfrescoRuntimeException

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";
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) FacesContext(javax.faces.context.FacesContext) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) ArrayList(java.util.ArrayList) List(java.util.List) FacesMessage(javax.faces.application.FacesMessage)

Aggregations

AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)197 NodeRef (org.alfresco.service.cmr.repository.NodeRef)79 QName (org.alfresco.service.namespace.QName)39 HashMap (java.util.HashMap)38 IOException (java.io.IOException)32 ArrayList (java.util.ArrayList)31 JSONException (org.json.JSONException)23 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)22 Serializable (java.io.Serializable)20 M2Model (org.alfresco.repo.dictionary.M2Model)18 JSONObject (org.json.JSONObject)15 Date (java.util.Date)14 Map (java.util.Map)12 FacesContext (javax.faces.context.FacesContext)12 InputStream (java.io.InputStream)10 RetryingTransactionCallback (org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback)10 SiteInfo (org.alfresco.service.cmr.site.SiteInfo)10 JSONArray (org.json.JSONArray)10 List (java.util.List)8 FileNotFoundException (org.alfresco.service.cmr.model.FileNotFoundException)8