diff --git a/src/main/java/com/loafle/overflow/central/commons/utils/PageUtil.java b/src/main/java/com/loafle/overflow/central/commons/utils/PageUtil.java index 4d348ee..ba77ebb 100644 --- a/src/main/java/com/loafle/overflow/central/commons/utils/PageUtil.java +++ b/src/main/java/com/loafle/overflow/central/commons/utils/PageUtil.java @@ -1,6 +1,7 @@ package com.loafle.overflow.central.commons.utils; -import com.loafle.overflow.central.commons.model.PageParams; +import com.loafle.overflow.core.model.PageParams; + import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Sort; diff --git a/src/main/java/com/loafle/overflow/central/module/noauthprobe/dao/NoAuthProbeDAO.java b/src/main/java/com/loafle/overflow/central/module/noauthprobe/dao/NoAuthProbeDAO.java index 59c2ac6..734c95b 100644 --- a/src/main/java/com/loafle/overflow/central/module/noauthprobe/dao/NoAuthProbeDAO.java +++ b/src/main/java/com/loafle/overflow/central/module/noauthprobe/dao/NoAuthProbeDAO.java @@ -1,7 +1,8 @@ package com.loafle.overflow.central.module.noauthprobe.dao; -import com.loafle.overflow.central.module.domain.model.Domain; -import com.loafle.overflow.central.module.noauthprobe.model.NoAuthProbe; +import com.loafle.overflow.model.domain.Domain; +import com.loafle.overflow.model.noauthprobe.NoAuthProbe; + import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; @@ -14,12 +15,14 @@ import java.util.List; */ @Repository public interface NoAuthProbeDAO extends JpaRepository { -// NoAuthProbeDeprecate findByTempKey(NoAuthProbeDeprecate noAuthAgent); -// List findAllByNoAuth(NoAuthProbeDeprecate noAuthAgent); -// @Query("SELECT n FROM NoAuthProbe n WHERE n.tempProbeKey = :tempProbeKey") NoAuthProbe findByTempProbeKey(String tempProbeKey); -// @Query("select m from Member m WHERE m.email = :#{#m2.email}") + @Query("SELECT n FROM NoAuthProbe n WHERE n.domain.id = :#{#domain.id} and n.status.id = 3") // 3 = Process List findAllByDomain(@Param("domain") Domain domain); + +// NoAuthProbeDeprecate findByTempKey(NoAuthProbeDeprecate noAuthAgent); +// List findAllByNoAuth(NoAuthProbeDeprecate noAuthAgent); +// @Query("SELECT n FROM NoAuthProbe n WHERE n.tempProbeKey = :tempProbeKey") +// @Query("select m from Member m WHERE m.email = :#{#m2.email}") } diff --git a/src/main/java/com/loafle/overflow/central/module/noauthprobe/model/NoAuthProbe.java b/src/main/java/com/loafle/overflow/central/module/noauthprobe/model/NoAuthProbe.java deleted file mode 100644 index b6ecc12..0000000 --- a/src/main/java/com/loafle/overflow/central/module/noauthprobe/model/NoAuthProbe.java +++ /dev/null @@ -1,138 +0,0 @@ -package com.loafle.overflow.central.module.noauthprobe.model; - - -import com.loafle.overflow.central.module.domain.model.Domain; -import com.loafle.overflow.central.module.meta.model.MetaNoAuthProbeStatus; -import com.loafle.overflow.central.module.probe.model.Probe; - -import javax.persistence.*; -import java.util.Date; - -/** - * Created by root on 17. 6. 22. - */ -@Entity -@Table(name = "NOAUTH_PROBE", schema = "public") -public class NoAuthProbe { - private long id; - private String description; - private MetaNoAuthProbeStatus status; - private String tempProbeKey; - private Date createDate; - private String apiKey; - private Domain domain; - private Probe probe; - - @Id - @GeneratedValue(strategy= GenerationType.IDENTITY) - public long getId() { - return id; - } - - public void setId(long id) { - this.id = id; - } - - @Column(name = "DESCRIPTION", nullable = true, length = 1000) - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - @ManyToOne - @JoinColumn(name = "STATUS", nullable = false) - public MetaNoAuthProbeStatus getStatus() { - return status; - } - - public void setStatus(MetaNoAuthProbeStatus status) { - this.status = status; - } - - @Column(name = "TEMP_PROBE_KEY", nullable = false, length = 50, unique = true) - public String getTempProbeKey() { - return tempProbeKey; - } - - public void setTempProbeKey(String tempProbeKey) { - this.tempProbeKey = tempProbeKey; - } - - @Temporal(TemporalType.TIMESTAMP) - @Column(name = "CREATE_DATE", nullable = false, columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", insertable = false, updatable = false) - public Date getCreateDate() { - return createDate; - } - - public void setCreateDate(Date createDate) { - this.createDate = createDate; - } - - @Column(name = "API_KEY", nullable = true, length = 50) - public String getApiKey() { - return apiKey; - } - - public void setApiKey(String apiKey) { - this.apiKey = apiKey; - } - - @ManyToOne - @JoinColumn(name = "DOMAIN_ID", nullable=false) - public Domain getDomain() { - return domain; - } - - public void setDomain(Domain domain) { - this.domain = domain; - } - - @ManyToOne - @JoinColumn(name = "PROBE_ID", nullable = true) - public Probe getProbe() { - return probe; - } - - public void setProbe(Probe probe) { - this.probe = probe; - } - -// @Override -// public boolean equals(Object o) { -// if (this == o) return true; -// if (o == null || getClass() != o.getClass()) return false; -// -// NoAuthProbe that = (NoAuthProbe) o; -// -// if (id != that.id) return false; -// if (domainId != that.domainId) return false; -// if (hostName != null ? !hostName.equals(that.hostName) : that.hostName != null) return false; -// if (macAddress != null ? !macAddress.equals(that.macAddress) : that.macAddress != null) return false; -// if (ipAddress != null ? !ipAddress.equals(that.ipAddress) : that.ipAddress != null) return false; -// if (status != null ? !status.equals(that.status) : that.status != null) return false; -// if (tempProbeKey != null ? !tempProbeKey.equals(that.tempProbeKey) : that.tempProbeKey != null) return false; -// if (createDate != null ? !createDate.equals(that.createDate) : that.createDate != null) return false; -// if (apiKey != null ? !apiKey.equals(that.apiKey) : that.apiKey != null) return false; -// if (probeId != null ? !probeId.equals(that.probeId) : that.probeId != null) return false; -// -// return true; -// } -// -// @Override -// public int hashCode() { -// int result = (int) (id ^ (id >>> 32)); -// result = 31 * result + (hostName != null ? hostName.hashCode() : 0); -// result = 31 * result + (macAddress != null ? macAddress.hashCode() : 0); -// result = 31 * result + (ipAddress != null ? ipAddress.hashCode() : 0); -// result = 31 * result + (status != null ? status.hashCode() : 0); -// result = 31 * result + (tempProbeKey != null ? tempProbeKey.hashCode() : 0); -// result = 31 * result + (createDate != null ? createDate.hashCode() : 0); -// result = 31 * result + (apiKey != null ? apiKey.hashCode() : 0); -// result = 31 * result + (int) (domainId ^ (domainId >>> 32)); -// result = 31 * result + (probeId != null ? probeId.hashCode() : 0); -// return result; -// } -} diff --git a/src/main/java/com/loafle/overflow/central/module/noauthprobe/service/NoAuthProbeService.java b/src/main/java/com/loafle/overflow/central/module/noauthprobe/service/CentralNoAuthProbeService.java similarity index 79% rename from src/main/java/com/loafle/overflow/central/module/noauthprobe/service/NoAuthProbeService.java rename to src/main/java/com/loafle/overflow/central/module/noauthprobe/service/CentralNoAuthProbeService.java index 7b31efa..6ac6a6d 100644 --- a/src/main/java/com/loafle/overflow/central/module/noauthprobe/service/NoAuthProbeService.java +++ b/src/main/java/com/loafle/overflow/central/module/noauthprobe/service/CentralNoAuthProbeService.java @@ -5,19 +5,22 @@ import com.loafle.overflow.central.commons.service.MessagePublisher; import com.loafle.overflow.central.commons.stereotype.ProbeAPI; import com.loafle.overflow.central.commons.stereotype.WebappAPI; import com.loafle.overflow.central.commons.utils.GenerateKey; -import com.loafle.overflow.central.module.apikey.model.ApiKey; -import com.loafle.overflow.central.module.apikey.service.ApiKeyService; -import com.loafle.overflow.central.module.domain.model.Domain; -import com.loafle.overflow.central.module.domain.model.DomainMember; -import com.loafle.overflow.central.module.domain.service.DomainMemberService; -import com.loafle.overflow.central.module.member.model.Member; import com.loafle.overflow.central.module.member.service.MemberService; -import com.loafle.overflow.central.module.meta.model.MetaNoAuthProbeStatus; -import com.loafle.overflow.central.module.meta.model.MetaProbeStatus; import com.loafle.overflow.central.module.noauthprobe.dao.NoAuthProbeDAO; -import com.loafle.overflow.central.module.noauthprobe.model.NoAuthProbe; -import com.loafle.overflow.central.module.probe.model.Probe; -import com.loafle.overflow.central.module.probe.service.ProbeService; +import com.loafle.overflow.core.exception.OverflowException; +import com.loafle.overflow.model.apikey.ApiKey; +import com.loafle.overflow.model.domain.Domain; +import com.loafle.overflow.model.domain.DomainMember; +import com.loafle.overflow.model.member.Member; +import com.loafle.overflow.model.meta.MetaNoAuthProbeStatus; +import com.loafle.overflow.model.meta.MetaProbeStatus; +import com.loafle.overflow.model.noauthprobe.NoAuthProbe; +import com.loafle.overflow.model.probe.Probe; +import com.loafle.overflow.service.central.apikey.ApiKeyService; +import com.loafle.overflow.service.central.domain.DomainMemberService; +import com.loafle.overflow.service.central.noauthprobe.NoAuthProbeService; +import com.loafle.overflow.service.central.probe.ProbeService; + import org.codehaus.jackson.map.ObjectMapper; import org.codehaus.jackson.type.TypeReference; import org.springframework.beans.factory.annotation.Autowired; @@ -34,7 +37,7 @@ import java.util.UUID; * Created by snoop on 17. 6. 28. */ @Service("NoAuthProbeService") -public class NoAuthProbeService { +public class CentralNoAuthProbeService implements NoAuthProbeService{ @Autowired private NoAuthProbeDAO noAuthProbeDAO; @@ -55,7 +58,7 @@ public class NoAuthProbeService { private DomainMemberService domainMemberService; @ProbeAPI - public NoAuthProbe regist(NoAuthProbe noAuthProbe) { + public NoAuthProbe regist(NoAuthProbe noAuthProbe) throws OverflowException{ ApiKey apiKey = apiKeyService.readByApiKey(noAuthProbe.getApiKey()); noAuthProbe.setDomain(apiKey.getDomain()); @@ -69,17 +72,17 @@ public class NoAuthProbeService { } - public List readAllByDomain(Domain domain) { + public List readAllByDomain(Domain domain) throws OverflowException { return this.noAuthProbeDAO.findAllByDomain(domain); } - public NoAuthProbe read(long id) { + public NoAuthProbe read(long id) throws OverflowException { return this.noAuthProbeDAO.findOne(id); } @WebappAPI - public List acceptNoAuthProbe(NoAuthProbe noAuthProbe) throws IOException { + public List acceptNoAuthProbe(NoAuthProbe noAuthProbe) throws OverflowException { String memberEmail = SessionMetadata.getTargetID(); // Todo domain injection & member injection @@ -125,7 +128,7 @@ public class NoAuthProbeService { } @WebappAPI - public List denyNoauthProbe(NoAuthProbe noAuthProbe) { + public List denyNoauthProbe(NoAuthProbe noAuthProbe) throws OverflowException { noAuthProbe.setStatus(new MetaNoAuthProbeStatus((short) 2)); this.noAuthProbeDAO.save(noAuthProbe); diff --git a/src/main/java/com/loafle/overflow/central/module/notification/dao/NotificationDAO.java b/src/main/java/com/loafle/overflow/central/module/notification/dao/NotificationDAO.java index 524c925..d9c4a4d 100644 --- a/src/main/java/com/loafle/overflow/central/module/notification/dao/NotificationDAO.java +++ b/src/main/java/com/loafle/overflow/central/module/notification/dao/NotificationDAO.java @@ -1,7 +1,8 @@ package com.loafle.overflow.central.module.notification.dao; -import com.loafle.overflow.central.module.member.model.Member; -import com.loafle.overflow.central.module.notification.model.Notification; +import com.loafle.overflow.model.member.Member; +import com.loafle.overflow.model.notification.Notification; + import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; diff --git a/src/main/java/com/loafle/overflow/central/module/notification/model/Notification.java b/src/main/java/com/loafle/overflow/central/module/notification/model/Notification.java deleted file mode 100644 index a557e21..0000000 --- a/src/main/java/com/loafle/overflow/central/module/notification/model/Notification.java +++ /dev/null @@ -1,89 +0,0 @@ -package com.loafle.overflow.central.module.notification.model; - -import com.loafle.overflow.central.module.member.model.Member; - -import javax.persistence.*; -import java.util.Date; - -/** - * Created by insanity on 17. 8. 25. - */ -@Entity -@Table(name = "NOTIFICATION", schema = "public") -public class Notification { - private long id; - private Date createDate; - private String title; - private String message; - private Member member; - private Date confirmDate; - private String url; - - @Id - @GeneratedValue(strategy= GenerationType.IDENTITY) - public long getId() { - return id; - } - - public void setId(long id) { - this.id = id; - } - - @Temporal(TemporalType.TIMESTAMP) - @Column(name = "CREATE_DATE", nullable = false, columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", insertable = false, updatable = false) - public Date getCreateDate() { - return createDate; - } - - public void setCreateDate(Date createDate) { - this.createDate = createDate; - } - - @Column(name = "TITLE", nullable = false, length = 50) - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } - - @Column(name = "MESSAGE", nullable = false, length = 255) - public String getMessage() { - return message; - } - - public void setMessage(String message) { - this.message = message; - } - - @ManyToOne - @JoinColumn(name = "MEMBER_ID", nullable = false) - public Member getMember() { - return member; - } - - public void setMember(Member member) { - this.member = member; - } - - @Temporal(TemporalType.TIMESTAMP) - @Column(name = "CONFIRM_DATE", nullable = true) - public Date getConfirmDate() { - return confirmDate; - } - - public void setConfirmDate(Date confirmDate) { - this.confirmDate = confirmDate; - } - - - @Column(name = "URL", nullable = false, length = 255) - public String getUrl() { - return url; - } - - public void setUrl(String url) { - this.url = url; - } -} diff --git a/src/main/java/com/loafle/overflow/central/module/notification/service/NotificationService.java b/src/main/java/com/loafle/overflow/central/module/notification/service/CentralNotificationService.java similarity index 68% rename from src/main/java/com/loafle/overflow/central/module/notification/service/NotificationService.java rename to src/main/java/com/loafle/overflow/central/module/notification/service/CentralNotificationService.java index b262a88..07b90f9 100644 --- a/src/main/java/com/loafle/overflow/central/module/notification/service/NotificationService.java +++ b/src/main/java/com/loafle/overflow/central/module/notification/service/CentralNotificationService.java @@ -1,10 +1,13 @@ package com.loafle.overflow.central.module.notification.service; -import com.loafle.overflow.central.commons.model.PageParams; import com.loafle.overflow.central.commons.utils.PageUtil; -import com.loafle.overflow.central.module.member.model.Member; import com.loafle.overflow.central.module.notification.dao.NotificationDAO; -import com.loafle.overflow.central.module.notification.model.Notification; +import com.loafle.overflow.core.exception.OverflowException; +import com.loafle.overflow.core.model.PageParams; +import com.loafle.overflow.model.member.Member; +import com.loafle.overflow.model.notification.Notification; +import com.loafle.overflow.service.central.notification.NotificationService; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.stereotype.Service; @@ -16,28 +19,28 @@ import java.util.List; * Created by insanity on 17. 8. 25. */ @Service("NotificationService") -public class NotificationService { +public class CentralNotificationService implements NotificationService { @Autowired private NotificationDAO notificationDAO; - public Notification regist(Notification notification) { + public Notification regist(Notification notification) throws OverflowException { return this.notificationDAO.save(notification); } - public Page readAllByMember(Member member, PageParams pageParams) { + public Page readAllByMember(Member member, PageParams pageParams) throws OverflowException { return this.notificationDAO.findAllByMember(member, PageUtil.getPageRequest(pageParams)); } - public Page readAllUnconfirmedByMember(Member member, PageParams pageParams) { + public Page readAllUnconfirmedByMember(Member member, PageParams pageParams) throws OverflowException { return this.notificationDAO.findAllUnconfirmedByMember(member, PageUtil.getPageRequest(pageParams)); } - public int readUnconfirmedCount(Member member) { + public int readUnconfirmedCount(Member member) throws OverflowException { return this.notificationDAO.findAllUnconfirmedCountByMember(member); } - public Page markAllAsRead(Member member, PageParams pageParams) { + public Page markAllAsRead(Member member, PageParams pageParams) throws OverflowException { List list = this.notificationDAO.findAllByMember(member); for (Notification n : list) { n.setConfirmDate(new Date()); @@ -46,7 +49,7 @@ public class NotificationService { return this.readAllByMember(member, pageParams); } - public Page markAllAsUnread(Member member, PageParams pageParams) { + public Page markAllAsUnread(Member member, PageParams pageParams) throws OverflowException { List list = this.notificationDAO.findAllByMember(member); for (Notification n : list) { n.setConfirmDate(null); @@ -55,8 +58,9 @@ public class NotificationService { return this.readAllByMember(member, pageParams); } - public Notification markAsRead(Notification notification) { + public Notification markAsRead(Notification notification) throws OverflowException { notification.setConfirmDate(new Date()); return this.notificationDAO.save(notification); } + } diff --git a/src/main/java/com/loafle/overflow/central/module/probe/dao/ProbeDAO.java b/src/main/java/com/loafle/overflow/central/module/probe/dao/ProbeDAO.java index 34fafee..269225c 100644 --- a/src/main/java/com/loafle/overflow/central/module/probe/dao/ProbeDAO.java +++ b/src/main/java/com/loafle/overflow/central/module/probe/dao/ProbeDAO.java @@ -1,7 +1,8 @@ package com.loafle.overflow.central.module.probe.dao; -import com.loafle.overflow.central.module.domain.model.Domain; -import com.loafle.overflow.central.module.probe.model.Probe; +import com.loafle.overflow.model.domain.Domain; +import com.loafle.overflow.model.probe.Probe; + import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; @@ -13,9 +14,7 @@ import java.util.List; */ @Repository public interface ProbeDAO extends JpaRepository { -// public List findAgentListByMemberId(Member member); Probe findByProbeKey(String probeKey); - List findAllByDomainOrderByIdDesc(Domain domain); } \ No newline at end of file diff --git a/src/main/java/com/loafle/overflow/central/module/probe/dao/ProbeHostDAO.java b/src/main/java/com/loafle/overflow/central/module/probe/dao/ProbeHostDAO.java index 6ebcd63..52cd495 100644 --- a/src/main/java/com/loafle/overflow/central/module/probe/dao/ProbeHostDAO.java +++ b/src/main/java/com/loafle/overflow/central/module/probe/dao/ProbeHostDAO.java @@ -1,7 +1,8 @@ package com.loafle.overflow.central.module.probe.dao; -import com.loafle.overflow.central.module.probe.model.Probe; -import com.loafle.overflow.central.module.probe.model.ProbeHost; +import com.loafle.overflow.model.probe.Probe; +import com.loafle.overflow.model.probe.ProbeHost; + import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; @@ -10,6 +11,5 @@ import org.springframework.stereotype.Repository; */ @Repository public interface ProbeHostDAO extends JpaRepository { - ProbeHost findByProbe(Probe probe); } diff --git a/src/main/java/com/loafle/overflow/central/module/probe/dao/ProbeTaskDAO.java b/src/main/java/com/loafle/overflow/central/module/probe/dao/ProbeTaskDAO.java index 914e5c5..38f8b23 100644 --- a/src/main/java/com/loafle/overflow/central/module/probe/dao/ProbeTaskDAO.java +++ b/src/main/java/com/loafle/overflow/central/module/probe/dao/ProbeTaskDAO.java @@ -1,17 +1,17 @@ package com.loafle.overflow.central.module.probe.dao; -import com.loafle.overflow.central.module.probe.model.Probe; -import com.loafle.overflow.central.module.probe.model.ProbeTask; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; import java.util.List; +import com.loafle.overflow.model.probe.Probe; +import com.loafle.overflow.model.probe.ProbeTask; + /** * Created by snoop on 17. 6. 26. */ @Repository public interface ProbeTaskDAO extends JpaRepository { - List findAllByProbe(Probe probe); } diff --git a/src/main/java/com/loafle/overflow/central/module/probe/exception/ProbeNotFoundException.java b/src/main/java/com/loafle/overflow/central/module/probe/exception/ProbeNotFoundException.java index b164e2f..206f5d4 100644 --- a/src/main/java/com/loafle/overflow/central/module/probe/exception/ProbeNotFoundException.java +++ b/src/main/java/com/loafle/overflow/central/module/probe/exception/ProbeNotFoundException.java @@ -6,7 +6,9 @@ import com.loafle.overflow.central.commons.exception.OverflowRuntimeException; * Created by snoop on 17. 9. 14. */ public class ProbeNotFoundException extends OverflowRuntimeException { - public ProbeNotFoundException() { + private static final long serialVersionUID = 1L; + + public ProbeNotFoundException() { super(); } diff --git a/src/main/java/com/loafle/overflow/central/module/probe/model/Probe.java b/src/main/java/com/loafle/overflow/central/module/probe/model/Probe.java deleted file mode 100644 index f4b79e4..0000000 --- a/src/main/java/com/loafle/overflow/central/module/probe/model/Probe.java +++ /dev/null @@ -1,190 +0,0 @@ -package com.loafle.overflow.central.module.probe.model; - -import com.loafle.overflow.central.module.domain.model.Domain; -import com.loafle.overflow.central.module.infra.model.Infra; -import com.loafle.overflow.central.module.member.model.Member; -import com.loafle.overflow.central.module.meta.model.MetaProbeStatus; - -import javax.persistence.*; -import java.util.Date; -import java.util.List; - -/** - * Created by root on 17. 6. 22. - */ -@Entity -@Table(name = "PROBE", schema = "public") -public class Probe { - - private long id; - private MetaProbeStatus status; - private String description; - private Date createDate; - private Domain domain; - private String probeKey; - private String encryptionKey; - private String displayName; - private String cidr; - private Date authorizeDate; - private Member authorizeMember; - - private List targets; - -// private InfraHost host; -// private int targetCount; -// private int sensorCount; - - public Probe() { - - } - - public Probe(long id) { - this.id = id; - } - - @Id - @GeneratedValue(strategy= GenerationType.IDENTITY) - public long getId() { - return id; - } - - public void setId(long id) { - this.id = id; - } - - @ManyToOne - @JoinColumn(name = "STATUS", nullable = false) - public MetaProbeStatus getStatus() { - return status; - } - - public void setStatus(MetaProbeStatus status) { - this.status = status; - } - - - @Column(name = "DESCRIPTION", nullable = true, length = 50) - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - @Temporal(TemporalType.TIMESTAMP) - @Column(name = "CREATE_DATE", nullable = false, columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", insertable = false, updatable = false) - public Date getCreateDate() { - return createDate; - } - - public void setCreateDate(Date createDate) { - this.createDate = createDate; - } - - @ManyToOne - @JoinColumn(name = "DOMAIN_ID", nullable = false) - public Domain getDomain() { - return domain; - } - - public void setDomain(Domain domain) { - this.domain = domain; - } - - - @Column(name = "PROBE_KEY", nullable = false, unique = true) - public String getProbeKey() { - return probeKey; - } - - public void setProbeKey(String probeKey) { - this.probeKey = probeKey; - } - - - @Column(name = "ENCRYPTION_KEY", nullable = false, length = 100, unique = true) - public String getEncryptionKey() { - return encryptionKey; - } - - public void setEncryptionKey(String encryptionKey) { - this.encryptionKey = encryptionKey; - } - - - @Transient - public List getTargets() { - return targets; - } - - public void setTargets(List targets) { - this.targets = targets; - } - - // @Column(name = "TARGET_COUNT", nullable = false) -// public int getTargetCount() { -// return targetCount; -// } -// -// public void setTargetCount(int targetCount) { -// this.targetCount = targetCount; -// } -// -// @Column(name = "SENSOR_COUNT", nullable = false) -// public int getSensorCount() { -// return sensorCount; -// } -// -// public void setSensorCount(int sensorCount) { -// this.sensorCount = sensorCount; -// } - - @Column(name = "DISPLAY_NAME") - public String getDisplayName() { - return displayName; - } - - public void setDisplayName(String displayName) { - this.displayName = displayName; - } - - @Column(name = "CIDR") - public String getCidr() { - return cidr; - } - - public void setCidr(String cidr) { - this.cidr = cidr; - } - - @Temporal(TemporalType.TIMESTAMP) - @Column(name = "AUTHORIZE_DATE", nullable = false, columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", insertable = false, updatable = false) - public Date getAuthorizeDate() { - return authorizeDate; - } - - public void setAuthorizeDate(Date authorizeDate) { - this.authorizeDate = authorizeDate; - } - - @ManyToOne - @JoinColumn(name = "AUTHORIZE_MEMBER_ID", nullable = false) - public Member getAuthorizeMember() { - return authorizeMember; - } - - public void setAuthorizeMember(Member authorizeMember) { - this.authorizeMember = authorizeMember; - } -// -// @ManyToOne -// @JoinColumn(name = "HOST_ID", nullable = false) -// public InfraHost getHost() { -// return host; -// } -// -// public void setHost(InfraHost host) { -// this.host = host; -// } -} diff --git a/src/main/java/com/loafle/overflow/central/module/probe/model/ProbeHost.java b/src/main/java/com/loafle/overflow/central/module/probe/model/ProbeHost.java deleted file mode 100644 index 7746473..0000000 --- a/src/main/java/com/loafle/overflow/central/module/probe/model/ProbeHost.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.loafle.overflow.central.module.probe.model; - -import com.loafle.overflow.central.module.infra.model.InfraHost; - -import javax.persistence.*; - -/** - * Created by insanity on 17. 8. 21. - */ - -@Entity -@Table(name = "PROBE_INFRAHOST", schema = "public") -public class ProbeHost { - - private long id; - private Probe probe; - private InfraHost host; - - @Id - @GeneratedValue(strategy= GenerationType.IDENTITY) - public long getId() { - return id; - } - - public void setId(long id) { - this.id = id; - } - - @OneToOne - @JoinColumn(name = "PROBE_ID", nullable = false) - public Probe getProbe() { - return probe; - } - - public void setProbe(Probe probe) { - this.probe = probe; - } - - @OneToOne - @JoinColumn(name = "HOST_ID", nullable = false) - public InfraHost getHost() { - return host; - } - - public void setHost(InfraHost infraHost) { - this.host = infraHost; - } -} diff --git a/src/main/java/com/loafle/overflow/central/module/probe/model/ProbeTask.java b/src/main/java/com/loafle/overflow/central/module/probe/model/ProbeTask.java deleted file mode 100644 index ad2533e..0000000 --- a/src/main/java/com/loafle/overflow/central/module/probe/model/ProbeTask.java +++ /dev/null @@ -1,143 +0,0 @@ -package com.loafle.overflow.central.module.probe.model; - - -import com.loafle.overflow.central.module.meta.model.MetaProbeTaskType; - -import javax.persistence.*; -import java.util.Date; - -/** - * Created by root on 17. 6. 22. - */ -@Entity -@Table(name = "PROBE_TASK", schema = "public") -public class ProbeTask { - private long id; - private MetaProbeTaskType taskType; - private Probe probe; - private String data; - private Date createDate; - private Date sendDate; - private Date startDate; - private Date endDate; - private Boolean succeed; - - @Id - @GeneratedValue(strategy= GenerationType.IDENTITY) - public long getId() { - return id; - } - - public void setId(long id) { - this.id = id; - } - - @ManyToOne - @JoinColumn(name = "TYPE_ID", nullable = false) - public MetaProbeTaskType getTaskType() { - return taskType; - } - - public void setTaskType(MetaProbeTaskType taskType) { - this.taskType = taskType; - } - - @ManyToOne - @JoinColumn(name = "PROBE_ID", nullable = false) - public Probe getProbe() { - return probe; - } - - public void setProbe(Probe probe) { - this.probe = probe; - } - - @Column(name = "DATA", nullable = true, length = 255) - public String getData() { - return data; - } - - public void setData(String data) { - this.data = data; - } - - @Temporal(TemporalType.TIMESTAMP) - @Column(name = "CREATE_DATE", nullable = false, columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", insertable = false, updatable = false) - public Date getCreateDate() { - return createDate; - } - - public void setCreateDate(Date createDate) { - this.createDate = createDate; - } - - @Column(name = "SEND_DATE", nullable = true) - public Date getSendDate() { - return sendDate; - } - - public void setSendDate(Date sendDate) { - this.sendDate = sendDate; - } - - @Column(name = "START_DATE", nullable = true) - public Date getStartDate() { - return startDate; - } - - public void setStartDate(Date startDate) { - this.startDate = startDate; - } - - @Column(name = "END_DATE", nullable = true) - public Date getEndDate() { - return endDate; - } - - public void setEndDate(Date endDate) { - this.endDate = endDate; - } - - @Column(name = "SUCCEED", nullable = true) - public Boolean getSucceed() { - return succeed; - } - - public void setSucceed(Boolean succeed) { - this.succeed = succeed; - } - -// @Override -// public boolean equals(Object o) { -// if (this == o) return true; -// if (o == null || getClass() != o.getClass()) return false; -// -// ProbeTask that = (ProbeTask) o; -// -// if (id != that.id) return false; -// if (typeId != that.typeId) return false; -// if (probeId != that.probeId) return false; -// if (data != null ? !data.equals(that.data) : that.data != null) return false; -// if (createDate != null ? !createDate.equals(that.createDate) : that.createDate != null) return false; -// if (sendDate != null ? !sendDate.equals(that.sendDate) : that.sendDate != null) return false; -// if (startDate != null ? !startDate.equals(that.startDate) : that.startDate != null) return false; -// if (endDate != null ? !endDate.equals(that.endDate) : that.endDate != null) return false; -// if (succeed != null ? !succeed.equals(that.succeed) : that.succeed != null) return false; -// -// return true; -// } -// -// @Override -// public int hashCode() { -// int result = (int) (id ^ (id >>> 32)); -// result = 31 * result + (int) typeId; -// result = 31 * result + (int) (probeId ^ (probeId >>> 32)); -// result = 31 * result + (data != null ? data.hashCode() : 0); -// result = 31 * result + (createDate != null ? createDate.hashCode() : 0); -// result = 31 * result + (sendDate != null ? sendDate.hashCode() : 0); -// result = 31 * result + (startDate != null ? startDate.hashCode() : 0); -// result = 31 * result + (endDate != null ? endDate.hashCode() : 0); -// result = 31 * result + (succeed != null ? succeed.hashCode() : 0); -// return result; -// } -} diff --git a/src/main/java/com/loafle/overflow/central/module/probe/service/ProbeHostService.java b/src/main/java/com/loafle/overflow/central/module/probe/service/CentralProbeHostService.java similarity index 52% rename from src/main/java/com/loafle/overflow/central/module/probe/service/ProbeHostService.java rename to src/main/java/com/loafle/overflow/central/module/probe/service/CentralProbeHostService.java index 1a48c23..0e468e4 100644 --- a/src/main/java/com/loafle/overflow/central/module/probe/service/ProbeHostService.java +++ b/src/main/java/com/loafle/overflow/central/module/probe/service/CentralProbeHostService.java @@ -1,8 +1,11 @@ package com.loafle.overflow.central.module.probe.service; import com.loafle.overflow.central.module.probe.dao.ProbeHostDAO; -import com.loafle.overflow.central.module.probe.model.Probe; -import com.loafle.overflow.central.module.probe.model.ProbeHost; +import com.loafle.overflow.core.exception.OverflowException; +import com.loafle.overflow.model.probe.Probe; +import com.loafle.overflow.model.probe.ProbeHost; +import com.loafle.overflow.service.central.probe.ProbeHostService; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -10,16 +13,16 @@ import org.springframework.stereotype.Service; * Created by snoop on 17. 8. 21. */ @Service("ProbeHostService") -public class ProbeHostService { +public class CentralProbeHostService implements ProbeHostService { @Autowired private ProbeHostDAO probeHostDAO; - public ProbeHost readByProbe(Probe probe) { + public ProbeHost readByProbe(Probe probe) throws OverflowException { return this.probeHostDAO.findByProbe(probe); } - public ProbeHost regist(ProbeHost probeHost) { + public ProbeHost regist(ProbeHost probeHost) throws OverflowException { return this.probeHostDAO.save(probeHost); } } diff --git a/src/main/java/com/loafle/overflow/central/module/probe/service/CentralProbeService.java b/src/main/java/com/loafle/overflow/central/module/probe/service/CentralProbeService.java new file mode 100644 index 0000000..a63f2e8 --- /dev/null +++ b/src/main/java/com/loafle/overflow/central/module/probe/service/CentralProbeService.java @@ -0,0 +1,47 @@ +package com.loafle.overflow.central.module.probe.service; + +import com.loafle.overflow.central.module.probe.dao.ProbeDAO; +import com.loafle.overflow.core.exception.OverflowException; +import com.loafle.overflow.model.domain.Domain; +import com.loafle.overflow.model.probe.Probe; +import com.loafle.overflow.service.central.probe.ProbeService; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * Created by snoop on 17. 6. 28. + */ +@Service("ProbeService") +public class CentralProbeService implements ProbeService { + + @Autowired + private ProbeDAO probeDAO; + + public Probe regist(Probe probe) throws OverflowException { + return this.probeDAO.save(probe); + } + + public List regist(List probes) throws OverflowException { + return this.probeDAO.save(probes); + } + + public List readAllByDomain(Domain domain) throws OverflowException { + List probes = this.probeDAO.findAllByDomainOrderByIdDesc(domain); + return probes; + } + + public Probe read(long id) throws OverflowException { + return this.probeDAO.findOne(id); + } + + public Probe readByProbeKey(String probeKey) throws OverflowException { + return this.probeDAO.findByProbeKey(probeKey); + } + + public Probe modify(Probe probe) throws OverflowException { + return this.probeDAO.save(probe); + } +} diff --git a/src/main/java/com/loafle/overflow/central/module/probe/service/ProbeTaskService.java b/src/main/java/com/loafle/overflow/central/module/probe/service/CentralProbeTaskService.java similarity index 53% rename from src/main/java/com/loafle/overflow/central/module/probe/service/ProbeTaskService.java rename to src/main/java/com/loafle/overflow/central/module/probe/service/CentralProbeTaskService.java index 51bee6f..9c60ab2 100644 --- a/src/main/java/com/loafle/overflow/central/module/probe/service/ProbeTaskService.java +++ b/src/main/java/com/loafle/overflow/central/module/probe/service/CentralProbeTaskService.java @@ -1,8 +1,11 @@ package com.loafle.overflow.central.module.probe.service; import com.loafle.overflow.central.module.probe.dao.ProbeTaskDAO; -import com.loafle.overflow.central.module.probe.model.Probe; -import com.loafle.overflow.central.module.probe.model.ProbeTask; +import com.loafle.overflow.core.exception.OverflowException; +import com.loafle.overflow.model.probe.Probe; +import com.loafle.overflow.model.probe.ProbeTask; +import com.loafle.overflow.service.central.probe.ProbeTaskService; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -12,16 +15,16 @@ import java.util.List; * Created by snoop on 17. 6. 28. */ @Service("ProbeTaskService") -public class ProbeTaskService { +public class CentralProbeTaskService implements ProbeTaskService{ @Autowired private ProbeTaskDAO probeTaskDAO; - public ProbeTask regist(ProbeTask probeTask) { + public ProbeTask regist(ProbeTask probeTask) throws OverflowException { return this.probeTaskDAO.save(probeTask); } - public List readAllByProbe(Probe probe) { + public List readAllByProbe(Probe probe) throws OverflowException { return this.probeTaskDAO.findAllByProbe(probe); } } diff --git a/src/main/java/com/loafle/overflow/central/module/probe/service/ProbeService.java b/src/main/java/com/loafle/overflow/central/module/probe/service/ProbeService.java deleted file mode 100644 index 3f21543..0000000 --- a/src/main/java/com/loafle/overflow/central/module/probe/service/ProbeService.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.loafle.overflow.central.module.probe.service; - -import com.loafle.overflow.central.module.domain.model.Domain; -import com.loafle.overflow.central.module.infra.dao.InfraDAO; -import com.loafle.overflow.central.module.probe.dao.ProbeDAO; -import com.loafle.overflow.central.module.probe.model.Probe; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -import java.util.List; - -/** - * Created by snoop on 17. 6. 28. - */ -@Service("ProbeService") -public class ProbeService { - - @Autowired - private ProbeDAO probeDAO; - @Autowired - private InfraDAO infraDAO; - - public Probe regist(Probe probe) { - return this.probeDAO.save(probe); - } - - public List regist(List probes) { - return this.probeDAO.save(probes); - } - - public List readAllByDomain(Domain domain) { - List probes = this.probeDAO.findAllByDomainOrderByIdDesc(domain); - for(Probe probe : probes) { - probe.setTargets(this.infraDAO.findAllByProbe(probe)); - } - return probes; - } - - public Probe read(long id) { - Probe probe = this.probeDAO.findOne(id); - probe.setTargets(this.infraDAO.findAllByProbe(probe)); - return probe; - } - - public Probe readByProbeKey(String probeKey) { - - return this.probeDAO.findByProbeKey(probeKey); - } - - public Probe modify(Probe probe) { - return this.probeDAO.save(probe); - } -} diff --git a/src/main/java/com/loafle/overflow/central/module/sensor/dao/SensorDAO.java b/src/main/java/com/loafle/overflow/central/module/sensor/dao/SensorDAO.java index 235a7fd..998ca3f 100644 --- a/src/main/java/com/loafle/overflow/central/module/sensor/dao/SensorDAO.java +++ b/src/main/java/com/loafle/overflow/central/module/sensor/dao/SensorDAO.java @@ -1,8 +1,6 @@ package com.loafle.overflow.central.module.sensor.dao; -import com.loafle.overflow.central.module.sensor.model.Sensor; -import com.loafle.overflow.central.module.target.model.Target; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; @@ -12,18 +10,18 @@ import org.springframework.stereotype.Repository; import java.util.List; +import com.loafle.overflow.model.sensor.Sensor; +import com.loafle.overflow.model.target.Target; + /** * Created by root on 17. 6. 9. */ @Repository public interface SensorDAO extends JpaRepository { - Page findAllByTarget(Target target, Pageable pageable); List findAllByTarget(Target target); @Query("SELECT s from Sensor s WHERE s.target in (:targetList)") Page findAllByTargetList(@Param("targetList") List targetList, Pageable pageable); -// List findAllByTargetList(List targets); - } diff --git a/src/main/java/com/loafle/overflow/central/module/sensor/dao/SensorItemDAO.java b/src/main/java/com/loafle/overflow/central/module/sensor/dao/SensorItemDAO.java index b9d847c..594c227 100644 --- a/src/main/java/com/loafle/overflow/central/module/sensor/dao/SensorItemDAO.java +++ b/src/main/java/com/loafle/overflow/central/module/sensor/dao/SensorItemDAO.java @@ -1,7 +1,8 @@ package com.loafle.overflow.central.module.sensor.dao; -import com.loafle.overflow.central.module.sensor.model.Sensor; -import com.loafle.overflow.central.module.sensor.model.SensorItem; +import com.loafle.overflow.model.sensor.Sensor; +import com.loafle.overflow.model.sensor.SensorItem; + import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; diff --git a/src/main/java/com/loafle/overflow/central/module/sensor/dao/SensorItemDependencyDAO.java b/src/main/java/com/loafle/overflow/central/module/sensor/dao/SensorItemDependencyDAO.java index 797a307..aa62f75 100644 --- a/src/main/java/com/loafle/overflow/central/module/sensor/dao/SensorItemDependencyDAO.java +++ b/src/main/java/com/loafle/overflow/central/module/sensor/dao/SensorItemDependencyDAO.java @@ -2,7 +2,8 @@ package com.loafle.overflow.central.module.sensor.dao; import com.loafle.overflow.central.module.meta.model.MetaSensorDisplayItem; import com.loafle.overflow.central.module.meta.model.MetaSensorItemKey; -import com.loafle.overflow.central.module.sensor.model.SensorItemDependency; +import com.loafle.overflow.model.sensor.SensorItemDependency; + import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; diff --git a/src/main/java/com/loafle/overflow/central/module/sensor/model/Sensor.java b/src/main/java/com/loafle/overflow/central/module/sensor/model/Sensor.java deleted file mode 100644 index ec2e376..0000000 --- a/src/main/java/com/loafle/overflow/central/module/sensor/model/Sensor.java +++ /dev/null @@ -1,104 +0,0 @@ -package com.loafle.overflow.central.module.sensor.model; - -import com.loafle.overflow.central.module.meta.model.MetaCrawler; -import com.loafle.overflow.central.module.meta.model.MetaSensorStatus; -import com.loafle.overflow.central.module.target.model.Target; -import org.hibernate.annotations.OnDelete; -import org.hibernate.annotations.OnDeleteAction; - -import javax.persistence.*; -import java.util.Date; - -/** - * Created by root on 17. 6. 22. - */ -@Entity -@Table(name = "SENSOR", schema = "public") -public class Sensor { - private long id; - private Date createDate; - private String description; - private MetaSensorStatus status; - private Target target; - private MetaCrawler crawler; - private String crawlerInputItems; - private short itemCount = 0; - - @Id - @GeneratedValue(strategy= GenerationType.IDENTITY) - public long getId() { - return id; - } - - public void setId(long id) { - this.id = id; - } - - @Temporal(TemporalType.TIMESTAMP) - @Column(name = "CREATE_DATE", nullable = false, columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", insertable = false, updatable = false) - public Date getCreateDate() { - return createDate; - } - - public void setCreateDate(Date createDate) { - this.createDate = createDate; - } - - @Column(name = "DESCRIPTION", nullable = true, length = 50) - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - @ManyToOne - @JoinColumn(name = "STATUS") - public MetaSensorStatus getStatus() { - return status; - } - - public void setStatus(MetaSensorStatus status) { - this.status = status; - } - - @ManyToOne - @OnDelete(action = OnDeleteAction.CASCADE) - @JoinColumn(name = "TARGET_ID", nullable = false) - public Target getTarget() { - return target; - } - - public void setTarget(Target target) { - this.target = target; - } - - @ManyToOne - @JoinColumn(name = "CRAWLER_ID", nullable = false) - public MetaCrawler getCrawler() { - return crawler; - } - - public void setCrawler(MetaCrawler crawler) { - this.crawler = crawler; - } - - @Column(name = "CRAWLER_INPUT_ITEMS", nullable = true, length = 50) - public String getCrawlerInputItems() { - return crawlerInputItems; - } - - public void setCrawlerInputItems(String crawlerInputItems) { - this.crawlerInputItems = crawlerInputItems; - } - - @Column(name = "ITEM_COUNT", nullable = false) - public short getItemCount() { - return itemCount; - } - - public void setItemCount(short itemCount) { - this.itemCount = itemCount; - } -} diff --git a/src/main/java/com/loafle/overflow/central/module/sensor/model/SensorItem.java b/src/main/java/com/loafle/overflow/central/module/sensor/model/SensorItem.java deleted file mode 100644 index 278d0d6..0000000 --- a/src/main/java/com/loafle/overflow/central/module/sensor/model/SensorItem.java +++ /dev/null @@ -1,62 +0,0 @@ -package com.loafle.overflow.central.module.sensor.model; - -import com.loafle.overflow.central.module.meta.model.MetaSensorDisplayItem; -import org.hibernate.annotations.OnDelete; -import org.hibernate.annotations.OnDeleteAction; - -import javax.persistence.*; -import java.util.Date; - -/** - * Created by root on 17. 6. 22. - */ -@Entity -@Table(name = "SENSOR_ITEM", schema = "public") -public class SensorItem { - private long id; - private Sensor sensor; - private MetaSensorDisplayItem item; - private Date createDate; - - @Id - @GeneratedValue(strategy= GenerationType.IDENTITY) - public long getId() { - return id; - } - - public void setId(long id) { - this.id = id; - } - - @ManyToOne - @JoinColumn(name = "SENSOR_ID", nullable = false) - @OnDelete(action = OnDeleteAction.CASCADE) - public Sensor getSensor() { - return this.sensor; - } - - public void setSensor(Sensor sensor) { - this.sensor = sensor; - } - - @ManyToOne - @JoinColumn(name = "ITEM_ID", nullable = false) - public MetaSensorDisplayItem getItem() { - return item; - } - - public void setItem(MetaSensorDisplayItem item) { - this.item = item; - } - - @Temporal(TemporalType.TIMESTAMP) - @Column(name = "CREATE_DATE", nullable = false, columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", insertable = false, updatable = false) - public Date getCreateDate() { - return createDate; - } - - public void setCreateDate(Date createDate) { - this.createDate = createDate; - } - -} diff --git a/src/main/java/com/loafle/overflow/central/module/sensor/model/SensorItemDependency.java b/src/main/java/com/loafle/overflow/central/module/sensor/model/SensorItemDependency.java deleted file mode 100644 index 9f077f3..0000000 --- a/src/main/java/com/loafle/overflow/central/module/sensor/model/SensorItemDependency.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.loafle.overflow.central.module.sensor.model; - -import com.loafle.overflow.central.module.meta.model.MetaSensorDisplayItem; -import com.loafle.overflow.central.module.meta.model.MetaSensorItemKey; - -import javax.persistence.*; - -/** - * Created by insanity on 17. 9. 20. - */ -@Entity -@Table(name = "SENSOR_ITEM_DEPENDENCY", schema = "public") -public class SensorItemDependency { - private long id; - private MetaSensorDisplayItem displayItem; - private MetaSensorItemKey sensorItem; - - @Id - @GeneratedValue(strategy= GenerationType.IDENTITY) - public long getId() { - return id; - } - - public void setId(long id) { - this.id = id; - } - - - @ManyToOne - @JoinColumn(name = "DISPLAY_ITEM_ID", nullable = false) - public MetaSensorDisplayItem getDisplayItem() { - return displayItem; - } - - public void setDisplayItem(MetaSensorDisplayItem displayItem) { - this.displayItem = displayItem; - } - - @ManyToOne - @JoinColumn(name = "SENSOR_ITEM_ID", nullable = false) - public MetaSensorItemKey getSensorItem() { - return sensorItem; - } - - public void setSensorItem(MetaSensorItemKey sensorItem) { - this.sensorItem = sensorItem; - } -} diff --git a/src/main/java/com/loafle/overflow/central/module/sensor/service/SensorItemDependencyService.java b/src/main/java/com/loafle/overflow/central/module/sensor/service/CentralSensorItemDependencyService.java similarity index 92% rename from src/main/java/com/loafle/overflow/central/module/sensor/service/SensorItemDependencyService.java rename to src/main/java/com/loafle/overflow/central/module/sensor/service/CentralSensorItemDependencyService.java index 646b793..5629e92 100644 --- a/src/main/java/com/loafle/overflow/central/module/sensor/service/SensorItemDependencyService.java +++ b/src/main/java/com/loafle/overflow/central/module/sensor/service/CentralSensorItemDependencyService.java @@ -3,7 +3,8 @@ package com.loafle.overflow.central.module.sensor.service; import com.loafle.overflow.central.module.meta.model.MetaSensorDisplayItem; import com.loafle.overflow.central.module.meta.model.MetaSensorItemKey; import com.loafle.overflow.central.module.sensor.dao.SensorItemDependencyDAO; -import com.loafle.overflow.central.module.sensor.model.SensorItemDependency; +import com.loafle.overflow.model.sensor.SensorItemDependency; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -16,7 +17,7 @@ import java.util.Map; */ @Service("SensorItemDependencyService") -public class SensorItemDependencyService { +public class CentralSensorItemDependencyService { @Autowired private SensorItemDependencyDAO sensorItemDependencyDAO; diff --git a/src/main/java/com/loafle/overflow/central/module/sensor/service/SensorItemService.java b/src/main/java/com/loafle/overflow/central/module/sensor/service/CentralSensorItemService.java similarity index 83% rename from src/main/java/com/loafle/overflow/central/module/sensor/service/SensorItemService.java rename to src/main/java/com/loafle/overflow/central/module/sensor/service/CentralSensorItemService.java index a3ed86e..7f49f4c 100644 --- a/src/main/java/com/loafle/overflow/central/module/sensor/service/SensorItemService.java +++ b/src/main/java/com/loafle/overflow/central/module/sensor/service/CentralSensorItemService.java @@ -4,8 +4,9 @@ import com.loafle.overflow.central.commons.model.PageParams; import com.loafle.overflow.central.commons.utils.PageUtil; import com.loafle.overflow.central.module.sensor.dao.SensorDAO; import com.loafle.overflow.central.module.sensor.dao.SensorItemDAO; -import com.loafle.overflow.central.module.sensor.model.Sensor; -import com.loafle.overflow.central.module.sensor.model.SensorItem; +import com.loafle.overflow.model.sensor.Sensor; +import com.loafle.overflow.model.sensor.SensorItem; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.stereotype.Service; @@ -17,7 +18,7 @@ import java.util.List; * Created by insanity on 17. 6. 28. */ @Service("SensorItemService") -public class SensorItemService { +public class CentralSensorItemService { @Autowired private SensorItemDAO sensorItemDAO; @@ -27,7 +28,7 @@ public class SensorItemService { @Transactional public SensorItem regist(SensorItem sensorItem) { Sensor s = sensorDAO.findOne(sensorItem.getSensor().getId()); - s.setItemCount((short)(s.getItemCount() + 1)); + // s.setItemCount((short)(s.getItemCount() + 1)); this.sensorDAO.save(s); return this.sensorItemDAO.save(sensorItem); } @@ -35,7 +36,7 @@ public class SensorItemService { @Transactional public boolean registAll(List sensorItemList) { Sensor s = sensorDAO.findOne(sensorItemList.get(0).getSensor().getId()); - s.setItemCount((short)sensorItemList.size()); + // s.setItemCount((short)sensorItemList.size()); this.sensorDAO.save(s); this.sensorItemDAO.save(sensorItemList); return true; @@ -52,7 +53,7 @@ public class SensorItemService { @Transactional public void remove(SensorItem sensorItem) { Sensor s = sensorItem.getSensor(); - s.setItemCount((short)(s.getItemCount() - 1)); + // s.setItemCount((short)(s.getItemCount() - 1)); this.sensorDAO.save(s); this.sensorItemDAO.delete(sensorItem); } diff --git a/src/main/java/com/loafle/overflow/central/module/sensor/service/SensorService.java b/src/main/java/com/loafle/overflow/central/module/sensor/service/CentralSensorService.java similarity index 61% rename from src/main/java/com/loafle/overflow/central/module/sensor/service/SensorService.java rename to src/main/java/com/loafle/overflow/central/module/sensor/service/CentralSensorService.java index 18ef432..0df4a99 100644 --- a/src/main/java/com/loafle/overflow/central/module/sensor/service/SensorService.java +++ b/src/main/java/com/loafle/overflow/central/module/sensor/service/CentralSensorService.java @@ -2,21 +2,24 @@ package com.loafle.overflow.central.module.sensor.service; import com.loafle.overflow.central.commons.model.PageParams; import com.loafle.overflow.central.commons.utils.PageUtil; -import com.loafle.overflow.central.module.domain.model.Domain; import com.loafle.overflow.central.module.generator.service.SensorConfigGenerator; import com.loafle.overflow.central.module.infra.exception.InfraNotFoundException; -import com.loafle.overflow.central.module.infra.model.Infra; import com.loafle.overflow.central.module.infra.service.InfraService; -import com.loafle.overflow.central.module.meta.model.MetaSensorStatus; import com.loafle.overflow.central.module.meta.service.MetaSensorItemKeyService; import com.loafle.overflow.central.module.probe.exception.ProbeNotFoundException; -import com.loafle.overflow.central.module.probe.model.Probe; -import com.loafle.overflow.central.module.probe.service.ProbeService; import com.loafle.overflow.central.module.sensor.dao.SensorDAO; -import com.loafle.overflow.central.module.sensor.model.Sensor; -import com.loafle.overflow.central.module.sensor.model.SensorItem; import com.loafle.overflow.central.module.target.exception.TargetNotFoundException; -import com.loafle.overflow.central.module.target.model.Target; +import com.loafle.overflow.core.exception.OverflowException; +import com.loafle.overflow.model.domain.Domain; +import com.loafle.overflow.model.infra.Infra; +import com.loafle.overflow.model.meta.MetaSensorStatus; +import com.loafle.overflow.model.probe.Probe; +import com.loafle.overflow.model.sensor.Sensor; +import com.loafle.overflow.model.sensor.SensorItem; +import com.loafle.overflow.model.target.Target; +import com.loafle.overflow.service.central.probe.ProbeService; +import com.loafle.overflow.service.central.sensor.SensorService; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.stereotype.Service; @@ -29,7 +32,7 @@ import java.util.List; * Created by insanity on 17. 6. 28. */ @Service("SensorService") -public class SensorService { +public class CentralSensorService implements SensorService { @Autowired SensorDAO sensorDAO; @@ -41,10 +44,7 @@ public class SensorService { private InfraService infraService; @Autowired - private SensorItemService sensorItemService; - - @Autowired - private MetaSensorItemKeyService metaSensorItemKeyService; + private CentralSensorItemService sensorItemService; @Autowired private SensorConfigGenerator sensorConfigGenerator; @@ -53,67 +53,63 @@ public class SensorService { return this.sensorDAO.save(sensor); } -// public List readAllByTarget(Target target, PageParams pageParams) { -// return this.sensorDAO.findAllByTarget(target, PageUtil.getPageRequest(pageParams)); -// } - - public Page readAllByDomain(Domain domain, PageParams pageParams) { + public Page readAllByDomain(Domain domain, PageParams pageParams) throws OverflowException { List probeList = this.probeService.readAllByDomain(domain); - if(probeList == null || probeList.size() <= 0) { + if (probeList == null || probeList.size() <= 0) { throw new ProbeNotFoundException(); } List targetList = this.infraService.readAllTargetByProbeList(probeList); - if(targetList == null || targetList.size() <= 0) { + if (targetList == null || targetList.size() <= 0) { throw new TargetNotFoundException(); } return this.sensorDAO.findAllByTargetList(targetList, PageUtil.getPageRequest(pageParams)); } - public Page readAllByInfra(long infraId, PageParams pageParams) { + public Page readAllByInfra(long infraId, PageParams pageParams) throws OverflowException { Infra dbInfra = this.infraService.read(infraId); - if(dbInfra == null || dbInfra.getTarget() == null) { + if (dbInfra == null || dbInfra.getTarget() == null) { throw new InfraNotFoundException(); } return this.sensorDAO.findAllByTarget(dbInfra.getTarget(), PageUtil.getPageRequest(pageParams)); } - public Page readAllByTarget(Target target, PageParams pageParams) { + public Page readAllByTarget(Target target, PageParams pageParams) throws OverflowException { return this.sensorDAO.findAllByTarget(target, PageUtil.getPageRequest(pageParams)); } - public Sensor read(String id) { + public Sensor read(String id) throws OverflowException { return this.sensorDAO.findOne(Long.valueOf(id)); } - public void remove(Sensor sensor) { + public void remove(Sensor sensor) throws OverflowException { this.sensorDAO.delete(sensor); } - public Sensor start(Sensor sensor) { - MetaSensorStatus status = new MetaSensorStatus((short)1); + public Sensor start(Sensor sensor) throws OverflowException { + MetaSensorStatus status = new MetaSensorStatus((short) 1); sensor.setStatus(status); return this.sensorDAO.save(sensor); } - public Sensor stop(Sensor sensor) { - MetaSensorStatus status = new MetaSensorStatus((short)2); + public Sensor stop(Sensor sensor) throws OverflowException { + MetaSensorStatus status = new MetaSensorStatus((short) 2); sensor.setStatus(status); return this.sensorDAO.save(sensor); } @Transactional - public Sensor registSensorConfig(Sensor sensor, List sensorItemList, String etcJson) { + public Sensor registSensorConfig(Sensor sensor, List sensorItemList, String etcJson) throws OverflowException { this.sensorDAO.save(sensor); - for(SensorItem sensorItem : sensorItemList) { + for (SensorItem sensorItem : sensorItemList) { sensorItem.setSensor(sensor); } @@ -122,10 +118,13 @@ public class SensorService { return sensor; } - public String generateSensorConfig(Sensor sensor) throws IOException { + public String generateSensorConfig(Sensor sensor) throws OverflowException { - return this.sensorConfigGenerator.generate(sensor); + return this.sensorConfigGenerator.generate(sensor); } + // public List readAllByTarget(Target target, PageParams pageParams) { + // return this.sensorDAO.findAllByTarget(target, PageUtil.getPageRequest(pageParams)); + // } } diff --git a/src/main/java/com/loafle/overflow/central/module/target/dao/TargetDAO.java b/src/main/java/com/loafle/overflow/central/module/target/dao/TargetDAO.java index 1aa85c0..59da4a3 100644 --- a/src/main/java/com/loafle/overflow/central/module/target/dao/TargetDAO.java +++ b/src/main/java/com/loafle/overflow/central/module/target/dao/TargetDAO.java @@ -1,22 +1,12 @@ package com.loafle.overflow.central.module.target.dao; -import com.loafle.overflow.central.module.infra.model.Infra; -import com.loafle.overflow.central.module.probe.model.Probe; -import com.loafle.overflow.central.module.target.model.Target; +import com.loafle.overflow.model.target.Target; import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; -import java.util.List; - - /** * Created by root on 17. 6. 5. */ @Repository public interface TargetDAO extends JpaRepository { -// List findAllByProbe(Probe probe);] - - } diff --git a/src/main/java/com/loafle/overflow/central/module/target/exception/TargetNotFoundException.java b/src/main/java/com/loafle/overflow/central/module/target/exception/TargetNotFoundException.java index 3bfe1b4..f09d820 100644 --- a/src/main/java/com/loafle/overflow/central/module/target/exception/TargetNotFoundException.java +++ b/src/main/java/com/loafle/overflow/central/module/target/exception/TargetNotFoundException.java @@ -6,7 +6,9 @@ import com.loafle.overflow.central.commons.exception.OverflowRuntimeException; * Created by snoop on 17. 9. 14. */ public class TargetNotFoundException extends OverflowRuntimeException { - public TargetNotFoundException() { + private static final long serialVersionUID = 1L; + + public TargetNotFoundException() { super(); } diff --git a/src/main/java/com/loafle/overflow/central/module/target/model/Target.java b/src/main/java/com/loafle/overflow/central/module/target/model/Target.java deleted file mode 100644 index 871af7d..0000000 --- a/src/main/java/com/loafle/overflow/central/module/target/model/Target.java +++ /dev/null @@ -1,98 +0,0 @@ -package com.loafle.overflow.central.module.target.model; - -import com.loafle.overflow.central.module.sensor.model.Sensor; - -import javax.persistence.*; -import java.util.Date; -import java.util.List; - -/** - * Created by root on 17. 6. 22. - */ -@Entity -@Table(name = "TARGET", schema = "public") -public class Target { - - private long id; - private Date createDate; - private String displayName; - private String description; - - private List sensors; - - /* - private long id; - private Date createDate; - private String displayName; - private String description; - */ - - @Id - @GeneratedValue(strategy= GenerationType.IDENTITY) - public long getId() { - return id; - } - - public void setId(long id) { - this.id = id; - } - - @Temporal(TemporalType.TIMESTAMP) - @Column(name = "CREATE_DATE", nullable = false, columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", insertable = false, updatable = false) - public Date getCreateDate() { - return createDate; - } - - public void setCreateDate(Date createDate) { - this.createDate = createDate; - } - - @Column(name = "DISPLAY_NAME") - public String getDisplayName() { - return displayName; - } - - public void setDisplayName(String displayName) { - this.displayName = displayName; - } - - @Column(name = "DESCRIPTION") - public String getDescription() { - return description; - } - - 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; -// } - - @Transient - public List getSensors() { - return sensors; - } - - public void setSensors(List sensors) { - this.sensors = sensors; - } -} diff --git a/src/main/java/com/loafle/overflow/central/module/target/service/CentralTargetDiscoveryService.java b/src/main/java/com/loafle/overflow/central/module/target/service/CentralTargetDiscoveryService.java new file mode 100644 index 0000000..1819eb3 --- /dev/null +++ b/src/main/java/com/loafle/overflow/central/module/target/service/CentralTargetDiscoveryService.java @@ -0,0 +1,220 @@ +package com.loafle.overflow.central.module.target.service; + +import com.loafle.overflow.central.commons.utils.StringConvertor; +import com.loafle.overflow.central.module.discovery.model.Host; +import com.loafle.overflow.central.module.discovery.model.Port; +import com.loafle.overflow.central.module.discovery.type.PortType; +import com.loafle.overflow.central.module.infra.model.*; +import com.loafle.overflow.central.module.infra.model.InfraService; +import com.loafle.overflow.central.module.infra.service.*; +import com.loafle.overflow.central.module.meta.model.MetaInfraType; +import com.loafle.overflow.central.module.meta.model.MetaInfraVendor; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import javax.transaction.Transactional; +import java.util.List; + +/** + * Created by snoop on 17. 6. 28. + */ +@Service("TargetDiscoveryService") +public class CentralTargetDiscoveryService { + + @Autowired + private CentralTargetService targetService; + + @Autowired + private InfraMachineService infraMachineService; + + @Autowired + private InfraOSService infraOSService; + + @Autowired + private InfraHostService infraHostService; + + @Autowired + private com.loafle.overflow.central.module.infra.service.InfraService infraService; + + @Autowired + private InfraOSPortService infraOSPortService; + + @Autowired + private InfraServiceService infraServiceService; + + // @Transactional + // public boolean saveAllTarget(List hosts, Probe probe) { + + // InfraHost infraHost = null; + + // for(Host host : hosts) { + + // infraHost = this.createAndReadHost(host, probe); + + // this.createPort(infraHost, host, probe); + + // } + // return true; + // } + + // private void createService(InfraHost infraHost, Port port, Probe probe) { + + // if(port.getServices() == null) { + // return; + // } + + // MetaInfraType typeService = new MetaInfraType(); + // typeService.setId(7); + + // String portType = "UDP"; + + // if(port.getPortType() == PortType.TLS || port.getPortType() == PortType.TCP) { + // portType = "TCP"; + // } + + // for(com.loafle.overflow.central.module.discovery.model.Service service : port.getServices()) { + + // InfraService dbInfraService = this.infraServiceService.readByService(infraHost.getId(), port.getPortNumber(), portType); + + // if(dbInfraService != null) { + // if(service.isTarget() && dbInfraService.getTarget() == null) { + // Target targetService = new Target(); + // targetService.setDisplayName(service.getServiceName() + "-Service"); + // this.targetService.regist(targetService); + // dbInfraService.setTarget(targetService); + // this.infraServiceService.regist(dbInfraService); + // } + // continue; + // } + + // InfraService infraService = new InfraService(); + // infraService.setHost(infraHost); + // infraService.setPort(port.getPortNumber()); + // infraService.setPortType(portType); + // infraService.setInfraType(typeService); + // infraService.setProbe(probe); + + // if (port.getPortType() == PortType.TLS) { + // infraService.setTlsType(true); + // } + // infraService.setVendor(MetaInfraVendor.CreateInfraVendorByService(service.getServiceName())); + + // if(service.isTarget()) { + // Target targetService = new Target(); + // targetService.setDisplayName(service.getServiceName() + "-Service"); + // this.targetService.regist(targetService); + // infraService.setTarget(targetService); + // } + + // this.infraServiceService.regist(infraService); + + // } + + // } + + // private void createPort(InfraHost infraHost, Host host, Probe probe) { + + // if(host.getPorts() == null) { + // return; + // } + + // String portType = "UDP"; + + // MetaInfraType typePort = new MetaInfraType(); + // typePort.setId(6); + + // InfraOS infraOS = infraHost.getOs(); + + // for(Port port : host.getPorts()) { + + // if(port.getPortType() == PortType.TLS || port.getPortType() == PortType.TCP) { + // portType = "TCP"; + // } + + // InfraOSPort dbInfraOSPort = this.infraOSPortService.readByPort(infraOS.getId(), port.getPortNumber(), portType); + // if(dbInfraOSPort == null) { + // InfraOSPort infraOSPort = new InfraOSPort(); + // infraOSPort.setOs(infraOS); + // infraOSPort.setPort(port.getPortNumber()); + // infraOSPort.setPortType(portType); + // infraOSPort.setProbe(probe); + // infraOSPort.setInfraType(typePort); + + // if (port.getPortType() == PortType.TLS) { + // infraOSPort.setTlsType(true); + // } + // infraOSPort.setVendor(MetaInfraVendor.CreateInfraVendorByPort(port.getPortNumber())); + // this.infraOSPortService.regist(infraOSPort); + // } + + // this.createService(infraHost, port, probe); + // } + // } + + // private InfraHost createAndReadHost(Host host, Probe probe) { + + // InfraHost infraHost = this.infraHostService.readByIp(host.getIp()); + // if(infraHost != null) { + + // if(host.isTarget() && infraHost.getTarget() == null) { + // Target target = new Target(); + // target.setDisplayName(String.valueOf(host.getIp()) + "-Host"); + + // this.targetService.regist(target); + // infraHost.setTarget(target); + // this.infraHostService.regist(infraHost); + // } + + // return infraHost; + // } else { + // MetaInfraType typeMachine = new MetaInfraType(); + // typeMachine.setId(1); // 1 = Machine; + + // MetaInfraType typeOS = new MetaInfraType(); + // typeOS.setId(3); // 3 = Os + + // MetaInfraType typeHost = new MetaInfraType(); + // typeHost.setId(2); // 2 = Host + + // InfraMachine infraMachine = new InfraMachine(); + // infraMachine.setProbe(probe); + // infraMachine.setInfraType(typeMachine); + // infraMachine.setMeta(StringConvertor.intToIp(host.getIp())+"-MACHINE"); + // this.infraMachineService.regist(infraMachine); + + // InfraOS infraOS = new InfraOS(); + // infraOS.setMachine(infraMachine); + // infraOS.setVendor(MetaInfraVendor.CreateInfraVendorByOS(host.getOs())); + // infraOS.setInfraType(typeOS); + // infraOS.setProbe(probe); + // infraOS.setMeta(StringConvertor.intToIp(host.getIp())+"-OS"); + // this.infraOSService.regist(infraOS); + + // InfraHost newInfraHost = new InfraHost(); + // newInfraHost.setIp(host.getIp()); + // newInfraHost.setMac(host.getMac()); + // newInfraHost.setOs(infraOS); + // newInfraHost.setInfraType(typeHost); + // newInfraHost.setProbe(probe); + + // if(host.isTarget()) { + // Target target = new Target(); + // target.setDisplayName(StringConvertor.intToIp(host.getIp()) + "-Host"); + + // this.targetService.regist(target); + // newInfraHost.setTarget(target); + // } + + // this.infraHostService.regist(newInfraHost); + // infraHost = newInfraHost; + // } + + + + // return infraHost; + // } + + + + +} diff --git a/src/main/java/com/loafle/overflow/central/module/target/service/TargetService.java b/src/main/java/com/loafle/overflow/central/module/target/service/CentralTargetService.java similarity index 54% rename from src/main/java/com/loafle/overflow/central/module/target/service/TargetService.java rename to src/main/java/com/loafle/overflow/central/module/target/service/CentralTargetService.java index 256ed70..9b8e999 100644 --- a/src/main/java/com/loafle/overflow/central/module/target/service/TargetService.java +++ b/src/main/java/com/loafle/overflow/central/module/target/service/CentralTargetService.java @@ -1,36 +1,31 @@ package com.loafle.overflow.central.module.target.service; -import com.loafle.overflow.central.module.probe.model.Probe; import com.loafle.overflow.central.module.target.dao.TargetDAO; -import com.loafle.overflow.central.module.target.model.Target; +import com.loafle.overflow.core.exception.OverflowException; +import com.loafle.overflow.model.target.Target; +import com.loafle.overflow.service.central.target.TargetService; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import java.util.List; - /** * Created by insanity on 17. 6. 28. */ @Service("TargetService") -public class TargetService { +public class CentralTargetService implements TargetService { @Autowired private TargetDAO targetDAO; - public Target regist(Target target) { + public Target regist(Target target) throws OverflowException { return this.targetDAO.save(target); } - public Target read(String id) { + public Target read(String id) throws OverflowException { return this.targetDAO.findOne(Long.valueOf(id)); } -// public List readAllByProbe(Probe probe) { -// return this.targetDAO.findAllByProbe(probe); -// } - - public void remove(Target target) { + public void remove(Target target) throws OverflowException { this.targetDAO.delete(target); } - }