/** * Create a collection and store it within database * * @param array $object : collection description as json file */ public function create($object) { $name = isset($object['name']) ? $object['name'] : null; /* * Check that collection does not exist */ if (isset($name) && isset($this->collections[$name])) { RestoLogUtil::httpError(2003); } /* * Load collection */ $collection = new RestoCollection($name, $this->context, $this->user); $collection->loadFromJSON($object, true); /* * Store query */ if ($this->context->storeQuery === true) { $this->user->storeQuery($this->context->method, 'create', $name, null, $this->context->query, $this->context->getUrl()); } return true; }
/** * * Process HTTP PUT request on collections * * collections/{collection} | Update {collection} * collections/{collection}/{feature} | Update {feature} * * @param array $segments * @param array $data */ private function PUT_collections($segments, $data) { /* * {collection} is mandatory and no modifier is allowed */ if (!isset($segments[1]) || isset($segments[3])) { RestoLogUtil::httpError(404); } $collection = new RestoCollection($segments[1], $this->context, $this->user, array('autoload' => true)); $featureIdentifier = isset($segments[2]) ? $segments[2] : null; if (isset($featureIdentifier)) { $feature = new RestoFeature($this->context, $this->user, array('featureIdentifier' => $featureIdentifier, 'collection' => $collection)); if (!$feature->isValid()) { RestoLogUtil::httpError(404); } } /* * Only owner of the collection can update it */ if (!$this->user->hasRightsTo(RestoUser::UPDATE, array('collection' => $collection))) { RestoLogUtil::httpError(403); } /* * collections/{collection} */ if (!isset($feature)) { $collection->loadFromJSON($data, true); if ($this->context->storeQuery === true) { $this->user->storeQuery($this->context->method, 'update', $collection->name, null, $this->context->query, $this->context->getUrl()); } return RestoLogUtil::success('Collection ' . $collection->name . ' updated'); } else { RestoLogUtil::httpError(501); } }
/** * @depends testCreateCollection * @expectedException Exception * @expectedExceptionCode 500 * @expectedExceptionMessage Invalid input JSON * * Test collection creatation with a bad json file * -> missing osdescription */ public function testExceptionCreateCollection_4() { $this->initContext(); $data = 'totto'; $collection = new RestoCollection('Example', $this->context, $this->admin); $collection->loadFromJSON($data, true); }