Skip to Content.
Sympa Menu

perfsonar-dev - perfsonar: r5283 - in branches/new-structure-with-base2/ps-mdm-ls: conf src/main/java/org/perfsonar/service/lookupservice

Subject: perfsonar development work

List archive

perfsonar: r5283 - in branches/new-structure-with-base2/ps-mdm-ls: conf src/main/java/org/perfsonar/service/lookupservice


Chronological Thread 
  • From:
  • To:
  • Subject: perfsonar: r5283 - in branches/new-structure-with-base2/ps-mdm-ls: conf src/main/java/org/perfsonar/service/lookupservice
  • Date: Tue, 22 Sep 2009 06:40:53 -0400

Author: trzaszcz
Date: 2009-09-22 06:40:53 -0400 (Tue, 22 Sep 2009)
New Revision: 5283

Modified:
branches/new-structure-with-base2/ps-mdm-ls/conf/configuration.xml

branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/LSQueryAction.java
Log:
LSQueryResponse enhancement

Modified: branches/new-structure-with-base2/ps-mdm-ls/conf/configuration.xml
===================================================================
--- branches/new-structure-with-base2/ps-mdm-ls/conf/configuration.xml
2009-09-07 13:50:33 UTC (rev 5282)
+++ branches/new-structure-with-base2/ps-mdm-ls/conf/configuration.xml
2009-09-22 10:40:53 UTC (rev 5283)
@@ -194,7 +194,7 @@
mapping="org.perfsonar.base2.xml.nmwg.Parameter"/>
<element name="*"
mapping="org.perfsonar.base2.xml.Element"/>
- <element name="{http://ggf.org/ns/nmwg/query/}subject";
+ <element
name="{http://ggf.org/ns/nmwg/tools/org/perfsonar/service/lookup/xquery/1.0/}subject";

mapping="org.perfsonar.base2.xml.TextElement"/>



Modified:
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/LSQueryAction.java
===================================================================
---
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/LSQueryAction.java
2009-09-07 13:50:33 UTC (rev 5282)
+++
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/LSQueryAction.java
2009-09-22 10:40:53 UTC (rev 5283)
@@ -1,129 +1,131 @@
package org.perfsonar.service.lookupservice;

+import java.util.Collection;
+
import org.apache.log4j.Logger;
import org.perfsonar.base2.service.exceptions.PerfSONARException;
import org.perfsonar.base2.service.requesthandler.ServiceMessage;
import org.perfsonar.base2.service.storage.xml.XMLDBResult;
+import org.perfsonar.base2.service.util.ResultCodesUtil;
import org.perfsonar.base2.xml.Element;
import org.perfsonar.base2.xml.nmwg.Data;
import org.perfsonar.base2.xml.nmwg.Message;
-import org.perfsonar.base2.xml.nmwg.Metadata;
import org.perfsonar.service.lookupservice.storage.LookupServiceDAO;

/**
* Action responsible for LS Query
+ *
* @author Maciej Glowiak
- *
+ *
*/
public class LSQueryAction {

- private static final Logger logger =
Logger.getLogger(LSQueryAction.class.getName());
+ private static final Logger logger =
Logger.getLogger(LSQueryAction.class
+ .getName());

- private LookupServiceDAO dao;
-
- public LSQueryAction(LookupServiceDAO dao) {
- this.dao = dao;
- }
-
- public void performQuery(
- ServiceMessage serviceRequest, ServiceMessage serviceResponse,
- Message message, Element subject, String lsOutput)
- throws PerfSONARException {
+ private LookupServiceDAO dao;

- //native vs escaped
- // <nmwg:parameter name="lsOutput">native</nmwg:parameter>
- //if not null check if different from "escaped"
- if (lsOutput!=null) {
- if (!"escaped".equals(lsOutput)) {
- String m = "This version of LS supports only [escaped]
results of xquery (by default). You used ["+lsOutput+"] value.";
- logger.error(m);
- throw new
PerfSONARException("error/ls/output_not_accepted",m);
- }
- }
-
- //get subject query
- String query = subject.getText();
-
- logger.debug("Query=["+query+"]");
+ public LSQueryAction(LookupServiceDAO dao) {
+ this.dao = dao;
+ }

- //TEMPORARY
- //convert query, change &gt; = ">", &lt; = "<".
- //query = convertEntitiesToCharacters(query);
-
- //Performing XQuery operation on the database
- logger.debug("Perform query");
-
- /* ------------- XQuery ------------- */
-
- XMLDBResult results = dao.performXQuery(query);
-
- /* ------------- XQuery ------------- */
-
- logger.debug("Got ["+results.getElementsCount()+"] results from DB");
-
- //create ServiceEngineResponse and put there the results
- Message response = new Message();
-
- //add empty metadata block to ServiceEngineResponse
- Metadata responseMetadata = new Metadata();
-
- String metadataId = "LSQueryResponseMetadata";
- responseMetadata.setId(metadataId);
- response.addChild(responseMetadata);
-
- //add data elements to ServiceEngineResponse
- Data responseData = new Data();
- String dataId = "LSQueryResponseData";
- responseData.setId(dataId);
- responseData.setMetadataIdRef(metadataId);
-
- //iterate results, create Datum for them and put all
- //these Datum into Data
-
- for (Element e : results.getResults()) {
-
- //create new datum
- Element datum = new Element(
- "datum",
- "psservice",
-
"http://ggf.org/ns/nmwg/tools/org/perfsonar/service/1.0/";);
-
- //put result into datum
- //if it's textual value (exist:value) extract text and put as
text
- if (e.hasName("exist", "value")) datum.setText(e.getText());
- else datum.addChild(e);
-
- responseData.addChild(datum);
- }
-
- //Encapsulate Data in Response Message
- response.addChild(responseData);
-
- serviceResponse.setElement(response);
+ public void performQuery(ServiceMessage serviceRequest,
+ ServiceMessage serviceResponse, Message message,
Element subject,
+ String lsOutput) throws PerfSONARException {

- }
+ // native vs escaped
+ // <nmwg:parameter name="lsOutput">native</nmwg:parameter>
+ // if not null check if different from "escaped"
+ // if (lsOutput!=null) {
+ // if (!"escaped".equals(lsOutput)) {
+ // String m =
+ // "This version of LS supports only [escaped] results of
xquery (by default). You used ["+lsOutput+"] value.";
+ // logger.error(m);
+ // throw new
PerfSONARException("error/ls/output_not_accepted",m);
+ // }
+ // }

-
- /*
- public String convertEntitiesToCharacters(String input) {
-
- String output = input;
-
- //&lt;
- output = input.replaceAll("\\&lt\\;", "<");
- //&gt;
- output = output.replaceAll("\\&gt\\;", ">");
- //&amp;
- output = output.replaceAll("\\&amp\\;", "&");
- //&apos;
- output = output.replaceAll("\\&apos\\;", "'");
- //&quot;
- output = output.replaceAll("\\&quot\\;", "\"");
-
- return output;
-
- }
- */
-
+ // get subject query
+ String query = subject.getText();

-} //LS
+ logger.debug("Query=[" + query + "]");
+
+ // TEMPORARY
+ // convert query, change &gt; = ">", &lt; = "<".
+ // query = convertEntitiesToCharacters(query);
+
+ // Performing XQuery operation on the database
+ logger.debug("Perform query");
+
+ /* ------------- XQuery ------------- */
+
+ XMLDBResult results = dao.performXQuery(query);
+
+ /* ------------- XQuery ------------- */
+
+ logger
+ .debug("Got [" + results.getElementsCount()
+ + "] results from DB");
+
+ // create ServiceEngineResponse and put there the results
+
+ Message msg = ResultCodesUtil.generateResultMessage(
+ null, "success/ls/query");
+ Data data = (Data) msg.getChildren("data").toArray(new
Element[1])[0];
+ data.getChildren().clear();
+ msg.setId("LSQueryResponse");
+
+
+ if(results.getTotal() > 0){
+ // if there are some results
+
+ // iterate results, create Datum for them and put all
+ // these Datum into Data
+
+ for (Element e : results.getResults()) {
+
+ // create new datum
+ Element datum = createDatumElement();
+
+ // put result into datum
+ // if it's textual value (exist:value)
extract text and put as text
+ if (e.hasName("exist", "value"))
+ datum.setText(e.getText());
+ else
+ datum.addChild(e);
+
+ data.addChild(datum);
+ }
+ }else{
+ // add empty datum element
+ data.addChild(createDatumElement());
+ }
+
+ serviceResponse.setElement(msg);
+
+ }
+
+ /*
+ * public String convertEntitiesToCharacters(String input) {
+ *
+ * String output = input;
+ *
+ * //&lt; output = input.replaceAll("\\&lt\\;", "<"); //&gt; output =
+ * output.replaceAll("\\&gt\\;", ">"); //&amp; output =
+ * output.replaceAll("\\&amp\\;", "&"); //&apos; output =
+ * output.replaceAll("\\&apos\\;", "'"); //&quot; output =
+ * output.replaceAll("\\&quot\\;", "\"");
+ *
+ * return output;
+ *
+ * }
+ */
+
+ private Element createDatumElement(){
+ Element el=new Element("datum", "psservice",
+ "http://ggf.org/ns/nmwg/tools/org/perfsonar/service/1.0/";);
+ return el;
+ }
+
+
+} // LS



  • perfsonar: r5283 - in branches/new-structure-with-base2/ps-mdm-ls: conf src/main/java/org/perfsonar/service/lookupservice, svnlog, 09/22/2009

Archive powered by MHonArc 2.6.16.

Top of Page