From b88ed19ed06a3aad35baebfe809256b0d4a1513b Mon Sep 17 00:00:00 2001 From: jeb228 Date: Tue, 13 Apr 2010 19:51:58 +0000 Subject: [PATCH] Merge revisions 4706 4715 4724 4726 4731 4733 4734 4735 4739 to the trunk. For bjl23 and bdc34. Also web.xml from 4719, but not EntityController.java, which causes SVN to barf. --- webapp/config/web.xml | 4 + .../webapp/controller/ContactMailServlet.java | 383 ++++++++++-------- .../URLRewritingHttpServletResponse.java | 21 +- .../webapp/ontology/update/ABoxUpdater.java | 56 ++- .../ontology/update/OntologyUpdater.java | 17 +- .../servlet/setup/UpdateKnowledgeBase.java | 4 +- 6 files changed, 292 insertions(+), 193 deletions(-) diff --git a/webapp/config/web.xml b/webapp/config/web.xml index e5f2f3aca..905cd2921 100644 --- a/webapp/config/web.xml +++ b/webapp/config/web.xml @@ -1044,6 +1044,10 @@ entity /individual/* + + entity + /display/* + updateEntityFlags /updateEntityFlags diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/ContactMailServlet.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/ContactMailServlet.java index 18ccf5ddf..2d4dec962 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/ContactMailServlet.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/ContactMailServlet.java @@ -22,21 +22,24 @@ import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.apache.log4j.Logger; - import edu.cornell.mannlib.vitro.webapp.ConfigurationProperties; import edu.cornell.mannlib.vitro.webapp.beans.Portal; public class ContactMailServlet extends VitroHttpServlet { private static final Logger LOG = Logger.getLogger(ContactMailServlet.class); - public static HttpServletRequest request; - public static HttpServletRequest response; + private final static String CONFIRM_PAGE = "/thankyou.jsp"; + private final static String ERR_PAGE = "/contact_err.jsp"; + private final static String SPAM_MESSAGE = "Your message was flagged as spam."; + private final static String EMAIL_BACKUP_FILE_PATH = "/WEB-INF/LatestMessage.html"; + + private final static String WEB_USERNAME_PARAM = "webusername"; + private final static String WEB_USEREMAIL_PARAM = "webuseremail"; + private final static String COMMENTS_PARAM = "s34gfd88p9x1"; + private static String smtpHost = null; - private static final Log log = LogFactory.getLog(ContactMailServlet.class.getName()); public void init(ServletConfig servletConfig) throws javax.servlet.ServletException { super.init(servletConfig); @@ -62,39 +65,57 @@ public class ContactMailServlet extends VitroHttpServlet { public void doGet( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException { + VitroRequest vreq = new VitroRequest(request); Portal portal = vreq.getPortal(); - - String confirmpage = "/thankyou.jsp"; - String errpage = "/contact_err.jsp"; - String status = null; // holds the error status + String statusMsg = null; // holds the error status if (smtpHost==null || smtpHost.equals("")){ - status = "This application has not yet been configured to send mail " + + statusMsg = "This application has not yet been configured to send mail " + "-- smtp host has not been identified in the Configuration Properties file."; - response.sendRedirect( "test?bodyJsp=" + errpage + "&ERR=" + status + "&home=" + portal.getPortalId() ); + redirectToError(response, statusMsg, portal); return; } - String SPAM_MESSAGE = "Your message was flagged as spam."; - - boolean probablySpam = false; - String spamReason = ""; - - String originalReferer = (String) request.getSession().getAttribute("commentsFormReferer"); - request.getSession().removeAttribute("commentsFormReferer"); - if (originalReferer == null) { - originalReferer = "none"; - // (the following does not support cookie-less browsing:) - // probablySpam = true; - // status = SPAM_MESSAGE; + String webusername = vreq.getParameter(WEB_USERNAME_PARAM); + String webuseremail = vreq.getParameter(WEB_USEREMAIL_PARAM); + String comments = vreq.getParameter(COMMENTS_PARAM); + + String validationMessage = validateInput(webusername, webuseremail, + comments); + if (validationMessage != null) { + redirectToError(response, validationMessage, portal); + return; + } + webusername = webusername.trim(); + webuseremail = webuseremail.trim(); + comments = comments.trim(); + + String spamReason = null; + + String originalReferer = (String) request.getSession() + .getAttribute("commentsFormReferer"); + if (originalReferer != null) { + request.getSession().removeAttribute("commentsFormReferer"); + /* does not support legitimate clients that don't send the Referer header + String referer = request.getHeader("Referer"); + if (referer == null || + (referer.indexOf("comments") <0 + && referer.indexOf("correction") <0) ) { + spamReason = "The form was not submitted from the " + + "Contact Us or Corrections page."; + statusMsg = SPAM_MESSAGE; + } + */ } else { - String referer = request.getHeader("Referer"); - if (referer.indexOf("comments")<0 && referer.indexOf("correction")<0) { - probablySpam=true; - status = SPAM_MESSAGE ; - spamReason = "The form was not submitted from the Contact Us or Corrections page."; - } + originalReferer = "none"; + } + + if (spamReason == null) { + spamReason = checkForSpam(comments); + if (spamReason != null) { + statusMsg = SPAM_MESSAGE; + } } String formType = vreq.getParameter("DeliveryType"); @@ -104,19 +125,19 @@ public class ContactMailServlet extends VitroHttpServlet { if ("comment".equals(formType)) { if (portal.getContactMail() == null || portal.getContactMail().trim().length()==0) { - log.error("No contact mail address defined in current portal "+portal.getPortalId()); + LOG.error("No contact mail address defined in current portal "+portal.getPortalId()); throw new Error( "To establish the Contact Us mail capability the system administrators must " + "specify an email address in the current portal."); } else { deliverToArray = portal.getContactMail().split(","); } - deliveryfrom = "Message from the "+portal.getAppName()+" Contact Form (ARMANN-nospam)"; + deliveryfrom = "Message from the "+portal.getAppName()+" Contact Form"; } else if ("correction".equals(formType)) { if (portal.getCorrectionMail() == null || portal.getCorrectionMail().trim().length()==0) { - log.error("Expecting one or more correction email addresses to be specified in current portal "+portal.getPortalId()+"; will attempt to use contact mail address"); + LOG.error("Expecting one or more correction email addresses to be specified in current portal "+portal.getPortalId()+"; will attempt to use contact mail address"); if (portal.getContactMail() == null || portal.getContactMail().trim().length()==0) { - log.error("No contact mail address or correction mail address defined in current portal "+portal.getPortalId()); + LOG.error("No contact mail address or correction mail address defined in current portal "+portal.getPortalId()); } else { deliverToArray = portal.getContactMail().split(","); } @@ -126,78 +147,104 @@ public class ContactMailServlet extends VitroHttpServlet { deliveryfrom = "Message from the "+portal.getAppName()+" Correction Form (ARMANN-nospam)"; } else { deliverToArray = portal.getContactMail().split(","); - status = SPAM_MESSAGE ; + statusMsg = SPAM_MESSAGE ; spamReason = "The form specifies no delivery type."; } recipientCount=(deliverToArray == null) ? 0 : deliverToArray.length; if (recipientCount == 0) { - log.error("recipientCount is 0 when DeliveryType specified as \""+formType+"\""); + LOG.error("recipientCount is 0 when DeliveryType specified as \""+formType+"\""); throw new Error( "To establish the Contact Us mail capability the system administrators must " + "specify at least one email address in the current portal."); } - // obtain passed in form data with a simple trim on the values - String webusername = vreq.getParameter("webusername");// Null.trim(); will give you an exception - String webuseremail = vreq.getParameter("webuseremail");//.trim(); - String comments = vreq.getParameter("s34gfd88p9x1"); + String msgText = composeEmail(webusername, webuseremail, comments, + deliveryfrom, originalReferer, request.getRemoteAddr()); + + // debugging + PrintWriter outFile = new PrintWriter + (new FileWriter(request.getSession().getServletContext() + .getRealPath(EMAIL_BACKUP_FILE_PATH),true)); //autoflush + writeBackupCopy(outFile, msgText, spamReason); - if( webusername == null || "".equals(webusername) ){ - probablySpam=true; - status = SPAM_MESSAGE; - spamReason = "A proper webusername field was not found in the form submitted."; - webusername=""; - } else - webusername=webusername.trim(); + // Set the smtp host + Properties props = System.getProperties(); + props.put("mail.smtp.host", smtpHost); + Session s = Session.getDefaultInstance(props,null); // was Session.getInstance(props,null); + //s.setDebug(true); + try { + + if (spamReason == null) { + sendMessage(s, webuseremail, deliverToArray, deliveryfrom, + recipientCount, msgText); + } - if( webuseremail == null || "".equals(webuseremail) ){ - probablySpam=true; - status = SPAM_MESSAGE; - spamReason = "A proper webuser email field was not found in the form submitted."; - webuseremail=""; - } else - webuseremail=webuseremail.trim(); + } catch (AddressException e) { + statusMsg = "Please supply a valid email address."; + outFile.println( statusMsg ); + outFile.println( e.getMessage() ); + } catch (SendFailedException e) { + statusMsg = "The system was unable to deliver your mail. Please try again later. [SEND FAILED]"; + outFile.println( statusMsg ); + outFile.println( e.getMessage() ); + } catch (MessagingException e) { + statusMsg = "The system was unable to deliver your mail. Please try again later. [MESSAGING]"; + outFile.println( statusMsg ); + outFile.println( e.getMessage() ); + e.printStackTrace(); + } - if (comments==null || comments.equals("")) { // to avoid error messages in log due to null comments String - probablySpam=true; - status = SPAM_MESSAGE; - spamReason = "The proper comments field was not found in the form submitted."; + outFile.flush(); + outFile.close(); + + // Redirect to the appropriate confirmation page + if (statusMsg == null && spamReason == null) { + // message was sent successfully + redirectToConfirmation(response, statusMsg, portal); } else { - comments=comments.trim(); + // exception occurred + redirectToError( response, statusMsg, portal); } + } - /* *************************** The following chunk code is for blocking specific types of spam messages. It should be removed from a more generalized codebase. */ + public void doPost( HttpServletRequest request, HttpServletResponse response ) + throws ServletException, IOException + { + doGet( request, response ); + } - /* if this blog markup is found, treat comment as blog spam */ - if (!probablySpam - && (comments.indexOf("[/url]") > -1 - || comments.indexOf("[/URL]") > -1 - || comments.indexOf("[url=") > -1 - || comments.indexOf("[URL=") > -1)) { - probablySpam = true; - status = SPAM_MESSAGE; - spamReason = "The message contained blog link markup."; - } - - /* if message is absurdly short, treat as blog spam */ - if (!probablySpam && comments.length()<15) { - probablySpam=true; - status = SPAM_MESSAGE; - spamReason="The message was too short."; - } - - /* if contact form was requested directly, and message contains 'phentermine', treat as spam */ - if (!probablySpam && originalReferer.equals("none") && (comments.indexOf("phentermine")>-1 || comments.indexOf("Phentermine")>-1)) { - probablySpam=true; - status = SPAM_MESSAGE; - spamReason = "The comments form was requested directly, and the message contains the word 'Phentermine.'"; - } - - /* ************************** end spam filtering code */ - - StringBuffer msgBuf = new StringBuffer(); // contains the intro copy for the body of the email message - String lineSeparator = System.getProperty("line.separator"); // \r\n on windows, \n on unix + private void redirectToConfirmation(HttpServletResponse response, + String statusMsg, Portal portal) throws IOException { + response.sendRedirect( "test?bodyJsp=" + CONFIRM_PAGE + "&home=" + + portal.getPortalId() ); + } + + private void redirectToError(HttpServletResponse response, String statusMsg, + Portal portal) throws IOException { + response.sendRedirect( "test?bodyJsp=" + ERR_PAGE + "&ERR=" + statusMsg + + "&home=" + portal.getPortalId() ); + } + + /** Intended to mangle url so it can get through spam filtering + * http://host/dir/servlet?param=value -> host: dir/servlet?param=value */ + public String stripProtocol( String in ){ + if( in == null ) + return ""; + else + return in.replaceAll("http://", "host: " ); + } + + private String composeEmail(String webusername, String webuseremail, + String comments, String deliveryfrom, + String originalReferer, String ipAddr) { + + StringBuffer msgBuf = new StringBuffer(); + // contains the intro copy for the body of the email message + + String lineSeparator = System.getProperty("line.separator"); + // \r\n on windows, \n on unix + // from MyLibrary msgBuf.setLength(0); msgBuf.append("Content-Type: text/html; charset='us-ascii'" + lineSeparator); @@ -208,7 +255,8 @@ public class ContactMailServlet extends VitroHttpServlet { msgBuf.append("" + lineSeparator ); msgBuf.append("" + lineSeparator ); msgBuf.append("

" + deliveryfrom + "

" + lineSeparator ); - msgBuf.append("

From: "+webusername +" (" + webuseremail + ")"+" at IP address "+request.getRemoteAddr()+"

"+lineSeparator); + msgBuf.append("

From: "+webusername +" (" + webuseremail + ")" + + " at IP address " + ipAddr + "

"+lineSeparator); if (!(originalReferer == null || originalReferer.equals("none"))){ //The spam filter that is being used by the listsrv is rejecting " + lineSeparator ); msgBuf.append("" + lineSeparator ); - String msgText = msgBuf.toString(); - // debugging - PrintWriter outFile = new PrintWriter (new FileWriter(request.getSession().getServletContext().getRealPath("/WEB-INF/LatestMessage.html"),true)); //autoflush - - Calendar cal = Calendar.getInstance(); + return msgBuf.toString(); + } + + private void writeBackupCopy(PrintWriter outFile, String msgText, + String spamReason) { + Calendar cal = Calendar.getInstance(); outFile.println("
"); outFile.println(); outFile.println("

"+cal.getTime()+"

"); outFile.println(); - if (probablySpam) { + if (spamReason != null) { outFile.println("

REJECTED - SPAM

"); outFile.println("

"+spamReason+"

"); outFile.println(); @@ -247,86 +296,82 @@ public class ContactMailServlet extends VitroHttpServlet { outFile.println(); outFile.flush(); // outFile.close(); + } + + private void sendMessage(Session s, String webuseremail, + String[] deliverToArray, String deliveryfrom, int recipientCount, + String msgText) + throws AddressException, SendFailedException, MessagingException { + // Construct the message + MimeMessage msg = new MimeMessage( s ); + //System.out.println("trying to send message from servlet"); - // Set the smtp host - Properties props = System.getProperties(); - props.put("mail.smtp.host", smtpHost); - Session s = Session.getDefaultInstance(props,null); // was Session.getInstance(props,null); - //s.setDebug(true); - try { - // Construct the message - MimeMessage msg = new MimeMessage( s ); - //System.out.println("trying to send message from servlet"); + // Set the from address + msg.setFrom( new InternetAddress( webuseremail )); - // Set the from address - msg.setFrom( new InternetAddress( webuseremail )); - - // Set the recipient address - - if (recipientCount>0){ - InternetAddress[] address=new InternetAddress[recipientCount]; - for (int i=0; i0){ + InternetAddress[] address=new InternetAddress[recipientCount]; + for (int i=0; i -1 + || comments.indexOf("[/URL]") > -1 + || comments.indexOf("[url=") > -1 + || comments.indexOf("[URL=") > -1)) { + return "The message contained blog link markup."; } - } - - public void doPost( HttpServletRequest request, HttpServletResponse response ) - throws ServletException, IOException - { - doGet( request, response ); - } - - /** Intended to mangle url so it can get through spam filtering - * http://host/dir/servlet?param=value -> host: dir/servlet?param=value */ - public String stripProtocol( String in ){ - if( in == null ) - return ""; - else - return in.replaceAll("http://", "host: " ); + /* if message is absurdly short, treat as blog spam */ + if (comments.length()<15) { + return "The message was too short."; + } + + return null; + } } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/filters/URLRewritingHttpServletResponse.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/filters/URLRewritingHttpServletResponse.java index 840e792d2..08965269d 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/filters/URLRewritingHttpServletResponse.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/filters/URLRewritingHttpServletResponse.java @@ -27,6 +27,7 @@ import org.openrdf.model.URI; import org.openrdf.model.impl.URIImpl; import edu.cornell.mannlib.vitro.webapp.beans.Portal; +import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; import edu.cornell.mannlib.vitro.webapp.utils.NamespaceMapper; import edu.cornell.mannlib.vitro.webapp.utils.NamespaceMapperFactory; @@ -37,12 +38,14 @@ public class URLRewritingHttpServletResponse implements HttpServletResponse { private HttpServletResponse _response; private HttpServletRequest _request; private ServletContext _context; + private WebappDaoFactory wadf; private int contextPathDepth; private Pattern slashPattern = Pattern.compile("/"); public URLRewritingHttpServletResponse(HttpServletResponse response, HttpServletRequest request, ServletContext context) { this._response = response; this._context = context; + this.wadf = (WebappDaoFactory) context.getAttribute("webappDaoFactory"); this.contextPathDepth = slashPattern.split(request.getContextPath()).length-1; } @@ -94,8 +97,11 @@ public class URLRewritingHttpServletResponse implements HttpServletResponse { return _response.encodeURL(inUrl); } - // rewrite home parameters as portal prefixes for URLs not relative to the current location - if (url.pathBeginsWithSlash && PortalPickerFilter.isPortalPickingActive) { + // rewrite home parameters as portal prefixes or remove + // if there is only one portal + if ( url.pathBeginsWithSlash && + (PortalPickerFilter.isPortalPickingActive || + wadf.getPortalDao().isSinglePortal()) ) { PortalPickerFilter ppf = PortalPickerFilter.getPortalPickerFilter(this._context); if ( (ppf != null) && (url.queryParams != null) ) { Iterator qpIt = url.queryParams.iterator(); @@ -149,7 +155,16 @@ public class URLRewritingHttpServletResponse implements HttpServletResponse { if ( (uri.getNamespace() != null) && (uri.getLocalName() != null) ) { String prefix = nsMap.getPrefixForNamespace(uri.getNamespace()); String localName = uri.getLocalName(); - if (prefix != null) { + if (wadf.getDefaultNamespace(). + equals(uri.getNamespace()) + && prefix == null) { + // make a URI that matches the URI + // of the resource to support + // linked data request + url.pathParts.add(localName); + // remove the ugly uri parameter + indexToRemove = qpIndex; + } else if (prefix != null) { // add the pretty path parts url.pathParts.add(prefix); url.pathParts.add(localName); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/ontology/update/ABoxUpdater.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/ontology/update/ABoxUpdater.java index 1f48148bb..f4953b9c8 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/ontology/update/ABoxUpdater.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/ontology/update/ABoxUpdater.java @@ -24,6 +24,7 @@ import com.hp.hpl.jena.shared.Lock; import com.hp.hpl.jena.vocabulary.OWL; import com.hp.hpl.jena.vocabulary.RDF; +import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; import edu.cornell.mannlib.vitro.webapp.ontology.update.AtomicOntologyChange.AtomicChangeType; /** @@ -35,6 +36,7 @@ public class ABoxUpdater { private OntModel oldTboxModel; private OntModel newTboxModel; private OntModel aboxModel; + private OntModel newTBoxAnnotationsModel; private OntologyChangeLogger logger; private OntologyChangeRecord record; private OntClass OWL_THING = (ModelFactory @@ -57,12 +59,14 @@ public class ABoxUpdater { public ABoxUpdater(OntModel oldTboxModel, OntModel newTboxModel, OntModel aboxModel, + OntModel newAnnotationsModel, OntologyChangeLogger logger, OntologyChangeRecord record) { this.oldTboxModel = oldTboxModel; this.newTboxModel = newTboxModel; this.aboxModel = aboxModel; + this.newTBoxAnnotationsModel = newAnnotationsModel; this.logger = logger; this.record = record; } @@ -129,30 +133,58 @@ public class ABoxUpdater { Resource newClass = ResourceFactory.createResource(change.getDestinationURI()); // Change class references in the subjects of statements + + // BJL 2010-04-09 : In future versions we need to keep track of + // the difference between true direct renamings and "use-insteads." + // For now, the best behavior is to remove any remaining statements + // where the old class is the subject, *unless* the statements + // is part of the new annotations file (see comment below) or the + // predicate is vitro:autolinkedToTab. In the latter case, + // the autolinking annotation should be rewritten using the + // new class name. + + Property autoLinkedToTab = ResourceFactory.createProperty(VitroVocabulary.TAB_AUTOLINKEDTOTAB); + StmtIterator iter = aboxModel.listStatements(oldClass, (Property) null, (RDFNode) null); - int count = 0; + int renameCount = 0; + int removeCount = 0; while (iter.hasNext()) { - count++; Statement oldStatement = iter.next(); - Statement newStatement = ResourceFactory.createStatement(newClass, oldStatement.getPredicate(), oldStatement.getObject()); - retractions.add(oldStatement); - additions.add(newStatement); + if (newTBoxAnnotationsModel.contains(oldStatement)) { + continue; + // if this statement was loaded from the new annotations, + // don't attempt to remove it. + // This happens in cases where a class hasn't really + // been removed, but we just want to map any ABox + // data using it to use a different class instead. + } + if (autoLinkedToTab.equals(oldStatement.getPredicate())) { + renameCount++; + Statement newStatement = ResourceFactory.createStatement(newClass, oldStatement.getPredicate(), oldStatement.getObject()); + additions.add(newStatement); + } else { + removeCount++; + retractions.add(oldStatement); + } //logChange(oldStatement, false); //logChange(newStatement,true); } //log summary of changes - if (count > 0) { - logger.log("Changed " + count + " subject reference" + ((count > 1) ? "s" : "") + " to the " + oldClass.getURI() + " class to be " + newClass.getURI()); + if (renameCount > 0) { + logger.log("Changed " + renameCount + " subject reference" + ((renameCount > 1) ? "s" : "") + " to the " + oldClass.getURI() + " class to be " + newClass.getURI()); + } + if (removeCount > 0) { + logger.log("Removed " + removeCount + " remaining subject reference" + ((removeCount > 1) ? "s" : "") + " to the " + oldClass.getURI() + " class"); } - // Change class references in the objects of statements + // Change class references in the objects of rdf:type statements iter = aboxModel.listStatements((Resource) null, (Property) null, oldClass); - count = 0; + renameCount = 0; while (iter.hasNext()) { - count++; + renameCount++; Statement oldStatement = iter.next(); Statement newStatement = ResourceFactory.createStatement(oldStatement.getSubject(), oldStatement.getPredicate(), newClass); retractions.add(oldStatement); @@ -163,8 +195,8 @@ public class ABoxUpdater { } //log summary of changes - if (count > 0) { - logger.log("Changed " + count + " object reference" + ((count > 1) ? "s" : "") + " to the " + oldClass.getURI() + " class to be " + newClass.getURI()); + if (renameCount > 0) { + logger.log("Changed " + renameCount + " object reference" + ((renameCount > 1) ? "s" : "") + " to the " + oldClass.getURI() + " class to be " + newClass.getURI()); } aboxModel.remove(retractions); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/ontology/update/OntologyUpdater.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/ontology/update/OntologyUpdater.java index 08ff48964..ea2a4b127 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/ontology/update/OntologyUpdater.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/ontology/update/OntologyUpdater.java @@ -96,13 +96,11 @@ public class OntologyUpdater { settings.getNewTBoxModel(), settings.getOldTBoxModel()); - //updateTBox(changes); - //preprocessChanges(changes); + //process the TBox before the ABox + updateTBoxAnnotations(); updateABox(changes); - updateTBoxAnnotations(); - } /** @@ -172,8 +170,12 @@ public class OntologyUpdater { } } aboxModel.add(actualAdditions); - logger.log("Constructed " + actualAdditions.size() + " new " + - "statements using SPARQL CONSTRUCT queries."); + if (actualAdditions.size() > 0) { + logger.log("Constructed " + actualAdditions.size() + " new " + + "statement" + + ((actualAdditions.size() > 1) ? "s" : "") + + " using SPARQL CONSTRUCT queries."); + } record.recordAdditions(actualAdditions); } finally { aboxModel.leaveCriticalSection(); @@ -198,7 +200,8 @@ public class OntologyUpdater { OntModel newTBoxModel = settings.getNewTBoxModel(); OntModel ABoxModel = settings.getOntModelSelector().getABoxModel(); ABoxUpdater aboxUpdater = new ABoxUpdater( - oldTBoxModel, newTBoxModel, ABoxModel, logger, record); + oldTBoxModel, newTBoxModel, ABoxModel, + settings.getNewTBoxAnnotationsModel(), logger, record); aboxUpdater.processPropertyChanges(changes.getAtomicPropertyChanges()); aboxUpdater.processClassChanges(changes.getAtomicClassChanges()); // run additional SPARQL CONSTRUCTS diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/UpdateKnowledgeBase.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/UpdateKnowledgeBase.java index 944e2387c..84230e346 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/UpdateKnowledgeBase.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/UpdateKnowledgeBase.java @@ -54,9 +54,9 @@ public class UpdateKnowledgeBase implements ServletContextListener { private final String ERROR_LOG_FILE = DATA_DIR + LOG_DIR + "knowledgeBaseUpdate.error.log"; private final String REMOVED_DATA_FILE = DATA_DIR + CHANGED_DATA_DIR + - "removedData.rdf"; + "removedData.n3"; private final String ADDED_DATA_FILE = DATA_DIR + CHANGED_DATA_DIR + - "addedData.rdf"; + "addedData.n3"; private final String SPARQL_CONSTRUCTS_DIR = DATA_DIR + "sparqlConstructs/"; private final String MISC_REPLACEMENTS_FILE = DATA_DIR + "miscReplacements.rdf"; private final String OLD_TBOX_MODEL_DIR = DATA_DIR + "oldVersion/";