Skip to content

Commit

Permalink
Updated repo's queries name and logic
Browse files Browse the repository at this point in the history
  • Loading branch information
pasqualino.cristaudo committed Dec 4, 2023
1 parent da19be7 commit dd1fe19
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


import it.pagopa.interop.signalhub.updater.cache.model.ConsumerEServiceCache;
import it.pagopa.interop.signalhub.updater.utility.CacheUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
Expand All @@ -16,17 +17,16 @@ public class ConsumerEServiceCacheRepository {
@Qualifier("RedisTemplateConsumer")
private RedisTemplate<String, ConsumerEServiceCache> redisTemplate;


public void updateConsumerEService(ConsumerEServiceCache item){
Long index = this.findByEservice(item);
if(index != null) {
redisTemplate.opsForList().set(item.getEserviceId().concat("-").concat(item.getConsumerId()), index, item);
redisTemplate.opsForList().set(CacheUtils.getCacheKey(item.getEserviceId(), item.getConsumerId()), index, item);
log.info("Redis update OrganizationEService: {} ", item.getEserviceId());
}
}

private Long findByEservice(ConsumerEServiceCache consumerEServiceCache) {
return redisTemplate.opsForList().indexOf(consumerEServiceCache.getEserviceId().concat("-").concat(consumerEServiceCache.getConsumerId()), consumerEServiceCache);
return redisTemplate.opsForList().indexOf(CacheUtils.getCacheKey(consumerEServiceCache.getEserviceId(), consumerEServiceCache.getConsumerId()), consumerEServiceCache);
}


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;


@Repository
public interface TracingBatchRepository extends JpaRepository<TracingBatchEntity, Long> {
@Query("select trace from TracingBatchEntity trace where trace.lastEventId = (select MAX(t.lastEventId) from TracingBatchEntity t where t.type = :type) order by trace.tmstCreated desc" )
List<TracingBatchEntity> findByStateAndLastEventIdMaxAndType(String type);
List<TracingBatchEntity> findLatestByType(String type);

@Query("SELECT trace FROM TracingBatchEntity trace WHERE trace.state = :state AND trace.lastEventId = :lastEventId AND trace.type = :type")
List<TracingBatchEntity> findAllStateEndedWithErrorAndLastEventIdAndType(String state, Long lastEventId, String type);
@Query("SELECT trace FROM TracingBatchEntity trace WHERE trace.state = it.pagopa.interop.signalhub.updater.model.TracingBatchStateEnum.ENDED_WITH_ERROR AND trace.lastEventId = :lastEventId AND trace.type = :type")
List<TracingBatchEntity> findAllByStateEndedWithErrorAndLastEventIdAndType(Long lastEventId, String type);
}

0 comments on commit dd1fe19

Please sign in to comment.