Skip to content

Commit 17007e4

Browse files
authored
Merge pull request #239 from srishtigrp78/feature/version/upgrade
AMM-997 | Retrieval of multiple files from a subcategory
2 parents a0a362f + 7be3796 commit 17007e4

4 files changed

Lines changed: 47 additions & 20 deletions

File tree

src/main/java/com/iemr/common/data/kmfilemanager/KMFileManager.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ public class KMFileManager {
110110
@Transient
111111
@Expose
112112
private Integer categoryID;
113-
@Transient
113+
114+
@Column(name = "SubCategoryID")
114115
@Expose
115116
private Integer subCategoryID;
116117
@Transient

src/main/java/com/iemr/common/repository/kmfilemanager/KMFileManagerRepository.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,5 +74,9 @@ ArrayList<KMFileManager> getKMFileLists(@Param("providerServiceMapID") Integer p
7474
@Query("select kmFileManager.fileName, kmFileManager.fileExtension from KMFileManager kmFileManager "
7575
+ "where kmFileManager.fileUID = :fileUID")
7676
List<Object[]> getFileNameByUID(@Param("fileUID") String fileUID);
77+
78+
79+
@Query("SELECT km FROM KMFileManager km WHERE km.subCategoryID = :subCategoryID AND km.deleted = false")
80+
List<KMFileManager> getFilesBySubCategoryID(@Param("subCategoryID") Integer subCategoryID);
7781

7882
}

src/main/java/com/iemr/common/service/kmfilemanager/KMFileManagerServiceImpl.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ public String addKMFile(String request) throws IOException, NoSuchAlgorithmExcep
125125
return kmFileManagers.toString();
126126
}
127127

128+
128129
private ArrayList<KMFileManager> addKMFile(Iterable<KMFileManager> kmFileManagers)
129130
throws IOException, NoSuchAlgorithmException {
130131
ArrayList<KMFileManager> savedFileManagers = new ArrayList<KMFileManager>();
@@ -175,6 +176,9 @@ private ArrayList<KMFileManager> addKMFile(Iterable<KMFileManager> kmFileManager
175176
if (uuid != null) {
176177
kmFileManager.setKmUploadStatus(KM_UPLOADSTATUS_COMPLETED);
177178
kmFileManager.setFileUID(uuid);
179+
180+
kmFileManager.setSubCategoryID(kmFileManager.getSubCategoryID());
181+
178182
savedFileManagers.add(kmFileManagerRepository.save(kmFileManager));
179183
if (kmFileManager.getSubCategoryID() != null) {
180184
updateSubcategoryFilePath(kmFileManager);
@@ -197,6 +201,7 @@ private ArrayList<KMFileManager> addKMFile(Iterable<KMFileManager> kmFileManager
197201
return savedFileManagers;
198202
}
199203

204+
200205
private void updateSubcategoryFilePath(KMFileManager kmFileManager) {
201206
subCategoryRepository.updateFilePath(kmFileManager.getSubCategoryID(), kmFileManager.getFileUID());
202207
}

src/main/java/com/iemr/common/service/services/CommonServiceImpl.java

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
import com.iemr.common.utils.exception.IEMRException;
5858
import com.iemr.common.utils.mapper.InputMapper;
5959
import com.iemr.common.data.common.DocFileManager;
60+
import com.iemr.common.data.kmfilemanager.KMFileManager;
6061

6162
@Service
6263
@PropertySource("classpath:/application.properties")
@@ -133,29 +134,45 @@ public Iterable<CategoryDetails> getCategories() {
133134
return categoriesList;
134135
}
135136

137+
138+
//newChange
136139
@Override
137140
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;
157173
}
158174

175+
159176
private String getFilePath(String fileUID)
160177
{
161178
String fileUIDAsURI = null;

0 commit comments

Comments
 (0)