Example usage for org.springframework.beans BeanWrapper getPropertyValue

List of usage examples for org.springframework.beans BeanWrapper getPropertyValue

Introduction

In this page you can find the example usage for org.springframework.beans BeanWrapper getPropertyValue.

Prototype

@Nullable
Object getPropertyValue(String propertyName) throws BeansException;

Source Link

Document

Get the current value of the specified property.

Usage

From source file:gov.nih.nci.cabig.caaers.audit.AdverseEventHistoryTest.java

protected void assertAllFieldPropertiesExist(List<DataAuditEventValue> values) {

    BeanWrapper wrappedCommand = new BeanWrapperImpl(adverseEvent);
    for (DataAuditEventValue value : values) {

        String msg = "The property " + value.getAttributeName() + " is not present in the adverse event. ";
        try {/*from   w w w  . jav a  2  s. co  m*/
            assertNotNull(msg, wrappedCommand.getPropertyType(value.getAttributeName()));
            assertEquals(value.getCurrentValue(),
                    wrappedCommand.getPropertyValue(value.getAttributeName()).toString());
        } catch (InvalidPropertyException ipe) {
            log.debug("Property not found exception", ipe);
            fail(msg);
        }
    }
}

From source file:gov.nih.nci.cabig.caaers.domain.repository.ReportValidationServiceImpl.java

/**
 * Validate./*  www .ja  v a 2s .  c o  m*/
 *
 * @param aeReport the ae report
 * @param mandatoryFields the mandatory fields
 * @param selfReferencedMandatoryFields the self referenced mandatory fields
 * @param section the section
 * @param messages the messages
 */
@SuppressWarnings("unchecked")
private void validate(ExpeditedAdverseEventReport aeReport, List<String> mandatoryFields,
        List<String> selfReferencedMandatoryFields, ExpeditedReportSection section,
        ReportSubmittability messages) {
    BeanWrapper bw = new BeanWrapperImpl(aeReport);

    TreeNode sectionNode = expeditedReportTree.getNodeForSection(section);
    if (sectionNode == null)
        throw new CaaersSystemException("There is no section node in the report tree for " + section.name()
                + ".  This shouldn't be possible.");

    List<String> applicableFields = new LinkedList<String>();
    for (String field : mandatoryFields) {
        TreeNode n = sectionNode.find(field);
        if (n == null)
            continue;
        applicableFields.add(field);
    }
    List<UnsatisfiedProperty> unsatisfied = expeditedReportTree.verifyPropertiesPresent(applicableFields,
            aeReport);
    for (UnsatisfiedProperty uProp : unsatisfied) {
        if (isErrorApplicable(bw, section, uProp))
            messages.addMissingField(section, uProp.getDisplayName(), uProp.getBeanPropertyName());
    }

    //evaluate the self referenced fields

    for (String fieldPath : selfReferencedMandatoryFields) {
        TreeNode node = expeditedReportTree.find(fieldPath);

        if (node != null && sectionNode.isAncestorOf(node)) {
            Object value = bw.getPropertyValue(fieldPath);

            if (value == null
                    || (value instanceof CodedEnum && String.valueOf(value).contains("Please select"))) {
                messages.addMissingField(section, node.getDisplayName(), fieldPath);
            }
        }

    }

}

From source file:gov.nih.nci.cabig.caaers.domain.repository.ReportValidationServiceImpl.java

/**
 * Applicability criteria :-//from   w w  w  .  j  av  a2s  .  c  o  m
 *   1. Lab category micro-biology (then baseline and
 * @param section
 * @param property
 * @return
 */
public boolean isErrorApplicable(BeanWrapper bw, ExpeditedReportSection section, UnsatisfiedProperty property) {
    String propertyPath = property.getBeanPropertyName();
    int dotIndex = propertyPath.indexOf('.');

    String parentEntityPath = dotIndex == -1 ? propertyPath : propertyPath.substring(0, dotIndex);

    if (section == LABS_SECTION) {
        Lab lab = (Lab) bw.getPropertyValue(parentEntityPath);
        return isLabErrorApplicable(lab, propertyPath);
    }
    if (section == MEDICAL_DEVICE_SECTION) {
        MedicalDevice device = (MedicalDevice) bw.getPropertyValue(parentEntityPath);
        return isMedicalDeviceErrorApplicable(device, propertyPath);
    }

    if (section == DESCRIPTION_SECTION) {
        AdverseEventResponseDescription description = (AdverseEventResponseDescription) bw
                .getPropertyValue(parentEntityPath);
        return isDescriptionErrorApplicable(description, propertyPath);
    }

    if (section == CONCOMITANT_MEDICATION_SECTION) {
        ConcomitantMedication conMed = (ConcomitantMedication) bw.getPropertyValue(parentEntityPath);
        return isConMedErrorApplicable(conMed, propertyPath);
    }

    return true;
}

From source file:gov.nih.nci.cabig.caaers.rules.common.CaaersRuleUtil.java

public static Map<String, Object> multiplexAndEvaluate(Object src, String path) {
    Map<String, Object> map = new HashMap<String, Object>();
    String[] pathParts = path.split("\\[\\]\\.");
    if (pathParts.length < 2)
        return map;

    BeanWrapper bw = new BeanWrapperImpl(src);
    Object coll = bw.getPropertyValue(pathParts[0]);
    if (coll instanceof Collection) {
        int i = 0;
        for (Object o : (Collection) coll) {
            if (pathParts.length == 2) {
                String s = pathParts[0] + "[" + i + "]." + pathParts[1];
                map.put(s, o);/*from   w  ww .jav  a  2  s .c o m*/

            } else {
                String s = pathParts[0] + "[" + i + "]";
                String[] _newPathParts = new String[pathParts.length - 1];
                System.arraycopy(pathParts, 1, _newPathParts, 0, _newPathParts.length);
                String _p = StringUtils.join(_newPathParts, "[].");
                Map<String, Object> m = multiplexAndEvaluate(o, _p);
                //map.put(s, o);
                for (String k : m.keySet()) {
                    map.put(s + "." + k, m.get(k));
                }
            }
            i++;
        }
    }

    return map;
}

From source file:gov.nih.nci.cabig.caaers.web.admin.CreateINDController.java

public void validate(INDCommand command, BindException errors) {
    BeanWrapper commandBean = new BeanWrapperImpl(command);
    for (InputFieldGroup fieldGroup : fieldMap.values()) {
        for (InputField field : fieldGroup.getFields()) {
            field.validate(commandBean, errors);
        }/*from w w  w  .java 2s.c  o  m*/
    }
    // check if the strINDNumber is a numeric value
    if (!StringUtils.isNumeric((String) commandBean.getPropertyValue("strINDNumber"))) {
        errors.rejectValue("strINDNumber", "ADM_IND_001", "IND# must be numeric");
    }
}

From source file:gov.nih.nci.cabig.caaers.web.ae.AbstractExpeditedAdverseEventInputCommand.java

/**
 * The repeating fields available in the mandatory sections will be pre-initialized here.
 *//*from ww w .j a  v  a2 s .c o m*/

@SuppressWarnings("unchecked")
public void initializeMandatorySectionFields() {
    Collection<ExpeditedReportSection> mandatorySections = getMandatorySections();
    if (mandatorySections == null || mandatorySections.isEmpty()) {
        log.info("No mandatory sections available, so no fields will be pre initialized");
        return;
    }

    // pre-initialize lazy fields in mandatory sections.
    BeanWrapper wrapper = new BeanWrapperImpl(getAeReport());
    for (ExpeditedReportSection section : getMandatorySections()) {
        assert (section != null) : "A section is null in command.getManatorySections()";

        TreeNode sectionNode = expeditedReportTree.getNodeForSection(section);
        if (sectionNode == null)
            log.warn("Unable to fetch TreeNode for section" + section.name());

        assert (sectionNode != null) : section.toString() + ", is not available in ExpeditedReportTree.";
        if (sectionNode.getChildren() == null)
            continue;

        for (TreeNode node : sectionNode.getChildren()) {
            if (node.isList()) {
                log.info("Initialized '" + node.getPropertyName() + "' in section " + section.name());
                try {
                    wrapper.getPropertyValue(node.getPropertyName() + "[0]");
                } catch (Exception e) {
                    e.printStackTrace();
                    log.debug("exception while getting property value: " + node.getPropertyName() + "[0]"
                            + "in expedited report");
                }
            }
        }

        // special case, when Agent section is mandatory, at least one course agent should be ther.
        if (ExpeditedReportSection.AGENTS_INTERVENTION_SECTION.equals(section)) {
            TreeNode agentSectionNode = expeditedReportTree
                    .getNodeForSection(ExpeditedReportSection.AGENTS_INTERVENTION_SECTION);
            List<CourseAgent> courseAgents = (List<CourseAgent>) wrapper.getPropertyValue(
                    agentSectionNode.getChildren().get(0).getPropertyName() + ".courseAgents");
            courseAgents.get(0);
        }
    }

}

From source file:gov.nih.nci.cabig.caaers.web.ae.MandatoryProperties.java

public List<UnsatisfiedProperty> getUnsatisfied(TreeNode section, ExpeditedAdverseEventReport aeReport) {

    BeanWrapper bw = new BeanWrapperImpl(aeReport);
    for (String path : realPropertyPaths) {
        TreeNode node = tree.find(path);
        if (node != null && section.isAncestorOf(node)) {
            Object value = bw.getPropertyValue(path);
            if (value == null
                    || (value instanceof CodedEnum && String.valueOf(value).contains("Please select")))
                return Arrays.asList(new UnsatisfiedProperty(node, path));
        }//from   ww  w  .ja va  2s  . c o  m
    }

    List<TreeNode> filtered = new LinkedList<TreeNode>();
    for (TreeNode node : getMandatoryNodes()) {
        if (section.isAncestorOf(node))
            filtered.add(node);
    }
    return tree.verifyNodesSatisfied(filtered, aeReport);
}

From source file:gov.nih.nci.cabig.caaers.web.fields.AbstractInputField.java

public static void validate(InputField field, BeanWrapper commandBean, Errors errors) {
    if (field.getValidators() == null || !field.isValidateable())
        return;/*from w w  w .j a  v  a 2  s .  c  o  m*/
    for (FieldValidator validator : field.getValidators()) {
        if (!validator.isValid(commandBean.getPropertyValue(field.getPropertyName()))) {
            errors.rejectValue(field.getPropertyName(), "REQUIRED",
                    "<b>" + validator.getMessagePrefix() + ":</b> &quot;" + field.getDisplayName() + "&quot;");
            return;
        }
    }
}

From source file:gov.nih.nci.cabig.caaers.web.fields.AbstractInputField.java

public static boolean isEmpty(InputField field, BeanWrapper commandBean) {
    return commandBean.getPropertyValue(field.getPropertyName()) == null;
}

From source file:gov.nih.nci.cabig.caaers.web.rule.notification.ReviewTab.java

public Pair fetchFieldValue(InputField field, BeanWrapper command) {
    Object value = command.getPropertyValue(field.getPropertyName());
    String strValue = (value == null) ? null : String.valueOf(value);
    return new Pair(field.getDisplayName(), strValue);
}