All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.covisint.platform.oauth.client.granttype.certificate.CertificateGrantTypeClientBuilder Maven / Gradle / Ivy

/* 
 * Copyright 2015 Covisint
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


package com.covisint.platform.oauth.client.granttype.certificate;

import static com.covisint.platform.oauth.core.SupportedMediaType.CERTIFICATE_GRANT_MT;
import static com.damnhandy.uri.template.UriTemplateBuilder.var;

import com.covisint.core.http.service.client.BaseResourceClientBuilder;
import com.covisint.core.support.constraint.Nonnull;
import com.covisint.core.support.constraint.NotEmpty;
import com.damnhandy.uri.template.MalformedUriTemplateException;
import com.damnhandy.uri.template.UriTemplate;
import com.google.common.net.MediaType;

/** Build class for {@link CertificateGrantTypeClient}s. */
public class CertificateGrantTypeClientBuilder extends
        BaseResourceClientBuilder {

    /** Base path to the resource collection endpoint. */
    private static final String RESOURCE_COLLECTION_PATH = "/";

    /** Media type of a version certificate grant resource representation. */
    private static final MediaType MEDIA_TYPE = MediaType.parse(CERTIFICATE_GRANT_MT.value());

    /** {@inheritDoc} */
    @Nonnull @NotEmpty 
    protected String getResourceCollectionPath() {
        return RESOURCE_COLLECTION_PATH;
    }

    /** {@inheritDoc} */
    @Nonnull 
    protected MediaType getResourceRepresentation() {
        return MEDIA_TYPE;
    }

    /**
     * Returns the certificate grantTyp retrieval end point.
     * 
     * @return the certificate grantTyp retrieval end point.
     */
    @Nonnull 
    protected final UriTemplate getCertificateGrantTypeByIdEndpoint() {

        try {
            return UriTemplate.buildFromTemplate(getServiceBaseUrl()).literal("/subjects").path(var("subjectId"))
                    .literal("/grants").path(var("grantTypeId")).build();
        } catch (final MalformedUriTemplateException e) {
            throw new IllegalStateException("Error creating retrieval endpoint template", e);
        }
    }

    /**
     * Returns the certificate grantTyp search end point.
     * 
     * @return the certificate grantTyp search end point.
     */
    @Nonnull 
    protected final UriTemplate getCertificateGrantTypeEndpoint() {

        try {
            return UriTemplate.buildFromTemplate(getServiceBaseUrl()).literal("/subjects").path(var("subjectId"))
                    .literal("/grants").build();
        } catch (final MalformedUriTemplateException e) {
            throw new IllegalStateException("Error creating search endpoint template", e);
        }
    }

    /**
     * Returns the certificate grantTyp add end point.
     * 
     * @return the certificate grantTyp add end point.
     */
    @Nonnull 
    protected final UriTemplate getCertificateGrantTypeAddEndpoint() {

        try {
            return UriTemplate.buildFromTemplate(getServiceBaseUrl()).literal("/subjects").path(var("subjectId"))
                    .literal("/grants").build();
        } catch (final MalformedUriTemplateException e) {
            throw new IllegalStateException("Error creating add endpoint template", e);
        }
    }

    /**
     * Returns the certificate grantTyp deletion end point.
     * 
     * @return the certificate grantTyp deletion end point.
     */
    @Nonnull 
    protected final UriTemplate getCertificateGrantTypeDeleteEndpoint() {

        try {
            return UriTemplate.buildFromTemplate(getServiceBaseUrl()).literal("/subjects").path(var("subjectId"))
                    .literal("/grants").path(var("grantTypeId")).build();
        } catch (final MalformedUriTemplateException e) {
            throw new IllegalStateException("Error creating modification endpoint template", e);
        }
    }

    /** {@inheritDoc} */
    @Nonnull 
    public CertificateGrantTypeClientImpl build() {
        final CertificateGrantTypeClientImpl impl = populateBaseBuilder(new CertificateGrantTypeClientImpl());
        impl.setGetCertificateGrantTypeUriTemplate(getCertificateGrantTypeByIdEndpoint());
        impl.setSearchCertificateGrantTypeUriTemplate(getCertificateGrantTypeEndpoint());
        impl.setPostCertificateGrantTypeUriTemplate(getCertificateGrantTypeAddEndpoint());
        impl.setDeleteCertificateGrantTypeUriTemplate(getCertificateGrantTypeDeleteEndpoint());
        return impl;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy