Search in sources :

Example 1 with JavascriptFunctions

use of org.eclipse.vorto.service.mapping.internal.converter.JavascriptFunctions in project vorto by eclipse.

the class MappingSpecificationBuilder method build.

public IMappingSpecification build() {
    try {
        Infomodel infomodel = this.repositoryClient.getContent(ModelId.fromPrettyFormat(this.modelId), Infomodel.class, this.targetPlatformKey).get();
        DefaultMappingSpecification specification = new DefaultMappingSpecification();
        specification.setInfomodel(infomodel);
        for (ModelProperty fbProperty : infomodel.getFunctionblocks()) {
            ModelId fbModelId = (ModelId) fbProperty.getType();
            ModelId mappingId = fbProperty.getMappingReference();
            FunctionblockModel fbm;
            if (mappingId != null) {
                fbm = this.repositoryClient.getContent(fbModelId, FunctionblockModel.class, mappingId).get();
            } else {
                fbm = this.repositoryClient.getContent(fbModelId, FunctionblockModel.class, this.targetPlatformKey).get();
            }
            if (fbm.getStereotype(STEREOTYPE_FUNCTIONS).isPresent()) {
                Stereotype functionsStereotype = fbm.getStereotype(STEREOTYPE_FUNCTIONS).get();
                JavascriptFunctions functions = new JavascriptFunctions(fbProperty.getName().toLowerCase());
                for (String functionName : functionsStereotype.getAttributes().keySet()) {
                    if (!"_namespace".equalsIgnoreCase(functionName)) {
                        functions.addFunction(functionName, functionsStereotype.getAttributes().get(functionName));
                    }
                }
                this.library.addFunctions(functions);
            }
            specification.getFbs().put(fbProperty.getName(), fbm);
        }
        specification.setLibrary(this.library);
        return specification;
    } catch (Exception e) {
        throw new MappingSpecificationProblem("Problem reading mapping specification", e);
    }
}
Also used : FunctionblockModel(org.eclipse.vorto.repository.api.content.FunctionblockModel) DefaultMappingSpecification(org.eclipse.vorto.service.mapping.internal.spec.DefaultMappingSpecification) JavascriptFunctions(org.eclipse.vorto.service.mapping.internal.converter.JavascriptFunctions) Infomodel(org.eclipse.vorto.repository.api.content.Infomodel) ModelProperty(org.eclipse.vorto.repository.api.content.ModelProperty) Stereotype(org.eclipse.vorto.repository.api.content.Stereotype) ModelId(org.eclipse.vorto.repository.api.ModelId)

Example 2 with JavascriptFunctions

use of org.eclipse.vorto.service.mapping.internal.converter.JavascriptFunctions in project vorto by eclipse.

the class SpecGattConverter method getCustomFunctions.

@Override
public Optional<Functions> getCustomFunctions() {
    JavascriptFunctions functions = new JavascriptFunctions("button");
    functions.addFunction("convertSensorValue", "function convertSensorValue(value) { return value*0.01; }");
    return Optional.of(functions);
}
Also used : JavascriptFunctions(org.eclipse.vorto.service.mapping.internal.converter.JavascriptFunctions)

Example 3 with JavascriptFunctions

use of org.eclipse.vorto.service.mapping.internal.converter.JavascriptFunctions in project vorto by eclipse.

the class SpecWithByteArrayConverter method getCustomFunctions.

@Override
public Optional<Functions> getCustomFunctions() {
    JavascriptFunctions functions = new JavascriptFunctions("button");
    functions.addFunction("convertSensorValue", "function convertSensorValue(value) { return value*0.01; }");
    return Optional.of(functions);
}
Also used : JavascriptFunctions(org.eclipse.vorto.service.mapping.internal.converter.JavascriptFunctions)

Example 4 with JavascriptFunctions

use of org.eclipse.vorto.service.mapping.internal.converter.JavascriptFunctions in project vorto by eclipse.

the class SpecWithCustomFunction method getCustomFunctions.

@Override
public Optional<Functions> getCustomFunctions() {
    JavascriptFunctions functions = new JavascriptFunctions("button");
    functions.addFunction("convertClickType", "function convertClickType(clickType) {if (clickType === 'SINGLE') return 1; else if (clickType === 'DOUBLE') return 2; else return 99;}");
    return Optional.of(functions);
}
Also used : JavascriptFunctions(org.eclipse.vorto.service.mapping.internal.converter.JavascriptFunctions)

Aggregations

JavascriptFunctions (org.eclipse.vorto.service.mapping.internal.converter.JavascriptFunctions)4 ModelId (org.eclipse.vorto.repository.api.ModelId)1 FunctionblockModel (org.eclipse.vorto.repository.api.content.FunctionblockModel)1 Infomodel (org.eclipse.vorto.repository.api.content.Infomodel)1 ModelProperty (org.eclipse.vorto.repository.api.content.ModelProperty)1 Stereotype (org.eclipse.vorto.repository.api.content.Stereotype)1 DefaultMappingSpecification (org.eclipse.vorto.service.mapping.internal.spec.DefaultMappingSpecification)1