Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- *
- * @param obj the PestMeasurement whose fields will be set
- * @param fieldName the field name of the object
- * @param fieldValue the value to be set to the field of the object
- * @return true if the value has been successfully set to the field, false if an error occurs
- */
- public boolean invokeSetter(Object obj, String propertyName, Object variableValue) {
- PropertyDescriptor pd
- try {
- pd = new PropertyDescriptor(propertyName, obj.getClass())
- Method setter = pd.getWriteMethod()
- try {
- setter.invoke(obj, variableValue)
- return true
- } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
- output.warn("Setter method for field ${propertyName} not found")
- return false
- }
- } catch (IntrospectionException e) {
- output.warn("Invoking setter for field ${propertyName} failed")
- return false
- }
- }
- /** Saves all properties of the task that triggered script into the status record */
- public void fillTaskProperties(PestMeasurement pm, PestMeasurement statusPm) {
- Measurement measurement = measurementService.loadMeasurementDetails(session, pm)
- processService.getTaskPropertyDefinitions(statusPm.getType().getSubflowChain()).each { p ->
- String propName = p.getName()
- Object propValue = measurement.getPropertyValue(p, 0, false)
- if (propValue != null && !propName.equals("data") && !propName.equals("photo_note")) {
- if (p.getFieldName() != null) { //with column name
- propValue = pm.getPropertyValue(p.getFieldNameSafe())
- if (propValue != null) invokeSetter(statusPm, p.getFieldName(), propValue)
- } else { // no column name
- if (p.getDataType().isNumeric()) {
- // is numeric
- saveNumericProperty(statusPm, Double.parseDouble(String.valueOf(propValue)), p)
- } else if (p.getDataType().isString()) {
- // is string
- saveStringProperty(statusPm, String.valueOf(propValue), p)
- } else {
- //resource type
- output.println("Resource properties will be handled separately")
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement