/** * Refresh tags for feature * * @param RestoFeature $feature */ public function refresh($feature) { $featureArray = $feature->toArray(); $this->context->dbDriver->update(RestoDatabaseDriver::KEYWORDS, array('feature' => $feature, 'keywords' => $this->getKeywords($this->removeReservedProperties($featureArray['properties']), $featureArray['geometry']))); }
/** * @depends testFeatureCollection * * Test order exception */ public function testRestoOrder() { $this->initContext(); $order = $this->admin->placeOrder(array(array('c5dc1f32-002d-5ee9-bd4a-c690461eb734'))); $_order = new RestoOrder($this->admin, $this->context, $order['orderId']); $json_decode = json_decode($_order->toJSON(true), true); $this->assertEquals('success', $json_decode['status']); $this->assertEquals(404, $json_decode['order']['errors'][0]['ErrorCode']); $meta4 = $_order->toMETA4(); $feature = new RestoFeature($this->context, $this->admin, array('featureIdentifier' => 'c5dc1f32-002d-5ee9-bd4a-c690461eb734')); $order = $this->admin->placeOrder(array($feature->toArray())); $_order = new RestoOrder($this->admin, $this->context, $order['orderId']); $json_decode = json_decode($_order->toJSON(true), true); $this->assertEquals(403, $json_decode['order']['errors'][0]['ErrorCode']); $profile = array('userid' => 3, 'groups' => 'default', 'email' => 'test_email_order', 'password' => 'test_password', 'username' => 'test_username', 'givenname' => 'test_givenname', 'lastname' => 'test_lastname', 'country' => 'FR', 'organization' => 'FR', 'flags' => 'REGISTERED', 'topics' => null, 'validatedby' => 'admin', 'validationdate' => 'now()', 'activated' => 1); $user = new RestoUser($profile, $this->context); $order = $user->placeOrder(array($feature->toArray())); $_order = new RestoOrder($user, $this->context, $order['orderId']); $json_decode = json_decode($_order->toJSON(true), true); $this->assertEquals(3002, $json_decode['order']['errors'][0]['ErrorCode']); $license = new RestoLicense($this->context, 'Example', true); $user->signLicense($license); $order = $user->placeOrder(array($feature->toArray())); $_order = new RestoOrder($user, $this->context, $order['orderId']); $json_decode = json_decode($_order->toJSON(true), true); $this->assertEquals($order['orderId'], $json_decode['order']['orderId']); $this->assertEquals('c5dc1f32-002d-5ee9-bd4a-c690461eb734', $json_decode['order']['items'][0]['id']); $meta4 = $_order->toMETA4(); $fake_array = $feature->toArray(); $fake_array['properties']['services']['download']['url'] = null; $order = $user->placeOrder(array($fake_array)); $_order = new RestoOrder($user, $this->context, $order['orderId']); $json_decode = json_decode($_order->toJSON(true), true); $this->assertEquals(404, $json_decode['order']['errors'][0]['ErrorCode']); $this->assertEquals('Item not downloadable', $json_decode['order']['errors'][0]['ErrorMessage']); $fake_array['properties'] = null; $order = $user->placeOrder(array($fake_array)); $_order = new RestoOrder($user, $this->context, $order['orderId']); $json_decode = json_decode($_order->toJSON(true), true); $this->assertEquals(404, $json_decode['order']['errors'][0]['ErrorCode']); $this->assertEquals('Invalid item', $json_decode['order']['errors'][0]['ErrorMessage']); /* * TODO : test $meta4 content */ }
/** * Update feature keywords * * @param RestoFeature $feature * @param array $keywords * @throws Exception */ public function updateFeatureKeywords($feature, $keywords) { $toUpdate = array(); /* * Store new keywords */ if (is_array($keywords)) { $columns = array_merge(array('keywords' => '\'' . pg_escape_string(json_encode($keywords)) . '\''), $this->landuseColumns($keywords)); $columns[$feature->collection->model->getDbKey('hashes')] = '\'{' . join(',', $this->getHashes($keywords)) . '}\''; foreach ($columns as $columnName => $columnValue) { array_push($toUpdate, $columnName . '=' . $columnValue); } } if (empty($toUpdate)) { RestoLogUtil::httpError(400, 'Nothing to update for ' . $feature->identifier); } try { /* * Begin transaction */ $this->dbDriver->query('BEGIN'); /* * Remove previous facets */ $this->removeFeatureFacets($feature->toArray()); /* * Update feature */ $this->dbDriver->query('UPDATE resto.features SET ' . join(',', $toUpdate) . ' WHERE identifier = \'' . pg_escape_string($feature->identifier) . '\''); /* * Store new facets */ $this->storeKeywordsFacets($feature->collection, $keywords, true); /* * Commit */ $this->dbDriver->query('COMMIT'); } catch (Exception $e) { $this->dbDriver->query('ROLLBACK'); RestoLogUtil::httpError(500, 'Cannot update feature ' . $feature->identifier); } return true; }