variables.parentFormName = "parentForm";
variables.subFormName = "subForms";
var retStruct = StructNew();
var updateDataStruct = arguments.elementData;
var ccapiDataStruct = StructNew();
var storyDataState = "";
var storyCurrentState = "";
var createEditWIPstruct = StructNew();
var wipArray = ArrayNew(1);
var savedWIPData = StructNew();
// Check see if there is a globalStoryID key in the data struct
// - if the globalStoryID is empty or if it is set to 0 create a New WIP record from the provided data
if ( NOT StructKeyExists(updateDataStruct, application.npsStory.appConfig.story.fieldNames.globalStoryID)
OR LEN(TRIM(updateDataStruct[application.npsStory.appConfig.story.fieldNames.globalStoryID])) EQ 0
OR updateDataStruct[application.npsStory.appConfig.story.fieldNames.globalStoryID] EQ 0 ) {
// THIS IS FOR CREATING A NEW WIP STORY RECORD (version 1)
// Copy the data passed in to the ccapiDataStruct
ccapiDataStruct = updateDataStruct;
// Create a New WIP record from the NEW data since this data does not have a VALID globalStoryID
ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.globalStoryID] = CreateUUID();
// If no UUID was passed in create one
if ( NOT StructKeyExists(ccapiDataStruct, application.npsStory.appConfig.story.fieldNames.storyID) )
ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.storyID] = CreateUUID();
ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.storyVersionID] = 1;
ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.wip] = 1;
ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.active] = 0;
ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.archived] = 0;
ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.archiveDate] = 0;
// - Set the wipDate
ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.wipDate] = application.npsStory.date.csDateFormat(Now(),Now());
// Reset the publishDate
ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.publishDate] = 0;
// Reset the storyPageID
//ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.storyPageID] = 0;
// - Set Author History Field with the current user
ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.authorEditHistory] = request.user.id;
// Create the new WIP record
retStruct = createStoryRecord(elementData=ccapiDataStruct);
}
else {
// Use the getStoryCurrentVersionState to check the STATE of the current version of the story is WIP or ACTIVE
storyCurrentState = getStoryCurrentVersionState(globalStoryID=updateDataStruct[application.npsStory.appConfig.story.fieldNames.globalStoryID],version="max");
//application.ADF.utils.dodump(storyCurrentState,"storyCurrentState - handleSaveWIP",1);
// if the story is archived
if ( storyCurrentState EQ "archived" ) {
// Copy the data passed in to the ccapiDataStruct
ccapiDataStruct = updateDataStruct;
// Do not create a wip from an archived record
retStruct['type'] = 'wip-from-archived-not-allowed';
retStruct['status'] = 'fail';
}
// if the story is published and active
else if ( storyCurrentState EQ "published" OR storyCurrentState EQ "active" ) {
// If the current state is PUBLISHED or ACTIVE
// - First we need to create a new WIP version
// - Then UPDATE the NEW WIP with the data passed in via the arguments.elementData
// Create a new WIP for Edit version
createEditWIPstruct = handleCreateEditWIP(globalStoryID=updateDataStruct[application.npsStory.appConfig.story.fieldNames.globalStoryID]);
//application.ADF.utils.dodump(createEditWIPstruct,"createEditWIPstruct - handleSaveWIP",0);
if ( StructKeyExists(createEditWIPstruct, "storyID") AND LEN(TRIM(createEditWIPstruct.storyID)) ) {
// Get the latest Data before overwritting with the updateDataStruct
wipArray = variables.storyDAO.getStory(uniqueID=createEditWIPstruct.storyID,idField=application.npsStory.appConfig.story.fieldNames.storyID);
// Get the data for saved WIP version (option 2)
//savedWIPData = getWIPStoryData(globalStoryID=updateDataStruct.globalStoryID);
if ( ArrayLen(wipArray) AND StructKeyExists(wipArray[1],"values") AND StructKeyExists(wipArray[1],"pageid") ) {
ccapiDataStruct = wipArray[1].values;
ccapiDataStruct.dataPageID = wipArray[1].pageID;
// Do not use the UUID from the FORM Data
// - Remove the UUID field from the passed in data before copying it over the New EDIT WIP
//StructDelete(updateDataStruct,"UUID");
//updateDataStruct = unversionStoryData(elementData=updateDataStruct,removeFieldList="storyID");
updateDataStruct = unversionStoryData(elementData=updateDataStruct,removeFieldList=application.npsStory.appConfig.story.fieldNames.storyID);
// Use the updateDataStruct to modify specific values for the keys in the ccapiDataStruct
StructAppend( ccapiDataStruct, updateDataStruct, true);
// Make sure the STATE is set for WIP
ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.wip] = 1;
ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.active] = 0;
ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.archived] = 0;
ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.archiveDate] = 0;
// - Set the wipDate
ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.wipDate] = application.npsStory.date.csDateFormat(Now(),Now());
// Use the storyVersionID of the Newly created WIP for Edit version
if ( StructKeyExists(createEditWIPstruct,"storyVersionID") AND LEN(TRIM(createEditWIPstruct['storyVersionID'])) )
ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.storyVersionID] = createEditWIPstruct['storyVersionID'];
// Reset the storyPageID
//ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.storyPageID] = 0;
// Make sure the Author Edit History List is up-to-date
//ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.authorEditHistory] = listAppendNoDuplicates(list=ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.authorEditHistory],value=request.user.id);
// Now UPDATE the newly created WIP version with the data that was passed in
retStruct = updateStoryRecord(elementData=ccapiDataStruct);
}
else {
doErrorLogging("storyService","handleSaveWIP - wipArray - 'no data for the Newly created WIP for Edit version'",wipArray);
}
}
else {
doErrorLogging("storyService","handleSaveWIP - createEditWIPstruct - 'no storyID for the Newly created WIP for Edit version'",createEditWIPstruct);
}
}
else if ( storyCurrentState EQ "wip" ) {
// If the current state is WIP we need to UPDATE the current WIP version using the updateDataStruct that was passed in
// Get the latest Data from the current WIP Version before overwritting with the updateDataStruct
//wipArray = variables.storyDAO.getStoryVerisonsByGlobalStoryID(globalStoryID=updateDataStruct.globalStoryID,version="max",state="wip");
// Get the data for saved WIP version before overwritting with the updateDataStruct
savedWIPData = getWIPStoryData(globalStoryID=updateDataStruct[application.npsStory.appConfig.story.fieldNames.globalStoryID]);
if ( StructKeyExists(savedWIPData,"values") AND StructKeyExists(savedWIPData,"pageid") ) {
ccapiDataStruct = savedWIPData.values;
ccapiDataStruct.dataPageID = savedWIPData.pageID;
// Use the updateDataStruct to modify specific values for the keys in the ccapiDataStruct
StructAppend( ccapiDataStruct, updateDataStruct, true);
// Make sure the Version STATE is set for WIP
ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.wip] = 1;
ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.active] = 0;
ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.archived] = 0;
ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.archiveDate] = 0;
// - Set the wipDate
ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.wipDate] = application.npsStory.date.csDateFormat(Now(),Now());
// Reset the publishDate
ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.publishDate] = 0;
// Reset the storyPageID
//ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.storyPageID] = 0;
// Make sure the Author History Field is up-to-date
//ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.authorEditHistory] = listAppendNoDuplicates(list=ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.authorEditHistory],value=request.user.id);
// Now UPDATE the newly create WIP vesrion with the data that was passed in
retStruct = updateStoryRecord(elementData=ccapiDataStruct);
}
else {
doErrorLogging("storyService","handleSaveWIP - savedWIPData - 'no WIP version'",savedWIPData);
}
}
else {
// If we are here then there was not saved WIP or saved ACTIVE version for the current GlobalStoryID
// so log it...
doErrorLogging("storyService","handleSaveACTIVE - handleSaveWIP - 'FAIL - no wip - no active'",updateDataStruct);
// Copy the data passed in to the ccapiDataStruct
ccapiDataStruct = updateDataStruct;
retStruct['status'] = 'fail';
}
}
// Add the current IDs to the retStruct
retStruct['storyID'] = ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.storyID];
retStruct['globalStoryID'] = ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.globalStoryID];
retStruct['storyVersionID'] = ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.storyVersionID];
//application.ADF.utils.dodump(retStruct,"retStruct - handleSaveWIP",0);
// Return the status struct
return retStruct;
var retStruct = StructNew();
var updateDataStruct = arguments.elementData;
var ccapiDataStruct = StructNew();
var storyCurrentState = "";
var createEditWIPstruct = StructNew();
var savedActiveDataArray = ArrayNew(1);
var savedWIPDataArray = ArrayNew(1);
var savedDataStruct = StructNew();
var oldVersionDataStruct = StructNew();
var updateOldVersionStruct = StructNew();
var publishStoryPageID = 0;
var publishPageStruct = StructNew();
var savedActiveData = StructNew();
var savedWIPData = StructNew();
var appConfigStruct = getAppConfig();
var configTypeNode = arguments.configType;
var pageCreateConfigStatus = false;
retStruct['status'] = 'success';
// Get configuration data
if ( StructKeyExists(appConfigStruct,configTypeNode) AND StructKeyExists(appConfigStruct[configTypeNode],"createPages") AND IsBoolean(appConfigStruct[configTypeNode].createPages) )
pageCreateConfigStatus = appConfigStruct[configTypeNode].createPages;
// Check see if there is a globalStoryID key in the data struct
// - if the globalStoryID is empty or if it is set to 0 create a New ACTIVE record from the provided data
if ( NOT StructKeyExists(updateDataStruct, application.npsStory.appConfig.story.fieldNames.globalStoryID)
OR LEN(TRIM(updateDataStruct[application.npsStory.appConfig.story.fieldNames.globalStoryID])) EQ 0
OR updateDataStruct[application.npsStory.appConfig.story.fieldNames.globalStoryID] EQ 0 ) {
// Create the new b/c nothing exists
// - Copy the data passed in to the ccapiDataStruct
ccapiDataStruct = updateDataStruct;
// - Create a New WIP record from the NEW data since this data does not have a VALID globalStoryID
ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.globalStoryID] = CreateUUID();
ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.storyVersionID] = 1;
ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.wip] = 0;
ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.active] = 1;
ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.archived] = 0;
ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.archiveDate] = 0;
// - Set the publishDate
ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.publishDate] = application.npsStory.date.csDateFormat(Now(),Now());
// Clear the storyPageID (ready to be updated after the page has been created)
//ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.storyPageID] = 0;
retStruct['type'] = 'publish-new';
}
else {
// We have a globalStoryID now check if the current saved version is in a WIP or an Active state
// - If the record is ACTIVE we need to COPY it and increment the the NEW records storyVersionID
// - If the record is WIP then we need to UPDATE it SET the ACTIVE=0 and the WIP=1 and increment the records storyVersionID
// Use the getStoryCurrentVersionState function to check the STATE of the current version of the story
storyCurrentState = getStoryCurrentVersionState(globalStoryID=updateDataStruct[application.npsStory.appConfig.story.fieldNames.globalStoryID],version="max");
// if the story is archived and active
if ( storyCurrentState EQ "archived" ) {
// Copy the data passed in to the ccapiDataStruct
ccapiDataStruct = updateDataStruct;
// Do not publish an archived record
retStruct['type'] = 'publish-archived-not-allowed';
retStruct['status'] = 'fail';
}
// if the story is published and active
// - If the record is ACTIVE we need to COPY it and increment the the NEW records storyVersionID
else if ( storyCurrentState EQ "published" OR storyCurrentState EQ "active" ) {
// Get the data for saved ACTIVE version
savedActiveData = getActiveStoryData(globalStoryID=updateDataStruct[application.npsStory.appConfig.story.fieldNames.globalStoryID]);
if ( StructKeyExists(savedActiveData,"values") AND StructKeyExists(savedActiveData,"pageid") ) {
// Save the current data record as inactive
oldVersionDataStruct = savedActiveData.values;
oldVersionDataStruct.dataPageID = savedActiveData.pageid;
oldVersionDataStruct[application.npsStory.appConfig.story.fieldNames.wip] = 0;
oldVersionDataStruct[application.npsStory.appConfig.story.fieldNames.active] = 0;
oldVersionDataStruct[application.npsStory.appConfig.story.fieldNames.archived] = 0;
oldVersionDataStruct[application.npsStory.appConfig.story.fieldNames.archiveDate] = 0;
// Reset the publishDate
//oldVersionDataStruct[application.npsStory.appConfig.story.fieldNames.publishDate] = 0;
// Reset the storyPageID
//oldVersionDataStruct[application.npsStory.appConfig.story.fieldNames.storyPageID] = 0;
// Update Old Active Version - disabling this version as the ACTIVE published version (also make sure WIP is not enabled)
updateOldVersionStruct = updateStoryRecord(elementData=oldVersionDataStruct);
// Create a copy of the current data as the new active version
// Now create a NEW published version
// - Start the process of creating the new active record
ccapiDataStruct = savedActiveData.values;
// Use the updateDataStruct to modify specific values for the keys in the ccapiDataStruct
StructAppend( ccapiDataStruct, updateDataStruct, true);
// Delete the datapageid since we will me making a new element record
//StructDelete(ccapiDataStruct, "dataPageID");
// Create a New UUID
ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.storyID] = CreateUUID();
// Set the NEW Version STATE to ACTIVE=1 and WIP=0
ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.wip] = 0;
ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.active] = 1;
ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.archived] = 0;
ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.archiveDate] = 0;
// Increment the version for the saved data
if ( StructKeyExists(savedActiveData.values, application.npsStory.appConfig.story.fieldNames.storyVersionID) AND IsNumeric(savedActiveData.values[application.npsStory.appConfig.story.fieldNames.storyVersionID]) )
ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.storyVersionID] = savedActiveData.values[application.npsStory.appConfig.story.fieldNames.storyVersionID] + 1;
else
ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.storyVersionID] = 1;
// Set the PUB Date
ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.publishDate] = application.npsStory.date.csDateFormat(Now(),Now());
// Set the storyPageID from the old data
if ( StructKeyExists(savedActiveData.values, application.npsStory.appConfig.story.fieldNames.storyPageID) AND IsNumeric(savedActiveData.values[application.npsStory.appConfig.story.fieldNames.storyPageID]) )
ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.storyPageID] = savedActiveData.values[application.npsStory.appConfig.story.fieldNames.storyPageID];
retStruct['type'] = 'publish-from-active';
}
else {
// How did we get here?
doErrorLogging("storyService","handleSaveACTIVE - savedActiveData - 'current max is active... but no data?'",savedActiveData);
}
}
// If the record is WIP then we need to UPDATE it SET the ACTIVE=0 and the WIP=1 and increment the records storyVersionID
else if ( storyCurrentState EQ "wip" ) {
// If there is one... Get the data for saved ACTIVE version
savedActiveData = getActiveStoryData(globalStoryID=updateDataStruct[application.npsStory.appConfig.story.fieldNames.globalStoryID]);
// Disable the current ACTIVE version
if ( StructKeyExists(savedActiveData,"values") AND StructKeyExists(savedActiveData,"pageid") ) {
// Update Old Active Version - disabling this version as the ACTIVE published version (also make sure WIP is not enabled)
oldVersionDataStruct = savedActiveData.values;
oldVersionDataStruct.dataPageID = savedActiveData.pageid;
oldVersionDataStruct[application.npsStory.appConfig.story.fieldNames.wip] = 0;
oldVersionDataStruct[application.npsStory.appConfig.story.fieldNames.active] = 0;
oldVersionDataStruct[application.npsStory.appConfig.story.fieldNames.archived] = 0;
oldVersionDataStruct[application.npsStory.appConfig.story.fieldNames.archiveDate] = 0;
// Reset the storyPageID
//oldVersionDataStruct[application.npsStory.appConfig.story.fieldNames.storyPageID] = 0;
// Update Old Active Version - disabling this version as the ACTIVE published version (also make sure WIP is not enabled)
updateOldVersionStruct = updateStoryRecord(elementData=oldVersionDataStruct);
}
// Now UPDATE the WIP and make it the NEW published version
// Get the data for saved WIP version
savedWIPData = getWIPStoryData(globalStoryID=updateDataStruct[application.npsStory.appConfig.story.fieldNames.globalStoryID]);
// Chanage the current WIP to ACTIVE
if ( StructKeyExists(savedWIPData,"values") AND StructKeyExists(savedWIPData,"pageid") ) {
ccapiDataStruct = savedWIPData.values;
ccapiDataStruct.dataPageID = savedWIPData.pageid;
// Use the updateDataStruct to modify specific values for the keys in the ccapiDataStruct
StructAppend( ccapiDataStruct, updateDataStruct, true);
// Set the NEW Version STATE to ACTIVE=1 and WIP=0
ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.wip] = 0;
ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.active] = 1;
ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.archived] = 0;
ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.archiveDate] = 0;
// use the version for the saved data (DO NOT Increment this value)
if ( StructKeyExists(savedWIPData.values, application.npsStory.appConfig.story.fieldNames.storyVersionID) AND IsNumeric(savedWIPData.values[application.npsStory.appConfig.story.fieldNames.storyVersionID]) )
ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.storyVersionID] = savedWIPData.values[application.npsStory.appConfig.story.fieldNames.storyVersionID];
else
ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.storyVersionID] = 1;
// Set the PUB Date
ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.publishDate] = application.npsStory.date.csDateFormat(Now(),Now());
// Set the storyPageID from the old ACTIVE data (if available)
if ( StructKeyExists(savedActiveData,"values") AND StructKeyExists(savedActiveData.values, application.npsStory.appConfig.story.fieldNames.storyPageID) AND IsNumeric(savedActiveData.values[application.npsStory.appConfig.story.fieldNames.storyPageID]) )
ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.storyPageID] = savedActiveData.values[application.npsStory.appConfig.story.fieldNames.storyPageID];
//else
// ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.storyPageID] = 0;
retStruct['type'] = 'publish-from-wip';
}
else {
// How did we get here. If the current v
doErrorLogging("storyService","handleSaveACTIVE - savedWIPData - 'current wip is active... but no data'",savedWIPData);
}
}
else {
// If we are here... there was NOT a saved WIP or saved ACTIVE version for the current GlobalStoryID
// so log it...
// A CreateEditFromWIP was supposed to be run before we got here
doErrorLogging("storyService","handleSaveACTIVE - updateDataStruct - 'FAIL - no wip - no active... CreateEditFromWIP did not run'",updateDataStruct);
// Copy the data passed in to the ccapiDataStruct
ccapiDataStruct = updateDataStruct;
retStruct['status'] = 'fail';
}
}
//doErrorLogging("storyService","handleSaveACTIVE - Published Page Creation Process",retStruct);
//doErrorLogging("storyService","handleSaveACTIVE - Published Page Creation Process",pageCreateConfigStatus);
/* START - Published Page Creation Process */
if ( pageCreateConfigStatus AND retStruct['status'] NEQ "fail" ) {
try {
// Published Page (or update page if needed)
publishPageStruct = application.npsStory.storyPageService.handlePublishStoryPage(elementData=ccapiDataStruct);
if ( StructKeyExists(publishPageStruct,"STORYPAGEID") ) {
publishStoryPageID = publishPageStruct.storyPageID;
// Set the story page ID
ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.storyPageID] = publishStoryPageID;
ccapiDataStruct['page_url'] = publishPageStruct.storyPageName;
}
}
catch (any e) {
retStruct['errorType'] = 'page-create';
retStruct['status'] = 'fail';
// if page creatiion or update failed throw an error
doErrorLogging("storyService","handleSaveACTIVE - publishPageStruct - 'FAIL - Error was thrown during the Published Page Process.'", e);
}
}
/* END - Published Page Creation Process */
/* START - Save Story CE Record Process */
if ( retStruct['status'] NEQ "fail" ) {
// Set the story page ID
ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.storyPageID] = publishStoryPageID;
// Temp store for any of the current set retStruct data
tempRetStruct = retStruct;
// Create a NEW element record...
// 1) if we are publishing a NEW STORY
// 2) if we are publishing STORY that is CURRENTLY ACTIVE
if ( retStruct.type EQ 'publish-new' OR retStruct.type EQ 'publish-from-active' ) {
// Since we are creating a new record
// If a dataPageID exists... delete it
if ( StructKeyExists(ccapiDataStruct,"dataPageID") )
StructDelete(ccapiDataStruct, "dataPageID");
// Create the new ACTIVE record
retStruct = createStoryRecord(elementData=ccapiDataStruct);
}
else {
// Update the Story record with the
retStruct = updateStoryRecord(elementData=ccapiDataStruct);
}
StructAppend(retStruct, tempRetStruct, true);
}
/* END - Save Story CE Record Process */
// Add the current IDs to the retStruct
if ( StructKeyExists(ccapiDataStruct, application.npsStory.appConfig.story.fieldNames.storyID) )
retStruct['storyID'] = ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.storyID];
if ( StructKeyExists(ccapiDataStruct, application.npsStory.appConfig.story.fieldNames.globalStoryID) )
retStruct['globalStoryID'] = ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.globalStoryID];
if ( StructKeyExists(ccapiDataStruct, application.npsStory.appConfig.story.fieldNames.storyVersionID) )
retStruct['storyVersionID'] = ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.storyVersionID];
if ( IsNumeric(publishStoryPageID) )
retStruct['storyPageID'] = publishStoryPageID;
// Return the status struct
return retStruct;
var retStruct = StructNew();
var updateDataStruct = arguments.elementData;
var apiDataStruct = StructNew();
var globalStoryID = "";
var activeStoryID = "";
var wipStoryID = "";
var storyPageID = 0;
var activeData = ArrayNew(1);
var activeDataStruct = StructNew();
var wipData = ArrayNew(1);
var wipDataStruct = StructNew();
var deletePageStruct = StructNew();
var updateActive = StructNew();
var updateWIP = StructNew();
var appConfigStruct = getAppConfig();
var configTypeNode = arguments.configType;
var pageCreateConfigStatus = false;
// Get configuration data
if ( StructKeyExists(appConfigStruct,configTypeNode) AND StructKeyExists(appConfigStruct[configTypeNode],"createPages") AND IsBoolean(appConfigStruct[configTypeNode].createPages) )
pageCreateConfigStatus = appConfigStruct[configTypeNode].createPages;
// To archive a story we will:
// - Get the GSID from the provided element data
if ( StructKeyExists(updateDataStruct, application.npsStory.appConfig.story.fieldNames.globalStoryID)
AND updateDataStruct[application.npsStory.appConfig.story.fieldNames.globalStoryID] NEQ 0 ) {
globalStoryID = updateDataStruct[application.npsStory.appConfig.story.fieldNames.globalStoryID];
}
if ( LEN(TRIM(globalStoryID)) ) {
// - With the GSID check to see if we have a WIP, an ACTIVE or a WIP and an ACTIVE
activeStoryID = hasACTIVE(globalStoryID=globalStoryID);
//application.ADF.utils.dodump(activeStoryID,"activeStoryID",1);
wipStoryID = hasWIP(globalStoryID=globalStoryID);
//application.ADF.utils.dodump(wipStoryID,"wipStoryID",1);
// - Archive the Active record and delete the Page
if ( LEN(TRIM(activeStoryID)) ) {
// - Get Active Data
activeData = variables.storyDAO.getStory(uniqueID=activeStoryID);
if ( ArrayLen(activeData) ) {
if ( StructKeyExists(activeData[1],"values") )
activeDataStruct = activeData[1].values;
if ( StructKeyExists(activeData[1],"pageID") )
activeDataStruct.dataPageID = activeData[1].pageID;
//application.ADF.utils.dodump(activeDataStruct,"activeDataStruct",1);
// If we have active data delete the page and update the record
if ( NOT StructIsEmpty(activeDataStruct) ) {
// Delete the page for the active record
if ( pageCreateConfigStatus ) {
// Get the storyPageID
if ( StructKeyExists(activeDataStruct,application.npsStory.appConfig.story.fieldNames.storyPageID) )
storyPageID = activeDataStruct[application.npsStory.appConfig.story.fieldNames.storyPageID];
if ( IsNumeric(storyPageID) AND storyPageID GT 0 )
deletePageStruct = application.npsStory.storyPageDAO.handlePageDelete(storyPageID);
//application.ADF.utils.dodump(deletePageStruct,"deletePageStruct",1);
retStruct['archive-delete-published-page'] = deletePageStruct;
}
// - Set the ACTIVE data to archived
activeDataStruct = setStoryDataAsArchived(activeDataStruct);
//application.ADF.utils.dodump(activeDataStruct,"activeDataStruct",1);
// - Update the ACTIVE element record
updateActive = updateStoryRecord(elementData=activeDataStruct);
// - Add active update to the resutls
retStruct["archive-active-update"] = updateActive;
}
}
}
if ( LEN(TRIM(wipStoryID)) ) {
// - Get WIP Data
wipData = variables.storyDAO.getStory(uniqueID=wipStoryID);
if ( ArrayLen(wipData) ) {
if ( StructKeyExists(wipData[1],"values") )
wipDataStruct = wipData[1].values;
if ( StructKeyExists(wipData[1],"pageID") )
wipDataStruct.dataPageID = wipData[1].pageID;
//application.ADF.utils.dodump(wipDataStruct,"wipDataStruct",1);
if ( NOT StructIsEmpty(wipDataStruct) ) {
// - Set the WIP data to archived
wipDataStruct = setStoryDataAsArchived(wipDataStruct);
//application.ADF.utils.dodump(wipDataStruct,"wipDataStruct",1);
// - Update the WIP element record
updateWIP = updateStoryRecord(elementData=wipDataStruct);
// - Add wip to the resutls
retStruct["archive-wip-update"] = updateWIP;
}
}
}
}
else {
// - If we are hear ... there was not valid GlobalStoryID in the element record
doErrorLogging("storyService","handleSaveARCHIVED - updateDataStruct - 'FAIL - no global story id - archive did not complete.'",updateDataStruct);
retStruct['status'] = 'fail';
}
retStruct['globalStoryID'] = globalStoryID;
// Return the status struct
return retStruct;
var retStruct = StructNew();
var updateDataStruct = arguments.elementData;
var apiDataStruct = StructNew();
var globalStoryID = "";
var activeStoryID = "";
var wipStoryID = "";
var activeData = ArrayNew(1);
var activeDataStruct = StructNew();
var wipData = ArrayNew(1);
var wipDataStruct = StructNew();
var deletePageStruct = StructNew();
var updateActive = StructNew();
var updateWIP = StructNew();
var publishPageStruct = StructNew();
var appConfigStruct = getAppConfig();
var configTypeNode = arguments.configType;
var pageCreateConfigStatus = false;
// Get configuration data
if ( StructKeyExists(appConfigStruct,configTypeNode) AND StructKeyExists(appConfigStruct[configTypeNode],"createPages") AND IsBoolean(appConfigStruct[configTypeNode].createPages) )
pageCreateConfigStatus = appConfigStruct[configTypeNode].createPages;
// To UNARCHIVE a story we will:
// - Get the GSID from the provided element data
if ( StructKeyExists(updateDataStruct, application.npsStory.appConfig.story.fieldNames.globalStoryID)
AND updateDataStruct[application.npsStory.appConfig.story.fieldNames.globalStoryID] NEQ 0 ) {
globalStoryID = updateDataStruct[application.npsStory.appConfig.story.fieldNames.globalStoryID];
}
if ( LEN(TRIM(globalStoryID)) ) {
// - With the GSID check to see if we have a WIP, an ACTIVE or a WIP and an ACTIVE
activeStoryID = hasACTIVE(globalStoryID=globalStoryID);
//application.ADF.utils.dodump(activeStoryID,"activeStoryID",1);
wipStoryID = hasWIP(globalStoryID=globalStoryID);
//application.ADF.utils.dodump(wipStoryID,"wipStoryID",1);
// - Update the Active record and create the Page
if ( LEN(TRIM(activeStoryID)) ) {
// - Get Active Data
activeData = variables.storyDAO.getStory(uniqueID=activeStoryID);
if ( ArrayLen(activeData) ) {
if ( StructKeyExists(activeData[1],"values") )
activeDataStruct = activeData[1].values;
if ( StructKeyExists(activeData[1],"pageID") )
activeDataStruct.dataPageID = activeData[1].pageID;
//application.ADF.utils.dodump(activeDataStruct,"activeDataStruct",1);
// If we have active data create the page and update the record
if ( NOT StructIsEmpty(activeDataStruct) ) {
// Create the page for the active record
if ( pageCreateConfigStatus ) {
// Create the published page
try {
// Published Page (or update page if needed)
publishPageStruct = application.npsStory.storyPageService.handlePublishStoryPage(elementData=activeDataStruct);
if ( StructKeyExists(publishPageStruct,"STORYPAGEID") ) {
// Set the story page ID
activeDataStruct[application.npsStory.appConfig.story.fieldNames.storyPageID] = publishPageStruct.storyPageID;
activeDataStruct['page_url'] = publishPageStruct.storyPageName;
}
}
catch (any e) {
publishPageStruct['errorType'] = 'page-create';
publishPageStruct['status'] = 'fail';
publishPageStruct['details'] = e;
// if page creatiion or update failed throw an error
doErrorLogging("storyService","handleSaveUNARCHIVED - publishPageStruct - 'FAIL - Error was thrown during the Publish Archive Page Process.'", e);
}
//application.ADF.utils.dodump(publishPageStruct,"publishPageStruct",1);
retStruct['archive-active-create-page'] = publishPageStruct;
}
// - Set the ACTIVE data to UNARCHIVED
activeDataStruct = setStoryDataAsUnarchived(activeDataStruct);
//application.ADF.utils.dodump(activeDataStruct,"activeDataStruct",1);
// - Update the ACTIVE element record
updateActive = updateStoryRecord(elementData=activeDataStruct);
// - Add active update to the resutls
retStruct["archive-active-update"] = updateActive;
}
}
}
// Update the WIP version
if ( LEN(TRIM(wipStoryID)) ) {
// - Get WIP Data
wipData = variables.storyDAO.getStory(uniqueID=wipStoryID);
if ( ArrayLen(wipData) ) {
if ( StructKeyExists(wipData[1],"values") )
wipDataStruct = wipData[1].values;
if ( StructKeyExists(wipData[1],"pageID") )
wipDataStruct.dataPageID = wipData[1].pageID;
//application.ADF.utils.dodump(wipDataStruct,"wipDataStruct",1);
if ( NOT StructIsEmpty(wipDataStruct) ) {
// - Set the WIP data to UNARCHIVED
wipDataStruct = setStoryDataAsUnarchived(wipDataStruct);
//application.ADF.utils.dodump(wipDataStruct,"wipDataStruct",1);
// - Update the WIP element record
updateWIP = updateStoryRecord(elementData=wipDataStruct);
// - Add wip to the resutls
retStruct["archive-wip-update"] = updateWIP;
}
}
}
}
else {
// - If we are hear ... there was not valid GlobalStoryID in the element record
doErrorLogging("storyService","handleSaveUNARCHIVED - updateDataStruct - 'FAIL - no global story id - archive did not complete.'",updateDataStruct);
retStruct['status'] = 'fail';
}
retStruct['globalStoryID'] = globalStoryID;
// Return the status struct
return retStruct;
var dupCheckDataArray = ArrayNew(1);
var ccapiDataStruct = arguments.elementData;
var retStruct = StructNew();
var saveStatusStruct = StructNew();
// If a dataPageID is in the data struct remove it since this is a new record
if ( StructKeyExists(ccapiDataStruct,"dataPageID") )
StructDelete(ccapiDataStruct,"dataPageID");
// Check to make sure that this UUID is not in use in the element records
// - If so create a new UUID for this "new" record
if ( StructKeyExists(ccapiDataStruct, application.npsStory.appConfig.story.fieldNames.storyID) )
{
dupCheckDataArray = variables.storyDAO.getStory(uniqueID=ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.storyID]);
if ( ArrayLen(dupCheckDataArray) AND StructKeyExists(dupCheckDataArray[1],"values") )
ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.storyID] = CreateUUID();
}
// Create a new record (no dataPageID)
saveStatusStruct = variables.storyDAO.storyParentCCAPI(ccapiDataStruct);
// Set the data update type
retStruct['type'] = 'create-story';
// Add the element update status to the status struct
if ( StructKeyExists(saveStatusStruct,"CONTENTUPDATED") AND saveStatusStruct['CONTENTUPDATED'] IS true )
retStruct['status'] = 'success';
else
retStruct['status'] = 'fail';
// Return the status struct
return retStruct;
var currentSavedDataArray = ArrayNew(1);
var updateDataStruct = arguments.elementData;
var ccapiDataStruct = StructNew();
var doUpdate = false;
var retStruct = StructNew();
var updateStatusStruct = StructNew();
//application.ADF.utils.dodump(updateDataStruct,"updateStoryRecord",0);
// If a dataPageID is NOT the data struct then attempt to get one
if ( NOT StructKeyExists(updateDataStruct,"dataPageID") )
{
if ( StructKeyExists(updateDataStruct, application.npsStory.appConfig.story.fieldNames.storyID) AND LEN(TRIM(updateDataStruct[application.npsStory.appConfig.story.fieldNames.storyID])) )
{
// Get the Current Data from the Element from the UUID value
currentSavedDataArray = variables.storyDAO.getStory(uniqueID=updateDataStruct[application.npsStory.appConfig.story.fieldNames.storyID]);
//application.ADF.utils.dodump(currentSavedDataArray,"currentSavedDataArray - updateStoryRecord",0);
if ( ArrayLen(currentSavedDataArray) AND StructKeyExists(currentSavedDataArray[1],"pageid") AND IsNumeric(currentSavedDataArray[1].pageid) AND currentSavedDataArray[1].pageid NEQ 0 )
{
// Copy the saved data to the ccapiDataStruct
if ( StructKeyExists(currentSavedDataArray[1],"values") )
ccapiDataStruct = currentSavedDataArray[1].values;
// Set the dataPageID of the saved data to the ccapiDataStruct
ccapiDataStruct.dataPageID = currentSavedDataArray[1].pageid;
}
}
//application.ADF.utils.dodump(ccapiDataStruct,"ccapiDataStruct - updateStoryRecord",0);
// Use the updateDataStruct to modify specific values for the keys in the ccapiDataStruct
StructAppend( ccapiDataStruct, updateDataStruct, true);
// Now that the Data is READY set doUpdate to TRUE
doUpdate = true;
//application.ADF.utils.dodump(ccapiDataStruct,"ccapiDataStruct (after adding new data) - updateStoryRecord",0);
// Check if we now have a dataPageID in the struct now
// - If we do NOT have a datapageID. ( //TODO: Either fail or do a create )
if ( NOT StructKeyExists(ccapiDataStruct,"dataPageID") )
{
if ( arguments.onUpdateError EQ "create" )
{
// Run the create code instead of an update
updateStatusStruct = createStoryRecord(elementData=ccapiDataStruct);
doUpdate = false;
}
else
{
// Update failed. No dataPageID and onUpdateError is set to 'error'
retStruct['type'] = 'no-story-update';
doUpdate = false;
}
}
}
else
{
// If we have a valid dataPageID then we are ready to do the UPDATE!
ccapiDataStruct = updateDataStruct;
doUpdate = true;
}
// Only run the storyParentCCAPI call if the doUpdate is set to TRUE (basically... if we have a dataPageID in the struct )
if ( StructKeyExists(ccapiDataStruct,"dataPageID") AND doUpdate )
{
// Update the record (has a dataPageID)
updateStatusStruct = variables.storyDAO.storyParentCCAPI(ccapiDataStruct);
// Set the data update type
retStruct['type'] = 'update-story';
}
// Add the element update status to the status struct
if ( StructKeyExists(updateStatusStruct,"CONTENTUPDATED") AND updateStatusStruct['CONTENTUPDATED'] IS true )
retStruct['status'] = 'success';
else
retStruct['status'] = 'fail';
//application.ADF.utils.dodump(retStruct,"retStruct - updateStoryRecord",0);
// Return the status struct
return retStruct;
var retStruct = StructNew();
var storyData = StructNew();
var storyDataStruct = StructNew();
var archivedStoryIDlist = "";
if ( LEN(TRIM(arguments.globalStoryID)) AND arguments.globalStoryID NEQ 0 ) {
// Check to see if we have any archived records
archivedStoryIDlist = hasArchived(globalStoryID=globalStoryID);
//application.adf.utils.doDump(archivedStoryIDlist,"archivedStoryIDlist",1);
// Get the data for the Max Story version
storyData = getMaxVersionStoryData(globalStoryID=arguments.globalStoryID);
//application.adf.utils.doDump(storyData,"storyData",1);
if ( StructKeyExists(storyData,"values") ) {
storyDataStruct = storyData.values;
// if we have archived versions then we need to UNARCHIVE them
if ( ListLen(archivedStoryIDlist) ) {
// To UNARCHIVE ... set the ARCHIVE FLAG to 0 for the ACTIVE and WIP story records
retStruct = handleSaveUNARCHIVED(elementData=storyDataStruct);
retStruct['type'] = 'story-unarchived';
retStruct['msg'] = "Story Restored!";
}
else {
// To ARCHIVE ... set the ARCHIVE FLAG to 1 for the ACTIVE and WIP story records
retStruct = handleSaveARCHIVED(elementData=storyDataStruct);
retStruct['type'] = 'story-archived';
retStruct['msg'] = "Story Archived!";
}
}
else {
retStruct['type'] = 'no-story-data-to-archive';
retStruct['msg'] = "Story Archive Error! No data was found for the passed in Global Story ID.";
}
}
else {
retStruct['type'] = 'no-story-archived-no-gsid';
retStruct['msg'] = "Story Archive Error! A Global Story ID was not passed in.";
}
// Add the current UUIDs to the retStruct
retStruct['globalStoryID'] = arguments.globalStoryID;
// Return the status struct
return retStruct;
var currDataStruct = StructNew();
var savedDataArray = ArrayNew(1);
var savedDataStruct = StructNew();
var savedDataPageID = 0;
var hasChanged = false;
var updateSavedDataStruct = StructNew();
var oldDataArray = ArrayNew(1);
var ccapiDataStruct = StructNew();
var retStruct = StructNew();
var saveStatus = StructNew();
var maxVersionArray = ArrayNew(1);
var storyDataState = "";
var doSave = false;
// If needed... create a new unique globalStoryID for the story record.
// - if the globalStoryID IS equal to 0... replace that value with a UUID
if ( LEN(TRIM(arguments.globalStoryID)) EQ 0 OR arguments.globalStoryID EQ 0 ) {
// Create a completely 'new' blank story as a WIP version
//ccapiDataStruct.title = "";
ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.storyID] = CreateUUID();
ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.globalStoryID] = CreateUUID();
ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.storyVersionID] = 1;
ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.wip] = 1;
ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.active] = 0;
ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.archived] = 0;
ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.publishDate] = 0;
ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.archiveDate] = 0;
// - Set the wipDate
ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.wipDate] = application.npsStory.date.csDateFormat(Now(),Now());
//ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.storyPageID] = 0;
// Create the new WIP record
retStruct = createStoryRecord(elementData=ccapiDataStruct);
retStruct['type'] = 'create-new-story-wip';
doSave = false;
}
else {
// Check for the WIP Version ( return ALL versions both WIP and Active by the provided globalStoryID )
maxVersionArray = variables.storyDAO.getStoryVerisonsByGlobalStoryID(globalStoryID=arguments.globalStoryID,version="max");
//application.ADF.utils.dodump(maxVersionArray,"maxVersionArray - handleCreateEditWIP",0);
if ( ArrayLen(maxVersionArray) AND StructKeyExists(maxVersionArray[1],"pageid") AND StructKeyExists(maxVersionArray[1],"values") ) {
// Set the values of the Current version
savedDataPageID = maxVersionArray[1].PageID;
savedDataStruct = maxVersionArray[1].values;
// Use the parseStoryDataState function to check the STATE of the current version
storyDataState = parseStoryDataState(elementData=savedDataStruct);
// if the story is archived
/* if ( storyCurrentState EQ "archived" ) {
// Copy the data passed in to the ccapiDataStruct
ccapiDataStruct = savedDataStruct;
// Do not create a wip from an archived record
retStruct['type'] = 'wip-from-archived-not-allowed';
retStruct['status'] = 'fail';
}*/
if ( storyDataState EQ "wip" ) {
// This returned version is the WIP then use this as the version to load in to the Form (dataPageID or by UUID)
// Run Updates on this version.
ccapiDataStruct = savedDataStruct;
// setting overrides are not needed because no update or create is happening here.
retStruct['type'] = "existing-wip";
retStruct['status'] = "success";
}
else {
// If a WIP does not exist CREATE one based on the a COPY of the current MAX record
// set the new UUID for the new version of the WIP record
ccapiDataStruct = savedDataStruct;
ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.storyID] = CreateUUID();
ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.wip] = 1;
ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.active] = 0;
ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.archived] = 0;
ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.publishDate] = 0;
ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.archiveDate] = 0;
//ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.storyPageID] = 0;
// - Set the wipDate
ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.wipDate] = application.npsStory.date.csDateFormat(Now(),Now());
if ( IsNumeric( ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.storyVersionID] ) )
ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.storyVersionID] = ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.storyVersionID] + 1;
else
ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.storyVersionID] = 1;
// Create the new WIP record
retStruct = createStoryRecord(elementData=ccapiDataStruct);
retStruct['type'] = "copy-to-wip";
}
}
else {
// Create a completely 'new' blank story as a WIP version
ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.storyID] = CreateUUID();
ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.globalStoryID] = CreateUUID();
ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.storyVersionID] = 1;
ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.wip] = 1;
ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.active] = 0;
ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.archived] = 0;
ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.publishDate] = 0;
ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.archiveDate] = 0;
// - Set the wipDate
ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.wipDate] = application.npsStory.date.csDateFormat(Now(),Now());
//ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.storyPageID] = 0;
// Create the new WIP record
retStruct = createStoryRecord(elementData=ccapiDataStruct);
retStruct['type'] = 'create-new-wip';
}
}
// Add the current UUIDs to the retStruct
retStruct['storyID'] = ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.storyID];
retStruct['globalStoryID'] = ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.globalStoryID];
retStruct['storyVersionID'] = ccapiDataStruct[application.npsStory.appConfig.story.fieldNames.storyVersionID];
// Return the status struct
return retStruct;
var retDataStruct = StructNew();
var retDataArray = ArrayNew(1);
var fldCnt = 1;
var ceName = "";
var jsonFieldString = "";
var sonFieldStruct = StructNew();
var subFormUUID = "";
//Loop over the Form Data Struct to process each form and its json fields string
for ( key in arguments.formDataStruct ) {
// Determine Form's 'the Custom Element Name
ceName = parseCustomElementName(formFieldNameID=key);
// Set the Form's JSON string
jsonFieldString = arguments.formDataStruct[key];
// Convert the JSON sting to an Struct
jsonFieldStruct = StructNew();
if ( LEN(TRIM(jsonFieldString)) AND IsJSON(jsonFieldString) )
jsonFieldStruct = deserializejson(jsonFieldString);
// Clear the sub form UUID field variable for each loop pass
subFormUUID = "";
// Handle the main STORY form
if ( ceName EQ "Story" ) {
if ( NOT StructKeyExists(retDataStruct,ceName) )
retDataStruct[ceName] = jsonFieldStruct;
}
else {
// Set the sub form UUID field name
if ( ceName EQ "Story Section" ) {
if ( StructKeyExists(jsonFieldStruct, application.npsStory.appConfig.story.sectionFieldNames.UUID) )
subFormUUID = jsonFieldStruct[application.npsStory.appConfig.story.sectionFieldNames.UUID];
}
else if ( ceName EQ "Story Pull Quote" ) {
if ( StructKeyExists(jsonFieldStruct, application.npsStory.appConfig.story.pullQuoteFieldNames.UUID) )
subFormUUID = jsonFieldStruct[application.npsStory.appConfig.story.pullQuoteFieldNames.UUID];
}
// Set the sub form data into the return form
if ( LEN(TRIM(subFormUUID)) ) {
if ( NOT StructKeyExists(retDataStruct,ceName) )
retDataStruct[ceName] = StructNew();
if ( NOT StructKeyExists(retDataStruct[ceName],subFormUUID) )
retDataStruct[ceName][subFormUUID] = jsonFieldStruct;
}
}
}
return retDataStruct;
var retStr = arguments.formFieldNameID;
var startRemoveStr = ListFirst(retStr,"_") & "_";
var endRemoveStr = "";
var i=1;
var removeCnt = 2;
// Remove the prefix "f_"
retStr = ReplaceNoCase(retStr,startRemoveStr,"","one");
// Remove the field suffix "_1000_2000"
for ( i=1;i LTE removeCnt;i=i+1 ) {
endRemoveStr = "_" & ListLast(retStr,"_");
retStr = ReplaceNoCase(retStr,endRemoveStr,"","one");
}
// Remove Underscores
retStr = ReplaceNoCase(retStr,"_"," ","all");;
// Return the Trimmed string as the Element Name
return retStr;
var dataStruct = arguments.elementData;
dataStruct[application.npsStory.appConfig.story.fieldNames.wip] = 1;
dataStruct[application.npsStory.appConfig.story.fieldNames.active] = 0;
dataStruct[application.npsStory.appConfig.story.fieldNames.archived] = 0;
dataStruct[application.npsStory.appConfig.story.fieldNames.archiveDate] = 0;
// Return the status struct
return dataStruct;
var dataStruct = arguments.elementData;
dataStruct[application.npsStory.appConfig.story.fieldNames.wip] = 0;
dataStruct[application.npsStory.appConfig.story.fieldNames.active] = 1;
dataStruct[application.npsStory.appConfig.story.fieldNames.publishDate] = application.npsStory.date.csDateFormat(Now(),Now());
dataStruct[application.npsStory.appConfig.story.fieldNames.archived] = 0;
dataStruct[application.npsStory.appConfig.story.fieldNames.archiveDate] = 0;
// Return the status struct
return dataStruct;
var retStruct = StructNew();
var dataStruct = arguments.elementData;
dataStruct[application.npsStory.appConfig.story.fieldNames.archived] = 1;
dataStruct[application.npsStory.appConfig.story.fieldNames.archiveDate] = application.npsStory.date.csDateFormat(Now(),Now());
dataStruct[application.npsStory.appConfig.story.fieldNames.storyPageID] = 0;
// Return the status struct
return dataStruct;
var retStruct = StructNew();
var dataStruct = arguments.elementData;
dataStruct[application.npsStory.appConfig.story.fieldNames.archived] = 0;
dataStruct[application.npsStory.appConfig.story.fieldNames.archiveDate] = 0;
// Return the status struct
return dataStruct;
var retStatus = "";
var csPageURL = "";
// Check the to see if the is data has a valid CS page URL from the storyPageID
if ( StructKeyExists(arguments.elementData, application.npsStory.appConfig.story.fieldNames.storyPageID) AND arguments.elementData[application.npsStory.appConfig.story.fieldNames.storyPageID] GT 0 )
csPageURL = application.npsStory.csData.getCSPageURL(arguments.elementData[application.npsStory.appConfig.story.fieldNames.storyPageID]);
// a 'archived' status takes presidence
if ( StructKeyExists(arguments.elementData, application.npsStory.appConfig.story.fieldNames.archived) AND arguments.elementData[application.npsStory.appConfig.story.fieldNames.archived] EQ 1 )
retStatus = "archived";
// 'published' is active with a valid CS Page URL this status takes presidence (after archived)
else if ( StructKeyExists(arguments.elementData, application.npsStory.appConfig.story.fieldNames.active)
AND arguments.elementData[application.npsStory.appConfig.story.fieldNames.active] EQ 1
AND LEN(TRIM(csPageURL)) )
retStatus = "published";
// 'active' has no valid CS Page URL
else if ( StructKeyExists(arguments.elementData, application.npsStory.appConfig.story.fieldNames.active)
AND arguments.elementData[application.npsStory.appConfig.story.fieldNames.active] EQ 1 )
retStatus = "active";
// 'wip' is work in progress
else if ( StructKeyExists(arguments.elementData, application.npsStory.appConfig.story.fieldNames.wip) AND arguments.elementData[application.npsStory.appConfig.story.fieldNames.wip] EQ 1 )
retStatus = "wip";
else
retStatus = "";
return retStatus;
var retStatus = "";
var versionStr = "max";
var dataArray = variables.storyDAO.getStoryVerisonsByGlobalStoryID(globalStoryID=arguments.globalStoryID,version=versionStr);
// if a data array is returned ... parse the current version state from the data
if ( ArrayLen(dataArray) AND StructKeyExists(dataArray[1],"values") )
retStatus = parseStoryDataState(elementData=dataArray[1].values);
return retStatus;
var retUUID = "";
var dataStruct = getWIPStoryData(globalStoryID=arguments.globalStoryID);
// if a data is returned ... get the data from the first record
if ( StructKeyExists(dataStruct,"values") AND StructKeyExists(dataStruct.values, application.npsStory.appConfig.story.fieldNames.storyID) )
retUUID = dataStruct.values[application.npsStory.appConfig.story.fieldNames.storyID];
return retUUID;
var retUUID = "";
var dataStruct = getActiveStoryData(globalStoryID=arguments.globalStoryID);
// if a data is returned ... get the data from the first record
if ( StructKeyExists(dataStruct,"values") AND StructKeyExists(dataStruct.values, application.npsStory.appConfig.story.fieldNames.storyID) )
retUUID = dataStruct.values[application.npsStory.appConfig.story.fieldNames.storyID];
return retUUID;
var retUUIDlist = "";
var dataArray = getArchivedStoryData(globalStoryID=arguments.globalStoryID);
var i=1;
// build a list of records that have be flipped to ARCHIVED
for ( i=1; i LTE ArrayLen(dataArray); i=i+1 ){
if ( StructKeyExists(dataArray[i],"values") AND StructKeyExists(dataArray[i].values, application.npsStory.appConfig.story.fieldNames.storyID) AND LEN(TRIM(dataArray[i].values[application.npsStory.appConfig.story.fieldNames.storyID])) )
retUUIDlist = ListAppend(retUUIDlist,dataArray[i].values[application.npsStory.appConfig.story.fieldNames.storyID]);
}
return retUUIDlist;
var retData = StructNew();
var versionStr = "MAX";
var stateStr = "WIP";
var dataArray = variables.storyDAO.getStoryVerisonsByGlobalStoryID(globalStoryID=arguments.globalStoryID,version=versionStr,state=stateStr);
// if a data is returned ... get the data from the first record
if ( ArrayLen(dataArray) AND StructKeyExists(dataArray[1],"values") )
retData = dataArray[1];
return retData;
var retData = StructNew();
var versionStr = "MAX";
var stateStr = "ACTIVE";
var dataArray = variables.storyDAO.getStoryVerisonsByGlobalStoryID(globalStoryID=arguments.globalStoryID,version=versionStr,state=stateStr);
// if a data is returned ... get the data from the first record
if ( ArrayLen(dataArray) AND StructKeyExists(dataArray[1],"values") )
retData = dataArray[1];
return retData;
var retUUID = StructNew();
var storyData = variables.storyDAO.getActiveStoryData(globalStoryID=arguments.globalStoryID);
// if a data is returned ... get the story ID
if ( StructKeyExists(storyData,"values") AND StructKeyExists(storyData.values,"storyid") )
retUUID = storyData.values.storyid;
return retUUID;
var versionStr = "ALL";
var stateStr = "ARCHIVED";
var dataArray = variables.storyDAO.getStoryVerisonsByGlobalStoryID(globalStoryID=arguments.globalStoryID,version=versionStr,state=stateStr);
return dataArray;
var retData = StructNew();
var versionStr = "MAX";
var dataArray = variables.storyDAO.getStoryVerisonsByGlobalStoryID(globalStoryID=arguments.globalStoryID,version=versionStr);
// if a data is returned ... get the data from the first record
if ( ArrayLen(dataArray) AND StructKeyExists(dataArray[1],"values") )
retData = dataArray[1];
return retData;
return application.npsStory.ceData.arrayOfCEDataSort(aOfS=arguments.storyDataArray,key=application.npsStory.appConfig.story.fieldNames.storyVersionID,sortOrder=arguments.sortorder,sortType="numeric");
var versionStr = "MAX";
var stateStr = "ACTIVE";
return variables.storyDAO.getStoryCSPageID(globalStoryID=arguments.globalStoryID,version=versionStr,state=stateStr);
var rtnStruct = structNew();
var storyFormIDList = formIDList();
var reqFldStruct = StructNew();
var i = 1;
for ( i=1; i LTE ListLen(storyFormIDList); i=i+1 ) {
reqFldStruct = requiredFieldsStruct(ListGetAt(storyFormIDList,i));
StructAppend(rtnStruct,reqFldStruct,1);
}
return rtnStruct;
var fieldQuery = queryNew("temp");
var rtnStruct = structNew();
var itm = 1;
var thisFieldKey = "";
var thisField = "";
var thisFieldID = 0;
var fieldData = StructNew();
// Get the Element Query by the formID
if( arguments.formID GT 0 )
{
// get the field query for this element
fieldQuery = application.npsStory.ceData.getElementFieldsByFormID(arguments.formID);
// loop through the query and build the default structure
for( itm=1; itm lte fieldQuery.recordCount; itm=itm+1 )
{
thisFieldID = fieldQuery.fieldID[itm];
thisFieldKey = LCASE("FIC_" & arguments.formID & "_" & thisFieldID);
fieldData = application.npsStory.ceData.getFieldDefaultValueFromID(thisFieldID);
// replace the FIC_ from the beginning
thisField = ReplaceNoCase(fieldQuery.fieldName[itm], "FIC_", "", "all");
// add this field in
if ( StructKeyExists(fieldData,"REQUIRED") AND fieldData.REQUIRED EQ "yes" )
{
rtnStruct[thisFieldKey] = StructNew();
if ( StructKeyExists(fieldData,"type") )
rtnStruct[thisFieldKey]["type"] = fieldData.type;
if ( StructKeyExists(fieldData,"label") )
rtnStruct[thisFieldKey]["label"] = fieldData.label;
if ( LEN(TRIM(thisField)) )
rtnStruct[thisFieldKey]["name"] = thisField;
}
}
}
return rtnStruct;
var formID = 0;
var rtnStruct = structNew();
if ( LEN(TRIM(arguments.ceName)) )
formID = application.npsStory.ceData.getFormIDByCEName(arguments.ceName);
if ( IsNumeric(formID) AND formID GT 0 )
rtnStruct = requiredFieldsStruct(formID=formID);
return rtnStruct;
var rtnStruct = structNew();
var subsiteQry = application.npsStory.csData.getSubsiteQueryByID(arguments.subsiteID);
if ( StructKeyExists(subsiteQry,"name") )
rtnStruct.subsiteName = subsiteQry["name"][1];
if ( StructKeyExists(subsiteQry,"subsiteID") )
rtnStruct.subsiteID = subsiteQry["subsiteID"][1];
if ( StructKeyExists(subsiteQry,"subsiteURL") )
rtnStruct.subsiteURL = subsiteQry["subsiteURL"][1];
if ( StructKeyExists(subsiteQry,"subsiteDir") )
rtnStruct.subsiteDir = subsiteQry["subsiteDir"][1];
return rtnStruct;
var rtnStr = "";
var subsiteStruct = getSubsiteStructBySubsiteID(arguments.subsiteID);
if ( StructKeyExists(subsiteStruct,"subsiteURL") )
rtnStr = subsiteStruct["subsiteURL"];
return rtnStr;
var rtnStruct = arguments.elementData;
var i = 1;
var rKey = "";
for ( i=1; i LTE ListLen(arguments.removeFieldList); i=i+1 ) {
rKey = ListGetAt(arguments.removeFieldList,i);
// if the key exists remove it fromt element data structure
if ( StructKeyExists(rtnStruct,rKey) )
StructDelete(rtnStruct,rKey);
}
return rtnStruct;
var findStr = "<[^>]*>";
return REREPLACE(arguments.str,findStr,arguments.replaceStr,'all');
return server.commonspot.udf.html.unescape(arguments.str);
var bad_chars="/,\,*,&,%,$,¿,Æ,Ç,Ð,Ñ,Ý,Þ,ß,æ,ç,ð,ñ,÷,ø,ý,þ,ÿ";
var good_chars="-,-,-,-,-,-,-,AE,C,D,N,Y,I,B,ae,c,o,n,-,o,y,1,y";
var scrubbed="";
var b = "0";
// A's
for (b = 192; b LTE 197; b++) {
bad_chars=listAppend(bad_chars,CHR(b));
good_chars=listAppend(good_chars,"A");
}
// a's
for (b = 224; b LTE 229; b++) {
bad_chars=listAppend(bad_chars,CHR(b));
good_chars=listAppend(good_chars,"a");
}
// E's
for (b = 200; b LTE 203; b++) {
bad_chars=listAppend(bad_chars,CHR(b));
good_chars=listAppend(good_chars,"E");
}
// e's
for (b = 232; b LTE 235; b++) {
bad_chars=listAppend(bad_chars,CHR(b));
good_chars=listAppend(good_chars,"e");
}
// I's
for (b = 204; b LTE 207; b++) {
bad_chars=listAppend(bad_chars,CHR(b));
good_chars=listAppend(good_chars,"I");
}
// i's
for (b = 236; b LTE 239; b++) {
bad_chars=listAppend(bad_chars,CHR(b));
good_chars=listAppend(good_chars,"i");
}
// 0's
for (b = 210; b LTE 216; b++) {
bad_chars=listAppend(bad_chars,CHR(b));
good_chars=listAppend(good_chars,"O");
}
// o's
for (b = 242; b LTE 246; b++) {
bad_chars=listAppend(bad_chars,CHR(b));
good_chars=listAppend(good_chars,"o");
}
// U's
for (b = 217; b LTE 220; b++) {
bad_chars=listAppend(bad_chars,CHR(b));
good_chars=listAppend(good_chars,"U");
}
// u's
for (b = 249; b LTE 252; b++) {
bad_chars=listAppend(bad_chars,CHR(b));
good_chars=listAppend(good_chars,"u");
}
if ( arguments.fileName eq "" )
return "";
else
return replace(replace(ReplaceList(trim(arguments.fileName), bad_chars, good_chars)," ","_","all"),"'","","all");
var isDifferent = false;
var isEqual = compareStructData(structDataA=arguments.structDataA,structDataB=arguments.structDataB,excludeKeyList=arguments.excludeKeyList);
if ( NOT isEqual )
isDifferent = true;
return isDifferent;
var isEqual = false;
var i=1;
var currentKey = "";
// Remove the Primary Keys before doing compare
for ( i=1;i LTE ListLen(arguments.excludeKeyList);i=i+1 ) {
currentKey = ListGetAt(arguments.excludeKeyList,i);
if ( LEN(TRIM(currentKey)) )
{
if ( StructKeyExists(arguments.structDataA,currentKey) )
StructDelete(arguments.structDataA,currentKey);
if ( StructKeyExists(arguments.structDataB,currentKey) )
StructDelete(arguments.structDataB,currentKey);
}
}
// Check the entire object because it is faster.
if ( arguments.structDataA.EQUALS(arguments.structDataB) )
isEqual = true;
return isEqual;
var isDefferent = false;
var listDifferences = listDiff(list1=arguments.list1,list2=arguments.list2,delimiters=arguments.delimiters);
if ( ListLen(listDifferences) )
isDefferent = true;
return isDefferent;
var listReturn = "";
var position = 1;
var value = "";
//checking list1
for(position = 1; position LTE ListLen(arguments.list1,arguments.delimiters); position = position + 1) {
value = ListGetAt(arguments.list1, position , arguments.delimiters );
if (ListFindNoCase(arguments.list2, value , arguments.delimiters ) EQ 0)
listReturn = ListAppend(listReturn, value , arguments.delimiters );
}
//checking list2
for(position = 1; position LTE ListLen(arguments.list2,arguments.delimiters); position = position + 1) {
value = ListGetAt(arguments.list2, position , arguments.delimiters );
if (ListFindNoCase(arguments.list1, value , arguments.delimiters ) EQ 0)
listReturn = ListAppend(listReturn, value , arguments.delimiters );
}
return listReturn;
var retStr = arguments.list;
if ( NOT listFindNoCase(arguments.list,arguments.value,arguments.delimiters) )
retStr = listAppend(arguments.list,arguments.value,arguments.delimiters);
return retStr;