Exemple #1
0
	def unserialize(self, serial_ops):
		"""
		Unserialize a list of dictionaries to operations and add them to this
		manager.
		
		@function {public} unserialize
		@param {Object[]} serial_ops
		"""
		
		ops = Array()
		
		for op in serial_ops:
			ops.append(Operation.unserialize(op))
		
		self.put(ops)
Exemple #2
0
	def elementsWithin(self, start, end):
		"""
		Returns the Elements between the start and end index.
		
		@function {public Element[]} elementsWithin
		@param {int} start Start index
		@param {int} end End index
		"""
		
		lst = Array()
		for i in xrange(self._elements.length):
			elt = self._elements[i]
			if elt.position() >= start and elt.position() < end:
				lst.append(elt)
		
		return lst
Exemple #3
0
	def serialize(self, fetch = False):
		"""
		Serialize this manager's operations into a list of dictionaries.
		Set fetch to true to also clear this manager.
		
		@function {public Object[]} serialize
		@param {optional Boolean} fetch
		"""
		if fetch:
			ops = self.fetch()
		else:
			ops = self.operations
		
		out = Array()
		
		for op in ops:
			out.append(op.serialize())
		
		return out
Exemple #4
0
	def fetch(self):
		"""
		Returns the pending operations and removes them from this manager.
		
		@function {public Operation[]} fetch
		"""
		ops = Array()
		i = 0
		s = 0
		while i < len(self.operations):
			op = self.operations[i]
			if self.lockedBlips.contains(op.blipId):
				if i - s > 0:
					self.removeOperations(s, i-1)
					i -= s+1
				s = i+1
			else:
				ops.append(op)
			i += 1
		if i - s > 0:
			self.removeOperations(s, i-1)
		return ops
Exemple #5
0
	def loadBlipsFromSnapshot(self, blips, rootBlipId):
		"""
		Load the blips from a snapshot.
		@function {public} loadBlipsFromSnapshot
		@param {Object} blips The JSON-serialized snapshot to load
		@param {String} rootBlipId ID to identify the root Blip
		"""
		
		pp = self._wave.participantProvider()
		
		# Ordering
		created = Hash()
		for blip_id, blip in blips.iteritems():
			created.set(blip["creationTime"], blip_id)
		order = created.getKeys()
		order.sort()
		
		for timestamp in order:
			blip_id = created[timestamp]
			blip = blips[blip_id]
			contributors = Array()
			for cid in blip["contributors"]:
				contributors.append(pp.participant(cid))
			blip_options = {
				"is_root": blip_id == rootBlipId,
				"last_modified": blip["lastModifiedTime"],
				"version": blip["version"],
				"submitted": blip["submitted"]
			}
			blip_elements = []
			for serialelement in blip["elements"]:
				if serialelement["type"] == ELEMENT_TYPE["GADGET"]:
					blip_elements.append(GadgetElement(None, serialelement["id"], serialelement["index"], serialelement["properties"]))
				else:
					blip_elements.append(Element(None, serialelement["id"], serialelement["index"], serialelement["type"], serialelement["properties"]))
			blipObj = self.appendBlip(blip_id, blip_options, blip["content"], blip_elements, pp.participant(blip["creator"]), contributors)