From 07e9f73e4850c9d1e977917a5fcfca157bb63e3b Mon Sep 17 00:00:00 2001 From: crusader Date: Thu, 7 Jun 2018 15:02:38 +0900 Subject: [PATCH] ing --- .editorconfig | 13 + .vscode/settings.json | 3 + .../com/loafle/overflow/central/Central.java | 24 +- .../commons/service/MessagePublisher.java | 20 +- .../central/commons/utils/EmailSender.java | 166 +++---- .../central/commons/utils/GenerateKey.java | 18 +- .../central/commons/utils/PageUtil.java | 24 +- .../commons/utils/SessionMetadata.java | 73 +-- .../commons/utils/StringConvertor.java | 82 ++-- .../central/module/apikey/dao/ApiKeyDAO.java | 7 +- .../apikey/service/CentralApiKeyService.java | 42 +- .../module/auth/dao/AuthCrawlerDAO.java | 2 +- .../service/CentralAuthCrawlerService.java | 2 +- .../central/module/domain/dao/DomainDAO.java | 3 +- .../module/email/dao/EmailAuthDAO.java | 4 +- .../generator/service/GenerateUtil.java | 117 +++-- .../generator/service/InfraHostGenerator.java | 8 +- .../service/InfraHostWMIGenerator.java | 25 +- .../service/InfraServiceGenerator.java | 141 +++--- .../service/InfraServiceJMXGenerator.java | 3 +- .../service/InfraServiceMysqlGenerator.java | 76 +-- .../service/SensorConfigGenerator.java | 61 ++- .../module/history/dao/HistoryDAO.java | 8 +- .../service/CentralHistoryService.java | 42 +- .../central/module/infra/dao/InfraDAO.java | 10 +- .../module/infra/dao/InfraHostDAO.java | 2 +- .../module/infra/dao/InfraOSPortDAO.java | 2 +- .../module/infra/dao/InfraServiceDAO.java | 2 +- .../service/CentralInfraHostService.java | 23 +- .../service/CentralInfraMachineService.java | 16 +- .../CentralInfraOSApplicationService.java | 16 +- .../service/CentralInfraOSDaemonService.java | 16 +- .../service/CentralInfraOSPortService.java | 24 +- .../infra/service/CentralInfraOSService.java | 16 +- .../infra/service/CentralInfraService.java | 88 ++-- .../service/CentralInfraServiceService.java | 24 +- .../central/module/member/dao/MemberDAO.java | 2 +- .../module/member/dao/MemberTotpDAO.java | 4 +- .../member/service/CentralMemberService.java | 436 +++++++++--------- .../service/CentralMemberTotpService.java | 179 +++---- .../meta/dao/MetaCrawlerInputItemDAO.java | 2 +- .../module/meta/dao/MetaInfraVendorDAO.java | 2 +- .../module/meta/dao/MetaProbePackageDAO.java | 2 +- .../module/meta/dao/MetaProbeStatusDAO.java | 3 +- .../module/meta/dao/MetaProbeTaskTypeDAO.java | 2 +- .../module/meta/dao/MetaProbeVersionDAO.java | 2 +- .../meta/dao/MetaSensorDisplayItemDAO.java | 2 +- .../meta/dao/MetaSensorDisplayMappingDAO.java | 5 +- .../module/meta/dao/MetaSensorItemDAO.java | 2 +- .../module/meta/dao/MetaSensorItemKeyDAO.java | 2 +- .../meta/dao/MetaSensorItemTypeDAO.java | 2 +- .../module/meta/dao/MetaSensorStatusDAO.java | 2 +- .../module/meta/dao/MetaVendorCrawlerDAO.java | 2 +- .../dao/MetaVendorCrawlerSensorItemDAO.java | 2 +- .../CentralMetaCrawlerInputItemService.java | 11 +- .../service/CentralMetaCrawlerService.java | 10 +- .../CentralMetaHistoryTypeService.java | 22 +- .../service/CentralMetaInfraTypeService.java | 10 +- .../CentralMetaInfraVendorService.java | 10 +- .../service/CentralMetaInputTypeService.java | 10 +- .../CentralMetaMemberStatusService.java | 10 +- .../CentralMetaNoAuthProbeStatusService.java | 10 +- .../CentralMetaProbeArchitectureService.java | 10 +- .../service/CentralMetaProbeOsService.java | 10 +- .../CentralMetaProbePackageService.java | 11 +- .../CentralMetaProbeStatusService.java | 10 +- .../CentralMetaProbeTaskTypeService.java | 10 +- .../CentralMetaProbeVersionService.java | 10 +- .../CentralMetaSensorDisplayItemService.java | 23 +- ...entralMetaSensorDisplayMappingService.java | 18 +- .../CentralMetaSensorItemTypeService.java | 22 +- .../CentralMetaSensorItemUnitService.java | 10 +- .../CentralMetaSensorStatusService.java | 10 +- .../CentralMetaVendorCrawlerService.java | 17 +- .../noauthprobe/dao/NoAuthProbeDAO.java | 21 +- .../notification/dao/NotificationDAO.java | 8 +- .../service/CentralNotificationService.java | 75 ++- .../central/module/probe/dao/ProbeDAO.java | 14 +- .../module/probe/dao/ProbeHostDAO.java | 4 +- .../module/probe/dao/ProbeTaskDAO.java | 2 +- .../service/CentralProbeHostService.java | 28 +- .../probe/service/CentralProbeService.java | 132 +++--- .../service/CentralProbeTaskService.java | 18 +- .../central/module/sensor/dao/SensorDAO.java | 6 +- .../module/sensor/dao/SensorItemDAO.java | 2 +- .../sensor/dao/SensorItemDependencyDAO.java | 5 +- .../CentralSensorItemDependencyService.java | 44 +- .../service/CentralSensorItemService.java | 64 +-- .../sensor/service/CentralSensorService.java | 185 ++++---- .../central/module/target/dao/TargetDAO.java | 5 +- .../CentralTargetDiscoveryService.java | 391 ++++++++-------- .../target/service/CentralTargetService.java | 252 +++++----- .../central/proxy/ProxyServerInterceptor.java | 20 +- .../overflow/central/proxy/ServiceProxy.java | 7 +- .../redis/service/RedisMessagePublisher.java | 2 +- .../overflow/central/spring/AppConfig.java | 32 +- .../central/spring/CacheConfiguration.java | 24 +- .../central/spring/JdbcConfiguration.java | 137 +++--- .../central/spring/MailConfiguration.java | 97 ++-- .../central/spring/RedisConfiguration.java | 85 ++-- 100 files changed, 1889 insertions(+), 1881 deletions(-) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..6e87a00 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,13 @@ +# Editor configuration, see http://editorconfig.org +root = true + +[*] +charset = utf-8 +indent_style = space +indent_size = 2 +insert_final_newline = true +trim_trailing_whitespace = true + +[*.md] +max_line_length = off +trim_trailing_whitespace = false diff --git a/.vscode/settings.json b/.vscode/settings.json index 1133129..af826ed 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,3 +1,6 @@ { + "editor.tabSize": 2, + "editor.insertSpaces": true, + "java.configuration.updateBuildConfiguration": "automatic" } \ No newline at end of file diff --git a/src/main/java/com/loafle/overflow/central/Central.java b/src/main/java/com/loafle/overflow/central/Central.java index 442240c..87f71ef 100644 --- a/src/main/java/com/loafle/overflow/central/Central.java +++ b/src/main/java/com/loafle/overflow/central/Central.java @@ -5,17 +5,17 @@ import com.loafle.overflow.central.proxy.ServiceProxy; import java.io.IOException; public class Central { - public static void main(String[] args) throws IOException, InterruptedException { - if(args.length <= 0) { - System.out.println("Port args"); - System.out.println("first parameter is Port Number"); - return; - } - - int port = Integer.valueOf(args[0]); - - final ServiceProxy server = new ServiceProxy(); - server.start(port); - server.blockUntilShutdown(); + public static void main(String[] args) throws IOException, InterruptedException { + if (args.length <= 0) { + System.out.println("Port args"); + System.out.println("first parameter is Port Number"); + return; } + + int port = Integer.valueOf(args[0]); + + final ServiceProxy server = new ServiceProxy(); + server.start(port); + server.blockUntilShutdown(); + } } 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 24d760f..a471e1e 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,19 +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 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 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 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 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 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; + void publishToProbe(final String probeKey, final String method, final Object... params) throws OverflowException; } diff --git a/src/main/java/com/loafle/overflow/central/commons/utils/EmailSender.java b/src/main/java/com/loafle/overflow/central/commons/utils/EmailSender.java index 169ffdd..57da90f 100644 --- a/src/main/java/com/loafle/overflow/central/commons/utils/EmailSender.java +++ b/src/main/java/com/loafle/overflow/central/commons/utils/EmailSender.java @@ -29,106 +29,106 @@ import java.util.Map; @Service("EmailSender") public class EmailSender { - @Autowired - private JavaMailSender mailSender; + @Autowired + private JavaMailSender mailSender; - @Autowired - private VelocityEngine velocityEngine; + @Autowired + private VelocityEngine velocityEngine; - private String key = "loafle@RandomKey"; - private String initVector = "loafleInitVector"; + private String key = "loafle@RandomKey"; + private String initVector = "loafleInitVector"; - public void sendSimpleEmail(final Mail mail) throws MailException { + public void sendSimpleEmail(final Mail mail) throws MailException { - MimeMessagePreparator preparator = mimeMessage -> { - MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true, "UTF-8"); - helper.setTo(mail.getMailTo()); - helper.setFrom("geek@loafle.com"); - helper.setSubject(mail.getMailSubject()); - helper.setText(getContentFromTemplate(mail.getModel(), mail), true); - helper.addInline("company-logo", new ClassPathResource("/vmtemplates/overFlow_logo.png")); - }; + MimeMessagePreparator preparator = mimeMessage -> { + MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true, "UTF-8"); + helper.setTo(mail.getMailTo()); + helper.setFrom("geek@loafle.com"); + helper.setSubject(mail.getMailSubject()); + helper.setText(getContentFromTemplate(mail.getModel(), mail), true); + helper.addInline("company-logo", new ClassPathResource("/vmtemplates/overFlow_logo.png")); + }; - this.mailSender.send(preparator); + this.mailSender.send(preparator); + } + + public void sendMailWithAttachment(Mail mail) throws MessagingException { + MimeMessage message = mailSender.createMimeMessage(); + // pass 'true' to the constructor to create a multipart message + MimeMessageHelper helper = new MimeMessageHelper(message, true); + + helper.setTo(mail.getMailTo()); + helper.setSubject(mail.getMailSubject()); + helper.setText(mail.getMailContent()); + helper.setFrom("geek@loafle.com"); + // FileSystemResource file = new FileSystemResource(new + // File(mail.getAttachments())); + // helper.addAttachment("Invoice", file); + + mailSender.send(message); + } + + public String encrypt(String value) { + try { + IvParameterSpec iv = new IvParameterSpec(initVector.getBytes("UTF-8")); + + SecretKeySpec skeySpec = new SecretKeySpec(key.getBytes("UTF-8"), "AES"); + + Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING"); + cipher.init(Cipher.ENCRYPT_MODE, skeySpec, iv); + + byte[] encrypted = cipher.doFinal(value.getBytes()); + System.out.println("encrypted string: " + Base64.encodeBase64String(encrypted)); + + return Base64.encodeBase64String(encrypted); + } catch (Exception ex) { + ex.printStackTrace(); } - public void sendMailWithAttachment(Mail mail) throws MessagingException { - MimeMessage message = mailSender.createMimeMessage(); - // pass 'true' to the constructor to create a multipart message - MimeMessageHelper helper = new MimeMessageHelper(message, true); + return null; + } - helper.setTo(mail.getMailTo()); - helper.setSubject(mail.getMailSubject()); - helper.setText(mail.getMailContent()); - helper.setFrom("geek@loafle.com"); - // FileSystemResource file = new FileSystemResource(new - // File(mail.getAttachments())); - // helper.addAttachment("Invoice", file); + public String decrypt(String encrypted) { + try { + IvParameterSpec iv = new IvParameterSpec(initVector.getBytes("UTF-8")); + SecretKeySpec skeySpec = new SecretKeySpec(key.getBytes("UTF-8"), "AES"); - mailSender.send(message); + Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING"); + cipher.init(Cipher.DECRYPT_MODE, skeySpec, iv); + + byte[] original = cipher.doFinal(Base64.decodeBase64(encrypted)); + + return new String(original); + } catch (Exception ex) { + ex.printStackTrace(); } - public String encrypt(String value) { - try { - IvParameterSpec iv = new IvParameterSpec(initVector.getBytes("UTF-8")); + return null; + } - SecretKeySpec skeySpec = new SecretKeySpec(key.getBytes("UTF-8"), "AES"); + private String getContentFromTemplate(Map model, Mail mail) { + StringWriter writer = new StringWriter(); + VelocityContext context = new VelocityContext(); - Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING"); - cipher.init(Cipher.ENCRYPT_MODE, skeySpec, iv); + Template template = this.velocityEngine.getTemplate(mail.getTemplateLoacation(), "UTF-8"); - byte[] encrypted = cipher.doFinal(value.getBytes()); - System.out.println("encrypted string: " + Base64.encodeBase64String(encrypted)); + model.forEach((key, value) -> { + context.put(key, value); + }); - return Base64.encodeBase64String(encrypted); - } catch (Exception ex) { - ex.printStackTrace(); - } + template.merge(context, writer); - return null; - } + // try { - public String decrypt(String encrypted) { - try { - IvParameterSpec iv = new IvParameterSpec(initVector.getBytes("UTF-8")); - SecretKeySpec skeySpec = new SecretKeySpec(key.getBytes("UTF-8"), "AES"); - - Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING"); - cipher.init(Cipher.DECRYPT_MODE, skeySpec, iv); - - byte[] original = cipher.doFinal(Base64.decodeBase64(encrypted)); - - return new String(original); - } catch (Exception ex) { - ex.printStackTrace(); - } - - return null; - } - - private String getContentFromTemplate(Map model, Mail mail) { - StringWriter writer = new StringWriter(); - VelocityContext context = new VelocityContext(); - - Template template = this.velocityEngine.getTemplate(mail.getTemplateLoacation(), "UTF-8"); - - model.forEach((key, value) -> { - context.put(key, value); - }); - - template.merge(context, writer); - - // try { - - // template.merge(this.velocityEngine, content); - // // content.append(VelocityEngineUtils.mergeTemplateIntoString - // // (velocityEngine, - // // mail.getTemplateLoacation(), "UTF-8", model)); - // } catch (Exception e) { - // e.printStackTrace(); - // } - return writer.toString(); - } + // template.merge(this.velocityEngine, content); + // // content.append(VelocityEngineUtils.mergeTemplateIntoString + // // (velocityEngine, + // // mail.getTemplateLoacation(), "UTF-8", model)); + // } catch (Exception e) { + // e.printStackTrace(); + // } + return writer.toString(); + } } diff --git a/src/main/java/com/loafle/overflow/central/commons/utils/GenerateKey.java b/src/main/java/com/loafle/overflow/central/commons/utils/GenerateKey.java index 7fcede9..55039c2 100644 --- a/src/main/java/com/loafle/overflow/central/commons/utils/GenerateKey.java +++ b/src/main/java/com/loafle/overflow/central/commons/utils/GenerateKey.java @@ -8,18 +8,18 @@ import com.fasterxml.uuid.impl.TimeBasedGenerator; * Created by geek on 18. 3. 27. */ public class GenerateKey { - private static TimeBasedGenerator generator = Generators.timeBasedGenerator(EthernetAddress.fromInterface()); + private static TimeBasedGenerator generator = Generators.timeBasedGenerator(EthernetAddress.fromInterface()); - public static synchronized String getKey() { + public static synchronized String getKey() { - String[] uuids = generator.generate().toString().split("-"); - StringBuffer sb = new StringBuffer(); + String[] uuids = generator.generate().toString().split("-"); + StringBuffer sb = new StringBuffer(); - for ( int idx = 0; idx < uuids.length; idx++ ) { - sb.append(uuids[idx]); - } - - return sb.toString(); + for (int idx = 0; idx < uuids.length; idx++) { + sb.append(uuids[idx]); } + return sb.toString(); + } + } diff --git a/src/main/java/com/loafle/overflow/central/commons/utils/PageUtil.java b/src/main/java/com/loafle/overflow/central/commons/utils/PageUtil.java index ba77ebb..b46612c 100644 --- a/src/main/java/com/loafle/overflow/central/commons/utils/PageUtil.java +++ b/src/main/java/com/loafle/overflow/central/commons/utils/PageUtil.java @@ -9,18 +9,20 @@ import org.springframework.data.domain.Sort; * Created by insanity on 17. 8. 25. */ public class PageUtil { - private static Sort.Direction getSortDirection(String sortDirection) { - if(sortDirection.equalsIgnoreCase("ascending")) { - return Sort.Direction.ASC; - } - return Sort.Direction.DESC; + private static Sort.Direction getSortDirection(String sortDirection) { + if (sortDirection.equalsIgnoreCase("ascending")) { + return Sort.Direction.ASC; } + return Sort.Direction.DESC; + } - public static PageRequest getPageRequest(PageParams pageParams) { - if(pageParams.getSortCol().isEmpty()) pageParams.setSortCol("id"); - if(pageParams.getSortDirection().isEmpty()) pageParams.setSortDirection("descending"); + public static PageRequest getPageRequest(PageParams pageParams) { + if (pageParams.getSortCol().isEmpty()) + pageParams.setSortCol("id"); + if (pageParams.getSortDirection().isEmpty()) + pageParams.setSortDirection("descending"); - return new PageRequest(pageParams.getPageNo(), pageParams.getCountPerPage(), - new Sort(PageUtil.getSortDirection(pageParams.getSortDirection()), pageParams.getSortCol())); - } + return new PageRequest(pageParams.getPageNo(), pageParams.getCountPerPage(), + new Sort(PageUtil.getSortDirection(pageParams.getSortDirection()), pageParams.getSortCol())); + } } diff --git a/src/main/java/com/loafle/overflow/central/commons/utils/SessionMetadata.java b/src/main/java/com/loafle/overflow/central/commons/utils/SessionMetadata.java index 10cb83d..5670637 100644 --- a/src/main/java/com/loafle/overflow/central/commons/utils/SessionMetadata.java +++ b/src/main/java/com/loafle/overflow/central/commons/utils/SessionMetadata.java @@ -6,46 +6,49 @@ import io.grpc.Metadata; import static io.grpc.Metadata.ASCII_STRING_MARSHALLER; public class SessionMetadata { - /* - digits: 0-9 - uppercase letters: A-Z (normalized to lower) - lowercase letters: a-z - special characters: -_. - */ + /* + * digits: 0-9 uppercase letters: A-Z (normalized to lower) lowercase letters: + * a-z special characters: -_. + */ - public static final String CLIENT_TYPE_KEY = "OVERFLOW_GRPC_CLIENT_TYPE"; - public static final String SESSION_ID_KEY = "OVERFLOW_GRPC_SESSION_ID"; - public static final String TARGET_ID_KEY = "OVERFLOW_GRPC_TARGET_ID"; + public static final String CLIENT_TYPE_KEY = "OVERFLOW_GRPC_CLIENT_TYPE"; + public static final String SESSION_ID_KEY = "OVERFLOW_GRPC_SESSION_ID"; + public static final String TARGET_ID_KEY = "OVERFLOW_GRPC_TARGET_ID"; - public static final Context.Key CTX_CLIENT_TYPE_KEY = Context.key(CLIENT_TYPE_KEY); - public static final Context.Key CTX_SESSION_ID_KEY = Context.key(SESSION_ID_KEY); - public static final Context.Key CTX_TARGET_ID_KEY = Context.key(TARGET_ID_KEY); + public static final Context.Key CTX_CLIENT_TYPE_KEY = Context.key(CLIENT_TYPE_KEY); + public static final Context.Key CTX_SESSION_ID_KEY = Context.key(SESSION_ID_KEY); + public static final Context.Key CTX_TARGET_ID_KEY = Context.key(TARGET_ID_KEY); - public static final Metadata.Key METADATA_CLIENT_TYPE_KEY = Metadata.Key.of(CLIENT_TYPE_KEY, ASCII_STRING_MARSHALLER); - public static final Metadata.Key METADATA_SESSION_ID_KEY = Metadata.Key.of(SESSION_ID_KEY, ASCII_STRING_MARSHALLER); - public static final Metadata.Key METADATA_TARGET_ID_KEY = Metadata.Key.of(TARGET_ID_KEY, ASCII_STRING_MARSHALLER); + public static final Metadata.Key METADATA_CLIENT_TYPE_KEY = Metadata.Key.of(CLIENT_TYPE_KEY, + ASCII_STRING_MARSHALLER); + public static final Metadata.Key METADATA_SESSION_ID_KEY = Metadata.Key.of(SESSION_ID_KEY, + ASCII_STRING_MARSHALLER); + public static final Metadata.Key METADATA_TARGET_ID_KEY = Metadata.Key.of(TARGET_ID_KEY, + ASCII_STRING_MARSHALLER); - public static ClientType getClientType() { - return ClientType.valueOf(CTX_CLIENT_TYPE_KEY.get()); - } - public static String getSessionID() { - return CTX_SESSION_ID_KEY.get(); - } - public static String getTargetID() { - return CTX_TARGET_ID_KEY.get(); + public static ClientType getClientType() { + return ClientType.valueOf(CTX_CLIENT_TYPE_KEY.get()); + } + + public static String getSessionID() { + return CTX_SESSION_ID_KEY.get(); + } + + public static String getTargetID() { + return CTX_TARGET_ID_KEY.get(); + } + + public static enum ClientType { + MEMBER("MEMBER"), PROBE("PROBE"); + + final private String name; + + private ClientType(String name) { + this.name = name; } - public static enum ClientType { - MEMBER("MEMBER"), - PROBE("PROBE"); - - final private String name; - - private ClientType(String name) { - this.name = name; - } - public String toString() { - return name; - } + public String toString() { + return name; } + } } diff --git a/src/main/java/com/loafle/overflow/central/commons/utils/StringConvertor.java b/src/main/java/com/loafle/overflow/central/commons/utils/StringConvertor.java index 1ab7bbd..ea614fb 100644 --- a/src/main/java/com/loafle/overflow/central/commons/utils/StringConvertor.java +++ b/src/main/java/com/loafle/overflow/central/commons/utils/StringConvertor.java @@ -5,57 +5,51 @@ package com.loafle.overflow.central.commons.utils; */ public class StringConvertor { - public static String intToIp(long i) { - return ((i >> 24 ) & 0xFF) + "." + - ((i >> 16 ) & 0xFF) + "." + - ((i >> 8 ) & 0xFF) + "." + - ( i & 0xFF); + public static String intToIp(long i) { + return ((i >> 24) & 0xFF) + "." + ((i >> 16) & 0xFF) + "." + ((i >> 8) & 0xFF) + "." + (i & 0xFF); + } + + public static long ipToLong(String ipAddress) { + + String[] ipAddressInArray = ipAddress.split("\\."); + + long result = 0; + for (int i = 0; i < ipAddressInArray.length; i++) { + + int power = 3 - i; + int ip = Integer.parseInt(ipAddressInArray[i]); + result += ip * Math.pow(256, power); + } + return result; + } - public static long ipToLong(String ipAddress) { + // https://github.com/Sovietaced/floodlight/blob/master/src/main/java/net/floodlightcontroller/util/MACAddress.java - String[] ipAddressInArray = ipAddress.split("\\."); + public static final int MAC_ADDRESS_LENGTH = 6; - long result = 0; - for (int i = 0; i < ipAddressInArray.length; i++) { - - int power = 3 - i; - int ip = Integer.parseInt(ipAddressInArray[i]); - result += ip * Math.pow(256, power); - - } - - return result; + public static long macStrToLong(String address) { + String[] elements = address.split(":"); + if (elements.length != MAC_ADDRESS_LENGTH) { + throw new IllegalArgumentException( + "Specified MAC Address must contain 12 hex digits" + " separated pairwise by :'s."); } - - // https://github.com/Sovietaced/floodlight/blob/master/src/main/java/net/floodlightcontroller/util/MACAddress.java - - public static final int MAC_ADDRESS_LENGTH = 6; - - public static long macStrToLong(String address) { - String[] elements = address.split(":"); - if (elements.length != MAC_ADDRESS_LENGTH) { - throw new IllegalArgumentException( - "Specified MAC Address must contain 12 hex digits" + - " separated pairwise by :'s."); - } - - byte[] addressInBytes = new byte[MAC_ADDRESS_LENGTH]; - for (int i = 0; i < MAC_ADDRESS_LENGTH; i++) { - String element = elements[i]; - addressInBytes[i] = (byte)Integer.parseInt(element, 16); - } - - long mac = 0; - for (int i = 0; i < 6; i++) { - long t = (addressInBytes[i] & 0xffL) << ((5 - i) * 8); - mac |= t; - } - return mac; - -// return new MACAddress(addressInBytes); + byte[] addressInBytes = new byte[MAC_ADDRESS_LENGTH]; + for (int i = 0; i < MAC_ADDRESS_LENGTH; i++) { + String element = elements[i]; + addressInBytes[i] = (byte) Integer.parseInt(element, 16); } + long mac = 0; + for (int i = 0; i < 6; i++) { + long t = (addressInBytes[i] & 0xffL) << ((5 - i) * 8); + mac |= t; + } + return mac; + + // return new MACAddress(addressInBytes); + } + } diff --git a/src/main/java/com/loafle/overflow/central/module/apikey/dao/ApiKeyDAO.java b/src/main/java/com/loafle/overflow/central/module/apikey/dao/ApiKeyDAO.java index 035facd..78cc38b 100644 --- a/src/main/java/com/loafle/overflow/central/module/apikey/dao/ApiKeyDAO.java +++ b/src/main/java/com/loafle/overflow/central/module/apikey/dao/ApiKeyDAO.java @@ -1,19 +1,16 @@ package com.loafle.overflow.central.module.apikey.dao; - - import com.loafle.overflow.model.apikey.ApiKey; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; - /** * Created by root on 17. 6. 1. */ @Repository public interface ApiKeyDAO extends JpaRepository { - ApiKey findByApiKey(String apiKey); + ApiKey findByApiKey(String apiKey); - ApiKey findByDomainId(Long domainID); + ApiKey findByDomainId(Long domainID); } 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 0dc4632..5515967 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 @@ -1,9 +1,7 @@ package com.loafle.overflow.central.module.apikey.service; - 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.service.central.apikey.ApiKeyService; @@ -16,33 +14,31 @@ import org.springframework.stereotype.Service; @Service("ApiKeyService") public class CentralApiKeyService implements ApiKeyService { + @Autowired + private ApiKeyDAO apiKeyDAO; - @Autowired - private ApiKeyDAO apiKeyDAO; + public ApiKey regist(ApiKey apiKey) throws OverflowException { + return this.apiKeyDAO.save(apiKey); + } - public ApiKey regist(ApiKey apiKey) throws OverflowException { + public ApiKey readByDomainID(Long domainID) throws OverflowException { + return this.apiKeyDAO.findByDomainId(domainID); + } - return this.apiKeyDAO.save(apiKey); + public boolean check(String apiKey) throws OverflowException { + + ApiKey retApiKey = this.apiKeyDAO.findByApiKey(apiKey); + + if (retApiKey == null) { + return false; } - public ApiKey readByDomainID(Long domainID) throws OverflowException { - return this.apiKeyDAO.findByDomainId(domainID); - } + return true; + } - public boolean check(String apiKey) throws OverflowException { - - ApiKey retApiKey = this.apiKeyDAO.findByApiKey(apiKey); - - if(retApiKey == null) { - return false; - } - - return true; - } - - public ApiKey readByApiKey(String apiKey) throws OverflowException{ - return this.apiKeyDAO.findByApiKey(apiKey); - } + public ApiKey readByApiKey(String apiKey) throws OverflowException { + return this.apiKeyDAO.findByApiKey(apiKey); + } } 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 ded2eaf..39bb623 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 @@ -9,5 +9,5 @@ import org.springframework.stereotype.Repository; */ @Repository public interface AuthCrawlerDAO extends JpaRepository { - AuthCrawler findByMetaCrawlerIdAndTargetId(Short metaCrawlerId, Long targetId); + 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 84f85ae..d8f876b 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 @@ -25,7 +25,7 @@ public class CentralAuthCrawlerService implements AuthCrawlerService { public AuthCrawler regist(AuthCrawler authCrawler) { // if (authCrawler == null) { - // return this.authCrawlerDAO.save(authCrawler); + // return this.authCrawlerDAO.save(authCrawler); // } AuthCrawler dbAuthCrawler = this.authCrawlerDAO.findByMetaCrawlerIdAndTargetId(authCrawler.getMetaCrawler().getId(), diff --git a/src/main/java/com/loafle/overflow/central/module/domain/dao/DomainDAO.java b/src/main/java/com/loafle/overflow/central/module/domain/dao/DomainDAO.java index a12a2da..ee6daf2 100644 --- a/src/main/java/com/loafle/overflow/central/module/domain/dao/DomainDAO.java +++ b/src/main/java/com/loafle/overflow/central/module/domain/dao/DomainDAO.java @@ -1,6 +1,5 @@ package com.loafle.overflow.central.module.domain.dao; - import com.loafle.overflow.model.domain.Domain; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; @@ -9,5 +8,5 @@ import org.springframework.stereotype.Repository; * Created by root on 17. 6. 23. */ @Repository -public interface DomainDAO extends JpaRepository { +public interface DomainDAO extends JpaRepository { } 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 669a417..3cd016b 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 @@ -11,8 +11,8 @@ import java.util.List; */ @Repository public interface EmailAuthDAO extends JpaRepository { - EmailAuth findByEmailAuthKey(String emailAuthKey); + EmailAuth findByEmailAuthKey(String emailAuthKey); - List findByMemberId(Long memberId); + List findByMemberId(Long memberId); } 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 1635a71..531c473 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 @@ -23,82 +23,75 @@ import java.util.Map; @Service("GenerateUtil") public class GenerateUtil { - @Autowired - private MetaSensorItemKeyService metaSensorItemKeyService; + @Autowired + private MetaSensorItemKeyService metaSensorItemKeyService; + private Map> mappingMap = null; + public Map initMappingMap(MetaCrawler metaCrawler) throws OverflowException { - private Map> mappingMap = null; - - public Map initMappingMap(MetaCrawler metaCrawler) throws OverflowException { - - if(this.mappingMap == null) { - this.mappingMap = new HashMap<>(); - } - - Map resultMap = this.mappingMap.get(metaCrawler.getId()); - - if(resultMap != null) { - return resultMap; - } - - resultMap = this.metaSensorItemKeyService.readAllMapByMetaCrawlerID(metaCrawler.getId()); - this.mappingMap.put(metaCrawler.getId(), resultMap); - - return resultMap; + if (this.mappingMap == null) { + this.mappingMap = new HashMap<>(); } + Map resultMap = this.mappingMap.get(metaCrawler.getId()); - - public Crawler getCrawler(MetaCrawler metaCrawler) throws OverflowException { - - Crawler crawler = new Crawler(); - crawler.setName(metaCrawler.getName()); - - String container = ""; - - if(metaCrawler.getId() == MetaCrawlerEnum.CASSANDRA_CRAWLER.getValue() - || metaCrawler.getId() == MetaCrawlerEnum.CASSANDRA_CRAWLER.getValue() - || metaCrawler.getId() == MetaCrawlerEnum.MONGODB_CRAWLER.getValue() - || metaCrawler.getId() == MetaCrawlerEnum.MSSQL_CRAWLER.getValue() - || metaCrawler.getId() == MetaCrawlerEnum.ORACLE_CRAWLER.getValue() - || metaCrawler.getId() == MetaCrawlerEnum.POSTGRESQL_CRAWLER.getValue() - || metaCrawler.getId() == MetaCrawlerEnum.JMX_CRAWLER.getValue()) { - container = "java_proxy"; - } - else { - container = "network_proxy"; - } - - crawler.setContainer(container); - - return crawler; + if (resultMap != null) { + return resultMap; } + resultMap = this.metaSensorItemKeyService.readAllMapByMetaCrawlerID(metaCrawler.getId()); + this.mappingMap.put(metaCrawler.getId(), resultMap); + return resultMap; + } + public Crawler getCrawler(MetaCrawler metaCrawler) throws OverflowException { - public Map> sortItems(List sensorItems, Map keyMap) throws OverflowException { + Crawler crawler = new Crawler(); + crawler.setName(metaCrawler.getName()); - Map> metricMap = new HashMap<>(); + String container = ""; - MetaSensorItemKey itemKey = null; - - for(SensorItem sItem : sensorItems) { - itemKey = keyMap.get(sItem.getMetaSensorDisplayItem().getId()); - if(metricMap.containsKey(itemKey.getFroms()) == false) { - metricMap.put(itemKey.getFroms(), new ArrayList<>()); - } - metricMap.get(itemKey.getFroms()).add(itemKey); - } - - return metricMap; + if (metaCrawler.getId() == MetaCrawlerEnum.CASSANDRA_CRAWLER.getValue() + || metaCrawler.getId() == MetaCrawlerEnum.CASSANDRA_CRAWLER.getValue() + || metaCrawler.getId() == MetaCrawlerEnum.MONGODB_CRAWLER.getValue() + || metaCrawler.getId() == MetaCrawlerEnum.MSSQL_CRAWLER.getValue() + || metaCrawler.getId() == MetaCrawlerEnum.ORACLE_CRAWLER.getValue() + || metaCrawler.getId() == MetaCrawlerEnum.POSTGRESQL_CRAWLER.getValue() + || metaCrawler.getId() == MetaCrawlerEnum.JMX_CRAWLER.getValue()) { + container = "java_proxy"; + } else { + container = "network_proxy"; } - public Keys createKeys(MetaSensorItemKey itemKey) throws OverflowException { - Keys keys = new Keys(); - keys.setKey(itemKey.getKey()); - keys.setMetric(itemKey.getMetaSensorItem().getKey()); - return keys; + crawler.setContainer(container); + + return crawler; + } + + public Map> sortItems(List sensorItems, + Map keyMap) throws OverflowException { + + Map> metricMap = new HashMap<>(); + + MetaSensorItemKey itemKey = null; + + for (SensorItem sItem : sensorItems) { + itemKey = keyMap.get(sItem.getMetaSensorDisplayItem().getId()); + if (metricMap.containsKey(itemKey.getFroms()) == false) { + metricMap.put(itemKey.getFroms(), new ArrayList<>()); + } + metricMap.get(itemKey.getFroms()).add(itemKey); } + + return metricMap; + } + + public Keys createKeys(MetaSensorItemKey itemKey) throws OverflowException { + Keys keys = new Keys(); + keys.setKey(itemKey.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 bcceccc..ad4f56a 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 @@ -1,6 +1,5 @@ package com.loafle.overflow.central.module.generator.service; -import com.loafle.overflow.central.commons.utils.StringConvertor; import com.loafle.overflow.core.type.PortType; import com.loafle.overflow.model.auth.AuthCrawler; import com.loafle.overflow.model.infra.Infra; @@ -77,7 +76,8 @@ public class InfraHostGenerator { private Target createTarget(InfraHost infraHost, Sensor dbSensor) throws Exception { - AuthCrawler authCrawler = this.authCrawlerService.readByMetaCrawlerIDAndTargetID(dbSensor.getMetaCrawler().getId(), dbSensor.getTarget().getId()); + AuthCrawler authCrawler = this.authCrawlerService.readByMetaCrawlerIDAndTargetID(dbSensor.getMetaCrawler().getId(), + dbSensor.getTarget().getId()); if (authCrawler == null) { return null; @@ -87,7 +87,9 @@ public class InfraHostGenerator { Connection connection = new Connection(); connection.setIp(infraHost.getIpv4()); - HashMap optionMap = this.objectMapper.readValue(authCrawler.getAuthJson(), new TypeReference>(){}); + HashMap optionMap = this.objectMapper.readValue(authCrawler.getAuthJson(), + new TypeReference>() { + }); if (dbSensor.getMetaCrawler().getId() == MetaCrawlerEnum.WMI_CRAWLER.getValue()) { connection.setPort(135); diff --git a/src/main/java/com/loafle/overflow/central/module/generator/service/InfraHostWMIGenerator.java b/src/main/java/com/loafle/overflow/central/module/generator/service/InfraHostWMIGenerator.java index 6d46827..70bbd93 100644 --- a/src/main/java/com/loafle/overflow/central/module/generator/service/InfraHostWMIGenerator.java +++ b/src/main/java/com/loafle/overflow/central/module/generator/service/InfraHostWMIGenerator.java @@ -37,15 +37,15 @@ public class InfraHostWMIGenerator { Map> metricMap = null; metricMap = this.generateUtil.sortItems(sensorItems, keyMap); - // MetaSensorItemKey itemKey = null; + // MetaSensorItemKey itemKey = null; // - // for(SensorItem sItem : sensorItems) { - // itemKey = keyMap.get(sItem.getItem().getId()); - // if(metricMap.containsKey(itemKey.getFroms()) == false) { - // metricMap.put(itemKey.getFroms(), new ArrayList<>()); - // } - // metricMap.get(itemKey.getFroms()).add(itemKey); - // } + // for(SensorItem sItem : sensorItems) { + // itemKey = keyMap.get(sItem.getItem().getId()); + // if(metricMap.containsKey(itemKey.getFroms()) == false) { + // metricMap.put(itemKey.getFroms(), new ArrayList<>()); + // } + // metricMap.get(itemKey.getFroms()).add(itemKey); + // } List itemList = new ArrayList<>(); Item item = null; @@ -76,9 +76,9 @@ public class InfraHostWMIGenerator { stringBuffer.append(", "); } - // keys = new Keys(); - // keys.setKey(tempItemKey.getKey()); - // keys.setMetric(tempItemKey.getItem().getKey()); + // keys = new Keys(); + // keys.setKey(tempItemKey.getKey()); + // keys.setMetric(tempItemKey.getItem().getKey()); keysList.add(this.generateUtil.createKeys(tempItemKey)); } @@ -86,7 +86,8 @@ public class InfraHostWMIGenerator { String json = tempItemKey.getOption(); if (json != null && json.length() > 0) { - HashMap optionMap = this.objectMapper.readValue(json, new TypeReference>(){}); + HashMap optionMap = this.objectMapper.readValue(json, new TypeReference>() { + }); Object obj = null; obj = optionMap.get("appends"); 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 1ec57e4..80902ea 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 @@ -1,6 +1,5 @@ package com.loafle.overflow.central.module.generator.service; -import com.loafle.overflow.central.commons.utils.StringConvertor; import com.loafle.overflow.core.type.PortType; import com.loafle.overflow.model.auth.AuthCrawler; import com.loafle.overflow.model.infra.Infra; @@ -31,89 +30,91 @@ import java.util.Map; @Service("InfraServiceGenerator") public class InfraServiceGenerator { - @Autowired - private GenerateUtil generateUtil; + @Autowired + private GenerateUtil generateUtil; - @Autowired - private InfraServiceMysqlGenerator infraServiceMysqlGenerator; + @Autowired + private InfraServiceMysqlGenerator infraServiceMysqlGenerator; - @Autowired - private InfraServiceJMXGenerator infraServiceJMXGenerator; + @Autowired + private InfraServiceJMXGenerator infraServiceJMXGenerator; - @Autowired - private AuthCrawlerService authCrawlerService; + @Autowired + private AuthCrawlerService authCrawlerService; - @Autowired - private ObjectMapper objectMapper; + @Autowired + private ObjectMapper objectMapper; - public String process(Sensor dbSensor, List sensorItems, Infra infra) throws Exception { - com.loafle.overflow.model.infra.InfraService infraService = (com.loafle.overflow.model.infra.InfraService)infra; + public String process(Sensor dbSensor, List sensorItems, Infra infra) throws Exception { + com.loafle.overflow.model.infra.InfraService infraService = (com.loafle.overflow.model.infra.InfraService) infra; - SensorConfig sensorConfig = new SensorConfig(); - sensorConfig.setConfigID(String.valueOf(dbSensor.getId())); + SensorConfig sensorConfig = new SensorConfig(); + sensorConfig.setConfigID(String.valueOf(dbSensor.getId())); - Target target = this.createTarget(infraService, dbSensor); + Target target = this.createTarget(infraService, dbSensor); - if(target == null) { - return null; - } - - - sensorConfig.setTarget(target); - - // FIXME: Interval - Schedule schedule = new Schedule(); - schedule.setInterval("5"); - sensorConfig.setSchedule(schedule); - - Crawler crawler = this.generateUtil.getCrawler(dbSensor.getMetaCrawler()); - sensorConfig.setCrawler(crawler); - - Map keyMap = this.generateUtil.initMappingMap(dbSensor.getMetaCrawler()); - - if(dbSensor.getMetaCrawler().getId() == MetaCrawlerEnum.MYSQL_CRAWLER.getValue()) { - this.infraServiceMysqlGenerator.process(sensorItems, keyMap, dbSensor, sensorConfig); - } else if (dbSensor.getMetaCrawler().getId() == MetaCrawlerEnum.JMX_CRAWLER.getValue()) { - this.infraServiceJMXGenerator.process(sensorItems, keyMap, dbSensor, sensorConfig); - } - - return objectMapper.writeValueAsString(sensorConfig); + if (target == null) { + return null; } - private Target createTarget(InfraService infraService, Sensor sensor) throws Exception { + sensorConfig.setTarget(target); - AuthCrawler authCrawler = this.authCrawlerService.readByMetaCrawlerIDAndTargetID(sensor.getMetaCrawler().getId(), sensor.getTarget().getId()); + // FIXME: Interval + Schedule schedule = new Schedule(); + schedule.setInterval("5"); + sensorConfig.setSchedule(schedule); - if(authCrawler == null) { - return null; - } + Crawler crawler = this.generateUtil.getCrawler(dbSensor.getMetaCrawler()); + sensorConfig.setCrawler(crawler); - Target target = new Target(); - Connection connection = new Connection(); - connection.setIp(infraService.getInfraHost().getIpv4()); - connection.setPort(infraService.getPort()); - connection.setPortType(PortType.valueOf(infraService.getPortType())); - connection.setSsl(infraService.isTlsType()); + Map keyMap = this.generateUtil.initMappingMap(dbSensor.getMetaCrawler()); - target.setConnection(connection); - - HashMap optionMap = this.objectMapper.readValue(authCrawler.getAuthJson(), new TypeReference>(){}); - - Map auth = new HashMap<>(); - - 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.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); - } - - target.setAuth(auth); - - return target; + if (dbSensor.getMetaCrawler().getId() == MetaCrawlerEnum.MYSQL_CRAWLER.getValue()) { + this.infraServiceMysqlGenerator.process(sensorItems, keyMap, dbSensor, sensorConfig); + } else if (dbSensor.getMetaCrawler().getId() == MetaCrawlerEnum.JMX_CRAWLER.getValue()) { + this.infraServiceJMXGenerator.process(sensorItems, keyMap, dbSensor, sensorConfig); } + return objectMapper.writeValueAsString(sensorConfig); + } + + private Target createTarget(InfraService infraService, Sensor sensor) throws Exception { + + AuthCrawler authCrawler = this.authCrawlerService.readByMetaCrawlerIDAndTargetID(sensor.getMetaCrawler().getId(), + sensor.getTarget().getId()); + + if (authCrawler == null) { + return null; + } + + Target target = new Target(); + Connection connection = new Connection(); + connection.setIp(infraService.getInfraHost().getIpv4()); + connection.setPort(infraService.getPort()); + connection.setPortType(PortType.valueOf(infraService.getPortType())); + connection.setSsl(infraService.isTlsType()); + + target.setConnection(connection); + + HashMap optionMap = this.objectMapper.readValue(authCrawler.getAuthJson(), + new TypeReference>() { + }); + + Map auth = new HashMap<>(); + + 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.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); + } + + target.setAuth(auth); + + return target; + } + } 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 7b28cad..1c51f8e 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 @@ -73,7 +73,8 @@ public class InfraServiceJMXGenerator { List arrayCol = null; if (json != null && json.length() > 0) { - HashMap optionMap = this.objectMapper.readValue(json, new TypeReference>(){}); + HashMap optionMap = this.objectMapper.readValue(json, new TypeReference>() { + }); Object obj = null; obj = optionMap.get("aliases"); diff --git a/src/main/java/com/loafle/overflow/central/module/generator/service/InfraServiceMysqlGenerator.java b/src/main/java/com/loafle/overflow/central/module/generator/service/InfraServiceMysqlGenerator.java index f3c5362..19c9a23 100644 --- a/src/main/java/com/loafle/overflow/central/module/generator/service/InfraServiceMysqlGenerator.java +++ b/src/main/java/com/loafle/overflow/central/module/generator/service/InfraServiceMysqlGenerator.java @@ -33,14 +33,14 @@ public class InfraServiceMysqlGenerator { public void process(List sensorItems, Map keyMap, Sensor dbSensor, SensorConfig sensorConfig) throws Exception { - // List keysList = new ArrayList<>(); - // for(SensorItem sItem : sensorItems) { - // keys = new Keys(); - // keys.setMetric(sItem.getItem().getKey()); - // keys.setKey(KeyMap.get(sItem.getItem().getId()).getKey()); - // keysList.add(keys); - // } - // item.setKeys(keysList); + // List keysList = new ArrayList<>(); + // for(SensorItem sItem : sensorItems) { + // keys = new Keys(); + // keys.setMetric(sItem.getItem().getKey()); + // keys.setKey(KeyMap.get(sItem.getItem().getId()).getKey()); + // keysList.add(keys); + // } + // item.setKeys(keysList); Map> metricMap = null; metricMap = this.generateUtil.sortItems(sensorItems, keyMap); @@ -81,7 +81,8 @@ public class InfraServiceMysqlGenerator { String json = tempItemKey.getOption(); if (json != null && json.length() > 0) { - HashMap optionMap = this.objectMapper.readValue(json, new TypeReference>(){}); + HashMap optionMap = this.objectMapper.readValue(json, new TypeReference>() { + }); Object obj = null; obj = optionMap.get("valueColumn"); @@ -113,42 +114,43 @@ public class InfraServiceMysqlGenerator { sensorConfig.setItems(itemList); - // ObjectMapper objectMapper = new ObjectMapper(); + // ObjectMapper objectMapper = new ObjectMapper(); // - // return objectMapper.writeValueAsString(config); + // return objectMapper.writeValueAsString(config); } - // public void setQueryAndMapping(MetaCrawler metaCrawler, List keysList, QueryInfo queryInfo, MappingInfo mappingInfo) { + // public void setQueryAndMapping(MetaCrawler metaCrawler, List keysList, + // QueryInfo queryInfo, MappingInfo mappingInfo) { // - // switch (metaCrawler.getId()) { - // case 11: // mysql - // { - // String query = "show status where "; - //// queryInfo.setQuery("show status where "); + // switch (metaCrawler.getId()) { + // case 11: // mysql + // { + // String query = "show status where "; + //// queryInfo.setQuery("show status where "); // - // Keys keys = null; - // for(int indexI = 0 ; indexI < keysList.size(); ++indexI) { - // keys = keysList.get(indexI); - // query += "variable_name = '"; - // query += keys.getKey(); - // query += "'"; - // if(indexI + 1 < keysList.size()) { - // query += " or "; - // } - // } + // Keys keys = null; + // for(int indexI = 0 ; indexI < keysList.size(); ++indexI) { + // keys = keysList.get(indexI); + // query += "variable_name = '"; + // query += keys.getKey(); + // query += "'"; + // if(indexI + 1 < keysList.size()) { + // query += " or "; + // } + // } // - // queryInfo.setQuery(query); + // queryInfo.setQuery(query); // - // mappingInfo.setParseDirection("row"); - // mappingInfo.setValueColumn("Value"); + // mappingInfo.setParseDirection("row"); + // mappingInfo.setValueColumn("Value"); // - // List keyColumns = new ArrayList<>(); - // keyColumns.add("Variable_name"); + // List keyColumns = new ArrayList<>(); + // keyColumns.add("Variable_name"); // - // mappingInfo.setKeyColumns(keyColumns); - // } - // break; - // } + // mappingInfo.setKeyColumns(keyColumns); + // } + // break; + // } // - // } + // } } 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 c640e96..123a43b 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 @@ -19,47 +19,44 @@ import com.loafle.overflow.service.central.sensor.SensorItemService; @Service("SensorConfigGenerator") public class SensorConfigGenerator { - @Autowired - private SensorItemService sensorItemService; + @Autowired + private SensorItemService sensorItemService; - @Autowired - private InfraService infraService; + @Autowired + private InfraService infraService; - @Autowired - private InfraHostGenerator infraHostGenerator; + @Autowired + private InfraHostGenerator infraHostGenerator; - @Autowired - private InfraServiceGenerator infraServiceGenerator; + @Autowired + private InfraServiceGenerator infraServiceGenerator; + public String generate(Sensor sensor) throws Exception { + PageParams pageParams = new PageParams(); + pageParams.setPageNo(0); + pageParams.setCountPerPage(Integer.MAX_VALUE); + pageParams.setSortCol("id"); + pageParams.setSortDirection("descending"); + Page dbItemList = this.sensorItemService.readAllBySensorID(sensor.getId(), pageParams); - public String generate(Sensor sensor) throws Exception { - PageParams pageParams = new PageParams(); - pageParams.setPageNo(0); - pageParams.setCountPerPage(Integer.MAX_VALUE); - pageParams.setSortCol("id"); - pageParams.setSortDirection("descending"); - Page dbItemList = this.sensorItemService.readAllBySensorID(sensor.getId(), pageParams); + List sensorItems = dbItemList.getContent(); - List sensorItems = dbItemList.getContent(); + if (sensorItems.size() <= 0) { + return ""; + } + Sensor dbSensor = sensorItems.get(0).getSensor(); - if(sensorItems.size() <= 0) { - return ""; - } - Sensor dbSensor = sensorItems.get(0).getSensor(); + Infra infra = this.infraService.readByTargetID(dbSensor.getTarget().getId()); - Infra infra = this.infraService.readByTargetID(dbSensor.getTarget().getId()); - - // 7 = Infra OS Service - if(infra.getMetaInfraType().getId() == 7) { - return this.infraServiceGenerator.process(dbSensor, sensorItems, infra); - } - if(infra.getMetaInfraType().getId() == 2) { - return this.infraHostGenerator.process(dbSensor, sensorItems, infra); - } - - return null; + // 7 = Infra OS Service + if (infra.getMetaInfraType().getId() == 7) { + return this.infraServiceGenerator.process(dbSensor, sensorItems, infra); + } + if (infra.getMetaInfraType().getId() == 2) { + return this.infraHostGenerator.process(dbSensor, sensorItems, infra); } - + return null; + } } 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 dbc47d4..612c98b 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 @@ -12,11 +12,11 @@ import org.springframework.stereotype.Repository; */ @Repository public interface HistoryDAO extends JpaRepository { - Page findAllByProbeId(Long probeID, Pageable pageable); + Page findAllByProbeId(Long probeID, Pageable pageable); - Page findAllByProbeIdAndMetaHistoryTypeId(Long probeID, Integer metaHistoryTypeId, Pageable pageable); + Page findAllByProbeIdAndMetaHistoryTypeId(Long probeID, Integer metaHistoryTypeId, Pageable pageable); - Page findAllByDomainId(Long domainID, Pageable pageRequest); + Page findAllByDomainId(Long domainID, Pageable pageRequest); - Page findAllByDomainIdAndMetaHistoryTypeId(Long domainID, Integer metaHistoryTypeId, 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 6e3dc10..e9b7210 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 @@ -4,10 +4,7 @@ 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; -import com.loafle.overflow.model.meta.MetaHistoryType; -import com.loafle.overflow.model.probe.Probe; import com.loafle.overflow.service.central.history.HistoryService; import org.springframework.beans.factory.annotation.Autowired; @@ -16,28 +13,31 @@ import org.springframework.stereotype.Service; @Service("HistoryService") public class CentralHistoryService implements HistoryService { - @Autowired - private HistoryDAO historyDAO; + @Autowired + private HistoryDAO historyDAO; - public History regist(History history) throws OverflowException { - return this.historyDAO.save(history); - } + public History regist(History history) throws OverflowException { + return this.historyDAO.save(history); + } + public Page readAllByProbeIDAndMetaHistoryTypeID(Long probeID, Integer metaHistoryTypeID, + PageParams pageParams) throws OverflowException { + return this.historyDAO.findAllByProbeIdAndMetaHistoryTypeId(probeID, metaHistoryTypeID, + 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) throws OverflowException { + return this.historyDAO.findAllByProbeId(probeID, PageUtil.getPageRequest(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) throws OverflowException { + return this.historyDAO.findAllByDomainId(domainID, PageUtil.getPageRequest(pageParams)); + } - public Page readAllByDomainID(Long domainID, PageParams pageParams) throws OverflowException { - return this.historyDAO.findAllByDomainId(domainID, PageUtil.getPageRequest(pageParams)); - } - - public Page readAllByDomainIDAndMetaHistoryTypeID(Long domainID, Integer metaHistoryTypeID, PageParams pageParams) throws OverflowException { - return this.historyDAO.findAllByDomainIdAndMetaHistoryTypeId(domainID, metaHistoryTypeID, 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 6b1899e..56bdd3b 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 @@ -15,14 +15,14 @@ import java.util.List; */ @Repository public interface InfraDAO extends JpaRepository { - List findAllByProbeId(Long probeID); + List findAllByProbeId(Long probeID); - Page findAllByProbeId(Long probeID, Pageable pageable); + Page findAllByProbeId(Long probeID, Pageable pageable); - Page findAllByProbeIn(List probes, Pageable pageable); + Page findAllByProbeIn(List probes, Pageable pageable); - List findAllTargetByProbeIn(List probes); + List findAllTargetByProbeIn(List probes); - // Infra findByTargetId(Long targetID); + // Infra findByTargetId(Long targetID); } \ No newline at end of file diff --git a/src/main/java/com/loafle/overflow/central/module/infra/dao/InfraHostDAO.java b/src/main/java/com/loafle/overflow/central/module/infra/dao/InfraHostDAO.java index 8d44f04..d030841 100644 --- a/src/main/java/com/loafle/overflow/central/module/infra/dao/InfraHostDAO.java +++ b/src/main/java/com/loafle/overflow/central/module/infra/dao/InfraHostDAO.java @@ -9,6 +9,6 @@ import org.springframework.stereotype.Repository; */ @Repository public interface InfraHostDAO extends JpaRepository { - InfraHost findByProbeIdAndIpv4(Long probeId, String ipv4); + InfraHost findByProbeIdAndIpv4(Long probeId, String ipv4); } \ 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 38c24b9..2367be3 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 @@ -9,5 +9,5 @@ import org.springframework.stereotype.Repository; */ @Repository public interface InfraOSPortDAO extends JpaRepository { - InfraOSPort findByInfraOSAndPortAndPortType(Long infraOSId, Integer port, String portType); + InfraOSPort findByInfraOSAndPortAndPortType(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 9d0d749..5b16135 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 @@ -9,5 +9,5 @@ import org.springframework.stereotype.Repository; */ @Repository public interface InfraServiceDAO extends JpaRepository { - InfraService findByInfraHostIdAndPortAndPortType(Long infraHostId, Integer port, 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 ee38c48..149863d 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; @@ -14,19 +13,19 @@ import org.springframework.stereotype.Service; @Service("InfraHostService") public class CentralInfraHostService implements InfraHostService { - @Autowired - InfraHostDAO infraHostDAO; + @Autowired + InfraHostDAO infraHostDAO; - public InfraHost regist(InfraHost infraHost) throws OverflowException { - return this.infraHostDAO.save(infraHost); - } + public InfraHost regist(InfraHost infraHost) throws OverflowException { + return this.infraHostDAO.save(infraHost); + } - public InfraHost read(Long id) throws OverflowException { - return this.infraHostDAO.findById(id).get(); - } + public InfraHost read(Long id) throws OverflowException { + return this.infraHostDAO.findById(id).get(); + } - public InfraHost readByProbeIdAndIpv4(Long probeId, String ip) throws OverflowException { - return this.infraHostDAO.findByProbeIdAndIpv4(probeId, ip); - } + public InfraHost readByProbeIdAndIpv4(Long probeId, String ip) throws OverflowException { + return this.infraHostDAO.findByProbeIdAndIpv4(probeId, ip); + } } diff --git a/src/main/java/com/loafle/overflow/central/module/infra/service/CentralInfraMachineService.java b/src/main/java/com/loafle/overflow/central/module/infra/service/CentralInfraMachineService.java index e230a1f..946cec4 100644 --- a/src/main/java/com/loafle/overflow/central/module/infra/service/CentralInfraMachineService.java +++ b/src/main/java/com/loafle/overflow/central/module/infra/service/CentralInfraMachineService.java @@ -12,14 +12,14 @@ import org.springframework.stereotype.Service; */ @Service("InfraMachineService") public class CentralInfraMachineService implements InfraMachineService { - @Autowired - InfraMachineDAO infraMachineDAO; + @Autowired + InfraMachineDAO infraMachineDAO; - public InfraMachine regist(InfraMachine infraMachine) throws OverflowException { - return this.infraMachineDAO.save(infraMachine); - } + public InfraMachine regist(InfraMachine infraMachine) throws OverflowException { + return this.infraMachineDAO.save(infraMachine); + } - public InfraMachine read(Long id) { - return this.infraMachineDAO.findById(id).get(); - } + public InfraMachine read(Long id) { + return this.infraMachineDAO.findById(id).get(); + } } 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 0d2f3ad..bd071aa 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 @@ -13,14 +13,14 @@ import org.springframework.stereotype.Service; @Service("InfraOSApplicationService") public class CentralInfraOSApplicationService implements InfraOSApplicationService { - @Autowired - InfraOSApplicationDAO infraOSApplicationDAO; + @Autowired + InfraOSApplicationDAO infraOSApplicationDAO; - public InfraOSApplication regist(InfraOSApplication infraOSApplication) throws OverflowException { - return this.infraOSApplicationDAO.save(infraOSApplication); - } + public InfraOSApplication regist(InfraOSApplication infraOSApplication) throws OverflowException { + return this.infraOSApplicationDAO.save(infraOSApplication); + } - public InfraOSApplication read(Long id) throws OverflowException { - return this.infraOSApplicationDAO.findById(id).get(); - } + public InfraOSApplication read(Long id) throws OverflowException { + return this.infraOSApplicationDAO.findById(id).get(); + } } diff --git a/src/main/java/com/loafle/overflow/central/module/infra/service/CentralInfraOSDaemonService.java b/src/main/java/com/loafle/overflow/central/module/infra/service/CentralInfraOSDaemonService.java index 018b533..4f13ede 100644 --- a/src/main/java/com/loafle/overflow/central/module/infra/service/CentralInfraOSDaemonService.java +++ b/src/main/java/com/loafle/overflow/central/module/infra/service/CentralInfraOSDaemonService.java @@ -13,14 +13,14 @@ import org.springframework.stereotype.Service; @Service("InfraOSDaemonService") public class CentralInfraOSDaemonService implements InfraOSDaemonService { - @Autowired - InfraOSDaemonDAO infraOSDaemonDAO; + @Autowired + InfraOSDaemonDAO infraOSDaemonDAO; - public InfraOSDaemon regist(InfraOSDaemon infraOSDaemon) throws OverflowException { - return this.infraOSDaemonDAO.save(infraOSDaemon); - } + public InfraOSDaemon regist(InfraOSDaemon infraOSDaemon) throws OverflowException { + return this.infraOSDaemonDAO.save(infraOSDaemon); + } - public InfraOSDaemon read(Long id) throws OverflowException { - return this.infraOSDaemonDAO.findById(id).get(); - } + public InfraOSDaemon read(Long id) throws OverflowException { + return this.infraOSDaemonDAO.findById(id).get(); + } } 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 e623dbe..859fbfa 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 @@ -13,19 +13,19 @@ import org.springframework.stereotype.Service; @Service("InfraOSPortService") public class CentralInfraOSPortService implements InfraOSPortService { - @Autowired - InfraOSPortDAO infraOSPortDAO; + @Autowired + InfraOSPortDAO infraOSPortDAO; - public InfraOSPort regist(InfraOSPort infraOSPort) throws OverflowException { - return this.infraOSPortDAO.save(infraOSPort); - } + public InfraOSPort regist(InfraOSPort infraOSPort) throws OverflowException { + return this.infraOSPortDAO.save(infraOSPort); + } - public InfraOSPort read(Long id) throws OverflowException { - return this.infraOSPortDAO.findById(id).get(); - } + public InfraOSPort read(Long id) throws OverflowException { + return this.infraOSPortDAO.findById(id).get(); + } - public InfraOSPort readByInfraOSIDAndPortAndPortType(Long infraOSID, Integer port, String portType) - throws OverflowException { - return this.infraOSPortDAO.findByInfraOSAndPortAndPortType(infraOSID, port, portType); - } + public InfraOSPort readByInfraOSIDAndPortAndPortType(Long infraOSID, Integer port, String portType) + throws OverflowException { + return this.infraOSPortDAO.findByInfraOSAndPortAndPortType(infraOSID, port, portType); + } } diff --git a/src/main/java/com/loafle/overflow/central/module/infra/service/CentralInfraOSService.java b/src/main/java/com/loafle/overflow/central/module/infra/service/CentralInfraOSService.java index d19a078..ff2498e 100644 --- a/src/main/java/com/loafle/overflow/central/module/infra/service/CentralInfraOSService.java +++ b/src/main/java/com/loafle/overflow/central/module/infra/service/CentralInfraOSService.java @@ -13,14 +13,14 @@ import org.springframework.stereotype.Service; @Service("InfraOSService") public class CentralInfraOSService implements InfraOSService { - @Autowired - InfraOSDAO infraOSDAO; + @Autowired + InfraOSDAO infraOSDAO; - public InfraOS regist(InfraOS infraOS) throws OverflowException { - return this.infraOSDAO.save(infraOS); - } + public InfraOS regist(InfraOS infraOS) throws OverflowException { + return this.infraOSDAO.save(infraOS); + } - public InfraOS read(Long id) throws OverflowException { - return this.infraOSDAO.findById(id).get(); - } + public InfraOS read(Long id) throws OverflowException { + return this.infraOSDAO.findById(id).get(); + } } 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 e335c24..ba80aa2 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 @@ -24,58 +24,58 @@ import java.util.List; @Service("InfraService") public class CentralInfraService implements InfraService { - @Autowired - InfraDAO infraDAO; + @Autowired + InfraDAO infraDAO; - @Autowired - SensorDAO sensorDAO; + @Autowired + SensorDAO sensorDAO; - @Autowired - private ProbeService probeService; + @Autowired + private ProbeService probeService; - public Infra regist(Infra infra) throws OverflowException { - return this.infraDAO.save(infra); + public Infra regist(Infra infra) throws OverflowException { + return this.infraDAO.save(infra); + } + + public Infra read(Long id) throws OverflowException { + Infra infra = this.infraDAO.findById(id).get(); + return infra; + } + + public Page readAllByProbeID(Long probeID, PageParams pageParams) throws OverflowException { + return this.infraDAO.findAllByProbeId(probeID, PageUtil.getPageRequest(pageParams)); + } + + public Page readAllByDomainID(Long domainID, PageParams pageParams) throws OverflowException { + List probeList = this.probeService.readAllByDomainID(domainID); + + if (probeList == null || probeList.size() <= 0) { + throw new OverflowException("ProbeNotFoundException", new Throwable()); } - public Infra read(Long id) throws OverflowException { - Infra infra = this.infraDAO.findById(id).get(); - return infra; + Page infraList = this.infraDAO.findAllByProbeIn(probeList, PageUtil.getPageRequest(pageParams)); + return infraList; + } + + public List readAllTargetByDomainID(Long domainID) throws OverflowException { + + List probes = this.probeService.readAllByDomainID(domainID); + + if (probes == null || probes.size() <= 0) { + throw new OverflowException("ProbeNotFoundException", new Throwable()); } - public Page readAllByProbeID(Long probeID, PageParams pageParams) throws OverflowException { - return this.infraDAO.findAllByProbeId(probeID, PageUtil.getPageRequest(pageParams)); - } + return this.infraDAO.findAllTargetByProbeIn(probes); + } - public Page readAllByDomainID(Long domainID, PageParams pageParams) throws OverflowException { - List probeList = this.probeService.readAllByDomainID(domainID); + public List readAllTargetByProbes(List probes) throws OverflowException { + return this.infraDAO.findAllTargetByProbeIn(probes); + // return null; + } - if (probeList == null || probeList.size() <= 0) { - throw new OverflowException("ProbeNotFoundException", new Throwable()); - } - - Page infraList = this.infraDAO.findAllByProbeIn(probeList, PageUtil.getPageRequest(pageParams)); - return infraList; - } - - public List readAllTargetByDomainID(Long domainID) throws OverflowException { - - List probes = this.probeService.readAllByDomainID(domainID); - - if (probes == null || probes.size() <= 0) { - throw new OverflowException("ProbeNotFoundException", new Throwable()); - } - - return this.infraDAO.findAllTargetByProbeIn(probes); - } - - public List readAllTargetByProbes(List probes) throws OverflowException { - return this.infraDAO.findAllTargetByProbeIn(probes); - // return null; - } - - public Infra readByTargetID(Long targetID) throws OverflowException { - // return this.infraDAO.findByTargetId(targetID); - return null; - } + public Infra readByTargetID(Long targetID) throws OverflowException { + // return this.infraDAO.findByTargetId(targetID); + return null; + } } 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 6abc79b..0574087 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 @@ -13,19 +13,19 @@ import org.springframework.stereotype.Service; @Service("InfraServiceService") public class CentralInfraServiceService implements InfraServiceService { - @Autowired - InfraServiceDAO infraServiceDAO; + @Autowired + InfraServiceDAO infraServiceDAO; - public InfraService regist(InfraService infraService) throws OverflowException { - return this.infraServiceDAO.save(infraService); - } + public InfraService regist(InfraService infraService) throws OverflowException { + return this.infraServiceDAO.save(infraService); + } - public InfraService read(Long id) throws OverflowException { - return this.infraServiceDAO.findById(id).get(); - } + public InfraService read(Long id) throws OverflowException { + return this.infraServiceDAO.findById(id).get(); + } - public InfraService readByInfraHostIDAndPortAndPortType(Long infraHostID, int port, String portType) - throws OverflowException { - return this.infraServiceDAO.findByInfraHostIdAndPortAndPortType(infraHostID, port, 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 5c61481..c6d9f50 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 @@ -10,5 +10,5 @@ import org.springframework.stereotype.Repository; @Repository public interface MemberDAO extends JpaRepository { - Member findByEmail(String email); + 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 3942d5e..7e5c2cd 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 @@ -9,7 +9,7 @@ import org.springframework.stereotype.Repository; */ @Repository public interface MemberTotpDAO extends JpaRepository { - MemberTotp findBySecretCode(String secretCode); + MemberTotp findBySecretCode(String secretCode); - MemberTotp findByMemberEmail(String memberEmail); + 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 36bef05..f58468e 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 @@ -32,264 +32,258 @@ import java.util.regex.Pattern; @Service("MemberService") public class CentralMemberService implements MemberService { - @Autowired - private MemberDAO memberDAO; + @Autowired + private MemberDAO memberDAO; - @Autowired - private EmailAuthService emailAuthService; + @Autowired + private EmailAuthService emailAuthService; - @Autowired - private ApiKeyService apiKeyService; + @Autowired + private ApiKeyService apiKeyService; - @Autowired - private DomainMemberService domainMemberService; + @Autowired + private DomainMemberService domainMemberService; - @Autowired - private ProbeService probeService; + @Autowired + private ProbeService probeService; - private BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder(); + private BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder(); - public DomainMember signin(String signinId, String signinPw) throws OverflowException { - Member m = this.memberDAO.findByEmail(signinId); + public DomainMember signin(String signinId, String signinPw) throws OverflowException { + Member m = this.memberDAO.findByEmail(signinId); - if ( null == m ) { - throw new OverflowException("SignInIdNotExistException()", new Throwable()); - } - - if ( m.getMetaMemberStatus().getId() == 1 ) { - throw new OverflowException("EmailNotConfirmedException()", new Throwable()); - } - - Boolean match = passwordEncoder.matches(signinPw, m.getPw()); - if(!match) { - if (m.getSigninFailCount() > 10) { - throw new OverflowException("SigninOverFailedException()", new Throwable()); - } - m.setSigninFailCount(m.getSigninFailCount()+1); - this.modify(m); - throw new OverflowException("SignInPwNotMatchException()", new Throwable()); - } - - m.setSigninFailCount(0); - this.modify(m); - - DomainMember dm = domainMemberService.readByMemberEmail(m.getEmail()); - - // Todo Signin History - return dm; + if (null == m) { + throw new OverflowException("SignInIdNotExistException()", new Throwable()); } - public Member signup(Member member, String pw) throws OverflowException { + if (m.getMetaMemberStatus().getId() == 1) { + throw new OverflowException("EmailNotConfirmedException()", new Throwable()); + } - Member isMember = this.memberDAO.findByEmail(member.getEmail()); + Boolean match = passwordEncoder.matches(signinPw, m.getPw()); + if (!match) { + if (m.getSigninFailCount() > 10) { + throw new OverflowException("SigninOverFailedException()", new Throwable()); + } + m.setSigninFailCount(m.getSigninFailCount() + 1); + this.modify(m); + throw new OverflowException("SignInPwNotMatchException()", new Throwable()); + } - if (null != isMember && isMember.getId() > 0) { - throw new OverflowException("JoinedEmailException()", new Throwable()); - } + m.setSigninFailCount(0); + this.modify(m); - boolean checkPass = this.isPasswordStrong(pw); + DomainMember dm = domainMemberService.readByMemberEmail(m.getEmail()); - if (!checkPass) { - throw new OverflowException("PasswordNotStrongException()", new Throwable()); -// ( -// "Passwords must contain at least one uppercase letter, " + -// "special character, lowercase letter, and number, " + -// "and must be at least 6 characters long."); - } + // Todo Signin History + return dm; + } + + public Member signup(Member member, String pw) throws OverflowException { + + Member isMember = this.memberDAO.findByEmail(member.getEmail()); + + if (null != isMember && isMember.getId() > 0) { + throw new OverflowException("JoinedEmailException()", new Throwable()); + } + + boolean checkPass = this.isPasswordStrong(pw); + + if (!checkPass) { + throw new OverflowException("PasswordNotStrongException()", new Throwable()); + // ( + // "Passwords must contain at least one uppercase letter, " + + // "special character, lowercase letter, and number, " + + // "and must be at least 6 characters long."); + } + member.setPw(passwordEncoder.encode(pw)); + + if (member.getMetaMemberStatus() == null) { + member.setMetaMemberStatus(new MetaMemberStatus((short) 1)); + } + + member.setTotpType(false); + + Member resMember = this.memberDAO.save(member); + + try { + this.emailAuthService.sendEmailByMember(resMember); + } catch (Exception e) { + // Todo ReSend Mail + e.printStackTrace(); + } + + return resMember; + } + + public Member sendEmailForPassword(String email) throws OverflowException { + Member member = this.memberDAO.findByEmail(email); + + if (null == member) { + throw new OverflowException("SignInIdNotExistException()", new Throwable()); + } + + try { + this.emailAuthService.sendEmailResetPassword(member); + } catch (Exception e) { + // Todo ReSend Mail + e.printStackTrace(); + } + + return member; + } + + public Member resetPassword(String token, String pw) throws OverflowException { + String deStr = null; + + try { + deStr = URLDecoder.decode(token, "UTF-8"); + } catch (Exception e) { + + } + + // String deEmail = this.emailSender.decrypt(deStr); + EmailAuth auth = this.emailAuthService.readByToken(deStr); + + if (auth == null) { + throw new OverflowException("Not Exist Token", null); + } + + Member member = this.memberDAO.findByEmail(auth.getMember().getEmail()); + + if (null == member) { + throw new OverflowException("", null); + } + + boolean checkPass = this.isPasswordStrong(pw); + + if (!checkPass) { + throw new OverflowException("PasswordNotStrongException()", new Throwable()); + // "Passwords must contain at least one uppercase letter, " + + // "special character, lowercase letter, and number, " + + // "and must be at least 6 characters long."); + } + member.setPw(passwordEncoder.encode(pw)); + + return this.modify(member); + } + + public void signout(Member member) { + // Todo websocket session remove + } + + @WebappAPI + public Member modify(Member member, String pw) throws OverflowException { + String email = SessionMetadata.getTargetID(); + Member preMember = this.memberDAO.findByEmail(member.getEmail()); + + if (null == preMember || 0 >= preMember.getId()) { + throw new OverflowException("SigninId Not Exist()", new Throwable()); + } + member.setId(preMember.getId()); + if (null != pw && !pw.equals("")) { + boolean checkPass = this.isPasswordStrong(pw); + + if (!checkPass) { + throw new OverflowException("PasswordNotStrongException()", new Throwable()); + // "Passwords must contain at least one uppercase letter, " + + // "special character, lowercase letter, and number, " + + // "and must be at least 6 characters long."); + } + + Boolean match = passwordEncoder.matches(member.getPw(), preMember.getPw()); + if (!match) { member.setPw(passwordEncoder.encode(pw)); - - if (member.getMetaMemberStatus() == null) { - member.setMetaMemberStatus(new MetaMemberStatus((short) 1)); - } - - member.setTotpType(false); - - Member resMember = this.memberDAO.save(member); - - try { - this.emailAuthService.sendEmailByMember(resMember); - } catch (Exception e) { - // Todo ReSend Mail - e.printStackTrace(); - } - - return resMember; + } + } else { + member.setPw(preMember.getPw()); } - public Member sendEmailForPassword(String email) throws OverflowException { - Member member = this.memberDAO.findByEmail(email); + if (member.getMetaMemberStatus() == null || member.getMetaMemberStatus().getId() <= 0) { + member.setMetaMemberStatus(new MetaMemberStatus()); + member.getMetaMemberStatus().setId(preMember.getMetaMemberStatus().getId()); + } + return this.modify(member); + } - if (null == member) { - throw new OverflowException("SignInIdNotExistException()", new Throwable()); - } + private Member modify(Member member) throws OverflowException { + return this.memberDAO.save(member); + } - try { - this.emailAuthService.sendEmailResetPassword(member); - } catch (Exception e) { - // Todo ReSend Mail - e.printStackTrace(); - } + public Member confirmPw(String signinId, String signinPw) throws OverflowException { + Member preMember = this.memberDAO.findByEmail(signinId); - return member; + String encodePw = passwordEncoder.encode(signinPw); + Boolean match = passwordEncoder.matches(encodePw, preMember.getPw()); + + if (!match) { + throw new OverflowException("SignInPwNotMatchException", new Throwable()); } - public Member resetPassword(String token, String pw) throws OverflowException { - String deStr = null; + return preMember; + } - try { - deStr = URLDecoder.decode(token, "UTF-8"); - }catch (Exception e) { + public Member forgotPassword(String signinId, String newPw) throws OverflowException { + Member preMember = this.memberDAO.findByEmail(signinId); - } - -// String deEmail = this.emailSender.decrypt(deStr); - EmailAuth auth = this.emailAuthService.readByToken(deStr); - - if (auth == null) { - throw new OverflowException("Not Exist Token", null); - } - - Member member = this.memberDAO.findByEmail(auth.getMember().getEmail()); - - if (null == member) { - throw new OverflowException("", null); - } - - boolean checkPass = this.isPasswordStrong(pw); - - if (!checkPass) { - throw new OverflowException("PasswordNotStrongException()", new Throwable()); -// "Passwords must contain at least one uppercase letter, " + -// "special character, lowercase letter, and number, " + -// "and must be at least 6 characters long."); - } - member.setPw(passwordEncoder.encode(pw)); - - return this.modify(member); + if (null == preMember) { + throw new OverflowException("SignInIdNotExistException()", new Throwable()); } - public void signout(Member member) { - // Todo websocket session remove + Member cMember = this.modify(preMember, newPw); + + return cMember; + } + + public Member read(Long memberId) throws OverflowException { + if (memberId <= 0) { + throw new OverflowException("SignInIdNotExistException()", new Throwable()); } - @WebappAPI - public Member modify(Member member, String pw) throws OverflowException { - String email = SessionMetadata.getTargetID(); - Member preMember = this.memberDAO.findByEmail(member.getEmail()); + Member resMember = this.memberDAO.findById(memberId).get(); + return resMember; + } - if (null == preMember || 0 >= preMember.getId()) { - throw new OverflowException("SigninId Not Exist()", new Throwable()); - } - member.setId(preMember.getId()); - if (null != pw && !pw.equals("")) { - boolean checkPass = this.isPasswordStrong(pw); + @WebappAPI + public void withdrawal(Long memberId) throws OverflowException { + String email = SessionMetadata.getTargetID(); - if (!checkPass) { - throw new OverflowException("PasswordNotStrongException()", new Throwable()); -// "Passwords must contain at least one uppercase letter, " + -// "special character, lowercase letter, and number, " + -// "and must be at least 6 characters long."); - } + // Todo DB delete? + } - Boolean match = passwordEncoder.matches(member.getPw(), preMember.getPw()); - if(!match) { - member.setPw(passwordEncoder.encode(pw)); - } - } else { - member.setPw(preMember.getPw()); - } + public List readAllByProbeKey(String probeKey) throws OverflowException { - if (member.getMetaMemberStatus() == null || member.getMetaMemberStatus().getId() <= 0) { - member.setMetaMemberStatus(new MetaMemberStatus()); - member.getMetaMemberStatus().setId(preMember.getMetaMemberStatus().getId()); - } - return this.modify(member); + Probe probe = this.probeService.readByProbeKey(probeKey); + + if (probe == null) { + return null; } - private Member modify(Member member) throws OverflowException { - return this.memberDAO.save(member); + return this.domainMemberService.readAllMemberByDomainID(probe.getDomain().getId()); + } + + public List readAllByApiKey(String apikey) throws OverflowException { + + ApiKey apiKey = this.apiKeyService.readByApiKey(apikey); + + if (apiKey == null) { + return null; } - public Member confirmPw(String signinId, String signinPw) throws OverflowException { - Member preMember = this.memberDAO.findByEmail(signinId); + return this.domainMemberService.readAllMemberByDomainID(apiKey.getDomain().getId()); + } - String encodePw = passwordEncoder.encode(signinPw); - Boolean match = passwordEncoder.matches(encodePw, preMember.getPw()); + public List readAllByDomainID(final Long domainID) throws OverflowException { - if (!match) { - throw new OverflowException("SignInPwNotMatchException", new Throwable()); - } + return this.domainMemberService.readAllMemberByDomainID(domainID); + } - return preMember; - } + private static final String PASSWORD_REGEXP = "(" + "(?=.*[a-z])" + "(?=.*\\d)" + "(?=.*[A-Z])" + + "(?=.*[!@#$%^&*()_+\\-=\\[\\]{};':\"\\\\|,.<>\\/?])" + "." + "{6,40}" + ")"; + private Pattern pattern = Pattern.compile(PASSWORD_REGEXP); - public Member forgotPassword(String signinId, String newPw) throws OverflowException { - Member preMember = this.memberDAO.findByEmail(signinId); - - if (null == preMember) { - throw new OverflowException("SignInIdNotExistException()", new Throwable()); - } - - Member cMember = this.modify(preMember, newPw); - - return cMember; - } - - public Member read(Long memberId) throws OverflowException { - if (memberId <= 0) { - throw new OverflowException("SignInIdNotExistException()", new Throwable()); - } - - Member resMember = this.memberDAO.findById(memberId).get(); - return resMember; - } - - @WebappAPI - public void withdrawal(Long memberId) throws OverflowException { - String email = SessionMetadata.getTargetID(); - - // Todo DB delete? - } - - public List readAllByProbeKey(String probeKey) throws OverflowException { - - Probe probe = this.probeService.readByProbeKey(probeKey); - - if(probe == null) { - return null; - } - - return this.domainMemberService.readAllMemberByDomainID(probe.getDomain().getId()); - } - - public List readAllByApiKey(String apikey) throws OverflowException { - - ApiKey apiKey = this.apiKeyService.readByApiKey(apikey); - - if(apiKey == null) { - return null; - } - - return this.domainMemberService.readAllMemberByDomainID(apiKey.getDomain().getId()); - } - - public List readAllByDomainID(final Long domainID) throws OverflowException { - - return this.domainMemberService.readAllMemberByDomainID(domainID); - } - - private static final String PASSWORD_REGEXP = "(" + - "(?=.*[a-z])" + - "(?=.*\\d)" + - "(?=.*[A-Z])" + - "(?=.*[!@#$%^&*()_+\\-=\\[\\]{};':\"\\\\|,.<>\\/?])" + - "." + - "{6,40}" + - ")"; - private Pattern pattern = Pattern.compile(PASSWORD_REGEXP); - - protected boolean isPasswordStrong(String pass) { - Matcher m = pattern.matcher(pass); - return m.matches(); - } + protected boolean isPasswordStrong(String pass) { + Matcher m = pattern.matcher(pass); + return m.matches(); + } } 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 179e96b..0b8186d 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 @@ -19,99 +19,100 @@ import java.util.Map; */ @Service("MemberTotpService") public class CentralMemberTotpService implements MemberTotpService { - @Autowired - private MemberTotpDAO totpDAO; + @Autowired + private MemberTotpDAO totpDAO; - public void regist(Member member, String secretCode, String code) throws OverflowException { + public void regist(Member member, String secretCode, String code) throws OverflowException { - if (null == member || 0 >= member.getId()) { - throw new OverflowException("SignInIdNotExistException", new Throwable()); + if (null == member || 0 >= member.getId()) { + throw new OverflowException("SignInIdNotExistException", new Throwable()); + } + + if (!this.checkCode(secretCode, code)) { + throw new OverflowException("TotpCodeNotMatchException", new Throwable()); + } + + MemberTotp totp = new MemberTotp(); + totp.setMember(member); + totp.setSecretCode(secretCode); + + this.totpDAO.save(totp); + } + + public MemberTotp modify(MemberTotp totp) throws OverflowException { + if (null == totp.getSecretCode() || totp.getSecretCode().equals("")) { + throw new OverflowException("SecretCodeNotExistException", new Throwable()); + } + if (null == totp.getMember() || 0 < totp.getMember().getId()) { + throw new OverflowException("SignInIdNotExistException", new Throwable()); + } + + return this.totpDAO.save(totp); + } + + public void remove(Long id) throws OverflowException { + this.totpDAO.deleteById(id); + } + + public MemberTotp read(Long id) throws OverflowException { + return this.totpDAO.findById(id).get(); + } + + 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()); + } + return this.checkCode(totp.getSecretCode(), code); + } + + public boolean checkCode(String secretCode, String code) throws OverflowException { + GoogleAuthenticator googleAuthenticator = new GoogleAuthenticator(); + int codeInt = Integer.parseInt(code); + boolean isCheck = googleAuthenticator.authorize(secretCode, codeInt); + + if (!isCheck) { + throw new OverflowException("TotpCodeNotMatchException", new Throwable()); + } + + return isCheck; + } + + public Map createTotp(Member member) throws OverflowException { + Map returnMap = new HashMap<>(); + + GoogleAuthenticator googleAuthenticator = new GoogleAuthenticator(); + final GoogleAuthenticatorKey key = googleAuthenticator.createCredentials(); + + String secret = key.getKey(); + // List scratchCodes = key.getScratchCodes(); + // String otpAuthURL = GoogleAuthenticatorQRGenerator.getOtpAuthURL("overFlow", + // member.getEmail(), key); + URIBuilder uri = (new URIBuilder()).setScheme("otpauth").setHost("totp") + .setPath("/" + formatLabel("overFlow", member.getEmail())).setParameter("secret", key.getKey()); + + returnMap.put("key", secret); + returnMap.put("uri", uri.toString()); + + return returnMap; + } + + private String formatLabel(String issuer, String accountName) throws OverflowException { + if (accountName != null && accountName.trim().length() != 0) { + StringBuilder sb = new StringBuilder(); + if (issuer != null) { + if (issuer.contains(":")) { + throw new IllegalArgumentException("Issuer cannot contain the ':' character."); } - if (!this.checkCode(secretCode, code)) { - throw new OverflowException("TotpCodeNotMatchException", new Throwable()); - } + sb.append(issuer); + sb.append(":"); + } - MemberTotp totp = new MemberTotp(); - totp.setMember(member); - totp.setSecretCode(secretCode); - - this.totpDAO.save(totp); - } - - public MemberTotp modify(MemberTotp totp) throws OverflowException { - if (null == totp.getSecretCode() || totp.getSecretCode().equals("")) { - throw new OverflowException("SecretCodeNotExistException", new Throwable()); - } - if (null == totp.getMember() || 0 < totp.getMember().getId()) { - throw new OverflowException("SignInIdNotExistException", new Throwable()); - } - - return this.totpDAO.save(totp); - } - - public void remove(Long id) throws OverflowException { - this.totpDAO.deleteById(id); - } - - public MemberTotp read(Long id) throws OverflowException { - return this.totpDAO.findById(id).get(); - } - - 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()); - } - return this.checkCode(totp.getSecretCode(), code); - } - - public boolean checkCode(String secretCode, String code) throws OverflowException { - GoogleAuthenticator googleAuthenticator = new GoogleAuthenticator(); - int codeInt = Integer.parseInt(code); - boolean isCheck = googleAuthenticator.authorize(secretCode, codeInt); - - if (!isCheck) { - throw new OverflowException("TotpCodeNotMatchException", new Throwable()); - } - - return isCheck; - } - - public Map createTotp(Member member) throws OverflowException { - Map returnMap = new HashMap<>(); - - GoogleAuthenticator googleAuthenticator = new GoogleAuthenticator(); - final GoogleAuthenticatorKey key = googleAuthenticator.createCredentials(); - - String secret = key.getKey(); - // List scratchCodes = key.getScratchCodes(); - // String otpAuthURL = GoogleAuthenticatorQRGenerator.getOtpAuthURL("overFlow", member.getEmail(), key); - URIBuilder uri = (new URIBuilder()).setScheme("otpauth").setHost("totp") - .setPath("/" + formatLabel("overFlow", member.getEmail())).setParameter("secret", key.getKey()); - - returnMap.put("key", secret); - returnMap.put("uri", uri.toString()); - - return returnMap; - } - - private String formatLabel(String issuer, String accountName) throws OverflowException { - if (accountName != null && accountName.trim().length() != 0) { - StringBuilder sb = new StringBuilder(); - if (issuer != null) { - if (issuer.contains(":")) { - throw new IllegalArgumentException("Issuer cannot contain the ':' character."); - } - - sb.append(issuer); - sb.append(":"); - } - - sb.append(accountName); - return sb.toString(); - } else { - throw new IllegalArgumentException("Account name must not be empty."); - } + sb.append(accountName); + return sb.toString(); + } else { + throw new IllegalArgumentException("Account name must not be empty."); } + } } 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 bf4f09d..df6b5db 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 @@ -11,5 +11,5 @@ import java.util.List; */ @Repository public interface MetaCrawlerInputItemDAO extends JpaRepository { - List findAllByMetaCrawlerId(Short metaCrawlerId); + 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 c35149f..2c0c13f 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 @@ -11,5 +11,5 @@ import java.util.List; */ @Repository public interface MetaInfraVendorDAO extends JpaRepository { - List findAllByMetaInfraTypeId(Integer MetaInfraTypeId); + 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 2ecf4d5..d4ee377 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 @@ -11,5 +11,5 @@ import java.util.List; */ @Repository public interface MetaProbePackageDAO extends JpaRepository { - List findAllByMetaProbeOsId(Short metaProbeOsId); + List findAllByMetaProbeOsId(Short metaProbeOsId); } diff --git a/src/main/java/com/loafle/overflow/central/module/meta/dao/MetaProbeStatusDAO.java b/src/main/java/com/loafle/overflow/central/module/meta/dao/MetaProbeStatusDAO.java index f9511ee..80e20a2 100644 --- a/src/main/java/com/loafle/overflow/central/module/meta/dao/MetaProbeStatusDAO.java +++ b/src/main/java/com/loafle/overflow/central/module/meta/dao/MetaProbeStatusDAO.java @@ -8,6 +8,5 @@ import org.springframework.stereotype.Repository; * Created by snoop on 17. 6. 26. */ @Repository -public interface MetaProbeStatusDAO extends JpaRepository { +public interface MetaProbeStatusDAO extends JpaRepository { } - diff --git a/src/main/java/com/loafle/overflow/central/module/meta/dao/MetaProbeTaskTypeDAO.java b/src/main/java/com/loafle/overflow/central/module/meta/dao/MetaProbeTaskTypeDAO.java index 0db81dc..9f07939 100644 --- a/src/main/java/com/loafle/overflow/central/module/meta/dao/MetaProbeTaskTypeDAO.java +++ b/src/main/java/com/loafle/overflow/central/module/meta/dao/MetaProbeTaskTypeDAO.java @@ -8,5 +8,5 @@ import org.springframework.stereotype.Repository; * Created by insanity on 17. 6. 23. */ @Repository -public interface MetaProbeTaskTypeDAO extends JpaRepository{ +public interface MetaProbeTaskTypeDAO extends JpaRepository { } diff --git a/src/main/java/com/loafle/overflow/central/module/meta/dao/MetaProbeVersionDAO.java b/src/main/java/com/loafle/overflow/central/module/meta/dao/MetaProbeVersionDAO.java index d62ed78..2712382 100644 --- a/src/main/java/com/loafle/overflow/central/module/meta/dao/MetaProbeVersionDAO.java +++ b/src/main/java/com/loafle/overflow/central/module/meta/dao/MetaProbeVersionDAO.java @@ -8,5 +8,5 @@ import org.springframework.stereotype.Repository; * Created by insanity on 17. 6. 23. */ @Repository -public interface MetaProbeVersionDAO extends JpaRepository{ +public interface MetaProbeVersionDAO extends JpaRepository { } 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 2e0e731..7987182 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 @@ -11,5 +11,5 @@ import java.util.List; */ @Repository public interface MetaSensorDisplayItemDAO extends JpaRepository { - public List findAllByMetaCrawlerId(Short metaCrawlerId); + 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 ead747f..956bbc9 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 @@ -15,6 +15,7 @@ import java.util.List; @Repository public interface MetaSensorDisplayMappingDAO extends JpaRepository { - @Query("SELECT m.metaSensorItemKey from MetaSensorDisplayMapping m where m.metaSensorDisplayItem.id = :metaSensorDisplayItemId") - public List findAllMetaSensorItemKeyByMetaSensorDisplayItemId(@Param("metaSensorDisplayItemId") Long metaSensorDisplayItemId); + @Query("SELECT m.metaSensorItemKey from MetaSensorDisplayMapping m where m.metaSensorDisplayItem.id = :metaSensorDisplayItemId") + public List findAllMetaSensorItemKeyByMetaSensorDisplayItemId( + @Param("metaSensorDisplayItemId") Long metaSensorDisplayItemId); } diff --git a/src/main/java/com/loafle/overflow/central/module/meta/dao/MetaSensorItemDAO.java b/src/main/java/com/loafle/overflow/central/module/meta/dao/MetaSensorItemDAO.java index bb76454..ccc12d1 100644 --- a/src/main/java/com/loafle/overflow/central/module/meta/dao/MetaSensorItemDAO.java +++ b/src/main/java/com/loafle/overflow/central/module/meta/dao/MetaSensorItemDAO.java @@ -8,5 +8,5 @@ import org.springframework.stereotype.Repository; * Created by insanity on 17. 6. 23. */ @Repository -public interface MetaSensorItemDAO extends JpaRepository{ +public interface MetaSensorItemDAO extends JpaRepository { } 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 2175ab4..28d628c 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 @@ -11,5 +11,5 @@ import java.util.List; */ @Repository public interface MetaSensorItemKeyDAO extends JpaRepository { - List findAllByMetaCrawlerId(Short metaCrawlerId); + List findAllByMetaCrawlerId(Short metaCrawlerId); } diff --git a/src/main/java/com/loafle/overflow/central/module/meta/dao/MetaSensorItemTypeDAO.java b/src/main/java/com/loafle/overflow/central/module/meta/dao/MetaSensorItemTypeDAO.java index c5661c1..72927be 100644 --- a/src/main/java/com/loafle/overflow/central/module/meta/dao/MetaSensorItemTypeDAO.java +++ b/src/main/java/com/loafle/overflow/central/module/meta/dao/MetaSensorItemTypeDAO.java @@ -8,5 +8,5 @@ import org.springframework.stereotype.Repository; * Created by insanity on 17. 6. 23. */ @Repository -public interface MetaSensorItemTypeDAO extends JpaRepository{ +public interface MetaSensorItemTypeDAO extends JpaRepository { } diff --git a/src/main/java/com/loafle/overflow/central/module/meta/dao/MetaSensorStatusDAO.java b/src/main/java/com/loafle/overflow/central/module/meta/dao/MetaSensorStatusDAO.java index 19eb5e3..3a01890 100644 --- a/src/main/java/com/loafle/overflow/central/module/meta/dao/MetaSensorStatusDAO.java +++ b/src/main/java/com/loafle/overflow/central/module/meta/dao/MetaSensorStatusDAO.java @@ -9,5 +9,5 @@ import org.springframework.stereotype.Repository; */ @Repository -public interface MetaSensorStatusDAO extends JpaRepository { +public interface MetaSensorStatusDAO extends JpaRepository { } 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 bdcbdd2..44ccf8c 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 @@ -11,5 +11,5 @@ import java.util.List; */ @Repository public interface MetaVendorCrawlerDAO extends JpaRepository { - List findAllByMetaInfraVendorId(Integer metaInfraVendorId); + List findAllByMetaInfraVendorId(Integer metaInfraVendorId); } diff --git a/src/main/java/com/loafle/overflow/central/module/meta/dao/MetaVendorCrawlerSensorItemDAO.java b/src/main/java/com/loafle/overflow/central/module/meta/dao/MetaVendorCrawlerSensorItemDAO.java index d3c57fb..c734555 100644 --- a/src/main/java/com/loafle/overflow/central/module/meta/dao/MetaVendorCrawlerSensorItemDAO.java +++ b/src/main/java/com/loafle/overflow/central/module/meta/dao/MetaVendorCrawlerSensorItemDAO.java @@ -8,5 +8,5 @@ import org.springframework.stereotype.Repository; * Created by insanity on 17. 6. 23. */ @Repository -public interface MetaVendorCrawlerSensorItemDAO extends JpaRepository{ +public interface MetaVendorCrawlerSensorItemDAO extends JpaRepository { } 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 6263f48..c8649bb 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 @@ -2,7 +2,6 @@ package com.loafle.overflow.central.module.meta.service; import com.loafle.overflow.central.module.meta.dao.MetaCrawlerInputItemDAO; import com.loafle.overflow.core.exception.OverflowException; -import com.loafle.overflow.model.meta.MetaCrawler; import com.loafle.overflow.model.meta.MetaCrawlerInputItem; import com.loafle.overflow.service.central.meta.MetaCrawlerInputItemService; import org.springframework.beans.factory.annotation.Autowired; @@ -16,10 +15,10 @@ import java.util.List; @Service("MetaCrawlerInputItemService") public class CentralMetaCrawlerInputItemService implements MetaCrawlerInputItemService { - @Autowired - private MetaCrawlerInputItemDAO crawlerInputItemDAO; + @Autowired + private MetaCrawlerInputItemDAO crawlerInputItemDAO; - public List readAllByMetaCrawlerID(Short metaCrawlerID) throws OverflowException { - return this.crawlerInputItemDAO.findAllByMetaCrawlerId(metaCrawlerID); - } + 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/CentralMetaCrawlerService.java b/src/main/java/com/loafle/overflow/central/module/meta/service/CentralMetaCrawlerService.java index e972f9a..c2ecbb8 100644 --- a/src/main/java/com/loafle/overflow/central/module/meta/service/CentralMetaCrawlerService.java +++ b/src/main/java/com/loafle/overflow/central/module/meta/service/CentralMetaCrawlerService.java @@ -14,10 +14,10 @@ import java.util.List; @Service("MetaCrawlerService") public class CentralMetaCrawlerService { - @Autowired - private MetaCrawlerDAO crawlerDAO; + @Autowired + private MetaCrawlerDAO crawlerDAO; - public List readAll() throws OverflowException { - return this.crawlerDAO.findAll(); - } + public List readAll() throws OverflowException { + return this.crawlerDAO.findAll(); + } } 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 bde2393..2f32600 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 @@ -16,18 +16,18 @@ import java.util.List; @Service("MetaHistoryTypeService") public class CentralMetaHistoryTypeService implements MetaHistoryTypeService { - @Autowired - private MetaHistoryTypeDAO hisotyTypeDAO; + @Autowired + private MetaHistoryTypeDAO hisotyTypeDAO; - public List readAll() throws OverflowException { - return this.hisotyTypeDAO.findAll(); - } + public List readAll() throws OverflowException { + return this.hisotyTypeDAO.findAll(); + } - public MetaHistoryType regist(MetaHistoryType type) throws OverflowException { - return this.hisotyTypeDAO.save(type); - } + public MetaHistoryType regist(MetaHistoryType type) throws OverflowException { + return this.hisotyTypeDAO.save(type); + } - public List registAll(List metaHistoryTypes) throws OverflowException { - return (List)this.hisotyTypeDAO.saveAll(metaHistoryTypes); - } + public List registAll(List metaHistoryTypes) throws OverflowException { + return (List) this.hisotyTypeDAO.saveAll(metaHistoryTypes); + } } diff --git a/src/main/java/com/loafle/overflow/central/module/meta/service/CentralMetaInfraTypeService.java b/src/main/java/com/loafle/overflow/central/module/meta/service/CentralMetaInfraTypeService.java index 7a99166..216bf64 100644 --- a/src/main/java/com/loafle/overflow/central/module/meta/service/CentralMetaInfraTypeService.java +++ b/src/main/java/com/loafle/overflow/central/module/meta/service/CentralMetaInfraTypeService.java @@ -16,10 +16,10 @@ import java.util.List; @Service("MetaInfraTypeService") public class CentralMetaInfraTypeService implements MetaInfraTypeService { - @Autowired - private MetaInfraTypeDAO infraTypeDAO; + @Autowired + private MetaInfraTypeDAO infraTypeDAO; - public List readAll() throws OverflowException { - return this.infraTypeDAO.findAll(); - } + public List readAll() throws OverflowException { + return this.infraTypeDAO.findAll(); + } } 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 b15ce2c..fd42e3b 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 @@ -16,11 +16,11 @@ import java.util.List; @Service("MetaInfraVendorService") public class CentralMetaInfraVendorService implements MetaInfraVendorService { - @Autowired - private MetaInfraVendorDAO infraVendorDAO; + @Autowired + private MetaInfraVendorDAO infraVendorDAO; - public List readAllByMetaInfraTypeID(Integer metaInfraTypeID) throws OverflowException { - return this.infraVendorDAO.findAllByMetaInfraTypeId(metaInfraTypeID); - } + 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/CentralMetaInputTypeService.java b/src/main/java/com/loafle/overflow/central/module/meta/service/CentralMetaInputTypeService.java index 738285e..92ffd28 100644 --- a/src/main/java/com/loafle/overflow/central/module/meta/service/CentralMetaInputTypeService.java +++ b/src/main/java/com/loafle/overflow/central/module/meta/service/CentralMetaInputTypeService.java @@ -15,10 +15,10 @@ import java.util.List; @Service("MetaInputTypeService") public class CentralMetaInputTypeService implements MetaInputTypeService { - @Autowired - private MetaInputTypeDAO inputTypeDAO; + @Autowired + private MetaInputTypeDAO inputTypeDAO; - public List readAll() throws OverflowException { - return this.inputTypeDAO.findAll(); - } + public List readAll() throws OverflowException { + return this.inputTypeDAO.findAll(); + } } diff --git a/src/main/java/com/loafle/overflow/central/module/meta/service/CentralMetaMemberStatusService.java b/src/main/java/com/loafle/overflow/central/module/meta/service/CentralMetaMemberStatusService.java index d55ef3c..6cf1980 100644 --- a/src/main/java/com/loafle/overflow/central/module/meta/service/CentralMetaMemberStatusService.java +++ b/src/main/java/com/loafle/overflow/central/module/meta/service/CentralMetaMemberStatusService.java @@ -15,10 +15,10 @@ import java.util.List; @Service("MetaMemberStatusService") public class CentralMetaMemberStatusService implements MetaMemberStatusService { - @Autowired - private MetaMemberStatusDAO memberStatusDAO; + @Autowired + private MetaMemberStatusDAO memberStatusDAO; - public List readAll() throws OverflowException { - return this.memberStatusDAO.findAll(); - } + public List readAll() throws OverflowException { + return this.memberStatusDAO.findAll(); + } } diff --git a/src/main/java/com/loafle/overflow/central/module/meta/service/CentralMetaNoAuthProbeStatusService.java b/src/main/java/com/loafle/overflow/central/module/meta/service/CentralMetaNoAuthProbeStatusService.java index 5ca17e8..3d7f966 100644 --- a/src/main/java/com/loafle/overflow/central/module/meta/service/CentralMetaNoAuthProbeStatusService.java +++ b/src/main/java/com/loafle/overflow/central/module/meta/service/CentralMetaNoAuthProbeStatusService.java @@ -15,10 +15,10 @@ import java.util.List; @Service("MetaNoAuthProbeStatusService") public class CentralMetaNoAuthProbeStatusService implements MetaNoAuthProbeStatusService { - @Autowired - private MetaNoAuthProbeStatusDAO noAuthProbeStatusDAO; + @Autowired + private MetaNoAuthProbeStatusDAO noAuthProbeStatusDAO; - public List readAll() throws OverflowException { - return this.noAuthProbeStatusDAO.findAll(); - } + public List readAll() throws OverflowException { + return this.noAuthProbeStatusDAO.findAll(); + } } diff --git a/src/main/java/com/loafle/overflow/central/module/meta/service/CentralMetaProbeArchitectureService.java b/src/main/java/com/loafle/overflow/central/module/meta/service/CentralMetaProbeArchitectureService.java index c372b5c..49700b4 100644 --- a/src/main/java/com/loafle/overflow/central/module/meta/service/CentralMetaProbeArchitectureService.java +++ b/src/main/java/com/loafle/overflow/central/module/meta/service/CentralMetaProbeArchitectureService.java @@ -15,10 +15,10 @@ import java.util.List; @Service("MetaProbeArchitectureService") public class CentralMetaProbeArchitectureService implements MetaProbeArchitectureService { - @Autowired - private MetaProbeArchitectureDAO probeArchitectureDAO; + @Autowired + private MetaProbeArchitectureDAO probeArchitectureDAO; - public List readAll() throws OverflowException { - return this.probeArchitectureDAO.findAll(); - } + public List readAll() throws OverflowException { + return this.probeArchitectureDAO.findAll(); + } } diff --git a/src/main/java/com/loafle/overflow/central/module/meta/service/CentralMetaProbeOsService.java b/src/main/java/com/loafle/overflow/central/module/meta/service/CentralMetaProbeOsService.java index bb200a6..5a3bc79 100644 --- a/src/main/java/com/loafle/overflow/central/module/meta/service/CentralMetaProbeOsService.java +++ b/src/main/java/com/loafle/overflow/central/module/meta/service/CentralMetaProbeOsService.java @@ -15,10 +15,10 @@ import java.util.List; @Service("MetaProbeOsService") public class CentralMetaProbeOsService implements MetaProbeOsService { - @Autowired - private MetaProbeOsDAO probeOsDAO; + @Autowired + private MetaProbeOsDAO probeOsDAO; - public List readAll() throws OverflowException { - return this.probeOsDAO.findAll(); - } + public List readAll() throws OverflowException { + return this.probeOsDAO.findAll(); + } } 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 4f0dcb3..757e7c3 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 @@ -2,7 +2,6 @@ package com.loafle.overflow.central.module.meta.service; import com.loafle.overflow.central.module.meta.dao.MetaProbePackageDAO; import com.loafle.overflow.core.exception.OverflowException; -import com.loafle.overflow.model.meta.MetaProbeOs; import com.loafle.overflow.model.meta.MetaProbePackage; import com.loafle.overflow.service.central.meta.MetaProbePackageService; import org.springframework.beans.factory.annotation.Autowired; @@ -16,10 +15,10 @@ import java.util.List; @Service("MetaProbePackageService") public class CentralMetaProbePackageService implements MetaProbePackageService { - @Autowired - private MetaProbePackageDAO probePackageDAO; + @Autowired + private MetaProbePackageDAO probePackageDAO; - public List readAllByMetaProbeOsID(Short metaProbeOsID) throws OverflowException { - return this.probePackageDAO.findAllByMetaProbeOsId(metaProbeOsID); - } + 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/CentralMetaProbeStatusService.java b/src/main/java/com/loafle/overflow/central/module/meta/service/CentralMetaProbeStatusService.java index 144834c..c855846 100644 --- a/src/main/java/com/loafle/overflow/central/module/meta/service/CentralMetaProbeStatusService.java +++ b/src/main/java/com/loafle/overflow/central/module/meta/service/CentralMetaProbeStatusService.java @@ -15,10 +15,10 @@ import java.util.List; @Service("MetaProbeStatusService") public class CentralMetaProbeStatusService implements MetaProbeStatusService { - @Autowired - private MetaProbeStatusDAO probeStatusDAO; + @Autowired + private MetaProbeStatusDAO probeStatusDAO; - public List readAll() throws OverflowException { - return this.probeStatusDAO.findAll(); - } + public List readAll() throws OverflowException { + return this.probeStatusDAO.findAll(); + } } diff --git a/src/main/java/com/loafle/overflow/central/module/meta/service/CentralMetaProbeTaskTypeService.java b/src/main/java/com/loafle/overflow/central/module/meta/service/CentralMetaProbeTaskTypeService.java index 7b5bc16..0a4296f 100644 --- a/src/main/java/com/loafle/overflow/central/module/meta/service/CentralMetaProbeTaskTypeService.java +++ b/src/main/java/com/loafle/overflow/central/module/meta/service/CentralMetaProbeTaskTypeService.java @@ -16,10 +16,10 @@ import java.util.List; @Service("MetaProbeTaskTypeService") public class CentralMetaProbeTaskTypeService implements MetaProbeTaskTypeService { - @Autowired - private MetaProbeTaskTypeDAO probeTaskTypeDAO; + @Autowired + private MetaProbeTaskTypeDAO probeTaskTypeDAO; - public List readAll() throws OverflowException { - return this.probeTaskTypeDAO.findAll(); - } + public List readAll() throws OverflowException { + return this.probeTaskTypeDAO.findAll(); + } } diff --git a/src/main/java/com/loafle/overflow/central/module/meta/service/CentralMetaProbeVersionService.java b/src/main/java/com/loafle/overflow/central/module/meta/service/CentralMetaProbeVersionService.java index 62387fe..a500fed 100644 --- a/src/main/java/com/loafle/overflow/central/module/meta/service/CentralMetaProbeVersionService.java +++ b/src/main/java/com/loafle/overflow/central/module/meta/service/CentralMetaProbeVersionService.java @@ -16,10 +16,10 @@ import java.util.List; @Service("MetaProbeVersionService") public class CentralMetaProbeVersionService implements MetaProbeVersionService { - @Autowired - private MetaProbeVersionDAO probeVersionDAO; + @Autowired + private MetaProbeVersionDAO probeVersionDAO; - public List readAll() throws OverflowException { - return this.probeVersionDAO.findAll(); - } + public List readAll() throws OverflowException { + return this.probeVersionDAO.findAll(); + } } 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 eaa754d..476220f 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 @@ -2,7 +2,6 @@ package com.loafle.overflow.central.module.meta.service; import com.loafle.overflow.central.module.meta.dao.MetaSensorDisplayItemDAO; import com.loafle.overflow.core.exception.OverflowException; -import com.loafle.overflow.model.meta.MetaCrawler; import com.loafle.overflow.model.meta.MetaSensorDisplayItem; import com.loafle.overflow.service.central.meta.MetaSensorDisplayItemService; import org.springframework.beans.factory.annotation.Autowired; @@ -15,18 +14,18 @@ import java.util.List; */ @Service("MetaSensorDisplayItemService") public class CentralMetaSensorDisplayItemService implements MetaSensorDisplayItemService { - @Autowired - private MetaSensorDisplayItemDAO displayItemDAO; + @Autowired + private MetaSensorDisplayItemDAO displayItemDAO; - public MetaSensorDisplayItem regist(MetaSensorDisplayItem item) throws OverflowException { - return this.displayItemDAO.save(item); - } + public MetaSensorDisplayItem regist(MetaSensorDisplayItem item) throws OverflowException { + return this.displayItemDAO.save(item); + } - public MetaSensorDisplayItem read(Long id) throws OverflowException { - return this.displayItemDAO.findById(id).get(); - } + public MetaSensorDisplayItem read(Long id) throws OverflowException { + return this.displayItemDAO.findById(id).get(); + } - public List readAllByCrawlerID(Short metaCrawlerID) throws OverflowException { - return this.displayItemDAO.findAllByMetaCrawlerId(metaCrawlerID); - } + 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 dad08db..b328c68 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 @@ -2,7 +2,6 @@ package com.loafle.overflow.central.module.meta.service; import com.loafle.overflow.central.module.meta.dao.MetaSensorDisplayMappingDAO; import com.loafle.overflow.core.exception.OverflowException; -import com.loafle.overflow.model.meta.MetaSensorDisplayItem; import com.loafle.overflow.model.meta.MetaSensorDisplayMapping; import com.loafle.overflow.model.meta.MetaSensorItemKey; import com.loafle.overflow.service.central.meta.MetaSensorDisplayMappingService; @@ -16,14 +15,15 @@ import java.util.List; */ @Service("MetaSensorDisplayMappingService") public class CentralMetaSensorDisplayMappingService implements MetaSensorDisplayMappingService { - @Autowired - private MetaSensorDisplayMappingDAO mappingDAO; + @Autowired + private MetaSensorDisplayMappingDAO mappingDAO; - public MetaSensorDisplayMapping regist(MetaSensorDisplayMapping m) throws OverflowException { - return this.mappingDAO.save(m); - } + public MetaSensorDisplayMapping regist(MetaSensorDisplayMapping m) throws OverflowException { + return this.mappingDAO.save(m); + } - public List readAllMetaSensorItemKeyByDisplayItemID(Long metaSensorDisplayItemID) throws OverflowException { - return this.mappingDAO.findAllMetaSensorItemKeyByMetaSensorDisplayItemId(metaSensorDisplayItemID); - } + 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/CentralMetaSensorItemTypeService.java b/src/main/java/com/loafle/overflow/central/module/meta/service/CentralMetaSensorItemTypeService.java index 069f0e0..2509e84 100644 --- a/src/main/java/com/loafle/overflow/central/module/meta/service/CentralMetaSensorItemTypeService.java +++ b/src/main/java/com/loafle/overflow/central/module/meta/service/CentralMetaSensorItemTypeService.java @@ -16,18 +16,18 @@ import java.util.List; @Service("MetaSensorItemTypeService") public class CentralMetaSensorItemTypeService implements MetaSensorItemTypeService { - @Autowired - private MetaSensorItemTypeDAO sensorItemTypeDAO; + @Autowired + private MetaSensorItemTypeDAO sensorItemTypeDAO; - public List readAll() throws OverflowException { - return this.sensorItemTypeDAO.findAll(); - } + public List readAll() throws OverflowException { + return this.sensorItemTypeDAO.findAll(); + } - public MetaSensorItemType regist(MetaSensorItemType type) throws OverflowException { - return this.sensorItemTypeDAO.save(type); - } + public MetaSensorItemType regist(MetaSensorItemType type) throws OverflowException { + return this.sensorItemTypeDAO.save(type); + } - public List registAll(List list) throws OverflowException { - return (List)this.sensorItemTypeDAO.saveAll(list); - } + public List registAll(List list) throws OverflowException { + return (List) this.sensorItemTypeDAO.saveAll(list); + } } diff --git a/src/main/java/com/loafle/overflow/central/module/meta/service/CentralMetaSensorItemUnitService.java b/src/main/java/com/loafle/overflow/central/module/meta/service/CentralMetaSensorItemUnitService.java index 4af5f4f..7302c55 100644 --- a/src/main/java/com/loafle/overflow/central/module/meta/service/CentralMetaSensorItemUnitService.java +++ b/src/main/java/com/loafle/overflow/central/module/meta/service/CentralMetaSensorItemUnitService.java @@ -13,10 +13,10 @@ import org.springframework.stereotype.Service; @Service("MetaSensorItemUnitService") public class CentralMetaSensorItemUnitService implements MetaSensorItemUnitService { - @Autowired - private MetaSensorItemUnitDAO sensorItemUnitDAO; + @Autowired + private MetaSensorItemUnitDAO sensorItemUnitDAO; - public MetaSensorItemUnit regist(MetaSensorItemUnit sensorItemUnit) throws OverflowException { - return this.sensorItemUnitDAO.save(sensorItemUnit); - } + public MetaSensorItemUnit regist(MetaSensorItemUnit sensorItemUnit) throws OverflowException { + return this.sensorItemUnitDAO.save(sensorItemUnit); + } } diff --git a/src/main/java/com/loafle/overflow/central/module/meta/service/CentralMetaSensorStatusService.java b/src/main/java/com/loafle/overflow/central/module/meta/service/CentralMetaSensorStatusService.java index 5c22075..872bb4d 100644 --- a/src/main/java/com/loafle/overflow/central/module/meta/service/CentralMetaSensorStatusService.java +++ b/src/main/java/com/loafle/overflow/central/module/meta/service/CentralMetaSensorStatusService.java @@ -15,10 +15,10 @@ import java.util.List; @Service("MetaSensorStatusService") public class CentralMetaSensorStatusService implements MetaSensorStatusService { - @Autowired - private MetaSensorStatusDAO sensorStatusDAO; + @Autowired + private MetaSensorStatusDAO sensorStatusDAO; - public List readAll() throws OverflowException { - return this.sensorStatusDAO.findAll(); - } + public List readAll() throws OverflowException { + return this.sensorStatusDAO.findAll(); + } } 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 61038b6..b21f41e 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 @@ -2,7 +2,6 @@ package com.loafle.overflow.central.module.meta.service; import com.loafle.overflow.central.module.meta.dao.MetaVendorCrawlerDAO; import com.loafle.overflow.core.exception.OverflowException; -import com.loafle.overflow.model.meta.MetaInfraVendor; import com.loafle.overflow.model.meta.MetaVendorCrawler; import com.loafle.overflow.service.central.meta.MetaVendorCrawlerService; import org.springframework.beans.factory.annotation.Autowired; @@ -17,15 +16,15 @@ import java.util.List; @Service("MetaVendorCrawlerService") public class CentralMetaVendorCrawlerService implements MetaVendorCrawlerService { - @Autowired - private MetaVendorCrawlerDAO crawlerDAO; + @Autowired + private MetaVendorCrawlerDAO crawlerDAO; - public List readAllByMetaInfraVendorID(Integer metaInfraVendorID) throws OverflowException { + public List readAllByMetaInfraVendorID(Integer metaInfraVendorID) throws OverflowException { - return this.crawlerDAO.findAllByMetaInfraVendorId(metaInfraVendorID); - } + return this.crawlerDAO.findAllByMetaInfraVendorId(metaInfraVendorID); + } - public MetaVendorCrawler regist(MetaVendorCrawler metaVendorCrawler) throws OverflowException { - return this.crawlerDAO.save(metaVendorCrawler); - } + public MetaVendorCrawler regist(MetaVendorCrawler metaVendorCrawler) throws OverflowException { + return this.crawlerDAO.save(metaVendorCrawler); + } } 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 ff7c4e1..655d55d 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 @@ -13,16 +13,19 @@ import java.util.List; @Repository public interface NoAuthProbeDAO extends JpaRepository { - NoAuthProbe findByTempProbeKey(String tempProbeKey); + NoAuthProbe findByTempProbeKey(String tempProbeKey); - List findAllByDomainIdAndMetaNoAuthProbeStatusId(Long domainID, Short metaNoAuthProbeStatusId); + List findAllByDomainIdAndMetaNoAuthProbeStatusId(Long domainID, Short metaNoAuthProbeStatusId); -// NoAuthProbeDeprecate findByTempKey(NoAuthProbeDeprecate noAuthAgent); -// List findAllByNoAuth(NoAuthProbeDeprecate noAuthAgent); -// @Query("SELECT n FROM NoAuthProbe n WHERE n.tempProbeKey = :tempProbeKey") -// @Query("select m from Member m WHERE m.email = :#{#m2.email}") + // NoAuthProbeDeprecate findByTempKey(NoAuthProbeDeprecate noAuthAgent); + // List findAllByNoAuth(NoAuthProbeDeprecate noAuthAgent); + // @Query("SELECT n FROM NoAuthProbe n WHERE n.tempProbeKey = :tempProbeKey") + // @Query("select m from Member m WHERE m.email = :#{#m2.email}") - // @Modifying(clearAutomatically = true) - // @Query("UPDATE NoAuthProbe n set n.connectDate = :connectDate, n.connectAddress = :connectAddress where n.tempProbeKey = :tempProbeKey") - // int saveConnect(@Param("tempProbeKey") String tempProbeKey, @Param("connectDate") Date connectDate, @Param("connectAddress") String connectAddress); + // @Modifying(clearAutomatically = true) + // @Query("UPDATE NoAuthProbe n set n.connectDate = :connectDate, + // n.connectAddress = :connectAddress where n.tempProbeKey = :tempProbeKey") + // int saveConnect(@Param("tempProbeKey") String tempProbeKey, + // @Param("connectDate") Date connectDate, @Param("connectAddress") String + // connectAddress); } 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 aa654e6..9149781 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 @@ -15,11 +15,11 @@ import java.util.List; @Repository public interface NotificationDAO extends JpaRepository { - List findAllByMemberEmail(String memberEmail); + List findAllByMemberEmail(String memberEmail); - Page findAllByMemberEmail(String memberEmail, Pageable pageRequest); + Page findAllByMemberEmail(String memberEmail, Pageable pageRequest); - Page findAllByMemberEmailAndConfirmDateNull(String memberEmail, Pageable pageRequest); + Page findAllByMemberEmailAndConfirmDateNull(String memberEmail, Pageable pageRequest); - Long countByMemberEmailAndConfirmDateNull(String memberEmail); + 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 0830ea0..035fccc 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 @@ -4,7 +4,6 @@ import com.loafle.overflow.central.commons.utils.PageUtil; import com.loafle.overflow.central.module.notification.dao.NotificationDAO; import com.loafle.overflow.core.exception.OverflowException; import com.loafle.overflow.core.model.PageParams; -import com.loafle.overflow.model.member.Member; import com.loafle.overflow.model.notification.Notification; import com.loafle.overflow.service.central.notification.NotificationService; @@ -21,51 +20,51 @@ import java.util.List; @Service("NotificationService") public class CentralNotificationService implements NotificationService { - @Autowired - private NotificationDAO notificationDAO; + @Autowired + private NotificationDAO notificationDAO; - public Notification regist(Notification notification) throws OverflowException { - return this.notificationDAO.save(notification); - } + public Notification regist(Notification notification) throws OverflowException { + return this.notificationDAO.save(notification); + } - public Page readAllByMemberEmail(String memberEmail, PageParams pageParams) throws OverflowException { - return this.notificationDAO.findAllByMemberEmail(memberEmail, PageUtil.getPageRequest(pageParams)); - } + public Page readAllByMemberEmail(String memberEmail, PageParams pageParams) throws OverflowException { + return this.notificationDAO.findAllByMemberEmail(memberEmail, PageUtil.getPageRequest(pageParams)); + } - public Page readAllUnconfirmedByMemberEmail(String memberEmail, PageParams pageParams) - throws OverflowException { - return this.notificationDAO.findAllByMemberEmailAndConfirmDateNull(memberEmail, - PageUtil.getPageRequest(pageParams)); - } + public Page readAllUnconfirmedByMemberEmail(String memberEmail, PageParams pageParams) + throws OverflowException { + return this.notificationDAO.findAllByMemberEmailAndConfirmDateNull(memberEmail, + PageUtil.getPageRequest(pageParams)); + } - public Long readUnconfirmedCountByMemberEmail(String memberEmail) throws OverflowException { - return this.notificationDAO.countByMemberEmailAndConfirmDateNull(memberEmail); - } + public Long readUnconfirmedCountByMemberEmail(String memberEmail) throws OverflowException { + return this.notificationDAO.countByMemberEmailAndConfirmDateNull(memberEmail); + } - 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.saveAll(list); - return this.readAllByMemberEmail(memberEmail, pageParams); + 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.saveAll(list); + return this.readAllByMemberEmail(memberEmail, pageParams); + } - public Page markAllAsUnreadMemberEmail(String memberEmail, PageParams pageParams) - throws OverflowException { - List list = this.notificationDAO.findAllByMemberEmail(memberEmail); - for (Notification n : list) { - n.setConfirmDate(null); - } - this.notificationDAO.saveAll(list); - return this.readAllByMemberEmail(memberEmail, pageParams); + public Page markAllAsUnreadMemberEmail(String memberEmail, PageParams pageParams) + throws OverflowException { + List list = this.notificationDAO.findAllByMemberEmail(memberEmail); + for (Notification n : list) { + n.setConfirmDate(null); } + this.notificationDAO.saveAll(list); + return this.readAllByMemberEmail(memberEmail, pageParams); + } - public Notification markAsRead(Long notificationID) throws OverflowException { - Notification notification = this.notificationDAO.findById(notificationID).get(); - notification.setConfirmDate(new Date()); - return this.notificationDAO.save(notification); - } + public Notification markAsRead(Long notificationID) throws OverflowException { + Notification notification = this.notificationDAO.findById(notificationID).get(); + notification.setConfirmDate(new Date()); + return this.notificationDAO.save(notification); + } } diff --git a/src/main/java/com/loafle/overflow/central/module/probe/dao/ProbeDAO.java b/src/main/java/com/loafle/overflow/central/module/probe/dao/ProbeDAO.java index 88f4543..5e09bec 100644 --- a/src/main/java/com/loafle/overflow/central/module/probe/dao/ProbeDAO.java +++ b/src/main/java/com/loafle/overflow/central/module/probe/dao/ProbeDAO.java @@ -7,17 +7,19 @@ import org.springframework.stereotype.Repository; import java.util.List; - /** * Created by insanity on 17. 5. 29. */ @Repository public interface ProbeDAO extends JpaRepository { - Probe findByProbeKey(String probeKey); - List findAllByDomainIdOrderByIdDesc(Long domainID); + Probe findByProbeKey(String probeKey); - // @Modifying(clearAutomatically = true) - // @Query("UPDATE Probe p set p.connectDate = :connectDate, p.connectAddress = :connectAddress where p.probeKey = :probeKey") - // int saveConnect(@Param("probeKey") String probeKey, @Param("connectDate") Date connectDate, @Param("connectAddress") String connectAddress); + List findAllByDomainIdOrderByIdDesc(Long domainID); + + // @Modifying(clearAutomatically = true) + // @Query("UPDATE Probe p set p.connectDate = :connectDate, p.connectAddress = + // :connectAddress where p.probeKey = :probeKey") + // int saveConnect(@Param("probeKey") String probeKey, @Param("connectDate") + // Date connectDate, @Param("connectAddress") String connectAddress); } \ No newline at end of file diff --git a/src/main/java/com/loafle/overflow/central/module/probe/dao/ProbeHostDAO.java b/src/main/java/com/loafle/overflow/central/module/probe/dao/ProbeHostDAO.java index f36d96f..51b975f 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 @@ -12,7 +12,7 @@ import org.springframework.stereotype.Repository; */ @Repository public interface ProbeHostDAO extends JpaRepository { - ProbeHost findByProbeId(Long probeID); + ProbeHost findByProbeId(Long probeID); - List findAllByProbeDomainId(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 fc528d3..d7eb78b 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 c00681c..bced7ac 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 @@ -16,22 +16,22 @@ import org.springframework.stereotype.Service; @Service("ProbeHostService") public class CentralProbeHostService implements ProbeHostService { - @Autowired - private ProbeHostDAO probeHostDAO; + @Autowired + private ProbeHostDAO probeHostDAO; - public ProbeHost read(Long id) throws OverflowException { - return this.probeHostDAO.findById(id).get(); - } + public ProbeHost read(Long id) throws OverflowException { + return this.probeHostDAO.findById(id).get(); + } - public ProbeHost readByProbeID(Long probeID) throws OverflowException { - return this.probeHostDAO.findByProbeId(probeID); - } + public ProbeHost readByProbeID(Long probeID) throws OverflowException { + return this.probeHostDAO.findByProbeId(probeID); + } - public ProbeHost regist(ProbeHost probeHost) throws OverflowException { - return this.probeHostDAO.save(probeHost); - } + public ProbeHost regist(ProbeHost probeHost) throws OverflowException { + return this.probeHostDAO.save(probeHost); + } - public List readAllByDomainID(Long domainID) throws OverflowException { - return this.probeHostDAO.findAllByProbeDomainId(domainID); - } + public List readAllByDomainID(Long domainID) throws OverflowException { + 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 8c8b3bb..6a00c94 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 @@ -18,77 +18,77 @@ import java.util.List; @Service("ProbeService") public class CentralProbeService implements ProbeService { - @Autowired - private ProbeDAO probeDAO; - @Autowired - private MessagePublisher messagePublisher; + @Autowired + private ProbeDAO probeDAO; + @Autowired + private MessagePublisher messagePublisher; - public Probe regist(Probe probe) throws OverflowException { - return this.probeDAO.save(probe); + public Probe regist(Probe probe) throws OverflowException { + return this.probeDAO.save(probe); + } + + public List regist(List probes) throws OverflowException { + return (List) this.probeDAO.saveAll(probes); + } + + public List readAllByDomainID(Long domainID) throws OverflowException { + List probes = this.probeDAO.findAllByDomainIdOrderByIdDesc(domainID); + return probes; + } + + public Probe read(Long id) throws OverflowException { + return this.probeDAO.findById(id).get(); + } + + public Probe readByProbeKey(String probeKey) throws OverflowException { + return this.probeDAO.findByProbeKey(probeKey); + } + + public Probe modify(Probe probe) throws OverflowException { + return this.probeDAO.save(probe); + } + + public boolean remove(Long id) throws OverflowException { + this.probeDAO.deleteById(id); + return true; + } + + public Probe increaseTargetCount(Probe probe) { + Probe p = this.probeDAO.findById(probe.getId()).get(); + p.setTargetCount(p.getTargetCount() + 1); + return this.probeDAO.save(p); + } + + public Probe decreaseTargetCount(Probe probe) { + Probe p = this.probeDAO.findById(probe.getId()).get(); + int count = p.getTargetCount(); + if (count > 0) { + p.setTargetCount(count - 1); } + return this.probeDAO.save(p); + } - public List regist(List probes) throws OverflowException { - return (List)this.probeDAO.saveAll(probes); - } + public Probe modifyDisplayName(Long probeId, String displayName) { + Probe probe = this.probeDAO.findById(probeId).get(); + probe.setDisplayName(displayName); + return this.probeDAO.save(probe); + } - public List readAllByDomainID(Long domainID) throws OverflowException { - List probes = this.probeDAO.findAllByDomainIdOrderByIdDesc(domainID); - return probes; - } + public void onConnect(String probeKey, String connectAddress) throws OverflowException { + Probe probe = this.probeDAO.findByProbeKey(probeKey); + probe.setConnectDate(new Date()); + probe.setConnectAddress(connectAddress); + probe = this.probeDAO.save(probe); - public Probe read(Long id) throws OverflowException { - return this.probeDAO.findById(id).get(); - } + messagePublisher.publishToDomainMembers(probe.getDomain().getId(), "ProbeService.onConnect", probe); + } - public Probe readByProbeKey(String probeKey) throws OverflowException { - return this.probeDAO.findByProbeKey(probeKey); - } + public void onDisconnect(String probeKey) throws OverflowException { + Probe probe = this.probeDAO.findByProbeKey(probeKey); + probe.setConnectDate(null); + probe.setConnectAddress(null); + probe = this.probeDAO.save(probe); - public Probe modify(Probe probe) throws OverflowException { - return this.probeDAO.save(probe); - } - - public boolean remove(Long id) throws OverflowException { - this.probeDAO.deleteById(id); - return true; - } - - public Probe increaseTargetCount(Probe probe) { - Probe p = this.probeDAO.findById(probe.getId()).get(); - p.setTargetCount(p.getTargetCount() + 1); - return this.probeDAO.save(p); - } - - public Probe decreaseTargetCount(Probe probe) { - Probe p = this.probeDAO.findById(probe.getId()).get(); - int count = p.getTargetCount(); - if (count > 0) { - p.setTargetCount(count - 1); - } - return this.probeDAO.save(p); - } - - public Probe modifyDisplayName(Long probeId, String displayName) { - Probe probe = this.probeDAO.findById(probeId).get(); - probe.setDisplayName(displayName); - return this.probeDAO.save(probe); - } - - public void onConnect(String probeKey, String connectAddress) throws OverflowException { - Probe probe = this.probeDAO.findByProbeKey(probeKey); - probe.setConnectDate(new Date()); - probe.setConnectAddress(connectAddress); - probe = this.probeDAO.save(probe); - - messagePublisher.publishToDomainMembers(probe.getDomain().getId(), "ProbeService.onConnect", probe); - } - - public void onDisconnect(String probeKey) throws OverflowException { - Probe probe = this.probeDAO.findByProbeKey(probeKey); - probe.setConnectDate(null); - probe.setConnectAddress(null); - probe = this.probeDAO.save(probe); - - messagePublisher.publishToDomainMembers(probe.getDomain().getId(), "ProbeService.onDisconnect", probe); - } + messagePublisher.publishToDomainMembers(probe.getDomain().getId(), "ProbeService.onDisconnect", probe); + } } 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 216cb4a..e13f81d 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 @@ -14,16 +14,16 @@ import java.util.List; * Created by snoop on 17. 6. 28. */ @Service("ProbeTaskService") -public class CentralProbeTaskService implements ProbeTaskService{ +public class CentralProbeTaskService implements ProbeTaskService { - @Autowired - private ProbeTaskDAO probeTaskDAO; + @Autowired + private ProbeTaskDAO probeTaskDAO; - public ProbeTask regist(ProbeTask probeTask) throws OverflowException { - return this.probeTaskDAO.save(probeTask); - } + public ProbeTask regist(ProbeTask probeTask) throws OverflowException { + return this.probeTaskDAO.save(probeTask); + } - public List readAllByProbeID(Long probeID) throws OverflowException { - return this.probeTaskDAO.findAllByProbeId(probeID); - } + public List readAllByProbeID(Long probeID) throws OverflowException { + return this.probeTaskDAO.findAllByProbeId(probeID); + } } 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 213aa26..312c0a8 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 @@ -15,9 +15,9 @@ import com.loafle.overflow.model.target.Target; */ @Repository public interface SensorDAO extends JpaRepository { - Page findAllByTargetId(Long targetID, Pageable pageable); + Page findAllByTargetId(Long targetID, Pageable pageable); - List findAllByTargetId(Long targetID); + List findAllByTargetId(Long targetID); - Page findAllByTargetIn(List targets, 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 f7b3ff0..0342ca7 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 @@ -12,5 +12,5 @@ import org.springframework.stereotype.Repository; */ @Repository public interface SensorItemDAO extends JpaRepository { - Page findAllBySensorId(Long sensorId, 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 57088fa..81fa892 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 @@ -16,6 +16,7 @@ import java.util.List; @Repository public interface SensorItemDependencyDAO extends JpaRepository { - @Query("SELECT s.metaSensorItemKey from SensorItemDependency s where s.metaSensorDisplayItem.id = :metaSensorDisplayItemId") - List findAllMetaSensorItemKeyByMetaSensorDisplayItemId(@Param("metaSensorDisplayItemId") Long metaSensorDisplayItemId); + @Query("SELECT s.metaSensorItemKey from SensorItemDependency s where s.metaSensorDisplayItem.id = :metaSensorDisplayItemId") + List findAllMetaSensorItemKeyByMetaSensorDisplayItemId( + @Param("metaSensorDisplayItemId") 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 671b8e6..2e1aee0 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 @@ -21,29 +21,29 @@ import java.util.Map; @Service("SensorItemDependencyService") public class CentralSensorItemDependencyService implements SensorItemDependencyService { - @Autowired - private SensorItemDependencyDAO sensorItemDependencyDAO; + @Autowired + private SensorItemDependencyDAO sensorItemDependencyDAO; - public SensorItemDependency regist(SensorItemDependency dependency) throws OverflowException { - return this.sensorItemDependencyDAO.save(dependency); + public SensorItemDependency regist(SensorItemDependency dependency) throws OverflowException { + return this.sensorItemDependencyDAO.save(dependency); + } + + public List readAllMetaSensorItemKeyByMetaSensorDisplayItemID(Long metaSensorDisplayItemID) + throws OverflowException { + return this.sensorItemDependencyDAO.findAllMetaSensorItemKeyByMetaSensorDisplayItemId(metaSensorDisplayItemID); + } + + public Map> readAllMapByMetaSensorDisplayItems( + List metaSensorDisplayItems) throws OverflowException { + + Map> map = new HashMap>(); + + for (MetaSensorDisplayItem displayItem : metaSensorDisplayItems) { + List itemKeys = this.sensorItemDependencyDAO + .findAllMetaSensorItemKeyByMetaSensorDisplayItemId(displayItem.getId()); + map.put(displayItem.getKey(), itemKeys); } - public List readAllMetaSensorItemKeyByMetaSensorDisplayItemID(Long metaSensorDisplayItemID) - throws OverflowException { - return this.sensorItemDependencyDAO.findAllMetaSensorItemKeyByMetaSensorDisplayItemId(metaSensorDisplayItemID); - } - - public Map> readAllMapByMetaSensorDisplayItems( - List metaSensorDisplayItems) throws OverflowException { - - Map> map = new HashMap>(); - - for (MetaSensorDisplayItem displayItem : metaSensorDisplayItems) { - List itemKeys = this.sensorItemDependencyDAO - .findAllMetaSensorItemKeyByMetaSensorDisplayItemId(displayItem.getId()); - map.put(displayItem.getKey(), itemKeys); - } - - return map; - } + return map; + } } 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 0dca043..30e1bdc 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 @@ -22,41 +22,41 @@ import java.util.List; @Service("SensorItemService") public class CentralSensorItemService implements SensorItemService { - @Autowired - private SensorItemDAO sensorItemDAO; - @Autowired - private SensorDAO sensorDAO; + @Autowired + private SensorItemDAO sensorItemDAO; + @Autowired + private SensorDAO sensorDAO; - @Transactional - public SensorItem regist(SensorItem sensorItem) throws OverflowException { - Sensor s = sensorDAO.findById(sensorItem.getSensor().getId()).get(); - s.setItemCount((short) (s.getItemCount() + 1)); - this.sensorDAO.save(s); - return this.sensorItemDAO.save(sensorItem); - } + @Transactional + public SensorItem regist(SensorItem sensorItem) throws OverflowException { + Sensor s = sensorDAO.findById(sensorItem.getSensor().getId()).get(); + s.setItemCount((short) (s.getItemCount() + 1)); + this.sensorDAO.save(s); + return this.sensorItemDAO.save(sensorItem); + } - @Transactional - public boolean registAll(List sensorItemList) throws OverflowException { - Sensor s = sensorDAO.findById(sensorItemList.get(0).getSensor().getId()).get(); - s.setItemCount((short) sensorItemList.size()); - this.sensorDAO.save(s); - this.sensorItemDAO.saveAll(sensorItemList); - return true; - } + @Transactional + public boolean registAll(List sensorItemList) throws OverflowException { + Sensor s = sensorDAO.findById(sensorItemList.get(0).getSensor().getId()).get(); + s.setItemCount((short) sensorItemList.size()); + this.sensorDAO.save(s); + this.sensorItemDAO.saveAll(sensorItemList); + return true; + } - public SensorItem read(String id) throws OverflowException { - return this.sensorItemDAO.findById(Long.valueOf(id)).get(); - } + public SensorItem read(String id) throws OverflowException { + return this.sensorItemDAO.findById(Long.valueOf(id)).get(); + } - public Page readAllBySensorID(Long sensorID, PageParams pageParams) throws OverflowException { - return this.sensorItemDAO.findAllBySensorId(sensorID, 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)); - this.sensorDAO.save(s); - this.sensorItemDAO.delete(sensorItem); - } + @Transactional + public void remove(SensorItem sensorItem) throws OverflowException { + Sensor s = sensorItem.getSensor(); + 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 85bd2d8..dc41251 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 @@ -5,8 +5,6 @@ import com.loafle.overflow.central.module.generator.service.SensorConfigGenerato import com.loafle.overflow.central.module.sensor.dao.SensorDAO; 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.infra.Infra; import com.loafle.overflow.model.meta.MetaSensorStatus; import com.loafle.overflow.model.probe.Probe; import com.loafle.overflow.model.sensor.Sensor; @@ -31,109 +29,112 @@ import java.util.List; @Service("SensorService") public class CentralSensorService implements SensorService { - @Autowired - SensorDAO sensorDAO; + @Autowired + SensorDAO sensorDAO; - @Autowired - private ProbeService probeService; + @Autowired + private ProbeService probeService; - @Autowired - private InfraService infraService; + @Autowired + private InfraService infraService; - @Autowired - private SensorItemService sensorItemService; + @Autowired + private SensorItemService sensorItemService; - @Autowired - private SensorConfigGenerator sensorConfigGenerator; + @Autowired + private SensorConfigGenerator sensorConfigGenerator; - @Autowired - private TargetService targetService; + @Autowired + private TargetService targetService; - @Transactional - public Sensor regist(Sensor sensor) throws OverflowException { - this.targetService.increaseSensorCount(sensor.getTarget()); - return this.sensorDAO.save(sensor); + @Transactional + public Sensor regist(Sensor sensor) throws OverflowException { + this.targetService.increaseSensorCount(sensor.getTarget()); + return this.sensorDAO.save(sensor); + } + + public Page readAllByDomainID(Long domainID, PageParams pageParams) throws OverflowException { + + List probeList = this.probeService.readAllByDomainID(domainID); + + if (probeList == null || probeList.size() <= 0) { + throw new OverflowException("", new Throwable()); } - public Page readAllByDomainID(Long domainID, PageParams pageParams) throws OverflowException { + List targetList = this.infraService.readAllTargetByProbes(probeList); - List probeList = this.probeService.readAllByDomainID(domainID); - - if (probeList == null || probeList.size() <= 0) { - throw new OverflowException("", new Throwable()); - } - - List targetList = this.infraService.readAllTargetByProbes(probeList); - - if (targetList == null || targetList.size() <= 0) { - throw new OverflowException("", new Throwable()); - } - - return this.sensorDAO.findAllByTargetIn(targetList, PageUtil.getPageRequest(pageParams)); + if (targetList == null || targetList.size() <= 0) { + throw new OverflowException("", new Throwable()); } - public Page readAllByInfraID(Long infraID, PageParams pageParams) throws OverflowException { - // Infra dbInfra = this.infraService.read(infraID); - // if (dbInfra == null) { - // throw new OverflowException("", new Throwable()); - // } - // return this.sensorDAO.findAllByTargetId(dbInfra.getTarget().getId(), PageUtil.getPageRequest(pageParams)); - return null; + return this.sensorDAO.findAllByTargetIn(targetList, PageUtil.getPageRequest(pageParams)); + } + + public Page readAllByInfraID(Long infraID, PageParams pageParams) throws OverflowException { + // Infra dbInfra = this.infraService.read(infraID); + // if (dbInfra == null) { + // throw new OverflowException("", new Throwable()); + // } + // return this.sensorDAO.findAllByTargetId(dbInfra.getTarget().getId(), + // PageUtil.getPageRequest(pageParams)); + return null; + } + + public Page readAllByTargetID(Long targetID, PageParams pageParams) throws OverflowException { + return this.sensorDAO.findAllByTargetId(targetID, PageUtil.getPageRequest(pageParams)); + } + + public Sensor read(Long id) throws OverflowException { + return this.sensorDAO.findById(Long.valueOf(id)).get(); + } + + @Transactional + public void remove(Long sensorID) throws OverflowException { + Sensor sensor = this.sensorDAO.findById(sensorID).get(); + this.targetService.decreaseSensorCount(sensor.getTarget()); + this.sensorDAO.delete(sensor); + } + + public Sensor start(Long sensorID) throws OverflowException { + Sensor sensor = this.sensorDAO.findById(sensorID).get(); + MetaSensorStatus status = new MetaSensorStatus((short) 1); + sensor.setMetaSensorStatus(status); + return this.sensorDAO.save(sensor); + } + + public Sensor stop(Long sensorID) throws OverflowException { + Sensor sensor = this.sensorDAO.findById(sensorID).get(); + MetaSensorStatus status = new MetaSensorStatus((short) 2); + sensor.setMetaSensorStatus(status); + return this.sensorDAO.save(sensor); + } + + @Transactional + public Sensor registSensorConfig(Sensor sensor, List sensorItemList, String etcJson) + throws OverflowException { + + this.targetService.increaseSensorCount(sensor.getTarget()); + this.sensorDAO.save(sensor); + + for (SensorItem sensorItem : sensorItemList) { + sensorItem.setSensor(sensor); } - public Page readAllByTargetID(Long targetID, PageParams pageParams) throws OverflowException { - return this.sensorDAO.findAllByTargetId(targetID, PageUtil.getPageRequest(pageParams)); + this.sensorItemService.registAll(sensorItemList); + + return sensor; + } + + public String generateSensorConfig(Sensor sensor) throws OverflowException { + try { + return this.sensorConfigGenerator.generate(sensor); + } catch (Exception e) { + throw new OverflowException("", new Throwable()); } + } - public Sensor read(Long id) throws OverflowException { - return this.sensorDAO.findById(Long.valueOf(id)).get(); - } - - @Transactional - public void remove(Long sensorID) throws OverflowException { - Sensor sensor = this.sensorDAO.findById(sensorID).get(); - this.targetService.decreaseSensorCount(sensor.getTarget()); - this.sensorDAO.delete(sensor); - } - - public Sensor start(Long sensorID) throws OverflowException { - Sensor sensor = this.sensorDAO.findById(sensorID).get(); - MetaSensorStatus status = new MetaSensorStatus((short) 1); - sensor.setMetaSensorStatus(status); - return this.sensorDAO.save(sensor); - } - - public Sensor stop(Long sensorID) throws OverflowException { - Sensor sensor = this.sensorDAO.findById(sensorID).get(); - MetaSensorStatus status = new MetaSensorStatus((short) 2); - sensor.setMetaSensorStatus(status); - return this.sensorDAO.save(sensor); - } - - @Transactional - public Sensor registSensorConfig(Sensor sensor, List sensorItemList, String etcJson) throws OverflowException { - - this.targetService.increaseSensorCount(sensor.getTarget()); - this.sensorDAO.save(sensor); - - for (SensorItem sensorItem : sensorItemList) { - sensorItem.setSensor(sensor); - } - - this.sensorItemService.registAll(sensorItemList); - - return sensor; - } - - public String generateSensorConfig(Sensor sensor) throws OverflowException { - try { - return this.sensorConfigGenerator.generate(sensor); - } catch (Exception e) { - throw new OverflowException("", new Throwable()); - } - } - - // public List readAllByTarget(Target target, PageParams pageParams) { - // return this.sensorDAO.findAllByTarget(target, PageUtil.getPageRequest(pageParams)); - // } + // public List readAllByTarget(Target target, PageParams pageParams) { + // return this.sensorDAO.findAllByTarget(target, + // PageUtil.getPageRequest(pageParams)); + // } } diff --git a/src/main/java/com/loafle/overflow/central/module/target/dao/TargetDAO.java b/src/main/java/com/loafle/overflow/central/module/target/dao/TargetDAO.java index f195288..261baab 100644 --- a/src/main/java/com/loafle/overflow/central/module/target/dao/TargetDAO.java +++ b/src/main/java/com/loafle/overflow/central/module/target/dao/TargetDAO.java @@ -13,8 +13,9 @@ import org.springframework.stereotype.Repository; public interface TargetDAO extends JpaRepository { Target findByInfraId(Long infraId); -// @Query("select t.infra from target t where t.infra.probe.id = :probeId") -// Page findForProbeId(@Param("probeId") Long probeId, Pageable pageRequest); + // @Query("select t.infra from target t where t.infra.probe.id = :probeId") + // Page findForProbeId(@Param("probeId") Long probeId, Pageable + // pageRequest); Page findAllByInfraProbeId(Long probeId, Pageable pageRequest); } 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 202bc85..e2be40c 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 @@ -19,208 +19,219 @@ // import java.util.List; // /** -// * Created by snoop on 17. 6. 28. -// */ +// * Created by snoop on 17. 6. 28. +// */ // @Service("TargetDiscoveryService") -// public class CentralTargetDiscoveryService implements TargetDiscoveryService { +// public class CentralTargetDiscoveryService implements TargetDiscoveryService +// { -// @Autowired -// private TargetService targetService; +// @Autowired +// private TargetService targetService; -// @Autowired -// private CentralInfraMachineService infraMachineService; +// @Autowired +// private CentralInfraMachineService infraMachineService; -// @Autowired -// private CentralInfraOSService infraOSService; +// @Autowired +// private CentralInfraOSService infraOSService; -// @Autowired -// private CentralInfraHostService infraHostService; +// @Autowired +// private CentralInfraHostService infraHostService; -// // @Autowired -// // private CentralInfraService infraService; +// // @Autowired +// // private CentralInfraService infraService; -// @Autowired -// private CentralInfraOSPortService infraOSPortService; +// @Autowired +// private CentralInfraOSPortService infraOSPortService; -// @Autowired -// private CentralInfraServiceService infraServiceService; +// @Autowired +// private CentralInfraServiceService infraServiceService; -// @Transactional -// public boolean saveAllTarget(List hosts, Probe probe) throws OverflowException { +// @Transactional +// public boolean saveAllTarget(List hosts, Probe probe) throws +// OverflowException { -// InfraHost infraHost = null; +// InfraHost infraHost = null; -// for (Host host : hosts) { +// for (Host host : hosts) { -// infraHost = this.createAndReadHost(host, probe); +// infraHost = this.createAndReadHost(host, probe); -// this.createPort(infraHost, host, probe); - -// } -// return true; -// } - -// private void createService(InfraHost infraHost, Port port, Probe probe) throws OverflowException { - -// MetaInfraType typeService = new MetaInfraType(7); - -// String portType = "UDP"; - -// if (port.getPortType() == PortType.TLS || port.getPortType() == PortType.TCP || port.getPortType() == null) { -// portType = "TCP"; -// } - -// if (port.getServiceList() == null) { -// return; -// } - -// // 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); - -// InfraService dbInfraService = this.infraServiceService -// .readByInfraHostIDAndPortAndPortType(infraHost.getId(), port.getPortNumber(), portType); - -// if (dbInfraService != null) { -// if (service.isTarget() && dbInfraService.getTarget() == null) { -// Target targetService = new Target(); -// targetService.setDisplayName(service.getServiceName()); -// this.targetService.regist(targetService, probe); -// dbInfraService.setTarget(targetService); -// this.infraServiceService.regist(dbInfraService); -// } -// continue; -// } - -// InfraService infraService = new InfraService(); -// infraService.setInfraHost(infraHost); -// infraService.setPort(port.getPortNumber()); -// infraService.setPortType(portType); -// infraService.setMetaInfraType(typeService); -// infraService.setProbe(probe); - -// if (port.getPortType() == PortType.TLS) { -// infraService.setTlsType(true); -// } -// infraService.setMetaInfraVendor(MetaInfraVendor.CreateInfraVendorByService(service.getServiceName())); - -// if (service.isTarget()) { -// Target targetService = new Target(); -// targetService.setDisplayName(service.getServiceName()); -// this.targetService.regist(targetService, probe); -// infraService.setTarget(targetService); -// } - -// this.infraServiceService.regist(infraService); - -// } - -// } - -// private void createPort(InfraHost infraHost, Host host, Probe probe) throws OverflowException { - -// // if(host.getPorts() == null) { -// // return; -// // } - -// String portType = "UDP"; - -// MetaInfraType typePort = new MetaInfraType(6); - -// InfraOS infraOS = infraHost.getInfraOS(); - -// // for( String key: host.getPorts().keySet()) { - -// if (host.getPortList() == null) { -// return; -// } - -// for (Port port : host.getPortList()) { -// // Port port = host.getPorts().get(key); - -// if (port.getPortType() == PortType.TLS || port.getPortType() == PortType.TCP) { -// portType = "TCP"; -// } - -// InfraOSPort dbInfraOSPort = this.infraOSPortService.readByInfraOSIDAndPortAndPortType(infraOS.getId(), port.getPortNumber(), -// portType); -// if (dbInfraOSPort == null) { -// InfraOSPort infraOSPort = new InfraOSPort(); -// infraOSPort.setInfraOS(infraOS); -// infraOSPort.setPort(port.getPortNumber()); -// infraOSPort.setPortType(portType); -// infraOSPort.setProbe(probe); -// infraOSPort.setMetaInfraType(typePort); - -// if (port.getPortType() == PortType.TLS) { -// infraOSPort.setTlsType(true); -// } -// infraOSPort.setMetaInfraVendor(MetaInfraVendor.CreateInfraVendorByPort(port.getPortNumber())); -// this.infraOSPortService.regist(infraOSPort); -// } - -// this.createService(infraHost, port, probe); -// } -// } - -// private InfraHost createAndReadHost(Host host, Probe probe) throws OverflowException { - -// InfraHost infraHost = this.infraHostService.readByIp(host.getIpv4()); -// if (infraHost != null) { - -// if (host.isTarget() && infraHost.getTarget() == null) { -// Target target = new Target(); -// target.setDisplayName(host.getIpv4() + "-Host"); - -// this.targetService.regist(target, probe); -// infraHost.setTarget(target); -// this.infraHostService.regist(infraHost); -// } - -// return infraHost; -// } else { -// MetaInfraType typeMachine = new MetaInfraType(1); // 1 = Machine; - -// MetaInfraType typeOS = new MetaInfraType(3);// 3 = Os - -// MetaInfraType typeHost = new MetaInfraType(2); // 2 = Host - -// InfraMachine infraMachine = new InfraMachine(); -// infraMachine.setProbe(probe); -// infraMachine.setMetaInfraType(typeMachine); -// infraMachine.setMeta(host.getIpv4() + "-MACHINE"); -// this.infraMachineService.regist(infraMachine); - -// InfraOS infraOS = new InfraOS(); -// infraOS.setInfraMachine(infraMachine); -// infraOS.setMetaInfraVendor(MetaInfraVendor.CreateInfraVendorByOS(host.getOs())); -// infraOS.setMetaInfraType(typeOS); -// infraOS.setProbe(probe); -// infraOS.setMeta(host.getIpv4() + "-OS"); -// this.infraOSService.regist(infraOS); - -// InfraHost newInfraHost = new InfraHost(); -// newInfraHost.setIpv4(host.getIpv4()); -// newInfraHost.setMac(host.getMac()); -// newInfraHost.setInfraOS(infraOS); -// newInfraHost.setMetaInfraType(typeHost); -// newInfraHost.setProbe(probe); - -// if (host.isTarget()) { -// Target target = new Target(); -// target.setDisplayName(host.getIpv4() + "-Host"); - -// this.targetService.regist(target, probe); -// newInfraHost.setTarget(target); -// } - -// this.infraHostService.regist(newInfraHost); -// infraHost = newInfraHost; -// } - -// return infraHost; -// } +// this.createPort(infraHost, host, probe); + +// } +// return true; +// } + +// private void createService(InfraHost infraHost, Port port, Probe probe) +// throws OverflowException { + +// MetaInfraType typeService = new MetaInfraType(7); + +// String portType = "UDP"; + +// if (port.getPortType() == PortType.TLS || port.getPortType() == PortType.TCP +// || port.getPortType() == null) { +// portType = "TCP"; +// } + +// if (port.getServiceList() == null) { +// return; +// } + +// // 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); + +// InfraService dbInfraService = this.infraServiceService +// .readByInfraHostIDAndPortAndPortType(infraHost.getId(), port.getPortNumber(), +// portType); + +// if (dbInfraService != null) { +// if (service.isTarget() && dbInfraService.getTarget() == null) { +// Target targetService = new Target(); +// targetService.setDisplayName(service.getServiceName()); +// this.targetService.regist(targetService, probe); +// dbInfraService.setTarget(targetService); +// this.infraServiceService.regist(dbInfraService); +// } +// continue; +// } + +// InfraService infraService = new InfraService(); +// infraService.setInfraHost(infraHost); +// infraService.setPort(port.getPortNumber()); +// infraService.setPortType(portType); +// infraService.setMetaInfraType(typeService); +// infraService.setProbe(probe); + +// if (port.getPortType() == PortType.TLS) { +// infraService.setTlsType(true); +// } +// infraService.setMetaInfraVendor(MetaInfraVendor.CreateInfraVendorByService(service.getServiceName())); + +// if (service.isTarget()) { +// Target targetService = new Target(); +// targetService.setDisplayName(service.getServiceName()); +// this.targetService.regist(targetService, probe); +// infraService.setTarget(targetService); +// } + +// this.infraServiceService.regist(infraService); + +// } + +// } + +// private void createPort(InfraHost infraHost, Host host, Probe probe) throws +// OverflowException { + +// // if(host.getPorts() == null) { +// // return; +// // } + +// String portType = "UDP"; + +// MetaInfraType typePort = new MetaInfraType(6); + +// InfraOS infraOS = infraHost.getInfraOS(); + +// // for( String key: host.getPorts().keySet()) { + +// if (host.getPortList() == null) { +// return; +// } + +// for (Port port : host.getPortList()) { +// // Port port = host.getPorts().get(key); + +// if (port.getPortType() == PortType.TLS || port.getPortType() == PortType.TCP) +// { +// portType = "TCP"; +// } + +// InfraOSPort dbInfraOSPort = +// this.infraOSPortService.readByInfraOSIDAndPortAndPortType(infraOS.getId(), +// port.getPortNumber(), +// portType); +// if (dbInfraOSPort == null) { +// InfraOSPort infraOSPort = new InfraOSPort(); +// infraOSPort.setInfraOS(infraOS); +// infraOSPort.setPort(port.getPortNumber()); +// infraOSPort.setPortType(portType); +// infraOSPort.setProbe(probe); +// infraOSPort.setMetaInfraType(typePort); + +// if (port.getPortType() == PortType.TLS) { +// infraOSPort.setTlsType(true); +// } +// infraOSPort.setMetaInfraVendor(MetaInfraVendor.CreateInfraVendorByPort(port.getPortNumber())); +// this.infraOSPortService.regist(infraOSPort); +// } + +// this.createService(infraHost, port, probe); +// } +// } + +// private InfraHost createAndReadHost(Host host, Probe probe) throws +// OverflowException { + +// InfraHost infraHost = this.infraHostService.readByIp(host.getIpv4()); +// if (infraHost != null) { + +// if (host.isTarget() && infraHost.getTarget() == null) { +// Target target = new Target(); +// target.setDisplayName(host.getIpv4() + "-Host"); + +// this.targetService.regist(target, probe); +// infraHost.setTarget(target); +// this.infraHostService.regist(infraHost); +// } + +// return infraHost; +// } else { +// MetaInfraType typeMachine = new MetaInfraType(1); // 1 = Machine; + +// MetaInfraType typeOS = new MetaInfraType(3);// 3 = Os + +// MetaInfraType typeHost = new MetaInfraType(2); // 2 = Host + +// InfraMachine infraMachine = new InfraMachine(); +// infraMachine.setProbe(probe); +// infraMachine.setMetaInfraType(typeMachine); +// infraMachine.setMeta(host.getIpv4() + "-MACHINE"); +// this.infraMachineService.regist(infraMachine); + +// InfraOS infraOS = new InfraOS(); +// infraOS.setInfraMachine(infraMachine); +// infraOS.setMetaInfraVendor(MetaInfraVendor.CreateInfraVendorByOS(host.getOs())); +// infraOS.setMetaInfraType(typeOS); +// infraOS.setProbe(probe); +// infraOS.setMeta(host.getIpv4() + "-OS"); +// this.infraOSService.regist(infraOS); + +// InfraHost newInfraHost = new InfraHost(); +// newInfraHost.setIpv4(host.getIpv4()); +// newInfraHost.setMac(host.getMac()); +// newInfraHost.setInfraOS(infraOS); +// newInfraHost.setMetaInfraType(typeHost); +// newInfraHost.setProbe(probe); + +// if (host.isTarget()) { +// Target target = new Target(); +// target.setDisplayName(host.getIpv4() + "-Host"); + +// this.targetService.regist(target, probe); +// newInfraHost.setTarget(target); +// } + +// this.infraHostService.regist(newInfraHost); +// 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 05d752e..18688b7 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 @@ -31,148 +31,150 @@ import org.springframework.transaction.annotation.Transactional; @org.springframework.stereotype.Service("TargetService") public class CentralTargetService implements TargetService { - @Autowired - private TargetDAO targetDAO; - @Autowired - private CentralProbeService probeService; - @Autowired - private CentralInfraHostService infraHostService; - @Autowired - private CentralInfraServiceService infraServiceService; + @Autowired + private TargetDAO targetDAO; + @Autowired + private CentralProbeService probeService; + @Autowired + private CentralInfraHostService infraHostService; + @Autowired + private CentralInfraServiceService infraServiceService; - @Transactional - public Target regist(Target target, Probe probe) throws OverflowException { - this.probeService.increaseTargetCount(probe); - return this.targetDAO.save(target); - } + @Transactional + public Target regist(Target target, Probe probe) throws OverflowException { + this.probeService.increaseTargetCount(probe); + return this.targetDAO.save(target); + } - @Transactional - public void remove(Target target, Probe probe) throws OverflowException { - this.probeService.decreaseTargetCount(probe); - this.targetDAO.delete(target); - } + @Transactional + public void remove(Target target, Probe probe) throws OverflowException { + this.probeService.decreaseTargetCount(probe); + this.targetDAO.delete(target); + } - public Target read(String id) throws OverflowException { - return this.targetDAO.findById(Long.valueOf(id)).get(); - } + public Target read(String id) throws OverflowException { + return this.targetDAO.findById(Long.valueOf(id)).get(); + } - public Target modify(Target target) throws OverflowException { - return this.targetDAO.save(target); - } + public Target modify(Target target) throws OverflowException { + return this.targetDAO.save(target); + } - @Deprecated - public Target regist(Target target) throws OverflowException { - return this.targetDAO.save(target); - } + @Deprecated + public Target regist(Target target) throws OverflowException { + return this.targetDAO.save(target); + } - @Deprecated - public void remove(Target target) throws OverflowException { - this.targetDAO.delete(target); - } + @Deprecated + public void remove(Target target) throws OverflowException { + this.targetDAO.delete(target); + } - public Target increaseSensorCount(Target target) throws OverflowException { - Target t = this.targetDAO.findById(target.getId()).get(); - t.setSensorCount(t.getSensorCount() + 1); - return this.targetDAO.save(t); - } + public Target increaseSensorCount(Target target) throws OverflowException { + Target t = this.targetDAO.findById(target.getId()).get(); + t.setSensorCount(t.getSensorCount() + 1); + return this.targetDAO.save(t); + } - public Target decreaseSensorCount(Target target) throws OverflowException { - Target t = this.targetDAO.findById(target.getId()).get(); - int count = t.getSensorCount(); - if (t.getSensorCount() > 0) { - t.setSensorCount(count - 1); - } - return this.targetDAO.save(t); + public Target decreaseSensorCount(Target target) throws OverflowException { + Target t = this.targetDAO.findById(target.getId()).get(); + int count = t.getSensorCount(); + if (t.getSensorCount() > 0) { + t.setSensorCount(count - 1); } + return this.targetDAO.save(t); + } - public Target readExistHostTarget(Long probeId, String ip) throws OverflowException { - InfraHost infraHost = this.infraHostService.readByProbeIdAndIpv4(probeId, ip); - if (null == infraHost) - return null; - return this.targetDAO.findByInfraId(infraHost.getId()); - } + public Target readExistHostTarget(Long probeId, String ip) throws OverflowException { + InfraHost infraHost = this.infraHostService.readByProbeIdAndIpv4(probeId, ip); + if (null == infraHost) + return null; + return this.targetDAO.findByInfraId(infraHost.getId()); + } - public Target readExistServiceTarget(Long hostId, int portNumber, String portType) throws OverflowException { - InfraService infraService = this.infraServiceService.readByInfraHostIDAndPortAndPortType(hostId, portNumber, - portType); - if (null == infraService) - return null; - return this.targetDAO.findByInfraId(infraService.getId()); - } + public Target readExistServiceTarget(Long hostId, int portNumber, String portType) throws OverflowException { + InfraService infraService = this.infraServiceService.readByInfraHostIDAndPortAndPortType(hostId, portNumber, + portType); + if (null == infraService) + return null; + return this.targetDAO.findByInfraId(infraService.getId()); + } - public Page readAllByProbeID(Long probeID, PageParams pageParams) throws OverflowException { - return this.targetDAO.findAllByInfraProbeId(probeID, PageUtil.getPageRequest(pageParams)); -// return null; - } - @Transactional - public List registDiscoveredTargets(Long probeId, List hosts, List services) - throws OverflowException { - List targets = new ArrayList(); - targets.addAll(registDiscoveredHostTargets(probeId, hosts)); - targets.addAll(this.registDiscoveredServiceTargets(probeId, services)); - return targets; - } + public Page readAllByProbeID(Long probeID, PageParams pageParams) throws OverflowException { + return this.targetDAO.findAllByInfraProbeId(probeID, PageUtil.getPageRequest(pageParams)); + // return null; + } - private List registDiscoveredHostTargets(Long probeId, List hosts) throws OverflowException { - List targets = new ArrayList<>(); - if (null == hosts) - return targets; - for (Host host : hosts) { - InfraHost infraHost = this.registInfraHostByDiscoveredHost(host, probeId); - Target target = new Target(); - target.setInfra(infraHost); - String displayName = (host.getIpv6() == null || host.getIpv6().trim().isEmpty()) ? host.getIpv6() : host.getIpv4(); - target.setDisplayName(displayName); - targets.add(this.targetDAO.save(target)); - } - return targets; - } + @Transactional + public List registDiscoveredTargets(Long probeId, List hosts, List services) + throws OverflowException { + List targets = new ArrayList(); + targets.addAll(registDiscoveredHostTargets(probeId, hosts)); + targets.addAll(this.registDiscoveredServiceTargets(probeId, services)); + return targets; + } - private List registDiscoveredServiceTargets(Long probeId, List services) throws OverflowException { - List targets = new ArrayList<>(); - if (null == services) - return targets; - for (Service service : services) { - Host host = service.getPort().getHost(); - InfraHost infraHost = null; - InfraHost existInfraHost = this.infraHostService.readByProbeIdAndIpv4(probeId, host.getIpv4()); - InfraService infraService = null; - if (null != existInfraHost) { - infraHost = existInfraHost; - } else { - infraHost = this.registInfraHostByDiscoveredHost(host, probeId); - infraService = this.registInfraServiceByDiscoveredService(infraHost, service, probeId); - } - - Target target = new Target(); - target.setInfra(infraService); - String displayName = service.getServiceName(); - target.setDisplayName(displayName); - targets.add(this.targetDAO.save(target)); - } - return targets; + private List registDiscoveredHostTargets(Long probeId, List hosts) throws OverflowException { + List targets = new ArrayList<>(); + if (null == hosts) + return targets; + for (Host host : hosts) { + InfraHost infraHost = this.registInfraHostByDiscoveredHost(host, probeId); + Target target = new Target(); + target.setInfra(infraHost); + String displayName = (host.getIpv6() == null || host.getIpv6().trim().isEmpty()) ? host.getIpv6() + : host.getIpv4(); + target.setDisplayName(displayName); + targets.add(this.targetDAO.save(target)); } + return targets; + } - private InfraHost registInfraHostByDiscoveredHost(Host host, Long probeId) throws OverflowException { - InfraHost infraHost = new InfraHost(); - infraHost.setMetaInfraType(new MetaInfraType(2)); - infraHost.setProbe(new Probe(probeId)); - infraHost.setIpv4(host.getIpv4()); - infraHost.setIpv6(host.getIpv6()); - infraHost.setMac(host.getMac()); - return this.infraHostService.regist(infraHost); - } + private List registDiscoveredServiceTargets(Long probeId, List services) throws OverflowException { + List targets = new ArrayList<>(); + if (null == services) + return targets; + for (Service service : services) { + Host host = service.getPort().getHost(); + InfraHost infraHost = null; + InfraHost existInfraHost = this.infraHostService.readByProbeIdAndIpv4(probeId, host.getIpv4()); + InfraService infraService = null; + if (null != existInfraHost) { + infraHost = existInfraHost; + } else { + infraHost = this.registInfraHostByDiscoveredHost(host, probeId); + infraService = this.registInfraServiceByDiscoveredService(infraHost, service, probeId); + } - private InfraService registInfraServiceByDiscoveredService(InfraHost infraHost, Service service, Long probeId) - throws OverflowException { - InfraService infraService = new InfraService(); - infraHost.setMetaInfraType(new MetaInfraType(7)); - infraService.setInfraHost(infraHost); - infraService.setPort(service.getPort().getPortNumber()); - infraService.setPortType(service.getPort().getPortType().toString()); - infraService.setTlsType(service.getCryptoType() == CryptoType.TLS); - infraService.setMetaInfraVendor(MetaInfraVendor.CreateInfraVendorByService(service.getServiceName())); - return this.infraServiceService.regist(infraService); + Target target = new Target(); + target.setInfra(infraService); + String displayName = service.getServiceName(); + target.setDisplayName(displayName); + targets.add(this.targetDAO.save(target)); } + return targets; + } + + private InfraHost registInfraHostByDiscoveredHost(Host host, Long probeId) throws OverflowException { + InfraHost infraHost = new InfraHost(); + infraHost.setMetaInfraType(new MetaInfraType(2)); + infraHost.setProbe(new Probe(probeId)); + infraHost.setIpv4(host.getIpv4()); + infraHost.setIpv6(host.getIpv6()); + infraHost.setMac(host.getMac()); + return this.infraHostService.regist(infraHost); + } + + private InfraService registInfraServiceByDiscoveredService(InfraHost infraHost, Service service, Long probeId) + throws OverflowException { + InfraService infraService = new InfraService(); + infraHost.setMetaInfraType(new MetaInfraType(7)); + infraService.setInfraHost(infraHost); + infraService.setPort(service.getPort().getPortNumber()); + infraService.setPortType(service.getPort().getPortType().toString()); + infraService.setTlsType(service.getCryptoType() == CryptoType.TLS); + infraService.setMetaInfraVendor(MetaInfraVendor.CreateInfraVendorByService(service.getServiceName())); + return this.infraServiceService.regist(infraService); + } } diff --git a/src/main/java/com/loafle/overflow/central/proxy/ProxyServerInterceptor.java b/src/main/java/com/loafle/overflow/central/proxy/ProxyServerInterceptor.java index e6e486e..17132b9 100644 --- a/src/main/java/com/loafle/overflow/central/proxy/ProxyServerInterceptor.java +++ b/src/main/java/com/loafle/overflow/central/proxy/ProxyServerInterceptor.java @@ -6,16 +6,16 @@ import io.grpc.*; public class ProxyServerInterceptor implements ServerInterceptor { - @Override - public ServerCall.Listener interceptCall(ServerCall call, Metadata headers, - ServerCallHandler next) { - String clientType = headers.get(SessionMetadata.METADATA_CLIENT_TYPE_KEY); - String sessionID = headers.get(SessionMetadata.METADATA_SESSION_ID_KEY); - String targetID = headers.get(SessionMetadata.METADATA_TARGET_ID_KEY); + @Override + public ServerCall.Listener interceptCall(ServerCall call, Metadata headers, + ServerCallHandler next) { + String clientType = headers.get(SessionMetadata.METADATA_CLIENT_TYPE_KEY); + String sessionID = headers.get(SessionMetadata.METADATA_SESSION_ID_KEY); + String targetID = headers.get(SessionMetadata.METADATA_TARGET_ID_KEY); - Context ctx = Context.current().withValues(SessionMetadata.CTX_CLIENT_TYPE_KEY, clientType, - SessionMetadata.CTX_SESSION_ID_KEY, sessionID, SessionMetadata.CTX_TARGET_ID_KEY, targetID); + Context ctx = Context.current().withValues(SessionMetadata.CTX_CLIENT_TYPE_KEY, clientType, + SessionMetadata.CTX_SESSION_ID_KEY, sessionID, SessionMetadata.CTX_TARGET_ID_KEY, targetID); - return Contexts.interceptCall(ctx, call, headers, next); - } + return Contexts.interceptCall(ctx, call, headers, next); + } } diff --git a/src/main/java/com/loafle/overflow/central/proxy/ServiceProxy.java b/src/main/java/com/loafle/overflow/central/proxy/ServiceProxy.java index b58db4e..a23c48fa 100644 --- a/src/main/java/com/loafle/overflow/central/proxy/ServiceProxy.java +++ b/src/main/java/com/loafle/overflow/central/proxy/ServiceProxy.java @@ -34,13 +34,13 @@ public class ServiceProxy { ServiceImpl serviceImpl = ctx.getBean(ServiceImpl.class); server = NettyServerBuilder.forPort(port) - .addService(ServerInterceptors.intercept(serviceImpl, proxyServerInterceptor)) - .build().start(); + .addService(ServerInterceptors.intercept(serviceImpl, proxyServerInterceptor)).build().start(); logger.info("Server started, listening on " + port); Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { - // Use stderr here since the logger may have been reset by its JVM shutdown hook. + // Use stderr here since the logger may have been reset by its JVM shutdown + // hook. System.err.println("*** shutting down gRPC server since JVM is shutting down"); ServiceProxy.this.stop(); System.err.println("*** server shut down"); @@ -105,4 +105,3 @@ public class ServiceProxy { } } - diff --git a/src/main/java/com/loafle/overflow/central/redis/service/RedisMessagePublisher.java b/src/main/java/com/loafle/overflow/central/redis/service/RedisMessagePublisher.java index b1154f1..cb57122 100644 --- a/src/main/java/com/loafle/overflow/central/redis/service/RedisMessagePublisher.java +++ b/src/main/java/com/loafle/overflow/central/redis/service/RedisMessagePublisher.java @@ -133,7 +133,7 @@ public class RedisMessagePublisher implements MessagePublisher { results.add(json); } catch (IOException e) { e.printStackTrace(); - } + } } } return results; diff --git a/src/main/java/com/loafle/overflow/central/spring/AppConfig.java b/src/main/java/com/loafle/overflow/central/spring/AppConfig.java index b71a508..032b64a 100644 --- a/src/main/java/com/loafle/overflow/central/spring/AppConfig.java +++ b/src/main/java/com/loafle/overflow/central/spring/AppConfig.java @@ -15,19 +15,19 @@ import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; @PropertySource({ "classpath:database.properties", "classpath:mail.properties", "classpath:redis.properties", "classpath:cache.properties" }) public class AppConfig { - // @Bean - // public static PropertyPlaceholderConfigurer propertyPlaceholderConfigurer() { - // PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer(); - //// ppc.setLocation(new ClassPathResource("database.properties")); - // ppc.setLocations(new Resource[] { - // new ClassPathResource("database.properties"), - // new ClassPathResource("mail.properties"), - // new ClassPathResource("redis.properties") - // }); - // ppc.setIgnoreUnresolvablePlaceholders(true); + // @Bean + // public static PropertyPlaceholderConfigurer propertyPlaceholderConfigurer() { + // PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer(); + //// ppc.setLocation(new ClassPathResource("database.properties")); + // ppc.setLocations(new Resource[] { + // new ClassPathResource("database.properties"), + // new ClassPathResource("mail.properties"), + // new ClassPathResource("redis.properties") + // }); + // ppc.setIgnoreUnresolvablePlaceholders(true); // - // return ppc; - // } + // return ppc; + // } @Bean public PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() { return new PropertySourcesPlaceholderConfigurer(); @@ -35,10 +35,10 @@ public class AppConfig { // @Bean // public Gson gson() { - // GsonBuilder builder = new GsonBuilder(); - // builder.excludeFieldsWithModifiers(Modifier.TRANSIENT, Modifier.PRIVATE); - // // builder.excludeFieldsWithoutExposeAnnotation(); - // return builder.create(); + // GsonBuilder builder = new GsonBuilder(); + // builder.excludeFieldsWithModifiers(Modifier.TRANSIENT, Modifier.PRIVATE); + // // builder.excludeFieldsWithoutExposeAnnotation(); + // return builder.create(); // } @Bean public ObjectMapper getObjectMapper() { diff --git a/src/main/java/com/loafle/overflow/central/spring/CacheConfiguration.java b/src/main/java/com/loafle/overflow/central/spring/CacheConfiguration.java index d23209b..9414df8 100644 --- a/src/main/java/com/loafle/overflow/central/spring/CacheConfiguration.java +++ b/src/main/java/com/loafle/overflow/central/spring/CacheConfiguration.java @@ -10,17 +10,17 @@ import org.springframework.context.annotation.Configuration; @EnableCaching @Configuration public class CacheConfiguration { - @Value("#{'${cache.cache-names}'.split(',')}") - private String[] cacheNames; - @Value("${cache.caffeine.spec}") - private String spec; + @Value("#{'${cache.cache-names}'.split(',')}") + private String[] cacheNames; + @Value("${cache.caffeine.spec}") + private String spec; - @Bean - public CacheManager cacheManager() { - //A EhCache based Cache manager - CaffeineCacheManager cacheManager = new CaffeineCacheManager(cacheNames); - cacheManager.setAllowNullValues(false); - cacheManager.setCacheSpecification(spec); - return cacheManager; - } + @Bean + public CacheManager cacheManager() { + // A EhCache based Cache manager + CaffeineCacheManager cacheManager = new CaffeineCacheManager(cacheNames); + cacheManager.setAllowNullValues(false); + cacheManager.setCacheSpecification(spec); + return cacheManager; + } } diff --git a/src/main/java/com/loafle/overflow/central/spring/JdbcConfiguration.java b/src/main/java/com/loafle/overflow/central/spring/JdbcConfiguration.java index a7740a5..b7d1336 100644 --- a/src/main/java/com/loafle/overflow/central/spring/JdbcConfiguration.java +++ b/src/main/java/com/loafle/overflow/central/spring/JdbcConfiguration.java @@ -21,82 +21,79 @@ import javax.persistence.EntityManager; import javax.sql.DataSource; import java.util.Properties; - /** * Created by root on 17. 6. 13. */ @Configuration @EnableTransactionManagement -@EnableJpaRepositories(basePackages = {"com.loafle.overflow"}) -public class JdbcConfiguration implements TransactionManagementConfigurer { - @Value("${datasource.driver-class-name}") - private String driver; - @Value("${datasource.url}") - private String url; - @Value("${datasource.username}") - private String username; - @Value("${datasource.password}") - private String password; - @Value("${jpa.hibernate.dialect}") - private String dialect; - @Value("${jpa.hibernate.ddl-auto}") - private String hbm2ddlAuto; +@EnableJpaRepositories(basePackages = { "com.loafle.overflow" }) +public class JdbcConfiguration implements TransactionManagementConfigurer { + @Value("${datasource.driver-class-name}") + private String driver; + @Value("${datasource.url}") + private String url; + @Value("${datasource.username}") + private String username; + @Value("${datasource.password}") + private String password; + @Value("${jpa.hibernate.dialect}") + private String dialect; + @Value("${jpa.hibernate.ddl-auto}") + private String hbm2ddlAuto; - @Bean - public DataSource configureDataSource() { - DriverManagerDataSource dataSource = new DriverManagerDataSource(); - dataSource.setDriverClassName(driver); - dataSource.setUrl(url); - dataSource.setUsername(username); - dataSource.setPassword(password); - return dataSource; + @Bean + public DataSource configureDataSource() { + DriverManagerDataSource dataSource = new DriverManagerDataSource(); + dataSource.setDriverClassName(driver); + dataSource.setUrl(url); + dataSource.setUsername(username); + dataSource.setPassword(password); + return dataSource; + } + + @Bean + public LocalContainerEntityManagerFactoryBean entityManagerFactory() { + LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean(); + entityManagerFactoryBean.setDataSource(configureDataSource()); + entityManagerFactoryBean.setPackagesToScan("com.loafle.overflow"); + entityManagerFactoryBean.setJpaVendorAdapter(new HibernateJpaVendorAdapter()); + + Properties jpaProperties = new Properties(); + jpaProperties.put(Environment.DIALECT, dialect); + jpaProperties.put(Environment.HBM2DDL_AUTO, hbm2ddlAuto); + jpaProperties.put(Environment.SHOW_SQL, true); + + entityManagerFactoryBean.setJpaProperties(jpaProperties); + + return entityManagerFactoryBean; + } + + @Bean + @Qualifier(value = "transactionManager") + public PlatformTransactionManager annotationDrivenTransactionManager() { + return new JpaTransactionManager(); + } + + @Bean + public EntityManager entityManager() { + return entityManagerFactory().getObject().createEntityManager(); + } + + @Bean + public DataSourceInitializer dataSourceInitializer(DataSource dataSource) { + DataSourceInitializer initializer = new DataSourceInitializer(); + initializer.setDataSource(dataSource); + + ClassPathResource initSqlResource = new ClassPathResource("/init.sql"); + if (initSqlResource.exists()) { + ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator(); + databasePopulator.addScript(initSqlResource); + databasePopulator.setIgnoreFailedDrops(true); + initializer.setDatabasePopulator(databasePopulator); + } else { + initializer.setEnabled(false); } - @Bean - public LocalContainerEntityManagerFactoryBean entityManagerFactory() { - LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean(); - entityManagerFactoryBean.setDataSource(configureDataSource()); - entityManagerFactoryBean.setPackagesToScan("com.loafle.overflow"); - entityManagerFactoryBean.setJpaVendorAdapter(new HibernateJpaVendorAdapter()); - - Properties jpaProperties = new Properties(); - jpaProperties.put(Environment.DIALECT, dialect); - jpaProperties.put(Environment.HBM2DDL_AUTO, hbm2ddlAuto); - jpaProperties.put(Environment.SHOW_SQL, true); - - entityManagerFactoryBean.setJpaProperties(jpaProperties); - - return entityManagerFactoryBean; - } - - - - @Bean - @Qualifier(value = "transactionManager") - public PlatformTransactionManager annotationDrivenTransactionManager() { - return new JpaTransactionManager(); - } - - @Bean - public EntityManager entityManager() { - return entityManagerFactory().getObject().createEntityManager(); - } - - @Bean - public DataSourceInitializer dataSourceInitializer(DataSource dataSource) { - DataSourceInitializer initializer = new DataSourceInitializer(); - initializer.setDataSource(dataSource); - - ClassPathResource initSqlResource = new ClassPathResource("/init.sql"); - if (initSqlResource.exists()) { - ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator(); - databasePopulator.addScript(initSqlResource); - databasePopulator.setIgnoreFailedDrops(true); - initializer.setDatabasePopulator(databasePopulator); - } else { - initializer.setEnabled(false); - } - - return initializer; - } + return initializer; + } } diff --git a/src/main/java/com/loafle/overflow/central/spring/MailConfiguration.java b/src/main/java/com/loafle/overflow/central/spring/MailConfiguration.java index b391d80..fa127ff 100644 --- a/src/main/java/com/loafle/overflow/central/spring/MailConfiguration.java +++ b/src/main/java/com/loafle/overflow/central/spring/MailConfiguration.java @@ -18,63 +18,62 @@ import java.util.Properties; @ComponentScan(basePackages = "com.loafle.overflow") public class MailConfiguration { - @Value("${mail.host}") - private String host; - @Value("${mail.port}") - private int port; - @Value("${mail.username}") - private String username; - @Value("${mail.password}") - private String password; - @Value("${mail.protocol}") - private String protocol; + @Value("${mail.host}") + private String host; + @Value("${mail.port}") + private int port; + @Value("${mail.username}") + private String username; + @Value("${mail.password}") + private String password; + @Value("${mail.protocol}") + private String protocol; - @Bean - public JavaMailSenderImpl mailSender() { - JavaMailSenderImpl mailSender = new JavaMailSenderImpl(); + @Bean + public JavaMailSenderImpl mailSender() { + JavaMailSenderImpl mailSender = new JavaMailSenderImpl(); - mailSender.setHost(this.host); - mailSender.setPort(this.port); - mailSender.setUsername(this.username); - mailSender.setPassword(this.password); - mailSender.setProtocol(this.protocol); + mailSender.setHost(this.host); + mailSender.setPort(this.port); + mailSender.setUsername(this.username); + mailSender.setPassword(this.password); + mailSender.setProtocol(this.protocol); - mailSender.setJavaMailProperties(getJavaMailProperties()); + mailSender.setJavaMailProperties(getJavaMailProperties()); - return mailSender; - } + return mailSender; + } - @Bean - public Properties getJavaMailProperties() { - Properties javaMailProperties = new Properties(); - javaMailProperties.put("mail.smtp.starttls.enable", true); - javaMailProperties.put("mail.smtp.auth", true); - javaMailProperties.put("mail.transport.protocol", "smtp"); - javaMailProperties.put("mail.debug", "true"); - javaMailProperties.put("mail.smtps.ssl.checkserveridentity", true); - javaMailProperties.put("mail.smtps.ssl.trust", "*"); + @Bean + public Properties getJavaMailProperties() { + Properties javaMailProperties = new Properties(); + javaMailProperties.put("mail.smtp.starttls.enable", true); + javaMailProperties.put("mail.smtp.auth", true); + javaMailProperties.put("mail.transport.protocol", "smtp"); + javaMailProperties.put("mail.debug", "true"); + javaMailProperties.put("mail.smtps.ssl.checkserveridentity", true); + javaMailProperties.put("mail.smtps.ssl.trust", "*"); - return javaMailProperties; - } + return javaMailProperties; + } - - @Bean - public VelocityEngine getVelocityEngine() throws VelocityException, IOException { - Properties properties = new Properties(); - properties.load(this.getClass().getResourceAsStream("/velocity.properties")); - return new VelocityEngine(properties); - } + @Bean + public VelocityEngine getVelocityEngine() throws VelocityException, IOException { + Properties properties = new Properties(); + properties.load(this.getClass().getResourceAsStream("/velocity.properties")); + return new VelocityEngine(properties); + } } // -// @Value("${mail.properties.mail.smtp.auth}") -// private boolean smtpAuth; -// @Value("${mail.properties.mail.smtp.starttls.enable}") -// private boolean ttlEnable; -// @Value("${mail.transport.protocol}") -// private String transProtocol; -// @Value("${mail.smtps.ssl.checkserveridentity}") -// private boolean checkserver; -// @Value("${mail.smtps.ssl.trust}") -// private String sslTrust; +// @Value("${mail.properties.mail.smtp.auth}") +// private boolean smtpAuth; +// @Value("${mail.properties.mail.smtp.starttls.enable}") +// private boolean ttlEnable; +// @Value("${mail.transport.protocol}") +// private String transProtocol; +// @Value("${mail.smtps.ssl.checkserveridentity}") +// private boolean checkserver; +// @Value("${mail.smtps.ssl.trust}") +// private String sslTrust; diff --git a/src/main/java/com/loafle/overflow/central/spring/RedisConfiguration.java b/src/main/java/com/loafle/overflow/central/spring/RedisConfiguration.java index dea86bf..eb64170 100644 --- a/src/main/java/com/loafle/overflow/central/spring/RedisConfiguration.java +++ b/src/main/java/com/loafle/overflow/central/spring/RedisConfiguration.java @@ -20,54 +20,53 @@ import java.util.Map; @Configuration public class RedisConfiguration { - @Value("${redis.host}") - private String host; - @Value("${redis.port}") - private int port; - @Value("#{'${redis.channels}'.split(',')}") - private List channels; + @Value("${redis.host}") + private String host; + @Value("${redis.port}") + private int port; + @Value("#{'${redis.channels}'.split(',')}") + private List channels; - @Bean - JedisConnectionFactory jedisConnectionFactory() { - RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration(); - redisStandaloneConfiguration.setHostName(host); - redisStandaloneConfiguration.setPort(port); - // redisStandaloneConfiguration.setDatabase(0); - // redisStandaloneConfiguration.setPassword(RedisPassword.of("password")); + @Bean + JedisConnectionFactory jedisConnectionFactory() { + RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration(); + redisStandaloneConfiguration.setHostName(host); + redisStandaloneConfiguration.setPort(port); + // redisStandaloneConfiguration.setDatabase(0); + // redisStandaloneConfiguration.setPassword(RedisPassword.of("password")); - JedisClientConfigurationBuilder jedisClientConfiguration = JedisClientConfiguration.builder(); - jedisClientConfiguration.connectTimeout(Duration.ofSeconds(60));// 60s connection timeout + JedisClientConfigurationBuilder jedisClientConfiguration = JedisClientConfiguration.builder(); + jedisClientConfiguration.connectTimeout(Duration.ofSeconds(60));// 60s connection timeout - JedisConnectionFactory jedisConFactory = new JedisConnectionFactory(redisStandaloneConfiguration, - jedisClientConfiguration.build()); + JedisConnectionFactory jedisConFactory = new JedisConnectionFactory(redisStandaloneConfiguration, + jedisClientConfiguration.build()); + // JedisConnectionFactory jedisConFactory = new JedisConnectionFactory(); + // jedisConFactory.setHostName(host); + // jedisConFactory.setPort(port); + return jedisConFactory; + } - // JedisConnectionFactory jedisConFactory = new JedisConnectionFactory(); - // jedisConFactory.setHostName(host); - // jedisConFactory.setPort(port); - return jedisConFactory; - } - - @Bean - public RedisTemplate redisTemplate() { - final RedisTemplate template = new RedisTemplate(); - template.setConnectionFactory(jedisConnectionFactory()); - template.setValueSerializer(new GenericToStringSerializer(Object.class)); - return template; - } - - @Bean - MessagePublisher messagePublisher() { - return new RedisMessagePublisher(redisTemplate(), topics()); - } - - @Bean - Map topics() { - Map topicMap = new HashMap<>(this.channels.size()); - for (String channel: this.channels) { - topicMap.put(channel, new ChannelTopic(channel)); - } - return topicMap; + @Bean + public RedisTemplate redisTemplate() { + final RedisTemplate template = new RedisTemplate(); + template.setConnectionFactory(jedisConnectionFactory()); + template.setValueSerializer(new GenericToStringSerializer(Object.class)); + return template; + } + + @Bean + MessagePublisher messagePublisher() { + return new RedisMessagePublisher(redisTemplate(), topics()); + } + + @Bean + Map topics() { + Map topicMap = new HashMap<>(this.channels.size()); + for (String channel : this.channels) { + topicMap.put(channel, new ChannelTopic(channel)); } + return topicMap; + } }