Class TemplateHelper


  • public final class TemplateHelper
    extends java.lang.Object
    Static helper routines related to templates.
    Author:
    Thomas Riley, Richard Smith
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String apiTemplateMapToJson​(InterMineAPI im, java.util.Map<java.lang.String,​ApiTemplate> templates, Profile profile)
      Helper routine for serialising a map of templates to JSON.
      static java.lang.String apiTemplateMapToXml​(java.util.Map<java.lang.String,​ApiTemplate> templates, int version)
      Serialse a map of templates to XML.
      static TemplateQuery removeDirectAttributesFromView​(TemplateQuery tq)
      Removed from the view all the direct attributes that aren't editable constraints
      static java.lang.String templateMapToXml​(java.util.Map<java.lang.String,​TemplateQuery> templates, int version)
      Given a Map of TemplateQueries (mapping from template name to TemplateQuery) return a string containing each template seriaised as XML.
      static java.util.Map<java.lang.String,​ApiTemplate> upcast​(java.util.Map<java.lang.String,​TemplateQuery> templates)
      Transform a map of templates into a map of API templates.
      static java.util.Map<java.lang.String,​TemplateQuery> xmlToTemplateMap​(java.lang.String xml, java.util.Map<java.lang.String,​InterMineBag> savedBags, int version)
      Parse templates in XML format and return a map from template name to TemplateQuery.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • templateMapToXml

        public static java.lang.String templateMapToXml​(java.util.Map<java.lang.String,​TemplateQuery> templates,
                                                        int version)
        Given a Map of TemplateQueries (mapping from template name to TemplateQuery) return a string containing each template seriaised as XML. The root element will be a template-queries element.
        Parameters:
        templates - map from template name to TemplateQuery
        version - the version number of the XML format
        Returns:
        all template queries serialised as XML
        See Also:
        TemplateQuery
      • removeDirectAttributesFromView

        public static TemplateQuery removeDirectAttributesFromView​(TemplateQuery tq)
        Removed from the view all the direct attributes that aren't editable constraints
        Parameters:
        tq - The template to remove attributes from.
        Returns:
        altered template query
      • apiTemplateMapToXml

        public static java.lang.String apiTemplateMapToXml​(java.util.Map<java.lang.String,​ApiTemplate> templates,
                                                           int version)
        Serialse a map of templates to XML.
        Parameters:
        templates - The templates to serialise.
        version - The UserProfile version to use.
        Returns:
        An XML serialise.
      • upcast

        public static java.util.Map<java.lang.String,​ApiTemplate> upcast​(java.util.Map<java.lang.String,​TemplateQuery> templates)
        Transform a map of templates into a map of API templates.
        Parameters:
        templates - The original, non-api templates.
        Returns:
        templates brought into the realm of the API.
      • apiTemplateMapToJson

        public static java.lang.String apiTemplateMapToJson​(InterMineAPI im,
                                                            java.util.Map<java.lang.String,​ApiTemplate> templates,
                                                            Profile profile)
        Helper routine for serialising a map of templates to JSON.
        Parameters:
        templates - The map of templates to serialise.
        im - intermine API
        profile - user that owns these templates. Could be NULL
        Returns:
        A JSON string.
      • xmlToTemplateMap

        public static java.util.Map<java.lang.String,​TemplateQuery> xmlToTemplateMap​(java.lang.String xml,
                                                                                           java.util.Map<java.lang.String,​InterMineBag> savedBags,
                                                                                           int version)
                                                                                    throws java.lang.Exception
        Parse templates in XML format and return a map from template name to TemplateQuery.
        Parameters:
        xml - the template queries in xml format
        savedBags - Map from bag name to bag
        version - the version of the xml format, an attribute on ProfileManager
        Returns:
        Map from template name to TemplateQuery
        Throws:
        java.lang.Exception - when a parse exception occurs (wrapped in a RuntimeException)