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