Esempio n. 1
0
 def get_modified_ts(self):
     if self.is_reference:
         return self.entry.modified_ts
     else:
         if not self.obj:
             self.obj = DataObject.find(self.obj_id)
             if self.obj is None:
                 return self.entry.modified_ts
         return self.obj.modified_ts
Esempio n. 2
0
 def get_size(self):
     if self.is_reference:
         return 0
     else:
         if not self.obj:
             self.obj = DataObject.find(self.obj_id)
             if self.obj is None:
                 return 0
         return self.obj.size
Esempio n. 3
0
 def get_metadata(self):
     if self.is_reference:
         return self.entry.metadata
     else:
         if not self.obj:
             self.obj = DataObject.find(self.obj_id)
             if self.obj is None:
                 return self.entry.metadata
         return self.obj.metadata
Esempio n. 4
0
 def get_create_ts(self):
     if self.is_reference:
         return self.entry.create_ts
     else:
         if not self.obj:
             self.obj = DataObject.find(self.obj_id)
             if self.obj is None:
                 return self.entry.create_ts
         return self.obj.create_ts
Esempio n. 5
0
 def get_checksum(self):
     if self.is_reference:
         return None
     else:
         if not self.obj:
             self.obj = DataObject.find(self.obj_id)
             if self.obj is None:
                 return None
         return self.obj.checksum
Esempio n. 6
0
 def get_acl(self):
     if self.is_reference:
         return self.entry.acl
     else:
         if not self.obj:
             self.obj = DataObject.find(self.obj_id)
             if self.obj is None:
                 return self.entry.acl
         return self.obj.acl
Esempio n. 7
0
 def __init__(self, entry, obj=None):
     self.entry = entry
     self.url = self.entry.url
     self.path = self.entry.path()
     self.container = self.entry.container
     self.name = self.entry.name
     self.is_reference = is_reference(self.url)
     self.uuid = self.entry.uuid
     if not self.is_reference:
         self.obj_id = self.url.replace("cassandra://", "")
         self.obj = DataObject.find(self.obj_id)
     else:
         self.obj = None
Esempio n. 8
0
 def get_mimetype(self):
     #         if self.resource.get_mimetype():
     #             return self.resource.get_mimetype()
     #         mimetype = self.resource.get_metadata_key('cdmi_mimetype')
     #         if mimetype:
     #             return mimetype
     if self.is_reference:
         return self.entry.mimetype
     else:
         if not self.obj:
             self.obj = DataObject.find(self.obj_id)
             if self.obj is None:
                 return self.entry.mimetype
         return self.obj.mimetype
Esempio n. 9
0
    def create(cls,
               container,
               name,
               uuid=None,
               metadata=None,
               url=None,
               mimetype=None,
               username=None,
               size=None):
        """Create a new resource in the tree_entry table"""
        from indigo.models import Collection
        from indigo.models import Notification
        # Check if parent collection exists
        parent = Collection.find(container)
        if parent is None:
            raise NoSuchCollectionError(container)
        if uuid is None:
            uuid = default_cdmi_id()
        create_ts = datetime.now()
        modified_ts = create_ts
        path = merge(container, name)
        if metadata:
            metadata_cass = meta_cdmi_to_cassandra(metadata)
        # Check the container exists
        collection = Collection.find(container)
        if not collection:
            raise NoSuchCollectionError(container)
        # Make sure parent/name are not in use.
        existing = cls.find(path)
        if existing:
            raise ResourceConflictError(path)
        kwargs = {
            "container": container,
            "name": name,
            "url": url,
            "uuid": uuid,
        }
        if is_reference(url):
            kwargs["create_ts"] = create_ts
            kwargs["modified_ts"] = modified_ts
            kwargs["mimetype"] = mimetype
            if metadata:
                kwargs["metadata"] = metadata_cass
        else:
            obj_id = url.replace("cassandra://", "")
            data_obj = DataObject.find(obj_id)
            if metadata:
                data_obj.update(mimetype=mimetype, metadata=metadata_cass)
            else:
                if mimetype:
                    data_obj.update(mimetype=mimetype)
                if size:
                    data_obj.update(size=size)

        data_entry = TreeEntry.create(**kwargs)
        new = Resource(data_entry)

        session = get_graph_session()

        add_user_edge = ""
        if username:
            user = User.find(username)
            if user:
                add_user_edge = """v_user = {}.next();
                                   v_user.addEdge('owns', v_new);
                                   """.format(gq_get_vertex_user(user))
        else:
            add_user_edge = ""

        session.execute_graph("""v_parent = {}.next();
                                 v_new = {};
                                 v_parent.addEdge('son', v_new);
                                 {}
                                 """.format(gq_get_vertex_collection(parent),
                                            gq_add_vertex_resource(new),
                                            add_user_edge))
        if metadata:
            new.update_graph(metadata)

        state = new.mqtt_get_state()
        payload = new.mqtt_payload({}, state)
        Notification.create_resource(username, path, payload)
        # Index the resource
        new.index()
        return new