public ClientEntity getODataEntity()

in lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ODataBinderImpl.java [635:748]


  public ClientEntity getODataEntity(final ResWrap<Entity> resource) {
    if (LOG.isDebugEnabled()) {
      final StringWriter writer = new StringWriter();
      try {
        client.getSerializer(ContentType.JSON).write(writer, resource.getPayload());
      } catch (final ODataSerializerException e) {
        LOG.debug("EntityResource -> ODataEntity:\n{}", writer.toString());
      }
      writer.flush();
      LOG.debug("EntityResource -> ODataEntity:\n{}", writer.toString());
    }

    final ContextURL contextURL = ContextURLParser.parse(resource.getContextURL());
    final URI base = resource.getContextURL() == null
        ? resource.getPayload().getBaseURI()
        : contextURL.getServiceRoot();
    final EdmType edmType = findType(resource.getPayload().getType(), contextURL, resource.getMetadataETag());
    FullQualifiedName typeName = null;
    if (resource.getPayload().getType() == null) {
      if (edmType != null) {
        typeName = edmType.getFullQualifiedName();
      }
    } else {
      typeName = new FullQualifiedName(resource.getPayload().getType());
    }

    final ClientEntity entity = resource.getPayload().getSelfLink() == null
        ? client.getObjectFactory().newEntity(typeName)
        : client.getObjectFactory().newEntity(typeName,
            URIUtils.getURI(base, resource.getPayload().getSelfLink().getHref()));

    if (StringUtils.isNotBlank(resource.getPayload().getETag())) {
      entity.setETag(resource.getPayload().getETag());
    }

    if (resource.getPayload().getEditLink() != null) {
      entity.setEditLink(URIUtils.getURI(base, resource.getPayload().getEditLink().getHref()));
    }

    for (Link link : resource.getPayload().getAssociationLinks()) {
      entity.addLink(client.getObjectFactory().
          newAssociationLink(link.getTitle(), URIUtils.getURI(base, link.getHref())));
    }

    odataNavigationLinks(edmType, resource.getPayload(), entity, resource.getMetadataETag(), base);

    for (Link link : resource.getPayload().getMediaEditLinks()) {
      if (link.getRel().startsWith(Constants.NS_MEDIA_READ_LINK_REL)) {
        entity.addLink(client.getObjectFactory().newMediaReadLink(link.getTitle(), 
            URIUtils.getURI(base, link.getHref()), link.getType(), link.getMediaETag()));
      } else {
        entity.addLink(client.getObjectFactory().newMediaEditLink(link.getTitle(), 
            URIUtils.getURI(base, link.getHref()), link.getType(), link.getMediaETag()));        
      }
    }

    for (Operation op : resource.getPayload().getOperations()) {
      ClientOperation operation = new ClientOperation();
      operation.setTarget(URIUtils.getURI(base, op.getTarget()));
      operation.setTitle(op.getTitle());
      operation.setMetadataAnchor(op.getMetadataAnchor());
      entity.getOperations().add(operation);
    }

    if (resource.getPayload().isMediaEntity()) {
      entity.setMediaEntity(true);
      entity.setMediaContentSource(URIUtils.getURI(base, resource.getPayload().getMediaContentSource()));
      entity.setMediaContentType(resource.getPayload().getMediaContentType());
      entity.setMediaETag(resource.getPayload().getMediaETag());
    }

    Map<String, Integer> countMap = new HashMap<>();
    for (final Property property : resource.getPayload().getProperties()) {
      EdmType propertyType = null;
      if (edmType instanceof EdmEntityType) {
        EdmElement edmProperty = ((EdmEntityType) edmType).getProperty(property.getName());
        if (edmProperty != null) {
          propertyType = edmProperty.getType();
          if (edmProperty instanceof EdmNavigationProperty && !property.isNull()) {
            final String propertyTypeName = propertyType.getFullQualifiedName().getFullQualifiedNameAsString();
            entity.addLink(createLinkFromNavigationProperty(property, propertyTypeName, 
                countMap.remove(property.getName())));
            continue;
          }
        } else {
          int idx =  property.getName().indexOf(Constants.JSON_COUNT);
          if (idx != -1) {
            String navigationName = property.getName().substring(0, idx);
            edmProperty = ((EdmEntityType) edmType).getProperty(navigationName);
            if (edmProperty != null && edmProperty instanceof EdmNavigationProperty) {
              ClientLink link = entity.getNavigationLink(navigationName);
              if (link == null) {
                countMap.put(navigationName, (Integer) property.getValue());
              } else {
                link.asInlineEntitySet().getEntitySet().setCount((Integer) property.getValue());
              }
            }            
          }
        }
      }
      add(entity, getODataProperty(propertyType, property));
    }
    
    if (!countMap.isEmpty()) {
      for (Entry<String, Integer> entry : countMap.entrySet()) {
        entity.addLink(createLinkFromEmptyNavigationProperty(entry.getKey(), entry.getValue()));
      }
    }

    entity.setId(resource.getPayload().getId());
    odataAnnotations(resource.getPayload(), entity);

    return entity;
  }