Search in sources :

Example 36 with BeanWrapper

use of org.springframework.beans.BeanWrapper in project alien4cloud by alien4cloud.

the class RestStepsDefinitions method deserAndRegister.

@And("^I register path \"(.*?)\" with class \"(.*?)\" as \"(.*?)\"$")
public void deserAndRegister(String propertyPath, String className, String key) throws Throwable {
    Class clazz = Class.forName(className);
    RestResponse restResponse = JsonUtil.read(Context.getInstance().getRestResponse(), clazz);
    Object value = restResponse;
    if (!"null".equals(propertyPath)) {
        BeanWrapper beanWrapper = new BeanWrapperImpl(restResponse);
        value = beanWrapper.getPropertyValue(propertyPath);
    }
    REGISTRY.put(key, value);
}
Also used : BeanWrapper(org.springframework.beans.BeanWrapper) BeanWrapperImpl(org.springframework.beans.BeanWrapperImpl) RestResponse(alien4cloud.rest.model.RestResponse) And(cucumber.api.java.en.And)

Example 37 with BeanWrapper

use of org.springframework.beans.BeanWrapper in project alien4cloud by alien4cloud.

the class ConstraintParser method parseConstraint.

private PropertyConstraint parseConstraint(String operator, Node keyNode, Node expressionNode, ParsingContextExecution context) {
    ConstraintParsingInfo info = constraintBuildersMap.get(operator);
    if (info == null) {
        context.getParsingErrors().add(new ParsingError(ParsingErrorLevel.WARNING, ErrorCode.UNKNOWN_CONSTRAINT, "Constraint parsing issue", keyNode.getStartMark(), "Unknown constraint operator, will be ignored.", keyNode.getEndMark(), operator));
        return null;
    }
    PropertyConstraint constraint;
    try {
        constraint = info.constraintClass.newInstance();
    } catch (InstantiationException | IllegalAccessException e) {
        throw new ParsingTechnicalException("Unable to create constraint.", e);
    }
    BeanWrapper target = new BeanWrapperImpl(constraint);
    parseAndSetValue(target, null, expressionNode, context, new MappingTarget(info.expressionPropertyName, info.expressionParser));
    return constraint;
}
Also used : PropertyConstraint(org.alien4cloud.tosca.model.definitions.PropertyConstraint) BeanWrapper(org.springframework.beans.BeanWrapper) BeanWrapperImpl(org.springframework.beans.BeanWrapperImpl)

Example 38 with BeanWrapper

use of org.springframework.beans.BeanWrapper in project alien4cloud by alien4cloud.

the class MapParser method doParse.

private Map<String, T> doParse(MappingNode node, ParsingContextExecution context) {
    Map<String, T> map = Maps.newLinkedHashMap();
    for (NodeTuple entry : node.getValue()) {
        String key = scalarParser.parse(entry.getKeyNode(), context);
        T value = null;
        value = valueParser.parse(entry.getValueNode(), context);
        if (value != null) {
            if (keyPath != null) {
                BeanWrapper valueWrapper = new BeanWrapperImpl(value);
                valueWrapper.setPropertyValue(keyPath, key);
            }
            if (value == null) {
                ParsingError err = new ParsingError(ParsingErrorLevel.WARNING, ErrorCode.SYNTAX_ERROR, "Invalid format for the value.", node.getStartMark(), "The value cannot be parsed", node.getEndMark(), key);
                context.getParsingErrors().add(err);
            } else {
                map.put(key, value);
            }
        }
    }
    return map;
}
Also used : BeanWrapper(org.springframework.beans.BeanWrapper) BeanWrapperImpl(org.springframework.beans.BeanWrapperImpl) NodeTuple(org.yaml.snakeyaml.nodes.NodeTuple)

Example 39 with BeanWrapper

use of org.springframework.beans.BeanWrapper in project alien4cloud by alien4cloud.

the class AbstractTypeNodeParser method findWrapperPropertyByPath.

/**
 * For example:
 * <ul>
 * <li>.something : the value will be set to the property of root named 'something'
 * <li>child1.child2.prop : the value will be mapped u getChild1().getChild2().setProp()
 * </ul>
 */
private Entry<BeanWrapper, String> findWrapperPropertyByPath(BeanWrapper root, BeanWrapper current, String path) {
    int dotIdx = path.indexOf(".");
    if (dotIdx < 0) {
        return new DefaultMapEntry<BeanWrapper, String>(current, path);
    }
    BeanWrapper base = current;
    String nextPath = path;
    if (path.startsWith("../")) {
        base = new BeanWrapperImpl(ParsingContextExecution.getParent(current));
        nextPath = path.substring(3);
    } else if (path.startsWith(".")) {
        base = root;
        nextPath = path.substring(1);
    } else {
        String wrapperCandidateName = path.substring(0, path.indexOf("."));
        Object wrapperCandidate = current.getPropertyValue(wrapperCandidateName);
        base = new BeanWrapperImpl(wrapperCandidate);
        nextPath = path.substring(path.indexOf(".") + 1);
    }
    return findWrapperPropertyByPath(root, base, nextPath);
}
Also used : DefaultMapEntry(org.apache.commons.collections4.keyvalue.DefaultMapEntry) BeanWrapper(org.springframework.beans.BeanWrapper) BeanWrapperImpl(org.springframework.beans.BeanWrapperImpl)

Example 40 with BeanWrapper

use of org.springframework.beans.BeanWrapper in project molgenis by molgenis.

the class JobExecutor method writePropertyValues.

private void writePropertyValues(JobExecution jobExecution, MutablePropertyValues pvs) {
    BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(jobExecution);
    bw.setPropertyValues(pvs, true);
}
Also used : BeanWrapper(org.springframework.beans.BeanWrapper)

Aggregations

BeanWrapper (org.springframework.beans.BeanWrapper)144 BeanWrapperImpl (org.springframework.beans.BeanWrapperImpl)79 Test (org.junit.jupiter.api.Test)31 NumberTestBean (org.springframework.beans.testfixture.beans.NumberTestBean)21 BooleanTestBean (org.springframework.beans.testfixture.beans.BooleanTestBean)20 MutablePropertyValues (org.springframework.beans.MutablePropertyValues)19 ITestBean (org.springframework.beans.testfixture.beans.ITestBean)18 IndexedTestBean (org.springframework.beans.testfixture.beans.IndexedTestBean)18 TestBean (org.springframework.beans.testfixture.beans.TestBean)18 Consumes (javax.ws.rs.Consumes)16 PUT (javax.ws.rs.PUT)16 Path (javax.ws.rs.Path)16 PropertyEditorSupport (java.beans.PropertyEditorSupport)14 Assertions.assertThatIllegalArgumentException (org.assertj.core.api.Assertions.assertThatIllegalArgumentException)14 HashSet (java.util.HashSet)12 BeansException (org.springframework.beans.BeansException)12 PropertyDescriptor (java.beans.PropertyDescriptor)11 OnmsNode (org.opennms.netmgt.model.OnmsNode)9 Test (org.junit.Test)6 BigDecimal (java.math.BigDecimal)5