fixed exception
This commit is contained in:
parent
a194d9ae91
commit
83c412885d
|
@ -22,7 +22,18 @@ public class AuthCrawlerService {
|
|||
private InfraService infraService;
|
||||
|
||||
public AuthCrawler regist(AuthCrawler authCrawler) {
|
||||
return this.authCrawlerDAO.save(authCrawler);
|
||||
|
||||
AuthCrawler dbAuthCrawler = this.authCrawlerDAO.findByCrawlerAndTarget(authCrawler.getCrawler(), authCrawler.getTarget());
|
||||
|
||||
if(authCrawler == null) {
|
||||
return this.authCrawlerDAO.save(authCrawler);
|
||||
}
|
||||
|
||||
dbAuthCrawler.setAuthJson(authCrawler.getAuthJson());
|
||||
dbAuthCrawler.setCrawler(authCrawler.getCrawler());
|
||||
dbAuthCrawler.setTarget(authCrawler.getTarget());
|
||||
|
||||
return this.authCrawlerDAO.save(dbAuthCrawler);
|
||||
}
|
||||
|
||||
public boolean checkAuthCrawler(long infraId, MetaCrawler crawler, String authJson) {
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
package com.loafle.overflow.module.infra.exception;
|
||||
|
||||
import com.loafle.overflow.commons.exception.OverflowRuntimeException;
|
||||
|
||||
/**
|
||||
* Created by snoop on 17. 9. 14.
|
||||
*/
|
||||
public class InfraNotFoundException extends OverflowRuntimeException {
|
||||
public InfraNotFoundException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public InfraNotFoundException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
|
@ -5,6 +5,7 @@ import com.loafle.overflow.commons.utils.PageUtil;
|
|||
import com.loafle.overflow.module.domain.model.Domain;
|
||||
import com.loafle.overflow.module.infra.dao.InfraDAO;
|
||||
import com.loafle.overflow.module.infra.model.Infra;
|
||||
import com.loafle.overflow.module.probe.exception.ProbeNotFoundException;
|
||||
import com.loafle.overflow.module.probe.model.Probe;
|
||||
import com.loafle.overflow.module.probe.service.ProbeService;
|
||||
import com.loafle.overflow.module.target.model.Target;
|
||||
|
@ -41,6 +42,11 @@ public class InfraService {
|
|||
|
||||
public Page<Infra> readAllByDomain(Domain domain, PageParams pageParams) {
|
||||
List<Probe> probeList = this.probeService.readAllByDomain(domain);
|
||||
|
||||
if(probeList == null || probeList.size() <= 0) {
|
||||
throw new ProbeNotFoundException();
|
||||
}
|
||||
|
||||
return this.infraDAO.findAllByProbeList(probeList, PageUtil.getPageRequest(pageParams));
|
||||
}
|
||||
|
||||
|
@ -52,6 +58,10 @@ public class InfraService {
|
|||
|
||||
List<Probe> probeList = this.probeService.readAllByDomain(domain);
|
||||
|
||||
if(probeList == null || probeList.size() <= 0) {
|
||||
throw new ProbeNotFoundException();
|
||||
}
|
||||
|
||||
return this.infraDAO.findAllTargetByProbeList(probeList);
|
||||
}
|
||||
|
||||
|
|
|
@ -55,6 +55,11 @@ public class NoAuthProbeService {
|
|||
// Todo domain injection & member injection
|
||||
List<Probe> probes = new ArrayList<>();
|
||||
Probe probe = null;
|
||||
|
||||
Map<String, Object> objMap = null;
|
||||
Map<String, String> hostMap = null;
|
||||
Map<String, String> netMap = null;
|
||||
|
||||
for (NoAuthProbe noAuth : noAuthProbes) {
|
||||
BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
|
||||
String encryptKey = passwordEncoder.encode(UUID.randomUUID().toString());
|
||||
|
@ -68,13 +73,7 @@ public class NoAuthProbeService {
|
|||
probe.setTargetCount(0);
|
||||
probe.setSensorCount(0);
|
||||
|
||||
|
||||
Map<String, Object> objMap = null;
|
||||
objMap = this.objectMapper.readValue(noAuth.getDescription(), new TypeReference<HashMap<String,Object>>() {});
|
||||
|
||||
Map<String, String> hostMap = null;
|
||||
Map<String, String> netMap = null;
|
||||
|
||||
hostMap = (Map<String, String>)objMap.get("host");
|
||||
netMap = (Map<String, String>)objMap.get("network");
|
||||
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
package com.loafle.overflow.module.probe.exception;
|
||||
|
||||
import com.loafle.overflow.commons.exception.OverflowRuntimeException;
|
||||
|
||||
/**
|
||||
* Created by snoop on 17. 9. 14.
|
||||
*/
|
||||
public class ProbeNotFoundException extends OverflowRuntimeException {
|
||||
public ProbeNotFoundException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public ProbeNotFoundException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
|
@ -4,15 +4,18 @@ import com.loafle.overflow.commons.model.PageParams;
|
|||
import com.loafle.overflow.commons.utils.PageUtil;
|
||||
import com.loafle.overflow.module.domain.model.Domain;
|
||||
import com.loafle.overflow.module.generator.service.SensorConfigGenerator;
|
||||
import com.loafle.overflow.module.infra.exception.InfraNotFoundException;
|
||||
import com.loafle.overflow.module.infra.model.Infra;
|
||||
import com.loafle.overflow.module.infra.service.InfraService;
|
||||
import com.loafle.overflow.module.meta.model.MetaSensorStatus;
|
||||
import com.loafle.overflow.module.meta.service.MetaSensorItemKeyService;
|
||||
import com.loafle.overflow.module.probe.exception.ProbeNotFoundException;
|
||||
import com.loafle.overflow.module.probe.model.Probe;
|
||||
import com.loafle.overflow.module.probe.service.ProbeService;
|
||||
import com.loafle.overflow.module.sensor.dao.SensorDAO;
|
||||
import com.loafle.overflow.module.sensor.model.Sensor;
|
||||
import com.loafle.overflow.module.sensor.model.SensorItem;
|
||||
import com.loafle.overflow.module.target.exception.TargetNotFoundException;
|
||||
import com.loafle.overflow.module.target.model.Target;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
|
@ -58,15 +61,25 @@ public class SensorService {
|
|||
|
||||
List<Probe> probeList = this.probeService.readAllByDomain(domain);
|
||||
|
||||
if(probeList == null || probeList.size() <= 0) {
|
||||
throw new ProbeNotFoundException();
|
||||
}
|
||||
|
||||
List<Target> targetList = this.infraService.readAllTargetByProbeList(probeList);
|
||||
|
||||
if(targetList == null || targetList.size() <= 0) {
|
||||
throw new TargetNotFoundException();
|
||||
}
|
||||
|
||||
return this.sensorDAO.findAllByTargetList(targetList, PageUtil.getPageRequest(pageParams));
|
||||
}
|
||||
|
||||
public Page<Sensor> readAllByInfra(long infraId, PageParams pageParams) {
|
||||
Infra dbInfra = this.infraService.read(infraId);
|
||||
|
||||
if(dbInfra == null || dbInfra.getTarget() == null) return null;
|
||||
if(dbInfra == null || dbInfra.getTarget() == null) {
|
||||
throw new InfraNotFoundException();
|
||||
}
|
||||
|
||||
return this.sensorDAO.findAllByTarget(dbInfra.getTarget(), PageUtil.getPageRequest(pageParams));
|
||||
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
package com.loafle.overflow.module.target.exception;
|
||||
|
||||
import com.loafle.overflow.commons.exception.OverflowRuntimeException;
|
||||
|
||||
/**
|
||||
* Created by snoop on 17. 9. 14.
|
||||
*/
|
||||
public class TargetNotFoundException extends OverflowRuntimeException {
|
||||
public TargetNotFoundException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public TargetNotFoundException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
package com.loafle.overflow.module.infra.dao;
|
||||
|
||||
import com.loafle.overflow.module.probe.model.Probe;
|
||||
import com.loafle.overflow.spring.AppConfigTest;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by snoop on 17. 9. 14.
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(classes = {AppConfigTest.class})
|
||||
public class InfraDAOTest {
|
||||
|
||||
@Autowired
|
||||
private InfraDAO infraDAO;
|
||||
|
||||
@Test
|
||||
public void findAllByProbeList() throws Exception {
|
||||
|
||||
List<Probe> probes = new ArrayList<>();
|
||||
|
||||
Probe probe = new Probe();
|
||||
probe.setId(1);
|
||||
|
||||
probes.add(probe);
|
||||
|
||||
|
||||
this.infraDAO.findAllTargetByProbeList(probes);
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user