@@ -107,13 +107,18 @@ public void loadModelData() {
107107 try {
108108 if (loadInProgress .getAndSet (true )) {
109109 log .warn ("Başka bir thread model yükleme işlemini başlattı. İşlem zaten devam ediyor." );
110+ loadLock .unlock ();
110111 return ;
111112 }
112113
113114 log .info ("AI model verilerini yükleme başlıyor - Deneme {}" , loadAttempts .incrementAndGet ());
114115
116+ // Tam dosya yolunu oluştur
117+ String resourcePath = modelsResource .getURL ().toString ();
118+ log .info ("Model dosyası yolu: {}" , resourcePath );
119+
115120 // Model yükleme işlemini timeout ile sınırla ve ayrı bir thread'de çalıştır
116- loadModelsFromFile (modelsResource . getURL (). toString () )
121+ loadModelsFromFile (resourcePath )
117122 .timeout (Duration .ofSeconds (timeoutSeconds ))
118123 .subscribeOn (Schedulers .boundedElastic ())
119124 .doOnSuccess (count -> {
@@ -163,22 +168,48 @@ public void loadModelData() {
163168 private List <ModelDTO > readModelsFromJson (String filePath ) throws IOException {
164169 log .debug ("JSON dosyasından model verilerini okuma: {}" , filePath );
165170
166- Resource resource = resourceLoader .getResource (filePath .startsWith ("classpath:" ) ||
167- filePath .startsWith ("file:" ) ||
168- filePath .startsWith ("http" ) ?
169- filePath : "file:" + filePath );
171+ Resource resource ;
172+
173+ // Create proper resource based on path
174+ if (filePath .startsWith ("classpath:" )) {
175+ resource = resourceLoader .getResource (filePath );
176+ } else if (filePath .startsWith ("file:" ) || filePath .startsWith ("http" )) {
177+ resource = resourceLoader .getResource (filePath );
178+ } else {
179+ // Assume it's a file path if no prefix provided
180+ resource = resourceLoader .getResource ("file:" + filePath );
181+ // Fall back to classpath if file not found
182+ if (!resource .exists ()) {
183+ log .info ("Dosya yerelde bulunamadı, classpath'te aranıyor: {}" , filePath );
184+ resource = resourceLoader .getResource ("classpath:" + filePath );
185+ }
186+ }
170187
171188 if (!resource .exists ()) {
172189 log .error ("Model dosyası bulunamadı: {}" , filePath );
173- throw new IOException ("Model dosyası bulunamadı: " + filePath );
190+ // Try to fall back to the default location
191+ resource = resourceLoader .getResource ("classpath:newmodels.json" );
192+ if (!resource .exists ()) {
193+ throw new IOException ("Model dosyası bulunamadı: " + filePath + " ve varsayılan dosya da bulunamadı" );
194+ }
195+ log .info ("Varsayılan model dosyası kullanılıyor: newmodels.json" );
174196 }
175197
176198 try (InputStream inputStream = resource .getInputStream ()) {
177199 List <ModelDTO > models = objectMapper .readValue (
178200 inputStream ,
179201 new TypeReference <List <ModelDTO >>() {}
180202 );
181- log .info ("JSON dosyasından {} model okundu" , models .size ());
203+ log .info ("JSON dosyasından {} model okundu: {}" , models .size (), resource .getFilename ());
204+
205+ // Log the first few models for debugging
206+ if (!models .isEmpty ()) {
207+ int sampleSize = Math .min (models .size (), 3 );
208+ List <String > sampleModels = models .subList (0 , sampleSize ).stream ()
209+ .map (m -> m .modelId + " (" + m .provider + ")" )
210+ .collect (Collectors .toList ());
211+ log .info ("Örnek modeller: {}" , String .join (", " , sampleModels ));
212+ }
182213
183214 // Okunan verileri doğrula
184215 validateModels (models );
@@ -309,6 +340,16 @@ private Mono<Map<String, Provider>> saveProvidersReactive(List<ModelDTO> modelDT
309340 if (originalProviderCount > uniqueProviderNames .size ()) {
310341 log .warn ("{} model null veya boş provider içeriyor ve işlenmeyecek" ,
311342 originalProviderCount - uniqueProviderNames .size ());
343+
344+ // Uyarı: Null/boş provider içeren model ID'lerini raporla
345+ List <String > problematicModels = modelDTOs .stream ()
346+ .filter (dto -> dto .provider == null || dto .provider .trim ().isEmpty ())
347+ .map (dto -> dto .modelId != null ? dto .modelId : "bilinmeyen model" )
348+ .collect (Collectors .toList ());
349+
350+ if (!problematicModels .isEmpty ()) {
351+ log .warn ("Null/boş provider içeren modeller: {}" , String .join (", " , problematicModels ));
352+ }
312353 }
313354
314355 // Veritabanından mevcut provider'ları getir
@@ -341,6 +382,12 @@ private Mono<Map<String, Provider>> saveProvidersReactive(List<ModelDTO> modelDT
341382 }
342383
343384 Provider newProvider = createProvider (providerName , null );
385+
386+ // Ekstra güvenlik: Adın null olmadığından emin ol
387+ if (newProvider .getName () == null ) {
388+ log .error ("Provider oluşturma hatası: null isim. Orijinal isim: {}" , providerName );
389+ continue ;
390+ }
344391
345392 newProviders .add (newProvider );
346393 log .info ("Yeni provider hazırlanıyor: {}" , newProvider .getName ());
@@ -437,17 +484,17 @@ class ModelCounter {
437484
438485 processedModelIds .add (dto .modelId );
439486
440- // Provider kontrolü
487+ // Provider kontrolü - null veya boş provider'ları atla
441488 if (dto .provider == null || dto .provider .trim ().isEmpty ()) {
442- log .warn ("Model için provider null veya boş: {}" , dto .modelId );
489+ log .warn ("Model için provider null veya boş: {}, bu model atlanıyor " , dto .modelId );
443490 counter .invalidProviderCount ++;
444491 continue ;
445492 }
446493
447494 Provider provider = providerMap .get (dto .provider );
448495
449496 if (provider == null ) {
450- log .warn ("Model için provider bulunamadı {}: {}" , dto .modelId , dto .provider );
497+ log .warn ("Model için provider bulunamadı {}: {}, bu model atlanıyor " , dto .modelId , dto .provider );
451498 counter .errorCount ++;
452499 continue ;
453500 }
@@ -580,9 +627,14 @@ public Map<String, Object> getModelLoadingStatus() {
580627 * Provider oluşturma işlemini gerçekleştiren yardımcı metod
581628 */
582629 private Provider createProvider (String name , String description ) {
630+ if (name == null || name .trim ().isEmpty ()) {
631+ name = "Bilinmeyen-" + UUID .randomUUID ().toString ().substring (0 , 8 );
632+ log .warn ("Null veya boş provider ismi yerine benzersiz değer oluşturuldu: {}" , name );
633+ }
634+
583635 return Provider .builder ()
584636 .name (name )
585- .description (description )
637+ .description (description != null ? description : name + " Provider" )
586638 .active (true )
587639 .createdAt (LocalDateTime .now ())
588640 .updatedAt (LocalDateTime .now ())
0 commit comments