public static function getAnnotationTypeObject(AnnotationType $annotationType)
 {
     return array('id' => $annotationType->getId(), 'name' => $annotationType->getName());
 }
 public function createAnnotationTypeAction(Request $request, $datasetId)
 {
     $user = $this->getUser();
     if (!$this->container->get('image_annotator.authentication_manager')->isAuthenticated($request)) {
         return $this->redirect($this->generateUrl('fos_user_security_login'));
     }
     $userManager = $this->container->get('fos_user.user_manager');
     $userObject = $userManager->findUserByUsername($user->getUsername());
     if ($userObject == null) {
         throw new NotFoundHttpException("This user does not exist");
     }
     if (!$request->isXmlHttpRequest()) {
         throw new BadRequestHttpException('Only Ajax POST calls accepted');
     }
     $dataset = $this->getDoctrine()->getRepository('ImageAnnotatorBundle:Dataset')->find($datasetId);
     if ($dataset == null) {
         throw new NotFoundHttpException("This dataset does not exist");
     }
     $name = $request->get('name');
     $logger = $this->container->get('logger');
     $logger->info("name:" . $name);
     if ($name == null || strlen($name) < 2) {
         throw new NotFoundHttpException("This name does not exist/Name too short");
     }
     $annotationType = $this->getDoctrine()->getRepository('ImageAnnotatorBundle:AnnotationType')->findOneBy(array('name' => $name));
     if ($annotationType == null) {
         $annotationType = new AnnotationType();
         $annotationType->setName($name);
         $em = $this->container->get('doctrine')->getManager();
         $em->persist($annotationType);
         $dataset->addAnnotationType($annotationType);
         $em->flush();
         $return = array('annotationType' => JSEntities::getAnnotationTypeObject($annotationType), 'responseCode' => 200);
     } else {
         return $this->forward('ImageAnnotatorBundle:DatasetGateway:addAnnotationType', array('datasetId' => $datasetId, 'annotationTypeId' => $annotationType->getId()));
     }
     $return = json_encode($return);
     // json encode the array
     return new Response($return, 200, array('Content-Type' => 'application/json'));
 }