Search in sources :

Example 1 with JXPathNotFoundException

use of org.apache.commons.jxpath.JXPathNotFoundException in project vorto by eclipse.

the class AbstractDataMapper method mapFunctionBlock.

private FunctionblockData mapFunctionBlock(ModelProperty fbProperty, JXPathContext context) {
    FunctionblockData fbData = new FunctionblockData(fbProperty.getName());
    FunctionblockModel fbModel = specification.getFunctionBlock(fbProperty.getName());
    for (ModelProperty statusProperty : fbModel.getStatusProperties()) {
        try {
            Object mapped = this.mapProperty(statusProperty, context);
            if (mapped != null) {
                fbData.withStatusProperty(statusProperty.getName(), mapped);
            }
        } catch (JXPathNotFoundException | JXPathInvalidAccessException ex) {
            if (statusProperty.isMandatory()) {
                return null;
            }
        }
    }
    for (ModelProperty configProperty : fbModel.getConfigurationProperties()) {
        try {
            Object mapped = this.mapProperty(configProperty, context);
            if (mapped != null) {
                fbData.withConfigurationProperty(configProperty.getName(), mapped);
            }
        } catch (JXPathNotFoundException | JXPathInvalidAccessException ex) {
            if (configProperty.isMandatory()) {
                return null;
            }
        }
    }
    return onlyReturnIfPopulated(fbData);
}
Also used : FunctionblockModel(org.eclipse.vorto.repository.api.content.FunctionblockModel) JXPathNotFoundException(org.apache.commons.jxpath.JXPathNotFoundException) ModelProperty(org.eclipse.vorto.repository.api.content.ModelProperty) FunctionblockData(org.eclipse.vorto.service.mapping.normalized.FunctionblockData) JXPathInvalidAccessException(org.apache.commons.jxpath.JXPathInvalidAccessException)

Example 2 with JXPathNotFoundException

use of org.apache.commons.jxpath.JXPathNotFoundException in project vorto by eclipse.

the class DataMapperJxpath method mapProperty.

private Object mapProperty(IModel parent, ModelProperty property, JXPathContext input) {
    Optional<Stereotype> sourceStereotype = property.getStereotype(STEREOTYPE_SOURCE);
    if (sourceStereotype.isPresent() && hasXpath(sourceStereotype.get().getAttributes())) {
        String expression = replacePlaceHolders(sourceStereotype.get().getAttributes().get(ATTRIBUTE_XPATH), sourceStereotype.get().getAttributes());
        if (matchesPropertyCondition(sourceStereotype.get(), input)) {
            return input.getValue(expression);
        }
    } else if (property.getType() instanceof IModel) {
        IModel referencedModel = (IModel) property.getType();
        if (referencedModel instanceof EntityModel) {
            EntityModel entityModel = (EntityModel) referencedModel;
            EntityValue value = new EntityValue(entityModel);
            for (ModelProperty entityProperty : entityModel.getProperties()) {
                try {
                    Object mapped = this.mapProperty(entityModel, entityProperty, input);
                    if (mapped != null) {
                        value.withProperty(entityProperty.getName(), mapped);
                    }
                } catch (JXPathNotFoundException ex) {
                    if (entityProperty.isMandatory()) {
                        return null;
                    }
                } catch (JXPathInvalidAccessException ex) {
                    if (ex.getCause() instanceof JXPathNotFoundException) {
                        if (entityProperty.isMandatory()) {
                            return null;
                        }
                    }
                    throw new MappingException("A problem occured during mapping", ex);
                }
            }
            return onlyReturnIfPopulated(value);
        } else if (referencedModel instanceof EnumModel) {
            EnumModel enumModel = (EnumModel) referencedModel;
            EnumValue value = new EnumValue(enumModel);
            if (sourceStereotype.isPresent() && hasXpath(sourceStereotype.get().getAttributes())) {
                String expression = replacePlaceHolders(sourceStereotype.get().getAttributes().get(ATTRIBUTE_XPATH), sourceStereotype.get().getAttributes());
                if (matchesPropertyCondition(sourceStereotype.get(), input)) {
                    Object mappedEnumValue = input.getValue(expression);
                    if (mappedEnumValue instanceof String) {
                        value.setValue((String) mappedEnumValue);
                    }
                    return value;
                }
            }
        }
    }
    return null;
}
Also used : IModel(org.eclipse.vorto.model.IModel) JXPathNotFoundException(org.apache.commons.jxpath.JXPathNotFoundException) EnumValue(org.eclipse.vorto.model.runtime.EnumValue) EntityModel(org.eclipse.vorto.model.EntityModel) Stereotype(org.eclipse.vorto.model.Stereotype) EntityValue(org.eclipse.vorto.model.runtime.EntityValue) JXPathInvalidAccessException(org.apache.commons.jxpath.JXPathInvalidAccessException) MappingException(org.eclipse.vorto.mapping.engine.MappingException) EnumModel(org.eclipse.vorto.model.EnumModel) ModelProperty(org.eclipse.vorto.model.ModelProperty)

Example 3 with JXPathNotFoundException

use of org.apache.commons.jxpath.JXPathNotFoundException in project vorto by eclipse.

the class DataMapperJxpath method mapFunctionBlock.

private FunctionblockValue mapFunctionBlock(ModelProperty fbProperty, JXPathContext context) {
    FunctionblockModel fbModel = specification.getFunctionBlock(fbProperty.getName());
    if (!matchesCondition(fbModel, context)) {
        return null;
    }
    FunctionblockValue fbData = new FunctionblockValue(fbModel);
    for (ModelProperty statusProperty : fbModel.getStatusProperties()) {
        try {
            Object mapped = this.mapProperty(fbModel, statusProperty, context);
            if (mapped != null) {
                fbData.withStatusProperty(statusProperty.getName(), mapped);
            }
        } catch (JXPathNotFoundException ex) {
            if (statusProperty.isMandatory()) {
                return null;
            }
        } catch (JXPathInvalidAccessException ex) {
            if (ex.getCause() instanceof JXPathNotFoundException) {
                if (statusProperty.isMandatory()) {
                    return null;
                }
            }
            throw new MappingException("A problem occured during mapping", ex);
        }
    }
    for (ModelProperty configProperty : fbModel.getConfigurationProperties()) {
        try {
            Object mapped = this.mapProperty(fbModel, configProperty, context);
            if (mapped != null) {
                fbData.withConfigurationProperty(configProperty.getName(), mapped);
            }
        } catch (JXPathNotFoundException ex) {
            if (configProperty.isMandatory()) {
                return null;
            }
        } catch (JXPathInvalidAccessException ex) {
            if (ex.getCause() instanceof JXPathNotFoundException) {
                if (configProperty.isMandatory()) {
                    return null;
                }
            }
            throw new MappingException("A problem occured during mapping", ex);
        }
    }
    return onlyReturnIfPopulated(fbData);
}
Also used : FunctionblockModel(org.eclipse.vorto.model.FunctionblockModel) FunctionblockValue(org.eclipse.vorto.model.runtime.FunctionblockValue) JXPathNotFoundException(org.apache.commons.jxpath.JXPathNotFoundException) ModelProperty(org.eclipse.vorto.model.ModelProperty) JXPathInvalidAccessException(org.apache.commons.jxpath.JXPathInvalidAccessException) MappingException(org.eclipse.vorto.mapping.engine.MappingException)

Example 4 with JXPathNotFoundException

use of org.apache.commons.jxpath.JXPathNotFoundException in project collect by openforis.

the class AbstractExpression method evaluateSingle.

protected Object evaluateSingle(Node<?> contextNode, Node<?> thisNode) throws InvalidExpressionException {
    try {
        JXPathContext jxPathContext = createJXPathContext(contextNode, thisNode);
        Object object = compiledExpression.getValue(jxPathContext);
        return object;
    } catch (IllegalArgumentException e) {
        throw new InvalidExpressionException(e.getMessage(), this.compiledExpression.toString());
    } catch (JXPathInvalidSyntaxException e) {
        throw new InvalidExpressionException(e.getMessage(), this.compiledExpression.toString());
    } catch (JXPathNotFoundException e) {
        return null;
    }
}
Also used : JXPathNotFoundException(org.apache.commons.jxpath.JXPathNotFoundException) JXPathInvalidSyntaxException(org.apache.commons.jxpath.JXPathInvalidSyntaxException) ModelJXPathContext(org.openforis.idm.model.expression.internal.ModelJXPathContext) JXPathContext(org.apache.commons.jxpath.JXPathContext)

Aggregations

JXPathNotFoundException (org.apache.commons.jxpath.JXPathNotFoundException)4 JXPathInvalidAccessException (org.apache.commons.jxpath.JXPathInvalidAccessException)3 MappingException (org.eclipse.vorto.mapping.engine.MappingException)2 ModelProperty (org.eclipse.vorto.model.ModelProperty)2 JXPathContext (org.apache.commons.jxpath.JXPathContext)1 JXPathInvalidSyntaxException (org.apache.commons.jxpath.JXPathInvalidSyntaxException)1 EntityModel (org.eclipse.vorto.model.EntityModel)1 EnumModel (org.eclipse.vorto.model.EnumModel)1 FunctionblockModel (org.eclipse.vorto.model.FunctionblockModel)1 IModel (org.eclipse.vorto.model.IModel)1 Stereotype (org.eclipse.vorto.model.Stereotype)1 EntityValue (org.eclipse.vorto.model.runtime.EntityValue)1 EnumValue (org.eclipse.vorto.model.runtime.EnumValue)1 FunctionblockValue (org.eclipse.vorto.model.runtime.FunctionblockValue)1 FunctionblockModel (org.eclipse.vorto.repository.api.content.FunctionblockModel)1 ModelProperty (org.eclipse.vorto.repository.api.content.ModelProperty)1 FunctionblockData (org.eclipse.vorto.service.mapping.normalized.FunctionblockData)1 ModelJXPathContext (org.openforis.idm.model.expression.internal.ModelJXPathContext)1