Package org.drools.guvnor.server.util

Examples of org.drools.guvnor.server.util.ClassicDRLImporter


     */
    @Restrict("#{identity.loggedIn}")
    public String 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 );
            DroolsHeader.updateDroolsHeader( ClassicDRLImporter.mergeLines( DroolsHeader.getDroolsHeader( pkg ),
                                                                                     imp.getPackageHeader() ),
                                                      pkg );
            existing = true;
        } else {
            pkg = repository.createPackage( packageName,
                                            "<imported>" );
            DroolsHeader.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 );
View Full Code Here


     */
    @LoggedIn
    public String importClassicDRL(InputStream drlStream,
                                   String packageName) throws IOException,
                                                      DroolsParserException {
        ClassicDRLImporter imp = new ClassicDRLImporter( drlStream );
        ModuleItem pkg = null;

        if ( packageName == null ) {
            packageName = imp.getPackageName();
        }

        if ( packageName == null || "".equals( packageName ) ) {
            throw new IllegalArgumentException( "Missing package name." );
        }

        boolean existing = repository.containsModule( packageName );

        // Check if the package is archived
        if ( existing && repository.isModuleArchived( packageName ) ) {
            // Remove the package so it can be created again.
            ModuleItem item = repository.loadModule( packageName );
            item.remove();
            existing = false;
        }

        if ( existing ) {
            pkg = repository.loadModule( packageName );
            DroolsHeader.updateDroolsHeader( ClassicDRLImporter.mergeLines( DroolsHeader.getDroolsHeader( pkg ),
                                                                                     imp.getPackageHeader() ),
                                                      pkg );
            existing = true;
        } else {
            pkg = repository.createModule( packageName,
                                            "<imported>" );
            DroolsHeader.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 );
View Full Code Here

     * @param packageName Name for this package. Overrides the one in the DRL.
     */
    @LoggedIn
    public String importClassicDRL(InputStream drlInputStream,
                                   String packageName) {
        ClassicDRLImporter imp;
        try {
            imp = new ClassicDRLImporter(drlInputStream);
        } catch (DroolsParserException e) {
            throw new IllegalArgumentException(
                    "Could not parse the drlInputStream for package (" + packageName + "): " + e.getMessage(), e);
        }
        ModuleItem pkg = null;

        if ( packageName == null ) {
            packageName = imp.getPackageName();
        }

        if ( packageName == null || "".equals( packageName ) ) {
            throw new IllegalArgumentException( "Missing package name." );
        }

        boolean existing = repository.containsModule( packageName );

        // Check if the package is archived
        if ( existing && repository.isModuleArchived( packageName ) ) {
            // Remove the package so it can be created again.
            ModuleItem item = repository.loadModule( packageName );
            item.remove();
            existing = false;
        }

        if ( existing ) {
            pkg = repository.loadModule( packageName );
            DroolsHeader.updateDroolsHeader( ClassicDRLImporter.mergeLines( DroolsHeader.getDroolsHeader( pkg ),
                                                                                     imp.getPackageHeader() ),
                                                      pkg );
            existing = true;
        } else {
            pkg = repository.createModule( packageName,
                                            "<imported>" );
            DroolsHeader.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 );
View Full Code Here

     * @param packageName Name for this package. Overrides the one in the DRL.
     */
    @LoggedIn
    public String importClassicDRL(InputStream drlInputStream,
                                   String packageName) {
        ClassicDRLImporter imp;
        try {
            imp = new ClassicDRLImporter(drlInputStream);
        } catch (DroolsParserException e) {
            throw new IllegalArgumentException(
                    "Could not parse the drlInputStream for package (" + packageName + "): " + e.getMessage(), e);
        }
        ModuleItem pkg = null;

        if ( packageName == null ) {
            packageName = imp.getPackageName();
        }

        if ( packageName == null || "".equals( packageName ) ) {
            throw new IllegalArgumentException( "Missing package name." );
        }

        boolean existing = repository.containsModule( packageName );

        // Check if the package is archived
        if ( existing && repository.isModuleArchived( packageName ) ) {
            // Remove the package so it can be created again.
            ModuleItem item = repository.loadModule( packageName );
            item.remove();
            existing = false;
        }

        if ( existing ) {
            pkg = repository.loadModule( packageName );
            DroolsHeader.updateDroolsHeader( ClassicDRLImporter.mergeLines( DroolsHeader.getDroolsHeader( pkg ),
                                                                                     imp.getPackageHeader() ),
                                                      pkg );
            existing = true;
        } else {
            pkg = repository.createModule( packageName,
                                            "<imported>" );
            DroolsHeader.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 );
View Full Code Here

     */
    @LoggedIn
    public String importClassicDRL(InputStream drlStream,
                                   String packageName) throws IOException,
                                                      DroolsParserException {
        ClassicDRLImporter imp = new ClassicDRLImporter( drlStream );
        ModuleItem pkg = null;

        if ( packageName == null ) {
            packageName = imp.getPackageName();
        }

        if ( packageName == null || "".equals( packageName ) ) {
            throw new IllegalArgumentException( "Missing package name." );
        }

        boolean existing = repository.containsModule( packageName );

        // Check if the package is archived
        if ( existing && repository.isModuleArchived( packageName ) ) {
            // Remove the package so it can be created again.
            ModuleItem item = repository.loadModule( packageName );
            item.remove();
            existing = false;
        }

        if ( existing ) {
            pkg = repository.loadModule( packageName );
            DroolsHeader.updateDroolsHeader( ClassicDRLImporter.mergeLines( DroolsHeader.getDroolsHeader( pkg ),
                                                                                     imp.getPackageHeader() ),
                                                      pkg );
            existing = true;
        } else {
            pkg = repository.createModule( packageName,
                                            "<imported>" );
            DroolsHeader.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 );
View Full Code Here

    @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 );
View Full Code Here

    @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 );
View Full Code Here

public class ClassicDRLImporterTest {

    @Test
    public void testStandardDRL() throws Exception {

        ClassicDRLImporter imp = new ClassicDRLImporter( getDrl( "sample_legacy.drl" ) );
        assertEquals( "foo",
                      imp.getPackageName() );
        assertEquals( 2,
                      imp.getAssets().size() );

        assertEquals( "blah",
                      imp.getAssets().get( 0 ).name );
        assertEquals( "cha",
                      imp.getAssets().get( 1 ).name );

        System.err.println( imp.getPackageHeader() );

        assertTrue( imp.getPackageHeader().indexOf( "import goo.wee" ) > -1 );
        assertTrue( imp.getPackageHeader().indexOf( "package" ) == -1 );

        assertFalse( imp.isDSLEnabled() );

        assertEqualsIgnoreWhitespace( "when Whee() then goo();",
                                      imp.getAssets().get( 0 ).content );
        assertEqualsIgnoreWhitespace( "when Sup() then ka();",
                                      imp.getAssets().get( 1 ).content );
        assertTrue( imp.getAssets().get( 0 ).content.indexOf( " Whee()" ) > -1 );

    }
View Full Code Here

    }

    @Test
    public void testStandardWithQuotes() throws Exception {
        ClassicDRLImporter imp = new ClassicDRLImporter( getDrl( "sample_legacy_quotes.drl" ) );
        assertEquals( "foo",
                      imp.getPackageName() );
        assertEquals( 1,
                      imp.getAssets().size() );
        assertEquals(-1, imp.getAssets().get(0).name.indexOf("'"));
    }
View Full Code Here

        //        Matcher m = p.matcher("function void fooBar() {");
        //        assertTrue(m.matches());
        //        System.err.println(m.group());
        //        assertEquals("fooBar", m.group(1));

        ClassicDRLImporter imp = new ClassicDRLImporter( getDrl( "sample_legacy_functions.drl" ) );
        assertFalse( imp.isDSLEnabled() );

        assertEquals( 7,
                      imp.getAssets().size() );
        assertEquals( AssetFormats.FUNCTION,
                      imp.getAssets().get( 0 ).format );
        assertEquals( AssetFormats.FUNCTION,
                      imp.getAssets().get( 1 ).format );

        assertEquals( "goo1",
                      imp.getAssets().get( 0 ).name );
        assertEqualsIgnoreWhitespace( "function void goo1() { //do something ! { yeah } }",
                                      imp.getAssets().get( 0 ).content );

        assertEquals( "goo2",
                      imp.getAssets().get( 1 ).name );
        assertEqualsIgnoreWhitespace( "function String goo2(String la) { //yeah man ! return \"whee\"; }",
                                      imp.getAssets().get( 1 ).content );

        assertEquals( "goo3",
                      imp.getAssets().get( 2 ).name );
        assertEqualsIgnoreWhitespace( "function String goo3() { return \"HELLO\"; }",
                                      imp.getAssets().get( 2 ).content );

        assertEquals( "goo4",
                      imp.getAssets().get( 3 ).name );
        assertEqualsIgnoreWhitespace( "function String goo4() { if( true ) { return \"HELLO\"; } }",
                                      imp.getAssets().get( 3 ).content );

        assertEquals( "goo6",
                      imp.getAssets().get( 4 ).name );
        assertEqualsIgnoreWhitespace( "function String goo6() { return \"HELLO\"; /* } */ /* } } } */ }",
                                      imp.getAssets().get( 4 ).content );

        assertEquals( AssetFormats.DRL,
                      imp.getAssets().get( 5 ).format );
        assertEquals( AssetFormats.DRL,
                      imp.getAssets().get( 6 ).format );
        assertNotNull( imp.getAssets().get( 6 ).content );

    }
View Full Code Here

TOP

Related Classes of org.drools.guvnor.server.util.ClassicDRLImporter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.