View Javadoc
1   package com.kodexa.client.pipeline;
2   
3   import com.kodexa.client.Document;
4   import com.kodexa.client.store.DataStore;
5   import lombok.Getter;
6   import lombok.Setter;
7   
8   import java.util.*;
9   import java.util.stream.Collectors;
10  
11  /**
12   * The pipeline context is used to manage state through a running
13   * pipeline
14   */
15  public class PipelineContext {
16  
17      /**
18       * The available stores
19       */
20      public Map<String, DataStore> stores = new HashMap<String, DataStore>();
21  
22      /**
23       * The last document to be processed
24       */
25      private Document document;
26  
27      /**
28       * The parameters that were passed to the pipeline
29       */
30      @Getter
31      @Setter
32      private List<PipelineParameter> parameters = new ArrayList<>();
33  
34      /**
35       * Get a specific store
36       *
37       * @param name the name of the store to get
38       * @return The instance of the store (or null if not found)
39       */
40      public DataStore getStore(String name) {
41          return stores.get(name);
42      }
43  
44      /**
45       * Return a set of the names of the stores in the pipeline
46       *
47       * @return set of names
48       */
49      public Set<String> getStoreNames() {
50          return stores.keySet();
51      }
52  
53      /**
54       * Add the given store to the pipeline context
55       *
56       * @param name  the name of the store
57       * @param store The implementation of the store
58       */
59      public void addStore(String name, DataStore store) {
60          stores.put(name, store);
61      }
62  
63      /**
64       * Sets the final output document for the pipeline
65       *
66       * @param document the final output document
67       */
68      public void setOutputDocument(Document document) {
69          this.document = document;
70      }
71  
72      /**
73       * Returns the final output document, or null if there isn't one
74       *
75       * @return final output document
76       */
77      public Document getOutputDocument() {
78          return this.document;
79      }
80  
81      public Map<String, Object> getParameterMap() {
82          return this.parameters.stream()
83                  .collect(Collectors.toMap(PipelineParameter::getName, PipelineParameter::getValue));
84      }
85  }