forked from IQSS/dataverse
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #2510: Endpoint to uningest multiple data files
- Loading branch information
Showing
4 changed files
with
143 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
dataverse-webapp/src/main/java/edu/harvard/iq/dataverse/api/dto/UningestRequestDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package edu.harvard.iq.dataverse.api.dto; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
public class UningestRequestDTO { | ||
|
||
private Set<Long> dataFileIds = new HashSet<>(); | ||
|
||
// -------------------- GETTERS -------------------- | ||
|
||
public Set<Long> getDataFileIds() { | ||
return dataFileIds; | ||
} | ||
|
||
// -------------------- LOGIC -------------------- | ||
|
||
public UningestRequestDTO addDataFileId(Long id) { | ||
this.dataFileIds.add(id); | ||
return this; | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
dataverse-webapp/src/main/java/edu/harvard/iq/dataverse/api/dto/UningestableItemDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package edu.harvard.iq.dataverse.api.dto; | ||
|
||
import edu.harvard.iq.dataverse.persistence.datafile.DataFile; | ||
import edu.harvard.iq.dataverse.util.FileUtil; | ||
import org.apache.commons.lang.StringUtils; | ||
|
||
import java.io.Serializable; | ||
|
||
public class UningestableItemDTO implements Serializable { | ||
private Long dataFileId; | ||
private String fileName; | ||
private String originalFormat; | ||
private String md5; | ||
private String unf; | ||
|
||
// -------------------- GETTERS -------------------- | ||
|
||
|
||
public Long getDataFileId() { | ||
return dataFileId; | ||
} | ||
|
||
public String getFileName() { | ||
return fileName; | ||
} | ||
|
||
public String getOriginalFormat() { | ||
return originalFormat; | ||
} | ||
|
||
public String getMd5() { | ||
return md5; | ||
} | ||
|
||
public String getUnf() { | ||
return unf; | ||
} | ||
|
||
// -------------------- LOGIC -------------------- | ||
|
||
public static UningestableItemDTO fromDatafile(DataFile file) { | ||
UningestableItemDTO item = new UningestableItemDTO(); | ||
item.dataFileId = file.getId(); | ||
item.fileName = file.getFileMetadata().getLabel(); | ||
item.originalFormat = extractAndFormatExtension(file); | ||
item.md5 = file.getChecksumType() == DataFile.ChecksumType.MD5 | ||
? file.getChecksumValue() : StringUtils.EMPTY; | ||
item.unf = file.getUnf(); | ||
return item; | ||
} | ||
|
||
// -------------------- PRIVATE -------------------- | ||
|
||
public static String extractAndFormatExtension(DataFile file) { | ||
String extension = FileUtil.generateOriginalExtension(file.isTabularData() | ||
? file.getDataTable().getOriginalFileFormat() | ||
: file.getContentType()); | ||
return extension.replaceFirst("\\.", StringUtils.EMPTY).toUpperCase(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters