Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
package io.cloudboost;
import io.cloudboost.beans.CBResponse;
import io.cloudboost.json.JSONArray;
import io.cloudboost.json.JSONException;
import io.cloudboost.json.JSONObject;
import io.cloudboost.util.CBParser;
import io.cloudboost.util.CloudSocket;
import io.socket.client.Ack;
import io.socket.emitter.Emitter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
/**
*Wraps a single record from a table
* @author Ben
*
*/
public class CloudObject {
public ACL acl;
protected JSONObject document;
/**
* returns the underlying json document with all data about the record, do not modify this object unless you are absolutely sure
* of what you are doing
* @return document
*/
public JSONObject getDocument() {
return document;
}
/**
* replaces the underlying json object
* @param document
*/
public void setDocument(JSONObject document) {
this.document = document;
}
private CloudObject thisObj;
protected ArrayList _modifiedColumns;
/**
* Create a new CloudObject
* Constructor
*
* @param tableName -name of table to wrap
*/
public CloudObject(String tableName) {
this.acl = new ACL();
this._modifiedColumns = new ArrayList();
this._modifiedColumns.add("createdAt");
this._modifiedColumns.add("updatedAt");
this._modifiedColumns.add("ACL");
this._modifiedColumns.add("expires");
// adding properties of this object is document HashMap, which can
// letter pass to serialization
document = new JSONObject();
try {
document.put("_id",(Object) null);
document.put("_tableName", tableName);
document.put("_type", "custom");
document.put("createdAt", (Object) null);
document.put("updatedAt", (Object) null);
document.put("ACL", acl.getACL());
document.put("expires", JSONObject.NULL);
document.put("_modifiedColumns", this._modifiedColumns);
document.put("_isModified", true);
} catch (JSONException e) {
e.printStackTrace();
}
}
/**
* set the Access Control List for this record
* @param acl
*/
public void setAcl(ACL acl){
try {
set("ACL", acl);
} catch (CloudException e) {
e.printStackTrace();
}
}
/**
*
* Constructor
*
* @param tableName
* @param id
*/
public CloudObject(String tableName, String id) {
this.acl = new ACL();
this._modifiedColumns = new ArrayList();
// adding properties of this object is document HashMap, which can
// letter pass to serialization
document = new JSONObject();
try {
document.put("_id", id);
document.put("_tableName", tableName);
document.put("_type", "custom");
document.put("ACL", acl.acl.toString());
document.put("_isSearchable", false);
document.put("createdAt", (Object) null);
document.put("updatedAt", (Object) null);
document.put("expires", (Object) null);
document.put("_modifiedColumns", this._modifiedColumns);
document.put("_isModified", true);
} catch (JSONException e) {
e.printStackTrace();
}
}
/**
* get the id of this object if its already saved, otherwise null
* @return _id
*/
public String getId() {
try {
return (document.get("_id")).toString();
} catch (JSONException e) {
return null;
}
}
/**
* get the date of creation of this object
* @return createdAt
*/
public Date getCreatedAt() {
try {
return (Date) document.get("createdAt");
} catch (JSONException e) {
e.printStackTrace();
return null;
}
}
/**
* get the last update date of this object
* @return updatedAt
*/
public Date getUpdatedAt() {
try {
return (Date) document.get("updatedAt");
} catch (JSONException e) {
return null;
}
}
/**
* returns true if search can be performed on this object
* @return _isSearchable
*/
public boolean getIsSearchable() {
try {
return (boolean) document.get("_isSearchable");
} catch (JSONException e) {
e.printStackTrace();
return false;
}
}
/**
* should this object appear in searches
* @param value
*/
public void setIsSearchable(boolean value) {
try {
document.put("_isSearchable", value);
} catch (JSONException e) {
e.printStackTrace();
}
}
/**
* get when this cloudobject will expire
* @return expiry date
*/
public Calendar getExpires() {
try {
String str=document.getString("expires");
return (Calendar) document.get("expires");
} catch (JSONException e) {
e.printStackTrace();
return null;
}
}
/**
* set expiry time for this cloudobject, after which it will not appear in queries and searches
* @param value
*/
public void setExpires(Calendar value) {
try {
document.put("expires", value);
} catch (JSONException e) {
e.printStackTrace();
}
}
/**
* returns true if this cloudobject contains a given key
* @param key key to search for
* @return boolean
*/
public boolean hasKey(String key) {
return document.has(key);
}
/**
*
* Set a value to this cloudobject as object
*
* @param columnName
* @param data
* @throws CloudException
*/
public void set(String columnName, Object data) throws CloudException {
String keywords[] = { "_tableName", "_type", "operator" };
int index = -1;
if (columnName.equals("id") || columnName.equals("_id"))
throw new CloudException("You cannot set Id on a CloudObject");
if (columnName == "id" || columnName == "isSearchable") {
columnName = "_" + columnName;
}
for (int i = 0; i < keywords.length; i++) {
if (keywords[i].equals(columnName)) {
index = i;
break;
}
}
if (index > -1) {
throw new CloudException(columnName
+ "is a keyword. Please choose a different column name.");
}
if (data instanceof CloudObject) {
data = ((CloudObject) data).document;
}
if (data instanceof CloudGeoPoint) {
data = ((CloudGeoPoint) data).document;
}
if (data instanceof CloudFile) {
data = ((CloudFile) data).getDocument();
}
if(data instanceof ACL){
data=((ACL)data).getACL();
}
try {
if (data == null) {
document.put(columnName, JSONObject.NULL);
} else {
document.put(columnName, data);
}
this._modifiedColumns.add(columnName);
document.put("_modifiedColumns", this._modifiedColumns);
document.put("_isModified", true);
} catch (JSONException e) {
e.printStackTrace();
}
}
/**
*
* Set a value as an array
*
* @param columnName
* @param data
* @throws CloudException
*/
public void set(String columnName, Object[] data) throws CloudException {
String keywords[] = { "_tableName", "_type", "operator" };
int index = -1;
if (columnName.equals("id") || columnName.equals("_id"))
throw new CloudException("You cannot set Id on a CloudObject");
if (columnName == "id" || columnName == "isSearchable") {
columnName = "_" + columnName;
}
for (int i = 0; i < keywords.length; i++) {
if (keywords[i].equals(columnName)) {
index = i;
break;
}
}
if (index > -1) {
throw new CloudException(columnName
+ "is a keyword. Please choose a different column name.");
}
try {
if (data instanceof CloudObject[]) {
CloudObject[] arrayList = (CloudObject[]) data;
ArrayList