Search in sources :

Example 1 with PrefixedNamespace

use of org.odata4j.core.PrefixedNamespace in project teiid by teiid.

the class SAPMetadataProcessor method buildColumn.

@Override
protected Column buildColumn(MetadataFactory mf, Table table, EdmProperty ep, EdmEntitySet entitySet, String prefix) {
    boolean creatable = true;
    boolean updatable = true;
    boolean filterable = true;
    boolean required_in_filter = false;
    String columnName = ep.getName();
    if (prefix != null) {
        // $NON-NLS-1$
        columnName = prefix + "_" + columnName;
    }
    Column c = mf.addColumn(columnName, ODataTypeManager.teiidType(ep.getType().getFullyQualifiedTypeName()), table);
    c.setNameInSource(ep.getName());
    Iterable<? extends NamespacedAnnotation> annotations = ep.getAnnotations();
    for (NamespacedAnnotation annotation : annotations) {
        PrefixedNamespace namespace = annotation.getNamespace();
        if (namespace.getUri().equals(SAPURI)) {
            String name = annotation.getName();
            if (name.equalsIgnoreCase("label")) {
                // $NON-NLS-1$
                c.setAnnotation((String) annotation.getValue());
            } else if (name.equalsIgnoreCase("creatable")) {
                // $NON-NLS-1$
                creatable = Boolean.parseBoolean((String) annotation.getValue());
            }
            if (name.equalsIgnoreCase("visible")) {
                // $NON-NLS-1$
                c.setSelectable(Boolean.parseBoolean((String) annotation.getValue()));
            }
            if (name.equalsIgnoreCase("updatable")) {
                // $NON-NLS-1$
                updatable = Boolean.parseBoolean((String) annotation.getValue());
            }
            if (name.equalsIgnoreCase("sortable")) {
                // $NON-NLS-1$
                if (!Boolean.parseBoolean((String) annotation.getValue())) {
                    c.setSearchType(SearchType.Unsearchable);
                }
            }
            if (name.equalsIgnoreCase("filterable")) {
                // $NON-NLS-1$
                filterable = Boolean.parseBoolean((String) annotation.getValue());
            }
            if (name.equalsIgnoreCase("required-in-filter")) {
                // $NON-NLS-1$
                required_in_filter = Boolean.parseBoolean((String) annotation.getValue());
            }
            if (name.equalsIgnoreCase("filter-restriction")) {
            // $NON-NLS-1$
            // TODO:
            }
        }
    }
    c.setUpdatable(creatable && updatable);
    if (!filterable) {
        c.setSearchType(SearchType.Unsearchable);
    }
    if (required_in_filter) {
        if (this.accessPatterns.get(table) == null) {
            KeyRecord record = new KeyRecord(Type.AccessPattern);
            record.addColumn(c);
            this.accessPatterns.put(table, record);
        } else {
            this.accessPatterns.get(table).addColumn(c);
        }
    }
    // entity set defined to as must have filter
    // $NON-NLS-1$
    boolean requiresFilter = Boolean.parseBoolean(getProperty(entitySet, "requires-filter"));
    if (requiresFilter && filterable && !required_in_filter) {
        KeyRecord record = new KeyRecord(Type.AccessPattern);
        record.addColumn(c);
        table.getAccessPatterns().add(record);
    }
    return c;
}
Also used : NamespacedAnnotation(org.odata4j.core.NamespacedAnnotation) KeyRecord(org.teiid.metadata.KeyRecord) Column(org.teiid.metadata.Column) PrefixedNamespace(org.odata4j.core.PrefixedNamespace)

Example 2 with PrefixedNamespace

use of org.odata4j.core.PrefixedNamespace in project teiid by teiid.

the class SAPMetadataProcessor method buildTable.

@Override
protected Table buildTable(MetadataFactory mf, EdmEntitySet entitySet) {
    boolean creatable = true;
    boolean updatable = true;
    boolean deletable = true;
    boolean pageable = true;
    boolean topable = true;
    Table t = mf.addTable(entitySet.getName());
    Iterable<? extends NamespacedAnnotation> annotations = entitySet.getAnnotations();
    for (NamespacedAnnotation annotation : annotations) {
        PrefixedNamespace namespace = annotation.getNamespace();
        if (namespace.getUri().equals(SAPURI)) {
            String name = annotation.getName();
            if (name.equalsIgnoreCase("label")) {
                // $NON-NLS-1$
                t.setAnnotation((String) annotation.getValue());
            } else if (name.equalsIgnoreCase("creatable")) {
                // $NON-NLS-1$
                creatable = Boolean.parseBoolean((String) annotation.getValue());
            } else if (name.equalsIgnoreCase("updatable")) {
                // $NON-NLS-1$
                updatable = Boolean.parseBoolean((String) annotation.getValue());
            } else if (name.equalsIgnoreCase("pageable")) {
                // $NON-NLS-1$
                pageable = Boolean.parseBoolean((String) annotation.getValue());
            } else if (name.equalsIgnoreCase("topable")) {
                // $NON-NLS-1$
                topable = Boolean.parseBoolean((String) annotation.getValue());
            } else if (name.equalsIgnoreCase("deletable")) {
                // $NON-NLS-1$
                deletable = Boolean.parseBoolean((String) annotation.getValue());
            }
        }
    }
    t.setSupportsUpdate(creatable && updatable && deletable);
    if (!topable || !pageable) {
    // TODO: currently Teiid can not do this in fine grained manner;
    // will be turned on by default; but user needs to turn off using the
    // capabilities if any table does not support this feature
    }
    return t;
}
Also used : NamespacedAnnotation(org.odata4j.core.NamespacedAnnotation) Table(org.teiid.metadata.Table) PrefixedNamespace(org.odata4j.core.PrefixedNamespace)

Aggregations

NamespacedAnnotation (org.odata4j.core.NamespacedAnnotation)2 PrefixedNamespace (org.odata4j.core.PrefixedNamespace)2 Column (org.teiid.metadata.Column)1 KeyRecord (org.teiid.metadata.KeyRecord)1 Table (org.teiid.metadata.Table)1