Esempio n. 1
0
 public ChainTypeImpl(AutomationService service, OperationChain chain) {
   this.service = service;
   operations =
       chain.getOperations().toArray(new OperationParameters[chain.getOperations().size()]);
   id = chain.getId();
   aliases = chain.getAliases();
   chainParameters = chain.getChainParameters();
   this.chain = chain;
 }
  @OperationMethod
  public DocumentModelList run(DocumentModel context) throws Exception {

    DocumentModel favorites = favoritesManager.getFavorites(context, session);

    Map<String, Object> vars = ctx.getVars();
    vars.put("searchTerm", favorites.getId());
    vars.put("providerName", CollectionConstants.COLLECTION_CONTENT_PAGE_PROVIDER);

    OperationContext subctx = new OperationContext(ctx.getCoreSession(), vars);

    OperationChain chain = new OperationChain("operation");
    OperationParameters oparams = new OperationParameters(DocumentPageProviderOperation.ID, vars);
    chain.add(oparams);
    return (PaginableDocumentModelListImpl) service.run(subctx, chain);
  }
 public DocumentModelList getPageProviderDocs(
     CoreSession session,
     final String providerName,
     final String queryParams,
     final int pageSize) {
   OperationContext ctx = new OperationContext(session);
   OperationChain chain = new OperationChain(providerName + "_" + session.getSessionId());
   chain
       .add(DocumentPageProviderOperation.ID)
       .set("providerName", providerName)
       .set("queryParams", queryParams)
       .set("pageSize", new Integer(pageSize));
   try {
     return (DocumentModelList) Framework.getService(AutomationService.class).run(ctx, chain);
   } catch (Exception e) {
     LOG.error(e, e);
     return new DocumentModelListImpl();
   }
 }
Esempio n. 4
0
 public AutomationInfo(AutomationService service) {
   ops = service.getDocumentation();
   // build a map for easy lookup
   Map<String, OperationDocumentation> map = new HashMap<String, OperationDocumentation>();
   for (OperationDocumentation doc : ops) {
     map.put(doc.id, doc);
   }
   chains = new ArrayList<OperationDocumentation>();
   for (OperationChain chain : service.getOperationChains()) {
     OperationDocumentation doc = new OperationDocumentation(chain.getId());
     doc.description = chain.getDescription();
     doc.category = "Chain";
     doc.label = doc.id;
     doc.params = Collections.emptyList();
     // compute chain signature
     List<OperationParameters> ops = chain.getOperations();
     if (ops.isEmpty()) {
       doc.signature = new String[] {"void", "void"};
     } else if (ops.size() == 1) {
       OperationDocumentation opdoc = map.get(ops.get(0).id());
       doc.signature = opdoc.signature;
     } else {
       ArrayList<String[]> sigs = new ArrayList<String[]>();
       for (OperationParameters o : ops) {
         sigs.add(map.get(o.id()).signature);
       }
       String[] head = sigs.get(0);
       ArrayList<String> rs = new ArrayList<String>();
       for (int i = 0; i < head.length; i += 2) {
         String in = head[i];
         String out = head[i + 1];
         List<String> result = new ArrayList<String>();
         checkPath(out, sigs, 1, result);
         for (String r : result) {
           rs.add(in);
           rs.add(r);
         }
       }
       doc.signature = rs.toArray(new String[rs.size()]);
     }
     chains.add(doc);
   }
 }
 @Test
 public void testGetUserTasks() throws Exception {
   OperationContext ctx = new OperationContext(coreSession);
   ctx.setInput(document);
   automationService.run(ctx, "createSingleTaskChain");
   ctx.clear();
   OperationChain chain = new OperationChain("test");
   chain.add(GetUserTasks.ID);
   Blob blob = (Blob) automationService.run(ctx, chain);
   JSONArray rows = JSONArray.fromObject(blob.getString());
   assertEquals(1, rows.size());
   JSONObject obj = rows.getJSONObject(0);
   assertNotNull(obj.get("id")); // can be 1 or 2 depending
   assertEquals(obj.get("docref"), document.getRef().toString());
   assertEquals(obj.get("name"), "single test task");
   assertEquals(obj.get("directive"), "test directive");
   assertEquals(obj.get("comment"), "test comment");
   assertNotNull(obj.get("startDate"));
   assertNotNull(obj.get("dueDate"));
   assertTrue((Boolean) obj.get("expired"));
 }