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;
}
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()));
}
}
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));
}
}
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);
}
}
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);
}
}
Aggregations