def create(self, object=None, actor_id=None): if object is None: raise BadRequest("Object not present") if not isinstance(object, IonObjectBase): raise BadRequest("Object is not an IonObject") if not is_resource(object): raise BadRequest("Object is not a Resource") lcsm = get_restype_lcsm(object._get_type()) object.lcstate = lcsm.initial_state if lcsm else "DEPLOYED_AVAILABLE" cur_time = get_ion_ts() object.ts_created = cur_time object.ts_updated = cur_time new_res_id = create_unique_resource_id() res = self.rr_store.create(object, new_res_id) res_id, rev = res if actor_id and actor_id != 'anonymous': log.debug("Associate resource_id=%s with owner=%s" % (res_id, actor_id)) self.rr_store.create_association(res_id, PRED.hasOwner, actor_id) self.event_pub.publish_event(event_type="ResourceModifiedEvent", origin=res_id, origin_type=object._get_type(), sub_type="CREATE", mod_type=ResourceModificationType.CREATE) return res
def create(self, object=None, actor_id=None, object_id=None, attachments=None): """ Accepts object that is to be stored in the data store and tags them with additional data (timestamp and such) If actor_id is provided, creates hasOwner association with objects. If attachments are provided (in dict(att1=dict(data=xyz), att2=dict(data=aaa, content_type='text/plain') form) they get attached to the object. Returns a tuple containing object and revision identifiers. """ if object is None: raise BadRequest("Object not present") if not isinstance(object, IonObjectBase): raise BadRequest("Object is not an IonObject") if not is_resource(object): raise BadRequest("Object is not a Resource") if "_id" in object: raise BadRequest("Object must not contain _id") if "_rev" in object: raise BadRequest("Object must not contain _rev") lcsm = get_restype_lcsm(object._get_type()) object.lcstate = lcsm.initial_state if lcsm else LCS.DEPLOYED object.availability = lcsm.initial_availability if lcsm else AS.AVAILABLE cur_time = get_ion_ts() object.ts_created = cur_time object.ts_updated = cur_time if object_id is None: new_res_id = create_unique_resource_id() else: new_res_id = object_id res = self.rr_store.create(object, new_res_id, attachments=attachments) res_id, rev = res if actor_id and actor_id != 'anonymous': log.debug("Associate resource_id=%s with owner=%s", res_id, actor_id) self.create_association(res_id, PRED.hasOwner, actor_id) if self.container.has_capability(self.container.CCAP.EVENT_PUBLISHER): self.event_pub.publish_event(event_type="ResourceModifiedEvent", origin=res_id, origin_type=object._get_type(), sub_type="CREATE", mod_type=ResourceModificationType.CREATE) return res
def create(self, object=None, actor_id=None, object_id=None, attachments=None): """ Accepts object that is to be stored in the data store and tags them with additional data (timestamp and such) If actor_id is provided, creates hasOwner association with objects. If attachments are provided (in dict(att1=dict(data=xyz), att2=dict(data=aaa, content_type='text/plain') form) they get attached to the object. Returns a tuple containing object and revision identifiers. """ if object is None: raise BadRequest("Object not present") if not isinstance(object, IonObjectBase): raise BadRequest("Object is not an IonObject") if not is_resource(object): raise BadRequest("Object is not a Resource") lcsm = get_restype_lcsm(object._get_type()) object.lcstate = lcsm.initial_state if lcsm else "DEPLOYED_AVAILABLE" cur_time = get_ion_ts() object.ts_created = cur_time object.ts_updated = cur_time if object_id is None: new_res_id = create_unique_resource_id() else: new_res_id = object_id res = self.rr_store.create(object, new_res_id, attachments=attachments) res_id, rev = res if actor_id and actor_id != 'anonymous': log.debug("Associate resource_id=%s with owner=%s" % (res_id, actor_id)) self.rr_store.create_association(res_id, PRED.hasOwner, actor_id) self.event_pub.publish_event(event_type="ResourceModifiedEvent", origin=res_id, origin_type=object._get_type(), sub_type="CREATE", mod_type=ResourceModificationType.CREATE) return res
def create(self, object=None, actor_id=None): if object is None: raise BadRequest("Object not present") if not isinstance(object, IonObjectBase): raise BadRequest("Object is not an IonObject") if not is_resource(object): raise BadRequest("Object is not a Resource") lcsm = get_restype_lcsm(object._get_type()) object.lcstate = lcsm.initial_state if lcsm else "DEPLOYED_AVAILABLE" cur_time = get_ion_ts() object.ts_created = cur_time object.ts_updated = cur_time res = self.rr_store.create(object) res_id, rev = res if actor_id and actor_id != 'anonymous': log.debug("Associate resource_id=%s with owner=%s" % (res_id, actor_id)) self.rr_store.create_association(res_id, PRED.hasOwner, actor_id) return res