public RegisterOntologyResult registerOntology(CreateOntologyResult createOntologyResult, LoginResult loginResult) {
RegisterOntologyResult registerOntologyResult = null;
CreateOntologyInfo createOntologyInfo = createOntologyResult.getCreateOntologyInfo();
if ( createOntologyInfo.getHostingType() != null ) {
// use of this attribute indicates to use the new method
registerOntologyResult = registerOntology_newMethod(createOntologyResult, loginResult);
}
else {
registerOntologyResult = registerOntology_oldMethod(createOntologyResult, loginResult);
}
if (registerOntologyResult.getError() == null) {
/////////////////////////////////////////////////////////////////////////
// send email to notify successful registration
// (this is very ad hoc -- will be more configurable in a next version)
/////////////////////////////////////////////////////////////////////////
// TODO update to reuse auxiliary methods introduced later
final Set<String> recipients = new LinkedHashSet<String>();
try {
File f = new File(notifyEmailsFilename);
FileInputStream is = new FileInputStream(f);
for (Object line: IOUtils.readLines(is)) {
String email = String.valueOf(line).trim();
if (email.length() > 0 && !email.startsWith("#")) {
recipients.add(email);
}
}
IOUtils.closeQuietly(is);
}
catch (Exception e) {
log.warn("could not read in: " + notifyEmailsFilename, e);
}
if (recipients.size() > 0) {
final Map<String, String> data = new LinkedHashMap<String, String>();
try {
String ontologyUri = registerOntologyResult.getUri();
String version = null;
String withUriParam = null;
if ( OntServiceUtil.isOntResolvableUri(ontologyUri) ) {
// prefer to show the unversioned URI
try {
MmiUri mmiUri = new MmiUri(ontologyUri);
version = mmiUri.getVersion();
ontologyUri = mmiUri.copyWithVersion(null).getOntologyUri();
}
catch (URISyntaxException ignore) {
}
}
else {
withUriParam = config.getOntServiceUrl() + "?uri=" + ontologyUri;
}
data.put("URI", ontologyUri);
if (version != null) {
data.put("version", version);
}
if (withUriParam != null) {
data.put("Resolve with", withUriParam);
}
data.put("Registered by", loginResult.getUserName());
BaseOntologyInfo baseOntologyInfo = createOntologyInfo.getBaseOntologyInfo();
if (baseOntologyInfo != null) {
String displayLabel = baseOntologyInfo.getDisplayLabel();
if (displayLabel != null) {
data.put("DisplayLabel", baseOntologyInfo.getDisplayLabel());
}