Class MetadataService

java.lang.Object
com.gooddata.sdk.service.AbstractService
com.gooddata.sdk.service.md.MetadataService

public class MetadataService extends AbstractService
Query, create and update project metadata - attributes, facts, metrics, reports,...
  • Field Details

    • OBJ_TEMPLATE

      public static final org.springframework.web.util.UriTemplate OBJ_TEMPLATE
  • Constructor Details

    • MetadataService

      public MetadataService(org.springframework.web.client.RestTemplate restTemplate, GoodDataSettings settings)
  • Method Details

    • createObj

      public <T extends Obj> T createObj(Project project, T obj)
      Create metadata object in given project
      Type Parameters:
      T - type of the object to be created
      Parameters:
      project - project
      obj - metadata object to be created
      Returns:
      new metadata object
      Throws:
      ObjCreateException - if creation failed
      ObjNotFoundException - if new metadata object not found after creation
      com.gooddata.sdk.common.GoodDataRestException - if GoodData REST API returns unexpected status code when getting the new object
      com.gooddata.sdk.common.GoodDataException - if no response from API or client-side HTTP error when getting the new object
    • getObjByUri

      public <T extends Obj> T getObjByUri(String uri, Class<T> cls)
      Get metadata object by URI (format is /gdc/md/{PROJECT_ID}/obj/{OBJECT_ID})
      Type Parameters:
      T - type of the object to be returned
      Parameters:
      uri - URI in format /gdc/md/{PROJECT_ID}/obj/{OBJECT_ID}
      cls - class of the resulting object
      Returns:
      the metadata object
      Throws:
      ObjNotFoundException - if metadata object not found
      com.gooddata.sdk.common.GoodDataRestException - if GoodData REST API returns unexpected status code
      com.gooddata.sdk.common.GoodDataException - if no response from API or client-side HTTP error
    • getObjsByUris

      public Collection<Obj> getObjsByUris(Project project, Collection<String> uris)
      Retrieves a collection of objects corresponding to the supplied collection of URIs.
      Parameters:
      project - project that contains the objects to be retrieved
      uris - collection of URIs
      Returns:
      collection of metadata objects corresponding to the supplied URIs
    • updateObj

      public <T extends Updatable> T updateObj(T obj)
      Update given metadata object.
      Type Parameters:
      T - type of the updated object
      Parameters:
      obj - object to update
      Returns:
      updated metadata object
      Throws:
      ObjUpdateException - in case of error
    • removeObj

      public void removeObj(Obj obj)
      Remove metadata object URI
      Parameters:
      obj - metadata object to remove
      Throws:
      ObjNotFoundException - if metadata object not found
      com.gooddata.sdk.common.GoodDataRestException - if GoodData REST API returns unexpected status code
      com.gooddata.sdk.common.GoodDataException - if no response from API or client-side HTTP error
    • removeObjByUri

      public void removeObjByUri(String uri)
      Remove metadata object by URI (format is /gdc/md/{PROJECT_ID}/obj/{OBJECT_ID})
      Parameters:
      uri - URI in format /gdc/md/{PROJECT_ID}/obj/{OBJECT_ID}
      Throws:
      ObjNotFoundException - if metadata object not found
      com.gooddata.sdk.common.GoodDataRestException - if GoodData REST API returns unexpected status code
      com.gooddata.sdk.common.GoodDataException - if no response from API or client-side HTTP error
    • getObjById

      public <T extends Obj> T getObjById(Project project, String id, Class<T> cls)
      Get metadata object by id.
      Type Parameters:
      T - type of the object to be returned
      Parameters:
      project - project where to search for the object
      id - id of the object
      cls - class of the resulting object
      Returns:
      the metadata object
      Throws:
      ObjNotFoundException - if metadata object not found
      com.gooddata.sdk.common.GoodDataRestException - if GoodData REST API returns unexpected status code
      com.gooddata.sdk.common.GoodDataException - if no response from API or client-side HTTP error
    • getObjUri

      public <T extends Queryable> String getObjUri(Project project, Class<T> cls, Restriction... restrictions)
      Get metadata object URI by restrictions like identifier, title or summary.
      Type Parameters:
      T - type of the object to be returned
      Parameters:
      project - project where to search for the object
      cls - class of the resulting object
      restrictions - query restrictions
      Returns:
      the URI of metadata object
      Throws:
      ObjNotFoundException - if metadata object not found
      NonUniqueObjException - if more than one object corresponds to search restrictions
    • getObj

      public <T extends Queryable> T getObj(Project project, Class<T> cls, Restriction... restrictions)
      Get metadata object by restrictions like identifier, title or summary.
      Type Parameters:
      T - type of the object to be returned
      Parameters:
      project - project where to search for the object
      cls - class of the resulting object
      restrictions - query restrictions
      Returns:
      metadata object
      Throws:
      ObjNotFoundException - if metadata object not found
      NonUniqueObjException - if more than one object corresponds to search restrictions
    • find

      public <T extends Queryable> Collection<Entry> find(Project project, Class<T> cls, Restriction... restrictions)
      Find metadata by restrictions like identifier, title or summary.
      Type Parameters:
      T - type of the metadata referenced in returned entries
      Parameters:
      project - project where to search for the metadata
      cls - class of searched metadata
      restrictions - query restrictions
      Returns:
      the collection of metadata entries
      Throws:
      com.gooddata.sdk.common.GoodDataException - if unable to query metadata
    • findUris

      public <T extends Queryable> Collection<String> findUris(Project project, Class<T> cls, Restriction... restrictions)
      Find metadata URIs by restrictions like identifier, title or summary.
      Type Parameters:
      T - type of the metadata referenced by returned URIs
      Parameters:
      project - project where to search for the metadata
      cls - class of searched metadata
      restrictions - query restrictions
      Returns:
      the collection of metadata URIs
      Throws:
      com.gooddata.sdk.common.GoodDataException - if unable to query metadata
    • usedBy

      public Collection<Entry> usedBy(Project project, Obj obj, boolean nearest, Class<? extends Obj>... types)
      Find all objects which use the given object.
      Parameters:
      project - project
      obj - object to find using objects for
      nearest - find nearest objects only
      types - what types (categories) to search for (for example 'reportDefinition', 'report', 'tableDataLoad', 'table'...)
      Returns:
      objects using given objects.
    • usedBy

      public Collection<Entry> usedBy(Project project, String uri, boolean nearest, Class<? extends Obj>... types)
      Find all objects which use the given object.
      Parameters:
      project - project
      uri - URI of object to find using objects for
      nearest - find nearest objects only
      types - what types (categories) to search for (for example 'reportDefinition', 'report', 'tableDataLoad', 'table'...)
      Returns:
      objects using given objects.
      See Also:
    • usedBy

      public Collection<Usage> usedBy(Project project, Collection<String> uris, boolean nearest, Class<? extends Obj>... types)
      Find all objects which use the given objects. Batch alternative to usedBy(Project, String, boolean, Class[])
      Parameters:
      project - project
      uris - URIs of object to find using objects for
      nearest - find nearest objects only
      types - what types (categories) to search for (for example 'reportDefinition', 'report', 'tableDataLoad', 'table'...), returns all objects if no type is provided
      Returns:
      objects usages
      See Also:
    • findUris

      public Collection<String> findUris(Project project, Restriction... restrictions)
      Find metadata URIs by restrictions. Identifier is the only supported restriction.
      Parameters:
      project - project where to search for the metadata
      restrictions - query restrictions
      Returns:
      the collection of metadata URIs
      Throws:
      com.gooddata.sdk.common.GoodDataException - if unable to query metadata
    • identifiersToUris

      public Map<String,String> identifiersToUris(Project project, Collection<String> identifiers)
      Find metadata URIs for given identifiers.
      Parameters:
      project - project where to search for the metadata
      identifiers - query restrictions
      Returns:
      the map of identifiers as keys and metadata URIs as values
      Throws:
      com.gooddata.sdk.common.GoodDataException - if unable to query metadata
      See Also:
    • getAttributeElements

      public List<AttributeElement> getAttributeElements(Attribute attribute)
      Fetches attribute elements for given attribute using default display form.
      Parameters:
      attribute - attribute to fetch elements for
      Returns:
      attribute elements or empty set if there is no link for elements in default display form
    • getAttributeElements

      public List<AttributeElement> getAttributeElements(DisplayForm displayForm)
      Fetches attribute elements by given display form.
      Parameters:
      displayForm - display form to fetch attributes for
      Returns:
      attribute elements or empty set if there is no link for elements
    • getTimezone

      public String getTimezone(Project project)
      Get project/workspace timezone.
      Parameters:
      project - project from what to return the timezone
      Returns:
      string identifier of the timezone (see IANA/Olson tz database for possible values)
      Throws:
      com.gooddata.sdk.common.GoodDataRestException - if GoodData REST API returns unexpected status code
      com.gooddata.sdk.common.GoodDataException - if no response from API or client-side HTTP error
    • setTimezone

      public void setTimezone(Project project, String timezone)
      Set project/workspace timezone.
      Parameters:
      project - the project/workspace where to set the timezone
      timezone - the timezone to be set (see IANA/Olson tz database for possible values)