-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
7 changed files
with
291 additions
and
13 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
103 changes: 103 additions & 0 deletions
103
...ain/java/ai/stapi/graphoperations/graphLoader/graphLoaderOgm/GraphLoaderOGMValidator.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,103 @@ | ||
package ai.stapi.graphoperations.graphLoader.graphLoaderOgm; | ||
|
||
import ai.stapi.graphoperations.graphLanguage.graphDescription.GraphDescription; | ||
import ai.stapi.graphoperations.graphLanguage.graphDescription.specific.positive.*; | ||
import ai.stapi.graphoperations.graphLoader.graphLoaderOgm.exception.GraphLoaderOGMIsInvalid; | ||
import ai.stapi.graphoperations.objectGraphLanguage.*; | ||
|
||
public class GraphLoaderOGMValidator { | ||
|
||
private GraphLoaderOGMValidator() { | ||
} | ||
|
||
public static void validate(ObjectGraphMapping objectGraphMapping) { | ||
if (objectGraphMapping instanceof LeafObjectGraphMapping leaf) { | ||
GraphLoaderOGMValidator.validateLeaf(leaf); | ||
return; | ||
} | ||
if (objectGraphMapping instanceof ListObjectGraphMapping list) { | ||
GraphLoaderOGMValidator.validateList(list); | ||
return; | ||
} | ||
if (objectGraphMapping instanceof ObjectObjectGraphMapping object) { | ||
GraphLoaderOGMValidator.validateObject(object); | ||
return; | ||
} | ||
if (objectGraphMapping instanceof ReferenceObjectGraphMapping reference) { | ||
GraphLoaderOGMValidator.validateReference(reference); | ||
return; | ||
} | ||
if (objectGraphMapping instanceof InterfaceObjectGraphMapping inter) { | ||
GraphLoaderOGMValidator.validateInterface(inter); | ||
return; | ||
} | ||
throw GraphLoaderOGMIsInvalid.becauseUnexpectedOGMEncountered(objectGraphMapping); | ||
} | ||
|
||
private static void validateLeaf(LeafObjectGraphMapping leaf) { | ||
var graphDescription = leaf.getGraphDescription(); | ||
if (graphDescription instanceof UuidIdentityDescription uuid) { | ||
GraphLoaderOGMValidator.validateUuid(uuid); | ||
return; | ||
} | ||
if (graphDescription instanceof AbstractAttributeDescription attribute) { | ||
GraphLoaderOGMValidator.validateLeafAttribute(attribute); | ||
return; | ||
} | ||
throw GraphLoaderOGMIsInvalid.becauseLeafOGMHasUnexpectedGraphDescription(leaf); | ||
} | ||
|
||
private static void validateList(ListObjectGraphMapping list) { | ||
var graphDescription = list.getGraphDescription(); | ||
var childOGM = list.getChildObjectGraphMapping(); | ||
if (graphDescription instanceof AbstractAttributeDescription attribute) { | ||
GraphLoaderOGMValidator.validateListAttribute(attribute); | ||
if (childOGM instanceof LeafObjectGraphMapping leaf) { | ||
var childDescription = leaf.getGraphDescription(); | ||
if (childDescription instanceof NullGraphDescription) { | ||
return; | ||
} | ||
if (childDescription instanceof AbstractAttributeValueDescription) { | ||
return; | ||
} | ||
throw GraphLoaderOGMIsInvalid.becauseListChildLeafOgmHadUnexpectedGraphDescription(childDescription); | ||
} | ||
throw GraphLoaderOGMIsInvalid.becauseListOGMContainedAttributeDescriptionButNotChildLeafOGM(childOGM); | ||
} | ||
if (graphDescription instanceof NullGraphDescription) { | ||
if ( | ||
childOGM instanceof ReferenceObjectGraphMapping | ||
|| childOGM instanceof InterfaceObjectGraphMapping | ||
|| childOGM instanceof ObjectObjectGraphMapping | ||
) { | ||
GraphLoaderOGMValidator.validate(childOGM); | ||
return; | ||
} | ||
} | ||
throw GraphLoaderOGMIsInvalid.becauseListOGMHadUnexpectedGraphDescription(graphDescription); | ||
} | ||
|
||
private static void validateObject(ObjectObjectGraphMapping object) { | ||
|
||
} | ||
|
||
private static void validateReference(ReferenceObjectGraphMapping reference) { | ||
|
||
} | ||
|
||
private static void validateInterface(InterfaceObjectGraphMapping inter) { | ||
|
||
} | ||
|
||
private static void validateUuid(UuidIdentityDescription uuidIdentityDescription) { | ||
|
||
} | ||
|
||
private static void validateLeafAttribute(AbstractAttributeDescription attribute) { | ||
|
||
} | ||
|
||
private static void validateListAttribute(AbstractAttributeDescription attribute) { | ||
|
||
} | ||
} |
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
71 changes: 71 additions & 0 deletions
71
...i/stapi/graphoperations/graphLoader/graphLoaderOgm/exception/GraphLoaderOGMIsInvalid.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,71 @@ | ||
package ai.stapi.graphoperations.graphLoader.graphLoaderOgm.exception; | ||
|
||
import ai.stapi.graphoperations.graphLanguage.graphDescription.GraphDescription; | ||
import ai.stapi.graphoperations.objectGraphLanguage.LeafObjectGraphMapping; | ||
import ai.stapi.graphoperations.objectGraphLanguage.ObjectGraphMapping; | ||
import ai.stapi.utils.Stringifier; | ||
|
||
public class GraphLoaderOGMIsInvalid extends RuntimeException { | ||
|
||
private GraphLoaderOGMIsInvalid(String becauseMessage) { | ||
super("OGM to be used in Graph Loader is invalid, because " + becauseMessage); | ||
} | ||
|
||
public static GraphLoaderOGMIsInvalid becauseLeafOGMHasUnexpectedGraphDescription( | ||
LeafObjectGraphMapping leafObjectGraphMapping | ||
) { | ||
return new GraphLoaderOGMIsInvalid( | ||
String.format( | ||
"leaf OGM has unexpected graph description. " + | ||
"It should contain either UUID or Attribute description.%nLeaf OGM: '%s'", | ||
Stringifier.convertToString(leafObjectGraphMapping) | ||
) | ||
); | ||
} | ||
|
||
public static GraphLoaderOGMIsInvalid becauseUnexpectedOGMEncountered( | ||
ObjectGraphMapping invalidOGM | ||
) { | ||
return new GraphLoaderOGMIsInvalid( | ||
String.format( | ||
"unexpected OGM encountered. There should only be Leaf, List, Object, Reference, Interface OGMs." + | ||
"%nInvalid OGM: '%s'", | ||
Stringifier.convertToString(invalidOGM) | ||
) | ||
); | ||
} | ||
|
||
public static GraphLoaderOGMIsInvalid becauseListOGMContainedAttributeDescriptionButNotChildLeafOGM( | ||
ObjectGraphMapping invalidChildOGM | ||
) { | ||
return new GraphLoaderOGMIsInvalid( | ||
String.format( | ||
"list OGM contained attribute description, but child leaf OGM wasnt leaf." + | ||
"%nInvalid child OGM: '%s'", | ||
Stringifier.convertToString(invalidChildOGM) | ||
) | ||
); | ||
} | ||
|
||
public static GraphLoaderOGMIsInvalid becauseListChildLeafOgmHadUnexpectedGraphDescription( | ||
GraphDescription childDescription | ||
) { | ||
return new GraphLoaderOGMIsInvalid( | ||
String.format( | ||
"leaf OGM inside list OGM had unexpected graph description. It should either be null or attribute value." | ||
+ "%nInvalid description: '%s'", | ||
Stringifier.convertToString(childDescription) | ||
) | ||
); | ||
} | ||
|
||
public static GraphLoaderOGMIsInvalid becauseListOGMHadUnexpectedGraphDescription(GraphDescription graphDescription) { | ||
return new GraphLoaderOGMIsInvalid( | ||
String.format( | ||
"list OGM had unexpected graph description. It should either be null or attribute description." | ||
+ "%nInvalid description: '%s'", | ||
Stringifier.convertToString(graphDescription) | ||
) | ||
); | ||
} | ||
} |
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
67 changes: 67 additions & 0 deletions
67
...t/java/ai/stapi/graphoperations/graphLoader/graphLoaderOgm/GraphLoaderOgmFactoryTest.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,67 @@ | ||
package ai.stapi.graphoperations.graphLoader.graphLoaderOgm; | ||
|
||
import ai.stapi.graphoperations.fixtures.AttributeTypes; | ||
import ai.stapi.graphoperations.fixtures.ComplexJoinedGraphFixturesProvider; | ||
import ai.stapi.graphoperations.graphLanguage.graphDescription.specific.positive.EdgeDescriptionParameters; | ||
import ai.stapi.graphoperations.graphLanguage.graphDescription.specific.positive.NodeDescription; | ||
import ai.stapi.graphoperations.graphLanguage.graphDescription.specific.positive.NodeDescriptionParameters; | ||
import ai.stapi.graphoperations.graphLanguage.graphDescription.specific.positive.OutgoingEdgeDescription; | ||
import ai.stapi.graphoperations.graphLanguage.graphDescription.specific.query.AttributeQueryDescription; | ||
import ai.stapi.graphoperations.graphLanguage.graphDescription.specific.query.NodeQueryGraphDescription; | ||
import ai.stapi.graphoperations.graphLanguage.graphDescription.specific.query.OutgoingEdgeQueryDescription; | ||
import ai.stapi.graphoperations.graphLoader.search.SearchQueryParameters; | ||
import ai.stapi.graphoperations.graphLoader.search.sortOption.DescendingSortOption; | ||
import ai.stapi.test.integration.IntegrationTestCase; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
class GraphLoaderOgmFactoryTest extends IntegrationTestCase { | ||
|
||
@Autowired | ||
private GraphLoaderOgmFactory graphLoaderOgmFactory; | ||
|
||
@Test | ||
void itCanMapComplexGraphDescription() { | ||
var sort = new DescendingSortOption( | ||
new OutgoingEdgeDescription( | ||
new EdgeDescriptionParameters(ComplexJoinedGraphFixturesProvider.EDGE_TYPE_1), | ||
new NodeDescription( | ||
new NodeDescriptionParameters(ComplexJoinedGraphFixturesProvider.NODE_TYPE_2), | ||
new OutgoingEdgeDescription( | ||
new EdgeDescriptionParameters(ComplexJoinedGraphFixturesProvider.EDGE_TYPE_2), | ||
new NodeDescription( | ||
new NodeDescriptionParameters(ComplexJoinedGraphFixturesProvider.NODE_TYPE_3), | ||
new AttributeQueryDescription(AttributeTypes.EXAMPLE_QUANTITY) | ||
) | ||
) | ||
) | ||
) | ||
); | ||
var searchQueryParameters = SearchQueryParameters.builder().addSortOption(sort).build(); | ||
var graphDescription = new NodeQueryGraphDescription( | ||
new NodeDescriptionParameters(ComplexJoinedGraphFixturesProvider.NODE_TYPE_1), | ||
searchQueryParameters, | ||
new AttributeQueryDescription(AttributeTypes.EXAMPLE_NAME), | ||
new OutgoingEdgeQueryDescription( | ||
new EdgeDescriptionParameters(ComplexJoinedGraphFixturesProvider.EDGE_TYPE_1), | ||
SearchQueryParameters.from(), | ||
new NodeQueryGraphDescription( | ||
new NodeDescriptionParameters(ComplexJoinedGraphFixturesProvider.NODE_TYPE_2), | ||
SearchQueryParameters.from(), | ||
new OutgoingEdgeQueryDescription( | ||
new EdgeDescriptionParameters(ComplexJoinedGraphFixturesProvider.EDGE_TYPE_2), | ||
new SearchQueryParameters(), | ||
new NodeQueryGraphDescription( | ||
new NodeDescriptionParameters(ComplexJoinedGraphFixturesProvider.NODE_TYPE_3), | ||
new AttributeQueryDescription(AttributeTypes.EXAMPLE_NAME), | ||
new AttributeQueryDescription(AttributeTypes.EXAMPLE_QUANTITY), | ||
new AttributeQueryDescription(AttributeTypes.EXAMPLE_STRING_ATTRIBUTE) | ||
) | ||
) | ||
) | ||
) | ||
); | ||
var actual = this.graphLoaderOgmFactory.create(graphDescription); | ||
this.thenObjectApproved(actual); | ||
} | ||
} |