Java Code Examples for org.springframework.extensions.webscripts.WebScriptRequest

The following are top voted examples for showing how to use org.springframework.extensions.webscripts.WebScriptRequest. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: alfresco-remote-api   File: ActionConstraintGet.java   Source Code and License 8 votes vote down vote up
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
{
    Map<String, Object> model = new HashMap<String, Object>();

    // get request parameters
    Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
    String name = templateVars.get("name");

    // get specified parameter constraint
    ParameterConstraint parameterConstraint = actionService.getParameterConstraint(name);

    if (parameterConstraint == null)
    {
        throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find parameter constraint with name: " + name);
    }

    model.put("actionConstraint", parameterConstraint);

    return model;
}
 
Example 2
Project: alfresco-remote-api   File: AbstractRuleWebScript.java   Source Code and License 7 votes vote down vote up
/**
 * Parses the request and providing it's valid returns the NodeRef.
 * 
 * @param req The webscript request
 * @return The NodeRef passed in the request
 * 
 */
protected NodeRef parseRequestForNodeRef(WebScriptRequest req)
{
    // get the parameters that represent the NodeRef, we know they are present
    // otherwise this webscript would not have matched
    Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
    String storeType = templateVars.get("store_type");
    String storeId = templateVars.get("store_id");
    String nodeId = templateVars.get("id");

    // create the NodeRef and ensure it is valid
    StoreRef storeRef = new StoreRef(storeType, storeId);
    NodeRef nodeRef = new NodeRef(storeRef, nodeId);

    if (!this.nodeService.exists(nodeRef))
    {
        throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find node: " + nodeRef.toString());
    }

    return nodeRef;
}
 
Example 3
Project: alfresco-remote-api   File: QuickShareContentGet.java   Source Code and License 7 votes vote down vote up
protected void executeImpl(NodeRef nodeRef, Map<String, String> templateVars, WebScriptRequest req, WebScriptResponse res, Map<String, Object> model) throws IOException
{
    // render content
       QName propertyQName = ContentModel.PROP_CONTENT;
       String contentPart = templateVars.get("property");
       if (contentPart.length() > 0 && contentPart.charAt(0) == ';')
       {
           if (contentPart.length() < 2)
           {
               throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, "Content property malformed");
           }
           String propertyName = contentPart.substring(1);
           if (propertyName.length() > 0)
           {
               propertyQName = QName.createQName(propertyName, namespaceService);
           }
       }
       
       // determine attachment
       boolean attach = Boolean.valueOf(req.getParameter("a"));
       
       // Stream the content
       streamContentLocal(req, res, nodeRef, attach, propertyQName, model);
}
 
Example 4
Project: alfresco-remote-api   File: RatingDelete.java   Source Code and License 7 votes vote down vote up
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
{
    Map<String, Object> model = new HashMap<String, Object>();

    NodeRef nodeRef = parseRequestForNodeRef(req);
    String ratingSchemeName = parseRequestForScheme(req);
    
    Rating deletedRating = ratingService.removeRatingByCurrentUser(nodeRef, ratingSchemeName);
    if (deletedRating == null)
    {
        // There was no rating in the specified scheme to delete.
        throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, "Unable to delete non-existent rating: "
                + ratingSchemeName + " from " + nodeRef.toString());
    }
    
    model.put(NODE_REF, nodeRef.toString());
    model.put(AVERAGE_RATING, ratingService.getAverageRating(nodeRef, ratingSchemeName));
    model.put(RATINGS_TOTAL, ratingService.getTotalRating(nodeRef, ratingSchemeName));
    model.put(RATINGS_COUNT, ratingService.getRatingsCount(nodeRef, ratingSchemeName));
  
    return model;
}
 
Example 5
Project: alfresco-remote-api   File: WorkflowDefinitionGet.java   Source Code and License 7 votes vote down vote up
@Override
protected Map<String, Object> buildModel(WorkflowModelBuilder modelBuilder, WebScriptRequest req, Status status, Cache cache)
{
    Map<String, String> params = req.getServiceMatch().getTemplateVars();

    // Get the definition id from the params
    String workflowDefinitionId = params.get(PARAM_WORKFLOW_DEFINITION_ID);
    
    WorkflowDefinition workflowDefinition = workflowService.getDefinitionById(workflowDefinitionId);

    // Workflow definition is not found, 404
    if (workflowDefinition == null)
    {
        throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, 
                    "Unable to find workflow definition with id: " + workflowDefinitionId);
    }
    
    Map<String, Object> model = new HashMap<String, Object>();
    model.put("workflowDefinition", modelBuilder.buildDetailed(workflowDefinition));
    return model;
}
 
Example 6
Project: alfresco-remote-api   File: AlfrescoModelGet.java   Source Code and License 6 votes vote down vote up
private void handle(WebScriptRequest req, WebScriptResponse res) throws JSONException, IOException
{
    // create map of template vars
    String modelQName = req.getParameter("modelQName");
    if(modelQName == null)
    {
        throw new WebScriptException(
                Status.STATUS_BAD_REQUEST,
                "URL parameter 'modelQName' not provided.");
    }

    ModelDefinition.XMLBindingType bindingType = ModelDefinition.XMLBindingType.DEFAULT;
    AlfrescoModel model = solrTrackingComponent.getModel(QName.createQName(modelQName));
    res.setHeader("XAlfresco-modelChecksum", String.valueOf(model.getModelDef().getChecksum(bindingType)));
    model.getModelDef().toXML(bindingType, res.getOutputStream());
}
 
Example 7
Project: alfresco-remote-api   File: AbstractWorkflowWebscript.java   Source Code and License 6 votes vote down vote up
/**
 * Processes the given date filter parameter from the provided webscript request.
 * 
 * If the parameter is present but set to an empty string or to "null" the
 * date is added to the given filters Map as "", if the parameter
 * contains an ISO8601 date it's added as a Date object to the filters.
 * 
 * @param req The WebScript request
 * @param paramName The name of the parameter to look for
 * @param filters Map of filters to add the date to
 */
protected void processDateFilter(WebScriptRequest req, String paramName, Map<String, Object> filters)
{
    // TODO: support other keywords i.e. today, tomorrow
    
    String dateParam = req.getParameter(paramName);
    if (dateParam != null)
    {
        Object date = EMPTY;
        
        if (!EMPTY.equals(dateParam) && !NULL.equals(dateParam))
        {
            date = getDateParameter(req, paramName);
        }
        
        filters.put(paramName, date);
    }
}
 
Example 8
Project: alfresco-remote-api   File: RunningActionsGet.java   Source Code and License 6 votes vote down vote up
@Override
protected Map<String, Object> buildModel(
      RunningActionModelBuilder modelBuilder, WebScriptRequest req,
      Status status, Cache cache) {
   List<ExecutionSummary> actions = null;
   
   // Do they want all actions, or only certain ones?
   String type = req.getParameter("type");
   String nodeRef = req.getParameter("nodeRef");
   
   if(type != null) {
      actions = actionTrackingService.getExecutingActions(type);
   } else if(nodeRef != null) {
      NodeRef actionNodeRef = new NodeRef(nodeRef);
      Action action = runtimeActionService.createAction(actionNodeRef);
      actions = actionTrackingService.getExecutingActions(action); 
   } else {
      actions = actionTrackingService.getAllExecutingActions();
   }
   
   // Build the model list
   return modelBuilder.buildSimpleList(actions);
}
 
Example 9
Project: alfresco-remote-api   File: BulkFilesystemImportStatusWebScript.java   Source Code and License 6 votes vote down vote up
/**
 * @see org.springframework.extensions.webscripts.DeclarativeWebScript#executeImpl(WebScriptRequest, Status, Cache)
 */
@Override
protected Map<String, Object> executeImpl(WebScriptRequest request, Status status, Cache cache)
{
    Map<String, Object> result = new HashMap<String, Object>();
    
    cache.setNeverCache(true);
    
    LicenseDescriptor licenseDescriptor = descriptorService.getLicenseDescriptor();
    boolean isEnterprise = (licenseDescriptor == null ? false : (licenseDescriptor.getLicenseMode() == LicenseMode.ENTERPRISE));

    result.put(IS_ENTERPRISE, Boolean.valueOf(isEnterprise));
    result.put(RESULT_IMPORT_STATUS, bulkImporter.getStatus());
    
    return(result);
}
 
Example 10
Project: alfresco-remote-api   File: PropertiesGet.java   Source Code and License 6 votes vote down vote up
@Override
protected QName getClassQName(WebScriptRequest req)
{
    QName classQName = null;
    String className = req.getServiceMatch().getTemplateVars().get(DICTIONARY_CLASS_NAME);
    if (className != null && className.length() != 0)
    {            
        classQName = createClassQName(className);
        if (classQName == null)
        {
            // Error 
            throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the className - " + className + " - parameter in the URL");
        }
    }
    return classQName;
}
 
Example 11
Project: alfresco-remote-api   File: SolrFacetConfigAdminDelete.java   Source Code and License 6 votes vote down vote up
@Override
protected Map<String, Object> unprotectedExecuteImpl(WebScriptRequest req, Status status, Cache cache)
{
    // get the filterID parameter.
    Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
    String filterID = templateVars.get("filterID");

    if (filterID == null)
    {
        throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Filter id not provided");
    }
    facetService.deleteFacet(filterID);

    Map<String, Object> model = new HashMap<String, Object>(1);
    model.put("success", true);

    if (logger.isDebugEnabled())
    {
        logger.debug("Facet [" + filterID + "] has been deleted successfully");
    }

    return model;
}
 
Example 12
Project: alfresco-remote-api   File: AbstractClassGet.java   Source Code and License 6 votes vote down vote up
/**
 * Override method from DeclarativeWebScript
 */
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status)
{
    Map<String, Object> model = new HashMap<String, Object>(3);
    Map<QName, ClassDefinition> classdef = new HashMap<QName, ClassDefinition>();
    Map<QName, Collection<PropertyDefinition>> propdef = new HashMap<QName, Collection<PropertyDefinition>>();
    Map<QName, Collection<AssociationDefinition>> assocdef = new HashMap<QName, Collection<AssociationDefinition>>();

    QName classQname = getClassQname(req);
    classdef.put(classQname, this.dictionaryservice.getClass(classQname));
    propdef.put(classQname, this.dictionaryservice.getClass(classQname).getProperties().values());
    assocdef.put(classQname, this.dictionaryservice.getClass(classQname).getAssociations().values());

    model.put(MODEL_PROP_KEY_CLASS_DETAILS, classdef.values());
    model.put(MODEL_PROP_KEY_PROPERTY_DETAILS, propdef.values());
    model.put(MODEL_PROP_KEY_ASSOCIATION_DETAILS, assocdef.values());
    model.put(MODEL_PROP_KEY_MESSAGE_LOOKUP, this.dictionaryservice);

    return model;
}
 
Example 13
Project: alfresco-remote-api   File: PropertiesGet.java   Source Code and License 6 votes vote down vote up
@Override
protected QName getClassQName(WebScriptRequest req)
{
    QName classQName = null;
    String prefix = req.getServiceMatch().getTemplateVars().get(DICTIONARY_PREFIX);
    String shortName = req.getServiceMatch().getTemplateVars().get(DICTIONARY_SHORT_CLASS_NAME);
    if (prefix != null && prefix.length() != 0 && shortName != null && shortName.length()!= 0)
    {            
        classQName = createClassQName(prefix, shortName);
        if (classQName == null)
        {
            // Error 
            throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the className - " + prefix + ":" + shortName + " - parameter in the URL");
        }
    }
    return classQName;
}
 
Example 14
Project: alfresco-remote-api   File: LargeContentTestPut.java   Source Code and License 6 votes vote down vote up
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
{
    Map<String, Object> model = new HashMap<String, Object>();
    
    try
    {
        req.getContent().getInputStream().close();
        model.put("result", "success");
    }
    catch (IOException e)
    {
        throw new WebScriptException(Status.STATUS_INTERNAL_SERVER_ERROR, "Fail to read request content.");
    }
    return model;
}
 
Example 15
Project: alfresco-remote-api   File: AlfrescoModelsDiff.java   Source Code and License 6 votes vote down vote up
private void setExceptionResponse(WebScriptRequest req, Status responseStatus, String responseMessage, int statusCode, Exception e)
{
    String message = responseMessage + req;

    if (logger.isDebugEnabled())
    {
        logger.warn(message, e);
    }
    else
    {
        logger.warn(message);
    }

    responseStatus.setCode(statusCode, message);
    responseStatus.setException(e);
}
 
Example 16
Project: alfresco-remote-api   File: AbstractArchivedNodeWebScript.java   Source Code and License 6 votes vote down vote up
/**
 * Retrieves the named parameter as an integer, if the parameter is not present the default value is returned
 * 
 * @param req The WebScript request
 * @param paramName The name of parameter to look for
 * @param defaultValue The default value that should be returned if parameter is not present in request or if it is not positive
 * @return The request parameter or default value
 */
protected int getIntParameter(WebScriptRequest req, String paramName, int defaultValue)
{
    String paramString = req.getParameter(paramName);
    
    if (paramString != null)
    {
        try
        {
            int param = Integer.valueOf(paramString);
            
            if (param >= 0)
            {
                return param;
            }
        }
        catch (NumberFormatException e) 
        {
            throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, e.getMessage());
        }
    }
    
    return defaultValue;
}
 
Example 17
Project: alfresco-remote-api   File: RunningActionGet.java   Source Code and License 6 votes vote down vote up
@Override
protected Map<String, Object> buildModel(
      RunningActionModelBuilder modelBuilder, WebScriptRequest req,
      Status status, Cache cache) {
   // Which action did they ask for?
   String actionTrackingId = 
      req.getServiceMatch().getTemplateVars().get("action_tracking_id");

   ExecutionSummary action = 
      getSummaryFromKey(actionTrackingId);
   
   // Get the details, if we can
   Map<String,Object> model = modelBuilder.buildSimpleModel(action);
   
   if(model == null) {
      throw new WebScriptException(
            Status.STATUS_NOT_FOUND, 
            "No Running Action found with that tracking id"
      );
   }
   
   return model;
}
 
Example 18
Project: alfresco-remote-api   File: ReplicationDefinitionGet.java   Source Code and License 6 votes vote down vote up
@Override
protected Map<String, Object> buildModel(ReplicationModelBuilder modelBuilder, 
                                         WebScriptRequest req, Status status, Cache cache)
{
    // Which definition did they ask for?
    String replicationDefinitionName = 
       req.getServiceMatch().getTemplateVars().get("replication_definition_name");
    ReplicationDefinition replicationDefinition =
       replicationService.loadReplicationDefinition(replicationDefinitionName);
    
    // Does it exist?
    if(replicationDefinition == null) {
       throw new WebScriptException(
             Status.STATUS_NOT_FOUND, 
             "No Replication Definition found with that name"
       );
    }
   
    // Have it turned into simple models
    return modelBuilder.buildDetails(replicationDefinition);
}
 
Example 19
Project: alfresco-remote-api   File: SubscriptionServiceFollowPost.java   Source Code and License 6 votes vote down vote up
public JSONObject executeImpl(String userId, WebScriptRequest req, WebScriptResponse res) throws IOException,
        ParseException
{
    JSONArray jsonUsers = (JSONArray) JSONValue.parseWithException(req.getContent().getContent());

    for (Object o : jsonUsers)
    {
        String user = (o == null ? null : o.toString());
        if (user != null)
        {
            subscriptionService.follow(userId, user);
        }
    }

    return null;
}
 
Example 20
Project: alfresco-remote-api   File: SubscriptionServicePrivateListPut.java   Source Code and License 6 votes vote down vote up
public JSONObject executeImpl(String userId, WebScriptRequest req, WebScriptResponse res) throws IOException,
        ParseException
{
    JSONObject obj = (JSONObject) JSONValue.parseWithException(req.getContent().getContent());

    Object setPrivate = obj.get("private");

    if (setPrivate != null)
    {
        if (setPrivate.toString().equalsIgnoreCase("true"))
        {
            subscriptionService.setSubscriptionListPrivate(userId, true);
        } else if (setPrivate.toString().equalsIgnoreCase("false"))
        {
            subscriptionService.setSubscriptionListPrivate(userId, false);
        }
    }

    return super.executeImpl(userId, req, res);
}
 
Example 21
Project: alfresco-remote-api   File: MetaDataGet.java   Source Code and License 6 votes vote down vote up
@Override
protected Map<String, Object> executeImpl(final WebScriptRequest req, Status status, Cache cache)
{
    // create map of params (template vars)
    Map<String, String> params = req.getServiceMatch().getTemplateVars();
    final NodeRef nodeRef = WebScriptUtil.getNodeRef(params);
    if (nodeRef == null)
    {
        String msg = "A valid NodeRef must be specified!";
        throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, msg);
    }
    
    try
    {
        Map<String, Object> model = quickShareService.getMetaData(nodeRef);
        
        if (logger.isDebugEnabled())
        {
            logger.debug("Retrieved limited metadata: "+nodeRef+" ["+model+"]");
        }
        
        return model;
    }
    catch (InvalidNodeRefException inre)
    {
        logger.error("Unable to find node: "+inre.getNodeRef());
        throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find nodeRef: "+inre.getNodeRef());
    }
}
 
Example 22
Project: alfresco-remote-api   File: LinkGet.java   Source Code and License 6 votes vote down vote up
@Override
protected Map<String, Object> executeImpl(SiteInfo site, String linkName,
      WebScriptRequest req, JSONObject json, Status status, Cache cache) 
{
   Map<String, Object> model = new HashMap<String, Object>();
   
   // Try to find the link
   LinkInfo link = linksService.getLink(site.getShortName(), linkName);
   if (link == null)
   {
      String message = "No link found with that name";
      throw new WebScriptException(Status.STATUS_NOT_FOUND, message);
   }
   
   // Build the model
   model.put(PARAM_ITEM, renderLink(link));
   model.put("node", link.getNodeRef());
   model.put("link", link);
   model.put("site", site);
   model.put("siteId", site.getShortName());
   
   // All done
   return model;
}
 
Example 23
Project: alfresco-remote-api   File: ShareContentPost.java   Source Code and License 6 votes vote down vote up
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
{
    if (! isEnabled())
    {
        throw new WebScriptException(HttpServletResponse.SC_FORBIDDEN, "QuickShare is disabled system-wide");
    }
    
    // create map of params (template vars)
    Map<String, String> params = req.getServiceMatch().getTemplateVars();
    final NodeRef nodeRef = WebScriptUtil.getNodeRef(params);
    if (nodeRef == null)
    {
        String msg = "A valid NodeRef must be specified!";
        throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, msg);
    }
    
    try
    {
        QuickShareDTO dto = quickShareService.shareContent(nodeRef);
        
        Map<String, Object> model = new HashMap<String, Object>(1);
        model.put("sharedDTO", dto);
        return model;
    }
    catch (InvalidNodeRefException inre)
    {
    	throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find node: " + nodeRef);
    }
}
 
Example 24
Project: alfresco-remote-api   File: QuickShareMetaDataGet.java   Source Code and License 6 votes vote down vote up
@Override
protected Map<String, Object> executeImpl(final WebScriptRequest req, Status status, Cache cache)
{
    if (! isEnabled())
    {
        throw new WebScriptException(HttpServletResponse.SC_FORBIDDEN, "QuickShare is disabled system-wide");
    }
    
    // create map of params (template vars)
    Map<String, String> params = req.getServiceMatch().getTemplateVars();
    final String sharedId = params.get("shared_id");
    if (sharedId == null)
    {
        throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, "A valid sharedId must be specified !");
    }
    
    try
    {
        return quickShareService.getMetaData(sharedId);
    }
    catch (InvalidSharedIdException ex)
    {
        logger.error("Unable to find: "+sharedId);
        throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find: "+sharedId);
    }
    catch (InvalidNodeRefException inre)
    {
        logger.error("Unable to find: "+sharedId+" ["+inre.getNodeRef()+"]");
        throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find: "+sharedId);
    }
}
 
Example 25
Project: alfresco-remote-api   File: UserCalendarEntriesGet.java   Source Code and License 6 votes vote down vote up
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req,
      Status status, Cache cache) 
{
   Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
   
   // Site is optional
   SiteInfo site = null;
   String siteName = templateVars.get("site");
   if (siteName != null)
   {
      site = siteService.getSite(siteName);
      
      // MNT-3053 fix, siteName was provided in request but it doesn't exists or user has no permissions to access it.
      if (site == null)
      {
          status.setCode(HttpServletResponse.SC_NOT_FOUND, "Site '" + siteName + "' does not exist or user has no permissions to access it.");
          return null;
      }
   }
   
   return executeImpl(site, null, req, null, status, cache);
}
 
Example 26
Project: alfresco-remote-api   File: SolrFacetConfigAdminPost.java   Source Code and License 6 votes vote down vote up
@Override
protected Map<String, Object> unprotectedExecuteImpl(WebScriptRequest req, Status status, Cache cache)
{
    try
    {
        SolrFacetProperties fp = parseRequestForFacetProperties(req);
        facetService.createFacetNode(fp);

        if (logger.isDebugEnabled())
        {
            logger.debug("Created facet node: " + fp);
        }
    }
    catch (Throwable t)
    {
        throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Could not save the facet configuration.", t);
    }

    return new HashMap<>(); // Needs to be mutable.
}
 
Example 27
Project: alfresco-remote-api   File: ResourceWebScriptPut.java   Source Code and License 6 votes vote down vote up
/**
 * Returns the input stream for the request
 * @param req WebScriptRequest
 * @return InputStream
 */
private InputStream getStream(WebScriptRequest req)
{
    try
    {
        if (req instanceof WebScriptServletRequest)
        {
            WebScriptServletRequest servletRequest = (WebScriptServletRequest) req;
            return servletRequest.getHttpServletRequest().getInputStream();
        }
        else if (req instanceof WrappingWebScriptRequest)
        {
            // eg. BufferredRequest
            WrappingWebScriptRequest wrappedRequest = (WrappingWebScriptRequest) req;
            return wrappedRequest.getContent().getInputStream();
        }
    }
    catch (IOException error)
    {
        logger.warn("Failed to get the input stream.", error);
    }

    return null;
}
 
Example 28
Project: alfresco-remote-api   File: AbstractAuditWebScript.java   Source Code and License 6 votes vote down vote up
/**
 * Get the entry id from the request.
 * 
 * @return Returns the id or <tt>null</tt> if not present
 */
protected Long getId(WebScriptRequest req)
{
    Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
    String id = templateVars.get("id");
    if (id == null || id.length() == 0)
    {
        return null;
    }
    else
    {
        try
        {
            return Long.parseLong(id);
        }
        catch (NumberFormatException e)
        {
            return null;
        }
    }
}
 
Example 29
Project: alfresco-remote-api   File: AbstractAuditWebScript.java   Source Code and License 6 votes vote down vote up
/**
 * Get the path from the request.
 * 
 * @return                  Returns the path or <tt>null</tt> if not present
 */
protected String getParamPath(WebScriptRequest req)
{
    Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
    String paramPath = templateVars.get(PARAM_PATH);
    if (paramPath == null || paramPath.length() == 0)
    {
        paramPath = null;
    }
    else if (!paramPath.startsWith("/"))
    {
        // It won't ever, so we can expect to be here all the time
        paramPath = "/" + paramPath;
    }
    return paramPath;
}
 
Example 30
Project: alfresco-remote-api   File: Login.java   Source Code and License 6 votes vote down vote up
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status)
{
    // extract username and password
    String username = req.getParameter("u");
    if (username == null || username.length() == 0)
    {
        throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, "Username not specified");
    }
    String password = req.getParameter("pw");
    if (password == null)
    {
        throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, "Password not specified");
    }

    try
    {
        return login(username, password);
    }
    catch(WebScriptException e)
    {
        status.setCode(e.getStatus());
        status.setMessage(e.getMessage());
        status.setRedirect(true);
        return null;
    }
}
 
Example 31
Project: alfresco-remote-api   File: WorkflowInstanceGet.java   Source Code and License 6 votes vote down vote up
private boolean getIncludeTasks(WebScriptRequest req)
{
    String includeTasks = req.getParameter(PARAM_INCLUDE_TASKS);
    if (includeTasks != null)
    {
        try
        {
            return Boolean.valueOf(includeTasks);
        }
        catch (Exception e)
        {
            // do nothing, false will be returned
        }
    }

    // Defaults to false.
    return false;
}
 
Example 32
Project: Alfresco-Autocad-Viewer   File: HelloWorldWebScript.java   Source Code and License 5 votes vote down vote up
protected Map<String, Object> executeImpl(
        WebScriptRequest req, Status status, Cache cache) {
    Map<String, Object> model = new HashMap<String, Object>();
    model.put("fromJava", "HelloFromJava");

    logger.debug("Your 'Hello World' Web Script was called!");

    return model;
}
 
Example 33
Project: tieto-alfresco-repository_monitor   File: MonitorAclHierarchyWebscript.java   Source Code and License 5 votes vote down vote up
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
	LOGGER.debug("Initiate run calculation");
	
	long requestDepth = acquireLongParameter(req, "depth");
	final NodeRef jobNode = job.createAclHierarchyJob(requestDepth);

	monitorService.runMonitorOperation(jobNode);
	final Map<String, Object> model = new HashMap<>();
	model.put("jobNode", jobNode.toString());
	model.put("depth", String.valueOf(requestDepth));
	
	return model;
}
 
Example 34
Project: alfresco-file-transfer-receiver   File: FileTransferWebScript.java   Source Code and License 5 votes vote down vote up
public void execute(WebScriptRequest req, WebScriptResponse res) throws IOException
{
    if (enabled)
    {
        //log.debug("Transfer webscript invoked by user: " + AuthenticationUtil.getFullyAuthenticatedUser() +
        //        " running as " + AuthenticationUtil.getRunAsAuthentication().getName());
        processCommand(req.getServiceMatch().getTemplateVars().get("command"), req, res);
    }
    else
    {
        res.setStatus(Status.STATUS_NOT_FOUND);
    }
}
 
Example 35
Project: alfresco-remote-api   File: AbstractPropertyGet.java   Source Code and License 5 votes vote down vote up
/**
 * Override method from DeclarativeWebScript
 */
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
{
    Map<String, Object> model = new HashMap<String, Object>(1);
    QName classQname = getClassQname(req);
    QName propertyQname = getPropertyQname(req);

    if (this.dictionaryservice.getClass(classQname).getProperties().get(propertyQname) != null)
    {
        model.put(MODEL_PROP_KEY_PROPERTY_DETAILS, this.dictionaryservice.getClass(classQname).getProperties().get(propertyQname));
        model.put(MODEL_PROP_KEY_MESSAGE_LOOKUP, this.dictionaryservice);
    }

    return model;
}
 
Example 36
Project: alfresco-remote-api   File: PublicApiBrowserCMISDispatcher.java   Source Code and License 5 votes vote down vote up
@Override
protected CMISHttpServletRequest getHttpRequest(WebScriptRequest req)
{
	String serviceName = getServiceName();
	CMISHttpServletRequest httpReqWrapper = new PublicApiCMISHttpServletRequest(req, serviceName,
	        baseUrlGenerator, getBinding(), getCurrentDescriptor(), tenantAdminService);
   	return httpReqWrapper;
}
 
Example 37
Project: alfresco-remote-api   File: CMISDispatcherRegistryImpl.java   Source Code and License 5 votes vote down vote up
@Override
public CMISDispatcher getDispatcher(WebScriptRequest req)
{
	CMISDispatcher dispatcher = null;

	Match match = req.getServiceMatch();
	Map<String, String> templateVars = match.getTemplateVars();
	String bindingStr = templateVars.get("binding");
	String apiVersion = templateVars.get("apiVersion");
	if(bindingStr != null && apiVersion != null)
	{
		Binding binding = null;
		try
		{
			binding = Binding.valueOf(bindingStr);
		}
		catch(IllegalArgumentException e)
		{
			// nothing to do, binding remains null
		}
		
		if(binding != null)
		{
			Endpoint endpoint = new Endpoint(binding, apiVersion);
			dispatcher = registry.get(endpoint);
		}
		else
		{
			// TODO
		}
	}

	return dispatcher;
}
 
Example 38
Project: alfresco-remote-api   File: AssociationGet.java   Source Code and License 5 votes vote down vote up
@Override
protected QName getClassQname(WebScriptRequest req)
{
    String className = req.getServiceMatch().getTemplateVars().get(DICTIONARY_CLASS_NAME);
    
    // validate the classname
    if (isValidClassname(className) == false)
    {
        throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the classname - " + className + " - parameter in the URL");
    }
		
    return QName.createQName(getFullNamespaceURI(className));
}
 
Example 39
Project: alfresco-remote-api   File: AbstractSolrFacetConfigAdminWebScript.java   Source Code and License 5 votes vote down vote up
@Override
protected Map<String, Object> executeImpl(final WebScriptRequest req, final Status status, final Cache cache)
{
    validateCurrentUser();

    return unprotectedExecuteImpl(req, status, cache);
}
 
Example 40
Project: alfresco-remote-api   File: ClassGet.java   Source Code and License 5 votes vote down vote up
/**
 * Override method from AbstractClassGet
 */
@Override
protected QName getClassQname(WebScriptRequest req)
{
    String className = req.getServiceMatch().getTemplateVars().get(DICTIONARY_CLASS_NAME);
    //validate the classname and throw appropriate error message
    if (isValidClassname(className) == false)
    {
        throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the classname - " + className + " - parameter in the URL");
    }
    return QName.createQName(getFullNamespaceURI(className));
}
 
Example 41
Project: alfresco-remote-api   File: SubClassesGet.java   Source Code and License 5 votes vote down vote up
@Override
protected Collection<QName> getQNameCollection(WebScriptRequest req, boolean recursive)
{
    QName classQName = null;
    boolean isAspect = false;
    String className = req.getServiceMatch().getTemplateVars().get(DICTIONARY_CLASS_NAME);
    	
    //validate the className
    if(isValidClassname(className) == true)
    {
        classQName = QName.createQName(getFullNamespaceURI(className));
        if(isValidTypeorAspect(className) == true) 
        {
            isAspect = true;
        }
    }
    else
    {
        throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the className - " + className + " parameter in the URL");
    }
    
    // collect the subaspects or subtypes of the class
    if(isAspect == true) 
    {
        return this.dictionaryservice.getSubAspects(classQName, recursive);
	}
	else
    {
        return this.dictionaryservice.getSubTypes(classQName, recursive);
    }
}
 
Example 42
Project: alfresco-remote-api   File: ResourceWebScriptDelete.java   Source Code and License 5 votes vote down vote up
@Override
public Params extractParams(ResourceMetadata resourceMeta, WebScriptRequest req)
{
    String entityId = req.getServiceMatch().getTemplateVars().get(ResourceLocator.ENTITY_ID);
    String relationshipId = req.getServiceMatch().getTemplateVars().get(ResourceLocator.RELATIONSHIP_ID);
    final Params.RecognizedParams params = getRecognizedParams(req);
    
    switch (resourceMeta.getType())
    {
        case ENTITY:
             // note: entityId can be null - when deleting a set/collection
             return Params.valueOf(params, entityId, relationshipId, req);
        case RELATIONSHIP:
            // note: relationshipId can be null - when deleting a related set/collection
            return Params.valueOf(params, entityId, relationshipId, req);
        case PROPERTY:
            final String resourceName = req.getServiceMatch().getTemplateVars().get(ResourceLocator.RELATIONSHIP_RESOURCE);
            final String propertyName = req.getServiceMatch().getTemplateVars().get(ResourceLocator.PROPERTY);

            if (StringUtils.isNotBlank(entityId) && StringUtils.isNotBlank(resourceName))
            {
                if (StringUtils.isNotBlank(propertyName))
                {
                    return Params.valueOf(entityId, relationshipId, null, null, propertyName, params, null, req);
                }
                else
                {
                    return Params.valueOf(entityId, null, null, null, resourceName, params, null, req);
                }
            }
            //Fall through to unsupported.
        default:
            throw new UnsupportedResourceOperationException("DELETE not supported for Actions");
    }
}
 
Example 43
Project: alfresco-remote-api   File: AssociationsGet.java   Source Code and License 5 votes vote down vote up
@Override
protected QName getClassQname(WebScriptRequest req)
{
    String className = req.getServiceMatch().getTemplateVars().get(DICTIONARY_CLASS_NAME);
    //validate classname
    if (isValidClassname(className) == false)
    {
        throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the classname - " + className + " - parameter in the URL");
    }
    return QName.createQName(getFullNamespaceURI(className));
}
 
Example 44
Project: alfresco-remote-api   File: AbstractSubscriptionServiceWebScript.java   Source Code and License 5 votes vote down vote up
protected PagingRequest createPagingRequest(WebScriptRequest req)
{
    int skipCount = parseNumber("skipCount", req.getParameter("skipCount"), 0);
    int maxItems = parseNumber("maxItems", req.getParameter("maxItems"), -1);

    PagingRequest result = new PagingRequest(skipCount, maxItems, null);
    result.setRequestTotalCountMax(Integer.MAX_VALUE);

    return result;
}
 
Example 45
Project: alfresco-remote-api   File: AbstractArchivedNodeWebScript.java   Source Code and License 5 votes vote down vote up
protected StoreRef parseRequestForStoreRef(WebScriptRequest req)
{
    // get the parameters that represent the StoreRef, we know they are present
    // otherwise this webscript would not have matched
    Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
    String storeType = templateVars.get("store_type");
    String storeId = templateVars.get("store_id");

    // create the StoreRef and ensure it is valid
    StoreRef storeRef = new StoreRef(storeType, storeId);

    return storeRef;
}
 
Example 46
Project: alfresco-remote-api   File: DeclarativeSpreadsheetWebScript.java   Source Code and License 5 votes vote down vote up
/**
 * @see org.springframework.extensions.webscripts.DeclarativeWebScript#executeImpl(org.springframework.extensions.webscripts.WebScriptRequest, org.springframework.extensions.webscripts.Status)
 */
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status)
{
    Map<String, Object> model = new HashMap<String, Object>();
    model.put("success", Boolean.TRUE);
    
    // What format are they after?
    String format = req.getFormat();
    if("csv".equals(format) || "xls".equals(format) ||
       "xlsx".equals(format) || "excel".equals(format))
    {
        // Identify the thing to process
        Object resource = identifyResource(format, req);
    	
        // Generate the spreadsheet
        try
        {
            generateSpreadsheet(resource, format, req, status, model);
            return model;
        }
        catch(IOException e)
        {
            throw new WebScriptException(Status.STATUS_BAD_REQUEST, 
                    "Unable to generate template file", e);
        }
    }
    
    // If we get here, then it isn't a spreadsheet version
    if(allowHtmlFallback())
    {
     // There's some sort of help / upload form
     return model;
    }
    else
    {
       throw new WebScriptException("Web Script format '" + format + "' is not supported");
    }
}
 
Example 47
Project: alfresco-triggerauthenticationsync   File: StartPeopleSyncWebScript.java   Source Code and License 5 votes vote down vote up
@Override
public void execute(final WebScriptRequest request, final WebScriptResponse response) throws IOException {

	final Writer w = response.getWriter();
	String siteId = request.getParameter(PARAM_SITE_ID);
	String role = siteService.getMembersRole(siteId, authenticationService.getCurrentUserName());
	if (authorityService.hasAdminAuthority() || SiteModel.SITE_MANAGER.equals(role)) {

		log.debug("Starting job manually. jobdetailbean=" + jobdetailbean);
		SchedulerFactory schedFact = new StdSchedulerFactory();

		// Create a trigger that fires exactly once, ten seconds from now
		final long startTime = System.currentTimeMillis() + 1000L;
		final SimpleTrigger trigger = new SimpleTrigger("manualTrigger", null, new Date(startTime), null, 0, 0L);

		try {
			final Scheduler s = schedFact.getScheduler();
			s.addJobListener(new ManualJobListener());
			log.debug("trigger: " + trigger + ", scheduler: " + s);

			s.scheduleJob(jobdetailbean, trigger);
			s.start();

			String msgStart = "LDAP Sync triggered at " + new Date(startTime);
			log.info(msgStart);
			w.write(msgStart);

		} catch (final Exception e) {
			log.error("Error while executing " + jobdetailbean + " manually");
			throw new AlfrescoRuntimeException("Error while executing " + jobdetailbean + " manually", e);
		}

	} else {
		String msg = "Only Alfresco Administrators or SiteManagers can trigger ldpa sync action manually.";
		log.error(msg);
		throw new AlfrescoRuntimeException(msg);
	}
}
 
Example 48
Project: alfresco-remote-api   File: WorkflowInstancesGet.java   Source Code and License 5 votes vote down vote up
private Date getDateFromRequest(WebScriptRequest req, String paramName)
{
    String dateParam = req.getParameter(paramName);
    if (dateParam != null)
    {
        if (!EMPTY.equals(dateParam) && !NULL.equals(dateParam))
        {
            return getDateParameter(req, paramName);
        }
    }

    return null;
}
 
Example 49
Project: alfresco-remote-api   File: RuleTypesGet.java   Source Code and License 5 votes vote down vote up
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
{
    Map<String, Object> model = new HashMap<String, Object>();

    // get all rule types
    List<RuleType> ruletypes = ruleService.getRuleTypes();

    model.put("ruletypes", ruletypes);

    return model;
}
 
Example 50
Project: alfresco-remote-api   File: ReplicationServiceStatusGet.java   Source Code and License 5 votes vote down vote up
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
{
    Map<String, Object> model = new HashMap<String, Object>();
    boolean serviceEnabled = replicationService.isEnabled();
    
    model.put(ENABLED, serviceEnabled);
    
    return model;
}
 
Example 51
Project: alfresco-remote-api   File: CMISWebScript.java   Source Code and License 5 votes vote down vote up
public void execute(WebScriptRequest req, WebScriptResponse res) throws IOException
{
    CMISDispatcher dispatcher = registry.getDispatcher(req);
    if(dispatcher == null)
    {
    	res.setStatus(404);	
    }
    else
    {
    	dispatcher.execute(req, res);
    }
}
 
Example 52
Project: alfresco-remote-api   File: RepoRestrictionsGet.java   Source Code and License 5 votes vote down vote up
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
{
    Map<String, Object> model = new HashMap<String, Object>(7);
    
    RepoUsage restrictions = repoAdminService.getRestrictions();
    putUsageInModel(model, restrictions, false);
    
    // Done
    if (logger.isDebugEnabled())
    {
        logger.debug("Result: \n\tRequest: " + req + "\n\tModel: " + model);
    }
    return model;
}
 
Example 53
Project: alfresco-remote-api   File: NodeBrowserPost.java   Source Code and License 5 votes vote down vote up
private static String buildUrl(WebScriptRequest req, Map<String, String> params, String hash)
{
    StringBuilder url = new StringBuilder(256);
    
    url.append(req.getServicePath());
    if (!params.isEmpty())
    {
        boolean first = true;
        for (String key: params.keySet())
        {
            String val = params.get(key);
            if (val != null && val.length() != 0)
            {
                url.append(first ? '?' : '&');
                url.append(key);
                url.append('=');
                url.append(URLEncoder.encode(val));
                first = false;
            }
        }
    }
    if (hash != null && hash.length() != 0)
    {
        url.append('#').append(hash);
    }
    
    return url.toString();
}
 
Example 54
Project: alfresco-remote-api   File: ContentGet.java   Source Code and License 5 votes vote down vote up
/**
 * @see org.springframework.extensions.webscripts.WebScript#execute(WebScriptRequest, WebScriptResponse)
 */
public void execute(WebScriptRequest req, WebScriptResponse res)
    throws IOException
{
    // create map of args
    String[] names = req.getParameterNames();
    Map<String, String> args = new HashMap<String, String>(names.length, 1.0f);
    for (String name : names)
    {
        args.put(name, req.getParameter(name));
    }
    
    // create map of template vars
    Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
    
    // create object reference from url
    ObjectReference reference = createObjectReferenceFromUrl(args, templateVars);
    NodeRef nodeRef = reference.getNodeRef();
    if (nodeRef == null)
    {
        throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find " + reference.toString());
    }
    
    // determine attachment
    boolean attach = Boolean.valueOf(req.getParameter("a"));
    
    // render content
    QName propertyQName = ContentModel.PROP_CONTENT;
    String contentPart = templateVars.get("property");
    if (contentPart.length() > 0 && contentPart.charAt(0) == ';')
    {
        if (contentPart.length() < 2)
        {
            throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, "Content property malformed");
        }
        String propertyName = contentPart.substring(1);
        if (propertyName.length() > 0)
        {
            propertyQName = QName.createQName(propertyName, namespaceService);
        }
    }

    // Stream the content
    streamContentLocal(req, res, nodeRef, attach, propertyQName, null);
}
 
Example 55
Project: alfresco-remote-api   File: RequestReader.java   Source Code and License 5 votes vote down vote up
/**
 * Extracts the body contents from the request as a List, the JSON can be an array or just a single value without the [] symbols
 *
 * @param req          the request
 * @param jsonHelper   Jackson Helper
 * @param requiredType the type to return (without the List param)
 * @return A List of "Object" as the required type
 */
default <T> List<T> extractJsonContentAsList(WebScriptRequest req, JacksonHelper jsonHelper, Class<T> requiredType)
{
    Reader reader;
    try
    {
        reader = req.getContent().getReader();
        return jsonHelper.constructList(reader, requiredType);
    }
    catch (IOException e)
    {
        throw new ApiException("Could not read content from HTTP request body.", e.getCause());
    }
}
 
Example 56
Project: alfresco-remote-api   File: ForumPostRepliesPost.java   Source Code and License 5 votes vote down vote up
@Override
protected Map<String, Object> executeImpl(SiteInfo site, NodeRef nodeRef,
      TopicInfo topic, PostInfo post, WebScriptRequest req, JSONObject json,
      Status status, Cache cache) 
{
   // If they're trying to create a reply to a topic, they actually
   //  mean to create the reply on the primary post
   if (post == null)
   {
      post = discussionService.getPrimaryPost(topic);
      if (post == null)
      {
         throw new WebScriptException(Status.STATUS_PRECONDITION_FAILED,
               "First (primary) post was missing from the topic, can't fetch");
      }
   }
   else if (topic == null)
   {
      String error = "Node was of the wrong type, only Topic and Post are supported";
      throw new WebScriptException(Status.STATUS_BAD_REQUEST, error);
   }
   
   // Have the reply created
   PostInfo reply = doCreatePost(post, topic, req, json);
   
   // Add the activity entry for the reply change
   addActivityEntry("reply", "created", topic, reply, site, req, json);
   
   // Build the common model parts
   Map<String, Object> model = buildCommonModel(site, topic, reply, req);
   
   // Build the JSON for the new reply post
   model.put(KEY_POSTDATA, renderPost(reply, site));
   
   // All done
   return model;
}
 
Example 57
Project: alfresco-remote-api   File: PublicApiRepositoryContainer.java   Source Code and License 5 votes vote down vote up
/**
 * Execute script within required level of transaction
 */
@Override
protected void transactionedExecute(final WebScript script, final WebScriptRequest scriptReq, final WebScriptResponse scriptRes)
    throws IOException
{
    final HttpServletRequest httpServletRequest = WebScriptServletRuntime.getHttpServletRequest(scriptReq);
    if(httpServletRequest instanceof PublicApiHttpServletRequest)
    {
        // reset the request input stream if it has been read e.g. by getParameter
        PublicApiHttpServletRequest publicApiRequest = (PublicApiHttpServletRequest)httpServletRequest;
        publicApiRequest.resetInputStream();
    }

    super.transactionedExecute(script, scriptReq, scriptRes);
}
 
Example 58
Project: alfresco-remote-api   File: BlogPostsPost.java   Source Code and License 5 votes vote down vote up
@Override
protected Map<String, Object> executeImpl(SiteInfo site, NodeRef nodeRef,
     BlogPostInfo blog, WebScriptRequest req, JSONObject json, Status status, Cache cache) 
{
    Map<String, Object> model = new HashMap<String, Object>();
    
    // If they're doing Path Based rather than Site Based, ensure
    //  that the Container is a Tag Scope
    if(site == null && nodeRef != null)
    {
       ensureTagScope(nodeRef);
    }

    // Have the Blog Post created
    JsonParams jsonPostParams = parsePostParams(json);
    BlogPostInfo post = createBlogPost(jsonPostParams, site, nodeRef);
    
    Map<String, Object> blogPostData = BlogPostLibJs.getBlogPostData(post.getNodeRef(), services);
    model.put(ITEM, blogPostData);
    model.put(EXTERNAL_BLOG_CONFIG, BlogPostLibJs.hasExternalBlogConfiguration(nodeRef, services));
    
    boolean isDraft = blogPostData.get("isDraft") != null &&
                      ((Boolean)blogPostData.get("isDraft")).booleanValue();
    if (jsonPostParams.getSite() != null &&
            jsonPostParams.getContainer() != null &&
            jsonPostParams.getPage() != null &&
            !isDraft)
    {
        addActivityEntry("created", post, site, req, json, post.getNodeRef());
    }
    
    return model;
}
 
Example 59
Project: alfresco-remote-api   File: DeclarativeSpreadsheetWebScript.java   Source Code and License 5 votes vote down vote up
@Override
protected Map<String, Object> createTemplateParameters(WebScriptRequest req, WebScriptResponse res,
        Map<String, Object> customParams)
{
    Map<String, Object> model = super.createTemplateParameters(req, res, customParams);
    // We sometimes need to monkey around to do the binary output... 
    model.put("req", req);
    model.put("res", res);
    model.put("writeExcel", new WriteExcel(res, model, req.getFormat(), filenameBase));
    return model;
}
 
Example 60
Project: alfresco-remote-api   File: RatingsGet.java   Source Code and License 5 votes vote down vote up
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
{
    Map<String, Object> model = new HashMap<String, Object>();

    NodeRef nodeRef = parseRequestForNodeRef(req);
    
    // These are the data for the current user's ratings of this node, if any.
    List<Rating> myRatings = new ArrayList<Rating>();
    
    // These maps hold the average rating, accumulated total of all ratings and
    // the number of ratings applied for this node as a function of rating scheme.
    Map<String, Float> averageRatings = new HashMap<String, Float>();
    Map<String, Float> ratingsTotals = new HashMap<String, Float>();
    Map<String, Integer> ratingsCounts = new HashMap<String, Integer>();

    for (String schemeName : ratingService.getRatingSchemes().keySet())
    {
        final Rating ratingByCurrentUser = ratingService.getRatingByCurrentUser(nodeRef, schemeName);
        if (ratingByCurrentUser != null)
        {
            myRatings.add(ratingByCurrentUser);
        }
        averageRatings.put(schemeName, ratingService.getAverageRating(nodeRef, schemeName));
        ratingsTotals.put(schemeName, ratingService.getTotalRating(nodeRef, schemeName));
        ratingsCounts.put(schemeName, ratingService.getRatingsCount(nodeRef, schemeName));
    }

    model.put(NODE_REF, nodeRef.toString());
    model.put(RATINGS, myRatings);
    model.put(AVERAGE_RATINGS, averageRatings);
    model.put(RATINGS_TOTALS, ratingsTotals);
    model.put(RATINGS_COUNTS, ratingsCounts);
  
    return model;
}