src/main/java/com/property/manager/data/service/PropertyService.java
public ResponseEntity<?> updateProperty(ArrayList<PropertyDTO> propertyDTOs, ClientEntity clientEntity) {
        //checking if all propertyDTOs have id
        if (propertyDTOs.stream().
                anyMatch(propertyEntity -> propertyEntity.getId() == null))
            return new ResponseEntity<>(messageSource.getMessage(property_dto_required, null, null), HttpStatus.BAD_REQUEST);

        Collection<PropertyEntity> propertyEntities = propertyRepository.findAllByIdInAndRemovedIsFalse(
                propertyDTOs.stream().map(PropertyDTO::getId).collect(Collectors.toList()));

        //checking if propertyDTOs are client's
        if (!propertyEntities.stream().
                allMatch(propertyEntity -> propertyEntity.getClientEntity().getId().equals(clientEntity.getId())))
            return new ResponseEntity<>(HttpStatus.UNAUTHORIZED);


        //Filtering DTOs which have corresponding entities
        HashMap<Long, PropertyDTO> propertyDTOLongHashMap = new HashMap<>();
        propertyDTOs.forEach(propertyDTO -> propertyDTOLongHashMap.put(propertyDTO.getId(), propertyDTO));
        List<PropertyDTO> propertyDTOsFromEntities =
                propertyEntities.stream().
                        map(propertyEntity -> propertyDTOLongHashMap.get(propertyEntity.getId())).collect(Collectors.toList());
        propertyDTOs = (ArrayList<PropertyDTO>) propertyDTOsFromEntities;


        try {
            geoService.setPropertiesCoordinates(propertyDTOs);
        } catch (IOException | InterruptedException ex) {
            LOGGER.error("addProperty", ex);
            return new ResponseEntity<>(messageSource.getMessage(try_later, null, null), HttpStatus.INTERNAL_SERVER_ERROR);
        }

        propertyMapper.updateToEntities(propertyDTOs, (ArrayList<PropertyEntity>) propertyEntities);
        propertyEntities.forEach(propertyEntity -> propertyEntity.setClientEntity(clientEntity));
        propertyEntities = propertyRepository.saveAll(propertyEntities);
        return new ResponseEntity<>(propertyMapper.toDTOs(propertyEntities), HttpStatus.OK);
    }
/**
     * Updates properties, sets updated coordinates and saves in database
     *
     * @param propertyDTOs
     * @return ResponseEntity object, with status code and object
     */
Updates properties, sets updated coordinates and saves in database
@param propertyDTOs
@return ResponseEntity object, with status code and object
Updates properties sets updated coordinates and saves in database @param propertyDTOs @return ResponseEntity object with status code and object
public ResponseEntity<?> updateProperty(ArrayList<PropertyDTO> propertyDTOs, ClientEntity clientEntity) {
        if (propertyDTOs.stream().
                anyMatch(propertyEntity -> propertyEntity.getId() == null))
            return new ResponseEntity<>(messageSource.getMessage(property_dto_required, null, null), HttpStatus.BAD_REQUEST);
        Collection<PropertyEntity> propertyEntities = propertyRepository.findAllByIdInAndRemovedIsFalse(
                propertyDTOs.stream().map(PropertyDTO::getId).collect(Collectors.toList()));
        if (!propertyEntities.stream().
                allMatch(propertyEntity -> propertyEntity.getClientEntity().getId().equals(clientEntity.getId())))
            return new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
        HashMap<Long, PropertyDTO> propertyDTOLongHashMap = new HashMap<>();
        propertyDTOs.forEach(propertyDTO -> propertyDTOLongHashMap.put(propertyDTO.getId(), propertyDTO));
        List<PropertyDTO> propertyDTOsFromEntities =
                propertyEntities.stream().
                        map(propertyEntity -> propertyDTOLongHashMap.get(propertyEntity.getId())).collect(Collectors.toList());
        propertyDTOs = (ArrayList<PropertyDTO>) propertyDTOsFromEntities;
        try {
            geoService.setPropertiesCoordinates(propertyDTOs);
        } catch (IOException | InterruptedException ex) {
            LOGGER.error("addProperty", ex);
            return new ResponseEntity<>(messageSource.getMessage(try_later, null, null), HttpStatus.INTERNAL_SERVER_ERROR);
        }
        propertyMapper.updateToEntities(propertyDTOs, (ArrayList<PropertyEntity>) propertyEntities);
        propertyEntities.forEach(propertyEntity -> propertyEntity.setClientEntity(clientEntity));
        propertyEntities = propertyRepository.saveAll(propertyEntities);
        return new ResponseEntity<>(propertyMapper.toDTOs(propertyEntities), HttpStatus.OK);
    }
public ResponseEntity < ? > updateProperty ( ArrayList < PropertyDTO > propertyDTOs , ClientEntity clientEntity ) { if ( propertyDTOs . stream ( ) . anyMatch ( propertyEntity -> propertyEntity . getId ( ) == null ) ) return new ResponseEntity < > ( messageSource . getMessage ( property_dto_required , null , null ) , HttpStatus . BAD_REQUEST ) ; Collection < PropertyEntity > propertyEntities = propertyRepository . findAllByIdInAndRemovedIsFalse ( propertyDTOs . stream ( ) . map ( PropertyDTO :: getId ) . collect ( Collectors . toList ( ) ) ) ; if ( ! propertyEntities . stream ( ) . allMatch ( propertyEntity -> propertyEntity . getClientEntity ( ) . getId ( ) . equals ( clientEntity . getId ( ) ) ) ) return new ResponseEntity < > ( HttpStatus . UNAUTHORIZED ) ; HashMap < Long , PropertyDTO > propertyDTOLongHashMap = new HashMap < > ( ) ; propertyDTOs . forEach ( propertyDTO -> propertyDTOLongHashMap . put ( propertyDTO . getId ( ) , propertyDTO ) ) ; List < PropertyDTO > propertyDTOsFromEntities = propertyEntities . stream ( ) . map ( propertyEntity -> propertyDTOLongHashMap . get ( propertyEntity . getId ( ) ) ) . collect ( Collectors . toList ( ) ) ; propertyDTOs = ( ArrayList < PropertyDTO > ) propertyDTOsFromEntities ; try { geoService . setPropertiesCoordinates ( propertyDTOs ) ; } catch ( IOException | InterruptedException ex ) { LOGGER . error ( "addProperty" , ex ) ; return new ResponseEntity < > ( messageSource . getMessage ( try_later , null , null ) , HttpStatus . INTERNAL_SERVER_ERROR ) ; } propertyMapper . updateToEntities ( propertyDTOs , ( ArrayList < PropertyEntity > ) propertyEntities ) ; propertyEntities . forEach ( propertyEntity -> propertyEntity . setClientEntity ( clientEntity ) ) ; propertyEntities = propertyRepository . saveAll ( propertyEntities ) ; return new ResponseEntity < > ( propertyMapper . toDTOs ( propertyEntities ) , HttpStatus . OK ) ; }
Updates properties, sets updated coordinates and saves in database
 @param propertyDTOs
 @return ResponseEntity object, with status code and object
Updates properties sets updated coordinates and saves in database @param propertyDTOs @return ResponseEntity object with status code and object
//checking if all propertyDTOs have id //checking if propertyDTOs are client's //Filtering DTOs which have corresponding entities