com.covisint.platform.oauth.client.granttype.clientsecret.ClientSecretGrantTypeClientBuilder 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.clientsecret;
import static com.covisint.platform.oauth.core.SupportedMediaType.CLIENT_SECRET_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 ClientSecretGrantTypeClient}s. */
public class ClientSecretGrantTypeClientBuilder extends
BaseResourceClientBuilder {
/** Base path to the resource collection endpoint. */
private static final String RESOURCE_COLLECTION_PATH = "/";
/** Media type of a version client secret grant resource representation. */
private static final MediaType MEDIA_TYPE = MediaType.parse(CLIENT_SECRET_GRANT_MT.value());
/** {@inheritDoc} */
@Nonnull @NotEmpty
protected String getResourceCollectionPath() {
return RESOURCE_COLLECTION_PATH;
}
/** {@inheritDoc} */
@Nonnull
protected MediaType getResourceRepresentation() {
return MEDIA_TYPE;
}
/**
* Returns the client secret grantTyp retrieval end point.
*
* @return the client secret grantTyp retrieval end point.
*/
@Nonnull
protected final UriTemplate getClientSecretGrantTypeByIdEndpoint() {
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 client secret grantTyp search end point.
*
* @return the client secret grantTyp search end point.
*/
@Nonnull
protected final UriTemplate getClientSecretGrantTypeEndpoint() {
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 client secret grantTyp add end point.
*
* @return the client secret grantTyp add end point.
*/
@Nonnull
protected final UriTemplate getClientSecretGrantTypeAddEndpoint() {
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 client secret grantTyp deletion end point.
*
* @return the client secret grantTyp deletion end point.
*/
@Nonnull
protected final UriTemplate getClientSecretGrantTypeDeleteEndpoint() {
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 ClientSecretGrantTypeClientImpl build() {
final ClientSecretGrantTypeClientImpl impl = populateBaseBuilder(new ClientSecretGrantTypeClientImpl());
impl.setGetClientSecretGrantTypeUriTemplate(getClientSecretGrantTypeByIdEndpoint());
impl.setSearchClientSecretGrantTypeUriTemplate(getClientSecretGrantTypeEndpoint());
impl.setPostClientSecretGrantTypeUriTemplate(getClientSecretGrantTypeAddEndpoint());
impl.setDeleteClientSecretGrantTypeUriTemplate(getClientSecretGrantTypeDeleteEndpoint());
return impl;
}
}