-
Notifications
You must be signed in to change notification settings - Fork 45
AMM-1002 : Preprod- Unable to separate a Customization field for #134
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
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 | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -16,14 +16,15 @@ public interface SectionAndFieldsMappingRepo extends CrudRepository<SectionAndFi | |||||||||
// List<SectionAndFieldsMapping> findBySectionIdAndSectionNameAndServiceProviderId( | ||||||||||
// @Param("sectionId") Integer sectionId, @Param("serviceProviderId") Integer serviceProviderId); | ||||||||||
|
||||||||||
@Query("SELECT sfm FROM SectionAndFieldsMapping sfm WHERE sfm.sectionId = :sectionId AND (sfm.serviceProviderId = :serviceProviderId OR sfm.serviceProviderId= 0)") | ||||||||||
|
||||||||||
@Query("SELECT sfm FROM SectionAndFieldsMapping sfm WHERE sfm.fieldName = :fieldName AND (sfm.serviceProviderId = :serviceProviderId OR sfm.serviceProviderId = 0) AND (sfm.projectId = :projectId OR sfm.projectId = 0)") | ||||||||||
List<SectionAndFieldsMapping> findSectionIdAndSectionNameAndServiceProviderId( | ||||||||||
@Param("sectionId") Integer sectionId, @Param("serviceProviderId") Integer serviceProviderId); | ||||||||||
@Param("sectionId") Integer sectionId, @Param("serviceProviderId") Integer serviceProviderId, @Param("projectId") Integer projectId); | ||||||||||
|
||||||||||
@Query("SELECT sfm FROM SectionAndFieldsMapping sfm WHERE sfm.id = :id") | ||||||||||
SectionAndFieldsMapping getById(@Param("id") Integer id); | ||||||||||
|
||||||||||
@Query("SELECT sfm FROM SectionAndFieldsMapping sfm WHERE sfm.fieldName = :fieldName and sfm.serviceProviderId = :serviceProviderId") | ||||||||||
List<SectionAndFieldsMapping> getByFieldName(@Param("fieldName") String fieldName,@Param("serviceProviderId") Integer serviceProviderId); | ||||||||||
@Query("SELECT sfm FROM SectionAndFieldsMapping sfm WHERE sfm.fieldName = :fieldName and sfm.serviceProviderId = :serviceProviderId and sfm.projectId = :projectId") | ||||||||||
List<SectionAndFieldsMapping> getByFieldName(@Param("fieldName") String fieldName,@Param("serviceProviderId") Integer serviceProviderId,@Param("projectId") Integer projectId); | ||||||||||
Comment on lines
+27
to
+28
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. Inconsistent fallback behavior between queries. While the first query allows fallback to global settings (projectId=0), this query enforces strict matching. This inconsistency could lead to unexpected behavior where some queries find global settings and others don't. Consider applying the same fallback pattern: -@Query("SELECT sfm FROM SectionAndFieldsMapping sfm WHERE sfm.fieldName = :fieldName and sfm.serviceProviderId = :serviceProviderId and sfm.projectId = :projectId")
+@Query("SELECT sfm FROM SectionAndFieldsMapping sfm WHERE sfm.fieldName = :fieldName AND (sfm.serviceProviderId = :serviceProviderId OR sfm.serviceProviderId = 0) AND (sfm.projectId = :projectId OR sfm.projectId = 0)") π Committable suggestion
Suggested change
|
||||||||||
|
||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -180,14 +180,15 @@ public String saveSectionAndFields(SectionFieldsMappingDTO sectionFieldsMappingD | |
try { | ||
|
||
if (sectionFieldsMappingDTO != null && sectionFieldsMappingDTO.getFields() != null | ||
&& sectionFieldsMappingDTO.getFields().size() > 0) { | ||
&& sectionFieldsMappingDTO.getFields().size() > 0 && sectionFieldsMappingDTO.getProjectId() != null) { | ||
SectionAndFieldsMapping sectionAndFieldsMapping; | ||
List<SectionAndFieldsMapping> sectionAndFieldsMappingList = new ArrayList<>(); | ||
for (SectionAndFieldsMapping sectionFieldsMapping : sectionFieldsMappingDTO.getFields()) { | ||
List<SectionAndFieldsMapping> byFieldName = sectionAndFieldsMappingRepo | ||
.getByFieldName(sectionFieldsMapping.getFieldName(),sectionFieldsMapping.getServiceProviderId()); | ||
.getByFieldName(sectionFieldsMapping.getFieldName(),sectionFieldsMapping.getServiceProviderId(),sectionFieldsMappingDTO.getProjectId()); | ||
sectionAndFieldsMapping = new SectionAndFieldsMapping(); | ||
sectionAndFieldsMapping.setSectionId(sectionFieldsMappingDTO.getSectionId()); | ||
sectionAndFieldsMapping.setProjectId(sectionFieldsMappingDTO.getProjectId()); | ||
sectionAndFieldsMapping.setCreatedBy(sectionFieldsMappingDTO.getCreatedBy()); | ||
sectionAndFieldsMapping.setAllowMax(sectionFieldsMapping.getAllowMax()); | ||
sectionAndFieldsMapping.setFieldName(sectionFieldsMapping.getFieldName()); | ||
|
@@ -284,16 +285,19 @@ public String fetchMappedFields(String request, String Authorization) throws Exc | |
SectionAndFieldsMapping sectionAndFieldsMapping = InputMapper.gson().fromJson(request, | ||
SectionAndFieldsMapping.class); | ||
try { | ||
if(sectionAndFieldsMapping.getProjectId() == null) { | ||
throw new IllegalArgumentException("ProjectId is required"); | ||
} | ||
List<SectionAndFieldsMapping> resultSet = sectionAndFieldsMappingRepo | ||
.findSectionIdAndSectionNameAndServiceProviderId(sectionAndFieldsMapping.getSectionId(), | ||
sectionAndFieldsMapping.getServiceProviderId()); | ||
sectionAndFieldsMapping.getServiceProviderId(), sectionAndFieldsMapping.getProjectId()); | ||
|
||
String sectionName = sectionMasterCustomizationRepo.findSectionName(sectionAndFieldsMapping.getSectionId()); | ||
Map<String, Object> responseMap = new HashMap<>(); | ||
responseMap.put("sectionId", sectionAndFieldsMapping.getSectionId()); | ||
responseMap.put("sectionName", sectionName); | ||
responseMap.put("serviceProviderId", sectionAndFieldsMapping.getServiceProviderId()); | ||
|
||
responseMap.put("projectId", sectionAndFieldsMapping.getProjectId()); | ||
Comment on lines
+293
to
+300
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 projectId While the changes correctly include projectId in the query and response, consider adding a null check for projectId to prevent potential NullPointerException. - .findSectionIdAndSectionNameAndServiceProviderId(sectionAndFieldsMapping.getSectionId(),
- sectionAndFieldsMapping.getServiceProviderId(), sectionAndFieldsMapping.getProjectId());
+ if (sectionAndFieldsMapping.getProjectId() == null) {
+ throw new IllegalArgumentException("ProjectId is required");
+ }
+ .findSectionIdAndSectionNameAndServiceProviderId(sectionAndFieldsMapping.getSectionId(),
+ sectionAndFieldsMapping.getServiceProviderId(), sectionAndFieldsMapping.getProjectId());
|
||
List<Map<String, Object>> fieldsList = new ArrayList<>(); | ||
for (SectionAndFieldsMapping field : resultSet) { | ||
Map<String, Object> fieldMap = new HashMap<>(); | ||
|
@@ -372,6 +376,11 @@ public String updateSectionAndFields(String request, String Authorization) throw | |
if (sectionAndFieldsMapping.getId() != null) { | ||
SectionAndFieldsMapping response = sectionAndFieldsMappingRepo.getById(sectionAndFieldsMapping.getId()); | ||
if (response != null) { | ||
if(sectionAndFieldsMapping.getProjectId() != null) { | ||
ProjectCustomization project = projectCustomizationRepo.findById(sectionAndFieldsMapping.getProjectId()) | ||
.orElseThrow(() -> new IllegalArgumentException("Invalid projectId")); | ||
response.setProjectId(sectionAndFieldsMapping.getProjectId()); | ||
} | ||
if (sectionAndFieldsMapping.getFieldName() != null) | ||
response.setFieldName(sectionAndFieldsMapping.getFieldName()); | ||
if (sectionAndFieldsMapping.getIsRequired() != null) | ||
|
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.
Method name doesn't match its implementation.
The method name suggests it finds by
sectionId
andsectionName
, but the query filters byfieldName
. This mismatch could lead to confusion. Consider renaming the method to better reflect its functionality.