public static CQLQuery checkDefaultPredicates(CQLQuery original) throws Exception { LOG.debug("Checking query for Attributes with no predicate defined"); StringWriter originalWriter = new StringWriter(); Utils.serializeObject(original, DataServiceConstants.CQL_QUERY_QNAME, originalWriter); Element root = XMLUtilities.stringToDocument(originalWriter.getBuffer().toString()).getRootElement(); Filter attributeNoPredicateFilter = new Filter() { public boolean matches(Object o) { if (o instanceof Element) { Element e = (Element) o; if (e.getName().equals("Attribute") && e.getAttribute("predicate") == null) { return true; } } return false; } }; List<?> attributesWithNoPredicate = root.getContent(attributeNoPredicateFilter); Iterator<?> attribIter = attributesWithNoPredicate.iterator(); while (attribIter.hasNext()) { LOG.debug("Adding default predicate to an attribute"); Element elem = (Element) attribIter.next(); elem.setAttribute("predicate", "EQUAL_TO"); } String xml = XMLUtilities.elementToString(root); CQLQuery edited = Utils.deserializeObject(new StringReader(xml), CQLQuery.class); return edited; }
private CQLQuery loadQuery(String queryFilename) { CQLQuery query = null; File queryFile = new File(TEST_QUERIES_DIR, queryFilename); try { FileReader reader = new FileReader(queryFile); query = (CQLQuery) Utils.deserializeObject(reader, CQLQuery.class); } catch (Exception ex) { ex.printStackTrace(); fail("Error loading query " + queryFilename + ": " + ex.getMessage()); } return query; }
/** * getRegistration reads the XML file and creates a registration object from it for testing * * <p> * * @return * @throws DeserializationException * @throws SAXException */ private Registration getRegistration() throws DeserializationException, SAXException, IOException { // InputStream sampleIs = getClass().getResourceAsStream(sampleFile); InputStream sampleIs = new FileInputStream(sampleFile); InputStreamReader reader = new InputStreamReader(sampleIs); InputStream wsddIs = getClass().getResourceAsStream("/gov/nih/nci/ccts/grid/client/client-config.wsdd"); Registration reg = (gov.nih.nci.cabig.ccts.domain.Registration) Utils.deserializeObject( reader, gov.nih.nci.cabig.ccts.domain.Registration.class, wsddIs); return reg; }
public static void main(String[] args) { System.out.println("Running the Grid Service Client"); try { if (!(args.length < 2)) { if (args[0].equals("-url")) { IntroduceTestPersistentServiceClient client = new IntroduceTestPersistentServiceClient(args[1]); // place client calls here if you want to use this main as a // test.... java.io.FileReader fr1 = new java.io.FileReader("persistenceTestEPR1.xml"); org.apache.axis.message.addressing.EndpointReferenceType epr1 = (org.apache.axis.message.addressing.EndpointReferenceType) gov.nih.nci.cagrid.common.Utils.deserializeObject( fr1, org.apache.axis.message.addressing.EndpointReferenceType.class); org.test.persistent.resource.client.IntroduceTestPersistentResourceServiceClient resourceClient1 = new org.test.persistent.resource.client .IntroduceTestPersistentResourceServiceClient(epr1); projectmobius.org.BookType book1 = resourceClient1.getBook(); if (book1 != null && book1.getAuthor().equals("Shannon Hastings")) { System.out.println("Got recovered persistence resource and is correct"); new java.io.File("persistenceTestEPR1.xml").delete(); } else { new java.io.File("persistenceTestEPR1.xml").delete(); System.err.println("Could not retrieve the persistent resource"); System.exit(1); } resourceClient1.destroy(); book1 = null; try { book1 = resourceClient1.getBook(); } catch (Exception e) { System.out.println("Destroy and remove of persistence file worked."); } if (book1 != null) { System.err.println("Destroy and remove of persistence file error."); System.exit(1); } java.io.FileReader fr2 = new java.io.FileReader("persistenceTestEPR2.xml"); org.apache.axis.message.addressing.EndpointReferenceType epr2 = (org.apache.axis.message.addressing.EndpointReferenceType) gov.nih.nci.cagrid.common.Utils.deserializeObject( fr2, org.apache.axis.message.addressing.EndpointReferenceType.class); org.test.persistent.resource.client.IntroduceTestPersistentResourceServiceClient resourceClient2 = new org.test.persistent.resource.client .IntroduceTestPersistentResourceServiceClient(epr2); projectmobius.org.BookType book2 = resourceClient2.getBook(); if (book2 != null && book2.getAuthor().equals("Bozo The Clown")) { System.out.println("Got recovered persistence resource and is correct"); new java.io.File("persistenceTestEPR2.xml").delete(); } else { new java.io.File("persistenceTestEPR2.xml").delete(); System.err.println("Could not retrieve the persistent resource"); System.exit(1); } } else { usage(); System.exit(1); } } else { usage(); System.exit(1); } } catch (Exception e) { e.printStackTrace(); System.exit(1); } }