Package org.drools.guvnor.server.files.Response

Examples of org.drools.guvnor.server.files.Response.Text


    }

    private Response loadContent(String pkgName, String resourceFile) throws UnsupportedEncodingException {
        ModuleItem pkg = rulesRepository.loadModule(pkgName);
        if (resourceFile.equals(".package")) {
            Text r = new Response.Text();
            r.lastModified = pkg.getLastModified();
            r.data = pkg.getStringProperty( ModuleItem.HEADER_PROPERTY_NAME );
            return r;
        } else {
            if (resourceFile.indexOf("?version=") > -1) {
                String[] v = resourceFile.split("\\?version\\=");
                String version = v[1];
                String assetName = AssetItem.getAssetNameFromFileName(v[0])[0];
                AssetItem asset = pkg.loadAsset(assetName);
                if (asset.isArchived()) {
                    Text r = new Text();
                    r.data = "";
                    return r;
                }
                if (version.equals("all")) {
                    AssetHistoryIterator it =  asset.getHistory();
                    StringBuilder buf = new StringBuilder();
                    while(it.hasNext()) {

                        AssetItem h = it.next();

                        if (h.getVersionNumber() != 0) {
                            String checkinComment = h.getCheckinComment();
                            //String lastMo ... hmm what is needed?
                            String lastMofiedBy = h.getLastContributor();
                            if (lastMofiedBy == null || lastMofiedBy.equals("")) {
                                lastMofiedBy = asset.getCreator();
                            }
                            SimpleDateFormat sdf = getISODateFormat();
                            Calendar lastModDate = h.getLastModified();
                            if (lastModDate == null ) {
                                lastModDate = asset.getCreatedDate();
                            }
                            String lastModifiedOn = sdf.format(lastModDate.getTime());
                            buf.append(h.getVersionNumber());
                            buf.append("=");
                            buf.append(lastModifiedOn + "," + lastMofiedBy + "," + checkinComment);
                            if (it.hasNext()) {
                                buf.append('\n');
                            }
                        }

                    }
                    Text r = new Text();
                    r.lastModified = asset.getLastModified();
                    r.data = buf.toString();
                    return r;
                } else {
                    long versionNumber = Long.parseLong(version);
                    AssetHistoryIterator it =  asset.getHistory();
                    while (it.hasNext()) {
                        AssetItem h = it.next();
                        if (h.getVersionNumber() == versionNumber) {
                            return buildAssetContentResponse(pkg, h);
                        }
                    }
                    //hmm... we didn't find it
                    Text r = new Text();
                    r.lastModified = asset.getLastModified();
                    r.data = "Unknown version number : " + versionNumber;
                    return r;
                }
            } else {
View Full Code Here


            Binary r = new Response.Binary();
            r.lastModified = asset.getLastModified();
            r.stream = asset.getBinaryContentAttachment();
            return r;
        } else {
            Text r = new Response.Text();
            r.lastModified = pkg.getLastModified();
            r.data = asset.getContent();
            return r;
        }
    }
View Full Code Here

                sb.append(a.getName().replaceAll("\\s", "\\\\ ") + "." + a.getFormat() + "=" + sdf.format(lastMod.getTime()) + "," + a.getVersionNumber());
                sb.append('\n');
            }
        }

        Text r = new Response.Text();
        r.lastModified = pkg.getLastModified();
        r.data = sb.toString();
        return r;
    }
View Full Code Here

        assertEquals(1, asset1.getVersionNumber());

        RestAPI api = new RestAPI(repo);
        api.setAssetValidator(new AssetValidator());
        Text res = (Text) api.get("packages/testVersionHistoryAndArchived");
        System.err.println(res.data);
        assertTrue(res.data.indexOf("asset2.drl") > -1);

        asset2.archiveItem(true);
        asset2.checkin("");

        res = (Text) api.get("packages/testVersionHistoryAndArchived");
        assertEquals(-1, res.data.indexOf("asset2.drl"));


        Response resp = api.get("packages/testVersionHistoryAndArchived/asset1.drl?version=all");
        ByteArrayOutputStream out = new ByteArrayOutputStream();

        res.writeData(out);
        String d = new String(out.toByteArray());
        assertNotNull(d);

        resp = api.get("packages/testVersionHistoryAndArchived/asset2.drl?version=all");
        out = new ByteArrayOutputStream();
View Full Code Here

TOP

Related Classes of org.drools.guvnor.server.files.Response.Text

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.