Package ca.uhn.fhir.context

Examples of ca.uhn.fhir.context.RuntimeResourceDefinition


  }

  private FhirContext myContext;

  public BaseRuntimeChildDefinition getDefinition(Class<? extends IResource> theResourceType, String thePath) {
    RuntimeResourceDefinition def = myContext.getResourceDefinition(theResourceType);

    BaseRuntimeElementCompositeDefinition<?> currentDef = def;

    List<String> parts = Arrays.asList(thePath.split("\\."));
    List<String> subList = parts.subList(1, parts.size());
View Full Code Here


      return getDefinition(cmp, theSubList.subList(1, theSubList.size()));
    }
  }

  public List<Object> getValues(IResource theResource, String thePath) {
    RuntimeResourceDefinition def = myContext.getResourceDefinition(theResource);

    BaseRuntimeElementCompositeDefinition<?> currentDef = def;
    Object currentObj = theResource;

    List<String> parts = Arrays.asList(thePath.split("\\."));
View Full Code Here

    BundleEntry entry = addEntry();
    entry.setResource(theResource);

    entry.setResource(theResource);

    RuntimeResourceDefinition def = theContext.getResourceDefinition(theResource);

    if (theResource.getId() != null && StringUtils.isNotBlank(theResource.getId().getValue())) {
      String title = ResourceMetadataKeyEnum.TITLE.get(theResource);
      if (title != null) {
        entry.getTitle().setValue(title);
      } else {
        entry.getTitle().setValue(def.getName() + " " + theResource.getId().getValue());
      }

      StringBuilder b = new StringBuilder();
      b.append(theServerBase);
      if (b.length() > 0 && b.charAt(b.length() - 1) != '/') {
        b.append('/');
      }
      b.append(def.getName());
      b.append('/');
      String resId = theResource.getId().getIdPart();
      b.append(resId);

      entry.getId().setValue(b.toString());

      if (isNotBlank(theResource.getId().getVersionIdPart())) {
        b.append('/');
        b.append(Constants.PARAM_HISTORY);
        b.append('/');
        b.append(theResource.getId().getVersionIdPart());
      } else {
        IdDt versionId = (IdDt) ResourceMetadataKeyEnum.VERSION_ID.get(theResource);
        if (versionId != null) {
          b.append('/');
          b.append(Constants.PARAM_HISTORY);
          b.append('/');
          b.append(versionId.getValue());
        }
      }

      entry.getLinkSelf().setValue(b.toString());
    }

    InstantDt published = ResourceMetadataKeyEnum.PUBLISHED.get(theResource);
    if (published == null) {
      entry.getPublished().setToCurrentTimeInLocalTimeZone();
    } else {
      entry.setPublished(published);
    }

    InstantDt updated = ResourceMetadataKeyEnum.UPDATED.get(theResource);
    if (updated != null) {
      entry.setUpdated(updated);
    }

    InstantDt deleted = ResourceMetadataKeyEnum.DELETED_AT.get(theResource);
    if (deleted != null) {
      entry.setDeleted(deleted);
    }

    IdDt previous = ResourceMetadataKeyEnum.PREVIOUS_ID.get(theResource);
    if (previous != null) {
      entry.getLinkAlternate().setValue(previous.withServerBase(theServerBase, def.getName()));
    }

    TagList tagList = ResourceMetadataKeyEnum.TAG_LIST.get(theResource);
    if (tagList != null) {
      for (Tag nextTag : tagList) {
View Full Code Here

        theProvider);

    Delete deleteAnnotation = theMethod.getAnnotation(Delete.class);
    Class<? extends IResource> resourceType = deleteAnnotation.type();
    if (resourceType != IResource.class) {
      RuntimeResourceDefinition def = theContext.getResourceDefinition(resourceType);
      myResourceName = def.getName();
    } else {
      if (theProvider != null && theProvider instanceof IResourceProvider) {
        RuntimeResourceDefinition def = theContext.getResourceDefinition(((IResourceProvider) theProvider).getResourceType());
        myResourceName = def.getName();
      } else {
        throw new ConfigurationException("Can not determine resource type for method '" + theMethod.getName() + "' on type " + theMethod.getDeclaringClass().getCanonicalName() + " - Did you forget to include the resourceType() value on the @"
            + Delete.class.getSimpleName() + " method annotation?");
      }
    }
View Full Code Here

   */
  public BundleEntry addResource(IResource theResource, FhirContext theContext, String theServerBase) {
    BundleEntry entry = addEntry();
    entry.setResource(theResource);

    RuntimeResourceDefinition def = theContext.getResourceDefinition(theResource);

    String title = ResourceMetadataKeyEnum.TITLE.get(theResource);
    if (title != null) {
      entry.getTitle().setValue(title);
    } else {
      entry.getTitle().setValue(def.getName() + " " + StringUtils.defaultString(theResource.getId().getValue(), "(no ID)"));
    }

    if (theResource.getId() != null && StringUtils.isNotBlank(theResource.getId().getValue())) {

      StringBuilder b = new StringBuilder();
      b.append(theServerBase);
      if (b.length() > 0 && b.charAt(b.length() - 1) != '/') {
        b.append('/');
      }
      b.append(def.getName());
      b.append('/');
      String resId = theResource.getId().getIdPart();
      b.append(resId);

      entry.getId().setValue(b.toString());

      if (isNotBlank(theResource.getId().getVersionIdPart())) {
        b.append('/');
        b.append(Constants.PARAM_HISTORY);
        b.append('/');
        b.append(theResource.getId().getVersionIdPart());
      } else {
        IdDt versionId = (IdDt) ResourceMetadataKeyEnum.VERSION_ID.get(theResource);
        if (versionId != null) {
          b.append('/');
          b.append(Constants.PARAM_HISTORY);
          b.append('/');
          b.append(versionId.getValue());
        }
      }

      String qualifiedId = b.toString();
      entry.getLinkSelf().setValue(qualifiedId);

      // String resourceType = theContext.getResourceDefinition(theResource).getName();

      String linkSearch = ResourceMetadataKeyEnum.LINK_SEARCH.get(theResource);
      if (isNotBlank(linkSearch)) {
        if (!UrlUtil.isAbsolute(linkSearch)) {
          linkSearch = (theServerBase + "/" + linkSearch);
        }
        entry.getLinkSearch().setValue(linkSearch);
      }

      String linkAlternate = ResourceMetadataKeyEnum.LINK_ALTERNATE.get(theResource);
      if (isNotBlank(linkAlternate)) {
        if (!UrlUtil.isAbsolute(linkAlternate)) {
          linkSearch = (theServerBase + "/" + linkAlternate);
        }
        entry.getLinkAlternate().setValue(linkSearch);
      }

    }

    InstantDt published = ResourceMetadataKeyEnum.PUBLISHED.get(theResource);
    if (published == null) {
      entry.getPublished().setToCurrentTimeInLocalTimeZone();
    } else {
      entry.setPublished(published);
    }

    InstantDt updated = ResourceMetadataKeyEnum.UPDATED.get(theResource);
    if (updated != null) {
      entry.setUpdated(updated);
    }

    InstantDt deleted = ResourceMetadataKeyEnum.DELETED_AT.get(theResource);
    if (deleted != null) {
      entry.setDeleted(deleted);
    }

    IdDt previous = ResourceMetadataKeyEnum.PREVIOUS_ID.get(theResource);
    if (previous != null) {
      entry.getLinkAlternate().setValue(previous.withServerBase(theServerBase, def.getName()));
    }

    TagList tagList = ResourceMetadataKeyEnum.TAG_LIST.get(theResource);
    if (tagList != null) {
      for (Tag nextTag : tagList) {
View Full Code Here

            throw new DataFormatException("Element '" + theLocalPart + "' is not a resource, expected a resource at this position");
          }
        }
      }

      RuntimeResourceDefinition def = (RuntimeResourceDefinition) definition;
      myInstance = def.newInstance();
      if (myEntry != null) {
        myEntry.setResource(myInstance);
      }

      if ("Binary".equals(def.getName())) {
        push(new BinaryResourceState(getRootPreResourceState(), (Binary) myInstance));
      } else {
        push(new ElementCompositeState(getRootPreResourceState(), def, myInstance));
      }
    }
View Full Code Here

  private void encodeResourceToXmlStreamWriter(IResource theResource, XMLStreamWriter theEventWriter, boolean theIncludedResource) throws XMLStreamException, DataFormatException {
    if (!theIncludedResource) {
      super.containResourcesForEncoding(theResource);
    }

    RuntimeResourceDefinition resDef = myContext.getResourceDefinition(theResource);
    if (resDef == null) {
      throw new ConfigurationException("Unknown resource type: " + theResource.getClass());
    }

    theEventWriter.writeStartElement(resDef.getName());
    theEventWriter.writeDefaultNamespace(FHIR_NS);

    if (theIncludedResource && StringUtils.isNotBlank(theResource.getId().getValue())) {
      theEventWriter.writeAttribute("id", theResource.getId().getValue());
    }
View Full Code Here

    }

    IResource resource = entry.getResource();
    if (resource == null && id != null && isNotBlank(id.getResourceType())) {
      String resourceType = id.getResourceType();
      RuntimeResourceDefinition def = myContext.getResourceDefinition(resourceType);
      if (def == null) {
        throw new DataFormatException("Entry references unknown resource type: " + resourceType);
      }
      resource = def.newInstance();
      resource.setId(id);
      entry.setResource(resource);
    }

    if (resource != null) {
View Full Code Here

      writeAuthor(nextEntry, eventWriter);

      IResource resource = nextEntry.getResource();
      if (resource != null && !resource.isEmpty() && !deleted) {
        RuntimeResourceDefinition resDef = myContext.getResourceDefinition(resource);
        encodeResourceToJsonStreamWriter(resDef, resource, eventWriter, "content", false);
      }

      eventWriter.writeEnd(); // entry object
    }
View Full Code Here

      boolean theIsSubElementWithinResource) throws IOException {
    if (!theIsSubElementWithinResource) {
      super.containResourcesForEncoding(theResource);
    }

    RuntimeResourceDefinition resDef = myContext.getResourceDefinition(theResource);

    if (theObjectNameOrNull == null) {
      theEventWriter.writeStartObject();
    } else {
      theEventWriter.writeStartObject(theObjectNameOrNull);
    }

    theEventWriter.write("resourceType", resDef.getName());
    if (theIsSubElementWithinResource && theResource.getId() != null && isNotBlank(theResource.getId().getValue())) {
      theEventWriter.write("id", theResource.getId().getValue());
    }

    if (theResource instanceof Binary) {
View Full Code Here

TOP

Related Classes of ca.uhn.fhir.context.RuntimeResourceDefinition

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.