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
src/Cacic/WSBundle/Controller/NeoController.php
... | ... | @@ -116,18 +116,33 @@ class NeoController extends Controller { |
116 | 116 | $status = $request->getContent(); |
117 | 117 | $em = $this->getDoctrine()->getManager(); |
118 | 118 | |
119 | - $response = new JsonResponse(); | |
120 | 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 | 135 | $rede1 = $rede_json[0]; |
127 | 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 | 146 | $computador = $em->getRepository('CacicCommonBundle:Computador')->findOneBy(array( |
132 | 147 | 'teNodeAddress'=> $mac_json, |
133 | 148 | 'idSo' => $so |
... | ... | @@ -147,6 +162,7 @@ class NeoController extends Controller { |
147 | 162 | $computador->setIdSo( $so ); |
148 | 163 | $computador->setIdRede( $rede ); |
149 | 164 | $computador->setDtHrInclusao( $data); |
165 | + $computador->setTeIpComputador( $ip_computador); | |
150 | 166 | |
151 | 167 | $em->persist( $computador ); |
152 | 168 | |
... | ... | @@ -214,6 +230,7 @@ class NeoController extends Controller { |
214 | 230 | |
215 | 231 | $em->flush(); |
216 | 232 | |
233 | + $response = new JsonResponse(); | |
217 | 234 | $response->setStatusCode('200'); |
218 | 235 | return $response; |
219 | 236 | ... | ... |
src/Cacic/WSBundle/Tests/Controller/NeoControllerTest.php
... | ... | @@ -151,17 +151,32 @@ class NeoControllerTest extends WebTestCase |
151 | 151 | 'CONTENT_TYPE' => 'application/json', |
152 | 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 | 182 | $logger->debug("Dados JSON do computador enviados \n".$this->client->getRequest()->getcontent()); | ... | ... |