diff --git a/kouncil-backend/src/main/java/com/consdata/kouncil/datamasking/dto/PolicyDto.java b/kouncil-backend/src/main/java/com/consdata/kouncil/datamasking/dto/PolicyDto.java index de826fbd..6b48ddf1 100644 --- a/kouncil-backend/src/main/java/com/consdata/kouncil/datamasking/dto/PolicyDto.java +++ b/kouncil-backend/src/main/java/com/consdata/kouncil/datamasking/dto/PolicyDto.java @@ -11,5 +11,5 @@ public class PolicyDto { private String name; private MaskingType type; private Set fields; - private Set resources; + private Set resources; } diff --git a/kouncil-backend/src/main/java/com/consdata/kouncil/datamasking/dto/PolicyResourceDto.java b/kouncil-backend/src/main/java/com/consdata/kouncil/datamasking/dto/PolicyResourceDto.java new file mode 100644 index 00000000..a815b892 --- /dev/null +++ b/kouncil-backend/src/main/java/com/consdata/kouncil/datamasking/dto/PolicyResourceDto.java @@ -0,0 +1,12 @@ +package com.consdata.kouncil.datamasking.dto; + +import com.consdata.kouncil.clusters.dto.ClusterDto; +import lombok.Data; + +@Data +public class PolicyResourceDto { + + private Long id; + private ClusterDto cluster; + private String topic; +} diff --git a/kouncil-backend/src/main/java/com/consdata/kouncil/model/datamasking/Policy.java b/kouncil-backend/src/main/java/com/consdata/kouncil/model/datamasking/Policy.java index 8e235233..afec8b73 100644 --- a/kouncil-backend/src/main/java/com/consdata/kouncil/model/datamasking/Policy.java +++ b/kouncil-backend/src/main/java/com/consdata/kouncil/model/datamasking/Policy.java @@ -1,16 +1,19 @@ package com.consdata.kouncil.model.datamasking; import java.util.Set; +import javax.persistence.CascadeType; import javax.persistence.CollectionTable; import javax.persistence.Column; import javax.persistence.ElementCollection; import javax.persistence.Entity; import javax.persistence.EnumType; import javax.persistence.Enumerated; +import javax.persistence.FetchType; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.JoinColumn; +import javax.persistence.OneToMany; import javax.persistence.SequenceGenerator; import javax.persistence.Table; import lombok.Getter; @@ -40,9 +43,10 @@ public class Policy { @Column(name = "FIELD") private Set fields; + @Column(name = "APPLY_TO_ALL_RESOURCES") + private Boolean applyToAllResources; - @ElementCollection - @CollectionTable(name = "POLICY_RESOURCES", joinColumns = @JoinColumn(name = "POLICY_ID")) - @Column(name = "RESOURCES") - private Set resources; + @OneToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE}, fetch = FetchType.EAGER, orphanRemoval = true) + @JoinColumn(name = "POLICY_ID") + private Set resources; } diff --git a/kouncil-backend/src/main/java/com/consdata/kouncil/model/datamasking/PolicyResource.java b/kouncil-backend/src/main/java/com/consdata/kouncil/model/datamasking/PolicyResource.java new file mode 100644 index 00000000..70ac7c57 --- /dev/null +++ b/kouncil-backend/src/main/java/com/consdata/kouncil/model/datamasking/PolicyResource.java @@ -0,0 +1,39 @@ +package com.consdata.kouncil.model.datamasking; + +import com.consdata.kouncil.model.cluster.Cluster; +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.SequenceGenerator; +import javax.persistence.Table; +import lombok.Getter; +import lombok.Setter; + +@Entity +@Table(name = "POLICY_RESOURCE") +@Getter +@Setter +public class PolicyResource { + + @Id + @Column(name = "ID") + @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQ_POLICY_RESOURCE_GEN") + @SequenceGenerator(name = "SEQ_POLICY_RESOURCE_GEN", sequenceName = "SEQ_POLICY_RESOURCE", initialValue = 1, allocationSize = 1) + private Long id; + + @ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE}) + @JoinColumn(name = "CLUSTER_ID", insertable = false, updatable = false) + private Cluster cluster; + + @Column(name = "TOPIC") + private String topic; + + @ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE}) + @JoinColumn(name = "POLICY_ID", insertable = false, updatable = false) + private Policy policy; +} diff --git a/kouncil-backend/src/main/resources/db/migration/V7__data_masking.sql b/kouncil-backend/src/main/resources/db/migration/V7__data_masking.sql index c508d52f..f20fefad 100644 --- a/kouncil-backend/src/main/resources/db/migration/V7__data_masking.sql +++ b/kouncil-backend/src/main/resources/db/migration/V7__data_masking.sql @@ -2,7 +2,8 @@ create table policy ( id bigint not null primary key, name varchar(255), - masking_type varchar(255) + masking_type varchar(255), + apply_to_all_resources boolean ); create table policy_fields ( @@ -11,14 +12,18 @@ create table policy_fields field varchar(255) ); -create table policy_resources +create table policy_resource ( - policy_id bigint not null - constraint fkk7ao2gxpd7peapqwu27wj9dng references policy, - resources varchar(255) + id bigint not null primary key, + topic varchar(255), + cluster_id bigint + constraint fk58aualhiqf7wqmxjo5nwgnqn9 references cluster, + policy_id bigint + constraint fkltj5s392jlbr2mshmoyn3vd2a references policy ); CREATE SEQUENCE SEQ_POLICY MINVALUE 1 START WITH 1 INCREMENT BY 1 CACHE 10; +CREATE SEQUENCE SEQ_POLICY_RESOURCE MINVALUE 1 START WITH 1 INCREMENT BY 1 CACHE 10; insert into system_function(id, name, label, function_group) VALUES (nextval('SEQ_SYSTEM_FUNCTION'), 'POLICY_LIST', 'Policies list', 'DATA_MASKING'), diff --git a/kouncil-frontend/libs/feat-data-masking/src/lib/policies/policies.component.ts b/kouncil-frontend/libs/feat-data-masking/src/lib/policies/policies.component.ts index 6c99730c..1c2f01e8 100644 --- a/kouncil-frontend/libs/feat-data-masking/src/lib/policies/policies.component.ts +++ b/kouncil-frontend/libs/feat-data-masking/src/lib/policies/policies.component.ts @@ -88,16 +88,7 @@ export class PoliciesComponent extends AbstractTableComponent implements OnInit, sortable: true, draggable: true, width: 300, - valueFormatter: (value: MaskingType): string => { - switch (value) { - case MaskingType.ALL: - return 'Mask all'; - case MaskingType.FIRST_5: - return 'Hide first 5 letters'; - case MaskingType.LAST_5: - return 'Hide last 5 letters'; - } - } + valueFormatter: (value: MaskingType): string => MaskingType[value] }, { name: 'Fields', diff --git a/kouncil-frontend/libs/feat-data-masking/src/lib/policy.model.ts b/kouncil-frontend/libs/feat-data-masking/src/lib/policy.model.ts index c6fbc22e..028d21c8 100644 --- a/kouncil-frontend/libs/feat-data-masking/src/lib/policy.model.ts +++ b/kouncil-frontend/libs/feat-data-masking/src/lib/policy.model.ts @@ -5,7 +5,7 @@ export class Policy { } export enum MaskingType { - ALL = 'ALL', - FIRST_5 = 'FIRST_5', - LAST_5 = 'LAST_5' + ALL = 'Hide all', + FIRST_5 = 'Hide first 5 signs', + LAST_5 = 'Hide last 5 signs' }