Skip to content

Commit

Permalink
Code modifications per code review. (#4865)
Browse files Browse the repository at this point in the history
  • Loading branch information
landreev committed Aug 3, 2018
1 parent 29a257f commit 5c967f0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 29 deletions.
24 changes: 6 additions & 18 deletions src/main/java/edu/harvard/iq/dataverse/api/Files.java
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,9 @@ public Response uningestDatafile(@PathParam("id") String id) {
// for tabular ingest. It can be used on non-tabular datafiles; to try to
// ingest a file that has previously failed ingest, or to ingest a file of a
// type for which ingest was not previously supported.
// It will also be possible to *force* reingest of a datafile that's already
// ingested as Tabular data; for example, to address a bug that has been
// found in an ingest plugin.
// We are considering making it possible, in the future, to reingest
// a datafile that's already ingested as Tabular; for example, to address a
// bug that has been found in an ingest plugin.

@Path("{id}/reingest")
@POST
Expand All @@ -359,17 +359,9 @@ public Response reingest(@PathParam("id") String id) {
try {
dataFile = findDataFileOrDie(id);
} catch (WrappedResponse ex) {
dataFile = null;
}

if (dataFile == null) {
return error(Response.Status.NOT_FOUND, "File not found for given id.");
}

if (dataFile.isTabularData()) {
return error(Response.Status.BAD_REQUEST, "Datafile already ingested as Tabular (as of now, this API only works on uningested datafiles).");
}

Dataset dataset = dataFile.getOwner();

if (dataset == null) {
Expand All @@ -387,13 +379,9 @@ public Response reingest(@PathParam("id") String id) {
}

dataFile.SetIngestScheduled();

IngestRequest ingestRequest = dataFile.getIngestRequest();

if (ingestRequest == null) {
ingestRequest = new IngestRequest();
ingestRequest.setDataFile(dataFile);
dataFile.setIngestRequest(ingestRequest);

if (dataFile.getIngestRequest() == null) {
dataFile.setIngestRequest(new IngestRequest(dataFile));
}

dataFile.getIngestRequest().setForceTypeCheck(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ public void setId(Long id) {

private Boolean forceTypeCheck;

public IngestRequest() {
}

public IngestRequest(DataFile dataFile) {
this.dataFile = dataFile;
}

public DataFile getDataFile() {
return dataFile;
}
Expand Down
12 changes: 1 addition & 11 deletions src/main/java/edu/harvard/iq/dataverse/util/FileUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,6 @@ public class FileUtil implements java.io.Serializable {
private static final Logger logger = Logger.getLogger(FileUtil.class.getCanonicalName());

private static final String[] TABULAR_DATA_FORMAT_SET = {"POR", "SAV", "DTA", "RDA"};
// The list of formats for which we need to re-test, if we want to attempt
// to ingest the file again:
// Example: We have added support for Stata-13+; the new ingest plugin is called
// when the file type is detected as "application/x-stata-1[345]". But the
// previously uploaded, but not ingested stata files are in the database
// typed as "application/x-stata". So we want to run the new-and-improved
// DTA check that will re-identify the specific DTA flavor.
// If similar cases are introduced in the future, the affected formats will
// need to be added to the list.
private static final String[] TABULAR_DATA_FORMATS_RETEST = {"DTA"};

private static Map<String, String> STATISTICAL_FILE_EXTENSION = new HashMap<String, String>();

Expand Down Expand Up @@ -291,7 +281,7 @@ private static String determineContentType(File fileObject) {
}

public static String retestIngestableFileType(File file, String fileType) {
IngestableDataChecker tabChecker = new IngestableDataChecker(TABULAR_DATA_FORMATS_RETEST);
IngestableDataChecker tabChecker = new IngestableDataChecker(TABULAR_DATA_FORMAT_SET);
String newType = tabChecker.detectTabularDataFormat(file);

return newType != null ? newType : fileType;
Expand Down

0 comments on commit 5c967f0

Please sign in to comment.