-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Piotr Belke
authored and
Piotr Belke
committed
Oct 14, 2024
1 parent
9a8f41b
commit 3cd182a
Showing
48 changed files
with
1,184 additions
and
60 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
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
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
36 changes: 36 additions & 0 deletions
36
...cil-backend/src/main/java/com/consdata/kouncil/datamasking/converter/PolicyConverter.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,36 @@ | ||
package com.consdata.kouncil.datamasking.converter; | ||
|
||
import com.consdata.kouncil.datamasking.dto.PolicyDto; | ||
import com.consdata.kouncil.model.datamasking.Policy; | ||
import com.consdata.kouncil.model.datamasking.PolicyField; | ||
import com.consdata.kouncil.model.datamasking.PolicyResource; | ||
import java.util.HashSet; | ||
import lombok.AccessLevel; | ||
import lombok.NoArgsConstructor; | ||
import org.springframework.beans.BeanUtils; | ||
|
||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
public final class PolicyConverter { | ||
|
||
public static Policy convert(PolicyDto policyDto) { | ||
Policy policy = new Policy(); | ||
BeanUtils.copyProperties(policyDto, policy); | ||
|
||
policy.setFields(new HashSet<>()); | ||
|
||
policyDto.getFields().forEach(field -> { | ||
PolicyField policyField = new PolicyField(); | ||
BeanUtils.copyProperties(field, policyField); | ||
policy.getFields().add(policyField); | ||
}); | ||
|
||
policy.setResources(new HashSet<>()); | ||
policyDto.getResources().forEach(resource -> { | ||
PolicyResource policyResource = new PolicyResource(); | ||
BeanUtils.copyProperties(resource, policyResource); | ||
policy.getResources().add(policyResource); | ||
}); | ||
|
||
return policy; | ||
} | ||
} |
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
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
12 changes: 12 additions & 0 deletions
12
kouncil-backend/src/main/java/com/consdata/kouncil/datamasking/dto/PolicyFieldDto.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,12 @@ | ||
package com.consdata.kouncil.datamasking.dto; | ||
|
||
import com.consdata.kouncil.model.datamasking.FieldFindRule; | ||
import lombok.Data; | ||
|
||
@Data | ||
public class PolicyFieldDto { | ||
|
||
private Long id; | ||
private FieldFindRule findRule; | ||
private String field; | ||
} |
3 changes: 1 addition & 2 deletions
3
kouncil-backend/src/main/java/com/consdata/kouncil/datamasking/dto/PolicyResourceDto.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 |
---|---|---|
@@ -1,12 +1,11 @@ | ||
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 Long cluster; | ||
private String topic; | ||
} |
7 changes: 7 additions & 0 deletions
7
kouncil-backend/src/main/java/com/consdata/kouncil/model/datamasking/FieldFindRule.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,7 @@ | ||
package com.consdata.kouncil.model.datamasking; | ||
|
||
public enum FieldFindRule { | ||
|
||
ANY_LEVEL, | ||
EXACT_PATH | ||
} |
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
40 changes: 40 additions & 0 deletions
40
kouncil-backend/src/main/java/com/consdata/kouncil/model/datamasking/PolicyField.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,40 @@ | ||
package com.consdata.kouncil.model.datamasking; | ||
|
||
import javax.persistence.CascadeType; | ||
import javax.persistence.Column; | ||
import javax.persistence.Entity; | ||
import javax.persistence.EnumType; | ||
import javax.persistence.Enumerated; | ||
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_FIELD") | ||
@Getter | ||
@Setter | ||
public class PolicyField { | ||
|
||
@Id | ||
@Column(name = "ID") | ||
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQ_POLICY_FIELD_GEN") | ||
@SequenceGenerator(name = "SEQ_POLICY_FIELD_GEN", sequenceName = "SEQ_POLICY_FIELD", initialValue = 1, allocationSize = 1) | ||
private Long id; | ||
|
||
@Column(name = "FIELD") | ||
private String field; | ||
|
||
@Column(name = "FIND_RULE") | ||
@Enumerated(EnumType.STRING) | ||
private FieldFindRule findRule; | ||
|
||
@ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE}) | ||
@JoinColumn(name = "POLICY_ID", insertable = false, updatable = false) | ||
private Policy policy; | ||
} |
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
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
55 changes: 55 additions & 0 deletions
55
...backend/src/test/java/com/consdata/kouncil/datamasking/converter/PolicyConverterTest.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,55 @@ | ||
package com.consdata.kouncil.datamasking.converter; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.jupiter.api.Assertions.assertAll; | ||
|
||
import com.consdata.kouncil.datamasking.dto.PolicyDto; | ||
import com.consdata.kouncil.datamasking.dto.PolicyFieldDto; | ||
import com.consdata.kouncil.datamasking.dto.PolicyResourceDto; | ||
import com.consdata.kouncil.model.datamasking.MaskingType; | ||
import com.consdata.kouncil.model.datamasking.Policy; | ||
import java.util.HashSet; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class PolicyConverterTest { | ||
|
||
@Test | ||
void should_convert_to_entity() { | ||
//given | ||
PolicyDto policyDto = new PolicyDto(); | ||
policyDto.setId(1L); | ||
policyDto.setName("test"); | ||
policyDto.setApplyToAllResources(false); | ||
policyDto.setMaskingType(MaskingType.ALL); | ||
policyDto.setFields(new HashSet<>()); | ||
policyDto.getFields().add(createField(1L)); | ||
policyDto.getFields().add(createField(2L)); | ||
policyDto.getFields().add(createField(3L)); | ||
policyDto.setResources(new HashSet<>()); | ||
policyDto.getResources().add(createResource(1L)); | ||
policyDto.getResources().add(createResource(2L)); | ||
//when | ||
Policy policy = PolicyConverter.convert(policyDto); | ||
//then | ||
assertAll( | ||
() -> assertThat(policy.getId()).isEqualTo(policyDto.getId()), | ||
() -> assertThat(policy.getName()).isEqualTo(policyDto.getName()), | ||
() -> assertThat(policy.getApplyToAllResources()).isEqualTo(policyDto.getApplyToAllResources()), | ||
() -> assertThat(policy.getMaskingType()).isEqualTo(policyDto.getMaskingType()), | ||
() -> assertThat(policy.getFields()).hasSize(policyDto.getFields().size()), | ||
() -> assertThat(policy.getResources()).hasSize(policyDto.getResources().size()) | ||
); | ||
} | ||
|
||
private PolicyResourceDto createResource(long id) { | ||
PolicyResourceDto policyResource = new PolicyResourceDto(); | ||
policyResource.setId(id); | ||
return policyResource; | ||
} | ||
|
||
private PolicyFieldDto createField(long id) { | ||
PolicyFieldDto policyField = new PolicyFieldDto(); | ||
policyField.setId(id); | ||
return policyField; | ||
} | ||
} |
Oops, something went wrong.