Call.java
/*
* Copyright 2019 Global Crop Diversity Trust
*
* 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 org.genesys.brapi.model;
import java.util.Arrays;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMethod;
/**
* The BrAPI Call.
*/
public class Call {
private static final String BRAPI_CALL_PREFIX = "/brapi/v1/";
/** The call. */
private String call;
/** The data types. */
private String[] dataTypes;
/** The methods. */
private RequestMethod[] methods;
/** The Constant versions. */
private final String[] versions = { "1.3" };
public Call(String apiPrefix, String endpoint, RequestMethod[] requestMethods, String[] dataTypes) {
this.call = apiPrefix.concat(endpoint);
if (this.call.startsWith(BRAPI_CALL_PREFIX)) {
this.call = this.call.substring(BRAPI_CALL_PREFIX.length());
}
this.methods = requestMethods;
this.dataTypes = dataTypes;
if (this.dataTypes == null || this.dataTypes.length == 0) {
this.dataTypes = new String[] { MediaType.APPLICATION_JSON_VALUE };
}
}
/**
* Gets the call.
*
* @return the call
*/
public String getCall() {
return call;
}
/**
* Sets the call.
*
* @param call the new call
*/
public void setCall(String call) {
this.call = call;
}
/**
* Gets the data types.
*
* @return the data types
*/
public String[] getDataTypes() {
return dataTypes;
}
/**
* Sets the data types.
*
* @param dataTypes the new data types
*/
public void setDataTypes(String[] dataTypes) {
this.dataTypes = dataTypes;
}
/**
* Gets the methods.
*
* @return the methods
*/
public RequestMethod[] getMethods() {
return methods;
}
/**
* Sets the methods.
*
* @param methods the new methods
*/
public void setMethods(RequestMethod[] methods) {
this.methods = methods;
}
/**
* Gets the versions.
*
* @return the versions
*/
public String[] getVersions() {
return versions;
}
@Override
public String toString() {
return "" + call + " " + Arrays.toString(methods) + " dataTypes=" + Arrays.toString(dataTypes);
}
}