Skip to content
Snippets Groups Projects
Commit b76a1525 authored by Pegane Nestor's avatar Pegane Nestor
Browse files

FEAT #7345 check then update + modified sql + test adaptation

parent cef5066e
No related branches found
No related tags found
No related merge requests found
......@@ -163,7 +163,7 @@ class ResControllerTest extends TestCase
$responseBody = json_decode((string) $response->getBody());
$this->assertSame('Bad Request', $responseBody->errors);
$this->assertSame('Bad Request: invalid res_id', $responseBody->errors);
// DOCUMENT DOES NOT EXIST
$aArgs = [
......@@ -185,11 +185,11 @@ class ResControllerTest extends TestCase
$this->assertSame(_DOCUMENT_NOT_FOUND, $responseBody->errors);
//MISSING EXTERNAL INFO
//MISSING STATUS
$aArgs = [
'externalInfos' => [
[
'res_id' => 123456789,
'res_id' => self::$id,
'external_id' => "BB981212IIYZ",
'external_link' => "https://publik.nancy.fr/res/BB981212BB65"
]
......@@ -205,7 +205,7 @@ class ResControllerTest extends TestCase
$this->assertSame('Bad Request', $responseBody->errors);
//MISSING STATUS
//MISSING EXTERNAL INFOS
$aArgs = [
'externalInfos' => NULL,
'status' => "GRCSENT"
......@@ -242,4 +242,69 @@ class ResControllerTest extends TestCase
$this->assertSame(null, $res);
}
public function testGetList(){
$resController = new \Resource\controllers\ResController();
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'POST']);
$request = \Slim\Http\Request::createFromEnvironment($environment);
$aArgs = [
'select' => 'res_id',
'clause' => '1=1',
'withFile' => true,
'orderBy' => ['res_id'],
'limit' => 1
];
$fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request);
$response = $resController->getList($fullRequest, new \Slim\Http\Response());
$responseBody = json_decode((string)$response->getBody());
$arr_res = $responseBody->resources;
$this->assertNotNull($arr_res[0]->fileBase64Content);
$this->assertSame(100,$arr_res[0]->res_id);
$aArgs = [
'select' => 'res_id',
'clause' => '1=1',
'withFile' => false,
'orderBy' => ['res_id'],
'limit' => 1
];
$fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request);
$response = $resController->getList($fullRequest, new \Slim\Http\Response());
$responseBody = json_decode((string)$response->getBody());
$arr_res = $responseBody->resources;
$this->assertSame(null,$arr_res[0]->fileBase64Content);
$this->assertSame(100,$arr_res[0]->res_id);
$aArgs = [
'select' => '',
'clause' => '1=1',
'withFile' => false,
'orderBy' => ['res_id'],
'limit' => 1
];
$fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request);
$response = $resController->getList($fullRequest, new \Slim\Http\Response());
$responseBody = json_decode((string)$response->getBody());
$arr_res = $responseBody->resources;
$this->assertSame("Bad Request: select parameter not valid",$responseBody->errors);
$aArgs = [
'select' => 'res_id',
'clause' => '',
'withFile' => false,
'orderBy' => ['res_id'],
'limit' => 1
];
$fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request);
$response = $resController->getList($fullRequest, new \Slim\Http\Response());
$responseBody = json_decode((string)$response->getBody());
$arr_res = $responseBody->resources;
$this->assertSame("Bad Request: clause parameter not valid",$responseBody->errors);
}
}
......@@ -140,6 +140,13 @@ DROP VIEW IF EXISTS res_view_letterbox;
/* Alter table here because view depends on it*/
ALTER TABLE res_letterbox ALTER COLUMN priority TYPE character varying(16);
--ALTER TABLE for external infos webservice
ALTER TABLE res_letterbox DROP COLUMN IF EXISTS external_id;
ALTER TABLE res_letterbox ADD COLUMN external_id character varying(255);
ALTER TABLE res_letterbox DROP COLUMN IF EXISTS external_link;
ALTER TABLE res_letterbox ADD COLUMN external_link character varying(255);
CREATE OR REPLACE VIEW res_view_letterbox AS
SELECT r.tablename,
r.is_multi_docservers,
......
......@@ -1619,6 +1619,8 @@ CREATE TABLE res_letterbox
tnl_result character varying(10) DEFAULT NULL::character varying,
tnl_attempts integer DEFAULT NULL::integer,
ocr_result character varying(10) DEFAULT NULL::character varying,
external_id character varying(255) DEFAULT NULL::character varying,
external_link character varying(255) DEFAULT NULL::character varying,
CONSTRAINT res_letterbox_pkey PRIMARY KEY (res_id)
)
WITH (OIDS=FALSE);
......
......@@ -173,14 +173,19 @@ class ResController
}
$externalInfos = $data['externalInfos'];
foreach($externalInfos as $mail){
$check = Validator::intType()->validate($mail['res_id']);
$check = $check && Validator::StringType()->notEmpty()->validate($mail['external_id']);
$check = $check && Validator::StringType()->notEmpty()->validate($mail['external_link']);
if(!$check){
return $response->withStatus(400)->withJson(['errors' => 'Bad Request']);
foreach($externalInfos as $mail){
if(!Validator::intType()->validate($mail['res_id'])){
return $response->withStatus(400)->withJson(['errors' => 'Bad Request: invalid res_id']);
}
if(!Validator::StringType()->notEmpty()->validate($mail['external_id'])){
return $response->withStatus(400)->withJson(['errors' => 'Bad Request: invalid external_id for element : '.$mail['res_id']]);
}
if(!Validator::StringType()->notEmpty()->validate($mail['external_link'])){
return $response->withStatus(400)->withJson(['errors' => 'Bad Request: invalid external_link for element'.$mail['res_id']]);
}
}
foreach($externalInfos as $mail){
$document = ResModel::getById(['resId' => $mail['res_id'], 'select' => ['res_id']]);
if (empty($document)) {
return $response->withStatus(400)->withJson(['errors' => _DOCUMENT_NOT_FOUND]);
......@@ -189,8 +194,8 @@ class ResController
return $response->withStatus(403)->withJson(['errors' => 'Document out of perimeter']);
}
ResModel::update(['set' => ['external_id' => $mail['external_id'] , 'external_link' => $mail['external_link'], 'status' => $data['status']], 'where' => ['res_id = ?'], 'data' => [$document['res_id']]]);
}
}
return $response->withJson(['success' => 'success']);
}
......@@ -257,26 +262,31 @@ class ResController
public function getList(Request $request, Response $response)
{
$data = $request->getParams();
$check = Validator::stringType()->notEmpty()->validate($data['clause']);
$check = $check && Validator::stringType()->notEmpty()->validate($data['select']);
if(!Validator::stringType()->notEmpty()->validate($data['select'])){
return $response->withStatus(400)->withJson(['errors' => 'Bad Request: select parameter not valid']);
}
if(!Validator::stringType()->notEmpty()->validate($data['clause'])){
return $response->withStatus(400)->withJson(['errors' => 'Bad Request: clause parameter not valid']);
}
if(!empty($data['withFile'])){
$check = $check && Validator::boolType()->validate($data['withFile']);
if(!Validator::boolType()->validate($data['withFile'])){
return $response->withStatus(400)->withJson(['errors' => 'Bad Request: withFile parameter is not a boolean']);
}
}
if(!empty($data['orderBy'])){
$check = $check && Validator::arrayType()->notEmpty()->validate($data['orderBy']);
$orderBy = $data['orderBy'];
if(!Validator::arrayType()->notEmpty()->validate($data['orderBy'])){
return $response->withStatus(400)->withJson(['errors' => 'Bad Request: orderBy parameter not valid']);
}
}
if(!empty($data['limit'])){
$limit = (int) $data['limit'];
$check = $check && Validator::intType()->validate($limit);
}
if (!$check) {
return $response->withStatus(400)->withJson(['errors' => 'Bad Request']);
if(!Validator::intType()->validate($data['limit'])){
return $response->withStatus(400)->withJson(['errors' => 'Bad Request: limit parameter not valid']);
}
}
$orderBy = $data['orderBy'];
$limit = $data['limit'];
$select = explode(',', $data['select']);
if (!PreparedClauseController::isRequestValid(['select' => $select,'clause' => $data['clause'], 'orderBy' => $orderBy, 'limit' => $limit, 'userId' => $GLOBALS['userId']])) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment