private void handleDocumentAnnotation()

in src/main/java/org/apache/uima/json/jsoncas2/ser/FeatureStructureDeserializer.java [271:298]


  private void handleDocumentAnnotation(DeserializationContext aCtxt, CAS aCas,
          FeatureStructure aFS) throws JsonParseException {
    TypeSystem ts = aCas.getTypeSystem();
    Type docAnnoType = ts.getType(TYPE_NAME_DOCUMENT_ANNOTATION);
    if (!ts.subsumes(docAnnoType, aFS.getType())) {
      return;
    }

    String viewName = ((Annotation) aFS).getSofa().getSofaID();

    // Case 2b/3b: we already have handled the primary document annotation, this one is an extra
    if (isDocumentAnnotationCreated(aCtxt, viewName)) {
      // Nothing extra to do
      return;
    }

    Collection<TOP> docAnnotations = aCas.getIndexedFSs(docAnnoType);
    // Case 1: was no document annotation yet
    if (docAnnotations.isEmpty()) {
      markDocumentAnnotationCreated(aCtxt, viewName);
      return;
    }

    // Case 3a: need to replace the existing document annotation because it has a different type
    docAnnotations.forEach(aCas::removeFsFromIndexes);
    aCas.addFsToIndexes(aFS);
    markDocumentAnnotationCreated(aCtxt, viewName);
  }