Search in sources :

Example 6 with FunctionParameterDefinition

use of eu.esdihumboldt.hale.common.align.extension.function.FunctionParameterDefinition in project hale by halestudio.

the class GeographicalNameExplanation method addOptionalParameter.

private void addOptionalParameter(StringBuilder sb, Cell cell, String paramName, PropertyFunctionDefinition function, boolean html) {
    String value = CellUtil.getFirstParameter(cell, paramName).as(String.class);
    if (value != null && !value.isEmpty()) {
        FunctionParameterDefinition param = function.getParameter(paramName);
        if (html) {
            sb.append("<li><i>");
        } else {
            sb.append("- ");
        }
        sb.append(param.getDisplayName());
        if (html) {
            sb.append("</i>");
        }
        sb.append(": ");
        sb.append(value);
        if (html) {
            sb.append("</li>");
        } else {
            sb.append('\n');
        }
    }
}
Also used : FunctionParameterDefinition(eu.esdihumboldt.hale.common.align.extension.function.FunctionParameterDefinition)

Example 7 with FunctionParameterDefinition

use of eu.esdihumboldt.hale.common.align.extension.function.FunctionParameterDefinition in project hale by halestudio.

the class FunctionReferenceContent method getFunctionContent.

private InputStream getFunctionContent(String func_id) throws Exception {
    // maps "function" to the real function ID (used by the template)
    final FunctionDefinition<?> function = FunctionUtil.getFunction(func_id, null);
    if (function == null) {
        log.warn("Unknown function " + func_id);
        return null;
    }
    Callable<VelocityContext> contextFactory = new Callable<VelocityContext>() {

        @Override
        public VelocityContext call() throws Exception {
            VelocityContext context = new VelocityContext();
            context.put("showImage", imageContentMethod != null);
            context.put("function", function);
            // Map<paramDisplayName, sampleDataStringRepresentation>
            Map<String, String> parameterDocu = new HashMap<String, String>();
            for (FunctionParameterDefinition param : function.getDefinedParameters()) {
                if (param.getValueDescriptor() != null && param.getValueDescriptor().getSampleData() != null) {
                    Value sample = param.getValueDescriptor().getSampleData();
                    if (sample.isRepresentedAsDOM()) {
                        // get DOM Element as String
                        Element ele = sample.getDOMRepresentation();
                        StringWriter writer = new StringWriter();
                        StreamResult formattedXmlString = new StreamResult(writer);
                        XmlUtil.prettyPrint(new DOMSource(ele), formattedXmlString);
                        // escape special chars to display xml code on html
                        String xmlString = formattedXmlString.getWriter().toString();
                        xmlString = StringEscapeUtils.escapeXml(xmlString);
                        parameterDocu.put(param.getDisplayName(), xmlString);
                    } else {
                        parameterDocu.put(param.getDisplayName(), sample.getStringRepresentation());
                    }
                }
            }
            context.put("parameterDocu", parameterDocu);
            if (function.getCategoryId() != null) {
                String categoryId = function.getCategoryId();
                Category category = (CategoryExtension.getInstance().get(categoryId));
                // String category = categoryId.substring(categoryId
                // .lastIndexOf(".") + 1);
                // 
                // category = capitalize(category);
                context.put("category", category);
            }
            // creating path for the file to be included
            URL help_url = function.getHelpURL();
            if (help_url != null) {
                String help_path = help_url.getPath();
                String bundle = function.getDefiningBundle();
                StringBuffer sb_include = new StringBuffer();
                sb_include.append(bundle);
                sb_include.append(help_path);
                sb_include.append("/help");
                String final_help_url = sb_include.toString();
                context.put("include", final_help_url);
            }
            return context;
        }
    };
    return getContentFromTemplate(func_id, "function", contextFactory);
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) Category(eu.esdihumboldt.hale.common.align.extension.category.Category) StreamResult(javax.xml.transform.stream.StreamResult) HashMap(java.util.HashMap) VelocityContext(org.apache.velocity.VelocityContext) Element(org.w3c.dom.Element) FunctionParameterDefinition(eu.esdihumboldt.hale.common.align.extension.function.FunctionParameterDefinition) Callable(java.util.concurrent.Callable) URL(java.net.URL) StringWriter(java.io.StringWriter) Value(eu.esdihumboldt.hale.common.core.io.Value)

Example 8 with FunctionParameterDefinition

use of eu.esdihumboldt.hale.common.align.extension.function.FunctionParameterDefinition in project hale by halestudio.

the class ParameterBinding method getProperty.

@Override
public Object getProperty(String property) {
    boolean getAsList = true;
    final Optional<FunctionParameterDefinition> paramDef;
    if (function != null) {
        paramDef = function.getDefinedParameters().stream().filter(param -> Objects.equals(property, param.getName())).findFirst();
    } else {
        paramDef = Optional.empty();
    }
    if (paramDef.isPresent()) {
        if (paramDef.get().getMaxOccurrence() == 1) {
            getAsList = false;
        }
    }
    List<ParameterValue> values;
    if (cell != null && cell.getTransformationParameters() != null) {
        values = cell.getTransformationParameters().get(property);
    } else {
        values = Collections.emptyList();
    }
    if (getAsList) {
        // yield parameters as list
        return values.stream().map(value -> extractParameterValue(value, paramDef)).collect(Collectors.toList());
    } else {
        // yield parameter value or null if there is none
        if (values.isEmpty()) {
            if (paramDef.isPresent()) {
                ParameterValueDescriptor descriptor = paramDef.get().getValueDescriptor();
                if (descriptor != null && descriptor.getDefaultValue() != null) {
                    // use default value as parameter value
                    return extractParameterValue(new ParameterValue(descriptor.getDefaultValue()), paramDef);
                }
            }
            return null;
        } else {
            return extractParameterValue(values.get(0), paramDef);
        }
    }
}
Also used : Objects(java.util.Objects) List(java.util.List) FunctionDefinition(eu.esdihumboldt.hale.common.align.extension.function.FunctionDefinition) Cell(eu.esdihumboldt.hale.common.align.model.Cell) ParameterValueDescriptor(eu.esdihumboldt.hale.common.core.parameter.ParameterValueDescriptor) Optional(java.util.Optional) GroovyObjectSupport(groovy.lang.GroovyObjectSupport) ParameterValue(eu.esdihumboldt.hale.common.align.model.ParameterValue) Collections(java.util.Collections) Collectors(java.util.stream.Collectors) FunctionParameterDefinition(eu.esdihumboldt.hale.common.align.extension.function.FunctionParameterDefinition) ParameterValueDescriptor(eu.esdihumboldt.hale.common.core.parameter.ParameterValueDescriptor) ParameterValue(eu.esdihumboldt.hale.common.align.model.ParameterValue) FunctionParameterDefinition(eu.esdihumboldt.hale.common.align.extension.function.FunctionParameterDefinition)

Example 9 with FunctionParameterDefinition

use of eu.esdihumboldt.hale.common.align.extension.function.FunctionParameterDefinition in project hale by halestudio.

the class IdentifierParameterPage method createContent.

@Override
protected void createContent(Composite parent) {
    boolean relayout = this.parent != null;
    this.parent = parent;
    lastEntity = determineTargetEntity();
    if (lastEntity == null) {
        setPageComplete(false);
        // can't create controls
        return;
    }
    if (page != null) {
        // page was created before
        initialCountry = countryCode.getText();
        initialProvider = providerName.getText();
        initialProduct = productName.getText();
        initialVersion = version.getText();
        initialVersionNil = nilEditor.getAsText();
        page.dispose();
    }
    PropertyFunctionDefinition function = FunctionUtil.getPropertyFunction(ID, HaleUI.getServiceProvider());
    // create a composite to hold the widgets
    page = new Composite(parent, SWT.NULL);
    setControl(page);
    // create layout for this wizard page
    GridLayout gl = GridLayoutFactory.fillDefaults().create();
    page.setLayout(gl);
    AttributeEditorFactory aef = PlatformUI.getWorkbench().getService(AttributeEditorFactory.class);
    DefinitionLabelFactory dlf = PlatformUI.getWorkbench().getService(DefinitionLabelFactory.class);
    // identifier type
    TypeDefinition identifierType = null;
    Definition<?> def = lastEntity.getDefinition();
    if (def instanceof PropertyDefinition) {
        TypeDefinition typeDef = ((PropertyDefinition) def).getPropertyType();
        for (ChildDefinition<?> child : typeDef.getChildren()) {
            if (child.asProperty() != null && child.asProperty().getPropertyType().getName().getLocalPart().equals("IdentifierType")) {
                identifierType = child.asProperty().getPropertyType();
            }
        }
    }
    // Namespace group
    Group nsGroup = new Group(page, SWT.NONE);
    nsGroup.setText(Messages.IdentifierFunctionWizardPage_2);
    nsGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    nsGroup.setLayout(// 
    GridLayoutFactory.swtDefaults().numColumns(// 
    2).spacing(8, // 
    4).create());
    // localId
    if (identifierType != null) {
        // $NON-NLS-1$
        PropertyDefinition propDef = null;
        for (ChildDefinition<?> child : identifierType.getChildren()) {
            String localName = child.getName().getLocalPart();
            if (localName.equals("namespace")) {
                if (child.asProperty() != null) {
                    propDef = child.asProperty();
                }
            }
        }
        if (propDef != null) {
            Control nsLabel = dlf.createLabel(nsGroup, propDef, false);
            nsLabel.setLayoutData(new GridData(SWT.END, SWT.CENTER, false, false));
            Label nsDesc = new Label(nsGroup, SWT.NONE);
            nsDesc.setText(Messages.IdentifierFunctionWizardPage_4);
        }
    }
    // Country code
    Label ccLabel = new Label(nsGroup, SWT.NONE);
    ccLabel.setLayoutData(new GridData(SWT.END, SWT.CENTER, false, false));
    ccLabel.setText(Messages.IdentifierFunctionWizardPage_5);
    FunctionParameterDefinition param = function.getParameter(COUNTRY_PARAMETER_NAME);
    configureParameterLabel(ccLabel, param);
    this.countryCode = new Text(nsGroup, SWT.BORDER | SWT.SINGLE);
    // $NON-NLS-1$
    this.countryCode.setText(initialCountry);
    this.countryCode.setEnabled(true);
    this.countryCode.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    // Provider name
    Label providerLabel = new Label(nsGroup, SWT.NONE);
    providerLabel.setLayoutData(new GridData(SWT.END, SWT.CENTER, false, false));
    providerLabel.setText(Messages.IdentifierFunctionWizardPage_7);
    param = function.getParameter(DATA_PROVIDER_PARAMETER_NAME);
    configureParameterLabel(providerLabel, param);
    this.providerName = new Text(nsGroup, SWT.BORDER | SWT.SINGLE);
    // $NON-NLS-1$
    this.providerName.setText(initialProvider);
    this.providerName.setEnabled(true);
    this.providerName.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    // Product name
    Label productLabel = new Label(nsGroup, SWT.NONE);
    productLabel.setLayoutData(new GridData(SWT.END, SWT.CENTER, false, false));
    productLabel.setText(Messages.IdentifierFunctionWizardPage_9);
    param = function.getParameter(PRODUCT_PARAMETER_NAME);
    configureParameterLabel(productLabel, param);
    this.productName = new Text(nsGroup, SWT.BORDER | SWT.SINGLE);
    // $NON-NLS-1$
    this.productName.setText(initialProduct);
    this.productName.setEnabled(true);
    this.productName.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    // Local ID group
    Group idGroup = new Group(page, SWT.NONE);
    idGroup.setText(Messages.IdentifierFunctionWizardPage_11);
    idGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    idGroup.setLayout(new GridLayout(2, false));
    // localId
    Control idLabel = null;
    if (identifierType != null) {
        // $NON-NLS-1$
        PropertyDefinition propDef = null;
        for (ChildDefinition<?> child : identifierType.getChildren()) {
            String LocalName = child.getName().getLocalPart();
            if (LocalName.equals("localId")) {
                if (child.asProperty() != null) {
                    propDef = child.asProperty();
                }
            }
        }
        if (propDef != null) {
            idLabel = dlf.createLabel(idGroup, propDef, false);
        }
    }
    if (idLabel == null) {
        idLabel = new Label(idGroup, SWT.NONE);
        // $NON-NLS-1$
        ((Label) idLabel).setText("localId");
    }
    idLabel.setLayoutData(new GridData(SWT.END, SWT.CENTER, false, false));
    Control localId = dlf.createLabel(idGroup, getWizard().getUnfinishedCell().getSource().get(null).get(0).getDefinition().getDefinition(), true);
    localId.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    // Version group
    Group versGroup = new Group(page, SWT.NONE);
    versGroup.setText(Messages.IdentifierFunctionWizardPage_14);
    versGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    versGroup.setLayout(new GridLayout(2, false));
    // Version
    Control versionLabel = null;
    if (identifierType != null) {
        // $NON-NLS-1$
        PropertyDefinition propDef = null;
        for (ChildDefinition<?> child : identifierType.getChildren()) {
            String localName = child.getName().getLocalPart();
            if (localName.equals("versionId")) {
                if (child.asProperty() != null) {
                    propDef = child.asProperty();
                }
            }
        }
        if (propDef != null) {
            versionLabel = dlf.createLabel(versGroup, propDef, false);
        }
    }
    if (versionLabel == null) {
        versionLabel = new Label(versGroup, SWT.NONE);
        ((Label) versionLabel).setText(Messages.IdentifierFunctionWizardPage_16);
    }
    versionLabel.setLayoutData(new GridData(SWT.END, SWT.CENTER, false, false));
    this.version = new Text(versGroup, SWT.BORDER | SWT.SINGLE);
    // $NON-NLS-1$
    this.version.setText(initialVersion);
    this.version.setEnabled(true);
    this.version.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    // version nil reason
    if (identifierType != null) {
        // $NON-NLS-1$
        PropertyDefinition propDef = null;
        for (ChildDefinition<?> child : identifierType.getChildren()) {
            String localName = child.getName().getLocalPart();
            if (localName.equals("versionId")) {
                if (child.asProperty() != null) {
                    propDef = child.asProperty();
                }
            }
        }
        if (propDef != null) {
            for (ChildDefinition<?> child : propDef.getPropertyType().getChildren()) {
                String localName = child.getName().getLocalPart();
                if (localName.equals("nilReason")) {
                    if (child.asProperty() != null) {
                        propDef = child.asProperty();
                    }
                }
            }
        }
        if (propDef != null) {
            // label
            Control nilLabel = dlf.createLabel(versGroup, propDef, false);
            nilLabel.setLayoutData(new GridData(SWT.END, SWT.CENTER, false, false));
            // editor
            nilEditor = aef.createEditor(versGroup, propDef, null, false);
            nilEditor.getControl().setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
            // default to unknown
            nilEditor.setAsText(initialVersionNil);
        // //$NON-NLS-1$
        }
    }
    if (relayout) {
        parent.layout();
        getContainer().getShell().pack();
    }
    setPageComplete(true);
}
Also used : Group(org.eclipse.swt.widgets.Group) DefinitionLabelFactory(eu.esdihumboldt.hale.ui.common.definition.DefinitionLabelFactory) Composite(org.eclipse.swt.widgets.Composite) Label(org.eclipse.swt.widgets.Label) FunctionParameterDefinition(eu.esdihumboldt.hale.common.align.extension.function.FunctionParameterDefinition) AttributeEditorFactory(eu.esdihumboldt.hale.ui.common.definition.AttributeEditorFactory) Text(org.eclipse.swt.widgets.Text) PropertyDefinition(eu.esdihumboldt.hale.common.schema.model.PropertyDefinition) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) GridLayout(org.eclipse.swt.layout.GridLayout) Control(org.eclipse.swt.widgets.Control) GridData(org.eclipse.swt.layout.GridData) PropertyFunctionDefinition(eu.esdihumboldt.hale.common.align.extension.function.PropertyFunctionDefinition)

Example 10 with FunctionParameterDefinition

use of eu.esdihumboldt.hale.common.align.extension.function.FunctionParameterDefinition in project hale by halestudio.

the class SourceListParameterPage method setParameter.

/**
 * @see ParameterPage#setParameter(Set, ListMultimap)
 */
@Override
public void setParameter(Set<FunctionParameterDefinition> params, ListMultimap<String, ParameterValue> initialValues) {
    for (FunctionParameterDefinition param : params) {
        if (param.getName().equals(getParameterName())) {
            String description = param.getDescription();
            if (description != null) {
                setMessage(description);
            }
            String displayName = param.getDisplayName();
            if (displayName != null) {
                setTitle(displayName);
            }
            break;
        }
    }
    if (initialValues != null) {
        List<ParameterValue> initialData = initialValues.get(getParameterName());
        if (initialData.size() > 0)
            initialValue = initialData.get(0).as(String.class);
    }
}
Also used : ParameterValue(eu.esdihumboldt.hale.common.align.model.ParameterValue) FunctionParameterDefinition(eu.esdihumboldt.hale.common.align.extension.function.FunctionParameterDefinition)

Aggregations

FunctionParameterDefinition (eu.esdihumboldt.hale.common.align.extension.function.FunctionParameterDefinition)12 ParameterValue (eu.esdihumboldt.hale.common.align.model.ParameterValue)3 HashSet (java.util.HashSet)2 GridData (org.eclipse.swt.layout.GridData)2 Group (org.eclipse.swt.widgets.Group)2 Label (org.eclipse.swt.widgets.Label)2 Category (eu.esdihumboldt.hale.common.align.extension.category.Category)1 FunctionDefinition (eu.esdihumboldt.hale.common.align.extension.function.FunctionDefinition)1 PropertyFunctionDefinition (eu.esdihumboldt.hale.common.align.extension.function.PropertyFunctionDefinition)1 Cell (eu.esdihumboldt.hale.common.align.model.Cell)1 Value (eu.esdihumboldt.hale.common.core.io.Value)1 ParameterValueDescriptor (eu.esdihumboldt.hale.common.core.parameter.ParameterValueDescriptor)1 PropertyDefinition (eu.esdihumboldt.hale.common.schema.model.PropertyDefinition)1 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)1 AttributeEditorFactory (eu.esdihumboldt.hale.ui.common.definition.AttributeEditorFactory)1 DefinitionLabelFactory (eu.esdihumboldt.hale.ui.common.definition.DefinitionLabelFactory)1 ParameterPageFactory (eu.esdihumboldt.hale.ui.function.extension.ParameterPageFactory)1 GenericParameterPage (eu.esdihumboldt.hale.ui.function.generic.pages.GenericParameterPage)1 ParameterPage (eu.esdihumboldt.hale.ui.function.generic.pages.ParameterPage)1 Pair (eu.esdihumboldt.util.Pair)1