@@ -2146,6 +2146,59 @@ def get_revisions_list(id):
21462146
21472147 return jsonify (results )
21482148
2149+ """
2150+ Get all organs associated with a given dataset
2151+
2152+ The gateway treats this endpoint as public accessible
2153+
2154+ Parameters
2155+ ----------
2156+ id : str
2157+ The HuBMAP ID (e.g. HBM123.ABCD.456) or UUID of given entity
2158+
2159+ Returns
2160+ -------
2161+ json
2162+ a list of all the organs associated with the target dataset
2163+ """
2164+ @app .route ('/datasets/<id>/organs' , methods = ['GET' ])
2165+ def get_associated_organs_from_dataset (id ):
2166+ # Token is not required, but if an invalid token provided,
2167+ # we need to tell the client with a 401 error
2168+ validate_token_if_auth_header_exists (request )
2169+
2170+ # Use the internal token to query the target entity
2171+ # since public entities don't require user token
2172+ token = get_internal_token ()
2173+
2174+ # Query target entity against uuid-api and neo4j and return as a dict if exists
2175+ entity_dict = query_target_entity (id , token )
2176+ normalized_entity_type = entity_dict ['entity_type' ]
2177+
2178+ # Only for Dataset
2179+ if normalized_entity_type != 'Dataset' :
2180+ bad_request_error ("The entity of given id is not a Dataset" )
2181+
2182+ # published/public datasets don't require token
2183+ if entity_dict ['status' ].lower () != DATASET_STATUS_PUBLISHED :
2184+ # Token is required and the user must belong to HuBMAP-READ group
2185+ token = get_user_token (request , non_public_access_required = True )
2186+
2187+ # By now, either the entity is public accessible or
2188+ # the user token has the correct access level
2189+ associated_organs = app_neo4j_queries .get_associated_organs_from_dataset (neo4j_driver_instance , entity_dict ['uuid' ])
2190+
2191+ # If there are zero items in the list associated organs, then there are no associated
2192+ # Organs and a 404 will be returned.
2193+ if len (associated_organs ) < 1 :
2194+ not_found_error ("the dataset does not have any associated organs" )
2195+
2196+ complete_entities_list = schema_manager .get_complete_entities_list (token , associated_organs )
2197+
2198+ # Final result after normalization
2199+ final_result = schema_manager .normalize_entities_list_for_response (complete_entities_list )
2200+
2201+ return jsonify (final_result )
21492202
21502203####################################################################################################
21512204## Internal Functions
0 commit comments