Package org.drools.guvnor.server.util

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


        final String EXPECTED = "declare Type1 end"
                                + "declare Type2 extends Type1 field1 : String end"
                                + "declare Type3 end"
                                + "declare Type4 extends Type3 field1 : String end";

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

        assertEquals( 2,
                      imp.getAssets().size() );
        assertEquals( AssetFormats.DRL,
                      imp.getAssets().get( 0 ).format );
        assertEquals( AssetFormats.DRL_MODEL,
                      imp.getAssets().get( 1 ).format );

        assertEquals( "Rule",
                      imp.getAssets().get( 0 ).name );
        assertEqualsIgnoreWhitespace( "when Type1() then System.out.println(\"Type1\");",
                                      imp.getAssets().get( 0 ).content );

        assertEquals( "model",
                      imp.getAssets().get( 1 ).name );
        assertEqualsIgnoreWhitespace( EXPECTED,
                                      imp.getAssets().get( 1 ).content );
    }
View Full Code Here


    }
   
    @Test
    public void testWithDSL() throws Exception {

        ClassicDRLImporter imp = new ClassicDRLImporter( getDrl( "sample_legacy_with_dsl.drl" ) );

        assertTrue( imp.isDSLEnabled() );
        assertEquals( 2,
                      imp.getAssets().size() );
        System.out.println( imp.getPackageHeader()  );
       
        assertEquals( "foo",
                      imp.getPackageName() );
        assertTrue( imp.getPackageHeader().contains( "import goo.wee" ));
        assertTrue( imp.getPackageHeader().contains( "global ka.cha" ));

        assertEqualsIgnoreWhitespace( "when ka chow then bam",
                                      imp.getAssets().get( 0 ).content );
        assertEqualsIgnoreWhitespace( "when ka chiga then ka chow",
                                      imp.getAssets().get( 1 ).content );

        Asset as = imp.getAssets().get( 0 );
        assertEquals( AssetFormats.DSL_TEMPLATE_RULE,
                      as.format );

    }
View Full Code Here

    }

    @Test
    public void testComplexExample() throws Exception {
        ClassicDRLImporter imp = new ClassicDRLImporter( getDrl( "sample_complex.drl" ) );
        assertFalse( imp.isDSLEnabled() );
        assertEquals( 2,
                      imp.getAssets().size() );

        assertTrue( DRLFileContentHandler.isStandAloneRule( imp.getAssets().get( 0 ).content ) );
    }
View Full Code Here

     */
    @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 );
        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

     */
    @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

    @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) throws IOException,
                                                       DroolsParserException {

        ClassicDRLImporter imp = new ClassicDRLImporter( drlStream );
        PackageItem pkg = null;
       
       
        String packageName = imp.getPackageName();
        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

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.