Package org.drools.repository

Examples of org.drools.repository.ModuleItem


     */
    public String loadSourcePackage(String packageName,
                                    String packageVersion,
                                    boolean isLatest,
                                    OutputStream out) throws IOException {
        ModuleItem item = null;
        if ( isLatest ) {
            item = repository.loadModule( packageName );
            ModuleAssembler moduleAssembler = ModuleAssemblerManager.getModuleAssembler(item.getFormat(), item, null);
            String drl = moduleAssembler.getCompiledSource();
            out.write( drl.getBytes() );
            out.flush();
            return packageName + ".drl";
        } else {
            item = repository.loadModuleSnapshot( packageName,
                                                   packageVersion );
            ModuleAssembler moduleAssembler = ModuleAssemblerManager.getModuleAssembler(item.getFormat(), item, null);
            String drl = moduleAssembler.getCompiledSource();
            out.write( drl.getBytes() );
            out.flush();
            return packageName + "_" + URLEncoder.encode( packageVersion,
                                                          "UTF-8" ) + ".drl";
View Full Code Here


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

    /**
     * This will return the last time the package was built.
     */
    public long getLastModified(String name,
                                String version) {
        ModuleItem item = null;
        if ( version.equals( "LATEST" ) ) {
            item = repository.loadModule( name );
        } else {
            item = repository.loadModuleSnapshot( name,
                                                   version );
        }
        return item.getLastModified().getTimeInMillis();
    }
View Full Code Here

    public String loadSourceAsset(String packageName,
                                  String packageVersion,
                                  boolean isLatest,
                                  String assetName,
                                  ByteArrayOutputStream out) throws IOException {
        ModuleItem pkg = null;
        if ( isLatest ) {
            pkg = repository.loadModule( packageName );
        } else {
            pkg = repository.loadModuleSnapshot( packageName,
                                                  packageVersion );
        }

        AssetItem item = pkg.loadAsset( assetName );
        ContentHandler handler = ContentManager.getHandler( item.getFormat() );
        StringBuilder stringBuilder = new StringBuilder();
        if ( handler.isRuleAsset() ) {

            BRMSPackageBuilder builder = new BRMSPackageBuilder();
View Full Code Here

                                helper.isLatest(),
                                out);
                    }
                } else if (helper.isDocumentation()) {

                    ModuleItem pkg = rulesRepository.loadModule(helper.getPackageName());

                    GuvnorDroolsDocsBuilder builder;
                    try {
                        builder = GuvnorDroolsDocsBuilder.getInstance(pkg);
                    } catch (DroolsParserException e) {
                        throw new ServletException("Could not parse the rule package.");

                    }

                    fileName = "documentation.pdf";

                    builder.writePDF(out);

                } else if (helper.isPng()) {
                    ModuleItem pkg = rulesRepository.loadModule(helper.getPackageName());
                    AssetItem asset = pkg.loadAsset(helper.getAssetName());

                    fileName = fileManagerService.loadFileAttachmentByUUID(asset.getUUID(),
                            out);
                } else {
                    if (req.getRequestURI().endsWith("SCENARIOS")) {
                        fileName = "TestScenariosResult.txt";
                        doRunScenarios(helper,
                                out);
                    } else if (req.getRequestURI().endsWith("ChangeSet.xml")) {
                        String url = req.getRequestURL().toString().replace("/ChangeSet.xml",
                                "");
                        fileName = "ChangeSet.xml";
                        String xml = "";
                        xml += "<change-set xmlns='http://drools.org/drools-5.0/change-set'\n";
                        xml += "    xmlns:xs='http://www.w3.org/2001/XMLSchema-instance'\n";
                        xml += "    xs:schemaLocation='http://drools.org/drools-5.0/change-set http://anonsvn.jboss.org/repos/labs/labs/jbossrules/trunk/drools-api/src/main/resources/change-set-1.0.0.xsd' >\n";
                        xml += "    <add>\n ";
                        xml += "        <resource source='" + url + "' type='PKG' />\n";
                        xml += "    </add>\n";
                        xml += "</change-set>";
                        out.write(xml.getBytes());
                    } else if (req.getRequestURI().endsWith("MODEL")) {
                        ModuleItem pkg = rulesRepository.loadModule(helper.getPackageName());
                        AssetItemIterator it = pkg.listAssetsByFormat(AssetFormats.MODEL);
                        BufferedInputStream inputFile = null;
                        byte[] data = new byte[1000];
                        int count = 0;
                        int numberOfAssets = 0;
                        while (it.hasNext()) {
                            it.next();
                            numberOfAssets++;
                        }

                        if (numberOfAssets == 0) {
                            res.setContentType("text/html");
                            PrintWriter outEM = res.getWriter();
                            outEM.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 " +
                                    "Transitional//EN\">\n" +
                                    "<HTML>\n" +
                                    "<HEAD><TITLE>Empty POJO Model(jar)</TITLE></HEAD>\n" +
                                    "<BODY>\n" +
                                    "<H1>EMPTY MODEL</H1>\n" +
                                    "</BODY></HTML>");
                            return;
                        }

                        if (numberOfAssets > 1) {
                            fileName = "Model.zip";
                            inputFile = new BufferedInputStream(zipModel(pkg));
                            while ((count = inputFile.read(data, 0, 1000)) != -1) {
                                out.write(data, 0, count);
                            }

                            inputFile.close();
                        } else {
                            fileName = "ModelJar.jar";
                            inputFile = new BufferedInputStream(zipModel(pkg));
                            while ((count = inputFile.read(data, 0, 1000)) != -1) {
                                out.write(data, 0, count);
                            }

                            inputFile.close();

                        }


                    } else if (req.getRequestURI().contains("/SpringContext/")) {

                        String uri = req.getRequestURI();
                        int lastIndexOfSlash = uri.lastIndexOf('/');
                        String assetName = uri.substring(lastIndexOfSlash + 1);
                        fileName = assetName + ".xml";

                        ModuleItem pkg = rulesRepository.loadModule(helper.getPackageName());
                        AssetItem asset = pkg.loadAsset(assetName);
                        out.write(asset.getBinaryContentAsBytes());

                    } else {
                        fileName = fileManagerService.loadBinaryPackage(helper.getPackageName(),
                                helper.getVersion(),
View Full Code Here

        });
    }

    private void doRunScenarios(PackageDeploymentURIHelper helper,
                                ByteArrayOutputStream out) throws IOException {
        ModuleItem pkg;
        if (helper.isLatest()) {
            pkg = rulesRepository.loadModule(helper.getPackageName());
        } else {
            pkg = rulesRepository.loadModuleSnapshot(helper.getPackageName(),
                    helper.getVersion());
View Full Code Here

    @LoggedIn
    public void rebuildPackages() throws SerializationException {
        Iterator<ModuleItem> pkit = rulesRepository.listModules();
        StringBuilder errs = new StringBuilder();
        while (pkit.hasNext()) {
            ModuleItem pkg = pkit.next();
            try {
                BuilderResult builderResult = this.buildPackage(pkg.getUUID(),
                        true);
                if (builderResult != null) {
                    errs.append("Unable to build package name [").append(pkg.getName()).append("]\n");
                    StringBuilder buf = createStringBuilderFrom(builderResult);
                    log.warn(buf.toString());
                }
            } catch (Exception e) {
                e.printStackTrace();
                log.error("An error occurred building package [" + pkg.getName() + "]\n");
                errs.append("An error occurred building package [").append(pkg.getName()).append("]\n");
            }
        }
    }
View Full Code Here

    }

    @WebRemote
    @LoggedIn
    public Module loadModule(String uuid) {
        ModuleItem moduleItem = rulesRepository.loadModuleByUUID(uuid);
        // the uuid passed in is the uuid of that deployment bundle, not the
        // module uudi.
        // we have to figure out the module name.
        serviceSecurity.checkSecurityIsPackageReadOnlyWithPackageName(moduleItem.getName());
        return repositoryModuleOperations.loadModule(moduleItem);
    }
View Full Code Here

    public void rebuildSnapshots() throws SerializationException {
        serviceSecurity.checkSecurityIsAdmin();

        Iterator<ModuleItem> pkit = rulesRepository.listModules();
        while (pkit.hasNext()) {
            ModuleItem pkg = pkit.next();
            String[] snaps = rulesRepository.listModuleSnapshots(pkg.getName());
            for (String snapName : snaps) {
                ModuleItem snap = rulesRepository.loadModuleSnapshot(pkg.getName(),
                        snapName);
                BuilderResult builderResult = this.buildPackage(snap.getUUID(),
                        true);
                if (builderResult.hasLines()) {
                    StringBuilder stringBuilder = createStringBuilderFrom(builderResult);
                    throw new DetailedSerializationException("Unable to rebuild snapshot [" + snapName,
                            stringBuilder.toString() + "]");
View Full Code Here

        serviceSecurity.checkSecurityIsPackageDeveloperWithPackageName(moduleName);

        String[] snaps = rulesRepository.listModuleSnapshots(moduleName);
        SnapshotInfo[] snapshotInfos = new SnapshotInfo[snaps.length];
        for (int i = 0; i < snaps.length; i++) {
            ModuleItem moduleItem = rulesRepository.loadModuleSnapshot(moduleName,
                    snaps[i]);
            snapshotInfos[i] = moduleItemToSnapshotItem(snaps[i],
                    moduleItem);
        }
        return snapshotInfos;
View Full Code Here

TOP

Related Classes of org.drools.repository.ModuleItem

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.