Search in sources :

Example 1 with GWTJahiaServiceException

use of org.jahia.ajax.gwt.client.service.GWTJahiaServiceException in project jahia by Jahia.

the class TemplateHelper method getRenderedContent.

/**
 * Get rendered content
 *
 * @param path
 * @param template
 * @param configuration
 * @param contextParams
 * @param editMode
 * @param configName
 * @param request
 * @param response
 * @param currentUserSession
 * @param uiLocale
 * @param channelIdentifier
 * @param channelVariant
 */
public GWTRenderResult getRenderedContent(String path, String template, String configuration, final Map<String, List<String>> contextParams, boolean editMode, String configName, HttpServletRequest request, HttpServletResponse response, JCRSessionWrapper currentUserSession, Locale uiLocale, String channelIdentifier, String channelVariant) throws GWTJahiaServiceException {
    GWTRenderResult result = null;
    try {
        JCRNodeWrapper node = currentUserSession.getNode(path);
        Resource r = new Resource(node, "html", template, configuration);
        request.setAttribute("mode", "edit");
        request = new HttpServletRequestWrapper(request) {

            @Override
            public String getParameter(String name) {
                if (contextParams != null && contextParams.containsKey(name)) {
                    return contextParams.get(name).get(0);
                }
                return super.getParameter(name);
            }

            @Override
            public Map getParameterMap() {
                Map r = new HashMap(super.getParameterMap());
                if (contextParams != null) {
                    for (Map.Entry<String, List<String>> entry : contextParams.entrySet()) {
                        r.put(entry.getKey(), entry.getValue().toArray(new String[entry.getValue().size()]));
                    }
                }
                return r;
            }

            @Override
            public Enumeration getParameterNames() {
                return new Vector(getParameterMap().keySet()).elements();
            }

            @Override
            public String[] getParameterValues(String name) {
                if (contextParams != null && contextParams.containsKey(name)) {
                    List<String> list = contextParams.get(name);
                    return list.toArray(new String[list.size()]);
                }
                return super.getParameterValues(name);
            }
        };
        RenderContext renderContext = new RenderContext(request, response, currentUserSession.getUser());
        renderContext.setEditMode(editMode);
        if ("contributemode".equals(configName)) {
            renderContext.setContributionMode(true);
        }
        renderContext.setMainResource(r);
        EditConfiguration editConfiguration = null;
        if (configName != null) {
            editConfiguration = (EditConfiguration) SpringContextSingleton.getBean(configName);
        }
        renderContext.setEditModeConfig(editConfiguration);
        String permission = null;
        if (editConfiguration != null) {
            permission = editConfiguration.getRequiredPermission();
            renderContext.setServletPath(editConfiguration.getDefaultUrlMapping());
        } else {
            renderContext.setServletPath(Render.getRenderServletPath());
        }
        if (permission != null) {
            if (!node.getResolveSite().hasPermission(permission)) {
                throw new GWTJahiaServiceException(Messages.getInternal("label.gwt.error.access.denied", uiLocale));
            }
        }
        if (contextParams != null) {
            for (Map.Entry<String, List<String>> entry : contextParams.entrySet()) {
                r.getModuleParams().put(entry.getKey(), entry.getValue().get(0));
            }
        }
        JCRSiteNode site = node.getResolveSite();
        renderContext.setSite(site);
        if (channelIdentifier != null) {
            Channel activeChannel = channelService.getChannel(channelIdentifier);
            if (activeChannel != null) {
                renderContext.setChannel(activeChannel);
            }
        }
        response.setCharacterEncoding(SettingsBean.getInstance().getCharacterEncoding());
        String res = renderService.render(r, renderContext);
        Map<String, Map<String, Map<String, String>>> map = (Map<String, Map<String, Map<String, String>>>) renderContext.getRequest().getAttribute("staticAssets");
        String constraints = ConstraintsHelper.getConstraints(node);
        if (constraints == null) {
            constraints = "";
        }
        Map<String, List<GWTStaticAssetEntry>> m = new HashMap<String, List<GWTStaticAssetEntry>>();
        if (map != null) {
            for (Map.Entry<String, Map<String, Map<String, String>>> entry : map.entrySet()) {
                List<GWTStaticAssetEntry> fileEntries = new ArrayList<GWTStaticAssetEntry>();
                for (Map.Entry<String, Map<String, String>> filetypeEntries : entry.getValue().entrySet()) {
                    String filePath = filetypeEntries.getKey();
                    Map<String, String> fileOptions = filetypeEntries.getValue();
                    fileEntries.add(new GWTStaticAssetEntry(filePath, fileOptions));
                }
                m.put(entry.getKey(), fileEntries);
            }
        }
        result = new GWTRenderResult(res, m, constraints, node.getDisplayableName());
    } catch (PathNotFoundException e) {
        throw new GWTJahiaServiceException(Messages.getInternalWithArguments("label.gwt.error.not.found.for.user", uiLocale, path, currentUserSession.getUser().getName()));
    } catch (RepositoryException e) {
        logger.error(e.getMessage(), e);
        throw new GWTJahiaServiceException(Messages.getInternalWithArguments("label.gwt.error.repository.exception.on.path", uiLocale, path));
    } catch (RenderException e) {
        if (e.getCause() instanceof AccessDeniedException) {
            throw new GWTJahiaServiceException(Messages.getInternal("label.gwt.error.access.denied", uiLocale));
        } else {
            logger.error(e.getMessage(), e);
            throw new GWTJahiaServiceException(Messages.getInternalWithArguments("label.gwt.error.render.exception", uiLocale, e.getMessage()));
        }
    }
    return result;
}
Also used : JCRNodeWrapper(org.jahia.services.content.JCRNodeWrapper) AccessDeniedException(javax.jcr.AccessDeniedException) GWTStaticAssetEntry(org.jahia.ajax.gwt.client.data.GWTStaticAssetEntry) RenderException(org.jahia.services.render.RenderException) JCRSiteNode(org.jahia.services.content.decorator.JCRSiteNode) HttpServletRequestWrapper(javax.servlet.http.HttpServletRequestWrapper) RenderContext(org.jahia.services.render.RenderContext) GWTRenderResult(org.jahia.ajax.gwt.client.data.GWTRenderResult) GWTStaticAssetEntry(org.jahia.ajax.gwt.client.data.GWTStaticAssetEntry) Channel(org.jahia.services.channels.Channel) Resource(org.jahia.services.render.Resource) RepositoryException(javax.jcr.RepositoryException) GWTJahiaServiceException(org.jahia.ajax.gwt.client.service.GWTJahiaServiceException) EditConfiguration(org.jahia.services.uicomponents.bean.editmode.EditConfiguration) PathNotFoundException(javax.jcr.PathNotFoundException)

Example 2 with GWTJahiaServiceException

use of org.jahia.ajax.gwt.client.service.GWTJahiaServiceException in project jahia by Jahia.

the class UIConfigHelper method getGWTToolbarSet.

/**
 * Get gwt toolbar for the current user
 *
 * @return
 */
public GWTJahiaToolbar getGWTToolbarSet(JCRNodeWrapper contextNode, JCRSiteNode site, JahiaUser jahiaUser, Locale locale, Locale uiLocale, HttpServletRequest request, String toolbarGroup) throws GWTJahiaServiceException {
    try {
        // there is no pref or toolbar are hided
        // get all tool bars
        Toolbar toolbar = (Toolbar) SpringContextSingleton.getBean(toolbarGroup);
        Visibility visibility = toolbar.getVisibility();
        if ((visibility != null && visibility.getRealValue(contextNode, jahiaUser, locale, request)) || visibility == null) {
            return createGWTToolbar(contextNode, site, jahiaUser, locale, uiLocale, request, toolbar);
        } else {
            logger.info("Toolbar are not visible.");
            return null;
        }
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        throw new GWTJahiaServiceException(Messages.getInternalWithArguments("label.gwt.error.during.loading.toolbars", uiLocale, e.getMessage()));
    }
}
Also used : GWTJahiaServiceException(org.jahia.ajax.gwt.client.service.GWTJahiaServiceException) Visibility(org.jahia.services.uicomponents.bean.Visibility) GWTJahiaServiceException(org.jahia.ajax.gwt.client.service.GWTJahiaServiceException) RepositoryException(javax.jcr.RepositoryException) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException) Toolbar(org.jahia.services.uicomponents.bean.toolbar.Toolbar)

Example 3 with GWTJahiaServiceException

use of org.jahia.ajax.gwt.client.service.GWTJahiaServiceException in project jahia by Jahia.

the class UIConfigHelper method updateGWTJahiaStateInfo.

/**
 * Update GWT Jahia State Info
 *
 * @param gwtJahiaStateInfo
 * @return
 */
public GWTJahiaStateInfo updateGWTJahiaStateInfo(JCRSiteNode site, JahiaUser jahiaUser, Locale uiLocale, GWTJahiaStateInfo gwtJahiaStateInfo) throws GWTJahiaServiceException {
    try {
        if (gwtJahiaStateInfo == null) {
            gwtJahiaStateInfo = new GWTJahiaStateInfo();
            gwtJahiaStateInfo.setLastViewTime(System.currentTimeMillis());
            if (gwtJahiaStateInfo.isNeedRefresh()) {
                gwtJahiaStateInfo.setIconStyle("gwt-toolbar-icon-notification-refresh");
            }
        } else {
            if (gwtJahiaStateInfo.isNeedRefresh()) {
                return gwtJahiaStateInfo;
            }
        }
        // remove last alert message
        gwtJahiaStateInfo.setAlertMessage(null);
        return gwtJahiaStateInfo;
    } catch (Exception e) {
        logger.error("Error when triing to load Jahia state info due to", e);
        throw new GWTJahiaServiceException(Messages.getInternal("label.gwt.error.when.trying.to.load.jahia.state", uiLocale));
    }
}
Also used : GWTJahiaServiceException(org.jahia.ajax.gwt.client.service.GWTJahiaServiceException) GWTJahiaStateInfo(org.jahia.ajax.gwt.client.data.toolbar.monitor.GWTJahiaStateInfo) GWTJahiaServiceException(org.jahia.ajax.gwt.client.service.GWTJahiaServiceException) RepositoryException(javax.jcr.RepositoryException) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException)

Example 4 with GWTJahiaServiceException

use of org.jahia.ajax.gwt.client.service.GWTJahiaServiceException in project jahia by Jahia.

the class WorkflowHelper method getWorkflowInfo.

public GWTJahiaWorkflowInfo getWorkflowInfo(String path, boolean includeActiveWorfklows, JCRSessionWrapper session, Locale locale, Locale uiLocale) throws GWTJahiaServiceException {
    try {
        GWTJahiaWorkflowInfo info = new GWTJahiaWorkflowInfo();
        Map<GWTJahiaWorkflowType, GWTJahiaWorkflowDefinition> gwtWorkflowDefinitions = new HashMap<GWTJahiaWorkflowType, GWTJahiaWorkflowDefinition>();
        info.setPossibleWorkflows(gwtWorkflowDefinitions);
        JCRNodeWrapper node = session.getNode(path);
        Map<String, WorkflowDefinition> wfs = service.getPossibleWorkflows(node, true, locale);
        for (Map.Entry<String, WorkflowDefinition> entry : wfs.entrySet()) {
            gwtWorkflowDefinitions.put(getGWTJahiaWorkflowType(entry.getKey()), getGWTJahiaWorkflowDefinition(entry.getValue()));
        }
        Map<GWTJahiaWorkflowType, GWTJahiaWorkflow> gwtWorkflows = new HashMap<GWTJahiaWorkflowType, GWTJahiaWorkflow>();
        info.setActiveWorkflows(gwtWorkflows);
        if (includeActiveWorfklows) {
            List<Workflow> actives = service.getActiveWorkflows(node, locale, uiLocale);
            for (Workflow workflow : actives) {
                GWTJahiaWorkflow gwtWf = getGWTJahiaWorkflow(workflow);
                gwtWorkflows.put(getGWTJahiaWorkflowType(service.getWorkflowType(workflow.getWorkflowDefinition())), gwtWf);
                for (WorkflowAction workflowAction : workflow.getAvailableActions()) {
                    if (workflowAction instanceof WorkflowTask) {
                        WorkflowTask workflowTask = (WorkflowTask) workflowAction;
                        List<WorkflowParticipation> participations = workflowTask.getParticipations();
                        if (participations != null) {
                            for (WorkflowParticipation participation : participations) {
                                JahiaPrincipal principal = participation.getJahiaPrincipal();
                                if (principal instanceof JahiaGroup) {
                                    JCRGroupNode groupNode = groupManagerService.lookupGroupByPath(principal.getLocalPath());
                                    JCRUserNode userNode = userManagerService.lookupUserByPath(session.getUser().getLocalPath());
                                    if (groupNode != null && userNode != null && groupNode.isMember(userNode)) {
                                        gwtWf.getAvailableTasks().add(getGWTJahiaWorkflowTask(workflowTask, null));
                                        break;
                                    }
                                }
                                if (principal instanceof JahiaUser && principal.getLocalPath().equals(session.getUser().getLocalPath())) {
                                    gwtWf.getAvailableTasks().add(getGWTJahiaWorkflowTask(workflowTask, null));
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
        return info;
    } catch (RepositoryException e) {
        logger.error(e.getMessage(), e);
        throw new GWTJahiaServiceException("Cannot get workflow info for " + path + ". Cause: " + e.getLocalizedMessage(), e);
    }
}
Also used : JCRNodeWrapper(org.jahia.services.content.JCRNodeWrapper) CustomWorkflow(org.jahia.ajax.gwt.client.widget.workflow.CustomWorkflow) RepositoryException(javax.jcr.RepositoryException) JCRGroupNode(org.jahia.services.content.decorator.JCRGroupNode) JCRUserNode(org.jahia.services.content.decorator.JCRUserNode) GWTJahiaServiceException(org.jahia.ajax.gwt.client.service.GWTJahiaServiceException)

Example 5 with GWTJahiaServiceException

use of org.jahia.ajax.gwt.client.service.GWTJahiaServiceException in project jahia by Jahia.

the class WorkflowHelper method getWorkflows.

public List<GWTJahiaWorkflowDefinition> getWorkflows(Locale locale) throws GWTJahiaServiceException {
    try {
        final Set<String> workflowTypes = service.getTypesOfWorkflow();
        List<GWTJahiaWorkflowDefinition> definitions = new ArrayList<GWTJahiaWorkflowDefinition>();
        for (String workflowType : workflowTypes) {
            final List<WorkflowDefinition> workflowDefinitions = service.getWorkflowDefinitionsForType(workflowType, null, locale);
            for (WorkflowDefinition definition : workflowDefinitions) {
                definitions.add(getGWTJahiaWorkflowDefinition(definition));
            }
        }
        return definitions;
    } catch (RepositoryException e) {
        logger.error(e.getMessage(), e);
        throw new GWTJahiaServiceException("Cannot get workflows for " + locale + ". Cause: " + e.getLocalizedMessage(), e);
    }
}
Also used : GWTJahiaServiceException(org.jahia.ajax.gwt.client.service.GWTJahiaServiceException) RepositoryException(javax.jcr.RepositoryException)

Aggregations

GWTJahiaServiceException (org.jahia.ajax.gwt.client.service.GWTJahiaServiceException)77 RepositoryException (javax.jcr.RepositoryException)24 JCRNodeWrapper (org.jahia.services.content.JCRNodeWrapper)13 LockException (javax.jcr.lock.LockException)10 GWTJahiaNode (org.jahia.ajax.gwt.client.data.node.GWTJahiaNode)9 ExistingFileException (org.jahia.ajax.gwt.client.service.content.ExistingFileException)9 ItemNotFoundException (javax.jcr.ItemNotFoundException)8 JahiaException (org.jahia.exceptions.JahiaException)8 JCRSiteNode (org.jahia.services.content.decorator.JCRSiteNode)8 InputStream (java.io.InputStream)7 NoSuchNodeTypeException (javax.jcr.nodetype.NoSuchNodeTypeException)6 ExtendedNodeType (org.jahia.services.content.nodetypes.ExtendedNodeType)6 MalformedURLException (java.net.MalformedURLException)5 BufferedInputStream (java.io.BufferedInputStream)4 ParseException (java.text.ParseException)4 Query (javax.jcr.query.Query)4 ConstraintViolationException (javax.validation.ConstraintViolationException)4 GWTJahiaNodeACE (org.jahia.ajax.gwt.client.data.acl.GWTJahiaNodeACE)4 NonUniqueUrlMappingException (org.jahia.services.seo.jcr.NonUniqueUrlMappingException)4 TranslationException (org.jahia.services.translation.TranslationException)4