org.springframework.extensions.webscripts.WebScriptRequest Java Examples

The following examples show how to use org.springframework.extensions.webscripts.WebScriptRequest. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BulkFilesystemImportStatusWebScript.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 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 #2
Source File: PropertyGet.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
protected QName getPropertyQname(WebScriptRequest req)
{
    String propertyName = req.getServiceMatch().getTemplateVars().get(DICTIONARY_SHORTPROPERTY_NAME);
    String propertyPrefix = req.getServiceMatch().getTemplateVars().get(DICTIONARY_PROPERTY_FREFIX);
    
    //validate the presence of property name
    if(propertyName == null)
    {
        throw new WebScriptException(Status.STATUS_NOT_FOUND, "Missing parameter short propertyname in the URL");
    }
    //validate the presence of property prefix
    if(propertyPrefix == null)
    {
        throw new WebScriptException(Status.STATUS_NOT_FOUND, "Missing parameter propertyprefix in the URL");
    }
    
    return QName.createQName(getFullNamespaceURI(propertyPrefix, propertyName));
}
 
Example #3
Source File: ContentGet.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected void streamContentLocal(WebScriptRequest req, WebScriptResponse res, NodeRef nodeRef, boolean attach, QName propertyQName, Map<String, Object> model) throws IOException
{
    String userAgent = req.getHeader("User-Agent");
    userAgent = userAgent != null ? userAgent.toLowerCase() : "";
    boolean rfc5987Supported = (userAgent.contains("msie") ||
            userAgent.contains(" trident/") ||
            userAgent.contains(" chrome/") ||
            userAgent.contains(" firefox/") ||
            userAgent.contains(" safari/"));

    if (attach && rfc5987Supported)
    {
        String name = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_NAME);
        
        // maintain the original name of the node during the download - do not modify it - see MNT-16510
        streamContent(req, res, nodeRef, propertyQName, attach, name, model);
    }
    else
    {
        streamContent(req, res, nodeRef, propertyQName, attach, null, model);
    }
}
 
Example #4
Source File: AbstractAuditWebScript.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 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 #5
Source File: ForumPostGet.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 6 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) 
{
   // Build the common model parts
   Map<String, Object> model = buildCommonModel(site, topic, post, req);
   
   // Did they want just one post, or the whole of the topic?
   if (post != null)
   {
      model.put(KEY_POSTDATA, renderPost(post, site));
   }
   else if (topic != null)
   {
      model.put(KEY_POSTDATA, renderTopic(topic, site));
   }
   else
   {
      String error = "Node was of the wrong type, only Topic and Post are supported";
      throw new WebScriptException(Status.STATUS_BAD_REQUEST, error);
   }
   
   // All done
   return model;
}
 
Example #6
Source File: RunningActionsGet.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 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 #7
Source File: RunningActionGet.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 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 #8
Source File: LinkGet.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 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 #9
Source File: LargeContentTestPut.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 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 #10
Source File: AbstractClassGet.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 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 #11
Source File: ResourceWebScriptPut.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 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 #12
Source File: SubscriptionServiceUnfollowPost.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 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.unfollow(userId, user);
        }
    }

    return null;
}
 
Example #13
Source File: UserCalendarEntriesGet.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 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 #14
Source File: AbstractArchivedNodeWebScript.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 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 #15
Source File: SubscriptionServicePrivateListPut.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 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 #16
Source File: AbstractRatingWebScript.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 6 votes vote down vote up
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 #17
Source File: TestDeclarativeSpreadsheetWebScriptGet.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
protected List<Pair<QName, Boolean>> buildPropertiesForHeader(Object resource, String format, WebScriptRequest req)
{
    List<Pair<QName,Boolean>> properties = 
            new ArrayList<Pair<QName,Boolean>>(DeclarativeSpreadsheetWebScriptTest.COLUMNS.length);
        boolean required = true;
        for(QName qname : DeclarativeSpreadsheetWebScriptTest.COLUMNS) 
        {
            Pair<QName,Boolean> p = null;
            if(qname != null)
            {
                p = new Pair<QName, Boolean>(qname, required);
            }
            else
            {
                required = false;
            }
            properties.add(p);
        }
        return properties;
}
 
Example #18
Source File: BulkImportResumeWebScript.java    From alfresco-bulk-import with Apache License 2.0 6 votes vote down vote up
/**
 * @see DeclarativeWebScript#executeImpl(WebScriptRequest, Status, Cache)
 */
@Override
protected Map<String, Object> executeImpl(final WebScriptRequest request, final Status status, final Cache cache)
{
    Map<String, Object> result = new HashMap<>();

    cache.setNeverCache(true);
    
    if (importer.getStatus().isPaused())
    {
        result.put("result", "resume requested");
        importer.resume();
        status.setCode(Status.STATUS_ACCEPTED, "Resume requested.");
        status.setRedirect(true);  // Make sure the custom 202 status template is used (why this is needed at all is beyond me...)
    }
    else
    {
        result.put("result", "no imports in progress");
        status.setCode(Status.STATUS_BAD_REQUEST, "No bulk imports are in progress.");
    }
    
    return(result);
}
 
Example #19
Source File: RatingDelete.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 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>();

    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 #20
Source File: ReplicationDefinitionDelete.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 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"
       );
    }
    
    // Delete it
    replicationService.deleteReplicationDefinition(replicationDefinition);
    
    // Report that we have deleted it
    status.setCode(Status.STATUS_NO_CONTENT);
    status.setMessage("Replication Definition deleted");
    status.setRedirect(true);
    return null;
}
 
Example #21
Source File: ForumPostRepliesPost.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 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 #22
Source File: RecognizedParamsExtractorTest.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
private WebScriptRequest mockRequest(final Map<String,List<String>> params)
{
    final String[] paramNames = params.keySet().toArray(new String[]{});
    WebScriptRequest request = mock(WebScriptRequest.class);
    when(request.getParameterNames()).thenReturn(paramNames);
    when(request.getParameterValues(anyString())).thenAnswer(new Answer<String[]>() {
        @Override
        public String[] answer(InvocationOnMock invocation) throws Throwable {
            Object[] args = invocation.getArguments();
            return params.get((String) args[0]).toArray(new String[]{});
        }
    });
    return request;
}
 
Example #23
Source File: NodeLocatorGet.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
private Map<String, Serializable> mapParams(WebScriptRequest req)
{
    Map<String, Serializable> params = new HashMap<String, Serializable>();
    for (String key: req.getParameterNames())
    {
        String value = req.getParameter(key);
        if (value != null)
        {
            String decodedValue = URLDecoder.decode(value);
            // TODO Handle type conversions here.
            params.put(key, decodedValue);
        }
    }
    return params;
}
 
Example #24
Source File: WorkflowInstanceDiagramGet.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void execute(WebScriptRequest req, WebScriptResponse res) throws IOException
{
    Map<String, String> params = req.getServiceMatch().getTemplateVars();

    // getting workflow instance id from request parameters
    String workflowInstanceId = params.get("workflow_instance_id");
    
    WorkflowInstance workflowInstance = workflowService.getWorkflowById(workflowInstanceId);

    // workflow instance was not found -> return 404
    if (workflowInstance == null)
    {
        throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find workflow instance with id: " + workflowInstanceId);
    }
    
    // check whether there is a diagram available
    if (!workflowService.hasWorkflowImage(workflowInstanceId))
    {
        throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find diagram for workflow instance with id: " + workflowInstanceId);
    }
    
    // copy image data into temporary file
    File file = TempFileProvider.createTempFile("workflow-diagram-", ".png");
    InputStream imageData = workflowService.getWorkflowImage(workflowInstanceId);
    OutputStream os = new FileOutputStream(file);
    FileCopyUtils.copy(imageData, os);
    
    // stream temporary file back to client
    streamContent(req, res, file);
}
 
Example #25
Source File: TestCredentialsCommandProcessor.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
public int process(WebScriptRequest req, WebScriptResponse resp)
{
    //Since all the checks that are needed are actually carried out by the transfer web script, this processor
    //effectively becomes a no-op.
    int result = Status.STATUS_OK;
    resp.setStatus(result);
    return result;
}
 
Example #26
Source File: RuleTypesGet.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 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 #27
Source File: ReadGet.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 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
    {
        boolean canRead = quickShareService.canRead(sharedId);
        Map<String, Object> result = new HashMap<String, Object>();
        result.put("canRead", canRead);
        return result;            
    }
    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 #28
Source File: SerializerTestHelper.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
public SearchQuery extractFromJson(String json) throws IOException
{
    Content content = mock(Content.class);
    when(content.getReader()).thenReturn(new StringReader(json));
    WebScriptRequest request = mock(WebScriptRequest.class);
    when(request.getContent()).thenReturn(content);
    return extractJsonContent(request, jsonHelper, SearchQuery.class);
}
 
Example #29
Source File: RunningActionDelete.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 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");

   // Check it exists
   ExecutionSummary action = 
      getSummaryFromKey(actionTrackingId);
   if(action == null) {
      throw new WebScriptException(
            Status.STATUS_NOT_FOUND, 
            "No Running Action found with that tracking id"
      );
   }
   
   ExecutionDetails details =
      actionTrackingService.getExecutionDetails(action);
   if(details == null) {
      throw new WebScriptException(
            Status.STATUS_NOT_FOUND, 
            "No Running Action found with that tracking id"
      );
   }
   
   // Request the cancel
   actionTrackingService.requestActionCancellation(action);
   
   // Report it as having been cancelled
   status.setCode(Status.STATUS_NO_CONTENT);
   status.setMessage("Action cancellation requested");
   status.setRedirect(true);
   return null;
}
 
Example #30
Source File: NextTransactionGet.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status)
{
    Long fromCommitTime = Long.parseLong(req.getParameter("fromCommitTime"));
    
    Map<String, Object> model = new HashMap<>();
    model.put("nextTransactionCommitTimeMs", nodeDAO.getNextTxCommitTime(fromCommitTime));
    return model;
}