From 07ef365ad309d9708d34f196d060255de78506ad Mon Sep 17 00:00:00 2001 From: crusader Date: Tue, 5 Jun 2018 21:56:40 +0900 Subject: [PATCH] ing --- pom.xml | 27 +- .../commons/service/MessagePublisher.java | 15 +- .../apikey/service/CentralApiKeyService.java | 1 - .../module/auth/dao/AuthCrawlerDAO.java | 7 +- .../service/CentralAuthCrawlerService.java | 48 ++- .../service/CentralDiscoveryService.java | 7 + .../module/domain/dao/DomainMemberDAO.java | 14 +- .../service/CentralDomainMemberService.java | 30 +- .../domain/service/CentralDomainService.java | 10 +- .../module/email/dao/EmailAuthDAO.java | 5 +- .../email/service/EmailAuthService.java | 345 +++++++++--------- .../generator/service/GenerateUtil.java | 6 +- .../generator/service/InfraHostGenerator.java | 10 +- .../service/InfraServiceGenerator.java | 18 +- .../service/InfraServiceJMXGenerator.java | 2 +- .../service/SensorConfigGenerator.java | 6 +- .../module/history/dao/HistoryDAO.java | 10 +- .../service/CentralHistoryService.java | 15 +- .../central/module/infra/dao/InfraDAO.java | 11 +- .../module/infra/dao/InfraOSPortDAO.java | 6 +- .../module/infra/dao/InfraServiceDAO.java | 5 +- .../service/CentralInfraHostService.java | 5 +- .../CentralInfraOSApplicationService.java | 2 +- .../service/CentralInfraOSPortService.java | 5 +- .../infra/service/CentralInfraService.java | 19 +- .../service/CentralInfraServiceService.java | 5 +- .../central/module/member/dao/MemberDAO.java | 5 +- .../module/member/dao/MemberTotpDAO.java | 8 +- .../member/service/CentralMemberService.java | 12 +- .../service/CentralMemberTotpService.java | 4 +- .../meta/dao/MetaCrawlerInputItemDAO.java | 3 +- .../module/meta/dao/MetaInfraVendorDAO.java | 3 +- .../module/meta/dao/MetaProbePackageDAO.java | 3 +- .../meta/dao/MetaSensorDisplayItemDAO.java | 3 +- .../meta/dao/MetaSensorDisplayMappingDAO.java | 6 +- .../module/meta/dao/MetaSensorItemKeyDAO.java | 4 +- .../module/meta/dao/MetaVendorCrawlerDAO.java | 5 +- .../CentralMetaCrawlerInputItemService.java | 4 +- .../CentralMetaHistoryTypeService.java | 4 +- .../CentralMetaInfraVendorService.java | 5 +- .../CentralMetaProbePackageService.java | 4 +- .../CentralMetaSensorDisplayItemService.java | 4 +- ...entralMetaSensorDisplayMappingService.java | 4 +- .../CentralMetaSensorItemKeyService.java | 14 +- .../CentralMetaVendorCrawlerService.java | 4 +- .../noauthprobe/dao/NoAuthProbeDAO.java | 5 +- .../service/CentralNoAuthProbeService.java | 49 +-- .../notification/dao/NotificationDAO.java | 15 +- .../service/CentralNotificationService.java | 31 +- .../module/probe/dao/ProbeHostDAO.java | 6 +- .../module/probe/dao/ProbeTaskDAO.java | 2 +- .../service/CentralProbeHostService.java | 7 +- .../probe/service/CentralProbeService.java | 1 - .../service/CentralProbeTaskService.java | 1 - .../central/module/sensor/dao/SensorDAO.java | 7 +- .../module/sensor/dao/SensorItemDAO.java | 3 +- .../sensor/dao/SensorItemDependencyDAO.java | 3 +- .../CentralSensorItemDependencyService.java | 14 +- .../service/CentralSensorItemService.java | 10 +- .../sensor/service/CentralSensorService.java | 8 +- .../CentralTargetDiscoveryService.java | 102 +++--- .../target/service/CentralTargetService.java | 33 +- 62 files changed, 476 insertions(+), 554 deletions(-) diff --git a/pom.xml b/pom.xml index a42545b..80b3e9d 100644 --- a/pom.xml +++ b/pom.xml @@ -40,6 +40,18 @@ + + com.loafle.overflow + central-api + 1.0.0-SNAPSHOT + + + + com.loafle.overflow + commons-java + 1.0.6-SNAPSHOT + + com.loafle.commons rpc-java @@ -185,21 +197,6 @@ ${caffeine.version} - - - - com.loafle.overflow - central-api - 1.0.0-SNAPSHOT - - - - com.loafle.overflow - commons-java - 1.0.1-SNAPSHOT - - - com.warrenstrange googleauth diff --git a/src/main/java/com/loafle/overflow/central/commons/service/MessagePublisher.java b/src/main/java/com/loafle/overflow/central/commons/service/MessagePublisher.java index a86403b..24d760f 100644 --- a/src/main/java/com/loafle/overflow/central/commons/service/MessagePublisher.java +++ b/src/main/java/com/loafle/overflow/central/commons/service/MessagePublisher.java @@ -3,12 +3,19 @@ package com.loafle.overflow.central.commons.service; import com.loafle.overflow.core.exception.OverflowException; public interface MessagePublisher { - void publishToDomainMembers(final Long domainID, final String method, final Object... params) throws OverflowException; - void publishToDomainMembersByProbeKey(final String probeKey, final String method, final Object... params) throws OverflowException; + void publishToDomainMembers(final Long domainID, final String method, final Object... params) + throws OverflowException; + + void publishToDomainMembersByProbeKey(final String probeKey, final String method, final Object... params) + throws OverflowException; void publishToMember(final String memberID, final String method, final Object... params) throws OverflowException; - void publishToMemberSession(final String memberSessionID, final String method, final Object... params) throws OverflowException; - void publishToNoAuthProbe(final String tempProbeKey, final String method, final Object... params) throws OverflowException; + void publishToMemberSession(final String memberSessionID, final String method, final Object... params) + throws OverflowException; + + void publishToNoAuthProbe(final String tempProbeKey, final String method, final Object... params) + throws OverflowException; + void publishToProbe(final String probeKey, final String method, final Object... params) throws OverflowException; } diff --git a/src/main/java/com/loafle/overflow/central/module/apikey/service/CentralApiKeyService.java b/src/main/java/com/loafle/overflow/central/module/apikey/service/CentralApiKeyService.java index 0e5a737..0dc4632 100644 --- a/src/main/java/com/loafle/overflow/central/module/apikey/service/CentralApiKeyService.java +++ b/src/main/java/com/loafle/overflow/central/module/apikey/service/CentralApiKeyService.java @@ -6,7 +6,6 @@ import com.loafle.overflow.central.module.apikey.dao.ApiKeyDAO; 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.service.central.apikey.ApiKeyService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; diff --git a/src/main/java/com/loafle/overflow/central/module/auth/dao/AuthCrawlerDAO.java b/src/main/java/com/loafle/overflow/central/module/auth/dao/AuthCrawlerDAO.java index 279ef42..ded2eaf 100644 --- a/src/main/java/com/loafle/overflow/central/module/auth/dao/AuthCrawlerDAO.java +++ b/src/main/java/com/loafle/overflow/central/module/auth/dao/AuthCrawlerDAO.java @@ -1,11 +1,6 @@ package com.loafle.overflow.central.module.auth.dao; - - - import com.loafle.overflow.model.auth.AuthCrawler; -import com.loafle.overflow.model.meta.MetaCrawler; -import com.loafle.overflow.model.target.Target; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; @@ -14,5 +9,5 @@ import org.springframework.stereotype.Repository; */ @Repository public interface AuthCrawlerDAO extends JpaRepository { - AuthCrawler findByCrawlerAndTarget(MetaCrawler metaCrawler, Target target); + AuthCrawler findByMetaCrawlerIdAndTargetId(Short metaCrawlerId, Long targetId); } diff --git a/src/main/java/com/loafle/overflow/central/module/auth/service/CentralAuthCrawlerService.java b/src/main/java/com/loafle/overflow/central/module/auth/service/CentralAuthCrawlerService.java index b6d12ea..84f85ae 100644 --- a/src/main/java/com/loafle/overflow/central/module/auth/service/CentralAuthCrawlerService.java +++ b/src/main/java/com/loafle/overflow/central/module/auth/service/CentralAuthCrawlerService.java @@ -7,7 +7,6 @@ import com.loafle.overflow.core.exception.OverflowException; import com.loafle.overflow.model.auth.AuthCrawler; import com.loafle.overflow.model.infra.Infra; import com.loafle.overflow.model.meta.MetaCrawler; -import com.loafle.overflow.model.target.Target; import com.loafle.overflow.service.central.auth.AuthCrawlerService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -18,40 +17,39 @@ import org.springframework.stereotype.Service; @Service("AuthCrawlerService") public class CentralAuthCrawlerService implements AuthCrawlerService { - @Autowired - private AuthCrawlerDAO authCrawlerDAO; + @Autowired + private AuthCrawlerDAO authCrawlerDAO; - @Autowired - private CentralInfraService infraService; + @Autowired + private CentralInfraService infraService; - public AuthCrawler regist(AuthCrawler authCrawler) { + public AuthCrawler regist(AuthCrawler authCrawler) { + // if (authCrawler == null) { + // return this.authCrawlerDAO.save(authCrawler); + // } - AuthCrawler dbAuthCrawler = this.authCrawlerDAO.findByCrawlerAndTarget(authCrawler.getCrawler(), - authCrawler.getTarget()); + AuthCrawler dbAuthCrawler = this.authCrawlerDAO.findByMetaCrawlerIdAndTargetId(authCrawler.getMetaCrawler().getId(), + authCrawler.getTarget().getId()); - if (authCrawler == null) { - return this.authCrawlerDAO.save(authCrawler); - } + dbAuthCrawler.setAuthJson(authCrawler.getAuthJson()); + dbAuthCrawler.setMetaCrawler(authCrawler.getMetaCrawler()); + dbAuthCrawler.setTarget(authCrawler.getTarget()); - dbAuthCrawler.setAuthJson(authCrawler.getAuthJson()); - dbAuthCrawler.setCrawler(authCrawler.getCrawler()); - dbAuthCrawler.setTarget(authCrawler.getTarget()); + return this.authCrawlerDAO.save(dbAuthCrawler); + } - return this.authCrawlerDAO.save(dbAuthCrawler); - } + public boolean checkAuthCrawler(Long infraId, MetaCrawler metaCrawler, String authJson) throws OverflowException { - public boolean checkAuthCrawler(Long infraId, MetaCrawler crawler, String authJson) throws OverflowException { + Infra infra = this.infraService.read(infraId); - Infra infra = this.infraService.read(infraId); + // FIXME: Check Crawler on Probe - // FIXME: Check Crawler on Probe + return false; + } - return false; - } + public AuthCrawler readByMetaCrawlerIDAndTargetID(Short metaCrawlerID, Long targetID) throws OverflowException { - public AuthCrawler readAuth(MetaCrawler metaCrawler, Target target) throws OverflowException { - - return this.authCrawlerDAO.findByCrawlerAndTarget(metaCrawler, target); - } + return this.authCrawlerDAO.findByMetaCrawlerIdAndTargetId(metaCrawlerID, targetID); + } } diff --git a/src/main/java/com/loafle/overflow/central/module/discovery/service/CentralDiscoveryService.java b/src/main/java/com/loafle/overflow/central/module/discovery/service/CentralDiscoveryService.java index 4280f83..f1d0188 100644 --- a/src/main/java/com/loafle/overflow/central/module/discovery/service/CentralDiscoveryService.java +++ b/src/main/java/com/loafle/overflow/central/module/discovery/service/CentralDiscoveryService.java @@ -52,6 +52,13 @@ public class CentralDiscoveryService implements DiscoveryService { discoveryService); } + @WebappAPI + public void stopDiscovery(String probeID) throws OverflowException { + String requesterSessionID = SessionMetadata.getSessionID(); + + messagePublisher.publishToProbe(probeID, "DiscoveryService.StopDiscovery", requesterSessionID); + } + @ProbeAPI public void discoveryStart(String requesterSessionID, Date startDate) throws OverflowException { messagePublisher.publishToMemberSession(requesterSessionID, "DiscoveryService.discoveryStart", startDate); diff --git a/src/main/java/com/loafle/overflow/central/module/domain/dao/DomainMemberDAO.java b/src/main/java/com/loafle/overflow/central/module/domain/dao/DomainMemberDAO.java index 7b98953..e5a56d6 100644 --- a/src/main/java/com/loafle/overflow/central/module/domain/dao/DomainMemberDAO.java +++ b/src/main/java/com/loafle/overflow/central/module/domain/dao/DomainMemberDAO.java @@ -1,13 +1,9 @@ package com.loafle.overflow.central.module.domain.dao; - - import com.loafle.overflow.model.domain.Domain; import com.loafle.overflow.model.domain.DomainMember; import com.loafle.overflow.model.member.Member; 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; @@ -18,13 +14,9 @@ import java.util.List; @Repository public interface DomainMemberDAO extends JpaRepository { - @Query("SELECT dm from DomainMember dm where dm.member.email = (:email)") - DomainMember findByMemberEmail(@Param("email") String email); - - @Query("SELECT dm.domain from DomainMember dm where dm.member.id = (:memberID)") - Domain findDomainByMemberId(@Param("memberID") Long memberID); + DomainMember findByMemberEmail(String memberEmail); + Domain findDomainByMemberId(Long memberId); - @Query("SELECT dm.member from DomainMember dm where dm.domain.id = (:domainID)") - List findAllMemberByDomainId(@Param("domainID") Long domainID); + List findAllMemberByDomainId(Long domainID); } diff --git a/src/main/java/com/loafle/overflow/central/module/domain/service/CentralDomainMemberService.java b/src/main/java/com/loafle/overflow/central/module/domain/service/CentralDomainMemberService.java index 26d8a4b..ddd031e 100644 --- a/src/main/java/com/loafle/overflow/central/module/domain/service/CentralDomainMemberService.java +++ b/src/main/java/com/loafle/overflow/central/module/domain/service/CentralDomainMemberService.java @@ -2,8 +2,6 @@ package com.loafle.overflow.central.module.domain.service; import com.loafle.overflow.central.module.domain.dao.DomainMemberDAO; -import com.loafle.overflow.central.module.member.dao.MemberDAO; - import com.loafle.overflow.model.domain.Domain; import com.loafle.overflow.model.domain.DomainMember; import com.loafle.overflow.model.member.Member; @@ -19,23 +17,23 @@ import java.util.List; @Service("DomainMemberService") public class CentralDomainMemberService implements DomainMemberService { - @Autowired - private DomainMemberDAO domainMemberDAO; + @Autowired + private DomainMemberDAO domainMemberDAO; - public void regist(DomainMember domainMember) { - this.domainMemberDAO.save(domainMember); - } + public void regist(DomainMember domainMember) { + this.domainMemberDAO.save(domainMember); + } - public Domain readDomainByMemberID(Long memberID) { - return this.domainMemberDAO.findDomainByMemberId(memberID); - } + public Domain readDomainByMemberID(Long memberID) { + return this.domainMemberDAO.findDomainByMemberId(memberID); + } - public DomainMember readByMemberEmail(String email) { - return this.domainMemberDAO.findByMemberEmail(email); - } + public DomainMember readByMemberEmail(String email) { + return this.domainMemberDAO.findByMemberEmail(email); + } - public List readAllMemberByDomainID(final Long domainID) { - return this.domainMemberDAO.findAllMemberByDomainId(domainID); - } + public List readAllMemberByDomainID(final Long domainID) { + return this.domainMemberDAO.findAllMemberByDomainId(domainID); + } } diff --git a/src/main/java/com/loafle/overflow/central/module/domain/service/CentralDomainService.java b/src/main/java/com/loafle/overflow/central/module/domain/service/CentralDomainService.java index 1677cf0..b037e3f 100644 --- a/src/main/java/com/loafle/overflow/central/module/domain/service/CentralDomainService.java +++ b/src/main/java/com/loafle/overflow/central/module/domain/service/CentralDomainService.java @@ -14,10 +14,10 @@ import org.springframework.stereotype.Service; @Service("DomainService") public class CentralDomainService implements DomainService { - @Autowired - private DomainDAO domainDAO; + @Autowired + private DomainDAO domainDAO; - public void regist(Domain domain) throws OverflowException { - this.domainDAO.save(domain); - } + public void regist(Domain domain) throws OverflowException { + this.domainDAO.save(domain); + } } diff --git a/src/main/java/com/loafle/overflow/central/module/email/dao/EmailAuthDAO.java b/src/main/java/com/loafle/overflow/central/module/email/dao/EmailAuthDAO.java index 3949908..669a417 100644 --- a/src/main/java/com/loafle/overflow/central/module/email/dao/EmailAuthDAO.java +++ b/src/main/java/com/loafle/overflow/central/module/email/dao/EmailAuthDAO.java @@ -1,8 +1,6 @@ package com.loafle.overflow.central.module.email.dao; - import com.loafle.overflow.model.email.EmailAuth; -import com.loafle.overflow.model.member.Member; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; @@ -15,7 +13,6 @@ import java.util.List; public interface EmailAuthDAO extends JpaRepository { EmailAuth findByEmailAuthKey(String emailAuthKey); - List findByMember(Member member); + List findByMemberId(Long memberId); } - diff --git a/src/main/java/com/loafle/overflow/central/module/email/service/EmailAuthService.java b/src/main/java/com/loafle/overflow/central/module/email/service/EmailAuthService.java index 5fa1075..dd78dde 100644 --- a/src/main/java/com/loafle/overflow/central/module/email/service/EmailAuthService.java +++ b/src/main/java/com/loafle/overflow/central/module/email/service/EmailAuthService.java @@ -1,6 +1,5 @@ package com.loafle.overflow.central.module.email.service; - import com.loafle.overflow.central.commons.utils.EmailSender; import com.loafle.overflow.central.commons.utils.GenerateKey; import com.loafle.overflow.central.module.domain.dao.DomainDAO; @@ -28,221 +27,219 @@ import java.util.*; */ @Service("EmailAuthService") public class EmailAuthService { - private static final String WEB_GO_MEMBER_ADDR = "http://127.0.0.1:4200/#/auth/"; + private static final String WEB_GO_MEMBER_ADDR = "http://127.0.0.1:4200/#/auth/"; - @Autowired - private EmailAuthDAO emailAuthDAO; + @Autowired + private EmailAuthDAO emailAuthDAO; - @Autowired - private MemberDAO memberDAO; + @Autowired + private MemberDAO memberDAO; - @Autowired - private DomainDAO domainDAO; + @Autowired + private DomainDAO domainDAO; - @Autowired - private DomainMemberDAO domainMemberDAO; + @Autowired + private DomainMemberDAO domainMemberDAO; - @Autowired - private EmailSender emailSender; + @Autowired + private EmailSender emailSender; + // private static final String WEB_NG_MEMBER_ADDR = + // "http://127.0.0.1:4200/auth/"; -// private static final String WEB_NG_MEMBER_ADDR = "http://127.0.0.1:4200/auth/"; + public EmailAuth read(Long id) { + return this.emailAuthDAO.findOne(id); + } - public EmailAuth read(Long id) { - return this.emailAuthDAO.findOne(id); + public EmailAuth readBySignupAuthKey(String token) throws OverflowException { + // System.out.println("authKey = [" + token + "]"); + // String deStr = URLDecoder.decode(token, "UTF-8"); + // System.out.println("deStr = [" + deStr + "]"); + // + // EmailAuth auth = this.emailAuthDAO.findByEmailAuthKey(deStr); + + EmailAuth auth = this.readByToken(token); + + if (auth != null) { + + boolean res = this.isValidateTime(auth); + + if (!res) { + throw new OverflowException("The authentication expiration time has expired, or the token has been verified.", + new Throwable()); + } + + auth.setAuthConfirmDate(new Date()); + this.emailAuthDAO.save(auth); + auth.getMember().setMetaMemberStatus(new MetaMemberStatus((short) 2)); + this.memberDAO.save(auth.getMember()); + + Domain domain = new Domain(); + domain.setName(auth.getMember().getCompanyName()); + Domain domain1 = this.domainDAO.save(domain); + + DomainMember domainMember = new DomainMember(); + domainMember.setDomain(domain1); + domainMember.setMember(auth.getMember()); + this.domainMemberDAO.save(domainMember); } - public EmailAuth readBySignupAuthKey(String token) throws OverflowException { -// System.out.println("authKey = [" + token + "]"); -// String deStr = URLDecoder.decode(token, "UTF-8"); -// System.out.println("deStr = [" + deStr + "]"); -// -// EmailAuth auth = this.emailAuthDAO.findByEmailAuthKey(deStr); + return auth; + } - EmailAuth auth = this.readByToken(token); + public EmailAuth readByPwAuthKey(String token) throws OverflowException { - if (auth != null) { + EmailAuth auth = this.readByToken(token); - boolean res = this.isValidateTime(auth); + if (auth != null && (auth.getMember() != null && auth.getMember().getId() > 0)) { + boolean res = this.isValidateTime(auth); - if (!res) { - throw new OverflowException( - "The authentication expiration time has expired, or the token has been verified.", - new Throwable()); - } + if (!res) { + throw new OverflowException("The authentication expiration time has expired, or the token has been verified.", + new Throwable()); + } - auth.setAuthConfirmDate(new Date()); - this.emailAuthDAO.save(auth); - auth.getMember().setStatus(new MetaMemberStatus((short)2)); - this.memberDAO.save(auth.getMember()); - - Domain domain = new Domain(); - domain.setName(auth.getMember().getCompanyName()); - Domain domain1 = this.domainDAO.save(domain); - - DomainMember domainMember = new DomainMember(); - domainMember.setDomain(domain1); - domainMember.setMember(auth.getMember()); - this.domainMemberDAO.save(domainMember); - } - - return auth; + auth.setAuthConfirmDate(new Date()); + this.emailAuthDAO.save(auth); } - public EmailAuth readByPwAuthKey(String token) throws OverflowException { + return auth; - EmailAuth auth = this.readByToken(token); + } - if (auth != null && (auth.getMember() != null && auth.getMember().getId() > 0)) { - boolean res = this.isValidateTime(auth); - - if (!res) { - throw new OverflowException( - "The authentication expiration time has expired, or the token has been verified.", - new Throwable()); - } - - auth.setAuthConfirmDate(new Date()); - this.emailAuthDAO.save(auth); - } - - return auth; + public EmailAuth readByToken(String token) { + String encode = ""; + try { + encode = URLEncoder.encode(token, "UTF-8"); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); } - public EmailAuth readByToken(String token) { - String encode = ""; + EmailAuth auth = this.emailAuthDAO.findByEmailAuthKey(encode); - try { - encode = URLEncoder.encode(token, "UTF-8"); - }catch (UnsupportedEncodingException e) { - e.printStackTrace(); - } + return auth; + } + // dZQgXM1o/Cx48X8DM+6ec/oPfqA2l/LdWtijOZ2EnWk= - EmailAuth auth = this.emailAuthDAO.findByEmailAuthKey(encode); + public List readByMember(Long memberId) { + return this.emailAuthDAO.findByMemberId(memberId); + } - return auth; - } - // dZQgXM1o/Cx48X8DM+6ec/oPfqA2l/LdWtijOZ2EnWk= + public EmailAuth modify(EmailAuth emailAuth) { + return this.emailAuthDAO.save(emailAuth); + } - public List readByMember(Long memberId) { - return this.emailAuthDAO.findByMember(new Member(memberId)); + public EmailAuth sendEmailByMember(Member member) throws OverflowException { + return this.sendEMail(member, 1); + } + + // Todo Send Email Refactoring + public EmailAuth sendEmailResetPassword(Member member) throws OverflowException { + return this.sendEMail(member, 2); + } + + private boolean isValidateTime(EmailAuth auth) { + + Calendar cal = Calendar.getInstance(); + + cal.setTime(auth.getCreateDate()); + cal.add(Calendar.HOUR, 12); + Date futureDate = cal.getTime(); + + Date nowDate = new Date(); + + if (!nowDate.before(futureDate)) { + return false; } - public EmailAuth modify(EmailAuth emailAuth) { - return this.emailAuthDAO.save(emailAuth); + if (null != auth.getAuthConfirmDate()) { + return false; } - public EmailAuth sendEmailByMember(Member member) throws OverflowException { - return this.sendEMail(member, 1); + return true; + } + + private EmailAuth sendEMail(Member member, int status) throws OverflowException { + String key = GenerateKey.getKey(); + // String enMail = emailSender.encrypt(key); + + String mailSubject = null; + String entry = null; + String templateName = null; + + EmailAuth auth = new EmailAuth(); + auth.setMember(member); + auth.setEmailAuthKey(key); + auth.setMetaEmailStatus(new MetaEmailStatus(status)); + + // System.out.println("encode = [" + encode + "]"); + String encode = ""; + + try { + encode = URLEncoder.encode(key, "UTF-8"); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); } - // Todo Send Email Refactoring - public EmailAuth sendEmailResetPassword(Member member) throws OverflowException { - return this.sendEMail(member, 2); + if (status == 1) { + mailSubject = "Signup Confirm Mail"; + entry = "confirm-signup"; + templateName = "/vmtemplates/signup.vm"; + } else if (status == 2) { + mailSubject = "Reset Password Confirm Mail"; + entry = "confirm-reset-password"; + templateName = "/vmtemplates/password_reset.vm"; } - private boolean isValidateTime(EmailAuth auth) { + Mail mail = new Mail(); + mail.setMailTo(member.getEmail()); + mail.setMailSubject(mailSubject); + mail.setTemplateLoacation(templateName); - Calendar cal = Calendar.getInstance(); + String uri = WEB_GO_MEMBER_ADDR + entry + "?token=" + encode; - cal.setTime(auth.getCreateDate()); - cal.add(Calendar.HOUR, 12); - Date futureDate = cal.getTime(); + Map model = new HashMap<>(); + model.put("firstName", auth.getMember().getName()); + model.put("lastName", auth.getMember().getCompanyName()); + model.put("location", "Seoul"); + model.put("signature", "www.loafle.com"); + model.put("content", uri); + mail.setModel(model); + emailSender.sendSimpleEmail(mail); - Date nowDate = new Date(); + this.emailAuthDAO.save(auth); - if (!nowDate.before(futureDate)) { - return false; - } - - if (null != auth.getAuthConfirmDate()) { - return false; - } - - return true; - } - - private EmailAuth sendEMail(Member member, int status) throws OverflowException { - String key = GenerateKey.getKey(); -// String enMail = emailSender.encrypt(key); - - String mailSubject = null; - String entry = null; - String templateName = null; - - EmailAuth auth = new EmailAuth(); - auth.setMember(member); - auth.setEmailAuthKey(key); - auth.setEmailStatus(new MetaEmailStatus(status)); - -// System.out.println("encode = [" + encode + "]"); - String encode = ""; - - try { - encode = URLEncoder.encode(key, "UTF-8"); - }catch (UnsupportedEncodingException e) { - e.printStackTrace(); - } - - if (status == 1) { - mailSubject = "Signup Confirm Mail"; - entry = "confirm-signup"; - templateName = "/vmtemplates/signup.vm"; - } else if (status == 2) { - mailSubject = "Reset Password Confirm Mail"; - entry = "confirm-reset-password"; - templateName = "/vmtemplates/password_reset.vm"; - } - - Mail mail = new Mail(); - mail.setMailTo(member.getEmail()); - mail.setMailSubject(mailSubject); - mail.setTemplateLoacation(templateName); - - String uri = WEB_GO_MEMBER_ADDR + entry + "?token=" + encode; - - Map model = new HashMap<>(); - model.put("firstName", auth.getMember().getName()); - model.put("lastName", auth.getMember().getCompanyName()); - model.put("location", "Seoul"); - model.put("signature", "www.loafle.com"); - model.put("content", uri); - mail.setModel(model); - emailSender.sendSimpleEmail(mail); - - this.emailAuthDAO.save(auth); - - return auth; - } + return auth; + } } - - -// EmailAuth auth = new EmailAuth(); -// auth.setMember(member); -// String en = emailSender.encrypt(member.getEmail()); -// auth.setEmailAuthKey(en); -// auth.setEmailStatus(new MetaEmailStatus(1)); -// String encode = URLEncoder.encode(en, "UTF-8"); +// EmailAuth auth = new EmailAuth(); +// auth.setMember(member); +// String en = emailSender.encrypt(member.getEmail()); +// auth.setEmailAuthKey(en); +// auth.setEmailStatus(new MetaEmailStatus(1)); +// String encode = URLEncoder.encode(en, "UTF-8"); // -//// System.out.println("encode = [" + encode + "]"); -// Mail mail = new Mail(); -// mail.setMailTo(member.getEmail()); -// mail.setMailSubject("Confirm Email"); -//// mail.setMailContent("http://127.0.0.1:19080/account/confirm_signup?key="+ encode +"\r\nConfirm Email"); +//// System.out.println("encode = [" + encode + "]"); +// Mail mail = new Mail(); +// mail.setMailTo(member.getEmail()); +// mail.setMailSubject("Confirm Email"); +//// mail.setMailContent("http://127.0.0.1:19080/account/confirm_signup?key="+ +// encode +"\r\nConfirm Email"); // -// String uri = WEB_GO_MEMBER_ADDR + "confirm_signup?key=" + encode + "\r\nConfirm Email"; -// Map model = new HashMap<>(); -// model.put("firstName", auth.getMember().getName()); -// model.put("lastName", auth.getMember().getCompanyName()); -// model.put("location", "Seoul"); -// model.put("signature", "www.loafle.com"); -// model.put("content", uri); +// String uri = WEB_GO_MEMBER_ADDR + "confirm_signup?key=" + encode + +// "\r\nConfirm Email"; +// Map model = new HashMap<>(); +// model.put("firstName", auth.getMember().getName()); +// model.put("lastName", auth.getMember().getCompanyName()); +// model.put("location", "Seoul"); +// model.put("signature", "www.loafle.com"); +// model.put("content", uri); // -// mail.setModel(model); -// emailSender.sendSimpleEmail(mail); +// mail.setModel(model); +// emailSender.sendSimpleEmail(mail); // -// this.emailAuthDAO.save(auth); +// this.emailAuthDAO.save(auth); // -// return auth; \ No newline at end of file +// return auth; \ No newline at end of file diff --git a/src/main/java/com/loafle/overflow/central/module/generator/service/GenerateUtil.java b/src/main/java/com/loafle/overflow/central/module/generator/service/GenerateUtil.java index d4b24b9..1635a71 100644 --- a/src/main/java/com/loafle/overflow/central/module/generator/service/GenerateUtil.java +++ b/src/main/java/com/loafle/overflow/central/module/generator/service/GenerateUtil.java @@ -42,7 +42,7 @@ public class GenerateUtil { return resultMap; } - resultMap = this.metaSensorItemKeyService.readAllMapByCrawler(metaCrawler); + resultMap = this.metaSensorItemKeyService.readAllMapByMetaCrawlerID(metaCrawler.getId()); this.mappingMap.put(metaCrawler.getId(), resultMap); return resultMap; @@ -85,7 +85,7 @@ public class GenerateUtil { MetaSensorItemKey itemKey = null; for(SensorItem sItem : sensorItems) { - itemKey = keyMap.get(sItem.getItem().getId()); + itemKey = keyMap.get(sItem.getMetaSensorDisplayItem().getId()); if(metricMap.containsKey(itemKey.getFroms()) == false) { metricMap.put(itemKey.getFroms(), new ArrayList<>()); } @@ -98,7 +98,7 @@ public class GenerateUtil { public Keys createKeys(MetaSensorItemKey itemKey) throws OverflowException { Keys keys = new Keys(); keys.setKey(itemKey.getKey()); - keys.setMetric(itemKey.getItem().getKey()); + keys.setMetric(itemKey.getMetaSensorItem().getKey()); return keys; } } diff --git a/src/main/java/com/loafle/overflow/central/module/generator/service/InfraHostGenerator.java b/src/main/java/com/loafle/overflow/central/module/generator/service/InfraHostGenerator.java index db14e9a..bcceccc 100644 --- a/src/main/java/com/loafle/overflow/central/module/generator/service/InfraHostGenerator.java +++ b/src/main/java/com/loafle/overflow/central/module/generator/service/InfraHostGenerator.java @@ -63,12 +63,12 @@ public class InfraHostGenerator { schedule.setInterval("5"); sensorConfig.setSchedule(schedule); - Crawler crawler = this.generateUtil.getCrawler(dbSensor.getCrawler()); + Crawler crawler = this.generateUtil.getCrawler(dbSensor.getMetaCrawler()); sensorConfig.setCrawler(crawler); - Map keyMap = this.generateUtil.initMappingMap(dbSensor.getCrawler()); + Map keyMap = this.generateUtil.initMappingMap(dbSensor.getMetaCrawler()); - if (dbSensor.getCrawler().getId() == MetaCrawlerEnum.WMI_CRAWLER.getValue()) { + if (dbSensor.getMetaCrawler().getId() == MetaCrawlerEnum.WMI_CRAWLER.getValue()) { this.infraHostWMIGenerator.process(sensorItems, keyMap, dbSensor, sensorConfig); } @@ -77,7 +77,7 @@ public class InfraHostGenerator { private Target createTarget(InfraHost infraHost, Sensor dbSensor) throws Exception { - AuthCrawler authCrawler = this.authCrawlerService.readAuth(dbSensor.getCrawler(), dbSensor.getTarget()); + AuthCrawler authCrawler = this.authCrawlerService.readByMetaCrawlerIDAndTargetID(dbSensor.getMetaCrawler().getId(), dbSensor.getTarget().getId()); if (authCrawler == null) { return null; @@ -89,7 +89,7 @@ public class InfraHostGenerator { HashMap optionMap = this.objectMapper.readValue(authCrawler.getAuthJson(), new TypeReference>(){}); - if (dbSensor.getCrawler().getId() == MetaCrawlerEnum.WMI_CRAWLER.getValue()) { + if (dbSensor.getMetaCrawler().getId() == MetaCrawlerEnum.WMI_CRAWLER.getValue()) { connection.setPort(135); connection.setPortType(PortType.TCP); connection.setSsl(false); diff --git a/src/main/java/com/loafle/overflow/central/module/generator/service/InfraServiceGenerator.java b/src/main/java/com/loafle/overflow/central/module/generator/service/InfraServiceGenerator.java index 5d014cc..1ec57e4 100644 --- a/src/main/java/com/loafle/overflow/central/module/generator/service/InfraServiceGenerator.java +++ b/src/main/java/com/loafle/overflow/central/module/generator/service/InfraServiceGenerator.java @@ -66,14 +66,14 @@ public class InfraServiceGenerator { schedule.setInterval("5"); sensorConfig.setSchedule(schedule); - Crawler crawler = this.generateUtil.getCrawler(dbSensor.getCrawler()); + Crawler crawler = this.generateUtil.getCrawler(dbSensor.getMetaCrawler()); sensorConfig.setCrawler(crawler); - Map keyMap = this.generateUtil.initMappingMap(dbSensor.getCrawler()); + Map keyMap = this.generateUtil.initMappingMap(dbSensor.getMetaCrawler()); - if(dbSensor.getCrawler().getId() == MetaCrawlerEnum.MYSQL_CRAWLER.getValue()) { + if(dbSensor.getMetaCrawler().getId() == MetaCrawlerEnum.MYSQL_CRAWLER.getValue()) { this.infraServiceMysqlGenerator.process(sensorItems, keyMap, dbSensor, sensorConfig); - } else if (dbSensor.getCrawler().getId() == MetaCrawlerEnum.JMX_CRAWLER.getValue()) { + } else if (dbSensor.getMetaCrawler().getId() == MetaCrawlerEnum.JMX_CRAWLER.getValue()) { this.infraServiceJMXGenerator.process(sensorItems, keyMap, dbSensor, sensorConfig); } @@ -82,7 +82,7 @@ public class InfraServiceGenerator { private Target createTarget(InfraService infraService, Sensor sensor) throws Exception { - AuthCrawler authCrawler = this.authCrawlerService.readAuth(sensor.getCrawler(), sensor.getTarget()); + AuthCrawler authCrawler = this.authCrawlerService.readByMetaCrawlerIDAndTargetID(sensor.getMetaCrawler().getId(), sensor.getTarget().getId()); if(authCrawler == null) { return null; @@ -90,7 +90,7 @@ public class InfraServiceGenerator { Target target = new Target(); Connection connection = new Connection(); - connection.setIp(infraService.getHost().getIpv4()); + connection.setIp(infraService.getInfraHost().getIpv4()); connection.setPort(infraService.getPort()); connection.setPortType(PortType.valueOf(infraService.getPortType())); connection.setSsl(infraService.isTlsType()); @@ -101,11 +101,11 @@ public class InfraServiceGenerator { Map auth = new HashMap<>(); - if(sensor.getCrawler().getId() == MetaCrawlerEnum.MYSQL_CRAWLER.getValue()) { - auth.put("url", "jdbc:mysql://"+ infraService.getHost().getIpv4() +":" + infraService.getPort()); + if(sensor.getMetaCrawler().getId() == MetaCrawlerEnum.MYSQL_CRAWLER.getValue()) { + auth.put("url", "jdbc:mysql://"+ infraService.getInfraHost().getIpv4() +":" + infraService.getPort()); auth.put("id", optionMap.get("ID")); // FIXME: Auth Info auth.put("pw", optionMap.get("PassWord")); // FIXME: Auth Info - } else if (sensor.getCrawler().getId() == MetaCrawlerEnum.JMX_CRAWLER.getValue()) { + } else if (sensor.getMetaCrawler().getId() == MetaCrawlerEnum.JMX_CRAWLER.getValue()) { auth.put("id", optionMap.get("ID")); // FIXME: Auth Info auth.put("pw", optionMap.get("PassWord")); // FIXME: Auth Info connection.setPort(9840); diff --git a/src/main/java/com/loafle/overflow/central/module/generator/service/InfraServiceJMXGenerator.java b/src/main/java/com/loafle/overflow/central/module/generator/service/InfraServiceJMXGenerator.java index 0a99701..7b28cad 100644 --- a/src/main/java/com/loafle/overflow/central/module/generator/service/InfraServiceJMXGenerator.java +++ b/src/main/java/com/loafle/overflow/central/module/generator/service/InfraServiceJMXGenerator.java @@ -63,7 +63,7 @@ public class InfraServiceJMXGenerator { keys = new Keys(); keys.setKey(tempItemKey.getKey()); - keys.setMetric(tempItemKey.getItem().getKey()); + keys.setMetric(tempItemKey.getMetaSensorItem().getKey()); keysList.add(this.generateUtil.createKeys(tempItemKey)); } diff --git a/src/main/java/com/loafle/overflow/central/module/generator/service/SensorConfigGenerator.java b/src/main/java/com/loafle/overflow/central/module/generator/service/SensorConfigGenerator.java index be36a08..c640e96 100644 --- a/src/main/java/com/loafle/overflow/central/module/generator/service/SensorConfigGenerator.java +++ b/src/main/java/com/loafle/overflow/central/module/generator/service/SensorConfigGenerator.java @@ -38,7 +38,7 @@ public class SensorConfigGenerator { pageParams.setCountPerPage(Integer.MAX_VALUE); pageParams.setSortCol("id"); pageParams.setSortDirection("descending"); - Page dbItemList = this.sensorItemService.readAllBySensor(sensor, pageParams); + Page dbItemList = this.sensorItemService.readAllBySensorID(sensor.getId(), pageParams); List sensorItems = dbItemList.getContent(); @@ -50,10 +50,10 @@ public class SensorConfigGenerator { Infra infra = this.infraService.readByTargetID(dbSensor.getTarget().getId()); // 7 = Infra OS Service - if(infra.getInfraType().getId() == 7) { + if(infra.getMetaInfraType().getId() == 7) { return this.infraServiceGenerator.process(dbSensor, sensorItems, infra); } - if(infra.getInfraType().getId() == 2) { + if(infra.getMetaInfraType().getId() == 2) { return this.infraHostGenerator.process(dbSensor, sensorItems, infra); } diff --git a/src/main/java/com/loafle/overflow/central/module/history/dao/HistoryDAO.java b/src/main/java/com/loafle/overflow/central/module/history/dao/HistoryDAO.java index 699f6b5..dbc47d4 100644 --- a/src/main/java/com/loafle/overflow/central/module/history/dao/HistoryDAO.java +++ b/src/main/java/com/loafle/overflow/central/module/history/dao/HistoryDAO.java @@ -1,16 +1,12 @@ package com.loafle.overflow.central.module.history.dao; -import com.loafle.overflow.model.domain.Domain; import com.loafle.overflow.model.history.History; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; 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; - /** * Created by insanity on 17. 8. 23. */ @@ -18,11 +14,9 @@ import org.springframework.stereotype.Repository; public interface HistoryDAO extends JpaRepository { Page findAllByProbeId(Long probeID, Pageable pageable); - @Query("SELECT h FROM History h WHERE h.probe.id = :#{#probeID} and h.type.id = :#{#type.id}") - Page findAllByProbeIdAndType(@Param("probeID") Long probeID, @Param("type") com.loafle.overflow.model.meta.MetaHistoryType type, Pageable pageable); + Page findAllByProbeIdAndMetaHistoryTypeId(Long probeID, Integer metaHistoryTypeId, Pageable pageable); Page findAllByDomainId(Long domainID, Pageable pageRequest); - @Query("SELECT h FROM History h WHERE h.domain.id = :#{#domainID} and h.type.id = :#{#type.id}") - Page findAllByDomainIdAndType(@Param("domainID") Long domainID, @Param("type") com.loafle.overflow.model.meta.MetaHistoryType type, Pageable pageRequest); + Page findAllByDomainIdAndMetaHistoryTypeId(Long domainID, Integer metaHistoryTypeId, Pageable pageRequest); } diff --git a/src/main/java/com/loafle/overflow/central/module/history/service/CentralHistoryService.java b/src/main/java/com/loafle/overflow/central/module/history/service/CentralHistoryService.java index d93a6e0..6e3dc10 100644 --- a/src/main/java/com/loafle/overflow/central/module/history/service/CentralHistoryService.java +++ b/src/main/java/com/loafle/overflow/central/module/history/service/CentralHistoryService.java @@ -2,6 +2,7 @@ package com.loafle.overflow.central.module.history.service; import com.loafle.overflow.central.commons.utils.PageUtil; import com.loafle.overflow.central.module.history.dao.HistoryDAO; +import com.loafle.overflow.core.exception.OverflowException; import com.loafle.overflow.core.model.PageParams; import com.loafle.overflow.model.domain.Domain; import com.loafle.overflow.model.history.History; @@ -18,25 +19,25 @@ public class CentralHistoryService implements HistoryService { @Autowired private HistoryDAO historyDAO; - public History regist(History history) { + public History regist(History history) throws OverflowException { return this.historyDAO.save(history); } - public Page readAllByProbeIDAndType(Long probeID, MetaHistoryType type, PageParams pageParams) { - return this.historyDAO.findAllByProbeIdAndType(probeID, type, PageUtil.getPageRequest(pageParams)); + public Page readAllByProbeIDAndMetaHistoryTypeID(Long probeID, Integer metaHistoryTypeID, PageParams pageParams) throws OverflowException { + return this.historyDAO.findAllByProbeIdAndMetaHistoryTypeId(probeID, metaHistoryTypeID, PageUtil.getPageRequest(pageParams)); } - public Page readAllByProbeID(Long probeID, PageParams pageParams) { + public Page readAllByProbeID(Long probeID, PageParams pageParams) throws OverflowException { return this.historyDAO.findAllByProbeId(probeID, PageUtil.getPageRequest(pageParams)); } - public Page readAllByDomainID(Long domainID, PageParams pageParams) { + public Page readAllByDomainID(Long domainID, PageParams pageParams) throws OverflowException { return this.historyDAO.findAllByDomainId(domainID, PageUtil.getPageRequest(pageParams)); } - public Page readAllByDomainIDAndType(Long domainID, MetaHistoryType type, PageParams pageParams) { - return this.historyDAO.findAllByDomainIdAndType(domainID, type, PageUtil.getPageRequest(pageParams)); + public Page readAllByDomainIDAndMetaHistoryTypeID(Long domainID, Integer metaHistoryTypeID, PageParams pageParams) throws OverflowException { + return this.historyDAO.findAllByDomainIdAndMetaHistoryTypeId(domainID, metaHistoryTypeID, PageUtil.getPageRequest(pageParams)); } } diff --git a/src/main/java/com/loafle/overflow/central/module/infra/dao/InfraDAO.java b/src/main/java/com/loafle/overflow/central/module/infra/dao/InfraDAO.java index 77169cc..b947efe 100644 --- a/src/main/java/com/loafle/overflow/central/module/infra/dao/InfraDAO.java +++ b/src/main/java/com/loafle/overflow/central/module/infra/dao/InfraDAO.java @@ -6,8 +6,6 @@ import com.loafle.overflow.model.target.Target; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; 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; @@ -21,13 +19,10 @@ public interface InfraDAO extends JpaRepository { Page findAllByProbeId(Long probeID, Pageable pageable); - @Query("SELECT i FROM INFRA i WHERE i.probe IN (:probeList) AND i.target != NULL") - Page findAllByProbeList(@Param("probeList") List probeList, Pageable pageable); + Page findAllByProbeInAndTargetNotNull(List probes, Pageable pageable); - - @Query("SELECT DISTINCT i.target FROM INFRA i WHERE i.probe IN (:probeList)") - List findAllTargetByProbeList(@Param("probeList") List probeList); + List findAllTargetByProbeIn(List probes); Infra findByTargetId(Long targetID); -// List findAllByProbe(List probeList); + } \ No newline at end of file diff --git a/src/main/java/com/loafle/overflow/central/module/infra/dao/InfraOSPortDAO.java b/src/main/java/com/loafle/overflow/central/module/infra/dao/InfraOSPortDAO.java index ce387f6..db1b351 100644 --- a/src/main/java/com/loafle/overflow/central/module/infra/dao/InfraOSPortDAO.java +++ b/src/main/java/com/loafle/overflow/central/module/infra/dao/InfraOSPortDAO.java @@ -2,9 +2,6 @@ package com.loafle.overflow.central.module.infra.dao; import com.loafle.overflow.model.infra.InfraOSPort; import org.springframework.data.jpa.repository.JpaRepository; -// import org.springframework.data.jpa.repository.Query; -import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; /** @@ -12,6 +9,5 @@ import org.springframework.stereotype.Repository; */ @Repository public interface InfraOSPortDAO extends JpaRepository { - @Query("SELECT p from com.loafle.overflow.model.infra.InfraOSPort p WHERE p.os.id = (:osId) AND p.port = (:portNumber) AND p.portType = (:portType)") - InfraOSPort findByPort(@Param("osId") Long osId,@Param("portNumber") Integer portNumber,@Param("portType") String portType); + InfraOSPort findByInfraOSIdAndPortAndPortType(Long infraOSId, Integer port, String portType); } \ No newline at end of file diff --git a/src/main/java/com/loafle/overflow/central/module/infra/dao/InfraServiceDAO.java b/src/main/java/com/loafle/overflow/central/module/infra/dao/InfraServiceDAO.java index f9a6f9c..9d0d749 100644 --- a/src/main/java/com/loafle/overflow/central/module/infra/dao/InfraServiceDAO.java +++ b/src/main/java/com/loafle/overflow/central/module/infra/dao/InfraServiceDAO.java @@ -2,8 +2,6 @@ package com.loafle.overflow.central.module.infra.dao; import com.loafle.overflow.model.infra.InfraService; 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; /** @@ -11,6 +9,5 @@ import org.springframework.stereotype.Repository; */ @Repository public interface InfraServiceDAO extends JpaRepository { - @Query("SELECT ins from com.loafle.overflow.model.infra.InfraService ins WHERE ins.host.id = (:hostId) AND ins.port = (:portNumber) AND ins.portType = (:portType)") - InfraService findByService(@Param("hostId") Long hostId,@Param("portNumber") Integer portNumber,@Param("portType") String portType); + InfraService findByInfraHostIdAndPortAndPortType(Long infraHostId, Integer port, String portType); } \ No newline at end of file diff --git a/src/main/java/com/loafle/overflow/central/module/infra/service/CentralInfraHostService.java b/src/main/java/com/loafle/overflow/central/module/infra/service/CentralInfraHostService.java index e2c2d35..8a88797 100644 --- a/src/main/java/com/loafle/overflow/central/module/infra/service/CentralInfraHostService.java +++ b/src/main/java/com/loafle/overflow/central/module/infra/service/CentralInfraHostService.java @@ -1,6 +1,5 @@ package com.loafle.overflow.central.module.infra.service; - import com.loafle.overflow.central.module.infra.dao.InfraHostDAO; import com.loafle.overflow.core.exception.OverflowException; import com.loafle.overflow.model.infra.InfraHost; @@ -21,11 +20,11 @@ public class CentralInfraHostService implements InfraHostService { return this.infraHostDAO.save(infraHost); } - public InfraHost read(Long id) throws OverflowException { + public InfraHost read(Long id) throws OverflowException { return this.infraHostDAO.findOne(id); } - public InfraHost readByIp(String ip) throws OverflowException { + public InfraHost readByIp(String ip) throws OverflowException { return this.infraHostDAO.findByIpv4(ip); } diff --git a/src/main/java/com/loafle/overflow/central/module/infra/service/CentralInfraOSApplicationService.java b/src/main/java/com/loafle/overflow/central/module/infra/service/CentralInfraOSApplicationService.java index 77b81ae..b36e248 100644 --- a/src/main/java/com/loafle/overflow/central/module/infra/service/CentralInfraOSApplicationService.java +++ b/src/main/java/com/loafle/overflow/central/module/infra/service/CentralInfraOSApplicationService.java @@ -20,7 +20,7 @@ public class CentralInfraOSApplicationService implements InfraOSApplicationServi return this.infraOSApplicationDAO.save(infraOSApplication); } - public InfraOSApplication read(Long id)throws OverflowException { + public InfraOSApplication read(Long id) throws OverflowException { return this.infraOSApplicationDAO.findOne(id); } } diff --git a/src/main/java/com/loafle/overflow/central/module/infra/service/CentralInfraOSPortService.java b/src/main/java/com/loafle/overflow/central/module/infra/service/CentralInfraOSPortService.java index 5a3db99..bd74bbf 100644 --- a/src/main/java/com/loafle/overflow/central/module/infra/service/CentralInfraOSPortService.java +++ b/src/main/java/com/loafle/overflow/central/module/infra/service/CentralInfraOSPortService.java @@ -24,7 +24,8 @@ public class CentralInfraOSPortService implements InfraOSPortService { return this.infraOSPortDAO.findOne(id); } - public InfraOSPort readByPort(Long osId, int portNumber, String portType) throws OverflowException { - return this.infraOSPortDAO.findByPort(osId, portNumber, portType); + public InfraOSPort readByInfraOSIDAndPortAndPortType(Long infraOSID, Integer port, String portType) + throws OverflowException { + return this.infraOSPortDAO.findByInfraOSIdAndPortAndPortType(infraOSID, port, portType); } } diff --git a/src/main/java/com/loafle/overflow/central/module/infra/service/CentralInfraService.java b/src/main/java/com/loafle/overflow/central/module/infra/service/CentralInfraService.java index 79d85ac..ba16049 100644 --- a/src/main/java/com/loafle/overflow/central/module/infra/service/CentralInfraService.java +++ b/src/main/java/com/loafle/overflow/central/module/infra/service/CentralInfraService.java @@ -50,32 +50,31 @@ public class CentralInfraService implements InfraService { public Page readAllByDomainID(Long domainID, PageParams pageParams) throws OverflowException { List probeList = this.probeService.readAllByDomainID(domainID); - if(probeList == null || probeList.size() <= 0) { + if (probeList == null || probeList.size() <= 0) { throw new OverflowException("ProbeNotFoundException", new Throwable()); } - Page infraList = this.infraDAO.findAllByProbeList(probeList, PageUtil.getPageRequest(pageParams)); - for (Infra infra: infraList) { + Page infraList = this.infraDAO.findAllByProbeInAndTargetNotNull(probeList, PageUtil.getPageRequest(pageParams)); + for (Infra infra : infraList) { infra.getTarget().setSensors(this.sensorDAO.findAllByTargetId(infra.getTarget().getId())); } return infraList; } - public List readAllTargetByDomainID(Long domainID) throws OverflowException { - List probeList = this.probeService.readAllByDomainID(domainID); + List probes = this.probeService.readAllByDomainID(domainID); - if(probeList == null || probeList.size() <= 0) { + if (probes == null || probes.size() <= 0) { throw new OverflowException("ProbeNotFoundException", new Throwable()); } - return this.infraDAO.findAllTargetByProbeList(probeList); + return this.infraDAO.findAllTargetByProbeIn(probes); } - public List readAllTargetByProbeList(List probeList) throws OverflowException { - return this.infraDAO.findAllTargetByProbeList(probeList); -// return null; + public List readAllTargetByProbes(List probes) throws OverflowException { + return this.infraDAO.findAllTargetByProbeIn(probes); + // return null; } public Infra readByTargetID(Long targetID) throws OverflowException { diff --git a/src/main/java/com/loafle/overflow/central/module/infra/service/CentralInfraServiceService.java b/src/main/java/com/loafle/overflow/central/module/infra/service/CentralInfraServiceService.java index ecb33a2..895758c 100644 --- a/src/main/java/com/loafle/overflow/central/module/infra/service/CentralInfraServiceService.java +++ b/src/main/java/com/loafle/overflow/central/module/infra/service/CentralInfraServiceService.java @@ -24,7 +24,8 @@ public class CentralInfraServiceService implements InfraServiceService { return this.infraServiceDAO.findOne(id); } - public InfraService readByService(Long hostId, int portNumber, String portType) throws OverflowException { - return this.infraServiceDAO.findByService(hostId, portNumber, portType); + public InfraService readByInfraHostIDAndPortAndPortType(Long infraHostID, int port, String portType) + throws OverflowException { + return this.infraServiceDAO.findByInfraHostIdAndPortAndPortType(infraHostID, port, portType); } } diff --git a/src/main/java/com/loafle/overflow/central/module/member/dao/MemberDAO.java b/src/main/java/com/loafle/overflow/central/module/member/dao/MemberDAO.java index 9fcf2b1..5c61481 100644 --- a/src/main/java/com/loafle/overflow/central/module/member/dao/MemberDAO.java +++ b/src/main/java/com/loafle/overflow/central/module/member/dao/MemberDAO.java @@ -2,8 +2,6 @@ package com.loafle.overflow.central.module.member.dao; import com.loafle.overflow.model.member.Member; 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; /** @@ -12,6 +10,5 @@ import org.springframework.stereotype.Repository; @Repository public interface MemberDAO extends JpaRepository { - @Query("select m from Member m WHERE m.email = :signinId") - Member findByEmail(@Param("signinId") String signinId); + Member findByEmail(String email); } diff --git a/src/main/java/com/loafle/overflow/central/module/member/dao/MemberTotpDAO.java b/src/main/java/com/loafle/overflow/central/module/member/dao/MemberTotpDAO.java index 5dbbf8e..3942d5e 100644 --- a/src/main/java/com/loafle/overflow/central/module/member/dao/MemberTotpDAO.java +++ b/src/main/java/com/loafle/overflow/central/module/member/dao/MemberTotpDAO.java @@ -1,10 +1,7 @@ package com.loafle.overflow.central.module.member.dao; -import com.loafle.overflow.model.member.Member; import com.loafle.overflow.model.member.MemberTotp; 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; /** @@ -12,8 +9,7 @@ import org.springframework.stereotype.Repository; */ @Repository public interface MemberTotpDAO extends JpaRepository { - @Query("select m from MemberTotp m WHERE m.secretCode = :secretCode") - MemberTotp findBySecretCode(@Param("secretCode") String secretCode); + MemberTotp findBySecretCode(String secretCode); - MemberTotp findByMember(Member member); + MemberTotp findByMemberEmail(String memberEmail); } diff --git a/src/main/java/com/loafle/overflow/central/module/member/service/CentralMemberService.java b/src/main/java/com/loafle/overflow/central/module/member/service/CentralMemberService.java index 18f433f..4230a23 100644 --- a/src/main/java/com/loafle/overflow/central/module/member/service/CentralMemberService.java +++ b/src/main/java/com/loafle/overflow/central/module/member/service/CentralMemberService.java @@ -61,7 +61,7 @@ public class CentralMemberService implements MemberService { throw new OverflowException("SignInIdNotExistException()", new Throwable()); } - if ( m.getStatus().getId() == 1 ) { + if ( m.getMetaMemberStatus().getId() == 1 ) { throw new OverflowException("EmailNotConfirmedException()", new Throwable()); } @@ -103,8 +103,8 @@ public class CentralMemberService implements MemberService { } member.setPw(passwordEncoder.encode(pw)); - if (member.getStatus() == null) { - member.setStatus(new MetaMemberStatus((short) 1)); + if (member.getMetaMemberStatus() == null) { + member.setMetaMemberStatus(new MetaMemberStatus((short) 1)); } member.setTotpType(false); @@ -204,9 +204,9 @@ public class CentralMemberService implements MemberService { member.setPw(preMember.getPw()); } - if (member.getStatus() == null || member.getStatus().getId() <= 0) { - member.setStatus(new MetaMemberStatus()); - member.getStatus().setId(preMember.getStatus().getId()); + if (member.getMetaMemberStatus() == null || member.getMetaMemberStatus().getId() <= 0) { + member.setMetaMemberStatus(new MetaMemberStatus()); + member.getMetaMemberStatus().setId(preMember.getMetaMemberStatus().getId()); } return this.modify(member); } diff --git a/src/main/java/com/loafle/overflow/central/module/member/service/CentralMemberTotpService.java b/src/main/java/com/loafle/overflow/central/module/member/service/CentralMemberTotpService.java index a3124ad..342edf7 100644 --- a/src/main/java/com/loafle/overflow/central/module/member/service/CentralMemberTotpService.java +++ b/src/main/java/com/loafle/overflow/central/module/member/service/CentralMemberTotpService.java @@ -58,8 +58,8 @@ public class CentralMemberTotpService implements MemberTotpService { return this.totpDAO.findOne(id); } - public boolean checkCodeForMember(Member member, String code) throws OverflowException { - MemberTotp totp = this.totpDAO.findByMember(member); + public boolean checkCodeForMember(String memberEmail, String code) throws OverflowException { + MemberTotp totp = this.totpDAO.findByMemberEmail(memberEmail); if (null == totp && (totp.getSecretCode() == null || totp.getSecretCode().equals(""))) { throw new OverflowException("SignInIdNotExistException", new Throwable()); } diff --git a/src/main/java/com/loafle/overflow/central/module/meta/dao/MetaCrawlerInputItemDAO.java b/src/main/java/com/loafle/overflow/central/module/meta/dao/MetaCrawlerInputItemDAO.java index 4427106..bf4f09d 100644 --- a/src/main/java/com/loafle/overflow/central/module/meta/dao/MetaCrawlerInputItemDAO.java +++ b/src/main/java/com/loafle/overflow/central/module/meta/dao/MetaCrawlerInputItemDAO.java @@ -1,6 +1,5 @@ package com.loafle.overflow.central.module.meta.dao; -import com.loafle.overflow.model.meta.MetaCrawler; import com.loafle.overflow.model.meta.MetaCrawlerInputItem; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; @@ -12,5 +11,5 @@ import java.util.List; */ @Repository public interface MetaCrawlerInputItemDAO extends JpaRepository { - List findAllByCrawler(MetaCrawler crawler); + List findAllByMetaCrawlerId(Short metaCrawlerId); } diff --git a/src/main/java/com/loafle/overflow/central/module/meta/dao/MetaInfraVendorDAO.java b/src/main/java/com/loafle/overflow/central/module/meta/dao/MetaInfraVendorDAO.java index b6b72d3..c35149f 100644 --- a/src/main/java/com/loafle/overflow/central/module/meta/dao/MetaInfraVendorDAO.java +++ b/src/main/java/com/loafle/overflow/central/module/meta/dao/MetaInfraVendorDAO.java @@ -1,6 +1,5 @@ package com.loafle.overflow.central.module.meta.dao; -import com.loafle.overflow.model.meta.MetaInfraType; import com.loafle.overflow.model.meta.MetaInfraVendor; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; @@ -12,5 +11,5 @@ import java.util.List; */ @Repository public interface MetaInfraVendorDAO extends JpaRepository { - List findAllByInfraType(MetaInfraType infraType); + List findAllByMetaInfraTypeId(Integer MetaInfraTypeId); } diff --git a/src/main/java/com/loafle/overflow/central/module/meta/dao/MetaProbePackageDAO.java b/src/main/java/com/loafle/overflow/central/module/meta/dao/MetaProbePackageDAO.java index c54d413..2ecf4d5 100644 --- a/src/main/java/com/loafle/overflow/central/module/meta/dao/MetaProbePackageDAO.java +++ b/src/main/java/com/loafle/overflow/central/module/meta/dao/MetaProbePackageDAO.java @@ -1,6 +1,5 @@ package com.loafle.overflow.central.module.meta.dao; -import com.loafle.overflow.model.meta.MetaProbeOs; import com.loafle.overflow.model.meta.MetaProbePackage; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; @@ -12,5 +11,5 @@ import java.util.List; */ @Repository public interface MetaProbePackageDAO extends JpaRepository { - List findAllByOs(MetaProbeOs metaProbeOs); + List findAllByMetaProbeOsId(Short metaProbeOsId); } diff --git a/src/main/java/com/loafle/overflow/central/module/meta/dao/MetaSensorDisplayItemDAO.java b/src/main/java/com/loafle/overflow/central/module/meta/dao/MetaSensorDisplayItemDAO.java index 466475a..2e0e731 100644 --- a/src/main/java/com/loafle/overflow/central/module/meta/dao/MetaSensorDisplayItemDAO.java +++ b/src/main/java/com/loafle/overflow/central/module/meta/dao/MetaSensorDisplayItemDAO.java @@ -1,6 +1,5 @@ package com.loafle.overflow.central.module.meta.dao; -import com.loafle.overflow.model.meta.MetaCrawler; import com.loafle.overflow.model.meta.MetaSensorDisplayItem; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; @@ -12,5 +11,5 @@ import java.util.List; */ @Repository public interface MetaSensorDisplayItemDAO extends JpaRepository { - public List findAllByCrawler(MetaCrawler crawler); + public List findAllByMetaCrawlerId(Short metaCrawlerId); } diff --git a/src/main/java/com/loafle/overflow/central/module/meta/dao/MetaSensorDisplayMappingDAO.java b/src/main/java/com/loafle/overflow/central/module/meta/dao/MetaSensorDisplayMappingDAO.java index 66db4c7..73d9834 100644 --- a/src/main/java/com/loafle/overflow/central/module/meta/dao/MetaSensorDisplayMappingDAO.java +++ b/src/main/java/com/loafle/overflow/central/module/meta/dao/MetaSensorDisplayMappingDAO.java @@ -1,11 +1,8 @@ package com.loafle.overflow.central.module.meta.dao; -import com.loafle.overflow.model.meta.MetaSensorDisplayItem; import com.loafle.overflow.model.meta.MetaSensorDisplayMapping; import com.loafle.overflow.model.meta.MetaSensorItemKey; 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; @@ -15,6 +12,5 @@ import java.util.List; */ @Repository public interface MetaSensorDisplayMappingDAO extends JpaRepository { - @Query("SELECT m.itemKey from MetaSensorDisplayMapping m where m.displayItem = (:displayItem)") - public List findAllMetaSensorItemKeyByDisplayItem(@Param("displayItem") MetaSensorDisplayItem displayItem); + public List findAllMetaSensorItemKeyByMetaSensorDisplayItemId(Long metaSensorDisplayItemId); } diff --git a/src/main/java/com/loafle/overflow/central/module/meta/dao/MetaSensorItemKeyDAO.java b/src/main/java/com/loafle/overflow/central/module/meta/dao/MetaSensorItemKeyDAO.java index e930dda..2175ab4 100644 --- a/src/main/java/com/loafle/overflow/central/module/meta/dao/MetaSensorItemKeyDAO.java +++ b/src/main/java/com/loafle/overflow/central/module/meta/dao/MetaSensorItemKeyDAO.java @@ -1,6 +1,5 @@ package com.loafle.overflow.central.module.meta.dao; -import com.loafle.overflow.model.meta.MetaCrawler; import com.loafle.overflow.model.meta.MetaSensorItemKey; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; @@ -12,6 +11,5 @@ import java.util.List; */ @Repository public interface MetaSensorItemKeyDAO extends JpaRepository { -// @Query("SELECT msik.item.id, msik.key from MetaSensorItemKey msik WHERE msik.crawler.id = (:metaCrawler.id)") - List findAllByCrawler(MetaCrawler metaCrawler); + List findAllByMetaCrawlerId(Short metaCrawlerId); } diff --git a/src/main/java/com/loafle/overflow/central/module/meta/dao/MetaVendorCrawlerDAO.java b/src/main/java/com/loafle/overflow/central/module/meta/dao/MetaVendorCrawlerDAO.java index 459954b..bdcbdd2 100644 --- a/src/main/java/com/loafle/overflow/central/module/meta/dao/MetaVendorCrawlerDAO.java +++ b/src/main/java/com/loafle/overflow/central/module/meta/dao/MetaVendorCrawlerDAO.java @@ -1,6 +1,5 @@ package com.loafle.overflow.central.module.meta.dao; -import com.loafle.overflow.model.meta.MetaInfraVendor; import com.loafle.overflow.model.meta.MetaVendorCrawler; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; @@ -11,6 +10,6 @@ import java.util.List; * Created by insanity on 17. 6. 23. */ @Repository -public interface MetaVendorCrawlerDAO extends JpaRepository{ - List findAllByInfraVendor(MetaInfraVendor infraVendor); +public interface MetaVendorCrawlerDAO extends JpaRepository { + List findAllByMetaInfraVendorId(Integer metaInfraVendorId); } diff --git a/src/main/java/com/loafle/overflow/central/module/meta/service/CentralMetaCrawlerInputItemService.java b/src/main/java/com/loafle/overflow/central/module/meta/service/CentralMetaCrawlerInputItemService.java index b621cc5..6263f48 100644 --- a/src/main/java/com/loafle/overflow/central/module/meta/service/CentralMetaCrawlerInputItemService.java +++ b/src/main/java/com/loafle/overflow/central/module/meta/service/CentralMetaCrawlerInputItemService.java @@ -19,7 +19,7 @@ public class CentralMetaCrawlerInputItemService implements MetaCrawlerInputItemS @Autowired private MetaCrawlerInputItemDAO crawlerInputItemDAO; - public List readAllByMetaCrawler(MetaCrawler metaCrawler) throws OverflowException { - return this.crawlerInputItemDAO.findAllByCrawler(metaCrawler); + public List readAllByMetaCrawlerID(Short metaCrawlerID) throws OverflowException { + return this.crawlerInputItemDAO.findAllByMetaCrawlerId(metaCrawlerID); } } diff --git a/src/main/java/com/loafle/overflow/central/module/meta/service/CentralMetaHistoryTypeService.java b/src/main/java/com/loafle/overflow/central/module/meta/service/CentralMetaHistoryTypeService.java index ee4c284..2004a30 100644 --- a/src/main/java/com/loafle/overflow/central/module/meta/service/CentralMetaHistoryTypeService.java +++ b/src/main/java/com/loafle/overflow/central/module/meta/service/CentralMetaHistoryTypeService.java @@ -27,7 +27,7 @@ public class CentralMetaHistoryTypeService implements MetaHistoryTypeService { return this.hisotyTypeDAO.save(type); } - public List registAll(List types) throws OverflowException { - return this.hisotyTypeDAO.save(types); + public List registAll(List metaHistoryTypes) throws OverflowException { + return this.hisotyTypeDAO.save(metaHistoryTypes); } } diff --git a/src/main/java/com/loafle/overflow/central/module/meta/service/CentralMetaInfraVendorService.java b/src/main/java/com/loafle/overflow/central/module/meta/service/CentralMetaInfraVendorService.java index 471eba7..b15ce2c 100644 --- a/src/main/java/com/loafle/overflow/central/module/meta/service/CentralMetaInfraVendorService.java +++ b/src/main/java/com/loafle/overflow/central/module/meta/service/CentralMetaInfraVendorService.java @@ -2,7 +2,6 @@ package com.loafle.overflow.central.module.meta.service; import com.loafle.overflow.central.module.meta.dao.MetaInfraVendorDAO; import com.loafle.overflow.core.exception.OverflowException; -import com.loafle.overflow.model.meta.MetaInfraType; import com.loafle.overflow.model.meta.MetaInfraVendor; import com.loafle.overflow.service.central.meta.MetaInfraVendorService; import org.springframework.beans.factory.annotation.Autowired; @@ -20,8 +19,8 @@ public class CentralMetaInfraVendorService implements MetaInfraVendorService { @Autowired private MetaInfraVendorDAO infraVendorDAO; - public List readAllByMetaInfraType(MetaInfraType infraType) throws OverflowException { - return this.infraVendorDAO.findAllByInfraType(infraType); + public List readAllByMetaInfraTypeID(Integer metaInfraTypeID) throws OverflowException { + return this.infraVendorDAO.findAllByMetaInfraTypeId(metaInfraTypeID); } } diff --git a/src/main/java/com/loafle/overflow/central/module/meta/service/CentralMetaProbePackageService.java b/src/main/java/com/loafle/overflow/central/module/meta/service/CentralMetaProbePackageService.java index 504673e..4f0dcb3 100644 --- a/src/main/java/com/loafle/overflow/central/module/meta/service/CentralMetaProbePackageService.java +++ b/src/main/java/com/loafle/overflow/central/module/meta/service/CentralMetaProbePackageService.java @@ -19,7 +19,7 @@ public class CentralMetaProbePackageService implements MetaProbePackageService { @Autowired private MetaProbePackageDAO probePackageDAO; - public List readAllByOs(MetaProbeOs metaProbeOs) throws OverflowException { - return this.probePackageDAO.findAllByOs(metaProbeOs); + public List readAllByMetaProbeOsID(Short metaProbeOsID) throws OverflowException { + return this.probePackageDAO.findAllByMetaProbeOsId(metaProbeOsID); } } diff --git a/src/main/java/com/loafle/overflow/central/module/meta/service/CentralMetaSensorDisplayItemService.java b/src/main/java/com/loafle/overflow/central/module/meta/service/CentralMetaSensorDisplayItemService.java index 7a1a011..507c55f 100644 --- a/src/main/java/com/loafle/overflow/central/module/meta/service/CentralMetaSensorDisplayItemService.java +++ b/src/main/java/com/loafle/overflow/central/module/meta/service/CentralMetaSensorDisplayItemService.java @@ -26,7 +26,7 @@ public class CentralMetaSensorDisplayItemService implements MetaSensorDisplayIte return this.displayItemDAO.findOne(id); } - public List readAllByCrawler(MetaCrawler crawler) throws OverflowException { - return this.displayItemDAO.findAllByCrawler(crawler); + public List readAllByCrawlerID(Short metaCrawlerID) throws OverflowException { + return this.displayItemDAO.findAllByMetaCrawlerId(metaCrawlerID); } } diff --git a/src/main/java/com/loafle/overflow/central/module/meta/service/CentralMetaSensorDisplayMappingService.java b/src/main/java/com/loafle/overflow/central/module/meta/service/CentralMetaSensorDisplayMappingService.java index c700e1c..dad08db 100644 --- a/src/main/java/com/loafle/overflow/central/module/meta/service/CentralMetaSensorDisplayMappingService.java +++ b/src/main/java/com/loafle/overflow/central/module/meta/service/CentralMetaSensorDisplayMappingService.java @@ -23,7 +23,7 @@ public class CentralMetaSensorDisplayMappingService implements MetaSensorDisplay return this.mappingDAO.save(m); } - public List readAllMetaSensorItemKeyByDisplayItem(MetaSensorDisplayItem displayItem) throws OverflowException { - return this.mappingDAO.findAllMetaSensorItemKeyByDisplayItem(displayItem); + public List readAllMetaSensorItemKeyByDisplayItemID(Long metaSensorDisplayItemID) throws OverflowException { + return this.mappingDAO.findAllMetaSensorItemKeyByMetaSensorDisplayItemId(metaSensorDisplayItemID); } } diff --git a/src/main/java/com/loafle/overflow/central/module/meta/service/CentralMetaSensorItemKeyService.java b/src/main/java/com/loafle/overflow/central/module/meta/service/CentralMetaSensorItemKeyService.java index 2bff702..690e495 100644 --- a/src/main/java/com/loafle/overflow/central/module/meta/service/CentralMetaSensorItemKeyService.java +++ b/src/main/java/com/loafle/overflow/central/module/meta/service/CentralMetaSensorItemKeyService.java @@ -2,7 +2,6 @@ package com.loafle.overflow.central.module.meta.service; import com.loafle.overflow.central.module.meta.dao.MetaSensorItemKeyDAO; import com.loafle.overflow.core.exception.OverflowException; -import com.loafle.overflow.model.meta.MetaCrawler; import com.loafle.overflow.model.meta.MetaSensorItemKey; import com.loafle.overflow.service.central.meta.MetaSensorItemKeyService; import org.springframework.beans.factory.annotation.Autowired; @@ -22,19 +21,18 @@ public class CentralMetaSensorItemKeyService implements MetaSensorItemKeyService @Autowired private MetaSensorItemKeyDAO metaSensorItemKeyDAO; - public List readAllByCrawler(MetaCrawler metaCrawler) throws OverflowException { - return this.metaSensorItemKeyDAO.findAllByCrawler(metaCrawler); + public List readAllByMetaCrawlerID(Short metaCrawlerID) throws OverflowException { + return this.metaSensorItemKeyDAO.findAllByMetaCrawlerId(metaCrawlerID); } - - public Map readAllMapByCrawler(MetaCrawler metaCrawler) throws OverflowException { + public Map readAllMapByMetaCrawlerID(Short metaCrawlerID) throws OverflowException { Map resultMap = new HashMap<>(); - List resultList = this.metaSensorItemKeyDAO.findAllByCrawler(metaCrawler); + List resultList = this.metaSensorItemKeyDAO.findAllByMetaCrawlerId(metaCrawlerID); - for(MetaSensorItemKey oa : resultList) { - resultMap.put(oa.getItem().getId(), oa); + for (MetaSensorItemKey oa : resultList) { + resultMap.put(oa.getMetaSensorItem().getId(), oa); } return resultMap; diff --git a/src/main/java/com/loafle/overflow/central/module/meta/service/CentralMetaVendorCrawlerService.java b/src/main/java/com/loafle/overflow/central/module/meta/service/CentralMetaVendorCrawlerService.java index b3fe497..61038b6 100644 --- a/src/main/java/com/loafle/overflow/central/module/meta/service/CentralMetaVendorCrawlerService.java +++ b/src/main/java/com/loafle/overflow/central/module/meta/service/CentralMetaVendorCrawlerService.java @@ -20,9 +20,9 @@ public class CentralMetaVendorCrawlerService implements MetaVendorCrawlerService @Autowired private MetaVendorCrawlerDAO crawlerDAO; - public List readAllByInfraVendor(MetaInfraVendor infraVendor) throws OverflowException { + public List readAllByMetaInfraVendorID(Integer metaInfraVendorID) throws OverflowException { - return this.crawlerDAO.findAllByInfraVendor(infraVendor); + return this.crawlerDAO.findAllByMetaInfraVendorId(metaInfraVendorID); } public MetaVendorCrawler regist(MetaVendorCrawler metaVendorCrawler) throws OverflowException { 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 34629d3..ff7c4e1 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 @@ -3,8 +3,6 @@ package com.loafle.overflow.central.module.noauthprobe.dao; 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; import org.springframework.stereotype.Repository; import java.util.List; @@ -17,8 +15,7 @@ public interface NoAuthProbeDAO extends JpaRepository { NoAuthProbe findByTempProbeKey(String tempProbeKey); - @Query("SELECT n FROM NoAuthProbe n WHERE n.domain.id = :domainID and n.status.id = 3") // 3 = Process - List findAllByDomainId(@Param("domainID") Long domainID); + List findAllByDomainIdAndMetaNoAuthProbeStatusId(Long domainID, Short metaNoAuthProbeStatusId); // NoAuthProbeDeprecate findByTempKey(NoAuthProbeDeprecate noAuthAgent); // List findAllByNoAuth(NoAuthProbeDeprecate noAuthAgent); diff --git a/src/main/java/com/loafle/overflow/central/module/noauthprobe/service/CentralNoAuthProbeService.java b/src/main/java/com/loafle/overflow/central/module/noauthprobe/service/CentralNoAuthProbeService.java index 5b9ed5c..42d45c9 100644 --- a/src/main/java/com/loafle/overflow/central/module/noauthprobe/service/CentralNoAuthProbeService.java +++ b/src/main/java/com/loafle/overflow/central/module/noauthprobe/service/CentralNoAuthProbeService.java @@ -85,7 +85,7 @@ public class CentralNoAuthProbeService implements NoAuthProbeService { noAuthProbe.setDomain(apiKey.getDomain()); noAuthProbe.setTempProbeKey(GenerateKey.getKey()); - noAuthProbe.setStatus(new MetaNoAuthProbeStatus((short) 3)); + noAuthProbe.setMetaNoAuthProbeStatus(new MetaNoAuthProbeStatus((short) 3)); messagePublisher.publishToDomainMembers(apiKey.getDomain().getId(), "NoAuthProbeService.regist", noAuthProbe); @@ -94,7 +94,7 @@ public class CentralNoAuthProbeService implements NoAuthProbeService { public List readAllByDomainID(Long domainID) throws OverflowException { - return this.noAuthProbeDAO.findAllByDomainId(domainID); + return this.noAuthProbeDAO.findAllByDomainIdAndMetaNoAuthProbeStatusId(domainID, (short) 3); } public NoAuthProbe read(Long id) { @@ -119,15 +119,17 @@ public class CentralNoAuthProbeService implements NoAuthProbeService { InfraHost host = this.newInfraHost(os, noAuthProbeDescription.getNetwork()); this.newProbeHost(host, probe); - noAuthProbe.setStatus(new MetaNoAuthProbeStatus((short) 1)); + noAuthProbe.setMetaNoAuthProbeStatus(new MetaNoAuthProbeStatus((short) 1)); this.noAuthProbeDAO.save(noAuthProbe); - messagePublisher.publishToNoAuthProbe(noAuthProbe.getTempProbeKey(), "NoAuthProbeService.Accept", probe.getProbeKey()); + messagePublisher.publishToNoAuthProbe(noAuthProbe.getTempProbeKey(), "NoAuthProbeService.Accept", + probe.getProbeKey()); return this.readAllByDomainID(noAuthProbe.getDomain().getId()); } - private Probe newProbe(NoAuthProbe noauthprobe, NoAuthProbeDescription noAuthProbeDescription) throws OverflowException { + private Probe newProbe(NoAuthProbe noauthprobe, NoAuthProbeDescription noAuthProbeDescription) + throws OverflowException { BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder(); String encryptKey = passwordEncoder.encode(UUID.randomUUID().toString()); @@ -142,7 +144,7 @@ public class CentralNoAuthProbeService implements NoAuthProbeService { probe.setDomain(new Domain(apiKey.getDomain().getId())); probe.setAuthorizeMember(new Member(domainMember.getMember().getId())); probe.setTargetCount(0); - probe.setStatus(new MetaProbeStatus((short) 1)); + probe.setMetaProbeStatus(new MetaProbeStatus((short) 1)); String dispName = noAuthProbeDescription.getHost().getName(); dispName += " probe"; @@ -156,31 +158,30 @@ public class CentralNoAuthProbeService implements NoAuthProbeService { } private InfraMachine newInfraMachine(NoAuthProbe noauthprobe) throws OverflowException { - MetaInfraType infraType = new MetaInfraType(); - infraType.setId(1); + MetaInfraType metaInfraType = new MetaInfraType(1); InfraMachine infraMachine = new InfraMachine(); infraMachine.setMeta(noauthprobe.getDescription()); - infraMachine.setInfraType(infraType); + infraMachine.setMetaInfraType(metaInfraType); return this.infraMachineService.regist(infraMachine); } - private InfraOS newInfraOS(InfraMachine infraMachine, NoAuthProbeDescriptionHost noAuthProbeDescriptionHost) throws OverflowException { - MetaInfraType infraType = new MetaInfraType(); - infraType.setId(3); + private InfraOS newInfraOS(InfraMachine infraMachine, NoAuthProbeDescriptionHost noAuthProbeDescriptionHost) + throws OverflowException { + MetaInfraType metaInfraType = new MetaInfraType(3); InfraOS infraOS = new InfraOS(); - infraOS.setMachine(infraMachine); - infraOS.setInfraType(infraType); - infraOS.setVendor(MetaInfraVendor.CreateInfraVendorByOS(noAuthProbeDescriptionHost.getOS())); + infraOS.setInfraMachine(infraMachine); + infraOS.setMetaInfraType(metaInfraType); + infraOS.setMetaInfraVendor(MetaInfraVendor.CreateInfraVendorByOS(noAuthProbeDescriptionHost.getOS())); return this.infraOSService.regist(infraOS); } - private InfraHost newInfraHost(InfraOS infraOS, NoAuthProbeDescriptionNetwork noAuthProbeDescriptionNetwork) throws OverflowException { - MetaInfraType infraType = new MetaInfraType(); - infraType.setId(2); + private InfraHost newInfraHost(InfraOS infraOS, NoAuthProbeDescriptionNetwork noAuthProbeDescriptionNetwork) + throws OverflowException { + MetaInfraType metaInfraType = new MetaInfraType(2); InfraHost infraHost = new InfraHost(); String addrStr = noAuthProbeDescriptionNetwork.getAddress(); @@ -188,8 +189,8 @@ public class CentralNoAuthProbeService implements NoAuthProbeService { infraHost.setIpv4(addrArr[0]); infraHost.setMac(noAuthProbeDescriptionNetwork.getMacAddress()); - infraHost.setOs(infraOS); - infraHost.setInfraType(infraType); + infraHost.setInfraOS(infraOS); + infraHost.setMetaInfraType(metaInfraType); return this.infraHostService.regist(infraHost); } @@ -206,7 +207,7 @@ public class CentralNoAuthProbeService implements NoAuthProbeService { public List denyNoauthProbe(Long noAuthProbeID) throws OverflowException { NoAuthProbe noAuthProbe = this.noAuthProbeDAO.findOne(noAuthProbeID); - noAuthProbe.setStatus(new MetaNoAuthProbeStatus((short) 2)); + noAuthProbe.setMetaNoAuthProbeStatus(new MetaNoAuthProbeStatus((short) 2)); this.noAuthProbeDAO.save(noAuthProbe); messagePublisher.publishToNoAuthProbe(noAuthProbe.getTempProbeKey(), "NoAuthProbeService.Deny"); @@ -224,7 +225,8 @@ public class CentralNoAuthProbeService implements NoAuthProbeService { noAuthProbe.setConnectAddress(connectAddress); noAuthProbe = this.noAuthProbeDAO.save(noAuthProbe); - messagePublisher.publishToDomainMembers(noAuthProbe.getDomain().getId(), "NoAuthProbeService.onConnect", noAuthProbe); + messagePublisher.publishToDomainMembers(noAuthProbe.getDomain().getId(), "NoAuthProbeService.onConnect", + noAuthProbe); } public void onDisconnect(String tempKey) throws OverflowException { @@ -233,7 +235,8 @@ public class CentralNoAuthProbeService implements NoAuthProbeService { noAuthProbe.setConnectAddress(null); noAuthProbe = this.noAuthProbeDAO.save(noAuthProbe); - messagePublisher.publishToDomainMembers(noAuthProbe.getDomain().getId(), "NoAuthProbeService.onDisconnect", noAuthProbe); + messagePublisher.publishToDomainMembers(noAuthProbe.getDomain().getId(), "NoAuthProbeService.onDisconnect", + 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 d9c4a4d..aa654e6 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,13 +1,10 @@ package com.loafle.overflow.central.module.notification.dao; -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; -import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import java.util.List; @@ -16,15 +13,13 @@ import java.util.List; * Created by insanity on 17. 8. 25. */ @Repository -public interface NotificationDAO extends JpaRepository { +public interface NotificationDAO extends JpaRepository { - List findAllByMember(Member member); + List findAllByMemberEmail(String memberEmail); - Page findAllByMember(Member member, Pageable pageRequest); + Page findAllByMemberEmail(String memberEmail, Pageable pageRequest); - @Query("SELECT n FROM Notification n WHERE n.member.id = :#{#member.id} and n.confirmDate IS NULL") - Page findAllUnconfirmedByMember(@Param("member") Member member, Pageable pageRequest); + Page findAllByMemberEmailAndConfirmDateNull(String memberEmail, Pageable pageRequest); - @Query("SELECT COUNT(n) FROM Notification n WHERE n.member.id = :#{#member.id} and n.confirmDate IS NULL") - int findAllUnconfirmedCountByMember(@Param("member") Member member); + Long countByMemberEmailAndConfirmDateNull(String memberEmail); } diff --git a/src/main/java/com/loafle/overflow/central/module/notification/service/CentralNotificationService.java b/src/main/java/com/loafle/overflow/central/module/notification/service/CentralNotificationService.java index 07b90f9..8e2d346 100644 --- a/src/main/java/com/loafle/overflow/central/module/notification/service/CentralNotificationService.java +++ b/src/main/java/com/loafle/overflow/central/module/notification/service/CentralNotificationService.java @@ -28,37 +28,42 @@ public class CentralNotificationService implements NotificationService { return this.notificationDAO.save(notification); } - public Page readAllByMember(Member member, PageParams pageParams) throws OverflowException { - return this.notificationDAO.findAllByMember(member, PageUtil.getPageRequest(pageParams)); + public Page readAllByMemberEmail(String memberEmail, PageParams pageParams) throws OverflowException { + return this.notificationDAO.findAllByMemberEmail(memberEmail, PageUtil.getPageRequest(pageParams)); } - public Page readAllUnconfirmedByMember(Member member, PageParams pageParams) throws OverflowException { - return this.notificationDAO.findAllUnconfirmedByMember(member, PageUtil.getPageRequest(pageParams)); + public Page readAllUnconfirmedByMemberEmail(String memberEmail, PageParams pageParams) + throws OverflowException { + return this.notificationDAO.findAllByMemberEmailAndConfirmDateNull(memberEmail, + PageUtil.getPageRequest(pageParams)); } - public int readUnconfirmedCount(Member member) throws OverflowException { - return this.notificationDAO.findAllUnconfirmedCountByMember(member); + public Long readUnconfirmedCountByMemberEmail(String memberEmail) throws OverflowException { + return this.notificationDAO.countByMemberEmailAndConfirmDateNull(memberEmail); } - public Page markAllAsRead(Member member, PageParams pageParams) throws OverflowException { - List list = this.notificationDAO.findAllByMember(member); + public Page markAllAsReadByMemberEmail(String memberEmail, PageParams pageParams) + throws OverflowException { + List list = this.notificationDAO.findAllByMemberEmail(memberEmail); for (Notification n : list) { n.setConfirmDate(new Date()); } this.notificationDAO.save(list); - return this.readAllByMember(member, pageParams); + return this.readAllByMemberEmail(memberEmail, pageParams); } - public Page markAllAsUnread(Member member, PageParams pageParams) throws OverflowException { - List list = this.notificationDAO.findAllByMember(member); + public Page markAllAsUnreadMemberEmail(String memberEmail, PageParams pageParams) + throws OverflowException { + List list = this.notificationDAO.findAllByMemberEmail(memberEmail); for (Notification n : list) { n.setConfirmDate(null); } this.notificationDAO.save(list); - return this.readAllByMember(member, pageParams); + return this.readAllByMemberEmail(memberEmail, pageParams); } - public Notification markAsRead(Notification notification) throws OverflowException { + public Notification markAsRead(Long notificationID) throws OverflowException { + Notification notification = this.notificationDAO.findOne(notificationID); notification.setConfirmDate(new Date()); return this.notificationDAO.save(notification); } 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 6da4760..f36d96f 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 @@ -5,11 +5,8 @@ import java.util.List; import com.loafle.overflow.model.probe.ProbeHost; 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; - /** * Created by snoop on 17. 8. 21. */ @@ -17,6 +14,5 @@ import org.springframework.stereotype.Repository; public interface ProbeHostDAO extends JpaRepository { ProbeHost findByProbeId(Long probeID); - @Query("SELECT h FROM ProbeHost h WHERE h.probe.domain.id = (:domainID)") - List findAllByDomainId(@Param("domainID")Long domainID); + List findAllByProbeDomainId(Long domainID); } 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 98690ce..fc528d3 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 @@ -12,5 +12,5 @@ import com.loafle.overflow.model.probe.ProbeTask; */ @Repository public interface ProbeTaskDAO extends JpaRepository { - List findAllByProbeId(Long probeID); + List findAllByProbeId(Long probeId); } diff --git a/src/main/java/com/loafle/overflow/central/module/probe/service/CentralProbeHostService.java b/src/main/java/com/loafle/overflow/central/module/probe/service/CentralProbeHostService.java index f940915..d1dec5b 100644 --- a/src/main/java/com/loafle/overflow/central/module/probe/service/CentralProbeHostService.java +++ b/src/main/java/com/loafle/overflow/central/module/probe/service/CentralProbeHostService.java @@ -4,8 +4,6 @@ import java.util.List; import com.loafle.overflow.central.module.probe.dao.ProbeHostDAO; 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.model.probe.ProbeHost; import com.loafle.overflow.service.central.probe.ProbeHostService; @@ -32,9 +30,8 @@ public class CentralProbeHostService implements ProbeHostService { public ProbeHost regist(ProbeHost probeHost) throws OverflowException { return this.probeHostDAO.save(probeHost); } - + public List readAllByDomainID(Long domainID) throws OverflowException { - return this.probeHostDAO.findAllByDomainId(domainID); + return this.probeHostDAO.findAllByProbeDomainId(domainID); } } - 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 index c07e8b7..799a809 100644 --- 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 @@ -3,7 +3,6 @@ package com.loafle.overflow.central.module.probe.service; import com.loafle.overflow.central.commons.service.MessagePublisher; 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; diff --git a/src/main/java/com/loafle/overflow/central/module/probe/service/CentralProbeTaskService.java b/src/main/java/com/loafle/overflow/central/module/probe/service/CentralProbeTaskService.java index 31c74e5..216cb4a 100644 --- a/src/main/java/com/loafle/overflow/central/module/probe/service/CentralProbeTaskService.java +++ b/src/main/java/com/loafle/overflow/central/module/probe/service/CentralProbeTaskService.java @@ -2,7 +2,6 @@ package com.loafle.overflow.central.module.probe.service; import com.loafle.overflow.central.module.probe.dao.ProbeTaskDAO; 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; 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 d1efeee..213aa26 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,11 +1,8 @@ package com.loafle.overflow.central.module.sensor.dao; - import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; 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; @@ -19,8 +16,8 @@ import com.loafle.overflow.model.target.Target; @Repository public interface SensorDAO extends JpaRepository { Page findAllByTargetId(Long targetID, Pageable pageable); + List findAllByTargetId(Long targetID); - @Query("SELECT s from Sensor s WHERE s.target in (:targetList)") - Page findAllByTargetList(@Param("targetList") List targetList, Pageable pageable); + Page findAllByTargetIn(List targets, Pageable pageable); } 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 594c227..f7b3ff0 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,6 +1,5 @@ package com.loafle.overflow.central.module.sensor.dao; -import com.loafle.overflow.model.sensor.Sensor; import com.loafle.overflow.model.sensor.SensorItem; import org.springframework.data.domain.Page; @@ -13,5 +12,5 @@ import org.springframework.stereotype.Repository; */ @Repository public interface SensorItemDAO extends JpaRepository { - Page findAllBySensor(Sensor sensor, Pageable pageable); + Page findAllBySensorId(Long sensorId, Pageable pageable); } 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 753bd69..4081cf0 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 @@ -1,6 +1,5 @@ package com.loafle.overflow.central.module.sensor.dao; -import com.loafle.overflow.model.meta.MetaSensorDisplayItem; import com.loafle.overflow.model.meta.MetaSensorItemKey; import com.loafle.overflow.model.sensor.SensorItemDependency; @@ -15,5 +14,5 @@ import java.util.List; @Repository public interface SensorItemDependencyDAO extends JpaRepository { - List findAllByDisplayItem(MetaSensorDisplayItem displayItem); + List findAllByMetaSensorDisplayItemId(Long metaSensorDisplayItemId); } diff --git a/src/main/java/com/loafle/overflow/central/module/sensor/service/CentralSensorItemDependencyService.java b/src/main/java/com/loafle/overflow/central/module/sensor/service/CentralSensorItemDependencyService.java index e345698..fdc92e0 100644 --- a/src/main/java/com/loafle/overflow/central/module/sensor/service/CentralSensorItemDependencyService.java +++ b/src/main/java/com/loafle/overflow/central/module/sensor/service/CentralSensorItemDependencyService.java @@ -28,17 +28,19 @@ public class CentralSensorItemDependencyService implements SensorItemDependencyS return this.sensorItemDependencyDAO.save(dependency); } - public List readAllByDisplayItem(MetaSensorDisplayItem displayItem) throws OverflowException { - return this.sensorItemDependencyDAO.findAllByDisplayItem(displayItem); + public List readAllMetaSensorItemKeyByMetaSensorDisplayItemID(Long metaSensorDisplayItemID) + throws OverflowException { + return this.sensorItemDependencyDAO.findAllByMetaSensorDisplayItemId(metaSensorDisplayItemID); } - public Map> readAllByDisplayItems( - List displayItems) throws OverflowException { + public Map> readAllMapByMetaSensorDisplayItems( + List metaSensorDisplayItems) throws OverflowException { Map> map = new HashMap>(); - for (MetaSensorDisplayItem displayItem : displayItems) { - List itemKeys = this.sensorItemDependencyDAO.findAllByDisplayItem(displayItem); + for (MetaSensorDisplayItem displayItem : metaSensorDisplayItems) { + List itemKeys = this.sensorItemDependencyDAO + .findAllByMetaSensorDisplayItemId(displayItem.getId()); map.put(displayItem.getKey(), itemKeys); } diff --git a/src/main/java/com/loafle/overflow/central/module/sensor/service/CentralSensorItemService.java b/src/main/java/com/loafle/overflow/central/module/sensor/service/CentralSensorItemService.java index 80149d0..2de6d2c 100644 --- a/src/main/java/com/loafle/overflow/central/module/sensor/service/CentralSensorItemService.java +++ b/src/main/java/com/loafle/overflow/central/module/sensor/service/CentralSensorItemService.java @@ -30,7 +30,7 @@ public class CentralSensorItemService implements SensorItemService { @Transactional public SensorItem regist(SensorItem sensorItem) throws OverflowException { 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); } @@ -38,7 +38,7 @@ public class CentralSensorItemService implements SensorItemService { @Transactional public boolean registAll(List sensorItemList) throws OverflowException { 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; @@ -48,14 +48,14 @@ public class CentralSensorItemService implements SensorItemService { return this.sensorItemDAO.findOne(Long.valueOf(id)); } - public Page readAllBySensor(Sensor sensor, PageParams pageParams) throws OverflowException { - return this.sensorItemDAO.findAllBySensor(sensor, PageUtil.getPageRequest(pageParams)); + public Page readAllBySensorID(Long sensorID, PageParams pageParams) throws OverflowException { + return this.sensorItemDAO.findAllBySensorId(sensorID, PageUtil.getPageRequest(pageParams)); } @Transactional public void remove(SensorItem sensorItem) throws OverflowException { 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/CentralSensorService.java b/src/main/java/com/loafle/overflow/central/module/sensor/service/CentralSensorService.java index fc26dc6..75a3946 100644 --- a/src/main/java/com/loafle/overflow/central/module/sensor/service/CentralSensorService.java +++ b/src/main/java/com/loafle/overflow/central/module/sensor/service/CentralSensorService.java @@ -63,13 +63,13 @@ public class CentralSensorService implements SensorService { throw new OverflowException("", new Throwable()); } - List targetList = this.infraService.readAllTargetByProbeList(probeList); + List targetList = this.infraService.readAllTargetByProbes(probeList); if (targetList == null || targetList.size() <= 0) { throw new OverflowException("", new Throwable()); } - return this.sensorDAO.findAllByTargetList(targetList, PageUtil.getPageRequest(pageParams)); + return this.sensorDAO.findAllByTargetIn(targetList, PageUtil.getPageRequest(pageParams)); } public Page readAllByInfraID(Long infraID, PageParams pageParams) throws OverflowException { @@ -100,14 +100,14 @@ public class CentralSensorService implements SensorService { public Sensor start(Long sensorID) throws OverflowException { Sensor sensor = this.sensorDAO.findOne(sensorID); MetaSensorStatus status = new MetaSensorStatus((short) 1); - sensor.setStatus(status); + sensor.setMetaSensorStatus(status); return this.sensorDAO.save(sensor); } public Sensor stop(Long sensorID) throws OverflowException { Sensor sensor = this.sensorDAO.findOne(sensorID); MetaSensorStatus status = new MetaSensorStatus((short) 2); - sensor.setStatus(status); + sensor.setMetaSensorStatus(status); return this.sensorDAO.save(sensor); } 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 index 20f12fd..866030e 100644 --- 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 @@ -22,7 +22,7 @@ import java.util.List; * Created by snoop on 17. 6. 28. */ @Service("TargetDiscoveryService") -public class CentralTargetDiscoveryService implements TargetDiscoveryService{ +public class CentralTargetDiscoveryService implements TargetDiscoveryService { @Autowired private TargetService targetService; @@ -50,7 +50,7 @@ public class CentralTargetDiscoveryService implements TargetDiscoveryService{ InfraHost infraHost = null; - for(Host host : hosts) { + for (Host host : hosts) { infraHost = this.createAndReadHost(host, probe); @@ -62,29 +62,29 @@ public class CentralTargetDiscoveryService implements TargetDiscoveryService{ private void createService(InfraHost infraHost, Port port, Probe probe) throws OverflowException { - - MetaInfraType typeService = new MetaInfraType(); - typeService.setId(7); + MetaInfraType typeService = new MetaInfraType(7); String portType = "UDP"; - if(port.getPortType() == PortType.TLS || port.getPortType() == PortType.TCP || port.getPortType() == null) { + if (port.getPortType() == PortType.TLS || port.getPortType() == PortType.TCP || port.getPortType() == null) { portType = "TCP"; } - if(port.getServiceList() == null) { + if (port.getServiceList() == null) { return; } -// for(String key : port.getServices().keySet()) { - for(com.loafle.overflow.model.discovery.Service service : port.getServiceList()) { + // for(String key : port.getServices().keySet()) { + for (com.loafle.overflow.model.discovery.Service service : port.getServiceList()) { -// com.loafle.overflow.module.discovery.model.Service service = port.getServices().get(key); + // com.loafle.overflow.module.discovery.model.Service service = + // port.getServices().get(key); - InfraService dbInfraService = this.infraServiceService.readByService(infraHost.getId(), port.getPortNumber(), portType); + InfraService dbInfraService = this.infraServiceService + .readByInfraHostIDAndPortAndPortType(infraHost.getId(), port.getPortNumber(), portType); - if(dbInfraService != null) { - if(service.isTarget() && dbInfraService.getTarget() == null) { + if (dbInfraService != null) { + if (service.isTarget() && dbInfraService.getTarget() == null) { Target targetService = new Target(); targetService.setDisplayName(service.getServiceName()); this.targetService.regist(targetService, probe); @@ -95,18 +95,18 @@ public class CentralTargetDiscoveryService implements TargetDiscoveryService{ } InfraService infraService = new InfraService(); - infraService.setHost(infraHost); + infraService.setInfraHost(infraHost); infraService.setPort(port.getPortNumber()); infraService.setPortType(portType); - infraService.setInfraType(typeService); + infraService.setMetaInfraType(typeService); infraService.setProbe(probe); if (port.getPortType() == PortType.TLS) { infraService.setTlsType(true); } - infraService.setVendor(MetaInfraVendor.CreateInfraVendorByService(service.getServiceName())); + infraService.setMetaInfraVendor(MetaInfraVendor.CreateInfraVendorByService(service.getServiceName())); - if(service.isTarget()) { + if (service.isTarget()) { Target targetService = new Target(); targetService.setDisplayName(service.getServiceName()); this.targetService.regist(targetService, probe); @@ -121,43 +121,43 @@ public class CentralTargetDiscoveryService implements TargetDiscoveryService{ private void createPort(InfraHost infraHost, Host host, Probe probe) throws OverflowException { -// if(host.getPorts() == null) { -// return; -// } + // if(host.getPorts() == null) { + // return; + // } String portType = "UDP"; - MetaInfraType typePort = new MetaInfraType(); - typePort.setId(6); + MetaInfraType typePort = new MetaInfraType(6); - InfraOS infraOS = infraHost.getOs(); + InfraOS infraOS = infraHost.getInfraOS(); -// for( String key: host.getPorts().keySet()) { + // for( String key: host.getPorts().keySet()) { - if(host.getPortList() == null) { + if (host.getPortList() == null) { return; } - for( Port port: host.getPortList()) { -// Port port = host.getPorts().get(key); + for (Port port : host.getPortList()) { + // Port port = host.getPorts().get(key); - if(port.getPortType() == PortType.TLS || port.getPortType() == PortType.TCP) { + 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 dbInfraOSPort = this.infraOSPortService.readByInfraOSIDAndPortAndPortType(infraOS.getId(), port.getPortNumber(), + portType); + if (dbInfraOSPort == null) { InfraOSPort infraOSPort = new InfraOSPort(); - infraOSPort.setOs(infraOS); + infraOSPort.setInfraOS(infraOS); infraOSPort.setPort(port.getPortNumber()); infraOSPort.setPortType(portType); infraOSPort.setProbe(probe); - infraOSPort.setInfraType(typePort); + infraOSPort.setMetaInfraType(typePort); if (port.getPortType() == PortType.TLS) { infraOSPort.setTlsType(true); } - infraOSPort.setVendor(MetaInfraVendor.CreateInfraVendorByPort(port.getPortNumber())); + infraOSPort.setMetaInfraVendor(MetaInfraVendor.CreateInfraVendorByPort(port.getPortNumber())); this.infraOSPortService.regist(infraOSPort); } @@ -167,11 +167,10 @@ public class CentralTargetDiscoveryService implements TargetDiscoveryService{ private InfraHost createAndReadHost(Host host, Probe probe) throws OverflowException { - InfraHost infraHost = this.infraHostService.readByIp(host.getIpv4()); - if(infraHost != null) { + if (infraHost != null) { - if(host.isTarget() && infraHost.getTarget() == null) { + if (host.isTarget() && infraHost.getTarget() == null) { Target target = new Target(); target.setDisplayName(host.getIpv4() + "-Host"); @@ -182,38 +181,34 @@ public class CentralTargetDiscoveryService implements TargetDiscoveryService{ return infraHost; } else { - MetaInfraType typeMachine = new MetaInfraType(); - typeMachine.setId(1); // 1 = Machine; + MetaInfraType typeMachine = new MetaInfraType(1); // 1 = Machine; - MetaInfraType typeOS = new MetaInfraType(); - typeOS.setId(3); // 3 = Os + MetaInfraType typeOS = new MetaInfraType(3);// 3 = Os - MetaInfraType typeHost = new MetaInfraType(); - typeHost.setId(2); // 2 = Host + MetaInfraType typeHost = new MetaInfraType(2); // 2 = Host InfraMachine infraMachine = new InfraMachine(); infraMachine.setProbe(probe); - infraMachine.setInfraType(typeMachine); - infraMachine.setMeta(host.getIpv4()+"-MACHINE"); + infraMachine.setMetaInfraType(typeMachine); + infraMachine.setMeta(host.getIpv4() + "-MACHINE"); this.infraMachineService.regist(infraMachine); InfraOS infraOS = new InfraOS(); - infraOS.setMachine(infraMachine); - infraOS.setVendor(MetaInfraVendor.CreateInfraVendorByOS(host.getOs())); - infraOS.setInfraType(typeOS); + infraOS.setInfraMachine(infraMachine); + infraOS.setMetaInfraVendor(MetaInfraVendor.CreateInfraVendorByOS(host.getOs())); + infraOS.setMetaInfraType(typeOS); infraOS.setProbe(probe); - infraOS.setMeta(host.getIpv4()+"-OS"); + infraOS.setMeta(host.getIpv4() + "-OS"); this.infraOSService.regist(infraOS); InfraHost newInfraHost = new InfraHost(); newInfraHost.setIpv4(host.getIpv4()); newInfraHost.setMac(host.getMac()); - newInfraHost.setOs(infraOS); - newInfraHost.setInfraType(typeHost); + newInfraHost.setInfraOS(infraOS); + newInfraHost.setMetaInfraType(typeHost); newInfraHost.setProbe(probe); - - if(host.isTarget()) { + if (host.isTarget()) { Target target = new Target(); target.setDisplayName(host.getIpv4() + "-Host"); @@ -225,10 +220,7 @@ public class CentralTargetDiscoveryService implements TargetDiscoveryService{ infraHost = newInfraHost; } - - return infraHost; } - } diff --git a/src/main/java/com/loafle/overflow/central/module/target/service/CentralTargetService.java b/src/main/java/com/loafle/overflow/central/module/target/service/CentralTargetService.java index 7c4acc4..cf72243 100644 --- a/src/main/java/com/loafle/overflow/central/module/target/service/CentralTargetService.java +++ b/src/main/java/com/loafle/overflow/central/module/target/service/CentralTargetService.java @@ -7,8 +7,6 @@ import com.loafle.overflow.central.module.probe.service.CentralProbeService; import com.loafle.overflow.central.module.target.dao.TargetDAO; import com.loafle.overflow.core.exception.OverflowException; import com.loafle.overflow.model.discovery.Host; -import com.loafle.overflow.model.infra.InfraHost; -import com.loafle.overflow.model.meta.MetaInfraType; import com.loafle.overflow.model.probe.Probe; import com.loafle.overflow.model.target.Target; import com.loafle.overflow.service.central.target.TargetService; @@ -76,24 +74,19 @@ public class CentralTargetService implements TargetService { } @Transactional - public void registDiscoveredTargets(Long probeId, List hosts, List services) { + public List registDiscoveredTargets(Long probeId, List hosts, + List services) throws OverflowException { /* - 해당 host의 mac에 해당하는 infraHost가 이미 존재하는지 검사 - infraHost가 없다면 create - infraHost가 있다면 update - infraHost.getTarget()이 있어도 무조건 새로운 target으로 연결 - - - for(Host host : hosts) { - Target target = new Target(); - - MetaInfraType infraType = new MetaInfraType(); - infraType.setId(2); - InfraHost infraHost = new InfraHost(); - infraHost.setInfraType(infraType); - infraHost.setProbe(new Probe(probeId)); - infraHost.setTarget(target); - } - */ + * 해당 host의 mac에 해당하는 infraHost가 이미 존재하는지 검사 infraHost가 없다면 create infraHost가 + * 있다면 update infraHost.getTarget()이 있어도 무조건 새로운 target으로 연결 + * + * + * for(Host host : hosts) { Target target = new Target(); + * + * MetaInfraType infraType = new MetaInfraType(); infraType.setId(2); InfraHost + * infraHost = new InfraHost(); infraHost.setInfraType(infraType); + * infraHost.setProbe(new Probe(probeId)); infraHost.setTarget(target); } + */ + return null; } }