Package org.drools.repository

Examples of org.drools.repository.AssetItem


    @Path("{packageName}/assets/{assetName}/binary")
    @Produces(MediaType.APPLICATION_OCTET_STREAM)
    public Response getAssetBinary(@PathParam("packageName") String packageName, @PathParam("assetName") String assetName) {
        try {
            //Throws RulesRepositoryException if the package or asset does not exist
            AssetItem asset = rulesRepository.loadModule(packageName).loadAsset(assetName);
            String fileName = asset.getName() + "." + asset.getFormat();
            return Response.ok(asset.getBinaryContentAttachment()).header("Content-Disposition", "attachment; filename=" + fileName).build();
        } catch (Exception e) {
            throw new WebApplicationException(e);
        }
    }
View Full Code Here


    public void changeAssetPackage(String uuid,
                                   String newPackage,
                                   String comment) {
        serviceSecurity.checkSecurityIsPackageDeveloperWithPackageName(newPackage);
       
        AssetItem item = rulesRepository.loadAssetByUUID( uuid );

        //Perform house-keeping for when an Asset is removed from a package
        attachmentRemoved( item );

        log.info("USER:" + getCurrentUserName() + " CHANGING PACKAGE OF asset: [" + uuid + "] to [" + newPackage + "]");
View Full Code Here

    @WebRemote
    @LoggedIn
    public void promoteAssetToGlobalArea(String uuid) {
        serviceSecurity.checkSecurityIsPackageDeveloperWithPackageName( RulesRepository.GLOBAL_AREA );
        AssetItem item = rulesRepository.loadAssetByUUID( uuid );
        serviceSecurity.checkSecurityIsPackageDeveloperWithPackageName(item.getModuleName());

        //Perform house-keeping for when an Asset is removed from a module
        attachmentRemoved( item );

        log.info("USER:" + getCurrentUserName() + " CHANGING MODULE OF asset: [" + uuid + "] to [ globalArea ]");
View Full Code Here

    @WebRemote
    @LoggedIn
    public String renameAsset(String uuid,
                              String newName) {
        AssetItem item = rulesRepository.loadAssetByUUID(uuid);
        serviceSecurity.checkIsPackageDeveloperOrAnalyst(item);

        return repositoryAssetOperations.renameAsset(uuid,
                newName);
    }
View Full Code Here

    @Path("{packageName}/assets/{assetName}/source")
    @Produces(MediaType.TEXT_PLAIN)
    public String getAssetSource(@PathParam("packageName") String packageName, @PathParam("assetName") String assetName) {
        try {
            //Throws RulesRepositoryException if the package or asset does not exist
            AssetItem asset = rulesRepository.loadModule(packageName).loadAsset(assetName);
            return asset.getContent();
        } catch (Exception e) {
            throw new WebApplicationException(e);
        }
    }
View Full Code Here

    @WebRemote
    @LoggedIn
    public void removeAsset(String uuid) {
        try {
            AssetItem item = rulesRepository.loadAssetByUUID(uuid);
            serviceSecurity.checkSecurityIsPackageDeveloperWithPackageUuid(item.getModule().getUUID());

            item.remove();
            rulesRepository.save();
        } catch (RulesRepositoryException e) {
            log.error("Unable to remove asset.",
                    e);
            throw e;
View Full Code Here

                format = formatExtension != null ? formatExtension.getSimpleExtension(Translator.VALUE) : null;
                ExtensibleElement categoryExtension = metadataExtension.getExtension(Translator.CATEGORIES);
                initialCategory = formatExtension != null ? categoryExtension.getSimpleExtension(Translator.VALUE) : null;
            }

            AssetItem ai = rulesRepository.loadModule(packageName).addAsset(entry.getTitle(), entry.getSummary(), initialCategory, format);
           
            //The categories are not saved by addAsset(). Need to force it here.
            rulesRepository.getSession().save();
           
            return toAssetEntryAbdera(ai, uriInfo);
View Full Code Here

                extension = assetName.substring(assetName.lastIndexOf(".")+1);
            } else {
                fileName = assetName;               
            }           
           
            AssetItem ai = rulesRepository.loadModule(packageName).addAsset(fileName, "");
            ai.checkout();
            ai.updateBinaryContentAttachmentFileName(fileName);
            if(extension != null) {
                ai.updateFormat(extension);
            }
            ai.updateBinaryContentAttachment(is);
            ai.getModule().updateBinaryUpToDate(false);
            ai.checkin("update binary");
            rulesRepository.save();
            return toAssetEntryAbdera(ai, uriInfo);
        } catch (Exception e) {
            //catch RulesRepositoryException and other exceptions. For example when the package already exists.
            throw new WebApplicationException(e);
View Full Code Here

        return assets.toArray(new Asset[assets.size()]);
    }

    private void archiveOrUnarchiveAsset(String uuid,
                                         boolean archive) {
        AssetItem item = rulesRepository.loadAssetByUUID(uuid);
        serviceSecurity.checkIsPackageDeveloperOrAnalyst(item);
        if (item.getModule().isArchived()) {
            throw new RulesRepositoryException("The package [" + item.getModuleName() + "] that asset [" + item.getName() + "] belongs to is archived. You need to unarchive it first.");
        }
        log.info("USER:" + getCurrentUserName() + " ARCHIVING asset: [" + item.getName() + "] UUID: [" + item.getUUID() + "] ");
        try {
            ContentHandler handler = getContentHandler(item);
            if (handler instanceof ICanHasAttachment) {
                ((ICanHasAttachment) handler).onAttachmentRemoved(item);
            }
        } catch (IOException e) {
            log.error("Unable to remove asset attachment",
                    e);
        }
        item.archiveItem(archive);
        ModuleItem pkg = item.getModule();
        pkg.updateBinaryUpToDate(false);
        RuleBaseCache.getInstance().remove(pkg.getUUID());
        if (archive) {
            item.checkin("archived");
        } else {
            item.checkin("unarchived");
        }
        push("packageChange",
                pkg.getName());
    }
View Full Code Here

                ExtensibleElement stateExtension = metadataExtension.getExtension(Translator.STATE);
                state = stateExtension != null ? stateExtension.getSimpleExtension(Translator.VALUE) : null;
            }

            //Throws RulesRepositoryException if the package or asset does not exist
            AssetItem ai = rulesRepository.loadModule(packageName).loadAsset(assetName);
            //Update asset
            ai.checkout();
            ai.updateTitle(assetEntry.getTitle());
            ai.updateDescription(assetEntry.getSummary());
            if (format != null) {
                ai.updateFormat(format);
            }
           
            //REVISIT: What if the client really wants to set content to ""?
            if (assetEntry.getContent() != null && !"".equals(assetEntry.getContent())) {
                ai.updateContent(assetEntry.getContent());
            }
            if (categories != null) {
                ai.updateCategoryList(categories);
            }
            if (state != null) {
                ai.updateState(state);
            }
            ai.checkin("Check-in (summary): " + assetEntry.getSummary());
            rulesRepository.save();
        } catch (Exception e) {
            throw new WebApplicationException(e);
        }
    }
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.