Package org.drools.guvnor.server.files

Examples of org.drools.guvnor.server.files.RestAPI


        doAuthorizedAction(req,
                res,
                new Command() {
                    public void execute() throws Exception {
                        res.setContentType("text/html");
                        RestAPI api = getAPI();
                        String comment = req.getHeader("Checkin-Comment");
                        api.post(req.getRequestURI(),
                                req.getInputStream(),
                                (comment != null) ? comment : "");
                        res.getWriter().write("OK");
                    }
                });
View Full Code Here


            IOException {
        doAuthorizedAction(req,
                res,
                new Command() {
                    public void execute() throws Exception {
                        RestAPI api = getAPI();
                        String qString = req.getQueryString();
                        String ur = req.getRequestURI();
                        if (qString != null && qString.length() > 0) {
                            ur = ur + '?' + qString;
                        }
                        Response apiRes = api.get(ur);
                        res.setContentType("application/x-download");
                        res.setHeader("Content-Disposition",
                                "attachment; filename=data;");
                        apiRes.writeData(res.getOutputStream());
                        res.getOutputStream().flush();
View Full Code Here

        doAuthorizedAction(req,
                res,
                new Command() {
                    public void execute() throws Exception {
                        res.setContentType("text/html");
                        RestAPI api = getAPI();
                        String comment = req.getHeader("Checkin-Comment");
                        Calendar lastMod = getModified(req.getHeader("Last-Modified"));
                        api.put(req.getRequestURI(),
                                lastMod,
                                req.getInputStream(),
                                (comment != null) ? comment : "");
                        res.getWriter().write("OK");
                    }
View Full Code Here

        doAuthorizedAction(req,
                res,
                new Command() {
                    public void execute() throws Exception {
                        res.setContentType("text/html");
                        RestAPI api = getAPI();
                        api.delete(req.getRequestURI());
                        res.getWriter().write("OK");
                    }
                });
    }
View Full Code Here

        ModuleItem pkg = repo.createModule("testRestGetSpaces", "", ModuleItem.MODULE_FORMAT);
        AssetItem ass = pkg.addAsset("some space", "");
        ass.updateFormat("drl");
        ass.checkin("hey");

        RestAPI api = new RestAPI(repo);
       api.setAssetValidator(new AssetValidator());
        String url = "packages/testRestGetSpaces";
        Response res = api.get(url);

        ByteArrayOutputStream out = new ByteArrayOutputStream();
        res.writeData(out);

        assertTrue(new String(out.toByteArray()).indexOf("\\ ") > -1);

        url = "packages/testRestGetSpaces/some space.drl";
        res = api.get(url);
        assertNotNull(res.lastModified);

    }
View Full Code Here

        asset3.checkin("");

        assertTrue(asset3.isBinary());
        assertFalse(asset1.isBinary());

        RestAPI api = new RestAPI(repo);
        api.setAssetValidator(new AssetValidator());

        //this should get us the package configuration

        String url = "packages/testRestGetBasics/.package";
        Response res = api.get(url);
        assertNotNull(res.lastModified);
        assertEquals(pkg.getLastModified(), res.lastModified);
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        res.writeData(out);

        String dotPackage = new String(out.toByteArray());
        assertEquals(pkg.getStringProperty(ModuleItem.HEADER_PROPERTY_NAME), dotPackage);

        res = api.get("packages/testRestGetBasics");
        assertTrue(res instanceof Text);
        assertNotNull(res.lastModified);
        out = new ByteArrayOutputStream();
        res.writeData(out);
        String listing = new String(out.toByteArray());
        assertNotNull(listing);

        Properties p = new Properties();
        p.load(new ByteArrayInputStream(out.toByteArray()));
        assertEquals(3, p.size());

        assertTrue(p.containsKey("asset1.drl"));
        assertTrue(p.containsKey("asset2.xml"));
        assertTrue(p.containsKey("asset3.xls"));

        assertNotNull(p.getProperty("asset1.drl"));
        String prop = p.getProperty("asset1.drl");
        System.err.println(prop);
        String[] dt = prop.split(",");


        SimpleDateFormat sdf = RestAPI.getISODateFormat();
        Date d= sdf.parse(dt[0]);
        assertNotNull(d);

        assertEquals(sdf.format(asset1.getLastModified().getTime()), dt[0]);
        assertEquals(asset1.getVersionNumber(), Long.parseLong(dt[1]));


        //try text
        res = api.get("packages/testRestGetBasics/asset1.drl");
        assertTrue(res instanceof Text);
        out = new ByteArrayOutputStream();
        assertNotNull(res.lastModified);
        assertTrue(res.lastModified.getTime().after(sdf.parse("2000-04-14T18:36:37")));
        res.writeData(out);

        String s = new String(out.toByteArray());
        assertEquals(asset1.getContent(), s);


        //now binary
        res = api.get("packages/testRestGetBasics/asset3.xls");
        assertTrue(res instanceof Binary);
        out = new ByteArrayOutputStream();
        assertNotNull(res.lastModified);
        assertTrue(res.lastModified.getTime().after(sdf.parse("2000-04-14T18:36:37")));
        res.writeData(out);
View Full Code Here

    }

    @Test
    public void testGetMisc() throws Exception {
        RulesRepository repo = RepositorySessionUtil.getRepository();
        RestAPI api = new RestAPI(repo);
        api.setAssetValidator(new AssetValidator());
        api.get("");
        api.get("/");
        api.get("packages");
        api.get("snapshots");
        api.get("snapshots/defaultPackage");
    }
View Full Code Here

        asset1.updateFormat("drl");
        asset1.checkin("This is something");

        assertEquals(1, asset1.getVersionNumber());

        RestAPI api = new RestAPI(repo);
        api.setAssetValidator(new AssetValidator());
        Response res = api.get("packages/testRestGetVersionHistory/asset1.drl?version=all");
        ByteArrayOutputStream out = new ByteArrayOutputStream();

        res.writeData(out);
        String d = new String(out.toByteArray());
        //System.err.println(d);
        assertTrue(d.indexOf(",alan_parsons,This is something") > 0);


        asset1.updateContent("new content");
        asset1.checkin("This is another");

        res = api.get("packages/testRestGetVersionHistory/asset1.drl?version=all");
        out = new ByteArrayOutputStream();

        res.writeData(out);
        d = new String(out.toByteArray());
        System.err.println(d);
        assertTrue(d.indexOf(",alan_parsons,This is something") > 0);
        assertTrue(d.indexOf(",alan_parsons,This is another") > 0);
        assertTrue(d.indexOf("1=") > -1);
        assertTrue(d.indexOf("2=") > -1);
        assertEquals(-1, d.indexOf("0="));

        res = api.get("packages/testRestGetVersionHistory/asset1.drl?version=1");
        out = new ByteArrayOutputStream();

        res.writeData(out);
        d = new String(out.toByteArray());
        assertEquals("this is content", d);


        res = api.get("packages");
        res = api.get("packages?version=all");

        res = api.get("snapshots");
        res = api.get("snapshots?version=all");

    }
View Full Code Here

        asset2.updateFormat("drl");
        asset2.checkin("This is another");

        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();

        resp.writeData(out);
        d = new String(out.toByteArray());
        assertEquals("", d);
View Full Code Here

        RulesRepository repo = RepositorySessionUtil.getRepository();
        ModuleItem pkg = repo.createModule("testRestPost", "", ModuleItem.MODULE_FORMAT);
        pkg.updateStringProperty("This is some header", ModuleItem.HEADER_PROPERTY_NAME);
        repo.save();

        RestAPI api = new RestAPI(repo);
        api.setAssetValidator(new AssetValidator());
        ByteArrayInputStream in = new ByteArrayInputStream("abc".getBytes());
        api.post("/packages/testRestPost/asset1.drl", in, "a comment");

        AssetItem a = pkg.loadAsset("asset1");
        assertFalse(a.isBinary());
        assertEquals("drl", a.getFormat());
        assertEquals("abc", a.getContent());
        assertEquals("a comment", a.getCheckinComment());


        in = new ByteArrayInputStream("qed".getBytes());
        api.post("/packages/testRestPost/asset2.xls", in, "a comment");
        a = pkg.loadAsset("asset2");

        assertTrue(a.isBinary());
        String s = new String(a.getBinaryContentAsBytes());
        assertEquals("qed", s);
View Full Code Here

TOP

Related Classes of org.drools.guvnor.server.files.RestAPI

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.