var elements = ""; var thisElement = structNew(); var result = structNew(); var contentStruct = structNew(); var contentUpdateResponse = ""; var msg = ""; var logFile = ""; var error = ""; var ws = ""; var logStruct = structNew(); var logArray = arrayNew(1); // construct the CCAPI object variables.ccapi.initCCAPI(); result.contentUpdated = false; result.msg = "CCAPI Populate Content Error"; try { elements = variables.ccapi.getElements(); ws = variables.ccapi.getWS(); // get the settings for this element if ( isStruct(elements) and structKeyExists(elements, arguments.elementName) ) { // set up local variable for the element thisElement = elements[arguments.elementName]; // if there is no subsite default to 1 if( not structKeyExists(thisElement, "subsiteID") ) thisElement["subsiteID"] = 1; //2010-12-09 - RAK - If they forced the pageID set it if(arguments.forceSubsiteID neq -1){ thisElement["subsiteID"] = arguments.forceSubsiteID; }else if( structKeyExists(arguments.data, "subsiteID")){ //Otherwise check to see if subsiteID has been passed into data (signifying a local custom element) thisElement["subsiteID"] = arguments.data.subsiteID; } // assume global custom element and use default subsiteID // login for the first time or to the subsite where the new page was created if( variables.ccapi.loggedIn() eq 'false' or ( thisElement["subsiteID"] neq variables.ccapi.getSubsiteID() ) ) variables.ccapi.login(thisElement["subsiteID"]); //2010-12-09 - RAK - If they forced the pageID set it if(arguments.forcePageID neq -1){ thisElement["pageID"] = arguments.forcePageID; }else if( structKeyExists(arguments.data, "pageID") ){ //Otherwise check to see if the data passed in for this element contains "pageID" thisElement["pageID"] = arguments.data.pageID; } // clear locks before starting variables.ccapi.clearLock(thisElement["pageID"]); // construct specific data for the content creation API contentStruct.pageID = thisElement["pageID"]; if( structKeyExists(thisElement, "controlID") ) contentStruct.controlID = thisElement["controlID"]; else contentStruct.controlName = thisElement["controlName"]; // if we find the option to submit change in the data if( structKeyExists(arguments.data, "submitChange") ) contentStruct.submitChange = arguments.data.submitChange; else contentStruct.submitChange = "1"; // if we find the comment for the submission in the data struct if( structKeyExists(arguments.data, "submitChangeComment") ) contentStruct.submitChange_comment = arguments.data.submitChangeComment; else contentStruct.submitChange_comment = "Submit data for Custom element through API"; // Following structure contains the data. The structure keys are the 'field names' contentStruct.data = arguments.data; // Call CCAPI to add/update textblock if( thisElement["elementType"] eq "textblock") { // update textblock contentUpdateResponse = ws.populateTextblock(ssid=variables.ccapi.getSSID(), sParams=contentStruct); } if( thisElement["elementType"] eq "custom" ) { // update custom element contentUpdateResponse = ws.populateCustomElement(ssid=variables.ccapi.getSSID(), sParams=contentStruct); // check to see if update wasn't successful if( listFirst(contentUpdateResponse, ":") neq "Success" ) { // clear locks after completing update variables.ccapi.clearLock(thisElement["pageID"]); // If update wasn't successful then login again to the default subsite specified in the config xml file if( thisElement["subsiteID"] neq variables.ccapi.getSubsiteID() ) { variables.ccapi.login(thisElement["subsiteID"]); // TODO: do we need this logging? //logStruct.msg = "#request.formattedTimestamp# - Relogging into #thisElement['subsiteID']#"; //logStruct.logFile = 'populate_content.log'; //arrayAppend(logArray, logStruct); } else variables.ccapi.login(); // Now try it again after logging in contentUpdateResponse = ws.populateCustomElement(ssid=variables.ccapi.getSSID(), sParams=contentStruct); // TODO: do we need this logging? //logStruct.msg = "#request.formattedTimestamp# - 2ND ATTEMPT: contentUpdateResponse: #contentUpdateResponse#"; //logStruct.logFile = 'populate_content.log'; //arrayAppend(logArray, logStruct); } } // TODO handle debugging for texblock update call if( listFirst(contentUpdateResponse, ":") eq "Success" ) { result.contentUpdated = true; result.msg = contentUpdateResponse; logStruct.msg = "#request.formattedTimestamp# - Element Updated/Created: #thisElement['elementType']# [#arguments.elementName#]. ContentUpdateResponse: #contentUpdateResponse#"; logStruct.logFile = 'CCAPI_populate_content.log'; arrayAppend(logArray, logStruct); } else { result.msg = contentUpdateResponse; // comma separated for parsing // 'date','pageID','contentID','subsiteID','title','error' error = listRest(contentUpdateResponse, ":"); logStruct.msg = "#request.formattedTimestamp# - Error updating element: #thisElement['elementType']# [#arguments.elementName#]. Error recorded: #error#"; logStruct.logFile = 'CCAPI_populate_content_error.log'; arrayAppend(logArray, logStruct); } // clear locks after completing update variables.ccapi.clearLock(thisElement["pageID"]); } else // logging for the element name not existing { logStruct.msg = "#request.formattedTimestamp# - Element name does not exist in configuration: #arguments.elementName#"; logStruct.logFile = "CCAPI_populate_content_error.log"; arrayAppend(logArray, logStruct); } if( variables.ccapi.loggingEnabled() and arrayLen(logArray) ) variables.utils.bulkLogAppend(logArray); } catch ( ANY e ) { // Error caught, send back the error message result.contentUpdated = false; result.msg = e.message; // Log the error message also logStruct.msg = "#request.formattedTimestamp# - Error [Message: #e.message#] [Details: #e.Details#]"; logStruct.logFile = "CCAPI_populate_content_error.log"; arrayAppend(logArray, logStruct); variables.utils.bulkLogAppend(logArray); } // Logout variables.ccapi.logout(); // clear locks before starting //variables.ccapi.clearLock(thisElement["pageID"]);