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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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));
}