-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Govt StateID and DistrictId changes #58
Changes from all commits
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 | ||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -43,6 +43,10 @@ public class States { | |||||||||||||||||||||||||||||||
@Column(name = "StateID") | ||||||||||||||||||||||||||||||||
@Expose | ||||||||||||||||||||||||||||||||
private Integer stateID; | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
@Column(name = "GovtStateID") | ||||||||||||||||||||||||||||||||
@Expose | ||||||||||||||||||||||||||||||||
private Integer govtLGDStateID; | ||||||||||||||||||||||||||||||||
Comment on lines
+46
to
+49
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. Add getter/setter methods for govtLGDStateID field The new field lacks accessor methods which are needed for proper encapsulation. Also consider aligning the column name with the field name for consistency. Add the following methods: + public Integer getGovtLGDStateID() {
+ return this.govtLGDStateID;
+ }
+
+ public void setGovtLGDStateID(Integer govtLGDStateID) {
+ this.govtLGDStateID = govtLGDStateID;
+ } Consider renaming the column to match the field: - @Column(name = "GovtStateID")
+ @Column(name = "GovtLGDStateID") π Committable suggestion
Suggested change
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. @coderabbitai In DB its mentioned same 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. @ravishanigarapu Understood, thank you for the clarification. Since the database column is named However, the field βοΈ Learnings added
|
||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
@Column(name = "StateName") | ||||||||||||||||||||||||||||||||
@Expose | ||||||||||||||||||||||||||||||||
|
@@ -155,5 +159,10 @@ public String getStateName() { | |||||||||||||||||||||||||||||||
public void setStateName(String stateName) { | ||||||||||||||||||||||||||||||||
this.stateName = stateName; | ||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
public States(int StateID, String StateName, Integer govtLGDStateID) { | ||||||||||||||||||||||||||||||||
this.stateID = StateID; | ||||||||||||||||||||||||||||||||
this.stateName = StateName; | ||||||||||||||||||||||||||||||||
this.govtLGDStateID = govtLGDStateID; | ||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||
Comment on lines
+163
to
+167
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. π οΈ Refactor suggestion Add input validation and deprecate old constructor The new constructor should validate the govtLGDStateID parameter. Also, the old constructor should be marked as deprecated since it doesn't initialize all fields. Apply these changes: + @Deprecated(since = "AMM-1166", forRemoval = false)
public States(int StateID, String StateName) {
this.stateID = StateID;
this.stateName = StateName;
}
public States(int StateID, String StateName, Integer govtLGDStateID) {
this.stateID = StateID;
this.stateName = StateName;
+ if (govtLGDStateID != null && govtLGDStateID <= 0) {
+ throw new IllegalArgumentException("govtLGDStateID must be positive when provided");
+ }
this.govtLGDStateID = govtLGDStateID;
}
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. @coderabbitai it is used for other methods its not deprecated 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. @ravishanigarapu, understood. Thank you for the clarification that the old constructor is used in other methods and should not be deprecated. οΌ γ»Ογ»οΌ? βοΈ Learnings added
π§ Learnings used
|
||||||||||||||||||||||||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,7 +34,7 @@ | |
@Repository | ||
|
||
public interface DistrictMasterRepo extends CrudRepository<Districts, Integer> { | ||
@Query(" SELECT d.districtID, d.districtName FROM Districts d " + " WHERE d.stateID = :stateID AND d.deleted != true ") | ||
@Query(" SELECT d.districtID, d.districtName,d.govtLGDStateID,d.govtLGDDistrictID FROM Districts d " + " WHERE d.stateID = :stateID AND d.deleted != true ") | ||
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. π οΈ Refactor suggestion Improve query readability, type safety, and input validation Similar to StateMasterRepo, this query would benefit from better type safety and readability improvements. Also add parameter validation. Suggested improvements: + @NotNull(message = "stateID cannot be null")
+ @Positive(message = "stateID must be positive")
@Param("stateID") Integer stateID
- @Query(" SELECT d.districtID, d.districtName,d.govtLGDStateID,d.govtLGDDistrictID FROM Districts d " + " WHERE d.stateID = :stateID AND d.deleted != true ")
+ @Query("SELECT d.districtID as id, " +
+ " d.districtName as name, " +
+ " d.govtLGDStateID as stateLgdId, " +
+ " d.govtLGDDistrictID as districtLgdId " +
+ "FROM Districts d " +
+ "WHERE d.stateID = :stateID " +
+ "AND d.deleted != true") Create a DTO for type-safe returns: public class DistrictDTO {
private Integer id;
private String name;
private Integer stateLgdId;
private Integer districtLgdId;
// Constructor matching query projection
public DistrictDTO(Integer id, String name,
Integer stateLgdId, Integer districtLgdId) {
this.id = id;
this.name = name;
this.stateLgdId = stateLgdId;
this.districtLgdId = districtLgdId;
}
// Getters
} Update method signature: - public ArrayList<Object[]> getDistrictMaster(@Param("stateID") Integer stateID);
+ public List<DistrictDTO> getDistrictMaster(@Param("stateID") Integer stateID); 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. @coderabbitai not required 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. @ravishanigarapu, understood. |
||
public ArrayList<Object[]> getDistrictMaster(@Param("stateID") Integer stateID); | ||
|
||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -177,7 +177,8 @@ public String getDistrictList(Integer stateID) { | |||||||||||||||||||||||||||
ArrayList<Object[]> districtMasterList = districtMasterRepo.getDistrictMaster(stateID); | ||||||||||||||||||||||||||||
if (districtMasterList != null && districtMasterList.size() > 0) { | ||||||||||||||||||||||||||||
for (Object[] objArr : districtMasterList) { | ||||||||||||||||||||||||||||
Districts districtMaster = new Districts((Integer) objArr[0], (String) objArr[1]); | ||||||||||||||||||||||||||||
Districts districtMaster = new Districts((Integer) objArr[0], (String) objArr[1], (Integer) objArr[2], | ||||||||||||||||||||||||||||
(Integer) objArr[3]); | ||||||||||||||||||||||||||||
Comment on lines
+180
to
+181
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. Add array bounds and null checking before accessing elements. The code assumes the objArr array has at least 4 elements and that none are null. This could lead to ArrayIndexOutOfBoundsException or NullPointerException. - Districts districtMaster = new Districts((Integer) objArr[0], (String) objArr[1], (Integer) objArr[2],
- (Integer) objArr[3]);
+ if (objArr.length < 4) {
+ throw new IllegalStateException("Insufficient data for district creation");
+ }
+ Integer districtId = (Integer) objArr[0];
+ String districtName = (String) objArr[1];
+ Integer govtLGDStateId = (Integer) objArr[2];
+ Integer govtLGDDistrictId = (Integer) objArr[3];
+ if (districtId == null || districtName == null || govtLGDStateId == null || govtLGDDistrictId == null) {
+ throw new IllegalStateException("Null values found in district data");
+ }
+ Districts districtMaster = new Districts(districtId, districtName, govtLGDStateId, govtLGDDistrictId); π Committable suggestion
Suggested change
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. @coderabbitai its mandatory to get those fields 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. @ravishanigarapu Understood, thank you for the clarification. (_/) βοΈ Learnings added
|
||||||||||||||||||||||||||||
districtList.add(districtMaster); | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
|
@@ -237,7 +238,7 @@ public String getLocDetailsNew(Integer vanID, Integer spPSMID) { | |||||||||||||||||||||||||||
ArrayList<Object[]> stateMasterList = stateMasterRepo.getStateMaster(); | ||||||||||||||||||||||||||||
if (stateMasterList != null && stateMasterList.size() > 0) { | ||||||||||||||||||||||||||||
for (Object[] objArr : stateMasterList) { | ||||||||||||||||||||||||||||
States states = new States((Integer) objArr[0], (String) objArr[1]); | ||||||||||||||||||||||||||||
States states = new States((Integer) objArr[0], (String) objArr[1], (Integer) objArr[2]); | ||||||||||||||||||||||||||||
ravishanigarapu marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||
stateList.add(states); | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -33,15 +33,19 @@ | |||||||||||||||||||||||||||
import com.iemr.tm.utils.redis.RedisStorage; | ||||||||||||||||||||||||||||
import com.iemr.tm.utils.response.OutputResponse; | ||||||||||||||||||||||||||||
import com.iemr.tm.utils.sessionobject.SessionObject; | ||||||||||||||||||||||||||||
import com.iemr.tm.utils.validator.Validator; | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
import jakarta.servlet.http.HttpServletRequest; | ||||||||||||||||||||||||||||
import jakarta.servlet.http.HttpServletResponse; | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
@Component | ||||||||||||||||||||||||||||
public class HTTPRequestInterceptor implements HandlerInterceptor { | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
private Validator validator; | ||||||||||||||||||||||||||||
Logger logger = LoggerFactory.getLogger(this.getClass().getSimpleName()); | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
@Autowired | ||||||||||||||||||||||||||||
public void setValidator(Validator validator) { | ||||||||||||||||||||||||||||
this.validator = validator; | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
private SessionObject sessionObject; | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
@Autowired | ||||||||||||||||||||||||||||
|
@@ -86,6 +90,11 @@ public boolean preHandle(HttpServletRequest request, HttpServletResponse respons | |||||||||||||||||||||||||||
status = false; | ||||||||||||||||||||||||||||
break; | ||||||||||||||||||||||||||||
default: | ||||||||||||||||||||||||||||
String remoteAddress = request.getHeader("X-FORWARDED-FOR"); | ||||||||||||||||||||||||||||
if (remoteAddress == null || remoteAddress.trim().length() == 0) { | ||||||||||||||||||||||||||||
remoteAddress = request.getRemoteAddr(); | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
validator.checkKeyExists(authorization, remoteAddress); | ||||||||||||||||||||||||||||
Comment on lines
+93
to
+97
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. Add null check for validator before use. The validator is used without checking if it's null, which could lead to a NullPointerException. - validator.checkKeyExists(authorization, remoteAddress);
+ if (validator == null) {
+ throw new IllegalStateException("Validator is not initialized");
+ }
+ validator.checkKeyExists(authorization, remoteAddress); π Committable suggestion
Suggested change
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. @coderabbitai its mandatory thing 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. @ravishanigarapu, understood. If the (οΌοΈΏοΌ) βοΈ Learnings added
|
||||||||||||||||||||||||||||
break; | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
} catch (Exception e) { | ||||||||||||||||||||||||||||
|
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.
Add getter/setter methods for new LGD ID fields.
The new government LGD ID fields are missing their accessor methods, which are needed for proper encapsulation and data access.
π Committable suggestion
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.
@coderabbitai using constaructor not required
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.
@ravishanigarapu Understood. If you're using the constructor and don't require getter and setter methods for these fields, that's acceptable. Thanks for clarifying.