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.juneau.rest.server;
018
019import static org.apache.juneau.commons.utils.Shorts.*;
020
021import java.lang.annotation.*;
022
023import org.apache.juneau.commons.*;
024import org.apache.juneau.marshall.encoders.*;
025import org.apache.juneau.marshall.serializer.*;
026import org.apache.juneau.rest.server.converter.*;
027import org.apache.juneau.rest.server.guard.*;
028import org.apache.juneau.rest.server.matcher.*;
029
030/**
031 * Utility classes and methods for the {@link RestPost @RestPost} annotation.
032 *
033 * <h5 class='section'>See Also:</h5><ul>
034 *    <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/RestOpAnnotatedMethods">@RestOp-Annotated Method</a>
035 * </ul>
036 */
037public class RestPostAnnotation {
038
039   /**
040    * Private constructor to prevent instantiation.
041    */
042   private RestPostAnnotation() {
043      // Utility class - prevent instantiation
044   }
045
046   /**
047    * Builder class.
048    *
049    * <h5 class='section'>See Also:</h5><ul>
050    *    <li class='jm'>{@link org.apache.juneau.marshall.MarshallingContext.Builder#annotations(Annotation...)}
051    * </ul>
052    */
053   @SuppressWarnings({
054      "unchecked" // Type erasure requires cast for Builder inheritance
055   })
056   public static class Builder extends AnnotationObject.Builder {
057
058      private String[] description = {};
059      private Class<? extends RestConverter>[] converters = new Class[0];
060      private Class<? extends RestGuard>[] guards = new Class[0];
061      private Class<? extends RestMatcher>[] matchers = new Class[0];
062      private Class<? extends Encoder>[] encoders = new Class[0];
063      private Class<? extends Serializer>[] serializers = new Class[0];
064      private Class<?>[] parsers = {};
065      private OpSwagger swagger = OpSwaggerAnnotation.DEFAULT;
066      private String clientVersion = "";
067      private String defaultAccept = "";
068      private String defaultCharset = "";
069      private String defaultContentType = "";
070      private String maxInput = "";
071      private String observability = "";
072      private String asyncCompletionExecutor = "";
073      private String metricName = "";
074      private String metricTags = "";
075      private String problemDetails = "";
076      private String debugMarshalling = "";
077      private String rolesDeclared = "";
078      private String roleGuard = "";
079      private String summary = "";
080      private String value = "";
081      private String[] consumes = {};
082      private String[] defaultRequestFormData = {};
083      private String[] defaultRequestQueryData = {};
084      private String[] defaultRequestAttributes = {};
085      private String[] defaultRequestHeaders = {};
086      private String[] defaultResponseHeaders = {};
087      private String[] allowedParserOptions = {};
088      private String[] allowedSerializerOptions = {};
089      private String[] noInherit = {};
090      private String[] path = {};
091      private String[] produces = {};
092
093      /**
094       * Constructor.
095       */
096      protected Builder() {
097         super(RestPost.class);
098      }
099
100      /**
101       * Instantiates a new {@link RestPost @RestPost} object initialized with this builder.
102       *
103       * @return A new {@link RestPost @RestPost} object.
104       */
105      public RestPost build() {
106         return new Object(this);
107      }
108
109      /**
110       * Sets the description property on this annotation.
111       *
112       * @param value The new value for this property.
113       * @return This object.
114       */
115      public Builder description(String...value) {
116         description = value;
117         return this;
118      }
119
120      /**
121       * Sets the {@link RestPost#clientVersion()} property on this annotation.
122       *
123       * @param value The new value for this property.
124       * @return This object.
125       */
126      public Builder clientVersion(String value) {
127         clientVersion = value;
128         return this;
129      }
130
131      /**
132       * Sets the {@link RestPost#consumes()} property on this annotation.
133       *
134       * @param value The new value for this property.
135       * @return This object.
136       */
137      public Builder consumes(String...value) {
138         consumes = value;
139         return this;
140      }
141
142      /**
143       * Sets the {@link RestPost#converters()} property on this annotation.
144       *
145       * @param value The new value for this property.
146       * @return This object.
147       */
148      @SafeVarargs
149      public final Builder converters(Class<? extends RestConverter>...value) {
150         converters = value;
151         return this;
152      }
153
154      /**
155       * Sets the {@link RestPost#defaultAccept()} property on this annotation.
156       *
157       * @param value The new value for this property.
158       * @return This object.
159       */
160      public Builder defaultAccept(String value) {
161         defaultAccept = value;
162         return this;
163      }
164
165      /**
166       * Sets the {@link RestPost#defaultCharset()} property on this annotation.
167       *
168       * @param value The new value for this property.
169       * @return This object.
170       */
171      public Builder defaultCharset(String value) {
172         defaultCharset = value;
173         return this;
174      }
175
176      /**
177       * Sets the {@link RestPost#defaultContentType()} property on this annotation.
178       *
179       * @param value The new value for this property.
180       * @return This object.
181       */
182      public Builder defaultContentType(String value) {
183         defaultContentType = value;
184         return this;
185      }
186
187      /**
188       * Sets the {@link RestPost#defaultRequestAttributes()} property on this annotation.
189       *
190       * @param value The new value for this property.
191       * @return This object.
192       */
193      public Builder defaultRequestAttributes(String...value) {
194         defaultRequestAttributes = value;
195         return this;
196      }
197
198      /**
199       * Sets the {@link RestPost#defaultRequestFormData()} property on this annotation.
200       *
201       * @param value The new value for this property.
202       * @return This object.
203       */
204      public Builder defaultRequestFormData(String...value) {
205         defaultRequestFormData = value;
206         return this;
207      }
208
209      /**
210       * Sets the {@link RestPost#defaultRequestHeaders()} property on this annotation.
211       *
212       * @param value The new value for this property.
213       * @return This object.
214       */
215      public Builder defaultRequestHeaders(String...value) {
216         defaultRequestHeaders = value;
217         return this;
218      }
219
220      /**
221       * Sets the {@link RestPost#defaultRequestQueryData()} property on this annotation.
222       *
223       * @param value The new value for this property.
224       * @return This object.
225       */
226      public Builder defaultRequestQueryData(String...value) {
227         defaultRequestQueryData = value;
228         return this;
229      }
230
231      /**
232       * Sets the {@link RestPost#defaultResponseHeaders()} property on this annotation.
233       *
234       * @param value The new value for this property.
235       * @return This object.
236       */
237      public Builder defaultResponseHeaders(String...value) {
238         defaultResponseHeaders = value;
239         return this;
240      }
241
242      /**
243       * Sets the {@link RestPost#encoders()} property on this annotation.
244       *
245       * @param value The new value for this property.
246       * @return This object.
247       */
248      @SafeVarargs
249      public final Builder encoders(Class<? extends Encoder>...value) {
250         encoders = value;
251         return this;
252      }
253
254      /**
255       * Sets the {@link RestPost#guards()} property on this annotation.
256       *
257       * @param value The new value for this property.
258       * @return This object.
259       */
260      @SafeVarargs
261      public final Builder guards(Class<? extends RestGuard>...value) {
262         guards = value;
263         return this;
264      }
265
266      /**
267       * Sets the {@link RestPost#matchers()} property on this annotation.
268       *
269       * @param value The new value for this property.
270       * @return This object.
271       */
272      @SafeVarargs
273      public final Builder matchers(Class<? extends RestMatcher>...value) {
274         matchers = value;
275         return this;
276      }
277
278      /**
279       * Sets the {@link RestPost#maxInput()} property on this annotation.
280       *
281       * @param value The new value for this property.
282       * @return This object.
283       */
284      public Builder maxInput(String value) {
285         maxInput = value;
286         return this;
287      }
288
289      /**
290       * Sets the {@link RestPost#parsers()} property on this annotation.
291       *
292       * @param value The new value for this property.
293       * @return This object.
294       */
295      public Builder parsers(Class<?>...value) {
296         parsers = value;
297         return this;
298      }
299
300      /**
301       * Sets the {@link RestPost#path()} property on this annotation.
302       *
303       * @param value The new value for this property.
304       * @return This object.
305       */
306      public Builder path(String...value) {
307         path = value;
308         return this;
309      }
310
311      /**
312       * Sets the {@link RestPost#problemDetails()} property on this annotation.
313       *
314       * @param value The new value for this property.
315       * @return This object.
316       */
317      public Builder problemDetails(String value) {
318         problemDetails = value;
319         return this;
320      }
321
322      /**
323       * Sets the {@link RestPost#debugMarshalling()} property on this annotation.
324       *
325       * @param value The new value for this property.
326       * @return This object.
327       */
328      public Builder debugMarshalling(String value) {
329         debugMarshalling = value;
330         return this;
331      }
332
333      /**
334       * Sets the {@link RestPost#observability()} property on this annotation.
335       *
336       * @param value The new value for this property.
337       * @return This object.
338       */
339      public Builder observability(String value) {
340         observability = value;
341         return this;
342      }
343
344      /**
345       * Sets the {@link RestPost#asyncCompletionExecutor()} property on this annotation.
346       *
347       * @param value The new value for this property.
348       * @return This object.
349       */
350      public Builder asyncCompletionExecutor(String value) {
351         asyncCompletionExecutor = value;
352         return this;
353      }
354
355      /**
356       * Sets the {@link RestPost#metricName()} property on this annotation.
357       *
358       * @param value The new value for this property.
359       * @return This object.
360       */
361      public Builder metricName(String value) {
362         metricName = value;
363         return this;
364      }
365
366      /**
367       * Sets the {@link RestPost#metricTags()} property on this annotation.
368       *
369       * @param value The new value for this property.
370       * @return This object.
371       */
372      public Builder metricTags(String value) {
373         metricTags = value;
374         return this;
375      }
376
377      /**
378       * Sets the {@link RestPost#produces()} property on this annotation.
379       *
380       * @param value The new value for this property.
381       * @return This object.
382       */
383      public Builder produces(String...value) {
384         produces = value;
385         return this;
386      }
387
388      /**
389       * Sets the {@link RestPost#allowedSerializerOptions()} property on this annotation.
390       *
391       * @param value The new value for this property.
392       * @return This object.
393       */
394      public Builder allowedSerializerOptions(String...value) {
395         allowedSerializerOptions = value;
396         return this;
397      }
398
399      /**
400       * Sets the {@link RestPost#allowedParserOptions()} property on this annotation.
401       *
402       * @param value The new value for this property.
403       * @return This object.
404       */
405      public Builder allowedParserOptions(String...value) {
406         allowedParserOptions = value;
407         return this;
408      }
409
410      /**
411       * Sets the {@link RestPost#noInherit()} property on this annotation.
412       *
413       * @param value The new value for this property.
414       * @return This object.
415       */
416      public Builder noInherit(String...value) {
417         noInherit = value;
418         return this;
419      }
420
421      /**
422       * Sets the {@link RestPost#roleGuard()} property on this annotation.
423       *
424       * @param value The new value for this property.
425       * @return This object.
426       */
427      public Builder roleGuard(String value) {
428         roleGuard = value;
429         return this;
430      }
431
432      /**
433       * Sets the {@link RestPost#rolesDeclared()} property on this annotation.
434       *
435       * @param value The new value for this property.
436       * @return This object.
437       */
438      public Builder rolesDeclared(String value) {
439         rolesDeclared = value;
440         return this;
441      }
442
443      /**
444       * Sets the {@link RestPost#serializers()} property on this annotation.
445       *
446       * @param value The new value for this property.
447       * @return This object.
448       */
449      @SafeVarargs
450      public final Builder serializers(Class<? extends Serializer>...value) {
451         serializers = value;
452         return this;
453      }
454
455      /**
456       * Sets the {@link RestPost#summary()} property on this annotation.
457       *
458       * @param value The new value for this property.
459       * @return This object.
460       */
461      public Builder summary(String value) {
462         summary = value;
463         return this;
464      }
465
466      /**
467       * Sets the {@link RestPost#swagger()} property on this annotation.
468       *
469       * @param value The new value for this property.
470       * @return This object.
471       */
472      public Builder swagger(OpSwagger value) {
473         swagger = value;
474         return this;
475      }
476
477      /**
478       * Sets the {@link RestPost#value()} property on this annotation.
479       *
480       * @param value The new value for this property.
481       * @return This object.
482       */
483      public Builder value(String value) {
484         this.value = value;
485         return this;
486      }
487   }
488
489   @SuppressWarnings({
490      "java:S2160" // equals() inherited from AnnotationObject compares all annotation interface methods; subclass fields are accessed via those methods
491   })
492   private static class Object extends AnnotationObject implements RestPost {
493
494      private final String[] description;
495      private final Class<? extends RestConverter>[] converters;
496      private final Class<? extends RestGuard>[] guards;
497      private final Class<? extends RestMatcher>[] matchers;
498      private final Class<? extends Encoder>[] encoders;
499      private final Class<? extends Serializer>[] serializers;
500      private final Class<?>[] parsers;
501      private final OpSwagger swagger;
502      private final String clientVersion;
503      private final String defaultAccept;
504      private final String defaultCharset;
505      private final String defaultContentType;
506      private final String maxInput;
507      private final String observability;
508      private final String asyncCompletionExecutor;
509      private final String metricName;
510      private final String metricTags;
511      private final String problemDetails;
512      private final String debugMarshalling;
513      private final String rolesDeclared;
514      private final String roleGuard;
515      private final String summary;
516      private final String value;
517      private final String[] consumes;
518      private final String[] defaultRequestFormData;
519      private final String[] defaultRequestQueryData;
520      private final String[] defaultRequestAttributes;
521      private final String[] defaultRequestHeaders;
522      private final String[] defaultResponseHeaders;
523      private final String[] allowedParserOptions;
524      private final String[] allowedSerializerOptions;
525      private final String[] noInherit;
526      private final String[] path;
527      private final String[] produces;
528
529      Object(RestPostAnnotation.Builder b) {
530         super(b);
531         description = cp(b.description);
532         clientVersion = b.clientVersion;
533         consumes = cp(b.consumes);
534         converters = cp(b.converters);
535         defaultAccept = b.defaultAccept;
536         defaultCharset = b.defaultCharset;
537         defaultContentType = b.defaultContentType;
538         defaultRequestFormData = cp(b.defaultRequestFormData);
539         defaultRequestQueryData = cp(b.defaultRequestQueryData);
540         defaultRequestAttributes = cp(b.defaultRequestAttributes);
541         defaultRequestHeaders = cp(b.defaultRequestHeaders);
542         defaultResponseHeaders = cp(b.defaultResponseHeaders);
543         encoders = cp(b.encoders);
544         guards = cp(b.guards);
545         matchers = cp(b.matchers);
546         maxInput = b.maxInput;
547         parsers = cp(b.parsers);
548         allowedParserOptions = cp(b.allowedParserOptions);
549         allowedSerializerOptions = cp(b.allowedSerializerOptions);
550         noInherit = cp(b.noInherit);
551         path = cp(b.path);
552         observability = b.observability;
553         asyncCompletionExecutor = b.asyncCompletionExecutor;
554         metricName = b.metricName;
555         metricTags = b.metricTags;
556         problemDetails = b.problemDetails;
557         debugMarshalling = b.debugMarshalling;
558         produces = cp(b.produces);
559         roleGuard = b.roleGuard;
560         rolesDeclared = b.rolesDeclared;
561         serializers = cp(b.serializers);
562         summary = b.summary;
563         swagger = b.swagger;
564         value = b.value;
565      }
566
567      @Override /* Overridden from RestPost */
568      public String clientVersion() {
569         return clientVersion;
570      }
571
572      @Override /* Overridden from RestPost */
573      public String[] consumes() {
574         return consumes;
575      }
576
577      @Override /* Overridden from RestPost */
578      public Class<? extends RestConverter>[] converters() {
579         return converters;
580      }
581
582      @Override /* Overridden from RestPost */
583      public String defaultAccept() {
584         return defaultAccept;
585      }
586
587      @Override /* Overridden from RestPost */
588      public String defaultCharset() {
589         return defaultCharset;
590      }
591
592      @Override /* Overridden from RestPost */
593      public String defaultContentType() {
594         return defaultContentType;
595      }
596
597      @Override /* Overridden from RestPost */
598      public String[] defaultRequestAttributes() {
599         return defaultRequestAttributes;
600      }
601
602      @Override /* Overridden from RestPost */
603      public String[] defaultRequestFormData() {
604         return defaultRequestFormData;
605      }
606
607      @Override /* Overridden from RestPost */
608      public String[] defaultRequestHeaders() {
609         return defaultRequestHeaders;
610      }
611
612      @Override /* Overridden from RestPost */
613      public String[] defaultRequestQueryData() {
614         return defaultRequestQueryData;
615      }
616
617      @Override /* Overridden from RestPost */
618      public String[] defaultResponseHeaders() {
619         return defaultResponseHeaders;
620      }
621
622      @Override /* Overridden from RestPost */
623      public Class<? extends Encoder>[] encoders() {
624         return encoders;
625      }
626
627      @Override /* Overridden from RestPost */
628      public Class<? extends RestGuard>[] guards() {
629         return guards;
630      }
631
632      @Override /* Overridden from RestPost */
633      public Class<? extends RestMatcher>[] matchers() {
634         return matchers;
635      }
636
637      @Override /* Overridden from RestPost */
638      public String maxInput() {
639         return maxInput;
640      }
641
642      @Override /* Overridden from RestPost */
643      public Class<?>[] parsers() {
644         return parsers;
645      }
646
647      @Override /* Overridden from RestPost */
648      public String[] allowedParserOptions() {
649         return allowedParserOptions;
650      }
651
652      @Override /* Overridden from RestPost */
653      public String[] allowedSerializerOptions() {
654         return allowedSerializerOptions;
655      }
656
657      @Override /* Overridden from RestPost */
658      public String[] noInherit() {
659         return noInherit;
660      }
661
662      @Override /* Overridden from RestPost */
663      public String[] path() {
664         return path;
665      }
666
667      @Override /* Overridden from RestPost */
668      public String observability() {
669         return observability;
670      }
671
672      @Override /* Overridden from RestPost */
673      public String asyncCompletionExecutor() {
674         return asyncCompletionExecutor;
675      }
676
677      @Override /* Overridden from RestPost */
678      public String metricName() {
679         return metricName;
680      }
681
682      @Override /* Overridden from RestPost */
683      public String metricTags() {
684         return metricTags;
685      }
686
687      @Override /* Overridden from RestPost */
688      public String problemDetails() {
689         return problemDetails;
690      }
691
692      @Override /* Overridden from RestPost */
693      public String debugMarshalling() {
694         return debugMarshalling;
695      }
696
697      @Override /* Overridden from RestPost */
698      public String[] produces() {
699         return produces;
700      }
701
702      @Override /* Overridden from RestPost */
703      public String roleGuard() {
704         return roleGuard;
705      }
706
707      @Override /* Overridden from RestPost */
708      public String rolesDeclared() {
709         return rolesDeclared;
710      }
711
712      @Override /* Overridden from RestPost */
713      public Class<? extends Serializer>[] serializers() {
714         return serializers;
715      }
716
717      @Override /* Overridden from RestPost */
718      public String summary() {
719         return summary;
720      }
721
722      @Override /* Overridden from RestPost */
723      public OpSwagger swagger() {
724         return swagger;
725      }
726
727      @Override /* Overridden from RestPost */
728      public String value() {
729         return value;
730      }
731
732      @Override /* Overridden from annotation */
733      public String[] description() {
734         return description;
735      }
736   }
737
738   /** Default value */
739   public static final RestPost DEFAULT = create().build();
740
741   /**
742    * Instantiates a new builder for this class.
743    *
744    * @return A new builder object.
745    */
746   public static Builder create() {
747      return new Builder();
748   }
749}