Skip to content

Commit 95be768

Browse files
SR20290919SR20290919
authored andcommitted
linking of subcategory to multiple files
1 parent 629c28b commit 95be768

4 files changed

Lines changed: 143 additions & 20 deletions

File tree

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,11 @@ public class KMFileManager {
110110
@Transient
111111
@Expose
112112
private Integer categoryID;
113-
@Transient
113+
// @Transient
114+
// @Expose
115+
// private Integer subCategoryID;
116+
117+
@Column(name = "SubCategoryID") // 🔴 DB-mapped field to associate files with a subcategory
114118
@Expose
115119
private Integer subCategoryID;
116120
@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+
//newChange
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: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,78 @@ public String addKMFile(String request) throws IOException, NoSuchAlgorithmExcep
125125
return kmFileManagers.toString();
126126
}
127127

128+
// private ArrayList<KMFileManager> addKMFile(Iterable<KMFileManager> kmFileManagers)
129+
// throws IOException, NoSuchAlgorithmException {
130+
// ArrayList<KMFileManager> savedFileManagers = new ArrayList<KMFileManager>();
131+
// FileOutputStream newFile = null;
132+
// FileInputStream fis = null;
133+
// try
134+
// {
135+
// for (KMFileManager kmFileManager : kmFileManagers) {
136+
// if (kmFileManager.getFileName() != null && kmFileManager.getProviderServiceMapID() != null
137+
// && kmFileManager.getFileContent() != null) {
138+
// kmFileManager.setFileName(kmFileManager.getFileName().replace("`", "").replace("'", "").replace("$", "")
139+
// .replace("\\", "").replace("/", "").replace("~", "").replace("`", "").replace("!", "")
140+
// .replace("@", "").replace("#", "").replace("$", "").replace("%", "").replace("^", "")
141+
// .replace("&", "").replace("*", "").replace("(", "").replace(")", "").replace("{", "")
142+
// .replace("}", "").replace("[", "").replace("]", "").replace("|", "").replace("\\", "")
143+
// .replace(":", "").replace(";", "").replace("-", "").replace("_", "").replace("+", "")
144+
// .replace("=", "").replace("\"", "").replace("'", ""));
145+
// String tempFilePath = ConfigProperties.getPropertyByName("tempFilePath");
146+
// newFile = new FileOutputStream(tempFilePath + "/" + kmFileManager.getFileName());
147+
// newFile.write(Base64.getDecoder().decode(kmFileManager.getFileContent()));
148+
// newFile.flush();
149+
// newFile.close();
150+
// fis = new FileInputStream(tempFilePath + "/" + kmFileManager.getFileName());
151+
// String checksum = DigestUtils.md5DigestAsHex(fis);
152+
// fis.close();
153+
// logger.info("File is " + kmFileManager.getFileName());
154+
// logger.info("File size is " + new File(tempFilePath + "/" + kmFileManager.getFileName()).length());
155+
// logger.info("File checksum is " + checksum);
156+
// logger.info("File checksum length is " + checksum.length());
157+
// kmFileManager.setFileCheckSum(checksum);
158+
// kmFileManager.setKmUploadStatus(KM_UPLOADSTATUS_PENDING);
159+
// String version = getFileVersion(kmFileManager);
160+
// kmFileManager.setVersionNo(version);
161+
// String documentPath = kmFileManager.getProviderServiceMapID() + "/";
162+
// if (kmFileManager.getCategoryID() != null) {
163+
// documentPath += kmFileManager.getCategoryID() + "/";
164+
// }
165+
// if (kmFileManager.getSubCategoryID() != null) {
166+
// documentPath += kmFileManager.getSubCategoryID() + "/";
167+
// }
168+
// if (kmFileManager.getVanID() != null)
169+
// documentPath += kmFileManager.getVanID() + "/";
170+
//
171+
// documentPath += version + "/";
172+
// documentPath += kmFileManager.getFileName();
173+
// kmFileManager.setKmUploadStatus(KM_UPLOADSTATUS_STARTED);
174+
// String uuid = kmService.createDocument(documentPath, tempFilePath + "/" + kmFileManager.getFileName());
175+
// if (uuid != null) {
176+
// kmFileManager.setKmUploadStatus(KM_UPLOADSTATUS_COMPLETED);
177+
// kmFileManager.setFileUID(uuid);
178+
// savedFileManagers.add(kmFileManagerRepository.save(kmFileManager));
179+
// if (kmFileManager.getSubCategoryID() != null) {
180+
// updateSubcategoryFilePath(kmFileManager);
181+
// }
182+
// }
183+
// }
184+
// }
185+
// }
186+
// catch(Exception e)
187+
// {
188+
// logger.error("error " + e.getMessage());
189+
// }
190+
// finally
191+
// {
192+
// if(newFile !=null)
193+
// newFile.close();
194+
// if(fis !=null)
195+
// fis.close();
196+
// }
197+
// return savedFileManagers;
198+
// }
199+
128200
private ArrayList<KMFileManager> addKMFile(Iterable<KMFileManager> kmFileManagers)
129201
throws IOException, NoSuchAlgorithmException {
130202
ArrayList<KMFileManager> savedFileManagers = new ArrayList<KMFileManager>();
@@ -175,6 +247,9 @@ private ArrayList<KMFileManager> addKMFile(Iterable<KMFileManager> kmFileManager
175247
if (uuid != null) {
176248
kmFileManager.setKmUploadStatus(KM_UPLOADSTATUS_COMPLETED);
177249
kmFileManager.setFileUID(uuid);
250+
251+
kmFileManager.setSubCategoryID(kmFileManager.getSubCategoryID());
252+
178253
savedFileManagers.add(kmFileManagerRepository.save(kmFileManager));
179254
if (kmFileManager.getSubCategoryID() != null) {
180255
updateSubcategoryFilePath(kmFileManager);
@@ -197,6 +272,7 @@ private ArrayList<KMFileManager> addKMFile(Iterable<KMFileManager> kmFileManager
197272
return savedFileManagers;
198273
}
199274

275+
200276
private void updateSubcategoryFilePath(KMFileManager kmFileManager) {
201277
subCategoryRepository.updateFilePath(kmFileManager.getSubCategoryID(), kmFileManager.getFileUID());
202278
}

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

Lines changed: 58 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,67 @@ public Iterable<CategoryDetails> getCategories() {
133134
return categoriesList;
134135
}
135136

137+
// @Override
138+
// public Iterable<SubCategoryDetails> getSubCategories(String request) throws IEMRException, JsonMappingException, JsonProcessingException {
139+
// ObjectMapper objectMapper = new ObjectMapper();
140+
// SubCategoryDetails subCategoryDetails = objectMapper.readValue(request, SubCategoryDetails.class);
141+
// List<SubCategoryDetails> subCategoriesList = new ArrayList<SubCategoryDetails>();
142+
// ArrayList<Object[]> lists = subCategoryRepository.findByCategoryID(subCategoryDetails.getCategoryID());
143+
// for (Object[] objects : lists) {
144+
// if (objects != null && objects.length > 1) {
145+
// String SubCatFilePath = (String) objects[2];
146+
// String fileUIDAsURI = null;
147+
// String fileNameWithExtension = null;
148+
// if(SubCatFilePath!=null) {
149+
// fileUIDAsURI=getFilePath(SubCatFilePath);
150+
// List<Object[]> fileNameList = kmFileManagerRepository.getFileNameByUID(SubCatFilePath);
151+
// Object[] fileobjects = fileNameList.get(0);
152+
// fileNameWithExtension= (String)fileobjects[0]+ (String) fileobjects[1];
153+
// }
154+
// subCategoriesList.add(new SubCategoryDetails((Integer) objects[0], (String) objects[1], SubCatFilePath, fileUIDAsURI, fileNameWithExtension));
155+
// }
156+
// }
157+
// return subCategoriesList;
158+
// }
159+
160+
//newChange
136161
@Override
137162
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;
163+
ObjectMapper objectMapper = new ObjectMapper();
164+
SubCategoryDetails subCategoryDetails = objectMapper.readValue(request, SubCategoryDetails.class);
165+
List<SubCategoryDetails> subCategoriesList = new ArrayList<>();
166+
ArrayList<Object[]> lists = subCategoryRepository.findByCategoryID(subCategoryDetails.getCategoryID());
167+
168+
for (Object[] objects : lists) {
169+
if (objects != null && objects.length > 1) {
170+
Integer subCatId = (Integer) objects[0];
171+
String subCatName = (String) objects[1];
172+
173+
// Fetch all files under this subcategory from KMFileManager
174+
List<KMFileManager> files = kmFileManagerRepository.getFilesBySubCategoryID(subCatId);
175+
ArrayList<KMFileManager> fileList = new ArrayList<>(files);
176+
177+
String fileURL = null;
178+
String fileNameWithExtension = null;
179+
180+
if (!fileList.isEmpty()) {
181+
KMFileManager firstFile = fileList.get(0); // Just for representative file URL and name
182+
fileURL = getFilePath(firstFile.getFileUID());
183+
fileNameWithExtension = firstFile.getFileName() + firstFile.getFileExtension();
184+
}
185+
186+
SubCategoryDetails subCategory = new SubCategoryDetails(subCatId, subCatName);
187+
subCategory.setFileManger(fileList); // Attach all files here
188+
subCategory.setFileURL(fileURL); // Representative file URL
189+
subCategory.setFileNameWithExtension(fileNameWithExtension); // Representative file name+ext
190+
191+
subCategoriesList.add(subCategory);
192+
}
193+
}
194+
return subCategoriesList;
157195
}
158196

197+
159198
private String getFilePath(String fileUID)
160199
{
161200
String fileUIDAsURI = null;

0 commit comments

Comments
 (0)