
com.vendasta.accountgroup.v1.internal.Account Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of accountgroup.v1 Show documentation
Show all versions of accountgroup.v1 Show documentation
Java SDK for service account-group
The newest version!
package com.vendasta.accountgroup.v1.internal;
import java.util.List;
import java.util.ArrayList;
import java.util.Date;
import java.util.Map;
import java.util.HashMap;
import java.util.Collections;
import java.util.Arrays;
import java.time.Duration;
import org.apache.commons.lang3.StringUtils;
import com.vendasta.accountgroup.v1.generated.ApiProto;
/**
* A representation of a single account on an Account Group
**/
public final class Account {
private final boolean isTrial;
private final List tags;
private final String marketplaceAppId;
private final String accountId;
private final Date expiry;
private final String editionId;
private Account (
final boolean isTrial,
final List tags,
final String marketplaceAppId,
final String accountId,
final Date expiry,
final String editionId)
{
this.isTrial = isTrial;
this.tags = tags;
this.marketplaceAppId = marketplaceAppId;
this.accountId = accountId;
this.expiry = expiry;
this.editionId = editionId;
}
/**
* Whether the account is a trial account or not
* @return The final value of isTrial on the object
**/
public boolean getIsTrial() {
return this.isTrial;
}
/**
* Tags on the account
* @return The final value of tags on the object
**/
public List getTags() {
return this.tags;
}
/**
* The marketplace app id or the legacy product id the account belongs to
* @return The final value of marketplaceAppId on the object
**/
public String getMarketplaceAppId() {
return this.marketplaceAppId;
}
/**
* Account ID of this account
* @return The final value of accountId on the object
**/
public String getAccountId() {
return this.accountId;
}
/**
* The date on which the account expires
* @return The final value of expiry on the object
**/
public Date getExpiry() {
return this.expiry;
}
/**
* The id of the edition associated with the marketplace_app_id that was activated on the account group.
* @return The final value of editionId on the object
**/
public String getEditionId() {
return this.editionId;
}
public static class Builder {
private boolean isTrial;
private List tags;
private String marketplaceAppId;
private String accountId;
private Date expiry;
private String editionId;
public Builder() {
this.isTrial = false;
this.tags = new ArrayList();
this.marketplaceAppId = "";
this.accountId = "";
this.expiry = null;
this.editionId = "";
}
/**
* Adds a value to the builder for isTrial
* @param isTrial Value to assign to the mutable Builder
* @return The Builder instance so that call chaining works
**/
public Builder setIsTrial(boolean isTrial) {
this.isTrial = isTrial;
return this;
}
/**
* Adds a value to the builder for tags
* @param tags Value to assign to the mutable Builder
* @return The Builder instance so that call chaining works
**/
public Builder setTags(List tags) {
this.tags = tags;
return this;
}
/**
* Adds a value to the builder for marketplaceAppId
* @param marketplaceAppId Value to assign to the mutable Builder
* @return The Builder instance so that call chaining works
**/
public Builder setMarketplaceAppId(String marketplaceAppId) {
this.marketplaceAppId = marketplaceAppId;
return this;
}
/**
* Adds a value to the builder for accountId
* @param accountId Value to assign to the mutable Builder
* @return The Builder instance so that call chaining works
**/
public Builder setAccountId(String accountId) {
this.accountId = accountId;
return this;
}
/**
* Adds a value to the builder for expiry
* @param expiry Value to assign to the mutable Builder
* @return The Builder instance so that call chaining works
**/
public Builder setExpiry(Date expiry) {
this.expiry = expiry;
return this;
}
/**
* Adds a value to the builder for editionId
* @param editionId Value to assign to the mutable Builder
* @return The Builder instance so that call chaining works
**/
public Builder setEditionId(String editionId) {
this.editionId = editionId;
return this;
}
/**
* Takes the configuration in the mutable Builder and uses it to instantiate a final instance
* of the Account class
* @return The instantiated final Account
**/
public Account build() {
return new Account(
this.isTrial,
this.tags,
this.marketplaceAppId,
this.accountId,
this.expiry,
this.editionId);
}
}
/**
* Returns a Builder for Account, which is a mutable representation of the object. Once the
* client has built up an object they can then create an immutable Account object using the
* build function.
* @return A fresh Builder instance with no values set
**/
public static Builder newBuilder() {
return new Builder();
}
/**
* Provides a human-readable representation of this object. Useful for debugging.
* @return A string representation of the Account instance
**/
public String toString() {
String result = "Account\n";
result += "-> isTrial: (boolean)"
+ StringUtils.join("\n ", Arrays.asList(String.valueOf(this.isTrial).split("\n"))) + "\n";
result += "-> tags: (List)"
+ StringUtils.join("\n ", Arrays.asList(String.valueOf(this.tags).split("\n"))) + "\n";
result += "-> marketplaceAppId: (String)"
+ StringUtils.join("\n ", Arrays.asList(String.valueOf(this.marketplaceAppId).split("\n"))) + "\n";
result += "-> accountId: (String)"
+ StringUtils.join("\n ", Arrays.asList(String.valueOf(this.accountId).split("\n"))) + "\n";
result += "-> expiry: (Date)"
+ StringUtils.join("\n ", Arrays.asList(String.valueOf(this.expiry).split("\n"))) + "\n";
result += "-> editionId: (String)"
+ StringUtils.join("\n ", Arrays.asList(String.valueOf(this.editionId).split("\n"))) + "\n";
return result;
}
/**
* Allows for simple conversion between the low-level generated protobuf object to
* Account, which is much more usable.
* @return An instance of Account representing the input proto object
**/
public static Account fromProto(ApiProto.Account proto) {
Account out = null;
if (proto != null) {
Account.Builder outBuilder = Account.newBuilder()
.setIsTrial(proto.getIsTrial())
.setTags(proto.getTagsList())
.setMarketplaceAppId(proto.getMarketplaceAppId())
.setAccountId(proto.getAccountId())
.setExpiry(proto.hasExpiry()?new Date(proto.getExpiry().getSeconds() * 1000):null)
.setEditionId(proto.getEditionId());
out = outBuilder.build();
}
return out;
}
/**
* Convenience method for handling lists of proto objects. It calls .fromProto on each one
* and returns a list of the converted results.
* @return A list of Account instances representing the input proto objects
**/
public static List fromProtos(List protos) {
List out = new ArrayList();
for(ApiProto.Account proto : protos) {
out.add(Account.fromProto(proto));
}
return out;
}
/**
* Allows for simple conversion of an object to the low-level generated protobuf object.
* @return An instance of ApiProto.Account which is a proto object ready for wire transmission
**/
public ApiProto.Account toProto() {
Account obj = this;
ApiProto.Account.Builder outBuilder = ApiProto.Account.newBuilder();
outBuilder.setIsTrial(obj.getIsTrial());
outBuilder.addAllTags(obj.getTags());
outBuilder.setMarketplaceAppId(obj.getMarketplaceAppId());
outBuilder.setAccountId(obj.getAccountId());
if(obj.getExpiry()!=null){outBuilder.setExpiry(com.google.protobuf.Timestamp.newBuilder().setSeconds(obj.getExpiry().getTime() / 1000).build());}
outBuilder.setEditionId(obj.getEditionId());
return outBuilder.build();
}
/**
* Convenience method for handling lists of objects. It calls .toProto on each one and
* returns a list of the converted results.
* @return A list of ApiProto.Account instances representing the input objects.
*/
public static List toProtos(List objects) {
List out = new ArrayList();
if(objects != null) {
for (Account obj : objects) {
out.add(obj!=null?obj.toProto():null);
}
}
return out;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy