ARIS Super User Group
Register

View all
MP

Hello, everyone,

by mistake I deleted a script from Aris Cloud (Advanced).

Is there a way to recover it?

Is it possible to make a scheduled backup of all the scripts?

Thank you

Marco

by Ariene Kroeze
Posted on Mon, 09/02/2019 - 11:29
Hereby a script I've written to make a backup of all reports, macros and common files to (in my case) a folder on my e-disk.
When you run this scheduled (each day for example) than you have always a recent backup of all your scripts.
Kind regards, Ariene Kroeze


var msPath = "E:/ids-scheer/_Solutions/__BackupScripts/"
var mScriptAdminComponent = Context.getComponent("ScriptAdmin")
var gnLoc = Context.getSelectedLanguage()
var mlTeller = 0

function main(){
   

    for each (var lComponentID in [ 0,1,7] ){  // 0    =    common
                                        // 1    =    Report
                                        // 2    =    macro (??)

        var lScriptCategories = mScriptAdminComponent.getCategories(lComponentID, gnLoc)
        if (lScriptCategories.length==0){
            var lScriptInfos = mScriptAdminComponent.getScriptInfos (lComponentID, null, gnLoc)
            for each (var lScriptInfo in lScriptInfos){
                Script_HandleScript(lComponentID, null, lScriptInfo)

            }
        }else{
            for each (var lScriptCategory in lScriptCategories){
                var lScriptInfos = mScriptAdminComponent.getScriptInfos (lComponentID, lScriptCategory.getCategoryID ( ), gnLoc)
                for each (var lScriptInfo in lScriptInfos){
                    Script_HandleScript(lComponentID, lScriptCategory, lScriptInfo)
                }
            }
        }
    }
    //Dialogs.MsgBox("" + mlTeller + " backup files created/updated")
}
function Script_HandleScript(plComponent, pScriptCategory,  pScriptInfo){

    Context.writeStatus("busy with file " + mlTeller)
    var lsExt = ""

    switch (plComponent){
        case 0:
            var lsFolderName = msPath + "Common files/"
            Script_CreateFolder (lsFolderName)
            break
        case 1:

            var lsCategory = pScriptCategory.getName()
            Script_CreateFolder (msPath + "Reports")
            Script_CreateFolder (msPath + "Reports/" + lsCategory)
            var lsFolderName = msPath + "Reports/" + lsCategory + "/"
            lsExt=".arx"
            break
        case 7:
            var lsCategory = pScriptCategory.getName()
            Script_CreateFolder (msPath + "Macros" )
            Script_CreateFolder (msPath + "Macros/" + lsCategory)
            var lsFolderName = msPath + "Macros/" + lsCategory + "/"
            lsExt=".amx"
            break
        default:
            var lsFolderName = msPath + "Others/"     
            Script_CreateFolder(lsFolderName)
    }

    var lsFileLocation = lsFolderName + pScriptInfo.getName() 
    var lBytes = []
    if (pScriptInfo.isSimpleFile()){
        //var lBytes = Context.getFile(
        try{
            var lZipEntry = mScriptAdminComponent.exportFile (plComponent, pScriptInfo.getID(), pScriptInfo.getID())
            if (lZipEntry){
                lBytes = mScriptAdminComponent.exportFile (plComponent, pScriptInfo.getID(), pScriptInfo.getID()).getData()                 
            }
        }catch(ex){
            var lex = ex
            var aa=0
        }
    }else{
        lsFileLocation+=lsExt
        lBytes = mScriptAdminComponent.exportScript (plComponent, pScriptInfo.getID(), pScriptInfo.getImports())           
    }

    if (Files_WriteFileByByteArray (lsFileLocation, lBytes, true))mlTeller++

}
function Script_CreateFolder (psFolderName){
    var lbSuccess = Files_Exists(psFolderName)
    if (!lbSuccess){
        lbSuccess = Files_CreateFolder (psFolderName)
    }
    return lbSuccess
}
function Files_CreateFolder (psFolderName){
    var lbSuccess2Return = false;
    var lsFolderName = Files_GetCorrectFileName(psFolderName);
     // Create a directory; all ancestor directories must exist
    lbSuccess2Return = (new Packages.java.io.File(lsFolderName)).mkdir();
    return lbSuccess2Return;  
}
function Files_WriteFileByByteArray(psFileLocation, pByteArray, pbOverWrite){
    // write the byte content to a file
    var lbSuccess2Return =false;

    var lsFileName = Files_CheckedFilename(Files_ExtractFileName(psFileLocation));
    var lsPath2File= Files_ExtractPath(psFileLocation);
    if (Files_Exists(lsPath2File)){
        var lsFileLocation = lsPath2File + "/" + lsFileName;

        var lFile=new java.io.File(lsFileLocation);
        if(lFile.exists() && pbOverWrite){
            Files_DeleteFile(lsFileLocation)
        }
        try{
           var lFo=new java.io.FileOutputStream(lFile);
            lFo.write(pByteArray);
            lFo.close();
            lbSuccess2Return=true;
        }catch(ex){
            var lex=ex;           
        }
    }
    return lbSuccess2Return;
} 
function Files_CheckedFilename(psFileName, psReplace, psPrefix){
    var lsFileName2Return = "" + psFileName;

    var lsPrefix = "" + fTrim(psPrefix);
    if (!lsPrefix.equals(""))lsPrefix=Files_CheckedFilename(lsPrefix, psReplace,"");
    if (lsPrefix.equals(""))lsPrefix = "Report";
    var lsForbidden = "*/:?<>|" + String.fromCharCode(34);
    for (var i = 0; i<lsForbidden.length;i++){
      lsFileName2Return = lsFileName2Return.replace(lsForbidden.substr(i,1),psReplace);
    }
    lsFileName2Return=fTrim(lsFileName2Return);
    if (lsFileName2Return.equals("")){
        lsFileName2Return = lsPrefix + " " + fsNow("yyyy/MM/dd HH:mm:ss");
    }
    var lFirstChar=lsFileName2Return.substr(0,1);
    var lsNumbers="0123456789";
    if (lsNumbers.indexOf(lFirstChar)>-1){
        // filename begint met een nummer, magniet
        lsFileName2Return = lsPrefix + " " + lsFileName2Return;
    }
    return lsFileName2Return;
}
function Files_ExtractFileName (psFileName){
    var lsFileName2Return = "";
    var lsFileName = psFileName + "";
    lsFileName = Files_GetCorrectFileName(lsFileName);
    var lInstr = lsFileName.lastIndexOf("/");
    if (lInstr>=0) lsFileName=lsFileName.substr(lInstr + 1)
    lsFileName2Return = lsFileName;
    return lsFileName2Return;
} 
function Files_ExtractPath(psFileName){
    var lsPath2Return = "";
    var lsFileName = psFileName + "";
    lsFileName = Files_GetCorrectFileName(lsFileName);
    var lInstr = lsFileName.lastIndexOf("/");
    if (lInstr>=0) lsPath2Return=lsFileName.substr(0,lInstr)

    return lsPath2Return;
}

function Files_GetCorrectFileName(psFileName){
    var lsFileName2Return = psFileName;
    lsFileName2Return = (lsFileName2Return + "").replace(/\\/g,"/")+"";             
    return lsFileName2Return;
}
function Files_Exists(psFileLocation){
    var lBool2Return = false;
    var lsFileLocation = Files_GetCorrectFileName(psFileLocation);

    var lsFileNameComponents= lsFileLocation.split("/");

    if (fcIsGUID(lsFileNameComponents[0])){
        // is sprake van in Aris 9
         var lScriptAdminComponent = Context.getComponent("ScriptAdmin")
         if (fIsMissing(lScriptAdminComponent)){
             // user - not allowed to see scripts
         }else{
             var lsCatID = lsFileNameComponents[0];
             var lScriptInfos= lScriptAdminComponent.getScriptInfos (1, lsCatID, Context.getSelectedLanguage())            
             for (var i in lScriptInfos){
                 if (lScriptInfos[i].getName()+"" == lsFileNameComponents[1]){
                     lBool2Return=true;
                     break;
                 }
             }
        }
    }else{
        lBool2Return = new Packages.java.io.File(lsFileLocation).exists();
    }
    return lBool2Return;

}
function Files_DeleteFile(psFileLocation){
    var lbSuccess2Return =false;
    var lsFileLocation = Files_GetCorrectFileName(psFileLocation);
    if (Files_Exists(lsFileLocation)){
        try{
            var lbSuccess2Return = (new Packages.java.io.File(lsFileLocation))["delete"]();
        }catch(ex){
            var lex=ex;
            var aa=1;

        }
    }
    return lbSuccess2Return;
}    
function fcIsGUID(psString){
    var lbOK2Return = false;
    var i=0;

    var lsString = new String(psString + "");
    lsString=lsString.toUpperCase();

    lbOK2Return = true;
    if (lsString.length!=36){
        lbOK2Return = false;
    }else{
        lbOK2Return=true;
        for (var i=0;i<36;i++){
            if (i==8 || i==13 || i==18 || i==23){
                if (lsString.substr(i,1)!="-"){
                    lbOK2Return=false;
                    break;
                }
            }else{
                var lAsc = lsString.charCodeAt(i);
                if ((lAsc>=48 && lAsc <=57) || (lAsc>=65 && lAsc<=70)){
                    // ok!
                }else{
                    lbOK2Return=false;
                    break;
                }
            }
        }
    }
    return lbOK2Return;
}
function fTrim(psValue){
//  return ("" + psValue).trim()

    var lsValue2Return= "" + psValue;
    lsValue2Return=lsValue2Return.replace(/^ */,""); 
    lsValue2Return=lsValue2Return.replace(/ *$/,""); 
    return lsValue2Return;

}
  

main()
0
by Darren Conboy
Posted on Tue, 09/03/2019 - 19:16

In reply to by Ariene Kroeze

Hi Ariene, thanks for posting this. We've recently lost a number of scripts when a Group in our Evaluations Group was deleted by accident, so I'm very interested in getting this script to work for us.

I've replaced the file location that you had on the first line with my own file details to allow the script to build the new file structure and save the content on my work's laptop.

I'm not too sure where I should be running the script from though - I've set the context for the script as Database and Groups. When I manually run the script from a Database or Folder I get the dialogue pop ups but its not actually creating anything.

What am I missing?

BR, Darren

0
by Ariene Kroeze
Posted on Thu, 09/05/2019 - 11:53

What ARIS version do you use?

0
by Ariene Kroeze
Posted on Thu, 09/05/2019 - 12:05

The folder that must be defined in the first line of the script, must be a (shared) folder that can be accessed by the user account that runs the ARIS server and maybe by you.

Regards, Ariene

0
by Martin Schröder
Badge for 'Contributor' achievement
Posted on Fri, 09/06/2019 - 15:21

Hello Ariene,

your script is a great contribution.

You use a function fsNow("yyyy/MM/dd HH:mm:ss") to append a date to lsFileName2Return. This does not seem to be declared in the script, but elsewhere.

Is the definition of var msPath = "E:/ids-scheer/_Solutions/__BackupScripts/" with forward slashes also necessary on Windows?

Kind regards, Martin

0
by Ariene Kroeze
Posted on Mon, 09/09/2019 - 11:54
  • For the missing fsNow routine add the following code to your script:
function fsNow(psFormat){
    var lsNow2Return = ""
    var ldDate=new java.util.Date();
    var lsFormat = fValueIfMissing(psFormat,"yyyy/MM/dd HH:mm:ss");    
    if (lsFormat=="")lsFormat = "yyyy/MM/dd HH:mm:ss";
    var lDateFormat = java.text.SimpleDateFormat(lsFormat);
    lsNow2Return=lDateFormat.format(ldDate);
    return lsNow2Return;
}
function fIsMissing(pOptionalPar){
    var lbIsMissing2Return = false;
    if (pOptionalPar==undefined || pOptionalPar ==null){
        lbIsMissing2Return = true;        
    }
    return lbIsMissing2Return;
}
function fValueIfMissing(pOptional,pDefault){
    return (fIsMissing(pOptional) ? pDefault: pOptional)
}
  
  • Windows allows you to use forward slashes in stead of backward ones in file path names. In Javascript you have to add an extra backward slash before each backward slash, because the backward slash is a special character in Javascript.
0

Featured achievement

Genius
You like to help others solve their problems by answering questions.
Recent Unlocks
  • KF
  • KH
  • RG
  • Profile picture for user Vee_ARIS
  • Profile picture for user smarty
  • PacMan

Leaderboard

|
icon-arrow-down icon-arrow-cerulean-left icon-arrow-cerulean-right icon-arrow-down icon-arrow-left icon-arrow-right icon-arrow icon-back icon-close icon-comments icon-correct-answer icon-tick icon-download icon-facebook icon-flag icon-google-plus icon-hamburger icon-in icon-info icon-instagram icon-login-true icon-login icon-mail-notification icon-mail icon-mortarboard icon-newsletter icon-notification icon-pinterest icon-plus icon-rss icon-search icon-share icon-shield icon-snapchat icon-star icon-tutorials icon-twitter icon-universities icon-videos icon-views icon-whatsapp icon-xing icon-youtube icon-jobs icon-heart icon-heart2 aris-express bpm-glossary help-intro help-design Process_Mining_Icon help-publishing help-administration help-dashboarding help-archive help-risk icon-knowledge icon-question icon-events icon-message icon-more icon-pencil forum-icon icon-lock