001/*
002 * The contents of this file are subject to the terms of the Common Development and
003 * Distribution License (the License). You may not use this file except in compliance with the
004 * License.
005 *
006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
007 * specific language governing permission and limitations under the License.
008 *
009 * When distributing Covered Software, include this CDDL Header Notice in each file and include
010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
011 * Header, with the fields enclosed by brackets [] replaced by your own identifying
012 * information: "Portions copyright [year] [name of copyright owner]".
013 *
014 * Copyright 2016 ForgeRock AS.
015 */
016
017package org.forgerock.api.models;
018
019import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
020
021/**
022 * Class that represents the Read Operation type in API descriptor.
023 *
024 */
025@JsonDeserialize(builder = Read.Builder.class)
026public final class Read extends Operation {
027
028    /**
029     * Protected contstructor of the Operation.
030     *
031     * @param builder Operation Builder
032     */
033    private Read(Builder builder) {
034        super(builder);
035    }
036
037    /**
038     * Creates a new builder for Operation.
039     * @return New builder instance
040     */
041    public static final Builder read() {
042        return new Builder();
043    }
044
045    /**
046     * Allocates the Read operation type to the given Resource Builder.
047     * @param resourceBuilder - Resource Builder to add the operation
048     */
049    @Override
050    protected void allocateToResource(Resource.Builder resourceBuilder) {
051        resourceBuilder.read(this);
052    }
053
054    /**
055     * Builds a Read object from the data in the read annotation.
056     * @param read Read annotation that holds the data
057     * @param descriptor The root descriptor to add definitions to.
058     * @param relativeType The type relative to which schema resources should be resolved.
059     * @return Read instance
060     */
061    public static Read fromAnnotation(org.forgerock.api.annotations.Read read, ApiDescription descriptor,
062            Class<?> relativeType) {
063        return read()
064                .detailsFromAnnotation(read.operationDescription(), descriptor, relativeType)
065                .build();
066    }
067
068    /**
069     * Builder to help construct the Read.
070     */
071    public static final class Builder extends Operation.Builder<Builder> {
072
073        /**
074         * Returns the builder instance.
075         * @return Builder
076         */
077        @Override
078        protected Builder self() {
079            return this;
080        }
081
082        /**
083         * Builds the Create instance.
084         *
085         * @return Create instance
086         */
087        public Read build() {
088            return new Read(this);
089        }
090    }
091
092}