* @return
*/
public static ServiceRecordImpl createServiceRecordFromDescription( long eid, ServiceDescription sd, Calendar date ) {
log.info("Creating service record for SD = "+sd.getName());
// Look to see if there is already a matching ServiceRecord...
ServiceRecordPersistencyRemote srp = ServiceRecordPersistencyImpl.getInstance();
// This is the unique service identifier:
String serviceHash = ""+sd.hashCode();
log.info("Looking for existing service record with hash: "+serviceHash);
// Ensure service records are recorded.
ServiceRecordImpl sr = srp.findServiceRecordByHashcode(serviceHash);
if( sr != null ) {
log.info("Adding eid "+eid+" to service record for "+sr.getServiceName());
sr.getExperimentIds().add(Long.valueOf(eid));
log.info("Got "+sr.getExperimentIds().size());
srp.updateServiceRecord(sr);
return sr;
}
// Otherwise, create a new one.
sr = new ServiceRecordImpl();
log.info("Creating new Service Record...");
// sr.getExperiments().get(0).getExperimentSetup().getBasicProperties().getExperimentName();
// sr.getExperiments().get(0).getExperimentExecutable().getNumBatchExecutionRecords();
// Fill out:
sr.setServiceName( sd.getName() );
sr.setServiceVersion( sd.getVersion() );
sr.setServiceType( sd.getType() );
sr.setEndpoint(sd.getEndpoint().toString());
if( sd.getTool() != null ) {
sr.setToolName(sd.getTool().getName());
sr.setToolVersion(sd.getTool().getVersion());
if( sd.getTool().getIdentifier() != null ) {
sr.setToolIdentifier(sd.getTool().getIdentifier().toString());
}
}
sr.setServiceHash(serviceHash);
sr.setHost(sd.getEndpoint().getHost());
sr.setServiceDescription(sd);
sr.setDateFirstSeen(date);
if( eid > -1 ) {
sr.getExperimentIds().add( Long.valueOf(eid));
}
// Persist:
long srid = srp.persistServiceRecord(sr);
// Return the persisted record:
return srp.findServiceRecord(srid);
}