use of eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition in project hale by halestudio.
the class GroovyTransformationPage method addActions.
@Override
protected void addActions(ToolBar toolbar, CompilingSourceViewer<GroovyAST> viewer) {
super.addActions(toolbar, viewer);
PageHelp.createToolItem(toolbar, this);
TypeStructureTray.createToolItem(toolbar, this, SchemaSpaceID.SOURCE, new TypeProvider() {
@Override
public Collection<? extends TypeDefinition> getTypes() {
// create a dummy type with the variables as children
DefaultTypeDefinition dummy = new DefaultTypeDefinition(TypeStructureTray.VARIABLES_TYPE_NAME);
Cell cell = getWizard().getUnfinishedCell();
boolean useInstanceValues = CellUtil.getOptionalParameter(cell, GroovyTransformation.PARAM_INSTANCE_VARIABLES, Value.of(false)).as(Boolean.class);
for (EntityDefinition variable : getVariables()) {
if (variable.getDefinition() instanceof PropertyDefinition) {
PropertyDefinition prop = (PropertyDefinition) variable.getDefinition();
TypeDefinition propertyType;
if (useInstanceValues) {
// use instance type
propertyType = prop.getPropertyType();
} else {
// use dummy type with only the
// binding/HasValueFlag copied
DefaultTypeDefinition crippledType = new DefaultTypeDefinition(prop.getPropertyType().getName());
crippledType.setConstraint(prop.getPropertyType().getConstraint(Binding.class));
crippledType.setConstraint(prop.getPropertyType().getConstraint(HasValueFlag.class));
propertyType = crippledType;
}
DefaultPropertyDefinition dummyProp = new DefaultPropertyDefinition(new QName(getVariableName(variable)), dummy, propertyType);
// number of times
if (cell.getTransformationIdentifier().equals(GroovyGreedyTransformation.ID))
dummyProp.setConstraint(Cardinality.CC_ANY_NUMBER);
}
}
return Collections.singleton(dummy);
}
});
TypeStructureTray.createToolItem(toolbar, this, SchemaSpaceID.TARGET, new TypeProvider() {
@Override
public Collection<? extends TypeDefinition> getTypes() {
Property targetProperty = (Property) CellUtil.getFirstEntity(getWizard().getUnfinishedCell().getTarget());
if (targetProperty != null) {
return Collections.singleton(targetProperty.getDefinition().getDefinition().getPropertyType());
}
return Collections.emptyList();
}
});
PageFunctions.createToolItem(toolbar, this);
}
use of eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition in project hale by halestudio.
the class XPathPropertyDefinitionDialog method getInputDefinition.
private static TypeDefinition getInputDefinition(EntityDefinition entityDef) {
if (entityDef.getPropertyPath() == null || entityDef.getPropertyPath().isEmpty()) {
// types?
return entityDef.getType();
} else {
PropertyDefinition def = (PropertyDefinition) entityDef.getDefinition();
// create a dummy type for the input
TypeDefinition dummyType = new DefaultTypeDefinition(new QName("ValueFilterDummy"));
TypeDefinition emptyType = new DefaultTypeDefinition(new QName("EmptyDummy"));
// with .. as parent link
new DefaultPropertyDefinition(PARENT_NAME, dummyType, emptyType);
// and the value property added as itself
dummyType.addChild(def);
return dummyType;
}
}
use of eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition in project hale by halestudio.
the class FeatureChainingComplexTypeTest method testBackAndForth.
/**
* Tests converting a feature chaining configuration to DOM and back.
*/
@Test
public void testBackAndForth() {
FeatureChaining testConf = new FeatureChaining();
TypeDefinition fakeType = new DefaultTypeDefinition(new QName(AppSchemaIO.APP_SCHEMA_NAMESPACE, "FakeType"));
PropertyDefinition fakeProperty0 = new DefaultPropertyDefinition(new QName(AppSchemaIO.APP_SCHEMA_NAMESPACE, "fakeProperty0"), fakeType, new DefaultTypeDefinition(new QName("FakeNestedType0PropertyType")));
PropertyDefinition fakeProperty1 = new DefaultPropertyDefinition(new QName(AppSchemaIO.APP_SCHEMA_NAMESPACE, "FakeNestedType0"), fakeType, new DefaultTypeDefinition(new QName("FakeNestedType0Type")));
List<ChildContext> path0 = Arrays.asList(new ChildContext[] { new ChildContext(fakeProperty0), new ChildContext(fakeProperty1) });
ChainConfiguration chain0 = new ChainConfiguration();
chain0.setChainIndex(0);
chain0.setPrevChainIndex(-1);
chain0.setNestedTypeTarget(new PropertyEntityDefinition(fakeType, path0, SchemaSpaceID.TARGET, null));
PropertyDefinition fakeProperty2 = new DefaultPropertyDefinition(new QName(AppSchemaIO.APP_SCHEMA_NAMESPACE, "fakeProperty1"), fakeType, new DefaultTypeDefinition(new QName("FakeNestedType1PropertyType")));
PropertyDefinition fakeProperty3 = new DefaultPropertyDefinition(new QName(AppSchemaIO.APP_SCHEMA_NAMESPACE, "FakeNestedType1"), fakeType, new DefaultTypeDefinition(new QName("FakeNestedType1Type")));
List<ChildContext> path1 = Arrays.asList(new ChildContext[] { new ChildContext(fakeProperty0), new ChildContext(fakeProperty1), new ChildContext(fakeProperty2), new ChildContext(fakeProperty3) });
ChainConfiguration chain1 = new ChainConfiguration();
chain1.setChainIndex(1);
chain1.setPrevChainIndex(0);
chain1.setNestedTypeTarget(new PropertyEntityDefinition(fakeType, path1, SchemaSpaceID.TARGET, null));
chain1.setMappingName("fakeMapping");
testConf.putChain("test-join", 0, chain0);
testConf.putChain("test-join", 1, chain1);
// convert to DOM
Element fragment = HaleIO.getComplexElement(testConf);
// convert back
FeatureChaining converted = HaleIO.getComplexValue(fragment, FeatureChaining.class, null);
assertNotNull(converted);
assertFalse(converted.equals(testConf));
Map<String, JoinConfiguration> joins = converted.getJoins();
assertNotNull(joins);
assertEquals(1, joins.size());
JoinConfiguration join = joins.get("test-join");
assertNotNull(join);
assertEquals(2, join.getChains().size());
ChainConfiguration convChain0 = join.getChain(0);
assertNotNull(convChain0);
assertEquals(0, convChain0.getChainIndex());
assertEquals(-1, convChain0.getPrevChainIndex());
assertTrue(convChain0.getMappingName() == null);
PropertyType convPropertyType0 = convChain0.getJaxbNestedTypeTarget();
assertNotNull(convPropertyType0);
assertEquals("FakeType", convPropertyType0.getType().getName());
assertEquals(AppSchemaIO.APP_SCHEMA_NAMESPACE, convPropertyType0.getType().getNs());
assertEquals(2, convPropertyType0.getChild().size());
assertEquals("fakeProperty0", convPropertyType0.getChild().get(0).getName());
assertEquals(AppSchemaIO.APP_SCHEMA_NAMESPACE, convPropertyType0.getChild().get(0).getNs());
assertEquals("FakeNestedType0", convPropertyType0.getChild().get(1).getName());
assertEquals(AppSchemaIO.APP_SCHEMA_NAMESPACE, convPropertyType0.getChild().get(1).getNs());
ChainConfiguration convChain1 = join.getChain(1);
assertNotNull(convChain1);
assertEquals(1, convChain1.getChainIndex());
assertEquals(0, convChain1.getPrevChainIndex());
assertEquals("fakeMapping", convChain1.getMappingName());
PropertyType convPropertyType1 = convChain1.getJaxbNestedTypeTarget();
assertNotNull(convPropertyType1);
assertEquals("FakeType", convPropertyType1.getType().getName());
assertEquals(AppSchemaIO.APP_SCHEMA_NAMESPACE, convPropertyType1.getType().getNs());
assertEquals(4, convPropertyType1.getChild().size());
assertEquals("fakeProperty0", convPropertyType1.getChild().get(0).getName());
assertEquals(AppSchemaIO.APP_SCHEMA_NAMESPACE, convPropertyType1.getChild().get(0).getNs());
assertEquals("FakeNestedType0", convPropertyType1.getChild().get(1).getName());
assertEquals(AppSchemaIO.APP_SCHEMA_NAMESPACE, convPropertyType1.getChild().get(1).getNs());
assertEquals("fakeProperty1", convPropertyType1.getChild().get(2).getName());
assertEquals(AppSchemaIO.APP_SCHEMA_NAMESPACE, convPropertyType1.getChild().get(2).getNs());
assertEquals("FakeNestedType1", convPropertyType1.getChild().get(3).getName());
assertEquals(AppSchemaIO.APP_SCHEMA_NAMESPACE, convPropertyType1.getChild().get(3).getNs());
}
use of eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition in project hale by halestudio.
the class FilterTest method simpleFilterTestCQL.
@Test
public void simpleFilterTestCQL() throws CQLException {
DefaultTypeDefinition stringType = new DefaultTypeDefinition(new QName("StringType"));
stringType.setConstraint(Binding.get(String.class));
DefaultTypeDefinition personDef = new DefaultTypeDefinition(new QName("PersonType"));
personDef.addChild(new DefaultPropertyDefinition(new QName("Name"), personDef, stringType));
DefaultTypeDefinition autoDef = new DefaultTypeDefinition(new QName("AutoType"));
autoDef.addChild(new DefaultPropertyDefinition(new QName("Name"), autoDef, stringType));
autoDef.addChild(new DefaultPropertyDefinition(new QName("Besitzer"), autoDef, personDef));
MutableInstance auto = new DefaultInstance(autoDef, null);
auto.addProperty(new QName("Name"), "Mein Porsche");
MutableInstance ich = new DefaultInstance(personDef, null);
ich.addProperty(new QName("Name"), "Ich");
auto.addProperty(new QName("Besitzer"), ich);
Filter filter;
filter = new FilterGeoCqlImpl("Name = 'Mein Porsche'");
assertTrue(filter.match(auto));
Filter filter1 = new FilterGeoCqlImpl("Name like 'Porsche'");
assertFalse(filter1.match(auto));
Filter filter2 = new FilterGeoCqlImpl("Name like '%Porsche'");
assertTrue(filter2.match(auto));
}
use of eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition in project hale by halestudio.
the class JDBCSchemaReader method loadFromSource.
@Override
protected Schema loadFromSource(ProgressIndicator progress, IOReporter reporter) throws IOProviderConfigurationException, IOException {
DefaultSchema typeIndex = null;
progress.begin("Read database schema", ProgressIndicator.UNKNOWN);
Connection connection = null;
try {
// connect to the database
try {
connection = getConnection();
} catch (Exception e) {
reporter.error(new IOMessageImpl(e.getLocalizedMessage(), e));
reporter.setSuccess(false);
reporter.setSummary("Failed to connect to database.");
return null;
}
// connection has been created), report a warning message instead
try {
connection.setReadOnly(true);
} catch (SQLException e) {
// ignore
// reporter.warn(new IOMessageImpl(e.getLocalizedMessage(), e));
}
URI jdbcURI = getSource().getLocation();
final SchemaCrawlerOptions options = new SchemaCrawlerOptions();
SchemaInfoLevel level = new SchemaInfoLevel();
level.setTag("hale");
// these are enabled by default, we don't need them (yet)
level.setRetrieveSchemaCrawlerInfo(false);
level.setRetrieveJdbcDriverInfo(false);
level.setRetrieveDatabaseInfo(false);
// set what we need
level.setRetrieveTables(true);
level.setRetrieveColumnDataTypes(true);
level.setRetrieveUserDefinedColumnDataTypes(true);
// to get table columns
level.setRetrieveTableColumns(true);
// information, also
// includes primary key
// to get linking information
level.setRetrieveForeignKeys(true);
// level.setRetrieveIndices(true); // to get info about UNIQUE indices for validation
// XXX For some advanced info / DBMS specific info we'll need a
// properties file. See Config & InformationSchemaViews.
level.setTag("hale");
if (getParameter(SCHEMAS).as(String.class) != null) {
String schemas = getParameter(SCHEMAS).as(String.class).replace(',', '|');
options.setSchemaInclusionRule(new RegularExpressionInclusionRule(schemas));
}
if (SchemaSpaceID.SOURCE.equals(getSchemaSpace())) {
// show views and tables
final List<String> tableTypesWanted = Arrays.asList("TABLE", "VIEW", "MATERIALIZED VIEW");
// try to determine table types supported by the JDBC connection
final List<String> tableTypeSupported = new ArrayList<>();
try {
ResultSet rs = connection.getMetaData().getTableTypes();
while (rs.next()) {
String tableType = rs.getString(1);
tableTypeSupported.add(tableType);
}
} catch (Throwable t) {
// Ignore, try with wanted list
reporter.warn(new IOMessageImpl(MessageFormat.format("Could not determine supported table types for connection: {0}", t.getMessage()), t));
tableTypeSupported.addAll(tableTypesWanted);
}
options.setTableTypes(tableTypesWanted.stream().filter(tt -> tableTypeSupported.contains(tt)).collect(Collectors.toList()));
} else {
// only show tables
options.setTableTypes(Arrays.asList("TABLE"));
}
options.setSchemaInfoLevel(level);
// get advisor
// XXX should be created once, and used in other places if
// applicable
JDBCSchemaReaderAdvisor advisor = SchemaReaderAdvisorExtension.getInstance().getAdvisor(connection);
if (advisor != null) {
advisor.configureSchemaCrawler(options);
}
final Catalog database = SchemaCrawlerUtility.getCatalog(connection, options);
@SuppressWarnings("unused") String quotes = JDBCUtil.determineQuoteString(connection);
// FIXME not actually used here or in SQL schema reader
String overallNamespace = JDBCUtil.determineNamespace(jdbcURI, advisor);
// create the type index
typeIndex = new DefaultSchema(overallNamespace, jdbcURI);
for (final schemacrawler.schema.Schema schema : database.getSchemas()) {
// each schema represents a namespace
String namespace;
if (overallNamespace.isEmpty()) {
namespace = unquote(schema.getName());
} else {
namespace = overallNamespace;
if (schema.getName() != null) {
namespace += ":" + unquote(schema.getName());
}
}
for (final Table table : database.getTables(schema)) {
// each table is a type
// get the type definition
TypeDefinition type = getOrCreateTableType(schema, table, overallNamespace, namespace, typeIndex, connection, reporter, database);
// get ResultSetMetaData for extra info about columns (e. g.
// auto increment)
ResultsColumns additionalInfo = null;
Statement stmt = null;
try {
stmt = connection.createStatement();
// get if in table name, quotation required or not.
String fullTableName = getQuotedValue(table.getName());
if (schema.getName() != null) {
fullTableName = getQuotedValue(schema.getName()) + "." + fullTableName;
}
ResultSet rs = stmt.executeQuery("SELECT * FROM " + fullTableName + " WHERE 1 = 0");
additionalInfo = SchemaCrawlerUtility.getResultColumns(rs);
} catch (SQLException sqle) {
reporter.warn(new IOMessageImpl("Couldn't retrieve additional column meta data.", sqle));
} finally {
if (stmt != null)
try {
stmt.close();
} catch (SQLException e) {
// ignore
}
}
// create property definitions for each column
for (final Column column : table.getColumns()) {
DefaultPropertyDefinition property = getOrCreateProperty(schema, type, column, overallNamespace, namespace, typeIndex, connection, reporter, database);
// XXX does not work for example for PostgreSQL
if (additionalInfo != null) {
// ResultColumns does not quote the column namen in
// contrast to every other place
ResultsColumn rc = additionalInfo.getColumn(unquote(column.getName()));
if (rc != null && rc.isAutoIncrement())
property.setConstraint(AutoIncrementFlag.get(true));
}
}
}
}
reporter.setSuccess(true);
} catch (SchemaCrawlerException e) {
throw new IOProviderConfigurationException("Failed to read database schema", e);
} finally {
if (connection != null) {
try {
connection.close();
} catch (SQLException e) {
// ignore
}
}
progress.end();
}
return typeIndex;
}
Aggregations