/**
* Copyright (C) 2014 - present by OpenGamma Inc. and the OpenGamma group of companies
*
* Please see distribution for license.
*/
package com.opengamma.sesame.server;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Set;
import org.joda.beans.Bean;
import org.joda.beans.BeanDefinition;
import org.joda.beans.ImmutableBean;
import org.joda.beans.JodaBeanUtils;
import org.joda.beans.MetaProperty;
import org.joda.beans.Property;
import org.joda.beans.PropertyDefinition;
import org.joda.beans.impl.direct.DirectFieldsBeanBuilder;
import org.joda.beans.impl.direct.DirectMetaBean;
import org.joda.beans.impl.direct.DirectMetaProperty;
import org.joda.beans.impl.direct.DirectMetaPropertyMap;
import com.google.common.collect.ImmutableList;
import com.opengamma.sesame.config.ViewConfig;
/**
* A request for function execution.
* <p>
* The request contains details of what columns should be in the view, the valuation
* time and market data to be used and the securities (or trades or portfolios) for
* which calculations need to be performed. Note that the latter is optional as it
* is possible to specify a view which contains only non-portfolio outputs.
*
* @param <T> the cycle option type
* @deprecated only used by the deprecated {@link FunctionServer} {@code execute} methods, the replacement methods
* use individual arguments instead of a request object
*/
@Deprecated
@BeanDefinition
public final class FunctionServerRequest<T extends CycleOptions>
implements ImmutableBean {
/**
* The configuration for the view to be executed.
*/
@PropertyDefinition(validate = "notNull")
private final ViewConfig _viewConfig;
/**
* The cycle options used to control how the view is run.
*/
@PropertyDefinition(validate = "notNull")
private final T _cycleOptions;
/**
* The inputs for which the view is to be executed, may be empty.
*/
// TODO - should this be on the cycle options?
@PropertyDefinition(validate = "notNull")
private final List<Object> _inputs;
// todo - request should carry user information as well
//------------------------- AUTOGENERATED START -------------------------
///CLOVER:OFF
/**
* The meta-bean for {@code FunctionServerRequest}.
* @return the meta-bean, not null
*/
@SuppressWarnings("rawtypes")
public static FunctionServerRequest.Meta meta() {
return FunctionServerRequest.Meta.INSTANCE;
}
/**
* The meta-bean for {@code FunctionServerRequest}.
* @param <R> the bean's generic type
* @param cls the bean's generic type
* @return the meta-bean, not null
*/
@SuppressWarnings("unchecked")
public static <R extends CycleOptions> FunctionServerRequest.Meta<R> metaFunctionServerRequest(Class<R> cls) {
return FunctionServerRequest.Meta.INSTANCE;
}
static {
JodaBeanUtils.registerMetaBean(FunctionServerRequest.Meta.INSTANCE);
}
/**
* Returns a builder used to create an instance of the bean.
* @param <T> the type
* @return the builder, not null
*/
public static <T extends CycleOptions> FunctionServerRequest.Builder<T> builder() {
return new FunctionServerRequest.Builder<T>();
}
private FunctionServerRequest(
ViewConfig viewConfig,
T cycleOptions,
List<Object> inputs) {
JodaBeanUtils.notNull(viewConfig, "viewConfig");
JodaBeanUtils.notNull(cycleOptions, "cycleOptions");
JodaBeanUtils.notNull(inputs, "inputs");
this._viewConfig = viewConfig;
this._cycleOptions = cycleOptions;
this._inputs = ImmutableList.copyOf(inputs);
}
@SuppressWarnings("unchecked")
@Override
public FunctionServerRequest.Meta<T> metaBean() {
return FunctionServerRequest.Meta.INSTANCE;
}
@Override
public <R> Property<R> property(String propertyName) {
return metaBean().<R>metaProperty(propertyName).createProperty(this);
}
@Override
public Set<String> propertyNames() {
return metaBean().metaPropertyMap().keySet();
}
//-----------------------------------------------------------------------
/**
* Gets the configuration for the view to be executed.
* @return the value of the property, not null
*/
public ViewConfig getViewConfig() {
return _viewConfig;
}
//-----------------------------------------------------------------------
/**
* Gets the cycle options used to control how the view is run.
* @return the value of the property, not null
*/
public T getCycleOptions() {
return _cycleOptions;
}
//-----------------------------------------------------------------------
/**
* Gets the inputs.
* @return the value of the property, not null
*/
public List<Object> getInputs() {
return _inputs;
}
//-----------------------------------------------------------------------
/**
* Returns a builder that allows this bean to be mutated.
* @return the mutable builder, not null
*/
public Builder<T> toBuilder() {
return new Builder<T>(this);
}
@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (obj != null && obj.getClass() == this.getClass()) {
FunctionServerRequest<?> other = (FunctionServerRequest<?>) obj;
return JodaBeanUtils.equal(getViewConfig(), other.getViewConfig()) &&
JodaBeanUtils.equal(getCycleOptions(), other.getCycleOptions()) &&
JodaBeanUtils.equal(getInputs(), other.getInputs());
}
return false;
}
@Override
public int hashCode() {
int hash = getClass().hashCode();
hash = hash * 31 + JodaBeanUtils.hashCode(getViewConfig());
hash = hash * 31 + JodaBeanUtils.hashCode(getCycleOptions());
hash = hash * 31 + JodaBeanUtils.hashCode(getInputs());
return hash;
}
@Override
public String toString() {
StringBuilder buf = new StringBuilder(128);
buf.append("FunctionServerRequest{");
buf.append("viewConfig").append('=').append(getViewConfig()).append(',').append(' ');
buf.append("cycleOptions").append('=').append(getCycleOptions()).append(',').append(' ');
buf.append("inputs").append('=').append(JodaBeanUtils.toString(getInputs()));
buf.append('}');
return buf.toString();
}
//-----------------------------------------------------------------------
/**
* The meta-bean for {@code FunctionServerRequest}.
* @param <T> the type
*/
public static final class Meta<T extends CycleOptions> extends DirectMetaBean {
/**
* The singleton instance of the meta-bean.
*/
@SuppressWarnings("rawtypes")
static final Meta INSTANCE = new Meta();
/**
* The meta-property for the {@code viewConfig} property.
*/
private final MetaProperty<ViewConfig> _viewConfig = DirectMetaProperty.ofImmutable(
this, "viewConfig", FunctionServerRequest.class, ViewConfig.class);
/**
* The meta-property for the {@code cycleOptions} property.
*/
@SuppressWarnings({"unchecked", "rawtypes" })
private final MetaProperty<T> _cycleOptions = (DirectMetaProperty) DirectMetaProperty.ofImmutable(
this, "cycleOptions", FunctionServerRequest.class, Object.class);
/**
* The meta-property for the {@code inputs} property.
*/
@SuppressWarnings({"unchecked", "rawtypes" })
private final MetaProperty<List<Object>> _inputs = DirectMetaProperty.ofImmutable(
this, "inputs", FunctionServerRequest.class, (Class) List.class);
/**
* The meta-properties.
*/
private final Map<String, MetaProperty<?>> _metaPropertyMap$ = new DirectMetaPropertyMap(
this, null,
"viewConfig",
"cycleOptions",
"inputs");
/**
* Restricted constructor.
*/
private Meta() {
}
@Override
protected MetaProperty<?> metaPropertyGet(String propertyName) {
switch (propertyName.hashCode()) {
case 1970035271: // viewConfig
return _viewConfig;
case 1940313816: // cycleOptions
return _cycleOptions;
case -1183866391: // inputs
return _inputs;
}
return super.metaPropertyGet(propertyName);
}
@Override
public FunctionServerRequest.Builder<T> builder() {
return new FunctionServerRequest.Builder<T>();
}
@SuppressWarnings({"unchecked", "rawtypes" })
@Override
public Class<? extends FunctionServerRequest<T>> beanType() {
return (Class) FunctionServerRequest.class;
}
@Override
public Map<String, MetaProperty<?>> metaPropertyMap() {
return _metaPropertyMap$;
}
//-----------------------------------------------------------------------
/**
* The meta-property for the {@code viewConfig} property.
* @return the meta-property, not null
*/
public MetaProperty<ViewConfig> viewConfig() {
return _viewConfig;
}
/**
* The meta-property for the {@code cycleOptions} property.
* @return the meta-property, not null
*/
public MetaProperty<T> cycleOptions() {
return _cycleOptions;
}
/**
* The meta-property for the {@code inputs} property.
* @return the meta-property, not null
*/
public MetaProperty<List<Object>> inputs() {
return _inputs;
}
//-----------------------------------------------------------------------
@Override
protected Object propertyGet(Bean bean, String propertyName, boolean quiet) {
switch (propertyName.hashCode()) {
case 1970035271: // viewConfig
return ((FunctionServerRequest<?>) bean).getViewConfig();
case 1940313816: // cycleOptions
return ((FunctionServerRequest<?>) bean).getCycleOptions();
case -1183866391: // inputs
return ((FunctionServerRequest<?>) bean).getInputs();
}
return super.propertyGet(bean, propertyName, quiet);
}
@Override
protected void propertySet(Bean bean, String propertyName, Object newValue, boolean quiet) {
metaProperty(propertyName);
if (quiet) {
return;
}
throw new UnsupportedOperationException("Property cannot be written: " + propertyName);
}
}
//-----------------------------------------------------------------------
/**
* The bean-builder for {@code FunctionServerRequest}.
* @param <T> the type
*/
public static final class Builder<T extends CycleOptions> extends DirectFieldsBeanBuilder<FunctionServerRequest<T>> {
private ViewConfig _viewConfig;
private T _cycleOptions;
private List<Object> _inputs = new ArrayList<Object>();
/**
* Restricted constructor.
*/
private Builder() {
}
/**
* Restricted copy constructor.
* @param beanToCopy the bean to copy from, not null
*/
private Builder(FunctionServerRequest<T> beanToCopy) {
this._viewConfig = beanToCopy.getViewConfig();
this._cycleOptions = beanToCopy.getCycleOptions();
this._inputs = new ArrayList<Object>(beanToCopy.getInputs());
}
//-----------------------------------------------------------------------
@Override
public Object get(String propertyName) {
switch (propertyName.hashCode()) {
case 1970035271: // viewConfig
return _viewConfig;
case 1940313816: // cycleOptions
return _cycleOptions;
case -1183866391: // inputs
return _inputs;
default:
throw new NoSuchElementException("Unknown property: " + propertyName);
}
}
@SuppressWarnings("unchecked")
@Override
public Builder<T> set(String propertyName, Object newValue) {
switch (propertyName.hashCode()) {
case 1970035271: // viewConfig
this._viewConfig = (ViewConfig) newValue;
break;
case 1940313816: // cycleOptions
this._cycleOptions = (T) newValue;
break;
case -1183866391: // inputs
this._inputs = (List<Object>) newValue;
break;
default:
throw new NoSuchElementException("Unknown property: " + propertyName);
}
return this;
}
@Override
public Builder<T> set(MetaProperty<?> property, Object value) {
super.set(property, value);
return this;
}
@Override
public Builder<T> setString(String propertyName, String value) {
setString(meta().metaProperty(propertyName), value);
return this;
}
@Override
public Builder<T> setString(MetaProperty<?> property, String value) {
super.setString(property, value);
return this;
}
@Override
public Builder<T> setAll(Map<String, ? extends Object> propertyValueMap) {
super.setAll(propertyValueMap);
return this;
}
@Override
public FunctionServerRequest<T> build() {
return new FunctionServerRequest<T>(
_viewConfig,
_cycleOptions,
_inputs);
}
//-----------------------------------------------------------------------
/**
* Sets the {@code viewConfig} property in the builder.
* @param viewConfig the new value, not null
* @return this, for chaining, not null
*/
public Builder<T> viewConfig(ViewConfig viewConfig) {
JodaBeanUtils.notNull(viewConfig, "viewConfig");
this._viewConfig = viewConfig;
return this;
}
/**
* Sets the {@code cycleOptions} property in the builder.
* @param cycleOptions the new value, not null
* @return this, for chaining, not null
*/
public Builder<T> cycleOptions(T cycleOptions) {
JodaBeanUtils.notNull(cycleOptions, "cycleOptions");
this._cycleOptions = cycleOptions;
return this;
}
/**
* Sets the {@code inputs} property in the builder.
* @param inputs the new value, not null
* @return this, for chaining, not null
*/
public Builder<T> inputs(List<Object> inputs) {
JodaBeanUtils.notNull(inputs, "inputs");
this._inputs = inputs;
return this;
}
/**
* Sets the {@code inputs} property in the builder
* from an array of objects.
* @param inputs the new value, not null
* @return this, for chaining, not null
*/
public Builder<T> inputs(Object... inputs) {
return inputs(Arrays.asList(inputs));
}
//-----------------------------------------------------------------------
@Override
public String toString() {
StringBuilder buf = new StringBuilder(128);
buf.append("FunctionServerRequest.Builder{");
buf.append("viewConfig").append('=').append(JodaBeanUtils.toString(_viewConfig)).append(',').append(' ');
buf.append("cycleOptions").append('=').append(JodaBeanUtils.toString(_cycleOptions)).append(',').append(' ');
buf.append("inputs").append('=').append(JodaBeanUtils.toString(_inputs));
buf.append('}');
return buf.toString();
}
}
///CLOVER:ON
//-------------------------- AUTOGENERATED END --------------------------
}