private void verityLicenseIsConflictFree ( final DbLicense newComer ) { if ( newComer . getRegexp ( ) == null || newComer . getRegexp ( ) . isEmpty ( ) ) { return ; } final DbLicense existing = repoHandler . getLicense ( newComer . getName ( ) ) ; final List < DbLicense > licenses = repoHandler . getAllLicenses ( ) ; if ( null == existing ) { licenses . add ( newComer ) ; } else { existing . setRegexp ( newComer . getRegexp ( ) ) ; } final Optional < Report > reportOp = ReportsRegistry . findById ( MULTIPLE_LICENSE_MATCHING_STRINGS ) ; if ( reportOp . isPresent ( ) ) { final Report reportDef = reportOp . get ( ) ; ReportRequest reportRequest = new ReportRequest ( ) ; reportRequest . setReportId ( reportDef . getId ( ) ) ; Map < String , String > params = new HashMap <> ( ) ; // // TODO: Make the organization come as an external parameter from the client side. // This may have impact on the UI, as when the user will update a license he will // have to specify which organization he's editing the license for (in case there // are more organizations defined in the collection). // params . put ( "organization" , "Axway" ) ; reportRequest . setParamValues ( params ) ; final RepositoryHandler wrapped = wrapperBuilder . start ( repoHandler ) . replaceGetMethod ( "getAllLicenses" , licenses ) . build ( ) ; final ReportExecution execution = reportDef . execute ( wrapped , reportRequest ) ; List < String [ ] > data = execution . getData ( ) ; final Optional < String [ ] > first = data . stream ( ) . filter ( strings -> strings [ 2 ] . contains ( newComer . getName ( ) ) ) . findFirst ( ) ; if ( first . isPresent ( ) ) { final String [ ] strings = first . get ( ) ; final String message = String . format ( "Pattern conflict for string entry %s matching multiple licenses: %s" , strings [ 1 ] , strings [ 2 ] ) ; LOG . info ( message ) ; throw new WebApplicationException ( Response . status ( Response . Status . BAD_REQUEST ) . entity ( message ) . build ( ) ) ; } else { if ( ! data . isEmpty ( ) && ! data . get ( 0 ) [ 2 ] . isEmpty ( ) ) { LOG . info ( "There are remote conflicts between existing licenses and artifact strings" ) ; } } } else { if ( LOG . isWarnEnabled ( ) ) { LOG . warn ( String . format ( "Cannot find report by id %s" , MULTIPLE_LICENSE_MATCHING_STRINGS ) ) ; } } }
Check if new license pattern is valid and doesn t match any existing one