Skip to content

Commit

Permalink
Add ParseLiveQuery and add missing OCK fields (#67)
Browse files Browse the repository at this point in the history
* Add missing fields

* Add LiveQuery

* Update podspec

* Switch to canImport

* Use if not watchOS

* Add delegate for descriptions

* Update
  • Loading branch information
cbaker6 authored Nov 12, 2020
1 parent 473f8df commit f943a8f
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 27 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ xcuserdata/
## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4)
build/
DerivedData/
.DS_Store
*.moved-aside
*.pbxuser
!default.pbxuser
Expand Down
3 changes: 2 additions & 1 deletion ParseCareKit/PCKObjects/CarePlan.swift
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ open class CarePlan: PCKVersionedObject, PCKRemoteSynchronized {
completion(true,nil)
}

public func pullRevisions(_ localClock: Int, cloudClock: OCKRevisionRecord.KnowledgeVector, mergeRevision: @escaping (OCKRevisionRecord) -> Void){
public func pullRevisions(_ localClock: Int, cloudClock: OCKRevisionRecord.KnowledgeVector, mergeRevision: @escaping (OCKRevisionRecord) -> Void) -> PFQuery<PFObject> {

let query = CarePlan.query()!
query.whereKey(kPCKObjectClockKey, greaterThanOrEqualTo: localClock)
Expand Down Expand Up @@ -177,6 +177,7 @@ open class CarePlan: PCKVersionedObject, PCKRemoteSynchronized {
let revision = OCKRevisionRecord(entities: entities, knowledgeVector: cloudClock)
mergeRevision(revision)
}
return query
}

public func pushRevision(_ overwriteRemote: Bool, cloudClock: Int, completion: @escaping (Error?) -> Void){
Expand Down
3 changes: 2 additions & 1 deletion ParseCareKit/PCKObjects/Contact.swift
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ open class Contact: PCKVersionedObject, PCKRemoteSynchronized {
completion(true,nil)
}

public func pullRevisions(_ localClock: Int, cloudClock: OCKRevisionRecord.KnowledgeVector, mergeRevision: @escaping (OCKRevisionRecord) -> Void){
public func pullRevisions(_ localClock: Int, cloudClock: OCKRevisionRecord.KnowledgeVector, mergeRevision: @escaping (OCKRevisionRecord) -> Void) -> PFQuery<PFObject> {

let query = Contact.query()!
query.whereKey(kPCKObjectClockKey, greaterThanOrEqualTo: localClock)
Expand Down Expand Up @@ -263,6 +263,7 @@ open class Contact: PCKVersionedObject, PCKRemoteSynchronized {
let revision = OCKRevisionRecord(entities: entities, knowledgeVector: cloudClock)
mergeRevision(revision)
}
return query
}

public func pushRevision(_ overwriteRemote: Bool, cloudClock: Int, completion: @escaping (Error?) -> Void){
Expand Down
3 changes: 2 additions & 1 deletion ParseCareKit/PCKObjects/Outcome.swift
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ open class Outcome: PCKObject, PCKRemoteSynchronized {
completion(true,nil)
}

public func pullRevisions(_ localClock: Int, cloudClock: OCKRevisionRecord.KnowledgeVector, mergeRevision: @escaping (OCKRevisionRecord) -> Void){
public func pullRevisions(_ localClock: Int, cloudClock: OCKRevisionRecord.KnowledgeVector, mergeRevision: @escaping (OCKRevisionRecord) -> Void) -> PFQuery<PFObject> {

let query = Outcome.query()!
query.whereKey(kPCKObjectClockKey, greaterThanOrEqualTo: localClock)
Expand Down Expand Up @@ -169,6 +169,7 @@ open class Outcome: PCKObject, PCKRemoteSynchronized {
let revision = OCKRevisionRecord(entities: entities, knowledgeVector: cloudClock)
mergeRevision(revision)
}
return query
}

public func pushRevision(_ overwriteRemote: Bool, cloudClock: Int, completion: @escaping (Error?) -> Void){
Expand Down
4 changes: 2 additions & 2 deletions ParseCareKit/PCKObjects/OutcomeValue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,15 @@ open class OutcomeValue: PCKObject, PFSubclassing {
self.value = outcomeValue.value
self.units = outcomeValue.units

self.asset = outcomeValue.asset
self.groupIdentifier = outcomeValue.groupIdentifier
self.tags = outcomeValue.tags
self.source = outcomeValue.source
self.updatedDate = outcomeValue.updatedDate
self.remoteID = outcomeValue.remoteID
self.createdDate = outcomeValue.createdDate
self.notes = outcomeValue.notes?.compactMap{Note(careKitEntity: $0)}



return self
}

Expand Down
5 changes: 5 additions & 0 deletions ParseCareKit/PCKObjects/PCKObject.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ open class PCKObject: PFObject {
self.createdDate = other.createdDate
self.notes = other.notes
self.logicalClock = other.logicalClock
self.asset = other.asset
self.tags = other.tags
self.schemaVersion = other.schemaVersion
self.groupIdentifier = other.groupIdentifier
self.source = other.source
}

open func copyRelationalEntities(_ parse: PCKObject){
Expand Down
3 changes: 2 additions & 1 deletion ParseCareKit/PCKObjects/Patient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ open class Patient: PCKVersionedObject, PCKRemoteSynchronized {
completion(true,nil)
}

public func pullRevisions(_ localClock: Int, cloudClock: OCKRevisionRecord.KnowledgeVector, mergeRevision: @escaping (OCKRevisionRecord) -> Void){
public func pullRevisions(_ localClock: Int, cloudClock: OCKRevisionRecord.KnowledgeVector, mergeRevision: @escaping (OCKRevisionRecord) -> Void) -> PFQuery<PFObject> {

let query = Patient.query()!
query.whereKey(kPCKObjectClockKey, greaterThanOrEqualTo: localClock)
Expand Down Expand Up @@ -154,6 +154,7 @@ open class Patient: PCKVersionedObject, PCKRemoteSynchronized {
let revision = OCKRevisionRecord(entities: entities, knowledgeVector: cloudClock)
mergeRevision(revision)
}
return query
}

public func pushRevision(_ overwriteRemote: Bool, cloudClock: Int, completion: @escaping (Error?) -> Void){
Expand Down
3 changes: 2 additions & 1 deletion ParseCareKit/PCKObjects/Task.swift
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ open class Task: PCKVersionedObject, PCKRemoteSynchronized {
completion(true,nil)
}

public func pullRevisions(_ localClock: Int, cloudClock: OCKRevisionRecord.KnowledgeVector, mergeRevision: @escaping (OCKRevisionRecord) -> Void){
public func pullRevisions(_ localClock: Int, cloudClock: OCKRevisionRecord.KnowledgeVector, mergeRevision: @escaping (OCKRevisionRecord) -> Void) -> PFQuery<PFObject> {

let query = Task.query()!
query.whereKey(kPCKObjectClockKey, greaterThanOrEqualTo: localClock)
Expand Down Expand Up @@ -181,6 +181,7 @@ open class Task: PCKVersionedObject, PCKRemoteSynchronized {
let revision = OCKRevisionRecord(entities: entities, knowledgeVector: cloudClock)
mergeRevision(revision)
}
return query
}

public func pushRevision(_ overwriteRemote: Bool, cloudClock: Int, completion: @escaping (Error?) -> Void){
Expand Down
7 changes: 5 additions & 2 deletions ParseCareKit/ParseRemoteSynchronizationManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public protocol ParseRemoteSynchronizationDelegate: OCKRemoteSynchronizationDele
func storeUpdatedPatient(_ patient: OCKPatient)
func storeUpdatedTask(_ task: OCKTask)
func successfullyPushedDataToCloud()
func subscribe(_ query: PFQuery<PFObject>)
}

open class ParseRemoteSynchronizationManager: NSObject, OCKRemoteSynchronizable {
Expand Down Expand Up @@ -107,7 +108,7 @@ open class ParseRemoteSynchronizationManager: NSObject, OCKRemoteSynchronizable
}

var currentError = previousError
newConcreteClass.pullRevisions(localClock, cloudClock: cloudClock){
let query = newConcreteClass.pullRevisions(localClock, cloudClock: cloudClock){
customRevision in
mergeRevision(customRevision){
error in
Expand All @@ -120,6 +121,7 @@ open class ParseRemoteSynchronizationManager: NSObject, OCKRemoteSynchronizable

}
}
self.parseDelegate?.subscribe(query)
}

func pullRevisionsForCustomClasses(customClassesAlreadyPulled:Int=0, previousError: Error?, localClock: Int, cloudClock: OCKRevisionRecord.KnowledgeVector, mergeRevision: @escaping (OCKRevisionRecord, @escaping (Error?) -> Void) -> Void, completion: @escaping (Error?) -> Void){
Expand All @@ -134,7 +136,7 @@ open class ParseRemoteSynchronizationManager: NSObject, OCKRemoteSynchronizable
return
}
var currentError = previousError
newCustomClass.pullRevisions(localClock, cloudClock: cloudClock){
let query = newCustomClass.pullRevisions(localClock, cloudClock: cloudClock){
customRevision in
mergeRevision(customRevision){
error in
Expand All @@ -146,6 +148,7 @@ open class ParseRemoteSynchronizationManager: NSObject, OCKRemoteSynchronizable
self.pullRevisionsForCustomClasses(customClassesAlreadyPulled: customClassesAlreadyPulled+1, previousError: currentError, localClock: localClock, cloudClock: cloudClock, mergeRevision: mergeRevision, completion: completion)
}
}
self.parseDelegate?.subscribe(query)
}else{
completion(previousError)
}
Expand Down
2 changes: 1 addition & 1 deletion ParseCareKit/Protocols/PCKSynchronized.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ public protocol PCKSynchronized: PFObject, PFSubclassing {
Protocol that defines the properties and methods for parse carekit entities that are synchronized using a knowledge vector.
*/
public protocol PCKRemoteSynchronized: PCKSynchronized {
func pullRevisions(_ localClock: Int, cloudClock: OCKRevisionRecord.KnowledgeVector, mergeRevision: @escaping (OCKRevisionRecord) -> Void)
func pullRevisions(_ localClock: Int, cloudClock: OCKRevisionRecord.KnowledgeVector, mergeRevision: @escaping (OCKRevisionRecord) -> Void) -> PFQuery<PFObject>
func pushRevision(_ overwriteRemote: Bool, cloudClock: Int, completion: @escaping (Error?) -> Void)
}
Loading

0 comments on commit f943a8f

Please sign in to comment.