View Javadoc
1   /*
2    * The contents of this file are subject to the terms of the Common Development and
3    * Distribution License (the License). You may not use this file except in compliance with the
4    * License.
5    *
6    * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
7    * specific language governing permission and limitations under the License.
8    *
9    * When distributing Covered Software, include this CDDL Header Notice in each file and include
10   * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
11   * Header, with the fields enclosed by brackets [] replaced by your own identifying
12   * information: "Portions copyright [year] [name of copyright owner]".
13   *
14   * Copyright 2016 ForgeRock AS.
15   */
16  
17  package org.forgerock.api.models;
18  
19  import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
20  
21  /**
22   * Class that represents the Create Operation type in API descriptor.
23   *
24   */
25  @JsonDeserialize(builder = Update.Builder.class)
26  public final class Update extends Operation {
27  
28      /**
29       * Protected contstructor of the Operation.
30       *
31       * @param builder Operation Builder
32       */
33      private Update(Builder builder) {
34          super(builder);
35      }
36  
37      /**
38       * Creates a new builder for Operation.
39       * @return New builder instance
40       */
41      public static final Builder update() {
42          return new Builder();
43      }
44  
45      /**
46       * Allocates the Update operation type to the given Resource Builder.
47       * @param resourceBuilder - Resource Builder to add the operation
48       */
49      @Override
50      protected void allocateToResource(Resource.Builder resourceBuilder) {
51          resourceBuilder.update(this);
52      }
53  
54      /**
55       * Builds an Update object from the data stored in the annotation.
56       * @param update Update annotation that stores the data
57       * @param descriptor The root descriptor to add definitions to.
58       * @param relativeType The type relative to which schema resources should be resolved.
59       * @return Update instance
60       */
61      public static Update fromAnnotation(org.forgerock.api.annotations.Update update, ApiDescription descriptor,
62              Class<?> relativeType) {
63          return update()
64                  .detailsFromAnnotation(update.operationDescription(), descriptor, relativeType)
65                  .build();
66      }
67  
68      /**
69       * Builder to help construct Update.
70       */
71      public static final class Builder extends Operation.Builder<Builder> {
72  
73          private Builder() {
74              super();
75          }
76  
77          @Override
78          protected Builder self() {
79              return this;
80          }
81  
82          /**
83           * Builds the Create instance.
84           *
85           * @return Create instance
86           */
87          public Update build() {
88              return new Update(this);
89          }
90      }
91  
92  }