/** * Make a new rule definition * * @param name * The name of the rule. Should be unique among rule names on the * REST server. * @param description * Text description of the rule. */ public RuleDefinition(String name, String description) { this(); this.setName(name); this.setDescription(description); }
/** * Make a new rule definition * * @param name * The name of the rule. Should be unique among rule names on the * REST server. * @param description * Text description of the rule. */ public RuleDefinition(String name, String description) { this(); this.setName(name); this.setDescription(description); }
void receiveElement(Element ruleElement) { Element nameElement = getChildByName(ruleElement, RequestConstants.RESTAPI_NS, "name"); this.setName(nameElement.getTextContent()); Element descElement = getChildByName(ruleElement, RequestConstants.RESTAPI_NS, "description"); this.setDescription(descElement.getTextContent()); Element searchElement = getChildByName(ruleElement, RequestConstants.SEARCH_NS, "search"); try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); TransformerFactory transfac = TransformerFactory.newInstance(); Transformer trans = transfac.newTransformer(); trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); trans.setOutputProperty(OutputKeys.VERSION, "1.0"); trans.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); trans.setOutputProperty(OutputKeys.INDENT, "no"); trans.transform(new DOMSource(searchElement), new StreamResult(baos)); importQueryDefinition(new BytesHandle(baos.toByteArray()) .withFormat(Format.XML)); } catch (TransformerConfigurationException e) { throw new MarkLogicIOException( "Could not get query from rule payload"); } catch (TransformerException e) { throw new MarkLogicIOException( "Could not get query from rule payload"); } receiveRuleMetadataImpl(ruleElement); }
void receiveElement(Element ruleElement) { Element nameElement = getChildByName(ruleElement, RequestConstants.RESTAPI_NS, "name"); this.setName(nameElement.getTextContent()); Element descElement = getChildByName(ruleElement, RequestConstants.RESTAPI_NS, "description"); this.setDescription(descElement.getTextContent()); Element searchElement = getChildByName(ruleElement, RequestConstants.SEARCH_NS, "search"); try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); TransformerFactory transfac = TransformerFactory.newInstance(); Transformer trans = transfac.newTransformer(); trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); trans.setOutputProperty(OutputKeys.VERSION, "1.0"); trans.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); trans.setOutputProperty(OutputKeys.INDENT, "no"); trans.transform(new DOMSource(searchElement), new StreamResult(baos)); importQueryDefinition(new BytesHandle(baos.toByteArray()) .withFormat(Format.XML)); } catch (TransformerConfigurationException e) { throw new MarkLogicIOException( "Could not get query from rule payload"); } catch (TransformerException e) { throw new MarkLogicIOException( "Could not get query from rule payload"); } receiveRuleMetadataImpl(ruleElement); }
private static void setupMatchRules() throws ResourceNotFoundException, ForbiddenUserException, FailedRequestException { RuleDefinition definition = new RuleDefinition("favorites", "Rule for testing favorited:true"); String head = "<search:search xmlns:search=\"http://marklogic.com/appservices/search\">"; String qtext1 = "<search:qtext>favorited:true</search:qtext>"; String qtext2 = "<search:qtext>favorited:false</search:qtext>"; String tail = "</search:search>"; String ruleOptions = "<search:options >" + "<search:constraint name=\"favorited\">" + "<search:value>" + "<search:element name=\"favorited\" ns=\"\"/>" + "</search:value>" + "</search:constraint>" + "</search:options>"; StringHandle textQuery = new StringHandle(head + qtext1 + ruleOptions + tail); definition.importQueryDefinition(textQuery); ruleManager.writeRule(definition); textQuery = new StringHandle(head + qtext2 + ruleOptions + tail); definition.importQueryDefinition(textQuery); definition.setName("notfavorited"); definition.setDescription("Rule for testing favorited:false"); ruleManager.writeRule(definition); }