|
57 | 57 | import com.iemr.common.utils.exception.IEMRException; |
58 | 58 | import com.iemr.common.utils.mapper.InputMapper; |
59 | 59 | import com.iemr.common.data.common.DocFileManager; |
| 60 | +import com.iemr.common.data.kmfilemanager.KMFileManager; |
60 | 61 |
|
61 | 62 | @Service |
62 | 63 | @PropertySource("classpath:/application.properties") |
@@ -133,29 +134,45 @@ public Iterable<CategoryDetails> getCategories() { |
133 | 134 | return categoriesList; |
134 | 135 | } |
135 | 136 |
|
| 137 | + |
| 138 | + //newChange |
136 | 139 | @Override |
137 | 140 | public Iterable<SubCategoryDetails> getSubCategories(String request) throws IEMRException, JsonMappingException, JsonProcessingException { |
138 | | - ObjectMapper objectMapper = new ObjectMapper(); |
139 | | - SubCategoryDetails subCategoryDetails = objectMapper.readValue(request, SubCategoryDetails.class); |
140 | | - List<SubCategoryDetails> subCategoriesList = new ArrayList<SubCategoryDetails>(); |
141 | | - ArrayList<Object[]> lists = subCategoryRepository.findByCategoryID(subCategoryDetails.getCategoryID()); |
142 | | - for (Object[] objects : lists) { |
143 | | - if (objects != null && objects.length > 1) { |
144 | | - String SubCatFilePath = (String) objects[2]; |
145 | | - String fileUIDAsURI = null; |
146 | | - String fileNameWithExtension = null; |
147 | | - if(SubCatFilePath!=null) { |
148 | | - fileUIDAsURI=getFilePath(SubCatFilePath); |
149 | | - List<Object[]> fileNameList = kmFileManagerRepository.getFileNameByUID(SubCatFilePath); |
150 | | - Object[] fileobjects = fileNameList.get(0); |
151 | | - fileNameWithExtension= (String)fileobjects[0]+ (String) fileobjects[1]; |
152 | | - } |
153 | | - subCategoriesList.add(new SubCategoryDetails((Integer) objects[0], (String) objects[1], SubCatFilePath, fileUIDAsURI, fileNameWithExtension)); |
154 | | - } |
155 | | - } |
156 | | - return subCategoriesList; |
| 141 | + ObjectMapper objectMapper = new ObjectMapper(); |
| 142 | + SubCategoryDetails subCategoryDetails = objectMapper.readValue(request, SubCategoryDetails.class); |
| 143 | + List<SubCategoryDetails> subCategoriesList = new ArrayList<>(); |
| 144 | + ArrayList<Object[]> lists = subCategoryRepository.findByCategoryID(subCategoryDetails.getCategoryID()); |
| 145 | + |
| 146 | + for (Object[] objects : lists) { |
| 147 | + if (objects != null && objects.length > 1) { |
| 148 | + Integer subCatId = (Integer) objects[0]; |
| 149 | + String subCatName = (String) objects[1]; |
| 150 | + |
| 151 | + // Fetch all files under this subcategory from KMFileManager |
| 152 | + List<KMFileManager> files = kmFileManagerRepository.getFilesBySubCategoryID(subCatId); |
| 153 | + ArrayList<KMFileManager> fileList = new ArrayList<>(files); |
| 154 | + |
| 155 | + String fileURL = null; |
| 156 | + String fileNameWithExtension = null; |
| 157 | + |
| 158 | + if (!fileList.isEmpty()) { |
| 159 | + KMFileManager firstFile = fileList.get(0); // Just for representative file URL and name |
| 160 | + fileURL = getFilePath(firstFile.getFileUID()); |
| 161 | + fileNameWithExtension = firstFile.getFileName() + firstFile.getFileExtension(); |
| 162 | + } |
| 163 | + |
| 164 | + SubCategoryDetails subCategory = new SubCategoryDetails(subCatId, subCatName); |
| 165 | + subCategory.setFileManger(fileList); // Attach all files here |
| 166 | + subCategory.setFileURL(fileURL); // Representative file URL |
| 167 | + subCategory.setFileNameWithExtension(fileNameWithExtension); // Representative file name+ext |
| 168 | + |
| 169 | + subCategoriesList.add(subCategory); |
| 170 | + } |
| 171 | + } |
| 172 | + return subCategoriesList; |
157 | 173 | } |
158 | 174 |
|
| 175 | + |
159 | 176 | private String getFilePath(String fileUID) |
160 | 177 | { |
161 | 178 | String fileUIDAsURI = null; |
|
0 commit comments