Package org.drools.repository

Examples of org.drools.repository.AssetItem


                                                String[] path,
                                                List<String> result) {
        Iterator<AssetItem> it = loadPackageSnapshotFromRepository(repository,
                path).getAssets();
        while (it.hasNext()) {
            AssetItem asset = it.next();
            if (!asset.isArchived()) {
                addNameAndFormat(result,
                        asset);
            }
        }
    }
View Full Code Here


    private void handleReadOnlyGlobalAreaPackages(RulesRepository repository,
                                                  String[] path,
                                                  List<String> result) {
        Iterator<AssetItem> it = loadGlobalAreaFromRepository(repository).getAssets();
        while (it.hasNext()) {
            AssetItem asset = it.next();
            if (!asset.isArchived()) {
                addNameAndFormat(result,
                        asset);
            }
        }
    }
View Full Code Here

                                        List<String> result) {
        PackageItem pkg = loadPackageFromRepository(repository,
                path[1]);
        Iterator<AssetItem> it = pkg.getAssets();
        while (it.hasNext()) {
            AssetItem asset = it.next();
            if (!asset.isArchived()) {
                addNameAndFormat(result,
                        asset);
            }
        }
    }
View Full Code Here

                            path),
                    0);
        } else if (path.length == 4) {
            PackageItem pkg = loadPackageSnapshotFromRepository(repository,
                    path);
            AssetItem asset;
            try {
                asset = loadAssetItemFromPackageItem(pkg,
                        path[3]);
            } catch (Exception e) {
                return null;
            }
            return createStoredObject(uri,
                    asset,
                    asset.getContentLength());
        }
        throw new UnsupportedOperationException();

    }
View Full Code Here

            return createStoredObject(uri,
                    packageItem,
                    0);
        }

        AssetItem asset;
        try {
            asset = loadAssetItemFromPackageItem(packageItem,
                    path[2]);
        } catch (Exception e) {
            return null;
        }
        return createStoredObject(uri,
                asset,
                asset.getContentLength());
    }
View Full Code Here

                    loadGlobalAreaFromRepository(repository),
                    0);
            so.setFolder(isFolder(uri));
            return so;
        } else if (path.length == 2) {
            AssetItem asset;
            try {
                asset = loadAssetItemFromGlobalArea(repository,
                        path);
            } catch (Exception e) {
                return null;
            }
            return createStoredObject(uri,
                    asset,
                    asset.getContentLength());
        } else if (path.length == 3) {
            AssetItem asset;
            try {
                asset = loadAssetItemFromGlobalArea(repository,
                        path);
            } catch (Exception e) {
                return null;
            }
            return createStoredObject(uri,
                    asset,
                    asset.getContentLength());
        }
        throw new UnsupportedOperationException();
    }
View Full Code Here

                //delete asset
                if (path[2].startsWith("._")) {
                    WebDAVImpl.osxDoubleData.remove(uri);
                    return;
                }
                AssetItem item = loadAssetItemFromPackageItem(packageItem,
                        path[2]);
                item.archiveItem(true);
                item.checkin("");
            } else {
                //delete package
                packageItem.archiveItem(true);
                packageItem.checkin("");
            }
        } else if (isGlobalAreas(path)) {
            if (path.length == 2) {
                //delete asset
                if (path[1].startsWith("._")) {
                    WebDAVImpl.osxDoubleData.remove(uri);
                    return;
                }
                AssetItem item = loadAssetItemFromGlobalArea(repository,
                        path);
                item.archiveItem(true);
                item.checkin("");
            }
        } else {
            throw new IllegalArgumentException("Not allowed to remove this file.");
        }
View Full Code Here

                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
                return 0;
            }
            AssetItem asset = loadAssetItemFromPackage(repository,
                    path);
            if (asset.getFormat().equals("drl")) {
                try {
                    BufferedReader reader = new BufferedReader(new InputStreamReader(content));
                    StringBuilder sb = new StringBuilder();
                    String line = null;
                    while ((line = reader.readLine()) != null) {
                        if (!line.startsWith("package ")) {
                            sb.append(line).append("\n");
                        }
                    }
                    asset.updateBinaryContentAttachment(new ByteArrayInputStream(sb.toString().getBytes("UTF-8")));
                } catch (Exception e) {
                    //default
                    asset.updateBinaryContentAttachment(content);
                }
            } else {
                asset.updateBinaryContentAttachment(content);
            }
            //here we could save, or check in, depending on if enough time has passed to justify
            //a new version. Otherwise we will pollute the version history with lots of trivial versions.
            //if (shouldCreateNewVersion(asset.getLastModified())) {
            asset.checkin("<content from webdav>");
            //}
        } else if (isGlobalAreas(path)) {
            if (path[1].startsWith("._")) {
                try {
                    WebDAVImpl.osxDoubleData.put(uri,
                            IOUtils.toByteArray(content));
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
                return 0;
            }
            AssetItem asset = loadAssetItemFromGlobalArea(repository,
                    path);
            if (asset.getFormat().equals("drl")) {
                try {
                    BufferedReader reader = new BufferedReader(new InputStreamReader(content));
                    StringBuilder sb = new StringBuilder();
                    String line = null;
                    while ((line = reader.readLine()) != null) {
                        if (!line.startsWith("package ")) {
                            sb.append(line).append("\n");
                        }
                    }
                    asset.updateBinaryContentAttachment(new ByteArrayInputStream(sb.toString().getBytes("UTF-8")));
                } catch (Exception e) {
                    //default
                    asset.updateBinaryContentAttachment(content);
                }
            } else {
                asset.updateBinaryContentAttachment(content);
            }
            //here we could save, or check in, depending on if enough time has passed to justify
            //a new version. Otherwise we will pollute the version history with lots of trivial versions.
            //if (shouldCreateNewVersion(asset.getLastModified())) {
            asset.checkin("<content from webdav>");
            //}
        } else {
            throw new UnsupportedOperationException("Unable to save content to this location.");
        }
View Full Code Here

                .getFullPath(fullPath, workflowName, extension, fileName);
        fullPath = fullPath + "/" + fileName;

        try {

            AssetItem item = getFileManager().getRepository().loadAssetByUUID(uuid);

            final ByteArrayOutputStream out = new ByteArrayOutputStream();

            final JarInputStream jis = new JarInputStream(item
                    .getBinaryContentAttachment());
            JarEntry entry;
            final byte[] buf = new byte[1024];
            int len;
            while ((entry = jis.getNextJarEntry()) != null) {
View Full Code Here

        String extension = fileName.substring(fileName.indexOf('.') + 1);
        String fullPathToFolder = this.getFullPath(fullPath, workflowName,
                extension, fileName);
        fullPath = fullPathToFolder + "/" + fileName;

        AssetItem item = getFileManager().getRepository().loadAssetByUUID(uuid);

        InputStream in = item.getBinaryContentAttachment();

        String fileContent = request.getParameter("fileContent");

        ByteArrayOutputStream bais = new ByteArrayOutputStream();
        JarOutputStream jos = new JarOutputStream(bais);
        JarInputStream jis = null;

        try {
            if (in == null) {

                jos.putNextEntry(new JarEntry(fullPath));

                ByteArrayInputStream i = new ByteArrayInputStream(fileContent
                        .getBytes());

                int len = 0;
                byte[] copyBuf = new byte[1024];
                while (len != -1) {

                    len = i.read(copyBuf, 0, copyBuf.length);
                    if (len > 0) {
                        jos.write(copyBuf, 0, len);
                    }
                }

                i.close();
                jos.closeEntry();

            } else {

                jis = new JarInputStream(in);

                boolean found = false;
                JarEntry entry;
                while ((entry = jis.getNextJarEntry()) != null) {

                    jos.putNextEntry(new JarEntry(entry.getName()));

                    String name = entry.getName();
                    if (fullPath.equals(name)) {
                        found = true;

                        ByteArrayInputStream i = new ByteArrayInputStream(
                                fileContent.getBytes());

                        int len = 0;
                        byte[] copyBuf = new byte[1024];
                        while (len != -1) {

                            len = i.read(copyBuf, 0, copyBuf.length);
                            if (len > 0) {
                                jos.write(copyBuf, 0, len);
                            }
                        }

                        i.close();

                    } else {
                        int len = 0;
                        byte[] copyBuf = new byte[1024];
                        while (len != -1) {

                            len = jis.read(copyBuf, 0, copyBuf.length);
                            if (len > 0) {
                                jos.write(copyBuf, 0, len);
                            }
                        }
                    }

                    jis.closeEntry();
                    jos.closeEntry();
                }

                // If the file is not found, add it
                if (!found) {
                    jos.putNextEntry(new JarEntry(fullPath));

                    ByteArrayInputStream i = new ByteArrayInputStream(
                            fileContent.getBytes());

                    int len = 0;
                    byte[] copyBuf = new byte[1024];
                    while (len != -1) {

                        len = i.read(copyBuf, 0, copyBuf.length);
                        if (len > 0) {
                            jos.write(copyBuf, 0, len);
                        }
                    }

                    i.close();
                    jos.closeEntry();
                }
            }

            item.updateBinaryContentAttachment(new ByteArrayInputStream(bais
                    .toByteArray()));

            item.checkin("Updated " + fileName);

        } catch (IOException e) {
            throw new RulesRepositoryException(e);
        } finally {
            if (jis != null) {
View Full Code Here

TOP

Related Classes of org.drools.repository.AssetItem

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.