if(fileToPublish.equals(""))
return JobStatus.MISSING_FILE_TO_PUBLISH;
File publishFile = new File(fileToPublish);
if(!publishFile.exists() || publishFile.isDirectory()) {
JobStatus errorStatus = JobStatus.FILE_TO_PUBLISH_DOESNT_EXIST;
errorStatus.setMessage(fileToPublish + ": File to publish does not exist");
return errorStatus;
}
String fileExtension = Utils.getFileExtension(fileToPublish);
if(!allowedFileToPublishExtensions.contains(fileExtension))
return JobStatus.FILE_TO_PUBLISH_INVALID_FORMAT;
Dataset schema;
try {
schema = DatasetUtils.getDatasetInfo(connectionInfo.getUrl(), job.getDatasetID());
if(job.getPublishViaDi2Http() || job.getPublishViaFTP()) {
ControlFile control = job.getControlFile();
FileTypeControl fileControl = null;
switch (fileExtension) {
case "csv": fileControl = control.csv; break;
case "tsv": fileControl = control.tsv; break;
}
JobStatus actionOkay = checkAction(control.action, job, schema);
if (actionOkay.isError())
return actionOkay;
if (fileControl == null && !control.action.equalsIgnoreCase(PublishMethod.delete.name())) {
JobStatus noFileTypeContent = JobStatus.PUBLISH_ERROR;
noFileTypeContent.setMessage("The control file for '" + publishFile.getName() +
"' requires that the '" + fileExtension + "' option be filled in");
return noFileTypeContent;
}
String[] headers = getHeaders(fileControl, publishFile);
if (headers == null) {
JobStatus noHeaders = JobStatus.PUBLISH_ERROR;
noHeaders.setMessage("Headers must be specified in one of " + publishFile.getName() + " or the control file using 'columns'");
return noHeaders;
}
Set<String> synthetics = fileControl.syntheticLocations.keySet();
JobStatus csvDatasetAgreement = checkColumnAgreement(schema, headers, synthetics, publishFile.getName());
if (csvDatasetAgreement.isError())
return csvDatasetAgreement;
JobStatus controlHeaderAgreement = checkControlAgreement(fileControl, schema, headers, publishFile.getName());
if (controlHeaderAgreement.isError())
return controlHeaderAgreement;
JobStatus controlSensibility = validateControlFile(fileControl, connectionInfo.getUrl());
if (controlSensibility.isError())
return controlSensibility;
}
} catch (Exception e) {
// Not going to fail jobs on the validation check
}