From bee7eda0f0e15450c20ffbb8c0d05249fa44aea3 Mon Sep 17 00:00:00 2001 From: snoop Date: Thu, 27 Jul 2017 20:20:07 +0900 Subject: [PATCH] fixed target --- .../overflow/module/target/dao/TargetDAO.java | 4 +- .../overflow/module/target/model/Target.java | 49 +++++++++++++------ .../service/TargetDiscoveryService.java | 8 +-- .../module/target/service/TargetService.java | 6 +-- src/main/resources/init.sql | 4 +- .../target/service/TargetServiceTest.java | 19 ++++--- 6 files changed, 57 insertions(+), 33 deletions(-) diff --git a/src/main/java/com/loafle/overflow/module/target/dao/TargetDAO.java b/src/main/java/com/loafle/overflow/module/target/dao/TargetDAO.java index db22668..960cf95 100644 --- a/src/main/java/com/loafle/overflow/module/target/dao/TargetDAO.java +++ b/src/main/java/com/loafle/overflow/module/target/dao/TargetDAO.java @@ -3,6 +3,7 @@ package com.loafle.overflow.module.target.dao; import com.loafle.overflow.module.probe.model.Probe; import com.loafle.overflow.module.target.model.Target; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; import java.util.List; @@ -10,6 +11,7 @@ import java.util.List; /** * Created by root on 17. 6. 5. */ +@Repository public interface TargetDAO extends JpaRepository { - List findAllByProbe(Probe probe); +// List findAllByProbe(Probe probe); } diff --git a/src/main/java/com/loafle/overflow/module/target/model/Target.java b/src/main/java/com/loafle/overflow/module/target/model/Target.java index a7d13c9..ec2f5c5 100644 --- a/src/main/java/com/loafle/overflow/module/target/model/Target.java +++ b/src/main/java/com/loafle/overflow/module/target/model/Target.java @@ -17,8 +17,8 @@ public class Target { private long id; private Date createDate; - private Probe probe; - private Infra infra; + private String displayName; + private String description; /* private long id; @@ -47,25 +47,44 @@ public class Target { this.createDate = createDate; } - @ManyToOne - @JoinColumn(name = "PROBE_ID", nullable = false) - @OnDelete(action = OnDeleteAction.CASCADE) - public Probe getProbe() { - return probe; + @Column(name = "DISPLAY_NAME") + public String getDisplayName() { + return displayName; } - public void setProbe(Probe probe) { - this.probe = probe; + public void setDisplayName(String displayName) { + this.displayName = displayName; } - @ManyToOne - @JoinColumn(name = "INFRA_ID", nullable = false) - public Infra getInfra() { - return infra; + @Column(name = "DESCRIPTION") + public String getDescription() { + return description; } - public void setInfra(Infra infra) { - this.infra = infra; + public void setDescription(String description) { + this.description = description; } + +// @ManyToOne +// @JoinColumn(name = "PROBE_ID", nullable = false) +// @OnDelete(action = OnDeleteAction.CASCADE) +// public Probe getProbe() { +// return probe; +// } +// +// public void setProbe(Probe probe) { +// this.probe = probe; +// } +// +// @ManyToOne +// @JoinColumn(name = "INFRA_ID", nullable = false) +// public Infra getInfra() { +// return infra; +// } +// +// public void setInfra(Infra infra) { +// this.infra = infra; +// } + } diff --git a/src/main/java/com/loafle/overflow/module/target/service/TargetDiscoveryService.java b/src/main/java/com/loafle/overflow/module/target/service/TargetDiscoveryService.java index 92df65c..a54e0b5 100644 --- a/src/main/java/com/loafle/overflow/module/target/service/TargetDiscoveryService.java +++ b/src/main/java/com/loafle/overflow/module/target/service/TargetDiscoveryService.java @@ -75,8 +75,8 @@ public class TargetDiscoveryService { if(host.isTarget()) { Target targetHost = new Target(); - targetHost.setInfra(infraByHost); - targetHost.setProbe(probe); +// targetHost.setInfra(infraByHost); +// targetHost.setProbe(probe); this.targetDAO.save(targetHost); } @@ -126,8 +126,8 @@ public class TargetDiscoveryService { if(service.isTarget()) { Target targetService = new Target(); - targetService.setInfra(infraByService); - targetService.setProbe(probe); +// targetService.setInfra(infraByService); +// targetService.setProbe(probe); this.targetDAO.save(targetService); } diff --git a/src/main/java/com/loafle/overflow/module/target/service/TargetService.java b/src/main/java/com/loafle/overflow/module/target/service/TargetService.java index 136fe61..1d24225 100644 --- a/src/main/java/com/loafle/overflow/module/target/service/TargetService.java +++ b/src/main/java/com/loafle/overflow/module/target/service/TargetService.java @@ -25,9 +25,9 @@ public class TargetService { return this.targetDAO.findOne(Long.valueOf(id)); } - public List readAllByProbe(Probe probe) { - return this.targetDAO.findAllByProbe(probe); - } +// public List readAllByProbe(Probe probe) { +// return this.targetDAO.findAllByProbe(probe); +// } public void remove(Target target) { this.targetDAO.delete(target); diff --git a/src/main/resources/init.sql b/src/main/resources/init.sql index 9c73748..2c9579a 100644 --- a/src/main/resources/init.sql +++ b/src/main/resources/init.sql @@ -419,8 +419,8 @@ INSERT INTO public.infra (id,child_id,create_date,type_id) VALUES ( INSERT INTO public.probe (id,authorized_date,cidr,create_date,description,display_name,encryption_key,probe_key,sensor_count,target_count,member_id,domain_id,host_id,status) VALUES ( 1,'2017-07-27 20:01:28.513','192.168.1.0/24','2017-07-27 20:01:28.513','snoop probe','test probe','8c51fa9c5bcc11e7980a080027658d13','899fdd145bcc11e7b611080027658d13',0,0,1,1,1,1); -INSERT INTO public.target (id,create_date,infra_id,probe_id) VALUES ( -1,'2017-06-26 12:37:22.854',1,1); +INSERT INTO public.target (id,create_date,description,display_name) VALUES ( +1,'2017-07-27 20:18:09.555','i am target','ghost target'); INSERT INTO public.sensor (id,crawler_input_items,create_date,description,crawler_id,status,target_id) VALUES ( 1,NULL,'2017-06-26 20:19:07.009','My sensor',1,1,1); diff --git a/src/test/java/com/loafle/overflow/module/target/service/TargetServiceTest.java b/src/test/java/com/loafle/overflow/module/target/service/TargetServiceTest.java index a675db5..99b91cc 100644 --- a/src/test/java/com/loafle/overflow/module/target/service/TargetServiceTest.java +++ b/src/test/java/com/loafle/overflow/module/target/service/TargetServiceTest.java @@ -5,6 +5,7 @@ import com.loafle.overflow.module.probe.model.Probe; import com.loafle.overflow.module.target.model.Target; import com.loafle.overflow.spring.AppConfig; import com.loafle.overflow.spring.JdbcConfiguration; +import com.loafle.overflow.spring.MailConfiguration; import org.junit.Assert; import org.junit.Ignore; import org.junit.Test; @@ -18,9 +19,9 @@ import java.util.Date; /** * Created by insanity on 17. 6. 28. */ -@Ignore + @RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = {AppConfig.class, JdbcConfiguration.class}) +@ContextConfiguration(classes = {AppConfig.class, JdbcConfiguration.class, MailConfiguration.class}) public class TargetServiceTest { @Autowired TargetService targetService; @@ -29,12 +30,14 @@ public class TargetServiceTest { public void regist() throws Exception { Target t = new Target(); t.setCreateDate(new Date()); - Infra infra = new Infra(); - infra.setId(1); - Probe probe = new Probe(); - probe.setId(1); - t.setProbe(probe); - t.setInfra(infra); +// Infra infra = new Infra(); +// infra.setId(1); +// Probe probe = new Probe(); +// probe.setId(1); +// t.setProbe(probe); +// t.setInfra(infra); + t.setDescription("i am target"); + t.setDisplayName("ghost target"); Target res = this.targetService.regist(t); Assert.assertNotNull(res);