Skip to content

Commit

Permalink
fix: conditionally load service, mark one as primary when profile is …
Browse files Browse the repository at this point in the history
…activated
  • Loading branch information
cleydyr committed Jun 1, 2024
1 parent da075ab commit 14fce39
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
6 changes: 4 additions & 2 deletions src/main/java/biblivre/circulation/user/IndexableUserDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,17 @@
import java.util.function.Function;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Primary;
import org.springframework.context.annotation.Profile;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.elasticsearch.client.elc.NativeQuery;
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
import org.springframework.data.elasticsearch.core.SearchHits;
import org.springframework.stereotype.Service;

@Service
@ConditionalOnProperty(value = "elasticsearch.server.url")
@Profile("elasticsearch")
@Primary
public class IndexableUserDAO extends UserDAOImpl {
@Autowired private IndexableUserRepository indexableUserRepository;

Expand Down
4 changes: 3 additions & 1 deletion src/main/java/biblivre/circulation/user/UserDAOImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Slf4j
public abstract class UserDAOImpl extends AbstractDAO implements UserDAO {
@Service
public class UserDAOImpl extends AbstractDAO implements UserDAO {

@Override
public Map<Integer, UserDTO> map(Collection<Integer> ids) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@

@Configuration
public class ElasticsearchClientConfiguration extends ElasticsearchConfiguration {
@Value("${elasticsearch.server.url}")
String serverUrl;
@Value("${elasticsearch.server.url:}")
private String serverUrl;

@Value("${elasticsearch.api.key}")
String apiKey;
@Value("${elasticsearch.api.key:}")
private String apiKey;

@Override
public ClientConfiguration clientConfiguration() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package biblivre.search.user;

import org.springframework.context.annotation.Profile;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import org.springframework.stereotype.Repository;

@Repository
@Profile("elasticsearch")
public interface IndexableUserRepository extends ElasticsearchRepository<IndexableUser, Integer> {
void deleteBySchemaAndTenant(String schema, String tenant);
}

0 comments on commit 14fce39

Please sign in to comment.