initial work on VIVO-60
Merge branch 'develop' of https://github.com/vivo-project/Vitro into develop Conflicts: webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/VClassDaoSDB.java
This commit is contained in:
commit
b5b39638a1
149 changed files with 2033 additions and 1419 deletions
|
@ -25,6 +25,8 @@ import edu.cornell.mannlib.vitro.webapp.dao.VClassDao;
|
|||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.ModelContext;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.OntModelSelector;
|
||||
import edu.cornell.mannlib.vitro.webapp.i18n.I18n;
|
||||
import edu.cornell.mannlib.vitro.webapp.i18n.I18nBundle;
|
||||
|
||||
/**
|
||||
* A base class with some utility routines for page handler (created by
|
||||
|
@ -39,6 +41,7 @@ public abstract class AbstractPageHandler {
|
|||
private static final Log log = LogFactory.getLog(AbstractPageHandler.class);
|
||||
|
||||
protected final VitroRequest vreq;
|
||||
protected final I18nBundle i18n;
|
||||
protected final ServletContext ctx;
|
||||
protected final OntModel userAccountsModel;
|
||||
protected final OntModel unionModel;
|
||||
|
@ -50,6 +53,7 @@ public abstract class AbstractPageHandler {
|
|||
|
||||
protected AbstractPageHandler(VitroRequest vreq) {
|
||||
this.vreq = vreq;
|
||||
this.i18n = I18n.bundle(vreq);
|
||||
this.ctx = vreq.getSession().getServletContext();
|
||||
|
||||
OntModelSelector oms = ModelContext.getUnionOntModelSelector(ctx);
|
||||
|
@ -154,7 +158,8 @@ public abstract class AbstractPageHandler {
|
|||
private static final String ATTRIBUTE = Message.class.getName();
|
||||
|
||||
public static void setMessage(HttpServletRequest req, Message message) {
|
||||
log.debug("Added message to session: " + message.getMessageInfoMap());
|
||||
log.debug("Added message to session: "
|
||||
+ message.getMessageInfoMap());
|
||||
req.getSession().setAttribute(ATTRIBUTE, message);
|
||||
}
|
||||
|
||||
|
|
|
@ -214,32 +214,14 @@ public class VitroRequest extends HttpServletRequestWrapper {
|
|||
}
|
||||
|
||||
//Get the display and editing configuration model
|
||||
public OntModel getDisplayModel(){
|
||||
//bdc34: I have no idea what the correct way to get this model is
|
||||
|
||||
//try from the request
|
||||
if( _req.getAttribute("displayOntModel") != null ){
|
||||
return (OntModel) _req.getAttribute(DISPLAY_ONT_MODEL);
|
||||
|
||||
//try from the session
|
||||
} else {
|
||||
HttpSession session = _req.getSession(false);
|
||||
if( session != null ){
|
||||
if( session.getAttribute(DISPLAY_ONT_MODEL) != null ){
|
||||
return (OntModel) session.getAttribute(DISPLAY_ONT_MODEL);
|
||||
|
||||
//try from the context
|
||||
}else{
|
||||
if( session.getServletContext().getAttribute(DISPLAY_ONT_MODEL) != null){
|
||||
return (OntModel)session.getServletContext().getAttribute(DISPLAY_ONT_MODEL);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//nothing worked, could not find display model
|
||||
log.error("No display model could be found.");
|
||||
return null;
|
||||
public OntModel getDisplayModel(){
|
||||
Object value = _req.getAttribute(DISPLAY_ONT_MODEL);
|
||||
if (value instanceof OntModel) {
|
||||
return (OntModel) value;
|
||||
} else {
|
||||
log.error("No display model on the VitroRequest. Expecting an OntModel but found " + value);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -103,7 +103,7 @@ public abstract class UserAccountsAddPageStrategy extends UserAccountsPage {
|
|||
FreemarkerEmailMessage email = FreemarkerEmailFactory
|
||||
.createNewMessage(vreq);
|
||||
email.addRecipient(TO, page.getAddedAccount().getEmailAddress());
|
||||
email.setSubject("Your VIVO account has been created.");
|
||||
email.setSubject(i18n.text("account_created_subject", getSiteName()));
|
||||
if (page.isExternalAuthOnly()) {
|
||||
email.setTemplate(EMAIL_TEMPLATE_NO_PASSWORD);
|
||||
} else {
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
package edu.cornell.mannlib.vitro.webapp.controller.accounts.admin;
|
||||
|
||||
import static edu.cornell.mannlib.vitro.webapp.controller.accounts.user.UserAccountsUserController.getBogusStandardMessage;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
@ -15,7 +17,6 @@ import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.usepages.ManageRoot
|
|||
import edu.cornell.mannlib.vitro.webapp.beans.UserAccount;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.accounts.UserAccountsPage;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.accounts.user.UserAccountsUserController;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||
|
||||
/**
|
||||
|
@ -51,7 +52,7 @@ public class UserAccountsDeleter extends UserAccountsPage {
|
|||
UserAccount loggedInAccount = LoginStatusBean.getCurrentUser(vreq);
|
||||
if (loggedInAccount == null) {
|
||||
log.warn("Trying to delete accounts while not logged in!");
|
||||
bogusMessage = UserAccountsUserController.BOGUS_STANDARD_MESSAGE;
|
||||
bogusMessage = getBogusStandardMessage(vreq);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -61,14 +62,14 @@ public class UserAccountsDeleter extends UserAccountsPage {
|
|||
if (u == null) {
|
||||
log.warn("Delete account for '" + uri
|
||||
+ "' is bogus: no such user");
|
||||
bogusMessage = UserAccountsUserController.BOGUS_STANDARD_MESSAGE;
|
||||
bogusMessage = getBogusStandardMessage(vreq);
|
||||
return;
|
||||
}
|
||||
|
||||
if (u.getUri().equals(loggedInAccount.getUri())) {
|
||||
log.warn("'" + u.getUri()
|
||||
+ "' is trying to delete his own account.");
|
||||
bogusMessage = UserAccountsUserController.BOGUS_STANDARD_MESSAGE;
|
||||
bogusMessage = getBogusStandardMessage(vreq);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -78,7 +79,7 @@ public class UserAccountsDeleter extends UserAccountsPage {
|
|||
log.warn("Attempting to delete the root account, "
|
||||
+ "but not authorized. Logged in as "
|
||||
+ LoginStatusBean.getCurrentUser(vreq));
|
||||
bogusMessage = UserAccountsUserController.BOGUS_STANDARD_MESSAGE;
|
||||
bogusMessage = getBogusStandardMessage(vreq);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
package edu.cornell.mannlib.vitro.webapp.controller.accounts.admin;
|
||||
|
||||
import static edu.cornell.mannlib.vitro.webapp.controller.accounts.user.UserAccountsUserController.getBogusStandardMessage;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
@ -20,7 +22,6 @@ import edu.cornell.mannlib.vitro.webapp.beans.SelfEditingConfiguration;
|
|||
import edu.cornell.mannlib.vitro.webapp.beans.UserAccount;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.accounts.UserAccountsPage;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.accounts.user.UserAccountsUserController;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.authenticate.Authenticator;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ResponseValues;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.TemplateResponseValues;
|
||||
|
@ -116,7 +117,7 @@ public class UserAccountsEditPage extends UserAccountsPage {
|
|||
if (userAccount == null) {
|
||||
log.warn("Edit account for '" + userUri
|
||||
+ "' is bogus: no such user");
|
||||
bogusMessage = UserAccountsUserController.BOGUS_STANDARD_MESSAGE;
|
||||
bogusMessage = getBogusStandardMessage(vreq);
|
||||
return;
|
||||
}
|
||||
if (userAccount.isRootUser()) {
|
||||
|
@ -125,7 +126,7 @@ public class UserAccountsEditPage extends UserAccountsPage {
|
|||
log.warn("User is attempting to edit the root account, "
|
||||
+ "but is not authorized to do so. Logged in as: "
|
||||
+ LoginStatusBean.getCurrentUser(vreq));
|
||||
bogusMessage = UserAccountsUserController.BOGUS_STANDARD_MESSAGE;
|
||||
bogusMessage = getBogusStandardMessage(vreq);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,14 +46,12 @@ public class UserAccountsCreatePasswordPage extends
|
|||
|
||||
@Override
|
||||
protected String alreadyLoggedInMessage(String currentUserEmail) {
|
||||
return "You may not activate the account for " + userEmail
|
||||
+ " while you are logged in as " + currentUserEmail
|
||||
+ ". Please log out and try again.";
|
||||
return i18n.text("cant_activate_while_logged_in", userEmail, currentUserEmail);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String passwordChangeNotPendingMessage() {
|
||||
return "The account for " + userEmail + " has already been activated.";
|
||||
return i18n.text("account_already_activated", userEmail);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -69,7 +67,7 @@ public class UserAccountsCreatePasswordPage extends
|
|||
FreemarkerEmailMessage email = FreemarkerEmailFactory
|
||||
.createNewMessage(vreq);
|
||||
email.addRecipient(TO, userAccount.getEmailAddress());
|
||||
email.setSubject("Password successfully created.");
|
||||
email.setSubject(i18n.text("password_created_subject", getSiteName()));
|
||||
email.setTemplate(EMAIL_TEMPLATE);
|
||||
email.setBodyMap(body);
|
||||
email.processTemplate();
|
||||
|
|
|
@ -115,18 +115,17 @@ public class UserAccountsFirstTimeExternalPage extends UserAccountsPage {
|
|||
|
||||
private void validateExternalAuthId() {
|
||||
if (externalAuthId.isEmpty()) {
|
||||
bogusMessage = "Login failed - External ID is not found.";
|
||||
bogusMessage = i18n.text("external_id_not_provided");
|
||||
return;
|
||||
}
|
||||
if (null != userAccountsDao
|
||||
.getUserAccountByExternalAuthId(externalAuthId)) {
|
||||
bogusMessage = "User account already exists for '" + externalAuthId
|
||||
+ "'";
|
||||
bogusMessage = i18n.text("external_id_already_in_use",
|
||||
externalAuthId);
|
||||
return;
|
||||
}
|
||||
if (!Authenticator.getInstance(vreq).isUserPermittedToLogin(null)) {
|
||||
bogusMessage = "User logins are temporarily disabled "
|
||||
+ "while the system is being maintained.";
|
||||
bogusMessage = i18n.text("logins_disabled_for_maintenance");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -73,7 +73,7 @@ public abstract class UserAccountsFirstTimeExternalPageStrategy extends
|
|||
FreemarkerEmailMessage email = FreemarkerEmailFactory
|
||||
.createNewMessage(vreq);
|
||||
email.addRecipient(TO, ua.getEmailAddress());
|
||||
email.setSubject("Your VIVO account has been created.");
|
||||
email.setSubject(i18n.text("account_created_subject", getSiteName()));
|
||||
email.setTemplate(EMAIL_TEMPLATE);
|
||||
email.setBodyMap(body);
|
||||
email.processTemplate();
|
||||
|
|
|
@ -178,7 +178,7 @@ public abstract class UserAccountsMyAccountPageStrategy extends
|
|||
FreemarkerEmailMessage email = FreemarkerEmailFactory
|
||||
.createNewMessage(vreq);
|
||||
email.addRecipient(TO, page.getUserAccount().getEmailAddress());
|
||||
email.setSubject("Your VIVO email account has been changed.");
|
||||
email.setSubject(i18n.text("email_changed_subject"));
|
||||
email.setTemplate(EMAIL_TEMPLATE);
|
||||
email.setBodyMap(body);
|
||||
email.processTemplate();
|
||||
|
|
|
@ -23,8 +23,6 @@ public abstract class UserAccountsPasswordBasePage extends UserAccountsPage {
|
|||
private static final Log log = LogFactory
|
||||
.getLog(UserAccountsPasswordBasePage.class);
|
||||
|
||||
public static final String BOGUS_MESSAGE_NO_SUCH_ACCOUNT = "The account you are trying to set a password on is no longer available. Please contact your system administrator if you think this is an error.";
|
||||
|
||||
private static final String PARAMETER_SUBMIT = "submit";
|
||||
private static final String PARAMETER_USER = "user";
|
||||
private static final String PARAMETER_KEY = "key";
|
||||
|
@ -79,7 +77,7 @@ public abstract class UserAccountsPasswordBasePage extends UserAccountsPage {
|
|||
if (userAccount == null) {
|
||||
log.warn("Password request for '" + userEmail
|
||||
+ "' is bogus: no such user");
|
||||
bogusMessage = BOGUS_MESSAGE_NO_SUCH_ACCOUNT;
|
||||
bogusMessage = i18n.text("account_no_longer_exists");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -170,9 +168,9 @@ public abstract class UserAccountsPasswordBasePage extends UserAccountsPage {
|
|||
|
||||
public String getSuccessMessage() {
|
||||
if (loggedIn) {
|
||||
return "Your password has been saved.";
|
||||
return i18n.text("password_saved");
|
||||
} else {
|
||||
return "Your password has been saved. Please log in.";
|
||||
return i18n.text("password_saved_please_login");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -46,14 +46,13 @@ public class UserAccountsResetPasswordPage extends UserAccountsPasswordBasePage
|
|||
|
||||
@Override
|
||||
protected String alreadyLoggedInMessage(String currentUserEmail) {
|
||||
return "You may not reset the password for " + userEmail
|
||||
+ " while you are logged in as " + currentUserEmail
|
||||
+ ". Please log out and try again.";
|
||||
return i18n.text("cant_change_password_while_logged_in", userEmail,
|
||||
currentUserEmail);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String passwordChangeNotPendingMessage() {
|
||||
return "The password for " + userEmail + " has already been reset.";
|
||||
return i18n.text("password_change_not_pending", userEmail);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -69,7 +68,7 @@ public class UserAccountsResetPasswordPage extends UserAccountsPasswordBasePage
|
|||
FreemarkerEmailMessage email = FreemarkerEmailFactory
|
||||
.createNewMessage(vreq);
|
||||
email.addRecipient(TO, userAccount.getEmailAddress());
|
||||
email.setSubject("Password changed.");
|
||||
email.setSubject(i18n.text("password_changed_subject"));
|
||||
email.setTemplate(EMAIL_TEMPLATE);
|
||||
email.setBodyMap(body);
|
||||
email.processTemplate();
|
||||
|
|
|
@ -4,6 +4,8 @@ package edu.cornell.mannlib.vitro.webapp.controller.accounts.user;
|
|||
|
||||
import static edu.cornell.mannlib.vedit.beans.LoginStatusBean.AuthenticationSource.EXTERNAL;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
|
@ -18,6 +20,7 @@ import edu.cornell.mannlib.vitro.webapp.controller.authenticate.LoginRedirector;
|
|||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerHttpServlet;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.RedirectResponseValues;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ResponseValues;
|
||||
import edu.cornell.mannlib.vitro.webapp.i18n.I18n;
|
||||
|
||||
/**
|
||||
* Parcel out the different actions required of the UserAccounts GUI.
|
||||
|
@ -26,8 +29,6 @@ public class UserAccountsUserController extends FreemarkerHttpServlet {
|
|||
private static final Log log = LogFactory
|
||||
.getLog(UserAccountsUserController.class);
|
||||
|
||||
public static final String BOGUS_STANDARD_MESSAGE = "Request failed. Please contact your system administrator.";
|
||||
|
||||
private static final String ACTION_CREATE_PASSWORD = "/createPassword";
|
||||
private static final String ACTION_RESET_PASSWORD = "/resetPassword";
|
||||
private static final String ACTION_MY_ACCOUNT = "/myAccount";
|
||||
|
@ -116,7 +117,7 @@ public class UserAccountsUserController extends FreemarkerHttpServlet {
|
|||
return showLoginRedirection(vreq, page.getAfterLoginUrl());
|
||||
} catch (LoginNotPermitted e) {
|
||||
// This should have been anticipated by the page.
|
||||
return showHomePage(vreq, BOGUS_STANDARD_MESSAGE);
|
||||
return showHomePage(vreq, getBogusStandardMessage(vreq));
|
||||
}
|
||||
} else {
|
||||
return page.showPage();
|
||||
|
@ -124,7 +125,7 @@ public class UserAccountsUserController extends FreemarkerHttpServlet {
|
|||
}
|
||||
|
||||
private ResponseValues handleInvalidRequest(VitroRequest vreq) {
|
||||
return showHomePage(vreq, BOGUS_STANDARD_MESSAGE);
|
||||
return showHomePage(vreq, getBogusStandardMessage(vreq));
|
||||
}
|
||||
|
||||
private ResponseValues showHomePage(VitroRequest vreq, String message) {
|
||||
|
@ -159,4 +160,8 @@ public class UserAccountsUserController extends FreemarkerHttpServlet {
|
|||
}
|
||||
return uri;
|
||||
}
|
||||
|
||||
public static String getBogusStandardMessage(HttpServletRequest req) {
|
||||
return I18n.bundle(req).text("request_failed");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import java.util.List;
|
|||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ResponseValues;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.TemplateResponseValues;
|
||||
|
@ -48,6 +49,7 @@ public class HomePageController extends FreemarkerHttpServlet {
|
|||
}
|
||||
}*/
|
||||
body.put("dataServiceUrlVClassesForVClassGroup", UrlBuilder.getUrl("/dataservice?getVClassesForVClassGroup=1&classgroupUri="));
|
||||
body.put("geoFocusMapsEnabled", getGeoFocusMapsFlag(vreq));
|
||||
|
||||
return new TemplateResponseValues(BODY_TEMPLATE, body);
|
||||
}
|
||||
|
@ -61,4 +63,11 @@ public class HomePageController extends FreemarkerHttpServlet {
|
|||
protected String getPageTemplateName() {
|
||||
return PAGE_TEMPLATE;
|
||||
}
|
||||
|
||||
private boolean getGeoFocusMapsFlag(VitroRequest vreq) {
|
||||
String property = ConfigurationProperties.getBean(vreq).getProperty(
|
||||
"homePage.geoFocusMaps");
|
||||
return "enabled".equals(property);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -36,6 +36,7 @@ import edu.cornell.mannlib.vitro.webapp.filestorage.backend.FileStorageSetup;
|
|||
import edu.cornell.mannlib.vitro.webapp.filestorage.model.FileInfo;
|
||||
import edu.cornell.mannlib.vitro.webapp.filestorage.model.ImageInfo;
|
||||
import edu.cornell.mannlib.vitro.webapp.filestorage.uploadrequest.FileUploadServletRequest;
|
||||
import edu.cornell.mannlib.vitro.webapp.i18n.I18n;
|
||||
import edu.cornell.mannlib.vitro.webapp.web.images.PlaceholderUtil;
|
||||
|
||||
/**
|
||||
|
@ -48,6 +49,9 @@ public class ImageUploadController extends FreemarkerHttpServlet {
|
|||
|
||||
private static final String ATTRIBUTE_REFERRING_PAGE = "ImageUploadController.referringPage";
|
||||
|
||||
private static final String ERROR_CODE_UNRECOGNIZED_URI = "imageUpload.errorUnrecognizedURI";
|
||||
private static final String ERROR_CODE_NO_URI = "imageUpload.errorNoURI";
|
||||
|
||||
/** Limit file size to 6 megabytes. */
|
||||
public static final int MAXIMUM_FILE_SIZE = 6 * 1024 * 1024;
|
||||
|
||||
|
@ -97,6 +101,14 @@ public class ImageUploadController extends FreemarkerHttpServlet {
|
|||
|
||||
private static final String URL_HERE = UrlBuilder.getUrl("/uploadImages");
|
||||
|
||||
private static final String TEXT_BUNDLE = "imageUpload";
|
||||
private static final String TEXT_STRING_UPLOAD_TITLE = "upload_page_title";
|
||||
private static final String TEXT_STRING_UPLOAD_TITLE_WITH_NAME = "upload_page_title_with_name";
|
||||
private static final String TEXT_STRING_REPLACE_TITLE = "replace_page_title";
|
||||
private static final String TEXT_STRING_REPLACE_TITLE_WITH_NAME = "replace_page_title_with_name";
|
||||
private static final String TEXT_STRING_CROP_TITLE = "crop_page_title";
|
||||
private static final String TEXT_STRING_CROP_TITLE_WITH_NAME = "crop_page_title_with_name";
|
||||
|
||||
private FileStorage fileStorage;
|
||||
|
||||
/**
|
||||
|
@ -218,7 +230,7 @@ public class ImageUploadController extends FreemarkerHttpServlet {
|
|||
}
|
||||
} catch (UserMistakeException e) {
|
||||
// Can't find the entity? Complain.
|
||||
return showAddImagePageWithError(vreq, null, e.getMessage());
|
||||
return showAddImagePageWithError(vreq, null, e.formatMessage(vreq));
|
||||
} catch (Exception e) {
|
||||
// We weren't expecting this - log it, and apologize to the user.
|
||||
return new ExceptionResponseValues(e);
|
||||
|
@ -274,7 +286,7 @@ public class ImageUploadController extends FreemarkerHttpServlet {
|
|||
return showCropImagePage(vreq, entity,
|
||||
fileInfo.getBytestreamAliasUrl(), size);
|
||||
} catch (UserMistakeException e) {
|
||||
return showErrorMessage(vreq, entity, e.getMessage());
|
||||
return showErrorMessage(vreq, entity, e.formatMessage(vreq));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -284,6 +296,7 @@ public class ImageUploadController extends FreemarkerHttpServlet {
|
|||
*/
|
||||
private ResponseValues showErrorMessage(VitroRequest vreq,
|
||||
Individual entity, String message) {
|
||||
|
||||
ImageInfo imageInfo = ImageInfo.instanceFromEntityUri(
|
||||
vreq.getFullWebappDaoFactory(), entity);
|
||||
if (imageInfo == null) {
|
||||
|
@ -313,7 +326,7 @@ public class ImageUploadController extends FreemarkerHttpServlet {
|
|||
|
||||
return showExitPage(vreq, entity);
|
||||
} catch (UserMistakeException e) {
|
||||
return showErrorMessage(vreq, entity, e.getMessage());
|
||||
return showErrorMessage(vreq, entity, e.formatMessage(vreq));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -350,15 +363,14 @@ public class ImageUploadController extends FreemarkerHttpServlet {
|
|||
throws UserMistakeException {
|
||||
String entityUri = vreq.getParameter(PARAMETER_ENTITY_URI);
|
||||
if (entityUri == null) {
|
||||
throw new UserMistakeException("No entity URI was provided");
|
||||
throw new UserMistakeException(ERROR_CODE_NO_URI);
|
||||
}
|
||||
|
||||
Individual entity = vreq.getFullWebappDaoFactory().getIndividualDao()
|
||||
.getIndividualByURI(entityUri);
|
||||
if (entity == null) {
|
||||
throw new UserMistakeException(
|
||||
"This URI is not recognized as belonging to anyone: '"
|
||||
+ entityUri + "'");
|
||||
throw new UserMistakeException(ERROR_CODE_UNRECOGNIZED_URI,
|
||||
entityUri);
|
||||
}
|
||||
return entity;
|
||||
}
|
||||
|
@ -416,7 +428,7 @@ public class ImageUploadController extends FreemarkerHttpServlet {
|
|||
rv.put(BODY_THUMBNAIL_URL, placeholderUrl);
|
||||
rv.put(BODY_FORM_ACTION, formAction);
|
||||
rv.put(BODY_CANCEL_URL, cancelUrl);
|
||||
rv.put(BODY_TITLE, "Upload image" + forName(entity));
|
||||
rv.put(BODY_TITLE, figureUploadPageTitle(vreq, entity));
|
||||
rv.put(BODY_MAX_FILE_SIZE, MAXIMUM_FILE_SIZE / (1024 * 1024));
|
||||
rv.put(BODY_THUMBNAIL_HEIGHT, THUMBNAIL_HEIGHT);
|
||||
rv.put(BODY_THUMBNAIL_WIDTH, THUMBNAIL_WIDTH);
|
||||
|
@ -442,7 +454,7 @@ public class ImageUploadController extends FreemarkerHttpServlet {
|
|||
rv.put(BODY_DELETE_URL, formAction(entity.getURI(), ACTION_DELETE_EDIT));
|
||||
rv.put(BODY_FORM_ACTION, formAction(entity.getURI(), ACTION_UPLOAD));
|
||||
rv.put(BODY_CANCEL_URL, exitPageUrl(vreq, entity.getURI()));
|
||||
rv.put(BODY_TITLE, "Replace image" + forName(entity));
|
||||
rv.put(BODY_TITLE, figureReplacePageTitle(vreq, entity));
|
||||
rv.put(BODY_MAX_FILE_SIZE, MAXIMUM_FILE_SIZE / (1024 * 1024));
|
||||
rv.put(BODY_THUMBNAIL_HEIGHT, THUMBNAIL_HEIGHT);
|
||||
rv.put(BODY_THUMBNAIL_WIDTH, THUMBNAIL_WIDTH);
|
||||
|
@ -472,7 +484,7 @@ public class ImageUploadController extends FreemarkerHttpServlet {
|
|||
rv.put(BODY_MAIN_IMAGE_WIDTH, dimensions.width);
|
||||
rv.put(BODY_FORM_ACTION, formAction(entity.getURI(), ACTION_SAVE));
|
||||
rv.put(BODY_CANCEL_URL, exitPageUrl(vreq, entity.getURI()));
|
||||
rv.put(BODY_TITLE, "Crop Photo" + forName(entity));
|
||||
rv.put(BODY_TITLE, figureCropPageTitle(vreq, entity));
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
@ -522,24 +534,59 @@ public class ImageUploadController extends FreemarkerHttpServlet {
|
|||
}
|
||||
|
||||
/**
|
||||
* Format the entity's name for display as part of the page title.
|
||||
* Format the title for the Upload page.
|
||||
*/
|
||||
private String forName(Individual entity) {
|
||||
private String figureUploadPageTitle(HttpServletRequest req,
|
||||
Individual entity) {
|
||||
return figurePageTitle(req, entity, TEXT_STRING_UPLOAD_TITLE,
|
||||
TEXT_STRING_UPLOAD_TITLE_WITH_NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the title for the Replace page.
|
||||
*/
|
||||
private String figureReplacePageTitle(HttpServletRequest req,
|
||||
Individual entity) {
|
||||
return figurePageTitle(req, entity, TEXT_STRING_REPLACE_TITLE,
|
||||
TEXT_STRING_REPLACE_TITLE_WITH_NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the title for the Crop page.
|
||||
*/
|
||||
private String figureCropPageTitle(HttpServletRequest req, Individual entity) {
|
||||
return figurePageTitle(req, entity, TEXT_STRING_CROP_TITLE,
|
||||
TEXT_STRING_CROP_TITLE_WITH_NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* Format one of two page titles, depending on whether the entity has a
|
||||
* name.
|
||||
*/
|
||||
private String figurePageTitle(HttpServletRequest req, Individual entity,
|
||||
String noNameTitleKey, String nameTitleKey) {
|
||||
if (entity != null) {
|
||||
String name = entity.getName();
|
||||
if (name != null) {
|
||||
return " for " + name;
|
||||
return I18n.text(req, TEXT_BUNDLE, nameTitleKey, name);
|
||||
}
|
||||
}
|
||||
return "";
|
||||
return I18n.text(req, TEXT_BUNDLE, noNameTitleKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* Holds an error message to use as a complaint to the user.
|
||||
*/
|
||||
static class UserMistakeException extends Exception {
|
||||
UserMistakeException(String message) {
|
||||
private final Object[] parameters;
|
||||
|
||||
UserMistakeException(String message, Object... parameters) {
|
||||
super(message);
|
||||
this.parameters = parameters;
|
||||
}
|
||||
|
||||
public String formatMessage(HttpServletRequest req) {
|
||||
return I18n.text(req, getMessage(), parameters);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -49,6 +49,18 @@ import edu.cornell.mannlib.vitro.webapp.filestorage.uploadrequest.FileUploadServ
|
|||
public class ImageUploadHelper {
|
||||
private static final Log log = LogFactory.getLog(ImageUploadHelper.class);
|
||||
|
||||
/*
|
||||
* Keys to text strings for error messages.
|
||||
*/
|
||||
private static final String ERROR_CODE_NO_IMAGE_TO_CROP = "imageUpload.errorNoImageForCropping";
|
||||
private static final String ERROR_CODE_IMAGE_TOO_SMALL = "imageUpload.errorImageTooSmall";
|
||||
private static final String ERROR_CODE_UNKNOWN = "imageUpload.errorUnknown";
|
||||
private static final String ERROR_CODE_FILE_TOO_BIG = "imageUpload.errorFileTooBig";
|
||||
private static final String ERROR_CODE_UNRECOGNIZED_FILE_TYPE = "imageUpload.errorUnrecognizedFileType";
|
||||
private static final String ERROR_CODE_NO_PHOTO_SELECTED = "imageUpload.errorNoPhotoSelected";
|
||||
private static final String ERROR_CODE_BAD_MULTIPART_REQUEST = "imageUpload.errorBadMultipartRequest";
|
||||
private static final String ERROR_CODE_FORM_FIELD_MISSING = "imageUpload.errorFormFieldMissing";
|
||||
|
||||
/**
|
||||
* When they upload a new image, store it as this session attribute until
|
||||
* we're ready to attach it to the Individual.
|
||||
|
@ -127,35 +139,31 @@ public class ImageUploadHelper {
|
|||
Object exception = request.getAttribute(FILE_UPLOAD_EXCEPTION);
|
||||
if (exception != null) {
|
||||
int limit = MAXIMUM_FILE_SIZE / (1024 * 1024);
|
||||
throw new UserMistakeException(
|
||||
"Please upload an image smaller than " + limit
|
||||
+ " megabytes");
|
||||
throw new UserMistakeException(ERROR_CODE_FILE_TOO_BIG, limit);
|
||||
}
|
||||
|
||||
Map<String, List<FileItem>> map = (Map<String, List<FileItem>>) request
|
||||
.getAttribute(FILE_ITEM_MAP);
|
||||
if (map == null) {
|
||||
throw new IllegalStateException("Failed to parse the "
|
||||
+ "multi-part request for uploading an image.");
|
||||
throw new IllegalStateException(ERROR_CODE_BAD_MULTIPART_REQUEST);
|
||||
}
|
||||
List<FileItem> list = map.get(PARAMETER_UPLOADED_FILE);
|
||||
if ((list == null) || list.isEmpty()) {
|
||||
throw new UserMistakeException("The form did not contain a '"
|
||||
+ PARAMETER_UPLOADED_FILE + "' field.");
|
||||
throw new UserMistakeException(ERROR_CODE_FORM_FIELD_MISSING,
|
||||
PARAMETER_UPLOADED_FILE);
|
||||
}
|
||||
|
||||
FileItem file = list.get(0);
|
||||
if (file.getSize() == 0) {
|
||||
throw new UserMistakeException("Please browse and select a photo.");
|
||||
throw new UserMistakeException(ERROR_CODE_NO_PHOTO_SELECTED);
|
||||
}
|
||||
|
||||
String filename = getSimpleFilename(file);
|
||||
String mimeType = getMimeType(file);
|
||||
if (!RECOGNIZED_FILE_TYPES.containsValue(mimeType)) {
|
||||
log.debug("Unrecognized MIME type: '" + mimeType + "'");
|
||||
throw new UserMistakeException("'" + filename
|
||||
+ "' is not a recognized image file type. "
|
||||
+ "Please upload JPEG, GIF, or PNG files only.");
|
||||
throw new UserMistakeException(ERROR_CODE_UNRECOGNIZED_FILE_TYPE,
|
||||
filename);
|
||||
}
|
||||
|
||||
return file;
|
||||
|
@ -221,10 +229,8 @@ public class ImageUploadHelper {
|
|||
|
||||
if ((size.height < THUMBNAIL_HEIGHT)
|
||||
|| (size.width < THUMBNAIL_WIDTH)) {
|
||||
throw new UserMistakeException(
|
||||
"The uploaded image should be at least "
|
||||
+ THUMBNAIL_HEIGHT + " pixels high and "
|
||||
+ THUMBNAIL_WIDTH + " pixels wide.");
|
||||
throw new UserMistakeException(ERROR_CODE_IMAGE_TOO_SMALL,
|
||||
THUMBNAIL_HEIGHT, THUMBNAIL_WIDTH);
|
||||
}
|
||||
|
||||
return size;
|
||||
|
@ -237,8 +243,7 @@ public class ImageUploadHelper {
|
|||
throw e;
|
||||
} catch (Exception e) {
|
||||
log.warn("Unexpected exception in image handling", e);
|
||||
throw new UserMistakeException("Sorry, we were unable to process "
|
||||
+ "the photo you provided. Please try another photo.");
|
||||
throw new UserMistakeException(ERROR_CODE_UNKNOWN);
|
||||
} finally {
|
||||
if (source != null) {
|
||||
try {
|
||||
|
@ -261,8 +266,7 @@ public class ImageUploadHelper {
|
|||
ATTRIBUTE_TEMP_FILE);
|
||||
|
||||
if (fileInfo == null) {
|
||||
throw new UserMistakeException(
|
||||
"There is no image file to be cropped.");
|
||||
throw new UserMistakeException(ERROR_CODE_NO_IMAGE_TO_CROP);
|
||||
}
|
||||
|
||||
return fileInfo;
|
||||
|
|
|
@ -182,8 +182,19 @@ public class IndividualListController extends FreemarkerHttpServlet {
|
|||
}
|
||||
return rvMap;
|
||||
}
|
||||
|
||||
|
||||
public static Map<String,Object> getRandomResultsForVClass(String vclassURI, int page, int pageSize, IndividualDao indDao, ServletContext context) {
|
||||
Map<String,Object> rvMap = new HashMap<String,Object>();
|
||||
try{
|
||||
List<String> classUris = Collections.singletonList(vclassURI);
|
||||
IndividualListQueryResults results = SolrQueryUtils.buildAndExecuteRandomVClassQuery(classUris, page, pageSize, context, indDao);
|
||||
rvMap = getResultsForVClassQuery(results, page, pageSize, "");
|
||||
} catch(Throwable th) {
|
||||
log.error("An error occurred retrieving random results for vclass query", th);
|
||||
}
|
||||
return rvMap;
|
||||
}
|
||||
|
||||
//TODO: Get rid of this method and utilize SolrQueryUtils - currently appears to be referenced
|
||||
//only within DataGetterUtils
|
||||
public static long getIndividualCount(List<String> vclassUris, IndividualDao indDao, ServletContext context) {
|
||||
|
|
|
@ -1,216 +0,0 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.controller.freemarker;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.servlet.ServletConfig;
|
||||
import javax.servlet.ServletException;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import com.hp.hpl.jena.ontology.Individual;
|
||||
import com.hp.hpl.jena.ontology.OntModel;
|
||||
import com.hp.hpl.jena.rdf.listeners.StatementListener;
|
||||
import com.hp.hpl.jena.rdf.model.Literal;
|
||||
import com.hp.hpl.jena.rdf.model.Model;
|
||||
import com.hp.hpl.jena.rdf.model.NodeIterator;
|
||||
import com.hp.hpl.jena.rdf.model.RDFNode;
|
||||
import com.hp.hpl.jena.rdf.model.Resource;
|
||||
import com.hp.hpl.jena.rdf.model.Statement;
|
||||
import com.hp.hpl.jena.rdf.model.StmtIterator;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ResponseValues;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.TemplateResponseValues;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary;
|
||||
import freemarker.template.Configuration;
|
||||
import static edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary.DISPLAY_ONT_MODEL;
|
||||
|
||||
public class NavigationController extends FreemarkerHttpServlet {
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final Log log = LogFactory.getLog(NavigationController.class.getName());
|
||||
|
||||
//private Map<Pattern,String> urlPatternToURI;
|
||||
private NavigationURLPatternListener urlPatterns;
|
||||
|
||||
@Override
|
||||
public void init(ServletConfig config) throws ServletException {
|
||||
super.init(config);
|
||||
OntModel displayOntModel = (OntModel)config.getServletContext().getAttribute(DISPLAY_ONT_MODEL);
|
||||
this.urlPatterns = new NavigationURLPatternListener( );
|
||||
displayOntModel.getBaseModel().register( urlPatterns );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ResponseValues processRequest(VitroRequest vreq) {
|
||||
OntModel displayOntModel = (OntModel)getServletContext().getAttribute(DISPLAY_ONT_MODEL);
|
||||
OntModel jenaOntModel = (OntModel)getServletContext().getAttribute("jenaOntModel");
|
||||
|
||||
//figure out what is being requested
|
||||
Individual ind = urlPatterns.getDisplayIndividual(vreq.getPathInfo(),displayOntModel);
|
||||
Map<String,Object> values = getValues(ind, displayOntModel,jenaOntModel, getValuesFromRequest(/*?*/) );
|
||||
String template = getTemplate(ind, displayOntModel);
|
||||
|
||||
return new TemplateResponseValues(template, values);
|
||||
}
|
||||
|
||||
private Map<String,Object>getValuesFromRequest(){
|
||||
// TODO: figure out how to get request for FreeMarkerHttpServlet.
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
private String getTemplate(Individual ind, OntModel displayOntModel) {
|
||||
if( ind == null ) return "defaultBody";
|
||||
|
||||
// check vitroDisplay:requiresBodyTemplate
|
||||
displayOntModel.enterCriticalSection(Model.READ);
|
||||
StmtIterator it = displayOntModel.listStatements(ind, DisplayVocabulary.REQUIRES_BODY_TEMPLATE, (RDFNode) null);
|
||||
//NodeIterator it = ind.listPropertyValues(DisplayVocabulary.REQUIRES_BODY_TEMPLATE);
|
||||
try{
|
||||
while(it.hasNext()){
|
||||
Statement stmt = it.nextStatement();
|
||||
if( stmt.getObject().isLiteral() ){
|
||||
String template = ((Literal)stmt.getObject().as(Literal.class)).getLexicalForm();
|
||||
if( template != null && template.length() > 0 ){
|
||||
return template;
|
||||
}
|
||||
}
|
||||
}
|
||||
}finally{
|
||||
it.close();
|
||||
displayOntModel.leaveCriticalSection();
|
||||
}
|
||||
return "defaultBody";
|
||||
}
|
||||
|
||||
Map<String,Object> getValues(Individual ind, OntModel displayOntModel, OntModel assertionModel, Map<String,Object> baseValues){
|
||||
if( ind == null ) return Collections.emptyMap();
|
||||
|
||||
/* Figure out what ValueFactories are specified in the display ontology for this individual. */
|
||||
Set<ValueFactory> valueFactories = new HashSet<ValueFactory>();
|
||||
displayOntModel.enterCriticalSection(Model.READ);
|
||||
StmtIterator stmts = ind.listProperties(DisplayVocabulary.REQUIRES_VALUES);
|
||||
try{
|
||||
while(stmts.hasNext()){
|
||||
Statement stmt = stmts.nextStatement();
|
||||
RDFNode obj = stmt.getObject();
|
||||
valueFactories.addAll(getValueFactory(obj,displayOntModel));
|
||||
}
|
||||
}finally{
|
||||
stmts.close();
|
||||
displayOntModel.leaveCriticalSection();
|
||||
}
|
||||
|
||||
/* Get values from the ValueFactories. */
|
||||
HashMap<String,Object> values = new HashMap<String,Object>();
|
||||
values.putAll(baseValues);
|
||||
for(ValueFactory vf : valueFactories){
|
||||
values.putAll( vf.getValues(assertionModel, values));
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
protected Set<ValueFactory> getValueFactory( RDFNode valueNode, OntModel displayOntModel) {
|
||||
//maybe use jenabean or owl2java for this?
|
||||
if( valueNode.isResource() ){
|
||||
Resource res = (Resource)valueNode.as(Resource.class);
|
||||
Statement stmt = res.getProperty(DisplayVocabulary.JAVA_CLASS_NAME);
|
||||
if( stmt == null || !stmt.getObject().isLiteral() ){
|
||||
log.debug("Cannot build value factory: java class was " + stmt.getObject());
|
||||
return Collections.emptySet();
|
||||
}
|
||||
String javaClassName = ((Literal)stmt.getObject().as(Literal.class)).getLexicalForm();
|
||||
if( javaClassName == null || javaClassName.length() == 0 ){
|
||||
log.debug("Cannot build value factory: no java class was set.");
|
||||
return Collections.emptySet();
|
||||
}
|
||||
Class<?> clazz;
|
||||
Object newObj;
|
||||
try {
|
||||
clazz = Class.forName(javaClassName);
|
||||
} catch (ClassNotFoundException e) {
|
||||
log.debug("Cannot build value factory: no class found for " + javaClassName);
|
||||
return Collections.emptySet();
|
||||
}
|
||||
try {
|
||||
newObj = clazz.newInstance();
|
||||
} catch (Exception e) {
|
||||
log.debug("Cannot build value factory: exception while creating object of java class " + javaClassName + " " + e.getMessage());
|
||||
return Collections.emptySet();
|
||||
}
|
||||
if( newObj instanceof ValueFactory){
|
||||
ValueFactory valueFactory = (ValueFactory)newObj;
|
||||
return Collections.singleton( valueFactory );
|
||||
}else{
|
||||
log.debug("Cannot build value factory: " + javaClassName + " does not implement " + ValueFactory.class.getName() );
|
||||
return Collections.emptySet();
|
||||
}
|
||||
}else{
|
||||
log.debug("Cannot build value factory for " + valueNode);
|
||||
return Collections.emptySet();
|
||||
}
|
||||
}
|
||||
|
||||
interface ValueFactory {
|
||||
void configure( Map<String,String> config);
|
||||
Map<String,Object> getValues(OntModel model, Map<String,Object> values);
|
||||
}
|
||||
|
||||
private class NavigationURLPatternListener extends StatementListener {
|
||||
private Map<Pattern,String> urlPatternToURI;
|
||||
|
||||
public synchronized Map<Pattern,String> getUrlPatternToURIMap(){
|
||||
if( urlPatternToURI == null || urlPatternToURI.isEmpty() ){
|
||||
this.urlPatternToURI = buildUrlPatternToURI();
|
||||
}
|
||||
return urlPatternToURI;
|
||||
}
|
||||
|
||||
protected synchronized void invalidateURLPatternMap(){
|
||||
this.urlPatternToURI = null;
|
||||
}
|
||||
|
||||
public Individual getDisplayIndividual( String pathInfo , OntModel displayModel){
|
||||
Map<Pattern,String> map = getUrlPatternToURIMap();
|
||||
for( Pattern regex : map.keySet()){
|
||||
Matcher m = regex.matcher(pathInfo);
|
||||
if(m.matches() ){
|
||||
return displayModel.getIndividual(map.get(regex));
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected synchronized Map<Pattern,String> buildUrlPatternToURI(){
|
||||
OntModel displayModel = (OntModel)getServletContext().getAttribute("displayOntModel");
|
||||
Map<Pattern,String> map = new HashMap<Pattern,String>();
|
||||
StmtIterator stmts = displayModel.listStatements(null, DisplayVocabulary.URL_MAPPING,(Literal)null);
|
||||
while(stmts.hasNext()){
|
||||
Statement stmt = stmts.nextStatement();
|
||||
if( stmt.getSubject().isURIResource() && stmt.getObject().isLiteral()){
|
||||
Resource r = (Resource)stmt.getSubject().as( Resource.class);
|
||||
Pattern regex = Pattern.compile(stmt.getLiteral().getLexicalForm());
|
||||
map.put(regex,r.getURI());
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addedStatement(Statement s) {
|
||||
invalidateURLPatternMap();
|
||||
}
|
||||
@Override
|
||||
public void removedStatement(Statement s) {
|
||||
invalidateURLPatternMap();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -180,7 +180,7 @@ class IndividualResponseBuilder {
|
|||
|
||||
private boolean getprofilePageTypesFlag() {
|
||||
String property = ConfigurationProperties.getBean(vreq).getProperty(
|
||||
"MultiViews.profilePageTypes");
|
||||
"multiViews.profilePageTypes");
|
||||
return "enabled".equals(property);
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,84 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.controller.json;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.services.shortview.ShortViewService;
|
||||
import edu.cornell.mannlib.vitro.webapp.services.shortview.ShortViewService.ShortViewContext;
|
||||
import edu.cornell.mannlib.vitro.webapp.services.shortview.ShortViewServiceSetup;
|
||||
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.IndividualTemplateModel;
|
||||
|
||||
/**
|
||||
* Does a Solr search for individuals, and uses the short view to render each of
|
||||
* the results.
|
||||
*/
|
||||
public class GetRandomSolrIndividualsByVClass extends GetSolrIndividualsByVClass {
|
||||
private static final Log log = LogFactory
|
||||
.getLog(GetRandomSolrIndividualsByVClass.class);
|
||||
|
||||
protected GetRandomSolrIndividualsByVClass(VitroRequest vreq) {
|
||||
super(vreq);
|
||||
}
|
||||
|
||||
/**
|
||||
* Search for individuals by VClass.
|
||||
*/
|
||||
@Override
|
||||
protected JSONObject process() throws Exception {
|
||||
JSONObject rObj = null;
|
||||
|
||||
//This gets the first vclass value and sets that as display type.
|
||||
List<String> vclassIds = super.getVclassIds(vreq);
|
||||
String vclassId = vclassIds.get(0);
|
||||
vreq.setAttribute("queryType", "random");
|
||||
// vreq.setAttribute("displayType", vclassId);
|
||||
|
||||
//This will get all the solr individuals by VClass (if one value) or the intersection
|
||||
//i.e. individuals that have all the types for the different vclasses entered
|
||||
rObj = super.process();
|
||||
addShortViewRenderings(rObj);
|
||||
return rObj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Look through the return object. For each individual, render the short
|
||||
* view and insert the resulting HTML into the object.
|
||||
*/
|
||||
private void addShortViewRenderings(JSONObject rObj) throws JSONException {
|
||||
JSONArray individuals = rObj.getJSONArray("individuals");
|
||||
String vclassName = rObj.getJSONObject("vclass").getString("name");
|
||||
for (int i = 0; i < individuals.length(); i++) {
|
||||
JSONObject individual = individuals.getJSONObject(i);
|
||||
individual.put("shortViewHtml",
|
||||
renderShortView(individual.getString("URI"), vclassName));
|
||||
}
|
||||
}
|
||||
|
||||
private String renderShortView(String individualUri, String vclassName) {
|
||||
IndividualDao iDao = vreq.getWebappDaoFactory().getIndividualDao();
|
||||
Individual individual = iDao.getIndividualByURI(individualUri);
|
||||
|
||||
Map<String, Object> modelMap = new HashMap<String, Object>();
|
||||
modelMap.put("individual",
|
||||
new IndividualTemplateModel(individual, vreq));
|
||||
modelMap.put("vclass", vclassName);
|
||||
|
||||
ShortViewService svs = ShortViewServiceSetup.getService(ctx);
|
||||
return svs.renderShortView(individual, ShortViewContext.BROWSE,
|
||||
modelMap, vreq);
|
||||
}
|
||||
}
|
|
@ -24,6 +24,7 @@ public class GetSolrIndividualsByVClass extends JsonObjectProducer {
|
|||
protected JSONObject process() throws Exception {
|
||||
VClass vclass=null;
|
||||
|
||||
String queryType = (String) vreq.getAttribute("queryType");
|
||||
String vitroClassIdStr = vreq.getParameter("vclassId");
|
||||
if ( vitroClassIdStr != null && !vitroClassIdStr.isEmpty()){
|
||||
vclass = vreq.getWebappDaoFactory().getVClassDao().getVClassByURI(vitroClassIdStr);
|
||||
|
@ -35,8 +36,13 @@ public class GetSolrIndividualsByVClass extends JsonObjectProducer {
|
|||
log.debug("parameter vclassId URI parameter expected ");
|
||||
throw new Exception("parameter vclassId URI parameter expected ");
|
||||
}
|
||||
|
||||
vreq.setAttribute("displayType", vitroClassIdStr);
|
||||
return JsonServlet.getSolrIndividualsByVClass(vclass.getURI(), vreq, ctx);
|
||||
if ( queryType != null && queryType.equals("random")){
|
||||
return JsonServlet.getRandomSolrIndividualsByVClass(vclass.getURI(), vreq, ctx);
|
||||
} else {
|
||||
return JsonServlet.getSolrIndividualsByVClass(vclass.getURI(), vreq, ctx);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -72,7 +72,10 @@ public class JsonServlet extends VitroHttpServlet {
|
|||
new GetDataForPage(vreq).process(resp);
|
||||
}else if( vreq.getParameter("getRenderedSolrIndividualsByVClass") != null ){
|
||||
new GetRenderedSolrIndividualsByVClass(vreq).process(resp);
|
||||
}else if( vreq.getParameter("getRandomSolrIndividualsByVClass") != null ){
|
||||
new GetRandomSolrIndividualsByVClass(vreq).process(resp);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -135,7 +138,35 @@ public class JsonServlet extends VitroHttpServlet {
|
|||
return value;
|
||||
}
|
||||
|
||||
public static JSONObject getRandomSolrIndividualsByVClass(String vclassURI, HttpServletRequest req, ServletContext context) throws Exception {
|
||||
VitroRequest vreq = new VitroRequest(req);
|
||||
|
||||
Map<String, Object> map = getRandomSolrVClassResults(vclassURI, vreq, context);
|
||||
//last parameter indicates single vclass instead of multiple vclasses
|
||||
return processVClassResults(map, vreq, context, false);
|
||||
}
|
||||
|
||||
//Including version for Random Solr query for Vclass Intersections
|
||||
private static Map<String,Object> getRandomSolrVClassResults(String vclassURI, VitroRequest vreq, ServletContext context){
|
||||
log.debug("Retrieving random Solr intersection results for " + vclassURI);
|
||||
|
||||
int page = IndividualListController.getPageParameter(vreq);
|
||||
int pageSize = Integer.parseInt(vreq.getParameter("pageSize"));
|
||||
log.debug("page and pageSize parameters = " + page + " and " + pageSize);
|
||||
Map<String,Object> map = null;
|
||||
try {
|
||||
map = IndividualListController.getRandomResultsForVClass(
|
||||
vclassURI,
|
||||
page,
|
||||
pageSize,
|
||||
vreq.getWebappDaoFactory().getIndividualDao(),
|
||||
context);
|
||||
} catch(Exception ex) {
|
||||
log.error("Error in retrieval of search results for VClass " + vclassURI, ex);
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@ import java.util.Collection;
|
|||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -24,7 +23,6 @@ import com.hp.hpl.jena.ontology.OntProperty;
|
|||
import com.hp.hpl.jena.ontology.OntResource;
|
||||
import com.hp.hpl.jena.ontology.ProfileException;
|
||||
import com.hp.hpl.jena.ontology.Restriction;
|
||||
import com.hp.hpl.jena.ontology.SomeValuesFromRestriction;
|
||||
import com.hp.hpl.jena.query.Query;
|
||||
import com.hp.hpl.jena.query.QueryExecution;
|
||||
import com.hp.hpl.jena.query.QueryExecutionFactory;
|
||||
|
@ -53,7 +51,6 @@ import edu.cornell.mannlib.vitro.webapp.beans.VClass;
|
|||
import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.InsertException;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.OntologyDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.VClassDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.event.EditEvent;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.pellet.PelletListener;
|
||||
|
@ -93,7 +90,7 @@ public class DataPropertyDaoJena extends PropertyDaoJena implements
|
|||
try {
|
||||
com.hp.hpl.jena.ontology.OntResource ind = ontModel.getOntResource(dataPropertyURI);
|
||||
if( ind != null ){
|
||||
ontModel.add(ind,(Property)DATAPROPERTY_ISEXTERNALID, "TRUE");
|
||||
ontModel.add(ind, DATAPROPERTY_ISEXTERNALID, "TRUE");
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
|
@ -114,7 +111,7 @@ public class DataPropertyDaoJena extends PropertyDaoJena implements
|
|||
while(restIt.hasNext()) {
|
||||
Resource restRes = restIt.next();
|
||||
if (restRes.canAs(OntResource.class)) {
|
||||
OntResource restOntRes = (OntResource) restRes.as(OntResource.class);
|
||||
OntResource restOntRes = restRes.as(OntResource.class);
|
||||
smartRemove(restOntRes, ontModel);
|
||||
}
|
||||
}
|
||||
|
@ -181,7 +178,7 @@ public class DataPropertyDaoJena extends PropertyDaoJena implements
|
|||
dp.setNamespace(op.getNameSpace());
|
||||
dp.setLocalName(op.getLocalName());
|
||||
OntologyDao oDao=getWebappDaoFactory().getOntologyDao();
|
||||
Ontology o = (Ontology)oDao.getOntologyByURI(dp.getNamespace());
|
||||
Ontology o = oDao.getOntologyByURI(dp.getNamespace());
|
||||
if (o==null) {
|
||||
if (!VitroVocabulary.vitroURI.equals(dp.getNamespace())) {
|
||||
log.debug("datapropFromOntProperty(): no ontology object found for the namespace "+dp.getNamespace());
|
||||
|
@ -206,8 +203,8 @@ public class DataPropertyDaoJena extends PropertyDaoJena implements
|
|||
dp.setExample(getPropertyStringValue(op,EXAMPLE_ANNOT));
|
||||
dp.setDescription(getPropertyStringValue(op,DESCRIPTION_ANNOT));
|
||||
dp.setPublicDescription(getPropertyStringValue(op,PUBLIC_DESCRIPTION_ANNOT));
|
||||
dp.setDisplayTier(((WebappDaoFactoryJena)getWebappDaoFactory()).getJenaBaseDao().getPropertyNonNegativeIntValue(op, DISPLAY_RANK_ANNOT));
|
||||
dp.setDisplayLimit(((WebappDaoFactoryJena)getWebappDaoFactory()).getJenaBaseDao().getPropertyNonNegativeIntValue(op, DISPLAY_LIMIT));
|
||||
dp.setDisplayTier((getWebappDaoFactory()).getJenaBaseDao().getPropertyNonNegativeIntValue(op, DISPLAY_RANK_ANNOT));
|
||||
dp.setDisplayLimit((getWebappDaoFactory()).getJenaBaseDao().getPropertyNonNegativeIntValue(op, DISPLAY_LIMIT));
|
||||
|
||||
//There might be multiple HIDDEN_FROM_DISPLAY_BELOW_ROLE_LEVEL_ANNOT properties, only use the highest
|
||||
StmtIterator it = op.listProperties(HIDDEN_FROM_DISPLAY_BELOW_ROLE_LEVEL_ANNOT);
|
||||
|
@ -216,7 +213,7 @@ public class DataPropertyDaoJena extends PropertyDaoJena implements
|
|||
Statement stmt = it.nextStatement();
|
||||
RDFNode obj;
|
||||
if( stmt != null && (obj = stmt.getObject()) != null && obj.isURIResource() ){
|
||||
Resource res = (Resource)obj.as(Resource.class);
|
||||
Resource res = obj.as(Resource.class);
|
||||
if( res != null && res.getURI() != null ){
|
||||
BaseResourceBean.RoleLevel roleFromModel = BaseResourceBean.RoleLevel.getRoleByUri(res.getURI());
|
||||
if( roleFromModel != null &&
|
||||
|
@ -235,7 +232,7 @@ public class DataPropertyDaoJena extends PropertyDaoJena implements
|
|||
Statement stmt = it.nextStatement();
|
||||
RDFNode obj;
|
||||
if( stmt != null && (obj = stmt.getObject()) != null && obj.isURIResource() ){
|
||||
Resource res = (Resource)obj.as(Resource.class);
|
||||
Resource res = obj.as(Resource.class);
|
||||
if( res != null && res.getURI() != null ){
|
||||
BaseResourceBean.RoleLevel roleFromModel = BaseResourceBean.RoleLevel.getRoleByUri(res.getURI());
|
||||
if( roleFromModel != null &&
|
||||
|
@ -365,7 +362,7 @@ public class DataPropertyDaoJena extends PropertyDaoJena implements
|
|||
while (restIt.hasNext()) {
|
||||
Resource restRes = restIt.next();
|
||||
if (restRes.canAs(Restriction.class)) {
|
||||
Restriction rest = (Restriction) restRes.as(Restriction.class);
|
||||
Restriction rest = restRes.as(Restriction.class);
|
||||
if (rest.isAllValuesFromRestriction()) {
|
||||
AllValuesFromRestriction avfrest = rest.asAllValuesFromRestriction();
|
||||
if (avfrest.getAllValuesFrom() != null) {
|
||||
|
@ -485,7 +482,7 @@ public class DataPropertyDaoJena extends PropertyDaoJena implements
|
|||
}
|
||||
com.hp.hpl.jena.ontology.DatatypeProperty jDataprop = ontModel.createDatatypeProperty(dtp.getURI());
|
||||
if (dtp.getPublicName() != null && dtp.getPublicName().length() > 0) {
|
||||
jDataprop.setLabel(dtp.getPublicName(), (String) getDefaultLanguage());
|
||||
jDataprop.setLabel(dtp.getPublicName(), getDefaultLanguage());
|
||||
} else {
|
||||
jDataprop.removeAll(RDFS.label);
|
||||
}
|
||||
|
@ -609,7 +606,7 @@ public class DataPropertyDaoJena extends PropertyDaoJena implements
|
|||
while (parentNodeIt.hasNext()) {
|
||||
RDFNode parentNode = parentNodeIt.next();
|
||||
if (parentNode.canAs(Property.class)) {
|
||||
parentList.add((Property) parentNode.as(Property.class));
|
||||
parentList.add(parentNode.as(Property.class));
|
||||
}
|
||||
}
|
||||
if (parentList.size()==0) {
|
||||
|
|
|
@ -10,6 +10,9 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import com.hp.hpl.jena.datatypes.TypeMapper;
|
||||
import com.hp.hpl.jena.ontology.OntModel;
|
||||
import com.hp.hpl.jena.ontology.OntResource;
|
||||
|
@ -27,7 +30,6 @@ import com.hp.hpl.jena.rdf.model.Literal;
|
|||
import com.hp.hpl.jena.rdf.model.Model;
|
||||
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
||||
import com.hp.hpl.jena.rdf.model.Property;
|
||||
import com.hp.hpl.jena.rdf.model.RDFNode;
|
||||
import com.hp.hpl.jena.rdf.model.Resource;
|
||||
import com.hp.hpl.jena.rdf.model.ResourceFactory;
|
||||
import com.hp.hpl.jena.rdf.model.Statement;
|
||||
|
@ -40,14 +42,9 @@ import edu.cornell.mannlib.vitro.webapp.beans.DataProperty;
|
|||
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatementImpl;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.edit.ReorderController;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyStatementDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.event.IndividualUpdateEvent;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.ObjectPropertyStatementDaoJena;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
public class DataPropertyStatementDaoJena extends JenaBaseDao implements DataPropertyStatementDao
|
||||
{
|
||||
|
@ -114,7 +111,7 @@ public class DataPropertyStatementDaoJena extends JenaBaseDao implements DataPro
|
|||
StmtIterator stmtIt = ind.listProperties();
|
||||
while( stmtIt.hasNext() )
|
||||
{
|
||||
Statement st = (Statement)stmtIt.next();
|
||||
Statement st = stmtIt.next();
|
||||
boolean addToList = /*allowAnyNameSpace ? st.getObject().canAs(Literal.class) :*/ st.getObject().isLiteral() &&
|
||||
(
|
||||
(RDF.value.equals(st.getPredicate()) || VitroVocabulary.value.equals(st.getPredicate().getURI()))
|
||||
|
@ -210,7 +207,7 @@ public class DataPropertyStatementDaoJena extends JenaBaseDao implements DataPro
|
|||
// do something annoying if we are dealing with a blank node
|
||||
try {
|
||||
getOntModel().enterCriticalSection(Lock.READ);
|
||||
OntResource ontRes = (OntResource) getOntModel().createResource(
|
||||
OntResource ontRes = getOntModel().createResource(
|
||||
new AnonId(entity.getLocalName())).as(OntResource.class);
|
||||
if (ontRes == null) {
|
||||
return edList;
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
package edu.cornell.mannlib.vitro.webapp.dao.jena;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import com.hp.hpl.jena.ontology.OntModel;
|
||||
|
@ -12,20 +11,15 @@ import com.hp.hpl.jena.query.Dataset;
|
|||
import com.hp.hpl.jena.query.QueryExecution;
|
||||
import com.hp.hpl.jena.query.QueryExecutionFactory;
|
||||
import com.hp.hpl.jena.query.QueryFactory;
|
||||
import com.hp.hpl.jena.query.QuerySolution;
|
||||
import com.hp.hpl.jena.query.QuerySolutionMap;
|
||||
import com.hp.hpl.jena.query.ResultSet;
|
||||
import com.hp.hpl.jena.rdf.model.Literal;
|
||||
import com.hp.hpl.jena.rdf.model.Model;
|
||||
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
||||
import com.hp.hpl.jena.rdf.model.Resource;
|
||||
import com.hp.hpl.jena.rdf.model.ResourceFactory;
|
||||
import com.hp.hpl.jena.rdf.model.Statement;
|
||||
import com.hp.hpl.jena.rdf.model.StmtIterator;
|
||||
import com.hp.hpl.jena.shared.Lock;
|
||||
import com.hp.hpl.jena.vocabulary.RDF;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.DataProperty;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatementImpl;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||
|
@ -85,7 +79,7 @@ public class DataPropertyStatementDaoSDB extends DataPropertyStatementDaoJena
|
|||
StmtIterator stmtIt = ind.listProperties();
|
||||
while( stmtIt.hasNext() )
|
||||
{
|
||||
Statement st = (Statement)stmtIt.next();
|
||||
Statement st = stmtIt.next();
|
||||
boolean addToList = /*allowAnyNameSpace ? st.getObject().canAs(Literal.class) :*/ st.getObject().isLiteral() &&
|
||||
(
|
||||
(RDF.value.equals(st.getPredicate()) || VitroVocabulary.value.equals(st.getPredicate().getURI()))
|
||||
|
|
|
@ -4,14 +4,10 @@ package edu.cornell.mannlib.vitro.webapp.dao.jena;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
import com.hp.hpl.jena.ontology.OntModel;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Datatype;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.DatatypeDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||
|
||||
public class DatatypeDaoJena extends JenaBaseDao implements DatatypeDao {
|
||||
|
||||
|
|
|
@ -9,7 +9,6 @@ import java.util.List;
|
|||
import java.util.ListIterator;
|
||||
import java.util.Set;
|
||||
|
||||
import com.hp.hpl.jena.ontology.OntModel;
|
||||
import com.hp.hpl.jena.rdf.model.Model;
|
||||
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
||||
import com.hp.hpl.jena.rdf.model.Property;
|
||||
|
@ -89,14 +88,13 @@ public class DependentResourceDeleteJena {
|
|||
* Find all statements where for a given statement in the assertions,
|
||||
* there is at least one statement in the retractions that has
|
||||
* the same predicate and object. */
|
||||
@SuppressWarnings("unchecked")
|
||||
private static List<Statement> getChangedStmts(Model assertions, Model retractions){
|
||||
List<Statement> changedStmts = new LinkedList<Statement>();
|
||||
StmtIterator it = assertions.listStatements();
|
||||
while(it.hasNext()){
|
||||
Statement assertionStmtStatement = it.nextStatement();
|
||||
if( assertionStmtStatement.getObject().canAs( Resource.class )){
|
||||
Resource asserObj = (Resource) assertionStmtStatement.getObject().as(Resource.class);
|
||||
Resource asserObj = assertionStmtStatement.getObject().as(Resource.class);
|
||||
StmtIterator retractionStmts =
|
||||
retractions.listStatements(
|
||||
(Resource)null,
|
||||
|
@ -138,7 +136,7 @@ public class DependentResourceDeleteJena {
|
|||
|
||||
if( ( obj.canAs(Resource.class) && isPredicateDependencyRelation(stmt.getPredicate(), model) )
|
||||
|| ( obj.isAnon() && perviousWasDependentResource ) ){
|
||||
Resource res = (Resource)obj.as(Resource.class);
|
||||
Resource res = obj.as(Resource.class);
|
||||
String id = res.isAnon()?res.getId().toString():res.getURI();
|
||||
|
||||
if( !visitedUris.contains(id) ){
|
||||
|
|
|
@ -7,9 +7,7 @@ import java.io.File;
|
|||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.StringReader;
|
||||
import java.nio.channels.FileChannel;
|
||||
|
||||
|
@ -22,7 +20,6 @@ import com.hp.hpl.jena.rdf.model.Property;
|
|||
import com.hp.hpl.jena.rdf.model.Resource;
|
||||
import com.hp.hpl.jena.rdf.model.ResourceFactory;
|
||||
import com.hp.hpl.jena.rdf.model.Statement;
|
||||
import com.hp.hpl.jena.util.FileManager;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.DisplayModelDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary;
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
package edu.cornell.mannlib.vitro.webapp.dao.jena;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
||||
import org.apache.commons.collections.iterators.EmptyIterator;
|
||||
|
|
|
@ -146,7 +146,7 @@ public class IndividualDaoJena extends JenaBaseDao implements IndividualDao {
|
|||
|
||||
|
||||
if (theClass.isAnon() && theClass.canAs(UnionClass.class)) {
|
||||
UnionClass u = (UnionClass) theClass.as(UnionClass.class);
|
||||
UnionClass u = theClass.as(UnionClass.class);
|
||||
for (OntClass operand : u.listOperands().toList()) {
|
||||
VClass vc = new VClassJena(operand, getWebappDaoFactory());
|
||||
ents.addAll(getIndividualsByVClass(vc));
|
||||
|
@ -159,8 +159,8 @@ public class IndividualDaoJena extends JenaBaseDao implements IndividualDao {
|
|||
try {
|
||||
while (stmtIt.hasNext()) {
|
||||
Statement stmt = stmtIt.nextStatement();
|
||||
OntResource ind = (OntResource) stmt.getSubject().as(OntResource.class);
|
||||
ents.add(new IndividualJena(ind, (WebappDaoFactoryJena) getWebappDaoFactory()));
|
||||
OntResource ind = stmt.getSubject().as(OntResource.class);
|
||||
ents.add(new IndividualJena(ind, getWebappDaoFactory()));
|
||||
}
|
||||
} finally {
|
||||
stmtIt.close();
|
||||
|
@ -232,7 +232,7 @@ public class IndividualDaoJena extends JenaBaseDao implements IndividualDao {
|
|||
ontModel.getBaseModel().notifyEvent(new IndividualCreationEvent(getWebappDaoFactory().getUserURI(),true,entURI));
|
||||
com.hp.hpl.jena.ontology.Individual ind = ontModel.createIndividual(entURI,cls);
|
||||
if (ent.getName() != null) {
|
||||
ind.setLabel(ent.getName(), (String) getDefaultLanguage());
|
||||
ind.setLabel(ent.getName(), getDefaultLanguage());
|
||||
}
|
||||
List<VClass> vclasses = ent.getVClasses(false);
|
||||
if (vclasses != null) {
|
||||
|
@ -388,7 +388,7 @@ public class IndividualDaoJena extends JenaBaseDao implements IndividualDao {
|
|||
return 1;
|
||||
}
|
||||
if (res.canAs(OntResource.class)) {
|
||||
OntResource ontRes = (OntResource) res.as(OntResource.class);
|
||||
OntResource ontRes = res.as(OntResource.class);
|
||||
smartRemove(ontRes, ontModel);
|
||||
} else {
|
||||
ontModel.removeAll(res,null,null);
|
||||
|
@ -420,7 +420,7 @@ public class IndividualDaoJena extends JenaBaseDao implements IndividualDao {
|
|||
OntResource ontRes = (entityURI.startsWith(VitroVocabulary.PSEUDO_BNODE_NS))
|
||||
? (OntResource) ontModel.createResource(new AnonId(entityURI.substring(VitroVocabulary.PSEUDO_BNODE_NS.length()))).as(OntResource.class)
|
||||
: ontModel.getOntResource(entityURI);
|
||||
Individual ent = new IndividualJena(ontRes, (WebappDaoFactoryJena) getWebappDaoFactory());
|
||||
Individual ent = new IndividualJena(ontRes, getWebappDaoFactory());
|
||||
return ent;
|
||||
} catch (Exception ex) {
|
||||
return null;
|
||||
|
@ -494,7 +494,7 @@ public class IndividualDaoJena extends JenaBaseDao implements IndividualDao {
|
|||
String subUri = ((Resource)sub).getURI();
|
||||
if( ! individualsMap.containsKey(subUri)){
|
||||
com.hp.hpl.jena.ontology.Individual ind = getOntModel().getIndividual(subUri);
|
||||
individualsMap.put(subUri,new IndividualJena(ind, (WebappDaoFactoryJena) getWebappDaoFactory()));
|
||||
individualsMap.put(subUri,new IndividualJena(ind, getWebappDaoFactory()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -519,7 +519,7 @@ public class IndividualDaoJena extends JenaBaseDao implements IndividualDao {
|
|||
String subUri = ((Resource)sub).getURI();
|
||||
if( ! individualsMap.containsKey(subUri)){
|
||||
com.hp.hpl.jena.ontology.Individual ind = getOntModel().getIndividual(subUri);
|
||||
individualsMap.put(subUri,new IndividualJena(ind, (WebappDaoFactoryJena) getWebappDaoFactory()));
|
||||
individualsMap.put(subUri,new IndividualJena(ind, getWebappDaoFactory()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -544,7 +544,7 @@ public class IndividualDaoJena extends JenaBaseDao implements IndividualDao {
|
|||
String subUri = ((Resource)sub).getURI();
|
||||
if( ! individualsMap.containsKey(subUri)){
|
||||
com.hp.hpl.jena.ontology.Individual ind = getOntModel().getIndividual(subUri);
|
||||
individualsMap.put(subUri,new IndividualJena(ind, (WebappDaoFactoryJena) getWebappDaoFactory()));
|
||||
individualsMap.put(subUri,new IndividualJena(ind, getWebappDaoFactory()));
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
|
@ -594,7 +594,7 @@ public class IndividualDaoJena extends JenaBaseDao implements IndividualDao {
|
|||
continue;
|
||||
}
|
||||
com.hp.hpl.jena.ontology.Individual ind = getOntModel().getIndividual(st.getURI());
|
||||
inds.add(new IndividualJena(ind, (WebappDaoFactoryJena) getWebappDaoFactory()));
|
||||
inds.add(new IndividualJena(ind, getWebappDaoFactory()));
|
||||
}
|
||||
} finally {
|
||||
if( stmts != null ) stmts.close();
|
||||
|
|
|
@ -106,7 +106,7 @@ public class IndividualDaoSDB extends IndividualDaoJena {
|
|||
: ResourceFactory.createResource(vclassURI);
|
||||
|
||||
if (theClass.isAnon() && theClass.canAs(UnionClass.class)) {
|
||||
UnionClass u = (UnionClass) theClass.as(UnionClass.class);
|
||||
UnionClass u = theClass.as(UnionClass.class);
|
||||
for (OntClass operand : u.listOperands().toList()) {
|
||||
VClass vc = new VClassJena(operand, getWebappDaoFactory());
|
||||
ents.addAll(getIndividualsByVClass(vc));
|
||||
|
@ -523,7 +523,7 @@ public class IndividualDaoSDB extends IndividualDaoJena {
|
|||
try {
|
||||
ResultSet results = qe.execSelect();
|
||||
while (results.hasNext()) {
|
||||
QuerySolution qs = (QuerySolution) results.next();
|
||||
QuerySolution qs = results.next();
|
||||
Resource res = (Resource) qs.get("?ent");
|
||||
if (res.getURI() != null) {
|
||||
individualURIs.add(res.getURI());
|
||||
|
|
|
@ -254,8 +254,8 @@ public class IndividualJena extends IndividualImpl implements Individual {
|
|||
if (!s.getSubject().canAs(OntResource.class) || !s.getObject().canAs(OntResource.class)) {
|
||||
continue;
|
||||
}
|
||||
Individual subj = new IndividualJena((OntResource) s.getSubject().as(OntResource.class), webappDaoFactory);
|
||||
Individual obj = new IndividualJena((OntResource) s.getObject().as(OntResource.class), webappDaoFactory);
|
||||
Individual subj = new IndividualJena(s.getSubject().as(OntResource.class), webappDaoFactory);
|
||||
Individual obj = new IndividualJena(s.getObject().as(OntResource.class), webappDaoFactory);
|
||||
ObjectProperty op = webappDaoFactory.getObjectPropertyDao().getObjectPropertyByURI(s.getPredicate().getURI());
|
||||
if (subj != null && obj != null && op != null) {
|
||||
ObjectPropertyStatement ops = new ObjectPropertyStatementImpl();
|
||||
|
@ -287,7 +287,7 @@ public class IndividualJena extends IndividualImpl implements Individual {
|
|||
RDFNode value = values.nextNode();
|
||||
if (value.canAs(OntResource.class)) {
|
||||
relatedIndividuals.add(
|
||||
new IndividualJena((OntResource) value.as(OntResource.class), webappDaoFactory) );
|
||||
new IndividualJena(value.as(OntResource.class), webappDaoFactory) );
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
|
@ -305,7 +305,7 @@ public class IndividualJena extends IndividualImpl implements Individual {
|
|||
try {
|
||||
RDFNode value = ind.getPropertyValue(ind.getModel().getProperty(propertyURI));
|
||||
if (value != null && value.canAs(OntResource.class)) {
|
||||
return new IndividualJena((OntResource) value.as(OntResource.class), webappDaoFactory);
|
||||
return new IndividualJena(value.as(OntResource.class), webappDaoFactory);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
@ -582,11 +582,11 @@ public class IndividualJena extends IndividualImpl implements Individual {
|
|||
int rv = 0;
|
||||
try {
|
||||
if( val1 instanceof String )
|
||||
rv = collator.compare( ((String)val1) , ((String)val2) );
|
||||
rv = collator.compare(val1 , val2);
|
||||
//rv = ((String)val1).compareTo((String)val2);
|
||||
else if( val1 instanceof Date ) {
|
||||
DateTime dt1 = new DateTime((Date)val1);
|
||||
DateTime dt2 = new DateTime((Date)val2);
|
||||
DateTime dt1 = new DateTime(val1);
|
||||
DateTime dt2 = new DateTime(val2);
|
||||
rv = dt1.compareTo(dt2);
|
||||
}
|
||||
else
|
||||
|
|
|
@ -478,8 +478,7 @@ public class IndividualSDB extends IndividualImpl implements Individual {
|
|||
Individual subj = null;
|
||||
try {
|
||||
subj = new IndividualSDB(
|
||||
((OntResource) s.getSubject().as(OntResource.class))
|
||||
.getURI(),
|
||||
s.getSubject().as(OntResource.class).getURI(),
|
||||
this.dwf, datasetMode, webappDaoFactory);
|
||||
} catch (IndividualNotFoundException e) {
|
||||
// leave null subject
|
||||
|
@ -487,8 +486,7 @@ public class IndividualSDB extends IndividualImpl implements Individual {
|
|||
Individual obj = null;
|
||||
try {
|
||||
obj = new IndividualSDB(
|
||||
((OntResource) s.getObject().as(OntResource.class))
|
||||
.getURI(),
|
||||
s.getObject().as(OntResource.class).getURI(),
|
||||
this.dwf, datasetMode, webappDaoFactory);
|
||||
} catch (IndividualNotFoundException e) {
|
||||
// leave null object
|
||||
|
@ -548,8 +546,7 @@ public class IndividualSDB extends IndividualImpl implements Individual {
|
|||
if (value.canAs(OntResource.class)) {
|
||||
relatedIndividuals.add(
|
||||
new IndividualSDB(
|
||||
((OntResource) value.as(OntResource.class))
|
||||
.getURI(),
|
||||
value.as(OntResource.class).getURI(),
|
||||
this.dwf,
|
||||
datasetMode,
|
||||
webappDaoFactory) );
|
||||
|
@ -588,7 +585,7 @@ public class IndividualSDB extends IndividualImpl implements Individual {
|
|||
if (value != null && value.canAs(OntResource.class)) {
|
||||
try {
|
||||
return new IndividualSDB(
|
||||
((OntResource) value.as(OntResource.class)).getURI(),
|
||||
value.as(OntResource.class).getURI(),
|
||||
dwf, datasetMode, webappDaoFactory);
|
||||
} catch (IndividualNotFoundException e) {
|
||||
return null;
|
||||
|
@ -1045,8 +1042,8 @@ public class IndividualSDB extends IndividualImpl implements Individual {
|
|||
rv = collator.compare( ((String)val1) , ((String)val2) );
|
||||
//rv = ((String)val1).compareTo((String)val2);
|
||||
else if( val1 instanceof Date ) {
|
||||
DateTime dt1 = new DateTime((Date)val1);
|
||||
DateTime dt2 = new DateTime((Date)val2);
|
||||
DateTime dt1 = new DateTime(val1);
|
||||
DateTime dt2 = new DateTime(val2);
|
||||
rv = dt1.compareTo(dt2);
|
||||
}
|
||||
else
|
||||
|
|
|
@ -12,7 +12,6 @@ import java.util.Date;
|
|||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
|
@ -23,7 +22,6 @@ import com.hp.hpl.jena.datatypes.xsd.XSDDatatype;
|
|||
import com.hp.hpl.jena.graph.Node;
|
||||
import com.hp.hpl.jena.iri.IRI;
|
||||
import com.hp.hpl.jena.iri.IRIFactory;
|
||||
import com.hp.hpl.jena.iri.Violation;
|
||||
import com.hp.hpl.jena.ontology.DatatypeProperty;
|
||||
import com.hp.hpl.jena.ontology.ObjectProperty;
|
||||
import com.hp.hpl.jena.ontology.OntClass;
|
||||
|
@ -749,10 +747,10 @@ public class JenaBaseDao extends JenaBaseDaoCon {
|
|||
|
||||
if (label != null && label.length() > 0) {
|
||||
|
||||
String existingValue = ontRes.getLabel((String) getDefaultLanguage());
|
||||
String existingValue = ontRes.getLabel(getDefaultLanguage());
|
||||
|
||||
if (existingValue == null || !existingValue.equals(label)) {
|
||||
ontRes.setLabel(label, (String) getDefaultLanguage());
|
||||
ontRes.setLabel(label, getDefaultLanguage());
|
||||
}
|
||||
} else {
|
||||
ontRes.removeAll(RDFS.label);
|
||||
|
@ -910,7 +908,7 @@ public class JenaBaseDao extends JenaBaseDaoCon {
|
|||
if (iri.hasViolation(false) ) {
|
||||
String errorStr = ("Bad URI: "+ uri +
|
||||
"\nOnly well-formed absolute URIrefs can be included in RDF/XML output: "
|
||||
+ ((Violation)iri.violations(false).next()).getShortMessage());
|
||||
+ (iri.violations(false).next()).getShortMessage());
|
||||
return errorStr;
|
||||
} else {
|
||||
return null;
|
||||
|
@ -933,7 +931,7 @@ public class JenaBaseDao extends JenaBaseDaoCon {
|
|||
String idStr = vitroURIStr.split("#")[1];
|
||||
RDFNode rdfNode = ontModel.getRDFNode(Node.createAnon(AnonId.create(idStr)));
|
||||
if ( (rdfNode != null) && (rdfNode.canAs(OntClass.class)) ) {
|
||||
cls = (OntClass) rdfNode.as(OntClass.class);
|
||||
cls = rdfNode.as(OntClass.class);
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
|
@ -1006,7 +1004,7 @@ public class JenaBaseDao extends JenaBaseDaoCon {
|
|||
StmtIterator stmtIt = getOntModel().listStatements((Resource)null, prop, value);
|
||||
while (stmtIt.hasNext()) {
|
||||
Statement stmt = stmtIt.nextStatement();
|
||||
possibleSubjectSet.add((Resource)stmt.getSubject());
|
||||
possibleSubjectSet.add(stmt.getSubject());
|
||||
|
||||
}
|
||||
Iterator<Resource> possibleSubjectIt = possibleSubjectSet.iterator();
|
||||
|
@ -1016,7 +1014,7 @@ public class JenaBaseDao extends JenaBaseDaoCon {
|
|||
boolean hasAlternatePath = false;
|
||||
while (stmtIt.hasNext()) {
|
||||
Statement stmt = stmtIt.nextStatement();
|
||||
if (stmt.getObject().isResource() && possibleSubjectSet.contains((Resource)stmt.getObject())) {
|
||||
if (stmt.getObject().isResource() && possibleSubjectSet.contains(stmt.getObject())) {
|
||||
hasAlternatePath = true;
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@ import java.util.HashSet;
|
|||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.openjena.riot.RiotException;
|
||||
|
||||
import com.hp.hpl.jena.rdf.model.Model;
|
||||
import com.hp.hpl.jena.rdf.model.ModelChangedListener;
|
||||
|
@ -17,7 +16,6 @@ import com.hp.hpl.jena.rdf.model.Statement;
|
|||
import com.hp.hpl.jena.rdf.model.StmtIterator;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.ChangeListener;
|
||||
import edu.cornell.mannlib.vitro.webapp.servlet.setup.JenaDataSourceSetupBase;
|
||||
import edu.cornell.mannlib.vitro.webapp.servlet.setup.SimpleReasonerSetup;
|
||||
|
||||
/**
|
||||
|
|
|
@ -95,7 +95,7 @@ public class JenaModelUtils {
|
|||
.getRootClasses();
|
||||
for (Iterator<VClass> rootClassIt = rootClasses.iterator();
|
||||
rootClassIt.hasNext(); ) {
|
||||
VClass rootClass = (VClass) rootClassIt.next();
|
||||
VClass rootClass = rootClassIt.next();
|
||||
Individual classGroup = modelForClassgroups.createIndividual(
|
||||
wadf.getDefaultNamespace() + "vitroClassGroup" +
|
||||
rootClass.getLocalName(), classGroupClass);
|
||||
|
@ -108,7 +108,7 @@ public class JenaModelUtils {
|
|||
for (Iterator<String> childIt = myWebappDaoFactory.getVClassDao()
|
||||
.getAllSubClassURIs(rootClass.getURI()).iterator();
|
||||
childIt.hasNext(); ) {
|
||||
String childURI = (String) childIt.next();
|
||||
String childURI = childIt.next();
|
||||
Resource childClass = modelForClassgroupAnnotations
|
||||
.getResource(childURI);
|
||||
if (!modelForClassgroupAnnotations.contains(
|
||||
|
|
|
@ -92,7 +92,7 @@ public class ObjectPropertyDaoJena extends PropertyDaoJena implements ObjectProp
|
|||
p.setNamespace(op.getNameSpace());
|
||||
p.setLocalName(op.getLocalName());
|
||||
OntologyDao oDao=getWebappDaoFactory().getOntologyDao();
|
||||
Ontology o = (Ontology)oDao.getOntologyByURI(p.getNamespace());
|
||||
Ontology o = oDao.getOntologyByURI(p.getNamespace());
|
||||
if (o==null) {
|
||||
if (!VitroVocabulary.vitroURI.equals(p.getNamespace())) {
|
||||
log.debug("propertyFromOntProperty(): no ontology object found for the namespace "+p.getNamespace());
|
||||
|
@ -180,7 +180,7 @@ public class ObjectPropertyDaoJena extends PropertyDaoJena implements ObjectProp
|
|||
Statement stmt = it.nextStatement();
|
||||
RDFNode obj;
|
||||
if( stmt != null && (obj = stmt.getObject()) != null && obj.isURIResource() ){
|
||||
Resource res = (Resource)obj.as(Resource.class);
|
||||
Resource res = obj.as(Resource.class);
|
||||
if( res != null && res.getURI() != null ){
|
||||
BaseResourceBean.RoleLevel roleFromModel = BaseResourceBean.RoleLevel.getRoleByUri(res.getURI());
|
||||
if( roleFromModel != null &&
|
||||
|
@ -199,7 +199,7 @@ public class ObjectPropertyDaoJena extends PropertyDaoJena implements ObjectProp
|
|||
Statement stmt = it.nextStatement();
|
||||
RDFNode obj;
|
||||
if( stmt != null && (obj = stmt.getObject()) != null && obj.isURIResource() ){
|
||||
Resource res = (Resource)obj.as(Resource.class);
|
||||
Resource res = obj.as(Resource.class);
|
||||
if( res != null && res.getURI() != null ){
|
||||
BaseResourceBean.RoleLevel roleFromModel = BaseResourceBean.RoleLevel.getRoleByUri(res.getURI());
|
||||
if( roleFromModel != null &&
|
||||
|
@ -259,7 +259,7 @@ public class ObjectPropertyDaoJena extends PropertyDaoJena implements ObjectProp
|
|||
while (opIt.hasNext()) {
|
||||
Resource res = (Resource) opIt.next();
|
||||
if ( (res.canAs(OntProperty.class)) && (!NONUSER_NAMESPACES.contains(res.getNameSpace())) ) {
|
||||
props.add(propertyFromOntProperty((OntProperty)res.as(OntProperty.class)));
|
||||
props.add(propertyFromOntProperty(res.as(OntProperty.class)));
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
|
@ -298,7 +298,7 @@ public class ObjectPropertyDaoJena extends PropertyDaoJena implements ObjectProp
|
|||
while(it.hasNext()){
|
||||
ObjectPropertyStatement objPropertyStmt = (ObjectPropertyStatement)it.next();
|
||||
if (hash.containsKey(objPropertyStmt.getPropertyURI())) {
|
||||
ObjectProperty p = (ObjectProperty) hash.get(objPropertyStmt.getPropertyURI());
|
||||
ObjectProperty p = hash.get(objPropertyStmt.getPropertyURI());
|
||||
p.addObjectPropertyStatement(objPropertyStmt);
|
||||
} else {
|
||||
OntProperty op = getOntModel().getOntProperty(objPropertyStmt.getPropertyURI());
|
||||
|
@ -603,7 +603,7 @@ public class ObjectPropertyDaoJena extends PropertyDaoJena implements ObjectProp
|
|||
while(restIt.hasNext()) {
|
||||
Resource restRes = restIt.next();
|
||||
if (restRes.canAs(OntResource.class)) {
|
||||
OntResource restOntRes = (OntResource) restRes.as(OntResource.class);
|
||||
OntResource restOntRes = restRes.as(OntResource.class);
|
||||
smartRemove(restOntRes, ontModel);
|
||||
}
|
||||
}
|
||||
|
@ -627,7 +627,7 @@ public class ObjectPropertyDaoJena extends PropertyDaoJena implements ObjectProp
|
|||
while(restIt.hasNext()) {
|
||||
Resource restRes = restIt.next();
|
||||
if (restRes.canAs(OntResource.class)) {
|
||||
OntResource restOntRes = (OntResource) restRes.as(OntResource.class);
|
||||
OntResource restOntRes = restRes.as(OntResource.class);
|
||||
smartRemove(restOntRes, ontModel);
|
||||
}
|
||||
}
|
||||
|
@ -660,7 +660,7 @@ public class ObjectPropertyDaoJena extends PropertyDaoJena implements ObjectProp
|
|||
while (propIt.hasNext()) {
|
||||
Resource res = (Resource) propIt.next();
|
||||
if (res.canAs(OntProperty.class)) {
|
||||
com.hp.hpl.jena.ontology.OntProperty op = (com.hp.hpl.jena.ontology.OntProperty) res.as(OntProperty.class);
|
||||
com.hp.hpl.jena.ontology.OntProperty op = res.as(OntProperty.class);
|
||||
boolean isRoot = false;
|
||||
Iterator parentIt = op.listSuperProperties();
|
||||
if (parentIt != null) {
|
||||
|
|
|
@ -99,7 +99,7 @@ public class ObjectPropertyStatementDaoJena extends JenaBaseDao implements Objec
|
|||
ClosableIterator<Statement> propIt = ind.listProperties();
|
||||
try {
|
||||
while (propIt.hasNext()) {
|
||||
Statement st = (Statement) propIt.next();
|
||||
Statement st = propIt.next();
|
||||
|
||||
if (st.getObject().isResource() && !(NONUSER_NAMESPACES.contains(st.getPredicate().getNameSpace()))) {
|
||||
try {
|
||||
|
@ -173,7 +173,7 @@ public class ObjectPropertyStatementDaoJena extends JenaBaseDao implements Objec
|
|||
try {
|
||||
int count = 0;
|
||||
while ( (opsIt.hasNext()) && ((endIndex<0) || (count<endIndex)) ) {
|
||||
Statement stmt = (Statement) opsIt.next();
|
||||
Statement stmt = opsIt.next();
|
||||
if (stmt.getObject().isResource()) {
|
||||
++count;
|
||||
if (startIndex<0 || startIndex<=count) {
|
||||
|
|
|
@ -102,7 +102,7 @@ public class ObjectPropertyStatementDaoSDB extends
|
|||
ClosableIterator<Statement> propIt = ind.listProperties();
|
||||
try {
|
||||
while (propIt.hasNext()) {
|
||||
Statement st = (Statement) propIt.next();
|
||||
Statement st = propIt.next();
|
||||
if (st.getObject().isResource() && !(NONUSER_NAMESPACES.contains(st.getPredicate().getNameSpace()))) {
|
||||
try {
|
||||
ObjectPropertyStatement objPropertyStmt = new ObjectPropertyStatementImpl();
|
||||
|
|
|
@ -2,10 +2,8 @@
|
|||
|
||||
package edu.cornell.mannlib.vitro.webapp.dao.jena;
|
||||
|
||||
import java.text.Collator;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
import com.hp.hpl.jena.ontology.OntModel;
|
||||
|
@ -16,7 +14,6 @@ import com.hp.hpl.jena.util.iterator.ClosableIterator;
|
|||
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Ontology;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.OntologyDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||
|
||||
public class OntologyDaoJena extends JenaBaseDao implements OntologyDao {
|
||||
|
||||
|
|
|
@ -8,7 +8,6 @@ import java.util.HashMap;
|
|||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
|
|
@ -34,7 +34,6 @@ import com.hp.hpl.jena.rdf.model.Statement;
|
|||
import com.hp.hpl.jena.rdf.model.StmtIterator;
|
||||
import com.hp.hpl.jena.shared.Lock;
|
||||
import com.hp.hpl.jena.sparql.resultset.ResultSetMem;
|
||||
import com.hp.hpl.jena.util.iterator.ClosableIterator;
|
||||
import com.hp.hpl.jena.vocabulary.OWL;
|
||||
import com.hp.hpl.jena.vocabulary.RDFS;
|
||||
|
||||
|
@ -151,7 +150,7 @@ public class PropertyDaoJena extends JenaBaseDao implements PropertyDao {
|
|||
List<String> directSubproperties = getSubPropertyURIs(propertyURI);
|
||||
Iterator<String> it=directSubproperties.iterator();
|
||||
while(it.hasNext()){
|
||||
String uri = (String)it.next();
|
||||
String uri = it.next();
|
||||
if (!subtree.contains(uri)) {
|
||||
subtree.add(uri);
|
||||
getAllSubPropertyURIs(uri,subtree);
|
||||
|
@ -192,7 +191,7 @@ public class PropertyDaoJena extends JenaBaseDao implements PropertyDao {
|
|||
List<String> directSuperproperties = getSuperPropertyURIs(propertyURI,true);
|
||||
Iterator<String> it=directSuperproperties.iterator();
|
||||
while(it.hasNext()){
|
||||
String uri = (String)it.next();
|
||||
String uri = it.next();
|
||||
if (!subtree.contains(uri)) {
|
||||
subtree.add(uri);
|
||||
getAllSuperPropertyURIs(uri,subtree);
|
||||
|
@ -342,13 +341,13 @@ public class PropertyDaoJena extends JenaBaseDao implements PropertyDao {
|
|||
|
||||
if (targetProp != null) {
|
||||
|
||||
StmtIterator stmtIter = ontModel.listStatements((Resource) null, OWL.onProperty, (RDFNode) targetProp);
|
||||
StmtIterator stmtIter = ontModel.listStatements((Resource) null, OWL.onProperty, targetProp);
|
||||
|
||||
while (stmtIter.hasNext()) {
|
||||
Statement statement = stmtIter.next();
|
||||
|
||||
if ( statement.getSubject().canAs(OntClass.class) ) {
|
||||
classURISet.addAll(getRelatedClasses((OntClass) statement.getSubject().as(OntClass.class)));
|
||||
classURISet.addAll(getRelatedClasses(statement.getSubject().as(OntClass.class)));
|
||||
} else {
|
||||
log.warn("getClassesWithRestrictionOnProperty: Unexpected use of onProperty: it is not applied to a class");
|
||||
}
|
||||
|
@ -661,7 +660,7 @@ public class PropertyDaoJena extends JenaBaseDao implements PropertyDao {
|
|||
// TODO: check if restriction is something like
|
||||
// maxCardinality 0 or allValuesFrom owl:Nothing,
|
||||
// in which case the property is NOT applicable!
|
||||
Restriction rest = (Restriction) relatedClass.as(Restriction.class);
|
||||
Restriction rest = relatedClass.as(Restriction.class);
|
||||
OntProperty onProperty = rest.getOnProperty();
|
||||
if (onProperty != null) {
|
||||
Resource[] ranges = new Resource[2];
|
||||
|
@ -726,7 +725,7 @@ public class PropertyDaoJena extends JenaBaseDao implements PropertyDao {
|
|||
rangeClassURI = PSEUDO_BNODE_NS + rangeRes.getId()
|
||||
.toString();
|
||||
} else {
|
||||
rangeClassURI = (String) rangeRes.getURI();
|
||||
rangeClassURI = rangeRes.getURI();
|
||||
}
|
||||
pi.setRangeClassURI(rangeClassURI);
|
||||
VClass range = getWebappDaoFactory().getVClassDao()
|
||||
|
|
|
@ -4,7 +4,6 @@ package edu.cornell.mannlib.vitro.webapp.dao.jena;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
|
@ -16,7 +15,6 @@ import com.hp.hpl.jena.datatypes.xsd.XSDDatatype;
|
|||
import com.hp.hpl.jena.ontology.Individual;
|
||||
import com.hp.hpl.jena.ontology.OntModel;
|
||||
import com.hp.hpl.jena.ontology.OntModelSpec;
|
||||
import com.hp.hpl.jena.rdf.model.Literal;
|
||||
import com.hp.hpl.jena.rdf.model.Model;
|
||||
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
||||
import com.hp.hpl.jena.rdf.model.Resource;
|
||||
|
@ -26,7 +24,6 @@ import com.hp.hpl.jena.shared.Lock;
|
|||
import com.hp.hpl.jena.util.iterator.ClosableIterator;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.IndividualImpl;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Property;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.PropertyGroup;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyDao;
|
||||
|
@ -228,7 +225,7 @@ public class PropertyGroupDaoJena extends JenaBaseDao implements PropertyGroupDa
|
|||
try {
|
||||
Individual groupInd = ontModel.getIndividual(group.getURI());
|
||||
try {
|
||||
groupInd.setLabel(group.getName(), (String) getDefaultLanguage());
|
||||
groupInd.setLabel(group.getName(), getDefaultLanguage());
|
||||
} catch (Exception e) {
|
||||
log.error("error updating name for "+groupInd.getURI());
|
||||
}
|
||||
|
|
|
@ -7,27 +7,18 @@ import java.util.Calendar;
|
|||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.hp.hpl.jena.ontology.ObjectProperty;
|
||||
import com.hp.hpl.jena.ontology.OntClass;
|
||||
import com.hp.hpl.jena.ontology.OntModel;
|
||||
import com.hp.hpl.jena.ontology.OntProperty;
|
||||
import com.hp.hpl.jena.ontology.Restriction;
|
||||
import com.hp.hpl.jena.rdf.model.Property;
|
||||
import com.hp.hpl.jena.rdf.model.Resource;
|
||||
import com.hp.hpl.jena.rdf.model.ResourceFactory;
|
||||
import com.hp.hpl.jena.rdf.model.Statement;
|
||||
import com.hp.hpl.jena.rdf.model.StmtIterator;
|
||||
import com.hp.hpl.jena.shared.Lock;
|
||||
import com.hp.hpl.jena.vocabulary.OWL;
|
||||
import com.hp.hpl.jena.vocabulary.RDF;
|
||||
import com.hp.hpl.jena.vocabulary.RDFS;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement;
|
||||
|
@ -35,7 +26,6 @@ import edu.cornell.mannlib.vitro.webapp.beans.PropertyInstance;
|
|||
import edu.cornell.mannlib.vitro.webapp.beans.PropertyInstanceIface;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.PropertyInstanceDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.VClassDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.event.IndividualDeletionEvent;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.event.IndividualUpdateEvent;
|
||||
public class PropertyInstanceDaoJena extends PropertyDaoJena implements
|
||||
|
@ -58,7 +48,7 @@ public class PropertyInstanceDaoJena extends PropertyDaoJena implements
|
|||
Property pred = tboxModel.getProperty(propertyURI);
|
||||
OntProperty invPred = null;
|
||||
if (pred.canAs(OntProperty.class)) {
|
||||
invPred = ((OntProperty)pred.as(OntProperty.class)).getInverse();
|
||||
invPred = pred.as(OntProperty.class).getInverse();
|
||||
}
|
||||
Resource objRes = ontModel.getResource(objectURI);
|
||||
if ( (subjRes != null) && (pred != null) && (objRes != null) ) {
|
||||
|
|
|
@ -8,7 +8,6 @@ import java.util.Iterator;
|
|||
import com.hp.hpl.jena.graph.Node;
|
||||
import com.hp.hpl.jena.query.Dataset;
|
||||
import com.hp.hpl.jena.rdf.model.Model;
|
||||
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
||||
import com.hp.hpl.jena.shared.Lock;
|
||||
import com.hp.hpl.jena.sparql.core.DatasetGraph;
|
||||
|
||||
|
|
|
@ -10,10 +10,6 @@ import java.util.List;
|
|||
import com.hp.hpl.jena.graph.Graph;
|
||||
import com.hp.hpl.jena.graph.Node;
|
||||
import com.hp.hpl.jena.graph.Triple;
|
||||
import com.hp.hpl.jena.query.Query;
|
||||
import com.hp.hpl.jena.query.QueryExecution;
|
||||
import com.hp.hpl.jena.query.QueryExecutionFactory;
|
||||
import com.hp.hpl.jena.query.QueryFactory;
|
||||
import com.hp.hpl.jena.query.QuerySolution;
|
||||
import com.hp.hpl.jena.query.ResultSet;
|
||||
import com.hp.hpl.jena.shared.Lock;
|
||||
|
@ -21,7 +17,6 @@ import com.hp.hpl.jena.shared.LockMRSW;
|
|||
import com.hp.hpl.jena.sparql.core.DatasetGraph;
|
||||
import com.hp.hpl.jena.sparql.core.Quad;
|
||||
import com.hp.hpl.jena.sparql.resultset.JSONInput;
|
||||
import com.hp.hpl.jena.sparql.resultset.ResultSetMem;
|
||||
import com.hp.hpl.jena.sparql.util.Context;
|
||||
import com.hp.hpl.jena.util.iterator.SingletonIterator;
|
||||
import com.hp.hpl.jena.util.iterator.WrappedIterator;
|
||||
|
|
|
@ -4,7 +4,6 @@ package edu.cornell.mannlib.vitro.webapp.dao.jena;
|
|||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
|
|
|
@ -305,7 +305,7 @@ public class RDFServiceModelMaker implements ModelMaker {
|
|||
List<String> graphNames = rdfService.getGraphURIs();
|
||||
Iterator<String> nameIt = graphNames.iterator();
|
||||
while (nameIt.hasNext()) {
|
||||
String name = (String) nameIt.next();
|
||||
String name = nameIt.next();
|
||||
metadataModel.add(dbResource,metadataModel.getProperty(
|
||||
HAS_NAMED_MODEL_URI),name);
|
||||
}
|
||||
|
|
|
@ -98,11 +98,11 @@ public class VClassDaoJena extends JenaBaseDao implements VClassDao {
|
|||
labelStr += "some values from ";
|
||||
}
|
||||
if (fillerRes.canAs(OntClass.class)) {
|
||||
OntClass avf = (OntClass) fillerRes.as(OntClass.class);
|
||||
OntClass avf = fillerRes.as(OntClass.class);
|
||||
labelStr += getLabelForClass(avf,withPrefix,forPickList);
|
||||
} else {
|
||||
try {
|
||||
labelStr += getLabelOrId( (OntResource) fillerRes.as(OntResource.class));
|
||||
labelStr += getLabelOrId(fillerRes.as(OntResource.class));
|
||||
} catch (Exception e) {
|
||||
labelStr += "???";
|
||||
}
|
||||
|
@ -113,9 +113,9 @@ public class VClassDaoJena extends JenaBaseDao implements VClassDao {
|
|||
RDFNode fillerNode = hvRest.getHasValue();
|
||||
try {
|
||||
if (fillerNode.isResource()) {
|
||||
labelStr += getLabelOrId((OntResource)fillerNode.as(OntResource.class));
|
||||
labelStr += getLabelOrId(fillerNode.as(OntResource.class));
|
||||
} else {
|
||||
labelStr += ((Literal) fillerNode.as(Literal.class)).getLexicalForm();
|
||||
labelStr += fillerNode.as(Literal.class).getLexicalForm();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
labelStr += "???";
|
||||
|
@ -138,10 +138,10 @@ public class VClassDaoJena extends JenaBaseDao implements VClassDao {
|
|||
String labelStr = "(";
|
||||
if (cls.isComplementClass()) {
|
||||
labelStr += "not ";
|
||||
ComplementClass ccls = (ComplementClass) cls.as(ComplementClass.class);
|
||||
ComplementClass ccls = cls.as(ComplementClass.class);
|
||||
labelStr += getLabelForClass(ccls.getOperand(),withPrefix,forPickList);
|
||||
} else if (cls.isIntersectionClass()) {
|
||||
IntersectionClass icls = (IntersectionClass) cls.as(IntersectionClass.class);
|
||||
IntersectionClass icls = cls.as(IntersectionClass.class);
|
||||
for (Iterator operandIt = icls.listOperands(); operandIt.hasNext();) {
|
||||
OntClass operand = (OntClass) operandIt.next();
|
||||
labelStr += getLabelForClass(operand,withPrefix,forPickList);
|
||||
|
@ -150,7 +150,7 @@ public class VClassDaoJena extends JenaBaseDao implements VClassDao {
|
|||
}
|
||||
}
|
||||
} else if (cls.isUnionClass()) {
|
||||
UnionClass icls = (UnionClass) cls.as(UnionClass.class);
|
||||
UnionClass icls = cls.as(UnionClass.class);
|
||||
for (Iterator operandIt = icls.listOperands(); operandIt.hasNext();) {
|
||||
OntClass operand = (OntClass) operandIt.next();
|
||||
labelStr += getLabelForClass(operand,withPrefix,forPickList);
|
||||
|
@ -169,7 +169,7 @@ public class VClassDaoJena extends JenaBaseDao implements VClassDao {
|
|||
} else {
|
||||
if (withPrefix || forPickList) {
|
||||
OntologyDao oDao=getWebappDaoFactory().getOntologyDao();
|
||||
Ontology o = (Ontology)oDao.getOntologyByURI(cls.getNameSpace());
|
||||
Ontology o = oDao.getOntologyByURI(cls.getNameSpace());
|
||||
if (o!=null) {
|
||||
if (withPrefix) {
|
||||
return(o.getPrefix()==null?(o.getName()==null?"unspec:"+getLabelOrId(cls):o.getName()+":"+getLabelOrId(cls)):o.getPrefix()+":"+getLabelOrId(cls));
|
||||
|
@ -208,7 +208,7 @@ public class VClassDaoJena extends JenaBaseDao implements VClassDao {
|
|||
while(restIt.hasNext()) {
|
||||
Resource restRes = restIt.next();
|
||||
if (restRes.canAs(OntResource.class)) {
|
||||
OntResource restOntRes = (OntResource) restRes.as(OntResource.class);
|
||||
OntResource restOntRes = restRes.as(OntResource.class);
|
||||
smartRemove(restOntRes, ontModel);
|
||||
}
|
||||
}
|
||||
|
@ -216,7 +216,7 @@ public class VClassDaoJena extends JenaBaseDao implements VClassDao {
|
|||
while(restIt.hasNext()) {
|
||||
Resource restRes = restIt.next();
|
||||
if (restRes.canAs(OntResource.class)) {
|
||||
OntResource restOntRes = (OntResource) restRes.as(OntResource.class);
|
||||
OntResource restOntRes = restRes.as(OntResource.class);
|
||||
smartRemove(restOntRes, ontModel);
|
||||
}
|
||||
}
|
||||
|
@ -400,7 +400,7 @@ public class VClassDaoJena extends JenaBaseDao implements VClassDao {
|
|||
List<String> directSubclasses = getSubClassURIs(classURI);
|
||||
Iterator<String> it=directSubclasses.iterator();
|
||||
while(it.hasNext()){
|
||||
String uri = (String)it.next();
|
||||
String uri = it.next();
|
||||
if (!subtree.contains(uri)) {
|
||||
subtree.add(uri);
|
||||
getAllSubClassURIs(uri,subtree);
|
||||
|
@ -423,7 +423,7 @@ public class VClassDaoJena extends JenaBaseDao implements VClassDao {
|
|||
while (superClassIt.hasNext()) {
|
||||
Statement stmt = superClassIt.nextStatement();
|
||||
if (stmt.getObject().canAs(OntResource.class)) {
|
||||
OntResource superRes = (OntResource) stmt.getObject().as(OntResource.class);
|
||||
OntResource superRes = stmt.getObject().as(OntResource.class);
|
||||
String test = getClassURIStr(superRes);
|
||||
superclassURIs.add(test);
|
||||
}
|
||||
|
@ -442,7 +442,7 @@ public class VClassDaoJena extends JenaBaseDao implements VClassDao {
|
|||
List<String> directSuperclasses = getSuperClassURIs(classURI, true);
|
||||
Iterator<String> it=directSuperclasses.iterator();
|
||||
while(it.hasNext()){
|
||||
String uri = (String)it.next();
|
||||
String uri = it.next();
|
||||
if (!subtree.contains(uri)) {
|
||||
subtree.add(uri);
|
||||
getAllSuperClassURIs(uri,subtree);
|
||||
|
@ -459,7 +459,7 @@ public class VClassDaoJena extends JenaBaseDao implements VClassDao {
|
|||
while (classIt.hasNext()) {
|
||||
try {
|
||||
Individual classInd = classIt.next();
|
||||
OntClass cls = (OntClass) classInd.as(OntClass.class);
|
||||
OntClass cls = classInd.as(OntClass.class);
|
||||
if (!cls.isAnon() && !(NONUSER_NAMESPACES.contains(cls.getNameSpace()))) {
|
||||
classes.add(new VClassJena(cls,getWebappDaoFactory()));
|
||||
}
|
||||
|
@ -724,17 +724,17 @@ public class VClassDaoJena extends JenaBaseDao implements VClassDao {
|
|||
Statement axStmt = (Statement) axStmtIt.next();
|
||||
OntResource subjOntRes = null;
|
||||
if (axStmt.getSubject().canAs(OntResource.class)) {
|
||||
subjOntRes = (OntResource) axStmt.getSubject().as(OntResource.class);
|
||||
subjOntRes = axStmt.getSubject().as(OntResource.class);
|
||||
}
|
||||
if (
|
||||
(subjOntRes != null) && (subjSuperclasses.contains(getClassURIStr(subjOntRes))) &&
|
||||
(axStmt.getPredicate().equals(RDFS.subClassOf) || (axStmt.getPredicate().equals(OWL.equivalentClass)))
|
||||
) {
|
||||
if (restRes.canAs(AllValuesFromRestriction.class)) {
|
||||
AllValuesFromRestriction avfRest = (AllValuesFromRestriction) restRes.as(AllValuesFromRestriction.class);
|
||||
AllValuesFromRestriction avfRest = restRes.as(AllValuesFromRestriction.class);
|
||||
Resource avf = avfRest.getAllValuesFrom();
|
||||
if (avf.canAs(OntClass.class)) {
|
||||
superclass = (OntClass) avfRest.getAllValuesFrom().as(OntClass.class);
|
||||
superclass = avfRest.getAllValuesFrom().as(OntClass.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -818,8 +818,8 @@ public class VClassDaoJena extends JenaBaseDao implements VClassDao {
|
|||
while (annotIt.hasNext()) {
|
||||
try {
|
||||
Statement annot = (Statement) annotIt.next();
|
||||
Resource cls = (Resource) annot.getSubject();
|
||||
VClass vcw = (VClass) getVClassByURI(cls.getURI());
|
||||
Resource cls = annot.getSubject();
|
||||
VClass vcw = getVClassByURI(cls.getURI());
|
||||
if (vcw != null) {
|
||||
boolean classIsInstantiated = false;
|
||||
if (getIndividualCount) {
|
||||
|
@ -926,7 +926,7 @@ public class VClassDaoJena extends JenaBaseDao implements VClassDao {
|
|||
OntClass ontCls = ontModel.createClass(cls.getURI());
|
||||
try {
|
||||
if (cls.getName() != null && cls.getName().length() > 0) {
|
||||
ontCls.setLabel(cls.getName(), (String) getDefaultLanguage());
|
||||
ontCls.setLabel(cls.getName(), getDefaultLanguage());
|
||||
} else {
|
||||
ontCls.removeAll(RDFS.label);
|
||||
}
|
||||
|
|
|
@ -2,6 +2,9 @@
|
|||
|
||||
package edu.cornell.mannlib.vitro.webapp.dao.jena;
|
||||
|
||||
|
||||
import com.hp.hpl.jena.ontology.AnnotationProperty;
|
||||
import com.hp.hpl.jena.ontology.OntClass;
|
||||
import com.hp.hpl.jena.query.Dataset;
|
||||
import com.hp.hpl.jena.query.Query;
|
||||
import com.hp.hpl.jena.query.QueryExecution;
|
||||
|
@ -59,9 +62,9 @@ public class VClassDaoSDB extends VClassDaoJena {
|
|||
try {
|
||||
while (annotIt.hasNext()) {
|
||||
try {
|
||||
Statement annot = (Statement) annotIt.nextStatement();
|
||||
Resource cls = (Resource) annot.getSubject();
|
||||
VClass vcw = (VClass) getVClassByURI(cls.getURI());
|
||||
Statement annot = (Statement) annotIt.next();
|
||||
Resource cls = annot.getSubject();
|
||||
VClass vcw = getVClassByURI(cls.getURI());
|
||||
if (vcw != null) {
|
||||
boolean classIsInstantiated = false;
|
||||
if (getIndividualCount) {
|
||||
|
|
|
@ -4,10 +4,8 @@ package edu.cornell.mannlib.vitro.webapp.dao.jena;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.ServletContextEvent;
|
||||
|
@ -33,7 +31,6 @@ import com.hp.hpl.jena.vocabulary.RDFS;
|
|||
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.VClassGroup;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.VClassDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.VClassGroupDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||
|
|
|
@ -14,11 +14,9 @@ import org.apache.commons.logging.Log;
|
|||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import com.hp.hpl.jena.datatypes.xsd.XSDDatatype;
|
||||
import com.hp.hpl.jena.ontology.DatatypeProperty;
|
||||
import com.hp.hpl.jena.ontology.Individual;
|
||||
import com.hp.hpl.jena.ontology.OntModel;
|
||||
import com.hp.hpl.jena.ontology.OntModelSpec;
|
||||
import com.hp.hpl.jena.rdf.model.Literal;
|
||||
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
||||
import com.hp.hpl.jena.rdf.model.Resource;
|
||||
import com.hp.hpl.jena.rdf.model.ResourceFactory;
|
||||
|
@ -32,7 +30,6 @@ import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary;
|
|||
import edu.cornell.mannlib.vitro.webapp.dao.InsertException;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.VClassDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.VClassGroupDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||
import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch;
|
||||
|
||||
|
@ -82,7 +79,7 @@ public class VClassGroupDaoJena extends JenaBaseDao implements VClassGroupDao {
|
|||
ClosableIterator<Individual> groupIt = getOntModel().listIndividuals(CLASSGROUP);
|
||||
try {
|
||||
while (groupIt.hasNext()) {
|
||||
Individual groupInd = (Individual) groupIt.next();
|
||||
Individual groupInd = groupIt.next();
|
||||
VClassGroup group = groupFromGroupIndividual(groupInd);
|
||||
if (group!=null) {
|
||||
groups.add(group);
|
||||
|
@ -94,7 +91,7 @@ public class VClassGroupDaoJena extends JenaBaseDao implements VClassGroupDao {
|
|||
Collections.sort(groups);
|
||||
Iterator<VClassGroup> groupsIt = groups.iterator();
|
||||
while (groupsIt.hasNext()) {
|
||||
VClassGroup group = (VClassGroup) groupsIt.next();
|
||||
VClassGroup group = groupsIt.next();
|
||||
map.put(group.getPublicName(), group);
|
||||
}
|
||||
return map;
|
||||
|
@ -140,7 +137,7 @@ public class VClassGroupDaoJena extends JenaBaseDao implements VClassGroupDao {
|
|||
ClosableIterator<Individual> groupIt = getOntModel().listIndividuals(CLASSGROUP);
|
||||
try {
|
||||
while (groupIt.hasNext()) {
|
||||
Individual grp = (Individual) groupIt.next();
|
||||
Individual grp = groupIt.next();
|
||||
VClassGroup vgrp = groupFromGroupIndividual(grp);
|
||||
if (vgrp != null) {
|
||||
groups.add(vgrp);
|
||||
|
@ -247,7 +244,7 @@ public class VClassGroupDaoJena extends JenaBaseDao implements VClassGroupDao {
|
|||
int removedGroupsCount = 0;
|
||||
ListIterator<VClassGroup> it = groups.listIterator();
|
||||
while(it.hasNext()){
|
||||
VClassGroup group = (VClassGroup) it.next();
|
||||
VClassGroup group = it.next();
|
||||
List<VClass> classes = group.getVitroClassList();
|
||||
if( classes == null || classes.size() < 1 ){
|
||||
removedGroupsCount++;
|
||||
|
@ -283,7 +280,7 @@ public class VClassGroupDaoJena extends JenaBaseDao implements VClassGroupDao {
|
|||
try {
|
||||
Individual groupInd = ontModel.getIndividual(vcg.getURI());
|
||||
try {
|
||||
groupInd.setLabel(vcg.getPublicName(), (String) getDefaultLanguage());
|
||||
groupInd.setLabel(vcg.getPublicName(), getDefaultLanguage());
|
||||
} catch (Exception e) {
|
||||
log.error("error updating name for "+groupInd.getURI());
|
||||
}
|
||||
|
|
|
@ -324,7 +324,7 @@ public class VClassJena extends VClass {
|
|||
Statement stmt = it.nextStatement();
|
||||
RDFNode obj;
|
||||
if( stmt != null && (obj = stmt.getObject()) != null && obj.isURIResource() ){
|
||||
Resource res = (Resource)obj.as(Resource.class);
|
||||
Resource res = obj.as(Resource.class);
|
||||
if( res != null && res.getURI() != null ){
|
||||
BaseResourceBean.RoleLevel roleFromModel = BaseResourceBean.RoleLevel.getRoleByUri(res.getURI());
|
||||
if( roleFromModel != null &&
|
||||
|
@ -358,7 +358,7 @@ public class VClassJena extends VClass {
|
|||
Statement stmt = it.nextStatement();
|
||||
RDFNode obj;
|
||||
if( stmt != null && (obj = stmt.getObject()) != null && obj.isURIResource() ){
|
||||
Resource res = (Resource)obj.as(Resource.class);
|
||||
Resource res = obj.as(Resource.class);
|
||||
if( res != null && res.getURI() != null ){
|
||||
BaseResourceBean.RoleLevel roleFromModel = BaseResourceBean.RoleLevel.getRoleByUri(res.getURI());
|
||||
if( roleFromModel != null &&
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
|
||||
package edu.cornell.mannlib.vitro.webapp.dao.jena;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
|
@ -14,7 +12,6 @@ import com.hp.hpl.jena.ontology.OntModel;
|
|||
import com.hp.hpl.jena.rdf.model.Model;
|
||||
import com.hp.hpl.jena.rdf.model.ModelMaker;
|
||||
import com.hp.hpl.jena.rdf.model.ModelReader;
|
||||
import com.hp.hpl.jena.rdf.model.Resource;
|
||||
import com.hp.hpl.jena.util.iterator.ExtendedIterator;
|
||||
|
||||
/**
|
||||
|
|
|
@ -11,7 +11,6 @@ import java.util.Set;
|
|||
|
||||
import com.hp.hpl.jena.iri.IRI;
|
||||
import com.hp.hpl.jena.iri.IRIFactory;
|
||||
import com.hp.hpl.jena.iri.Violation;
|
||||
import com.hp.hpl.jena.ontology.OntModel;
|
||||
import com.hp.hpl.jena.ontology.OntModelSpec;
|
||||
import com.hp.hpl.jena.ontology.OntResource;
|
||||
|
@ -184,7 +183,7 @@ public class WebappDaoFactoryJena implements WebappDaoFactory {
|
|||
IRI iri = factory.create( uriStr );
|
||||
if (iri.hasViolation(false) ) {
|
||||
validURI = false;
|
||||
errorMsg += ((Violation)iri.violations(false).next())
|
||||
errorMsg += (iri.violations(false).next())
|
||||
.getShortMessage() + " ";
|
||||
} else if (checkUniqueness) {
|
||||
OntModel ontModel = ontModelSelector.getFullModel();
|
||||
|
|
|
@ -2,15 +2,9 @@
|
|||
|
||||
package edu.cornell.mannlib.vitro.webapp.dao.jena.pellet;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
|
||||
import com.hp.hpl.jena.rdf.model.Property;
|
||||
import com.hp.hpl.jena.rdf.model.Resource;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.pellet.ObjectPropertyStatementPattern;
|
||||
|
||||
public class ObjectPropertyStatementPatternFactory {
|
||||
|
||||
//private static Set<ObjectPropertyStatementPattern> patternSet = new HashSet<ObjectPropertyStatementPattern>();
|
||||
|
|
|
@ -320,9 +320,9 @@ public class PelletListener implements ModelChangedListener {
|
|||
try {
|
||||
if ( ( ((Resource)stmt.getObject()).equals(RDFS.Resource) ) ) {
|
||||
reject = true;
|
||||
} else if ( ( ((Resource)stmt.getSubject()).equals(OWL.Nothing) ) ) {
|
||||
} else if ( ( stmt.getSubject().equals(OWL.Nothing) ) ) {
|
||||
reject = true;
|
||||
} else if ( ( ((Resource)stmt.getObject()).equals(OWL.Nothing) ) ) {
|
||||
} else if ( ( stmt.getObject().equals(OWL.Nothing) ) ) {
|
||||
reject = true;
|
||||
}
|
||||
} catch (Exception e) {}
|
||||
|
|
|
@ -2,27 +2,11 @@
|
|||
|
||||
package edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.utils;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
|
||||
import net.sf.json.JSONObject;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import com.hp.hpl.jena.ontology.OntModel;
|
||||
import com.hp.hpl.jena.rdf.model.RDFNode;
|
||||
import com.hp.hpl.jena.rdf.model.ResourceFactory;
|
||||
import com.hp.hpl.jena.rdf.model.StmtIterator;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.ModelContext;
|
||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.utils.ProcessDataGetterN3;
|
||||
import edu.cornell.mannlib.vitro.webapp.utils.dataGetter.DataGetter;
|
||||
|
||||
/*
|
||||
* This class determines what n3 should be returned for a particular data getter and can be overwritten or extended in VIVO.
|
||||
*/
|
||||
|
|
|
@ -4,25 +4,12 @@ package edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocess
|
|||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
|
||||
import net.sf.json.JSONObject;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import com.hp.hpl.jena.ontology.OntModel;
|
||||
import com.hp.hpl.jena.rdf.model.RDFNode;
|
||||
import com.hp.hpl.jena.rdf.model.ResourceFactory;
|
||||
import com.hp.hpl.jena.rdf.model.StmtIterator;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.ModelContext;
|
||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.utils.ProcessDataGetterN3;
|
||||
import edu.cornell.mannlib.vitro.webapp.utils.dataGetter.DataGetter;
|
||||
|
||||
/*
|
||||
* This class determines what n3 should be returned for a particular data getter and can be overwritten or extended in VIVO.
|
||||
*/
|
||||
|
|
|
@ -61,8 +61,8 @@ public class FreemarkerEmailFactory {
|
|||
FreemarkerEmailFactory factory = getFactory(vreq);
|
||||
FreemarkerConfiguration fConfig = FreemarkerConfigurationLoader
|
||||
.getConfig(vreq);
|
||||
return new FreemarkerEmailMessage(fConfig, factory.getEmailSession(),
|
||||
factory.getReplyToAddress());
|
||||
return new FreemarkerEmailMessage(vreq, fConfig,
|
||||
factory.getEmailSession(), factory.getReplyToAddress());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -27,8 +27,10 @@ import javax.mail.internet.MimeMultipart;
|
|||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerConfiguration;
|
||||
import edu.cornell.mannlib.vitro.webapp.web.directives.EmailDirective;
|
||||
import freemarker.core.Environment;
|
||||
import freemarker.template.Template;
|
||||
import freemarker.template.TemplateException;
|
||||
|
||||
|
@ -47,7 +49,8 @@ public class FreemarkerEmailMessage {
|
|||
private static final Log log = LogFactory
|
||||
.getLog(FreemarkerEmailMessage.class);
|
||||
|
||||
private final Session session;
|
||||
private final VitroRequest vreq;
|
||||
private final Session mailSession;
|
||||
private final FreemarkerConfiguration config;
|
||||
|
||||
private final List<Recipient> recipients = new ArrayList<Recipient>();
|
||||
|
@ -63,9 +66,10 @@ public class FreemarkerEmailMessage {
|
|||
/**
|
||||
* Package access - should only be created by the factory.
|
||||
*/
|
||||
FreemarkerEmailMessage(FreemarkerConfiguration fConfig, Session session,
|
||||
InternetAddress replyToAddress) {
|
||||
this.session = session;
|
||||
FreemarkerEmailMessage(VitroRequest vreq, FreemarkerConfiguration fConfig,
|
||||
Session mailSession, InternetAddress replyToAddress) {
|
||||
this.vreq = vreq;
|
||||
this.mailSession = mailSession;
|
||||
this.replyToAddress = replyToAddress;
|
||||
this.config = fConfig;
|
||||
}
|
||||
|
@ -141,7 +145,13 @@ public class FreemarkerEmailMessage {
|
|||
|
||||
try {
|
||||
Template template = config.getTemplate(templateName);
|
||||
template.process(bodyMap, new StringWriter());
|
||||
|
||||
Environment env = template.createProcessingEnvironment(bodyMap,
|
||||
new StringWriter());
|
||||
env.setCustomAttribute("request", vreq);
|
||||
env.setCustomAttribute("context", vreq.getSession()
|
||||
.getServletContext());
|
||||
env.process();
|
||||
} catch (TemplateException e) {
|
||||
log.error(e, e);
|
||||
} catch (IOException e) {
|
||||
|
@ -151,7 +161,7 @@ public class FreemarkerEmailMessage {
|
|||
|
||||
public boolean send() {
|
||||
try {
|
||||
MimeMessage msg = new MimeMessage(session);
|
||||
MimeMessage msg = new MimeMessage(mailSession);
|
||||
msg.setReplyTo(new Address[] { replyToAddress });
|
||||
|
||||
if (fromAddress == null) {
|
||||
|
@ -199,11 +209,11 @@ public class FreemarkerEmailMessage {
|
|||
bodyPart.setContent(textBody, type);
|
||||
content.addBodyPart(bodyPart);
|
||||
}
|
||||
|
||||
public String getReplyToAddress() {
|
||||
return replyToAddress.getAddress();
|
||||
}
|
||||
|
||||
|
||||
public String getReplyToAddress() {
|
||||
return replyToAddress.getAddress();
|
||||
}
|
||||
|
||||
private <T> T nonNull(T value, T defaultValue) {
|
||||
return (value == null) ? defaultValue : value;
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ import static edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary.USE_MODEL_P
|
|||
import static edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary.USE_TBOX_MODEL_PARAM;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
|
@ -47,10 +48,14 @@ import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.FilterFactory;
|
|||
import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.HideFromDisplayByPolicyFilter;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.VitroFilters;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.ModelContext;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.RDFServiceGraph;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.VitroModelSource;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactoryJena;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactorySDB;
|
||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.filter.LanguageFilteringRDFService;
|
||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.filter.LanguageFilteringUtils;
|
||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceUtils;
|
||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.jena.model.RDFServiceModel;
|
||||
import edu.cornell.mannlib.vitro.webapp.servlet.setup.JenaDataSourceSetupBase;
|
||||
|
||||
/**
|
||||
|
@ -133,6 +138,22 @@ public class VitroRequestPrep implements Filter {
|
|||
log.debug("Found a WebappDaoFactory in the session and using it for this request");
|
||||
}
|
||||
|
||||
// Set up the DisplayModel, with language filtering if appropriate.
|
||||
OntModel displayModel;
|
||||
Object displayModelObject = req.getSession().getAttribute(DISPLAY_ONT_MODEL);
|
||||
if (displayModelObject instanceof OntModel) {
|
||||
displayModel = (OntModel) displayModelObject;
|
||||
} else {
|
||||
displayModel = (OntModel) _context.getAttribute(DISPLAY_ONT_MODEL);
|
||||
}
|
||||
|
||||
if (Boolean.valueOf(ConfigurationProperties.getBean(vreq).getProperty(
|
||||
"RDFService.languageFilter", "true"))) {
|
||||
displayModel = LanguageFilteringUtils.wrapOntModelInALanguageFilter(displayModel, req);
|
||||
}
|
||||
vreq.setAttribute(DISPLAY_ONT_MODEL, displayModel);
|
||||
|
||||
|
||||
//Do model switching and replace the WebappDaoFactory with
|
||||
//a different version if requested by parameters
|
||||
wdf = checkForModelSwitching(vreq, wdf);
|
||||
|
|
|
@ -3,10 +3,7 @@
|
|||
package edu.cornell.mannlib.vitro.webapp.filters;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
|
@ -22,6 +19,7 @@ import javax.servlet.http.HttpServletRequest;
|
|||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import com.hp.hpl.jena.ontology.OntModel;
|
||||
import com.hp.hpl.jena.ontology.OntModelSpec;
|
||||
import com.hp.hpl.jena.query.Dataset;
|
||||
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
||||
|
@ -38,6 +36,7 @@ import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactorySDB.SDBDatasetM
|
|||
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
|
||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceFactory;
|
||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.filter.LanguageFilteringRDFService;
|
||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.filter.LanguageFilteringUtils;
|
||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceUtils;
|
||||
|
||||
public class WebappDaoFactorySDBPrep implements Filter {
|
||||
|
@ -88,18 +87,10 @@ public class WebappDaoFactorySDBPrep implements Filter {
|
|||
String defaultNamespace = (String) _ctx.getAttribute("defaultNamespace");
|
||||
WebappDaoFactory wadf = null;
|
||||
VitroRequest vreq = new VitroRequest((HttpServletRequest) request);
|
||||
|
||||
List<String> langs = new ArrayList<String>();
|
||||
|
||||
log.debug("Accept-Language: " + vreq.getHeader("Accept-Language"));
|
||||
List<String> langs = LanguageFilteringUtils.localesToLanguages(vreq.getLocales());
|
||||
|
||||
log.debug("Accept-Language: " + vreq.getHeader("Accept-Language"));
|
||||
Enumeration<Locale> locs = vreq.getLocales();
|
||||
while (locs.hasMoreElements()) {
|
||||
Locale locale = locs.nextElement();
|
||||
langs.add(locale.toString().replace("_", "-"));
|
||||
}
|
||||
if (langs.isEmpty()) {
|
||||
langs.add("en");
|
||||
}
|
||||
WebappDaoFactoryConfig config = new WebappDaoFactoryConfig();
|
||||
config.setDefaultNamespace(defaultNamespace);
|
||||
config.setPreferredLanguages(langs);
|
||||
|
@ -110,12 +101,14 @@ public class WebappDaoFactorySDBPrep implements Filter {
|
|||
RDFService unfilteredRDFService = factory.getShortTermRDFService();
|
||||
RDFService rdfService = null;
|
||||
|
||||
if (!"false".equals(
|
||||
ConfigurationProperties.getBean(vreq).getProperty(
|
||||
"RDFService.languageFilter", "true"))) {
|
||||
rdfService = new LanguageFilteringRDFService(unfilteredRDFService, langs);
|
||||
if (Boolean.valueOf(ConfigurationProperties.getBean(vreq).getProperty(
|
||||
"RDFService.languageFilter", "true"))) {
|
||||
rdfService = new LanguageFilteringRDFService(unfilteredRDFService, langs);
|
||||
oms = LanguageFilteringUtils.replaceDisplayModelInSelector(oms,
|
||||
LanguageFilteringUtils.wrapOntModelInALanguageFilter(oms.getDisplayModel(), request));
|
||||
baseOms = LanguageFilteringUtils.replaceDisplayModelInSelector(baseOms, oms.getDisplayModel());
|
||||
} else {
|
||||
rdfService = unfilteredRDFService;
|
||||
rdfService = unfilteredRDFService;
|
||||
}
|
||||
|
||||
Dataset dataset = new RDFServiceDataset(rdfService);
|
||||
|
|
|
@ -39,8 +39,9 @@ public class I18nBundle {
|
|||
public I18nBundle(String bundleName, ResourceBundle resources) {
|
||||
this(bundleName, resources, MESSAGE_KEY_NOT_FOUND);
|
||||
}
|
||||
|
||||
private I18nBundle(String bundleName, ResourceBundle resources, String notFoundMessage) {
|
||||
|
||||
private I18nBundle(String bundleName, ResourceBundle resources,
|
||||
String notFoundMessage) {
|
||||
if (bundleName == null) {
|
||||
throw new IllegalArgumentException("bundleName may not be null");
|
||||
}
|
||||
|
@ -49,20 +50,22 @@ public class I18nBundle {
|
|||
}
|
||||
if (resources == null) {
|
||||
throw new NullPointerException("resources may not be null.");
|
||||
}if (notFoundMessage == null) {
|
||||
}
|
||||
if (notFoundMessage == null) {
|
||||
throw new NullPointerException("notFoundMessage may not be null.");
|
||||
}
|
||||
this.bundleName = bundleName;
|
||||
this.resources = resources;
|
||||
this.notFoundMessage = notFoundMessage;
|
||||
}
|
||||
|
||||
|
||||
public String text(String key, Object... parameters) {
|
||||
log.debug("Asking for '" + key + "' from bundle '" + bundleName + "'");
|
||||
|
||||
String textString;
|
||||
if (resources.containsKey(key)) {
|
||||
textString = resources.getString(key);
|
||||
log.debug("In '" + bundleName + "', " + key + "='" + textString
|
||||
+ "')");
|
||||
return formatString(textString, parameters);
|
||||
} else {
|
||||
String message = MessageFormat.format(notFoundMessage, bundleName,
|
||||
|
|
|
@ -53,6 +53,23 @@ public class VitroResourceBundle extends ResourceBundle {
|
|||
// Factory method
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Returns the bundle for the for foo_ba_RR, providing that
|
||||
* foo_ba_RR.properties exists in the I18n area of either the theme or the
|
||||
* application.
|
||||
*
|
||||
* If the desired file doesn't exist in either location, return null.
|
||||
* Usually, this does not indicate a problem but only that we were looking
|
||||
* for too specific a bundle. For example, if the base name of the bundle is
|
||||
* "all" and the locale is "en_US", we will likely return null on the search
|
||||
* for all_en_US.properties, and all_en.properties, but will return a full
|
||||
* bundle for all.properties.
|
||||
*
|
||||
* Of course, if all.properties doesn't exist either, then we have a
|
||||
* problem, but that will be reported elsewhere.
|
||||
*
|
||||
* @return the populated bundle or null.
|
||||
*/
|
||||
public static VitroResourceBundle getBundle(String bundleName,
|
||||
ServletContext ctx, String appI18nPath, String themeI18nPath,
|
||||
Control control) {
|
||||
|
@ -60,7 +77,7 @@ public class VitroResourceBundle extends ResourceBundle {
|
|||
return new VitroResourceBundle(bundleName, ctx, appI18nPath,
|
||||
themeI18nPath, control);
|
||||
} catch (FileNotFoundException e) {
|
||||
log.debug(e);
|
||||
log.debug(e.getMessage());
|
||||
return null;
|
||||
} catch (Exception e) {
|
||||
log.warn(e, e);
|
||||
|
|
|
@ -8,8 +8,10 @@ import java.io.InputStream;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
@ -368,17 +370,20 @@ public class LanguageFilteringRDFService implements RDFService {
|
|||
|
||||
int index = langs.indexOf(lang);
|
||||
if (index >= 0) {
|
||||
log.debug("languageIndex for '" + lang + "' is " + index);
|
||||
return index;
|
||||
}
|
||||
|
||||
if (lang.length() > 2) {
|
||||
index = langs.indexOf(lang.substring(0, 2));
|
||||
if (index >= 0) {
|
||||
log.debug("languageIndex for '" + lang + "' is " + index + inexactMatchPenalty);
|
||||
return index + inexactMatchPenalty;
|
||||
}
|
||||
}
|
||||
|
||||
if (lang.isEmpty()) {
|
||||
log.debug("languageIndex for '" + lang + "' is " + noLanguage);
|
||||
return noLanguage;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,81 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.rdfservice.filter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import javax.servlet.ServletRequest;
|
||||
|
||||
import com.hp.hpl.jena.ontology.OntModel;
|
||||
import com.hp.hpl.jena.ontology.OntModelSpec;
|
||||
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.OntModelSelector;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.OntModelSelectorImpl;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.RDFServiceGraph;
|
||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.jena.model.RDFServiceModel;
|
||||
|
||||
/**
|
||||
* Some methods that will come in handy when dealing with Language Filtering
|
||||
*/
|
||||
public class LanguageFilteringUtils {
|
||||
|
||||
/**
|
||||
* Take an Enumeration of Locale objects, such as we might get from a
|
||||
* request, and convert to a List of langauage strings, such as are needed
|
||||
* by the LanguageFilteringRDFService.
|
||||
*
|
||||
* While converting, change all underscores (as in Locale names) to hyphens
|
||||
* (as in RDF language specifiers).
|
||||
*/
|
||||
public static List<String> localesToLanguages(Enumeration<?> locales) {
|
||||
List<String> langs = new ArrayList<>();
|
||||
while (locales.hasMoreElements()) {
|
||||
Locale locale = (Locale) locales.nextElement();
|
||||
langs.add(locale.toString().replace("_", "-"));
|
||||
}
|
||||
if (langs.isEmpty()) {
|
||||
langs.add("en");
|
||||
}
|
||||
return langs;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a new OntModelSelector that containing a new display model and all
|
||||
* of the other models in the original OntModelSelector.
|
||||
*/
|
||||
public static OntModelSelector replaceDisplayModelInSelector(
|
||||
OntModelSelector oldOms, OntModel newDisplayModel) {
|
||||
OntModelSelectorImpl newOms = new OntModelSelectorImpl();
|
||||
newOms.setABoxModel(oldOms.getABoxModel());
|
||||
newOms.setApplicationMetadataModel(oldOms.getApplicationMetadataModel());
|
||||
newOms.setDisplayModel(newDisplayModel);
|
||||
newOms.setFullModel(oldOms.getFullModel());
|
||||
newOms.setTBoxModel(oldOms.getTBoxModel());
|
||||
newOms.setUserAccountsModel(oldOms.getUserAccountsModel());
|
||||
return newOms;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a Language Filtering layer to an OntModel by treating it as an RDFService.
|
||||
*/
|
||||
public static OntModel wrapOntModelInALanguageFilter(OntModel rawModel,
|
||||
ServletRequest req) {
|
||||
/** This is some nasty layering. Could we do this more easily? */
|
||||
List<String> languages = localesToLanguages(req.getLocales());
|
||||
return ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM,
|
||||
RDFServiceGraph.createRDFServiceModel(
|
||||
new RDFServiceGraph(
|
||||
new LanguageFilteringRDFService(
|
||||
new RDFServiceModel(rawModel), languages))));
|
||||
}
|
||||
|
||||
private LanguageFilteringUtils() {
|
||||
// Nothing to instantiate
|
||||
}
|
||||
|
||||
}
|
|
@ -211,7 +211,8 @@ public class PagedSearchController extends FreemarkerHttpServlet {
|
|||
|
||||
Map<String, Object> body = new HashMap<String, Object>();
|
||||
|
||||
String classGroupParam = vreq.getParameter(PARAM_CLASSGROUP);
|
||||
String classGroupParam = vreq.getParameter(PARAM_CLASSGROUP);
|
||||
log.debug("Query text is \""+ classGroupParam + "\"");
|
||||
boolean classGroupFilterRequested = false;
|
||||
if (!StringUtils.isEmpty(classGroupParam)) {
|
||||
VClassGroup grp = grpDao.getGroupByURI(classGroupParam);
|
||||
|
|
|
@ -94,17 +94,10 @@ public class WebappDaoSetup extends JenaDataSourceSetupBase
|
|||
setStartupDataset(dataset, ctx);
|
||||
|
||||
// ABox assertions
|
||||
Model aboxAssertions = dataset.getNamedModel(
|
||||
JenaDataSourceSetupBase.JENA_DB_MODEL);
|
||||
baseOms.setABoxModel(
|
||||
ModelFactory.createOntologyModel(
|
||||
OntModelSpec.OWL_MEM, aboxAssertions));
|
||||
baseOms.setABoxModel(ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, dataset.getNamedModel(JenaDataSourceSetupBase.JENA_DB_MODEL)));
|
||||
|
||||
// ABox inferences
|
||||
Model aboxInferences = dataset.getNamedModel(
|
||||
JenaDataSourceSetupBase.JENA_INF_MODEL);
|
||||
inferenceOms.setABoxModel(ModelFactory.createOntologyModel(
|
||||
OntModelSpec.OWL_MEM, aboxInferences));
|
||||
inferenceOms.setABoxModel(ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, dataset.getNamedModel(JenaDataSourceSetupBase.JENA_INF_MODEL)));
|
||||
|
||||
// TBox assertions
|
||||
try {
|
||||
|
@ -115,15 +108,11 @@ public class WebappDaoSetup extends JenaDataSourceSetupBase
|
|||
|
||||
if (tboxAssertionsDB != null) {
|
||||
long startTime = System.currentTimeMillis();
|
||||
System.out.println(
|
||||
"Copying cached tbox assertions into memory");
|
||||
log.info("Copying cached tbox assertions into memory");
|
||||
tboxAssertions.add(tboxAssertionsDB);
|
||||
System.out.println((System.currentTimeMillis() - startTime)
|
||||
/ 1000 + " seconds to load tbox assertions");
|
||||
log.info((System.currentTimeMillis() - startTime)/ 1000 + " seconds to load tbox assertions");
|
||||
tboxAssertions.getBaseModel().register(new ModelSynchronizer(tboxAssertionsDB));
|
||||
}
|
||||
|
||||
tboxAssertions.getBaseModel().register(new ModelSynchronizer(
|
||||
tboxAssertionsDB));
|
||||
|
||||
baseOms.setTBoxModel(tboxAssertions);
|
||||
} catch (Throwable e) {
|
||||
|
@ -139,15 +128,15 @@ public class WebappDaoSetup extends JenaDataSourceSetupBase
|
|||
|
||||
if (tboxInferencesDB != null) {
|
||||
long startTime = System.currentTimeMillis();
|
||||
System.out.println(
|
||||
log.info(
|
||||
"Copying cached tbox inferences into memory");
|
||||
tboxInferences.add(tboxInferencesDB);
|
||||
System.out.println((System.currentTimeMillis() - startTime)
|
||||
/ 1000 + " seconds to load tbox inferences");
|
||||
|
||||
tboxInferences.getBaseModel().register(new ModelSynchronizer(
|
||||
tboxInferencesDB));
|
||||
}
|
||||
|
||||
tboxInferences.getBaseModel().register(new ModelSynchronizer(
|
||||
tboxInferencesDB));
|
||||
inferenceOms.setTBoxModel(tboxInferences);
|
||||
} catch (Throwable e) {
|
||||
log.error("Unable to load tbox inference cache from DB", e);
|
||||
|
@ -155,7 +144,6 @@ public class WebappDaoSetup extends JenaDataSourceSetupBase
|
|||
}
|
||||
|
||||
// union ABox
|
||||
|
||||
Model m = ModelFactory.createUnion(
|
||||
baseOms.getABoxModel(), inferenceOms.getABoxModel());
|
||||
m = ModelFactory.createModelForGraph(
|
||||
|
@ -167,8 +155,7 @@ public class WebappDaoSetup extends JenaDataSourceSetupBase
|
|||
unionOms.setABoxModel(unionABoxModel);
|
||||
|
||||
// union TBox
|
||||
m = ModelFactory.createUnion(
|
||||
baseOms.getTBoxModel(), inferenceOms.getTBoxModel());
|
||||
m = ModelFactory.createUnion(baseOms.getTBoxModel(), inferenceOms.getTBoxModel());
|
||||
m = ModelFactory.createModelForGraph(
|
||||
new SpecialBulkUpdateHandlerGraph(
|
||||
m.getGraph(),
|
||||
|
|
|
@ -5,7 +5,6 @@ package edu.cornell.mannlib.vitro.webapp.utils.pageDataGetter;
|
|||
import java.net.URLEncoder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -17,22 +16,11 @@ import org.apache.commons.logging.Log;
|
|||
import org.apache.commons.logging.LogFactory;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.hp.hpl.jena.rdf.model.Model;
|
||||
import com.hp.hpl.jena.rdf.model.RDFNode;
|
||||
import com.hp.hpl.jena.rdf.model.ResourceFactory;
|
||||
import com.hp.hpl.jena.rdf.model.Statement;
|
||||
import com.hp.hpl.jena.rdf.model.StmtIterator;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.VClassGroup;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.IndividualListController;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.PageDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.ModelContext;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.VClassGroupCache;
|
||||
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.VClassGroupTemplateModel;
|
||||
|
||||
|
|
|
@ -190,6 +190,26 @@ public class SolrQueryUtils {
|
|||
}
|
||||
}
|
||||
|
||||
public static SolrQuery getRandomQuery(List<String> vclassUris, int page, int pageSize){
|
||||
String queryText = "";
|
||||
|
||||
try {
|
||||
queryText = makeMultiClassQuery(vclassUris);
|
||||
log.debug("queryText is " + queryText);
|
||||
SolrQuery query = new SolrQuery(queryText);
|
||||
|
||||
//page count starts at 1, row count starts at 0
|
||||
query.setStart( page ).setRows( pageSize );
|
||||
|
||||
log.debug("Query is " + query.toString());
|
||||
return query;
|
||||
|
||||
} catch (Exception ex){
|
||||
log.error("Could not make the Solr query",ex);
|
||||
return new SolrQuery();
|
||||
}
|
||||
}
|
||||
|
||||
public static String makeMultiClassQuery( List<String> vclassUris){
|
||||
List<String> queryTypes = new ArrayList<String>();
|
||||
try {
|
||||
|
@ -217,4 +237,16 @@ public class SolrQueryUtils {
|
|||
return results;
|
||||
}
|
||||
|
||||
public static IndividualListQueryResults buildAndExecuteRandomVClassQuery(
|
||||
List<String> vclassURIs, int page, int pageSize,
|
||||
ServletContext context, IndividualDao indDao)
|
||||
throws SolrServerException {
|
||||
SolrQuery query = SolrQueryUtils.getRandomQuery(vclassURIs, page, pageSize);
|
||||
IndividualListQueryResults results = IndividualListQueryResults.runQuery(query, indDao, context);
|
||||
log.debug("Executed solr query for " + vclassURIs);
|
||||
if (results.getIndividuals().isEmpty()) {
|
||||
log.debug("entities list is null for vclass " + vclassURIs);
|
||||
}
|
||||
return results;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue