@Override
  public ODataEntity getODataEntity(final Entry resource, final URI defaultBaseURI) {
    if (LOG.isDebugEnabled()) {
      final StringWriter writer = new StringWriter();
      client.getSerializer().entry(resource, writer);
      writer.flush();
      LOG.debug("EntryResource -> ODataEntity:\n{}", writer.toString());
    }

    final URI base = defaultBaseURI == null ? resource.getBaseURI() : defaultBaseURI;

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

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

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

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

    for (Link link : resource.getNavigationLinks()) {
      final Entry inlineEntry = link.getInlineEntry();
      final Feed inlineFeed = link.getInlineFeed();

      if (inlineEntry == null && inlineFeed == null) {
        entity.addLink(
            client
                .getObjectFactory()
                .newEntityNavigationLink(link.getTitle(), base, link.getHref()));
      } else if (inlineFeed == null) {
        entity.addLink(
            client
                .getObjectFactory()
                .newInlineEntity(
                    link.getTitle(),
                    base,
                    link.getHref(),
                    getODataEntity(
                        inlineEntry,
                        inlineEntry.getBaseURI() == null ? base : inlineEntry.getBaseURI())));
      } else {
        entity.addLink(
            client
                .getObjectFactory()
                .newInlineEntitySet(
                    link.getTitle(),
                    base,
                    link.getHref(),
                    getODataEntitySet(
                        inlineFeed,
                        inlineFeed.getBaseURI() == null ? base : inlineFeed.getBaseURI())));
      }
    }

    for (Link link : resource.getMediaEditLinks()) {
      entity.addLink(
          client.getObjectFactory().newMediaEditLink(link.getTitle(), base, link.getHref()));
    }

    for (ODataOperation operation : resource.getOperations()) {
      operation.setTarget(URIUtils.getURI(base, operation.getTarget()));
      entity.getOperations().add(operation);
    }

    if (resource.isMediaEntry()) {
      entity.setMediaEntity(true);
      entity.setMediaContentSource(resource.getMediaContentSource());
      entity.setMediaContentType(resource.getMediaContentType());
    }

    for (Property property : resource.getProperties()) {
      entity.getProperties().add(getODataProperty(property));
    }

    return entity;
  }
  @Override
  public Entry getEntry(
      final ODataEntity entity, final Class<? extends Entry> reference, final boolean setType) {
    final Entry entry = ResourceFactory.newEntry(reference);
    entry.setType(entity.getName());

    // -------------------------------------------------------------
    // Add edit and self link
    // -------------------------------------------------------------
    final URI editLink = entity.getEditLink();
    if (editLink != null) {
      final LinkImpl entryEditLink = new LinkImpl();
      entryEditLink.setTitle(entity.getName());
      entryEditLink.setHref(editLink.toASCIIString());
      entryEditLink.setRel(Constants.EDIT_LINK_REL);
      entry.setEditLink(entryEditLink);
    }

    if (entity.isReadOnly()) {
      final LinkImpl entrySelfLink = new LinkImpl();
      entrySelfLink.setTitle(entity.getName());
      entrySelfLink.setHref(entity.getLink().toASCIIString());
      entrySelfLink.setRel(Constants.SELF_LINK_REL);
      entry.setSelfLink(entrySelfLink);
    }
    // -------------------------------------------------------------

    // -------------------------------------------------------------
    // Append navigation links (handling inline entry / feed as well)
    // -------------------------------------------------------------
    // handle navigation links
    for (ODataLink link : entity.getNavigationLinks()) {
      // append link
      LOG.debug("Append navigation link\n{}", link);
      entry
          .getNavigationLinks()
          .add(
              getLink(link, ResourceFactory.formatForEntryClass(reference) == ODataPubFormat.ATOM));
    }
    // -------------------------------------------------------------

    // -------------------------------------------------------------
    // Append edit-media links
    // -------------------------------------------------------------
    for (ODataLink link : entity.getEditMediaLinks()) {
      LOG.debug("Append edit-media link\n{}", link);
      entry
          .getMediaEditLinks()
          .add(
              getLink(link, ResourceFactory.formatForEntryClass(reference) == ODataPubFormat.ATOM));
    }
    // -------------------------------------------------------------

    // -------------------------------------------------------------
    // Append association links
    // -------------------------------------------------------------
    for (ODataLink link : entity.getAssociationLinks()) {
      LOG.debug("Append association link\n{}", link);
      entry
          .getAssociationLinks()
          .add(
              getLink(link, ResourceFactory.formatForEntryClass(reference) == ODataPubFormat.ATOM));
    }
    // -------------------------------------------------------------

    if (entity.isMediaEntity()) {
      entry.setMediaContentSource(entity.getMediaContentSource());
      entry.setMediaContentType(entity.getMediaContentType());
    }

    for (ODataProperty property : entity.getProperties()) {
      entry.getProperties().add(getProperty(property, reference, setType));
    }

    return entry;
  }