class DockerRegistryMapper implements EntityMapper<DockerRegistry> {

    @Override
    public XContentBuilder map(final EntityContainer<DockerRegistry> container) {
        DockerRegistry dockerRegistry = container.getEntity();
        try (XContentBuilder jsonBuilder = XContentFactory.jsonBuilder()) {
            jsonBuilder
                    .startObject()
                    .field(DOC_TYPE_FIELD, SearchDocumentType.DOCKER_REGISTRY.name())
                    .field("id", dockerRegistry.getId())
                    .field("name", dockerRegistry.getName())
                    .field("path", dockerRegistry.getPath())
                    .field("createdDate", parseDataToString(dockerRegistry.getCreatedDate()))
                    .field("description", dockerRegistry.getDescription())
                    .field("userName", dockerRegistry.getUserName());

            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 docker registry: ", e);
        }
    }

}