GenetworkClient Jar包使用例子
package test.cn.ac.registAService.service; import static org.junit.Assert.*; import java.util.Date; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; import java.util.UUID; import org.junit.After; import org.junit.Before; import org.junit.Test; import cn.ac.registAService.commons.util.Pair; import cn.ac.registAService.exception.BusinessException; import cn.ac.registAService.model.MetadataIso; import cn.ac.registAService.model.User; import cn.ac.registAService.service.IMetadataManager; import cn.ac.registAService.service.impl.MetadataManagerImpl; /** * @author zhonghua * @version 1.0 * @date 2012-11-23 上午9:28:41 * @fuction This example shows how to use GenetworkClient */ public class MetadataManagerTest { // 资源管理实现类 private IMetadataManager m=new MetadataManagerImpl();; // 资源信息 private MetadataIso metadata; // 资源的UUID private String strUUID="23f7ee80-e34e-4e16-a5a4-9ae2e334e9a8"; @Test//@Before public void testInsert() throws BusinessException { metadata = new MetadataIso(); User organizor = new User(); metadata.setLanguage("ch"); metadata.setTitle("修改资源2"); metadata.setMetadataAbstract("资源描述"); metadata.setMetadataKeyword("修改资源测试"); metadata.setBeginPosition(new Date()); //distribution section metadata.setLinkage("www.google"); //服务服务地址 metadata.setProtocol("csw"); //服务类型 metadata.setPortalLinkage("your web portal url"); //portal url Set<String> linkageInterfaceSet=new HashSet<String>(); //资源服务接口 linkageInterfaceSet.add("www.google.com"); linkageInterfaceSet.add("www.baibu.com"); linkageInterfaceSet.add("www.biying.com"); metadata.setLinkageInterface(linkageInterfaceSet); // 时间范围和空间范围没有设置值 Date date = new Date(); metadata.setBeginPosition(date); metadata.setEndPosition(date); metadata.setTopicCategory("节点类别"); metadata.setQuality("质量描述"); metadata.setDataType("modis数据"); metadata.setDataSize("100T"); metadata.setDataNumber("1314"); metadata.setSupplement("备注"); // 空间资源组织信息 organizor.setOrganisationName("资源组织名称"); organizor.setAdministrativeArea("xingzhengquyu"); organizor.setCity("city"); organizor.setCountry("county"); organizor.setDeliveryPoint("dizhi"); organizor.setElectronicMailAddress("email"); organizor.setIndividualName("fuzheren"); organizor.setPostalCode("youbian"); organizor.setVoice("telpohe"); metadata.setOrganizor(organizor); // 添加资源 boolean insert = m.insert(metadata); assertTrue(insert); } @Test public void testUpdate() throws BusinessException { boolean update = m.update(metadata); assertTrue(update); } @Test public void testGetRecordById() throws BusinessException { // 查询结果 MetadataIso queryResultMetatadat = m.getRecordById(strUUID); assertNotNull(queryResultMetatadat); //test linkgae inerface Set linkageInterfaceSet=queryResultMetatadat.getLinkageInterface(); Iterator it=linkageInterfaceSet.iterator(); System.out.println("linkage interface size="+linkageInterfaceSet.size()); while(it.hasNext()){ System.out.println("url="+it.next()); }//end for } @Test //get all metadata public void testGetRecords() throws BusinessException { List<MetadataIso> metadataList = m.getRecords(); assertNotNull(metadataList); System.out.println("the number of metadata="+metadataList.size()); for(MetadataIso metadata: metadataList ) { System.out.println("uuid="+metadata.getFileIdentifier()); } //end for } @Test //get records by clause public void testGetRecordsByClause() throws BusinessException{ //kinds of query clause---------------------------------------------------------- //wildcard query:全文检索 String wildcardQuery="<ogc:PropertyIsLike wildCard=\"%\" singleChar=\"_\" escapeChar=\"\\\">"+ "<ogc:PropertyName>AnyText</ogc:PropertyName>"+ "<ogc:Literal>%test%</ogc:Literal>" + "</ogc:PropertyIsLike>" ; //equalTo Query String equalToQuery="<ogc:PropertyIsEqualTo>"+ "\n"+ "<ogc:PropertyName>title</PropertyName> " + "\n"+ "<ogc:Literal>%中心%</Literal>" + "\n"+ "</ogc:PropertyIsEqualTo>" ; // //getRecords System.out.println("query clause:+\n"+wildcardQuery); Pair<String, List<MetadataIso>> metadataPair=m.getRecords(null, 0,0); assertNotNull(metadataPair); //total query number String totalNumber=metadataPair.getLeft(); System.out.println(totalNumber); List<MetadataIso> metadataList=metadataPair.getRight(); System.out.println(metadataList.size()); } @Test public void testGetOrganization() throws BusinessException { //note:You must fill out the organization name, otherwise you can't get the organization name which has no name. Map orgMap= m.getOrganization(); assertNotNull(orgMap); Set entrySet=orgMap.entrySet(); Iterator entryIt=entrySet.iterator(); while(entryIt.hasNext()) { Map.Entry me=(Map.Entry)entryIt.next(); System.out.println("org name="+me.getKey()); System.out.println("org's metadata number="+me.getValue()); }// end while } @Test//@After public void testDelete() throws BusinessException { // 删除资源 boolean delete = m.delete(strUUID); assertTrue(delete); } }