-
Notifications
You must be signed in to change notification settings - Fork 228
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Validators for JSON and Graphql Exporter
- Loading branch information
Showing
10 changed files
with
248 additions
and
34 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
.../main/java/com/yahoo/elide/async/export/validator/NoRelationshipsProjectionValidator.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,33 @@ | ||
/* | ||
* Copyright 2021, Yahoo Inc. | ||
* Licensed under the Apache License, Version 2.0 | ||
* See LICENSE file in project root for terms. | ||
*/ | ||
package com.yahoo.elide.async.export.validator; | ||
|
||
import com.yahoo.elide.core.exceptions.BadRequestException; | ||
import com.yahoo.elide.core.request.EntityProjection; | ||
|
||
import java.util.Collection; | ||
|
||
/** | ||
* Validates none of the projections have relationships. | ||
*/ | ||
public class NoRelationshipsProjectionValidator implements Validator { | ||
|
||
private static final Validator INSTANCE = new NoRelationshipsProjectionValidator(); | ||
|
||
public static Validator getInstance() { | ||
return INSTANCE; | ||
} | ||
|
||
@Override | ||
public void validateProjection(Collection<EntityProjection> projections) { | ||
for (EntityProjection projection : projections) { | ||
if (!projection.getRelationships().isEmpty()) { | ||
throw new BadRequestException( | ||
"Export is not supported for Query that requires traversing Relationships."); | ||
} | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...c/src/main/java/com/yahoo/elide/async/export/validator/SingleRootProjectionValidator.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,30 @@ | ||
/* | ||
* Copyright 2021, Yahoo Inc. | ||
* Licensed under the Apache License, Version 2.0 | ||
* See LICENSE file in project root for terms. | ||
*/ | ||
package com.yahoo.elide.async.export.validator; | ||
|
||
import com.yahoo.elide.core.exceptions.BadRequestException; | ||
import com.yahoo.elide.core.request.EntityProjection; | ||
|
||
import java.util.Collection; | ||
|
||
/** | ||
* Validates each projection in collection have one projection only. | ||
*/ | ||
public class SingleRootProjectionValidator implements Validator { | ||
|
||
private static final Validator INSTANCE = new SingleRootProjectionValidator(); | ||
|
||
public static Validator getInstance() { | ||
return INSTANCE; | ||
} | ||
|
||
@Override | ||
public void validateProjection(Collection<EntityProjection> projections) { | ||
if (projections.size() != 1) { | ||
throw new BadRequestException("Export is only supported for single Query with one root projection."); | ||
} | ||
} | ||
} |
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
24 changes: 24 additions & 0 deletions
24
elide-async/src/test/java/com/yahoo/elide/async/models/ArtifactGroup.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 @@ | ||
/* | ||
* Copyright 2021, Verizon Media. | ||
* Licensed under the Apache License, Version 2.0 | ||
* See LICENSE file in project root for terms. | ||
*/ | ||
package com.yahoo.elide.async.models; | ||
|
||
import com.yahoo.elide.annotation.Include; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import javax.persistence.Entity; | ||
import javax.persistence.Id; | ||
import javax.persistence.OneToMany; | ||
|
||
@Include(rootLevel = true, type = "group") | ||
@Entity | ||
public class ArtifactGroup { | ||
@Id | ||
private String name = ""; | ||
|
||
@OneToMany(mappedBy = "group") | ||
private List<ArtifactProduct> products = new ArrayList<>(); | ||
} |
22 changes: 22 additions & 0 deletions
22
elide-async/src/test/java/com/yahoo/elide/async/models/ArtifactProduct.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,22 @@ | ||
/* | ||
* Copyright 2021, Verizon Media. | ||
* Licensed under the Apache License, Version 2.0 | ||
* See LICENSE file in project root for terms. | ||
*/ | ||
package com.yahoo.elide.async.models; | ||
|
||
import com.yahoo.elide.annotation.Include; | ||
|
||
import javax.persistence.Entity; | ||
import javax.persistence.Id; | ||
import javax.persistence.ManyToOne; | ||
|
||
@Include(type = "product") | ||
@Entity | ||
public class ArtifactProduct { | ||
@Id | ||
private String name = ""; | ||
|
||
@ManyToOne | ||
private ArtifactGroup group = null; | ||
} |
Oops, something went wrong.