示例#1
0
  private Object getProperty(Object instance, FieldDto field, MotechDataService service)
      throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
    String fieldName = StringUtils.uncapitalize(field.getBasic().getName());

    PropertyDescriptor propertyDescriptor = PropertyUtil.getPropertyDescriptor(instance, fieldName);
    Method readMethod = propertyDescriptor.getReadMethod();

    if (readMethod == null) {
      throw new NoSuchMethodException(String.format("No getter for field %s", fieldName));
    }

    if (TypeDto.BLOB.getTypeClass().equals(field.getType().getTypeClass())) {
      return ArrayUtils.EMPTY_BYTE_OBJECT_ARRAY;
    }

    try {
      return readMethod.invoke(instance);
    } catch (InvocationTargetException e) {
      LOGGER.debug(
          "Invocation target exception thrown when retrieving field {}. This may indicate a non loaded field",
          fieldName,
          e);
      // fallback to the service
      return service.getDetachedField(instance, fieldName);
    }
  }
示例#2
0
  @Override
  public Object getInstanceField(Long entityId, Long instanceId, String fieldName) {
    EntityDto entity = getEntity(entityId);
    MotechDataService service = getServiceForEntity(entity);
    validateCredentialsForReading(entity);

    Object instance = service.retrieve(ID_FIELD_NAME, instanceId);

    return service.getDetachedField(instance, fieldName);
  }
示例#3
0
  private Object parseBlobValue(
      FieldRecord fieldRecord,
      MotechDataService service,
      String fieldName,
      Long deleteValueFieldId,
      Object instance) {
    Object parsedValue;
    if ((ArrayUtils.EMPTY_BYTE_OBJECT_ARRAY.equals(fieldRecord.getValue())
            || ArrayUtils.EMPTY_BYTE_ARRAY.equals(fieldRecord.getValue()))
        && !fieldRecord.getId().equals(deleteValueFieldId)) {
      parsedValue = service.getDetachedField(instance, fieldName);
    } else {
      parsedValue = fieldRecord.getValue();
    }

    return verifyParsedValue(parsedValue);
  }