Class GS1AIObject

java.lang.Object
tools.pantheum.gaia.gs1.model.GS1AIObject

public class GS1AIObject extends Object
The result of parsing GS1 content — either a plain element string or a GS1 Digital Link URI — holding all resolved GS1AIObjectElement instances and any object-level validation errors.

Both the element list and the error list are mutable after construction. New elements are appended via add(GS1AIObjectElement) and new object-level errors via addError(GaiaError). Public accessors always return defensive unmodifiable views.

Validity is determined by isValid(): the object is valid when there are no object-level non-WARNING errors and no element has attached errors. GaiaConstants.ErrorLevel.WARNING advisories do not affect validity.

  • Constructor Details

  • Method Details

    • getAchievedParseMode

      public GS1Constants.ParseMode getAchievedParseMode()
      The deepest pipeline stage actually reached during parsing (SYNTAX, CONTENT, or INTERPRETATION). This may be shallower than the requested mode when the pipeline stops early on errors. Set by the parsing pipeline; null if not produced by the pipeline.
      Returns:
      the achieved parse mode.
    • setAchievedParseMode

      public void setAchievedParseMode(GS1Constants.ParseMode mode)
      Records the deepest pipeline stage reached. Called by the parsing pipeline.
      Parameters:
      mode - the mode
    • add

      public void add(GS1AIObjectElement element)
      Adds a GS1AIObjectElement to this object.
      Parameters:
      element - the element to add; must not be null
    • addError

      public void addError(GaiaError error)
      Adds a GaiaError to this object.
      Parameters:
      error - the error to add; must not be null
    • getDigitalLinkInfo

      public GS1DigitalLinkInfo getDigitalLinkInfo()
      Metadata extracted from a GS1 Digital Link URI, or null if the input was not a Digital Link.
      Returns:
      the digital link info.
    • hasDigitalLink

      public boolean hasDigitalLink()
      Returns true if the input was a GS1 Digital Link URI carrying at least one primary identification key. The URL metadata may still be present (see getDigitalLinkInfo()) for a well-formed URL that lacks a primary key — such an input is not a usable Digital Link.
      Returns:
      true if this element has digital link.
    • getContentType

      public GS1Constants.GS1ContentType getContentType()
      Returns:
      the content type.
    • getAis

      public List<GS1AIObjectElement> getAis()
      All resolved AIs in input order.
      Returns:
      the AIs.
    • get

      public GS1AIObjectElement get(String aiCode)
      Returns the first AI matching the given code, or null if not present.
      Parameters:
      aiCode - the AI code
      Returns:
      the .
    • contains

      public boolean contains(String aiCode)
      Returns true if an AI with the given code is present.
      Parameters:
      aiCode - the AI code
      Returns:
      true if contains.
    • getErrors

      public List<GaiaError> getErrors()
      Object-level non-WARNING errors produced during parsing. Element-level errors (including structural integrity errors) are held on individual elements — use getAllErrors() to collect errors from all levels. Warnings are excluded; use getWarnings() to retrieve those.
      Returns:
      the errors.
    • getWarnings

      public List<GaiaError> getWarnings()
      Object-level GaiaConstants.ErrorLevel.WARNING advisories.
      Returns:
      the warnings.
    • getAllErrors

      public List<GaiaError> getAllErrors()
      All non-WARNING issues from both the object level and every element, in order: object-level errors first, then each element's errors in element order.
      Returns:
      the all errors.
    • getAllWarnings

      public List<GaiaError> getAllWarnings()
      All GaiaConstants.ErrorLevel.WARNING advisories from both the object level and every element.
      Returns:
      the all warnings.
    • getAllIssues

      public List<GaiaError> getAllIssues()
      All issues regardless of level — errors and warnings combined — from both the object level and every element. Use this when you need the complete picture.
      Returns:
      the all issues.
    • isValid

      public boolean isValid()
      Returns true only when there are no object-level errors and no element has any attached errors. GaiaConstants.ErrorLevel.WARNING advisories do not affect validity.
      Returns:
      true if this element is valid.
    • size

      public int size()
      Number of AIs held.
      Returns:
      the size.
    • toHriString

      public String toHriString()
      Returns the Human Readable Interpretation (HRI) of all AIs. Each AI is rendered as (aiCode)value and the elements are space-separated, e.g. (01)09506000134352 (17)271231 (10)LOT-ABC.
      Returns:
      the to HRI string.
    • toElementString

      public String toElementString()
      Renders all AIs as a raw GS1 element string — no brackets, each AI code immediately followed by its value, with an FNC1 (GS, ASCII 0x1D) separator after every variable-length element that is not the last (GS1AIObjectElement.isFixedLength()). Example: 010950600013435210LOT-ABC<GS>17271231.

      Only an error-free object can be rendered faithfully, so this method returns null when isValid() is false.

      Returns:
      the element string, or null if this object carries errors
    • getCanonicalDigitalLink

      public String getCanonicalDigitalLink()
      Returns the canonical GS1 Digital Link URI for this object (GS1 Digital Link Standard: URI Syntax §4.12), or null if this object was not parsed from a Digital Link — i.e. no element carries the GS1Constants.DigitalLinkAIType.PRIMARY_IDENTIFICATION_KEY role.

      The canonical form uses the https scheme on the id.gs1.org domain, the primary identification key and its key qualifiers as path segments (in their canonical order), and data attributes as query parameters sorted lexically by AI key. Reserved characters in values are percent-encoded (§4.2); GTIN values remain 14 digits.

      Example: an object parsed from http://example.com/01/09520123456788/22/2A?linkType=gs1:traceability yields https://id.gs1.org/01/09520123456788/22/2A.

      Returns:
      the canonical GS1 Digital Link URI, or null
    • toString

      public String toString()
      Overrides:
      toString in class Object