return registerOntologyResult;
}
public RegisterOntologyResult registerOntology_oldMethod(CreateOntologyResult createOntologyResult, LoginResult loginResult) {
RegisterOntologyResult registerOntologyResult = new RegisterOntologyResult();
String full_path = createOntologyResult.getFullPath();
log.info("registerOntology: Reading in temporary file: " +full_path);
File file = new File(full_path);
if ( ! file.canRead() ) {
String error = "Unexpected: cannot read: " +full_path;
log.info(error);
registerOntologyResult.setError(error);
return registerOntologyResult;
}
// Get resulting model:
String rdf;
try {
// rdf = Util2.readRdf(file);
rdf = Util2.readRdfWithCheckingUtf8(file);
}
catch (Throwable e) {
String error = "Unexpected: error while reading from: " +full_path+ " : " +e.getMessage();
log.info(error);
registerOntologyResult.setError(error);
return registerOntologyResult;
}
// ok, we have our ontology:
//////////////////////////////////////////////////////////////////////////
// finally, do actual registration to MMI registry
// Get final URI of resulting model
// FIXME this uses the same original URI
final String uri = createOntologyResult.getUri();
assert uri != null;
assert loginResult.getUserId() != null;
assert loginResult.getSessionId() != null;
log.info(": registering ...");
CreateOntologyInfo createOntologyInfo = createOntologyResult.getCreateOntologyInfo();
String ontologyId = createOntologyInfo.getPriorOntologyInfo().getOntologyId();
String ontologyUserId = createOntologyInfo.getPriorOntologyInfo().getOntologyUserId();
if ( ontologyId != null ) {
log.info("Will create a new version for ontologyId = " +ontologyId+ ", userId=" +ontologyUserId);
}
Map<String, String> newValues = createOntologyInfo .getMetadataValues();
try {
String fileName = new URL(uri).getPath();
//
// make sure the fileName ends with ".owl" as the aquaportal back-end seems
// to add that fixed extension in some operations (at least in the parse operation)
//
if ( ! fileName.toLowerCase().endsWith(".owl") ) {
log.info("register: setting file extension to .owl per aquaportal requirement.");
fileName += ".owl";
}
if ( ! createOntologyResult.isPreserveOriginalBaseNamespace() ) {
// We are about to do the actual registration. But first, re-check that there is NO a preexisting
// ontology that may conflict with this one.
// NOTE: this check has been done already in the review operation; however, we repeat it here
// in case there is a new registration done by other user in the meantime. Of course, we
// are NOT completely solving the potential concurrency problem with this re-check; we are just
// reducing the chances of that event.
if ( ontologyId == null ) {
final String namespaceRoot = newValues.get("namespaceRoot") != null
? newValues.get("namespaceRoot")
: defaultNamespaceRoot;
final String orgAbbreviation = newValues.get(OmvMmi.origMaintainerCode.getURI());
final String shortName = newValues.get(Omv.acronym.getURI());
if ( ! Util2.checkNoPreexistingOntology(namespaceRoot, orgAbbreviation, shortName, registerOntologyResult) ) {
return registerOntologyResult;
}
}
else {
// This is a submission of a *new version* of an existing ontology.
// Nothing needs to be checked here.
// NOTE: We don't need to repeat the _checkUriKeyCombinationForNewVersion step here
// as any change in the contents of the metadata forces the user to explicitly
// do the "review" operation, which already takes care of that check.
}
}
// OK, now do the actual registration:
OntologyUploader createOnt = new OntologyUploader(uri, fileName, rdf,
loginResult,
ontologyId, ontologyUserId,
newValues
);
String res = createOnt.create();
if ( res.startsWith("OK") ) {
registerOntologyResult.setUri(uri);
registerOntologyResult.setInfo(res);
// issue #168 fix:
// request that the ontology be loaded in the "ont" graph:
OntServiceUtil.loadOntologyInGraph(uri, null);
}
else {
registerOntologyResult.setError(res);
}
}
catch (Exception ex) {
ex.printStackTrace();
registerOntologyResult.setError(ex.getClass().getName()+ ": " +ex.getMessage());
}
log.info("registerOntologyResult = " +registerOntologyResult);