private static void fillAttachment(
      Attachment attachment,
      ObjectFactory objectFactory,
      URI baseUri,
      com.xpn.xwiki.api.Attachment xwikiAttachment,
      String xwikiRelativeUrl,
      String xwikiAbsoluteUrl,
      XWiki xwikiApi,
      Boolean withPrettyNames) {
    Document doc = xwikiAttachment.getDocument();

    attachment.setId(
        String.format("%s@%s", doc.getPrefixedFullName(), xwikiAttachment.getFilename()));
    attachment.setName(xwikiAttachment.getFilename());
    attachment.setSize(xwikiAttachment.getFilesize());
    attachment.setVersion(xwikiAttachment.getVersion());
    attachment.setPageId(doc.getPrefixedFullName());
    attachment.setPageVersion(doc.getVersion());
    attachment.setMimeType(xwikiAttachment.getMimeType());
    attachment.setAuthor(xwikiAttachment.getAuthor());
    if (withPrettyNames) {
      attachment.setAuthorName(xwikiApi.getUserName(xwikiAttachment.getAuthor(), false));
    }

    Calendar calendar = Calendar.getInstance();
    calendar.setTime(xwikiAttachment.getDate());
    attachment.setDate(calendar);

    attachment.setXwikiRelativeUrl(xwikiRelativeUrl);
    attachment.setXwikiAbsoluteUrl(xwikiAbsoluteUrl);

    String pageUri = uri(baseUri, PageResource.class, doc.getWiki(), doc.getSpace(), doc.getName());
    Link pageLink = objectFactory.createLink();
    pageLink.setHref(pageUri);
    pageLink.setRel(Relations.PAGE);
    attachment.getLinks().add(pageLink);
  }