This commit is contained in:
crusader 2018-06-07 15:02:38 +09:00
parent c3ca0ea93b
commit 07e9f73e48
100 changed files with 1889 additions and 1881 deletions

13
.editorconfig Normal file
View File

@ -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

View File

@ -1,3 +1,6 @@
{ {
"editor.tabSize": 2,
"editor.insertSpaces": true,
"java.configuration.updateBuildConfiguration": "automatic" "java.configuration.updateBuildConfiguration": "automatic"
} }

View File

@ -5,17 +5,17 @@ import com.loafle.overflow.central.proxy.ServiceProxy;
import java.io.IOException; import java.io.IOException;
public class Central { public class Central {
public static void main(String[] args) throws IOException, InterruptedException { public static void main(String[] args) throws IOException, InterruptedException {
if(args.length <= 0) { if (args.length <= 0) {
System.out.println("Port args"); System.out.println("Port args");
System.out.println("first parameter is Port Number"); System.out.println("first parameter is Port Number");
return; return;
}
int port = Integer.valueOf(args[0]);
final ServiceProxy server = new ServiceProxy();
server.start(port);
server.blockUntilShutdown();
} }
int port = Integer.valueOf(args[0]);
final ServiceProxy server = new ServiceProxy();
server.start(port);
server.blockUntilShutdown();
}
} }

View File

@ -3,19 +3,19 @@ package com.loafle.overflow.central.commons.service;
import com.loafle.overflow.core.exception.OverflowException; import com.loafle.overflow.core.exception.OverflowException;
public interface MessagePublisher { public interface MessagePublisher {
void publishToDomainMembers(final Long domainID, final String method, final Object... params) void publishToDomainMembers(final Long domainID, final String method, final Object... params)
throws OverflowException; throws OverflowException;
void publishToDomainMembersByProbeKey(final String probeKey, final String method, final Object... params) void publishToDomainMembersByProbeKey(final String probeKey, final String method, final Object... params)
throws OverflowException; 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) void publishToMemberSession(final String memberSessionID, final String method, final Object... params)
throws OverflowException; throws OverflowException;
void publishToNoAuthProbe(final String tempProbeKey, final String method, final Object... params) void publishToNoAuthProbe(final String tempProbeKey, final String method, final Object... params)
throws OverflowException; 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;
} }

View File

@ -29,106 +29,106 @@ import java.util.Map;
@Service("EmailSender") @Service("EmailSender")
public class EmailSender { public class EmailSender {
@Autowired @Autowired
private JavaMailSender mailSender; private JavaMailSender mailSender;
@Autowired @Autowired
private VelocityEngine velocityEngine; private VelocityEngine velocityEngine;
private String key = "loafle@RandomKey"; private String key = "loafle@RandomKey";
private String initVector = "loafleInitVector"; private String initVector = "loafleInitVector";
public void sendSimpleEmail(final Mail mail) throws MailException { public void sendSimpleEmail(final Mail mail) throws MailException {
MimeMessagePreparator preparator = mimeMessage -> { MimeMessagePreparator preparator = mimeMessage -> {
MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true, "UTF-8"); MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true, "UTF-8");
helper.setTo(mail.getMailTo()); helper.setTo(mail.getMailTo());
helper.setFrom("geek@loafle.com"); helper.setFrom("geek@loafle.com");
helper.setSubject(mail.getMailSubject()); helper.setSubject(mail.getMailSubject());
helper.setText(getContentFromTemplate(mail.getModel(), mail), true); helper.setText(getContentFromTemplate(mail.getModel(), mail), true);
helper.addInline("company-logo", new ClassPathResource("/vmtemplates/overFlow_logo.png")); 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 { return null;
MimeMessage message = mailSender.createMimeMessage(); }
// pass 'true' to the constructor to create a multipart message
MimeMessageHelper helper = new MimeMessageHelper(message, true);
helper.setTo(mail.getMailTo()); public String decrypt(String encrypted) {
helper.setSubject(mail.getMailSubject()); try {
helper.setText(mail.getMailContent()); IvParameterSpec iv = new IvParameterSpec(initVector.getBytes("UTF-8"));
helper.setFrom("geek@loafle.com"); SecretKeySpec skeySpec = new SecretKeySpec(key.getBytes("UTF-8"), "AES");
// FileSystemResource file = new FileSystemResource(new
// File(mail.getAttachments()));
// helper.addAttachment("Invoice", file);
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) { return null;
try { }
IvParameterSpec iv = new IvParameterSpec(initVector.getBytes("UTF-8"));
SecretKeySpec skeySpec = new SecretKeySpec(key.getBytes("UTF-8"), "AES"); private String getContentFromTemplate(Map<String, Object> model, Mail mail) {
StringWriter writer = new StringWriter();
VelocityContext context = new VelocityContext();
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING"); Template template = this.velocityEngine.getTemplate(mail.getTemplateLoacation(), "UTF-8");
cipher.init(Cipher.ENCRYPT_MODE, skeySpec, iv);
byte[] encrypted = cipher.doFinal(value.getBytes()); model.forEach((key, value) -> {
System.out.println("encrypted string: " + Base64.encodeBase64String(encrypted)); context.put(key, value);
});
return Base64.encodeBase64String(encrypted); template.merge(context, writer);
} catch (Exception ex) {
ex.printStackTrace();
}
return null; // try {
}
public String decrypt(String encrypted) { // template.merge(this.velocityEngine, content);
try { // // content.append(VelocityEngineUtils.mergeTemplateIntoString
IvParameterSpec iv = new IvParameterSpec(initVector.getBytes("UTF-8")); // // (velocityEngine,
SecretKeySpec skeySpec = new SecretKeySpec(key.getBytes("UTF-8"), "AES"); // // mail.getTemplateLoacation(), "UTF-8", model));
// } catch (Exception e) {
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING"); // e.printStackTrace();
cipher.init(Cipher.DECRYPT_MODE, skeySpec, iv); // }
return writer.toString();
byte[] original = cipher.doFinal(Base64.decodeBase64(encrypted)); }
return new String(original);
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
private String getContentFromTemplate(Map<String, Object> 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();
}
} }

View File

@ -8,18 +8,18 @@ import com.fasterxml.uuid.impl.TimeBasedGenerator;
* Created by geek on 18. 3. 27. * Created by geek on 18. 3. 27.
*/ */
public class GenerateKey { 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("-"); String[] uuids = generator.generate().toString().split("-");
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
for ( int idx = 0; idx < uuids.length; idx++ ) { for (int idx = 0; idx < uuids.length; idx++) {
sb.append(uuids[idx]); sb.append(uuids[idx]);
}
return sb.toString();
} }
return sb.toString();
}
} }

View File

@ -9,18 +9,20 @@ import org.springframework.data.domain.Sort;
* Created by insanity on 17. 8. 25. * Created by insanity on 17. 8. 25.
*/ */
public class PageUtil { public class PageUtil {
private static Sort.Direction getSortDirection(String sortDirection) { private static Sort.Direction getSortDirection(String sortDirection) {
if(sortDirection.equalsIgnoreCase("ascending")) { if (sortDirection.equalsIgnoreCase("ascending")) {
return Sort.Direction.ASC; return Sort.Direction.ASC;
}
return Sort.Direction.DESC;
} }
return Sort.Direction.DESC;
}
public static PageRequest getPageRequest(PageParams pageParams) { public static PageRequest getPageRequest(PageParams pageParams) {
if(pageParams.getSortCol().isEmpty()) pageParams.setSortCol("id"); if (pageParams.getSortCol().isEmpty())
if(pageParams.getSortDirection().isEmpty()) pageParams.setSortDirection("descending"); pageParams.setSortCol("id");
if (pageParams.getSortDirection().isEmpty())
pageParams.setSortDirection("descending");
return new PageRequest(pageParams.getPageNo(), pageParams.getCountPerPage(), return new PageRequest(pageParams.getPageNo(), pageParams.getCountPerPage(),
new Sort(PageUtil.getSortDirection(pageParams.getSortDirection()), pageParams.getSortCol())); new Sort(PageUtil.getSortDirection(pageParams.getSortDirection()), pageParams.getSortCol()));
} }
} }

View File

@ -6,46 +6,49 @@ import io.grpc.Metadata;
import static io.grpc.Metadata.ASCII_STRING_MARSHALLER; import static io.grpc.Metadata.ASCII_STRING_MARSHALLER;
public class SessionMetadata { public class SessionMetadata {
/* /*
digits: 0-9 * digits: 0-9 uppercase letters: A-Z (normalized to lower) lowercase letters:
uppercase letters: A-Z (normalized to lower) * a-z special characters: -_.
lowercase letters: a-z */
special characters: -_.
*/
public static final String CLIENT_TYPE_KEY = "OVERFLOW_GRPC_CLIENT_TYPE"; 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 SESSION_ID_KEY = "OVERFLOW_GRPC_SESSION_ID";
public static final String TARGET_ID_KEY = "OVERFLOW_GRPC_TARGET_ID"; public static final String TARGET_ID_KEY = "OVERFLOW_GRPC_TARGET_ID";
public static final Context.Key<String> CTX_CLIENT_TYPE_KEY = Context.key(CLIENT_TYPE_KEY); public static final Context.Key<String> CTX_CLIENT_TYPE_KEY = Context.key(CLIENT_TYPE_KEY);
public static final Context.Key<String> CTX_SESSION_ID_KEY = Context.key(SESSION_ID_KEY); public static final Context.Key<String> CTX_SESSION_ID_KEY = Context.key(SESSION_ID_KEY);
public static final Context.Key<String> CTX_TARGET_ID_KEY = Context.key(TARGET_ID_KEY); public static final Context.Key<String> CTX_TARGET_ID_KEY = Context.key(TARGET_ID_KEY);
public static final Metadata.Key<String> METADATA_CLIENT_TYPE_KEY = Metadata.Key.of(CLIENT_TYPE_KEY, ASCII_STRING_MARSHALLER); public static final Metadata.Key<String> METADATA_CLIENT_TYPE_KEY = Metadata.Key.of(CLIENT_TYPE_KEY,
public static final Metadata.Key<String> METADATA_SESSION_ID_KEY = Metadata.Key.of(SESSION_ID_KEY, ASCII_STRING_MARSHALLER); ASCII_STRING_MARSHALLER);
public static final Metadata.Key<String> METADATA_TARGET_ID_KEY = Metadata.Key.of(TARGET_ID_KEY, ASCII_STRING_MARSHALLER); public static final Metadata.Key<String> METADATA_SESSION_ID_KEY = Metadata.Key.of(SESSION_ID_KEY,
ASCII_STRING_MARSHALLER);
public static final Metadata.Key<String> METADATA_TARGET_ID_KEY = Metadata.Key.of(TARGET_ID_KEY,
ASCII_STRING_MARSHALLER);
public static ClientType getClientType() { public static ClientType getClientType() {
return ClientType.valueOf(CTX_CLIENT_TYPE_KEY.get()); return ClientType.valueOf(CTX_CLIENT_TYPE_KEY.get());
} }
public static String getSessionID() {
return CTX_SESSION_ID_KEY.get(); public static String getSessionID() {
} return CTX_SESSION_ID_KEY.get();
public static String getTargetID() { }
return CTX_TARGET_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 { public String toString() {
MEMBER("MEMBER"), return name;
PROBE("PROBE");
final private String name;
private ClientType(String name) {
this.name = name;
}
public String toString() {
return name;
}
} }
}
} }

View File

@ -5,57 +5,51 @@ package com.loafle.overflow.central.commons.utils;
*/ */
public class StringConvertor { public class StringConvertor {
public static String intToIp(long i) { public static String intToIp(long i) {
return ((i >> 24 ) & 0xFF) + "." + return ((i >> 24) & 0xFF) + "." + ((i >> 16) & 0xFF) + "." + ((i >> 8) & 0xFF) + "." + (i & 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; public static long macStrToLong(String address) {
for (int i = 0; i < ipAddressInArray.length; i++) { String[] elements = address.split(":");
if (elements.length != MAC_ADDRESS_LENGTH) {
int power = 3 - i; throw new IllegalArgumentException(
int ip = Integer.parseInt(ipAddressInArray[i]); "Specified MAC Address must contain 12 hex digits" + " separated pairwise by :'s.");
result += ip * Math.pow(256, power);
}
return result;
} }
byte[] addressInBytes = new byte[MAC_ADDRESS_LENGTH];
// https://github.com/Sovietaced/floodlight/blob/master/src/main/java/net/floodlightcontroller/util/MACAddress.java for (int i = 0; i < MAC_ADDRESS_LENGTH; i++) {
String element = elements[i];
public static final int MAC_ADDRESS_LENGTH = 6; addressInBytes[i] = (byte) Integer.parseInt(element, 16);
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);
} }
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);
}
} }

View File

@ -1,19 +1,16 @@
package com.loafle.overflow.central.module.apikey.dao; package com.loafle.overflow.central.module.apikey.dao;
import com.loafle.overflow.model.apikey.ApiKey; import com.loafle.overflow.model.apikey.ApiKey;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
/** /**
* Created by root on 17. 6. 1. * Created by root on 17. 6. 1.
*/ */
@Repository @Repository
public interface ApiKeyDAO extends JpaRepository<ApiKey, Long> { public interface ApiKeyDAO extends JpaRepository<ApiKey, Long> {
ApiKey findByApiKey(String apiKey); ApiKey findByApiKey(String apiKey);
ApiKey findByDomainId(Long domainID); ApiKey findByDomainId(Long domainID);
} }

View File

@ -1,9 +1,7 @@
package com.loafle.overflow.central.module.apikey.service; package com.loafle.overflow.central.module.apikey.service;
import com.loafle.overflow.central.module.apikey.dao.ApiKeyDAO; import com.loafle.overflow.central.module.apikey.dao.ApiKeyDAO;
import com.loafle.overflow.core.exception.OverflowException; import com.loafle.overflow.core.exception.OverflowException;
import com.loafle.overflow.model.apikey.ApiKey; import com.loafle.overflow.model.apikey.ApiKey;
import com.loafle.overflow.service.central.apikey.ApiKeyService; import com.loafle.overflow.service.central.apikey.ApiKeyService;
@ -16,33 +14,31 @@ import org.springframework.stereotype.Service;
@Service("ApiKeyService") @Service("ApiKeyService")
public class CentralApiKeyService implements ApiKeyService { public class CentralApiKeyService implements ApiKeyService {
@Autowired
private ApiKeyDAO apiKeyDAO;
@Autowired public ApiKey regist(ApiKey apiKey) throws OverflowException {
private ApiKeyDAO apiKeyDAO;
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 true;
return this.apiKeyDAO.findByDomainId(domainID); }
}
public boolean check(String apiKey) throws OverflowException { public ApiKey readByApiKey(String apiKey) throws OverflowException {
return this.apiKeyDAO.findByApiKey(apiKey);
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);
}
} }

View File

@ -9,5 +9,5 @@ import org.springframework.stereotype.Repository;
*/ */
@Repository @Repository
public interface AuthCrawlerDAO extends JpaRepository<AuthCrawler, Long> { public interface AuthCrawlerDAO extends JpaRepository<AuthCrawler, Long> {
AuthCrawler findByMetaCrawlerIdAndTargetId(Short metaCrawlerId, Long targetId); AuthCrawler findByMetaCrawlerIdAndTargetId(Short metaCrawlerId, Long targetId);
} }

View File

@ -25,7 +25,7 @@ public class CentralAuthCrawlerService implements AuthCrawlerService {
public AuthCrawler regist(AuthCrawler authCrawler) { public AuthCrawler regist(AuthCrawler authCrawler) {
// if (authCrawler == null) { // if (authCrawler == null) {
// return this.authCrawlerDAO.save(authCrawler); // return this.authCrawlerDAO.save(authCrawler);
// } // }
AuthCrawler dbAuthCrawler = this.authCrawlerDAO.findByMetaCrawlerIdAndTargetId(authCrawler.getMetaCrawler().getId(), AuthCrawler dbAuthCrawler = this.authCrawlerDAO.findByMetaCrawlerIdAndTargetId(authCrawler.getMetaCrawler().getId(),

View File

@ -1,6 +1,5 @@
package com.loafle.overflow.central.module.domain.dao; package com.loafle.overflow.central.module.domain.dao;
import com.loafle.overflow.model.domain.Domain; import com.loafle.overflow.model.domain.Domain;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
@ -9,5 +8,5 @@ import org.springframework.stereotype.Repository;
* Created by root on 17. 6. 23. * Created by root on 17. 6. 23.
*/ */
@Repository @Repository
public interface DomainDAO extends JpaRepository<Domain, Long> { public interface DomainDAO extends JpaRepository<Domain, Long> {
} }

View File

@ -11,8 +11,8 @@ import java.util.List;
*/ */
@Repository @Repository
public interface EmailAuthDAO extends JpaRepository<EmailAuth, Long> { public interface EmailAuthDAO extends JpaRepository<EmailAuth, Long> {
EmailAuth findByEmailAuthKey(String emailAuthKey); EmailAuth findByEmailAuthKey(String emailAuthKey);
List<EmailAuth> findByMemberId(Long memberId); List<EmailAuth> findByMemberId(Long memberId);
} }

View File

@ -23,82 +23,75 @@ import java.util.Map;
@Service("GenerateUtil") @Service("GenerateUtil")
public class GenerateUtil { public class GenerateUtil {
@Autowired @Autowired
private MetaSensorItemKeyService metaSensorItemKeyService; private MetaSensorItemKeyService metaSensorItemKeyService;
private Map<Short, Map<Integer, MetaSensorItemKey>> mappingMap = null;
public Map<Integer, MetaSensorItemKey> initMappingMap(MetaCrawler metaCrawler) throws OverflowException {
private Map<Short, Map<Integer, MetaSensorItemKey>> mappingMap = null; if (this.mappingMap == null) {
this.mappingMap = new HashMap<>();
public Map<Integer, MetaSensorItemKey> initMappingMap(MetaCrawler metaCrawler) throws OverflowException {
if(this.mappingMap == null) {
this.mappingMap = new HashMap<>();
}
Map<Integer, MetaSensorItemKey> 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;
} }
Map<Integer, MetaSensorItemKey> resultMap = this.mappingMap.get(metaCrawler.getId());
if (resultMap != null) {
public Crawler getCrawler(MetaCrawler metaCrawler) throws OverflowException { return resultMap;
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;
} }
resultMap = this.metaSensorItemKeyService.readAllMapByMetaCrawlerID(metaCrawler.getId());
this.mappingMap.put(metaCrawler.getId(), resultMap);
return resultMap;
}
public Crawler getCrawler(MetaCrawler metaCrawler) throws OverflowException {
public Map<String, List<MetaSensorItemKey>> sortItems(List<SensorItem> sensorItems, Map<Integer, MetaSensorItemKey> keyMap) throws OverflowException { Crawler crawler = new Crawler();
crawler.setName(metaCrawler.getName());
Map<String, List<MetaSensorItemKey>> metricMap = new HashMap<>(); String container = "";
MetaSensorItemKey itemKey = null; if (metaCrawler.getId() == MetaCrawlerEnum.CASSANDRA_CRAWLER.getValue()
|| metaCrawler.getId() == MetaCrawlerEnum.CASSANDRA_CRAWLER.getValue()
for(SensorItem sItem : sensorItems) { || metaCrawler.getId() == MetaCrawlerEnum.MONGODB_CRAWLER.getValue()
itemKey = keyMap.get(sItem.getMetaSensorDisplayItem().getId()); || metaCrawler.getId() == MetaCrawlerEnum.MSSQL_CRAWLER.getValue()
if(metricMap.containsKey(itemKey.getFroms()) == false) { || metaCrawler.getId() == MetaCrawlerEnum.ORACLE_CRAWLER.getValue()
metricMap.put(itemKey.getFroms(), new ArrayList<>()); || metaCrawler.getId() == MetaCrawlerEnum.POSTGRESQL_CRAWLER.getValue()
} || metaCrawler.getId() == MetaCrawlerEnum.JMX_CRAWLER.getValue()) {
metricMap.get(itemKey.getFroms()).add(itemKey); container = "java_proxy";
} } else {
container = "network_proxy";
return metricMap;
} }
public Keys createKeys(MetaSensorItemKey itemKey) throws OverflowException { crawler.setContainer(container);
Keys keys = new Keys();
keys.setKey(itemKey.getKey()); return crawler;
keys.setMetric(itemKey.getMetaSensorItem().getKey()); }
return keys;
public Map<String, List<MetaSensorItemKey>> sortItems(List<SensorItem> sensorItems,
Map<Integer, MetaSensorItemKey> keyMap) throws OverflowException {
Map<String, List<MetaSensorItemKey>> 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;
}
} }

View File

@ -1,6 +1,5 @@
package com.loafle.overflow.central.module.generator.service; 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.core.type.PortType;
import com.loafle.overflow.model.auth.AuthCrawler; import com.loafle.overflow.model.auth.AuthCrawler;
import com.loafle.overflow.model.infra.Infra; import com.loafle.overflow.model.infra.Infra;
@ -77,7 +76,8 @@ public class InfraHostGenerator {
private Target createTarget(InfraHost infraHost, Sensor dbSensor) throws Exception { 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) { if (authCrawler == null) {
return null; return null;
@ -87,7 +87,9 @@ public class InfraHostGenerator {
Connection connection = new Connection(); Connection connection = new Connection();
connection.setIp(infraHost.getIpv4()); connection.setIp(infraHost.getIpv4());
HashMap<String, String> optionMap = this.objectMapper.readValue(authCrawler.getAuthJson(), new TypeReference<Map<String, String>>(){}); HashMap<String, String> optionMap = this.objectMapper.readValue(authCrawler.getAuthJson(),
new TypeReference<Map<String, String>>() {
});
if (dbSensor.getMetaCrawler().getId() == MetaCrawlerEnum.WMI_CRAWLER.getValue()) { if (dbSensor.getMetaCrawler().getId() == MetaCrawlerEnum.WMI_CRAWLER.getValue()) {
connection.setPort(135); connection.setPort(135);

View File

@ -37,15 +37,15 @@ public class InfraHostWMIGenerator {
Map<String, List<MetaSensorItemKey>> metricMap = null; Map<String, List<MetaSensorItemKey>> metricMap = null;
metricMap = this.generateUtil.sortItems(sensorItems, keyMap); metricMap = this.generateUtil.sortItems(sensorItems, keyMap);
// MetaSensorItemKey itemKey = null; // MetaSensorItemKey itemKey = null;
// //
// for(SensorItem sItem : sensorItems) { // for(SensorItem sItem : sensorItems) {
// itemKey = keyMap.get(sItem.getItem().getId()); // itemKey = keyMap.get(sItem.getItem().getId());
// if(metricMap.containsKey(itemKey.getFroms()) == false) { // if(metricMap.containsKey(itemKey.getFroms()) == false) {
// metricMap.put(itemKey.getFroms(), new ArrayList<>()); // metricMap.put(itemKey.getFroms(), new ArrayList<>());
// } // }
// metricMap.get(itemKey.getFroms()).add(itemKey); // metricMap.get(itemKey.getFroms()).add(itemKey);
// } // }
List<Item> itemList = new ArrayList<>(); List<Item> itemList = new ArrayList<>();
Item item = null; Item item = null;
@ -76,9 +76,9 @@ public class InfraHostWMIGenerator {
stringBuffer.append(", "); stringBuffer.append(", ");
} }
// keys = new Keys(); // keys = new Keys();
// keys.setKey(tempItemKey.getKey()); // keys.setKey(tempItemKey.getKey());
// keys.setMetric(tempItemKey.getItem().getKey()); // keys.setMetric(tempItemKey.getItem().getKey());
keysList.add(this.generateUtil.createKeys(tempItemKey)); keysList.add(this.generateUtil.createKeys(tempItemKey));
} }
@ -86,7 +86,8 @@ public class InfraHostWMIGenerator {
String json = tempItemKey.getOption(); String json = tempItemKey.getOption();
if (json != null && json.length() > 0) { if (json != null && json.length() > 0) {
HashMap<String, String> optionMap = this.objectMapper.readValue(json, new TypeReference<Map<String, String>>(){}); HashMap<String, String> optionMap = this.objectMapper.readValue(json, new TypeReference<Map<String, String>>() {
});
Object obj = null; Object obj = null;
obj = optionMap.get("appends"); obj = optionMap.get("appends");

View File

@ -1,6 +1,5 @@
package com.loafle.overflow.central.module.generator.service; 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.core.type.PortType;
import com.loafle.overflow.model.auth.AuthCrawler; import com.loafle.overflow.model.auth.AuthCrawler;
import com.loafle.overflow.model.infra.Infra; import com.loafle.overflow.model.infra.Infra;
@ -31,89 +30,91 @@ import java.util.Map;
@Service("InfraServiceGenerator") @Service("InfraServiceGenerator")
public class InfraServiceGenerator { public class InfraServiceGenerator {
@Autowired @Autowired
private GenerateUtil generateUtil; private GenerateUtil generateUtil;
@Autowired @Autowired
private InfraServiceMysqlGenerator infraServiceMysqlGenerator; private InfraServiceMysqlGenerator infraServiceMysqlGenerator;
@Autowired @Autowired
private InfraServiceJMXGenerator infraServiceJMXGenerator; private InfraServiceJMXGenerator infraServiceJMXGenerator;
@Autowired @Autowired
private AuthCrawlerService authCrawlerService; private AuthCrawlerService authCrawlerService;
@Autowired @Autowired
private ObjectMapper objectMapper; private ObjectMapper objectMapper;
public String process(Sensor dbSensor, List<SensorItem> sensorItems, Infra infra) throws Exception { public String process(Sensor dbSensor, List<SensorItem> sensorItems, Infra infra) throws Exception {
com.loafle.overflow.model.infra.InfraService infraService = (com.loafle.overflow.model.infra.InfraService)infra; com.loafle.overflow.model.infra.InfraService infraService = (com.loafle.overflow.model.infra.InfraService) infra;
SensorConfig sensorConfig = new SensorConfig(); SensorConfig sensorConfig = new SensorConfig();
sensorConfig.setConfigID(String.valueOf(dbSensor.getId())); sensorConfig.setConfigID(String.valueOf(dbSensor.getId()));
Target target = this.createTarget(infraService, dbSensor); Target target = this.createTarget(infraService, dbSensor);
if(target == null) { if (target == null) {
return 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<Integer, MetaSensorItemKey> 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);
} }
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) { Crawler crawler = this.generateUtil.getCrawler(dbSensor.getMetaCrawler());
return null; sensorConfig.setCrawler(crawler);
}
Target target = new Target(); Map<Integer, MetaSensorItemKey> keyMap = this.generateUtil.initMappingMap(dbSensor.getMetaCrawler());
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); if (dbSensor.getMetaCrawler().getId() == MetaCrawlerEnum.MYSQL_CRAWLER.getValue()) {
this.infraServiceMysqlGenerator.process(sensorItems, keyMap, dbSensor, sensorConfig);
HashMap<String, String> optionMap = this.objectMapper.readValue(authCrawler.getAuthJson(), new TypeReference<Map<String, String>>(){}); } else if (dbSensor.getMetaCrawler().getId() == MetaCrawlerEnum.JMX_CRAWLER.getValue()) {
this.infraServiceJMXGenerator.process(sensorItems, keyMap, dbSensor, sensorConfig);
Map<String, Object> 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;
} }
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<String, String> optionMap = this.objectMapper.readValue(authCrawler.getAuthJson(),
new TypeReference<Map<String, String>>() {
});
Map<String, Object> 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;
}
} }

View File

@ -73,7 +73,8 @@ public class InfraServiceJMXGenerator {
List<String> arrayCol = null; List<String> arrayCol = null;
if (json != null && json.length() > 0) { if (json != null && json.length() > 0) {
HashMap<String, String> optionMap = this.objectMapper.readValue(json, new TypeReference<Map<String, String>>(){}); HashMap<String, String> optionMap = this.objectMapper.readValue(json, new TypeReference<Map<String, String>>() {
});
Object obj = null; Object obj = null;
obj = optionMap.get("aliases"); obj = optionMap.get("aliases");

View File

@ -33,14 +33,14 @@ public class InfraServiceMysqlGenerator {
public void process(List<SensorItem> sensorItems, Map<Integer, MetaSensorItemKey> keyMap, Sensor dbSensor, public void process(List<SensorItem> sensorItems, Map<Integer, MetaSensorItemKey> keyMap, Sensor dbSensor,
SensorConfig sensorConfig) throws Exception { SensorConfig sensorConfig) throws Exception {
// List<Keys> keysList = new ArrayList<>(); // List<Keys> keysList = new ArrayList<>();
// for(SensorItem sItem : sensorItems) { // for(SensorItem sItem : sensorItems) {
// keys = new Keys(); // keys = new Keys();
// keys.setMetric(sItem.getItem().getKey()); // keys.setMetric(sItem.getItem().getKey());
// keys.setKey(KeyMap.get(sItem.getItem().getId()).getKey()); // keys.setKey(KeyMap.get(sItem.getItem().getId()).getKey());
// keysList.add(keys); // keysList.add(keys);
// } // }
// item.setKeys(keysList); // item.setKeys(keysList);
Map<String, List<MetaSensorItemKey>> metricMap = null; Map<String, List<MetaSensorItemKey>> metricMap = null;
metricMap = this.generateUtil.sortItems(sensorItems, keyMap); metricMap = this.generateUtil.sortItems(sensorItems, keyMap);
@ -81,7 +81,8 @@ public class InfraServiceMysqlGenerator {
String json = tempItemKey.getOption(); String json = tempItemKey.getOption();
if (json != null && json.length() > 0) { if (json != null && json.length() > 0) {
HashMap<String, String> optionMap = this.objectMapper.readValue(json, new TypeReference<Map<String, String>>(){}); HashMap<String, String> optionMap = this.objectMapper.readValue(json, new TypeReference<Map<String, String>>() {
});
Object obj = null; Object obj = null;
obj = optionMap.get("valueColumn"); obj = optionMap.get("valueColumn");
@ -113,42 +114,43 @@ public class InfraServiceMysqlGenerator {
sensorConfig.setItems(itemList); 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<Keys> keysList, QueryInfo queryInfo, MappingInfo mappingInfo) { // public void setQueryAndMapping(MetaCrawler metaCrawler, List<Keys> keysList,
// QueryInfo queryInfo, MappingInfo mappingInfo) {
// //
// switch (metaCrawler.getId()) { // switch (metaCrawler.getId()) {
// case 11: // mysql // case 11: // mysql
// { // {
// String query = "show status where "; // String query = "show status where ";
//// queryInfo.setQuery("show status where "); //// queryInfo.setQuery("show status where ");
// //
// Keys keys = null; // Keys keys = null;
// for(int indexI = 0 ; indexI < keysList.size(); ++indexI) { // for(int indexI = 0 ; indexI < keysList.size(); ++indexI) {
// keys = keysList.get(indexI); // keys = keysList.get(indexI);
// query += "variable_name = '"; // query += "variable_name = '";
// query += keys.getKey(); // query += keys.getKey();
// query += "'"; // query += "'";
// if(indexI + 1 < keysList.size()) { // if(indexI + 1 < keysList.size()) {
// query += " or "; // query += " or ";
// } // }
// } // }
// //
// queryInfo.setQuery(query); // queryInfo.setQuery(query);
// //
// mappingInfo.setParseDirection("row"); // mappingInfo.setParseDirection("row");
// mappingInfo.setValueColumn("Value"); // mappingInfo.setValueColumn("Value");
// //
// List<String> keyColumns = new ArrayList<>(); // List<String> keyColumns = new ArrayList<>();
// keyColumns.add("Variable_name"); // keyColumns.add("Variable_name");
// //
// mappingInfo.setKeyColumns(keyColumns); // mappingInfo.setKeyColumns(keyColumns);
// } // }
// break; // break;
// } // }
// //
// } // }
} }

View File

@ -19,47 +19,44 @@ import com.loafle.overflow.service.central.sensor.SensorItemService;
@Service("SensorConfigGenerator") @Service("SensorConfigGenerator")
public class SensorConfigGenerator { public class SensorConfigGenerator {
@Autowired @Autowired
private SensorItemService sensorItemService; private SensorItemService sensorItemService;
@Autowired @Autowired
private InfraService infraService; private InfraService infraService;
@Autowired @Autowired
private InfraHostGenerator infraHostGenerator; private InfraHostGenerator infraHostGenerator;
@Autowired @Autowired
private InfraServiceGenerator infraServiceGenerator; 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<SensorItem> dbItemList = this.sensorItemService.readAllBySensorID(sensor.getId(), pageParams);
public String generate(Sensor sensor) throws Exception { List<SensorItem> sensorItems = dbItemList.getContent();
PageParams pageParams = new PageParams();
pageParams.setPageNo(0);
pageParams.setCountPerPage(Integer.MAX_VALUE);
pageParams.setSortCol("id");
pageParams.setSortDirection("descending");
Page<SensorItem> dbItemList = this.sensorItemService.readAllBySensorID(sensor.getId(), pageParams);
List<SensorItem> sensorItems = dbItemList.getContent(); if (sensorItems.size() <= 0) {
return "";
}
Sensor dbSensor = sensorItems.get(0).getSensor();
if(sensorItems.size() <= 0) { Infra infra = this.infraService.readByTargetID(dbSensor.getTarget().getId());
return "";
}
Sensor dbSensor = sensorItems.get(0).getSensor();
Infra infra = this.infraService.readByTargetID(dbSensor.getTarget().getId()); // 7 = Infra OS Service
if (infra.getMetaInfraType().getId() == 7) {
// 7 = Infra OS Service return this.infraServiceGenerator.process(dbSensor, sensorItems, infra);
if(infra.getMetaInfraType().getId() == 7) { }
return this.infraServiceGenerator.process(dbSensor, sensorItems, infra); if (infra.getMetaInfraType().getId() == 2) {
} return this.infraHostGenerator.process(dbSensor, sensorItems, infra);
if(infra.getMetaInfraType().getId() == 2) {
return this.infraHostGenerator.process(dbSensor, sensorItems, infra);
}
return null;
} }
return null;
}
} }

View File

@ -12,11 +12,11 @@ import org.springframework.stereotype.Repository;
*/ */
@Repository @Repository
public interface HistoryDAO extends JpaRepository<History, Long> { public interface HistoryDAO extends JpaRepository<History, Long> {
Page<History> findAllByProbeId(Long probeID, Pageable pageable); Page<History> findAllByProbeId(Long probeID, Pageable pageable);
Page<History> findAllByProbeIdAndMetaHistoryTypeId(Long probeID, Integer metaHistoryTypeId, Pageable pageable); Page<History> findAllByProbeIdAndMetaHistoryTypeId(Long probeID, Integer metaHistoryTypeId, Pageable pageable);
Page<History> findAllByDomainId(Long domainID, Pageable pageRequest); Page<History> findAllByDomainId(Long domainID, Pageable pageRequest);
Page<History> findAllByDomainIdAndMetaHistoryTypeId(Long domainID, Integer metaHistoryTypeId, Pageable pageRequest); Page<History> findAllByDomainIdAndMetaHistoryTypeId(Long domainID, Integer metaHistoryTypeId, Pageable pageRequest);
} }

View File

@ -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.central.module.history.dao.HistoryDAO;
import com.loafle.overflow.core.exception.OverflowException; import com.loafle.overflow.core.exception.OverflowException;
import com.loafle.overflow.core.model.PageParams; 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.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 com.loafle.overflow.service.central.history.HistoryService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -16,28 +13,31 @@ import org.springframework.stereotype.Service;
@Service("HistoryService") @Service("HistoryService")
public class CentralHistoryService implements HistoryService { public class CentralHistoryService implements HistoryService {
@Autowired @Autowired
private HistoryDAO historyDAO; private HistoryDAO historyDAO;
public History regist(History history) throws OverflowException { public History regist(History history) throws OverflowException {
return this.historyDAO.save(history); return this.historyDAO.save(history);
} }
public Page<History> readAllByProbeIDAndMetaHistoryTypeID(Long probeID, Integer metaHistoryTypeID,
PageParams pageParams) throws OverflowException {
return this.historyDAO.findAllByProbeIdAndMetaHistoryTypeId(probeID, metaHistoryTypeID,
PageUtil.getPageRequest(pageParams));
}
public Page<History> readAllByProbeIDAndMetaHistoryTypeID(Long probeID, Integer metaHistoryTypeID, PageParams pageParams) throws OverflowException { public Page<History> readAllByProbeID(Long probeID, PageParams pageParams) throws OverflowException {
return this.historyDAO.findAllByProbeIdAndMetaHistoryTypeId(probeID, metaHistoryTypeID, PageUtil.getPageRequest(pageParams)); return this.historyDAO.findAllByProbeId(probeID, PageUtil.getPageRequest(pageParams));
} }
public Page<History> readAllByProbeID(Long probeID, PageParams pageParams) throws OverflowException { public Page<History> readAllByDomainID(Long domainID, PageParams pageParams) throws OverflowException {
return this.historyDAO.findAllByProbeId(probeID, PageUtil.getPageRequest(pageParams)); return this.historyDAO.findAllByDomainId(domainID, PageUtil.getPageRequest(pageParams));
} }
public Page<History> readAllByDomainID(Long domainID, PageParams pageParams) throws OverflowException { public Page<History> readAllByDomainIDAndMetaHistoryTypeID(Long domainID, Integer metaHistoryTypeID,
return this.historyDAO.findAllByDomainId(domainID, PageUtil.getPageRequest(pageParams)); PageParams pageParams) throws OverflowException {
} return this.historyDAO.findAllByDomainIdAndMetaHistoryTypeId(domainID, metaHistoryTypeID,
PageUtil.getPageRequest(pageParams));
public Page<History> readAllByDomainIDAndMetaHistoryTypeID(Long domainID, Integer metaHistoryTypeID, PageParams pageParams) throws OverflowException { }
return this.historyDAO.findAllByDomainIdAndMetaHistoryTypeId(domainID, metaHistoryTypeID, PageUtil.getPageRequest(pageParams));
}
} }

View File

@ -15,14 +15,14 @@ import java.util.List;
*/ */
@Repository @Repository
public interface InfraDAO extends JpaRepository<Infra, Long> { public interface InfraDAO extends JpaRepository<Infra, Long> {
List<Infra> findAllByProbeId(Long probeID); List<Infra> findAllByProbeId(Long probeID);
Page<Infra> findAllByProbeId(Long probeID, Pageable pageable); Page<Infra> findAllByProbeId(Long probeID, Pageable pageable);
Page<Infra> findAllByProbeIn(List<Probe> probes, Pageable pageable); Page<Infra> findAllByProbeIn(List<Probe> probes, Pageable pageable);
List<Target> findAllTargetByProbeIn(List<Probe> probes); List<Target> findAllTargetByProbeIn(List<Probe> probes);
// Infra findByTargetId(Long targetID); // Infra findByTargetId(Long targetID);
} }

View File

@ -9,6 +9,6 @@ import org.springframework.stereotype.Repository;
*/ */
@Repository @Repository
public interface InfraHostDAO extends JpaRepository<InfraHost, Long> { public interface InfraHostDAO extends JpaRepository<InfraHost, Long> {
InfraHost findByProbeIdAndIpv4(Long probeId, String ipv4); InfraHost findByProbeIdAndIpv4(Long probeId, String ipv4);
} }

View File

@ -9,5 +9,5 @@ import org.springframework.stereotype.Repository;
*/ */
@Repository @Repository
public interface InfraOSPortDAO extends JpaRepository<InfraOSPort, Long> { public interface InfraOSPortDAO extends JpaRepository<InfraOSPort, Long> {
InfraOSPort findByInfraOSAndPortAndPortType(Long infraOSId, Integer port, String portType); InfraOSPort findByInfraOSAndPortAndPortType(Long infraOSId, Integer port, String portType);
} }

View File

@ -9,5 +9,5 @@ import org.springframework.stereotype.Repository;
*/ */
@Repository @Repository
public interface InfraServiceDAO extends JpaRepository<InfraService, Long> { public interface InfraServiceDAO extends JpaRepository<InfraService, Long> {
InfraService findByInfraHostIdAndPortAndPortType(Long infraHostId, Integer port, String portType); InfraService findByInfraHostIdAndPortAndPortType(Long infraHostId, Integer port, String portType);
} }

View File

@ -1,6 +1,5 @@
package com.loafle.overflow.central.module.infra.service; package com.loafle.overflow.central.module.infra.service;
import com.loafle.overflow.central.module.infra.dao.InfraHostDAO; import com.loafle.overflow.central.module.infra.dao.InfraHostDAO;
import com.loafle.overflow.core.exception.OverflowException; import com.loafle.overflow.core.exception.OverflowException;
import com.loafle.overflow.model.infra.InfraHost; import com.loafle.overflow.model.infra.InfraHost;
@ -14,19 +13,19 @@ import org.springframework.stereotype.Service;
@Service("InfraHostService") @Service("InfraHostService")
public class CentralInfraHostService implements InfraHostService { public class CentralInfraHostService implements InfraHostService {
@Autowired @Autowired
InfraHostDAO infraHostDAO; InfraHostDAO infraHostDAO;
public InfraHost regist(InfraHost infraHost) throws OverflowException { public InfraHost regist(InfraHost infraHost) throws OverflowException {
return this.infraHostDAO.save(infraHost); return this.infraHostDAO.save(infraHost);
} }
public InfraHost read(Long id) throws OverflowException { public InfraHost read(Long id) throws OverflowException {
return this.infraHostDAO.findById(id).get(); return this.infraHostDAO.findById(id).get();
} }
public InfraHost readByProbeIdAndIpv4(Long probeId, String ip) throws OverflowException { public InfraHost readByProbeIdAndIpv4(Long probeId, String ip) throws OverflowException {
return this.infraHostDAO.findByProbeIdAndIpv4(probeId, ip); return this.infraHostDAO.findByProbeIdAndIpv4(probeId, ip);
} }
} }

View File

@ -12,14 +12,14 @@ import org.springframework.stereotype.Service;
*/ */
@Service("InfraMachineService") @Service("InfraMachineService")
public class CentralInfraMachineService implements InfraMachineService { public class CentralInfraMachineService implements InfraMachineService {
@Autowired @Autowired
InfraMachineDAO infraMachineDAO; InfraMachineDAO infraMachineDAO;
public InfraMachine regist(InfraMachine infraMachine) throws OverflowException { public InfraMachine regist(InfraMachine infraMachine) throws OverflowException {
return this.infraMachineDAO.save(infraMachine); return this.infraMachineDAO.save(infraMachine);
} }
public InfraMachine read(Long id) { public InfraMachine read(Long id) {
return this.infraMachineDAO.findById(id).get(); return this.infraMachineDAO.findById(id).get();
} }
} }

View File

@ -13,14 +13,14 @@ import org.springframework.stereotype.Service;
@Service("InfraOSApplicationService") @Service("InfraOSApplicationService")
public class CentralInfraOSApplicationService implements InfraOSApplicationService { public class CentralInfraOSApplicationService implements InfraOSApplicationService {
@Autowired @Autowired
InfraOSApplicationDAO infraOSApplicationDAO; InfraOSApplicationDAO infraOSApplicationDAO;
public InfraOSApplication regist(InfraOSApplication infraOSApplication) throws OverflowException { public InfraOSApplication regist(InfraOSApplication infraOSApplication) throws OverflowException {
return this.infraOSApplicationDAO.save(infraOSApplication); return this.infraOSApplicationDAO.save(infraOSApplication);
} }
public InfraOSApplication read(Long id) throws OverflowException { public InfraOSApplication read(Long id) throws OverflowException {
return this.infraOSApplicationDAO.findById(id).get(); return this.infraOSApplicationDAO.findById(id).get();
} }
} }

View File

@ -13,14 +13,14 @@ import org.springframework.stereotype.Service;
@Service("InfraOSDaemonService") @Service("InfraOSDaemonService")
public class CentralInfraOSDaemonService implements InfraOSDaemonService { public class CentralInfraOSDaemonService implements InfraOSDaemonService {
@Autowired @Autowired
InfraOSDaemonDAO infraOSDaemonDAO; InfraOSDaemonDAO infraOSDaemonDAO;
public InfraOSDaemon regist(InfraOSDaemon infraOSDaemon) throws OverflowException { public InfraOSDaemon regist(InfraOSDaemon infraOSDaemon) throws OverflowException {
return this.infraOSDaemonDAO.save(infraOSDaemon); return this.infraOSDaemonDAO.save(infraOSDaemon);
} }
public InfraOSDaemon read(Long id) throws OverflowException { public InfraOSDaemon read(Long id) throws OverflowException {
return this.infraOSDaemonDAO.findById(id).get(); return this.infraOSDaemonDAO.findById(id).get();
} }
} }

View File

@ -13,19 +13,19 @@ import org.springframework.stereotype.Service;
@Service("InfraOSPortService") @Service("InfraOSPortService")
public class CentralInfraOSPortService implements InfraOSPortService { public class CentralInfraOSPortService implements InfraOSPortService {
@Autowired @Autowired
InfraOSPortDAO infraOSPortDAO; InfraOSPortDAO infraOSPortDAO;
public InfraOSPort regist(InfraOSPort infraOSPort) throws OverflowException { public InfraOSPort regist(InfraOSPort infraOSPort) throws OverflowException {
return this.infraOSPortDAO.save(infraOSPort); return this.infraOSPortDAO.save(infraOSPort);
} }
public InfraOSPort read(Long id) throws OverflowException { public InfraOSPort read(Long id) throws OverflowException {
return this.infraOSPortDAO.findById(id).get(); return this.infraOSPortDAO.findById(id).get();
} }
public InfraOSPort readByInfraOSIDAndPortAndPortType(Long infraOSID, Integer port, String portType) public InfraOSPort readByInfraOSIDAndPortAndPortType(Long infraOSID, Integer port, String portType)
throws OverflowException { throws OverflowException {
return this.infraOSPortDAO.findByInfraOSAndPortAndPortType(infraOSID, port, portType); return this.infraOSPortDAO.findByInfraOSAndPortAndPortType(infraOSID, port, portType);
} }
} }

View File

@ -13,14 +13,14 @@ import org.springframework.stereotype.Service;
@Service("InfraOSService") @Service("InfraOSService")
public class CentralInfraOSService implements InfraOSService { public class CentralInfraOSService implements InfraOSService {
@Autowired @Autowired
InfraOSDAO infraOSDAO; InfraOSDAO infraOSDAO;
public InfraOS regist(InfraOS infraOS) throws OverflowException { public InfraOS regist(InfraOS infraOS) throws OverflowException {
return this.infraOSDAO.save(infraOS); return this.infraOSDAO.save(infraOS);
} }
public InfraOS read(Long id) throws OverflowException { public InfraOS read(Long id) throws OverflowException {
return this.infraOSDAO.findById(id).get(); return this.infraOSDAO.findById(id).get();
} }
} }

View File

@ -24,58 +24,58 @@ import java.util.List;
@Service("InfraService") @Service("InfraService")
public class CentralInfraService implements InfraService { public class CentralInfraService implements InfraService {
@Autowired @Autowired
InfraDAO infraDAO; InfraDAO infraDAO;
@Autowired @Autowired
SensorDAO sensorDAO; SensorDAO sensorDAO;
@Autowired @Autowired
private ProbeService probeService; private ProbeService probeService;
public Infra regist(Infra infra) throws OverflowException { public Infra regist(Infra infra) throws OverflowException {
return this.infraDAO.save(infra); return this.infraDAO.save(infra);
}
public Infra read(Long id) throws OverflowException {
Infra infra = this.infraDAO.findById(id).get();
return infra;
}
public Page<Infra> readAllByProbeID(Long probeID, PageParams pageParams) throws OverflowException {
return this.infraDAO.findAllByProbeId(probeID, PageUtil.getPageRequest(pageParams));
}
public Page<Infra> readAllByDomainID(Long domainID, PageParams pageParams) throws OverflowException {
List<Probe> probeList = this.probeService.readAllByDomainID(domainID);
if (probeList == null || probeList.size() <= 0) {
throw new OverflowException("ProbeNotFoundException", new Throwable());
} }
public Infra read(Long id) throws OverflowException { Page<Infra> infraList = this.infraDAO.findAllByProbeIn(probeList, PageUtil.getPageRequest(pageParams));
Infra infra = this.infraDAO.findById(id).get(); return infraList;
return infra; }
public List<Target> readAllTargetByDomainID(Long domainID) throws OverflowException {
List<Probe> probes = this.probeService.readAllByDomainID(domainID);
if (probes == null || probes.size() <= 0) {
throw new OverflowException("ProbeNotFoundException", new Throwable());
} }
public Page<Infra> readAllByProbeID(Long probeID, PageParams pageParams) throws OverflowException { return this.infraDAO.findAllTargetByProbeIn(probes);
return this.infraDAO.findAllByProbeId(probeID, PageUtil.getPageRequest(pageParams)); }
}
public Page<Infra> readAllByDomainID(Long domainID, PageParams pageParams) throws OverflowException { public List<Target> readAllTargetByProbes(List<Probe> probes) throws OverflowException {
List<Probe> probeList = this.probeService.readAllByDomainID(domainID); return this.infraDAO.findAllTargetByProbeIn(probes);
// return null;
}
if (probeList == null || probeList.size() <= 0) { public Infra readByTargetID(Long targetID) throws OverflowException {
throw new OverflowException("ProbeNotFoundException", new Throwable()); // return this.infraDAO.findByTargetId(targetID);
} return null;
}
Page<Infra> infraList = this.infraDAO.findAllByProbeIn(probeList, PageUtil.getPageRequest(pageParams));
return infraList;
}
public List<Target> readAllTargetByDomainID(Long domainID) throws OverflowException {
List<Probe> probes = this.probeService.readAllByDomainID(domainID);
if (probes == null || probes.size() <= 0) {
throw new OverflowException("ProbeNotFoundException", new Throwable());
}
return this.infraDAO.findAllTargetByProbeIn(probes);
}
public List<Target> readAllTargetByProbes(List<Probe> probes) throws OverflowException {
return this.infraDAO.findAllTargetByProbeIn(probes);
// return null;
}
public Infra readByTargetID(Long targetID) throws OverflowException {
// return this.infraDAO.findByTargetId(targetID);
return null;
}
} }

View File

@ -13,19 +13,19 @@ import org.springframework.stereotype.Service;
@Service("InfraServiceService") @Service("InfraServiceService")
public class CentralInfraServiceService implements InfraServiceService { public class CentralInfraServiceService implements InfraServiceService {
@Autowired @Autowired
InfraServiceDAO infraServiceDAO; InfraServiceDAO infraServiceDAO;
public InfraService regist(InfraService infraService) throws OverflowException { public InfraService regist(InfraService infraService) throws OverflowException {
return this.infraServiceDAO.save(infraService); return this.infraServiceDAO.save(infraService);
} }
public InfraService read(Long id) throws OverflowException { public InfraService read(Long id) throws OverflowException {
return this.infraServiceDAO.findById(id).get(); return this.infraServiceDAO.findById(id).get();
} }
public InfraService readByInfraHostIDAndPortAndPortType(Long infraHostID, int port, String portType) public InfraService readByInfraHostIDAndPortAndPortType(Long infraHostID, int port, String portType)
throws OverflowException { throws OverflowException {
return this.infraServiceDAO.findByInfraHostIdAndPortAndPortType(infraHostID, port, portType); return this.infraServiceDAO.findByInfraHostIdAndPortAndPortType(infraHostID, port, portType);
} }
} }

View File

@ -10,5 +10,5 @@ import org.springframework.stereotype.Repository;
@Repository @Repository
public interface MemberDAO extends JpaRepository<Member, Long> { public interface MemberDAO extends JpaRepository<Member, Long> {
Member findByEmail(String email); Member findByEmail(String email);
} }

View File

@ -9,7 +9,7 @@ import org.springframework.stereotype.Repository;
*/ */
@Repository @Repository
public interface MemberTotpDAO extends JpaRepository<MemberTotp, Long> { public interface MemberTotpDAO extends JpaRepository<MemberTotp, Long> {
MemberTotp findBySecretCode(String secretCode); MemberTotp findBySecretCode(String secretCode);
MemberTotp findByMemberEmail(String memberEmail); MemberTotp findByMemberEmail(String memberEmail);
} }

View File

@ -32,264 +32,258 @@ import java.util.regex.Pattern;
@Service("MemberService") @Service("MemberService")
public class CentralMemberService implements MemberService { public class CentralMemberService implements MemberService {
@Autowired @Autowired
private MemberDAO memberDAO; private MemberDAO memberDAO;
@Autowired @Autowired
private EmailAuthService emailAuthService; private EmailAuthService emailAuthService;
@Autowired @Autowired
private ApiKeyService apiKeyService; private ApiKeyService apiKeyService;
@Autowired @Autowired
private DomainMemberService domainMemberService; private DomainMemberService domainMemberService;
@Autowired @Autowired
private ProbeService probeService; private ProbeService probeService;
private BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder(); private BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
public DomainMember signin(String signinId, String signinPw) throws OverflowException { public DomainMember signin(String signinId, String signinPw) throws OverflowException {
Member m = this.memberDAO.findByEmail(signinId); Member m = this.memberDAO.findByEmail(signinId);
if ( null == m ) { if (null == m) {
throw new OverflowException("SignInIdNotExistException()", new Throwable()); 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;
} }
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) { m.setSigninFailCount(0);
throw new OverflowException("JoinedEmailException()", new Throwable()); this.modify(m);
}
boolean checkPass = this.isPasswordStrong(pw); DomainMember dm = domainMemberService.readByMemberEmail(m.getEmail());
if (!checkPass) { // Todo Signin History
throw new OverflowException("PasswordNotStrongException()", new Throwable()); return dm;
// ( }
// "Passwords must contain at least one uppercase letter, " +
// "special character, lowercase letter, and number, " + public Member signup(Member member, String pw) throws OverflowException {
// "and must be at least 6 characters long.");
} 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)); member.setPw(passwordEncoder.encode(pw));
}
if (member.getMetaMemberStatus() == null) { } else {
member.setMetaMemberStatus(new MetaMemberStatus((short) 1)); member.setPw(preMember.getPw());
}
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 { if (member.getMetaMemberStatus() == null || member.getMetaMemberStatus().getId() <= 0) {
Member member = this.memberDAO.findByEmail(email); member.setMetaMemberStatus(new MetaMemberStatus());
member.getMetaMemberStatus().setId(preMember.getMetaMemberStatus().getId());
}
return this.modify(member);
}
if (null == member) { private Member modify(Member member) throws OverflowException {
throw new OverflowException("SignInIdNotExistException()", new Throwable()); return this.memberDAO.save(member);
} }
try { public Member confirmPw(String signinId, String signinPw) throws OverflowException {
this.emailAuthService.sendEmailResetPassword(member); Member preMember = this.memberDAO.findByEmail(signinId);
} catch (Exception e) {
// Todo ReSend Mail
e.printStackTrace();
}
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 { return preMember;
String deStr = null; }
try { public Member forgotPassword(String signinId, String newPw) throws OverflowException {
deStr = URLDecoder.decode(token, "UTF-8"); Member preMember = this.memberDAO.findByEmail(signinId);
}catch (Exception e) {
} if (null == preMember) {
throw new OverflowException("SignInIdNotExistException()", new Throwable());
// 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) { Member cMember = this.modify(preMember, newPw);
// Todo websocket session remove
return cMember;
}
public Member read(Long memberId) throws OverflowException {
if (memberId <= 0) {
throw new OverflowException("SignInIdNotExistException()", new Throwable());
} }
@WebappAPI Member resMember = this.memberDAO.findById(memberId).get();
public Member modify(Member member, String pw) throws OverflowException { return resMember;
String email = SessionMetadata.getTargetID(); }
Member preMember = this.memberDAO.findByEmail(member.getEmail());
if (null == preMember || 0 >= preMember.getId()) { @WebappAPI
throw new OverflowException("SigninId Not Exist()", new Throwable()); public void withdrawal(Long memberId) throws OverflowException {
} String email = SessionMetadata.getTargetID();
member.setId(preMember.getId());
if (null != pw && !pw.equals("")) {
boolean checkPass = this.isPasswordStrong(pw);
if (!checkPass) { // Todo DB delete?
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()); public List<Member> readAllByProbeKey(String probeKey) throws OverflowException {
if(!match) {
member.setPw(passwordEncoder.encode(pw));
}
} else {
member.setPw(preMember.getPw());
}
if (member.getMetaMemberStatus() == null || member.getMetaMemberStatus().getId() <= 0) { Probe probe = this.probeService.readByProbeKey(probeKey);
member.setMetaMemberStatus(new MetaMemberStatus());
member.getMetaMemberStatus().setId(preMember.getMetaMemberStatus().getId()); if (probe == null) {
} return null;
return this.modify(member);
} }
private Member modify(Member member) throws OverflowException { return this.domainMemberService.readAllMemberByDomainID(probe.getDomain().getId());
return this.memberDAO.save(member); }
public List<Member> 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 { return this.domainMemberService.readAllMemberByDomainID(apiKey.getDomain().getId());
Member preMember = this.memberDAO.findByEmail(signinId); }
String encodePw = passwordEncoder.encode(signinPw); public List<Member> readAllByDomainID(final Long domainID) throws OverflowException {
Boolean match = passwordEncoder.matches(encodePw, preMember.getPw());
if (!match) { return this.domainMemberService.readAllMemberByDomainID(domainID);
throw new OverflowException("SignInPwNotMatchException", new Throwable()); }
}
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 { protected boolean isPasswordStrong(String pass) {
Member preMember = this.memberDAO.findByEmail(signinId); Matcher m = pattern.matcher(pass);
return m.matches();
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<Member> 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<Member> 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<Member> 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();
}
} }

View File

@ -19,99 +19,100 @@ import java.util.Map;
*/ */
@Service("MemberTotpService") @Service("MemberTotpService")
public class CentralMemberTotpService implements MemberTotpService { public class CentralMemberTotpService implements MemberTotpService {
@Autowired @Autowired
private MemberTotpDAO totpDAO; 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()) { if (null == member || 0 >= member.getId()) {
throw new OverflowException("SignInIdNotExistException", new Throwable()); 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<String, String> createTotp(Member member) throws OverflowException {
Map<String, String> returnMap = new HashMap<>();
GoogleAuthenticator googleAuthenticator = new GoogleAuthenticator();
final GoogleAuthenticatorKey key = googleAuthenticator.createCredentials();
String secret = key.getKey();
// List<Integer> 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)) { sb.append(issuer);
throw new OverflowException("TotpCodeNotMatchException", new Throwable()); sb.append(":");
} }
MemberTotp totp = new MemberTotp(); sb.append(accountName);
totp.setMember(member); return sb.toString();
totp.setSecretCode(secretCode); } else {
throw new IllegalArgumentException("Account name must not be empty.");
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<String, String> createTotp(Member member) throws OverflowException {
Map<String, String> returnMap = new HashMap<>();
GoogleAuthenticator googleAuthenticator = new GoogleAuthenticator();
final GoogleAuthenticatorKey key = googleAuthenticator.createCredentials();
String secret = key.getKey();
// List<Integer> 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.");
}
} }
}
} }

View File

@ -11,5 +11,5 @@ import java.util.List;
*/ */
@Repository @Repository
public interface MetaCrawlerInputItemDAO extends JpaRepository<MetaCrawlerInputItem, Integer> { public interface MetaCrawlerInputItemDAO extends JpaRepository<MetaCrawlerInputItem, Integer> {
List<MetaCrawlerInputItem> findAllByMetaCrawlerId(Short metaCrawlerId); List<MetaCrawlerInputItem> findAllByMetaCrawlerId(Short metaCrawlerId);
} }

View File

@ -11,5 +11,5 @@ import java.util.List;
*/ */
@Repository @Repository
public interface MetaInfraVendorDAO extends JpaRepository<MetaInfraVendor, Integer> { public interface MetaInfraVendorDAO extends JpaRepository<MetaInfraVendor, Integer> {
List<MetaInfraVendor> findAllByMetaInfraTypeId(Integer MetaInfraTypeId); List<MetaInfraVendor> findAllByMetaInfraTypeId(Integer MetaInfraTypeId);
} }

View File

@ -11,5 +11,5 @@ import java.util.List;
*/ */
@Repository @Repository
public interface MetaProbePackageDAO extends JpaRepository<MetaProbePackage, Long> { public interface MetaProbePackageDAO extends JpaRepository<MetaProbePackage, Long> {
List<MetaProbePackage> findAllByMetaProbeOsId(Short metaProbeOsId); List<MetaProbePackage> findAllByMetaProbeOsId(Short metaProbeOsId);
} }

View File

@ -8,6 +8,5 @@ import org.springframework.stereotype.Repository;
* Created by snoop on 17. 6. 26. * Created by snoop on 17. 6. 26.
*/ */
@Repository @Repository
public interface MetaProbeStatusDAO extends JpaRepository<MetaProbeStatus, Short> { public interface MetaProbeStatusDAO extends JpaRepository<MetaProbeStatus, Short> {
} }

View File

@ -8,5 +8,5 @@ import org.springframework.stereotype.Repository;
* Created by insanity on 17. 6. 23. * Created by insanity on 17. 6. 23.
*/ */
@Repository @Repository
public interface MetaProbeTaskTypeDAO extends JpaRepository<MetaProbeTaskType, Short>{ public interface MetaProbeTaskTypeDAO extends JpaRepository<MetaProbeTaskType, Short> {
} }

View File

@ -8,5 +8,5 @@ import org.springframework.stereotype.Repository;
* Created by insanity on 17. 6. 23. * Created by insanity on 17. 6. 23.
*/ */
@Repository @Repository
public interface MetaProbeVersionDAO extends JpaRepository<MetaProbeVersion, Short>{ public interface MetaProbeVersionDAO extends JpaRepository<MetaProbeVersion, Short> {
} }

View File

@ -11,5 +11,5 @@ import java.util.List;
*/ */
@Repository @Repository
public interface MetaSensorDisplayItemDAO extends JpaRepository<MetaSensorDisplayItem, Long> { public interface MetaSensorDisplayItemDAO extends JpaRepository<MetaSensorDisplayItem, Long> {
public List<MetaSensorDisplayItem> findAllByMetaCrawlerId(Short metaCrawlerId); public List<MetaSensorDisplayItem> findAllByMetaCrawlerId(Short metaCrawlerId);
} }

View File

@ -15,6 +15,7 @@ import java.util.List;
@Repository @Repository
public interface MetaSensorDisplayMappingDAO extends JpaRepository<MetaSensorDisplayMapping, Short> { public interface MetaSensorDisplayMappingDAO extends JpaRepository<MetaSensorDisplayMapping, Short> {
@Query("SELECT m.metaSensorItemKey from MetaSensorDisplayMapping m where m.metaSensorDisplayItem.id = :metaSensorDisplayItemId") @Query("SELECT m.metaSensorItemKey from MetaSensorDisplayMapping m where m.metaSensorDisplayItem.id = :metaSensorDisplayItemId")
public List<MetaSensorItemKey> findAllMetaSensorItemKeyByMetaSensorDisplayItemId(@Param("metaSensorDisplayItemId") Long metaSensorDisplayItemId); public List<MetaSensorItemKey> findAllMetaSensorItemKeyByMetaSensorDisplayItemId(
@Param("metaSensorDisplayItemId") Long metaSensorDisplayItemId);
} }

View File

@ -8,5 +8,5 @@ import org.springframework.stereotype.Repository;
* Created by insanity on 17. 6. 23. * Created by insanity on 17. 6. 23.
*/ */
@Repository @Repository
public interface MetaSensorItemDAO extends JpaRepository<MetaSensorItem, Integer>{ public interface MetaSensorItemDAO extends JpaRepository<MetaSensorItem, Integer> {
} }

View File

@ -11,5 +11,5 @@ import java.util.List;
*/ */
@Repository @Repository
public interface MetaSensorItemKeyDAO extends JpaRepository<MetaSensorItemKey, Long> { public interface MetaSensorItemKeyDAO extends JpaRepository<MetaSensorItemKey, Long> {
List<MetaSensorItemKey> findAllByMetaCrawlerId(Short metaCrawlerId); List<MetaSensorItemKey> findAllByMetaCrawlerId(Short metaCrawlerId);
} }

View File

@ -8,5 +8,5 @@ import org.springframework.stereotype.Repository;
* Created by insanity on 17. 6. 23. * Created by insanity on 17. 6. 23.
*/ */
@Repository @Repository
public interface MetaSensorItemTypeDAO extends JpaRepository<MetaSensorItemType, Short>{ public interface MetaSensorItemTypeDAO extends JpaRepository<MetaSensorItemType, Short> {
} }

View File

@ -9,5 +9,5 @@ import org.springframework.stereotype.Repository;
*/ */
@Repository @Repository
public interface MetaSensorStatusDAO extends JpaRepository<MetaSensorStatus, Short> { public interface MetaSensorStatusDAO extends JpaRepository<MetaSensorStatus, Short> {
} }

View File

@ -11,5 +11,5 @@ import java.util.List;
*/ */
@Repository @Repository
public interface MetaVendorCrawlerDAO extends JpaRepository<MetaVendorCrawler, Integer> { public interface MetaVendorCrawlerDAO extends JpaRepository<MetaVendorCrawler, Integer> {
List<MetaVendorCrawler> findAllByMetaInfraVendorId(Integer metaInfraVendorId); List<MetaVendorCrawler> findAllByMetaInfraVendorId(Integer metaInfraVendorId);
} }

View File

@ -8,5 +8,5 @@ import org.springframework.stereotype.Repository;
* Created by insanity on 17. 6. 23. * Created by insanity on 17. 6. 23.
*/ */
@Repository @Repository
public interface MetaVendorCrawlerSensorItemDAO extends JpaRepository<MetaVendorCrawlerSensorItem, Long>{ public interface MetaVendorCrawlerSensorItemDAO extends JpaRepository<MetaVendorCrawlerSensorItem, Long> {
} }

View File

@ -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.central.module.meta.dao.MetaCrawlerInputItemDAO;
import com.loafle.overflow.core.exception.OverflowException; 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.model.meta.MetaCrawlerInputItem;
import com.loafle.overflow.service.central.meta.MetaCrawlerInputItemService; import com.loafle.overflow.service.central.meta.MetaCrawlerInputItemService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -16,10 +15,10 @@ import java.util.List;
@Service("MetaCrawlerInputItemService") @Service("MetaCrawlerInputItemService")
public class CentralMetaCrawlerInputItemService implements MetaCrawlerInputItemService { public class CentralMetaCrawlerInputItemService implements MetaCrawlerInputItemService {
@Autowired @Autowired
private MetaCrawlerInputItemDAO crawlerInputItemDAO; private MetaCrawlerInputItemDAO crawlerInputItemDAO;
public List<MetaCrawlerInputItem> readAllByMetaCrawlerID(Short metaCrawlerID) throws OverflowException { public List<MetaCrawlerInputItem> readAllByMetaCrawlerID(Short metaCrawlerID) throws OverflowException {
return this.crawlerInputItemDAO.findAllByMetaCrawlerId(metaCrawlerID); return this.crawlerInputItemDAO.findAllByMetaCrawlerId(metaCrawlerID);
} }
} }

View File

@ -14,10 +14,10 @@ import java.util.List;
@Service("MetaCrawlerService") @Service("MetaCrawlerService")
public class CentralMetaCrawlerService { public class CentralMetaCrawlerService {
@Autowired @Autowired
private MetaCrawlerDAO crawlerDAO; private MetaCrawlerDAO crawlerDAO;
public List<MetaCrawler> readAll() throws OverflowException { public List<MetaCrawler> readAll() throws OverflowException {
return this.crawlerDAO.findAll(); return this.crawlerDAO.findAll();
} }
} }

View File

@ -16,18 +16,18 @@ import java.util.List;
@Service("MetaHistoryTypeService") @Service("MetaHistoryTypeService")
public class CentralMetaHistoryTypeService implements MetaHistoryTypeService { public class CentralMetaHistoryTypeService implements MetaHistoryTypeService {
@Autowired @Autowired
private MetaHistoryTypeDAO hisotyTypeDAO; private MetaHistoryTypeDAO hisotyTypeDAO;
public List<MetaHistoryType> readAll() throws OverflowException { public List<MetaHistoryType> readAll() throws OverflowException {
return this.hisotyTypeDAO.findAll(); return this.hisotyTypeDAO.findAll();
} }
public MetaHistoryType regist(MetaHistoryType type) throws OverflowException { public MetaHistoryType regist(MetaHistoryType type) throws OverflowException {
return this.hisotyTypeDAO.save(type); return this.hisotyTypeDAO.save(type);
} }
public List<MetaHistoryType> registAll(List<MetaHistoryType> metaHistoryTypes) throws OverflowException { public List<MetaHistoryType> registAll(List<MetaHistoryType> metaHistoryTypes) throws OverflowException {
return (List<MetaHistoryType>)this.hisotyTypeDAO.saveAll(metaHistoryTypes); return (List<MetaHistoryType>) this.hisotyTypeDAO.saveAll(metaHistoryTypes);
} }
} }

View File

@ -16,10 +16,10 @@ import java.util.List;
@Service("MetaInfraTypeService") @Service("MetaInfraTypeService")
public class CentralMetaInfraTypeService implements MetaInfraTypeService { public class CentralMetaInfraTypeService implements MetaInfraTypeService {
@Autowired @Autowired
private MetaInfraTypeDAO infraTypeDAO; private MetaInfraTypeDAO infraTypeDAO;
public List<MetaInfraType> readAll() throws OverflowException { public List<MetaInfraType> readAll() throws OverflowException {
return this.infraTypeDAO.findAll(); return this.infraTypeDAO.findAll();
} }
} }

View File

@ -16,11 +16,11 @@ import java.util.List;
@Service("MetaInfraVendorService") @Service("MetaInfraVendorService")
public class CentralMetaInfraVendorService implements MetaInfraVendorService { public class CentralMetaInfraVendorService implements MetaInfraVendorService {
@Autowired @Autowired
private MetaInfraVendorDAO infraVendorDAO; private MetaInfraVendorDAO infraVendorDAO;
public List<MetaInfraVendor> readAllByMetaInfraTypeID(Integer metaInfraTypeID) throws OverflowException { public List<MetaInfraVendor> readAllByMetaInfraTypeID(Integer metaInfraTypeID) throws OverflowException {
return this.infraVendorDAO.findAllByMetaInfraTypeId(metaInfraTypeID); return this.infraVendorDAO.findAllByMetaInfraTypeId(metaInfraTypeID);
} }
} }

View File

@ -15,10 +15,10 @@ import java.util.List;
@Service("MetaInputTypeService") @Service("MetaInputTypeService")
public class CentralMetaInputTypeService implements MetaInputTypeService { public class CentralMetaInputTypeService implements MetaInputTypeService {
@Autowired @Autowired
private MetaInputTypeDAO inputTypeDAO; private MetaInputTypeDAO inputTypeDAO;
public List<MetaInputType> readAll() throws OverflowException { public List<MetaInputType> readAll() throws OverflowException {
return this.inputTypeDAO.findAll(); return this.inputTypeDAO.findAll();
} }
} }

View File

@ -15,10 +15,10 @@ import java.util.List;
@Service("MetaMemberStatusService") @Service("MetaMemberStatusService")
public class CentralMetaMemberStatusService implements MetaMemberStatusService { public class CentralMetaMemberStatusService implements MetaMemberStatusService {
@Autowired @Autowired
private MetaMemberStatusDAO memberStatusDAO; private MetaMemberStatusDAO memberStatusDAO;
public List<MetaMemberStatus> readAll() throws OverflowException { public List<MetaMemberStatus> readAll() throws OverflowException {
return this.memberStatusDAO.findAll(); return this.memberStatusDAO.findAll();
} }
} }

View File

@ -15,10 +15,10 @@ import java.util.List;
@Service("MetaNoAuthProbeStatusService") @Service("MetaNoAuthProbeStatusService")
public class CentralMetaNoAuthProbeStatusService implements MetaNoAuthProbeStatusService { public class CentralMetaNoAuthProbeStatusService implements MetaNoAuthProbeStatusService {
@Autowired @Autowired
private MetaNoAuthProbeStatusDAO noAuthProbeStatusDAO; private MetaNoAuthProbeStatusDAO noAuthProbeStatusDAO;
public List<MetaNoAuthProbeStatus> readAll() throws OverflowException { public List<MetaNoAuthProbeStatus> readAll() throws OverflowException {
return this.noAuthProbeStatusDAO.findAll(); return this.noAuthProbeStatusDAO.findAll();
} }
} }

View File

@ -15,10 +15,10 @@ import java.util.List;
@Service("MetaProbeArchitectureService") @Service("MetaProbeArchitectureService")
public class CentralMetaProbeArchitectureService implements MetaProbeArchitectureService { public class CentralMetaProbeArchitectureService implements MetaProbeArchitectureService {
@Autowired @Autowired
private MetaProbeArchitectureDAO probeArchitectureDAO; private MetaProbeArchitectureDAO probeArchitectureDAO;
public List<MetaProbeArchitecture> readAll() throws OverflowException { public List<MetaProbeArchitecture> readAll() throws OverflowException {
return this.probeArchitectureDAO.findAll(); return this.probeArchitectureDAO.findAll();
} }
} }

View File

@ -15,10 +15,10 @@ import java.util.List;
@Service("MetaProbeOsService") @Service("MetaProbeOsService")
public class CentralMetaProbeOsService implements MetaProbeOsService { public class CentralMetaProbeOsService implements MetaProbeOsService {
@Autowired @Autowired
private MetaProbeOsDAO probeOsDAO; private MetaProbeOsDAO probeOsDAO;
public List<MetaProbeOs> readAll() throws OverflowException { public List<MetaProbeOs> readAll() throws OverflowException {
return this.probeOsDAO.findAll(); return this.probeOsDAO.findAll();
} }
} }

View File

@ -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.central.module.meta.dao.MetaProbePackageDAO;
import com.loafle.overflow.core.exception.OverflowException; 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.model.meta.MetaProbePackage;
import com.loafle.overflow.service.central.meta.MetaProbePackageService; import com.loafle.overflow.service.central.meta.MetaProbePackageService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -16,10 +15,10 @@ import java.util.List;
@Service("MetaProbePackageService") @Service("MetaProbePackageService")
public class CentralMetaProbePackageService implements MetaProbePackageService { public class CentralMetaProbePackageService implements MetaProbePackageService {
@Autowired @Autowired
private MetaProbePackageDAO probePackageDAO; private MetaProbePackageDAO probePackageDAO;
public List<MetaProbePackage> readAllByMetaProbeOsID(Short metaProbeOsID) throws OverflowException { public List<MetaProbePackage> readAllByMetaProbeOsID(Short metaProbeOsID) throws OverflowException {
return this.probePackageDAO.findAllByMetaProbeOsId(metaProbeOsID); return this.probePackageDAO.findAllByMetaProbeOsId(metaProbeOsID);
} }
} }

View File

@ -15,10 +15,10 @@ import java.util.List;
@Service("MetaProbeStatusService") @Service("MetaProbeStatusService")
public class CentralMetaProbeStatusService implements MetaProbeStatusService { public class CentralMetaProbeStatusService implements MetaProbeStatusService {
@Autowired @Autowired
private MetaProbeStatusDAO probeStatusDAO; private MetaProbeStatusDAO probeStatusDAO;
public List<MetaProbeStatus> readAll() throws OverflowException { public List<MetaProbeStatus> readAll() throws OverflowException {
return this.probeStatusDAO.findAll(); return this.probeStatusDAO.findAll();
} }
} }

View File

@ -16,10 +16,10 @@ import java.util.List;
@Service("MetaProbeTaskTypeService") @Service("MetaProbeTaskTypeService")
public class CentralMetaProbeTaskTypeService implements MetaProbeTaskTypeService { public class CentralMetaProbeTaskTypeService implements MetaProbeTaskTypeService {
@Autowired @Autowired
private MetaProbeTaskTypeDAO probeTaskTypeDAO; private MetaProbeTaskTypeDAO probeTaskTypeDAO;
public List<MetaProbeTaskType> readAll() throws OverflowException { public List<MetaProbeTaskType> readAll() throws OverflowException {
return this.probeTaskTypeDAO.findAll(); return this.probeTaskTypeDAO.findAll();
} }
} }

View File

@ -16,10 +16,10 @@ import java.util.List;
@Service("MetaProbeVersionService") @Service("MetaProbeVersionService")
public class CentralMetaProbeVersionService implements MetaProbeVersionService { public class CentralMetaProbeVersionService implements MetaProbeVersionService {
@Autowired @Autowired
private MetaProbeVersionDAO probeVersionDAO; private MetaProbeVersionDAO probeVersionDAO;
public List<MetaProbeVersion> readAll() throws OverflowException { public List<MetaProbeVersion> readAll() throws OverflowException {
return this.probeVersionDAO.findAll(); return this.probeVersionDAO.findAll();
} }
} }

View File

@ -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.central.module.meta.dao.MetaSensorDisplayItemDAO;
import com.loafle.overflow.core.exception.OverflowException; 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.model.meta.MetaSensorDisplayItem;
import com.loafle.overflow.service.central.meta.MetaSensorDisplayItemService; import com.loafle.overflow.service.central.meta.MetaSensorDisplayItemService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -15,18 +14,18 @@ import java.util.List;
*/ */
@Service("MetaSensorDisplayItemService") @Service("MetaSensorDisplayItemService")
public class CentralMetaSensorDisplayItemService implements MetaSensorDisplayItemService { public class CentralMetaSensorDisplayItemService implements MetaSensorDisplayItemService {
@Autowired @Autowired
private MetaSensorDisplayItemDAO displayItemDAO; private MetaSensorDisplayItemDAO displayItemDAO;
public MetaSensorDisplayItem regist(MetaSensorDisplayItem item) throws OverflowException { public MetaSensorDisplayItem regist(MetaSensorDisplayItem item) throws OverflowException {
return this.displayItemDAO.save(item); return this.displayItemDAO.save(item);
} }
public MetaSensorDisplayItem read(Long id) throws OverflowException { public MetaSensorDisplayItem read(Long id) throws OverflowException {
return this.displayItemDAO.findById(id).get(); return this.displayItemDAO.findById(id).get();
} }
public List<MetaSensorDisplayItem> readAllByCrawlerID(Short metaCrawlerID) throws OverflowException { public List<MetaSensorDisplayItem> readAllByCrawlerID(Short metaCrawlerID) throws OverflowException {
return this.displayItemDAO.findAllByMetaCrawlerId(metaCrawlerID); return this.displayItemDAO.findAllByMetaCrawlerId(metaCrawlerID);
} }
} }

View File

@ -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.central.module.meta.dao.MetaSensorDisplayMappingDAO;
import com.loafle.overflow.core.exception.OverflowException; 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.MetaSensorDisplayMapping;
import com.loafle.overflow.model.meta.MetaSensorItemKey; import com.loafle.overflow.model.meta.MetaSensorItemKey;
import com.loafle.overflow.service.central.meta.MetaSensorDisplayMappingService; import com.loafle.overflow.service.central.meta.MetaSensorDisplayMappingService;
@ -16,14 +15,15 @@ import java.util.List;
*/ */
@Service("MetaSensorDisplayMappingService") @Service("MetaSensorDisplayMappingService")
public class CentralMetaSensorDisplayMappingService implements MetaSensorDisplayMappingService { public class CentralMetaSensorDisplayMappingService implements MetaSensorDisplayMappingService {
@Autowired @Autowired
private MetaSensorDisplayMappingDAO mappingDAO; private MetaSensorDisplayMappingDAO mappingDAO;
public MetaSensorDisplayMapping regist(MetaSensorDisplayMapping m) throws OverflowException { public MetaSensorDisplayMapping regist(MetaSensorDisplayMapping m) throws OverflowException {
return this.mappingDAO.save(m); return this.mappingDAO.save(m);
} }
public List<MetaSensorItemKey> readAllMetaSensorItemKeyByDisplayItemID(Long metaSensorDisplayItemID) throws OverflowException { public List<MetaSensorItemKey> readAllMetaSensorItemKeyByDisplayItemID(Long metaSensorDisplayItemID)
return this.mappingDAO.findAllMetaSensorItemKeyByMetaSensorDisplayItemId(metaSensorDisplayItemID); throws OverflowException {
} return this.mappingDAO.findAllMetaSensorItemKeyByMetaSensorDisplayItemId(metaSensorDisplayItemID);
}
} }

View File

@ -16,18 +16,18 @@ import java.util.List;
@Service("MetaSensorItemTypeService") @Service("MetaSensorItemTypeService")
public class CentralMetaSensorItemTypeService implements MetaSensorItemTypeService { public class CentralMetaSensorItemTypeService implements MetaSensorItemTypeService {
@Autowired @Autowired
private MetaSensorItemTypeDAO sensorItemTypeDAO; private MetaSensorItemTypeDAO sensorItemTypeDAO;
public List<MetaSensorItemType> readAll() throws OverflowException { public List<MetaSensorItemType> readAll() throws OverflowException {
return this.sensorItemTypeDAO.findAll(); return this.sensorItemTypeDAO.findAll();
} }
public MetaSensorItemType regist(MetaSensorItemType type) throws OverflowException { public MetaSensorItemType regist(MetaSensorItemType type) throws OverflowException {
return this.sensorItemTypeDAO.save(type); return this.sensorItemTypeDAO.save(type);
} }
public List<MetaSensorItemType> registAll(List<MetaSensorItemType> list) throws OverflowException { public List<MetaSensorItemType> registAll(List<MetaSensorItemType> list) throws OverflowException {
return (List<MetaSensorItemType>)this.sensorItemTypeDAO.saveAll(list); return (List<MetaSensorItemType>) this.sensorItemTypeDAO.saveAll(list);
} }
} }

View File

@ -13,10 +13,10 @@ import org.springframework.stereotype.Service;
@Service("MetaSensorItemUnitService") @Service("MetaSensorItemUnitService")
public class CentralMetaSensorItemUnitService implements MetaSensorItemUnitService { public class CentralMetaSensorItemUnitService implements MetaSensorItemUnitService {
@Autowired @Autowired
private MetaSensorItemUnitDAO sensorItemUnitDAO; private MetaSensorItemUnitDAO sensorItemUnitDAO;
public MetaSensorItemUnit regist(MetaSensorItemUnit sensorItemUnit) throws OverflowException { public MetaSensorItemUnit regist(MetaSensorItemUnit sensorItemUnit) throws OverflowException {
return this.sensorItemUnitDAO.save(sensorItemUnit); return this.sensorItemUnitDAO.save(sensorItemUnit);
} }
} }

View File

@ -15,10 +15,10 @@ import java.util.List;
@Service("MetaSensorStatusService") @Service("MetaSensorStatusService")
public class CentralMetaSensorStatusService implements MetaSensorStatusService { public class CentralMetaSensorStatusService implements MetaSensorStatusService {
@Autowired @Autowired
private MetaSensorStatusDAO sensorStatusDAO; private MetaSensorStatusDAO sensorStatusDAO;
public List<MetaSensorStatus> readAll() throws OverflowException { public List<MetaSensorStatus> readAll() throws OverflowException {
return this.sensorStatusDAO.findAll(); return this.sensorStatusDAO.findAll();
} }
} }

View File

@ -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.central.module.meta.dao.MetaVendorCrawlerDAO;
import com.loafle.overflow.core.exception.OverflowException; 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.model.meta.MetaVendorCrawler;
import com.loafle.overflow.service.central.meta.MetaVendorCrawlerService; import com.loafle.overflow.service.central.meta.MetaVendorCrawlerService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -17,15 +16,15 @@ import java.util.List;
@Service("MetaVendorCrawlerService") @Service("MetaVendorCrawlerService")
public class CentralMetaVendorCrawlerService implements MetaVendorCrawlerService { public class CentralMetaVendorCrawlerService implements MetaVendorCrawlerService {
@Autowired @Autowired
private MetaVendorCrawlerDAO crawlerDAO; private MetaVendorCrawlerDAO crawlerDAO;
public List<MetaVendorCrawler> readAllByMetaInfraVendorID(Integer metaInfraVendorID) throws OverflowException { public List<MetaVendorCrawler> readAllByMetaInfraVendorID(Integer metaInfraVendorID) throws OverflowException {
return this.crawlerDAO.findAllByMetaInfraVendorId(metaInfraVendorID); return this.crawlerDAO.findAllByMetaInfraVendorId(metaInfraVendorID);
} }
public MetaVendorCrawler regist(MetaVendorCrawler metaVendorCrawler) throws OverflowException { public MetaVendorCrawler regist(MetaVendorCrawler metaVendorCrawler) throws OverflowException {
return this.crawlerDAO.save(metaVendorCrawler); return this.crawlerDAO.save(metaVendorCrawler);
} }
} }

View File

@ -13,16 +13,19 @@ import java.util.List;
@Repository @Repository
public interface NoAuthProbeDAO extends JpaRepository<NoAuthProbe, Long> { public interface NoAuthProbeDAO extends JpaRepository<NoAuthProbe, Long> {
NoAuthProbe findByTempProbeKey(String tempProbeKey); NoAuthProbe findByTempProbeKey(String tempProbeKey);
List<NoAuthProbe> findAllByDomainIdAndMetaNoAuthProbeStatusId(Long domainID, Short metaNoAuthProbeStatusId); List<NoAuthProbe> findAllByDomainIdAndMetaNoAuthProbeStatusId(Long domainID, Short metaNoAuthProbeStatusId);
// NoAuthProbeDeprecate findByTempKey(NoAuthProbeDeprecate noAuthAgent); // NoAuthProbeDeprecate findByTempKey(NoAuthProbeDeprecate noAuthAgent);
// List<NoAuthProbeDeprecate> findAllByNoAuth(NoAuthProbeDeprecate noAuthAgent); // List<NoAuthProbeDeprecate> findAllByNoAuth(NoAuthProbeDeprecate noAuthAgent);
// @Query("SELECT n FROM NoAuthProbe n WHERE n.tempProbeKey = :tempProbeKey") // @Query("SELECT n FROM NoAuthProbe n WHERE n.tempProbeKey = :tempProbeKey")
// @Query("select m from Member m WHERE m.email = :#{#m2.email}") // @Query("select m from Member m WHERE m.email = :#{#m2.email}")
// @Modifying(clearAutomatically = true) // @Modifying(clearAutomatically = true)
// @Query("UPDATE NoAuthProbe n set n.connectDate = :connectDate, n.connectAddress = :connectAddress where n.tempProbeKey = :tempProbeKey") // @Query("UPDATE NoAuthProbe n set n.connectDate = :connectDate,
// int saveConnect(@Param("tempProbeKey") String tempProbeKey, @Param("connectDate") Date connectDate, @Param("connectAddress") String connectAddress); // n.connectAddress = :connectAddress where n.tempProbeKey = :tempProbeKey")
// int saveConnect(@Param("tempProbeKey") String tempProbeKey,
// @Param("connectDate") Date connectDate, @Param("connectAddress") String
// connectAddress);
} }

View File

@ -15,11 +15,11 @@ import java.util.List;
@Repository @Repository
public interface NotificationDAO extends JpaRepository<Notification, Long> { public interface NotificationDAO extends JpaRepository<Notification, Long> {
List<Notification> findAllByMemberEmail(String memberEmail); List<Notification> findAllByMemberEmail(String memberEmail);
Page<Notification> findAllByMemberEmail(String memberEmail, Pageable pageRequest); Page<Notification> findAllByMemberEmail(String memberEmail, Pageable pageRequest);
Page<Notification> findAllByMemberEmailAndConfirmDateNull(String memberEmail, Pageable pageRequest); Page<Notification> findAllByMemberEmailAndConfirmDateNull(String memberEmail, Pageable pageRequest);
Long countByMemberEmailAndConfirmDateNull(String memberEmail); Long countByMemberEmailAndConfirmDateNull(String memberEmail);
} }

View File

@ -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.central.module.notification.dao.NotificationDAO;
import com.loafle.overflow.core.exception.OverflowException; import com.loafle.overflow.core.exception.OverflowException;
import com.loafle.overflow.core.model.PageParams; 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.model.notification.Notification;
import com.loafle.overflow.service.central.notification.NotificationService; import com.loafle.overflow.service.central.notification.NotificationService;
@ -21,51 +20,51 @@ import java.util.List;
@Service("NotificationService") @Service("NotificationService")
public class CentralNotificationService implements NotificationService { public class CentralNotificationService implements NotificationService {
@Autowired @Autowired
private NotificationDAO notificationDAO; private NotificationDAO notificationDAO;
public Notification regist(Notification notification) throws OverflowException { public Notification regist(Notification notification) throws OverflowException {
return this.notificationDAO.save(notification); return this.notificationDAO.save(notification);
} }
public Page<Notification> readAllByMemberEmail(String memberEmail, PageParams pageParams) throws OverflowException { public Page<Notification> readAllByMemberEmail(String memberEmail, PageParams pageParams) throws OverflowException {
return this.notificationDAO.findAllByMemberEmail(memberEmail, PageUtil.getPageRequest(pageParams)); return this.notificationDAO.findAllByMemberEmail(memberEmail, PageUtil.getPageRequest(pageParams));
} }
public Page<Notification> readAllUnconfirmedByMemberEmail(String memberEmail, PageParams pageParams) public Page<Notification> readAllUnconfirmedByMemberEmail(String memberEmail, PageParams pageParams)
throws OverflowException { throws OverflowException {
return this.notificationDAO.findAllByMemberEmailAndConfirmDateNull(memberEmail, return this.notificationDAO.findAllByMemberEmailAndConfirmDateNull(memberEmail,
PageUtil.getPageRequest(pageParams)); PageUtil.getPageRequest(pageParams));
} }
public Long readUnconfirmedCountByMemberEmail(String memberEmail) throws OverflowException { public Long readUnconfirmedCountByMemberEmail(String memberEmail) throws OverflowException {
return this.notificationDAO.countByMemberEmailAndConfirmDateNull(memberEmail); return this.notificationDAO.countByMemberEmailAndConfirmDateNull(memberEmail);
} }
public Page<Notification> markAllAsReadByMemberEmail(String memberEmail, PageParams pageParams) public Page<Notification> markAllAsReadByMemberEmail(String memberEmail, PageParams pageParams)
throws OverflowException { throws OverflowException {
List<Notification> list = this.notificationDAO.findAllByMemberEmail(memberEmail); List<Notification> list = this.notificationDAO.findAllByMemberEmail(memberEmail);
for (Notification n : list) { for (Notification n : list) {
n.setConfirmDate(new Date()); n.setConfirmDate(new Date());
}
this.notificationDAO.saveAll(list);
return this.readAllByMemberEmail(memberEmail, pageParams);
} }
this.notificationDAO.saveAll(list);
return this.readAllByMemberEmail(memberEmail, pageParams);
}
public Page<Notification> markAllAsUnreadMemberEmail(String memberEmail, PageParams pageParams) public Page<Notification> markAllAsUnreadMemberEmail(String memberEmail, PageParams pageParams)
throws OverflowException { throws OverflowException {
List<Notification> list = this.notificationDAO.findAllByMemberEmail(memberEmail); List<Notification> list = this.notificationDAO.findAllByMemberEmail(memberEmail);
for (Notification n : list) { for (Notification n : list) {
n.setConfirmDate(null); n.setConfirmDate(null);
}
this.notificationDAO.saveAll(list);
return this.readAllByMemberEmail(memberEmail, pageParams);
} }
this.notificationDAO.saveAll(list);
return this.readAllByMemberEmail(memberEmail, pageParams);
}
public Notification markAsRead(Long notificationID) throws OverflowException { public Notification markAsRead(Long notificationID) throws OverflowException {
Notification notification = this.notificationDAO.findById(notificationID).get(); Notification notification = this.notificationDAO.findById(notificationID).get();
notification.setConfirmDate(new Date()); notification.setConfirmDate(new Date());
return this.notificationDAO.save(notification); return this.notificationDAO.save(notification);
} }
} }

View File

@ -7,17 +7,19 @@ import org.springframework.stereotype.Repository;
import java.util.List; import java.util.List;
/** /**
* Created by insanity on 17. 5. 29. * Created by insanity on 17. 5. 29.
*/ */
@Repository @Repository
public interface ProbeDAO extends JpaRepository<Probe, Long> { public interface ProbeDAO extends JpaRepository<Probe, Long> {
Probe findByProbeKey(String probeKey); Probe findByProbeKey(String probeKey);
List<Probe> findAllByDomainIdOrderByIdDesc(Long domainID);
// @Modifying(clearAutomatically = true) List<Probe> findAllByDomainIdOrderByIdDesc(Long domainID);
// @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); // @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);
} }

View File

@ -12,7 +12,7 @@ import org.springframework.stereotype.Repository;
*/ */
@Repository @Repository
public interface ProbeHostDAO extends JpaRepository<ProbeHost, Long> { public interface ProbeHostDAO extends JpaRepository<ProbeHost, Long> {
ProbeHost findByProbeId(Long probeID); ProbeHost findByProbeId(Long probeID);
List<ProbeHost> findAllByProbeDomainId(Long domainID); List<ProbeHost> findAllByProbeDomainId(Long domainID);
} }

View File

@ -12,5 +12,5 @@ import com.loafle.overflow.model.probe.ProbeTask;
*/ */
@Repository @Repository
public interface ProbeTaskDAO extends JpaRepository<ProbeTask, Long> { public interface ProbeTaskDAO extends JpaRepository<ProbeTask, Long> {
List<ProbeTask> findAllByProbeId(Long probeId); List<ProbeTask> findAllByProbeId(Long probeId);
} }

View File

@ -16,22 +16,22 @@ import org.springframework.stereotype.Service;
@Service("ProbeHostService") @Service("ProbeHostService")
public class CentralProbeHostService implements ProbeHostService { public class CentralProbeHostService implements ProbeHostService {
@Autowired @Autowired
private ProbeHostDAO probeHostDAO; private ProbeHostDAO probeHostDAO;
public ProbeHost read(Long id) throws OverflowException { public ProbeHost read(Long id) throws OverflowException {
return this.probeHostDAO.findById(id).get(); return this.probeHostDAO.findById(id).get();
} }
public ProbeHost readByProbeID(Long probeID) throws OverflowException { public ProbeHost readByProbeID(Long probeID) throws OverflowException {
return this.probeHostDAO.findByProbeId(probeID); return this.probeHostDAO.findByProbeId(probeID);
} }
public ProbeHost regist(ProbeHost probeHost) throws OverflowException { public ProbeHost regist(ProbeHost probeHost) throws OverflowException {
return this.probeHostDAO.save(probeHost); return this.probeHostDAO.save(probeHost);
} }
public List<ProbeHost> readAllByDomainID(Long domainID) throws OverflowException { public List<ProbeHost> readAllByDomainID(Long domainID) throws OverflowException {
return this.probeHostDAO.findAllByProbeDomainId(domainID); return this.probeHostDAO.findAllByProbeDomainId(domainID);
} }
} }

View File

@ -18,77 +18,77 @@ import java.util.List;
@Service("ProbeService") @Service("ProbeService")
public class CentralProbeService implements ProbeService { public class CentralProbeService implements ProbeService {
@Autowired @Autowired
private ProbeDAO probeDAO; private ProbeDAO probeDAO;
@Autowired @Autowired
private MessagePublisher messagePublisher; private MessagePublisher messagePublisher;
public Probe regist(Probe probe) throws OverflowException { public Probe regist(Probe probe) throws OverflowException {
return this.probeDAO.save(probe); return this.probeDAO.save(probe);
}
public List<Probe> regist(List<Probe> probes) throws OverflowException {
return (List<Probe>) this.probeDAO.saveAll(probes);
}
public List<Probe> readAllByDomainID(Long domainID) throws OverflowException {
List<Probe> 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<Probe> regist(List<Probe> probes) throws OverflowException { public Probe modifyDisplayName(Long probeId, String displayName) {
return (List<Probe>)this.probeDAO.saveAll(probes); Probe probe = this.probeDAO.findById(probeId).get();
} probe.setDisplayName(displayName);
return this.probeDAO.save(probe);
}
public List<Probe> readAllByDomainID(Long domainID) throws OverflowException { public void onConnect(String probeKey, String connectAddress) throws OverflowException {
List<Probe> probes = this.probeDAO.findAllByDomainIdOrderByIdDesc(domainID); Probe probe = this.probeDAO.findByProbeKey(probeKey);
return probes; probe.setConnectDate(new Date());
} probe.setConnectAddress(connectAddress);
probe = this.probeDAO.save(probe);
public Probe read(Long id) throws OverflowException { messagePublisher.publishToDomainMembers(probe.getDomain().getId(), "ProbeService.onConnect", probe);
return this.probeDAO.findById(id).get(); }
}
public Probe readByProbeKey(String probeKey) throws OverflowException { public void onDisconnect(String probeKey) throws OverflowException {
return this.probeDAO.findByProbeKey(probeKey); Probe probe = this.probeDAO.findByProbeKey(probeKey);
} probe.setConnectDate(null);
probe.setConnectAddress(null);
probe = this.probeDAO.save(probe);
public Probe modify(Probe probe) throws OverflowException { messagePublisher.publishToDomainMembers(probe.getDomain().getId(), "ProbeService.onDisconnect", probe);
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);
}
} }

View File

@ -14,16 +14,16 @@ import java.util.List;
* Created by snoop on 17. 6. 28. * Created by snoop on 17. 6. 28.
*/ */
@Service("ProbeTaskService") @Service("ProbeTaskService")
public class CentralProbeTaskService implements ProbeTaskService{ public class CentralProbeTaskService implements ProbeTaskService {
@Autowired @Autowired
private ProbeTaskDAO probeTaskDAO; private ProbeTaskDAO probeTaskDAO;
public ProbeTask regist(ProbeTask probeTask) throws OverflowException { public ProbeTask regist(ProbeTask probeTask) throws OverflowException {
return this.probeTaskDAO.save(probeTask); return this.probeTaskDAO.save(probeTask);
} }
public List<ProbeTask> readAllByProbeID(Long probeID) throws OverflowException { public List<ProbeTask> readAllByProbeID(Long probeID) throws OverflowException {
return this.probeTaskDAO.findAllByProbeId(probeID); return this.probeTaskDAO.findAllByProbeId(probeID);
} }
} }

View File

@ -15,9 +15,9 @@ import com.loafle.overflow.model.target.Target;
*/ */
@Repository @Repository
public interface SensorDAO extends JpaRepository<Sensor, Long> { public interface SensorDAO extends JpaRepository<Sensor, Long> {
Page<Sensor> findAllByTargetId(Long targetID, Pageable pageable); Page<Sensor> findAllByTargetId(Long targetID, Pageable pageable);
List<Sensor> findAllByTargetId(Long targetID); List<Sensor> findAllByTargetId(Long targetID);
Page<Sensor> findAllByTargetIn(List<Target> targets, Pageable pageable); Page<Sensor> findAllByTargetIn(List<Target> targets, Pageable pageable);
} }

View File

@ -12,5 +12,5 @@ import org.springframework.stereotype.Repository;
*/ */
@Repository @Repository
public interface SensorItemDAO extends JpaRepository<SensorItem, Long> { public interface SensorItemDAO extends JpaRepository<SensorItem, Long> {
Page<SensorItem> findAllBySensorId(Long sensorId, Pageable pageable); Page<SensorItem> findAllBySensorId(Long sensorId, Pageable pageable);
} }

View File

@ -16,6 +16,7 @@ import java.util.List;
@Repository @Repository
public interface SensorItemDependencyDAO extends JpaRepository<SensorItemDependency, Long> { public interface SensorItemDependencyDAO extends JpaRepository<SensorItemDependency, Long> {
@Query("SELECT s.metaSensorItemKey from SensorItemDependency s where s.metaSensorDisplayItem.id = :metaSensorDisplayItemId") @Query("SELECT s.metaSensorItemKey from SensorItemDependency s where s.metaSensorDisplayItem.id = :metaSensorDisplayItemId")
List<MetaSensorItemKey> findAllMetaSensorItemKeyByMetaSensorDisplayItemId(@Param("metaSensorDisplayItemId") Long metaSensorDisplayItemId); List<MetaSensorItemKey> findAllMetaSensorItemKeyByMetaSensorDisplayItemId(
@Param("metaSensorDisplayItemId") Long metaSensorDisplayItemId);
} }

View File

@ -21,29 +21,29 @@ import java.util.Map;
@Service("SensorItemDependencyService") @Service("SensorItemDependencyService")
public class CentralSensorItemDependencyService implements SensorItemDependencyService { public class CentralSensorItemDependencyService implements SensorItemDependencyService {
@Autowired @Autowired
private SensorItemDependencyDAO sensorItemDependencyDAO; private SensorItemDependencyDAO sensorItemDependencyDAO;
public SensorItemDependency regist(SensorItemDependency dependency) throws OverflowException { public SensorItemDependency regist(SensorItemDependency dependency) throws OverflowException {
return this.sensorItemDependencyDAO.save(dependency); return this.sensorItemDependencyDAO.save(dependency);
}
public List<MetaSensorItemKey> readAllMetaSensorItemKeyByMetaSensorDisplayItemID(Long metaSensorDisplayItemID)
throws OverflowException {
return this.sensorItemDependencyDAO.findAllMetaSensorItemKeyByMetaSensorDisplayItemId(metaSensorDisplayItemID);
}
public Map<String, List<MetaSensorItemKey>> readAllMapByMetaSensorDisplayItems(
List<MetaSensorDisplayItem> metaSensorDisplayItems) throws OverflowException {
Map<String, List<MetaSensorItemKey>> map = new HashMap<String, List<MetaSensorItemKey>>();
for (MetaSensorDisplayItem displayItem : metaSensorDisplayItems) {
List<MetaSensorItemKey> itemKeys = this.sensorItemDependencyDAO
.findAllMetaSensorItemKeyByMetaSensorDisplayItemId(displayItem.getId());
map.put(displayItem.getKey(), itemKeys);
} }
public List<MetaSensorItemKey> readAllMetaSensorItemKeyByMetaSensorDisplayItemID(Long metaSensorDisplayItemID) return map;
throws OverflowException { }
return this.sensorItemDependencyDAO.findAllMetaSensorItemKeyByMetaSensorDisplayItemId(metaSensorDisplayItemID);
}
public Map<String, List<MetaSensorItemKey>> readAllMapByMetaSensorDisplayItems(
List<MetaSensorDisplayItem> metaSensorDisplayItems) throws OverflowException {
Map<String, List<MetaSensorItemKey>> map = new HashMap<String, List<MetaSensorItemKey>>();
for (MetaSensorDisplayItem displayItem : metaSensorDisplayItems) {
List<MetaSensorItemKey> itemKeys = this.sensorItemDependencyDAO
.findAllMetaSensorItemKeyByMetaSensorDisplayItemId(displayItem.getId());
map.put(displayItem.getKey(), itemKeys);
}
return map;
}
} }

View File

@ -22,41 +22,41 @@ import java.util.List;
@Service("SensorItemService") @Service("SensorItemService")
public class CentralSensorItemService implements SensorItemService { public class CentralSensorItemService implements SensorItemService {
@Autowired @Autowired
private SensorItemDAO sensorItemDAO; private SensorItemDAO sensorItemDAO;
@Autowired @Autowired
private SensorDAO sensorDAO; private SensorDAO sensorDAO;
@Transactional @Transactional
public SensorItem regist(SensorItem sensorItem) throws OverflowException { public SensorItem regist(SensorItem sensorItem) throws OverflowException {
Sensor s = sensorDAO.findById(sensorItem.getSensor().getId()).get(); Sensor s = sensorDAO.findById(sensorItem.getSensor().getId()).get();
s.setItemCount((short) (s.getItemCount() + 1)); s.setItemCount((short) (s.getItemCount() + 1));
this.sensorDAO.save(s); this.sensorDAO.save(s);
return this.sensorItemDAO.save(sensorItem); return this.sensorItemDAO.save(sensorItem);
} }
@Transactional @Transactional
public boolean registAll(List<SensorItem> sensorItemList) throws OverflowException { public boolean registAll(List<SensorItem> sensorItemList) throws OverflowException {
Sensor s = sensorDAO.findById(sensorItemList.get(0).getSensor().getId()).get(); Sensor s = sensorDAO.findById(sensorItemList.get(0).getSensor().getId()).get();
s.setItemCount((short) sensorItemList.size()); s.setItemCount((short) sensorItemList.size());
this.sensorDAO.save(s); this.sensorDAO.save(s);
this.sensorItemDAO.saveAll(sensorItemList); this.sensorItemDAO.saveAll(sensorItemList);
return true; return true;
} }
public SensorItem read(String id) throws OverflowException { public SensorItem read(String id) throws OverflowException {
return this.sensorItemDAO.findById(Long.valueOf(id)).get(); return this.sensorItemDAO.findById(Long.valueOf(id)).get();
} }
public Page<SensorItem> readAllBySensorID(Long sensorID, PageParams pageParams) throws OverflowException { public Page<SensorItem> readAllBySensorID(Long sensorID, PageParams pageParams) throws OverflowException {
return this.sensorItemDAO.findAllBySensorId(sensorID, PageUtil.getPageRequest(pageParams)); return this.sensorItemDAO.findAllBySensorId(sensorID, PageUtil.getPageRequest(pageParams));
} }
@Transactional @Transactional
public void remove(SensorItem sensorItem) throws OverflowException { public void remove(SensorItem sensorItem) throws OverflowException {
Sensor s = sensorItem.getSensor(); Sensor s = sensorItem.getSensor();
s.setItemCount((short) (s.getItemCount() - 1)); s.setItemCount((short) (s.getItemCount() - 1));
this.sensorDAO.save(s); this.sensorDAO.save(s);
this.sensorItemDAO.delete(sensorItem); this.sensorItemDAO.delete(sensorItem);
} }
} }

View File

@ -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.central.module.sensor.dao.SensorDAO;
import com.loafle.overflow.core.exception.OverflowException; import com.loafle.overflow.core.exception.OverflowException;
import com.loafle.overflow.core.model.PageParams; 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.meta.MetaSensorStatus;
import com.loafle.overflow.model.probe.Probe; import com.loafle.overflow.model.probe.Probe;
import com.loafle.overflow.model.sensor.Sensor; import com.loafle.overflow.model.sensor.Sensor;
@ -31,109 +29,112 @@ import java.util.List;
@Service("SensorService") @Service("SensorService")
public class CentralSensorService implements SensorService { public class CentralSensorService implements SensorService {
@Autowired @Autowired
SensorDAO sensorDAO; SensorDAO sensorDAO;
@Autowired @Autowired
private ProbeService probeService; private ProbeService probeService;
@Autowired @Autowired
private InfraService infraService; private InfraService infraService;
@Autowired @Autowired
private SensorItemService sensorItemService; private SensorItemService sensorItemService;
@Autowired @Autowired
private SensorConfigGenerator sensorConfigGenerator; private SensorConfigGenerator sensorConfigGenerator;
@Autowired @Autowired
private TargetService targetService; private TargetService targetService;
@Transactional @Transactional
public Sensor regist(Sensor sensor) throws OverflowException { public Sensor regist(Sensor sensor) throws OverflowException {
this.targetService.increaseSensorCount(sensor.getTarget()); this.targetService.increaseSensorCount(sensor.getTarget());
return this.sensorDAO.save(sensor); return this.sensorDAO.save(sensor);
}
public Page<Sensor> readAllByDomainID(Long domainID, PageParams pageParams) throws OverflowException {
List<Probe> probeList = this.probeService.readAllByDomainID(domainID);
if (probeList == null || probeList.size() <= 0) {
throw new OverflowException("", new Throwable());
} }
public Page<Sensor> readAllByDomainID(Long domainID, PageParams pageParams) throws OverflowException { List<Target> targetList = this.infraService.readAllTargetByProbes(probeList);
List<Probe> probeList = this.probeService.readAllByDomainID(domainID); if (targetList == null || targetList.size() <= 0) {
throw new OverflowException("", new Throwable());
if (probeList == null || probeList.size() <= 0) {
throw new OverflowException("", new Throwable());
}
List<Target> targetList = this.infraService.readAllTargetByProbes(probeList);
if (targetList == null || targetList.size() <= 0) {
throw new OverflowException("", new Throwable());
}
return this.sensorDAO.findAllByTargetIn(targetList, PageUtil.getPageRequest(pageParams));
} }
public Page<Sensor> readAllByInfraID(Long infraID, PageParams pageParams) throws OverflowException { return this.sensorDAO.findAllByTargetIn(targetList, PageUtil.getPageRequest(pageParams));
// Infra dbInfra = this.infraService.read(infraID); }
// if (dbInfra == null) {
// throw new OverflowException("", new Throwable()); public Page<Sensor> readAllByInfraID(Long infraID, PageParams pageParams) throws OverflowException {
// } // Infra dbInfra = this.infraService.read(infraID);
// return this.sensorDAO.findAllByTargetId(dbInfra.getTarget().getId(), PageUtil.getPageRequest(pageParams)); // if (dbInfra == null) {
return null; // throw new OverflowException("", new Throwable());
// }
// return this.sensorDAO.findAllByTargetId(dbInfra.getTarget().getId(),
// PageUtil.getPageRequest(pageParams));
return null;
}
public Page<Sensor> 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<SensorItem> sensorItemList, String etcJson)
throws OverflowException {
this.targetService.increaseSensorCount(sensor.getTarget());
this.sensorDAO.save(sensor);
for (SensorItem sensorItem : sensorItemList) {
sensorItem.setSensor(sensor);
} }
public Page<Sensor> readAllByTargetID(Long targetID, PageParams pageParams) throws OverflowException { this.sensorItemService.registAll(sensorItemList);
return this.sensorDAO.findAllByTargetId(targetID, PageUtil.getPageRequest(pageParams));
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 { // public List<Sensor> readAllByTarget(Target target, PageParams pageParams) {
return this.sensorDAO.findById(Long.valueOf(id)).get(); // return this.sensorDAO.findAllByTarget(target,
} // PageUtil.getPageRequest(pageParams));
// }
@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<SensorItem> 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<Sensor> readAllByTarget(Target target, PageParams pageParams) {
// return this.sensorDAO.findAllByTarget(target, PageUtil.getPageRequest(pageParams));
// }
} }

View File

@ -13,8 +13,9 @@ import org.springframework.stereotype.Repository;
public interface TargetDAO extends JpaRepository<Target, Long> { public interface TargetDAO extends JpaRepository<Target, Long> {
Target findByInfraId(Long infraId); Target findByInfraId(Long infraId);
// @Query("select t.infra from target t where t.infra.probe.id = :probeId") // @Query("select t.infra from target t where t.infra.probe.id = :probeId")
// Page<Target> findForProbeId(@Param("probeId") Long probeId, Pageable pageRequest); // Page<Target> findForProbeId(@Param("probeId") Long probeId, Pageable
// pageRequest);
Page<Target> findAllByInfraProbeId(Long probeId, Pageable pageRequest); Page<Target> findAllByInfraProbeId(Long probeId, Pageable pageRequest);
} }

View File

@ -19,208 +19,219 @@
// import java.util.List; // import java.util.List;
// /** // /**
// * Created by snoop on 17. 6. 28. // * Created by snoop on 17. 6. 28.
// */ // */
// @Service("TargetDiscoveryService") // @Service("TargetDiscoveryService")
// public class CentralTargetDiscoveryService implements TargetDiscoveryService { // public class CentralTargetDiscoveryService implements TargetDiscoveryService
// {
// @Autowired // @Autowired
// private TargetService targetService; // private TargetService targetService;
// @Autowired // @Autowired
// private CentralInfraMachineService infraMachineService; // private CentralInfraMachineService infraMachineService;
// @Autowired // @Autowired
// private CentralInfraOSService infraOSService; // private CentralInfraOSService infraOSService;
// @Autowired // @Autowired
// private CentralInfraHostService infraHostService; // private CentralInfraHostService infraHostService;
// // @Autowired // // @Autowired
// // private CentralInfraService infraService; // // private CentralInfraService infraService;
// @Autowired // @Autowired
// private CentralInfraOSPortService infraOSPortService; // private CentralInfraOSPortService infraOSPortService;
// @Autowired // @Autowired
// private CentralInfraServiceService infraServiceService; // private CentralInfraServiceService infraServiceService;
// @Transactional // @Transactional
// public boolean saveAllTarget(List<Host> hosts, Probe probe) throws OverflowException { // public boolean saveAllTarget(List<Host> 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); // this.createPort(infraHost, host, probe);
// } // }
// return true; // return true;
// } // }
// private void createService(InfraHost infraHost, Port port, Probe probe) throws OverflowException { // private void createService(InfraHost infraHost, Port port, Probe probe)
// throws OverflowException {
// MetaInfraType typeService = new MetaInfraType(7);
// MetaInfraType typeService = new MetaInfraType(7);
// String portType = "UDP";
// String portType = "UDP";
// if (port.getPortType() == PortType.TLS || port.getPortType() == PortType.TCP || port.getPortType() == null) {
// portType = "TCP"; // if (port.getPortType() == PortType.TLS || port.getPortType() == PortType.TCP
// } // || port.getPortType() == null) {
// portType = "TCP";
// if (port.getServiceList() == null) { // }
// return;
// } // if (port.getServiceList() == null) {
// return;
// // for(String key : port.getServices().keySet()) { // }
// for (com.loafle.overflow.model.discovery.Service service : port.getServiceList()) {
// // for(String key : port.getServices().keySet()) {
// // com.loafle.overflow.module.discovery.model.Service service = // for (com.loafle.overflow.model.discovery.Service service :
// // port.getServices().get(key); // port.getServiceList()) {
// InfraService dbInfraService = this.infraServiceService // // com.loafle.overflow.module.discovery.model.Service service =
// .readByInfraHostIDAndPortAndPortType(infraHost.getId(), port.getPortNumber(), portType); // // port.getServices().get(key);
// if (dbInfraService != null) { // InfraService dbInfraService = this.infraServiceService
// if (service.isTarget() && dbInfraService.getTarget() == null) { // .readByInfraHostIDAndPortAndPortType(infraHost.getId(), port.getPortNumber(),
// Target targetService = new Target(); // portType);
// targetService.setDisplayName(service.getServiceName());
// this.targetService.regist(targetService, probe); // if (dbInfraService != null) {
// dbInfraService.setTarget(targetService); // if (service.isTarget() && dbInfraService.getTarget() == null) {
// this.infraServiceService.regist(dbInfraService); // Target targetService = new Target();
// } // targetService.setDisplayName(service.getServiceName());
// continue; // this.targetService.regist(targetService, probe);
// } // dbInfraService.setTarget(targetService);
// this.infraServiceService.regist(dbInfraService);
// InfraService infraService = new InfraService(); // }
// infraService.setInfraHost(infraHost); // continue;
// infraService.setPort(port.getPortNumber()); // }
// infraService.setPortType(portType);
// infraService.setMetaInfraType(typeService); // InfraService infraService = new InfraService();
// infraService.setProbe(probe); // infraService.setInfraHost(infraHost);
// infraService.setPort(port.getPortNumber());
// if (port.getPortType() == PortType.TLS) { // infraService.setPortType(portType);
// infraService.setTlsType(true); // infraService.setMetaInfraType(typeService);
// } // infraService.setProbe(probe);
// infraService.setMetaInfraVendor(MetaInfraVendor.CreateInfraVendorByService(service.getServiceName()));
// if (port.getPortType() == PortType.TLS) {
// if (service.isTarget()) { // infraService.setTlsType(true);
// Target targetService = new Target(); // }
// targetService.setDisplayName(service.getServiceName()); // infraService.setMetaInfraVendor(MetaInfraVendor.CreateInfraVendorByService(service.getServiceName()));
// this.targetService.regist(targetService, probe);
// infraService.setTarget(targetService); // if (service.isTarget()) {
// } // Target targetService = new Target();
// targetService.setDisplayName(service.getServiceName());
// this.infraServiceService.regist(infraService); // 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;
// // } // private void createPort(InfraHost infraHost, Host host, Probe probe) throws
// OverflowException {
// String portType = "UDP";
// // if(host.getPorts() == null) {
// MetaInfraType typePort = new MetaInfraType(6); // // return;
// // }
// InfraOS infraOS = infraHost.getInfraOS();
// String portType = "UDP";
// // for( String key: host.getPorts().keySet()) {
// MetaInfraType typePort = new MetaInfraType(6);
// if (host.getPortList() == null) {
// return; // InfraOS infraOS = infraHost.getInfraOS();
// }
// // for( String key: host.getPorts().keySet()) {
// for (Port port : host.getPortList()) {
// // Port port = host.getPorts().get(key); // if (host.getPortList() == null) {
// return;
// if (port.getPortType() == PortType.TLS || port.getPortType() == PortType.TCP) { // }
// portType = "TCP";
// } // for (Port port : host.getPortList()) {
// // Port port = host.getPorts().get(key);
// InfraOSPort dbInfraOSPort = this.infraOSPortService.readByInfraOSIDAndPortAndPortType(infraOS.getId(), port.getPortNumber(),
// portType); // if (port.getPortType() == PortType.TLS || port.getPortType() == PortType.TCP)
// if (dbInfraOSPort == null) { // {
// InfraOSPort infraOSPort = new InfraOSPort(); // portType = "TCP";
// infraOSPort.setInfraOS(infraOS); // }
// infraOSPort.setPort(port.getPortNumber());
// infraOSPort.setPortType(portType); // InfraOSPort dbInfraOSPort =
// infraOSPort.setProbe(probe); // this.infraOSPortService.readByInfraOSIDAndPortAndPortType(infraOS.getId(),
// infraOSPort.setMetaInfraType(typePort); // port.getPortNumber(),
// portType);
// if (port.getPortType() == PortType.TLS) { // if (dbInfraOSPort == null) {
// infraOSPort.setTlsType(true); // InfraOSPort infraOSPort = new InfraOSPort();
// } // infraOSPort.setInfraOS(infraOS);
// infraOSPort.setMetaInfraVendor(MetaInfraVendor.CreateInfraVendorByPort(port.getPortNumber())); // infraOSPort.setPort(port.getPortNumber());
// this.infraOSPortService.regist(infraOSPort); // infraOSPort.setPortType(portType);
// } // infraOSPort.setProbe(probe);
// infraOSPort.setMetaInfraType(typePort);
// this.createService(infraHost, port, probe);
// } // if (port.getPortType() == PortType.TLS) {
// } // infraOSPort.setTlsType(true);
// }
// private InfraHost createAndReadHost(Host host, Probe probe) throws OverflowException { // infraOSPort.setMetaInfraVendor(MetaInfraVendor.CreateInfraVendorByPort(port.getPortNumber()));
// this.infraOSPortService.regist(infraOSPort);
// InfraHost infraHost = this.infraHostService.readByIp(host.getIpv4()); // }
// if (infraHost != null) {
// this.createService(infraHost, port, probe);
// if (host.isTarget() && infraHost.getTarget() == null) { // }
// Target target = new Target(); // }
// target.setDisplayName(host.getIpv4() + "-Host");
// private InfraHost createAndReadHost(Host host, Probe probe) throws
// this.targetService.regist(target, probe); // OverflowException {
// infraHost.setTarget(target);
// this.infraHostService.regist(infraHost); // InfraHost infraHost = this.infraHostService.readByIp(host.getIpv4());
// } // if (infraHost != null) {
// return infraHost; // if (host.isTarget() && infraHost.getTarget() == null) {
// } else { // Target target = new Target();
// MetaInfraType typeMachine = new MetaInfraType(1); // 1 = Machine; // target.setDisplayName(host.getIpv4() + "-Host");
// MetaInfraType typeOS = new MetaInfraType(3);// 3 = Os // this.targetService.regist(target, probe);
// infraHost.setTarget(target);
// MetaInfraType typeHost = new MetaInfraType(2); // 2 = Host // this.infraHostService.regist(infraHost);
// }
// InfraMachine infraMachine = new InfraMachine();
// infraMachine.setProbe(probe); // return infraHost;
// infraMachine.setMetaInfraType(typeMachine); // } else {
// infraMachine.setMeta(host.getIpv4() + "-MACHINE"); // MetaInfraType typeMachine = new MetaInfraType(1); // 1 = Machine;
// this.infraMachineService.regist(infraMachine);
// MetaInfraType typeOS = new MetaInfraType(3);// 3 = Os
// InfraOS infraOS = new InfraOS();
// infraOS.setInfraMachine(infraMachine); // MetaInfraType typeHost = new MetaInfraType(2); // 2 = Host
// infraOS.setMetaInfraVendor(MetaInfraVendor.CreateInfraVendorByOS(host.getOs()));
// infraOS.setMetaInfraType(typeOS); // InfraMachine infraMachine = new InfraMachine();
// infraOS.setProbe(probe); // infraMachine.setProbe(probe);
// infraOS.setMeta(host.getIpv4() + "-OS"); // infraMachine.setMetaInfraType(typeMachine);
// this.infraOSService.regist(infraOS); // infraMachine.setMeta(host.getIpv4() + "-MACHINE");
// this.infraMachineService.regist(infraMachine);
// InfraHost newInfraHost = new InfraHost();
// newInfraHost.setIpv4(host.getIpv4()); // InfraOS infraOS = new InfraOS();
// newInfraHost.setMac(host.getMac()); // infraOS.setInfraMachine(infraMachine);
// newInfraHost.setInfraOS(infraOS); // infraOS.setMetaInfraVendor(MetaInfraVendor.CreateInfraVendorByOS(host.getOs()));
// newInfraHost.setMetaInfraType(typeHost); // infraOS.setMetaInfraType(typeOS);
// newInfraHost.setProbe(probe); // infraOS.setProbe(probe);
// infraOS.setMeta(host.getIpv4() + "-OS");
// if (host.isTarget()) { // this.infraOSService.regist(infraOS);
// Target target = new Target();
// target.setDisplayName(host.getIpv4() + "-Host"); // InfraHost newInfraHost = new InfraHost();
// newInfraHost.setIpv4(host.getIpv4());
// this.targetService.regist(target, probe); // newInfraHost.setMac(host.getMac());
// newInfraHost.setTarget(target); // newInfraHost.setInfraOS(infraOS);
// } // newInfraHost.setMetaInfraType(typeHost);
// newInfraHost.setProbe(probe);
// this.infraHostService.regist(newInfraHost);
// infraHost = newInfraHost; // if (host.isTarget()) {
// } // Target target = new Target();
// target.setDisplayName(host.getIpv4() + "-Host");
// return infraHost;
// } // this.targetService.regist(target, probe);
// newInfraHost.setTarget(target);
// }
// this.infraHostService.regist(newInfraHost);
// infraHost = newInfraHost;
// }
// return infraHost;
// }
// } // }

View File

@ -31,148 +31,150 @@ import org.springframework.transaction.annotation.Transactional;
@org.springframework.stereotype.Service("TargetService") @org.springframework.stereotype.Service("TargetService")
public class CentralTargetService implements TargetService { public class CentralTargetService implements TargetService {
@Autowired @Autowired
private TargetDAO targetDAO; private TargetDAO targetDAO;
@Autowired @Autowired
private CentralProbeService probeService; private CentralProbeService probeService;
@Autowired @Autowired
private CentralInfraHostService infraHostService; private CentralInfraHostService infraHostService;
@Autowired @Autowired
private CentralInfraServiceService infraServiceService; private CentralInfraServiceService infraServiceService;
@Transactional @Transactional
public Target regist(Target target, Probe probe) throws OverflowException { public Target regist(Target target, Probe probe) throws OverflowException {
this.probeService.increaseTargetCount(probe); this.probeService.increaseTargetCount(probe);
return this.targetDAO.save(target); return this.targetDAO.save(target);
} }
@Transactional @Transactional
public void remove(Target target, Probe probe) throws OverflowException { public void remove(Target target, Probe probe) throws OverflowException {
this.probeService.decreaseTargetCount(probe); this.probeService.decreaseTargetCount(probe);
this.targetDAO.delete(target); this.targetDAO.delete(target);
} }
public Target read(String id) throws OverflowException { public Target read(String id) throws OverflowException {
return this.targetDAO.findById(Long.valueOf(id)).get(); return this.targetDAO.findById(Long.valueOf(id)).get();
} }
public Target modify(Target target) throws OverflowException { public Target modify(Target target) throws OverflowException {
return this.targetDAO.save(target); return this.targetDAO.save(target);
} }
@Deprecated @Deprecated
public Target regist(Target target) throws OverflowException { public Target regist(Target target) throws OverflowException {
return this.targetDAO.save(target); return this.targetDAO.save(target);
} }
@Deprecated @Deprecated
public void remove(Target target) throws OverflowException { public void remove(Target target) throws OverflowException {
this.targetDAO.delete(target); this.targetDAO.delete(target);
} }
public Target increaseSensorCount(Target target) throws OverflowException { public Target increaseSensorCount(Target target) throws OverflowException {
Target t = this.targetDAO.findById(target.getId()).get(); Target t = this.targetDAO.findById(target.getId()).get();
t.setSensorCount(t.getSensorCount() + 1); t.setSensorCount(t.getSensorCount() + 1);
return this.targetDAO.save(t); return this.targetDAO.save(t);
} }
public Target decreaseSensorCount(Target target) throws OverflowException { public Target decreaseSensorCount(Target target) throws OverflowException {
Target t = this.targetDAO.findById(target.getId()).get(); Target t = this.targetDAO.findById(target.getId()).get();
int count = t.getSensorCount(); int count = t.getSensorCount();
if (t.getSensorCount() > 0) { if (t.getSensorCount() > 0) {
t.setSensorCount(count - 1); t.setSensorCount(count - 1);
}
return this.targetDAO.save(t);
} }
return this.targetDAO.save(t);
}
public Target readExistHostTarget(Long probeId, String ip) throws OverflowException { public Target readExistHostTarget(Long probeId, String ip) throws OverflowException {
InfraHost infraHost = this.infraHostService.readByProbeIdAndIpv4(probeId, ip); InfraHost infraHost = this.infraHostService.readByProbeIdAndIpv4(probeId, ip);
if (null == infraHost) if (null == infraHost)
return null; return null;
return this.targetDAO.findByInfraId(infraHost.getId()); return this.targetDAO.findByInfraId(infraHost.getId());
} }
public Target readExistServiceTarget(Long hostId, int portNumber, String portType) throws OverflowException { public Target readExistServiceTarget(Long hostId, int portNumber, String portType) throws OverflowException {
InfraService infraService = this.infraServiceService.readByInfraHostIDAndPortAndPortType(hostId, portNumber, InfraService infraService = this.infraServiceService.readByInfraHostIDAndPortAndPortType(hostId, portNumber,
portType); portType);
if (null == infraService) if (null == infraService)
return null; return null;
return this.targetDAO.findByInfraId(infraService.getId()); return this.targetDAO.findByInfraId(infraService.getId());
} }
public Page<Target> readAllByProbeID(Long probeID, PageParams pageParams) throws OverflowException { public Page<Target> readAllByProbeID(Long probeID, PageParams pageParams) throws OverflowException {
return this.targetDAO.findAllByInfraProbeId(probeID, PageUtil.getPageRequest(pageParams)); return this.targetDAO.findAllByInfraProbeId(probeID, PageUtil.getPageRequest(pageParams));
// return null; // return null;
} }
@Transactional
public List<Target> registDiscoveredTargets(Long probeId, List<Host> hosts, List<Service> services)
throws OverflowException {
List<Target> targets = new ArrayList<Target>();
targets.addAll(registDiscoveredHostTargets(probeId, hosts));
targets.addAll(this.registDiscoveredServiceTargets(probeId, services));
return targets;
}
private List<Target> registDiscoveredHostTargets(Long probeId, List<Host> hosts) throws OverflowException { @Transactional
List<Target> targets = new ArrayList<>(); public List<Target> registDiscoveredTargets(Long probeId, List<Host> hosts, List<Service> services)
if (null == hosts) throws OverflowException {
return targets; List<Target> targets = new ArrayList<Target>();
for (Host host : hosts) { targets.addAll(registDiscoveredHostTargets(probeId, hosts));
InfraHost infraHost = this.registInfraHostByDiscoveredHost(host, probeId); targets.addAll(this.registDiscoveredServiceTargets(probeId, services));
Target target = new Target(); return targets;
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 List<Target> registDiscoveredServiceTargets(Long probeId, List<Service> services) throws OverflowException { private List<Target> registDiscoveredHostTargets(Long probeId, List<Host> hosts) throws OverflowException {
List<Target> targets = new ArrayList<>(); List<Target> targets = new ArrayList<>();
if (null == services) if (null == hosts)
return targets; return targets;
for (Service service : services) { for (Host host : hosts) {
Host host = service.getPort().getHost(); InfraHost infraHost = this.registInfraHostByDiscoveredHost(host, probeId);
InfraHost infraHost = null; Target target = new Target();
InfraHost existInfraHost = this.infraHostService.readByProbeIdAndIpv4(probeId, host.getIpv4()); target.setInfra(infraHost);
InfraService infraService = null; String displayName = (host.getIpv6() == null || host.getIpv6().trim().isEmpty()) ? host.getIpv6()
if (null != existInfraHost) { : host.getIpv4();
infraHost = existInfraHost; target.setDisplayName(displayName);
} else { targets.add(this.targetDAO.save(target));
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;
} }
return targets;
}
private InfraHost registInfraHostByDiscoveredHost(Host host, Long probeId) throws OverflowException { private List<Target> registDiscoveredServiceTargets(Long probeId, List<Service> services) throws OverflowException {
InfraHost infraHost = new InfraHost(); List<Target> targets = new ArrayList<>();
infraHost.setMetaInfraType(new MetaInfraType(2)); if (null == services)
infraHost.setProbe(new Probe(probeId)); return targets;
infraHost.setIpv4(host.getIpv4()); for (Service service : services) {
infraHost.setIpv6(host.getIpv6()); Host host = service.getPort().getHost();
infraHost.setMac(host.getMac()); InfraHost infraHost = null;
return this.infraHostService.regist(infraHost); 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) Target target = new Target();
throws OverflowException { target.setInfra(infraService);
InfraService infraService = new InfraService(); String displayName = service.getServiceName();
infraHost.setMetaInfraType(new MetaInfraType(7)); target.setDisplayName(displayName);
infraService.setInfraHost(infraHost); targets.add(this.targetDAO.save(target));
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);
} }
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);
}
} }

View File

@ -6,16 +6,16 @@ import io.grpc.*;
public class ProxyServerInterceptor implements ServerInterceptor { public class ProxyServerInterceptor implements ServerInterceptor {
@Override @Override
public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(ServerCall<ReqT, RespT> call, Metadata headers, public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(ServerCall<ReqT, RespT> call, Metadata headers,
ServerCallHandler<ReqT, RespT> next) { ServerCallHandler<ReqT, RespT> next) {
String clientType = headers.get(SessionMetadata.METADATA_CLIENT_TYPE_KEY); String clientType = headers.get(SessionMetadata.METADATA_CLIENT_TYPE_KEY);
String sessionID = headers.get(SessionMetadata.METADATA_SESSION_ID_KEY); String sessionID = headers.get(SessionMetadata.METADATA_SESSION_ID_KEY);
String targetID = headers.get(SessionMetadata.METADATA_TARGET_ID_KEY); String targetID = headers.get(SessionMetadata.METADATA_TARGET_ID_KEY);
Context ctx = Context.current().withValues(SessionMetadata.CTX_CLIENT_TYPE_KEY, clientType, Context ctx = Context.current().withValues(SessionMetadata.CTX_CLIENT_TYPE_KEY, clientType,
SessionMetadata.CTX_SESSION_ID_KEY, sessionID, SessionMetadata.CTX_TARGET_ID_KEY, targetID); 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);
} }
} }

View File

@ -34,13 +34,13 @@ public class ServiceProxy {
ServiceImpl serviceImpl = ctx.getBean(ServiceImpl.class); ServiceImpl serviceImpl = ctx.getBean(ServiceImpl.class);
server = NettyServerBuilder.forPort(port) server = NettyServerBuilder.forPort(port)
.addService(ServerInterceptors.intercept(serviceImpl, proxyServerInterceptor)) .addService(ServerInterceptors.intercept(serviceImpl, proxyServerInterceptor)).build().start();
.build().start();
logger.info("Server started, listening on " + port); logger.info("Server started, listening on " + port);
Runtime.getRuntime().addShutdownHook(new Thread() { Runtime.getRuntime().addShutdownHook(new Thread() {
@Override @Override
public void run() { 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"); System.err.println("*** shutting down gRPC server since JVM is shutting down");
ServiceProxy.this.stop(); ServiceProxy.this.stop();
System.err.println("*** server shut down"); System.err.println("*** server shut down");
@ -105,4 +105,3 @@ public class ServiceProxy {
} }
} }

View File

@ -133,7 +133,7 @@ public class RedisMessagePublisher implements MessagePublisher {
results.add(json); results.add(json);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
} }
return results; return results;

View File

@ -15,19 +15,19 @@ import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
@PropertySource({ "classpath:database.properties", "classpath:mail.properties", "classpath:redis.properties", @PropertySource({ "classpath:database.properties", "classpath:mail.properties", "classpath:redis.properties",
"classpath:cache.properties" }) "classpath:cache.properties" })
public class AppConfig { public class AppConfig {
// @Bean // @Bean
// public static PropertyPlaceholderConfigurer propertyPlaceholderConfigurer() { // public static PropertyPlaceholderConfigurer propertyPlaceholderConfigurer() {
// PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer(); // PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer();
//// ppc.setLocation(new ClassPathResource("database.properties")); //// ppc.setLocation(new ClassPathResource("database.properties"));
// ppc.setLocations(new Resource[] { // ppc.setLocations(new Resource[] {
// new ClassPathResource("database.properties"), // new ClassPathResource("database.properties"),
// new ClassPathResource("mail.properties"), // new ClassPathResource("mail.properties"),
// new ClassPathResource("redis.properties") // new ClassPathResource("redis.properties")
// }); // });
// ppc.setIgnoreUnresolvablePlaceholders(true); // ppc.setIgnoreUnresolvablePlaceholders(true);
// //
// return ppc; // return ppc;
// } // }
@Bean @Bean
public PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() { public PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
return new PropertySourcesPlaceholderConfigurer(); return new PropertySourcesPlaceholderConfigurer();
@ -35,10 +35,10 @@ public class AppConfig {
// @Bean // @Bean
// public Gson gson() { // public Gson gson() {
// GsonBuilder builder = new GsonBuilder(); // GsonBuilder builder = new GsonBuilder();
// builder.excludeFieldsWithModifiers(Modifier.TRANSIENT, Modifier.PRIVATE); // builder.excludeFieldsWithModifiers(Modifier.TRANSIENT, Modifier.PRIVATE);
// // builder.excludeFieldsWithoutExposeAnnotation(); // // builder.excludeFieldsWithoutExposeAnnotation();
// return builder.create(); // return builder.create();
// } // }
@Bean @Bean
public ObjectMapper getObjectMapper() { public ObjectMapper getObjectMapper() {

View File

@ -10,17 +10,17 @@ import org.springframework.context.annotation.Configuration;
@EnableCaching @EnableCaching
@Configuration @Configuration
public class CacheConfiguration { public class CacheConfiguration {
@Value("#{'${cache.cache-names}'.split(',')}") @Value("#{'${cache.cache-names}'.split(',')}")
private String[] cacheNames; private String[] cacheNames;
@Value("${cache.caffeine.spec}") @Value("${cache.caffeine.spec}")
private String spec; private String spec;
@Bean @Bean
public CacheManager cacheManager() { public CacheManager cacheManager() {
//A EhCache based Cache manager // A EhCache based Cache manager
CaffeineCacheManager cacheManager = new CaffeineCacheManager(cacheNames); CaffeineCacheManager cacheManager = new CaffeineCacheManager(cacheNames);
cacheManager.setAllowNullValues(false); cacheManager.setAllowNullValues(false);
cacheManager.setCacheSpecification(spec); cacheManager.setCacheSpecification(spec);
return cacheManager; return cacheManager;
} }
} }

View File

@ -21,82 +21,79 @@ import javax.persistence.EntityManager;
import javax.sql.DataSource; import javax.sql.DataSource;
import java.util.Properties; import java.util.Properties;
/** /**
* Created by root on 17. 6. 13. * Created by root on 17. 6. 13.
*/ */
@Configuration @Configuration
@EnableTransactionManagement @EnableTransactionManagement
@EnableJpaRepositories(basePackages = {"com.loafle.overflow"}) @EnableJpaRepositories(basePackages = { "com.loafle.overflow" })
public class JdbcConfiguration implements TransactionManagementConfigurer { public class JdbcConfiguration implements TransactionManagementConfigurer {
@Value("${datasource.driver-class-name}") @Value("${datasource.driver-class-name}")
private String driver; private String driver;
@Value("${datasource.url}") @Value("${datasource.url}")
private String url; private String url;
@Value("${datasource.username}") @Value("${datasource.username}")
private String username; private String username;
@Value("${datasource.password}") @Value("${datasource.password}")
private String password; private String password;
@Value("${jpa.hibernate.dialect}") @Value("${jpa.hibernate.dialect}")
private String dialect; private String dialect;
@Value("${jpa.hibernate.ddl-auto}") @Value("${jpa.hibernate.ddl-auto}")
private String hbm2ddlAuto; private String hbm2ddlAuto;
@Bean @Bean
public DataSource configureDataSource() { public DataSource configureDataSource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource(); DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName(driver); dataSource.setDriverClassName(driver);
dataSource.setUrl(url); dataSource.setUrl(url);
dataSource.setUsername(username); dataSource.setUsername(username);
dataSource.setPassword(password); dataSource.setPassword(password);
return dataSource; 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 return initializer;
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;
}
} }

View File

@ -18,63 +18,62 @@ import java.util.Properties;
@ComponentScan(basePackages = "com.loafle.overflow") @ComponentScan(basePackages = "com.loafle.overflow")
public class MailConfiguration { public class MailConfiguration {
@Value("${mail.host}") @Value("${mail.host}")
private String host; private String host;
@Value("${mail.port}") @Value("${mail.port}")
private int port; private int port;
@Value("${mail.username}") @Value("${mail.username}")
private String username; private String username;
@Value("${mail.password}") @Value("${mail.password}")
private String password; private String password;
@Value("${mail.protocol}") @Value("${mail.protocol}")
private String protocol; private String protocol;
@Bean @Bean
public JavaMailSenderImpl mailSender() { public JavaMailSenderImpl mailSender() {
JavaMailSenderImpl mailSender = new JavaMailSenderImpl(); JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
mailSender.setHost(this.host); mailSender.setHost(this.host);
mailSender.setPort(this.port); mailSender.setPort(this.port);
mailSender.setUsername(this.username); mailSender.setUsername(this.username);
mailSender.setPassword(this.password); mailSender.setPassword(this.password);
mailSender.setProtocol(this.protocol); mailSender.setProtocol(this.protocol);
mailSender.setJavaMailProperties(getJavaMailProperties()); mailSender.setJavaMailProperties(getJavaMailProperties());
return mailSender; return mailSender;
} }
@Bean @Bean
public Properties getJavaMailProperties() { public Properties getJavaMailProperties() {
Properties javaMailProperties = new Properties(); Properties javaMailProperties = new Properties();
javaMailProperties.put("mail.smtp.starttls.enable", true); javaMailProperties.put("mail.smtp.starttls.enable", true);
javaMailProperties.put("mail.smtp.auth", true); javaMailProperties.put("mail.smtp.auth", true);
javaMailProperties.put("mail.transport.protocol", "smtp"); javaMailProperties.put("mail.transport.protocol", "smtp");
javaMailProperties.put("mail.debug", "true"); javaMailProperties.put("mail.debug", "true");
javaMailProperties.put("mail.smtps.ssl.checkserveridentity", true); javaMailProperties.put("mail.smtps.ssl.checkserveridentity", true);
javaMailProperties.put("mail.smtps.ssl.trust", "*"); javaMailProperties.put("mail.smtps.ssl.trust", "*");
return javaMailProperties; return javaMailProperties;
} }
@Bean
@Bean public VelocityEngine getVelocityEngine() throws VelocityException, IOException {
public VelocityEngine getVelocityEngine() throws VelocityException, IOException { Properties properties = new Properties();
Properties properties = new Properties(); properties.load(this.getClass().getResourceAsStream("/velocity.properties"));
properties.load(this.getClass().getResourceAsStream("/velocity.properties")); return new VelocityEngine(properties);
return new VelocityEngine(properties); }
}
} }
// //
// @Value("${mail.properties.mail.smtp.auth}") // @Value("${mail.properties.mail.smtp.auth}")
// private boolean smtpAuth; // private boolean smtpAuth;
// @Value("${mail.properties.mail.smtp.starttls.enable}") // @Value("${mail.properties.mail.smtp.starttls.enable}")
// private boolean ttlEnable; // private boolean ttlEnable;
// @Value("${mail.transport.protocol}") // @Value("${mail.transport.protocol}")
// private String transProtocol; // private String transProtocol;
// @Value("${mail.smtps.ssl.checkserveridentity}") // @Value("${mail.smtps.ssl.checkserveridentity}")
// private boolean checkserver; // private boolean checkserver;
// @Value("${mail.smtps.ssl.trust}") // @Value("${mail.smtps.ssl.trust}")
// private String sslTrust; // private String sslTrust;

View File

@ -20,54 +20,53 @@ import java.util.Map;
@Configuration @Configuration
public class RedisConfiguration { public class RedisConfiguration {
@Value("${redis.host}") @Value("${redis.host}")
private String host; private String host;
@Value("${redis.port}") @Value("${redis.port}")
private int port; private int port;
@Value("#{'${redis.channels}'.split(',')}") @Value("#{'${redis.channels}'.split(',')}")
private List<String> channels; private List<String> channels;
@Bean @Bean
JedisConnectionFactory jedisConnectionFactory() { JedisConnectionFactory jedisConnectionFactory() {
RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration(); RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration();
redisStandaloneConfiguration.setHostName(host); redisStandaloneConfiguration.setHostName(host);
redisStandaloneConfiguration.setPort(port); redisStandaloneConfiguration.setPort(port);
// redisStandaloneConfiguration.setDatabase(0); // redisStandaloneConfiguration.setDatabase(0);
// redisStandaloneConfiguration.setPassword(RedisPassword.of("password")); // redisStandaloneConfiguration.setPassword(RedisPassword.of("password"));
JedisClientConfigurationBuilder jedisClientConfiguration = JedisClientConfiguration.builder(); JedisClientConfigurationBuilder jedisClientConfiguration = JedisClientConfiguration.builder();
jedisClientConfiguration.connectTimeout(Duration.ofSeconds(60));// 60s connection timeout jedisClientConfiguration.connectTimeout(Duration.ofSeconds(60));// 60s connection timeout
JedisConnectionFactory jedisConFactory = new JedisConnectionFactory(redisStandaloneConfiguration, JedisConnectionFactory jedisConFactory = new JedisConnectionFactory(redisStandaloneConfiguration,
jedisClientConfiguration.build()); jedisClientConfiguration.build());
// JedisConnectionFactory jedisConFactory = new JedisConnectionFactory();
// jedisConFactory.setHostName(host);
// jedisConFactory.setPort(port);
return jedisConFactory;
}
// JedisConnectionFactory jedisConFactory = new JedisConnectionFactory(); @Bean
// jedisConFactory.setHostName(host); public RedisTemplate<String, Object> redisTemplate() {
// jedisConFactory.setPort(port); final RedisTemplate<String, Object> template = new RedisTemplate<String, Object>();
return jedisConFactory; template.setConnectionFactory(jedisConnectionFactory());
} template.setValueSerializer(new GenericToStringSerializer<Object>(Object.class));
return template;
@Bean }
public RedisTemplate<String, Object> redisTemplate() {
final RedisTemplate<String, Object> template = new RedisTemplate<String, Object>(); @Bean
template.setConnectionFactory(jedisConnectionFactory()); MessagePublisher messagePublisher() {
template.setValueSerializer(new GenericToStringSerializer<Object>(Object.class)); return new RedisMessagePublisher(redisTemplate(), topics());
return template; }
}
@Bean
@Bean Map<String, ChannelTopic> topics() {
MessagePublisher messagePublisher() { Map<String, ChannelTopic> topicMap = new HashMap<>(this.channels.size());
return new RedisMessagePublisher(redisTemplate(), topics()); for (String channel : this.channels) {
} topicMap.put(channel, new ChannelTopic(channel));
@Bean
Map<String, ChannelTopic> topics() {
Map<String, ChannelTopic> topicMap = new HashMap<>(this.channels.size());
for (String channel: this.channels) {
topicMap.put(channel, new ChannelTopic(channel));
}
return topicMap;
} }
return topicMap;
}
} }