Search in sources :

Example 11 with ServiceRegistry

use of org.alfresco.service.ServiceRegistry in project acs-community-packaging by Alfresco.

the class EditUserDetailsDialog method finishImpl.

@Override
protected String finishImpl(FacesContext context, String outcome) throws Exception {
    try {
        ServiceRegistry services = Repository.getServiceRegistry(FacesContext.getCurrentInstance());
        DictionaryService dd = services.getDictionaryService();
        Map<QName, Serializable> props = getNodeService().getProperties(getPerson().getNodeRef());
        for (String key : getPerson().getProperties().keySet()) {
            QName propQName = QName.createQName(key);
            if (dd.getProperty(propQName) == null || dd.getProperty(propQName).isProtected() == false) {
                props.put(propQName, (Serializable) getPerson().getProperties().get(key));
            }
        }
        // persist all property changes
        NodeRef personRef = getPerson().getNodeRef();
        this.getNodeService().setProperties(personRef, props);
        // save person description content field
        if (this.personDescription != null) {
            ContentService cs = services.getContentService();
            ContentWriter writer = cs.getWriter(personRef, ContentModel.PROP_PERSONDESC, true);
            writer.setMimetype(MimetypeMap.MIMETYPE_HTML);
            writer.putContent(this.personDescription);
        }
        // setup user avatar association
        if (this.photoRef != null) {
            List<AssociationRef> refs = this.getNodeService().getTargetAssocs(personRef, ContentModel.ASSOC_AVATAR);
            // remove old association if it exists
            if (refs.size() == 1) {
                NodeRef existingRef = refs.get(0).getTargetRef();
                this.getNodeService().removeAssociation(personRef, existingRef, ContentModel.ASSOC_AVATAR);
            }
            // setup new association
            this.getNodeService().createAssociation(personRef, this.photoRef, ContentModel.ASSOC_AVATAR);
        }
        // if the above calls were successful, then reset Person Node in the session
        Application.getCurrentUser(context).reset();
    } catch (Throwable err) {
        Utils.addErrorMessage(MessageFormat.format(Application.getMessage(context, Repository.ERROR_GENERIC), err.getMessage()), err);
        outcome = null;
        ReportedException.throwIfNecessary(err);
    }
    return outcome;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) DictionaryService(org.alfresco.service.cmr.dictionary.DictionaryService) Serializable(java.io.Serializable) ContentWriter(org.alfresco.service.cmr.repository.ContentWriter) QName(org.alfresco.service.namespace.QName) ServiceRegistry(org.alfresco.service.ServiceRegistry) ContentService(org.alfresco.service.cmr.repository.ContentService) AssociationRef(org.alfresco.service.cmr.repository.AssociationRef)

Example 12 with ServiceRegistry

use of org.alfresco.service.ServiceRegistry in project acs-community-packaging by Alfresco.

the class DocumentPropertiesDialog method getContentTypes.

/**
 * @return Returns a list of content types to allow the user to select from
 */
public List<SelectItem> getContentTypes() {
    if (this.contentTypes == null) {
        this.contentTypes = new ArrayList<SelectItem>(80);
        ServiceRegistry registry = Repository.getServiceRegistry(FacesContext.getCurrentInstance());
        MimetypeService mimetypeService = registry.getMimetypeService();
        // get the mime type display names
        Map<String, String> mimeTypes = mimetypeService.getDisplaysByMimetype();
        for (String mimeType : mimeTypes.keySet()) {
            this.contentTypes.add(new SelectItem(mimeType, mimeTypes.get(mimeType)));
        }
        // make sure the list is sorted by the values
        QuickSort sorter = new QuickSort(this.contentTypes, "label", true, IDataContainer.SORT_CASEINSENSITIVE);
        sorter.sort();
    }
    return this.contentTypes;
}
Also used : QuickSort(org.alfresco.web.data.QuickSort) SelectItem(javax.faces.model.SelectItem) MimetypeService(org.alfresco.service.cmr.repository.MimetypeService) ServiceRegistry(org.alfresco.service.ServiceRegistry)

Example 13 with ServiceRegistry

use of org.alfresco.service.ServiceRegistry in project acs-community-packaging by Alfresco.

the class WorkflowUtil method isTaskEditable.

public static boolean isTaskEditable(String taskId, ServletContext sc) {
    if (taskId == null || taskId.isEmpty()) {
        return false;
    }
    ServiceRegistry serviceRegistry = Repository.getServiceRegistry(sc);
    String username = serviceRegistry.getAuthenticationService().getCurrentUserName();
    WorkflowService workflowService = serviceRegistry.getWorkflowService();
    WorkflowTask task = workflowService.getTaskById(taskId);
    return workflowService.isTaskEditable(task, username);
}
Also used : WorkflowService(org.alfresco.service.cmr.workflow.WorkflowService) WorkflowTask(org.alfresco.service.cmr.workflow.WorkflowTask) ServiceRegistry(org.alfresco.service.ServiceRegistry)

Example 14 with ServiceRegistry

use of org.alfresco.service.ServiceRegistry in project acs-community-packaging by Alfresco.

the class BaseServlet method checkAccess.

/**
 * Check the user has the given permission on the given node. If they do not either force a log on if this is a guest
 * user or forward to an error page.
 *
 * @param req
 *           the request
 * @param res
 *           the response
 * @param nodeRef
 *           the node in question
 * @param allowLogIn
 *           Indicates whether guest users without access to the node should be redirected to the log in page. If
 *           <code>false</code>, a status 403 forbidden page is displayed instead.
 * @return <code>true</code>, if the user has access
 * @throws IOException
 *            Signals that an I/O exception has occurred.
 * @throws ServletException
 *            On other errors
 */
public boolean checkAccess(HttpServletRequest req, HttpServletResponse res, NodeRef nodeRef, String permission, boolean allowLogIn) throws IOException, ServletException {
    ServletContext sc = getServletContext();
    ServiceRegistry serviceRegistry = getServiceRegistry(sc);
    PermissionService permissionService = serviceRegistry.getPermissionService();
    // check that the user has the permission
    if (permissionService.hasPermission(nodeRef, permission) == AccessStatus.DENIED) {
        if (logger.isDebugEnabled())
            logger.debug("User does not have " + permission + " permission for NodeRef: " + nodeRef.toString());
        if (allowLogIn && serviceRegistry.getAuthorityService().hasGuestAuthority()) {
            if (logger.isDebugEnabled())
                logger.debug("Redirecting to login page...");
            redirectToLoginPage(req, res, sc);
        } else {
            if (logger.isDebugEnabled())
                logger.debug("Forwarding to error page...");
            Application.handleSystemError(sc, req, res, MSG_ERROR_PERMISSIONS, HttpServletResponse.SC_FORBIDDEN, logger);
        }
        return false;
    }
    return true;
}
Also used : PermissionService(org.alfresco.service.cmr.security.PermissionService) ServletContext(javax.servlet.ServletContext) ServiceRegistry(org.alfresco.service.ServiceRegistry)

Example 15 with ServiceRegistry

use of org.alfresco.service.ServiceRegistry in project acs-community-packaging by Alfresco.

the class CommandServlet method service.

/**
 * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
 */
protected void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
    String uri = req.getRequestURI();
    if (logger.isDebugEnabled())
        logger.debug("Processing URL: " + uri + (req.getQueryString() != null ? ("?" + req.getQueryString()) : ""));
    AuthenticationStatus status = servletAuthenticate(req, res);
    if (status == AuthenticationStatus.Failure) {
        return;
    }
    setNoCacheHeaders(res);
    uri = uri.substring(req.getContextPath().length());
    StringTokenizer t = new StringTokenizer(uri, "/");
    int tokenCount = t.countTokens();
    if (tokenCount < 3) {
        throw new IllegalArgumentException("Command Servlet URL did not contain all required args: " + uri);
    }
    // skip servlet name
    t.nextToken();
    // get the command processor to execute the command e.g. "workflow"
    String procName = t.nextToken();
    // get the command to perform
    String command = t.nextToken();
    // get any remaining uri elements to pass to the processor
    String[] urlElements = new String[tokenCount - 3];
    for (int i = 0; i < tokenCount - 3; i++) {
        urlElements[i] = t.nextToken();
    }
    // retrieve the URL arguments to pass to the processor
    Map<String, String> args = new HashMap<String, String>(8, 1.0f);
    Enumeration names = req.getParameterNames();
    while (names.hasMoreElements()) {
        String name = (String) names.nextElement();
        args.put(name, req.getParameter(name));
    }
    try {
        // get configured command processor by name from Config Service
        CommandProcessor processor = createCommandProcessor(procName);
        // validate that the processor has everything it needs to run the command
        if (processor.validateArguments(getServletContext(), command, args, urlElements) == false) {
            redirectToLoginPage(req, res, getServletContext());
            return;
        }
        ServiceRegistry serviceRegistry = getServiceRegistry(getServletContext());
        UserTransaction txn = null;
        try {
            txn = serviceRegistry.getTransactionService().getUserTransaction();
            txn.begin();
            // inform the processor to execute the specified command
            if (processor instanceof ExtCommandProcessor) {
                ((ExtCommandProcessor) processor).process(serviceRegistry, req, res, command);
            } else {
                processor.process(serviceRegistry, req, command);
            }
            // commit the transaction
            txn.commit();
        } catch (Throwable txnErr) {
            try {
                if (txn != null) {
                    txn.rollback();
                }
            } catch (Exception tex) {
            }
            throw txnErr;
        }
        String returnPage = req.getParameter(ARG_RETURNPAGE);
        if (returnPage != null && returnPage.length() != 0) {
            validateReturnPage(returnPage, req);
            if (logger.isDebugEnabled())
                logger.debug("Redirecting to specified return page: " + returnPage);
            res.sendRedirect(returnPage);
        } else {
            if (logger.isDebugEnabled())
                logger.debug("No return page specified, displaying status output.");
            if (res.getContentType() == null && !res.isCommitted()) {
                res.setContentType("text/html");
                // request that the processor output a useful status message
                PrintWriter out = res.getWriter();
                processor.outputStatus(out);
                out.close();
            }
        }
    } catch (Throwable err) {
        throw new AlfrescoRuntimeException("Error during command servlet processing: " + err.getMessage(), err);
    }
}
Also used : UserTransaction(javax.transaction.UserTransaction) Enumeration(java.util.Enumeration) HashMap(java.util.HashMap) ExtCommandProcessor(org.alfresco.web.app.servlet.command.ExtCommandProcessor) MalformedURLException(java.net.MalformedURLException) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) StringTokenizer(java.util.StringTokenizer) ExtCommandProcessor(org.alfresco.web.app.servlet.command.ExtCommandProcessor) CommandProcessor(org.alfresco.web.app.servlet.command.CommandProcessor) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) ServiceRegistry(org.alfresco.service.ServiceRegistry) PrintWriter(java.io.PrintWriter)

Aggregations

ServiceRegistry (org.alfresco.service.ServiceRegistry)32 NodeRef (org.alfresco.service.cmr.repository.NodeRef)17 NodeService (org.alfresco.service.cmr.repository.NodeService)8 FacesContext (javax.faces.context.FacesContext)7 MimetypeService (org.alfresco.service.cmr.repository.MimetypeService)6 QName (org.alfresco.service.namespace.QName)6 StringTokenizer (java.util.StringTokenizer)5 Serializable (java.io.Serializable)4 HashMap (java.util.HashMap)4 SelectItem (javax.faces.model.SelectItem)4 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)4 ContentService (org.alfresco.service.cmr.repository.ContentService)4 ContentWriter (org.alfresco.service.cmr.repository.ContentWriter)4 StoreRef (org.alfresco.service.cmr.repository.StoreRef)4 PermissionService (org.alfresco.service.cmr.security.PermissionService)4 TransactionService (org.alfresco.service.transaction.TransactionService)4 QuickSort (org.alfresco.web.data.QuickSort)4 SocketException (java.net.SocketException)3 Map (java.util.Map)3 UserTransaction (javax.transaction.UserTransaction)3