Skip to main content
MediaBeacon University

Appendix

Known Issues

Saving an existing file as a new file or copying an existing file does not retain metadata on the new file.

Example

From a M4 plan on a user’s local machine, an image file is opened that needs to be retouched. User makes the necessary edits and saves the file with a new name designating a new version.

The hoped for result would be 2 files, the original and the renamed, both of which have retained metadata.

The actual result with the current M4sterPlan version is 2 files where the original file has retained metadata but the new renamed file has no metadata retained.

Suggested Workaround

End User:

  1. Open FileCloud desktop folder.
  2. Open file.
  3. Make edits to file.
  4. Save file with same name (Image.jpg).
  5. Wait 60 seconds.
  6. Rename file (ie Image_v1.jpg).
  7. The result is 1 file (renamed file) that has all metadata retained.

M4ScratchBasketClientSide.js

/**
 * The workflow that is used to add the assets in scratch basket to a plan.
 *
 * @author Sergei Plokhikh
 */
/**
 * Constants for schema and properties.
 */
var kM4sterPlanSchema = “http://mediabeacon.com/ns/m4sterplan/1.0/”;
var kM4sterPlanTitleField = new Property(kM4sterPlanSchema, “title”);
var kM4sterPlanUsersField = new Property(kM4sterPlanSchema, “users”);
var kFileNameField = “file_name”;
/**
 * The script name.
 */
var kScriptName = “M4ScratchBasket”;
/**
 * Returns true, if string is empty, otherwise returns false.
 */
function isEmpty(theString)
{
return theString == null || theString.length == 0;
}
/**
 * Returns the directory id by path.
 */
function getDirIdByPath(thePath)
{
if (fileManager.isFolder(thePath))
{
var aFolder = new ManagedFolder(thePath);
return aFolder.directoryId;
}
return -1;
}
/**
 * Returns the list of m4ster plans that matches the query.
 */
function typeAhead(theQuery)
{
if (theQuery[0] == “*”)
{
theQuery = theQuery.substring(1);
}
var aResults = new Array();
var aCriteria = new Criteria(searchManager.conjunctions.AND);
var aCriterion = new DatabaseCriterion(kFileNameField);
aCriterion.setCondition(searchManager.conditions.endsWith);
aCriterion.setValue(“.xmpb”);
aCriteria.addCriterion(aCriterion);
aCriterion = new XmpCriterion(kM4sterPlanTitleField);
aCriterion.setCondition(searchManager.conditions.contains);
aCriterion.setValue(theQuery);
aCriteria.addCriterion(aCriterion);
aCriterion = new XmpCriterion(kM4sterPlanUsersField);
aCriterion.setCondition(searchManager.conditions.contains);
aCriterion.setValue(context.getUser().username);
aCriteria.addCriterion(aCriterion);
var aSearch = new Search();
aSearch.setCriteria(aCriteria);
aSearch.execute(function(theAsset)
{
var aMeta = (theAsset.xmp != null && theAsset.xmp.meta != null) ? theAsset.xmp.meta : null;
if (aMeta != null)
{
var aPlanName = aMeta.getProperty(kM4sterPlanTitleField);
var aDirId = getDirIdByPath(theAsset.parent.path);
if (!isEmpty(aPlanName) && aDirId > -1)
{
var aValue = aPlanName + ‘ (dir:’ + aDirId + ‘)’;
var aData = {“display”: aPlanName, “value”: aValue};
aResults.push(aData);
}
}
}, 0, 100);
return JSON.stringify(aResults, undefined, 2);
}
/**
 * Creates or updates a progress bar for an user.
 */
function showStatus(theProgressId, theMessage, thePercent)
{
logAtLevel(“INFO: “ + theMessage, kScriptName, logLevels.INFO);
notificationManager.updateStatus(context.getUser().userId, theProgressId, theMessage, thePercent, kScriptName);
}
/**
 * Copies the assets to the m4ster plan folders.
 */
function addAssetsToPlan(thePlans, theBasketTabName, theBasketWidgetId)
{
var aProgressId = new Date().getTime();
var aStartTime = new Date().getTime();
try
{
var aDirIds = parsePlansData(thePlans);
if (aDirIds.length > 0)
{
var aFiles = getScratchBasketFiles(theBasketTabName, theBasketWidgetId);
if (aFiles.length > 0)
{
var aCurrentNumber = 1;
for (var i = 0; i < aDirIds.length; i++)
{
var aDirId = parseInt(aDirIds[i]);
var aFolder = fileManager.getFolderObjectById(aDirId);
if (aFolder)
{
for (var j = 0; j < aFiles.length; j++)
{
var aPercent = Math.round((aCurrentNumber / (aFiles.length * aDirIds.length)) * 99);
showStatus(aProgressId, “Copying Assets (“ + aPercent + “%)”, aPercent);
aCurrentNumber++;


var aFile = aFiles[j];
var aDestFilePath = aFolder.path + aFile.name;
if (fileManager.isFile(aDestFilePath))
{
fileManager.fileDelete(new ManagedFile(aDestFilePath));
}
fileManager.fileCopy(aFile, aFolder);
}
} else
{
logAtLevel(“Folder does not exist: “ + aDirId, kScriptName, logLevels.WARNING);
}
}
} else
{
throw “Scratch basket is empty”;
}
} else
{
throw “M4sterPlan directories has not been found”;
}
var anEndTime = new Date().getTime();
var aProcessTime = anEndTime - aStartTime;
if (aProcessTime < 5 * 1000)
{
workflowManager.sleep(5 - Math.floor(aProcessTime / 1000));
}
showStatus(aProgressId, “Done”, 100);
} catch (anException)
{
logAtLevel(‘ERROR: ‘ + anException, kScriptName, logLevels.WARNING);
showStatus(aProgressId, “Error”, -1);
return false;
}
return true;
}
function getScratchBasketFiles(theBasketTabName, theBasketWidgetId)
{
var aQuery = “SELECT j94c_asset_id FROM j94t_scratch_basket WHERE j94c_tab_name = ‘” + theBasketTabName + “’ AND j94c_widget_id = ‘” + theBasketWidgetId + “’ AND j94c_user = ‘” + context.getUser().userId + “’”;
var aSQL = new SQL();
var anAssetIds = aSQL.queryForList(aQuery);
var aResults = new Array();
if (anAssetIds != null && anAssetIds.length > 0)
{
for (var i = 0; i < anAssetIds.length; i++)
{
var aFile = fileManager.getFileObjectById(anAssetIds[i]);
if (aFile)
{
aResults.push(aFile);
}
}
}
return aResults;
}
/**
 * Parses the plan data and returns the list of plans directory ids.
 */
function parsePlansData(thePlans)
{
var aResults = new Array();
var aPlans = thePlans.split(‘,’);
for (var i = 0; i < aPlans.length; i++)
{
var aPlan = aPlans[i];
var anIndex = aPlan.indexOf(‘(dir:’);
if (anIndex > -1)
{
var aDirId = aPlan.substr(anIndex + ‘(dir:’.length, aPlan.length - 1);
aResults.push(aDirId);
}
}
return aResults;
}
/**
 * Main function to run.
 */
function main()
{
var anAction = context.getParameter(“action”);
logAtLevel(“ACTION: “ + anAction, kScriptName, logLevels.INFO);
try
{
switch (anAction)
{
case “addAssetsToPlan”:
var aPlans = context.getParameter(‘plans’);
var aBasketTabName = context.getParameter(‘basketTabName’);
var aBasketWidgetId = context.getParameter(‘basketWidgetId’);
return addAssetsToPlan(aPlans, aBasketTabName, aBasketWidgetId);
break;
}
} catch (anException)
{
logAtLevel(“Exception: “ + anException, kScriptName, logLevels.WARNING);
return anException;
}
var aQuery = context.getParameter(“query”);
if (!!aQuery && aQuery.length > 0)
{
return typeAhead(aQuery);
}
}
main();
  • Was this article helpful?