📄 query.java
字号:
package com.remedy;
import java.io.IOException;
import java.util.HashMap;
import com.andy.*;
import com.andy.conn.ConnAR;
import com.remedy.arsys.api.ARException;
import com.remedy.arsys.api.ARServerUser;
import com.remedy.arsys.api.ArithmeticOrRelationalOperand;
import com.remedy.arsys.api.Constants;
import com.remedy.arsys.api.Entry;
import com.remedy.arsys.api.EntryFactory;
import com.remedy.arsys.api.EntryID;
import com.remedy.arsys.api.EntryKey;
import com.remedy.arsys.api.EntryListCriteria;
import com.remedy.arsys.api.FieldID;
import com.remedy.arsys.api.InternalID;
import com.remedy.arsys.api.NameID;
import com.remedy.arsys.api.QualifierInfo;
import com.remedy.arsys.api.RelationalOperationInfo;
import com.remedy.arsys.api.SortInfo;
import com.remedy.arsys.api.Timestamp;
import com.remedy.arsys.api.Value;
public class Query
{
public String schema="CMDB_ItemBase";
public String sch="CMDB_Tivoli_Mapping";
public void agentDeployNotify(String ep_name)
{
int tag=0;
try{
HashMap maps=new HashMap();
maps.put("agent_ep_flag","1");
HashMap mapQualification=new HashMap();
mapQualification.put("agent_endpoint",ep_name);
tag=new ModifyEntry().modifyEntryByQualification(schema,maps,mapQualification);
}catch(Exception e)
{
System.out.println(e.getMessage());
}
}
public String[] listNoAgentEPs()
{
String noAgentEPs[]=null;
try
{
EntryKey[] key=null;
Entry entry=null;
EntryFactory entryMan=EntryFactory.getFactory();
entry= (Entry)entryMan.newInstance();
ARServerUser context = new ConnAR().GetARServerUser();
entry.setContext(context);
ArithmeticOrRelationalOperand operleft1 = new ArithmeticOrRelationalOperand(new FieldID(605010031));
ArithmeticOrRelationalOperand operright1 = new ArithmeticOrRelationalOperand(new Value());
RelationalOperationInfo op1 = new RelationalOperationInfo(Constants.AR_REL_OP_NOT_EQUAL,operleft1,operright1);
QualifierInfo qual1 = new QualifierInfo(op1);
ArithmeticOrRelationalOperand operleft2 = new ArithmeticOrRelationalOperand(new FieldID(605010033));
ArithmeticOrRelationalOperand operright2 = new ArithmeticOrRelationalOperand(new Value(1));
RelationalOperationInfo op2 = new RelationalOperationInfo(Constants.AR_REL_OP_NOT_EQUAL,operleft2,operright2);
QualifierInfo qual2 = new QualifierInfo(op2);
QualifierInfo qual = new QualifierInfo(QualifierInfo.AR_COND_OP_AND,qual1,qual2);
EntryID [] entryarray = new EntryID[1];
SortInfo [] sort = new SortInfo[1];
sort[0] = new SortInfo(new InternalID(), 1);
EntryListCriteria listcrit = new EntryListCriteria(new NameID(schema),qual,0,new Timestamp(),sort, entryarray);
key = EntryFactory.find(context,listcrit,false, null);
String[] fieldName=new String[1];
fieldName[0]="agent_endpoint";
if(key!=null)
{
System.out.println("len:"+key.length);
noAgentEPs=new String[key.length];
for(int i=0;i<key.length;i++)
{
HashMap tmpEp_name=new GetEntry().getEntryByEntryKey(schema,fieldName,key[i]);
if(tmpEp_name.get("agent_endpoint")==null)
{
noAgentEPs[i]=null;
}
else
{
noAgentEPs[i]=tmpEp_name.get("agent_endpoint").toString();
}
}
}
}catch(Exception e)
{
System.out.println(e.getMessage());
}
return noAgentEPs;
}
public HashMap[] getCiids(String ep_name)
{
String[] fieldName=new String[9];
fieldName[0]="CIID";
fieldName[1]="Category";
fieldName[2]="Type";
fieldName[3]="Item";
fieldName[4]="所属系统";
fieldName[5]="所属子系统";
fieldName[6]="所属模块";
fieldName[7]="agent_os_type";
fieldName[8]="agent_ep_flag";
HashMap mapQualification=new HashMap();
mapQualification.put("agent_endpoint",ep_name);
HashMap ciids[]=null;
try
{
EntryKey[] key=GeneralMethod.getEntryKey(schema,mapQualification);
HashMap fieldValue=new HashMap();
//HashMap requestIDFieldValue=new HashMap();
//返回值: HashMap requestIDFieldValue(String requestID,HashMap fieldValue)
//HashMap fieldValue(String fieldName,String Value)
int len=key.length;
ciids=new HashMap[len];
for(int i=0;i<len;i++)
{
fieldValue=new GetEntry().getEntryByEntryKey(schema,fieldName,key[i]);
ciids[i]=fieldValue;
}
}catch(Exception e)
{
System.out.println(e.getMessage());
}
return ciids;
}
public String getEndpoint(String ciid)
{
String ep_name=null;
String[] fieldName=new String[1];
fieldName[0]="agent_endpoint";
HashMap mapQualification=new HashMap();
mapQualification.put("CIID",ciid);
try
{
String[] tmpRequestID=GeneralMethod.getRequestID(schema,mapQualification);
if(tmpRequestID.length==1)
{
String requestID=tmpRequestID[0];
ep_name=new GetEntry().getEntryByRequestID(schema,fieldName,requestID).get("agent_endpoint").toString();
}
}catch(Exception e)
{
System.out.println(e.getMessage());
}
return ep_name;
}
public boolean addNewClass(String source,String adapter_host, String province_tivoli,String hostname,String origin,String clas,String situation_name )
{
boolean tag=false;
HashMap map=new HashMap();
map.put("source",source);
map.put("adapter_host",adapter_host);
map.put("province_tivoli",province_tivoli);
map.put("hostname",hostname);
map.put("origin",origin);
map.put("class",clas);
map.put("situation_name",situation_name);
try
{
new CreateEntry().createEntry(sch,map);
tag=true;
}catch(Exception e)
{
e.printStackTrace();
}
return tag;
}
public boolean isExsitClass(String source,String adapter_host, String hostname,String origin,String clas,String situation_name )
{
boolean tag=false;
try
{
EntryKey[] key=getKey(source,adapter_host,hostname,origin,clas,situation_name);
if(key!=null)
{
System.out.println("len:"+key.length);
tag=true;
}
}catch(Exception e)
{
System.out.println(e.getMessage());
}
return tag;
}
public String getCIID(String source,String adapter_host, String hostname,String origin,String clas,String situation_name)
{
String ciid=null;
String[] fieldName=new String[1];
fieldName[0]="CIID";
try
{
EntryKey[] key=getKey(source,adapter_host,hostname,origin,clas ,situation_name);
if(key!=null)
{
System.out.println("len:"+key.length);
ciid=new GetEntry().getEntryByEntryKey(sch,fieldName,key[0]).get("CIID").toString();
}
}catch(Exception e)
{
System.out.println(e.getMessage());
}
return ciid;
}
public EntryKey[] getKey(String source,String adapter_host, String hostname,String origin,String clas,String situation_name)
{
EntryKey[] key=null;
try
{
Entry entry=null;
EntryFactory entryMan=EntryFactory.getFactory();
entry= (Entry)entryMan.newInstance();
ARServerUser context = new ConnAR().GetARServerUser();
entry.setContext(context);
ArithmeticOrRelationalOperand operleft1 = new ArithmeticOrRelationalOperand(new FieldID(605910000));
ArithmeticOrRelationalOperand operright1 = new ArithmeticOrRelationalOperand(new Value(source));
RelationalOperationInfo op1 = new RelationalOperationInfo(Constants.AR_REL_OP_EQUAL,operleft1,operright1);
QualifierInfo qual1 = new QualifierInfo(op1);
ArithmeticOrRelationalOperand operleft2 = new ArithmeticOrRelationalOperand(new FieldID(605910001));
ArithmeticOrRelationalOperand operright2 = new ArithmeticOrRelationalOperand(new Value(adapter_host));
RelationalOperationInfo op2 = new RelationalOperationInfo(Constants.AR_REL_OP_EQUAL,operleft2,operright2);
QualifierInfo qual2 = new QualifierInfo(op2);
QualifierInfo qual3 = new QualifierInfo(QualifierInfo.AR_COND_OP_AND,qual1,qual2);
ArithmeticOrRelationalOperand operleft4 = new ArithmeticOrRelationalOperand(new FieldID(605910003));
ArithmeticOrRelationalOperand operright4 = new ArithmeticOrRelationalOperand(new Value(hostname));
RelationalOperationInfo op4 = new RelationalOperationInfo(Constants.AR_REL_OP_EQUAL,operleft4,operright4);
QualifierInfo qual4 = new QualifierInfo(op4);
QualifierInfo qual5 = new QualifierInfo(QualifierInfo.AR_COND_OP_AND,qual3,qual4);
ArithmeticOrRelationalOperand operleft6 = new ArithmeticOrRelationalOperand(new FieldID(605910004));
ArithmeticOrRelationalOperand operright6 = new ArithmeticOrRelationalOperand(new Value(origin));
RelationalOperationInfo op6 = new RelationalOperationInfo(Constants.AR_REL_OP_EQUAL,operleft6,operright6);
QualifierInfo qual6 = new QualifierInfo(op6);
QualifierInfo qual7 = new QualifierInfo(QualifierInfo.AR_COND_OP_AND,qual5,qual6);
ArithmeticOrRelationalOperand operleft8 = new ArithmeticOrRelationalOperand(new FieldID(605910005));
ArithmeticOrRelationalOperand operright8 = new ArithmeticOrRelationalOperand(new Value(clas));
RelationalOperationInfo op8 = new RelationalOperationInfo(Constants.AR_REL_OP_EQUAL,operleft8,operright8);
QualifierInfo qual8 = new QualifierInfo(op8);
QualifierInfo qual9 = new QualifierInfo(QualifierInfo.AR_COND_OP_AND,qual8,qual7);
ArithmeticOrRelationalOperand operleft10 = new ArithmeticOrRelationalOperand(new FieldID(605910006));
ArithmeticOrRelationalOperand operright10 = new ArithmeticOrRelationalOperand(new Value(situation_name));
RelationalOperationInfo op10 = new RelationalOperationInfo(Constants.AR_REL_OP_EQUAL,operleft10,operright10);
QualifierInfo qual10 = new QualifierInfo(op10);
QualifierInfo qual = new QualifierInfo(QualifierInfo.AR_COND_OP_AND,qual9,qual10);
EntryID [] entryarray = new EntryID[1];
SortInfo [] sort = new SortInfo[1];
sort[0] = new SortInfo(new InternalID(), 1);
EntryListCriteria listcrit = new EntryListCriteria(new NameID(sch),qual,0,new Timestamp(),sort, entryarray);
key = EntryFactory.find(context,listcrit,false, null);
}catch(Exception e)
{
e.printStackTrace();
}
return key;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -