Изменено поле типа паттерна
This commit is contained in:
@@ -4,7 +4,8 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
|
|||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
import org.hibernate.annotations.GenericGenerator;
|
import org.hibernate.annotations.GenericGenerator;
|
||||||
import ru.serega6531.packmate.model.enums.PatternType;
|
import ru.serega6531.packmate.model.enums.PatternDirectionType;
|
||||||
|
import ru.serega6531.packmate.model.enums.PatternSearchType;
|
||||||
|
|
||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -33,9 +34,9 @@ public class Pattern {
|
|||||||
|
|
||||||
private String color; // для вставки в css
|
private String color; // для вставки в css
|
||||||
|
|
||||||
private boolean isRegex;
|
private PatternSearchType searchType;
|
||||||
|
|
||||||
private PatternType type;
|
private PatternDirectionType directionType;
|
||||||
|
|
||||||
@ManyToMany(mappedBy = "foundPatterns", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
@ManyToMany(mappedBy = "foundPatterns", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
package ru.serega6531.packmate.model.enums;
|
package ru.serega6531.packmate.model.enums;
|
||||||
|
|
||||||
public enum PatternType {
|
public enum PatternDirectionType {
|
||||||
INPUT, OUTPUT, BOTH
|
INPUT, OUTPUT, BOTH
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package ru.serega6531.packmate.model.enums;
|
||||||
|
|
||||||
|
public enum PatternSearchType {
|
||||||
|
REGEX, SUBSTRING, SUBBYTES
|
||||||
|
}
|
||||||
@@ -1,7 +1,5 @@
|
|||||||
package ru.serega6531.packmate.model.enums;
|
package ru.serega6531.packmate.model.enums;
|
||||||
|
|
||||||
public enum SubscriptionMessageType {
|
public enum SubscriptionMessageType {
|
||||||
|
|
||||||
SAVE_SERVICE, SAVE_PATTERN, DELETE_SERVICE, DELETE_PATTERN, NEW_STREAM
|
SAVE_SERVICE, SAVE_PATTERN, DELETE_SERVICE, DELETE_PATTERN, NEW_STREAM
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,12 +2,12 @@ package ru.serega6531.packmate.repository;
|
|||||||
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
import ru.serega6531.packmate.model.Pattern;
|
import ru.serega6531.packmate.model.Pattern;
|
||||||
import ru.serega6531.packmate.model.enums.PatternType;
|
import ru.serega6531.packmate.model.enums.PatternDirectionType;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface PatternRepository extends JpaRepository<Pattern, Integer> {
|
public interface PatternRepository extends JpaRepository<Pattern, Integer> {
|
||||||
|
|
||||||
List<Pattern> findAllByTypeEqualsOrTypeEquals(PatternType type, PatternType both);
|
List<Pattern> findAllByTypeEqualsOrTypeEquals(PatternDirectionType type, PatternDirectionType both);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,8 +8,9 @@ import org.springframework.stereotype.Service;
|
|||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import ru.serega6531.packmate.model.FoundPattern;
|
import ru.serega6531.packmate.model.FoundPattern;
|
||||||
import ru.serega6531.packmate.model.Pattern;
|
import ru.serega6531.packmate.model.Pattern;
|
||||||
import ru.serega6531.packmate.model.enums.PatternType;
|
import ru.serega6531.packmate.model.enums.PatternDirectionType;
|
||||||
import ru.serega6531.packmate.model.Stream;
|
import ru.serega6531.packmate.model.Stream;
|
||||||
|
import ru.serega6531.packmate.model.enums.PatternSearchType;
|
||||||
import ru.serega6531.packmate.model.enums.SubscriptionMessageType;
|
import ru.serega6531.packmate.model.enums.SubscriptionMessageType;
|
||||||
import ru.serega6531.packmate.model.pojo.SubscriptionMessage;
|
import ru.serega6531.packmate.model.pojo.SubscriptionMessage;
|
||||||
import ru.serega6531.packmate.repository.PatternRepository;
|
import ru.serega6531.packmate.repository.PatternRepository;
|
||||||
@@ -53,8 +54,8 @@ public class PatternService {
|
|||||||
String content = new String(bytes);
|
String content = new String(bytes);
|
||||||
|
|
||||||
return patterns.values().stream()
|
return patterns.values().stream()
|
||||||
.filter(p -> p.getType() == (incoming ? PatternType.INPUT : PatternType.OUTPUT)
|
.filter(p -> p.getDirectionType() == (incoming ? PatternDirectionType.INPUT : PatternDirectionType.OUTPUT)
|
||||||
|| p.getType() == PatternType.BOTH)
|
|| p.getDirectionType() == PatternDirectionType.BOTH)
|
||||||
.map(pattern -> match(pattern, content))
|
.map(pattern -> match(pattern, content))
|
||||||
.flatMap(List::stream)
|
.flatMap(List::stream)
|
||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());
|
||||||
@@ -63,7 +64,7 @@ public class PatternService {
|
|||||||
private List<FoundPattern> match(Pattern pattern, String content) {
|
private List<FoundPattern> match(Pattern pattern, String content) {
|
||||||
List<FoundPattern> found = new ArrayList<>();
|
List<FoundPattern> found = new ArrayList<>();
|
||||||
|
|
||||||
if (pattern.isRegex()) {
|
if (pattern.getSearchType() == PatternSearchType.REGEX) {
|
||||||
final java.util.regex.Pattern regex = compilePattern(pattern);
|
final java.util.regex.Pattern regex = compilePattern(pattern);
|
||||||
final Matcher matcher = regex.matcher(content);
|
final Matcher matcher = regex.matcher(content);
|
||||||
|
|
||||||
@@ -76,7 +77,7 @@ public class PatternService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return found;
|
return found;
|
||||||
} else {
|
} else if (pattern.getSearchType() == PatternSearchType.SUBSTRING) {
|
||||||
int startSearch = 0;
|
int startSearch = 0;
|
||||||
|
|
||||||
final String value = pattern.getValue();
|
final String value = pattern.getValue();
|
||||||
@@ -96,6 +97,9 @@ public class PatternService {
|
|||||||
|
|
||||||
startSearch = end + 1;
|
startSearch = end + 1;
|
||||||
}
|
}
|
||||||
|
} else { // SUBBYTES
|
||||||
|
// TODO
|
||||||
|
return found;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user