Author: sevein
Date: Mon Oct 17 17:49:35 2011
New Revision: 10130

Log:
Send different summary and expected status code for each error case

Modified:
   
trunk/plugins/qtSwordPlugin/modules/qtSwordPlugin/actions/depositAction.class.php

Modified: 
trunk/plugins/qtSwordPlugin/modules/qtSwordPlugin/actions/depositAction.class.php
==============================================================================
--- 
trunk/plugins/qtSwordPlugin/modules/qtSwordPlugin/actions/depositAction.class.php
   Mon Oct 17 16:26:36 2011        (r10129)
+++ 
trunk/plugins/qtSwordPlugin/modules/qtSwordPlugin/actions/depositAction.class.php
   Mon Oct 17 17:49:35 2011        (r10130)
@@ -18,12 +18,12 @@
  */
 
 // TODO
-// Check user authorization
-// Check upload/repository limit
-// Check attatchment size, zero?
-// Package
-// Response
-// Complete XML error documents and use them correctly for each http status 
code
+// 1.2 Check user authorization
+// 1.2 Check upload/repository limit
+// post-1.2 PUT/DELETE verbs
+// post-1.2 X-On-Behalf-Of (mediation)
+// post-1.2 X-No-Op (dev feature: dry run)
+// post-1.2 X-Verbose (dev feature: verbose output)
 
 class qtSwordPluginDepositAction extends sfAction
 {
@@ -31,49 +31,34 @@
   {
     if (null === $this->resource = $this->getRoute()->resource)
     {
-      return $this->generateResponse(404, 'error/ErrorContent');
+      return $this->generateResponse(404, 'error/ErrorBadRequest', 
array('summary' => $this->context->i18n->__('Not found')));
     }
 
     $this->user = $request->getAttribute('user');
 
     if ($request->isMethod('post'))
     {
-      /* TODO: it is not working properly, see QubitAcl error
       if (QubitAcl::check(QubitInformationObject::getRoot(), 'create', 
array('user' => $this->user)))
       {
-        return $this->generateResponse(403);
+        return $this->generateResponse(403, 'error/ErrorBadRequest', 
array('summary' => $this->context->i18n->__('Forbidden')));
       }
-      */
 
       $this->packageFormat = $request->getHttpHeader('X-Packaging');
       $this->packageContentType = $request->getContentType();
-      // $this->packageContentLength = $request->getContentLength();
 
       // Check if the packaging format is supported
       if (!in_array($this->packageFormat, 
qtSwordPluginConfiguration::$packaging))
       {
-        return $this->generateResponse(415, 'error/ErrorContent');
+        return $this->generateResponse(415, 'error/ErrorContent', 
array('summary' => $this->context->i18n->__('The supplied format is not 
supported by this server')));
       }
 
       // Check if the content type is supported
       if (!in_array($this->packageContentType, 
qtSwordPluginConfiguration::$mediaRanges))
       {
-        return $this->generateResponse(415, 'error/ErrorContent');
-      }
-
-      // TODO: Mediation (see [2])
-      // $request->getHttpHeader('X-On-Behalf-Of');
-
-      // TODO: Development features
-      // X-No-Op (dry run)
-      // X-Verbose (verbose output)
-
-      // Clarify that we don't support this extension yet
-      if ('true' == $request->getHttpHeader('X-No-Op'))
-      {
-        return $this->generateResponse(400, 'error/ErrorBadRequest');
+        return $this->generateResponse(415, 'error/ErrorContent', 
array('summary' => $this->context->i18n->__('The supplied content type is not 
supported by this server')));
       }
 
+      // Save the file temporary
       $filename = qtSwordPlugin::saveRequestContent();
 
       // Package name
@@ -81,19 +66,20 @@
       {
         $this->packageName = 
substr($request->getHttpHeader('Content-Disposition'), 9);
       }
-      else
       {
-        // TODO name, [RFC2183]
+        // TODO see [RFC2183]
+        $this->packageName = $filename;
       }
 
       // Calculated MD5 check does not match the value provided by the client
       if (md5(file_get_contents($filename)) != 
$request->getHttpHeader('Content-MD5'))
       {
-        return $this->generateResponse(412, 
'error/ErrorChecksumMismatchSuccess');
+        return $this->generateResponse(412, 
'error/ErrorChecksumMismatchSuccess', array('summary' => 
$this->context->i18n->__('Checksum sent does not match the calculated 
checksum')));
       }
 
       // Open the file, parse xml, get objects
       $extractor = new qtPackageExtractor($filename, array(
+        'name' => $this->packageName,
         'format' => $this->packageFormat,
         'resource' => $this->resource,
         'type' => $this->packageContentType));
@@ -112,20 +98,20 @@
       // Location
       // $this->response->setHttpHeader('Location', '...');
 
-      return $this->generateResponse(201, 'deposit');
+      return $this->generateResponse(201, 'deposit', array('headers' =>
+        array('Location' => url_for(array($this->informationObject, 'module' 
=> 'informationobject')))));
     }
     else if ($request->isMethod('put') || $request->isMethod('delete'))
     {
-      // TODO: Editing and deleting resources, not implemented
-      return $this->generateResponse(501);
+      return $this->generateResponse(501, 'error/ErrorNotImplemented', 
array('summary' => $this->context->i18n->__('Not implemented')));
     }
     else
     {
-      return $this->generateResponse(400, 'error/ErrorBadRequest');
+      return $this->generateResponse(400, 'error/ErrorBadRequest', 
array('summary' => $this->context->i18n->__('Bad request')));
     }
   }
 
-  protected function generateResponse($code, $template = null, array $headers 
= array())
+  protected function generateResponse($code, $template = null, array $options 
= array())
   {
     $this->response->setStatusCode($code);
 
@@ -135,6 +121,19 @@
 
       $this->response->setHttpHeader('Content-Type', 'application/atom+xml; 
charset="utf-8"');
 
+      if (isset($options['headers']))
+      {
+        foreach ($options['headers'] as $key => $value)
+        {
+          $this->response->setHttpHeader($key, $value);
+        }
+      }
+
+      if (isset($options['summary']))
+      {
+        $this->summary = $options['summary'];
+      }
+
       $this->setTemplate($template);
     }
 

-- 
You received this message because you are subscribed to the Google Groups 
"Qubit Toolkit Commits" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/qubit-commits?hl=en.

Reply via email to