Пример #1
0
  @Override
  public FieldRecord getInstanceValueAsRelatedField(Long entityId, Long fieldId, Long instanceId) {
    validateCredentialsForReading(getEntity(entityId));
    try {
      FieldRecord fieldRecord;
      FieldDto field = entityService.getEntityFieldById(entityId, fieldId);
      MotechDataService service =
          DataServiceHelper.getDataService(
              bundleContext, field.getMetadata(RELATED_CLASS).getValue());

      Object instance = service.findById(instanceId);
      if (instance == null) {
        throw new ObjectNotFoundException(service.getClassType().getName(), instanceId);
      }
      fieldRecord = new FieldRecord(field);
      fieldRecord.setValue(
          parseValueForDisplay(instance, field.getMetadata(Constants.MetadataKeys.RELATED_FIELD)));
      fieldRecord.setDisplayValue(instance.toString());
      return fieldRecord;
    } catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
      throw new ObjectReadException(entityId, e);
    }
  }