@Restrict("#{identity.loggedIn}")
public void importClassicDRL(InputStream drlStream,
String packageName) throws IOException,
DroolsParserException {
ClassicDRLImporter imp = new ClassicDRLImporter( drlStream );
PackageItem pkg = null;
if ( packageName == null ) {
packageName = imp.getPackageName();
}
if ( packageName == null || "".equals( packageName ) ) {
throw new IllegalArgumentException( "Missing package name." );
}
boolean existing = repository.containsPackage( packageName );
// Check if the package is archived
if ( existing && repository.isPackageArchived( packageName ) ) {
// Remove the package so it can be created again.
PackageItem item = repository.loadPackage( packageName );
item.remove();
existing = false;
}
if ( existing ) {
pkg = repository.loadPackage( packageName );
ServiceImplementation.updateDroolsHeader( ClassicDRLImporter.mergeLines( ServiceImplementation.getDroolsHeader( pkg ),
imp.getPackageHeader() ),
pkg );
existing = true;
} else {
pkg = repository.createPackage( packageName,
"<imported>" );
ServiceImplementation.updateDroolsHeader( imp.getPackageHeader(),
pkg );
}
boolean newVer = Boolean.parseBoolean( System.getProperty( "drools.createNewVersionOnImport",
"true" ) );
for ( Asset as : imp.getAssets() ) {
if ( existing && pkg.containsAsset( as.name ) ) {
AssetItem asset = pkg.loadAsset( as.name );
if ( asset.getFormat().equals( as.format ) ) {
asset.updateContent( as.content );