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

com.genability.client.api.request.AccountAnalysisRequest Maven / Gradle / Ivy

The newest version!
package com.genability.client.api.request;

import java.io.IOException;
import java.io.Serializable;
import java.util.List;

import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.joda.time.LocalDate;
import org.joda.time.tz.DateTimeZoneBuilder;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.genability.client.types.PropertyData;
import com.genability.client.types.TariffRate;

public class AccountAnalysisRequest extends AbstractRequest implements Serializable {
	
	/*
	 * This special timezone is used to indicate that a particular datetime should be
	 * serialized as a date only (i.e. exclude the time portion of the DateTime)
	 */
	private static final DateTimeZone DATE_ONLY_TIMEZONE = new DateTimeZoneBuilder()
			.toDateTimeZone("Genability LocalDate Signal", true);
	private static final long serialVersionUID = 1L;

	private String providerAccountId;
	private String accountId;
	private Boolean populateCosts;
	private Boolean useIntelligentBaselining;

	private DateTime fromDateTime;
	private DateTime toDateTime;

	private List propertyInputs;

	private List rateInputs;

	public String getProviderAccountId() {
		return providerAccountId;
	}

	public void setProviderAccountId(String providerAccountId) {
		this.providerAccountId = providerAccountId;
	}

	public String getAccountId() {
		return accountId;
	}

	public void setAccountId(String accountId) {
		this.accountId = accountId;
	}

	public Boolean getPopulateCosts() {
		return populateCosts;
	}

	public void setPopulateCosts(final boolean populateCosts) {
		this.populateCosts = populateCosts;
	}

	public Boolean getUseIntelligentBaselining() { return useIntelligentBaselining; }

	public void setUseIntelligentBaselining(final boolean useIb) { this.useIntelligentBaselining = useIb; }

	@JsonSerialize(using=DateTimeSerializer.class)
	public DateTime getFromDateTime() {
		return fromDateTime;
	}

	 /**
	 * This method is used to set the fromDateTime as a date only. The resulting request will include the following:
	 * "fromDateTime":"YYYY-MM-DD"
	 * 
	 * @param year The year.
	 * @param month The month.
	 * @param day The day.
	 */
	@JsonIgnore
	 public void setFromDateTime(int year, int month, int day) {
		setFromDateTime(new LocalDate(year, month, day));
	 }

	 /**
	 * This method is used to set the fromDateTime as a date only. The resulting request will include the following:
	 * "fromDateTime":"YYYY-MM-DD"
	 * 
	 * @param date The date.
	 */
	@JsonIgnore
	 public void setFromDateTime(LocalDate date) {
		 fromDateTime = convertLocalDate(date);
	 }

	 @JsonProperty
	 public void setFromDateTime(DateTime fromDateTime) {
		 this.fromDateTime = fromDateTime;
	 }

	 @JsonSerialize(using=DateTimeSerializer.class)
	 public DateTime getToDateTime() {
		 return toDateTime;
	 }

	 /**
	 * This method is used to set the toDateTime as a date only. The resulting request will include the following:
	 * "toDateTime":"YYYY-MM-DD"
	 * 
	 * @param year The year.
	 * @param month The month.
	 * @param day The day.
	 */
	@JsonIgnore
	 public void setToDateTime(int year, int month, int day) {
		 setToDateTime(new LocalDate(year, month, day));
	 }

	 /**
	 * This method is used to set the toDateTime as a date only. The resulting request will include the following:
	 * "toDateTime":"YYYY-MM-DD"
	 * 
	 * @param date The date.
	 */
	@JsonIgnore
	 public void setToDateTime(LocalDate date) {
		 toDateTime = convertLocalDate(date);
	 }

	 @JsonProperty
	 public void setToDateTime(DateTime toDateTime) {
		 this.toDateTime = toDateTime;
	 }

	 public List getRateInputs() {
		 return rateInputs;
	 }

	 public void setRateInputs(List rateInputs) {
		 this.rateInputs = rateInputs;
	 }

	 public List getPropertyInputs() {
		 return propertyInputs;
	 }

	 public void setPropertyInputs(List propertyInputs) {
		 this.propertyInputs = propertyInputs;
	 }

	 private DateTime convertLocalDate(LocalDate date) {
		 DateTime dt = new DateTime(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth(), 0, 0, DATE_ONLY_TIMEZONE);
		 return dt;
	 }
	 
	 /*		
	  * This class is used to serialize DateTime objects. In the special case where the timeZone is set to		
	  * AccountAnalysisRequest.DATE_ONLY_TIMEZONE, the result will contain the date only		
	  */
	 private static class DateTimeSerializer extends JsonSerializer {

		 @Override
		 public void serialize(DateTime value, JsonGenerator jgen,
				 SerializerProvider provider) throws IOException,
				 JsonProcessingException {

			 if (DATE_ONLY_TIMEZONE.equals(value.getZone())) {
				 LocalDate date = new LocalDate(value.getYear(), value.getMonthOfYear(), value.getDayOfMonth());
				 jgen.writeObject(date);
			 } else {
				 jgen.writeObject(value);
			 }

		 }
	 }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy