private void init(boolean calledByFactory) throws SearchException {
HrRecord record = this.getHrRecord();
if(record != null && calledByFactory == true) {
if(record.getProtocol() instanceof HarvestProtocolCsw) {
HarvestProtocolCsw hpCsw = (HarvestProtocolCsw) record.getProtocol();
this.setProfileId(hpCsw.getProfile());
}
return;
}
boolean doCapabilities = false;
// get uuid for this search
String uuid = "";
Map<String, String> map = super.getFactoryAttributes();
if(map != null) {
uuid = Val.chkStr(super.getFactoryAttributes().get("uuid"));
}
if("".equals(uuid)) {
uuid = this.getKey();
}
try {
// Extracting getRecordByID and GetRecordsUrl associated with uuid in
// session
RequestContext reqContext = this.getRequestContext();
if(reqContext == null) {
throw new NullPointerException("RequestContext in search engine is null");
}
String sessionKeyPrfx = this.getClass().getCanonicalName() + ":uuid:"
+ uuid;
String sessionGetMetadataKey = sessionKeyPrfx + ":GetMetadataRecord:url";
String sessionGetRecordsKey = sessionKeyPrfx + ":GetRecords:url";
String sessionProfileId = sessionKeyPrfx + ":profileId";
String sessionCapabUrl = sessionKeyPrfx + ":capabilities:url";
String sessionCapObject = sessionKeyPrfx + ":capabilities:object";
Object objCapObject = reqContext.extractFromSession(sessionCapObject);
if(objCapObject instanceof CswCatalogCapabilities) {
this.setCapabilities((CswCatalogCapabilities)objCapObject);
}
Object objGetMetadataUrl = reqContext.extractFromSession(
sessionGetMetadataKey);
Object objGetRecordsUrl = reqContext.extractFromSession(
sessionGetRecordsKey);
Object objProfileId = reqContext.extractFromSession(
sessionProfileId);
Object objGetCapabUrl = reqContext.extractFromSession(
sessionCapabUrl);
if (objGetMetadataUrl == null
|| "".equals(objGetMetadataUrl.toString().trim())
|| objGetRecordsUrl == null
|| "".equals(objGetRecordsUrl.toString().trim())
|| objProfileId == null
|| "".equals(objProfileId.toString().trim())
|| objGetCapabUrl == null
|| "".equals(objGetCapabUrl.toString().trim())) {
doCapabilities = true;
} else {
this.setGetRecordsUrl(objGetRecordsUrl.toString());
this.setGetMetadataRecordUrl(objGetMetadataUrl.toString());
this.setProfileId(objProfileId.toString());
this.setGetCapabiltiesUrl(objGetCapabUrl.toString());
}
// Checking the db to check if profile and url are still the same
GptRepository repos = new GptRepository();
try {
if (record == null) {
record = repos.readHarvestRecord(uuid, this.getRequestContext());
}
Protocol harvestProtocol = record.getProtocol();
if (harvestProtocol instanceof HarvestProtocolCsw) {
HarvestProtocolCsw harvestProtocolCsw = (HarvestProtocolCsw) harvestProtocol;
if (!this.getProfileId().equals(harvestProtocolCsw.getProfile())
|| !this.getGetCapabiltiesUrl().equals(record.getHostUrl())) {
doCapabilities = true;
this.setProfileId(harvestProtocolCsw.getProfile());
this.setGetCapabiltiesUrl(record.getHostUrl());
}
} else {
throw new SearchException("repository id " + uuid + " is not expected"