Package org.apache.stanbol.rules.manager.changes

Examples of org.apache.stanbol.rules.manager.changes.RemoveRecipe


                    ruleseq.add(IRI.create(seq.replace(" ", "").trim()));

                // Add the new rule to the end
                ruleseq.add(IRI.create(rule));
                // Remove the old recipe
                RemoveRecipe remove = new RemoveRecipe(ruleStore);
                boolean ok = remove.removeRecipe(IRI.create(recipe));

                if (!ok){
                    ResponseBuilder rb = Response.status(Status.CONFLICT);
                    MediaType mediaType = MediaTypeUtil.getAcceptableMediaType(headers, null);
                    if (mediaType != null) rb.header(HttpHeaders.CONTENT_TYPE, mediaType);
                    addCORSOrigin(servletContext, rb, headers);
                    return rb.build();
                }

                // Add the recipe with the new rule
                AddRecipe newadd = new AddRecipe(ruleStore);
                ok = newadd.addRecipe(IRI.create(recipe), ruleseq, desc);

                if (ok) {
                    ruleStore.saveOntology();
                    ResponseBuilder rb = Response.ok();
                    MediaType mediaType = MediaTypeUtil.getAcceptableMediaType(headers, null);
                    if (mediaType != null) rb.header(HttpHeaders.CONTENT_TYPE, mediaType);
                    addCORSOrigin(servletContext, rb, headers);
                    return rb.build();
                } else {
                    ResponseBuilder rb = Response.status(Status.NO_CONTENT);
                    MediaType mediaType = MediaTypeUtil.getAcceptableMediaType(headers, null);
                    if (mediaType != null) rb.header(HttpHeaders.CONTENT_TYPE, mediaType);
                    addCORSOrigin(servletContext, rb, headers);
                    return rb.build();
                }
            }

            // The rule is added to the store and to the recipe
            if ((kres_syntax != null) & (description != null)) {
                // Get the rule
                AddRule inrule = new AddRule(ruleStore);
                boolean ok = inrule.addRule(IRI.create(rule), kres_syntax, description);
                if (!ok) {
                    log.error("Problem to add: " + rule);
                    ResponseBuilder rb = Response.status(Status.CONFLICT);
                    MediaType mediaType = MediaTypeUtil.getAcceptableMediaType(headers, null);
                    if (mediaType != null) rb.header(HttpHeaders.CONTENT_TYPE, mediaType);
                    addCORSOrigin(servletContext, rb, headers);
                    return rb.build();
                }

                // Get the recipe
                GetRecipe getrecipe = new GetRecipe(ruleStore);
                this.map = getrecipe.getRecipe(IRI.create(recipe));
                if (map != null) {
                    this.desc = getrecipe.getDescription(IRI.create(recipe));

                    if (desc == null){
                        ResponseBuilder rb = Response.status(Status.NOT_FOUND);
                        MediaType mediaType = MediaTypeUtil.getAcceptableMediaType(headers, null);
                        if (mediaType != null) rb.header(HttpHeaders.CONTENT_TYPE, mediaType);
                        addCORSOrigin(servletContext, rb, headers);
                        return rb.build();
                    }
                } else {
                    ResponseBuilder rb = Response.status(Status.NOT_FOUND);
                    MediaType mediaType = MediaTypeUtil.getAcceptableMediaType(headers, null);
                    if (mediaType != null) rb.header(HttpHeaders.CONTENT_TYPE, mediaType);
                    addCORSOrigin(servletContext, rb, headers);
                    return rb.build();
                }

                String[] sequence = map.get(IRI.create(recipe)).split(",");
                Vector<IRI> ruleseq = new Vector();
                if (!sequence[0].isEmpty()) for (String seq : sequence)
                    ruleseq.add(IRI.create(seq.replace(" ", "").trim()));

                // Add the new rule to the end
                ruleseq.add(IRI.create(rule));
                // Remove the old recipe
                RemoveRecipe remove = new RemoveRecipe(ruleStore);
                ok = remove.removeRecipe(IRI.create(recipe));
                if (!ok) {
                    log.error("ERROR TO REMOVE OLD RECIPE: " + recipe);
                    ResponseBuilder rb = Response.status(Status.CONFLICT);
                    MediaType mediaType = MediaTypeUtil.getAcceptableMediaType(headers, null);
                    if (mediaType != null) rb.header(HttpHeaders.CONTENT_TYPE, mediaType);
View Full Code Here


    public Response removeRecipe(@QueryParam(value = "recipe") String recipe,
                                 @Context HttpHeaders headers) {

        try {

            RemoveRecipe instance = new RemoveRecipe(ruleStore);

            // String ID =
            // kresRuleStore.getOntology().getOntologyID().toString().replace(">","").replace("<","")+"#";

            boolean ok = instance.removeRecipe(IRI.create(recipe));

            if (!ok) {
                //return Response.status(Status.CONFLICT).build();
                ResponseBuilder rb = Response.status(Status.CONFLICT);
                rb.header(HttpHeaders.CONTENT_TYPE, MediaType.TEXT_PLAIN + "; charset=utf-8");
View Full Code Here

        // Load the example file
        LoadRuleFile load = new LoadRuleFile("./src/main/resources/RuleOntology/TestRuleFileExample.txt",
                store);
        OWLOntology owlstart = load.getStore().getOntology();
        String recipeName = owlID + "MyRecipe";
        RemoveRecipe instance = new RemoveRecipe(load.getStore());

        boolean expResult = true;
        boolean result = instance.removeRecipe(IRI.create(recipeName));
        OWLOntology owlend = instance.getStore().getOntology();

        if (result) {
            assertEquals(expResult, (owlstart.getAxiomCount() > owlend.getAxiomCount()));
            // TODO review the generated test code and remove the default call to fail.
        } else {
View Full Code Here

        // Load the example file
        LoadRuleFile load = new LoadRuleFile("./src/main/resources/RuleOntology/TestRuleFileExample.txt",
                store);
        OWLOntology owlstart = load.getStore().getOntology();
        String recipeName = "MyRecipe";
        RemoveRecipe instance = new RemoveRecipe(load.getStore());

        boolean expResult = true;
        boolean result = instance.removeRecipe(recipeName);
        OWLOntology owlend = instance.getStore().getOntology();

        if (result) {
            assertEquals(expResult, (owlstart.getAxiomCount() > owlend.getAxiomCount()));
            // TODO review the generated test code and remove the default call to fail.
        } else {
View Full Code Here

TOP

Related Classes of org.apache.stanbol.rules.manager.changes.RemoveRecipe

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.