Commits

Anonymous committed 2b683b6

Fix API code errors, add ability to set ldda associations, fixed misc error in util

Comments (0)

Files changed (4)

lib/galaxy/util/__init__.py

 
 def restore_text(text):
     """Restores sanitized text"""
+    if not text:
+        return text
     for key, value in mapped_chars.items():
         text = text.replace(value, key)
     return text

lib/galaxy/web/api/histories.py

                     state = states.QUEUED
                 elif summary[states.OK] == num_sets:
                     state = states.OK                       
+				item['state_details'] = summary
             item['contents_url'] = url_for( 'history_contents', history_id=history_id )
+              
             item['state'] = state
-            item['state_details'] = summary
         except Exception, e:
             item = "Error in history API at showing history detail"
             log.error(item + ": %s" % str(e))

lib/galaxy/web/api/history_contents.py

 
 log = logging.getLogger( __name__ )
 
-class HistoryContentsController( BaseAPIController, UsesHistoryDatasetAssociation, UsesHistory ):
+class HistoryContentsController( BaseAPIController, UsesHistoryDatasetAssociation, UsesHistory, UsesLibrary, UsesLibraryItems ):
 
     @web.expose_api
     def index( self, trans, history_id, **kwd ):
 
         if from_ld_id:
             try:
-                ld = get_library_content_for_access( trans, from_ld_id )
+                ld = self.get_library_dataset( trans, from_ld_id, check_ownership=False, check_accessible=False )
                 assert type( ld ) is trans.app.model.LibraryDataset, "Library content id ( %s ) is not a dataset" % from_ld_id
             except AssertionError, e:
                 trans.response.status = 400

lib/galaxy/web/api/library_contents.py

         """
         class_name, content_id = self.__decode_library_content_id( trans, id )
         if class_name == 'LibraryFolder':
-            content = self.get_library_folder( trans, content_id, check_ownership=False, check_accessibility=True )
+            content = self.get_library_folder( trans, content_id, check_ownership=False, check_accessible=True )
         else:
-            content = self.get_library_dataset( trans, content_id, check_ownership=False, check_accessibility=True )
+            content = self.get_library_dataset( trans, content_id, check_ownership=False, check_accessible=True )
         return self.encode_all_ids( trans, content.get_api_value( view='element' ) )
 
     @web.expose_api
             return "Missing requred 'folder_id' parameter."
         else:
             folder_id = payload.pop( 'folder_id' )
+            class_name, folder_id = self.__decode_library_content_id( trans, folder_id )
         try:
             # security is checked in the downstream controller
-            parent = self.get_library_folder( trans, folder_id, check_ownership=False, check_accessibility=False )
+            parent = self.get_library_folder( trans, folder_id, check_ownership=False, check_accessible=False )
         except Exception, e:
             return str( e )
         # The rest of the security happens in the library_common controller.
                                    url = url_for( 'library_content', library_id=library_id, id=encoded_id ) ) )
             return rval
 
+    @web.expose_api
+    def update( self, trans, id,  library_id, payload, **kwd ):
+        """
+        PUT /api/libraries/{encoded_library_id}/contents/{encoded_content_type_and_id}
+        Sets relationships among items
+        """
+        if 'converted_dataset_id' in payload:
+            converted_id = payload.pop( 'converted_dataset_id' )
+            content = self.get_library_dataset( trans, id, check_ownership=False, check_accessible=False )
+            content_conv = self.get_library_dataset( trans, converted_id, check_ownership=False, check_accessible=False )
+            assoc = trans.app.model.ImplicitlyConvertedDatasetAssociation( parent = content.library_dataset_dataset_association,
+                dataset = content_conv.library_dataset_dataset_association,
+                file_type = content_conv.library_dataset_dataset_association.extension,
+                metadata_safe = True )
+            trans.sa_session.add( assoc )
+            trans.sa_session.flush()
+
     def __decode_library_content_id( self, trans, content_id ):
         if ( len( content_id ) % 16 == 0 ):
             return 'LibraryDataset', content_id