Ejemplo n.º 1
0
 public function handleItem(RequestItem $requestItem)
 {
     try {
         $token = $requestItem->getToken();
         $method = strtolower($requestItem->getMethod());
         if ($token->isAnonymous() && !in_array($method, self::$GET_SYNONYMS)) {
             // Anonymous requests are only allowed to GET data (not create/edit/delete)
             throw new SocialSpiException("[{$method}] not allowed for anonymous users", ResponseError::$BAD_REQUEST);
         } elseif (in_array($method, self::$GET_SYNONYMS)) {
             $parameters = $requestItem->getParameters();
             if (in_array("@supportedFields", $parameters, true)) {
                 $response = $this->getSupportedFields($parameters);
             } else {
                 $response = $this->handleGet($requestItem);
             }
         } elseif (in_array($method, self::$UPDATE_SYNONYMS)) {
             $response = $this->handlePut($requestItem);
         } elseif (in_array($method, self::$DELETE_SYNONYMS)) {
             $response = $this->handleDelete($requestItem);
         } elseif (in_array($method, self::$CREATE_SYNONYMS)) {
             $response = $this->handlePost($requestItem);
         } else {
             throw new SocialSpiException("Unserviced Http method type", ResponseError::$BAD_REQUEST);
         }
     } catch (SocialSpiException $e) {
         $response = new ResponseItem($e->getCode(), $e->getMessage());
     } catch (Exception $e) {
         $response = new ResponseItem(ResponseError::$INTERNAL_ERROR, "Internal error: " . $e->getMessage());
     }
     return $response;
 }
 /**
  * /groups/{userId}
  *
  * examples:
  * /groups/john.doe?fields=count
  * /groups/@me
  *
  * @param RequestItem $requestItem
  * @return ResponseItem
  */
 public function handleGet(RequestItem $requestItem)
 {
     $this->checkService();
     $requestItem->applyUrlTemplate(self::$GROUPS_PATH);
     $userIds = $requestItem->getUsers();
     if (count($userIds) < 1) {
         throw new InvalidArgumentException("No userId(s) specified");
     }
     return $this->service->getPersonGroups($userIds[0], $requestItem->getGroup(), $requestItem->getToken());
 }
Ejemplo n.º 3
0
 public function handleItem(RequestItem $requestItem)
 {
     try {
         $method = strtolower($requestItem->getMethod());
         $method = 'handle' . ucfirst($method);
         $response = $this->{$method}($requestItem);
     } catch (SocialSpiException $e) {
         $response = new ResponseItem($e->getCode(), $e->getMessage());
     } catch (Exception $e) {
         $response = new ResponseItem(ResponseError::$INTERNAL_ERROR, "Internal error: " . $e->getMessage());
     }
     return $response;
 }
Ejemplo n.º 4
0
 /**
  * Updates the album. The URI structure: /{userId}/{groupId}/{albumId}
  */
 public function handlePut(RequestItem $requestItem)
 {
     $this->checkService();
     $requestItem->applyUrlTemplate(self::$ALBUM_PATH);
     $userIds = $requestItem->getUsers();
     $groupId = $requestItem->getGroup();
     $albumIds = $requestItem->getListParameter('albumId');
     $album = $requestItem->getParameter('album');
     HandlerPreconditions::requireSingular($userIds, "userId must be singular value");
     HandlerPreconditions::requireNotEmpty($groupId, "groupId must be specified.");
     HandlerPreconditions::requireSingular($albumIds, "albumId must be singular value.");
     HandlerPreconditions::requireNotEmpty($album, "album must be specified.");
     $album['id'] = $albumIds[0];
     return $this->service->updateAlbum($userIds[0], $groupId, $album, $requestItem->getToken());
 }
Ejemplo n.º 5
0
 /**
  * /activities/{userId}/@self
  *
  * examples:
  * /activities/@viewer/@self/@app
  * /activities/john.doe/@self
  * - postBody is an activity object
  */
 public function handlePost(RequestItem $requestItem)
 {
     $requestItem->applyUrlTemplate(self::$ACTIVITY_ID_PATH);
     $userIds = $requestItem->getUsers();
     $activityIds = $requestItem->getListParameter("activityId");
     if (empty($userIds)) {
         throw new InvalidArgumentException("No userId specified");
     } elseif (count($userIds) > 1) {
         throw new InvalidArgumentException("Multiple userIds not supported");
     }
     // TODO This seems reasonable to allow on PUT but we don't have an update verb.
     if (!empty($activityIds)) {
         throw new InvalidArgumentException("Cannot specify activityId in create");
     }
     return $this->service->createActivity($userIds[0], $requestItem->getGroup(), $requestItem->getAppId(), $requestItem->getFields(), $requestItem->getParameter("activity"), $requestItem->getToken());
 }
 /**
  * Partuza's implementation of the OAuth Lookup service. Partuza supports all currently existing forms of
  * OAuth signatures: 3 legged, 2 legged and body_hash's
  *
  * @param RequestItem $oauthRequest
  * @param string $appUrl
  * @param string $userId
  * @return SecurityToken or null
  */
 public function getSecurityToken($oauthRequest, $appUrl, $userId, $contentType)
 {
     try {
         // Incomming requests with a POST body can either have an oauth_body_hash, or include the post body in the main oauth_signature; Also for either of these to be valid
         // we need to make sure it has a proper the content-type; So the below checks if it's a post, if so if the content-type is supported, and if so deals with the 2
         // post body signature styles
         $includeRawPost = false;
         $acceptedContentTypes = array('application/atom+xml', 'application/xml', 'application/json');
         if (isset($GLOBALS['HTTP_RAW_POST_DATA']) && !empty($GLOBALS['HTTP_RAW_POST_DATA'])) {
             if (!in_array($contentType, $acceptedContentTypes)) {
                 // This is rather double (since the ApiServlet does the same check), but for us to do a meaninful processing of a post body, this has to be correct
                 throw new Exception("Invalid Content-Type specified for this request, only 'application/atom+xml', 'application/xml' and 'application/json' are accepted");
             } else {
                 if (isset($_GET['oauth_body_hash'])) {
                     // this request uses the oauth_body_hash spec extension. Check the body hash and if it fails return 'null' (oauth signature failure)
                     // otherwise continue on to the regular oauth signature verification, without including the post body in the main oauth_signature calculation
                     if (!$this->verifyBodyHash($GLOBALS['HTTP_RAW_POST_DATA'], $_GET['oauth_body_hash'])) {
                         return null;
                     }
                 } else {
                     // use the (somewhat oauth spec invalid) raw post body in the main oauth hash calculation
                     $includeRawPost = $GLOBALS['HTTP_RAW_POST_DATA'];
                 }
             }
         }
         $dataStore = new PartuzaOAuthDataStore();
         if ($includeRawPost) {
             // if $includeRawPost has been set above, we need to include the post body in the main oauth_signature
             $oauthRequest->set_parameter($includeRawPost, '');
         }
         $oauth_token = $oauthRequest->get_parameters('oauth_token');
         if (!isset($oauth_token)) {
             // No oauth_token means this is a 2 legged OAuth request
             $ret = $this->verify2LeggedOAuth($oauthRequest, $userId, $appUrl, $dataStore);
         } else {
             // Otherwise it's a clasic 3 legged oauth request
             $ret = $this->verify3LeggedOAuth($oauthRequest, $userId, $appUrl, $dataStore);
         }
         if ($includeRawPost) {
             unset($oauthRequest->parameters[$includeRawPost]);
         }
         return $ret;
     } catch (OAuthException $e) {
         return null;
     }
 }
 public function handleInvalidate(RequestItem $request)
 {
     $this->checkService();
     if (!$request->getToken()->getAppId() && !$request->getToken()->getAppUrl()) {
         throw new SocialSpiException("Can't invalidate content without specifying application", ResponseError::$BAD_REQUEST);
     }
     $isBackendInvalidation = AuthenticationMode::$OAUTH_CONSUMER_REQUEST == $request->getToken()->getAuthenticationMode();
     $invalidationKeys = $request->getListParameter('invalidationKeys');
     $resources = array();
     $userIds = array();
     if ($request->getToken()->getViewerId()) {
         $userIds[] = $request->getToken()->getViewerId();
     }
     foreach ($invalidationKeys as $key) {
         if (strpos($key, 'http') !== false) {
             if (!$isBackendInvalidation) {
                 throw new SocialSpiException('Cannot flush application resources from a gadget. Must use OAuth consumer request');
             }
             $resources[] = $key;
         } else {
             if ($key == '@viewer') {
                 continue;
             }
             if (!$isBackendInvalidation) {
                 throw new SocialSpiException('Cannot invalidate the content for a user other than the viewer from a gadget.');
             }
             $userIds[] = $key;
         }
     }
     $this->service->invalidateApplicationResources($resources, $request->getToken());
     $this->service->invalidateUserResources($userIds, $request->getToken());
 }
Ejemplo n.º 8
0
 public function __construct($rpc, SecurityToken $token)
 {
     parent::__construct($rpc['method'], $rpc['method'], $token);
     if (isset($rpc->params)) {
         $this->data = $rpc['params'];
     } else {
         $this->data = array();
     }
 }
Ejemplo n.º 9
0
 /**
  * /messages/{groupId}/outbox/{msgId}
  * /messages/{groupId}/outbox
  *
  * @param RequestItem $requestItem
  * @return responseItem
  */
 public function handlePost(RequestItem $requestItem)
 {
     $requestItem->applyUrlTemplate(self::$MESSAGES_PATH);
     $userIds = $requestItem->getUsers();
     $message = $requestItem->getParameter('message');
     $optionalMessageId = $requestItem->getParameter('msgId');
     return $this->service->createMessage($userIds[0], $requestItem->getAppId(), $message, $optionalMessageId, $requestItem->getToken());
 }
Ejemplo n.º 10
0
 /**
  * Extracts the Xml entity name from the request url
  *
  * @param RequestItem $requestItem the request item
  * @param array $entryTypes the map of entries
  * @return string the request type
  */
 public static function getRequestType($requestItem, $entryTypes)
 {
     // map the Request URL to the content type to use
     $params = $requestItem->getParameters();
     if (!is_array($params)) {
         throw new Exception("Unsupported request type");
     }
     $type = false;
     foreach ($params as $key => $val) {
         if (isset($entryTypes[$key])) {
             $type = $entryTypes[$key];
             break;
         }
     }
     if (!$type) {
         throw new Exception("Unsupported request type");
     }
     return $type;
 }
Ejemplo n.º 11
0
 /**
  * /appdata/{userId}/{groupId}/{appId}
  * - fields={field1, field2}
  *
  * examples:
  * /appdata/john.doe/@friends/app?fields=count
  * /appdata/john.doe/@self/app
  *
  * The post data should be a regular json object. All of the fields vars will
  * be pulled from the values and set on the person object. If there are no
  * fields vars then all of the data will be overridden.
  */
 public function handlePost(RequestItem $requestItem)
 {
     $requestItem->applyUrlTemplate(self::$APP_DATA_PATH);
     $userIds = $requestItem->getUsers();
     if (count($userIds) < 1) {
         throw new InvalidArgumentException("No userId specified");
     } elseif (count($userIds) > 1) {
         throw new InvalidArgumentException("Multiple userIds not supported");
     }
     $values = $requestItem->getParameter("data");
     // this used to be $requestItem->getFields() instead of using the fields, but that makes no sense to me
     // better to detect the fields depending on input right?
     $fields = array();
     foreach (array_keys($values) as $key) {
         $fields[] = $key;
         if (!$this->isValidKey($key)) {
             throw new SocialSpiException("One or more of the app data keys are invalid: " . $key, ResponseError::$BAD_REQUEST);
         }
     }
     $this->service->updatePersonData($userIds[0], $requestItem->getGroup(), $requestItem->getAppId(), $fields, $values, $requestItem->getToken());
 }
 /**
  *
  * @param array $rpc
  * @param SecurityToken $token
  */
 public function __construct($rpc, SecurityToken $token)
 {
     if (empty($rpc['method'])) {
         throw new SocialSpiException("Missing method in RPC call");
     }
     parent::__construct($rpc['method'], $rpc['method'], $token);
     if (isset($rpc['params'])) {
         $this->data = $rpc['params'];
     } else {
         $this->data = array();
     }
 }
 /**
  * ATutor's implementation of the OAuth Lookup service. ATutor supports all currently existing forms of
  * OAuth signatures: 3 legged, 2 legged and body_hash's
  *
  * @param RequestItem $oauthRequest
  * @param string $appUrl
  * @param string $userId
  * @return SecurityToken or null
  */
 public function getSecurityToken($oauthRequest, $appUrl, $userId)
 {
     try {
         // Incomming requests with a POST body can either have an oauth_body_hash, or include the post body in the main oauth_signature; Also for either of these to be valid
         // we need to make sure it has a proper the content-type; So the below checks if it's a post, if so if the content-type is supported, and if so deals with the 2
         // post body signature styles
         $includeRawPost = false;
         if (isset($GLOBALS['HTTP_RAW_POST_DATA']) && !empty($GLOBALS['HTTP_RAW_POST_DATA'])) {
             if (isset($_GET['oauth_body_hash'])) {
                 // this request uses the oauth_body_hash spec extension. Check the body hash and if it fails return 'null' (oauth signature failure)
                 // otherwise continue on to the regular oauth signature verification, without including the post body in the main oauth_signature calculation
                 if (!$this->verifyBodyHash($GLOBALS['HTTP_RAW_POST_DATA'], $_GET['oauth_body_hash'])) {
                     return null;
                 }
             } else {
                 // use the (somewhat oauth spec invalid) raw post body in the main oauth hash calculation
                 $includeRawPost = $GLOBALS['HTTP_RAW_POST_DATA'];
             }
         }
         $dataStore = new ATutorOAuthDataStore();
         if ($includeRawPost) {
             // if $includeRawPost has been set above, we need to include the post body in the main oauth_signature
             $oauthRequest->set_parameter($includeRawPost, '');
         }
         if (!isset($oauthRequest->parameters['oauth_token'])) {
             // No oauth_token means this is a 2 legged OAuth request
             $ret = $this->verify2LeggedOAuth($oauthRequest, $userId, $appUrl, $dataStore);
         } else {
             // Otherwise it's a clasic 3 legged oauth request
             $ret = $this->verify3LeggedOAuth($oauthRequest, $userId, $appUrl, $dataStore);
         }
         if ($includeRawPost) {
             unset($oauthRequest->parameters[$includeRawPost]);
         }
         return $ret;
     } catch (OAuthException $e) {
         return null;
     }
 }
Ejemplo n.º 14
0
 /**
  * /activities/{userId}/@self
  *
  * examples:
  * /activities/@viewer/@self/@app
  * /activities/john.doe/@self
  * - postBody is an activity object
  */
 public function handlePost(RequestItem $requestItem)
 {
     $requestItem->applyUrlTemplate(self::$ACTIVITY_ID_PATH);
     $userIds = $requestItem->getUsers();
     $activityIds = $requestItem->getListParameter("activityId");
     if (empty($userIds)) {
         throw new InvalidArgumentException("No userId specified");
     } elseif (count($userIds) > 1) {
         throw new InvalidArgumentException("Multiple userIds not supported");
     }
     // TODO This seems reasonable to allow on PUT but we don't have an update verb.
     if (!empty($activityIds)) {
         throw new InvalidArgumentException("Cannot specify activityId in create");
     }
     /*
      * Note, on just about all types of social networks you would only allow activities to be created when the owner == viewer, and the userId == viewer as well, in code this would mean:
      *  if ($token->getOwnerId() != $token->getViewerId() || $token->getViewerId() != $userId->getUserId($token)) {
      *    throw new SocialSpiException("Create activity permission denied.", ResponseError::$UNAUTHORIZED);
      *  }
      */
     return $this->service->createActivity($userIds[0], $requestItem->getGroup(), $requestItem->getAppId(), $requestItem->getFields(), $requestItem->getParameter("activity"), $requestItem->getToken());
 }
Ejemplo n.º 15
0
 /**
  * Allowed end-points /people/{userId}+/{groupId} /people/{userId}/{groupId}/{optionalPersonId}+
  *
  * examples: /people/john.doe/@all /people/john.doe/@friends /people/john.doe/@self
  */
 public function handleGet(RequestItem $request)
 {
     $this->checkService();
     $request->applyUrlTemplate(self::$PEOPLE_PATH);
     $groupId = $request->getGroup();
     $optionalPersonId = $request->getListParameter("personId");
     $fields = $request->getFields(self::$DEFAULT_FIELDS);
     $userIds = $request->getUsers();
     // Preconditions
     if (count($userIds) < 1) {
         throw new IllegalArgumentException("No userId specified");
     } elseif (count($userIds) > 1 && count($optionalPersonId) != 0) {
         throw new IllegalArgumentException("Cannot fetch personIds for multiple userIds");
     }
     $options = new CollectionOptions();
     $options->setSortBy($request->getSortBy());
     $options->setSortOrder($request->getSortOrder());
     $options->setFilterBy($request->getFilterBy());
     $options->setFilterOperation($request->getFilterOperation());
     $options->setFilterValue($request->getFilterValue());
     $options->setStartIndex($request->getStartIndex());
     $options->setCount($request->getCount());
     $token = $request->getToken();
     $groupType = $groupId->getType();
     // handle Anonymous Viewer exceptions
     $containAnonymousUser = false;
     if ($token->isAnonymous()) {
         // Find out whether userIds contains
         // a) @viewer, b) @me, c) SecurityToken::$ANONYMOUS
         foreach ($userIds as $key => $id) {
             if (in_array($id->getType(), self::$ANONYMOUS_ID_TYPE) || $id->getType() == 'userId' && $id->getUserId($token) == SecurityToken::$ANONYMOUS) {
                 $containAnonymousUser = true;
                 unset($userIds[$key]);
             }
         }
         if ($containAnonymousUser) {
             $userIds = array_values($userIds);
             // Skip any requests if groupId is not @self or @all, since anonymous viewer won't have friends.
             if ($groupType != 'self' && $groupType != 'all') {
                 throw new Exception("Can't get friend from an anonymous viewer.");
             }
         }
     }
     if ($containAnonymousUser && count($userIds) == 0) {
         return self::$ANONYMOUS_VIEWER;
     }
     $service = $this->service;
     $ret = null;
     if (count($userIds) == 1) {
         if (count($optionalPersonId) == 0) {
             if ($groupType == 'self') {
                 $ret = $service->getPerson($userIds[0], $groupId, $fields, $token);
             } else {
                 $ret = $service->getPeople($userIds, $groupId, $options, $fields, $token);
             }
         } elseif (count($optionalPersonId) == 1) {
             $ret = $service->getPerson($optionalPersonId[0], $groupId, $fields, $token);
         } else {
             $personIds = array();
             foreach ($optionalPersonId as $pid) {
                 $personIds[] = new UserId('userId', $pid);
             }
             // Every other case is a collection response of optional person ids
             $ret = $service->getPeople($personIds, new GroupId('self', null), $options, $fields, $token);
         }
     } else {
         // Every other case is a collection response.
         $ret = $service->getPeople($userIds, $groupId, $options, $fields, $token);
     }
     // Append anonymous viewer
     if ($containAnonymousUser) {
         if (is_array($ret)) {
             // Single user
             $people = array($ret, self::$ANONYMOUS_VIEWER);
             $ret = new RestfulCollection($people, $options->getStartIndex(), 2);
             $ret->setItemsPerPage($options->getCount());
         } else {
             // Multiple users
             $ret->entry[] = self::$ANONYMOUS_VIEWER;
             $ret->totalResults += 1;
         }
     }
     return $ret;
 }
Ejemplo n.º 16
0
 function run()
 {
     // Create area where files will be placed if it is the first item;
     if (!is_dir($this->ftpdir)) {
         mkdir($this->ftpdir);
         // Create .htacess for each user ftpdir
         $fd = fopen("{$this->ftpdir}/.htaccess", "w") or die("Cannot open file {$this->ftpdir}\n");
         fwrite($fd, "Options Indexes FollowSymLinks");
         fclose($fd);
         if ($GLOBALS["stationDebug"]) {
             echo "p2u.run creating directory  {$this->ftpdir} <br>\n";
         }
     }
     // Check if this Tiff file is present in disk system
     if (count($this->tiffs) == 0) {
         $this->dbman->endModule($this->moduleId, 5, "tiffs were not found on disk");
         die;
     }
     #
     # Code Segment for Quality Control Test executions
     #
     include_once "globalsFunctions.php";
     include_once "request.class.php";
     $reqItem = new RequestItem($this->dbcat);
     $reqItem->searchItem($this->numitem);
     $reqItem_status = $reqItem->getItemStatus();
     #
     # end of segment
     #
     foreach ($this->tiffs as $tiff) {
         if (strlen($tiff) == 0) {
             $this->dbman->endModule($this->moduleId, 5, "{$tiff} was not found on disk");
             die;
         }
         // OK tiff is already in disk, lets make a copy for user
         //Don't zip BAND3 from CCD2 Intrument
         if (strstr($tiff, "CCD2") && strstr($tiff, "BAND3")) {
             continue;
         }
         #
         # Code Segment for Quality Control Test executions
         #
         if ($reqItem_status == 'Q') {
             /* 
             			  decodeTiff(basename($tiff),$satellite,$number,$instrument,$channel,$type,$date);
             				$qlt_dir = getQualityDir($satellite.$number); 
             				$qlt_dir_usreq = $qlt_dir . $this->userid . $this->reqid; 
             // Create area where files will be placed if it is the first item;
             			  if (!is_dir($qlt_dir_usreq)) mkdir ($qlt_dir_usreq);
             		    $cmd = "cp $tiff $qlt_dir_usreq";
             			  $res = exec($cmd);
             */
         } else {
             $this->saveTiffforUser($tiff);
         }
         #
         # end of segment
         #
     }
     include_once "listFiles.php";
     // Code Segment for dispatching "h1" LANDSAT-5 radiometric parameters file (amongst tiff files).
     $dir = dirname($this->tiffs[0]) . "/";
     $h1_files = listFiles($dir, "h1");
     foreach ($h1_files as $h1_file) {
         if ($h1_file != "") {
             $this->saveTiffforUser($dir . "/" . $h1_file);
         }
     }
     // End Code Segment for LANDSAT-5
     #
     # Code Segment for dispatching "scenario" files (under directory "scenario")
     #
     $cmd = "find {$dir} -name \"*scenario\" ";
     $output = shell_exec($cmd);
     $output = substr($output, 0, strlen($output) - 1);
     $scenario_fullname = explode("\n", $output);
     $this->saveTiffforUser($scenario_fullname[0]);
     #
     # End Code Sement
     #
     #
     # Code Segment for Quality Control Test executions
     #
     if ($reqItem_status == 'Q') {
         $this->dbman->endModule($this->moduleId);
         $reqItem->updateStatus('A');
         return;
     } else {
         $this->updateRequest();
     }
     #
     # end of segment
     #
     // Check how many items have been requested and how many are done
     //			$sql = "SELECT * FROM request WHERE reqid = $this->reqid";
     $sql = "SELECT COUNT(*) as nitem, sum(Status='F' or Status='E') as nitemdone from RequestItem where ReqId = {$this->reqid}";
     $this->dbcat->query($sql);
     if ($row = $this->dbcat->fetchRow()) {
         $nitem = $row["nitem"];
         $nitemdone = $row["nitemdone"];
     } else {
         $this->dbman->endModule($this->moduleId, 4, "{$this->reqid} was not found in DB");
     }
     $this->dbcat->freeResult();
     // If it is last item, send user a mail and terminate function run
     if ($GLOBALS["stationDebug"]) {
         echo "p2u.run nitemdone {$nitemdone} nitem {$nitem}<br>\n";
     }
     if ($nitemdone == $nitem) {
         $this->sendMail();
     } else {
         $this->sendIntermediateMail();
     }
 }
Ejemplo n.º 17
0
 public function getParams(RequestItem $request)
 {
     $param_map = array_flip($this->parameters);
     $regex = $this->expression;
     $matches = preg_split($regex, $request->uri(), null, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
     $params = [];
     foreach ($param_map as $key => $value) {
         $params[$key] = array_shift($matches);
     }
     return $params;
 }
 /**
  * Extracts the Atom entity name from the request url
  *
  * @param RequestItem $requestItem the request item
  * @return string the request type
  */
 private function getRequestType($requestItem)
 {
     // map the Request URL to the content type to use
     $params = $requestItem->getParameters();
     if (!is_array($params) || empty(self::$entryTypes[$params[0]])) {
         throw new Exception("Unsupported request type");
     }
     return self::$entryTypes[$params[0]];
 }
Ejemplo n.º 19
0
 /**
  * Delivers a request item to the appropriate DataRequestHandler.
  */
 protected function handleRequestItem(RequestItem $requestItem)
 {
     // lazy initialization of the service handlers, no need to instance them all for each request
     if (!isset($this->handlers[$requestItem->getService()])) {
         switch ($requestItem->getService()) {
             case self::$PEOPLE_ROUTE:
                 require_once 'src/social/spi/PersonService.php';
                 require_once 'src/social/service/PersonHandler.php';
                 $this->handlers[self::$PEOPLE_ROUTE] = new PersonHandler();
                 break;
             case self::$ACTIVITY_ROUTE:
                 require_once 'src/social/spi/ActivityService.php';
                 require_once 'src/social/service/ActivityHandler.php';
                 $this->handlers[self::$ACTIVITY_ROUTE] = new ActivityHandler();
                 break;
             case self::$APPDATA_ROUTE:
                 require_once 'src/social/spi/AppDataService.php';
                 require_once 'src/social/service/AppDataHandler.php';
                 $this->handlers[self::$APPDATA_ROUTE] = new AppDataHandler();
                 break;
             case self::$MESSAGE_ROUTE:
                 require_once 'src/social/spi/MessagesService.php';
                 require_once 'src/social/service/MessagesHandler.php';
                 $this->handlers[self::$MESSAGE_ROUTE] = new MessagesHandler();
                 break;
             case self::$INVALIDATE_ROUTE:
                 require_once 'src/social/spi/InvalidateService.php';
                 require_once 'src/social/service/InvalidateHandler.php';
                 $this->handlers[self::$INVALIDATE_ROUTE] = new InvalidateHandler();
                 break;
             case self::$SYSTEM_ROUTE:
                 require_once 'src/social/service/SystemHandler.php';
                 $this->handlers[self::$SYSTEM_ROUTE] = new SystemHandler();
                 break;
             case self::$ALBUM_ROUTE:
                 require_once 'src/social/spi/AlbumService.php';
                 require_once 'src/social/service/AlbumHandler.php';
                 $this->handlers[self::$ALBUM_ROUTE] = new AlbumHandler();
                 break;
             case self::$MEDIA_ITEM_ROUTE:
                 require_once 'src/social/spi/MediaItemService.php';
                 require_once 'src/social/service/MediaItemHandler.php';
                 $this->handlers[self::$MEDIA_ITEM_ROUTE] = new MediaItemHandler();
                 break;
             default:
                 throw new SocialSpiException("The service " . $requestItem->getService() . " is not implemented", ResponseError::$NOT_IMPLEMENTED);
                 break;
         }
     }
     $handler = $this->handlers[$requestItem->getService()];
     return $handler->handleItem($requestItem);
 }
Ejemplo n.º 20
0
 public function __construct($service, $method, SecurityToken $token, $inputConverterMethod, $outputConverter)
 {
     parent::__construct($service, $method, $token);
     $this->inputConverterMethod = $inputConverterMethod;
     $this->outputConverter = $outputConverter;
 }
Ejemplo n.º 21
0
 function generateReqItem($parReqId, $parUserType)
 {
     $parDate = date("Y-m-d H:i:s");
     $nM = searchMedia($this->bd, $matMedia, $this->media);
     $parStatus = 'B';
     //			$this->price = $this->price - $matMedia[0]->getPrice(); // trim media price (occasionally) embedded in image price
     // when evaluating cart item price.
     $userType = $parUserType;
     if (($this->price or $matMedia[0]->getPrice()) and $userType != 1) {
         $parStatus = 'Q';
     }
     // Manager (UserType =1)
     // doesn't need allowance;
     // Q is the Request Item Status
     // correspondin to Quality Contro Test - priced items only
     $objReqI = new RequestItem($this->bd);
     $objReqI->fill($parReqId, $this->sceneId, $this->productId, $this->bands, $this->sceneShift, $this->corretion, $this->orientation, $this->resampling, $this->datum, $this->projection, $this->longOrigin, $this->latOrigin, $this->stdLat1, $this->stdLat2, $this->format, $this->inter, $this->media, $this->price, $parDate, $parStatus, $parDate, $this->restoration);
     if (!$objReqI->insert()) {
         //Deletar todos os pedidos e itens
         // Modificar o estado do pedido e dos demais itens do cart
         return false;
     }
     return true;
 }
Ejemplo n.º 22
0
 /**
  * Delivers a request item to the appropriate DataRequestHandler.
  */
 protected function handleRequestItem(RequestItem $requestItem)
 {
     if (!isset($this->handlers[$requestItem->getService()])) {
         throw new SocialSpiException("The service " . $requestItem->getService() . " is not implemented", ResponseError::$NOT_IMPLEMENTED);
     }
     $handler = $this->handlers[$requestItem->getService()];
     return $handler->handleItem($requestItem);
 }
 /**
  * Delivers a request item to the appropriate DataRequestHandler.
  *
  * @param RequestItem $requestItem
  * @return ResponseItem
  */
 protected function handleRequestItem(RequestItem $requestItem)
 {
     // lazy initialization of the service handlers, no need to instance them all for each request
     $service = $requestItem->getService();
     if (!isset($this->handlers[$service])) {
         $handlerClasses = Config::get('service_handler');
         if (isset($handlerClasses[$service])) {
             $handlerClass = $handlerClasses[$service];
             $this->handlers[$service] = new $handlerClass();
         } else {
             throw new SocialSpiException("The service " . $service . " is not implemented", ResponseError::$NOT_IMPLEMENTED);
         }
     }
     $handler = $this->handlers[$service];
     return $handler->handleItem($requestItem);
 }
Ejemplo n.º 24
0
 public static function isGet()
 {
     static::createInstance();
     return static::$current->isGet();
 }
Ejemplo n.º 25
0
 /**
  * Allowed end-points /people/{userId}+/{groupId} /people/{userId}/{groupId}/{optionalPersonId}+
  *
  * examples: /people/john.doe/@all /people/john.doe/@friends /people/john.doe/@self
  */
 public function handleGet(RequestItem $request)
 {
     $request->applyUrlTemplate(self::$PEOPLE_PATH);
     $groupId = $request->getGroup();
     $optionalPersonId = $request->getListParameter("personId");
     $fields = $request->getFields(self::$DEFAULT_FIELDS);
     $userIds = $request->getUsers();
     // Preconditions
     if (count($userIds) < 1) {
         throw new IllegalArgumentException("No userId specified");
     } elseif (count($userIds) > 1 && count($optionalPersonId) != 0) {
         throw new IllegalArgumentException("Cannot fetch personIds for multiple userIds");
     }
     $options = new CollectionOptions();
     $options->setSortBy($request->getSortBy());
     $options->setSortOrder($request->getSortOrder());
     $options->setFilterBy($request->getFilterBy());
     $options->setFilterOperation($request->getFilterOperation());
     $options->setFilterValue($request->getFilterValue());
     $options->setStartIndex($request->getStartIndex());
     $options->setCount($request->getCount());
     // personId: Array (     [0] => 8 )
     if (count($userIds) == 1) {
         if (count($optionalPersonId) == 0) {
             if ($groupId->getType() == 'self') {
                 return $this->personService->getPerson($userIds[0], $groupId, $fields, $request->getToken());
             } else {
                 return $this->personService->getPeople($userIds, $groupId, $options, $fields, $request->getToken());
             }
         } elseif (count($optionalPersonId) == 1) {
             return $this->personService->getPerson($optionalPersonId[0], $groupId, $fields, $request->getToken());
         } else {
             $personIds = array();
             foreach ($optionalPersonId as $pid) {
                 $personIds[] = new UserId('userId', $pid);
             }
             // Every other case is a collection response of optional person ids
             return $this->personService->getPeople($personIds, new GroupId('self', null), $options, $fields, $request->getToken());
         }
     }
     // Every other case is a collection response.
     return $this->personService->getPeople($userIds, $groupId, $options, $fields, $request->getToken());
 }
Ejemplo n.º 26
0
 /**
  * Updates a message or a message collection.
  */
 public function handlePut(RequestItem $requestItem)
 {
     $this->checkService();
     $requestItem->applyUrlTemplate(self::$MESSAGES_PATH);
     $userIds = $requestItem->getUsers();
     HandlerPreconditions::requireSingular($userIds, "UserId is not singular.");
     $msgCollId = $requestItem->getParameter("msgCollId");
     HandlerPreconditions::requireNotEmpty($msgCollId, "msgCollId is required.");
     $messageIds = $requestItem->getListParameter("messageId");
     if (empty($messageIds)) {
         // Updates message collection.
         $messageCollection = $requestItem->getParameter("entity");
         $messageCollection['id'] = $msgCollId;
         HandlerPreconditions::requireNotEmpty($messageCollection, "Can't parse message collection.");
         return $this->service->updateMessageCollection($userIds[0], $messageCollection, $requestItem->getToken());
     } else {
         // Updates a message.
         HandlerPreconditions::requireSingular($messageIds, "Message id is not singular.");
         $message = $requestItem->getParameter("entity");
         $message['id'] = $messageIds[0];
         HandlerPreconditions::requireNotEmpty($message, "Can't parse message.");
         return $this->service->updateMessage($userIds[0], $msgCollId, $message, $requestItem->getToken());
     }
 }