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 Read Operation type in API descriptor.
23 *
24 */
25 @JsonDeserialize(builder = Read.Builder.class)
26 public final class Read extends Operation {
27
28 /**
29 * Protected contstructor of the Operation.
30 *
31 * @param builder Operation Builder
32 */
33 private Read(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 read() {
42 return new Builder();
43 }
44
45 /**
46 * Allocates the Read 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.read(this);
52 }
53
54 /**
55 * Builds a Read object from the data in the read annotation.
56 * @param read Read annotation that holds 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 Read instance
60 */
61 public static Read fromAnnotation(org.forgerock.api.annotations.Read read, ApiDescription descriptor,
62 Class<?> relativeType) {
63 return read()
64 .detailsFromAnnotation(read.operationDescription(), descriptor, relativeType)
65 .build();
66 }
67
68 /**
69 * Builder to help construct the Read.
70 */
71 public static final class Builder extends Operation.Builder<Builder> {
72
73 /**
74 * Returns the builder instance.
75 * @return Builder
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 Read build() {
88 return new Read(this);
89 }
90 }
91
92 }