Skip to content

Commit

Permalink
Fixed a minor issue in recovery of failed workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
datasetutil committed Jan 13, 2015
1 parent b7570fc commit f6ba387
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions src/main/java/com/sforce/dataset/loader/DatasetLoader.java
Expand Up @@ -259,24 +259,30 @@ public static boolean uploadDataset(String inputFileString,
altSchema = ExternalFileSchema.getSchemaWithNewDateParts(schema);

String hdrId = getLastIncompleteFileHdr(partnerConnection, datasetAlias, logger);
if(hdrId==null)
if(hdrId!=null)
{
hdrId = insertFileHdr(partnerConnection, datasetAlias,datasetFolder, altSchema.toBytes(), uploadFormat, Operation, logger);
}else
File lastgzbinFile = new File(datasetArchiveDir, hdrId + "." + FilenameUtils.getBaseName(inputFile.getName()) + ".gz");
if(lastgzbinFile.exists())
{
logger.println("Record {"+hdrId+"} is being reused from InsightsExternalData");
updateHdrJson = true;
}
}

if(hdrId==null || hdrId.isEmpty())
{
logger.println("Record {"+hdrId+"} is being reused from InsightsExternalData");
updateHdrJson = true;
hdrId = insertFileHdr(partnerConnection, datasetAlias,datasetFolder, altSchema.toBytes(), uploadFormat, Operation, logger);
}

if(hdrId ==null || hdrId.isEmpty())
{
logger.println("Error: failed to insert header row into the saleforce SObject");
return false;
}

inputFile = CsvExternalSort.sortFile(inputFile, inputFileCharset, false, 1, schema);

//Create the Bin file
// File binFile = new File(csvFile.getParent(), datasetName + ".bin");
//Create the Bin file
//File binFile = new File(csvFile.getParent(), datasetName + ".bin");
File gzbinFile = inputFile;
if(!FilenameUtils.getExtension(inputFile.getName()).equalsIgnoreCase("csv"))
{
Expand Down Expand Up @@ -1458,7 +1464,7 @@ private static boolean checkAPIAccess(PartnerConnection partnerConnection, Print
private static String getLastIncompleteFileHdr(PartnerConnection partnerConnection, String datasetAlias, PrintStream logger) throws Exception
{
String rowId = null;
String soqlQuery = String.format("SELECT Id FROM InsightsExternalData WHERE EdgemartAlias = '%s' AND Status = 'New' AND Action = 'None' ORDER BY CreatedDate DESC LIMIT 1",datasetAlias);
String soqlQuery = String.format("SELECT Id,Status,Action FROM InsightsExternalData WHERE EdgemartAlias = '%s' ORDER BY CreatedDate DESC LIMIT 1",datasetAlias);
partnerConnection.setQueryOptions(2000);
QueryResult qr = partnerConnection.query(soqlQuery);
int rowsSoFar = 0;
Expand All @@ -1470,12 +1476,18 @@ private static String getLastIncompleteFileHdr(PartnerConnection partnerConnecti
SObject[] records = qr.getRecords();
for (int i = 0; i < records.length; ++i)
{
if(rowsSoFar==0) //only get the first one
{
String fieldName = "Id";
Object value = SfdcUtils.getFieldValueFromQueryResult(fieldName,records[i]);
if (value != null) {
if(rowsSoFar==0) //only get the first one
fieldName = "Status";
Object Status = SfdcUtils.getFieldValueFromQueryResult(fieldName,records[i]);
fieldName = "Action";
Object Action = SfdcUtils.getFieldValueFromQueryResult(fieldName,records[i]);
if (value != null && Status != null && Status.toString().equalsIgnoreCase("new") && Action != null && Action.toString().equalsIgnoreCase("none")) {
rowId = value.toString();
}
}
rowsSoFar++;
}
if (qr.isDone()) {
Expand Down

0 comments on commit f6ba387

Please sign in to comment.