software.tnb.jira.validation.generated.model.SharePermission Maven / Gradle / Ivy
The newest version!
/*
* The Jira Cloud platform REST API
* Jira Cloud platform REST API documentation
*
* The version of the OpenAPI document: 1001.0.0-SNAPSHOT
* Contact: [email protected]
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
package software.tnb.jira.validation.generated.model;
import java.util.Objects;
import com.google.gson.TypeAdapter;
import com.google.gson.annotations.JsonAdapter;
import com.google.gson.annotations.SerializedName;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import java.io.IOException;
import java.util.Arrays;
import software.tnb.jira.validation.generated.model.GroupName;
import software.tnb.jira.validation.generated.model.Project;
import software.tnb.jira.validation.generated.model.ProjectRole;
import software.tnb.jira.validation.generated.model.UserBean;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonArray;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.google.gson.TypeAdapterFactory;
import com.google.gson.reflect.TypeToken;
import com.google.gson.TypeAdapter;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import java.io.IOException;
import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import software.tnb.jira.validation.generated.JSON;
/**
* Details of a share permission for the filter.
*/
@jakarta.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2023-11-09T10:37:50.591249290Z[Etc/UTC]")
public class SharePermission {
public static final String SERIALIZED_NAME_ID = "id";
@SerializedName(SERIALIZED_NAME_ID)
private Long id;
/**
* The type of share permission: * `user` Shared with a user. * `group` Shared with a group. If set in a request, then specify `sharePermission.group` as well. * `project` Shared with a project. If set in a request, then specify `sharePermission.project` as well. * `projectRole` Share with a project role in a project. This value is not returned in responses. It is used in requests, where it needs to be specify with `projectId` and `projectRoleId`. * `global` Shared globally. If set in a request, no other `sharePermission` properties need to be specified. * `loggedin` Shared with all logged-in users. Note: This value is set in a request by specifying `authenticated` as the `type`. * `project-unknown` Shared with a project that the user does not have access to. Cannot be set in a request.
*/
@JsonAdapter(TypeEnum.Adapter.class)
public enum TypeEnum {
USER("user"),
GROUP("group"),
PROJECT("project"),
PROJECTROLE("projectRole"),
GLOBAL("global"),
LOGGEDIN("loggedin"),
AUTHENTICATED("authenticated"),
PROJECT_UNKNOWN("project-unknown");
private String value;
TypeEnum(String value) {
this.value = value;
}
public String getValue() {
return value;
}
@Override
public String toString() {
return String.valueOf(value);
}
public static TypeEnum fromValue(String value) {
for (TypeEnum b : TypeEnum.values()) {
if (b.value.equals(value)) {
return b;
}
}
throw new IllegalArgumentException("Unexpected value '" + value + "'");
}
public static class Adapter extends TypeAdapter {
@Override
public void write(final JsonWriter jsonWriter, final TypeEnum enumeration) throws IOException {
jsonWriter.value(enumeration.getValue());
}
@Override
public TypeEnum read(final JsonReader jsonReader) throws IOException {
String value = jsonReader.nextString();
return TypeEnum.fromValue(value);
}
}
}
public static final String SERIALIZED_NAME_TYPE = "type";
@SerializedName(SERIALIZED_NAME_TYPE)
private TypeEnum type;
public static final String SERIALIZED_NAME_PROJECT = "project";
@SerializedName(SERIALIZED_NAME_PROJECT)
private Project project;
public static final String SERIALIZED_NAME_ROLE = "role";
@SerializedName(SERIALIZED_NAME_ROLE)
private ProjectRole role;
public static final String SERIALIZED_NAME_GROUP = "group";
@SerializedName(SERIALIZED_NAME_GROUP)
private GroupName group;
public static final String SERIALIZED_NAME_USER = "user";
@SerializedName(SERIALIZED_NAME_USER)
private UserBean user;
public SharePermission() {
}
public SharePermission(
Long id
) {
this();
this.id = id;
}
/**
* The unique identifier of the share permission.
* @return id
**/
@jakarta.annotation.Nullable
public Long getId() {
return id;
}
public SharePermission type(TypeEnum type) {
this.type = type;
return this;
}
/**
* The type of share permission: * `user` Shared with a user. * `group` Shared with a group. If set in a request, then specify `sharePermission.group` as well. * `project` Shared with a project. If set in a request, then specify `sharePermission.project` as well. * `projectRole` Share with a project role in a project. This value is not returned in responses. It is used in requests, where it needs to be specify with `projectId` and `projectRoleId`. * `global` Shared globally. If set in a request, no other `sharePermission` properties need to be specified. * `loggedin` Shared with all logged-in users. Note: This value is set in a request by specifying `authenticated` as the `type`. * `project-unknown` Shared with a project that the user does not have access to. Cannot be set in a request.
* @return type
**/
@jakarta.annotation.Nonnull
public TypeEnum getType() {
return type;
}
public void setType(TypeEnum type) {
this.type = type;
}
public SharePermission project(Project project) {
this.project = project;
return this;
}
/**
* Get project
* @return project
**/
@jakarta.annotation.Nullable
public Project getProject() {
return project;
}
public void setProject(Project project) {
this.project = project;
}
public SharePermission role(ProjectRole role) {
this.role = role;
return this;
}
/**
* Get role
* @return role
**/
@jakarta.annotation.Nullable
public ProjectRole getRole() {
return role;
}
public void setRole(ProjectRole role) {
this.role = role;
}
public SharePermission group(GroupName group) {
this.group = group;
return this;
}
/**
* Get group
* @return group
**/
@jakarta.annotation.Nullable
public GroupName getGroup() {
return group;
}
public void setGroup(GroupName group) {
this.group = group;
}
public SharePermission user(UserBean user) {
this.user = user;
return this;
}
/**
* Get user
* @return user
**/
@jakarta.annotation.Nullable
public UserBean getUser() {
return user;
}
public void setUser(UserBean user) {
this.user = user;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
SharePermission sharePermission = (SharePermission) o;
return Objects.equals(this.id, sharePermission.id) &&
Objects.equals(this.type, sharePermission.type) &&
Objects.equals(this.project, sharePermission.project) &&
Objects.equals(this.role, sharePermission.role) &&
Objects.equals(this.group, sharePermission.group) &&
Objects.equals(this.user, sharePermission.user);
}
@Override
public int hashCode() {
return Objects.hash(id, type, project, role, group, user);
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class SharePermission {\n");
sb.append(" id: ").append(toIndentedString(id)).append("\n");
sb.append(" type: ").append(toIndentedString(type)).append("\n");
sb.append(" project: ").append(toIndentedString(project)).append("\n");
sb.append(" role: ").append(toIndentedString(role)).append("\n");
sb.append(" group: ").append(toIndentedString(group)).append("\n");
sb.append(" user: ").append(toIndentedString(user)).append("\n");
sb.append("}");
return sb.toString();
}
/**
* Convert the given object to string with each line indented by 4 spaces
* (except the first line).
*/
private String toIndentedString(Object o) {
if (o == null) {
return "null";
}
return o.toString().replace("\n", "\n ");
}
public static HashSet openapiFields;
public static HashSet openapiRequiredFields;
static {
// a set of all properties/fields (JSON key names)
openapiFields = new HashSet();
openapiFields.add("id");
openapiFields.add("type");
openapiFields.add("project");
openapiFields.add("role");
openapiFields.add("group");
openapiFields.add("user");
// a set of required properties/fields (JSON key names)
openapiRequiredFields = new HashSet();
openapiRequiredFields.add("type");
}
/**
* Validates the JSON Element and throws an exception if issues found
*
* @param jsonElement JSON Element
* @throws IOException if the JSON Element is invalid with respect to SharePermission
*/
public static void validateJsonElement(JsonElement jsonElement) throws IOException {
if (jsonElement == null) {
if (!SharePermission.openapiRequiredFields.isEmpty()) { // has required fields but JSON element is null
throw new IllegalArgumentException(String.format("The required field(s) %s in SharePermission is not found in the empty JSON string", SharePermission.openapiRequiredFields.toString()));
}
}
Set> entries = jsonElement.getAsJsonObject().entrySet();
// check to see if the JSON string contains additional fields
for (Entry entry : entries) {
if (!SharePermission.openapiFields.contains(entry.getKey())) {
throw new IllegalArgumentException(String.format("The field `%s` in the JSON string is not defined in the `SharePermission` properties. JSON: %s", entry.getKey(), jsonElement.toString()));
}
}
// check to make sure all required properties/fields are present in the JSON string
for (String requiredField : SharePermission.openapiRequiredFields) {
if (jsonElement.getAsJsonObject().get(requiredField) == null) {
throw new IllegalArgumentException(String.format("The required field `%s` is not found in the JSON string: %s", requiredField, jsonElement.toString()));
}
}
JsonObject jsonObj = jsonElement.getAsJsonObject();
if (!jsonObj.get("type").isJsonPrimitive()) {
throw new IllegalArgumentException(String.format("Expected the field `type` to be a primitive type in the JSON string but got `%s`", jsonObj.get("type").toString()));
}
// validate the optional field `project`
if (jsonObj.get("project") != null && !jsonObj.get("project").isJsonNull()) {
Project.validateJsonElement(jsonObj.get("project"));
}
// validate the optional field `role`
if (jsonObj.get("role") != null && !jsonObj.get("role").isJsonNull()) {
ProjectRole.validateJsonElement(jsonObj.get("role"));
}
// validate the optional field `group`
if (jsonObj.get("group") != null && !jsonObj.get("group").isJsonNull()) {
GroupName.validateJsonElement(jsonObj.get("group"));
}
// validate the optional field `user`
if (jsonObj.get("user") != null && !jsonObj.get("user").isJsonNull()) {
UserBean.validateJsonElement(jsonObj.get("user"));
}
}
public static class CustomTypeAdapterFactory implements TypeAdapterFactory {
@SuppressWarnings("unchecked")
@Override
public TypeAdapter create(Gson gson, TypeToken type) {
if (!SharePermission.class.isAssignableFrom(type.getRawType())) {
return null; // this class only serializes 'SharePermission' and its subtypes
}
final TypeAdapter elementAdapter = gson.getAdapter(JsonElement.class);
final TypeAdapter thisAdapter
= gson.getDelegateAdapter(this, TypeToken.get(SharePermission.class));
return (TypeAdapter) new TypeAdapter() {
@Override
public void write(JsonWriter out, SharePermission value) throws IOException {
JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject();
elementAdapter.write(out, obj);
}
@Override
public SharePermission read(JsonReader in) throws IOException {
JsonElement jsonElement = elementAdapter.read(in);
validateJsonElement(jsonElement);
return thisAdapter.fromJsonTree(jsonElement);
}
}.nullSafe();
}
}
/**
* Create an instance of SharePermission given an JSON string
*
* @param jsonString JSON string
* @return An instance of SharePermission
* @throws IOException if the JSON string is invalid with respect to SharePermission
*/
public static SharePermission fromJson(String jsonString) throws IOException {
return JSON.getGson().fromJson(jsonString, SharePermission.class);
}
/**
* Convert an instance of SharePermission to an JSON string
*
* @return JSON string
*/
public String toJson() {
return JSON.getGson().toJson(this);
}
}