index
int64
repo_id
string
file_path
string
content
string
0
java-sources/ai/stapi/base-test/0.3.2/ai/stapi/test
java-sources/ai/stapi/base-test/0.3.2/ai/stapi/test/integration/AbstractIntegrationTestCase.java
package ai.stapi.test.integration; public class AbstractIntegrationTestCase extends SpringBootTestCase { }
0
java-sources/ai/stapi/base-test/0.3.2/ai/stapi/test
java-sources/ai/stapi/base-test/0.3.2/ai/stapi/test/integration/IntegrationTestCase.java
package ai.stapi.test.integration; import org.junit.jupiter.api.Tag; import org.springframework.context.annotation.Import; @Tag("integration") @Import(IntegrationTestConfig.class) public abstract class IntegrationTestCase extends AbstractIntegrationTestCase { }
0
java-sources/ai/stapi/base-test/0.3.2/ai/stapi/test
java-sources/ai/stapi/base-test/0.3.2/ai/stapi/test/integration/IntegrationTestConfig.java
package ai.stapi.test.integration; import ai.stapi.schema.structureSchemaProvider.RestrictedStructureSchemaFinder; import ai.stapi.schema.structureSchemaProvider.StructureSchemaFinder; import ai.stapi.schema.structuredefinition.loader.NullStructureDefinitionLoader; import ai.stapi.schema.structuredefinition.loader.StructureDefinitionLoader; import org.springframework.boot.test.context.TestConfiguration; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Profile; @Profile("test") @TestConfiguration public class IntegrationTestConfig { @Bean public static StructureSchemaFinder structureSchemaFinder() { return new RestrictedStructureSchemaFinder(); } @Bean public static StructureDefinitionLoader structureDefinitionLoader() { return new NullStructureDefinitionLoader(); } }
0
java-sources/ai/stapi/base-test/0.3.2/ai/stapi/test
java-sources/ai/stapi/base-test/0.3.2/ai/stapi/test/integration/SpringBootTestCase.java
package ai.stapi.test.integration; import ai.stapi.test.base.AbstractUnitTestCase; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit.jupiter.SpringExtension; @ExtendWith(SpringExtension.class) @SpringBootTest() @ActiveProfiles(profiles = {"test"}) public abstract class SpringBootTestCase extends AbstractUnitTestCase { }
0
java-sources/ai/stapi/base-test/0.3.2/ai/stapi/test
java-sources/ai/stapi/base-test/0.3.2/ai/stapi/test/schemaintegration/AbstractSchemaIntegrationTestCase.java
package ai.stapi.test.schemaintegration; import ai.stapi.schema.scopeProvider.ScopeOptions; import ai.stapi.schema.scopeProvider.ScopeProvider; import ai.stapi.test.integration.AbstractIntegrationTestCase; import org.junit.jupiter.api.*; import org.springframework.beans.factory.annotation.Autowired; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; public abstract class AbstractSchemaIntegrationTestCase extends AbstractIntegrationTestCase { @Autowired private ScopeProvider scopeProvider; @BeforeAll @Order(0) public static void setTestClassScopeBeforeAll( TestInfo testInfo, @Autowired ScopeProvider scopeProvider ) { var testClass = testInfo.getTestClass(); testClass.ifPresent(clazz -> { var testScopes = AbstractSchemaIntegrationTestCase.gatherScopeAnnotations(clazz); scopeProvider.set( new ScopeOptions( testScopes, List.of("domain", "test") ) ); }); } @BeforeEach @Order(0) public void setTestClassScope(TestInfo testInfo) { var testClass = testInfo.getTestClass(); testClass.ifPresent(clazz -> { var testScopes = AbstractSchemaIntegrationTestCase.gatherScopeAnnotations(clazz); this.scopeProvider.set( new ScopeOptions( testScopes, List.of("domain", "test") ) ); }); } private static List<String> gatherScopeAnnotations(Class<?> testClazz) { if (testClazz == null) { return new ArrayList<>(); } var testScopes = new ArrayList<String>(); var parent = testClazz.getSuperclass(); testScopes.addAll(AbstractSchemaIntegrationTestCase.gatherScopeAnnotations(parent)); testScopes.addAll( Arrays.stream(testClazz.getAnnotationsByType(StructureDefinitionScope.class)) .map(StructureDefinitionScope::value) .flatMap(Arrays::stream) .collect(Collectors.toCollection(ArrayList::new)) ); return testScopes; } }
0
java-sources/ai/stapi/base-test/0.3.2/ai/stapi/test
java-sources/ai/stapi/base-test/0.3.2/ai/stapi/test/schemaintegration/SchemaIntegrationTestCase.java
package ai.stapi.test.schemaintegration; import org.junit.jupiter.api.Tag; @Tag("schema-integration") public class SchemaIntegrationTestCase extends AbstractSchemaIntegrationTestCase { }
0
java-sources/ai/stapi/base-test/0.3.2/ai/stapi/test
java-sources/ai/stapi/base-test/0.3.2/ai/stapi/test/schemaintegration/StructureDefinitionScope.java
package ai.stapi.test.schemaintegration; import java.lang.annotation.*; @Inherited @Target({ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME) public @interface StructureDefinitionScope { String[] value(); }
0
java-sources/ai/stapi/common/0.3.2/ai/stapi
java-sources/ai/stapi/common/0.3.2/ai/stapi/configuration/ObjectRendererConfiguration.java
package ai.stapi.configuration; import ai.stapi.objectRenderer.infrastructure.objectToJsonStringRenderer.ObjectToJsonStringRenderer; import ai.stapi.objectRenderer.model.GenericObjectRenderer; import ai.stapi.objectRenderer.model.ObjectRenderer; import java.util.List; import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.context.annotation.Bean; @AutoConfiguration public class ObjectRendererConfiguration { @Bean public GenericObjectRenderer genericObjectRenderer( List<ObjectRenderer> objectRenderers ) { return new GenericObjectRenderer(objectRenderers); } @Bean public ObjectToJsonStringRenderer objectToJsonStringRenderer() { return new ObjectToJsonStringRenderer(); } }
0
java-sources/ai/stapi/common/0.3.2/ai/stapi
java-sources/ai/stapi/common/0.3.2/ai/stapi/configuration/SerializationConfiguration.java
package ai.stapi.configuration; import ai.stapi.serialization.classNameProvider.GenericClassNameProvider; import ai.stapi.serialization.classNameProvider.specific.SpecificClassNameProvider; import ai.stapi.serialization.jackson.JavaTimeConfigurer; import ai.stapi.serialization.jackson.SerializableObjectConfigurer; import com.fasterxml.jackson.databind.ObjectMapper; import java.util.List; import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.context.annotation.Bean; @AutoConfiguration public class SerializationConfiguration { @Bean public GenericClassNameProvider genericClassNameProvider( List<SpecificClassNameProvider> specificClassNameProviders ) { return new GenericClassNameProvider(specificClassNameProviders); } @Bean public SerializableObjectConfigurer serializableObjectConfigurer( GenericClassNameProvider genericClassNameProvider ) { return new SerializableObjectConfigurer(genericClassNameProvider); } @Bean @ConditionalOnMissingBean public ObjectMapper objectMapper() { return new ObjectMapper(); } @Bean @ConditionalOnBean(ObjectMapper.class) public ObjectMapper commonObjectMapper( ObjectMapper objectMapper, SerializableObjectConfigurer serializableObjectConfigurer ) { serializableObjectConfigurer.configure(objectMapper); JavaTimeConfigurer.configureJavaTimeModule(objectMapper); return objectMapper; } }
0
java-sources/ai/stapi/common/0.3.2/ai/stapi
java-sources/ai/stapi/common/0.3.2/ai/stapi/identity/UniqueIdentifier.java
package ai.stapi.identity; import java.io.Serializable; import java.util.Objects; import org.jetbrains.annotations.NotNull; public class UniqueIdentifier implements Comparable<UniqueIdentifier>, Serializable { private String id; protected UniqueIdentifier() { } public UniqueIdentifier(String id) { this.id = id; } public static UniqueIdentifier fromString(String string) { return new UniqueIdentifier(string); } @Override public boolean equals(Object o) { if (this == o) { return true; } if (!(o instanceof UniqueIdentifier that)) { return false; } return this.toString().equals(that.toString()); } @Override public int hashCode() { return Objects.hash(id); } public String getId() { return this.toString(); } @Override public String toString() { return this.id; } @Override public int compareTo(@NotNull UniqueIdentifier o) { return this.id.compareTo(o.toString()); } }
0
java-sources/ai/stapi/common/0.3.2/ai/stapi
java-sources/ai/stapi/common/0.3.2/ai/stapi/identity/UniversallyUniqueIdentifier.java
package ai.stapi.identity; import java.util.UUID; public class UniversallyUniqueIdentifier extends UniqueIdentifier { protected UniversallyUniqueIdentifier() { } public UniversallyUniqueIdentifier(String id) { super(id); } public UniversallyUniqueIdentifier(UUID id) { super(id.toString()); } public static UniversallyUniqueIdentifier randomUUID() { return new UniversallyUniqueIdentifier(UUID.randomUUID()); } public static UniversallyUniqueIdentifier fromString(String id) { return new UniversallyUniqueIdentifier(UUID.fromString(id)); } public UUID toUuid() { return UUID.fromString(this.getId()); } }
0
java-sources/ai/stapi/common/0.3.2/ai/stapi/objectRenderer
java-sources/ai/stapi/common/0.3.2/ai/stapi/objectRenderer/exceptions/OptionsAreNotSupportedByAnyRendererException.java
package ai.stapi.objectRenderer.exceptions; import ai.stapi.objectRenderer.model.RendererOptions; public class OptionsAreNotSupportedByAnyRendererException extends RuntimeException { public OptionsAreNotSupportedByAnyRendererException(RendererOptions options) { super( createMessage(options) ); } private static String createMessage(RendererOptions options) { return String.format( "Renderer options %s are not supported by any renderer.", options.getClass() ); } }
0
java-sources/ai/stapi/common/0.3.2/ai/stapi/objectRenderer
java-sources/ai/stapi/common/0.3.2/ai/stapi/objectRenderer/exceptions/OptionsAreSupportedByMultipleRenderersException.java
package ai.stapi.objectRenderer.exceptions; import ai.stapi.objectRenderer.model.RendererOptions; public class OptionsAreSupportedByMultipleRenderersException extends RuntimeException { public OptionsAreSupportedByMultipleRenderersException(RendererOptions options) { super( createMessage(options) ); } private static String createMessage(RendererOptions options) { return String.format( "Renderer options %s are supported by more than one renderer.", options.getClass() ); } }
0
java-sources/ai/stapi/common/0.3.2/ai/stapi/objectRenderer/infrastructure
java-sources/ai/stapi/common/0.3.2/ai/stapi/objectRenderer/infrastructure/objectToJsonStringRenderer/ObjectToJSonStringOptions.java
package ai.stapi.objectRenderer.infrastructure.objectToJsonStringRenderer; import ai.stapi.objectRenderer.model.RendererOptions; import java.util.Arrays; import java.util.List; public class ObjectToJSonStringOptions implements RendererOptions { private final List<RenderFeature> features; public ObjectToJSonStringOptions(RenderFeature... renderFeatures) { this.features = Arrays.stream(renderFeatures).toList(); } public ObjectToJSonStringOptions(List<RenderFeature> renderFeatures) { this.features = renderFeatures; } public List<RenderFeature> getFeatures() { return features; } public enum RenderFeature { SORT_FIELDS, HIDE_CREATED_AT, HIDE_DISPATCHED_AT, HIDE_IDS, HIDE_KEY_HASHCODE, RENDER_GETTERS } }
0
java-sources/ai/stapi/common/0.3.2/ai/stapi/objectRenderer/infrastructure
java-sources/ai/stapi/common/0.3.2/ai/stapi/objectRenderer/infrastructure/objectToJsonStringRenderer/ObjectToJsonStringRenderOutput.java
package ai.stapi.objectRenderer.infrastructure.objectToJsonStringRenderer; import ai.stapi.objectRenderer.model.RenderOutput; public class ObjectToJsonStringRenderOutput implements RenderOutput { private String output; public ObjectToJsonStringRenderOutput(String output) { this.output = output; } @Override public String toPrintableString() { return this.output; } }
0
java-sources/ai/stapi/common/0.3.2/ai/stapi/objectRenderer/infrastructure
java-sources/ai/stapi/common/0.3.2/ai/stapi/objectRenderer/infrastructure/objectToJsonStringRenderer/ObjectToJsonStringRenderer.java
package ai.stapi.objectRenderer.infrastructure.objectToJsonStringRenderer; import ai.stapi.objectRenderer.infrastructure.objectToJsonStringRenderer.ObjectToJSonStringOptions.RenderFeature; import ai.stapi.objectRenderer.model.ObjectRenderer; import ai.stapi.objectRenderer.model.RenderOutput; import ai.stapi.objectRenderer.model.RendererOptions; import ai.stapi.serialization.AbstractSerializableObject; import ai.stapi.serialization.jackson.JavaTimeConfigurer; import com.fasterxml.jackson.annotation.JsonAutoDetect; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; import java.util.Collection; import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; public class ObjectToJsonStringRenderer implements ObjectRenderer { @Override public RenderOutput render(Object obj) { if (obj == null) { return new ObjectToJsonStringRenderOutput("null"); } String result = ""; try { result = this.getMapper(new ObjectToJSonStringOptions()).writerWithDefaultPrettyPrinter() .writeValueAsString(obj); } catch (JsonProcessingException e) { throw new RuntimeException(e); } return new ObjectToJsonStringRenderOutput(result); } @Override public RenderOutput render( Object object, RendererOptions options ) { if (object == null) { return new ObjectToJsonStringRenderOutput("null"); } var specificOptions = (ObjectToJSonStringOptions) options; if (specificOptions.getFeatures() .contains(ObjectToJSonStringOptions.RenderFeature.SORT_FIELDS)) { object = this.convertObjectToSortedMap(object, specificOptions); } try { var result = this.getMapper(specificOptions) .writerWithDefaultPrettyPrinter() .writeValueAsString(object); if (specificOptions.getFeatures() .contains(ObjectToJSonStringOptions.RenderFeature.HIDE_IDS)) { result = this.hideId(result); } if (specificOptions.getFeatures().contains(RenderFeature.HIDE_KEY_HASHCODE)) { result = this.hideKeyHashcode(result); } if (specificOptions.getFeatures() .contains(ObjectToJSonStringOptions.RenderFeature.HIDE_CREATED_AT)) { result = this.hideCreatedAt(result); } if (specificOptions.getFeatures() .contains(ObjectToJSonStringOptions.RenderFeature.HIDE_DISPATCHED_AT)) { result = this.hideDispatchedAt(result); } return new ObjectToJsonStringRenderOutput(result); } catch (JsonProcessingException e) { throw new RuntimeException(e); } } private ObjectMapper getMapper(ObjectToJSonStringOptions options) { var mapper = new ObjectMapper(); JavaTimeConfigurer.configureJavaTimeModule(mapper); var shouldRenderGetters = options.getFeatures() .contains(ObjectToJSonStringOptions.RenderFeature.RENDER_GETTERS); mapper.setVisibility( mapper.getSerializationConfig() .getDefaultVisibilityChecker() .withFieldVisibility(JsonAutoDetect.Visibility.ANY) .withGetterVisibility(shouldRenderGetters ? JsonAutoDetect.Visibility.DEFAULT : JsonAutoDetect.Visibility.NONE) .withSetterVisibility(JsonAutoDetect.Visibility.NONE) .withCreatorVisibility(JsonAutoDetect.Visibility.NONE) .withIsGetterVisibility(shouldRenderGetters ? JsonAutoDetect.Visibility.DEFAULT : JsonAutoDetect.Visibility.NONE) ).disable(SerializationFeature.FAIL_ON_EMPTY_BEANS); return mapper; } private Map<String, Object> convertToMap(Object object, ObjectToJSonStringOptions options) { return this.getMapper(options).convertValue(object, new TypeReference<>() {}); } private Object convertObjectToSortedMap(Object object, ObjectToJSonStringOptions options) { if (object == null) { return null; } if (isPrimitiveType(object)) { return object; } if (object instanceof Collection<?> collection && !(object instanceof Map<?, ?>)) { return this.getMappedList(collection, options); } var result = convertToMap(object, options); return this.createSortedMap(result, options); } private boolean isPrimitiveType(Object object) { return object instanceof String || object instanceof Number || object instanceof Boolean; } private boolean isList(Object object) { return object instanceof Collection<?>; } private boolean isMap(Object object) { return object instanceof Map; } private Map<String, Object> createSortedMap( Map<String, Object> object, ObjectToJSonStringOptions options ) { var outputMap = new LinkedHashMap<String, Object>(); this.addSpecificFieldIfPresent( AbstractSerializableObject.NAME_OF_FIELD_WITH_SERIALIZATION_TYPE, outputMap, object, options ); this.addSpecificFieldIfPresent("id", outputMap, object, options); this.addFieldContainingStringIfPresent("Id", outputMap, object, options); //add primitiveType fields object.entrySet().stream() .filter(entry -> !outputMap.containsKey(entry.getKey())) .filter(entry -> isPrimitiveType(entry.getValue())) .sorted((e1, e2) -> e1.getKey().compareTo(e2.getKey())) .forEach(entry -> outputMap.put(entry.getKey(), entry.getValue())); //add other type fields object.entrySet().stream() .filter(entry -> !outputMap.containsKey(entry.getKey())) .sorted((e1, e2) -> e1.getKey().compareTo(e2.getKey())) .forEach(entry -> { if (entry.getValue() instanceof Map map) { outputMap.put(entry.getKey(), this.createSortedMap(map, options)); } else if (entry.getValue() instanceof Collection<?> list) { outputMap.put(entry.getKey(), this.getMappedList(list, options)); } else { outputMap.put(entry.getKey(), entry.getValue()); } }); return outputMap; } private Collection<?> getMappedList(Collection<?> collection, ObjectToJSonStringOptions options) { var sortedList = new LinkedList<>(); collection.forEach(item -> { if (!isList(item) && !isPrimitiveType(item)) { var map = this.convertToMap(item, options); sortedList.add(this.createSortedMap(map, options)); } else { sortedList.add(item); } }); return sortedList; } private void addSpecificFieldIfPresent( String fieldName, Map<String, Object> outputMap, Map<String, Object> objectMap, ObjectToJSonStringOptions options ) { objectMap.entrySet().stream() .filter(entry -> entry.getKey().equals(fieldName)) .findAny() .ifPresent( entry -> outputMap.put( entry.getKey(), this.convertObjectToSortedMap(entry.getValue(), options) ) ); } private void addFieldContainingStringIfPresent( String fieldName, Map<String, Object> outputMap, Map<String, Object> objectMap, ObjectToJSonStringOptions options ) { objectMap.entrySet().stream() .filter(entry -> entry.getKey().contains(fieldName)) .sorted((e1, e2) -> e1.getKey().compareTo(e2.getKey())) .forEach( entry -> outputMap.put( entry.getKey(), this.convertObjectToSortedMap(entry.getValue(), options) ) ); } private String hideId(String render) { return render.replaceAll("([a-f0-9]{8}(-[a-f0-9]{4}){4}[a-f0-9]{8})", "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx"); } private String hideKeyHashcode(String render) { return render.replaceAll( "(\"_key\"\\s*:\\s*\"[A-Za-z0-9-]+?_)([A-Za-z0-9]{6})", "$1xxxxxx" ); } private String hideCreatedAt(String render) { String regex = "\"createdAt\"\\s*:\\s*\"[^\"]+\""; String replacement = "\"createdAt\" : hidden_date"; Pattern pattern = Pattern.compile(regex); Matcher matcher = pattern.matcher(render); return matcher.replaceAll(replacement); } private String hideDispatchedAt(String render) { return render.replaceAll( "(?<=\"dispatchedAt\" : )(\"\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}\\.\\d+\")", "hidden_date"); } @Override public boolean supports(RendererOptions options) { return options instanceof ObjectToJSonStringOptions; } }
0
java-sources/ai/stapi/common/0.3.2/ai/stapi/objectRenderer
java-sources/ai/stapi/common/0.3.2/ai/stapi/objectRenderer/model/GenericObjectRenderer.java
package ai.stapi.objectRenderer.model; import ai.stapi.objectRenderer.exceptions.OptionsAreNotSupportedByAnyRendererException; import ai.stapi.objectRenderer.exceptions.OptionsAreSupportedByMultipleRenderersException; import java.util.List; public class GenericObjectRenderer { private List<ObjectRenderer> existingObjectRenderers; public GenericObjectRenderer(List<ObjectRenderer> existingObjectRenderers) { this.existingObjectRenderers = existingObjectRenderers; } public RenderOutput render(Object obj, RendererOptions options) { var renderer = this.getObjectRenderer(options); return renderer.render(obj, options); } private ObjectRenderer getObjectRenderer(RendererOptions options) { var renderers = existingObjectRenderers.stream().filter( renderer -> renderer.supports(options) ).toList(); if (renderers.isEmpty()) { throw new OptionsAreNotSupportedByAnyRendererException(options); } if (renderers.size() > 1) { throw new OptionsAreSupportedByMultipleRenderersException(options); } return renderers.stream() .findFirst() .orElseThrow(); } }
0
java-sources/ai/stapi/common/0.3.2/ai/stapi/objectRenderer
java-sources/ai/stapi/common/0.3.2/ai/stapi/objectRenderer/model/ObjectRenderer.java
package ai.stapi.objectRenderer.model; public interface ObjectRenderer { RenderOutput render(Object obj); RenderOutput render(Object obj, RendererOptions options); boolean supports(RendererOptions options); }
0
java-sources/ai/stapi/common/0.3.2/ai/stapi/objectRenderer
java-sources/ai/stapi/common/0.3.2/ai/stapi/objectRenderer/model/RenderOutput.java
package ai.stapi.objectRenderer.model; public interface RenderOutput { String toPrintableString(); }
0
java-sources/ai/stapi/common/0.3.2/ai/stapi/objectRenderer
java-sources/ai/stapi/common/0.3.2/ai/stapi/objectRenderer/model/RendererOptions.java
package ai.stapi.objectRenderer.model; public interface RendererOptions { }
0
java-sources/ai/stapi/common/0.3.2/ai/stapi
java-sources/ai/stapi/common/0.3.2/ai/stapi/serialization/AbstractSerializableObject.java
package ai.stapi.serialization; public abstract class AbstractSerializableObject implements SerializableObject { public static final String NAME_OF_FIELD_WITH_SERIALIZATION_TYPE = "serializationType"; private String serializationType; protected AbstractSerializableObject() { } protected AbstractSerializableObject(String serializationType) { this.serializationType = serializationType; } public String getSerializationType() { return serializationType; } }
0
java-sources/ai/stapi/common/0.3.2/ai/stapi
java-sources/ai/stapi/common/0.3.2/ai/stapi/serialization/SerializableObject.java
package ai.stapi.serialization; public interface SerializableObject { String getSerializationType(); }
0
java-sources/ai/stapi/common/0.3.2/ai/stapi/serialization
java-sources/ai/stapi/common/0.3.2/ai/stapi/serialization/classNameProvider/GenericClassNameProvider.java
package ai.stapi.serialization.classNameProvider; import ai.stapi.serialization.classNameProvider.exception.GenericClassNameProviderException; import ai.stapi.serialization.classNameProvider.specific.SpecificClassNameProvider; import java.util.List; public class GenericClassNameProvider { private final List<SpecificClassNameProvider> classNameProviderList; public GenericClassNameProvider(List<SpecificClassNameProvider> classNameProviderList) { this.classNameProviderList = classNameProviderList; } public Class<?> getClassType(String serializationType) { var provider = this.getSupportingSpecificProvider(serializationType); return provider.getClassType(serializationType); } public String getSerializationType(Class<?> classType) { var provider = this.getSupportingSpecificProvider(classType); return provider.getSerializationType(classType); } public List<Class<?>> getAllClasses() { return this.classNameProviderList.stream() .map(SpecificClassNameProvider::getAllClasses) .flatMap(List::stream) .toList(); } private SpecificClassNameProvider getSupportingSpecificProvider(String serializationType) { var supportingGraphWriters = this.classNameProviderList.stream() .filter(specificObjectGraphMapper -> specificObjectGraphMapper.supports(serializationType)); var listOfSupportingResolvers = supportingGraphWriters.toList(); if (listOfSupportingResolvers.size() == 0) { throw GenericClassNameProviderException.becauseNoSupportingSpecificProvider( serializationType); } if (listOfSupportingResolvers.size() > 1) { throw GenericClassNameProviderException.becauseMoreThanOneSpecificProvider( serializationType, listOfSupportingResolvers ); } return listOfSupportingResolvers.get(0); } private SpecificClassNameProvider getSupportingSpecificProvider(Class<?> classType) { var supportingGraphWriters = this.classNameProviderList.stream() .filter(specificObjectGraphMapper -> specificObjectGraphMapper.supports(classType)); var listOfSupportingResolvers = supportingGraphWriters.toList(); if (listOfSupportingResolvers.size() == 0) { throw GenericClassNameProviderException.becauseNoSupportingSpecificProvider( classType.getName()); } if (listOfSupportingResolvers.size() > 1) { throw GenericClassNameProviderException.becauseMoreThanOneSpecificProvider( classType.getName(), listOfSupportingResolvers ); } return listOfSupportingResolvers.get(0); } }
0
java-sources/ai/stapi/common/0.3.2/ai/stapi/serialization/classNameProvider
java-sources/ai/stapi/common/0.3.2/ai/stapi/serialization/classNameProvider/exception/GenericClassNameProviderException.java
package ai.stapi.serialization.classNameProvider.exception; import ai.stapi.serialization.classNameProvider.specific.SpecificClassNameProvider; import java.util.List; import java.util.stream.Collectors; public class GenericClassNameProviderException extends RuntimeException { private GenericClassNameProviderException(String message) { super(message); } public static GenericClassNameProviderException becauseNoSupportingSpecificProvider( String serializationType) { return new GenericClassNameProviderException( "\nThere is no " + SpecificClassNameProvider.class.getSimpleName() + " for serialization type '" + serializationType + "'.\n" + "Either there is some error in configuration or you should create a service which implements:\n" + SpecificClassNameProvider.class + " which supports this serialization type." ); } public static GenericClassNameProviderException becauseMoreThanOneSpecificProvider( String serializationType, List<SpecificClassNameProvider> listOfSupportingResolvers ) { return new GenericClassNameProviderException( "There is multiple supporting " + SpecificClassNameProvider.class.getSimpleName() + "for serialization type " + serializationType + "'." + " Supporting providers: [" + listOfSupportingResolvers.stream() .map(provider -> provider.getClass().getSimpleName()) .collect(Collectors.joining(", ")) + "]." ); } }
0
java-sources/ai/stapi/common/0.3.2/ai/stapi/serialization/classNameProvider
java-sources/ai/stapi/common/0.3.2/ai/stapi/serialization/classNameProvider/exception/SerializableObjectClassNameProviderException.java
package ai.stapi.serialization.classNameProvider.exception; public class SerializableObjectClassNameProviderException extends RuntimeException { private SerializableObjectClassNameProviderException(String message) { super(message); } public static SerializableObjectClassNameProviderException becauseTypeIsNotDefined( String serializationType) { return new SerializableObjectClassNameProviderException( "There is no defined class type for serialization type '" + serializationType + "'." ); } }
0
java-sources/ai/stapi/common/0.3.2/ai/stapi/serialization/classNameProvider
java-sources/ai/stapi/common/0.3.2/ai/stapi/serialization/classNameProvider/specific/AbstractSerializableObjectClassNameProvider.java
package ai.stapi.serialization.classNameProvider.specific; import ai.stapi.serialization.classNameProvider.exception.SerializableObjectClassNameProviderException; import java.util.List; import java.util.Map; public abstract class AbstractSerializableObjectClassNameProvider implements SpecificClassNameProvider { public Class<?> getClassType(String serializationType) { var map = this.getClassMap(); if (!map.containsKey(serializationType)) { throw SerializableObjectClassNameProviderException.becauseTypeIsNotDefined(serializationType); } return map.get(serializationType); } @Override public String getSerializationType(Class<?> classType) { return this.getClassMap().entrySet().stream() .filter(entry -> entry.getValue().equals(classType)) .findAny() .map(Map.Entry::getKey) .orElse("throw exception here"); } @Override public List<Class<?>> getAllClasses() { return this.getClassMap().values().stream().toList(); } @Override public boolean supports(String serializationType) { return this.getClassMap().containsKey(serializationType); } @Override public boolean supports(Class<?> classType) { return this.getClassMap().values().stream().anyMatch(value -> value.equals(classType)); } protected abstract Map<String, Class<?>> getClassMap(); }
0
java-sources/ai/stapi/common/0.3.2/ai/stapi/serialization/classNameProvider
java-sources/ai/stapi/common/0.3.2/ai/stapi/serialization/classNameProvider/specific/SpecificClassNameProvider.java
package ai.stapi.serialization.classNameProvider.specific; import java.util.List; public interface SpecificClassNameProvider { Class<?> getClassType(String serializationType); String getSerializationType(Class<?> classType); List<Class<?>> getAllClasses(); boolean supports(String serializationType); boolean supports(Class<?> classType); }
0
java-sources/ai/stapi/common/0.3.2/ai/stapi/serialization
java-sources/ai/stapi/common/0.3.2/ai/stapi/serialization/jackson/JavaTimeConfigurer.java
package ai.stapi.serialization.jackson; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; public class JavaTimeConfigurer { private JavaTimeConfigurer() { } public static void configureJavaTimeModule(ObjectMapper objectMapper) { objectMapper.registerModule(new JavaTimeModule()); objectMapper.configure(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE, false); objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); } }
0
java-sources/ai/stapi/common/0.3.2/ai/stapi/serialization
java-sources/ai/stapi/common/0.3.2/ai/stapi/serialization/jackson/SerializableObjectConfigurer.java
package ai.stapi.serialization.jackson; import ai.stapi.serialization.classNameProvider.GenericClassNameProvider; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.module.SimpleModule; public class SerializableObjectConfigurer { private final GenericClassNameProvider genericClassNameProvider; public SerializableObjectConfigurer(GenericClassNameProvider genericClassNameProvider) { this.genericClassNameProvider = genericClassNameProvider; } public void configure(ObjectMapper objectMapper) { var module = new SimpleModule("SerializableObjectModule"); module.setDeserializerModifier( new SerializableObjectDeserializerModifier(genericClassNameProvider, objectMapper) ); objectMapper.registerModule(module); } }
0
java-sources/ai/stapi/common/0.3.2/ai/stapi/serialization
java-sources/ai/stapi/common/0.3.2/ai/stapi/serialization/jackson/SerializableObjectDeserializer.java
package ai.stapi.serialization.jackson; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.databind.DeserializationContext; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.deser.std.StdDeserializer; import ai.stapi.serialization.AbstractSerializableObject; import ai.stapi.serialization.SerializableObject; import ai.stapi.serialization.classNameProvider.GenericClassNameProvider; import com.fasterxml.jackson.databind.module.SimpleModule; import java.io.IOException; public class SerializableObjectDeserializer<T extends SerializableObject> extends StdDeserializer<T> { private GenericClassNameProvider classNameProvider; private ObjectMapper objectMapper; private Class<?> setupBeanClass; public SerializableObjectDeserializer( GenericClassNameProvider classNameProvider, ObjectMapper objectMapper, Class<?> setupBeanClass ) { super(setupBeanClass); this.setupBeanClass = setupBeanClass; this.classNameProvider = classNameProvider; this.objectMapper = objectMapper; } @Override @SuppressWarnings("unchecked") public T deserialize( JsonParser jsonParser, DeserializationContext deserializationContext ) throws IOException { JsonNode node = jsonParser.getCodec().readTree(jsonParser); JsonNode jsonNode = node.get( AbstractSerializableObject.NAME_OF_FIELD_WITH_SERIALIZATION_TYPE ); if (jsonNode == null) { throw new RuntimeException( "Cannot deserialize SerializableObject, because it is missing serializationType." + "\nClass to be deserialized: " + this.setupBeanClass.getSimpleName() + "\nProvided data: " + node ); } var serializationType = jsonNode.asText(); var classType = classNameProvider.getClassType(serializationType); var serializedObject = node.toString(); return (T) this.objectMapper.readValue(serializedObject, classType); } }
0
java-sources/ai/stapi/common/0.3.2/ai/stapi/serialization
java-sources/ai/stapi/common/0.3.2/ai/stapi/serialization/jackson/SerializableObjectDeserializerModifier.java
package ai.stapi.serialization.jackson; import ai.stapi.serialization.SerializableObject; import ai.stapi.serialization.classNameProvider.GenericClassNameProvider; import com.fasterxml.jackson.databind.BeanDescription; import com.fasterxml.jackson.databind.DeserializationConfig; import com.fasterxml.jackson.databind.JsonDeserializer; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.deser.BeanDeserializerModifier; import java.lang.reflect.Modifier; public class SerializableObjectDeserializerModifier extends BeanDeserializerModifier { private final GenericClassNameProvider nameProvider; private final ObjectMapper objectMapper; public SerializableObjectDeserializerModifier( GenericClassNameProvider nameProvider, ObjectMapper objectMapper ) { this.nameProvider = nameProvider; this.objectMapper = objectMapper; } @Override public JsonDeserializer<?> modifyDeserializer( DeserializationConfig config, BeanDescription beanDesc, JsonDeserializer<?> deserializer ) { JsonDeserializer<?> defaultDeserializer = super.modifyDeserializer(config, beanDesc, deserializer); if ( (beanDesc.getBeanClass().isInterface() || Modifier.isAbstract( beanDesc.getBeanClass().getModifiers()) ) && SerializableObject.class.isAssignableFrom(beanDesc.getBeanClass()) ) { return new SerializableObjectDeserializer<>( this.nameProvider, this.objectMapper, beanDesc.getBeanClass() ); } return defaultDeserializer; } }
0
java-sources/ai/stapi/common/0.3.2/ai/stapi
java-sources/ai/stapi/common/0.3.2/ai/stapi/utils/Classifier.java
package ai.stapi.utils; import java.util.UUID; public class Classifier { public static boolean isPrimitiveOrString(Object value) { return value instanceof Byte || value instanceof Short || value instanceof Integer || value instanceof Long || value instanceof Float || value instanceof Double || value instanceof Character || value instanceof Boolean || value instanceof String || value instanceof UUID || value instanceof byte[]; } }
0
java-sources/ai/stapi/common/0.3.2/ai/stapi
java-sources/ai/stapi/common/0.3.2/ai/stapi/utils/LineFormatter.java
package ai.stapi.utils; import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; import java.util.stream.Stream; public class LineFormatter { private static final String TAB_INDENT = "\t"; private static final String SPACE_INDENT = " "; private static final String END_OF_LINE_SYMBOL = "\n"; public static String createLine(String renderedLine) { return LineFormatter.createLine(renderedLine, 0); } public static String createLines(Stream<String> renderedLines) { return renderedLines.map(LineFormatter::createLine).collect(Collectors.joining()); } public static String createLines(List<String> renderedLines) { return renderedLines.stream().map(LineFormatter::createLine).collect(Collectors.joining()); } public static String createLines(String... renderedLines) { return Arrays.stream(renderedLines).map(LineFormatter::createLine) .collect(Collectors.joining()); } public static String createLine(String renderedLine, int indentLevel) { return TAB_INDENT.repeat(indentLevel) + renderedLine + END_OF_LINE_SYMBOL; } public static String createSpaceIndentedLine(String renderedLine, int indentLevel) { return SPACE_INDENT.repeat(indentLevel) + renderedLine + END_OF_LINE_SYMBOL; } public static String createNewLine() { return END_OF_LINE_SYMBOL; } }
0
java-sources/ai/stapi/common/0.3.2/ai/stapi
java-sources/ai/stapi/common/0.3.2/ai/stapi/utils/Retryable.java
package ai.stapi.utils; import java.util.List; import java.util.function.Supplier; public interface Retryable<T> { static <T> T retry(int maxRetries, long retryInterval, Supplier<T> supplier, Integer expectedInteger) { int retries = maxRetries; T result = null; while (retries != 0) { result = supplier.get(); if ( result != null && ( result instanceof List && ((List<?>) result).size() >= expectedInteger || result instanceof Number number && number.intValue() >= expectedInteger ) ) { break; } try { Thread.sleep(retryInterval); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new RuntimeException(e); } retries--; } return result; } T run(); }
0
java-sources/ai/stapi/common/0.3.2/ai/stapi
java-sources/ai/stapi/common/0.3.2/ai/stapi/utils/Stringifier.java
package ai.stapi.utils; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; public class Stringifier { public static String convertToString(Object value) { try { return new ObjectMapper() .disable(SerializationFeature.FAIL_ON_EMPTY_BEANS) .writerWithDefaultPrettyPrinter() .writeValueAsString(value); } catch (JsonProcessingException ignored) { } return value.toString(); } }
0
java-sources/ai/stapi/form-api/0.2.3/ai/stapi
java-sources/ai/stapi/form-api/0.2.3/ai/stapi/formapi/FormEndpoint.java
package ai.stapi.formapi; import ai.stapi.formapi.forminfo.FormInfo; import ai.stapi.formapi.forminfo.FormInfoMapper; import ai.stapi.formapi.formmapper.FormMapper; import ai.stapi.formapi.formmapper.FormMapperResult; import org.springframework.web.bind.annotation.*; import java.util.Objects; @RestController public class FormEndpoint { private final FormMapper formMapper; private final FormInfoMapper formInfoMapper; public FormEndpoint(FormMapper formMapper, FormInfoMapper formInfoMapper) { this.formMapper = formMapper; this.formInfoMapper = formInfoMapper; } @PostMapping("/form/{operationId}") @ResponseBody public FormMapperResult form( @PathVariable String operationId, @RequestBody(required = false) FormRequest formRequest ) { var finalRequest = Objects.requireNonNullElseGet( formRequest, () -> new FormRequest(null, null, null) ); return this.formMapper.map(operationId, finalRequest); } @GetMapping("/form/info/{operationId}") @ResponseBody public FormInfo formInfo(@PathVariable String operationId) { return this.formInfoMapper.map(operationId); } }
0
java-sources/ai/stapi/form-api/0.2.3/ai/stapi
java-sources/ai/stapi/form-api/0.2.3/ai/stapi/formapi/FormRequest.java
package ai.stapi.formapi; import org.jetbrains.annotations.Nullable; import java.util.HashMap; import java.util.Map; public class FormRequest { @Nullable private final String resourceId; @Nullable private final Map<String, Object> targets; @Nullable private final Boolean omitExtension; public FormRequest( @Nullable String resourceId, @Nullable Map<String, Object> targets, @Nullable Boolean omitExtension ) { this.resourceId = resourceId; this.targets = targets; this.omitExtension = omitExtension; } @Nullable public String getResourceId() { return resourceId; } public Map<String, Object> getTargets() { return targets == null ? new HashMap<>() : targets; } public Boolean getOmitExtension() { return omitExtension == null || omitExtension; } }
0
java-sources/ai/stapi/form-api/0.2.3/ai/stapi/formapi
java-sources/ai/stapi/form-api/0.2.3/ai/stapi/formapi/configuration/FormApiConfiguration.java
package ai.stapi.formapi.configuration; import ai.stapi.formapi.forminfo.FormInfoMapper; import ai.stapi.formapi.formmapper.*; import ai.stapi.graphoperations.dagtoobjectconverter.DAGToObjectConverter; import ai.stapi.graphsystem.aggregatedefinition.model.AggregateDefinitionProvider; import ai.stapi.graphsystem.aggregategraphstatemodifier.EventFactoryModificationTraverser; import ai.stapi.graphsystem.operationdefinition.model.OperationDefinitionProvider; import ai.stapi.graphsystem.operationdefinition.model.OperationDefinitionStructureTypeMapper; import ai.stapi.schema.structureSchemaProvider.StructureSchemaFinder; import org.axonframework.config.Configuration; import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; @AutoConfiguration @ComponentScan("ai.stapi.formapi") public class FormApiConfiguration { @Bean public FormMapper formMapper( JsonSchemaMapper jsonSchemaMapper, UISchemaLoader uiSchemaLoader, FormDataLoader formDataLoader, OperationDefinitionProvider operationDefinitionProvider ) { return new FormMapper( jsonSchemaMapper, uiSchemaLoader, formDataLoader, operationDefinitionProvider ); } @Bean public JsonSchemaMapper jsonSchemaMapper( OperationDefinitionStructureTypeMapper operationDefinitionStructureTypeMapper, StructureSchemaFinder structureSchemaFinder ) { return new JsonSchemaMapper(operationDefinitionStructureTypeMapper, structureSchemaFinder); } @Bean @ConditionalOnMissingBean(UISchemaLoader.class) public UISchemaLoader schemaLoader() { return new NullUISchemaLoader(); } @Bean @ConditionalOnMissingBean(FormDataLoader.class) public AggregateRepositoryFormDataLoader formDataLoader( Configuration configuration, AggregateDefinitionProvider aggregateDefinitionProvider, EventFactoryModificationTraverser eventFactoryModificationTraverser, OperationDefinitionStructureTypeMapper operationDefinitionStructureTypeMapper, DAGToObjectConverter dagToObjectConverter ) { return new AggregateRepositoryFormDataLoader( configuration, aggregateDefinitionProvider, eventFactoryModificationTraverser, operationDefinitionStructureTypeMapper, dagToObjectConverter ); } @Bean public FormInfoMapper formInfoMapper( AggregateDefinitionProvider aggregateDefinitionProvider, OperationDefinitionProvider operationDefinitionProvider, StructureSchemaFinder structureSchemaFinder ) { return new FormInfoMapper( aggregateDefinitionProvider, operationDefinitionProvider, structureSchemaFinder ); } }
0
java-sources/ai/stapi/form-api/0.2.3/ai/stapi/formapi
java-sources/ai/stapi/form-api/0.2.3/ai/stapi/formapi/forminfo/FormInfo.java
package ai.stapi.formapi.forminfo; import java.util.Map; import java.util.Set; public class FormInfo { private final Map<String, Set<String>> possibleTargets; private final String resourceType; private final Boolean requiresResourceId; public FormInfo( Map<String, Set<String>> possibleTargets, String resourceType, Boolean requiresResourceId ) { this.possibleTargets = possibleTargets; this.resourceType = resourceType; this.requiresResourceId = requiresResourceId; } public Map<String, Set<String>> getPossibleTargets() { return possibleTargets; } public String getResourceType() { return resourceType; } public Boolean getRequiresResourceId() { return requiresResourceId; } }
0
java-sources/ai/stapi/form-api/0.2.3/ai/stapi/formapi
java-sources/ai/stapi/form-api/0.2.3/ai/stapi/formapi/forminfo/FormInfoMapper.java
package ai.stapi.formapi.forminfo; import ai.stapi.formapi.forminfo.exceptions.CannotMapFormInfo; import ai.stapi.graphsystem.aggregatedefinition.model.AggregateDefinitionDTO; import ai.stapi.graphsystem.aggregatedefinition.model.AggregateDefinitionProvider; import ai.stapi.graphsystem.aggregatedefinition.model.CommandHandlerDefinitionDTO; import ai.stapi.graphsystem.aggregatedefinition.model.exceptions.CannotProvideAggregateDefinition; import ai.stapi.graphsystem.operationdefinition.model.OperationDefinitionDTO; import ai.stapi.graphsystem.operationdefinition.model.OperationDefinitionProvider; import ai.stapi.schema.structureSchema.ComplexStructureType; import ai.stapi.schema.structureSchema.FieldType; import ai.stapi.schema.structureSchemaProvider.StructureSchemaFinder; import java.util.*; import java.util.stream.Collectors; import java.util.stream.Stream; public class FormInfoMapper { private final AggregateDefinitionProvider aggregateDefinitionProvider; private final OperationDefinitionProvider operationDefinitionProvider; private final StructureSchemaFinder structureSchemaFinder; public FormInfoMapper( AggregateDefinitionProvider aggregateDefinitionProvider, OperationDefinitionProvider operationDefinitionProvider, StructureSchemaFinder structureSchemaFinder ) { this.aggregateDefinitionProvider = aggregateDefinitionProvider; this.operationDefinitionProvider = operationDefinitionProvider; this.structureSchemaFinder = structureSchemaFinder; } public FormInfo map(String operationId) { AggregateDefinitionDTO aggregateDefinition; try { aggregateDefinition = this.aggregateDefinitionProvider.getAggregateForOperation(operationId); } catch (CannotProvideAggregateDefinition e) { throw CannotMapFormInfo.becauseThereWasNoCommandHandlerDefinitionForProvidedOperation(operationId, e); } var commandHandlerDefinition = aggregateDefinition.getCommand() .stream() .filter(command -> command.getOperation().getId().equals(operationId)) .findFirst() .orElseThrow( () -> CannotMapFormInfo.becauseThereWasNoCommandHandlerDefinitionForProvidedOperation(operationId) ); var resourceType = aggregateDefinition.getStructure().getId(); var operation = this.operationDefinitionProvider.provide(operationId); var resourceStructure = (ComplexStructureType) this.structureSchemaFinder.getStructureType(resourceType); var result = new HashMap<String, Set<String>>(); commandHandlerDefinition.getEventFactory() .stream() .flatMap(eventFactory -> eventFactory.getModification().stream()) .filter(modification -> modification.getStartIdParameterName() != null) .map(modification -> operation.getParameter(modification.getStartIdParameterName())) .forEach( parameter -> result.put( parameter.getName(), this.getPossibleTypes(resourceStructure, parameter.getReferencedFrom()) ) ); return new FormInfo( result, resourceType, Objects.equals( commandHandlerDefinition.getCreationalPolicy(), CommandHandlerDefinitionDTO.CreationPolicy.NEVER ) ); } private Set<String> getPossibleTypes( ComplexStructureType resourceStructureType, List<OperationDefinitionDTO.ParameterDTO.ReferencedFrom> referencedFrom ) { return referencedFrom.stream() .map(OperationDefinitionDTO.ParameterDTO.ReferencedFrom::getSource) .map(source -> source.split("\\.")) .map(splitSource -> Arrays.copyOfRange(splitSource,1, splitSource.length - 1)) .flatMap(splitSource -> this.getPossibleTypes(resourceStructureType, splitSource)) .collect(Collectors.toSet()); } private Stream<String> getPossibleTypes(ComplexStructureType currentStructureType, String[] splitSource) { var currentField = splitSource[0]; if (!currentStructureType.hasField(currentField)) { return Stream.of(); } var types = currentStructureType.getField(currentField) .getTypes() .stream() .filter(fieldType -> !fieldType.isPrimitiveType()) .map(FieldType::getType); if (splitSource.length == 1) { return types; } var restOfPath = Arrays.copyOfRange(splitSource, 1, splitSource.length); return types .map(this.structureSchemaFinder::getStructureType) .map(ComplexStructureType.class::cast) .flatMap(structure -> this.getPossibleTypes(structure, restOfPath)); } }
0
java-sources/ai/stapi/form-api/0.2.3/ai/stapi/formapi/forminfo
java-sources/ai/stapi/form-api/0.2.3/ai/stapi/formapi/forminfo/exceptions/CannotMapFormInfo.java
package ai.stapi.formapi.forminfo.exceptions; public class CannotMapFormInfo extends RuntimeException { private static final String MSG = "Cannot map form info, because "; private CannotMapFormInfo(String becauseMessage) { super(MSG + becauseMessage); } private CannotMapFormInfo(String becauseMessage, Throwable cause) { super(MSG + becauseMessage, cause); } public static CannotMapFormInfo becauseThereWasNoCommandHandlerDefinitionForProvidedOperation( String operationId ) { return new CannotMapFormInfo( String.format( "there was not command handler definition with provided operation.%nOperation name: '%s'", operationId ) ); } public static CannotMapFormInfo becauseThereWasNoCommandHandlerDefinitionForProvidedOperation( String operationId, Throwable cause ) { return new CannotMapFormInfo( String.format( "there was not command handler definition with provided operation.%nOperation name: '%s'", operationId ), cause ); } }
0
java-sources/ai/stapi/form-api/0.2.3/ai/stapi/formapi
java-sources/ai/stapi/form-api/0.2.3/ai/stapi/formapi/formmapper/AggregateRepositoryFormDataLoader.java
package ai.stapi.formapi.formmapper; import ai.stapi.axonsystem.dynamic.aggregate.DynamicAggregate; import ai.stapi.axonsystem.graphaggregate.AggregateWithGraph; import ai.stapi.formapi.formmapper.exceptions.CannotLoadFormData; import ai.stapi.graphoperations.dagtoobjectconverter.DAGToObjectConverter; import ai.stapi.graphsystem.aggregatedefinition.model.AggregateDefinitionDTO; import ai.stapi.graphsystem.aggregatedefinition.model.AggregateDefinitionProvider; import ai.stapi.graphsystem.aggregatedefinition.model.exceptions.CannotProvideAggregateDefinition; import ai.stapi.graphsystem.aggregategraphstatemodifier.EventFactoryModificationTraverser; import ai.stapi.graphsystem.operationdefinition.model.OperationDefinitionDTO; import ai.stapi.graphsystem.operationdefinition.model.OperationDefinitionStructureTypeMapper; import ai.stapi.identity.UniqueIdentifier; import org.axonframework.commandhandling.GenericCommandMessage; import org.axonframework.config.Configuration; import org.axonframework.messaging.unitofwork.CurrentUnitOfWork; import org.axonframework.messaging.unitofwork.DefaultUnitOfWork; import org.axonframework.modelling.command.Aggregate; import org.axonframework.modelling.command.AggregateNotFoundException; import org.axonframework.modelling.command.Repository; import java.util.HashMap; import java.util.Map; public class AggregateRepositoryFormDataLoader implements FormDataLoader { private final Repository<DynamicAggregate> repository; private final AggregateDefinitionProvider aggregateDefinitionProvider; private final EventFactoryModificationTraverser eventFactoryModificationTraverser; private final OperationDefinitionStructureTypeMapper operationDefinitionStructureTypeMapper; private final DAGToObjectConverter dagToObjectConverter; public AggregateRepositoryFormDataLoader( Configuration configuration, AggregateDefinitionProvider aggregateDefinitionProvider, EventFactoryModificationTraverser eventFactoryModificationTraverser, OperationDefinitionStructureTypeMapper operationDefinitionStructureTypeMapper, DAGToObjectConverter dagToObjectConverter ) { this.repository = configuration.repository(DynamicAggregate.class); this.aggregateDefinitionProvider = aggregateDefinitionProvider; this.eventFactoryModificationTraverser = eventFactoryModificationTraverser; this.operationDefinitionStructureTypeMapper = operationDefinitionStructureTypeMapper; this.dagToObjectConverter = dagToObjectConverter; } @Override public Map<String, Object> load( OperationDefinitionDTO operationDefinitionDTO, String resourceId, Map<String, Object> possibleStartIds ) { var operationId = operationDefinitionDTO.getId(); AggregateDefinitionDTO aggregateDefinition; try { aggregateDefinition = this.aggregateDefinitionProvider.getAggregateForOperation(operationId); } catch (CannotProvideAggregateDefinition e) { throw CannotLoadFormData.becauseThereWasNoCommandHandlerDefinitionForProvidedOperation(operationId, e); } var commandHandlerDefinition = aggregateDefinition.getCommand() .stream() .filter(command -> command.getOperation().getId().equals(operationId)) .findFirst() .orElseThrow( () -> CannotLoadFormData.becauseThereWasNoCommandHandlerDefinitionForProvidedOperation(operationId) ); var unitOfWork = DefaultUnitOfWork.startAndGet( new GenericCommandMessage<>(String.format( "Loading state of aggregate '%s' with id '%s'. To be used as form data for operation '%s'.", aggregateDefinition.getName(), resourceId, operationId )) ); CurrentUnitOfWork.set(unitOfWork); Aggregate<DynamicAggregate> aggregate; try { aggregate = this.repository.load(resourceId); } catch (AggregateNotFoundException e) { throw CannotLoadFormData.becauseAggregateByProvidedResourceIdWasNotFound(resourceId, e); } finally { CurrentUnitOfWork.clear(unitOfWork); } var operationStructureType = this.operationDefinitionStructureTypeMapper.map(operationDefinitionDTO); var state = aggregate.invoke(AggregateWithGraph::getInMemoryGraphRepository); var data = new HashMap<String, Object>(); commandHandlerDefinition .getEventFactory() .stream() .flatMap(eventFactory -> eventFactory.getModification().stream()) .forEach(modification -> { var inputValueParameterName = modification.getInputValueParameterName(); var traversingStart = this.eventFactoryModificationTraverser.getTraversingStartNode( aggregateDefinition.getStructure().getId(), new UniqueIdentifier(resourceId), possibleStartIds, modification, operationStructureType, state ); var modificationPath = modification.getModificationPath(); var splitPath = modificationPath.split("\\."); var modifiedNode = this.eventFactoryModificationTraverser.traverseToModifiedNode( traversingStart, splitPath, operationStructureType, modification ); var fieldName = splitPath[splitPath.length - 1]; var object = this.dagToObjectConverter.convert(modifiedNode); var value = object.get(fieldName); if (value != null) { data.put(inputValueParameterName, value); } }); return data; } }
0
java-sources/ai/stapi/form-api/0.2.3/ai/stapi/formapi
java-sources/ai/stapi/form-api/0.2.3/ai/stapi/formapi/formmapper/FormDataLoader.java
package ai.stapi.formapi.formmapper; import ai.stapi.graphsystem.operationdefinition.model.OperationDefinitionDTO; import java.util.Map; public interface FormDataLoader { Map<String, Object> load( OperationDefinitionDTO operationDefinitionDTO, String resourceId, Map<String, Object> possibleStartIds ); }
0
java-sources/ai/stapi/form-api/0.2.3/ai/stapi/formapi
java-sources/ai/stapi/form-api/0.2.3/ai/stapi/formapi/formmapper/FormMapper.java
package ai.stapi.formapi.formmapper; import ai.stapi.formapi.FormRequest; import ai.stapi.graphsystem.operationdefinition.model.OperationDefinitionProvider; import java.util.HashMap; public class FormMapper { private final JsonSchemaMapper jsonSchemaMapper; private final UISchemaLoader uiSchemaLoader; private final FormDataLoader formDataLoader; private final OperationDefinitionProvider operationDefinitionProvider; public FormMapper( JsonSchemaMapper jsonSchemaMapper, UISchemaLoader uiSchemaLoader, FormDataLoader formDataLoader, OperationDefinitionProvider operationDefinitionProvider ) { this.jsonSchemaMapper = jsonSchemaMapper; this.uiSchemaLoader = uiSchemaLoader; this.formDataLoader = formDataLoader; this.operationDefinitionProvider = operationDefinitionProvider; } public FormMapperResult map(String operationId, FormRequest formRequest) { var operation = this.operationDefinitionProvider.provide(operationId); var jsonSchema = this.jsonSchemaMapper.map(operation, formRequest.getOmitExtension()); var uiSchema = this.uiSchemaLoader.load(operation); return new FormMapperResult( jsonSchema, uiSchema, formRequest.getResourceId() == null ? new HashMap<>() : this.formDataLoader.load( operation, formRequest.getResourceId(), formRequest.getTargets() ) ); } }
0
java-sources/ai/stapi/form-api/0.2.3/ai/stapi/formapi
java-sources/ai/stapi/form-api/0.2.3/ai/stapi/formapi/formmapper/FormMapperResult.java
package ai.stapi.formapi.formmapper; import java.util.Map; public class FormMapperResult { private final Map<String, Object> formSchema; private final Map<String, Object> uiSchema; private final Map<String, Object> formData; public FormMapperResult( Map<String, Object> formSchema, Map<String, Object> uiSchema, Map<String, Object> formData ) { this.formSchema = formSchema; this.uiSchema = uiSchema; this.formData = formData; } public Map<String, Object> getFormSchema() { return formSchema; } public Map<String, Object> getUiSchema() { return uiSchema; } public Map<String, Object> getFormData() { return formData; } }
0
java-sources/ai/stapi/form-api/0.2.3/ai/stapi/formapi
java-sources/ai/stapi/form-api/0.2.3/ai/stapi/formapi/formmapper/JsonSchemaMapper.java
package ai.stapi.formapi.formmapper; import ai.stapi.formapi.formmapper.exceptions.CannotMapJsonSchema; import ai.stapi.formapi.formmapper.exceptions.CannotPrintJSONSchema; import ai.stapi.graph.attribute.attributeValue.Base64BinaryAttributeValue; import ai.stapi.graph.attribute.attributeValue.BooleanAttributeValue; import ai.stapi.graph.attribute.attributeValue.CanonicalAttributeValue; import ai.stapi.graph.attribute.attributeValue.CodeAttributeValue; import ai.stapi.graph.attribute.attributeValue.DateAttributeValue; import ai.stapi.graph.attribute.attributeValue.DateTimeAttributeValue; import ai.stapi.graph.attribute.attributeValue.DecimalAttributeValue; import ai.stapi.graph.attribute.attributeValue.IdAttributeValue; import ai.stapi.graph.attribute.attributeValue.InstantAttributeValue; import ai.stapi.graph.attribute.attributeValue.IntegerAttributeValue; import ai.stapi.graph.attribute.attributeValue.MarkdownAttributeValue; import ai.stapi.graph.attribute.attributeValue.OidAttributeValue; import ai.stapi.graph.attribute.attributeValue.PositiveIntegerAttributeValue; import ai.stapi.graph.attribute.attributeValue.StringAttributeValue; import ai.stapi.graph.attribute.attributeValue.TimeAttributeValue; import ai.stapi.graph.attribute.attributeValue.UnsignedIntegerAttributeValue; import ai.stapi.graph.attribute.attributeValue.UriAttributeValue; import ai.stapi.graph.attribute.attributeValue.UrlAttributeValue; import ai.stapi.graph.attribute.attributeValue.UuidAttributeValue; import ai.stapi.graph.attribute.attributeValue.XhtmlAttributeValue; import ai.stapi.graphsystem.operationdefinition.model.OperationDefinitionDTO; import ai.stapi.graphsystem.operationdefinition.model.OperationDefinitionStructureTypeMapper; import ai.stapi.schema.structureSchema.ComplexStructureType; import ai.stapi.schema.structureSchema.FieldDefinition; import ai.stapi.schema.structureSchema.FieldType; import ai.stapi.schema.structureSchemaProvider.StructureSchemaFinder; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; import org.everit.json.schema.ArraySchema; import org.everit.json.schema.BooleanSchema; import org.everit.json.schema.CombinedSchema; import org.everit.json.schema.NumberSchema; import org.everit.json.schema.ObjectSchema; import org.everit.json.schema.ReferenceSchema; import org.everit.json.schema.Schema; import org.everit.json.schema.StringSchema; public class JsonSchemaMapper { public static Set<String> STRING_LIKE_PRIMITIVES = Set.of( Base64BinaryAttributeValue.SERIALIZATION_TYPE, CanonicalAttributeValue.SERIALIZATION_TYPE, CodeAttributeValue.SERIALIZATION_TYPE, DateAttributeValue.SERIALIZATION_TYPE, DateTimeAttributeValue.SERIALIZATION_TYPE, TimeAttributeValue.SERIALIZATION_TYPE, IdAttributeValue.SERIALIZATION_TYPE, InstantAttributeValue.SERIALIZATION_TYPE, MarkdownAttributeValue.SERIALIZATION_TYPE, OidAttributeValue.SERIALIZATION_TYPE, UriAttributeValue.SERIALIZATION_TYPE, UrlAttributeValue.SERIALIZATION_TYPE, UuidAttributeValue.SERIALIZATION_TYPE, XhtmlAttributeValue.SERIALIZATION_TYPE, StringAttributeValue.SERIALIZATION_TYPE ); public static Set<String> NUMBER_LIKE_PRIMITIVES = Set.of( DecimalAttributeValue.SERIALIZATION_TYPE, PositiveIntegerAttributeValue.SERIALIZATION_TYPE, UnsignedIntegerAttributeValue.SERIALIZATION_TYPE, IntegerAttributeValue.SERIALIZATION_TYPE ); private final OperationDefinitionStructureTypeMapper operationDefinitionStructureTypeMapper; private final StructureSchemaFinder structureSchemaFinder; public JsonSchemaMapper( OperationDefinitionStructureTypeMapper operationDefinitionStructureTypeMapper, StructureSchemaFinder structureSchemaFinder ) { this.operationDefinitionStructureTypeMapper = operationDefinitionStructureTypeMapper; this.structureSchemaFinder = structureSchemaFinder; } public Map<String, Object> map(OperationDefinitionDTO operationDefinitionDTO) { return this.map(operationDefinitionDTO, true); } public Map<String, Object> map( OperationDefinitionDTO operationDefinitionDTO, Boolean omitExtension ) { var fakedStructureType = this.operationDefinitionStructureTypeMapper.map( operationDefinitionDTO ); var formMapperContext = new FormMapperContext(); var schema = this.getObjectSchema(fakedStructureType, formMapperContext, omitExtension); return this.printSchema(schema, formMapperContext); } private ObjectSchema getObjectSchema( ComplexStructureType structureType, FormMapperContext formMapperContext, Boolean omitExtension ) { return this.getObjectSchemaWithTitle( structureType, formMapperContext, omitExtension, structureType.getDefinitionType() ); } private ObjectSchema getObjectSchemaWithTitle( ComplexStructureType structureType, FormMapperContext formMapperContext, Boolean omitExtension, String title ) { var builder = new ObjectSchema.Builder(); builder.title(title); builder.description( structureType.getDescription() ); structureType.getAllFields() .values() .stream() .filter(field -> !omitExtension || (!field.getName().equals("extension") && !field.getName().equals("modifierExtension"))) .sorted(Comparator.comparing(FieldDefinition::getName)) .forEach(field -> this.mapField(field, builder, formMapperContext, omitExtension)); return builder.build(); } private void mapField( FieldDefinition field, ObjectSchema.Builder builder, FormMapperContext formMapperContext, Boolean omitExtension ) { var parameterName = field.getName(); if (field.getMin() > 0) { builder.addRequiredProperty(parameterName); } if (field.getTypes().isEmpty()) { return; } if (field.getFloatMax() > 1) { this.mapArrayField(field, builder, formMapperContext, omitExtension); return; } var schema = this.getSchema(field, formMapperContext, omitExtension); builder.addPropertySchema(parameterName, schema); } private Schema getSchema( FieldDefinition field, FormMapperContext formMapperContext, Boolean omitExtension ) { if (field.getTypes().size() > 1) { var schemaBuilder = new CombinedSchema.Builder().criterion(CombinedSchema.ONE_CRITERION); field.getTypes().stream() .map(type -> this.getMemberSchema(type, field, formMapperContext, omitExtension)) .forEach(schemaBuilder::subschema); return schemaBuilder.build(); } var type = field.getTypes().get(0); return this.getMemberSchema(type, field, formMapperContext, omitExtension); } private Schema getMemberSchema( FieldType type, FieldDefinition fieldDefinition, FormMapperContext formMapperContext, Boolean omitExtension ) { var typeName = type.getType(); if (type.isPrimitiveType()) { return this.getPrimitiveSchema(typeName, fieldDefinition); } else { var title = this.formatMachineReadableToHumanReadable(fieldDefinition.getName()); if (type.isReference()) { return new StringSchema.Builder().title(title).description( fieldDefinition.getDescription()).build(); } else { if (!formMapperContext.hasType(typeName)) { formMapperContext.addType(typeName); var structureType = (ComplexStructureType) this.structureSchemaFinder.getStructureType( typeName ); var objectSchema = this.getObjectSchemaWithTitle( structureType, formMapperContext, omitExtension, title ); formMapperContext.putSchema(typeName, objectSchema); } return new ReferenceSchema.Builder() .refValue(String.format("#/definitions/%s", typeName)) .title(title) .description(fieldDefinition.getDescription()) .build(); } } } private Schema getPrimitiveSchema(String type, FieldDefinition fieldDefinition) { var title = this.formatMachineReadableToHumanReadable(fieldDefinition.getName()); if (STRING_LIKE_PRIMITIVES.contains(type)) { return new StringSchema.Builder() .title(title) .description(fieldDefinition.getDescription()) .build(); } if (NUMBER_LIKE_PRIMITIVES.contains(type)) { return new NumberSchema.Builder() .title(title) .description(fieldDefinition.getDescription()) .build(); } if (type.equals(BooleanAttributeValue.SERIALIZATION_TYPE)) { return new BooleanSchema.Builder() .title(title) .description(fieldDefinition.getDescription()) .build(); } throw CannotMapJsonSchema.becauseUnknownPrimitiveTypeEncountered(type); } private void mapArrayField( FieldDefinition field, ObjectSchema.Builder builder, FormMapperContext formMapperContext, Boolean omitExtension ) { var itemSchema = this.getSchema(field, formMapperContext, omitExtension); String title = String.format("List of %s", formatMachineReadableToHumanReadable(field.getName())); builder.addPropertySchema( field.getName(), new ArraySchema.Builder() .allItemSchema(itemSchema) .title(title).build() ); } private Map<String, Object> printSchema(ObjectSchema schema, FormMapperContext formMapperContext) { try { var map = new ObjectMapper().readValue( schema.toString(), new TypeReference<HashMap<String, Object>>() { }); var definitionsMap = new HashMap<String, Object>(); formMapperContext.getComplexTypeSchemas().forEach( (typeName, definition) -> definitionsMap.put(typeName, this.printDefinition(definition)) ); map.put("definitions", definitionsMap); return map; } catch (JsonProcessingException e) { throw new CannotPrintJSONSchema(e); } } private Map<String, Object> printDefinition(ObjectSchema schema) { try { return new ObjectMapper().readValue( schema.toString(), new TypeReference<HashMap<String, Object>>() { }); } catch (JsonProcessingException e) { throw new CannotPrintJSONSchema(e); } } private static String formatMachineReadableToHumanReadable(String string) { StringBuilder result = new StringBuilder(); for (int i = 0; i < string.length(); i++) { if (shouldInsertSpace(string, i)) { result.append(" "); } result.append(i == 0 ? Character.toUpperCase(string.charAt(i)) : string.charAt(i)); } return result.toString(); } private static boolean shouldInsertSpace(String string, int index) { return isUppercase(string, index) && (isStartOfWord(string, index) || isEndOfAcronym(string, index)); } private static boolean isUppercase(String string, int index) { return Character.isUpperCase(string.charAt(index)); } private static boolean isStartOfWord(String string, int index) { return index > 0 && !isUppercase(string, index - 1); } private static boolean isEndOfAcronym(String string, int index) { return index < string.length() - 1 && !isUppercase(string, index + 1); } private static class FormMapperContext { private final Set<String> encounteredComplexTypes; private final Map<String, ObjectSchema> complexTypeSchemas; public FormMapperContext() { this.encounteredComplexTypes = new HashSet<>(); this.complexTypeSchemas = new HashMap<>(); } public void putSchema(String typeName, ObjectSchema schema) { this.complexTypeSchemas.put(typeName, schema); } public void addType(String typeName) { this.encounteredComplexTypes.add(typeName); } public boolean hasType(String typeName) { return this.encounteredComplexTypes.contains(typeName); } public Set<String> getEncounteredComplexTypes() { return encounteredComplexTypes; } public Map<String, ObjectSchema> getComplexTypeSchemas() { return complexTypeSchemas; } } }
0
java-sources/ai/stapi/form-api/0.2.3/ai/stapi/formapi
java-sources/ai/stapi/form-api/0.2.3/ai/stapi/formapi/formmapper/NullFormDataLoader.java
package ai.stapi.formapi.formmapper; import ai.stapi.graphsystem.operationdefinition.model.OperationDefinitionDTO; import java.util.Map; public class NullFormDataLoader implements FormDataLoader { @Override public Map<String, Object> load( OperationDefinitionDTO operationDefinitionDTO, String resourceId, Map<String, Object> possibleStartIds ) { return Map.of(); } }
0
java-sources/ai/stapi/form-api/0.2.3/ai/stapi/formapi
java-sources/ai/stapi/form-api/0.2.3/ai/stapi/formapi/formmapper/NullUISchemaLoader.java
package ai.stapi.formapi.formmapper; import ai.stapi.graphsystem.operationdefinition.model.OperationDefinitionDTO; import java.util.Map; public class NullUISchemaLoader implements UISchemaLoader { @Override public Map<String, Object> load(OperationDefinitionDTO operationDefinitionDTO) { return Map.of(); } }
0
java-sources/ai/stapi/form-api/0.2.3/ai/stapi/formapi
java-sources/ai/stapi/form-api/0.2.3/ai/stapi/formapi/formmapper/UISchemaLoader.java
package ai.stapi.formapi.formmapper; import ai.stapi.graphsystem.operationdefinition.model.OperationDefinitionDTO; import java.util.Map; public interface UISchemaLoader { Map<String, Object> load(OperationDefinitionDTO operationDefinitionDTO); }
0
java-sources/ai/stapi/form-api/0.2.3/ai/stapi/formapi/formmapper
java-sources/ai/stapi/form-api/0.2.3/ai/stapi/formapi/formmapper/exceptions/CannotLoadFormData.java
package ai.stapi.formapi.formmapper.exceptions; public class CannotLoadFormData extends RuntimeException { private static final String MSG = "Cannot load data for form, because "; private CannotLoadFormData(String becauseMessage) { super(MSG + becauseMessage); } private CannotLoadFormData(String becauseMessage, Throwable cause) { super(MSG + becauseMessage, cause); } public static CannotLoadFormData becauseThereWasNoCommandHandlerDefinitionForProvidedOperation( String operationId ) { return new CannotLoadFormData( String.format( "there was not command handler definition with provided operation.%nOperation name: '%s'", operationId ) ); } public static CannotLoadFormData becauseThereWasNoCommandHandlerDefinitionForProvidedOperation( String operationId, Throwable cause ) { return new CannotLoadFormData( String.format( "there was not command handler definition with provided operation.%nOperation name: '%s'", operationId ), cause ); } public static CannotLoadFormData becauseAggregateByProvidedResourceIdWasNotFound( String resourceId, Throwable cause ) { return new CannotLoadFormData( String.format( "no aggregate with provided resource id was found.%nResource id: '%s'", resourceId ), cause ); } }
0
java-sources/ai/stapi/form-api/0.2.3/ai/stapi/formapi/formmapper
java-sources/ai/stapi/form-api/0.2.3/ai/stapi/formapi/formmapper/exceptions/CannotMapJsonSchema.java
package ai.stapi.formapi.formmapper.exceptions; public class CannotMapJsonSchema extends RuntimeException { private CannotMapJsonSchema(String becauseMessage) { super("Cannot map JSON Schema, because " + becauseMessage); } public static CannotMapJsonSchema becauseUnknownPrimitiveTypeEncountered(String type) { return new CannotMapJsonSchema( String.format("unknown primitive type encountered.%nType: '%s'", type) ); } }
0
java-sources/ai/stapi/form-api/0.2.3/ai/stapi/formapi/formmapper
java-sources/ai/stapi/form-api/0.2.3/ai/stapi/formapi/formmapper/exceptions/CannotPrintJSONSchema.java
package ai.stapi.formapi.formmapper.exceptions; public class CannotPrintJSONSchema extends RuntimeException { public CannotPrintJSONSchema(Throwable cause) { super("Something went wrong when printing JSON Schema.", cause); } }
0
java-sources/ai/stapi/graph/0.3.2/ai/stapi
java-sources/ai/stapi/graph/0.3.2/ai/stapi/graph/AttributeContainer.java
package ai.stapi.graph; import ai.stapi.graph.attribute.Attribute; import ai.stapi.graph.exceptions.GraphException; import ai.stapi.graph.versionedAttributes.VersionedAttribute; import ai.stapi.graph.versionedAttributes.VersionedAttributeGroup; import java.io.Serializable; public interface AttributeContainer extends Serializable { AttributeContainer add(Attribute<?> attribute); VersionedAttribute<?> getVersionedAttribute(String name); Attribute<?> getAttribute(String name) throws GraphException; boolean containsAttribute(String name, Object value); boolean containsAttribute(String name); Object getAttributeValue(String name); boolean hasAttribute(String name); VersionedAttributeGroup getVersionedAttributes(); }
0
java-sources/ai/stapi/graph/0.3.2/ai/stapi
java-sources/ai/stapi/graph/0.3.2/ai/stapi/graph/EdgeLoader.java
package ai.stapi.graph; import ai.stapi.graph.traversableGraphElements.TraversableEdge; import ai.stapi.identity.UniqueIdentifier; import java.util.List; public interface EdgeLoader { List<TraversableEdge> loadEdges(UniqueIdentifier nodeId, String nodeType, String edgeType); List<TraversableEdge> loadEdges(UniqueIdentifier id, String nodeType); int getIdlessHashCodeForEdgesOnNode(UniqueIdentifier nodeId, String nodeType); }
0
java-sources/ai/stapi/graph/0.3.2/ai/stapi
java-sources/ai/stapi/graph/0.3.2/ai/stapi/graph/EdgeRepository.java
package ai.stapi.graph; import ai.stapi.graph.graphElementForRemoval.EdgeForRemoval; import ai.stapi.graph.graphelements.Edge; import ai.stapi.graph.traversableGraphElements.TraversableEdge; import ai.stapi.identity.UniqueIdentifier; import java.util.List; import java.util.Set; public interface EdgeRepository { void save(Edge edge); TraversableEdge loadEdge(UniqueIdentifier id, String type); boolean edgeExists(UniqueIdentifier id, String type); void replace(Edge edge); void removeEdge(UniqueIdentifier edgeId, String edgeType); void removeEdge(EdgeForRemoval edgeForRemoval); List<EdgeTypeInfo> getEdgeTypeInfos(); Set<TraversableEdge> findInAndOutEdgesForNode(UniqueIdentifier nodeId, String nodeType); TraversableEdge findEdgeByTypeAndNodes( String edgeType, NodeIdAndType nodeFrom, NodeIdAndType nodeTo ); }
0
java-sources/ai/stapi/graph/0.3.2/ai/stapi
java-sources/ai/stapi/graph/0.3.2/ai/stapi/graph/EdgeTypeInfo.java
package ai.stapi.graph; public class EdgeTypeInfo { private String type; private Long count; public EdgeTypeInfo(String type, Long count) { this.type = type; this.count = count; } public String getType() { return type; } public Long getCount() { return count; } }
0
java-sources/ai/stapi/graph/0.3.2/ai/stapi
java-sources/ai/stapi/graph/0.3.2/ai/stapi/graph/Graph.java
package ai.stapi.graph; import ai.stapi.graph.exceptions.EdgeNotFound; import ai.stapi.graph.exceptions.EdgeWithSameIdAndTypeAlreadyExists; import ai.stapi.graph.exceptions.MoreThanOneNodeOfTypeFoundException; import ai.stapi.graph.exceptions.NodeNotFound; import ai.stapi.graph.exceptions.NodeOfTypeNotFoundException; import ai.stapi.graph.exceptions.NodeWithSameIdAndTypeAlreadyExists; import ai.stapi.graph.exceptions.OneOrBothNodesOnEdgeDoesNotExist; import ai.stapi.graph.graphElementForRemoval.EdgeForRemoval; import ai.stapi.graph.graphElementForRemoval.GraphElementForRemoval; import ai.stapi.graph.graphElementForRemoval.NodeForRemoval; import ai.stapi.graph.graphelements.Edge; import ai.stapi.graph.graphelements.Node; import ai.stapi.graph.inMemoryGraph.DeduplicateOptions; import ai.stapi.graph.inMemoryGraph.InMemoryGraphRepository; import ai.stapi.graph.inMemoryGraph.exceptions.CannotCreateGraphWithOtherThanGraphElements; import ai.stapi.graph.inMemoryGraph.exceptions.GraphEdgesCannotBeMerged; import ai.stapi.graph.traversableGraphElements.TraversableEdge; import ai.stapi.identity.UniqueIdentifier; import com.google.common.collect.ImmutableMap; import java.util.Arrays; import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Set; import java.util.stream.Collectors; import org.apache.commons.collections4.map.LinkedMap; public class Graph { private ImmutableMap<GloballyUniqueIdentifier, Node> nodeMap; private ImmutableMap<GloballyUniqueIdentifier, Edge> edgeMap; private ImmutableMap<String, Long> nodeTypeCounts; private ImmutableMap<String, Long> edgeTypeCounts; public Graph() { this.nodeMap = ImmutableMap.of(); this.edgeMap = ImmutableMap.of(); this.nodeTypeCounts = ImmutableMap.of(); this.edgeTypeCounts = ImmutableMap.of(); } public Graph(AttributeContainer... graphElements) { this(); var newInMemoryGraph = this.withAll(graphElements); this.nodeMap = ImmutableMap.copyOf(newInMemoryGraph.nodeMap); this.edgeMap = ImmutableMap.copyOf(newInMemoryGraph.edgeMap); this.nodeTypeCounts = ImmutableMap.copyOf(newInMemoryGraph.nodeTypeCounts); this.edgeTypeCounts = ImmutableMap.copyOf(newInMemoryGraph.edgeTypeCounts); } private Graph( Map<GloballyUniqueIdentifier, Node> nodeMap, Map<GloballyUniqueIdentifier, Edge> edgeMap, Map<String, Long> nodeTypeCounts, Map<String, Long> edgeTypeCounts ) { this.nodeMap = ImmutableMap.copyOf(nodeMap); this.edgeMap = ImmutableMap.copyOf(edgeMap); this.nodeTypeCounts = ImmutableMap.copyOf(nodeTypeCounts); this.edgeTypeCounts = ImmutableMap.copyOf(edgeTypeCounts); } private Graph( Map<GloballyUniqueIdentifier, Node> nodeMap, Map<GloballyUniqueIdentifier, Edge> edgeMap ) { HashMap<String, Long> newNodeTypeCounts = new HashMap<>(); HashMap<String, Long> newEdgeTypeCounts = new HashMap<>(); nodeMap.values().forEach( node -> newNodeTypeCounts.put( node.getType(), newNodeTypeCounts.getOrDefault(node.getType(), 0L) + 1 ) ); edgeMap.values().forEach( edge -> newEdgeTypeCounts.put( edge.getType(), newEdgeTypeCounts.getOrDefault(edge.getType(), 0L) + 1 ) ); this.nodeMap = ImmutableMap.copyOf(nodeMap); this.edgeMap = ImmutableMap.copyOf(edgeMap); this.nodeTypeCounts = ImmutableMap.copyOf(newNodeTypeCounts); this.edgeTypeCounts = ImmutableMap.copyOf(newEdgeTypeCounts); } public static Graph unsafe( Map<GloballyUniqueIdentifier, Node> nodeMap, Map<GloballyUniqueIdentifier, Edge> edgeMap ) { return new Graph(nodeMap, edgeMap); } public InMemoryGraphRepository traversable() { return new InMemoryGraphRepository(this); } public Graph with(Node node) { if (this.nodeExists(node.getId(), node.getType())) { throw new NodeWithSameIdAndTypeAlreadyExists(node.getId(), node.getType()); } Map<GloballyUniqueIdentifier, Node> newNodeMap = new LinkedMap<>(this.nodeMap); newNodeMap.put( new GloballyUniqueIdentifier(node.getId(), node.getType()), node ); Map<String, Long> newNodeTypeCounts = new LinkedMap<>(this.nodeTypeCounts); newNodeTypeCounts.put( node.getType(), newNodeTypeCounts.getOrDefault( node.getType(), 0L ) + 1 ); return new Graph( newNodeMap, this.edgeMap, newNodeTypeCounts, this.edgeTypeCounts ); } public Graph with(Edge edge) { this.ensureEdgeWithSameIdAndTypeDoesNotExistsAlready(edge.getId(), edge.getType()); this.ensureContainsBothNodesOnEdge(edge); var newEdgeMap = new LinkedMap<>(this.edgeMap); newEdgeMap.put(new GloballyUniqueIdentifier(edge.getId(), edge.getType()), edge); var newEdgeTypeCounts = new LinkedMap<>(this.edgeTypeCounts); newEdgeTypeCounts.put( edge.getType(), newEdgeTypeCounts.getOrDefault(edge.getType(), 0L) + 1 ); return new Graph( this.nodeMap, newEdgeMap, this.nodeTypeCounts, newEdgeTypeCounts ); } private void ensureEdgeWithSameIdAndTypeDoesNotExistsAlready(UniqueIdentifier id, String edgeType) { if (this.edgeExists(id, edgeType)) { throw new EdgeWithSameIdAndTypeAlreadyExists(id.getId(), edgeType); } } public Graph withAll(AttributeContainer... graphElements) { Graph newGraph = this; var invalidObjects = Arrays.stream(graphElements) .filter(graphElement -> !(graphElement instanceof Node) && !(graphElement instanceof Edge)) .count(); if (invalidObjects > 0) { throw new CannotCreateGraphWithOtherThanGraphElements(); } for (AttributeContainer graphElement : graphElements) { if (graphElement instanceof Node node) { newGraph = newGraph.with(node); } if (graphElement instanceof Edge edge) { newGraph = newGraph.with(edge); } } return newGraph; } public Node getNode(UniqueIdentifier uniqueIdentifier, String nodeType) { var globallyUniqueIdentifier = new GloballyUniqueIdentifier(uniqueIdentifier, nodeType); if (!this.nodeMap.containsKey(globallyUniqueIdentifier)) { throw new NodeNotFound(uniqueIdentifier, nodeType); } var foundNode = this.nodeMap.get(globallyUniqueIdentifier); if (foundNode == null || !foundNode.getType().equals(nodeType)) { throw new NodeNotFound(uniqueIdentifier, nodeType); } return foundNode; } public Edge getEdge(UniqueIdentifier id, String edgeType) { var globallyUniqueIdentifier = new GloballyUniqueIdentifier(id, edgeType); if (!this.edgeMap.containsKey(globallyUniqueIdentifier)) { throw new EdgeNotFound(id, edgeType); } var foundEdge = this.edgeMap.get(globallyUniqueIdentifier); if (foundEdge == null || !foundEdge.getType().equals(edgeType)) { throw new EdgeNotFound(id, edgeType); } return foundEdge; } public Node getExactlyOneNodeOfType(String nodeType) { var foundNodes = this.getAllNodes(nodeType); if (foundNodes.isEmpty()) { throw new NodeOfTypeNotFoundException(nodeType); } if (foundNodes.size() > 1) { throw new MoreThanOneNodeOfTypeFoundException(nodeType); } return foundNodes.get(0); } public List<Node> getAllNodes() { return this.nodeMap.values().stream().toList(); } public List<Node> getAllNodes(String nodeType) { return this.nodeMap.values().stream() .filter(node -> node.getType().equals(nodeType)) .toList(); } public List<Edge> getAllEdges() { return this.edgeMap.values().stream().toList(); } public List<Edge> loadAllEdges(String edgeType) { return this.edgeMap.values().stream() .filter(edge -> edge.getType().equals(edgeType)) .toList(); } public Graph replace(Node node) { var newNodeMap = new LinkedMap<>(this.nodeMap); var newNodeTypeCounts = new LinkedMap<>(this.nodeTypeCounts); var globallyUniqueIdentifier = new GloballyUniqueIdentifier(node.getId(), node.getType()); var oldNode = this.nodeMap.get(globallyUniqueIdentifier); newNodeMap.put(globallyUniqueIdentifier, node); if (newNodeTypeCounts.containsKey(Objects.requireNonNull(oldNode).getType())) { long oldCount = newNodeTypeCounts.get(oldNode.getType()); newNodeTypeCounts.put(oldNode.getType(), oldCount - 1); } if (newNodeTypeCounts.containsKey(node.getType())) { long newCount = newNodeTypeCounts.get(node.getType()); newNodeTypeCounts.put(node.getType(), newCount + 1); } else { newNodeTypeCounts.put(node.getType(), 1L); } return new Graph( newNodeMap, this.edgeMap, newNodeTypeCounts, this.edgeTypeCounts ); } public Graph removeNode(UniqueIdentifier id, String nodeType) { if (!this.nodeExists(id, nodeType)) { return this; } var newEdgeMap = new LinkedMap<>(this.edgeMap); Set<TraversableEdge> inAndOutEdgesForNode = this.traversable().findInAndOutEdgesForNode( id, nodeType ); inAndOutEdgesForNode.forEach( traversableEdge -> newEdgeMap.remove( new GloballyUniqueIdentifier(traversableEdge.getId(), traversableEdge.getType()) ) ); var newNodeMap = new LinkedMap<>(this.nodeMap); newNodeMap.remove(new GloballyUniqueIdentifier(id, nodeType)); return new Graph( newNodeMap, newEdgeMap ); } public Graph removeNode(NodeForRemoval nodeForRemoval) { return this.removeNode(nodeForRemoval.getGraphElementId(), nodeForRemoval.getGraphElementType()); } public boolean nodeExists(UniqueIdentifier id, String type) { var globallyUniqueIdentifier = new GloballyUniqueIdentifier(id, type); return this.nodeMap.containsKey(globallyUniqueIdentifier) && Objects.requireNonNull(this.nodeMap.get(globallyUniqueIdentifier)).getType().equals(type); } public boolean containsNodeOfType(String nodeType) { return this.nodeTypeCounts.containsKey(nodeType); } public boolean edgeExists(UniqueIdentifier id, String type) { var globallyUniqueIdentifier = new GloballyUniqueIdentifier(id, type); return this.edgeMap.containsKey(globallyUniqueIdentifier) && Objects.requireNonNull(this.edgeMap.get(globallyUniqueIdentifier)).getType().equals(type); } public List<NodeTypeInfo> getNodeTypeInfos() { return this.nodeTypeCounts.entrySet().stream() .map(entry -> new NodeTypeInfo(entry.getKey(), entry.getValue())) .collect(Collectors.toList()); } public List<EdgeTypeInfo> getEdgeTypeInfos() { return this.edgeTypeCounts.entrySet().stream() .map(entry -> new EdgeTypeInfo(entry.getKey(), entry.getValue())) .collect(Collectors.toList()); } public List<NodeInfo> getNodeInfosBy(String nodeType) { return this.nodeMap.values().stream() .filter(graphNode -> graphNode.getType().equals(nodeType)) .map(graphNode -> new NodeInfo( graphNode.getId(), graphNode.getType(), this.traversable().loadNode(graphNode.getId(), graphNode.getType()) .getSortingNameWithNodeTypeFallback() ) ).sorted(Comparator.comparing(NodeInfo::getName)) .collect(Collectors.toList()); } public Graph replace(Edge edge) { var newEdgeMap = new LinkedMap<>(this.edgeMap); newEdgeMap.put(new GloballyUniqueIdentifier(edge.getId(), edge.getType()), edge); return new Graph( this.nodeMap, newEdgeMap, this.nodeTypeCounts, this.edgeTypeCounts ); } public Graph removeEdge(UniqueIdentifier edgeId, String edgeType) { if (!this.edgeExists(edgeId, edgeType)) { return this; } var globallyUniqueIdentifier = new GloballyUniqueIdentifier(edgeId, edgeType); var newEdgeMap = new LinkedMap<>(this.edgeMap); newEdgeMap.remove(globallyUniqueIdentifier); Map<String, Long> newEdgeTypeCounts = new LinkedMap<>(this.edgeTypeCounts); newEdgeTypeCounts.put( edgeType, newEdgeTypeCounts.getOrDefault(edgeType, 1L) - 1 ); return new Graph( this.nodeMap, newEdgeMap, this.nodeTypeCounts, newEdgeTypeCounts ); } public Graph removeEdge(EdgeForRemoval edgeForRemoval) { return this.removeEdge(edgeForRemoval.getGraphElementId(), edgeForRemoval.getGraphElementType()); } public Edge findEdgeByTypeAndNodes( String edgeType, NodeIdAndType nodeFromIdAndType, NodeIdAndType nodeToIdAndType ) { return this.edgeMap.values().stream() .filter(edge -> edge.getType().equals(edgeType) && edge.getNodeFromIdAndType().equals(nodeFromIdAndType) && edge.getNodeToIdAndType().equals(nodeToIdAndType) ).map(edge -> this.getEdge(edge.getId(), edge.getType())) .findFirst() .orElse(null); } public Graph merge(Graph otherGraph) { var newGraph = this; for (Node node : otherGraph.nodeMap.values()) { newGraph = newGraph.mergeNodeById(node); } for (Edge edge : otherGraph.edgeMap.values()) { newGraph = newGraph.merge(edge); } return newGraph; } public Graph removeGraphElements( GraphElementForRemoval... graphElementsForRemoval ) { return this.removeGraphElements(Arrays.stream(graphElementsForRemoval).toList()); } public Graph removeGraphElements( List<GraphElementForRemoval> graphElementsForRemoval ) { var newGraph = this; for (GraphElementForRemoval graphElementForRemoval : graphElementsForRemoval) { newGraph = newGraph.removeGraphElement(graphElementForRemoval); } return newGraph; } public Graph removeGraphElement(GraphElementForRemoval graphElementForRemoval) { var newGraph = this; if (graphElementForRemoval instanceof NodeForRemoval nodeForRemoval) { newGraph = this.removeNode(nodeForRemoval); } if (graphElementForRemoval instanceof EdgeForRemoval edgeForRemoval) { newGraph = this.removeEdge(edgeForRemoval); } return newGraph; } public Graph merge(Edge otherEdge) { if (!this.nodeExists( otherEdge.getNodeFromId(), otherEdge.getNodeFromType() ) || !this.nodeExists( otherEdge.getNodeToId(), otherEdge.getNodeToType() )) { throw new OneOrBothNodesOnEdgeDoesNotExist(otherEdge); } var graph = this; var otherEdgeIdentifier = new GloballyUniqueIdentifier(otherEdge.getId(), otherEdge.getType()); var foundEdge = graph.edgeMap.get(otherEdgeIdentifier); if (foundEdge == null) { var newEdgeMap = new LinkedMap<>(graph.edgeMap); newEdgeMap.put(otherEdgeIdentifier, otherEdge); Map<String, Long> newEdgeTypeCounts = new LinkedMap<>(graph.edgeTypeCounts); newEdgeTypeCounts.put( otherEdge.getType(), newEdgeTypeCounts.getOrDefault(otherEdge.getType(), 0L) + 1 ); return new Graph( graph.nodeMap, newEdgeMap, graph.nodeTypeCounts, newEdgeTypeCounts ); } else { var newMergedEdge = foundEdge.mergeOverwrite(otherEdge); var newEdgeMap = new LinkedMap<>(graph.edgeMap); newEdgeMap.put(new GloballyUniqueIdentifier(newMergedEdge.getId(), newMergedEdge.getType()), newMergedEdge); return new Graph( graph.nodeMap, newEdgeMap, graph.nodeTypeCounts, graph.edgeTypeCounts ); } } private void ensureContainsBothNodesOnEdge(Edge edge) { if ( !this.nodeExists(edge.getNodeFromId(), edge.getNodeFromType()) || !this.nodeExists(edge.getNodeToId(), edge.getNodeToType()) ) { throw new OneOrBothNodesOnEdgeDoesNotExist(edge); } } public Graph merge( Graph otherGraph, DeduplicateOptions options ) { if (options.equals(DeduplicateOptions.SAME_EDGE_TYPES_BETWEEN_SAME_NODES)) { return this.mergeWithEdgeDeduplication(otherGraph); } return this.merge(otherGraph); } private Graph mergeWithEdgeDeduplication(Graph otherGraph) { var newGraph = this; for (Node node : otherGraph.getAllNodes()) { newGraph = newGraph.mergeNodeById(node); } for (Edge otherGraphEdge : otherGraph.getAllEdges()) { List<Edge> localGraphEdges = newGraph.getAllEdges().stream().filter(processedEdge -> processedEdge.getNodeFromId().equals(otherGraphEdge.getNodeFromId()) && processedEdge.getNodeToId().equals(otherGraphEdge.getNodeToId()) && processedEdge.getType().equals(otherGraphEdge.getType()) ).collect(Collectors.toList()); if (localGraphEdges.size() > 1) { throw GraphEdgesCannotBeMerged.becauseThereIsMultipleEdgesGivenEdgeCouldBeMergeWith( localGraphEdges.stream().map(Edge::getId).toList() ); } if (localGraphEdges.isEmpty()) { newGraph = newGraph.merge(otherGraphEdge); } if (localGraphEdges.size() == 1) { var newEdge = (Edge) localGraphEdges.get(0).mergeAttributesWithAttributesOf(otherGraphEdge); newGraph = newGraph.merge(newEdge); } } return newGraph; } public Graph mergeNodeById(Node otherNode) { var newNodeMap = new LinkedMap<>(this.nodeMap); var newNodeTypeCounts = new LinkedMap<>(this.nodeTypeCounts); var foundNode = newNodeMap.get(new GloballyUniqueIdentifier(otherNode.getId(), otherNode.getType())); Node newNode; if (foundNode == null) { newNode = otherNode; newNodeTypeCounts.put( newNode.getType(), newNodeTypeCounts.getOrDefault(newNode.getType(), 0L) + 1 ); } else { newNode = foundNode.mergeOverwrite(otherNode); } newNodeMap.put(new GloballyUniqueIdentifier(newNode.getId(), newNode.getType()), newNode); return new Graph( newNodeMap, this.edgeMap, newNodeTypeCounts, this.edgeTypeCounts ); } public static class GloballyUniqueIdentifier { private final UniqueIdentifier uniqueIdentifier; private final String elementType; public GloballyUniqueIdentifier(UniqueIdentifier uniqueIdentifier, String elementType) { this.uniqueIdentifier = uniqueIdentifier; this.elementType = elementType; } public UniqueIdentifier getUniqueIdentifier() { return uniqueIdentifier; } public String getElementType() { return elementType; } @Override public boolean equals(Object other) { if (this == other) { return true; } if (!(other instanceof GloballyUniqueIdentifier otherIdentifier)) { return false; } if (!this.getUniqueIdentifier().equals(otherIdentifier.getUniqueIdentifier())) { return false; } return this.getElementType().equals(otherIdentifier.getElementType()); } @Override public int hashCode() { int result = this.getUniqueIdentifier().hashCode(); result = 31 * result + this.getElementType().hashCode(); return result; } } }
0
java-sources/ai/stapi/graph/0.3.2/ai/stapi
java-sources/ai/stapi/graph/0.3.2/ai/stapi/graph/NodeIdAndType.java
package ai.stapi.graph; import ai.stapi.identity.UniqueIdentifier; import java.util.Objects; public class NodeIdAndType { private String type; private UniqueIdentifier id; public static NodeIdAndType fromString(String fullId) { var split = fullId.split("/"); return new NodeIdAndType( new UniqueIdentifier(split[1]), split[0] ); } public NodeIdAndType(UniqueIdentifier id, String type) { this.type = type; this.id = id; } public String getType() { return type; } public UniqueIdentifier getId() { return id; } @Override public boolean equals(Object o) { if (this == o) { return true; } if (!(o instanceof NodeIdAndType that)) { return false; } return getType().equals(that.getType()) && getId().equals(that.getId()); } @Override public int hashCode() { return Objects.hash(getType(), getId()); } @Override public String toString() { return String.format("%s/%s", this.type, this.id.getId()); } }
0
java-sources/ai/stapi/graph/0.3.2/ai/stapi
java-sources/ai/stapi/graph/0.3.2/ai/stapi/graph/NodeInfo.java
package ai.stapi.graph; import ai.stapi.identity.UniqueIdentifier; public class NodeInfo { private UniqueIdentifier id; private String type; private String name; public NodeInfo(UniqueIdentifier id, String type, String name) { this.id = id; this.type = type; this.name = name; } public String getId() { return id.toString(); } public String getType() { return type; } public String getName() { return name; } }
0
java-sources/ai/stapi/graph/0.3.2/ai/stapi
java-sources/ai/stapi/graph/0.3.2/ai/stapi/graph/NodeLoader.java
package ai.stapi.graph; import ai.stapi.graph.traversableGraphElements.TraversableNode; import ai.stapi.identity.UniqueIdentifier; public interface NodeLoader { TraversableNode loadNode(UniqueIdentifier nodeId, String nodeType); }
0
java-sources/ai/stapi/graph/0.3.2/ai/stapi
java-sources/ai/stapi/graph/0.3.2/ai/stapi/graph/NodeRepository.java
package ai.stapi.graph; import ai.stapi.graph.graphElementForRemoval.NodeForRemoval; import ai.stapi.graph.graphelements.Node; import ai.stapi.graph.traversableGraphElements.TraversableNode; import ai.stapi.identity.UniqueIdentifier; import java.util.List; public interface NodeRepository { void save(Node node); TraversableNode loadNode(UniqueIdentifier UniqueIdentifier, String nodeType); void replace(Node node); void removeNode(UniqueIdentifier id, String nodeType); void removeNode(NodeForRemoval nodeForRemoval); boolean nodeExists(UniqueIdentifier id, String nodeType); List<NodeTypeInfo> getNodeTypeInfos(); List<NodeInfo> getNodeInfosBy(String nodeType); }
0
java-sources/ai/stapi/graph/0.3.2/ai/stapi
java-sources/ai/stapi/graph/0.3.2/ai/stapi/graph/NodeTypeInfo.java
package ai.stapi.graph; public class NodeTypeInfo { private String type; private Long count; public NodeTypeInfo(String type, Long count) { this.type = type; this.count = count; } public String getType() { return type; } public Long getCount() { return count; } }
0
java-sources/ai/stapi/graph/0.3.2/ai/stapi
java-sources/ai/stapi/graph/0.3.2/ai/stapi/graph/NullEdgeLoader.java
package ai.stapi.graph; import ai.stapi.graph.traversableGraphElements.TraversableEdge; import ai.stapi.identity.UniqueIdentifier; import java.util.ArrayList; import java.util.List; public class NullEdgeLoader implements EdgeLoader { @Override public List<TraversableEdge> loadEdges(UniqueIdentifier nodeId, String nodeType, String edgeType) { return new ArrayList<>(); } @Override public List<TraversableEdge> loadEdges(UniqueIdentifier id, String nodeType) { return new ArrayList<>(); } @Override public int getIdlessHashCodeForEdgesOnNode(UniqueIdentifier nodeId, String nodeType) { return 0; } }
0
java-sources/ai/stapi/graph/0.3.2/ai/stapi
java-sources/ai/stapi/graph/0.3.2/ai/stapi/graph/NullNodeLoader.java
package ai.stapi.graph; import ai.stapi.graph.traversableGraphElements.TraversableNode; import ai.stapi.identity.UniqueIdentifier; public class NullNodeLoader implements NodeLoader { @Override public TraversableNode loadNode(UniqueIdentifier nodeId, String nodeType) { return null; } }
0
java-sources/ai/stapi/graph/0.3.2/ai/stapi
java-sources/ai/stapi/graph/0.3.2/ai/stapi/graph/RepositoryEdgeLoader.java
package ai.stapi.graph; import ai.stapi.graph.attribute.AbstractAttributeContainer; import ai.stapi.graph.traversableGraphElements.TraversableEdge; import ai.stapi.identity.UniqueIdentifier; import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; public class RepositoryEdgeLoader implements EdgeLoader { private final EdgeRepository edgeRepository; public RepositoryEdgeLoader(EdgeRepository edgeRepository) { this.edgeRepository = edgeRepository; } @Override public List<TraversableEdge> loadEdges( UniqueIdentifier nodeId, String nodeType, String edgeType ) { return this.edgeRepository.findInAndOutEdgesForNode( nodeId, nodeType ).stream() .filter(edge -> edge.getType().equals(edgeType)) .collect(Collectors.toList()); } @Override public List<TraversableEdge> loadEdges(UniqueIdentifier nodeId, String nodeType) { return new ArrayList<>(this.edgeRepository.findInAndOutEdgesForNode( nodeId, nodeType )); } @Override public int getIdlessHashCodeForEdgesOnNode(UniqueIdentifier nodeId, String nodeType) { var inAndOutEdgesForNode = this.edgeRepository.findInAndOutEdgesForNode( nodeId, nodeType ); return inAndOutEdgesForNode.stream() .mapToInt(AbstractAttributeContainer::getIdlessHashCode) .sum(); } }
0
java-sources/ai/stapi/graph/0.3.2/ai/stapi
java-sources/ai/stapi/graph/0.3.2/ai/stapi/graph/RepositoryNodeLoader.java
package ai.stapi.graph; import ai.stapi.graph.traversableGraphElements.TraversableNode; import ai.stapi.identity.UniqueIdentifier; public class RepositoryNodeLoader implements NodeLoader { private final NodeRepository nodeRepository; public RepositoryNodeLoader(NodeRepository nodeRepository) { this.nodeRepository = nodeRepository; } @Override public TraversableNode loadNode(UniqueIdentifier nodeId, String nodeType) { return this.nodeRepository.loadNode( nodeId, nodeType ); } }
0
java-sources/ai/stapi/graph/0.3.2/ai/stapi/graph
java-sources/ai/stapi/graph/0.3.2/ai/stapi/graph/attribute/AbstractAttribute.java
package ai.stapi.graph.attribute; import java.time.Instant; import java.util.HashMap; import java.util.Map; import java.util.Objects; public abstract class AbstractAttribute<T> implements Attribute<T> { private final String name; private final Map<String, MetaData> metaData; protected AbstractAttribute(String name) { this.name = name; this.metaData = new HashMap<>(); } protected AbstractAttribute(String name, Instant createdAt) { this.name = name; this.metaData = new HashMap<>( Map.of(CreatedAtMetaData.NAME, new CreatedAtMetaData(createdAt)) ); } protected AbstractAttribute(String name, Map<String, MetaData> metaData) { this.name = name; this.metaData = new HashMap<>(metaData); } @Override public String getName() { return name; } @Override public Instant getCreatedAt() { var createdAt = this.metaData.get(CreatedAtMetaData.NAME); if (createdAt == null) { return null; } return CreatedAtMetaData .fromMetaData(createdAt) .getInstant(); } @Override public void setCreatedAt(Instant createdAt) { this.metaData.put( CreatedAtMetaData.NAME, new CreatedAtMetaData(createdAt) ); } @Override public Map<String, MetaData> getMetaData() { return this.metaData; } @Override public boolean equals(Object other) { if (this == other) { return true; } if (!(other instanceof AbstractAttribute<?> otherAttribute)) { return false; } return this.getName().equals(otherAttribute.getName()) && this.getValue().equals(otherAttribute.getValue()); } @Override //TODO: Why null? public int hashCode() { return Objects.hash(getName(), getValue(), null); } }
0
java-sources/ai/stapi/graph/0.3.2/ai/stapi/graph
java-sources/ai/stapi/graph/0.3.2/ai/stapi/graph/attribute/AbstractAttributeContainer.java
package ai.stapi.graph.attribute; import ai.stapi.graph.AttributeContainer; import ai.stapi.graph.exceptions.GraphException; import ai.stapi.graph.versionedAttributes.ImmutableVersionedAttributeGroup; import ai.stapi.graph.versionedAttributes.VersionedAttribute; import ai.stapi.graph.versionedAttributes.VersionedAttributeGroup; import java.util.List; import java.util.Objects; import java.util.stream.Collectors; public abstract class AbstractAttributeContainer implements AttributeContainer { private final VersionedAttributeGroup versionedAttributes; protected AbstractAttributeContainer() { this.versionedAttributes = new ImmutableVersionedAttributeGroup(); } protected AbstractAttributeContainer(VersionedAttributeGroup versionedAttributes) { this.versionedAttributes = versionedAttributes; } protected AbstractAttributeContainer(Attribute<?>... attributes) { this(new ImmutableVersionedAttributeGroup(attributes)); } @Override public AttributeContainer add(Attribute<?> attribute) { var newAttributes = this.versionedAttributes.add(attribute); return this.withNewAttributes(newAttributes); } protected abstract AttributeContainer withNewAttributes(VersionedAttributeGroup newAttributes); public VersionedAttributeGroup getVersionedAttributes() { return versionedAttributes; } public List<VersionedAttribute<?>> getVersionedAttributeList() { return versionedAttributes.getVersionedAttributeList(); } public List<Attribute<?>> getFlattenAttributes() { return this.versionedAttributes.getVersionedAttributeList().stream() .flatMap(VersionedAttribute::streamAttributeVersions) .collect(Collectors.toList()); } @Override public VersionedAttribute<?> getVersionedAttribute(String name) { return versionedAttributes.getVersionedAttribute(name); } @Override public Attribute<?> getAttribute(String name) throws GraphException { return this.versionedAttributes.getCurrentAttribute(name); } @Override public boolean containsAttribute(String name, Object value) { return this.versionedAttributes.isValuePresentInAnyVersion(name, value); } @Override public boolean containsAttribute(String name) { return this.versionedAttributes.hasAttribute(name); } @Override public Object getAttributeValue(String name) { return this.versionedAttributes.getCurrentAttributeValue(name); } public AttributeContainer mergeAttributesWithAttributesOf(AbstractAttributeContainer other) { return this.withNewAttributes( this.versionedAttributes.mergeOverwrite(other.getVersionedAttributes())); } @Override public boolean equals(Object o) { if (this == o) { return true; } if (!(o instanceof AbstractAttributeContainer that)) { return false; } return getVersionedAttributes().equals(that.getVersionedAttributes()); } @Override public int hashCode() { return Objects.hash(this.getVersionedAttributes()) + this.getHashCodeWithoutAttributes(); } public int getIdlessHashCode() { VersionedAttributeGroup versionedAttributes1 = this.getVersionedAttributes(); int idlessHashCodeWithoutAttributes = this.getIdlessHashCodeWithoutAttributes(); return Objects.hash(versionedAttributes1) + idlessHashCodeWithoutAttributes; } protected abstract int getHashCodeWithoutAttributes(); protected abstract int getIdlessHashCodeWithoutAttributes(); @Override public boolean hasAttribute(String name) { return this.versionedAttributes.hasAttribute(name); } public int getAttributeCount() { return this.versionedAttributes.numberOfUniqueAttributeNames(); } public String guessBestName() { if (this.hasAttribute("name")) { return (String) this.getAttribute("name").getValue(); } return null; } }
0
java-sources/ai/stapi/graph/0.3.2/ai/stapi/graph
java-sources/ai/stapi/graph/0.3.2/ai/stapi/graph/attribute/Attribute.java
package ai.stapi.graph.attribute; import java.io.Serializable; import java.time.Instant; import java.util.Map; public interface Attribute<T> extends Serializable { String getName(); Instant getCreatedAt(); void setCreatedAt(Instant createdAt); Map<String, MetaData> getMetaData(); T getValue(); Attribute<T> getCopy(); }
0
java-sources/ai/stapi/graph/0.3.2/ai/stapi/graph
java-sources/ai/stapi/graph/0.3.2/ai/stapi/graph/attribute/CreatedAtMetaData.java
package ai.stapi.graph.attribute; import ai.stapi.graph.attribute.attributeValue.InstantAttributeValue; import java.time.Instant; import java.util.List; public class CreatedAtMetaData extends MetaData { public static final String NAME = "createdAt"; public static CreatedAtMetaData fromMetaData(MetaData metaData) { if (metaData instanceof CreatedAtMetaData createdAtMetaData) { return createdAtMetaData; } return new CreatedAtMetaData((InstantAttributeValue) metaData.getValues().get(0)); } public CreatedAtMetaData(InstantAttributeValue instantAttribute) { super(NAME, List.of(instantAttribute)); } public CreatedAtMetaData(Instant utcTime) { super(NAME, List.of(new InstantAttributeValue(utcTime))); } public CreatedAtMetaData(String utcTime) { super(NAME, List.of(new InstantAttributeValue(Instant.parse(utcTime)))); } public Instant getInstant() { return (Instant) this.getValues().get(0).getValue(); } }
0
java-sources/ai/stapi/graph/0.3.2/ai/stapi/graph
java-sources/ai/stapi/graph/0.3.2/ai/stapi/graph/attribute/LeafAttribute.java
package ai.stapi.graph.attribute; import ai.stapi.graph.attribute.attributeValue.AttributeValue; import java.time.Instant; import java.util.Map; public class LeafAttribute<T, AV extends AttributeValue<T>> extends AbstractAttribute<T> { public static final String DATA_STRUCTURE_TYPE = "LeafAttribute"; private final AV boxedValue; public LeafAttribute(String name, Map<String, MetaData> metaData, AV boxedValue) { super(name, metaData); this.boxedValue = boxedValue; } public LeafAttribute(String name, Instant createdAt, AV boxedValue) { super(name, createdAt); this.boxedValue = boxedValue; } public LeafAttribute(String name, AV boxedValue) { super(name); this.boxedValue = boxedValue; } public AV getBoxedValue() { return boxedValue; } @Override public T getValue() { return this.getBoxedValue().getValue(); } @Override public LeafAttribute<T, AV> getCopy() { return new LeafAttribute<>(this.getName(), this.getCreatedAt(), this.getBoxedValue()); } }
0
java-sources/ai/stapi/graph/0.3.2/ai/stapi/graph
java-sources/ai/stapi/graph/0.3.2/ai/stapi/graph/attribute/ListAttribute.java
package ai.stapi.graph.attribute; import ai.stapi.graph.attribute.attributeValue.AttributeValue; import java.time.Instant; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; public class ListAttribute extends AbstractAttribute<List<?>> { public static final String DATA_STRUCTURE_TYPE = "ListAttribute"; private final List<AttributeValue<?>> boxedValues; public ListAttribute(String name, Instant createdAt, List<AttributeValue<?>> values) { super(name, createdAt); this.boxedValues = values; } public ListAttribute(String name, Instant createdAt) { super(name, createdAt); this.boxedValues = new ArrayList<>(); } public ListAttribute(String name, Map<String, MetaData> metaData) { super(name, metaData); this.boxedValues = new ArrayList<>(); } public ListAttribute(String name, Map<String, MetaData> metaData, List<AttributeValue<?>> values) { super(name, metaData); this.boxedValues = values; } public ListAttribute(String name, List<AttributeValue<?>> values) { this(name, new HashMap<>(), values); } public ListAttribute(String name, AttributeValue<?>... values) { this(name, Arrays.stream(values).collect(Collectors.toList())); } public ListAttribute(String name, Instant createdAt, AttributeValue<?>... values) { this(name, createdAt, Arrays.stream(values).collect(Collectors.toList())); } public ListAttribute(String name, Map<String, MetaData> metaData, AttributeValue<?>... values) { this(name, metaData, Arrays.stream(values).collect(Collectors.toList())); } public List<AttributeValue<?>> getBoxedValues() { return boxedValues; } @Override public List<?> getValue() { return this.boxedValues.stream().map(AttributeValue::getValue).toList(); } @Override public ListAttribute getCopy() { return new ListAttribute(this.getName(), this.getMetaData(), this.getBoxedValues()); } }
0
java-sources/ai/stapi/graph/0.3.2/ai/stapi/graph
java-sources/ai/stapi/graph/0.3.2/ai/stapi/graph/attribute/MetaData.java
package ai.stapi.graph.attribute; import ai.stapi.graph.attribute.attributeValue.AttributeValue; import java.util.ArrayList; import java.util.List; public class MetaData { private final String name; private final List<AttributeValue<?>> values; public MetaData( String name, List<AttributeValue<?>> values ) { this.name = name; this.values = new ArrayList<>(values); } public MetaData( String name, AttributeValue<?> value ) { this.name = name; this.values = List.of(value); } public String getName() { return name; } public List<AttributeValue<?>> getValues() { return values; } }
0
java-sources/ai/stapi/graph/0.3.2/ai/stapi/graph
java-sources/ai/stapi/graph/0.3.2/ai/stapi/graph/attribute/SetAttribute.java
package ai.stapi.graph.attribute; import ai.stapi.graph.attribute.attributeValue.AttributeValue; import java.time.Instant; import java.util.Arrays; import java.util.HashMap; import java.util.Map; import java.util.Set; import java.util.stream.Collectors; public class SetAttribute extends AbstractAttribute<Set<?>> { public static final String DATA_STRUCTURE_TYPE = "SetAttribute"; private final Set<AttributeValue<?>> boxedValues; public SetAttribute(String name, Instant createdAt, Set<AttributeValue<?>> values) { super(name, createdAt); this.boxedValues = values; } public SetAttribute(String name, Instant createdAt) { this(name, createdAt, Set.of()); } public SetAttribute(String name, Map<String, MetaData> metaData, Set<AttributeValue<?>> values) { super(name, metaData); this.boxedValues = values; } public SetAttribute(String name, Map<String, MetaData> metaData) { this(name, metaData, Set.of()); } public SetAttribute(String name, Set<AttributeValue<?>> values) { this(name, new HashMap<>(), values); } public SetAttribute(String name, AttributeValue<?>... values) { this(name, Arrays.stream(values).collect(Collectors.toSet())); } public SetAttribute(String name, Instant createdAt, AttributeValue<?>... values) { this(name, createdAt, Arrays.stream(values).collect(Collectors.toSet())); } public SetAttribute(String name, Map<String, MetaData> metaData, AttributeValue<?>... values) { this(name, metaData, Arrays.stream(values).collect(Collectors.toSet())); } public Set<AttributeValue<?>> getBoxedValues() { return boxedValues; } @Override public Set<?> getValue() { return this.boxedValues.stream().map(AttributeValue::getValue).collect(Collectors.toSet()); } @Override public SetAttribute getCopy() { return new SetAttribute(this.getName(), this.getMetaData(), this.getBoxedValues()); } }
0
java-sources/ai/stapi/graph/0.3.2/ai/stapi/graph/attribute
java-sources/ai/stapi/graph/0.3.2/ai/stapi/graph/attribute/attributeFactory/AttributeFactory.java
package ai.stapi.graph.attribute.attributeFactory; import ai.stapi.graph.attribute.Attribute; import ai.stapi.graph.attribute.MetaData; import java.util.List; import java.util.Map; public interface AttributeFactory { Attribute<?> create( String attributeName, List<AttributeValueFactoryInput> parameters, Map<String, MetaData> metaData ); boolean supportsStructureType(String structureType); }
0
java-sources/ai/stapi/graph/0.3.2/ai/stapi/graph/attribute
java-sources/ai/stapi/graph/0.3.2/ai/stapi/graph/attribute/attributeFactory/AttributeValueFactoryInput.java
package ai.stapi.graph.attribute.attributeFactory; public class AttributeValueFactoryInput { private final Object value; private final String dataType; public AttributeValueFactoryInput(Object value, String dataType) { this.value = value; this.dataType = dataType; } public Object getValue() { return value; } public String getDataType() { return dataType; } }
0
java-sources/ai/stapi/graph/0.3.2/ai/stapi/graph/attribute
java-sources/ai/stapi/graph/0.3.2/ai/stapi/graph/attribute/attributeFactory/GenericAttributeFactory.java
package ai.stapi.graph.attribute.attributeFactory; import ai.stapi.graph.attribute.Attribute; import ai.stapi.graph.attribute.MetaData; import ai.stapi.graph.attribute.attributeFactory.exceptions.CannotCreateAttribute; import java.util.List; import java.util.Map; import java.util.stream.Collectors; public class GenericAttributeFactory { private final List<AttributeFactory> attributeFactories; public GenericAttributeFactory(List<AttributeFactory> attributeFactories) { this.attributeFactories = attributeFactories; } public Attribute<?> create( String attributeName, String structureType, List<AttributeValueFactoryInput> values, Map<String, MetaData> metaData ) { var supported = attributeFactories.stream() .filter(factory -> factory.supportsStructureType(structureType)) .toList(); if (supported.isEmpty()) { throw CannotCreateAttribute.becauseProvidedStructureTypeIsNotSupportedByAnyFactory( attributeName, structureType, supported.stream().map(AttributeFactory::getClass).collect(Collectors.toList()) ); } if (supported.size() > 1) { throw CannotCreateAttribute.becauseProvidedStructureTypeIsSupportedByMoreThanOneFactory( attributeName, structureType, supported.stream().map(AttributeFactory::getClass).collect(Collectors.toList()) ); } return supported.get(0).create( attributeName, values, metaData ); } }
0
java-sources/ai/stapi/graph/0.3.2/ai/stapi/graph/attribute
java-sources/ai/stapi/graph/0.3.2/ai/stapi/graph/attribute/attributeFactory/LeafAttributeFactory.java
package ai.stapi.graph.attribute.attributeFactory; import ai.stapi.graph.attribute.Attribute; import ai.stapi.graph.attribute.LeafAttribute; import ai.stapi.graph.attribute.MetaData; import ai.stapi.graph.attribute.attributeFactory.attributeValueFactory.GenericAttributeValueFactory; import ai.stapi.graph.attribute.attributeFactory.exceptions.CannotCreateAttribute; import ai.stapi.utils.Stringifier; import java.util.List; import java.util.Map; import java.util.stream.Collectors; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class LeafAttributeFactory implements AttributeFactory { private final Logger logger; private final GenericAttributeValueFactory attributeValueFactory; public LeafAttributeFactory(GenericAttributeValueFactory attributeValueFactory) { this.logger = LoggerFactory.getLogger(LeafAttributeFactory.class); this.attributeValueFactory = attributeValueFactory; } @Override public Attribute<?> create( String attributeName, List<AttributeValueFactoryInput> parameters, Map<String, MetaData> metaData ) { if (parameters.isEmpty()) { throw CannotCreateAttribute.becauseLeafAttributeHadNoValues(attributeName); } if (parameters.size() > 1) { var stringyfiedValues = parameters.stream() .map(Stringifier::convertToString) .collect(Collectors.joining(", ")); var message = ( """ More values were provided, when creating Leaf Attribute, but it should have exactly one. Attribute name: %s Choosing value at first position. Values: %s """ ).formatted( attributeName, stringyfiedValues ); this.logger.warn(message); } var parameter = parameters.get(0); return new LeafAttribute<>( attributeName, metaData, this.attributeValueFactory.create( attributeName, parameter ) ); } @Override public boolean supportsStructureType(String structureType) { return structureType.equals(LeafAttribute.DATA_STRUCTURE_TYPE); } }
0
java-sources/ai/stapi/graph/0.3.2/ai/stapi/graph/attribute
java-sources/ai/stapi/graph/0.3.2/ai/stapi/graph/attribute/attributeFactory/ListAttributeFactory.java
package ai.stapi.graph.attribute.attributeFactory; import ai.stapi.graph.attribute.Attribute; import ai.stapi.graph.attribute.ListAttribute; import ai.stapi.graph.attribute.MetaData; import ai.stapi.graph.attribute.attributeFactory.attributeValueFactory.GenericAttributeValueFactory; import java.util.List; import java.util.Map; import java.util.stream.Collectors; public class ListAttributeFactory implements AttributeFactory { private final GenericAttributeValueFactory attributeValueFactory; public ListAttributeFactory(GenericAttributeValueFactory attributeValueFactory) { this.attributeValueFactory = attributeValueFactory; } @Override public Attribute<?> create( String attributeName, List<AttributeValueFactoryInput> parameters, Map<String, MetaData> metaData ) { if (parameters.isEmpty()) { return new ListAttribute( attributeName, metaData ); } return new ListAttribute( attributeName, metaData, parameters.stream() .map(param -> this.attributeValueFactory.create(attributeName, param)) .collect(Collectors.toList()) ); } @Override public boolean supportsStructureType(String structureType) { return structureType.equals(ListAttribute.DATA_STRUCTURE_TYPE); } }
0
java-sources/ai/stapi/graph/0.3.2/ai/stapi/graph/attribute
java-sources/ai/stapi/graph/0.3.2/ai/stapi/graph/attribute/attributeFactory/SetAttributeFactory.java
package ai.stapi.graph.attribute.attributeFactory; import ai.stapi.graph.attribute.Attribute; import ai.stapi.graph.attribute.MetaData; import ai.stapi.graph.attribute.SetAttribute; import ai.stapi.graph.attribute.attributeFactory.attributeValueFactory.GenericAttributeValueFactory; import java.util.List; import java.util.Map; import java.util.stream.Collectors; public class SetAttributeFactory implements AttributeFactory { private final GenericAttributeValueFactory attributeValueFactory; public SetAttributeFactory(GenericAttributeValueFactory attributeValueFactory) { this.attributeValueFactory = attributeValueFactory; } @Override public Attribute<?> create( String attributeName, List<AttributeValueFactoryInput> parameters, Map<String, MetaData> metaData ) { return new SetAttribute( attributeName, metaData, parameters.stream() .map(param -> this.attributeValueFactory.create(attributeName, param)) .collect(Collectors.toSet()) ); } @Override public boolean supportsStructureType(String structureType) { return structureType.equals(SetAttribute.DATA_STRUCTURE_TYPE); } }
0
java-sources/ai/stapi/graph/0.3.2/ai/stapi/graph/attribute/attributeFactory
java-sources/ai/stapi/graph/0.3.2/ai/stapi/graph/attribute/attributeFactory/attributeValueFactory/AbstractDateTimeAttributeValueFactory.java
package ai.stapi.graph.attribute.attributeFactory.attributeValueFactory; import ai.stapi.graph.attribute.attributeFactory.exceptions.CannotCreateAttribute; import ai.stapi.graph.attribute.attributeValue.AttributeValue; import java.time.Instant; import java.time.format.DateTimeFormatter; import java.time.format.DateTimeParseException; import java.util.List; import java.util.Optional; public abstract class AbstractDateTimeAttributeValueFactory implements AttributeValueFactory { @Override public AttributeValue<?> create(Object value, String attributeName) { if (!this.isValidValue(value)) { throw CannotCreateAttribute.becauseProvidedValueCouldNotBeConvertedToProvidedDataType( attributeName, this.getSupportedDataType(), value ); } var date = this.parseValueToDate((String) value); return this.createAttributeWithUtcTime(date.orElseThrow()); } @Override public boolean isValidValue(Object value) { if (!(value instanceof String stringValue)) { return false; } return this.parseValueToDate(stringValue).isPresent(); } @Override public boolean supportsDataType(String dataType) { return dataType.equals(this.getSupportedDataType()); } protected abstract AttributeValue<?> createAttributeWithUtcTime( Instant utcTime ); protected abstract String getSupportedDataType(); protected Optional<Instant> parseValueToDate(String value) { for (DateTimeFormatter formatter : getSupportedFormats()) { try { Instant instant = Instant.from(formatter.parse(value)); return Optional.of(Instant.from(instant)); } catch (DateTimeParseException ex) { // If this formatter doesn't work, try the next one } } // If none of the formatters worked, return empty return Optional.empty(); } private List<DateTimeFormatter> getSupportedFormats() { return List.of( DateTimeFormatter.ISO_OFFSET_DATE_TIME, DateTimeFormatter.ISO_INSTANT ); } }
0
java-sources/ai/stapi/graph/0.3.2/ai/stapi/graph/attribute/attributeFactory
java-sources/ai/stapi/graph/0.3.2/ai/stapi/graph/attribute/attributeFactory/attributeValueFactory/AttributeValueFactory.java
package ai.stapi.graph.attribute.attributeFactory.attributeValueFactory; import ai.stapi.graph.attribute.attributeValue.AttributeValue; public interface AttributeValueFactory { AttributeValue<?> create(Object value, String attributeName); boolean supportsDataType(String dataType); boolean isValidValue(Object value); }
0
java-sources/ai/stapi/graph/0.3.2/ai/stapi/graph/attribute/attributeFactory
java-sources/ai/stapi/graph/0.3.2/ai/stapi/graph/attribute/attributeFactory/attributeValueFactory/Base64BinaryValueFactory.java
package ai.stapi.graph.attribute.attributeFactory.attributeValueFactory; import ai.stapi.graph.attribute.attributeFactory.exceptions.CannotCreateAttribute; import ai.stapi.graph.attribute.attributeValue.AttributeValue; import ai.stapi.graph.attribute.attributeValue.Base64BinaryAttributeValue; public class Base64BinaryValueFactory implements AttributeValueFactory { @Override public AttributeValue<?> create(Object value, String attributeName) { if (!this.isValidValue(value)) { throw CannotCreateAttribute.becauseProvidedValueCouldNotBeConvertedToProvidedDataType( attributeName, Base64BinaryAttributeValue.SERIALIZATION_TYPE, value ); } return new Base64BinaryAttributeValue((String) value); } @Override public boolean supportsDataType(String dataType) { return dataType.equals(Base64BinaryAttributeValue.SERIALIZATION_TYPE); } @Override public boolean isValidValue(Object value) { return value instanceof String; } }
0
java-sources/ai/stapi/graph/0.3.2/ai/stapi/graph/attribute/attributeFactory
java-sources/ai/stapi/graph/0.3.2/ai/stapi/graph/attribute/attributeFactory/attributeValueFactory/BooleanValueFactory.java
package ai.stapi.graph.attribute.attributeFactory.attributeValueFactory; import ai.stapi.graph.attribute.attributeFactory.exceptions.CannotCreateAttribute; import ai.stapi.graph.attribute.attributeValue.AttributeValue; import ai.stapi.graph.attribute.attributeValue.BooleanAttributeValue; public class BooleanValueFactory implements AttributeValueFactory { @Override public AttributeValue<?> create(Object value, String attributeName) { if (!this.isValidValue(value)) { throw CannotCreateAttribute.becauseProvidedValueCouldNotBeConvertedToProvidedDataType( attributeName, BooleanAttributeValue.SERIALIZATION_TYPE, value ); } return new BooleanAttributeValue((Boolean) value); } @Override public boolean supportsDataType(String dataType) { return dataType.equals(BooleanAttributeValue.SERIALIZATION_TYPE); } @Override public boolean isValidValue(Object value) { return value instanceof Boolean; } }
0
java-sources/ai/stapi/graph/0.3.2/ai/stapi/graph/attribute/attributeFactory
java-sources/ai/stapi/graph/0.3.2/ai/stapi/graph/attribute/attributeFactory/attributeValueFactory/CanonicalValueFactory.java
package ai.stapi.graph.attribute.attributeFactory.attributeValueFactory; import ai.stapi.graph.attribute.attributeFactory.exceptions.CannotCreateAttribute; import ai.stapi.graph.attribute.attributeValue.AttributeValue; import ai.stapi.graph.attribute.attributeValue.CanonicalAttributeValue; public class CanonicalValueFactory implements AttributeValueFactory { @Override public AttributeValue<?> create(Object value, String attributeName) { if (!this.isValidValue(value)) { throw CannotCreateAttribute.becauseProvidedValueCouldNotBeConvertedToProvidedDataType( attributeName, CanonicalAttributeValue.SERIALIZATION_TYPE, value ); } return new CanonicalAttributeValue((String) value); } @Override public boolean supportsDataType(String dataType) { return dataType.equals(CanonicalAttributeValue.SERIALIZATION_TYPE); } @Override public boolean isValidValue(Object value) { return value instanceof String; } }
0
java-sources/ai/stapi/graph/0.3.2/ai/stapi/graph/attribute/attributeFactory
java-sources/ai/stapi/graph/0.3.2/ai/stapi/graph/attribute/attributeFactory/attributeValueFactory/CodeValueFactory.java
package ai.stapi.graph.attribute.attributeFactory.attributeValueFactory; import ai.stapi.graph.attribute.attributeFactory.exceptions.CannotCreateAttribute; import ai.stapi.graph.attribute.attributeValue.AttributeValue; import ai.stapi.graph.attribute.attributeValue.CodeAttributeValue; public class CodeValueFactory implements AttributeValueFactory { @Override public AttributeValue<?> create(Object value, String attributeName) { if (!this.isValidValue(value)) { throw CannotCreateAttribute.becauseProvidedValueCouldNotBeConvertedToProvidedDataType( attributeName, CodeAttributeValue.SERIALIZATION_TYPE, value ); } return new CodeAttributeValue((String) value); } @Override public boolean supportsDataType(String dataType) { return dataType.equals(CodeAttributeValue.SERIALIZATION_TYPE); } @Override public boolean isValidValue(Object value) { return value instanceof String; } }
0
java-sources/ai/stapi/graph/0.3.2/ai/stapi/graph/attribute/attributeFactory
java-sources/ai/stapi/graph/0.3.2/ai/stapi/graph/attribute/attributeFactory/attributeValueFactory/DateAttributeValueFactory.java
package ai.stapi.graph.attribute.attributeFactory.attributeValueFactory; import ai.stapi.graph.attribute.attributeFactory.exceptions.CannotCreateAttribute; import ai.stapi.graph.attribute.attributeValue.AttributeValue; import ai.stapi.graph.attribute.attributeValue.DateAttributeValue; import java.time.LocalDate; import java.time.format.DateTimeFormatter; import java.time.format.DateTimeParseException; import java.util.List; import java.util.Optional; public class DateAttributeValueFactory implements AttributeValueFactory { protected AttributeValue<?> createAttributeWithDate(LocalDate utcTime) { return new DateAttributeValue(utcTime); } protected String getSupportedDataType() { return DateAttributeValue.SERIALIZATION_TYPE; } @Override public AttributeValue<?> create(Object value, String attributeName) { if (!this.isValidValue(value)) { throw CannotCreateAttribute.becauseProvidedValueCouldNotBeConvertedToProvidedDataType( attributeName, this.getSupportedDataType(), value ); } var date = this.parseValueToDate((String) value); return this.createAttributeWithDate(date.orElseThrow()); } @Override public boolean isValidValue(Object value) { if (!(value instanceof String stringValue)) { return false; } return this.parseValueToDate(stringValue).isPresent(); } @Override public boolean supportsDataType(String dataType) { return dataType.equals(this.getSupportedDataType()); } protected Optional<LocalDate> parseValueToDate(String value) { try { LocalDate date = LocalDate.parse(value); return Optional.of(date); } catch (DateTimeParseException ex) { // If the parse operation fails, return an empty Optional return Optional.empty(); } } private List<DateTimeFormatter> getSupportedFormats() { return List.of( DateTimeFormatter.ISO_OFFSET_DATE_TIME, DateTimeFormatter.ISO_INSTANT ); } }
0
java-sources/ai/stapi/graph/0.3.2/ai/stapi/graph/attribute/attributeFactory
java-sources/ai/stapi/graph/0.3.2/ai/stapi/graph/attribute/attributeFactory/attributeValueFactory/DateTimeAttributeValueFactory.java
package ai.stapi.graph.attribute.attributeFactory.attributeValueFactory; import ai.stapi.graph.attribute.attributeValue.AttributeValue; import ai.stapi.graph.attribute.attributeValue.DateTimeAttributeValue; import java.time.Instant; public class DateTimeAttributeValueFactory extends AbstractDateTimeAttributeValueFactory { @Override protected AttributeValue<?> createAttributeWithUtcTime(Instant utcTime) { return new DateTimeAttributeValue(utcTime); } @Override protected String getSupportedDataType() { return DateTimeAttributeValue.SERIALIZATION_TYPE; } }
0
java-sources/ai/stapi/graph/0.3.2/ai/stapi/graph/attribute/attributeFactory
java-sources/ai/stapi/graph/0.3.2/ai/stapi/graph/attribute/attributeFactory/attributeValueFactory/DecimalValueFactory.java
package ai.stapi.graph.attribute.attributeFactory.attributeValueFactory; import ai.stapi.graph.attribute.attributeFactory.exceptions.CannotCreateAttribute; import ai.stapi.graph.attribute.attributeValue.AttributeValue; import ai.stapi.graph.attribute.attributeValue.DecimalAttributeValue; import org.apache.commons.lang3.math.NumberUtils; public class DecimalValueFactory implements AttributeValueFactory { @Override public AttributeValue<?> create(Object value, String attributeName) { if (!this.isValidValue(value)) { throw CannotCreateAttribute.becauseProvidedValueCouldNotBeConvertedToProvidedDataType( attributeName, DecimalAttributeValue.SERIALIZATION_TYPE, value ); } if (value instanceof Float floatValue) { return new DecimalAttributeValue(floatValue.doubleValue()); } if (value instanceof Double doubleValue) { return new DecimalAttributeValue(doubleValue); } if (value instanceof Integer integerValue) { return new DecimalAttributeValue(integerValue.doubleValue()); } if (value instanceof String stringValue) { return new DecimalAttributeValue(NumberUtils.createDouble(stringValue)); } throw CannotCreateAttribute.becauseProvidedValueCouldNotBeConvertedToProvidedDataType( attributeName, DecimalAttributeValue.SERIALIZATION_TYPE, value ); } @Override public boolean supportsDataType(String dataType) { return dataType.equals(DecimalAttributeValue.SERIALIZATION_TYPE); } @Override public boolean isValidValue(Object value) { if (value instanceof Float floatValue) { return true; } if (value instanceof Double doubleValue) { return true; } if (value instanceof Integer integerValue) { return true; } if (value instanceof String stringValue) { return NumberUtils.isParsable(stringValue); } return false; } }
0
java-sources/ai/stapi/graph/0.3.2/ai/stapi/graph/attribute/attributeFactory
java-sources/ai/stapi/graph/0.3.2/ai/stapi/graph/attribute/attributeFactory/attributeValueFactory/GenericAttributeValueFactory.java
package ai.stapi.graph.attribute.attributeFactory.attributeValueFactory; import ai.stapi.graph.attribute.attributeFactory.AttributeValueFactoryInput; import ai.stapi.graph.attribute.attributeFactory.exceptions.CannotCreateAttribute; import ai.stapi.graph.attribute.attributeValue.AttributeValue; import java.util.List; import java.util.stream.Collectors; public class GenericAttributeValueFactory { private final List<AttributeValueFactory> attributeValueFactories; public GenericAttributeValueFactory(List<AttributeValueFactory> attributeValueFactories) { this.attributeValueFactories = attributeValueFactories; } public AttributeValue<?> create( String attributeName, AttributeValueFactoryInput parameters ) { var valueFactory = this.getSupportedValueFactory( attributeName, parameters.getDataType() ); return valueFactory.create(parameters.getValue(), attributeName); } public boolean isValidValue( String dataType, Object value ) { var valueFactory = this.getSupportedValueFactory("", dataType); return valueFactory.isValidValue(value); } private AttributeValueFactory getSupportedValueFactory(String attributeName, String dataType) { var supported = attributeValueFactories.stream() .filter(factory -> factory.supportsDataType(dataType)) .toList(); if (supported.size() != 1) { throw CannotCreateAttribute.becauseProvidedDataTypeIsNotSupportedByExactlyOneValueFactory( attributeName, dataType, supported.stream().map(AttributeValueFactory::getClass).collect(Collectors.toList()) ); } return supported.get(0); } }
0
java-sources/ai/stapi/graph/0.3.2/ai/stapi/graph/attribute/attributeFactory
java-sources/ai/stapi/graph/0.3.2/ai/stapi/graph/attribute/attributeFactory/attributeValueFactory/IdValueFactory.java
package ai.stapi.graph.attribute.attributeFactory.attributeValueFactory; import ai.stapi.graph.attribute.attributeFactory.exceptions.CannotCreateAttribute; import ai.stapi.graph.attribute.attributeValue.AttributeValue; import ai.stapi.graph.attribute.attributeValue.IdAttributeValue; public class IdValueFactory implements AttributeValueFactory { @Override public AttributeValue<?> create(Object value, String attributeName) { if (!this.isValidValue(value)) { throw CannotCreateAttribute.becauseProvidedValueCouldNotBeConvertedToProvidedDataType( attributeName, IdAttributeValue.SERIALIZATION_TYPE, value ); } return new IdAttributeValue((String) value); } @Override public boolean supportsDataType(String dataType) { return dataType.equals(IdAttributeValue.SERIALIZATION_TYPE); } @Override public boolean isValidValue(Object value) { return value instanceof String; } }
0
java-sources/ai/stapi/graph/0.3.2/ai/stapi/graph/attribute/attributeFactory
java-sources/ai/stapi/graph/0.3.2/ai/stapi/graph/attribute/attributeFactory/attributeValueFactory/InstantAttributeValueFactory.java
package ai.stapi.graph.attribute.attributeFactory.attributeValueFactory; import ai.stapi.graph.attribute.attributeValue.AttributeValue; import ai.stapi.graph.attribute.attributeValue.InstantAttributeValue; import java.time.Instant; public class InstantAttributeValueFactory extends AbstractDateTimeAttributeValueFactory { @Override protected AttributeValue<?> createAttributeWithUtcTime(Instant utcTime) { return new InstantAttributeValue(utcTime); } @Override protected String getSupportedDataType() { return InstantAttributeValue.SERIALIZATION_TYPE; } }
0
java-sources/ai/stapi/graph/0.3.2/ai/stapi/graph/attribute/attributeFactory
java-sources/ai/stapi/graph/0.3.2/ai/stapi/graph/attribute/attributeFactory/attributeValueFactory/IntegerValueFactory.java
package ai.stapi.graph.attribute.attributeFactory.attributeValueFactory; import ai.stapi.graph.attribute.attributeFactory.exceptions.CannotCreateAttribute; import ai.stapi.graph.attribute.attributeValue.AttributeValue; import ai.stapi.graph.attribute.attributeValue.IntegerAttributeValue; public class IntegerValueFactory implements AttributeValueFactory { @Override public AttributeValue<?> create(Object value, String attributeName) { if (!this.isValidValue(value)) { throw CannotCreateAttribute.becauseProvidedValueCouldNotBeConvertedToProvidedDataType( attributeName, IntegerAttributeValue.SERIALIZATION_TYPE, value ); } return new IntegerAttributeValue((Integer) value); } @Override public boolean supportsDataType(String dataType) { return dataType.equals(IntegerAttributeValue.SERIALIZATION_TYPE); } @Override public boolean isValidValue(Object value) { return value instanceof Integer; } }
0
java-sources/ai/stapi/graph/0.3.2/ai/stapi/graph/attribute/attributeFactory
java-sources/ai/stapi/graph/0.3.2/ai/stapi/graph/attribute/attributeFactory/attributeValueFactory/MarkdownValueFactory.java
package ai.stapi.graph.attribute.attributeFactory.attributeValueFactory; import ai.stapi.graph.attribute.attributeFactory.exceptions.CannotCreateAttribute; import ai.stapi.graph.attribute.attributeValue.AttributeValue; import ai.stapi.graph.attribute.attributeValue.MarkdownAttributeValue; public class MarkdownValueFactory implements AttributeValueFactory { @Override public AttributeValue<?> create(Object value, String attributeName) { if (!this.isValidValue(value)) { throw CannotCreateAttribute.becauseProvidedValueCouldNotBeConvertedToProvidedDataType( attributeName, MarkdownAttributeValue.SERIALIZATION_TYPE, value ); } return new MarkdownAttributeValue((String) value); } @Override public boolean supportsDataType(String dataType) { return dataType.equals(MarkdownAttributeValue.SERIALIZATION_TYPE); } @Override public boolean isValidValue(Object value) { return value instanceof String; } }
0
java-sources/ai/stapi/graph/0.3.2/ai/stapi/graph/attribute/attributeFactory
java-sources/ai/stapi/graph/0.3.2/ai/stapi/graph/attribute/attributeFactory/attributeValueFactory/OidValueFactory.java
package ai.stapi.graph.attribute.attributeFactory.attributeValueFactory; import ai.stapi.graph.attribute.attributeFactory.exceptions.CannotCreateAttribute; import ai.stapi.graph.attribute.attributeValue.AttributeValue; import ai.stapi.graph.attribute.attributeValue.OidAttributeValue; public class OidValueFactory implements AttributeValueFactory { @Override public AttributeValue<?> create(Object value, String attributeName) { if (!this.isValidValue(value)) { throw CannotCreateAttribute.becauseProvidedValueCouldNotBeConvertedToProvidedDataType( attributeName, OidAttributeValue.SERIALIZATION_TYPE, value ); } return new OidAttributeValue((String) value); } @Override public boolean supportsDataType(String dataType) { return dataType.equals(OidAttributeValue.SERIALIZATION_TYPE); } @Override public boolean isValidValue(Object value) { return value instanceof String; } }
0
java-sources/ai/stapi/graph/0.3.2/ai/stapi/graph/attribute/attributeFactory
java-sources/ai/stapi/graph/0.3.2/ai/stapi/graph/attribute/attributeFactory/attributeValueFactory/PositiveIntegerValueFactory.java
package ai.stapi.graph.attribute.attributeFactory.attributeValueFactory; import ai.stapi.graph.attribute.attributeFactory.exceptions.CannotCreateAttribute; import ai.stapi.graph.attribute.attributeValue.AttributeValue; import ai.stapi.graph.attribute.attributeValue.PositiveIntegerAttributeValue; public class PositiveIntegerValueFactory implements AttributeValueFactory { @Override public AttributeValue<?> create(Object value, String attributeName) { if (!this.isValidValue(value)) { throw CannotCreateAttribute.becauseProvidedValueCouldNotBeConvertedToProvidedDataType( attributeName, PositiveIntegerAttributeValue.SERIALIZATION_TYPE, value ); } return new PositiveIntegerAttributeValue((Integer) value); } @Override public boolean supportsDataType(String dataType) { return dataType.equals(PositiveIntegerAttributeValue.SERIALIZATION_TYPE); } @Override public boolean isValidValue(Object value) { if (!(value instanceof Integer integerValue)) { return false; } return integerValue >= 0; } }
0
java-sources/ai/stapi/graph/0.3.2/ai/stapi/graph/attribute/attributeFactory
java-sources/ai/stapi/graph/0.3.2/ai/stapi/graph/attribute/attributeFactory/attributeValueFactory/StringValueFactory.java
package ai.stapi.graph.attribute.attributeFactory.attributeValueFactory; import ai.stapi.graph.attribute.attributeFactory.exceptions.CannotCreateAttribute; import ai.stapi.graph.attribute.attributeValue.AttributeValue; import ai.stapi.graph.attribute.attributeValue.StringAttributeValue; public class StringValueFactory implements AttributeValueFactory { @Override public AttributeValue<?> create(Object value, String attributeName) { if (!this.isValidValue(value)) { throw CannotCreateAttribute.becauseProvidedValueCouldNotBeConvertedToProvidedDataType( attributeName, StringAttributeValue.SERIALIZATION_TYPE, value ); } return new StringAttributeValue((String) value); } @Override public boolean supportsDataType(String dataType) { return dataType.equals(StringAttributeValue.SERIALIZATION_TYPE); } @Override public boolean isValidValue(Object value) { return value instanceof String; } }
0
java-sources/ai/stapi/graph/0.3.2/ai/stapi/graph/attribute/attributeFactory
java-sources/ai/stapi/graph/0.3.2/ai/stapi/graph/attribute/attributeFactory/attributeValueFactory/TimeAttributeValueFactory.java
package ai.stapi.graph.attribute.attributeFactory.attributeValueFactory; import ai.stapi.graph.attribute.attributeFactory.exceptions.CannotCreateAttribute; import ai.stapi.graph.attribute.attributeValue.AttributeValue; import ai.stapi.graph.attribute.attributeValue.TimeAttributeValue; import java.time.LocalTime; import java.time.format.DateTimeFormatter; import java.time.format.DateTimeParseException; import java.util.List; import java.util.Optional; public class TimeAttributeValueFactory implements AttributeValueFactory { protected AttributeValue<?> createAttributeWithTime(LocalTime time) { return new TimeAttributeValue(time); } protected String getSupportedDataType() { return TimeAttributeValue.SERIALIZATION_TYPE; } @Override public AttributeValue<?> create(Object value, String attributeName) { if (!this.isValidValue(value)) { throw CannotCreateAttribute.becauseProvidedValueCouldNotBeConvertedToProvidedDataType( attributeName, this.getSupportedDataType(), value ); } var date = this.parseValueToDate((String) value); return this.createAttributeWithTime(date.orElseThrow()); } @Override public boolean isValidValue(Object value) { if (!(value instanceof String stringValue)) { return false; } return this.parseValueToDate(stringValue).isPresent(); } @Override public boolean supportsDataType(String dataType) { return dataType.equals(this.getSupportedDataType()); } protected Optional<LocalTime> parseValueToDate(String value) { try { LocalTime time = LocalTime.parse(value); return Optional.of(time); } catch (DateTimeParseException ex) { // If the parse operation fails, return an empty Optional return Optional.empty(); } } private List<DateTimeFormatter> getSupportedFormats() { return List.of( DateTimeFormatter.ISO_OFFSET_DATE_TIME, DateTimeFormatter.ISO_INSTANT ); } }
0
java-sources/ai/stapi/graph/0.3.2/ai/stapi/graph/attribute/attributeFactory
java-sources/ai/stapi/graph/0.3.2/ai/stapi/graph/attribute/attributeFactory/attributeValueFactory/UnknownValueFactory.java
package ai.stapi.graph.attribute.attributeFactory.attributeValueFactory; import ai.stapi.graph.attribute.attributeValue.AttributeValue; import ai.stapi.graph.attribute.attributeValue.UnknownAttributeValue; public class UnknownValueFactory implements AttributeValueFactory { @Override public AttributeValue<?> create(Object value, String attributeName) { return new UnknownAttributeValue(value); } @Override public boolean supportsDataType(String dataType) { return dataType.equals(UnknownAttributeValue.SERIALIZATION_TYPE); } @Override public boolean isValidValue(Object value) { return true; } }
0
java-sources/ai/stapi/graph/0.3.2/ai/stapi/graph/attribute/attributeFactory
java-sources/ai/stapi/graph/0.3.2/ai/stapi/graph/attribute/attributeFactory/attributeValueFactory/UnsignedIntegerValueFactory.java
package ai.stapi.graph.attribute.attributeFactory.attributeValueFactory; import ai.stapi.graph.attribute.attributeFactory.exceptions.CannotCreateAttribute; import ai.stapi.graph.attribute.attributeValue.AttributeValue; import ai.stapi.graph.attribute.attributeValue.UnsignedIntegerAttributeValue; public class UnsignedIntegerValueFactory implements AttributeValueFactory { @Override public AttributeValue<?> create(Object value, String attributeName) { if (!this.isValidValue(value)) { throw CannotCreateAttribute.becauseProvidedValueCouldNotBeConvertedToProvidedDataType( attributeName, UnsignedIntegerAttributeValue.SERIALIZATION_TYPE, value ); } return new UnsignedIntegerAttributeValue((Integer) value); } @Override public boolean supportsDataType(String dataType) { return dataType.equals(UnsignedIntegerAttributeValue.SERIALIZATION_TYPE); } @Override public boolean isValidValue(Object value) { return value instanceof Integer; } }