package com.axelor.dms.db.repo;

import java.util.Map;

import org.joda.time.LocalDateTime;

import com.axelor.db.JpaRepository;
import com.axelor.dms.db.DMSFile;

public class DMSFileRepository extends JpaRepository<DMSFile> {

	public DMSFileRepository() {
		super(DMSFile.class);
	}

	@Override
	public Map<String, Object> populate(Map<String, Object> json) {
		final Object id = json.get("id");
		if (id == null) {
			return json;
		}
		final DMSFile file = find((Long) id);
		if (file == null) {
			return json;
		}

		boolean isFile = file.getIsDirectory() != Boolean.TRUE;
		LocalDateTime dt = file.getUpdatedOn();
		if (dt == null) {
			dt = file.getCreatedOn();
		}

		json.put("typeIcon", isFile ? "fa fa-file" : "fa fa-folder");
		json.put("lastModified", dt);

		return json;
	}
}

@@ -26,16 +26,39 @@
 .repo;%0A%0A
+import java.util.List;%0A
 import j
@@ -303,16 +303,360 @@
 s);%0A%09%7D%0A%0A
+%09@Override%0A%09public void remove(DMSFile entity) %7B%0A%09%09// remove all children%0A%09%09if (entity.getIsDirectory() == Boolean.TRUE) %7B%0A%09%09%09final List%3CDMSFile%3E children = all().filter(%22self.parent.id = ?%22, entity.getId()).fetch();%0A%09%09%09for (DMSFile child : children) %7B%0A%09%09%09%09if (child != entity) %7B%0A%09%09%09%09%09remove(child);;%0A%09%09%09%09%7D%0A%09%09%09%7D%0A%09%09%7D%0A%09%09super.remove(entity);%0A%09%7D%0A%0A
 %09@Overri

Delete children when deleting dms folder