class FolderMapper implements EntityMapper<Folder> {

    @Override
    public XContentBuilder map(final EntityContainer<Folder> container) {
        Folder folder = container.getEntity();
        try (XContentBuilder jsonBuilder = XContentFactory.jsonBuilder()) {
            jsonBuilder
                    .startObject()
                    .field(DOC_TYPE_FIELD, SearchDocumentType.FOLDER.name())
                    .field("id", folder.getId())
                    .field("name", folder.getName())
                    .field("parentId", folder.getParentId())
                    .field("createdDate", parseDataToString(folder.getCreatedDate()));

            buildUserContent(container.getOwner(), jsonBuilder);
            buildMetadata(container.getMetadata(), jsonBuilder);
            buildPermissions(container.getPermissions(), jsonBuilder);

            jsonBuilder.endObject();

            return jsonBuilder;
        } catch (IOException e) {
            throw new IllegalArgumentException("Failed to create elasticsearch document for pipeline folder: ", e);
        }
    }

}