Skip to content
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

5577 - need to filter tools by mimetype on file page #5578

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/main/java/edu/harvard/iq/dataverse/FilePage.java
Expand Up @@ -188,12 +188,18 @@ public String init() {

this.guestbookResponse = this.guestbookResponseService.initGuestbookResponseForFragment(fileMetadata, session);

// this.getFileDownloadHelper().setGuestbookResponse(guestbookResponse);

// Find external tools based on their type, the file content type, and whether
// ingest has created a derived file for that type
// Currently, tabular data files are the only type of derived file created, so
// isTabularData() works - true for tabular types where a .tab file has been
// created and false for other mimetypes
String contentType = file.getContentType();
//For tabular data, indicate successful ingest by returning a contentType for the derived .tab file
if (file.isTabularData()) {
configureTools = externalToolService.findByType(ExternalTool.Type.CONFIGURE);
exploreTools = externalToolService.findByType(ExternalTool.Type.EXPLORE);
contentType=DataFileServiceBean.MIME_TYPE_TSV_ALT;
}
configureTools = externalToolService.findByType(ExternalTool.Type.CONFIGURE, contentType);
exploreTools = externalToolService.findByType(ExternalTool.Type.EXPLORE, contentType);

} else {

Expand Down
Expand Up @@ -48,12 +48,25 @@ public List<ExternalTool> findAll() {
* @return A list of tools or an empty list.
*/
public List<ExternalTool> findByType(Type type) {
return findByType(type, null);
}

/**
* @param type
* @param contentType - mimetype
* @return A list of tools or an empty list.
*/
public List<ExternalTool> findByType(Type type, String contentType) {

List<ExternalTool> externalTools = new ArrayList<>();

//If contentType==null, get all tools of the given ExternalTool.Type
TypedQuery<ExternalTool> typedQuery = em.createQuery("SELECT OBJECT(o) FROM ExternalTool AS o WHERE o.type = :type", ExternalTool.class);
TypedQuery<ExternalTool> typedQuery = contentType != null ? em.createQuery("SELECT OBJECT(o) FROM ExternalTool AS o WHERE o.type = :type AND o.contentType = :contentType", ExternalTool.class):
em.createQuery("SELECT OBJECT(o) FROM ExternalTool AS o WHERE o.type = :type", ExternalTool.class);
typedQuery.setParameter("type", type);
if(contentType!=null) {
typedQuery.setParameter("contentType", contentType);
}
List<ExternalTool> toolsFromQuery = typedQuery.getResultList();
if (toolsFromQuery != null) {
externalTools = toolsFromQuery;
Expand Down Expand Up @@ -165,4 +178,6 @@ private static String getOptionalTopLevelField(JsonObject jsonObject, String key
}




}