-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[api, frontend] Endpoints modelization (#268)
- Loading branch information
1 parent
5e6d006
commit 4477697
Showing
9 changed files
with
215 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
openex-model/src/main/java/io/openex/annotation/Ipv4OrIpv6Constraint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package io.openex.annotation; | ||
|
||
import io.openex.validator.Ipv4OrIpv6Validator; | ||
|
||
import javax.validation.Constraint; | ||
import javax.validation.Payload; | ||
import javax.validation.ReportAsSingleViolation; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.Target; | ||
|
||
import static java.lang.annotation.ElementType.FIELD; | ||
import static java.lang.annotation.RetentionPolicy.RUNTIME; | ||
|
||
@Target(FIELD) | ||
@Retention(RUNTIME) | ||
@Constraint(validatedBy = Ipv4OrIpv6Validator.class) | ||
@ReportAsSingleViolation | ||
public @interface Ipv4OrIpv6Constraint { | ||
String message() default "must be ipv4 or ipv6"; | ||
|
||
Class<?>[] groups() default {}; | ||
|
||
Class<? extends Payload>[] payload() default {}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
openex-model/src/main/java/io/openex/database/model/System.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package io.openex.database.model; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.databind.annotation.JsonSerialize; | ||
import io.openex.annotation.Ipv4OrIpv6Constraint; | ||
import io.openex.database.audit.ModelBaseListener; | ||
import io.openex.helper.MultiIdDeserializer; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
import org.hibernate.annotations.GenericGenerator; | ||
|
||
import javax.persistence.*; | ||
import java.time.Instant; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import static java.time.Instant.now; | ||
|
||
@Getter | ||
@Setter | ||
@Entity | ||
@Table(name = "systems") | ||
@EntityListeners(ModelBaseListener.class) | ||
public class System implements Base { | ||
|
||
public enum SYSTEM_TYPE { | ||
ENDPOINT, | ||
WEBSITE, | ||
} | ||
|
||
public enum OS_TYPE { | ||
LINUX, | ||
WINDOWS, | ||
} | ||
|
||
@Id | ||
@Column(name = "system_id") | ||
@GeneratedValue(generator = "UUID") | ||
@GenericGenerator(name = "UUID", strategy = "org.hibernate.id.UUIDGenerator") | ||
@JsonProperty("system_id") | ||
private String id; | ||
|
||
@Column(name = "system_created_at") | ||
@JsonProperty("system_created_at") | ||
private Instant createdAt = now(); | ||
|
||
@Column(name = "system_updated_at") | ||
@JsonProperty("system_updated_at") | ||
private Instant updatedAt = now(); | ||
|
||
@Column(name = "system_name") | ||
@JsonProperty("system_name") | ||
private String name; | ||
|
||
@Column(name = "system_type") | ||
@JsonProperty("system_type") | ||
@Enumerated(EnumType.STRING) | ||
private SYSTEM_TYPE type; | ||
|
||
@Ipv4OrIpv6Constraint | ||
@Column(name = "system_ip") | ||
@JsonProperty("system_ip") | ||
private String ip; | ||
|
||
@Column(name = "system_hostname") | ||
@JsonProperty("system_hostname") | ||
private String hostname; | ||
|
||
@Column(name = "system_os") | ||
@JsonProperty("system_os") | ||
@Enumerated(EnumType.STRING) | ||
private OS_TYPE os; | ||
|
||
@ManyToMany(mappedBy = "systems", fetch = FetchType.LAZY) | ||
@JsonSerialize(using = MultiIdDeserializer.class) | ||
@JsonProperty("system_zones") | ||
private List<Zone> zones = new ArrayList<>(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
openex-model/src/main/java/io/openex/database/model/Zone.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package io.openex.database.model; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.databind.annotation.JsonSerialize; | ||
import io.openex.annotation.Ipv4OrIpv6Constraint; | ||
import io.openex.database.audit.ModelBaseListener; | ||
import io.openex.helper.MultiIdDeserializer; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
import org.hibernate.annotations.GenericGenerator; | ||
|
||
import javax.persistence.*; | ||
import java.time.Instant; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import static java.time.Instant.now; | ||
|
||
@Getter | ||
@Setter | ||
@Entity | ||
@Table(name = "zones") | ||
@EntityListeners(ModelBaseListener.class) | ||
public class Zone implements Base { | ||
|
||
@Id | ||
@Column(name = "zone_id") | ||
@GeneratedValue(generator = "UUID") | ||
@GenericGenerator(name = "UUID", strategy = "org.hibernate.id.UUIDGenerator") | ||
@JsonProperty("zone_id") | ||
private String id; | ||
|
||
@Column(name = "zone_name") | ||
@JsonProperty("zone_name") | ||
private String name; | ||
|
||
@Column(name = "zone_description") | ||
@JsonProperty("zone_description") | ||
private String description; | ||
|
||
@Column(name = "zone_created_at") | ||
@JsonProperty("zone_created_at") | ||
private Instant createdAt = now(); | ||
|
||
@Column(name = "zone_updated_at") | ||
@JsonProperty("zone_updated_at") | ||
private Instant updatedAt = now(); | ||
|
||
@ManyToMany(fetch = FetchType.LAZY) | ||
@JoinTable(name = "systems_zones", | ||
joinColumns = @JoinColumn(name = "zone_id"), | ||
inverseJoinColumns = @JoinColumn(name = "system_id")) | ||
@JsonSerialize(using = MultiIdDeserializer.class) | ||
@JsonProperty("zone_systems") | ||
private List<System> systems = new ArrayList<>(); | ||
} |
8 changes: 8 additions & 0 deletions
8
openex-model/src/main/java/io/openex/database/repository/SystemRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package io.openex.database.repository; | ||
|
||
import io.openex.database.model.System; | ||
import org.springframework.data.repository.CrudRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface SystemRepository extends CrudRepository<System, String> { } |
8 changes: 8 additions & 0 deletions
8
openex-model/src/main/java/io/openex/database/repository/ZoneRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package io.openex.database.repository; | ||
|
||
import io.openex.database.model.Zone; | ||
import org.springframework.data.repository.CrudRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface ZoneRepository extends CrudRepository<Zone, String> { } |
21 changes: 21 additions & 0 deletions
21
openex-model/src/main/java/io/openex/validator/Ipv4OrIpv6Validator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package io.openex.validator; | ||
|
||
import io.openex.annotation.Ipv4OrIpv6Constraint; | ||
import org.apache.commons.validator.routines.InetAddressValidator; | ||
|
||
import javax.validation.ConstraintValidator; | ||
import javax.validation.ConstraintValidatorContext; | ||
|
||
public class Ipv4OrIpv6Validator implements ConstraintValidator<Ipv4OrIpv6Constraint, String> { | ||
|
||
@Override | ||
public void initialize(Ipv4OrIpv6Constraint ip) { | ||
} | ||
|
||
@Override | ||
public boolean isValid(String ip, ConstraintValidatorContext cxt) { | ||
InetAddressValidator validator = InetAddressValidator.getInstance(); | ||
return validator.isValid(ip); | ||
} | ||
|
||
} |