Добавлены классы для пакетов и паттернов
This commit is contained in:
@@ -0,0 +1,32 @@
|
|||||||
|
package ru.serega6531.packmate.controller;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import ru.serega6531.packmate.model.Packet;
|
||||||
|
import ru.serega6531.packmate.service.PacketService;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/packet/")
|
||||||
|
public class PacketController {
|
||||||
|
|
||||||
|
private final PacketService service;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public PacketController(PacketService service) {
|
||||||
|
this.service = service;
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/all")
|
||||||
|
public List<Packet> getPackets() {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/{stream}")
|
||||||
|
public List<Packet> getStreams(@PathVariable int stream) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
package ru.serega6531.packmate.controller;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import ru.serega6531.packmate.model.Pattern;
|
||||||
|
import ru.serega6531.packmate.service.PatternService;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/pattern/")
|
||||||
|
public class PatternController {
|
||||||
|
|
||||||
|
private final PatternService service;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public PatternController(PatternService service) {
|
||||||
|
this.service = service;
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping
|
||||||
|
public List<Pattern> getPatterns() {
|
||||||
|
return service.findAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("/{id}")
|
||||||
|
public void deletePattern(@PathVariable int id) {
|
||||||
|
service.deleteById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping
|
||||||
|
public Pattern addPattern(@RequestBody Pattern pattern) {
|
||||||
|
return service.save(pattern);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
package ru.serega6531.packmate.controller;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import ru.serega6531.packmate.model.CtfService;
|
||||||
|
import ru.serega6531.packmate.service.ServicesService;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/service/")
|
||||||
|
public class ServiceController {
|
||||||
|
|
||||||
|
private final ServicesService service;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public ServiceController(ServicesService service) {
|
||||||
|
this.service = service;
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping
|
||||||
|
public List<CtfService> getServices() {
|
||||||
|
return service.findAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("/{port}")
|
||||||
|
public void deleteService(@PathVariable int port) {
|
||||||
|
service.deleteById(port);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping
|
||||||
|
public CtfService addService(@RequestBody CtfService ctfService) {
|
||||||
|
return service.save(ctfService);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
package ru.serega6531.packmate.controller;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
|
||||||
import ru.serega6531.packmate.model.Service;
|
|
||||||
import ru.serega6531.packmate.repository.ServiceRepository;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("/api/service/manage")
|
|
||||||
public class ServicesController {
|
|
||||||
|
|
||||||
private final ServiceRepository repository;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
public ServicesController(ServiceRepository repository) {
|
|
||||||
this.repository = repository;
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping
|
|
||||||
public List<Service> getServices() {
|
|
||||||
return repository.findAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
@DeleteMapping("/{port}")
|
|
||||||
public void deleteService(@PathVariable int port) {
|
|
||||||
repository.deleteById(port);
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostMapping
|
|
||||||
public List<Service> addService(@RequestBody Service service) {
|
|
||||||
repository.save(service);
|
|
||||||
return getServices();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,26 +1,34 @@
|
|||||||
package ru.serega6531.packmate.controller;
|
package ru.serega6531.packmate.controller;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
import ru.serega6531.packmate.model.Stream;
|
import ru.serega6531.packmate.model.Stream;
|
||||||
|
import ru.serega6531.packmate.service.StreamService;
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/service/")
|
@RequestMapping("/api/stream/")
|
||||||
public class StreamsController {
|
public class StreamController {
|
||||||
|
|
||||||
|
private final StreamService service;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public StreamController(StreamService service) {
|
||||||
|
this.service = service;
|
||||||
|
}
|
||||||
|
|
||||||
@GetMapping("/all")
|
@GetMapping("/all")
|
||||||
public List<Stream> getStreams() {
|
public List<Stream> getStreams() {
|
||||||
return Collections.emptyList();
|
return service.findAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/{port}")
|
@GetMapping("/{port}")
|
||||||
public List<Stream> getStreams(@PathVariable int port) {
|
public List<Stream> getStreams(@PathVariable int port) {
|
||||||
return Collections.emptyList();
|
return service.findAllByServicePort(port);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
23
src/main/java/ru/serega6531/packmate/model/CtfService.java
Normal file
23
src/main/java/ru/serega6531/packmate/model/CtfService.java
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
package ru.serega6531.packmate.model;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import javax.persistence.CascadeType;
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.OneToMany;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Entity
|
||||||
|
public class CtfService {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
private int port;
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@OneToMany(mappedBy = "service", cascade = CascadeType.ALL, orphanRemoval = true)
|
||||||
|
private List<Stream> streams;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -26,4 +26,6 @@ public class Packet {
|
|||||||
@JoinColumn(name = "stream_id", nullable = false)
|
@JoinColumn(name = "stream_id", nullable = false)
|
||||||
private Stream stream;
|
private Stream stream;
|
||||||
|
|
||||||
|
private long timestamp;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
33
src/main/java/ru/serega6531/packmate/model/Pattern.java
Normal file
33
src/main/java/ru/serega6531/packmate/model/Pattern.java
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
package ru.serega6531.packmate.model;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import org.hibernate.annotations.GenericGenerator;
|
||||||
|
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Entity
|
||||||
|
@GenericGenerator(
|
||||||
|
name = "pattern_generator",
|
||||||
|
strategy = "org.hibernate.id.enhanced.SequenceStyleGenerator",
|
||||||
|
parameters = {
|
||||||
|
@org.hibernate.annotations.Parameter(name = "sequence_name", value = "pattern_seq"),
|
||||||
|
@org.hibernate.annotations.Parameter(name = "initial_value", value = "1"),
|
||||||
|
@org.hibernate.annotations.Parameter(name = "increment_size", value = "1")
|
||||||
|
}
|
||||||
|
)
|
||||||
|
public class Pattern {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(generator = "pattern_generator")
|
||||||
|
private int id;
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
private String value;
|
||||||
|
|
||||||
|
private String color; // для вставки в css
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
package ru.serega6531.packmate.model;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
import javax.persistence.Entity;
|
|
||||||
import javax.persistence.Id;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
@Entity
|
|
||||||
public class Service {
|
|
||||||
|
|
||||||
@Id
|
|
||||||
private int port;
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -23,7 +23,13 @@ public class Stream {
|
|||||||
@GeneratedValue(generator = "stream_generator")
|
@GeneratedValue(generator = "stream_generator")
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
|
@ManyToOne
|
||||||
|
@JoinColumn(name = "service_id", nullable = false)
|
||||||
|
private CtfService service;
|
||||||
|
|
||||||
@OneToMany(mappedBy = "stream", cascade = CascadeType.ALL, orphanRemoval = true)
|
@OneToMany(mappedBy = "stream", cascade = CascadeType.ALL, orphanRemoval = true)
|
||||||
private List<Packet> packet;
|
private List<Packet> packets;
|
||||||
|
|
||||||
|
private long timestamp;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package ru.serega6531.packmate.repository;
|
||||||
|
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import ru.serega6531.packmate.model.Packet;
|
||||||
|
|
||||||
|
public interface PacketRepository extends JpaRepository<Packet, Long> {
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package ru.serega6531.packmate.repository;
|
||||||
|
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import ru.serega6531.packmate.model.Pattern;
|
||||||
|
|
||||||
|
public interface PatternRepository extends JpaRepository<Pattern, Integer> {
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package ru.serega6531.packmate.repository;
|
package ru.serega6531.packmate.repository;
|
||||||
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
import ru.serega6531.packmate.model.Service;
|
import ru.serega6531.packmate.model.CtfService;
|
||||||
|
|
||||||
public interface ServiceRepository extends JpaRepository<Service, Integer> {
|
public interface ServiceRepository extends JpaRepository<CtfService, Integer> {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,5 +3,10 @@ package ru.serega6531.packmate.repository;
|
|||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
import ru.serega6531.packmate.model.Stream;
|
import ru.serega6531.packmate.model.Stream;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public interface StreamRepository extends JpaRepository<Stream, Long> {
|
public interface StreamRepository extends JpaRepository<Stream, Long> {
|
||||||
|
|
||||||
|
List<Stream> findAllByService_Port(int port);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package ru.serega6531.packmate.service;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class PacketService {
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package ru.serega6531.packmate.service;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import ru.serega6531.packmate.model.Pattern;
|
||||||
|
import ru.serega6531.packmate.repository.PatternRepository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class PatternService {
|
||||||
|
|
||||||
|
private final PatternRepository repository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public PatternService(PatternRepository repository) {
|
||||||
|
this.repository = repository;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Pattern> findAll() {
|
||||||
|
return repository.findAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteById(int id) {
|
||||||
|
repository.deleteById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Pattern save(Pattern service) {
|
||||||
|
return repository.save(service);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package ru.serega6531.packmate.service;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import ru.serega6531.packmate.model.CtfService;
|
||||||
|
import ru.serega6531.packmate.repository.ServiceRepository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class ServicesService {
|
||||||
|
|
||||||
|
private final ServiceRepository repository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public ServicesService(ServiceRepository repository) {
|
||||||
|
this.repository = repository;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<CtfService> findAll() {
|
||||||
|
return repository.findAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteById(int id) {
|
||||||
|
repository.deleteById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CtfService save(CtfService service) {
|
||||||
|
return repository.save(service);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package ru.serega6531.packmate.service;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import ru.serega6531.packmate.model.Stream;
|
||||||
|
import ru.serega6531.packmate.repository.StreamRepository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class StreamService {
|
||||||
|
|
||||||
|
private final StreamRepository repository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public StreamService(StreamRepository repository) {
|
||||||
|
this.repository = repository;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Stream> findAll() {
|
||||||
|
return repository.findAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Stream> findAllByServicePort(int port) {
|
||||||
|
return repository.findAllByService_Port(port);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user