com.files.models.FileCommentReaction Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of files-sdk Show documentation
Show all versions of files-sdk Show documentation
The Files.com Java client library provides convenient access to the Files.com API from JVM based applications.
package com.files.models;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.json.JsonMapper;
import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectReader;
import com.files.FilesClient;
import com.files.FilesConfig;
import com.files.net.HttpMethods.RequestMethods;
import com.files.util.ModelUtils;
import com.files.util.FilesInputStream;
import java.io.BufferedInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import lombok.Getter;
import lombok.Setter;
@JsonIgnoreProperties(ignoreUnknown = true)
public class FileCommentReaction {
private HashMap options;
private ObjectMapper objectMapper = JsonMapper
.builder()
.disable(MapperFeature.CAN_OVERRIDE_ACCESS_MODIFIERS)
.build();
public FileCommentReaction() {
this(null, null);
}
public FileCommentReaction(HashMap parameters) {
this(parameters, null);
}
public FileCommentReaction(HashMap parameters, HashMap options) {
this.options = options;
try{
ObjectReader objectReader = objectMapper.readerForUpdating(this);
objectReader.readValue(objectMapper.writeValueAsString(parameters));
} catch (JsonProcessingException e){
// TODO: error generation on constructor
}
}
/**
* Reaction ID
*/
@Getter
@Setter
@JsonProperty("id")
public Long id;
/**
* Emoji used in the reaction.
*/
@Getter
@Setter
@JsonProperty("emoji")
public String emoji;
/**
* User ID. Provide a value of `0` to operate the current session's user.
*/
@Getter
@Setter
@JsonProperty("user_id")
public Long userId;
/**
* ID of file comment to attach reaction to.
*/
@Getter
@Setter
@JsonProperty("file_comment_id")
public Long fileCommentId;
/**
*/
public FileCommentReaction delete(HashMap parameters) {
return delete(parameters);
}
public void destroy(HashMap parameters) {
delete(parameters);
}
public void save() throws IOException {
HashMap parameters = ModelUtils.toParameterMap(objectMapper.writeValueAsString(this));
if (parameters.containsKey("id") && parameters.get("id") != null) {
throw new UnsupportedOperationException("The FileCommentReaction Object doesn't support updates.");
} else {
FileCommentReaction newObject = FileCommentReaction.create(parameters, this.options);
}
}
/**
* Parameters:
* user_id - int64 - User ID. Provide a value of `0` to operate the current session's user.
* file_comment_id (required) - int64 - ID of file comment to attach reaction to.
* emoji (required) - string - Emoji to react with.
*/
public static FileCommentReaction create() throws IOException {
return create(null,null);
}
public static FileCommentReaction create( HashMap parameters) throws IOException {
return create(parameters, null);
}
public static FileCommentReaction create( HashMap parameters, HashMap options) throws IOException {
parameters = parameters != null ? parameters : new HashMap();
options = options != null ? options : new HashMap();
if (parameters.containsKey("user_id") && !(parameters.get("user_id") instanceof Long )) {
throw new IllegalArgumentException("Bad parameter: user_id must be of type Long parameters[\"user_id\"]");
}
if (parameters.containsKey("file_comment_id") && !(parameters.get("file_comment_id") instanceof Long )) {
throw new IllegalArgumentException("Bad parameter: file_comment_id must be of type Long parameters[\"file_comment_id\"]");
}
if (parameters.containsKey("emoji") && !(parameters.get("emoji") instanceof String )) {
throw new IllegalArgumentException("Bad parameter: emoji must be of type String parameters[\"emoji\"]");
}
if (!parameters.containsKey("file_comment_id") || parameters.get("file_comment_id") == null) {
throw new NullPointerException("Parameter missing: file_comment_id parameters[\"file_comment_id\"]");
}
if (!parameters.containsKey("emoji") || parameters.get("emoji") == null) {
throw new NullPointerException("Parameter missing: emoji parameters[\"emoji\"]");
}
String url = String.format("%s%s/file_comment_reactions", FilesConfig.getInstance().getApiRoot(), FilesConfig.getInstance().getApiBase());
TypeReference typeReference = new TypeReference() {};
return FilesClient.requestItem(url, RequestMethods.POST, typeReference, parameters, options);
}
/**
*/
public static FileCommentReaction delete() throws IOException {
return delete(null, null,null);
}
public static FileCommentReaction delete(Long id, HashMap parameters) throws IOException {
return delete(id, parameters, null);
}
public static FileCommentReaction delete(HashMap parameters, HashMap options) throws IOException {
return delete(null, parameters, options);
}
public static FileCommentReaction delete(Long id, HashMap parameters, HashMap options) throws IOException {
parameters = parameters != null ? parameters : new HashMap();
options = options != null ? options : new HashMap();
if (id == null && parameters.containsKey("id") && parameters.get("id") != null) {
id = ((Long) parameters.get("id"));
}
if (!(id instanceof Long) ) {
throw new IllegalArgumentException("Bad parameter: id must be of type Long parameters[\"id\"]");
}
if (id == null) {
throw new NullPointerException("Argument or Parameter missing: id parameters[\"id\"]");
}
String urlParts[] = {FilesConfig.getInstance().getApiRoot(), FilesConfig.getInstance().getApiBase(), String.valueOf(id)};
for (int i = 2; i < urlParts.length; i++) {
try {
urlParts[i] = new URI(null, null, urlParts[i], null).getRawPath();
} catch (URISyntaxException ex){
}
}
String url = String.format("%s%s/file_comment_reactions/%s", urlParts);
TypeReference typeReference = new TypeReference() {};
return FilesClient.requestItem(url, RequestMethods.DELETE, typeReference, parameters, options);
}
public static FileCommentReaction destroy() throws IOException {
return destroy(null, null, null);
}
public static FileCommentReaction destroy(Long id, HashMap parameters, HashMap options) throws IOException {
return delete(id, parameters, options);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy