@Override public void addRelations(Task task,Iterable<ObjectId> projectIds,String fieldName){
  List<Project> newProjectList=new LinkedList<>();
  Iterable<Project> projectsToAdd=projectRepository.findAll(projectIds,null);
  projectsToAdd.forEach(null);
  try {
    if (PropertyUtils.getProperty(task,fieldName) != null) {
      Iterable<Project> projects=(Iterable<Project>)PropertyUtils.getProperty(task,fieldName);
      projects.forEach(null);
    }
  }
 catch (  Exception e) {
    throw new RuntimeException(e);
  }
  try {
    PropertyUtils.setProperty(task,fieldName,newProjectList);
  }
 catch (  Exception e) {
    throw new RuntimeException(e);
  }
  taskRepository.save(task);
}

@ Override public void addRelations ( Task task , Iterable < ObjectId > projectIds , String fieldName ) { List < Project > newProjectList = new LinkedList < > ( ) ; Iterable < Project > projectsToAdd = projectRepository . findAll ( projectIds , null ) ; projectsToAdd . forEach ( null ) ; try { if ( PropertyUtils . getProperty ( task , fieldName ) != null ) { Iterable < Project > projects = ( Iterable < Project > ) PropertyUtils . getProperty ( task , fieldName ) ; projects . forEach ( null ) ; } } catch ( Exception e ) { throw new RuntimeException ( e ) ; } try { PropertyUtils . setProperty ( task , fieldName , newProjectList ) ; } catch ( Exception e ) { throw new RuntimeException ( e ) ; } taskRepository . save ( task ) ; }
a simple implementation of the addrelations method which presents the general concept of the method . it should not be used in production because of possible race condition - production ready code should perform an atomic operation .
