/// <summary> /// Returns the pointer to "row". /// </summary> /// <returns>The pointer.</returns> /// <param name="row">Row.</param> private MoBackPointer GetPointer(MoBackRow row) { MoBackTableInterface targetTable = new MoBackTableInterface(row.TableName.ToString()); MoBackPointer pToTarget = new MoBackPointer(row.ObjectId.ToString(), targetTable); return(pToTarget); }
/// <summary> /// Creates a MoBackRelation object from JSON returned from server. /// </summary> /// <returns>The relation.</returns> /// <param name="relationJSON">Relation in JSON form, from server.</param> public static MoBackRelation RelationFromMoBackJSON(SimpleJSONNode relationJSON) { MoBackRelation relation = new MoBackRelation(); SimpleJSONArray pointersJSON = relationJSON ["value"].AsArray; for (int i = 0; i < pointersJSON.Count; i++) { // If the nested json doesn't have a pointer type, just return null. // When AchieveRelation with ?include={ColumnName}, it will return an object type. if (pointersJSON[i]["__type"].Value != "Pointer") { if (pointersJSON[i]["__type"].Value == "object") { Debug.LogWarning("The response JSON contains Object type, not Pointer type, can't parse this relationJson. Try MoBackRelation.MoBackRowFromRelationJSON() instead"); return(null); } else { Debug.LogError("Unknown type: " + pointersJSON[i]["__type"].Value); return(null); } } relation._pointers.Add(MoBackPointer.PointerFromMoBackJSON(pointersJSON[i])); } return(relation); }
/// <summary> /// Converts a MoBackPointer to a JSON object for storage. /// </summary> /// <returns> A JSON object. </returns> /// <param name="pointer"> A MoBackPointer object. </param> public static SimpleJSONClass PointerToMoBackJSON(MoBackPointer pointer) { SimpleJSONClass pointerJsonStructure = new SimpleJSONClass(); pointerJsonStructure["__type"] = "Pointer"; pointerJsonStructure["objectId"] = pointer.objectID; pointerJsonStructure["className"] = pointer.tableID; return(pointerJsonStructure); }
/// <summary> /// Set the specified index and value. /// </summary> /// <param name="index"> An index value. </param> /// <param name="value"> A MoBackPointer value. </param> public void Set(int index, MoBackPointer value) { if (ValidateIndex(index)) { objects[index] = value; objectTypes[index] = MoBackValueType.Pointer; } else { Debug.LogError("Error: Index is out of range."); } }
/// <summary> /// Request to remove one or more pointers to a relations column. /// </summary> /// <returns>The relations.</returns> /// <param name="relationColumnID">Relation column to add pointers to.</param> /// <param name="pointerToRemove">Pointer to add.</param> public MoBackRequest RemoveRelations(string relationColumnID, MoBackRow[] pointerToRemove) { MoBackPointer[] targetArray = new MoBackPointer[pointerToRemove.Length]; for (int i = 0; i < pointerToRemove.Length; i++) { targetArray[i] = GetPointer(pointerToRemove[i]); } if (string.IsNullOrEmpty(ObjectId)) { return(null); } return(MoBackTableInterface.RequestBuilder.ModifyRelationForGivenRowColumn(TableName, ObjectId, relationColumnID, MoBackRelation.RelationRemoveOpAsMoBackJSON(targetArray))); }
/// <summary> /// MoBack JSON from relation. Of dubious usefulness because uploading and updating relations directly is presently forbidden. /// </summary> /// <returns>The moback JSON representing the relation.</returns> /// <param name="relation">Relation.</param> public static SimpleJSONNode MoBackJSONFromRelation(MoBackRelation relation) { SimpleJSONClass relationJSON = new SimpleJSONClass(); relationJSON ["__type"] = "Pointer"; SimpleJSONArray pointersJSON = new SimpleJSONArray(); for (int i = 0; i < relation._pointers.Count; i++) { pointersJSON.Add(MoBackPointer.PointerToMoBackJSON(relation._pointers[i])); } relationJSON ["value"] = pointersJSON; return(relationJSON); }
/// <summary> /// Gets JSON the server expects for an remove relation operation, that removes the supplied list of pointers to some relation. /// </summary> /// <returns>The remove operation as mo back JSO.</returns> /// <param name="pointersToRemove">Pointers to add.</param> public static SimpleJSONClass RelationRemoveOpAsMoBackJSON(MoBackPointer[] pointersToRemove) { SimpleJSONClass relationOpJsonStructure = new SimpleJSONClass(); relationOpJsonStructure ["__op"] = "removeRelation"; SimpleJSONArray pointers = new SimpleJSONArray(); for (int i = 0; i < pointersToRemove.Length; i++) { pointers.Add(MoBackPointer.PointerToMoBackJSON(pointersToRemove[i])); } relationOpJsonStructure ["objects"] = pointers; return(relationOpJsonStructure); }
/// <summary> /// Request to add one or more pointers to a relations column. /// </summary> /// <returns>The relations.</returns> /// <param name="relationColumnID">Relation column to add pointers to.</param> /// <param name="pointersToAdd">Pointers to add.</param> public MoBackRequest AddRelations(string relationColumnID, MoBackRow[] pointersToAdd) { MoBackPointer[] targetArray = new MoBackPointer[pointersToAdd.Length]; for (int i = 0; i < pointersToAdd.Length; i++) { targetArray[i] = GetPointer(pointersToAdd[i]); } if (string.IsNullOrEmpty(ObjectId)) { Debug.LogError("Relations can only be added to objects that have known object IDs"); return(null); } return(MoBackTableInterface.RequestBuilder.ModifyRelationForGivenRowColumn(TableName, ObjectId, relationColumnID, MoBackRelation.RelationAddOpAsMoBackJSON(targetArray))); }
/// <summary> /// Sets the value with a MoBackPointer element at the specified key. /// </summary> /// <param name="key"> The key to be set. </param> /// <param name="value"> The value to set. </param> public void SetValue(string key, MoBackPointer value) { storeValues[key] = value; SetColumnType(key, MoBackValueType.Pointer); }
/// <summary> /// Adds a MoBackPointer type value to the container. /// </summary> /// <param name="value"> A MoBackPointer value. </param> public void Add(MoBackPointer value) { objects.Add(value); objectTypes.Add(MoBackValueType.Pointer); }