Using HTTP POST to import a solution to the repository

Questions, tips and tricks and techniques for scripting in Servoy

Using HTTP POST to import a solution to the repository

Postby antonio » Sat Oct 28, 2006 11:25 pm

REPOSTED

With Servoy Developer 2, it was not possible to access the import pages on servoy-admin using HTTP POST methods. With V3 that's now possible, opening the opportunity to automate imports to the repository.

Based on Jan Aleman's previous posting, http://forum.servoy.com/viewtopic.php?t=6051 I've expanded the code to push a new solution into the repository. It's useful for those sites running Servoy Offline, where you don't want the end users to have direct access to the repository nor the admin pages. The parameters and comments are based on the source for http://localhost:8080/servoy-admin/solutions/import

A couple of important points
- the method mustn't be in the solution you are importing to the repository. Run it from another solution.
- You need Servoy 3.1 at least (the HTTP plugin on earlier versions didn't support this method)


Code: Select all
var SolutionRelease = application.getSolutionRelease();
var SolutionName = application.getSolutionName()

var L_Poster, L_HttpResult, L_HttpCode, L_TmpFile,L_TmpSiNo, L_AddParam ;
  L_TmpFile = plugins.file.convertStringToJSFile('C:/Program Files/Servoy3/solutions/MySolution2.servoy');
  L_TmpSiNo = L_TmpFile.exists();

if ( L_TmpSiNo == true )
{

   //Import file...
   L_Poster     = plugins.http.getPoster('http://localhost:8080/servoy-admin/solutions/import');
   L_AddParam  = L_Poster.addFile('if','file',L_TmpFile);
   L_AddParam  = L_Poster.addParameter('submit','Import!');
   
   //General options...
   L_AddParam  = L_Poster.addParameter('ac','1'); // 1 = Activate new release of imported solution and modules
   L_AddParam  = L_Poster.addParameter('os','1'); // 1 = Overwrite repository styles with import version
   L_AddParam  = L_Poster.addParameter('om','1'); // 1 = Overwrite repository media with import version
   L_AddParam  = L_Poster.addParameter('og','1'); // 1 = Overwrite repository group security settings with import version
   
   L_AddParam  = L_Poster.addParameter('fs','0'); // 1 = Override auto enter types to the auto enter types contained in the import version.
   //WARNING: This may break other solutions using the same tables, or cause tables to use nonexistent dbidentity or dbsequence sequences or other database auto enter types!

   L_AddParam  = L_Poster.addParameter('ak','0'); // 1 = Allow reserved SQL keywords as table or column names (will fail unless supported by the backend database)
   L_AddParam  = L_Poster.addParameter('sd','0'); // 1 = Import solution sample data
   L_AddParam  = L_Poster.addParameter('id','0'); // 1 = Import internationalization
   L_AddParam  = L_Poster.addParameter('io','0'); // 1 = Insert new internationalization (i18n) keys only
   
   //User import options...
   L_AddParam  = L_Poster.addParameter('up','1');
   // 0 = Do not import users contained in import
   // 1 = Create nonexisting users and add existing users to groups specified in import
   // 2 = Overwrite existing users completely (USE WITH CARE)
   L_AddParam  = L_Poster.addParameter('aa','1'); // 1 = Allow users to be added to the Administrators group
   
   // Merging options   - if merging
//   L_AddParam  = L_Poster.addParameter('ms','0'); // Merge solution if revision information is available, and when a merge conflict arises use:
//   L_AddParam  = L_Poster.addParameter('ul','0'); //  0 = repository version; 1 = import version
   
   // or Merging options   - if not merging
   L_AddParam  = L_Poster.addParameter('ms','1'); // Do not merge solution, and:
   L_AddParam  = L_Poster.addParameter('of','1'); //  overwrite repository forms with import version
   L_AddParam  = L_Poster.addParameter('df','1'); //       delete repository forms which do not exist in import version
   
   // DO POST   
   L_HttpCode   = L_Poster.doPost(AdminUsername, AdminPassword);
   L_HttpResult = L_Poster.getPageData();
   if (utils.stringPatternCount(L_HttpResult, "Import successful...") > 0  )

   {
      plugins.dialogs.showInfoDialog( "Success!",  "Update successfully completed. Click OK to continue",  "OK")
      application.closeSolution("MySolution") // to close the updater and re-open MySolution
   }
   else
   {
      // an error occurred, error handling here
      plugins.dialogs.showErrorDialog( "ERROR",  "Import failed",  "OK")
   }
}
Tony
Servoy 8 - 2022.03 LTS
antonio
 
Posts: 640
Joined: Sun Apr 02, 2006 2:14 am
Location: Australia

Re: Using HTTP POST to import a solution to the repository

Postby dpearce » Sat May 15, 2010 5:39 pm

Tony,

I have just implemented this for 3.5.12 and my solution as it has the advantage of doing table updates as well.

My only issue is that once the post has executed the update solution sort of goes dead. It doesnt close on the Application.close function and load the main app up. and any script it tries to execute apart from the success dialogue just come up with errors. lots of null pointers. It as if the solution stays open, but its not really there!

Did you find this and is there anyway around it, as it would be nice to update my user tables and then close the updater and open the main solution.

David
dpearce
 
Posts: 469
Joined: Sun Dec 03, 2006 11:53 am

Re: Using HTTP POST to import a solution to the repository

Postby antonio » Sun May 16, 2010 2:34 pm

Hi David,

I've never tried it in 3.5.x or later, so I can't be sure, but I recall seeing something similar in 3.1.x, so I decided to show a dialog explaining the need to restart, then application.exit()
Tony
Servoy 8 - 2022.03 LTS
antonio
 
Posts: 640
Joined: Sun Apr 02, 2006 2:14 am
Location: Australia

Re: Using HTTP POST to import a solution to the repository

Postby dpearce » Sun May 16, 2010 2:52 pm

Thanks tony,

yes I did this on my mac version saying you might have to restart, hoping it may be a mac thing.

Now struggling with Windows, as webservices dont seem to be on as standard on Vista!! and i cant even see easily where to switch it on!!!

David
dpearce
 
Posts: 469
Joined: Sun Dec 03, 2006 11:53 am

Re: Using HTTP POST to import a solution to the repository

Postby rogel » Mon Jan 23, 2012 12:25 am

dpearce wrote:Thanks tony,

yes I did this on my mac version saying you might have to restart, hoping it may be a mac thing.

Now struggling with Windows, as webservices dont seem to be on as standard on Vista!! and i cant even see easily where to switch it on!!!

David


Executing the code below gives me the html source of "import solution" screen. Can anyone help me what's missing?

Thanks!

Code: Select all
function importsolution(event) {
   application.output("start importsolution");
   
   var responseBody = null
   var client = plugins.http.createNewHttpClient();
   //Create a new request of specified type.
   var L_Poster = client.createPostRequest(application.getServerURL()+"/servoy-admin/solutions/import");
//Import file...
   var L_AddParam  = L_Poster.addParameter('submit','Import!');
   var importFile = 'C:/rogel/samplesolution.servoy';
   L_Poster.addFile('if','file', importFile);
   //General options...
   L_Poster.addParameter('emm','1'); // 1 = Enter  maintenance mode
   L_Poster.addParameter('ac','1'); // 1 = Activate new release of imported solution and modules
   L_Poster.addParameter('os','1'); // 1 = Overwrite repository styles with import version
   L_Poster.addParameter('om','1'); // 1 = Overwrite repository media with import version
   L_Poster.addParameter('og','1'); // 1 = Overwrite repository group security settings with import version
   
   L_Poster.addParameter('clean','0'); // 1 = Clean import
   L_Poster.addParameter('fs','0'); // 1 = Override existing sequence type definitions (in repository) with the sequence types contained in the import file.
   L_Poster.addParameter('useq','0'); // 1 = Update sequences for all tables on all servers used by the imported solution and modules.
   L_Poster.addParameter('fd','0'); // 1 = Override existing default values (in repository) with the default values contained in the import file.

   L_Poster.addParameter('ak','0'); // 1 = Allow reserved SQL keywords as table or column names (will fail unless supported by the backend database)
   L_Poster.addParameter('dm','1'); // 1 = Allow data model (database) changes
   L_Poster.addParameter('dmc','0'); // 1 = Display data model (database) changes
   L_Poster.addParameter('sd','0'); // 1 = Import solution sample data
   L_Poster.addParameter('id','0'); // 1 = Import internationalization
   L_Poster.addParameter('io','0'); // 1 = Insert new internationalization (i18n) keys only

   //User import options...
   L_Poster.addParameter('up','1');

   L_Poster.addParameter('aa','1'); // 1 = Allow users to be added to the Administrators group

   // or Merging options   - if not merging
   L_Poster.addParameter('ms','0'); // Do not merge solution, and:
   L_Poster.addParameter('of','1'); //  overwrite repository forms with import version
   L_Poster.addParameter('df','1'); //       delete repository forms which do not exist in import version

  var response = L_Poster.executeRequest();
   application.output("response="+response.getResponseBody());
}
rogel
 
Posts: 264
Joined: Mon Jul 04, 2011 9:09 am


Return to Methods

Who is online

Users browsing this forum: No registered users and 5 guests