use of ch.iec.tc57._2011.schema.message.ReplyType in project CIM-Identities by epri-dev.
the class CIMIdentities method createdCIMIdentitiesRequest.
public ch.iec.tc57._2016.cimidentitiesmessage.CIMIdentitiesResponseMessageType createdCIMIdentitiesRequest(ch.iec.tc57._2016.cimidentitiesmessage.CIMIdentitiesEventMessageType message) throws ClassNotFoundException {
ch.iec.tc57._2016.cimidentitiesmessage.CIMIdentitiesResponseMessageType response = new ch.iec.tc57._2016.cimidentitiesmessage.CIMIdentitiesResponseMessageType();
// Event message type only contains the header/payload
// Response message type contains header/payload/reply
// therefore, response message type must be set for CIMIdentitiesResponseMessageType
ReplyType value = new ReplyType();
// String result = value.getResult();
value.setResult("OK");
// set response header/payload/reply
response.setHeader(message.getHeader());
response.setPayload(message.getPayload());
response.setReply(value);
// extract individual values for insertion into database
ArrayList<CIMIdentity> cim = (ArrayList<CIMIdentity>) response.getPayload().getCIMIdentities().getCIMIdentity();
mRID = cim.get(0).getIdentifiedObject().getMRID();
NName = cim.get(0).getNames().get(0).getName();
NTName = cim.get(0).getNames().get(0).getNameType().getName();
NTDes = cim.get(0).getNames().get(0).getNameType().getDescription();
NTAName = cim.get(0).getNames().get(0).getNameType().getNameTypeAuthority().getName();
NTADes = cim.get(0).getNames().get(0).getNameType().getNameTypeAuthority().getDescription();
try {
Class.forName("org.postgresql.Driver");
Connection con = DriverManager.getConnection(host, uName, password);
Statement stmt = con.createStatement();
// as uuidEntered == false
if (mRID.equals("") || mRID.equals("?")) {
String genUUID = "INSERT INTO public.\"Identity\" (id_pkey, entry)" + "VALUES (DEFAULT, DEFAULT)";
stmt.executeUpdate(genUUID);
String getUUID = "SELECT id.id_pkey FROM \"Identity\" id " + "ORDER BY id.entry desc LIMIT 1";
ResultSet rs = stmt.executeQuery(getUUID);
rs.next();
mRID = rs.getString("id_pkey");
response.getPayload().getCIMIdentities().getCIMIdentity().get(0).getIdentifiedObject().setMRID(mRID);
} else {
String entUUID = "INSERT INTO public.\"Identity\"(id_pkey, entry)" + "VALUES ('" + mRID + "', DEFAULT)";
stmt.executeUpdate(entUUID);
}
String insertIDObj = "INSERT INTO public.\"IdentifiedObject\"(io_pkey)" + "VALUES('" + mRID + "')";
String insertName = "INSERT INTO public.\"Name\"(n_pkey, n_name)" + "VALUES('" + mRID + "', '" + NName + "')";
String insertNT = "INSERT INTO public.\"NameType\"(nt_pkey, nt_description, nt_name)" + "VALUES ('" + mRID + "', '" + NTDes + "', '" + NTName + "')";
String insertNTA = "INSERT INTO public.\"NameTypeAuthority\"(nta_pkey, nta_name, nta_description)" + "VALUES ('" + mRID + "', '" + NTAName + "', '" + NTADes + "')";
stmt.executeUpdate(insertIDObj);
stmt.executeUpdate(insertName);
stmt.executeUpdate(insertNT);
stmt.executeUpdate(insertNTA);
stmt.close();
con.close();
return response;
} catch (SQLException err) {
value.setResult("FAILED");
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
err.printStackTrace(pw);
value.getError().get(0).setDetails(sw.toString());
response.setReply(value);
return response;
}
}
use of ch.iec.tc57._2011.schema.message.ReplyType in project CIM-Identities by epri-dev.
the class GetCIMIdentities method queryCIMIdentities.
public ch.iec.tc57._2016.cimidentitiesqueriesmessage.CIMIdentitiesQueriesResponseMessageType queryCIMIdentities(ch.iec.tc57._2016.cimidentitiesqueriesmessage.CIMIdentitiesQueriesRequestMessageType message) throws QueryCIMIdentitiesFaultMessage {
// create response message object
ch.iec.tc57._2016.cimidentitiesqueriesmessage.CIMIdentitiesQueriesResponseMessageType response = new ch.iec.tc57._2016.cimidentitiesqueriesmessage.CIMIdentitiesQueriesResponseMessageType();
// create header object to assign to response. Set to "get" by default
ch.iec.tc57._2011.schema.message.HeaderType header = new ch.iec.tc57._2011.schema.message.HeaderType();
header.setVerb("get");
header.setNoun("CIM Identities");
response.setHeader(header);
// create reply object that if successfully is "OK", if not is "FAILED"
ReplyType value = new ReplyType();
value.setResult("OK");
response.setReply(value);
// create Payload object for response message
ch.iec.tc57._2016.cimidentitiesqueriesmessage.CIMIdentitiesQueriesPayloadType payload = new ch.iec.tc57._2016.cimidentitiesqueriesmessage.CIMIdentitiesQueriesPayloadType();
response.setPayload(payload);
try {
String query;
String uuid = message.getRequest().getCIMIdentitiesQueries().getEndDeviceGroup().get(0).getMRID();
if (uuid == null || uuid.equals("") || uuid.equals("?")) {
query = "SELECT *" + "FROM public.\"NameType\" as nt, public.\"Name\" as n, " + "public.\"NameTypeAuthority\" as nta " + "WHERE n.n_pkey = nt.nt_pkey AND " + "nt.nt_pkey = nta.nta_pkey " + "ORDER BY n.n_name ASC;";
} else {
query = "SELECT *" + "FROM public.\"NameType\" as nt, public.\"Name\" as n, " + "public.\"NameTypeAuthority\" as nta " + "WHERE n.n_pkey = '" + uuid + "' AND " + "n.n_pkey = nt.nt_pkey AND " + "nt.nt_pkey = nta.nta_pkey";
}
Class.forName("org.postgresql.Driver");
Connection conn = DriverManager.getConnection(host, uName, password);
Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
ResultSet rs = stmt.executeQuery(query);
int size = 0;
if (rs != null) {
rs.beforeFirst();
rs.last();
size = rs.getRow();
rs.beforeFirst();
CIMIdentities cimIDs = new CIMIdentities();
payload.setCIMIdentities(cimIDs);
ArrayList<CIMIdentity> cim = (ArrayList<CIMIdentity>) payload.getCIMIdentities().getCIMIdentity();
// sets size of the ArrayList to size of the Result Set
cim.ensureCapacity(size);
int i = 0;
while (rs.next()) {
// create new CIM Identity objects for each object that will be assigned later
// when querying the database
CIMIdentity cimid = new CIMIdentity();
IdentifiedObject idObj = new IdentifiedObject();
Name name = new Name();
cim.add(i, cimid);
List<Name> names = cim.get(i).getNames();
NameType nameType = new NameType();
NameTypeAuthority nameTypeAuthority = new NameTypeAuthority();
// set the mRID
idObj.setMRID(rs.getString("n_pkey"));
cim.get(i).setIdentifiedObject(idObj);
names.add(0, name);
name.setName(rs.getString("n_name"));
names.get(0).setName(name.getName());
nameType.setName(rs.getString("nt_name"));
nameType.setDescription(rs.getString("nt_description"));
names.get(0).setNameType(nameType);
nameTypeAuthority.setName(rs.getString("nta_name"));
nameTypeAuthority.setDescription(rs.getString("nta_description"));
names.get(0).getNameType().setNameTypeAuthority(nameTypeAuthority);
i++;
}
rs.close();
stmt.close();
conn.close();
} else {
CIMIdentities cimIDs = new CIMIdentities();
payload.setCIMIdentities(cimIDs);
ArrayList<CIMIdentity> cim = (ArrayList<CIMIdentity>) payload.getCIMIdentities().getCIMIdentity();
cim.ensureCapacity(size);
CIMIdentity cimid = new CIMIdentity();
IdentifiedObject idObj = new IdentifiedObject();
Name name = new Name();
cim.add(0, cimid);
List<Name> names = cim.get(0).getNames();
NameType nameType = new NameType();
NameTypeAuthority nameTypeAuthority = new NameTypeAuthority();
// set the mRID
idObj.setMRID(rs.getString(""));
cim.get(0).setIdentifiedObject(idObj);
names.add(0, name);
name.setName(rs.getString(""));
names.get(0).setName(name.getName());
nameType.setName(rs.getString(""));
nameType.setDescription(rs.getString(""));
names.get(0).setNameType(nameType);
nameTypeAuthority.setName(rs.getString(""));
nameTypeAuthority.setDescription(rs.getString(""));
names.get(0).getNameType().setNameTypeAuthority(nameTypeAuthority);
}
response.setPayload(payload);
} catch (Exception err) {
value.setResult("Failed");
err.printStackTrace();
}
response.setReply(value);
return response;
}
use of ch.iec.tc57._2011.schema.message.ReplyType in project CIM-Identities by epri-dev.
the class CIMIdentities method deletedCIMIdentitiesRequest.
public ch.iec.tc57._2016.cimidentitiesmessage.CIMIdentitiesResponseMessageType deletedCIMIdentitiesRequest(ch.iec.tc57._2016.cimidentitiesmessage.CIMIdentitiesEventMessageType message) throws FaultMessage {
ch.iec.tc57._2016.cimidentitiesmessage.CIMIdentitiesResponseMessageType response = new ch.iec.tc57._2016.cimidentitiesmessage.CIMIdentitiesResponseMessageType();
ReplyType value = new ReplyType();
value.setResult("OK");
// set response header/payload/reply
response.setHeader(message.getHeader());
response.setPayload(message.getPayload());
response.setReply(value);
try {
Connection con = DriverManager.getConnection(host, uName, password);
Statement stmt = con.createStatement();
mRID = response.getPayload().getCIMIdentities().getCIMIdentity().get(0).getIdentifiedObject().getMRID();
String delUUID = "DELETE FROM public.\"Identity\" WHERE id_pkey = '" + mRID + "'";
stmt.executeUpdate(delUUID);
stmt.close();
con.close();
return response;
} catch (SQLException err) {
value.setResult("FAILED");
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
err.printStackTrace(pw);
value.getError().get(0).setDetails(sw.toString());
response.setReply(value);
return response;
}
}
use of ch.iec.tc57._2011.schema.message.ReplyType in project CIM-Identities by epri-dev.
the class CIMIdentities method changedCIMIdentitiesRequest.
public ch.iec.tc57._2016.cimidentitiesmessage.CIMIdentitiesResponseMessageType changedCIMIdentitiesRequest(ch.iec.tc57._2016.cimidentitiesmessage.CIMIdentitiesEventMessageType message) throws FaultMessage {
// Event message type only contains the header/payload
// Response message type contains header/payload/reply
// therefore, response message type must be set for CIMIdentitiesResponseMessageType
ch.iec.tc57._2016.cimidentitiesmessage.CIMIdentitiesResponseMessageType response = new ch.iec.tc57._2016.cimidentitiesmessage.CIMIdentitiesResponseMessageType();
ReplyType value = new ReplyType();
// String result = value.getResult();
value.setResult("OK");
// set response header/payload/reply
response.setHeader(message.getHeader());
response.setPayload(message.getPayload());
response.setReply(value);
try {
ArrayList<CIMIdentity> cim = (ArrayList<CIMIdentity>) response.getPayload().getCIMIdentities().getCIMIdentity();
mRID = cim.get(0).getIdentifiedObject().getMRID();
NName = cim.get(0).getNames().get(0).getName();
NTName = cim.get(0).getNames().get(0).getNameType().getName();
NTDes = cim.get(0).getNames().get(0).getNameType().getDescription();
NTAName = cim.get(0).getNames().get(0).getNameType().getNameTypeAuthority().getName();
NTADes = cim.get(0).getNames().get(0).getNameType().getNameTypeAuthority().getDescription();
Connection con = DriverManager.getConnection(host, uName, password);
Statement stmt = con.createStatement();
// to-do: Add error checking if "Randomly Generate" is selected
String updateName = "UPDATE public.\"Name\" SET n_name = '" + NName + "' WHERE n_pkey = '" + mRID + "'";
String updateNT = "UPDATE public.\"NameType\" SET nt_name = '" + NTName + "', nt_description = '" + NTDes + "' WHERE nt_pkey = '" + mRID + "'";
String updateNTA = "UPDATE public.\"NameTypeAuthority\" SET nta_name = '" + NTAName + "', nta_description = '" + NTADes + "' WHERE nta_pkey = '" + mRID + "'";
stmt.executeUpdate(updateName);
stmt.executeUpdate(updateNT);
stmt.executeUpdate(updateNTA);
stmt.close();
con.close();
return response;
} catch (SQLException err) {
value.setResult("FAILED");
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
err.printStackTrace(pw);
value.getError().get(0).setDetails(sw.toString());
response.setReply(value);
return response;
}
}
Aggregations