-
Notifications
You must be signed in to change notification settings - Fork 20
Develop #888
Changes from 150 commits
28b4751
279971f
b6f6417
d728c12
de2fcff
2fe7dda
efed9ee
e350362
9fbd2da
291385f
e072b18
67f7a2a
08454d9
fccf62f
2709c88
51bd0f7
ee7496d
421c7a9
68fd5de
6aa0ee6
ee0e507
d19315d
1af44f1
18bed51
2821bae
db0d337
4630df8
611b995
d0bc522
e70ce6c
e834834
8185a33
824fdec
ce54eda
40d3b97
01e54c8
d8b0c03
c9454de
cc99548
611f7bf
fbc4af7
d1d9a46
7c59091
bcf8c7b
8234110
f7ad737
3bd19e7
4b6aad3
22cc939
b29c34a
368bc82
6f2069f
2eca768
251fd7c
a6b5533
0728cdd
e13a3f0
b01e061
1feb674
3a8a234
3d3d2bf
7dd84a3
471cf49
1d3fe03
63542a5
b544764
3efae56
c7f49e5
fec65b8
d421ae7
e65f347
16890be
72f9578
d603564
67cf72b
608910c
7fb1e6e
bc5c6ef
16e3125
8b23985
53b73b2
9ade404
b0636b7
5c6f91d
51d0d67
0841114
a7465a9
d96d496
2d6b83f
49a292b
c0233a8
cf7e312
e665b86
591c6fa
60e66bb
bdeb0fb
ffa1d4a
e6196c9
f3947f6
ec123ae
26e7375
7a6d9b6
61e125d
60c5c02
f5967b1
b2def2f
458d9db
679e6aa
81979fc
ed9b746
7bea11b
e24ea4f
7e71d95
3a865a7
a74ec00
8d4efdd
bf0ecb3
db3824d
3bff38e
1be043c
cc34a75
4a11e7f
7c76dd0
bc093ed
3915763
58e398a
43be3ee
0fa7f44
d9d3beb
b70f21f
5a8eaf4
da6f6f7
f6933a2
7ae0d2c
6bd1d0f
f9c815c
c61f398
107fca2
f9184ff
8af8e68
9b6d4cf
0ae9fab
2a8dc81
9a84d13
ea0d3ec
55b0a9e
6e64334
c036ce6
0695131
0021659
8b4c730
668eef4
f8f172c
49df0ad
73cc5d0
7a65244
cd25f8e
b57214c
9f9cf75
8fdb8fe
9af8c3a
587b476
10a704f
f1f9d86
7fd9f1c
ac4dd01
4373e28
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -125,4 +125,39 @@ public class PropertiesManager { | |
|
||
@Value("${egov.hrms.max.pagination.limit}") | ||
public Integer hrmsMaxLimit; | ||
|
||
// FuzzyConfigs | ||
@Value("${hrms.search.pagination.default.limit}") | ||
public Long defaultLimit; | ||
|
||
@Value("${hrms.search.pagination.default.offset}") | ||
public Long defaultOffset; | ||
|
||
@Value("${hrms.search.pagination.max.search.limit}") | ||
public Long searchLimit; | ||
|
||
@Value("${hrms.search.pagination.max.search.limit}") | ||
private Long maxSearchLimit; | ||
Comment on lines
+139
to
+140
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid Duplicate Property Keys. The property key - @Value("${hrms.search.pagination.max.search.limit}")
- public Long searchLimit;
+ @Value("${hrms.search.pagination.search.limit}")
+ public Long searchLimit;
|
||
|
||
@Value("${hrms.fuzzy.search.is.wildcard}") | ||
private Boolean isSearchWildcardBased; | ||
|
||
@Value("${hrms.search.name.fuziness}") | ||
private String nameFuziness; | ||
|
||
// es configs | ||
@Value("${elasticsearch.host}") | ||
private String esHost; | ||
|
||
@Value("${hrms.es.index}") | ||
private String esPTIndex; | ||
|
||
@Value("${elasticsearch.search.endpoint}") | ||
private String esSearchEndpoint; | ||
|
||
@Value("${egov.es.username}") | ||
private String userName; | ||
|
||
@Value("${egov.es.password}") | ||
private String password; | ||
Comment on lines
+158
to
+162
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Secure Sensitive Information. Avoid storing sensitive information such as Elasticsearch credentials in code. Consider using environment variables or a secrets management tool. @Value("${egov.es.username:#{null}}")
private String userName;
@Value("${egov.es.password:#{null}}")
private String password; |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package org.egov.hrms.repository; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.egov.hrms.config.PropertiesManager; | ||
import org.egov.hrms.web.contract.EmployeeSearchCriteria; | ||
import org.egov.tracer.model.CustomException; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.HttpEntity; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.stereotype.Repository; | ||
import org.springframework.web.client.RestTemplate; | ||
|
||
import java.util.Base64; | ||
import java.util.List; | ||
|
||
@Slf4j | ||
@Repository | ||
public class ElasticSearchRepository { | ||
private PropertiesManager config; | ||
|
||
private FuzzySearchQueryBuilder queryBuilder; | ||
|
||
private RestTemplate restTemplate; | ||
|
||
private ObjectMapper mapper; | ||
|
||
@Autowired | ||
public ElasticSearchRepository(PropertiesManager config, FuzzySearchQueryBuilder queryBuilder, RestTemplate restTemplate, ObjectMapper mapper) { | ||
this.config = config; | ||
this.queryBuilder = queryBuilder; | ||
this.restTemplate = restTemplate; | ||
this.mapper = mapper; | ||
} | ||
|
||
public Object fuzzySearchEmployees(EmployeeSearchCriteria criteria, List<String> uuids) { | ||
|
||
|
||
String url = getESURL(); | ||
|
||
String searchQuery = queryBuilder.getFuzzySearchQuery(criteria, uuids); | ||
|
||
HttpHeaders headers = new HttpHeaders(); | ||
headers.add("Authorization", getESEncodedCredentials()); | ||
headers.setContentType(MediaType.APPLICATION_JSON); | ||
log.info("Headers: " + headers.toString()); | ||
HttpEntity<String> requestEntity = new HttpEntity<>(searchQuery, headers); | ||
ResponseEntity response = null; | ||
try { | ||
response = restTemplate.postForEntity(url, requestEntity, Object.class); | ||
|
||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
throw new CustomException("ES_ERROR","Failed to fetch data from ES"); | ||
} | ||
|
||
return response.getBody(); | ||
|
||
} | ||
|
||
|
||
/** | ||
* Generates elasticsearch search url from application properties | ||
* | ||
* @return | ||
*/ | ||
private String getESURL() { | ||
|
||
StringBuilder builder = new StringBuilder(config.getEsHost()); | ||
builder.append(config.getEsPTIndex()); | ||
builder.append(config.getEsSearchEndpoint()); | ||
|
||
return builder.toString(); | ||
} | ||
|
||
public String getESEncodedCredentials() { | ||
String credentials = config.getUserName() + ":" + config.getPassword(); | ||
byte[] credentialsBytes = credentials.getBytes(); | ||
byte[] base64CredentialsBytes = Base64.getEncoder().encode(credentialsBytes); | ||
return "Basic " + new String(base64CredentialsBytes); | ||
} | ||
Comment on lines
+78
to
+83
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Secure handling of credentials in The method encodes credentials using Base64, which is not secure for sensitive data. Consider using a more secure method for handling credentials. - String credentials = config.getUserName() + ":" + config.getPassword();
- byte[] credentialsBytes = credentials.getBytes();
- byte[] base64CredentialsBytes = Base64.getEncoder().encode(credentialsBytes);
- return "Basic " + new String(base64CredentialsBytes);
+ // Consider using a secure credentials management system or encryption
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid using
printStackTrace
for exception handling.Using
printStackTrace
is not recommended for production code. Consider using a logger to capture exceptions.Committable suggestion