Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.drools.guvnor.server.repository;
  
  
 
This class is used to migrate version 4 ruleflow assets in a version 4 or 5 drools repository into version 5 ruleflow assets. IMPORTANT: the current code only performs the transformations if the Drools system property drools.ruleflow.port is true, just as the drools compiler only transforms version 4 ruleflows to 5 if this property is set. If a ruleflow is migrated, it is checked in as new version so that the previous version is preserved. The current code checks-in the new version as the admin user with an appropriate comment indicating that the flow has been migrated. Hover, the code could also be changed to check-in each migrated ruleflow using the credentials of the last person to check-in the ruleflow, however, in future there may be a danger that the person who last checked in the file may have lost privileges to check-in the file, so we use the admin user for now.

Author(s):
Shahad Ahmed
 
 public class MigrateRepository {
 	
 	private static final Logger log  = Logger.getLoggerMigrateRepository.class );


Returns true if the drools system property drools.ruleflow.port is true indicating that ruleflow migration should be performed.

Parameters:
repo
Returns:
true if the drools system property drools.ruleflow.port is true indicating that ruleflow migration should be performed.
Throws:
javax.jcr.RepositoryException /
 
 	public static boolean needsRuleflowMigration(RulesRepository repothrows RepositoryException {
 		String portRuleFlow = System.getProperty"drools.ruleflow.port""false" );
 		return portRuleFlow.equalsIgnoreCase("true");
 	}


Iterates through all the packages in the given repository migrating all drools 4 .rfm and .rf ruleflow assets that need to be migrated to 5. Note that archived assets, and assets in snapshots are also migrated.

Parameters:
repo
Throws:
javax.jcr.RepositoryException /
 
 	public static void migrateRuleflows(RulesRepository repothrows RepositoryException 
 	{
 		.debug("AUTO MIGRATION: Performing drools ruleflow migration...");
 
 		PackageIterator pkgs = repo.listPackages();
 		boolean performed = false;
 		while(pkgs.hasNext()) {
 			performed = true;
 			PackageItem pkg = (PackageItempkgs.next();
 
 			String[] snaps = repo.listPackageSnapshots(pkg.getName());
 			if (snaps != null) {
 				for (int i = 0; i < snaps.lengthi++) {
 					PackageItem snap = repo.loadPackageSnapshot(pkg.getName(), snaps[i]);
 				}
 			}
 		}
 
 		if (performed) {
 			.debug("AUTO MIGRATION: Drools rulesflow migration completed.");
 		}
 	}


migrate all ruleflows in the package, including archived ones. The migrated ruleflow is checked in as a new version and previous versions are not migrated. NOTE that we always try to migrate if the drools.ruleflow.port property is true, even if the repository has been migrated before. This is needed as the drools.ruleflow.port property may have been false when the repository was first migrated (i.e. the HEADER_PROPERTY_NAME above may have been migrated, but not the ruleflows). Also, all snapshot packages are updated as well.

Parameters:
pkg /
	private static void migrateRuleflows(PackageItem pkg
	{
		String portRuleFlow = System.getProperty"drools.ruleflow.port""false" );
		if ( portRuleFlow.equalsIgnoreCase"true" ) ) 
		{
			while(it.hasNext())
			{
				AssetItem item = it.next();
				String rf = item.getContent();
				try
				{
					if(RuleFlowMigrator.needToMigrateRFM(rf))
					{
						.debug("Migrating v4 RFM to v5: " + item.getName());
						rf = RuleFlowMigrator.portRFMToCurrentVersion(rf);
						item.updateContent(rf);
						item.checkin("Auto migration from ruleflow RFM version 4 to 5");
					}
					else if(RuleFlowMigrator.needToMigrateRF(rf))
                    {
                        .debug("Migrating v4 RF to v5: " + item.getName());
                        rf = RuleFlowMigrator.portRFToCurrentVersion(rf);
                        item.updateContent(rf);
                        item.checkin("Auto migration from ruleflow RF version 4 to 5");
                    }
				}
				catch (Exception ex)
				{
					.error("Ruleflow migration failed for item: " 
item.getName() + " due to " + ex);
				}
			}
		}
	}


    
This will load an iterator for assets in the given package of the given format type, including archived assets.

Parameters:
pkg The package to check
formats an array of the format types to find.
Returns:
an iterator for assets of the given format type, including archived assets. /
    		String[] formats) {
        if (formats.length == 1) {
            return pkg.queryAssets"drools:format='" + formats[0] + "'" , true);
        } else {
            String predicate = " ( ";
            for ( int i = 0; i < formats.lengthi++ ) {
                predicate = predicate + "drools:format='" + formats[i] + "'";
                if (!(i == formats.length -1 )) { predicate =  predicate + " OR "; }
            }
            predicate = predicate + " ) ";
            return pkg.queryAssetspredicate , true);
        }
    }
New to GrepCode? Check out our FAQ X