Commit 64e36f3fe4e692d0c18bb010252056fbbba59eab
Committed by
gabrielamayoli
1 parent
d413a141
Exists in
master
and in
1 other branch
Atualização de primeiros testes do primeiro controller da nova coleta.
Showing
2 changed files
with
22 additions
and
21 deletions
Show diff stats
src/Cacic/WSBundle/Controller/NeoController.php
| ... | ... | @@ -17,6 +17,9 @@ use Symfony\Component\Serializer\Encoder\JsonEncoder; |
| 17 | 17 | use Symfony\Component\Serializer\Normalizer\GetSetMethodNormalizer; |
| 18 | 18 | use Symfony\Component\HttpFoundation\Session\Storage\MetadataBag; |
| 19 | 19 | |
| 20 | +use Cacic\CommonBundle\Entity\Computador; | |
| 21 | +use Cacic\CommonBundle\Entity\LogAcesso; | |
| 22 | +use Cacic\CommonBundle\Entity\SoRepository; | |
| 20 | 23 | |
| 21 | 24 | class NeoController extends Controller { |
| 22 | 25 | |
| ... | ... | @@ -63,7 +66,7 @@ class NeoController extends Controller { |
| 63 | 66 | |
| 64 | 67 | $auth = $this->forward('CacicCommonBundle:Security:login', array( |
| 65 | 68 | 'username' => $usuario->user, |
| 66 | - 'password' => $usuario->senha, | |
| 69 | + 'password' => $usuario->password, | |
| 67 | 70 | )); |
| 68 | 71 | |
| 69 | 72 | $session = $request->getSession(); |
| ... | ... | @@ -106,7 +109,7 @@ class NeoController extends Controller { |
| 106 | 109 | $em = $this->getDoctrine()->getManager(); |
| 107 | 110 | |
| 108 | 111 | $response = new JsonResponse(); |
| 109 | - $dados = json_decode($status); | |
| 112 | + $dados = json_decode($status, true); | |
| 110 | 113 | $logger->debug("JSON get Test status".print_r($dados, true)); |
| 111 | 114 | |
| 112 | 115 | $so_json = $dados['so']; |
| ... | ... | @@ -116,13 +119,15 @@ class NeoController extends Controller { |
| 116 | 119 | $mac_json = $rede1['mac']; |
| 117 | 120 | $rede = $rede1['interface']; |
| 118 | 121 | |
| 119 | - $so = $em->getRepository('CacicCommonBundle:So')->findOneBy(array('te_so' => $so_json)); | |
| 120 | - $mac = $em->getRepository('CacicCommonBundle:Computador')->findOneBy(array('te_node_address'=> $mac_json)); | |
| 122 | + $so = $em->getRepository('CacicCommonBundle:So')->createIfNotExist($so_json); | |
| 123 | + $computador = $em->getRepository('CacicCommonBundle:Computador')->findOneBy(array( | |
| 124 | + 'teNodeAddress'=> $mac_json, | |
| 125 | + 'idSo' => $so | |
| 126 | + )); | |
| 121 | 127 | $logger->debug("$so".print_r($so, true)); |
| 122 | - $logger->debug("$mac".print_r($mac, true)); | |
| 128 | + $logger->debug("$computador".print_r($computador, true)); | |
| 123 | 129 | |
| 124 | 130 | // Regra: MAC e SO são únicos e não podem ser nulos |
| 125 | - $computador = $em->findOneBy( array( 'te_node_address'=> $mac, 'te_so'=> $so->getTeSo()) ); | |
| 126 | 131 | $data = new \DateTime('NOW'); //armazena data Atual |
| 127 | 132 | |
| 128 | 133 | //2 - Insere computador que não existe |
| ... | ... | @@ -130,14 +135,14 @@ class NeoController extends Controller { |
| 130 | 135 | { |
| 131 | 136 | $computador = new Computador(); |
| 132 | 137 | |
| 133 | - $computador->setTeNodeAddress( $mac ); | |
| 138 | + $computador->setTeNodeAddress( $mac_json ); | |
| 134 | 139 | $computador->setIdSo( $so ); |
| 135 | 140 | $computador->setIdRede( $rede ); |
| 136 | 141 | $computador->setDtHrInclusao( $data); |
| 137 | - $computador->setTePalavraChave( $request->get('PHP_AUTH_PW') ); | |
| 138 | 142 | |
| 139 | 143 | $em->persist( $computador ); |
| 140 | 144 | |
| 145 | + | |
| 141 | 146 | } |
| 142 | 147 | |
| 143 | 148 | /* |
| ... | ... | @@ -155,13 +160,10 @@ class NeoController extends Controller { |
| 155 | 160 | // 2.1 - Se existir, atualiza hora de inclusão |
| 156 | 161 | else |
| 157 | 162 | { |
| 158 | - $update = $em->getRepository('CacicCommonBundle:Computador')->findBy(aresponserray('te_node_address'=> $mac, 'te_so'=> $so->getTeSo())); | |
| 159 | - | |
| 160 | - $update->setDtHrInclusao($data); | |
| 163 | + $computador->setDtHrInclusao( $data); | |
| 161 | 164 | |
| 162 | 165 | //Atualiza hora de inclusão |
| 163 | - $em->persist($update); | |
| 164 | - $em->flush(); | |
| 166 | + $em->persist($computador); | |
| 165 | 167 | |
| 166 | 168 | |
| 167 | 169 | } |
| ... | ... | @@ -183,7 +185,7 @@ class NeoController extends Controller { |
| 183 | 185 | |
| 184 | 186 | // Grava o log |
| 185 | 187 | $em->persist($log_acesso); |
| 186 | - $em->flush(); | |
| 188 | + | |
| 187 | 189 | |
| 188 | 190 | } else { |
| 189 | 191 | $dt_ultimo_acesso = $ultimo_acesso->getData()->format('Y-m-d'); |
| ... | ... | @@ -198,12 +200,11 @@ class NeoController extends Controller { |
| 198 | 200 | |
| 199 | 201 | // Grava o log |
| 200 | 202 | $em->persist($log_acesso); |
| 201 | - $em->flush(); | |
| 203 | + | |
| 202 | 204 | } |
| 203 | 205 | } |
| 204 | 206 | |
| 205 | - // 4 - Retorna chave de criptografia | |
| 206 | - | |
| 207 | + $em->flush(); | |
| 207 | 208 | |
| 208 | 209 | $response->setStatusCode('200'); |
| 209 | 210 | return $response; | ... | ... |
src/Cacic/WSBundle/Tests/Controller/NeoControllerTest.php
| ... | ... | @@ -65,8 +65,8 @@ class NeoControllerTest extends WebTestCase |
| 65 | 65 | 'CONTENT_TYPE' => 'application/json', |
| 66 | 66 | //'HTTPS' => true |
| 67 | 67 | ), |
| 68 | - '{ "user" : "02128544106", | |
| 69 | - "senha": "159753" | |
| 68 | + '{ "user" : "cacic-adm", | |
| 69 | + "password": "123456" | |
| 70 | 70 | }' |
| 71 | 71 | ); |
| 72 | 72 | $logger->debug("Dados JSON de login enviados \n".$this->client->getRequest()->getcontent()); |
| ... | ... | @@ -97,8 +97,8 @@ class NeoControllerTest extends WebTestCase |
| 97 | 97 | 'CONTENT_TYPE' => 'application/json', |
| 98 | 98 | //'HTTPS' => true |
| 99 | 99 | ), |
| 100 | - '{ "user" : "02128544106", | |
| 101 | - "senha": "159753" | |
| 100 | + '{ "user" : "cacic-adm", | |
| 101 | + "password": "123456" | |
| 102 | 102 | }' |
| 103 | 103 | ); |
| 104 | 104 | $logger->debug("Dados JSON de login enviados \n".$this->client->getRequest()->getcontent()); | ... | ... |