Skip to content

Commit

Permalink
make GmaEntitiesAnnotationAllowList nullable (#321)
Browse files Browse the repository at this point in the history
* make allowlist nullable

* add unit test
  • Loading branch information
ybz1013 authored Nov 27, 2023
1 parent 43e97e6 commit 39ab63f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@
import java.util.Map;
import java.util.Optional;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;


public class GmaAnnotationParser {
private static final String GMA = "gma";

private final GmaEntitiesAnnotationAllowList _gmaEntitiesAnnotationAllowList;

public GmaAnnotationParser(@Nonnull GmaEntitiesAnnotationAllowList gmaEntitiesAnnotationAllowList) {
public GmaAnnotationParser(@Nullable GmaEntitiesAnnotationAllowList gmaEntitiesAnnotationAllowList) {
_gmaEntitiesAnnotationAllowList = gmaEntitiesAnnotationAllowList;
}

Expand Down Expand Up @@ -59,7 +60,7 @@ public Optional<GmaAnnotation> parse(@Nonnull DataSchema schema) {
Joiner.on('\n').join(result.getMessages())));
}

if (gmaAnnotation.hasAspect() && gmaAnnotation.getAspect().hasEntities()) {
if (_gmaEntitiesAnnotationAllowList != null && gmaAnnotation.hasAspect() && gmaAnnotation.getAspect().hasEntities()) {
_gmaEntitiesAnnotationAllowList.check(schema, gmaAnnotation.getAspect());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,13 @@ public void parseCommonAspectDisallowed() {
GmaEntitiesAnnotationAllowList.AnnotationNotAllowedException.class)
.hasMessage("@gma.aspect.entities not allowed on com.linkedin.testing.CommonAspect");
}

@Test
public void parseCommonAspectAllowedWithNullAllowList() {
final Optional<GmaAnnotation> gma = new GmaAnnotationParser(null).parse(
(RecordDataSchema) DataTemplateUtil.getSchema(CommonAspect.class));
assertThat(gma).contains(new GmaAnnotation().setAspect(new AspectAnnotation().setEntities(
new AspectEntityAnnotationArray(new AspectEntityAnnotation().setUrn("com.linkedin.testing.FooUrn"),
new AspectEntityAnnotation().setUrn("com.linkedin.testing.BarUrn")))));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.util.Optional;
import java.util.stream.Collectors;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import lombok.extern.slf4j.Slf4j;


Expand All @@ -36,7 +37,7 @@ private SchemaAnnotationRetriever(@Nonnull String resolverPath, @Nonnull GmaAnno
_baseNamespace = baseNamespace;
}

public SchemaAnnotationRetriever(@Nonnull String resolverPath, @Nonnull GmaEntitiesAnnotationAllowList allowList,
public SchemaAnnotationRetriever(@Nonnull String resolverPath, @Nullable GmaEntitiesAnnotationAllowList allowList,
String baseNamespace) {
this(resolverPath, new GmaAnnotationParser(allowList), baseNamespace);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.Collection;
import java.util.stream.Collectors;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.rythmengine.Rythm;


Expand All @@ -31,7 +32,7 @@ private void generate(@Nonnull Collection<String> sourcePaths, @Nonnull String g
* @throws IOException exception on input error
*/
public void generate(@Nonnull Collection<String> resolverPaths, @Nonnull Collection<String> sourcePaths,
@Nonnull String generatedFileOutput, @Nonnull GmaEntitiesAnnotationAllowList allowList) throws IOException {
@Nonnull String generatedFileOutput, @Nullable GmaEntitiesAnnotationAllowList allowList) throws IOException {
generate(sourcePaths, generatedFileOutput,
new SchemaAnnotationRetriever(resolverPaths.stream().collect(Collectors.joining(":")), allowList, null));
}
Expand Down

0 comments on commit 39ab63f

Please sign in to comment.