public function viewAction(Request $request, $id)
    {
        $em = $this->getDoctrine()->getManager();

        /** @var $file \Orkestra\Bundle\ApplicationBundle\Entity\File */
        $file = $em->find('Orkestra\Bundle\ApplicationBundle\Entity\File', $id);

        if (!$file || !file_exists($file->getPath())) {
            throw $this->createNotFoundException('Unable to locate File');
        }

        $securityContext = $this->get('security.context');

        foreach ($file->getGroups() as $group) {
            if (!$securityContext->isGranted($group->getRole())) {
                throw $this->createNotFoundException('Unable to locate File');
            }
        }

        $response = new Response();
        $response->setLastModified(new \DateTime('@' . filemtime($file->getPath())));
        $response->setPublic();
        if (($hash = $file->getMd5()) !== '') {
            $response->setEtag($hash);
        }

        if ($response->isNotModified($request)) {
            return $response;
        }

        $response->setContent($file->getContent());
        $response->headers->add(array(
            'Content-Type' => $file->getMimeType(),
        ));

        return $response;
    }