-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Util classes for building and validating schema + leia-common #11
Merged
Merged
Changes from 12 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
981f62a
adds utils for building schemaAttributes and validation of json
18dd4bb
Merge branch 'master' of github.com:abhigun/leia into abhishek/schema…
41ed9fa
version bump
ae6eeff
moves qualifiers to set on attribute
5da6e95
adds leia-common module and moved all validation utils
e5aa303
code refactoring of all utils
8ee39be
adds support for plain objects, bug fixes and tests
24444eb
adds support for plain objects, bug fixes and tests
c989e42
pom changes and change log addition
8961292
review changes
0a5fd98
adding leia-common dependency to client
5ba56cb
code refactoring
279ad6c
review changes and changelog additions
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
~ Copyright (c) 2024. Koushik R <[email protected]>. | ||
~ | ||
~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
~ you may not use this file except in compliance with the License. | ||
~ You may obtain a copy of the License at | ||
~ | ||
~ http://www.apache.org/licenses/LICENSE-2.0 | ||
~ | ||
~ Unless required by applicable law or agreed to in writing, software | ||
~ distributed under the License is distributed on an "AS IS" BASIS, | ||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
~ See the License for the specific language governing permissions and | ||
~ limitations under the License. | ||
--> | ||
|
||
|
||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>com.grookage.leia</groupId> | ||
<artifactId>leia-parent</artifactId> | ||
<version>0.0.1-RC7</version> | ||
<relativePath>../leia-parent</relativePath> | ||
</parent> | ||
|
||
<artifactId>leia-common</artifactId> | ||
|
||
<properties> | ||
<lang3.version>3.11</lang3.version> | ||
<maven.deploy.skip>false</maven.deploy.skip> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<artifactId>lombok</artifactId> | ||
<groupId>org.projectlombok</groupId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.apache.commons</groupId> | ||
<artifactId>commons-lang3</artifactId> | ||
<version>${lang3.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<artifactId>junit-jupiter</artifactId> | ||
<groupId>org.junit.jupiter</groupId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.grookage.leia</groupId> | ||
<artifactId>leia-models</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<artifactId>mockito-core</artifactId> | ||
<groupId>org.mockito</groupId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<artifactId>mockito-junit-jupiter</artifactId> | ||
<groupId>org.mockito</groupId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<artifactId>mockito-inline</artifactId> | ||
<groupId>org.mockito</groupId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.grookage.leia</groupId> | ||
<artifactId>leia-models</artifactId> | ||
<type>test-jar</type> | ||
<exclusions> | ||
<exclusion> | ||
<artifactId>*</artifactId> | ||
<groupId>*</groupId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
|
||
|
||
</dependencies> | ||
|
||
</project> |
44 changes: 44 additions & 0 deletions
44
leia-common/src/main/java/com/grookage/leia/common/builder/SchemaBuilder.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,44 @@ | ||
/* | ||
* Copyright (c) 2024. Koushik R <[email protected]>. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.grookage.leia.common.builder; | ||
|
||
import com.grookage.leia.common.utils.SchemaAttributeUtils; | ||
import com.grookage.leia.models.annotations.SchemaDefinition; | ||
import com.grookage.leia.models.schema.ingestion.CreateSchemaRequest; | ||
import lombok.experimental.UtilityClass; | ||
|
||
import java.util.Objects; | ||
import java.util.Optional; | ||
|
||
@UtilityClass | ||
public class SchemaBuilder { | ||
public Optional<CreateSchemaRequest> buildSchemaRequest(final Class<?> klass) { | ||
if (Objects.isNull(klass) || !klass.isAnnotationPresent(SchemaDefinition.class)) { | ||
return Optional.empty(); | ||
} | ||
final var schemaDefinition = klass.getAnnotation(SchemaDefinition.class); | ||
return Optional.of(CreateSchemaRequest.builder() | ||
.schemaName(schemaDefinition.name()) | ||
.namespace(schemaDefinition.namespace()) | ||
.description(schemaDefinition.description()) | ||
.schemaType(schemaDefinition.type()) | ||
.validationType(schemaDefinition.validation()) | ||
.attributes(SchemaAttributeUtils.getSchemaAttributes(klass)) | ||
.build() | ||
); | ||
} | ||
} |
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
84 changes: 84 additions & 0 deletions
84
leia-common/src/main/java/com/grookage/leia/common/utils/QualifierUtils.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,84 @@ | ||
/* | ||
* Copyright (c) 2024. Koushik R <[email protected]>. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.grookage.leia.common.utils; | ||
|
||
import com.grookage.leia.models.annotations.attribute.qualifiers.Encrypted; | ||
import com.grookage.leia.models.annotations.attribute.qualifiers.PII; | ||
import com.grookage.leia.models.annotations.attribute.qualifiers.ShortLived; | ||
import com.grookage.leia.models.qualifiers.EncryptedQualifier; | ||
import com.grookage.leia.models.qualifiers.PIIQualifier; | ||
import com.grookage.leia.models.qualifiers.QualifierInfo; | ||
import com.grookage.leia.models.qualifiers.QualifierType; | ||
import com.grookage.leia.models.qualifiers.ShortLivedQualifier; | ||
import lombok.experimental.UtilityClass; | ||
|
||
import java.lang.reflect.Field; | ||
import java.lang.reflect.Type; | ||
import java.util.HashSet; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
import java.util.Set; | ||
|
||
@UtilityClass | ||
public class QualifierUtils { | ||
public Optional<QualifierInfo> filter(final Set<QualifierInfo> qualifiers, | ||
final QualifierType type) { | ||
if (Objects.isNull(qualifiers)) { | ||
return Optional.empty(); | ||
} | ||
return qualifiers.stream() | ||
.filter(qualifierInfo -> qualifierInfo.getType().equals(type)) | ||
.findFirst(); | ||
} | ||
|
||
public Set<QualifierInfo> getQualifierInfo(final Type type) { | ||
if (type instanceof Class<?> klass) { | ||
return getQualifierInfo(klass); | ||
} | ||
return new HashSet<>(); | ||
} | ||
|
||
public Set<QualifierInfo> getQualifierInfo(final Field field) { | ||
koushikr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Set<QualifierInfo> qualifiers = new HashSet<>(); | ||
if (field.isAnnotationPresent(Encrypted.class)) { | ||
qualifiers.add(new EncryptedQualifier()); | ||
} | ||
if (field.isAnnotationPresent(PII.class)) { | ||
qualifiers.add(new PIIQualifier()); | ||
} | ||
if (field.isAnnotationPresent(ShortLived.class)) { | ||
final var shortLived = field.getAnnotation(ShortLived.class); | ||
qualifiers.add(new ShortLivedQualifier(shortLived.ttlSeconds())); | ||
} | ||
return qualifiers; | ||
} | ||
|
||
public Set<QualifierInfo> getQualifierInfo(final Class<?> klass) { | ||
koushikr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Set<QualifierInfo> qualifiers = new HashSet<>(); | ||
if (klass.isAnnotationPresent(Encrypted.class)) { | ||
qualifiers.add(new EncryptedQualifier()); | ||
} | ||
if (klass.isAnnotationPresent(PII.class)) { | ||
qualifiers.add(new PIIQualifier()); | ||
} | ||
if (klass.isAnnotationPresent(ShortLived.class)) { | ||
final var shortLived = klass.getAnnotation(ShortLived.class); | ||
qualifiers.add(new ShortLivedQualifier(shortLived.ttlSeconds())); | ||
} | ||
return qualifiers; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same, rename this to getQualifer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, changed it to
getQualifiers