Advertisement
Guest User

lib

a guest
Mar 30th, 2020
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | None | 0 0
  1. /**
  2. *
  3. * @param obj the PestMeasurement whose fields will be set
  4. * @param fieldName the field name of the object
  5. * @param fieldValue the value to be set to the field of the object
  6. * @return true if the value has been successfully set to the field, false if an error occurs
  7. */
  8. public boolean invokeSetter(Object obj, String propertyName, Object variableValue) {
  9. PropertyDescriptor pd
  10. try {
  11. pd = new PropertyDescriptor(propertyName, obj.getClass())
  12. Method setter = pd.getWriteMethod()
  13. try {
  14. setter.invoke(obj, variableValue)
  15. return true
  16.  
  17. } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
  18. output.warn("Setter method for field ${propertyName} not found")
  19. return false
  20. }
  21. } catch (IntrospectionException e) {
  22. output.warn("Invoking setter for field ${propertyName} failed")
  23. return false
  24. }
  25. }
  26.  
  27. /** Saves all properties of the task that triggered script into the status record */
  28. public void fillTaskProperties(PestMeasurement pm, PestMeasurement statusPm) {
  29. Measurement measurement = measurementService.loadMeasurementDetails(session, pm)
  30. processService.getTaskPropertyDefinitions(statusPm.getType().getSubflowChain()).each { p ->
  31. String propName = p.getName()
  32. Object propValue = measurement.getPropertyValue(p, 0, false)
  33.  
  34. if (propValue != null && !propName.equals("data") && !propName.equals("photo_note")) {
  35. if (p.getFieldName() != null) { //with column name
  36. propValue = pm.getPropertyValue(p.getFieldNameSafe())
  37. if (propValue != null) invokeSetter(statusPm, p.getFieldName(), propValue)
  38. } else { // no column name
  39. if (p.getDataType().isNumeric()) {
  40. // is numeric
  41. saveNumericProperty(statusPm, Double.parseDouble(String.valueOf(propValue)), p)
  42. } else if (p.getDataType().isString()) {
  43. // is string
  44. saveStringProperty(statusPm, String.valueOf(propValue), p)
  45. } else {
  46. //resource type
  47. output.println("Resource properties will be handled separately")
  48. }
  49. }
  50. }
  51. }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement