Commit 39309d28768f9220acd5e29f14c1bba283dd3f02
Committed by
gabrielamayoli
1 parent
6bf47202
Exists in
master
and in
1 other branch
Finalização de primeiros testes do primeiro controller da nova coleta.
Showing
3 changed files
with
50 additions
and
18 deletions
Show diff stats
src/Cacic/CommonBundle/Resources/config/doctrine/Computador.orm.yml
@@ -51,7 +51,7 @@ Cacic\CommonBundle\Entity\Computador: | @@ -51,7 +51,7 @@ Cacic\CommonBundle\Entity\Computador: | ||
51 | tePalavraChave: | 51 | tePalavraChave: |
52 | type: text | 52 | type: text |
53 | fixed: true | 53 | fixed: true |
54 | - nullable: false | 54 | + nullable: true |
55 | column: te_palavra_chave | 55 | column: te_palavra_chave |
56 | forcaColeta: | 56 | forcaColeta: |
57 | type: text | 57 | type: text |
src/Cacic/WSBundle/Controller/NeoController.php
@@ -116,18 +116,33 @@ class NeoController extends Controller { | @@ -116,18 +116,33 @@ class NeoController extends Controller { | ||
116 | $status = $request->getContent(); | 116 | $status = $request->getContent(); |
117 | $em = $this->getDoctrine()->getManager(); | 117 | $em = $this->getDoctrine()->getManager(); |
118 | 118 | ||
119 | - $response = new JsonResponse(); | ||
120 | $dados = json_decode($status, true); | 119 | $dados = json_decode($status, true); |
121 | - $logger->debug("JSON get Test status".print_r($dados, true)); | ||
122 | - | ||
123 | - $so_json = $dados['so']; | 120 | + if (empty($dados)) { |
121 | + // REtorna erro se o JSON for inválido | ||
122 | + $error_msg = '{ | ||
123 | + "message": "JSON Inválido", | ||
124 | + "codigo": 1 | ||
125 | + }'; | ||
126 | + $response = new JsonResponse(); | ||
127 | + $response->setStatusCode('500'); | ||
128 | + $response->setContent($error_msg); | ||
129 | + return $response; | ||
130 | + } | ||
131 | + $logger->debug("JSON get Test status".print_r(json_decode($status, true), true)); | ||
124 | 132 | ||
125 | - $rede_json = $dados['rede']; | 133 | + $so_json = $dados['computador']['operatingSystem']; |
134 | + $rede_json = $dados['computador']['networkDevices']; | ||
126 | $rede1 = $rede_json[0]; | 135 | $rede1 = $rede_json[0]; |
127 | $mac_json = $rede1['mac']; | 136 | $mac_json = $rede1['mac']; |
128 | - $rede = $rede1['interface']; | 137 | + $ip_computador = $rede1['ipv4']; |
138 | + $netmask = $rede1['netmask_ipv4']; | ||
129 | 139 | ||
130 | - $so = $em->getRepository('CacicCommonBundle:So')->createIfNotExist($so_json); | 140 | + // Pega rede |
141 | + $rede = $this->getDoctrine()->getRepository('CacicCommonBundle:Rede')->getDadosRedePreColeta( $ip_computador, $netmask ); | ||
142 | + | ||
143 | + $logger->debug("1111111111111111111111111111111111111111111 ".print_r($so_json, true)); | ||
144 | + | ||
145 | + $so = $em->getRepository('CacicCommonBundle:So')->createIfNotExist($so_json['nomeOs']); | ||
131 | $computador = $em->getRepository('CacicCommonBundle:Computador')->findOneBy(array( | 146 | $computador = $em->getRepository('CacicCommonBundle:Computador')->findOneBy(array( |
132 | 'teNodeAddress'=> $mac_json, | 147 | 'teNodeAddress'=> $mac_json, |
133 | 'idSo' => $so | 148 | 'idSo' => $so |
@@ -147,6 +162,7 @@ class NeoController extends Controller { | @@ -147,6 +162,7 @@ class NeoController extends Controller { | ||
147 | $computador->setIdSo( $so ); | 162 | $computador->setIdSo( $so ); |
148 | $computador->setIdRede( $rede ); | 163 | $computador->setIdRede( $rede ); |
149 | $computador->setDtHrInclusao( $data); | 164 | $computador->setDtHrInclusao( $data); |
165 | + $computador->setTeIpComputador( $ip_computador); | ||
150 | 166 | ||
151 | $em->persist( $computador ); | 167 | $em->persist( $computador ); |
152 | 168 | ||
@@ -214,6 +230,7 @@ class NeoController extends Controller { | @@ -214,6 +230,7 @@ class NeoController extends Controller { | ||
214 | 230 | ||
215 | $em->flush(); | 231 | $em->flush(); |
216 | 232 | ||
233 | + $response = new JsonResponse(); | ||
217 | $response->setStatusCode('200'); | 234 | $response->setStatusCode('200'); |
218 | return $response; | 235 | return $response; |
219 | 236 |
src/Cacic/WSBundle/Tests/Controller/NeoControllerTest.php
@@ -151,17 +151,32 @@ class NeoControllerTest extends WebTestCase | @@ -151,17 +151,32 @@ class NeoControllerTest extends WebTestCase | ||
151 | 'CONTENT_TYPE' => 'application/json', | 151 | 'CONTENT_TYPE' => 'application/json', |
152 | //'HTTPS' => true | 152 | //'HTTPS' => true |
153 | ), | 153 | ), |
154 | - '{ "so" : "2.6.1", | ||
155 | - "rede": [ | ||
156 | - { "mac" : "e0:3f:49:e4:72:75", | ||
157 | - "ip" : "10.1.0.137", | ||
158 | - "interface": "Rede Local" | 154 | + '{ |
155 | + "computador": { | ||
156 | + "networkDevices": [ | ||
157 | + { | ||
158 | + "ipv4": "10.1.0.56", | ||
159 | + "ipv6": "fe80::295b:a8db:d433:ebe%4", | ||
160 | + "mac": "9C:D2:1E:EA:E0:89", | ||
161 | + "netmask_ipv4": "255.255.255.0", | ||
162 | + "netmask_ipv6": "ffff:ffff:ffff:ffff::", | ||
163 | + "nome": "Wi-Fi" | ||
164 | + }, | ||
165 | + { | ||
166 | + "ipv4": "192.168.56.1", | ||
167 | + "ipv6": "fe80::19f2:4739:8a9e:45e4%16", | ||
168 | + "mac": "08:00:27:00:14:2B", | ||
169 | + "netmask_ipv4": "255.255.255.0", | ||
170 | + "netmask_ipv6": "ffff:ffff:ffff:ffff::", | ||
171 | + "nome": "VirtualBox Host-Only Network" | ||
172 | + } | ||
173 | + ], | ||
174 | + "operatingSystem": { | ||
175 | + "idOs": 176, | ||
176 | + "nomeOs": "Windows_NT" | ||
159 | }, | 177 | }, |
160 | - { "mac" : "e0:3f:49:e4:72:76", | ||
161 | - "ip" : "10.1.0.138", | ||
162 | - "interface": "Rede Local" | ||
163 | - } | ||
164 | - ] | 178 | + "usuario": "Eric Menezes" |
179 | + } | ||
165 | }' | 180 | }' |
166 | ); | 181 | ); |
167 | $logger->debug("Dados JSON do computador enviados \n".$this->client->getRequest()->getcontent()); | 182 | $logger->debug("Dados JSON do computador enviados \n".$this->client->getRequest()->getcontent()); |