public void updateFromFile ( MultipartFile file ) { ObjectMapper objectMapper = ValidationObjUtil . getDefaultObjectMapper ( ) ; try { String jsonStr = new String ( file . getBytes ( ) , "UTF-8" ) ; List < ValidationData > list = objectMapper . readValue ( jsonStr , objectMapper . getTypeFactory ( ) . constructCollectionType ( List . class , ValidationData . class ) ) ; List < ReqUrl > reqUrls = ValidationReqUrlUtil . getUrlListFromValidationDatas ( list ) ; reqUrls . forEach ( reqUrl -> { this . deleteValidationData ( reqUrl ) ; } ) ; Map < Long , Long > idsMap = new HashMap <> ( ) ; List < ValidationData > saveList = new ArrayList <> ( ) ; list . forEach ( data -> { long oldId = data . getId ( ) ; data . setId ( null ) ; data = this . validationDataRepository . save ( data ) ; idsMap . put ( oldId , data . getId ( ) ) ; saveList . add ( data ) ; } ) ; saveList . forEach ( data -> { if ( data . getParentId ( ) != null ) { data . setParentId ( idsMap . get ( data . getParentId ( ) ) ) ; this . validationDataRepository . save ( data ) ; } } ) ; } catch ( IOException e ) { log . info ( "file io exception : " + e . getMessage ( ) ) ; } }
Update from file .