private boolean checkIfPathMatchesForEncoding(List<ElementsPath> theElements, boolean theCheckingForEncodeElements) { myEncodeContext.pushPath(myDef.getElementName(), false); if (theCheckingForEncodeElements && isEncodeElementsAppliesToChildResourcesOnly() && myEncodeContext.getResourcePath().size() < 2) { retVal = true; } else if (theElements == null) { retVal = true; } else { EncodeContextPath currentResourcePath = myEncodeContext.getCurrentResourcePath(); ourLog.trace("Current resource path: {}", currentResourcePath); for (ElementsPath next : theElements) { myEncodeContext.popPath(); return retVal;
private boolean checkIfParentShouldBeEncodedAndBuildPath() { List<ElementsPath> encodeElements = myEncodeElements; String currentResourceName = myEncodeContext.getResourcePath().get(myEncodeContext.getResourcePath().size() - 1).getName(); if (myEncodeElementsAppliesToResourceTypes != null && !myEncodeElementsAppliesToResourceTypes.contains(currentResourceName)) { encodeElements = null; } boolean retVal = checkIfPathMatchesForEncoding(encodeElements, true); /* * We force the meta tag to be encoded even if it's not specified as an element in the * elements filter, specifically because we'll need it in order to automatically add * the SUBSETTED tag */ if (!retVal) { if ("meta".equals(myEncodeContext.getLeafResourcePathFirstField()) && shouldAddSubsettedTag(myEncodeContext)) { // The next element is a child of the <meta> element retVal = true; } else if ("meta".equals(myDef.getElementName()) && shouldAddSubsettedTag(myEncodeContext)) { // The next element is the <meta> element retVal = true; } } return retVal; }
/** * Add an element at the end of the path */ protected void pushPath(String thePathElement, boolean theResource) { assert isNotBlank(thePathElement); assert !thePathElement.contains("."); assert theResource ^ Character.isLowerCase(thePathElement.charAt(0)); EncodeContextPathElement element = new EncodeContextPathElement(thePathElement, theResource); getPath().add(element); if (theResource) { myResourcePath.add(element); } }
private void encodeChildElementToStreamWriter(IBaseResource theResource, XMLStreamWriter theEventWriter, IBase theElement, String childName, BaseRuntimeElementDefinition<?> childDef, String theExtensionUrl, boolean theIncludedResource, CompositeChildElement theParent, EncodeContext theEncodeContext) throws XMLStreamException, DataFormatException { theEncodeContext.pushPath(childName, false); try { IBaseResource resource = (IBaseResource) theElement; String resourceName = myContext.getResourceDefinition(resource).getName(); theEncodeContext.pushPath(resourceName, true); encodeResourceToXmlStreamWriter(resource, theEventWriter, false, theEncodeContext); theEncodeContext.popPath(); theEventWriter.writeEndElement(); break; theEncodeContext.popPath();
for (BaseCodingDt securityLabel : securityLabels) { theEventWriter.beginObject(); theEncodeContext.pushPath("security", false); encodeCompositeElementChildrenToStreamWriter(resDef, resource, securityLabel, theEventWriter, theContainedResource, null, theEncodeContext); theEncodeContext.popPath(); theEventWriter.endObject();
protected boolean shouldEncodeResourceId(IBaseResource theResource, EncodeContext theEncodeContext) { boolean retVal = true; if (isOmitResourceId()) { retVal = false; } else { if (myDontEncodeElements != null) { String resourceName = myContext.getResourceDefinition(theResource).getName(); if (myDontEncodeElements.stream().anyMatch(t -> t.equalsPath(resourceName + ".id"))) { retVal = false; } else if (myDontEncodeElements.stream().anyMatch(t -> t.equalsPath("*.id"))) { retVal = false; } else if (theEncodeContext.getResourcePath().size() == 1 && myDontEncodeElements.stream().anyMatch(t -> t.equalsPath("id"))) { retVal = false; } } } return retVal; }
private void encodeResourceToJsonStreamWriter(RuntimeResourceDefinition theResDef, IBaseResource theResource, JsonLikeWriter theEventWriter, String theObjectNameOrNull, boolean theContainedResource, EncodeContext theEncodeContext) throws IOException { IIdType resourceId = null; if (StringUtils.isNotBlank(theResource.getIdElement().getIdPart())) { resourceId = theResource.getIdElement(); if (theResource.getIdElement().getValue().startsWith("urn:")) { resourceId = null; } } if (!theContainedResource) { if (!super.shouldEncodeResourceId(theResource, theEncodeContext)) { resourceId = null; } else if (theEncodeContext.getResourcePath().size() == 1 && getEncodeForceResourceId() != null) { resourceId = getEncodeForceResourceId(); } } encodeResourceToJsonStreamWriter(theResDef, theResource, theEventWriter, theObjectNameOrNull, theContainedResource, resourceId, theEncodeContext); }
protected boolean shouldAddSubsettedTag(EncodeContext theEncodeContext) { if (isSummaryMode()) { return true; } if (isSuppressNarratives()) { return true; } if (myEncodeElements != null) { if (isEncodeElementsAppliesToChildResourcesOnly() && theEncodeContext.getResourcePath().size() < 2) { return false; } String currentResourceName = theEncodeContext.getResourcePath().get(theEncodeContext.getResourcePath().size() - 1).getName(); if (myEncodeElementsAppliesToResourceTypes == null || myEncodeElementsAppliesToResourceTypes.contains(currentResourceName)) { return true; } } return false; }
private void encodeResourceToXmlStreamWriter(IBaseResource theResource, XMLStreamWriter theEventWriter, boolean theIncludedResource, EncodeContext theEncodeContext) throws XMLStreamException, DataFormatException { IIdType resourceId = null; if (StringUtils.isNotBlank(theResource.getIdElement().getIdPart())) { resourceId = theResource.getIdElement(); if (theResource.getIdElement().getValue().startsWith("urn:")) { resourceId = null; } } if (!theIncludedResource) { if (super.shouldEncodeResourceId(theResource, theEncodeContext) == false) { resourceId = null; } else if (theEncodeContext.getResourcePath().size() == 1 && getEncodeForceResourceId() != null) { resourceId = getEncodeForceResourceId(); } } encodeResourceToXmlStreamWriter(theResource, theEventWriter, theIncludedResource, resourceId, theEncodeContext); }
protected void encodeResourceToWriter(IBaseResource theResource, Writer theWriter, EncodeContext theEncodeContext) throws IOException { Validate.notNull(theResource, "theResource can not be null"); Validate.notNull(theWriter, "theWriter can not be null"); Validate.notNull(theEncodeContext, "theEncodeContext can not be null"); if (theResource.getStructureFhirVersionEnum() != myContext.getVersion().getVersion()) { throw new IllegalArgumentException( "This parser is for FHIR version " + myContext.getVersion().getVersion() + " - Can not encode a structure for version " + theResource.getStructureFhirVersionEnum()); } String resourceName = myContext.getResourceDefinition(theResource).getName(); theEncodeContext.pushPath(resourceName, true); doEncodeResourceToWriter(theResource, theWriter, theEncodeContext); theEncodeContext.popPath(); }
@Override public void encodeResourceToJsonLikeWriter(IBaseResource theResource, JsonLikeWriter theJsonLikeWriter) throws IOException, DataFormatException { Validate.notNull(theResource, "theResource can not be null"); Validate.notNull(theJsonLikeWriter, "theJsonLikeWriter can not be null"); if (theResource.getStructureFhirVersionEnum() != myContext.getVersion().getVersion()) { throw new IllegalArgumentException( "This parser is for FHIR version " + myContext.getVersion().getVersion() + " - Can not encode a structure for version " + theResource.getStructureFhirVersionEnum()); } EncodeContext encodeContext = new EncodeContext(); String resourceName = myContext.getResourceDefinition(theResource).getName(); encodeContext.pushPath(resourceName, true); doEncodeResourceToJsonLikeWriter(theResource, theJsonLikeWriter, encodeContext); }
@Override public final void encodeResourceToWriter(IBaseResource theResource, Writer theWriter) throws IOException, DataFormatException { EncodeContext encodeContext = new EncodeContext(); encodeResourceToWriter(theResource, theWriter, encodeContext); }