org.atemsource.atem.utility.schema.SchemaBuilder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of atem-utility Show documentation
Show all versions of atem-utility Show documentation
Atem utilities for cloning, comparing and transforming
The newest version!
package org.atemsource.atem.utility.schema;
import javax.annotation.PostConstruct;
import org.atemsource.atem.api.attribute.Attribute;
import org.atemsource.atem.api.attribute.CollectionAttribute;
import org.atemsource.atem.api.attribute.relation.ListAssociationAttribute;
import org.atemsource.atem.api.attribute.relation.SingleAttribute;
import org.atemsource.atem.api.type.EntityType;
import org.atemsource.atem.api.type.EntityTypeBuilder;
import org.atemsource.atem.api.type.Type;
import org.atemsource.atem.api.type.primitive.DateType;
import org.atemsource.atem.api.type.primitive.IntegerType;
import org.atemsource.atem.api.type.primitive.TextType;
import org.atemsource.atem.spi.DynamicEntityTypeSubrepository;
import org.atemsource.atem.utility.transform.api.Converter;
import org.atemsource.atem.utility.transform.api.JavaConverter;
import org.atemsource.atem.utility.transform.api.JavaTransformation;
import org.atemsource.atem.utility.transform.api.TransformationBuilderFactory;
import org.atemsource.atem.utility.transform.api.TransformationContext;
import org.atemsource.atem.utility.transform.api.TypeTransformationBuilder;
import org.atemsource.atem.utility.transform.impl.EntityTypeTransformation;
import org.atemsource.atem.utility.transform.impl.builder.CollectionToMap;
import org.atemsource.atem.utility.transform.impl.builder.Embed;
import org.atemsource.atem.utility.transform.impl.builder.GenericTransformationBuilder;
import org.atemsource.atem.utility.transform.impl.builder.OneToOneAttributeTransformationBuilder;
import org.atemsource.atem.utility.transform.impl.builder.SingleAttributeTransformationBuilder;
import org.atemsource.atem.utility.transform.impl.converter.ConverterUtils;
import org.codehaus.jackson.node.ObjectNode;
public class SchemaBuilder
{
private EntityTypeTransformation, ?> primitiveTypeTransformation;
private DynamicEntityTypeSubrepository> subrepository;
private EntityTypeTransformation transformation;
private TransformationBuilderFactory transformationBuilderFactory;
private void createDateTypeTransformation(EntityTypeTransformation superTransformation)
{
EntityTypeBuilder typeBuilder = subrepository.createBuilder("date-type");
TypeTransformationBuilder transformationBuilder =
transformationBuilderFactory.create(DateType.class, typeBuilder);
transformationBuilder.includeSuper(superTransformation);
transformationBuilder.buildTypeTransformation();
}
private void createIntegerTypeTransformation(EntityTypeTransformation superTransformation)
{
EntityTypeBuilder typeBuilder = subrepository.createBuilder("integer-type");
TypeTransformationBuilder transformationBuilder =
transformationBuilderFactory.create(IntegerType.class, typeBuilder);
transformationBuilder.includeSuper(superTransformation);
transformationBuilder.buildTypeTransformation();
}
private void createListTypeTransformation(EntityTypeTransformation superTransformation)
{
EntityTypeBuilder typeBuilder = subrepository.createBuilder("list-type");
TypeTransformationBuilder transformationBuilder =
transformationBuilderFactory.create(ListAssociationAttribute.class, typeBuilder);
transformationBuilder.includeSuper(superTransformation);
transformationBuilder.buildTypeTransformation();
}
private void createTextTypeTransformation(EntityTypeTransformation superTransformation)
{
EntityTypeBuilder typeBuilder = subrepository.createBuilder("text-type");
TypeTransformationBuilder transformationBuilder =
transformationBuilderFactory.create(TextType.class, typeBuilder);
transformationBuilder.includeSuper(superTransformation);
transformationBuilder.buildTypeTransformation();
}
protected EntityTypeTransformation, ?> createTypeTransformation(EntityTypeTransformation basicTransformation)
{
EntityTypeBuilder typeBuilder = subrepository.createBuilder("primitive-type");
TypeTransformationBuilder transformationBuilder =
transformationBuilderFactory.create(Type.class, typeBuilder);
createTextTypeTransformation((EntityTypeTransformation) transformationBuilder.getReference());
createIntegerTypeTransformation((EntityTypeTransformation) transformationBuilder.getReference());
transformationBuilder.transform().from("code").to("id");
transformationBuilder.includeSuper(basicTransformation);
return transformationBuilder.buildTypeTransformation();
}
private Converter, String> getAttributeKeyConverter()
{
JavaConverter, String> javaConverter = new JavaConverter, String>()
{
@Override
public String convertAB(Attribute a, TransformationContext ctx)
{
return a.getCode();
}
@Override
public Attribute convertBA(String b, TransformationContext ctx)
{
return null;
}
};
return ConverterUtils.create(javaConverter);
}
private Converter