001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.camel.model;
018
019import java.util.function.Supplier;
020
021import javax.xml.bind.annotation.XmlAccessType;
022import javax.xml.bind.annotation.XmlAccessorType;
023import javax.xml.bind.annotation.XmlAttribute;
024import javax.xml.bind.annotation.XmlRootElement;
025import javax.xml.bind.annotation.XmlTransient;
026
027import org.apache.camel.AggregationStrategy;
028import org.apache.camel.spi.Metadata;
029
030/**
031 * The Claim Check EIP allows you to replace message content with a claim check
032 * (a unique key), which can be used to retrieve the message content at a later
033 * time.
034 */
035@Metadata(label = "eip,routing")
036@XmlRootElement(name = "claimCheck")
037@XmlAccessorType(XmlAccessType.FIELD)
038public class ClaimCheckDefinition extends NoOutputDefinition<ClaimCheckDefinition> {
039
040    @XmlAttribute(required = true)
041    @Metadata(enums = "Get,GetAndRemove,Set,Push,Pop", javaType = "org.apache.camel.model.ClaimCheckOperation")
042    private String operation;
043    @XmlAttribute
044    private String key;
045    @XmlAttribute
046    private String filter;
047    @XmlAttribute(name = "strategyRef")
048    @Metadata(label = "advanced")
049    private String aggregationStrategyRef;
050    @XmlAttribute(name = "strategyMethodName")
051    @Metadata(label = "advanced")
052    private String aggregationStrategyMethodName;
053    @XmlTransient
054    private AggregationStrategy aggregationStrategy;
055
056    public ClaimCheckDefinition() {
057    }
058
059    @Override
060    public String toString() {
061        if (operation != null) {
062            return "ClaimCheck[" + operation + "]";
063        } else {
064            return "ClaimCheck";
065        }
066    }
067
068    @Override
069    public String getShortName() {
070        return "claimCheck";
071    }
072
073    @Override
074    public String getLabel() {
075        return "claimCheck";
076    }
077
078    // Fluent API
079    // -------------------------------------------------------------------------
080
081    /**
082     * The claim check operation to use. The following operations is supported:
083     * <ul>
084     * <li>Get</li> - Gets (does not remove) the claim check by the given key.
085     * <li>GetAndRemove</li> - Gets and remove the claim check by the given key.
086     * <li>Set</li> - Sets a new (will override if key already exists) claim
087     * check with the given key.
088     * <li>Push</li> - Sets a new claim check on the stack (does not use key).
089     * <li>Pop</li> - Gets the latest claim check from the stack (does not use
090     * key).
091     * </ul>
092     */
093    public ClaimCheckDefinition operation(ClaimCheckOperation operation) {
094        return operation(operation.name());
095    }
096
097    /**
098     * The claim check operation to use. The following operations is supported:
099     * <ul>
100     * <li>Get</li> - Gets (does not remove) the claim check by the given key.
101     * <li>GetAndRemove</li> - Gets and remove the claim check by the given key.
102     * <li>Set</li> - Sets a new (will override if key already exists) claim
103     * check with the given key.
104     * <li>Push</li> - Sets a new claim check on the stack (does not use key).
105     * <li>Pop</li> - Gets the latest claim check from the stack (does not use
106     * key).
107     * </ul>
108     */
109    public ClaimCheckDefinition operation(String operation) {
110        setOperation(operation);
111        return this;
112    }
113
114    /**
115     * To use a specific key for claim check id (for dynamic keys use simple
116     * language syntax as the key).
117     */
118    public ClaimCheckDefinition key(String key) {
119        setKey(key);
120        return this;
121    }
122
123    /**
124     * Specified a filter to control what data gets merging data back from the
125     * claim check repository. The following syntax is supported:
126     * <ul>
127     * <li>body</li> - to aggregate the message body
128     * <li>attachments</li> - to aggregate all the message attachments
129     * <li>headers</li> - to aggregate all the message headers
130     * <li>header:pattern</li> - to aggregate all the message headers that
131     * matches the pattern.
132     * </ul>
133     * The pattern uses the following rules are applied in this order:
134     * <ul>
135     * <li>exact match, returns true</li>
136     * <li>wildcard match (pattern ends with a * and the name starts with the
137     * pattern), returns true</li>
138     * <li>regular expression match, returns true</li>
139     * <li>otherwise returns false</li>
140     * </ul>
141     * <p>
142     * You can specify multiple rules separated by comma. For example to include
143     * the message body and all headers starting with foo
144     * <tt>body,header:foo*</tt>. The syntax supports the following prefixes
145     * which can be used to specify include,exclude, or remove
146     * <ul>
147     * <li>+</li> - to include (which is the default mode)
148     * <li>-</li> - to exclude (exclude takes precedence over include)
149     * <li>--</li> - to remove (remove takes precedence)
150     * </ul>
151     * For example to exclude a header name foo, and remove all headers starting
152     * with bar <tt>-header:foo,--headers:bar*</tt> Note you cannot have both
153     * include and exclude <tt>header:pattern</tt> at the same time.
154     */
155    public ClaimCheckDefinition filter(String filter) {
156        setFilter(filter);
157        return this;
158    }
159
160    /**
161     * To use a custom {@link AggregationStrategy} instead of the default
162     * implementation. Notice you cannot use both custom aggregation strategy
163     * and configure data at the same time.
164     */
165    public ClaimCheckDefinition aggregationStrategy(AggregationStrategy aggregationStrategy) {
166        setAggregationStrategy(aggregationStrategy);
167        return this;
168    }
169
170    /**
171     * To use a custom {@link AggregationStrategy} instead of the default
172     * implementation. Notice you cannot use both custom aggregation strategy
173     * and configure data at the same time.
174     */
175    public ClaimCheckDefinition aggregationStrategy(Supplier<AggregationStrategy> aggregationStrategy) {
176        setAggregationStrategy(aggregationStrategy.get());
177        return this;
178    }
179
180    /**
181     * To use a custom {@link AggregationStrategy} instead of the default
182     * implementation. Notice you cannot use both custom aggregation strategy
183     * and configure data at the same time.
184     */
185    public ClaimCheckDefinition aggregationStrategyRef(String aggregationStrategyRef) {
186        setAggregationStrategyRef(aggregationStrategyRef);
187        return this;
188    }
189
190    /**
191     * This option can be used to explicit declare the method name to use, when
192     * using POJOs as the AggregationStrategy.
193     */
194    public ClaimCheckDefinition aggregationStrategyMethodName(String aggregationStrategyMethodName) {
195        setAggregationStrategyMethodName(aggregationStrategyMethodName);
196        return this;
197    }
198
199    // Properties
200    // -------------------------------------------------------------------------
201
202    public String getKey() {
203        return key;
204    }
205
206    public void setKey(String key) {
207        this.key = key;
208    }
209
210    public String getOperation() {
211        return operation;
212    }
213
214    public void setOperation(String operation) {
215        this.operation = operation;
216    }
217
218    public String getFilter() {
219        return filter;
220    }
221
222    public void setFilter(String filter) {
223        this.filter = filter;
224    }
225
226    public String getAggregationStrategyRef() {
227        return aggregationStrategyRef;
228    }
229
230    public void setAggregationStrategyRef(String aggregationStrategyRef) {
231        this.aggregationStrategyRef = aggregationStrategyRef;
232    }
233
234    public String getAggregationStrategyMethodName() {
235        return aggregationStrategyMethodName;
236    }
237
238    public void setAggregationStrategyMethodName(String aggregationStrategyMethodName) {
239        this.aggregationStrategyMethodName = aggregationStrategyMethodName;
240    }
241
242    public AggregationStrategy getAggregationStrategy() {
243        return aggregationStrategy;
244    }
245
246    public void setAggregationStrategy(AggregationStrategy aggregationStrategy) {
247        this.aggregationStrategy = aggregationStrategy;
248    }
249}