Compare commits
58 commits
texts
...
texts-1.12
Author | SHA1 | Date | |
---|---|---|---|
9e5236c712 | |||
e48b2d7e0f | |||
cdcc051d3f | |||
952ffa66ad | |||
95d559712f | |||
9d4d29b653 | |||
b6f0ed229c | |||
2519c4a6a7 | |||
3c2e9cab05 | |||
![]() |
bf7c6ffaf7 | ||
![]() |
028af518f9 | ||
![]() |
5a4648554a | ||
![]() |
b123f3bd9b | ||
![]() |
a7e1e60c7e | ||
9565fbd925 | |||
![]() |
762388e88b | ||
1e7cc745bc | |||
![]() |
93fd5a5f39 | ||
![]() |
33ae07dcbf | ||
![]() |
20507a75fb | ||
![]() |
1d89cbc908 | ||
![]() |
1720272155 | ||
![]() |
27353bfb91 | ||
d21dc92b0b | |||
![]() |
3c04cc0f80 | ||
![]() |
1819fa1dd4 | ||
![]() |
7a24e259e8 | ||
![]() |
e7993668b6 | ||
![]() |
63639fc852 | ||
![]() |
c07af3d794 | ||
![]() |
5075d78537 | ||
![]() |
bbead68e88 | ||
![]() |
71ca39d597 | ||
![]() |
cd437a503e | ||
![]() |
0b9919c55d | ||
![]() |
3984203552 | ||
![]() |
bc12d2037c | ||
![]() |
b6062fe4a0 | ||
![]() |
b283a8342a | ||
![]() |
ebca021bc4 | ||
![]() |
c5a716e90e | ||
![]() |
def81c9013 | ||
![]() |
93bd5183e2 | ||
![]() |
70aefebedf | ||
4ed88b81e3 | |||
![]() |
cdfb18a455 | ||
![]() |
2ad521e9da | ||
![]() |
ff8ba8adcc | ||
![]() |
eb61192d11 | ||
![]() |
193b38159a | ||
![]() |
e4e0a7d061 | ||
![]() |
6b612316ee | ||
![]() |
eb949919b5 | ||
![]() |
28188e9719 | ||
![]() |
06d9f5d333 | ||
![]() |
8b9a7484b3 | ||
![]() |
936305be2a | ||
![]() |
119413413a |
265 changed files with 13043 additions and 2561 deletions
34
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
34
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
---
|
||||||
|
name: Bug report
|
||||||
|
about: Create a report to help us improve
|
||||||
|
title: ''
|
||||||
|
labels: ''
|
||||||
|
assignees: ''
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**Describe the bug**
|
||||||
|
A clear and concise description of what the bug is.
|
||||||
|
|
||||||
|
**To Reproduce**
|
||||||
|
Steps to reproduce the behavior:
|
||||||
|
1. Go to '...'
|
||||||
|
2. Click on '....'
|
||||||
|
3. Scroll down to '....'
|
||||||
|
4. See error
|
||||||
|
|
||||||
|
**Expected behavior**
|
||||||
|
A clear and concise description of what you expected to happen.
|
||||||
|
|
||||||
|
**Screenshots**
|
||||||
|
If applicable, add screenshots to help explain your problem.
|
||||||
|
|
||||||
|
**Desktop (please complete the following information):**
|
||||||
|
- OS: [e.g. Windows, Linux]
|
||||||
|
- Browser [e.g. chrome, safari]
|
||||||
|
- Tomcat version [e.g. 8, 9]
|
||||||
|
- VIVO version [e.g. 1.11.0, 1.12.0]
|
||||||
|
- Apache Solr or ElasticSearch version
|
||||||
|
|
||||||
|
**Additional context**
|
||||||
|
Add any other context about the problem here.
|
20
.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
20
.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
---
|
||||||
|
name: Feature request
|
||||||
|
about: Suggest an idea for this project
|
||||||
|
title: ''
|
||||||
|
labels: ''
|
||||||
|
assignees: ''
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**Is your feature request related to a problem? Please describe.**
|
||||||
|
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
||||||
|
|
||||||
|
**Describe the solution you'd like**
|
||||||
|
A clear and concise description of what you want to happen.
|
||||||
|
|
||||||
|
**Describe alternatives you've considered**
|
||||||
|
A clear and concise description of any alternative solutions or features you've considered.
|
||||||
|
|
||||||
|
**Additional context**
|
||||||
|
Add any other context or screenshots about the feature request here.
|
28
.github/workflows/build.yml
vendored
Normal file
28
.github/workflows/build.yml
vendored
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
name: Build
|
||||||
|
|
||||||
|
on: [ push, pull_request, workflow_dispatch ]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
env:
|
||||||
|
MAVEN_OPTS: -Xmx1024M
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Maven Cache
|
||||||
|
uses: actions/cache@v2
|
||||||
|
with:
|
||||||
|
path: ~/.m2/repository
|
||||||
|
key: ${{ runner.os }}-cache-m2-${{ hashFiles('**/pom.xml') }}
|
||||||
|
restore-keys: ${{ runner.os }}-cache-m2-
|
||||||
|
|
||||||
|
- name: Setup Java
|
||||||
|
uses: actions/setup-java@v1
|
||||||
|
with:
|
||||||
|
java-version: 11
|
||||||
|
|
||||||
|
- name: Maven Build
|
||||||
|
run: mvn clean install
|
22
.travis.yml
22
.travis.yml
|
@ -1,22 +0,0 @@
|
||||||
language: java
|
|
||||||
dist: trusty
|
|
||||||
sudo: false
|
|
||||||
|
|
||||||
jdk:
|
|
||||||
- openjdk8
|
|
||||||
- oraclejdk8
|
|
||||||
|
|
||||||
env:
|
|
||||||
# Give Maven 1GB of memory to work with
|
|
||||||
- MAVEN_OPTS=-Xmx1024M
|
|
||||||
|
|
||||||
cache:
|
|
||||||
directories:
|
|
||||||
- .autoconf
|
|
||||||
- $HOME/.m2
|
|
||||||
|
|
||||||
install:
|
|
||||||
- "echo 'Skipping install stage, dependencies will be downloaded during build and test stages.'"
|
|
||||||
|
|
||||||
script:
|
|
||||||
- "mvn clean package -Dmaven.test.skip=false"
|
|
|
@ -1,6 +1,6 @@
|
||||||
# What is Vitro?
|
# What is Vitro?
|
||||||
|
|
||||||
[](https://travis-ci.org/vivo-project/Vitro)
|
[](https://github.com/vivo-project/Vitro/actions?query=workflow%3ABuild)
|
||||||
|
|
||||||
Vitro is a general-purpose web-based ontology and instance editor with customizable public browsing.
|
Vitro is a general-purpose web-based ontology and instance editor with customizable public browsing.
|
||||||
|
|
||||||
|
|
|
@ -7,13 +7,13 @@
|
||||||
|
|
||||||
<groupId>org.vivoweb</groupId>
|
<groupId>org.vivoweb</groupId>
|
||||||
<artifactId>vitro-api</artifactId>
|
<artifactId>vitro-api</artifactId>
|
||||||
<version>1.11.2-SNAPSHOT</version>
|
<version>1.12.1-SNAPSHOT</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>org.vivoweb</groupId>
|
<groupId>org.vivoweb</groupId>
|
||||||
<artifactId>vitro-project</artifactId>
|
<artifactId>vitro-project</artifactId>
|
||||||
<version>1.11.2-SNAPSHOT</version>
|
<version>1.12.1-SNAPSHOT</version>
|
||||||
<relativePath>..</relativePath>
|
<relativePath>..</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
@ -66,7 +66,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.vivoweb</groupId>
|
<groupId>org.vivoweb</groupId>
|
||||||
<artifactId>vitro-dependencies</artifactId>
|
<artifactId>vitro-dependencies</artifactId>
|
||||||
<version>1.11.2-SNAPSHOT</version>
|
<version>1.12.1-SNAPSHOT</version>
|
||||||
<type>pom</type>
|
<type>pom</type>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@ -85,7 +85,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit</artifactId>
|
||||||
<version>4.11</version>
|
<version>4.13.1</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|
|
@ -62,6 +62,7 @@ public class ApplicationSetup implements ServletContextListener {
|
||||||
|
|
||||||
private void locateApplicationConfigFile() {
|
private void locateApplicationConfigFile() {
|
||||||
Path path = this.vitroHomeDir.getPath().resolve(APPLICATION_SETUP_PATH);
|
Path path = this.vitroHomeDir.getPath().resolve(APPLICATION_SETUP_PATH);
|
||||||
|
|
||||||
if (!Files.exists(path)) {
|
if (!Files.exists(path)) {
|
||||||
throw new IllegalStateException("'" + path + "' does not exist.");
|
throw new IllegalStateException("'" + path + "' does not exist.");
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,14 @@ public class RootUserPolicy implements PolicyIface {
|
||||||
private static final Log log = LogFactory.getLog(RootUserPolicy.class);
|
private static final Log log = LogFactory.getLog(RootUserPolicy.class);
|
||||||
|
|
||||||
private static final String PROPERTY_ROOT_USER_EMAIL = "rootUser.emailAddress";
|
private static final String PROPERTY_ROOT_USER_EMAIL = "rootUser.emailAddress";
|
||||||
|
/*
|
||||||
|
* UQAM Add-Feature For parameterization of rootUser
|
||||||
|
*/
|
||||||
|
private static final String PROPERTY_ROOT_USER_PASSWORD = "rootUser.password";
|
||||||
|
private static final String PROPERTY_ROOT_USER_PASSWORD_CHANGE_REQUIRED = "rootUser.passwordChangeRequired";
|
||||||
|
|
||||||
private static final String ROOT_USER_INITIAL_PASSWORD = "rootPassword";
|
private static final String ROOT_USER_INITIAL_PASSWORD = "rootPassword";
|
||||||
|
private static final String ROOT_USER_INITIAL_PASSWORD_CHANGE_REQUIRED = "true";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is the entire policy. If you are a root user, you are authorized.
|
* This is the entire policy. If you are a root user, you are authorized.
|
||||||
|
@ -150,10 +157,12 @@ public class RootUserPolicy implements PolicyIface {
|
||||||
ua.setEmailAddress(configuredRootUser);
|
ua.setEmailAddress(configuredRootUser);
|
||||||
ua.setFirstName("root");
|
ua.setFirstName("root");
|
||||||
ua.setLastName("user");
|
ua.setLastName("user");
|
||||||
|
// UQAM Add-Feature using getRootPasswordFromConfig()
|
||||||
ua.setArgon2Password(Authenticator.applyArgon2iEncoding(
|
ua.setArgon2Password(Authenticator.applyArgon2iEncoding(
|
||||||
ROOT_USER_INITIAL_PASSWORD));
|
getRootPasswordFromConfig()));
|
||||||
ua.setMd5Password("");
|
ua.setMd5Password("");
|
||||||
ua.setPasswordChangeRequired(true);
|
// UQAM Add-Feature using getRootPasswdChangeRequiredFromConfig()
|
||||||
|
ua.setPasswordChangeRequired(getRootPasswdChangeRequiredFromConfig().booleanValue());
|
||||||
ua.setStatus(Status.ACTIVE);
|
ua.setStatus(Status.ACTIVE);
|
||||||
ua.setRootUser(true);
|
ua.setRootUser(true);
|
||||||
|
|
||||||
|
@ -191,7 +200,31 @@ public class RootUserPolicy implements PolicyIface {
|
||||||
ss.warning(this, "For security, "
|
ss.warning(this, "For security, "
|
||||||
+ "it is best to delete unneeded root user accounts.");
|
+ "it is best to delete unneeded root user accounts.");
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
* UQAM Add-Feature
|
||||||
|
* Add for getting rootUser.password property value from runtime.properties
|
||||||
|
*/
|
||||||
|
private String getRootPasswordFromConfig() {
|
||||||
|
String passwd = ConfigurationProperties.getBean(ctx).getProperty(
|
||||||
|
PROPERTY_ROOT_USER_PASSWORD);
|
||||||
|
if (passwd == null) {
|
||||||
|
passwd = ROOT_USER_INITIAL_PASSWORD;
|
||||||
|
}
|
||||||
|
return passwd;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* UQAM Add-Feature
|
||||||
|
* Add for getting rootUser.passwordChangeRequired property value from runtime.properties
|
||||||
|
*/
|
||||||
|
private Boolean getRootPasswdChangeRequiredFromConfig() {
|
||||||
|
String passwdCR = ConfigurationProperties.getBean(ctx).getProperty(
|
||||||
|
PROPERTY_ROOT_USER_PASSWORD_CHANGE_REQUIRED);
|
||||||
|
if (passwdCR == null) {
|
||||||
|
passwdCR = ROOT_USER_INITIAL_PASSWORD_CHANGE_REQUIRED;
|
||||||
|
}
|
||||||
|
return new Boolean(passwdCR);
|
||||||
|
}
|
||||||
@Override
|
@Override
|
||||||
public void contextDestroyed(ServletContextEvent sce) {
|
public void contextDestroyed(ServletContextEvent sce) {
|
||||||
// Nothing to destroy
|
// Nothing to destroy
|
||||||
|
|
|
@ -20,6 +20,7 @@ public class ApplicationBean {
|
||||||
public final static int VIVO_SEARCHBOX_SIZE = 20;
|
public final static int VIVO_SEARCHBOX_SIZE = 20;
|
||||||
|
|
||||||
private final static String DEFAULT_APPLICATION_NAME = "Vitro";
|
private final static String DEFAULT_APPLICATION_NAME = "Vitro";
|
||||||
|
private final static String DEFAULT_APPLICATION_AVAILABLE_LANGS_FILE = "available-langs";
|
||||||
private final static String DEFAULT_ROOT_LOGOTYPE_IMAGE = "";
|
private final static String DEFAULT_ROOT_LOGOTYPE_IMAGE = "";
|
||||||
private final static int DEFAULT_ROOT_LOGOTYPE_WIDTH = 0;
|
private final static int DEFAULT_ROOT_LOGOTYPE_WIDTH = 0;
|
||||||
private final static int DEFAULT_ROOT_LOGOTYPE_HEIGHT = 0;
|
private final static int DEFAULT_ROOT_LOGOTYPE_HEIGHT = 0;
|
||||||
|
@ -33,6 +34,7 @@ public class ApplicationBean {
|
||||||
private boolean initialized = false;
|
private boolean initialized = false;
|
||||||
private String sessionIdStr = null;
|
private String sessionIdStr = null;
|
||||||
private String applicationName = DEFAULT_APPLICATION_NAME;
|
private String applicationName = DEFAULT_APPLICATION_NAME;
|
||||||
|
private String availableLangsFile = DEFAULT_APPLICATION_AVAILABLE_LANGS_FILE;
|
||||||
|
|
||||||
private String rootLogotypeImage = DEFAULT_ROOT_LOGOTYPE_IMAGE;
|
private String rootLogotypeImage = DEFAULT_ROOT_LOGOTYPE_IMAGE;
|
||||||
private int rootLogotypeWidth = DEFAULT_ROOT_LOGOTYPE_WIDTH;
|
private int rootLogotypeWidth = DEFAULT_ROOT_LOGOTYPE_WIDTH;
|
||||||
|
@ -52,6 +54,7 @@ public class ApplicationBean {
|
||||||
output += " initialized from DB: [" + initialized + "]\n";
|
output += " initialized from DB: [" + initialized + "]\n";
|
||||||
output += " session id: [" + sessionIdStr + "]\n";
|
output += " session id: [" + sessionIdStr + "]\n";
|
||||||
output += " application name: [" + applicationName + "]\n";
|
output += " application name: [" + applicationName + "]\n";
|
||||||
|
output += " available langs file: [" + availableLangsFile + "]\n";
|
||||||
output += " root logotype image: [" + rootLogotypeImage + "]\n";
|
output += " root logotype image: [" + rootLogotypeImage + "]\n";
|
||||||
output += " root logotype width: [" + rootLogotypeWidth + "]\n";
|
output += " root logotype width: [" + rootLogotypeWidth + "]\n";
|
||||||
output += " root logotype height: [" + rootLogotypeHeight + "]\n";
|
output += " root logotype height: [" + rootLogotypeHeight + "]\n";
|
||||||
|
@ -177,6 +180,10 @@ public class ApplicationBean {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getAvailableLangsFile() {
|
||||||
|
return availableLangsFile;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Directory to find the images. Subdirectories include css, jsp and site_icons.
|
* Directory to find the images. Subdirectories include css, jsp and site_icons.
|
||||||
* Example: "themes/enhanced/"
|
* Example: "themes/enhanced/"
|
||||||
|
|
|
@ -7,17 +7,11 @@ import java.util.Collections;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.authenticate.Authenticator;
|
import org.apache.commons.lang3.RandomStringUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Information about the account of a user. URI, email, password, etc.
|
* Information about the account of a user. URI, email, password, etc.
|
||||||
*
|
*
|
||||||
* The "password link expires hash" is just a string that is derived from the
|
|
||||||
* value in the passwordLinkExpires field. It doesn't have to be a hash, and
|
|
||||||
* there is no need for it to be cryptographic, but it seems embarrassing to
|
|
||||||
* just send the value as a clear string. There is no real need for security
|
|
||||||
* here, except that a brute force attack would allow someone to change the
|
|
||||||
* password on an account that they know has a password change pending.
|
|
||||||
*/
|
*/
|
||||||
public class UserAccount {
|
public class UserAccount {
|
||||||
public static final int MIN_PASSWORD_LENGTH = 6;
|
public static final int MIN_PASSWORD_LENGTH = 6;
|
||||||
|
@ -52,6 +46,7 @@ public class UserAccount {
|
||||||
private String md5Password = ""; // Never null.
|
private String md5Password = ""; // Never null.
|
||||||
private String oldPassword = ""; // Never null.
|
private String oldPassword = ""; // Never null.
|
||||||
private long passwordLinkExpires = 0L; // Never negative.
|
private long passwordLinkExpires = 0L; // Never negative.
|
||||||
|
private String emailKey = "";
|
||||||
private boolean passwordChangeRequired = false;
|
private boolean passwordChangeRequired = false;
|
||||||
|
|
||||||
private int loginCount = 0; // Never negative.
|
private int loginCount = 0; // Never negative.
|
||||||
|
@ -133,15 +128,27 @@ public class UserAccount {
|
||||||
return passwordLinkExpires;
|
return passwordLinkExpires;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPasswordLinkExpiresHash() {
|
|
||||||
return limitStringLength(8, Authenticator.applyArgon2iEncoding(String
|
|
||||||
.valueOf(passwordLinkExpires)));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPasswordLinkExpires(long passwordLinkExpires) {
|
public void setPasswordLinkExpires(long passwordLinkExpires) {
|
||||||
this.passwordLinkExpires = Math.max(0, passwordLinkExpires);
|
this.passwordLinkExpires = Math.max(0, passwordLinkExpires);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void generateEmailKey() {
|
||||||
|
boolean useLetters = true;
|
||||||
|
boolean useNumbers = true;
|
||||||
|
int length = 64;
|
||||||
|
emailKey = RandomStringUtils.random(length, useLetters, useNumbers);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEmailKey(String emailKey) {
|
||||||
|
if (emailKey != null) {
|
||||||
|
this.emailKey = emailKey;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getEmailKey() {
|
||||||
|
return emailKey;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isPasswordChangeRequired() {
|
public boolean isPasswordChangeRequired() {
|
||||||
return passwordChangeRequired;
|
return passwordChangeRequired;
|
||||||
}
|
}
|
||||||
|
@ -247,6 +254,7 @@ public class UserAccount {
|
||||||
+ (", oldPassword=" + oldPassword)
|
+ (", oldPassword=" + oldPassword)
|
||||||
+ (", argon2password=" + argon2Password)
|
+ (", argon2password=" + argon2Password)
|
||||||
+ (", passwordLinkExpires=" + passwordLinkExpires)
|
+ (", passwordLinkExpires=" + passwordLinkExpires)
|
||||||
|
+ (", emailKey =" + emailKey)
|
||||||
+ (", passwordChangeRequired=" + passwordChangeRequired)
|
+ (", passwordChangeRequired=" + passwordChangeRequired)
|
||||||
+ (", externalAuthOnly=" + externalAuthOnly)
|
+ (", externalAuthOnly=" + externalAuthOnly)
|
||||||
+ (", loginCount=" + loginCount) + (", status=" + status)
|
+ (", loginCount=" + loginCount) + (", status=" + status)
|
||||||
|
|
|
@ -109,7 +109,7 @@ public abstract class ConfigurationProperties {
|
||||||
throw new NullPointerException("bean may not be null.");
|
throw new NullPointerException("bean may not be null.");
|
||||||
}
|
}
|
||||||
context.setAttribute(ATTRIBUTE_NAME, bean);
|
context.setAttribute(ATTRIBUTE_NAME, bean);
|
||||||
log.info(bean);
|
log.debug(bean);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Package access, so unit tests can call it. */
|
/** Package access, so unit tests can call it. */
|
||||||
|
|
|
@ -118,7 +118,6 @@ public class ConfigurationPropertiesSetup implements ServletContextListener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private File locateRuntimePropertiesFile(File vitroHomeDir,
|
private File locateRuntimePropertiesFile(File vitroHomeDir,
|
||||||
File vitroHomeDirConfig, StartupStatus ss) {
|
File vitroHomeDirConfig, StartupStatus ss) {
|
||||||
|
|
||||||
|
|
|
@ -249,6 +249,7 @@ public class UserAccountsSelector {
|
||||||
user.setMd5Password(ifLiteralPresent(solution, "md5pwd", ""));
|
user.setMd5Password(ifLiteralPresent(solution, "md5pwd", ""));
|
||||||
user.setArgon2Password(ifLiteralPresent(solution, "a2pwd", ""));
|
user.setArgon2Password(ifLiteralPresent(solution, "a2pwd", ""));
|
||||||
user.setPasswordLinkExpires(ifLongPresent(solution, "expire", 0L));
|
user.setPasswordLinkExpires(ifLongPresent(solution, "expire", 0L));
|
||||||
|
user.setEmailKey(ifLiteralPresent(solution, "emailKey", ""));
|
||||||
user.setLoginCount(ifIntPresent(solution, "count", 0));
|
user.setLoginCount(ifIntPresent(solution, "count", 0));
|
||||||
user.setLastLoginTime(ifLongPresent(solution, "lastLogin", 0));
|
user.setLastLoginTime(ifLongPresent(solution, "lastLogin", 0));
|
||||||
user.setStatus(parseStatus(solution, "status", null));
|
user.setStatus(parseStatus(solution, "status", null));
|
||||||
|
|
|
@ -156,6 +156,7 @@ public class UserAccountsAddPage extends UserAccountsPage {
|
||||||
u.setOldPassword("");
|
u.setOldPassword("");
|
||||||
u.setPasswordChangeRequired(false);
|
u.setPasswordChangeRequired(false);
|
||||||
u.setPasswordLinkExpires(0);
|
u.setPasswordLinkExpires(0);
|
||||||
|
u.setEmailKey("");
|
||||||
u.setLoginCount(0);
|
u.setLoginCount(0);
|
||||||
u.setLastLoginTime(0L);
|
u.setLastLoginTime(0L);
|
||||||
u.setStatus(Status.INACTIVE);
|
u.setStatus(Status.INACTIVE);
|
||||||
|
|
|
@ -84,6 +84,7 @@ public abstract class UserAccountsAddPageStrategy extends UserAccountsPage {
|
||||||
u.setStatus(Status.ACTIVE);
|
u.setStatus(Status.ACTIVE);
|
||||||
} else {
|
} else {
|
||||||
u.setPasswordLinkExpires(figureExpirationDate().getTime());
|
u.setPasswordLinkExpires(figureExpirationDate().getTime());
|
||||||
|
u.generateEmailKey();
|
||||||
u.setStatus(Status.INACTIVE);
|
u.setStatus(Status.INACTIVE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -119,10 +120,8 @@ public abstract class UserAccountsAddPageStrategy extends UserAccountsPage {
|
||||||
private String buildCreatePasswordLink() {
|
private String buildCreatePasswordLink() {
|
||||||
try {
|
try {
|
||||||
String email = page.getAddedAccount().getEmailAddress();
|
String email = page.getAddedAccount().getEmailAddress();
|
||||||
String hash = page.getAddedAccount()
|
String key = page.getAddedAccount().getEmailKey();
|
||||||
.getPasswordLinkExpiresHash();
|
String relativeUrl = UrlBuilder.getUrl(CREATE_PASSWORD_URL, "user", email, "key", key);
|
||||||
String relativeUrl = UrlBuilder.getUrl(CREATE_PASSWORD_URL,
|
|
||||||
"user", email, "key", hash);
|
|
||||||
|
|
||||||
URL context = new URL(vreq.getRequestURL().toString());
|
URL context = new URL(vreq.getRequestURL().toString());
|
||||||
URL url = new URL(context, relativeUrl);
|
URL url = new URL(context, relativeUrl);
|
||||||
|
|
|
@ -274,6 +274,7 @@ public class UserAccountsEditPage extends UserAccountsPage {
|
||||||
userAccount.setOldPassword("");
|
userAccount.setOldPassword("");
|
||||||
userAccount.setPasswordChangeRequired(false);
|
userAccount.setPasswordChangeRequired(false);
|
||||||
userAccount.setPasswordLinkExpires(0L);
|
userAccount.setPasswordLinkExpires(0L);
|
||||||
|
userAccount.setEmailKey("");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isRootUser()) {
|
if (isRootUser()) {
|
||||||
|
|
|
@ -82,6 +82,7 @@ public abstract class UserAccountsEditPageStrategy extends UserAccountsPage {
|
||||||
protected void setAdditionalProperties(UserAccount u) {
|
protected void setAdditionalProperties(UserAccount u) {
|
||||||
if (resetPassword && !page.isExternalAuthOnly()) {
|
if (resetPassword && !page.isExternalAuthOnly()) {
|
||||||
u.setPasswordLinkExpires(figureExpirationDate().getTime());
|
u.setPasswordLinkExpires(figureExpirationDate().getTime());
|
||||||
|
u.generateEmailKey();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,10 +122,8 @@ public abstract class UserAccountsEditPageStrategy extends UserAccountsPage {
|
||||||
private String buildResetPasswordLink() {
|
private String buildResetPasswordLink() {
|
||||||
try {
|
try {
|
||||||
String email = page.getUpdatedAccount().getEmailAddress();
|
String email = page.getUpdatedAccount().getEmailAddress();
|
||||||
String hash = page.getUpdatedAccount()
|
String key = page.getUpdatedAccount().getEmailKey();
|
||||||
.getPasswordLinkExpiresHash();
|
String relativeUrl = UrlBuilder.getUrl(RESET_PASSWORD_URL, "user", email, "key", key);
|
||||||
String relativeUrl = UrlBuilder.getUrl(RESET_PASSWORD_URL,
|
|
||||||
"user", email, "key", hash);
|
|
||||||
|
|
||||||
URL context = new URL(vreq.getRequestURL().toString());
|
URL context = new URL(vreq.getRequestURL().toString());
|
||||||
URL url = new URL(context, relativeUrl);
|
URL url = new URL(context, relativeUrl);
|
||||||
|
|
|
@ -36,6 +36,7 @@ public class UserAccountsCreatePasswordPage extends
|
||||||
userAccount.setArgon2Password(Authenticator.applyArgon2iEncoding(newPassword));
|
userAccount.setArgon2Password(Authenticator.applyArgon2iEncoding(newPassword));
|
||||||
userAccount.setMd5Password("");
|
userAccount.setMd5Password("");
|
||||||
userAccount.setPasswordLinkExpires(0L);
|
userAccount.setPasswordLinkExpires(0L);
|
||||||
|
userAccount.setEmailKey("");
|
||||||
userAccount.setPasswordChangeRequired(false);
|
userAccount.setPasswordChangeRequired(false);
|
||||||
userAccount.setStatus(Status.ACTIVE);
|
userAccount.setStatus(Status.ACTIVE);
|
||||||
userAccountsDao.updateUserAccount(userAccount);
|
userAccountsDao.updateUserAccount(userAccount);
|
||||||
|
@ -54,6 +55,11 @@ public class UserAccountsCreatePasswordPage extends
|
||||||
return i18n.text("account_already_activated", userEmail);
|
return i18n.text("account_already_activated", userEmail);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String passwordChangeInavlidKeyMessage() {
|
||||||
|
return i18n.text("password_change_invalid_key", userEmail);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String templateName() {
|
protected String templateName() {
|
||||||
return TEMPLATE_NAME;
|
return TEMPLATE_NAME;
|
||||||
|
|
|
@ -195,6 +195,7 @@ public class UserAccountsFirstTimeExternalPage extends UserAccountsPage {
|
||||||
u.setExternalAuthId(externalAuthId);
|
u.setExternalAuthId(externalAuthId);
|
||||||
u.setPasswordChangeRequired(false);
|
u.setPasswordChangeRequired(false);
|
||||||
u.setPasswordLinkExpires(0);
|
u.setPasswordLinkExpires(0);
|
||||||
|
u.setEmailKey("");
|
||||||
u.setExternalAuthOnly(true);
|
u.setExternalAuthOnly(true);
|
||||||
u.setLoginCount(0);
|
u.setLoginCount(0);
|
||||||
u.setStatus(Status.ACTIVE);
|
u.setStatus(Status.ACTIVE);
|
||||||
|
|
|
@ -159,6 +159,7 @@ public abstract class UserAccountsMyAccountPageStrategy extends
|
||||||
userAccount.setMd5Password("");
|
userAccount.setMd5Password("");
|
||||||
userAccount.setPasswordChangeRequired(false);
|
userAccount.setPasswordChangeRequired(false);
|
||||||
userAccount.setPasswordLinkExpires(0L);
|
userAccount.setPasswordLinkExpires(0L);
|
||||||
|
userAccount.setEmailKey("");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -103,12 +103,12 @@ public abstract class UserAccountsPasswordBasePage extends UserAccountsPage {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String expectedKey = userAccount.getPasswordLinkExpiresHash();
|
String expectedKey = userAccount.getEmailKey();
|
||||||
if (!key.equals(expectedKey)) {
|
if (key.isEmpty() || !key.equals(expectedKey)) {
|
||||||
log.warn("Password request for '" + userEmail + "' is bogus: key ("
|
log.warn("Password request for '" + userEmail + "' is bogus: key ("
|
||||||
+ key + ") doesn't match expected key (" + expectedKey
|
+ key + ") doesn't match expected key (" + expectedKey
|
||||||
+ ")");
|
+ ")");
|
||||||
bogusMessage = passwordChangeNotPendingMessage();
|
bogusMessage = passwordChangeInavlidKeyMessage();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -153,7 +153,7 @@ public abstract class UserAccountsPasswordBasePage extends UserAccountsPage {
|
||||||
body.put("minimumLength", UserAccount.MIN_PASSWORD_LENGTH);
|
body.put("minimumLength", UserAccount.MIN_PASSWORD_LENGTH);
|
||||||
body.put("maximumLength", UserAccount.MAX_PASSWORD_LENGTH);
|
body.put("maximumLength", UserAccount.MAX_PASSWORD_LENGTH);
|
||||||
body.put("userAccount", userAccount);
|
body.put("userAccount", userAccount);
|
||||||
body.put("key", userAccount.getPasswordLinkExpiresHash());
|
body.put("key", userAccount.getEmailKey());
|
||||||
body.put("newPassword", newPassword);
|
body.put("newPassword", newPassword);
|
||||||
body.put("confirmPassword", confirmPassword);
|
body.put("confirmPassword", confirmPassword);
|
||||||
body.put("formUrls", buildUrlsMap());
|
body.put("formUrls", buildUrlsMap());
|
||||||
|
@ -177,5 +177,7 @@ public abstract class UserAccountsPasswordBasePage extends UserAccountsPage {
|
||||||
|
|
||||||
protected abstract String passwordChangeNotPendingMessage();
|
protected abstract String passwordChangeNotPendingMessage();
|
||||||
|
|
||||||
|
protected abstract String passwordChangeInavlidKeyMessage();
|
||||||
|
|
||||||
protected abstract String templateName();
|
protected abstract String templateName();
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,6 +56,11 @@ public class UserAccountsResetPasswordPage extends UserAccountsPasswordBasePage
|
||||||
return i18n.text("password_change_not_pending", userEmail);
|
return i18n.text("password_change_not_pending", userEmail);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String passwordChangeInavlidKeyMessage() {
|
||||||
|
return i18n.text("password_change_invalid_key", userEmail);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String templateName() {
|
protected String templateName() {
|
||||||
return TEMPLATE_NAME;
|
return TEMPLATE_NAME;
|
||||||
|
|
|
@ -17,6 +17,8 @@ import javax.servlet.annotation.WebServlet;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.i18n.I18n;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.i18n.I18nBundle;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
@ -75,8 +77,8 @@ public class SparqlQueryController extends FreemarkerHttpServlet {
|
||||||
private static final String[] SAMPLE_QUERY = { //
|
private static final String[] SAMPLE_QUERY = { //
|
||||||
"", //
|
"", //
|
||||||
"#", //
|
"#", //
|
||||||
"# This example query gets 20 geographic locations", //
|
"i18n:sparql_query_description_0", //
|
||||||
"# and (if available) their labels", //
|
"i18n:sparql_query_description_1", //
|
||||||
"#", //
|
"#", //
|
||||||
"SELECT ?geoLocation ?label", //
|
"SELECT ?geoLocation ?label", //
|
||||||
"WHERE", //
|
"WHERE", //
|
||||||
|
@ -193,9 +195,11 @@ public class SparqlQueryController extends FreemarkerHttpServlet {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ResponseValues processRequest(VitroRequest vreq) throws Exception {
|
protected ResponseValues processRequest(VitroRequest vreq) throws Exception {
|
||||||
|
I18nBundle i18n = I18n.bundle(vreq);
|
||||||
|
|
||||||
Map<String, Object> bodyMap = new HashMap<>();
|
Map<String, Object> bodyMap = new HashMap<>();
|
||||||
bodyMap.put("sampleQuery", buildSampleQuery(buildPrefixList(vreq)));
|
bodyMap.put("sampleQuery", buildSampleQuery(i18n, buildPrefixList(vreq)));
|
||||||
bodyMap.put("title", "SPARQL Query");
|
bodyMap.put("title", i18n.text("sparql_query_title"));
|
||||||
bodyMap.put("submitUrl", UrlBuilder.getUrl("admin/sparqlquery"));
|
bodyMap.put("submitUrl", UrlBuilder.getUrl("admin/sparqlquery"));
|
||||||
return new TemplateResponseValues(TEMPLATE_NAME, bodyMap);
|
return new TemplateResponseValues(TEMPLATE_NAME, bodyMap);
|
||||||
}
|
}
|
||||||
|
@ -222,7 +226,7 @@ public class SparqlQueryController extends FreemarkerHttpServlet {
|
||||||
return prefixList;
|
return prefixList;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String buildSampleQuery(List<Prefix> prefixList) {
|
private String buildSampleQuery(I18nBundle i18n, List<Prefix> prefixList) {
|
||||||
StringWriter sw = new StringWriter();
|
StringWriter sw = new StringWriter();
|
||||||
PrintWriter writer = new PrintWriter(sw);
|
PrintWriter writer = new PrintWriter(sw);
|
||||||
|
|
||||||
|
@ -230,6 +234,10 @@ public class SparqlQueryController extends FreemarkerHttpServlet {
|
||||||
writer.println(p);
|
writer.println(p);
|
||||||
}
|
}
|
||||||
for (String line : SAMPLE_QUERY) {
|
for (String line : SAMPLE_QUERY) {
|
||||||
|
if (line.startsWith("i18n:")) {
|
||||||
|
// Get i18n translation
|
||||||
|
line = i18n.text(line.substring("i18n:".length()));
|
||||||
|
}
|
||||||
writer.println(line);
|
writer.println(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -134,6 +134,7 @@ public class BasicAuthenticator extends Authenticator {
|
||||||
userAccount.setMd5Password("");
|
userAccount.setMd5Password("");
|
||||||
userAccount.setPasswordChangeRequired(false);
|
userAccount.setPasswordChangeRequired(false);
|
||||||
userAccount.setPasswordLinkExpires(0L);
|
userAccount.setPasswordLinkExpires(0L);
|
||||||
|
userAccount.setEmailKey("");
|
||||||
getUserAccountsDao().updateUserAccount(userAccount);
|
getUserAccountsDao().updateUserAccount(userAccount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -108,7 +108,9 @@ public class LoginRedirector {
|
||||||
throws IOException {
|
throws IOException {
|
||||||
try {
|
try {
|
||||||
DisplayMessage.setMessage(request, assembleWelcomeMessage());
|
DisplayMessage.setMessage(request, assembleWelcomeMessage());
|
||||||
response.sendRedirect(getRedirectionUriForLoggedInUser());
|
String redirectUrl = getRedirectionUriForLoggedInUser();
|
||||||
|
log.debug("Sending redirect to path: " + redirectUrl);
|
||||||
|
response.sendRedirect(redirectUrl);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
log.debug("Problem with re-direction", e);
|
log.debug("Problem with re-direction", e);
|
||||||
response.sendRedirect(getApplicationHomePageUrl());
|
response.sendRedirect(getApplicationHomePageUrl());
|
||||||
|
@ -175,21 +177,13 @@ public class LoginRedirector {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* The application home page can be overridden by an attribute in the
|
|
||||||
* ServletContext. Further, it can either be an absolute URL, or it can be
|
|
||||||
* relative to the application. Weird.
|
|
||||||
*/
|
|
||||||
private String getApplicationHomePageUrl() {
|
private String getApplicationHomePageUrl() {
|
||||||
String contextRedirect = (String) session.getServletContext()
|
String contextPath = request.getContextPath();
|
||||||
.getAttribute("postLoginRequest");
|
if (contextPath.equals("")) {
|
||||||
if (contextRedirect != null) {
|
return "/";
|
||||||
if (contextRedirect.indexOf(":") == -1) {
|
}
|
||||||
return request.getContextPath() + contextRedirect;
|
else {
|
||||||
} else {
|
return contextPath;
|
||||||
return contextRedirect;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return request.getContextPath();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,7 @@ public class Classes2ClassesRetryController extends BaseEditController {
|
||||||
action = epo.getAction();
|
action = epo.getAction();
|
||||||
}
|
}
|
||||||
|
|
||||||
VClassDao vcDao = ModelAccess.on(getServletContext()).getWebappDaoFactory().getVClassDao();
|
VClassDao vcDao = ModelAccess.on(request).getWebappDaoFactory().getVClassDao();
|
||||||
epo.setDataAccessObject(vcDao);
|
epo.setDataAccessObject(vcDao);
|
||||||
Classes2Classes objectForEditing = new Classes2Classes();
|
Classes2Classes objectForEditing = new Classes2Classes();
|
||||||
|
|
||||||
|
|
|
@ -51,8 +51,7 @@ public class ClassgroupRetryController extends BaseEditController {
|
||||||
action = epo.getAction();
|
action = epo.getAction();
|
||||||
}
|
}
|
||||||
|
|
||||||
VClassGroupDao cgDao = ModelAccess.on(
|
VClassGroupDao cgDao = ModelAccess.on(request).getWebappDaoFactory().getVClassGroupDao();
|
||||||
getServletContext()).getWebappDaoFactory().getVClassGroupDao();
|
|
||||||
|
|
||||||
epo.setDataAccessObject(cgDao);
|
epo.setDataAccessObject(cgDao);
|
||||||
|
|
||||||
|
|
|
@ -50,11 +50,12 @@ public class DatapropRetryController extends BaseEditController {
|
||||||
|
|
||||||
//create an EditProcessObject for this and put it in the session
|
//create an EditProcessObject for this and put it in the session
|
||||||
EditProcessObject epo = super.createEpo(request);
|
EditProcessObject epo = super.createEpo(request);
|
||||||
|
epo.setImplementationClass(DataProperty.class);
|
||||||
epo.setBeanClass(DataProperty.class);
|
epo.setBeanClass(DataProperty.class);
|
||||||
|
|
||||||
VitroRequest vreq = new VitroRequest(request);
|
VitroRequest vreq = new VitroRequest(request);
|
||||||
|
|
||||||
WebappDaoFactory wadf = ModelAccess.on(getServletContext()).getWebappDaoFactory();
|
WebappDaoFactory wadf = ModelAccess.on(vreq).getWebappDaoFactory();
|
||||||
|
|
||||||
DatatypeDao dDao = wadf.getDatatypeDao();
|
DatatypeDao dDao = wadf.getDatatypeDao();
|
||||||
DataPropertyDao dpDao = wadf.getDataPropertyDao();
|
DataPropertyDao dpDao = wadf.getDataPropertyDao();
|
||||||
|
|
|
@ -106,7 +106,7 @@ public class FauxPropertyRetryController extends BaseEditController {
|
||||||
|
|
||||||
this.epo = epo;
|
this.epo = epo;
|
||||||
|
|
||||||
this.fpDao = ModelAccess.on(ctx).getWebappDaoFactory()
|
this.fpDao = ModelAccess.on(req).getWebappDaoFactory()
|
||||||
.getFauxPropertyDao();
|
.getFauxPropertyDao();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -114,6 +114,8 @@ public class FauxPropertyRetryController extends BaseEditController {
|
||||||
void populate() {
|
void populate() {
|
||||||
epo.setDataAccessObject(fpDao);
|
epo.setDataAccessObject(fpDao);
|
||||||
epo.setAction(determineAction());
|
epo.setAction(determineAction());
|
||||||
|
epo.setImplementationClass(FauxProperty.class);
|
||||||
|
epo.setBeanClass(FauxProperty.class);
|
||||||
|
|
||||||
if (epo.getUseRecycledBean()) {
|
if (epo.getUseRecycledBean()) {
|
||||||
beanForEditing = (FauxProperty) epo.getNewBean();
|
beanForEditing = (FauxProperty) epo.getNewBean();
|
||||||
|
|
|
@ -71,7 +71,7 @@ public class NamespacePrefixOperationController extends BaseEditController {
|
||||||
|
|
||||||
if (request.getParameter("_cancel") == null) {
|
if (request.getParameter("_cancel") == null) {
|
||||||
|
|
||||||
OntModel ontModel = ModelAccess.on(getServletContext()).getOntModel();
|
OntModel ontModel = ModelAccess.on(req).getOntModel();
|
||||||
String namespaceStr = request.getParameter("namespace");
|
String namespaceStr = request.getParameter("namespace");
|
||||||
String prefixStr = request.getParameter("prefix");
|
String prefixStr = request.getParameter("prefix");
|
||||||
|
|
||||||
|
|
|
@ -51,7 +51,7 @@ public class PropertyGroupRetryController extends BaseEditController {
|
||||||
}
|
}
|
||||||
|
|
||||||
PropertyGroupDao pgDao = ModelAccess.on(
|
PropertyGroupDao pgDao = ModelAccess.on(
|
||||||
getServletContext()).getWebappDaoFactory().getPropertyGroupDao();
|
req).getWebappDaoFactory().getPropertyGroupDao();
|
||||||
|
|
||||||
epo.setDataAccessObject(pgDao);
|
epo.setDataAccessObject(pgDao);
|
||||||
|
|
||||||
|
|
|
@ -53,6 +53,7 @@ public class PropertyRetryController extends BaseEditController {
|
||||||
|
|
||||||
/*for testing*/
|
/*for testing*/
|
||||||
ObjectProperty testMask = new ObjectProperty();
|
ObjectProperty testMask = new ObjectProperty();
|
||||||
|
epo.setImplementationClass(ObjectProperty.class);
|
||||||
epo.setBeanClass(ObjectProperty.class);
|
epo.setBeanClass(ObjectProperty.class);
|
||||||
epo.setBeanMask(testMask);
|
epo.setBeanMask(testMask);
|
||||||
|
|
||||||
|
@ -64,7 +65,7 @@ public class PropertyRetryController extends BaseEditController {
|
||||||
action = epo.getAction();
|
action = epo.getAction();
|
||||||
}
|
}
|
||||||
|
|
||||||
ObjectPropertyDao propDao = ModelAccess.on(getServletContext()).getWebappDaoFactory().getObjectPropertyDao();
|
ObjectPropertyDao propDao = ModelAccess.on(req).getWebappDaoFactory().getObjectPropertyDao();
|
||||||
epo.setDataAccessObject(propDao);
|
epo.setDataAccessObject(propDao);
|
||||||
OntologyDao ontDao = request.getUnfilteredWebappDaoFactory().getOntologyDao();
|
OntologyDao ontDao = request.getUnfilteredWebappDaoFactory().getOntologyDao();
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,7 @@ public class RestrictionOperationController extends BaseEditController {
|
||||||
String defaultLandingPage = getDefaultLandingPage(request);
|
String defaultLandingPage = getDefaultLandingPage(request);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
OntModel ontModel = ModelAccess.on(getServletContext())
|
OntModel ontModel = ModelAccess.on(req)
|
||||||
.getOntModel(TBOX_ASSERTIONS);
|
.getOntModel(TBOX_ASSERTIONS);
|
||||||
|
|
||||||
HashMap epoHash = null;
|
HashMap epoHash = null;
|
||||||
|
|
|
@ -48,7 +48,7 @@ public class VclassEditController extends BaseEditController {
|
||||||
EditProcessObject epo = super.createEpo(request, FORCE_NEW);
|
EditProcessObject epo = super.createEpo(request, FORCE_NEW);
|
||||||
request.setAttribute("epoKey", epo.getKey());
|
request.setAttribute("epoKey", epo.getKey());
|
||||||
|
|
||||||
VClassDao vcwDao = ModelAccess.on(getServletContext()).getWebappDaoFactory(ASSERTIONS_ONLY).getVClassDao();
|
VClassDao vcwDao = ModelAccess.on(req).getWebappDaoFactory(ASSERTIONS_ONLY).getVClassDao();
|
||||||
VClass vcl = (VClass)vcwDao.getVClassByURI(request.getParameter("uri"));
|
VClass vcl = (VClass)vcwDao.getVClassByURI(request.getParameter("uri"));
|
||||||
|
|
||||||
if (vcl == null) {
|
if (vcl == null) {
|
||||||
|
@ -152,8 +152,8 @@ public class VclassEditController extends BaseEditController {
|
||||||
request.setAttribute("formSelect",formSelect);
|
request.setAttribute("formSelect",formSelect);
|
||||||
|
|
||||||
// if supported, we want to show only the asserted superclasses and subclasses.
|
// if supported, we want to show only the asserted superclasses and subclasses.
|
||||||
VClassDao vcDao = ModelAccess.on(getServletContext()).getWebappDaoFactory(ASSERTIONS_ONLY).getVClassDao();
|
VClassDao vcDao = ModelAccess.on(req).getWebappDaoFactory(ASSERTIONS_ONLY).getVClassDao();
|
||||||
VClassDao displayVcDao = ModelAccess.on(getServletContext()).getWebappDaoFactory().getVClassDao();
|
VClassDao displayVcDao = ModelAccess.on(req).getWebappDaoFactory().getVClassDao();
|
||||||
|
|
||||||
List<VClass> superVClasses = getVClassesForURIList(
|
List<VClass> superVClasses = getVClassesForURIList(
|
||||||
vcDao.getSuperClassURIs(vcl.getURI(),false), displayVcDao);
|
vcDao.getSuperClassURIs(vcl.getURI(),false), displayVcDao);
|
||||||
|
|
|
@ -66,11 +66,10 @@ public class VclassRetryController extends BaseEditController {
|
||||||
action = epo.getAction();
|
action = epo.getAction();
|
||||||
}
|
}
|
||||||
|
|
||||||
WebappDaoFactory wadf = ModelAccess.on(getServletContext()).getWebappDaoFactory();
|
WebappDaoFactory wadf = ModelAccess.on(req).getWebappDaoFactory();
|
||||||
|
|
||||||
VClassDao vcwDao = wadf.getVClassDao();
|
VClassDao vcwDao = wadf.getVClassDao();
|
||||||
epo.setDataAccessObject(vcwDao);
|
epo.setDataAccessObject(vcwDao);
|
||||||
VClassGroupDao cgDao = wadf.getVClassGroupDao();
|
|
||||||
OntologyDao oDao = wadf.getOntologyDao();
|
OntologyDao oDao = wadf.getOntologyDao();
|
||||||
|
|
||||||
VClass vclassForEditing = null;
|
VClass vclassForEditing = null;
|
||||||
|
|
|
@ -37,7 +37,7 @@ public class NamespacesListingController extends BaseEditController {
|
||||||
|
|
||||||
VitroRequest vrequest = new VitroRequest(request);
|
VitroRequest vrequest = new VitroRequest(request);
|
||||||
|
|
||||||
OntModel ontModel = ModelAccess.on(getServletContext()).getOntModel();
|
OntModel ontModel = ModelAccess.on(vrequest).getOntModel();
|
||||||
|
|
||||||
ArrayList results = new ArrayList();
|
ArrayList results = new ArrayList();
|
||||||
request.setAttribute("results",results);
|
request.setAttribute("results",results);
|
||||||
|
|
|
@ -54,7 +54,7 @@ public class RestrictionsListingController extends BaseEditController {
|
||||||
|
|
||||||
epo = super.createEpo(request);
|
epo = super.createEpo(request);
|
||||||
|
|
||||||
OntModel ontModel = ModelAccess.on(getServletContext()).getOntModel();
|
OntModel ontModel = ModelAccess.on(vrequest).getOntModel();
|
||||||
|
|
||||||
ObjectPropertyDao opDao = vrequest.getUnfilteredWebappDaoFactory().getObjectPropertyDao();
|
ObjectPropertyDao opDao = vrequest.getUnfilteredWebappDaoFactory().getObjectPropertyDao();
|
||||||
VClassDao vcDao = vrequest.getUnfilteredWebappDaoFactory().getVClassDao();
|
VClassDao vcDao = vrequest.getUnfilteredWebappDaoFactory().getVClassDao();
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
package edu.cornell.mannlib.vitro.webapp.controller.freemarker;
|
package edu.cornell.mannlib.vitro.webapp.controller.freemarker;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -42,6 +44,8 @@ public class BrowseController extends FreemarkerHttpServlet {
|
||||||
List<VClassGroup> groups = null;
|
List<VClassGroup> groups = null;
|
||||||
VClassGroupsForRequest vcgc = VClassGroupCache.getVClassGroups(vreq);
|
VClassGroupsForRequest vcgc = VClassGroupCache.getVClassGroups(vreq);
|
||||||
groups =vcgc.getGroups();
|
groups =vcgc.getGroups();
|
||||||
|
Collections.sort(groups, publicNameComparator);
|
||||||
|
// sortGroupListByPublicName(groups);
|
||||||
List<VClassGroupTemplateModel> vcgroups = new ArrayList<VClassGroupTemplateModel>(groups.size());
|
List<VClassGroupTemplateModel> vcgroups = new ArrayList<VClassGroupTemplateModel>(groups.size());
|
||||||
for (VClassGroup group : groups) {
|
for (VClassGroup group : groups) {
|
||||||
vcgroups.add(new VClassGroupTemplateModel(group));
|
vcgroups.add(new VClassGroupTemplateModel(group));
|
||||||
|
@ -50,4 +54,35 @@ public class BrowseController extends FreemarkerHttpServlet {
|
||||||
|
|
||||||
return new TemplateResponseValues(templateName, body);
|
return new TemplateResponseValues(templateName, body);
|
||||||
}
|
}
|
||||||
|
public Comparator<VClassGroup> publicNameComparator = new Comparator<VClassGroup>() {
|
||||||
|
|
||||||
|
public int compare(VClassGroup s1, VClassGroup s2) {
|
||||||
|
String groupName1 = s1.getPublicName().toUpperCase();
|
||||||
|
String groupName2 = s2.getPublicName().toUpperCase();
|
||||||
|
|
||||||
|
//ascending order
|
||||||
|
return groupName1.compareTo(groupName2);
|
||||||
|
|
||||||
|
//descending order
|
||||||
|
//return groupName2.compareTo(groupName1);
|
||||||
|
}};
|
||||||
|
|
||||||
|
//
|
||||||
|
// public void sortGroupListByPublicName(List<VClassGroup> groupList) {
|
||||||
|
// groupList.sort(new Comparator<VClassGroup>() {
|
||||||
|
// public int compare(VClassGroup first, VClassGroup second) {
|
||||||
|
// if (first != null) {
|
||||||
|
// if (second != null) {
|
||||||
|
// return (first.getDisplayRank() - second.getDisplayRank());
|
||||||
|
// } else {
|
||||||
|
// log.error("error--2nd VClassGroup is null in VClassGroupDao.getGroupList().compare()");
|
||||||
|
// }
|
||||||
|
// } else {
|
||||||
|
// log.error("error--1st VClassGroup is null in VClassGroupDao.getGroupList().compare()");
|
||||||
|
// }
|
||||||
|
// return 0;
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,200 @@
|
||||||
|
package edu.cornell.mannlib.vitro.webapp.controller.freemarker;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
import javax.servlet.annotation.WebServlet;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.apache.jena.query.Query;
|
||||||
|
import org.apache.jena.query.QueryExecution;
|
||||||
|
import org.apache.jena.query.QueryExecutionFactory;
|
||||||
|
import org.apache.jena.query.QueryFactory;
|
||||||
|
import org.apache.jena.query.QuerySolution;
|
||||||
|
import org.apache.jena.query.QuerySolutionMap;
|
||||||
|
import org.apache.jena.query.ResultSet;
|
||||||
|
import org.apache.jena.rdf.model.Model;
|
||||||
|
import org.apache.jena.rdf.model.ResourceFactory;
|
||||||
|
import org.apache.jena.shared.Lock;
|
||||||
|
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.auth.permissions.SimplePermission;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.AuthorizationRequest;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||||
|
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.controller.freemarker.responsevalues.TemplateResponseValues;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.QueryUtils;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.event.BulkUpdateEvent;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelNames;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.ChangeSet;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceException;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceUtils;
|
||||||
|
|
||||||
|
@WebServlet(name="DeleteIndividualController",urlPatterns="/deleteIndividualController")
|
||||||
|
public class DeleteIndividualController extends FreemarkerHttpServlet{
|
||||||
|
|
||||||
|
private static final Log log = LogFactory.getLog(DeleteIndividualController.class);
|
||||||
|
private static final boolean BEGIN = true;
|
||||||
|
private static final boolean END = !BEGIN;
|
||||||
|
|
||||||
|
private static String TYPE_QUERY = ""
|
||||||
|
+ "PREFIX vitro: <http://vitro.mannlib.cornell.edu/ns/vitro/0.7#>"
|
||||||
|
+ "SELECT ?type "
|
||||||
|
+ "WHERE"
|
||||||
|
+ "{ ?individualURI vitro:mostSpecificType ?type ."
|
||||||
|
+ "}";
|
||||||
|
private static String queryForDeleteQuery =
|
||||||
|
"PREFIX display: <" + DisplayVocabulary.DISPLAY_NS +"> \n" +
|
||||||
|
"SELECT ?deleteQueryText WHERE { ?associatedURI display:hasDeleteQuery ?deleteQueryText }";
|
||||||
|
|
||||||
|
private static final String DEFAULT_DELETE_QUERY_TEXT = "DESCRIBE ?individualURI";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected AuthorizationRequest requiredActions(VitroRequest vreq) {
|
||||||
|
return SimplePermission.DO_FRONT_END_EDITING.ACTION;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ResponseValues processRequest(VitroRequest vreq) {
|
||||||
|
String errorMessage = handleErrors(vreq);
|
||||||
|
if (!errorMessage.isEmpty()) {
|
||||||
|
return prepareErrorMessage(errorMessage);
|
||||||
|
}
|
||||||
|
String individualUri = vreq.getParameter("individualUri");
|
||||||
|
String type = getObjectMostSpecificType(individualUri, vreq);
|
||||||
|
Model displayModel = vreq.getDisplayModel();
|
||||||
|
|
||||||
|
String delteQueryText = getDeleteQueryForType(type, displayModel);
|
||||||
|
byte[] toRemove = getIndividualsToDelete(individualUri, delteQueryText, vreq);
|
||||||
|
if (toRemove.length > 0) {
|
||||||
|
deleteIndividuals(toRemove, vreq);
|
||||||
|
}
|
||||||
|
String redirectUrl = getRedirectUrl(vreq);
|
||||||
|
|
||||||
|
return new RedirectResponseValues(redirectUrl, HttpServletResponse.SC_SEE_OTHER);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getRedirectUrl(VitroRequest vreq) {
|
||||||
|
String redirectUrl = vreq.getParameter("redirectUrl");
|
||||||
|
if (redirectUrl != null) {
|
||||||
|
return redirectUrl;
|
||||||
|
}
|
||||||
|
return "/";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private TemplateResponseValues prepareErrorMessage(String errorMessage) {
|
||||||
|
HashMap<String, Object> map = new HashMap<String, Object>();
|
||||||
|
map.put("errorMessage", errorMessage);
|
||||||
|
return new TemplateResponseValues("error-message.ftl", map);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String handleErrors(VitroRequest vreq) {
|
||||||
|
String uri = vreq.getParameter("individualUri");
|
||||||
|
if (uri == null) {
|
||||||
|
return "Individual uri is null. No object to delete.";
|
||||||
|
}
|
||||||
|
if (uri.contains(">")) {
|
||||||
|
return "Individual uri shouldn't contain >";
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getDeleteQueryForType(String typeURI, Model displayModel) {
|
||||||
|
String deleteQueryText = DEFAULT_DELETE_QUERY_TEXT;
|
||||||
|
Query queryForTypeSpecificDeleteQuery = QueryFactory.create(queryForDeleteQuery);
|
||||||
|
QuerySolutionMap initialBindings = new QuerySolutionMap();
|
||||||
|
initialBindings.add("associatedURI", ResourceFactory.createResource(typeURI));
|
||||||
|
displayModel.enterCriticalSection(Lock.READ);
|
||||||
|
try {
|
||||||
|
QueryExecution qexec = QueryExecutionFactory.create(queryForTypeSpecificDeleteQuery, displayModel, initialBindings);
|
||||||
|
try {
|
||||||
|
ResultSet results = qexec.execSelect();
|
||||||
|
while (results.hasNext()) {
|
||||||
|
QuerySolution solution = results.nextSolution();
|
||||||
|
deleteQueryText = solution.get("deleteQueryText").toString();
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
qexec.close();
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
displayModel.leaveCriticalSection();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!deleteQueryText.equals(DEFAULT_DELETE_QUERY_TEXT)) {
|
||||||
|
log.debug("For " + typeURI + " found delete query \n" + deleteQueryText);
|
||||||
|
} else {
|
||||||
|
log.debug("For " + typeURI + " delete query not found. Using defalut query \n" + deleteQueryText);
|
||||||
|
}
|
||||||
|
return deleteQueryText;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getObjectMostSpecificType(String individualURI, VitroRequest vreq) {
|
||||||
|
String type = "";
|
||||||
|
try {
|
||||||
|
Query typeQuery = QueryFactory.create(TYPE_QUERY);
|
||||||
|
QuerySolutionMap bindings = new QuerySolutionMap();
|
||||||
|
bindings.add("individualURI", ResourceFactory.createResource(individualURI));
|
||||||
|
Model ontModel = vreq.getJenaOntModel();
|
||||||
|
QueryExecution qexec = QueryExecutionFactory.create(typeQuery, ontModel, bindings);
|
||||||
|
ResultSet results = qexec.execSelect();
|
||||||
|
while (results.hasNext()) {
|
||||||
|
QuerySolution solution = results.nextSolution();
|
||||||
|
type = solution.get("type").toString();
|
||||||
|
log.debug(type);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Failed to get type for individual URI " + individualURI);
|
||||||
|
log.error(e, e);
|
||||||
|
}
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
private byte[] getIndividualsToDelete(String targetIndividual, String deleteQuery, VitroRequest vreq) {
|
||||||
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
|
try {
|
||||||
|
Query queryForTypeSpecificDeleteQuery = QueryFactory.create(deleteQuery);
|
||||||
|
QuerySolutionMap bindings = new QuerySolutionMap();
|
||||||
|
bindings.add("individualURI", ResourceFactory.createResource(targetIndividual));
|
||||||
|
Model ontModel = vreq.getJenaOntModel();
|
||||||
|
QueryExecution qexec = QueryExecutionFactory.create(queryForTypeSpecificDeleteQuery, ontModel, bindings);
|
||||||
|
Model results = qexec.execDescribe();
|
||||||
|
results.write(out, "N3");
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Query raised an error \n" + deleteQuery);
|
||||||
|
log.error(e, e);
|
||||||
|
}
|
||||||
|
return out.toByteArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void deleteIndividuals(byte[] toRemove, VitroRequest vreq) {
|
||||||
|
String removingString = new String(toRemove, StandardCharsets.UTF_8);
|
||||||
|
RDFService rdfService = vreq.getRDFService();
|
||||||
|
ChangeSet cs = makeChangeSet(rdfService);
|
||||||
|
InputStream in = new ByteArrayInputStream(toRemove);
|
||||||
|
cs.addRemoval(in, RDFServiceUtils.getSerializationFormatFromJenaString("N3"), ModelNames.ABOX_ASSERTIONS);
|
||||||
|
try {
|
||||||
|
rdfService.changeSetUpdate(cs);
|
||||||
|
} catch (RDFServiceException e) {
|
||||||
|
log.error("Got error while removing\n" + removingString);
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private ChangeSet makeChangeSet(RDFService rdfService) {
|
||||||
|
ChangeSet cs = rdfService.manufactureChangeSet();
|
||||||
|
cs.addPreChangeEvent(new BulkUpdateEvent(null, BEGIN));
|
||||||
|
cs.addPostChangeEvent(new BulkUpdateEvent(null, END));
|
||||||
|
return cs;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -10,6 +10,9 @@ import javax.servlet.http.HttpServletResponse;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
|
import org.apache.jena.rdf.model.Property;
|
||||||
|
import org.apache.jena.rdf.model.ResourceFactory;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.auth.permissions.SimplePermission;
|
import edu.cornell.mannlib.vitro.webapp.auth.permissions.SimplePermission;
|
||||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.AuthorizationRequest;
|
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.AuthorizationRequest;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.DataProperty;
|
import edu.cornell.mannlib.vitro.webapp.beans.DataProperty;
|
||||||
|
@ -25,6 +28,8 @@ import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationUti
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.N3EditUtils;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.N3EditUtils;
|
||||||
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess;
|
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess;
|
||||||
import edu.cornell.mannlib.vitro.webapp.web.URLEncoder;
|
import edu.cornell.mannlib.vitro.webapp.web.URLEncoder;
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Custom deletion controller to which deletion requests from default property form are sent. May be replaced
|
* Custom deletion controller to which deletion requests from default property form are sent. May be replaced
|
||||||
* later with additional features in process rdf form controller or alternative location.
|
* later with additional features in process rdf form controller or alternative location.
|
||||||
|
@ -64,8 +69,8 @@ public class DeletePropertyController extends FreemarkerHttpServlet {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
String subjectUri = EditConfigurationUtils.getSubjectUri(vreq);
|
String subjectUri = EditConfigurationUtils.getSubjectUri(vreq);
|
||||||
String predicateUri = EditConfigurationUtils.getPredicateUri(vreq);
|
String predicateUri = EditConfigurationUtils.getPredicateUri(vreq);
|
||||||
int hashIndex = predicateUri.lastIndexOf("#");
|
Property prop = ResourceFactory.createProperty(predicateUri);
|
||||||
String localName = predicateUri.substring(hashIndex + 1);
|
String localName = prop.getLocalName();
|
||||||
String redirectUrl = "/entity?uri=" + URLEncoder.encode(subjectUri);
|
String redirectUrl = "/entity?uri=" + URLEncoder.encode(subjectUri);
|
||||||
return redirectUrl + "#" + URLEncoder.encode(localName);
|
return redirectUrl + "#" + URLEncoder.encode(localName);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,435 @@
|
||||||
|
package edu.cornell.mannlib.vitro.webapp.controller.freemarker;
|
||||||
|
|
||||||
|
import static edu.cornell.mannlib.vitro.webapp.auth.requestedAction.AuthorizationRequest.UNAUTHORIZED;
|
||||||
|
import static edu.cornell.mannlib.vitro.webapp.controller.freemarker.ImageUploadController.PARAMETER_UPLOADED_FILE;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import javax.servlet.ServletException;
|
||||||
|
import javax.servlet.annotation.WebServlet;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
import org.apache.commons.fileupload.FileItem;
|
||||||
|
import org.apache.commons.io.FilenameUtils;
|
||||||
|
import org.apache.commons.lang3.RandomStringUtils;
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.apache.jena.ontology.OntModel;
|
||||||
|
import org.apache.tika.Tika;
|
||||||
|
import org.apache.tika.mime.MimeType;
|
||||||
|
import org.apache.tika.mime.MimeTypeException;
|
||||||
|
import org.apache.tika.mime.MimeTypes;
|
||||||
|
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.application.ApplicationUtils;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.AuthorizationRequest;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.RequestedAction;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.propstmt.AddObjectPropertyStatement;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.propstmt.DropObjectPropertyStatement;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.beans.Property;
|
||||||
|
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.RedirectResponseValues;
|
||||||
|
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.WebappDaoFactory;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.filestorage.UploadedFileHelper;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.filestorage.model.FileInfo;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.i18n.I18n;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.modules.fileStorage.FileStorage;
|
||||||
|
|
||||||
|
@WebServlet(name = "FileUploadController", urlPatterns = { "/uploadFile" })
|
||||||
|
public class FileUploadController extends FreemarkerHttpServlet {
|
||||||
|
private static final String TEMPLATE_VAR_FORM_ACTION = "formAction";
|
||||||
|
private static final String TEMPLATE_VAR_MAX_FILE_SIZE = "maxFileSize";
|
||||||
|
private static final String PARAM_REFERRER = "referrer";
|
||||||
|
private static final String TEMPLATE_VAR_SUPPORTED_TYPES = "supportedTypes";
|
||||||
|
private static final String TEMPLATE_VAR_SUPPORTED_MIME_TYPES = "supportedMIMETypes";
|
||||||
|
|
||||||
|
private static final String TEMPLATE_VAR_ERROR_MESSAGE = "errorMessage";
|
||||||
|
private static final String DEFAULT_FILE_NAME = "fileName";
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private static final Log log = LogFactory.getLog(FileUploadController.class);
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
private static final String PARAMETER_ACTION = "action";
|
||||||
|
private static final String ACTION_DELETE = "delete";
|
||||||
|
private static final String ACTION_UPLOAD = "upload";
|
||||||
|
private static final String PARAMETER_FILE_URI = "fileUri";
|
||||||
|
private static final String PARAMETER_SUBJECT_URI = "subjectUri";
|
||||||
|
private static final String CONFIG_MAX_FILE_SIZE = "fileUpload.maxFileSize";
|
||||||
|
private static final String ALLOWED_MIME_TYPES = "fileUpload.allowedMIMETypes";
|
||||||
|
private static final Long DEFAULT_FILE_SIZE = (long) (10 * 1024 * 1024);
|
||||||
|
private static final String PARAMETER_PREDICATE_URI = "predicateUri";
|
||||||
|
private static final String DEFAULT_TEMPLATE = "fileUpload-default.ftl";
|
||||||
|
private static Long maxFileSize = DEFAULT_FILE_SIZE;
|
||||||
|
private FileStorage fileStorage;
|
||||||
|
private Set<String> allowedMimeTypes;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init() throws ServletException {
|
||||||
|
super.init();
|
||||||
|
fileStorage = ApplicationUtils.instance().getFileStorage();
|
||||||
|
setMaxFileSize();
|
||||||
|
setAllowedMimeTypes();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected AuthorizationRequest requiredActions(VitroRequest vreq) {
|
||||||
|
RequestedAction ra;
|
||||||
|
try {
|
||||||
|
Property predicate = new Property(getPredicateUri(vreq));
|
||||||
|
final OntModel jenaOntModel = vreq.getJenaOntModel();
|
||||||
|
final String subject = getSubjectUri(vreq);
|
||||||
|
if (isUpload(vreq)) {
|
||||||
|
ra = new AddObjectPropertyStatement(jenaOntModel, subject, predicate,RequestedAction.SOME_URI);
|
||||||
|
} else { // delete
|
||||||
|
ra = new DropObjectPropertyStatement(jenaOntModel, subject, predicate, getFileUri(vreq));
|
||||||
|
}
|
||||||
|
return ra;
|
||||||
|
} catch (Exception e) {
|
||||||
|
return UNAUTHORIZED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getFileUri(VitroRequest vreq) {
|
||||||
|
return vreq.getParameter(PARAMETER_FILE_URI);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected ResponseValues processRequest(VitroRequest vreq) {
|
||||||
|
try {
|
||||||
|
getReferrer(vreq);
|
||||||
|
validateRequest(vreq);
|
||||||
|
if (isUpload(vreq)) {
|
||||||
|
uploadFile(vreq);
|
||||||
|
} else if (isDelete(vreq)) {
|
||||||
|
deleteFile(vreq);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
return pageResponse(vreq, e.getMessage());
|
||||||
|
}
|
||||||
|
return new RedirectResponseValues(getNextPageUrl(vreq), HttpServletResponse.SC_SEE_OTHER);
|
||||||
|
}
|
||||||
|
private String getNextPageUrl(VitroRequest vreq) {
|
||||||
|
return getReferrer(vreq);
|
||||||
|
}
|
||||||
|
|
||||||
|
private TemplateResponseValues pageResponse(VitroRequest vreq, String error) {
|
||||||
|
TemplateResponseValues rv = new TemplateResponseValues(DEFAULT_TEMPLATE);
|
||||||
|
rv.put(PARAMETER_ACTION, vreq.getParameter(PARAMETER_ACTION));
|
||||||
|
rv.put(TEMPLATE_VAR_FORM_ACTION, formatRequestUrl(vreq));
|
||||||
|
if (!error.isEmpty()) {
|
||||||
|
rv.put(TEMPLATE_VAR_ERROR_MESSAGE, error);
|
||||||
|
}
|
||||||
|
rv.put(PARAM_REFERRER,getReferrer(vreq));
|
||||||
|
rv.put(TEMPLATE_VAR_SUPPORTED_TYPES, printAllowedFileExtensions());
|
||||||
|
rv.put(TEMPLATE_VAR_SUPPORTED_MIME_TYPES, printAllowedMimeTypes());
|
||||||
|
rv.put(TEMPLATE_VAR_MAX_FILE_SIZE, maxFileSizeInMegabytes());
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String formatRequestUrl(VitroRequest vreq) {
|
||||||
|
String result = vreq.getRequestURL().toString() + "?";
|
||||||
|
String query = vreq.getQueryString();
|
||||||
|
if (query != null) {
|
||||||
|
result += query;
|
||||||
|
}
|
||||||
|
String referrer = vreq.getParameter(PARAM_REFERRER);
|
||||||
|
if (referrer == null || referrer.isEmpty()) {
|
||||||
|
result += "&" + PARAM_REFERRER + "=" + getReferrer(vreq);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Double maxFileSizeInMegabytes() {
|
||||||
|
if (maxFileSize > 0) {
|
||||||
|
return ((double) maxFileSize/1048576);
|
||||||
|
} else {
|
||||||
|
return 0.0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void validateRequest(VitroRequest vreq) throws FileUploadException {
|
||||||
|
if (isUpload(vreq)) {
|
||||||
|
validateUploadRequest(vreq);
|
||||||
|
} else if (isDelete(vreq)) {
|
||||||
|
validateDeleteRequest(vreq);
|
||||||
|
} else if (hasAction(vreq)) {
|
||||||
|
throw new FileUploadException("Only delete and upload actions supported");
|
||||||
|
} else {
|
||||||
|
throw new FileUploadException("No action specified");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void validateDeleteRequest(VitroRequest vreq) throws FileUploadException {
|
||||||
|
validateSubjectUri(vreq);
|
||||||
|
validatePredicateUri(vreq);
|
||||||
|
validateFileUri(vreq);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void validateUploadRequest(VitroRequest vreq) throws FileUploadException {
|
||||||
|
validateSubjectUri(vreq);
|
||||||
|
validatePredicateUri(vreq);
|
||||||
|
validateFile(vreq);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void validateFile(VitroRequest vreq) throws FileUploadException {
|
||||||
|
Map<String, List<FileItem>> map = vreq.getFiles();
|
||||||
|
if (map == null) {
|
||||||
|
throw new FileUploadException("File to upload not found");
|
||||||
|
}
|
||||||
|
List<FileItem> list = map.get(PARAMETER_UPLOADED_FILE);
|
||||||
|
if ((list == null) || list.isEmpty()) {
|
||||||
|
throw new FileUploadException("No file uploaded");
|
||||||
|
}
|
||||||
|
FileItem file = list.get(0);
|
||||||
|
if (file.getSize() == 0) {
|
||||||
|
throw new FileUploadException("Uploaded file size is 0");
|
||||||
|
}
|
||||||
|
if (file.getSize() > maxFileSize) {
|
||||||
|
throw new FileUploadException("Uploaded file is too big. Maximum file size is " + maxFileSize
|
||||||
|
+ " bytes. Uploaded file is " + file.getSize() + " bytes.");
|
||||||
|
}
|
||||||
|
validateMimeType(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void validateMimeType(FileItem file) throws FileUploadException {
|
||||||
|
String mime = getMimeType(file);
|
||||||
|
if (mime.isEmpty()) {
|
||||||
|
throw new FileUploadException("File type is unrecognized");
|
||||||
|
}
|
||||||
|
String extension = null;
|
||||||
|
MimeTypes types = MimeTypes.getDefaultMimeTypes();
|
||||||
|
try {
|
||||||
|
MimeType mimeType = types.forName(mime);
|
||||||
|
extension = mimeType.getExtension();
|
||||||
|
} catch (MimeTypeException e) {
|
||||||
|
log.error(e.getLocalizedMessage());
|
||||||
|
}
|
||||||
|
if (extension == null || extension.isEmpty()) {
|
||||||
|
throw new FileUploadException("Extension for mime type " + mime + " not found");
|
||||||
|
}
|
||||||
|
if (!allowedMimeTypes.contains(mime.toLowerCase())) {
|
||||||
|
log.error("File mime type is not allowed. " + printAllowedMimeTypes() + " Current mime type is " + mime);
|
||||||
|
throw new FileUploadException(
|
||||||
|
"File type is not allowed. Allowed file types: " + printAllowedFileExtensions() +
|
||||||
|
" Current file type is " + getExtension(mime).replaceAll("\\.", ""));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String printAllowedFileExtensions() {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
for (Iterator<String> it = allowedMimeTypes.iterator(); it.hasNext();) {
|
||||||
|
String mimeType = (String) it.next();
|
||||||
|
String extension = getExtension(mimeType);
|
||||||
|
sb.append(extension.replaceAll("\\.", ""));
|
||||||
|
if (it.hasNext()) {
|
||||||
|
sb.append(", ");
|
||||||
|
} else {
|
||||||
|
sb.append(".");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String printAllowedMimeTypes() {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
for (Iterator<String> it = allowedMimeTypes.iterator(); it.hasNext();) {
|
||||||
|
String mimeType = (String) it.next();
|
||||||
|
sb.append(mimeType);
|
||||||
|
if (it.hasNext()) {
|
||||||
|
sb.append(", ");
|
||||||
|
} else {
|
||||||
|
sb.append(".");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean hasAction(VitroRequest vreq) {
|
||||||
|
return vreq.getParameter(PARAMETER_ACTION) != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void deleteFile(VitroRequest vreq) {
|
||||||
|
String subjectUri = getSubjectUri(vreq);
|
||||||
|
String predicateUri = getPredicateUri(vreq);
|
||||||
|
String fileUri = getFileUri(vreq);
|
||||||
|
WebappDaoFactory webAppDaoFactory = vreq.getUnfilteredWebappDaoFactory();
|
||||||
|
UploadedFileHelper fileHelper = new UploadedFileHelper(fileStorage, webAppDaoFactory, getServletContext());
|
||||||
|
fileHelper.removeUploadedFile(subjectUri, predicateUri, fileUri);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void uploadFile(VitroRequest vreq) throws FileUploadException {
|
||||||
|
String subjectUri = getSubjectUri(vreq);
|
||||||
|
String predicateUri = getPredicateUri(vreq);
|
||||||
|
FileItem file = getUploadedFile(vreq);
|
||||||
|
String uploadedFileName = getUploadedFileName(file);
|
||||||
|
String storedFileName = createStoredFileName(file);
|
||||||
|
WebappDaoFactory webAppDaoFactory = vreq.getUnfilteredWebappDaoFactory();
|
||||||
|
UploadedFileHelper fileHelper = new UploadedFileHelper(fileStorage, webAppDaoFactory, getServletContext());
|
||||||
|
FileInfo fileInfo = createFile(file, storedFileName, fileHelper);
|
||||||
|
fileHelper.attachFileToSubject(fileInfo, subjectUri, predicateUri);
|
||||||
|
fileHelper.setPublicFileName(fileInfo, uploadedFileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
private FileInfo createFile(FileItem file, String storedFileName, UploadedFileHelper fileHelper)
|
||||||
|
throws FileUploadException {
|
||||||
|
FileInfo fileInfo = null;
|
||||||
|
try {
|
||||||
|
fileInfo = fileHelper.createFile(storedFileName, getMimeType(file), file.getInputStream());
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error(e.getLocalizedMessage());
|
||||||
|
throw new FileUploadException(e.getLocalizedMessage());
|
||||||
|
}
|
||||||
|
return fileInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String createStoredFileName(FileItem file) {
|
||||||
|
String mimeString = getMimeType(file);
|
||||||
|
int length = 64;
|
||||||
|
boolean useLetters = true;
|
||||||
|
boolean useNumbers = true;
|
||||||
|
String storedFileName = RandomStringUtils.random(length, useLetters, useNumbers) + getExtension(mimeString);
|
||||||
|
return storedFileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getExtension(String mimeString) {
|
||||||
|
String extension = "";
|
||||||
|
MimeTypes types = MimeTypes.getDefaultMimeTypes();
|
||||||
|
try {
|
||||||
|
MimeType mime = types.forName(mimeString);
|
||||||
|
extension = mime.getExtension();
|
||||||
|
} catch (MimeTypeException e) {
|
||||||
|
log.error(e.getLocalizedMessage());
|
||||||
|
}
|
||||||
|
return extension;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getUploadedFileName(FileItem file) {
|
||||||
|
String fileName = file.getName();
|
||||||
|
if (fileName == null) {
|
||||||
|
return DEFAULT_FILE_NAME;
|
||||||
|
} else {
|
||||||
|
return FilenameUtils.getName(fileName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getMimeType(FileItem file) {
|
||||||
|
Tika tika = new Tika();
|
||||||
|
InputStream is;
|
||||||
|
String mime = "";
|
||||||
|
try {
|
||||||
|
is = file.getInputStream();
|
||||||
|
mime = tika.detect(is);
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.error(e.getLocalizedMessage());
|
||||||
|
}
|
||||||
|
return mime;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void validateFileUri(VitroRequest vreq) throws FileUploadException {
|
||||||
|
String fileUri = getFileUri(vreq);
|
||||||
|
validateUriNotEmpty(fileUri,"file");
|
||||||
|
validateIndividual(vreq, fileUri);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void validateSubjectUri(VitroRequest vreq) throws FileUploadException {
|
||||||
|
String subjectUri = getSubjectUri(vreq);
|
||||||
|
validateUriNotEmpty(subjectUri,"subject");
|
||||||
|
validateIndividual(vreq, subjectUri);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void validatePredicateUri(VitroRequest vreq) throws FileUploadException {
|
||||||
|
String predicateUri = getPredicateUri(vreq);
|
||||||
|
validateUriNotEmpty(predicateUri,"predicate");
|
||||||
|
validateIndividual(vreq, predicateUri);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void validateIndividual(VitroRequest vreq, String subjectUri) throws FileUploadException {
|
||||||
|
Individual subject = vreq.getUnfilteredWebappDaoFactory().getIndividualDao()
|
||||||
|
.getIndividualByURI(subjectUri);
|
||||||
|
if (subject == null) {
|
||||||
|
throw new FileUploadException("Uri " + subjectUri + "doesn't exist");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void validateUriNotEmpty(String predicateUri,String name) throws FileUploadException {
|
||||||
|
if (predicateUri == null || predicateUri.trim().isEmpty()) {
|
||||||
|
throw new FileUploadException("No " + name + " uri was given");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getPredicateUri(VitroRequest vreq) {
|
||||||
|
return vreq.getParameter(PARAMETER_PREDICATE_URI);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getSubjectUri(VitroRequest vreq) {
|
||||||
|
return vreq.getParameter(PARAMETER_SUBJECT_URI);
|
||||||
|
}
|
||||||
|
|
||||||
|
private FileItem getUploadedFile(VitroRequest vreq) {
|
||||||
|
return vreq.getFiles().get(PARAMETER_UPLOADED_FILE).get(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isUpload(VitroRequest vreq) {
|
||||||
|
String action = vreq.getParameter(PARAMETER_ACTION);
|
||||||
|
return ACTION_UPLOAD.equals(action);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isDelete(VitroRequest vreq) {
|
||||||
|
String action = vreq.getParameter(PARAMETER_ACTION);
|
||||||
|
return ACTION_DELETE.equals(action);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setAllowedMimeTypes() {
|
||||||
|
ConfigurationProperties config = ConfigurationProperties.getBean(getServletContext());
|
||||||
|
String allowedTypes = config.getProperty(ALLOWED_MIME_TYPES, "");
|
||||||
|
allowedMimeTypes = new HashSet<String>(Arrays.asList(allowedTypes.toLowerCase().trim().split("\\s*,\\s*")));
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getReferrer(VitroRequest vreq) {
|
||||||
|
String referrer = vreq.getParameter(PARAM_REFERRER);
|
||||||
|
if (referrer == null) {
|
||||||
|
referrer = vreq.getHeader("Referer");
|
||||||
|
}
|
||||||
|
if (referrer == null) {
|
||||||
|
referrer = "/";
|
||||||
|
}
|
||||||
|
return referrer;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setMaxFileSize() {
|
||||||
|
ConfigurationProperties config = ConfigurationProperties.getBean(getServletContext());
|
||||||
|
String configFileSize = config.getProperty(CONFIG_MAX_FILE_SIZE, DEFAULT_FILE_SIZE.toString());
|
||||||
|
try {
|
||||||
|
maxFileSize = Long.parseLong(configFileSize);
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
log.error("maxFileSize parsing failed");
|
||||||
|
log.error(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static class FileUploadException extends Exception {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
private final Object[] parameters;
|
||||||
|
|
||||||
|
FileUploadException(String message, Object... parameters) {
|
||||||
|
super(message);
|
||||||
|
this.parameters = parameters;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String formatMessage(HttpServletRequest req) {
|
||||||
|
return I18n.text(req, getMessage(), parameters);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -8,6 +8,7 @@ import static javax.mail.Message.RecipientType.TO;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -17,7 +18,6 @@ import javax.servlet.ServletException;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.MenuDaoJena;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
@ -93,6 +93,8 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
|
||||||
throws IOException, ServletException {
|
throws IOException, ServletException {
|
||||||
|
|
||||||
super.doGet(request,response);
|
super.doGet(request,response);
|
||||||
|
//UQAM-Optimization set for UTF-8
|
||||||
|
response.setCharacterEncoding("UTF-8");
|
||||||
|
|
||||||
VitroRequest vreq = new VitroRequest(request);
|
VitroRequest vreq = new VitroRequest(request);
|
||||||
ResponseValues responseValues = null;
|
ResponseValues responseValues = null;
|
||||||
|
@ -103,8 +105,8 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
|
||||||
if (!isAuthorizedToDisplayPage(request, response, requiredActions(vreq))) {
|
if (!isAuthorizedToDisplayPage(request, response, requiredActions(vreq))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
responseValues = processRequest(vreq);
|
responseValues = processRequest(vreq);
|
||||||
|
|
||||||
doResponse(vreq, response, responseValues);
|
doResponse(vreq, response, responseValues);
|
||||||
|
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
|
@ -276,8 +278,15 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
|
||||||
// is specified in the main page template.
|
// is specified in the main page template.
|
||||||
bodyString = "";
|
bodyString = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
templateDataModel.put("body", bodyString);
|
templateDataModel.put("body", bodyString);
|
||||||
|
|
||||||
|
String lang = vreq.getLocale().getLanguage();
|
||||||
|
if (!vreq.getLocale().getCountry().isEmpty()) {
|
||||||
|
lang += "-" + vreq.getLocale().getCountry();
|
||||||
|
}
|
||||||
|
templateDataModel.put("country", lang);
|
||||||
|
|
||||||
// Tell the template and any directives it uses that we're processing a page template.
|
// Tell the template and any directives it uses that we're processing a page template.
|
||||||
templateDataModel.put("templateType", PAGE_TEMPLATE_TYPE);
|
templateDataModel.put("templateType", PAGE_TEMPLATE_TYPE);
|
||||||
|
|
||||||
|
@ -462,7 +471,7 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
|
||||||
|
|
||||||
protected MainMenu getDisplayModelMenu(VitroRequest vreq){
|
protected MainMenu getDisplayModelMenu(VitroRequest vreq){
|
||||||
String url = vreq.getRequestURI().substring(vreq.getContextPath().length());
|
String url = vreq.getRequestURI().substring(vreq.getContextPath().length());
|
||||||
return vreq.getWebappDaoFactory().getMenuDao().getMainMenu(vreq, url);
|
return vreq.getWebappDaoFactory().getMenuDao().getMainMenu(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
// NIHVIVO-3307: we need this here instead of FreemarkerConfiguration.java so that updates to
|
// NIHVIVO-3307: we need this here instead of FreemarkerConfiguration.java so that updates to
|
||||||
|
|
|
@ -37,6 +37,7 @@ public class UrlBuilder {
|
||||||
LOGIN("/login"),
|
LOGIN("/login"),
|
||||||
LOGOUT("/logout"),
|
LOGOUT("/logout"),
|
||||||
OBJECT_PROPERTY_EDIT("/propertyEdit"),
|
OBJECT_PROPERTY_EDIT("/propertyEdit"),
|
||||||
|
EXTENDED_SEARCH("/extendedsearch"),
|
||||||
SEARCH("/search"),
|
SEARCH("/search"),
|
||||||
SITE_ADMIN("/siteAdmin"),
|
SITE_ADMIN("/siteAdmin"),
|
||||||
TERMS_OF_USE("/termsOfUse"),
|
TERMS_OF_USE("/termsOfUse"),
|
||||||
|
|
|
@ -11,28 +11,29 @@ import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.servlet.ServletException;
|
import javax.servlet.ServletException;
|
||||||
import javax.servlet.annotation.WebServlet;
|
import javax.servlet.annotation.WebServlet;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.LocaleUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
import org.apache.jena.query.QuerySolution;
|
import org.apache.jena.query.QuerySolution;
|
||||||
import org.apache.jena.query.ResultSet;
|
import org.apache.jena.query.ResultSet;
|
||||||
import org.apache.jena.rdf.model.Literal;
|
import org.apache.jena.rdf.model.Literal;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerHttpServlet;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ExceptionResponseValues;
|
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ExceptionResponseValues;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ResponseValues;
|
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.controller.freemarker.responsevalues.TemplateResponseValues;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.QueryUtils;
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.QueryUtils;
|
||||||
import edu.cornell.mannlib.vitro.webapp.i18n.selection.SelectedLocale;
|
import edu.cornell.mannlib.vitro.webapp.i18n.selection.SelectedLocale;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.filter.LanguageFilteringUtils;
|
||||||
|
|
||||||
|
|
||||||
/*Servlet to view all labels in various languages for individual*/
|
/*Servlet to view all labels in various languages for individual*/
|
||||||
|
@ -47,12 +48,13 @@ public class ViewLabelsServlet extends FreemarkerHttpServlet{
|
||||||
String subjectUri = vreq.getParameter("subjectUri");
|
String subjectUri = vreq.getParameter("subjectUri");
|
||||||
body.put("subjectUri", subjectUri);
|
body.put("subjectUri", subjectUri);
|
||||||
try {
|
try {
|
||||||
//Get all language codes/labels in the system, and this list is sorted by language name
|
|
||||||
List<HashMap<String, String>> locales = this.getLocales(vreq);
|
|
||||||
//Get code to label hashmap - we use this to get the language name for the language code returned in the rdf literal
|
|
||||||
HashMap<String, String> localeCodeToNameMap = this.getFullCodeToLanguageNameMap(locales);
|
|
||||||
//the labels already added by the user
|
//the labels already added by the user
|
||||||
ArrayList<Literal> existingLabels = this.getExistingLabels(subjectUri, vreq);
|
ArrayList<Literal> existingLabels = this.getExistingLabels(subjectUri, vreq);
|
||||||
|
//Get all language codes/labels used in the list of existing labels
|
||||||
|
List<HashMap<String, String>> locales = this.getLocales(vreq, existingLabels);
|
||||||
|
//Get code to label hashmap - we use this to get the language name for the language code returned in the rdf literal
|
||||||
|
HashMap<String, String> localeCodeToNameMap = this.getFullCodeToLanguageNameMap(locales);
|
||||||
|
|
||||||
//existing labels keyed by language name and each of the list of labels is sorted by language name
|
//existing labels keyed by language name and each of the list of labels is sorted by language name
|
||||||
HashMap<String, List<LabelInformation>> existingLabelsByLanguageName = this.getLabelsSortedByLanguageName(existingLabels, localeCodeToNameMap, vreq, subjectUri);
|
HashMap<String, List<LabelInformation>> existingLabelsByLanguageName = this.getLabelsSortedByLanguageName(existingLabels, localeCodeToNameMap, vreq, subjectUri);
|
||||||
//Get available locales for the drop down for adding a new label, also sorted by language name
|
//Get available locales for the drop down for adding a new label, also sorted by language name
|
||||||
|
@ -137,20 +139,26 @@ public class ViewLabelsServlet extends FreemarkerHttpServlet{
|
||||||
doGet(request, response);
|
doGet(request, response);
|
||||||
}
|
}
|
||||||
|
|
||||||
//get locales
|
//get locales present in list of literals
|
||||||
public List<HashMap<String, String>> getLocales(VitroRequest vreq) {
|
public List<HashMap<String, String>> getLocales(VitroRequest vreq,
|
||||||
List<Locale> selectables = SelectedLocale.getSelectableLocales(vreq);
|
List<Literal> existingLiterals) {
|
||||||
if (selectables.isEmpty()) {
|
Set<Locale> locales = new HashSet<Locale>();
|
||||||
|
for(Literal literal : existingLiterals) {
|
||||||
|
String language = literal.getLanguage();
|
||||||
|
if(!StringUtils.isEmpty(language)) {
|
||||||
|
locales.add(LanguageFilteringUtils.languageToLocale(language));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (locales.isEmpty()) {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
List<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
|
List<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
|
||||||
Locale currentLocale = SelectedLocale.getCurrentLocale(vreq);
|
Locale currentLocale = SelectedLocale.getCurrentLocale(vreq);
|
||||||
for (Locale locale : selectables) {
|
for (Locale locale : locales) {
|
||||||
try {
|
try {
|
||||||
list.add(buildLocaleMap(locale, currentLocale));
|
list.add(buildLocaleMap(locale, currentLocale));
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
log.warn("Can't show the Locale selector for '" + locale
|
log.warn("Can't show locale '" + locale + "': " + e);
|
||||||
+ "': " + e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -188,8 +196,8 @@ public class ViewLabelsServlet extends FreemarkerHttpServlet{
|
||||||
|
|
||||||
ArrayList<Literal> labels = new ArrayList<Literal>();
|
ArrayList<Literal> labels = new ArrayList<Literal>();
|
||||||
try {
|
try {
|
||||||
//We want to get the labels for all the languages, not just the display language
|
// Show only labels with current language filtering
|
||||||
ResultSet results = QueryUtils.getLanguageNeutralQueryResults(queryStr, vreq);
|
ResultSet results = QueryUtils.getQueryResults(queryStr, vreq);
|
||||||
while (results.hasNext()) {
|
while (results.hasNext()) {
|
||||||
QuerySolution soln = results.nextSolution();
|
QuerySolution soln = results.nextSolution();
|
||||||
Literal nodeLiteral = soln.get("label").asLiteral();
|
Literal nodeLiteral = soln.get("label").asLiteral();
|
||||||
|
|
|
@ -6,14 +6,13 @@ import java.io.IOException;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.apache.jena.rdf.model.RDFNode;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.IndividualTemplateModelBuilder;
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
import org.apache.jena.query.QuerySolution;
|
import org.apache.jena.query.QuerySolution;
|
||||||
import org.apache.jena.query.ResultSet;
|
import org.apache.jena.query.ResultSet;
|
||||||
|
|
||||||
|
@ -36,6 +35,7 @@ import edu.cornell.mannlib.vitro.webapp.i18n.selection.SelectedLocale;
|
||||||
import edu.cornell.mannlib.vitro.webapp.utils.dataGetter.ExecuteDataRetrieval;
|
import edu.cornell.mannlib.vitro.webapp.utils.dataGetter.ExecuteDataRetrieval;
|
||||||
import edu.cornell.mannlib.vitro.webapp.web.beanswrappers.ReadOnlyBeansWrapper;
|
import edu.cornell.mannlib.vitro.webapp.web.beanswrappers.ReadOnlyBeansWrapper;
|
||||||
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.IndividualTemplateModel;
|
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.IndividualTemplateModel;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.IndividualTemplateModelBuilder;
|
||||||
import edu.ucsf.vitro.opensocial.OpenSocialManager;
|
import edu.ucsf.vitro.opensocial.OpenSocialManager;
|
||||||
import freemarker.ext.beans.BeansWrapper;
|
import freemarker.ext.beans.BeansWrapper;
|
||||||
import freemarker.template.TemplateModel;
|
import freemarker.template.TemplateModel;
|
||||||
|
@ -123,8 +123,10 @@ class IndividualResponseBuilder {
|
||||||
* into the data model: no real data can be modified.
|
* into the data model: no real data can be modified.
|
||||||
*/
|
*/
|
||||||
// body.put("individual", wrap(itm, BeansWrapper.EXPOSE_SAFE));
|
// body.put("individual", wrap(itm, BeansWrapper.EXPOSE_SAFE));
|
||||||
body.put("labelCount", getLabelCount(itm.getUri(), vreq));
|
LabelAndLanguageCount labelAndLanguageCount = getLabelAndLanguageCount(
|
||||||
body.put("languageCount", getLanguagesRepresentedCount(itm.getUri(), vreq));
|
itm.getUri(), vreq);
|
||||||
|
body.put("labelCount", labelAndLanguageCount.getLabelCount());
|
||||||
|
body.put("languageCount", labelAndLanguageCount.getLanguageCount());
|
||||||
//We also need to know the number of available locales
|
//We also need to know the number of available locales
|
||||||
body.put("localesCount", SelectedLocale.getSelectableLocales(vreq).size());
|
body.put("localesCount", SelectedLocale.getSelectableLocales(vreq).size());
|
||||||
body.put("profileType", getProfileType(itm.getUri(), vreq));
|
body.put("profileType", getProfileType(itm.getUri(), vreq));
|
||||||
|
@ -282,61 +284,103 @@ class IndividualResponseBuilder {
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String LABEL_COUNT_QUERY = ""
|
private static String LABEL_QUERY = ""
|
||||||
+ "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n"
|
+ "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n"
|
||||||
+ "SELECT ( str(COUNT(?label)) AS ?labelCount ) WHERE { \n"
|
+ "SELECT ?label WHERE { \n"
|
||||||
+ " ?subject rdfs:label ?label \n"
|
+ " ?subject rdfs:label ?label \n"
|
||||||
+ " FILTER isLiteral(?label) \n"
|
+ " FILTER isLiteral(?label) \n"
|
||||||
+ "}" ;
|
+ "}" ;
|
||||||
|
|
||||||
private static String DISTINCT_LANGUAGE_QUERY = ""
|
// Queries that were previously used for counts via RDFService that didn't
|
||||||
+ "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n"
|
// filter results by language. With language filtering, aggregate
|
||||||
+ "SELECT ( str(COUNT(DISTINCT lang(?label))) AS ?languageCount ) WHERE { \n"
|
// functions like COUNT() cannot be used.
|
||||||
+ " ?subject rdfs:label ?label \n"
|
|
||||||
+ " FILTER isLiteral(?label) \n"
|
|
||||||
+ "}" ;
|
|
||||||
|
|
||||||
private static Integer getLabelCount(String subjectUri, VitroRequest vreq) {
|
// private static String LABEL_COUNT_QUERY = ""
|
||||||
String queryStr = QueryUtils.subUriForQueryVar(LABEL_COUNT_QUERY, "subject", subjectUri);
|
// + "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n"
|
||||||
|
// + "SELECT ( str(COUNT(?label)) AS ?labelCount ) WHERE { \n"
|
||||||
|
// + " ?subject rdfs:label ?label \n"
|
||||||
|
// + " FILTER isLiteral(?label) \n"
|
||||||
|
// + "}" ;
|
||||||
|
|
||||||
|
// private static String DISTINCT_LANGUAGE_QUERY = ""
|
||||||
|
// + "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n"
|
||||||
|
// + "SELECT ( str(COUNT(DISTINCT lang(?label))) AS ?languageCount ) WHERE { \n"
|
||||||
|
// + " ?subject rdfs:label ?label \n"
|
||||||
|
// + " FILTER isLiteral(?label) \n"
|
||||||
|
// + "}" ;
|
||||||
|
|
||||||
|
private static LabelAndLanguageCount getLabelAndLanguageCount(
|
||||||
|
String subjectUri, VitroRequest vreq) {
|
||||||
|
// 1.12.0 Now filtering to only the labels for the current locale so as
|
||||||
|
// to be consistent with other editing forms. Because the language
|
||||||
|
// filter can only act on a result set containing actual literals,
|
||||||
|
// we can't do the counting with a COUNT() in the query itself. So
|
||||||
|
// we will now use the LABEL_QUERY instead of LABEL_COUNT_QUERY and
|
||||||
|
// count the rows and the number of distinct languages represented.
|
||||||
|
Set<String> distinctLanguages = new HashSet<String>();
|
||||||
|
String queryStr = QueryUtils.subUriForQueryVar(LABEL_QUERY, "subject", subjectUri);
|
||||||
log.debug("queryStr = " + queryStr);
|
log.debug("queryStr = " + queryStr);
|
||||||
int theCount = 0;
|
int labelCount = 0;
|
||||||
try {
|
try {
|
||||||
//ResultSet results = QueryUtils.getQueryResults(queryStr, vreq);
|
ResultSet results = QueryUtils.getQueryResults(queryStr, vreq);
|
||||||
//Get query results across all languages in order for template to show manage labels link correctly
|
while(results.hasNext()) {
|
||||||
ResultSet results = QueryUtils.getLanguageNeutralQueryResults(queryStr, vreq);
|
QuerySolution qsoln = results.next();
|
||||||
if (results.hasNext()) {
|
labelCount++;
|
||||||
QuerySolution soln = results.nextSolution();
|
String lang = qsoln.getLiteral("label").getLanguage();
|
||||||
RDFNode labelCount = soln.get("labelCount");
|
if(lang == null) {
|
||||||
if (labelCount != null && labelCount.isLiteral()) {
|
lang = "";
|
||||||
theCount = labelCount.asLiteral().getInt();
|
|
||||||
}
|
}
|
||||||
|
distinctLanguages.add(lang);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error(e, e);
|
log.error(e, e);
|
||||||
}
|
}
|
||||||
return theCount;
|
return new LabelAndLanguageCount(labelCount, distinctLanguages.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class LabelAndLanguageCount {
|
||||||
|
|
||||||
|
private Integer labelCount;
|
||||||
|
private Integer languageCount;
|
||||||
|
|
||||||
|
public LabelAndLanguageCount(Integer labelCount, Integer languageCount) {
|
||||||
|
this.labelCount = labelCount;
|
||||||
|
this.languageCount = languageCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getLabelCount() {
|
||||||
|
return this.labelCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getLanguageCount() {
|
||||||
|
return this.languageCount;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//what is the number of languages represented across the labels
|
//what is the number of languages represented across the labels
|
||||||
private static Integer getLanguagesRepresentedCount(String subjectUri, VitroRequest vreq) {
|
// This version not compatible with language-filtering RDF services
|
||||||
String queryStr = QueryUtils.subUriForQueryVar(DISTINCT_LANGUAGE_QUERY, "subject", subjectUri);
|
// private static Integer getLanguagesRepresentedCount(String subjectUri, VitroRequest vreq) {
|
||||||
log.debug("queryStr = " + queryStr);
|
// String queryStr = QueryUtils.subUriForQueryVar(DISTINCT_LANGUAGE_QUERY, "subject", subjectUri);
|
||||||
int theCount = 0;
|
// log.debug("queryStr = " + queryStr);
|
||||||
try {
|
// int theCount = 0;
|
||||||
|
// try {
|
||||||
ResultSet results = QueryUtils.getLanguageNeutralQueryResults(queryStr, vreq);
|
//
|
||||||
if (results.hasNext()) {
|
// ResultSet results = QueryUtils.getLanguageNeutralQueryResults(queryStr, vreq);
|
||||||
QuerySolution soln = results.nextSolution();
|
// if (results.hasNext()) {
|
||||||
RDFNode languageCount = soln.get("languageCount");
|
// QuerySolution soln = results.nextSolution();
|
||||||
if (languageCount != null && languageCount.isLiteral()) {
|
// RDFNode languageCount = soln.get("languageCount");
|
||||||
theCount = languageCount.asLiteral().getInt();
|
// if (languageCount != null && languageCount.isLiteral()) {
|
||||||
}
|
// theCount = languageCount.asLiteral().getInt();
|
||||||
}
|
// log.info("Language count is " + theCount);
|
||||||
} catch (Exception e) {
|
// }
|
||||||
log.error(e, e);
|
// }
|
||||||
}
|
// } catch (Exception e) {
|
||||||
return theCount;
|
// log.error(e, e);
|
||||||
}
|
// }
|
||||||
|
// log.info("Returning language count " + theCount);
|
||||||
|
// return theCount;
|
||||||
|
// }
|
||||||
|
|
||||||
private static String PROFILE_TYPE_QUERY = ""
|
private static String PROFILE_TYPE_QUERY = ""
|
||||||
+ "PREFIX display: <http://vitro.mannlib.cornell.edu/ontologies/display/1.1#> \n"
|
+ "PREFIX display: <http://vitro.mannlib.cornell.edu/ontologies/display/1.1#> \n"
|
||||||
|
|
|
@ -4,6 +4,7 @@ package edu.cornell.mannlib.vitro.webapp.controller.json;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||||
|
@ -15,6 +16,7 @@ import org.apache.commons.logging.LogFactory;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao;
|
import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.i18n.selection.SelectedLocale;
|
||||||
import edu.cornell.mannlib.vitro.webapp.services.shortview.ShortViewService;
|
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.ShortViewService.ShortViewContext;
|
||||||
import edu.cornell.mannlib.vitro.webapp.services.shortview.ShortViewServiceSetup;
|
import edu.cornell.mannlib.vitro.webapp.services.shortview.ShortViewServiceSetup;
|
||||||
|
@ -73,7 +75,11 @@ public class GetRandomSearchIndividualsByVClass extends GetSearchIndividualsByVC
|
||||||
modelMap.put("individual",
|
modelMap.put("individual",
|
||||||
IndividualTemplateModelBuilder.build(individual, vreq));
|
IndividualTemplateModelBuilder.build(individual, vreq));
|
||||||
modelMap.put("vclass", vclassName);
|
modelMap.put("vclass", vclassName);
|
||||||
|
String langCtx = vreq.getLocale().getLanguage(); //UQAM-Linguistic-Management build the linguistic context
|
||||||
|
if (!vreq.getLocale().getCountry().isEmpty()) {
|
||||||
|
langCtx += "-" + vreq.getLocale().getCountry();
|
||||||
|
}
|
||||||
|
modelMap.put("langCtx", langCtx); // UQAM-Linguistic-Management add the linguistic context to map
|
||||||
ShortViewService svs = ShortViewServiceSetup.getService(ctx);
|
ShortViewService svs = ShortViewServiceSetup.getService(ctx);
|
||||||
return svs.renderShortView(individual, ShortViewContext.BROWSE,
|
return svs.renderShortView(individual, ShortViewContext.BROWSE,
|
||||||
modelMap, vreq);
|
modelMap, vreq);
|
||||||
|
|
|
@ -155,6 +155,7 @@ public class VitroVocabulary {
|
||||||
public static final String USERACCOUNT_LAST_LOGIN_TIME = VITRO_AUTH + "lastLoginTime";
|
public static final String USERACCOUNT_LAST_LOGIN_TIME = VITRO_AUTH + "lastLoginTime";
|
||||||
public static final String USERACCOUNT_STATUS = VITRO_AUTH + "status";
|
public static final String USERACCOUNT_STATUS = VITRO_AUTH + "status";
|
||||||
public static final String USERACCOUNT_PASSWORD_LINK_EXPIRES = VITRO_AUTH + "passwordLinkExpires";
|
public static final String USERACCOUNT_PASSWORD_LINK_EXPIRES = VITRO_AUTH + "passwordLinkExpires";
|
||||||
|
public static final String USERACCOUNT_EMAIL_KEY = VITRO_AUTH + "emailKey";
|
||||||
public static final String USERACCOUNT_PASSWORD_CHANGE_REQUIRED = VITRO_AUTH + "passwordChangeRequired";
|
public static final String USERACCOUNT_PASSWORD_CHANGE_REQUIRED = VITRO_AUTH + "passwordChangeRequired";
|
||||||
public static final String USERACCOUNT_EXTERNAL_AUTH_ID = VITRO_AUTH + "externalAuthId";
|
public static final String USERACCOUNT_EXTERNAL_AUTH_ID = VITRO_AUTH + "externalAuthId";
|
||||||
public static final String USERACCOUNT_EXTERNAL_AUTH_ONLY = VITRO_AUTH + "externalAuthOnly";
|
public static final String USERACCOUNT_EXTERNAL_AUTH_ONLY = VITRO_AUTH + "externalAuthOnly";
|
||||||
|
@ -233,6 +234,9 @@ public class VitroVocabulary {
|
||||||
public static final String IND_MAIN_IMAGE = VITRO_PUBLIC + "mainImage";
|
public static final String IND_MAIN_IMAGE = VITRO_PUBLIC + "mainImage";
|
||||||
public static final String IND_IMAGE = VITRO_PUBLIC + "image";
|
public static final String IND_IMAGE = VITRO_PUBLIC + "image";
|
||||||
|
|
||||||
|
public static final String STORED_FILE = VITRO_PUBLIC + "storedFile";
|
||||||
|
public static final String PUBLIC_FILENAME = VITRO_PUBLIC + "publicFilename";
|
||||||
|
|
||||||
// =============== Date Time with Precision vocabulary ===============
|
// =============== Date Time with Precision vocabulary ===============
|
||||||
private static final String DATETIME_NS = "http://vivoweb.org/ontology/core#";
|
private static final String DATETIME_NS = "http://vivoweb.org/ontology/core#";
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,8 @@ package edu.cornell.mannlib.vitro.webapp.dao;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.i18n.I18nBundle;
|
||||||
|
|
||||||
public interface WebappDaoFactory {
|
public interface WebappDaoFactory {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -132,4 +134,6 @@ public interface WebappDaoFactory {
|
||||||
|
|
||||||
public MenuDao getMenuDao();
|
public MenuDao getMenuDao();
|
||||||
|
|
||||||
|
public I18nBundle getI18nBundle();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,14 +5,17 @@ package edu.cornell.mannlib.vitro.webapp.dao;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.PropertyDao.FullPropertyKey;
|
import edu.cornell.mannlib.vitro.webapp.dao.PropertyDao.FullPropertyKey;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.filter.LanguageFilteringUtils;
|
||||||
|
|
||||||
public class WebappDaoFactoryConfig {
|
public class WebappDaoFactoryConfig {
|
||||||
|
|
||||||
private List<String> preferredLanguages;
|
private List<String> preferredLanguages;
|
||||||
|
private List<Locale> preferredLocales;
|
||||||
private String defaultNamespace;
|
private String defaultNamespace;
|
||||||
private Set<String> nonUserNamespaces;
|
private Set<String> nonUserNamespaces;
|
||||||
private boolean isUnderlyingStoreReasoned = false;
|
private boolean isUnderlyingStoreReasoned = false;
|
||||||
|
@ -20,6 +23,7 @@ public class WebappDaoFactoryConfig {
|
||||||
|
|
||||||
public WebappDaoFactoryConfig() {
|
public WebappDaoFactoryConfig() {
|
||||||
preferredLanguages = Arrays.asList("en-US", "en", "EN");
|
preferredLanguages = Arrays.asList("en-US", "en", "EN");
|
||||||
|
preferredLocales = LanguageFilteringUtils.languagesToLocales(preferredLanguages);
|
||||||
defaultNamespace = "http://vitro.mannlib.cornell.edu/ns/default#";
|
defaultNamespace = "http://vitro.mannlib.cornell.edu/ns/default#";
|
||||||
nonUserNamespaces = new HashSet<String>();
|
nonUserNamespaces = new HashSet<String>();
|
||||||
nonUserNamespaces.add(VitroVocabulary.vitroURI);
|
nonUserNamespaces.add(VitroVocabulary.vitroURI);
|
||||||
|
@ -33,6 +37,14 @@ public class WebappDaoFactoryConfig {
|
||||||
this.preferredLanguages = pl;
|
this.preferredLanguages = pl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Locale> getPreferredLocales() {
|
||||||
|
return this.preferredLocales;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPreferredLocales(List<Locale> pl) {
|
||||||
|
this.preferredLocales = pl;
|
||||||
|
}
|
||||||
|
|
||||||
public String getDefaultNamespace() {
|
public String getDefaultNamespace() {
|
||||||
return defaultNamespace;
|
return defaultNamespace;
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyDao;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.InsertException;
|
import edu.cornell.mannlib.vitro.webapp.dao.InsertException;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.VitroFilters;
|
import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.VitroFilters;
|
||||||
|
|
||||||
class DataPropertyDaoFiltering extends BaseFiltering implements DataPropertyDao{
|
public class DataPropertyDaoFiltering extends BaseFiltering implements DataPropertyDao{
|
||||||
final DataPropertyDao innerDataPropertyDao;
|
final DataPropertyDao innerDataPropertyDao;
|
||||||
final VitroFilters filters;
|
final VitroFilters filters;
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyStatementDao;
|
import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyStatementDao;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.VitroFilters;
|
import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.VitroFilters;
|
||||||
|
|
||||||
class DataPropertyStatementDaoFiltering extends BaseFiltering implements DataPropertyStatementDao{
|
public class DataPropertyStatementDaoFiltering extends BaseFiltering implements DataPropertyStatementDao{
|
||||||
|
|
||||||
final DataPropertyStatementDao innerDataPropertyStatementDao;
|
final DataPropertyStatementDao innerDataPropertyStatementDao;
|
||||||
final VitroFilters filters;
|
final VitroFilters filters;
|
||||||
|
|
|
@ -26,47 +26,34 @@ public class FauxPropertyDaoFiltering extends BaseFiltering implements FauxPrope
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<FauxProperty> getFauxPropertiesForBaseUri(String uri) {
|
public List<FauxProperty> getFauxPropertiesForBaseUri(String uri) {
|
||||||
// TODO Auto-generated method stub
|
return innerFauxPropertyDao.getFauxPropertiesForBaseUri(uri);
|
||||||
throw new RuntimeException(
|
|
||||||
"FauxPropertyDao.getFauxPropertiesForBaseUri() not implemented.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FauxProperty getFauxPropertyFromContextUri(String contextUri) {
|
public FauxProperty getFauxPropertyFromContextUri(String contextUri) {
|
||||||
// TODO Auto-generated method stub
|
return innerFauxPropertyDao.getFauxPropertyFromContextUri(contextUri);
|
||||||
throw new RuntimeException(
|
|
||||||
"FauxPropertyDaoFiltering.getFauxPropertyFromConfigContextUri() not implemented.");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FauxProperty getFauxPropertyByUris(String domainUri, String baseUri,
|
public FauxProperty getFauxPropertyByUris(String domainUri, String baseUri,
|
||||||
String rangeUri) {
|
String rangeUri) {
|
||||||
// TODO Auto-generated method stub
|
return innerFauxPropertyDao.getFauxPropertyByUris(domainUri, baseUri,
|
||||||
throw new RuntimeException(
|
rangeUri);
|
||||||
"FauxPropertyDaoFiltering.getFauxPropertyByUris() not implemented.");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateFauxProperty(FauxProperty fp) {
|
public void updateFauxProperty(FauxProperty fp) {
|
||||||
// TODO Auto-generated method stub
|
innerFauxPropertyDao.updateFauxProperty(fp);
|
||||||
throw new RuntimeException("FauxPropertyDaoFiltering.updateFauxProperty() not implemented.");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void deleteFauxProperty(FauxProperty fp) {
|
public void deleteFauxProperty(FauxProperty fp) {
|
||||||
// TODO Auto-generated method stub
|
innerFauxPropertyDao.deleteFauxProperty(fp);
|
||||||
throw new RuntimeException("FauxPropertyDao.deleteFauxProperty() not implemented.");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void insertFauxProperty(FauxProperty fp) {
|
public void insertFauxProperty(FauxProperty fp) {
|
||||||
// TODO Auto-generated method stub
|
innerFauxPropertyDao.insertFauxProperty(fp);
|
||||||
throw new RuntimeException("FauxPropertyDao.insertFauxProperty() not implemented.");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.VitroFilters;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.EditLiteral;
|
import edu.cornell.mannlib.vitro.webapp.edit.EditLiteral;
|
||||||
|
|
||||||
|
|
||||||
class IndividualDaoFiltering extends BaseFiltering implements IndividualDao{
|
public class IndividualDaoFiltering extends BaseFiltering implements IndividualDao{
|
||||||
IndividualDao innerIndividualDao;
|
IndividualDao innerIndividualDao;
|
||||||
VitroFilters filters;
|
VitroFilters filters;
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ import edu.cornell.mannlib.vitro.webapp.dao.InsertException;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.ObjectPropertyDao;
|
import edu.cornell.mannlib.vitro.webapp.dao.ObjectPropertyDao;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.VitroFilters;
|
import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.VitroFilters;
|
||||||
|
|
||||||
class ObjectPropertyDaoFiltering extends BaseFiltering implements ObjectPropertyDao{
|
public class ObjectPropertyDaoFiltering extends BaseFiltering implements ObjectPropertyDao{
|
||||||
final ObjectPropertyDao innerObjectPropertyDao;
|
final ObjectPropertyDao innerObjectPropertyDao;
|
||||||
final VitroFilters filters;
|
final VitroFilters filters;
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatementImpl;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.ObjectPropertyStatementDao;
|
import edu.cornell.mannlib.vitro.webapp.dao.ObjectPropertyStatementDao;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.VitroFilters;
|
import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.VitroFilters;
|
||||||
|
|
||||||
class ObjectPropertyStatementDaoFiltering extends BaseFiltering implements ObjectPropertyStatementDao{
|
public class ObjectPropertyStatementDaoFiltering extends BaseFiltering implements ObjectPropertyStatementDao{
|
||||||
final ObjectPropertyStatementDao innerObjectPropertyStatementDao;
|
final ObjectPropertyStatementDao innerObjectPropertyStatementDao;
|
||||||
final VitroFilters filters;
|
final VitroFilters filters;
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@ import edu.cornell.mannlib.vitro.webapp.dao.VClassDao;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.VClassGroupDao;
|
import edu.cornell.mannlib.vitro.webapp.dao.VClassGroupDao;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.VitroFilters;
|
import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.VitroFilters;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.i18n.I18nBundle;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This wraps a WebappDaoFactory and applies filtering.
|
* This wraps a WebappDaoFactory and applies filtering.
|
||||||
|
@ -276,4 +277,9 @@ public class WebappDaoFactoryFiltering implements WebappDaoFactory {
|
||||||
public void close() {
|
public void close() {
|
||||||
innerWebappDaoFactory.close();
|
innerWebappDaoFactory.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public I18nBundle getI18nBundle() {
|
||||||
|
return innerWebappDaoFactory.getI18nBundle();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,22 +83,21 @@ public class ApplicationDaoJena extends JenaBaseDao implements ApplicationDao {
|
||||||
}
|
}
|
||||||
ontModel.enterCriticalSection(Lock.WRITE);
|
ontModel.enterCriticalSection(Lock.WRITE);
|
||||||
try {
|
try {
|
||||||
appInd.setLabel(application.getApplicationName(), null);
|
updateRDFSLabel(appInd, application.getApplicationName());
|
||||||
updatePropertyStringValue(
|
updatePlainLiteralValue(
|
||||||
appInd, APPLICATION_ABOUTTEXT, application.getAboutText(),
|
appInd, APPLICATION_ABOUTTEXT, application.getAboutText());
|
||||||
ontModel);
|
updatePlainLiteralValue(
|
||||||
updatePropertyStringValue(
|
|
||||||
appInd, APPLICATION_ACKNOWLEGETEXT,
|
appInd, APPLICATION_ACKNOWLEGETEXT,
|
||||||
application.getAcknowledgeText(), ontModel);
|
application.getAcknowledgeText());
|
||||||
updatePropertyStringValue(
|
updatePropertyStringValue(
|
||||||
appInd, APPLICATION_CONTACTMAIL,
|
appInd, APPLICATION_CONTACTMAIL,
|
||||||
application.getContactMail(), ontModel);
|
application.getContactMail(), ontModel);
|
||||||
updatePropertyStringValue(
|
updatePropertyStringValue(
|
||||||
appInd, APPLICATION_CORRECTIONMAIL,
|
appInd, APPLICATION_CORRECTIONMAIL,
|
||||||
application.getCorrectionMail(), ontModel);
|
application.getCorrectionMail(), ontModel);
|
||||||
updatePropertyStringValue(
|
updatePlainLiteralValue(
|
||||||
appInd, APPLICATION_COPYRIGHTANCHOR,
|
appInd, APPLICATION_COPYRIGHTANCHOR,
|
||||||
application.getCopyrightAnchor(), ontModel);
|
application.getCopyrightAnchor());
|
||||||
updatePropertyStringValue(
|
updatePropertyStringValue(
|
||||||
appInd, APPLICATION_COPYRIGHTURL,
|
appInd, APPLICATION_COPYRIGHTURL,
|
||||||
application.getCopyrightURL(), ontModel);
|
application.getCopyrightURL(), ontModel);
|
||||||
|
|
|
@ -516,9 +516,9 @@ public class DataPropertyDaoJena extends PropertyDaoJena implements
|
||||||
if (dtp.getFunctional()) {
|
if (dtp.getFunctional()) {
|
||||||
ontModel.add(jDataprop,RDF.type,OWL.FunctionalProperty);
|
ontModel.add(jDataprop,RDF.type,OWL.FunctionalProperty);
|
||||||
}
|
}
|
||||||
addPropertyStringValue(jDataprop, EXAMPLE, dtp.getExample(), ontModel);
|
updatePlainLiteralValue(jDataprop, EXAMPLE, dtp.getExample());
|
||||||
addPropertyStringValue(jDataprop, DESCRIPTION_ANNOT, dtp.getDescription(), ontModel);
|
updatePlainLiteralValue(jDataprop, DESCRIPTION_ANNOT, dtp.getDescription());
|
||||||
addPropertyStringValue(jDataprop, PUBLIC_DESCRIPTION_ANNOT, dtp.getPublicDescription(), ontModel);
|
updatePlainLiteralValue(jDataprop, PUBLIC_DESCRIPTION_ANNOT, dtp.getPublicDescription());
|
||||||
addPropertyStringValue(jDataprop, EDITING, dtp.getEditing(), ontModel);
|
addPropertyStringValue(jDataprop, EDITING, dtp.getEditing(), ontModel);
|
||||||
addPropertyNonNegativeIntValue(jDataprop, DISPLAY_RANK_ANNOT, dtp.getDisplayTier(), ontModel);
|
addPropertyNonNegativeIntValue(jDataprop, DISPLAY_RANK_ANNOT, dtp.getDisplayTier(), ontModel);
|
||||||
addPropertyNonNegativeIntValue(jDataprop, DISPLAY_LIMIT, dtp.getDisplayLimit(), ontModel);
|
addPropertyNonNegativeIntValue(jDataprop, DISPLAY_LIMIT, dtp.getDisplayLimit(), ontModel);
|
||||||
|
@ -587,9 +587,9 @@ public class DataPropertyDaoJena extends PropertyDaoJena implements
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
updatePropertyStringValue(jDataprop, EXAMPLE, dtp.getExample(), ontModel);
|
updatePlainLiteralValue(jDataprop, EXAMPLE, dtp.getExample());
|
||||||
updatePropertyStringValue(jDataprop, DESCRIPTION_ANNOT, dtp.getDescription(), ontModel);
|
updatePlainLiteralValue(jDataprop, DESCRIPTION_ANNOT, dtp.getDescription());
|
||||||
updatePropertyStringValue(jDataprop, PUBLIC_DESCRIPTION_ANNOT, dtp.getPublicDescription(), ontModel);
|
updatePlainLiteralValue(jDataprop, PUBLIC_DESCRIPTION_ANNOT, dtp.getPublicDescription());
|
||||||
updatePropertyStringValue(jDataprop, EDITING, dtp.getEditing(), ontModel);
|
updatePropertyStringValue(jDataprop, EDITING, dtp.getEditing(), ontModel);
|
||||||
updatePropertyNonNegativeIntValue(jDataprop, DISPLAY_RANK_ANNOT, dtp.getDisplayTier(), ontModel);
|
updatePropertyNonNegativeIntValue(jDataprop, DISPLAY_RANK_ANNOT, dtp.getDisplayTier(), ontModel);
|
||||||
updatePropertyNonNegativeIntValue(jDataprop, DISPLAY_LIMIT, dtp.getDisplayLimit(), ontModel);
|
updatePropertyNonNegativeIntValue(jDataprop, DISPLAY_LIMIT, dtp.getDisplayLimit(), ontModel);
|
||||||
|
|
|
@ -230,10 +230,9 @@ public class FauxPropertyDaoJena extends JenaBaseDao implements FauxPropertyDao
|
||||||
OBJECT_PROPERTY_DISPLAY_CONFIG);
|
OBJECT_PROPERTY_DISPLAY_CONFIG);
|
||||||
addPropertyResourceURINotEmpty(config, PROPERTY_GROUP,
|
addPropertyResourceURINotEmpty(config, PROPERTY_GROUP,
|
||||||
fp.getGroupURI());
|
fp.getGroupURI());
|
||||||
addPropertyStringValue(config, DISPLAY_NAME, fp.getDisplayName(),
|
updatePlainLiteralValue(config, DISPLAY_NAME, fp.getDisplayName());
|
||||||
displayModel);
|
updatePlainLiteralValue(config, PUBLIC_DESCRIPTION_ANNOT,
|
||||||
addPropertyStringValue(config, PUBLIC_DESCRIPTION_ANNOT,
|
fp.getPublicDescription());
|
||||||
fp.getPublicDescription(), displayModel);
|
|
||||||
addPropertyIntValue(config, DISPLAY_RANK_ANNOT,
|
addPropertyIntValue(config, DISPLAY_RANK_ANNOT,
|
||||||
fp.getDisplayTier(), displayModel);
|
fp.getDisplayTier(), displayModel);
|
||||||
addPropertyIntValue(config, DISPLAY_LIMIT, fp.getDisplayLimit(),
|
addPropertyIntValue(config, DISPLAY_LIMIT, fp.getDisplayLimit(),
|
||||||
|
@ -328,10 +327,10 @@ public class FauxPropertyDaoJena extends JenaBaseDao implements FauxPropertyDao
|
||||||
.getConfigUri());
|
.getConfigUri());
|
||||||
updatePropertyResourceURIValue(config, PROPERTY_GROUP,
|
updatePropertyResourceURIValue(config, PROPERTY_GROUP,
|
||||||
fp.getGroupURI());
|
fp.getGroupURI());
|
||||||
updatePropertyStringValue(config, DISPLAY_NAME,
|
updatePlainLiteralValue(config, DISPLAY_NAME,
|
||||||
fp.getDisplayName(), displayModel);
|
fp.getDisplayName());
|
||||||
updatePropertyStringValue(config, PUBLIC_DESCRIPTION_ANNOT,
|
updatePlainLiteralValue(config, PUBLIC_DESCRIPTION_ANNOT,
|
||||||
fp.getPublicDescription(), displayModel);
|
fp.getPublicDescription());
|
||||||
updatePropertyIntValue(config, DISPLAY_RANK_ANNOT,
|
updatePropertyIntValue(config, DISPLAY_RANK_ANNOT,
|
||||||
fp.getDisplayTier(), displayModel);
|
fp.getDisplayTier(), displayModel);
|
||||||
updatePropertyIntValue(config, DISPLAY_LIMIT, fp.getDisplayLimit(),
|
updatePropertyIntValue(config, DISPLAY_LIMIT, fp.getDisplayLimit(),
|
||||||
|
|
|
@ -5,8 +5,8 @@ package edu.cornell.mannlib.vitro.webapp.dao.jena;
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
@ -14,14 +14,14 @@ import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.apache.jena.iri.IRI;
|
|
||||||
import org.apache.jena.iri.IRIFactory;
|
|
||||||
|
|
||||||
import org.apache.jena.datatypes.xsd.XSDDatatype;
|
import org.apache.jena.datatypes.xsd.XSDDatatype;
|
||||||
import org.apache.jena.graph.Node;
|
import org.apache.jena.graph.Node;
|
||||||
import org.apache.jena.graph.NodeFactory;
|
import org.apache.jena.graph.NodeFactory;
|
||||||
|
import org.apache.jena.iri.IRI;
|
||||||
|
import org.apache.jena.iri.IRIFactory;
|
||||||
import org.apache.jena.ontology.DatatypeProperty;
|
import org.apache.jena.ontology.DatatypeProperty;
|
||||||
import org.apache.jena.ontology.ObjectProperty;
|
import org.apache.jena.ontology.ObjectProperty;
|
||||||
import org.apache.jena.ontology.OntClass;
|
import org.apache.jena.ontology.OntClass;
|
||||||
|
@ -39,6 +39,7 @@ import org.apache.jena.rdf.model.NodeIterator;
|
||||||
import org.apache.jena.rdf.model.Property;
|
import org.apache.jena.rdf.model.Property;
|
||||||
import org.apache.jena.rdf.model.RDFNode;
|
import org.apache.jena.rdf.model.RDFNode;
|
||||||
import org.apache.jena.rdf.model.Resource;
|
import org.apache.jena.rdf.model.Resource;
|
||||||
|
import org.apache.jena.rdf.model.ResourceFactory;
|
||||||
import org.apache.jena.rdf.model.Statement;
|
import org.apache.jena.rdf.model.Statement;
|
||||||
import org.apache.jena.rdf.model.StmtIterator;
|
import org.apache.jena.rdf.model.StmtIterator;
|
||||||
import org.apache.jena.shared.Lock;
|
import org.apache.jena.shared.Lock;
|
||||||
|
@ -754,21 +755,110 @@ public class JenaBaseDao extends JenaBaseDaoCon {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* convenience method for updating the RDFS label
|
* Add to an OntResource an rdfs:label value with lexical form and default
|
||||||
|
* language tag. Remove any other existing values in default language.
|
||||||
|
* If lexicalForm parameter is null, remove all plain literal values of
|
||||||
|
* Property in default language.
|
||||||
|
* @param ontRes may not be null
|
||||||
|
* @param lexicalForm may be null. If null, existing values will be deleted
|
||||||
|
* but none will be added.
|
||||||
*/
|
*/
|
||||||
protected void updateRDFSLabel(OntResource ontRes, String label) {
|
protected void updateRDFSLabel(OntResource ontRes, String lexicalForm) {
|
||||||
|
updatePlainLiteralValue(ontRes, RDFS.label, lexicalForm);
|
||||||
if (label != null && label.length() > 0) {
|
|
||||||
|
|
||||||
String existingValue = ontRes.getLabel(getDefaultLanguage());
|
|
||||||
|
|
||||||
if (existingValue == null || !existingValue.equals(label)) {
|
|
||||||
ontRes.setLabel(label, getDefaultLanguage());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add to an OntResource an rdfs:label value with lexical form and optional
|
||||||
|
* language tag. Remove any other existing plain literal values that match
|
||||||
|
* specified language or lack language tags if no language is supplied.
|
||||||
|
* If lexicalForm parameter is null, remove all plain literal labels in
|
||||||
|
* specified language, or all existing language-less labels
|
||||||
|
* if no language is specified.
|
||||||
|
* @param ontRes may not be null
|
||||||
|
* @param lexicalForm may be null. If null, existing values will be deleted
|
||||||
|
* but none will be added.
|
||||||
|
* @param lang may be null. If null, method acts on language-less plain
|
||||||
|
* literal labels and ignores those with language tags.
|
||||||
|
*/
|
||||||
|
protected void updateRDFSLabel(OntResource ontRes, String lexicalForm, String lang) {
|
||||||
|
updatePlainLiteralValue(ontRes, RDFS.label, lexicalForm, lang);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add to an OntResource a Property value with lexical form and default
|
||||||
|
* language tag. Remove any other existing values in default language.
|
||||||
|
* If lexicalForm parameter is null, remove all plain literal values of
|
||||||
|
* Property in default language.
|
||||||
|
* @param ontRes may not be null
|
||||||
|
* @param lexicalForm may be null. If null, existing values will be deleted
|
||||||
|
* but none will be added.
|
||||||
|
*/
|
||||||
|
protected void updatePlainLiteralValue(OntResource ontRes, Property property,
|
||||||
|
String lexicalForm) {
|
||||||
|
updatePlainLiteralValue(ontRes, property, lexicalForm, getDefaultLanguage());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add to an OntResource a Property value with lexical form and optional
|
||||||
|
* language tag. Remove any other existing plain literal values that match
|
||||||
|
* specified language or lack language tags if no language is supplied.
|
||||||
|
* If lexicalForm parameter is null, remove all plain literal values of
|
||||||
|
* Property in specified language, or all existing language-less literals
|
||||||
|
* if no language is specified.
|
||||||
|
* @param ontRes may not be null
|
||||||
|
* @param lexicalForm may be null. If null, existing values will be deleted
|
||||||
|
* but none will be added.
|
||||||
|
* @param lang may be null. If null, method acts on language-less
|
||||||
|
* plain literal values and ignores those with language tags.
|
||||||
|
*/
|
||||||
|
protected void updatePlainLiteralValue(OntResource ontRes, Property property,
|
||||||
|
String lexicalForm, String lang) {
|
||||||
|
if(ontRes == null) {
|
||||||
|
throw new IllegalArgumentException("ontRes may not be null.");
|
||||||
|
}
|
||||||
|
boolean addNew = true;
|
||||||
|
List<Statement> toRemove = new ArrayList<Statement>();
|
||||||
|
StmtIterator existingStmts = ontRes.listProperties(property);
|
||||||
|
while(existingStmts.hasNext()) {
|
||||||
|
Statement stmt = existingStmts.next();
|
||||||
|
if(stmt.getObject().isLiteral()) {
|
||||||
|
Literal lit = stmt.getObject().asLiteral();
|
||||||
|
if( (lang == null && isLanguageLessPlainLiteral(lit))
|
||||||
|
|| (lang != null && lang.equals(lit.getLanguage())) ) {
|
||||||
|
if(!lit.getLexicalForm().equals(lexicalForm)) {
|
||||||
|
toRemove.add(stmt);
|
||||||
} else {
|
} else {
|
||||||
ontRes.removeAll(RDFS.label);
|
// New literal already exists in the model.
|
||||||
|
// Do not add it again.
|
||||||
|
addNew = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(!toRemove.isEmpty()) {
|
||||||
|
ontRes.getModel().remove(toRemove);
|
||||||
|
}
|
||||||
|
if (addNew && (lexicalForm != null)) {
|
||||||
|
if(!StringUtils.isEmpty(lang)) {
|
||||||
|
ontRes.addProperty(property, ResourceFactory.createLangLiteral(
|
||||||
|
lexicalForm, lang));
|
||||||
|
} else {
|
||||||
|
ontRes.addProperty(property, ResourceFactory.createPlainLiteral(
|
||||||
|
lexicalForm));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isLanguageLessPlainLiteral(Literal lit) {
|
||||||
|
// In RDF 1.1 all the language-less literals get datatype xsd:string.
|
||||||
|
// The null datatype check is here just in case this gets run on an older
|
||||||
|
// version of Jena. rdf:PlainLiteral is also a datatype, but doesn't
|
||||||
|
// (yet) seem to be used by Jena.
|
||||||
|
return StringUtils.isEmpty(lit.getLanguage())
|
||||||
|
&& ((lit.getDatatype() == null)
|
||||||
|
|| XSDDatatype.XSDstring.equals(lit.getDatatype()) ||
|
||||||
|
(RDF.getURI() + "PlainLiteral").equals(lit.getDatatypeURI()));
|
||||||
|
}
|
||||||
|
|
||||||
private Literal getLabel(String lang, List<RDFNode>labelList) {
|
private Literal getLabel(String lang, List<RDFNode>labelList) {
|
||||||
for (RDFNode label : labelList) {
|
for (RDFNode label : labelList) {
|
||||||
|
@ -780,6 +870,13 @@ public class JenaBaseDao extends JenaBaseDaoCon {
|
||||||
}
|
}
|
||||||
if ((lang != null) && (lang.equals(labelLanguage))) {
|
if ((lang != null) && (lang.equals(labelLanguage))) {
|
||||||
return labelLit;
|
return labelLit;
|
||||||
|
} else
|
||||||
|
/*
|
||||||
|
* UQAM-Linguistic-Management
|
||||||
|
* Check for country-part of lang (ex: 'en' for default consideration of labelLanguage in english but not encoded by 'en-US' most case of labels in vivo.owl)
|
||||||
|
*/
|
||||||
|
if ((lang != null) && (Arrays.asList(lang.split("-")).get(0).equals(labelLanguage))) {
|
||||||
|
return labelLit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -121,6 +121,7 @@ public class JenaBaseDaoCon {
|
||||||
protected DatatypeProperty USERACCOUNT_LAST_LOGIN_TIME = _constModel.createDatatypeProperty(VitroVocabulary.USERACCOUNT_LAST_LOGIN_TIME);
|
protected DatatypeProperty USERACCOUNT_LAST_LOGIN_TIME = _constModel.createDatatypeProperty(VitroVocabulary.USERACCOUNT_LAST_LOGIN_TIME);
|
||||||
protected DatatypeProperty USERACCOUNT_STATUS = _constModel.createDatatypeProperty(VitroVocabulary.USERACCOUNT_STATUS);
|
protected DatatypeProperty USERACCOUNT_STATUS = _constModel.createDatatypeProperty(VitroVocabulary.USERACCOUNT_STATUS);
|
||||||
protected DatatypeProperty USERACCOUNT_PASSWORD_LINK_EXPIRES = _constModel.createDatatypeProperty(VitroVocabulary.USERACCOUNT_PASSWORD_LINK_EXPIRES);
|
protected DatatypeProperty USERACCOUNT_PASSWORD_LINK_EXPIRES = _constModel.createDatatypeProperty(VitroVocabulary.USERACCOUNT_PASSWORD_LINK_EXPIRES);
|
||||||
|
protected DatatypeProperty USERACCOUNT_EMAIL_KEY = _constModel.createDatatypeProperty(VitroVocabulary.USERACCOUNT_EMAIL_KEY);
|
||||||
protected DatatypeProperty USERACCOUNT_PASSWORD_CHANGE_REQUIRED = _constModel.createDatatypeProperty(VitroVocabulary.USERACCOUNT_PASSWORD_CHANGE_REQUIRED);
|
protected DatatypeProperty USERACCOUNT_PASSWORD_CHANGE_REQUIRED = _constModel.createDatatypeProperty(VitroVocabulary.USERACCOUNT_PASSWORD_CHANGE_REQUIRED);
|
||||||
protected DatatypeProperty USERACCOUNT_EXTERNAL_AUTH_ID = _constModel.createDatatypeProperty(VitroVocabulary.USERACCOUNT_EXTERNAL_AUTH_ID);
|
protected DatatypeProperty USERACCOUNT_EXTERNAL_AUTH_ID = _constModel.createDatatypeProperty(VitroVocabulary.USERACCOUNT_EXTERNAL_AUTH_ID);
|
||||||
protected DatatypeProperty USERACCOUNT_EXTERNAL_AUTH_ONLY = _constModel.createDatatypeProperty(VitroVocabulary.USERACCOUNT_EXTERNAL_AUTH_ONLY);
|
protected DatatypeProperty USERACCOUNT_EXTERNAL_AUTH_ONLY = _constModel.createDatatypeProperty(VitroVocabulary.USERACCOUNT_EXTERNAL_AUTH_ONLY);
|
||||||
|
|
|
@ -72,6 +72,7 @@ public class MenuDaoJena extends JenaBaseDao implements MenuDao {
|
||||||
return getMenu( getOntModelSelector().getDisplayModel(), url );
|
return getMenu( getOntModelSelector().getDisplayModel(), url );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public MainMenu getMainMenu( ServletRequest req, String url ) {
|
public MainMenu getMainMenu( ServletRequest req, String url ) {
|
||||||
OntModel displayModel = LanguageFilteringUtils.wrapOntModelInALanguageFilter(getOntModelSelector().getDisplayModel(), req );
|
OntModel displayModel = LanguageFilteringUtils.wrapOntModelInALanguageFilter(getOntModelSelector().getDisplayModel(), req );
|
||||||
return getMenu(displayModel, url) ;
|
return getMenu(displayModel, url) ;
|
||||||
|
|
|
@ -714,14 +714,14 @@ public class ObjectPropertyDaoJena extends PropertyDaoJena implements ObjectProp
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
updatePropertyStringValue(p,EXAMPLE_ANNOT,prop.getExample(),getOntModel());
|
updatePlainLiteralValue(p, EXAMPLE_ANNOT, prop.getExample());
|
||||||
updatePropertyStringValue(p,DESCRIPTION_ANNOT,prop.getDescription(),getOntModel());
|
updatePlainLiteralValue(p, DESCRIPTION_ANNOT, prop.getDescription());
|
||||||
updatePropertyStringValue(p,PUBLIC_DESCRIPTION_ANNOT,prop.getPublicDescription(),getOntModel());
|
updatePlainLiteralValue(p, PUBLIC_DESCRIPTION_ANNOT, prop.getPublicDescription());
|
||||||
updatePropertyNonNegativeIntegerValue(p,DISPLAY_LIMIT,prop.getDomainDisplayLimitInteger(),getOntModel());
|
updatePropertyNonNegativeIntegerValue(p,DISPLAY_LIMIT,prop.getDomainDisplayLimitInteger(),getOntModel());
|
||||||
updatePropertyStringValue(p,PROPERTY_ENTITYSORTDIRECTION,prop.getDomainEntitySortDirection(),getOntModel());
|
updatePropertyStringValue(p,PROPERTY_ENTITYSORTDIRECTION,prop.getDomainEntitySortDirection(),getOntModel());
|
||||||
if (inv != null) {
|
if (inv != null) {
|
||||||
updatePropertyStringValue(inv,EXAMPLE_ANNOT,prop.getExample(),getOntModel());
|
updatePlainLiteralValue(inv, EXAMPLE_ANNOT, prop.getExample());
|
||||||
updatePropertyStringValue(inv,DESCRIPTION_ANNOT,prop.getDescription(),getOntModel());
|
updatePlainLiteralValue(inv, DESCRIPTION_ANNOT, prop.getDescription());
|
||||||
updatePropertyNonNegativeIntegerValue(inv,DISPLAY_LIMIT,prop.getRangeDisplayLimitInteger(),getOntModel());
|
updatePropertyNonNegativeIntegerValue(inv,DISPLAY_LIMIT,prop.getRangeDisplayLimitInteger(),getOntModel());
|
||||||
updatePropertyStringValue(inv,PROPERTY_ENTITYSORTDIRECTION,prop.getRangeEntitySortDirection(),getOntModel());
|
updatePropertyStringValue(inv,PROPERTY_ENTITYSORTDIRECTION,prop.getRangeEntitySortDirection(),getOntModel());
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,10 +12,10 @@ import java.util.function.Supplier;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
import org.apache.jena.graph.Capabilities;
|
import org.apache.jena.graph.Capabilities;
|
||||||
import org.apache.jena.graph.Graph;
|
import org.apache.jena.graph.Graph;
|
||||||
import org.apache.jena.graph.GraphEventManager;
|
import org.apache.jena.graph.GraphEventManager;
|
||||||
|
import org.apache.jena.graph.GraphListener;
|
||||||
import org.apache.jena.graph.GraphStatisticsHandler;
|
import org.apache.jena.graph.GraphStatisticsHandler;
|
||||||
import org.apache.jena.graph.Node;
|
import org.apache.jena.graph.Node;
|
||||||
import org.apache.jena.graph.TransactionHandler;
|
import org.apache.jena.graph.TransactionHandler;
|
||||||
|
@ -23,7 +23,6 @@ import org.apache.jena.graph.Triple;
|
||||||
import org.apache.jena.graph.impl.GraphWithPerform;
|
import org.apache.jena.graph.impl.GraphWithPerform;
|
||||||
import org.apache.jena.graph.impl.SimpleEventManager;
|
import org.apache.jena.graph.impl.SimpleEventManager;
|
||||||
import org.apache.jena.query.QuerySolution;
|
import org.apache.jena.query.QuerySolution;
|
||||||
import org.apache.jena.rdf.listeners.StatementListener;
|
|
||||||
import org.apache.jena.rdf.model.Model;
|
import org.apache.jena.rdf.model.Model;
|
||||||
import org.apache.jena.rdf.model.ModelFactory;
|
import org.apache.jena.rdf.model.ModelFactory;
|
||||||
import org.apache.jena.rdf.model.StmtIterator;
|
import org.apache.jena.rdf.model.StmtIterator;
|
||||||
|
@ -290,10 +289,15 @@ public class RDFServiceGraph implements GraphWithPerform {
|
||||||
literalBuff.append("\"");
|
literalBuff.append("\"");
|
||||||
pyString(literalBuff, node.getLiteralLexicalForm());
|
pyString(literalBuff, node.getLiteralLexicalForm());
|
||||||
literalBuff.append("\"");
|
literalBuff.append("\"");
|
||||||
if (node.getLiteralDatatypeURI() != null) {
|
/*
|
||||||
literalBuff.append("^^<").append(node.getLiteralDatatypeURI()).append(">");
|
* UQAM-Bug-Correction
|
||||||
} else if (!StringUtils.isEmpty(node.getLiteralLanguage())) {
|
* reversing the condition tests.
|
||||||
|
* It is important to prioritize the language typology test in order to exploit the linguistic context in testing the type of data
|
||||||
|
*/
|
||||||
|
if (!StringUtils.isEmpty(node.getLiteralLanguage())) {
|
||||||
literalBuff.append("@").append(node.getLiteralLanguage());
|
literalBuff.append("@").append(node.getLiteralLanguage());
|
||||||
|
} else if (node.getLiteralDatatypeURI() != null) {
|
||||||
|
literalBuff.append("^^<").append(node.getLiteralDatatypeURI()).append(">");
|
||||||
}
|
}
|
||||||
return literalBuff.toString();
|
return literalBuff.toString();
|
||||||
} else {
|
} else {
|
||||||
|
@ -404,7 +408,18 @@ public class RDFServiceGraph implements GraphWithPerform {
|
||||||
@Override
|
@Override
|
||||||
public GraphEventManager getEventManager() {
|
public GraphEventManager getEventManager() {
|
||||||
if (eventManager == null) {
|
if (eventManager == null) {
|
||||||
eventManager = new SimpleEventManager(this);
|
eventManager = new SimpleEventManager() {
|
||||||
|
@Override
|
||||||
|
public void notifyEvent(Graph g, Object event) {
|
||||||
|
ChangeSet changeSet = rdfService.manufactureChangeSet();
|
||||||
|
changeSet.addPreChangeEvent(event);
|
||||||
|
try {
|
||||||
|
rdfService.changeSetUpdate(changeSet);
|
||||||
|
} catch (RDFServiceException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
return eventManager;
|
return eventManager;
|
||||||
}
|
}
|
||||||
|
@ -590,21 +605,7 @@ public class RDFServiceGraph implements GraphWithPerform {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Model createRDFServiceModel(final RDFServiceGraph g) {
|
public static Model createRDFServiceModel(final RDFServiceGraph g) {
|
||||||
Model m = VitroModelFactory.createModelForGraph(g);
|
return VitroModelFactory.createModelForGraph(g);
|
||||||
m.register(new StatementListener() {
|
|
||||||
@Override
|
|
||||||
public void notifyEvent(Model m, Object event) {
|
|
||||||
ChangeSet changeSet = g.getRDFService().manufactureChangeSet();
|
|
||||||
changeSet.addPreChangeEvent(event);
|
|
||||||
try {
|
|
||||||
g.getRDFService().changeSetUpdate(changeSet);
|
|
||||||
} catch (RDFServiceException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
return m;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -232,10 +232,10 @@ public class SparqlGraph implements GraphWithPerform {
|
||||||
literalBuff.append("\"");
|
literalBuff.append("\"");
|
||||||
pyString(literalBuff, node.getLiteralLexicalForm());
|
pyString(literalBuff, node.getLiteralLexicalForm());
|
||||||
literalBuff.append("\"");
|
literalBuff.append("\"");
|
||||||
if (node.getLiteralDatatypeURI() != null) {
|
if (!StringUtils.isEmpty(node.getLiteralLanguage())) {
|
||||||
literalBuff.append("^^<").append(node.getLiteralDatatypeURI()).append(">");
|
|
||||||
} else if (!StringUtils.isEmpty(node.getLiteralLanguage())) {
|
|
||||||
literalBuff.append("@").append(node.getLiteralLanguage());
|
literalBuff.append("@").append(node.getLiteralLanguage());
|
||||||
|
} else if (node.getLiteralDatatypeURI() != null) {
|
||||||
|
literalBuff.append("^^<").append(node.getLiteralDatatypeURI()).append(">");
|
||||||
}
|
}
|
||||||
return literalBuff.toString();
|
return literalBuff.toString();
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -4,7 +4,6 @@ package edu.cornell.mannlib.vitro.webapp.dao.jena;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
@ -98,6 +97,8 @@ public class UserAccountsDaoJena extends JenaBaseDao implements UserAccountsDao
|
||||||
u.setOldPassword(getPropertyStringValue(r, USERACCOUNT_OLD_PASSWORD));
|
u.setOldPassword(getPropertyStringValue(r, USERACCOUNT_OLD_PASSWORD));
|
||||||
u.setPasswordLinkExpires(getPropertyLongValue(r,
|
u.setPasswordLinkExpires(getPropertyLongValue(r,
|
||||||
USERACCOUNT_PASSWORD_LINK_EXPIRES));
|
USERACCOUNT_PASSWORD_LINK_EXPIRES));
|
||||||
|
u.setEmailKey(getPropertyStringValue(r,USERACCOUNT_EMAIL_KEY));
|
||||||
|
|
||||||
u.setPasswordChangeRequired(getPropertyBooleanValue(r,
|
u.setPasswordChangeRequired(getPropertyBooleanValue(r,
|
||||||
USERACCOUNT_PASSWORD_CHANGE_REQUIRED));
|
USERACCOUNT_PASSWORD_CHANGE_REQUIRED));
|
||||||
u.setExternalAuthOnly(getPropertyBooleanValue(r,
|
u.setExternalAuthOnly(getPropertyBooleanValue(r,
|
||||||
|
@ -240,6 +241,8 @@ public class UserAccountsDaoJena extends JenaBaseDao implements UserAccountsDao
|
||||||
userAccount.getLoginCount(), model);
|
userAccount.getLoginCount(), model);
|
||||||
addPropertyLongValue(res, USERACCOUNT_LAST_LOGIN_TIME,
|
addPropertyLongValue(res, USERACCOUNT_LAST_LOGIN_TIME,
|
||||||
userAccount.getLastLoginTime(), model);
|
userAccount.getLastLoginTime(), model);
|
||||||
|
addPropertyStringValue(res, USERACCOUNT_EMAIL_KEY,
|
||||||
|
userAccount.getEmailKey(), model);
|
||||||
if (userAccount.getStatus() != null) {
|
if (userAccount.getStatus() != null) {
|
||||||
addPropertyStringValue(res, USERACCOUNT_STATUS, userAccount
|
addPropertyStringValue(res, USERACCOUNT_STATUS, userAccount
|
||||||
.getStatus().toString(), model);
|
.getStatus().toString(), model);
|
||||||
|
@ -306,6 +309,8 @@ public class UserAccountsDaoJena extends JenaBaseDao implements UserAccountsDao
|
||||||
userAccount.getLoginCount(), model);
|
userAccount.getLoginCount(), model);
|
||||||
updatePropertyLongValue(res, USERACCOUNT_LAST_LOGIN_TIME,
|
updatePropertyLongValue(res, USERACCOUNT_LAST_LOGIN_TIME,
|
||||||
userAccount.getLastLoginTime(), model);
|
userAccount.getLastLoginTime(), model);
|
||||||
|
updatePropertyStringValue(res, USERACCOUNT_EMAIL_KEY,
|
||||||
|
userAccount.getEmailKey(), model);
|
||||||
if (userAccount.getStatus() == null) {
|
if (userAccount.getStatus() == null) {
|
||||||
updatePropertyStringValue(res, USERACCOUNT_STATUS, null, model);
|
updatePropertyStringValue(res, USERACCOUNT_STATUS, null, model);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.dao.jena;
|
package edu.cornell.mannlib.vitro.webapp.dao.jena;
|
||||||
|
|
||||||
|
import static java.lang.String.format;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
@ -60,15 +62,18 @@ import edu.cornell.mannlib.vitro.webapp.dao.OntologyDao;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.VClassDao;
|
import edu.cornell.mannlib.vitro.webapp.dao.VClassDao;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
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.event.EditEvent;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.i18n.I18nBundle;
|
||||||
import edu.cornell.mannlib.vitro.webapp.web.URLEncoder;
|
import edu.cornell.mannlib.vitro.webapp.web.URLEncoder;
|
||||||
|
|
||||||
public class VClassDaoJena extends JenaBaseDao implements VClassDao {
|
public class VClassDaoJena extends JenaBaseDao implements VClassDao {
|
||||||
|
|
||||||
protected static final Log log = LogFactory.getLog(VClassDaoJena.class);
|
protected static final Log log = LogFactory.getLog(VClassDaoJena.class);
|
||||||
|
private final I18nBundle i18n;
|
||||||
private boolean isUnderlyingStoreReasoned = false;
|
private boolean isUnderlyingStoreReasoned = false;
|
||||||
|
|
||||||
public VClassDaoJena(WebappDaoFactoryJena wadf, boolean isUnderlyingStoreReasoned) {
|
public VClassDaoJena(WebappDaoFactoryJena wadf, boolean isUnderlyingStoreReasoned) {
|
||||||
super(wadf);
|
super(wadf);
|
||||||
|
this.i18n = wadf.getI18nBundle();
|
||||||
this.isUnderlyingStoreReasoned = isUnderlyingStoreReasoned;
|
this.isUnderlyingStoreReasoned = isUnderlyingStoreReasoned;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,17 +96,19 @@ public class VClassDaoJena extends JenaBaseDao implements VClassDao {
|
||||||
Restriction rest = cls.asRestriction();
|
Restriction rest = cls.asRestriction();
|
||||||
OntProperty onProperty = rest.getOnProperty();
|
OntProperty onProperty = rest.getOnProperty();
|
||||||
StringBuilder labelStr = new StringBuilder();
|
StringBuilder labelStr = new StringBuilder();
|
||||||
labelStr.append("restriction on ").append(getLabelOrId(onProperty)).append(": ");
|
labelStr.append(format("%s ", i18n.text("restriction_on")))
|
||||||
|
.append(getLabelOrId(onProperty))
|
||||||
|
.append(": ");
|
||||||
if (rest.isAllValuesFromRestriction() || rest.isSomeValuesFromRestriction()) {
|
if (rest.isAllValuesFromRestriction() || rest.isSomeValuesFromRestriction()) {
|
||||||
Resource fillerRes = null;
|
Resource fillerRes = null;
|
||||||
if (rest.isAllValuesFromRestriction()) {
|
if (rest.isAllValuesFromRestriction()) {
|
||||||
AllValuesFromRestriction avfRest = rest.asAllValuesFromRestriction();
|
AllValuesFromRestriction avfRest = rest.asAllValuesFromRestriction();
|
||||||
fillerRes = avfRest.getAllValuesFrom();
|
fillerRes = avfRest.getAllValuesFrom();
|
||||||
labelStr.append("all values from ");
|
labelStr.append(format("%s ", i18n.text("all_values_from")));
|
||||||
} else {
|
} else {
|
||||||
SomeValuesFromRestriction svfRest = rest.asSomeValuesFromRestriction();
|
SomeValuesFromRestriction svfRest = rest.asSomeValuesFromRestriction();
|
||||||
fillerRes = svfRest.getSomeValuesFrom();
|
fillerRes = svfRest.getSomeValuesFrom();
|
||||||
labelStr.append("some values from ");
|
labelStr.append(format("%s ", i18n.text("some_values_from")));
|
||||||
}
|
}
|
||||||
if (fillerRes.canAs(OntClass.class)) {
|
if (fillerRes.canAs(OntClass.class)) {
|
||||||
OntClass avf = fillerRes.as(OntClass.class);
|
OntClass avf = fillerRes.as(OntClass.class);
|
||||||
|
@ -115,7 +122,7 @@ public class VClassDaoJena extends JenaBaseDao implements VClassDao {
|
||||||
}
|
}
|
||||||
} else if (rest.isHasValueRestriction()) {
|
} else if (rest.isHasValueRestriction()) {
|
||||||
HasValueRestriction hvRest = rest.asHasValueRestriction();
|
HasValueRestriction hvRest = rest.asHasValueRestriction();
|
||||||
labelStr.append("has value ");
|
labelStr.append(format("%s ", i18n.text("has_value")));
|
||||||
RDFNode fillerNode = hvRest.getHasValue();
|
RDFNode fillerNode = hvRest.getHasValue();
|
||||||
try {
|
try {
|
||||||
if (fillerNode.isResource()) {
|
if (fillerNode.isResource()) {
|
||||||
|
@ -128,22 +135,22 @@ public class VClassDaoJena extends JenaBaseDao implements VClassDao {
|
||||||
}
|
}
|
||||||
} else if (rest.isMinCardinalityRestriction()) {
|
} else if (rest.isMinCardinalityRestriction()) {
|
||||||
MinCardinalityRestriction mcRest = rest.asMinCardinalityRestriction();
|
MinCardinalityRestriction mcRest = rest.asMinCardinalityRestriction();
|
||||||
labelStr.append("minimum cardinality ");
|
labelStr.append(format("%s ", i18n.text("minimum_cardinality")));
|
||||||
labelStr.append(mcRest.getMinCardinality());
|
labelStr.append(mcRest.getMinCardinality());
|
||||||
} else if (rest.isMaxCardinalityRestriction()) {
|
} else if (rest.isMaxCardinalityRestriction()) {
|
||||||
MaxCardinalityRestriction mcRest = rest.asMaxCardinalityRestriction();
|
MaxCardinalityRestriction mcRest = rest.asMaxCardinalityRestriction();
|
||||||
labelStr.append("maximum cardinality ");
|
labelStr.append(format("%s ", i18n.text("maximum_cardinality")));
|
||||||
labelStr.append(mcRest.getMaxCardinality());
|
labelStr.append(mcRest.getMaxCardinality());
|
||||||
} else if (rest.isCardinalityRestriction()) {
|
} else if (rest.isCardinalityRestriction()) {
|
||||||
CardinalityRestriction cRest = rest.asCardinalityRestriction();
|
CardinalityRestriction cRest = rest.asCardinalityRestriction();
|
||||||
labelStr.append("cardinality ");
|
labelStr.append(format("%s ", i18n.text("cardinality")));
|
||||||
labelStr.append(cRest.getCardinality());
|
labelStr.append(cRest.getCardinality());
|
||||||
}
|
}
|
||||||
return labelStr.toString();
|
return labelStr.toString();
|
||||||
} else if (isBooleanClassExpression(cls)) {
|
} else if (isBooleanClassExpression(cls)) {
|
||||||
StringBuilder labelStr = new StringBuilder("(");
|
StringBuilder labelStr = new StringBuilder("(");
|
||||||
if (cls.isComplementClass()) {
|
if (cls.isComplementClass()) {
|
||||||
labelStr.append("not ");
|
labelStr.append(format("%s ", i18n.text("not")));
|
||||||
ComplementClass ccls = cls.as(ComplementClass.class);
|
ComplementClass ccls = cls.as(ComplementClass.class);
|
||||||
labelStr.append(getLabelForClass(ccls.getOperand(), withPrefix, forPickList));
|
labelStr.append(getLabelForClass(ccls.getOperand(), withPrefix, forPickList));
|
||||||
} else if (cls.isIntersectionClass()) {
|
} else if (cls.isIntersectionClass()) {
|
||||||
|
@ -153,7 +160,7 @@ public class VClassDaoJena extends JenaBaseDao implements VClassDao {
|
||||||
OntClass operand = operandIt.next();
|
OntClass operand = operandIt.next();
|
||||||
labelStr.append(getLabelForClass(operand, withPrefix, forPickList));
|
labelStr.append(getLabelForClass(operand, withPrefix, forPickList));
|
||||||
if (operandIt.hasNext()) {
|
if (operandIt.hasNext()) {
|
||||||
labelStr.append(" and ");
|
labelStr.append(format(" %s ", i18n.text("and")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (cls.isUnionClass()) {
|
} else if (cls.isUnionClass()) {
|
||||||
|
@ -163,7 +170,7 @@ public class VClassDaoJena extends JenaBaseDao implements VClassDao {
|
||||||
OntClass operand = operandIt.next();
|
OntClass operand = operandIt.next();
|
||||||
labelStr.append(getLabelForClass(operand, withPrefix, forPickList));
|
labelStr.append(getLabelForClass(operand, withPrefix, forPickList));
|
||||||
if (operandIt.hasNext()) {
|
if (operandIt.hasNext()) {
|
||||||
labelStr.append(" or ");
|
labelStr.append(format(" %s ", i18n.text("or")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -952,9 +959,9 @@ public class VClassDaoJena extends JenaBaseDao implements VClassDao {
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("error linking class "+cls.getURI()+" to class group");
|
log.error("error linking class "+cls.getURI()+" to class group");
|
||||||
}
|
}
|
||||||
addPropertyStringValue(ontCls,SHORTDEF,cls.getShortDef(),ontModel);
|
updatePlainLiteralValue(ontCls, SHORTDEF, cls.getShortDef());
|
||||||
addPropertyStringValue(ontCls,EXAMPLE_ANNOT,cls.getExample(),ontModel);
|
updatePlainLiteralValue(ontCls, EXAMPLE_ANNOT, cls.getExample());
|
||||||
addPropertyStringValue(ontCls,DESCRIPTION_ANNOT,cls.getDescription(),ontModel);
|
updatePlainLiteralValue(ontCls, DESCRIPTION_ANNOT, cls.getDescription());
|
||||||
addPropertyIntValue(ontCls,DISPLAY_LIMIT,cls.getDisplayLimit(),ontModel);
|
addPropertyIntValue(ontCls,DISPLAY_LIMIT,cls.getDisplayLimit(),ontModel);
|
||||||
addPropertyIntValue(ontCls,DISPLAY_RANK_ANNOT,cls.getDisplayRank(),ontModel);
|
addPropertyIntValue(ontCls,DISPLAY_RANK_ANNOT,cls.getDisplayRank(),ontModel);
|
||||||
|
|
||||||
|
@ -1011,9 +1018,9 @@ public class VClassDaoJena extends JenaBaseDao implements VClassDao {
|
||||||
if (ontCls != null) {
|
if (ontCls != null) {
|
||||||
updateRDFSLabel(ontCls, cls.getName());
|
updateRDFSLabel(ontCls, cls.getName());
|
||||||
updatePropertyResourceURIValue(ontCls,IN_CLASSGROUP,cls.getGroupURI(),ontModel);
|
updatePropertyResourceURIValue(ontCls,IN_CLASSGROUP,cls.getGroupURI(),ontModel);
|
||||||
updatePropertyStringValue(ontCls,SHORTDEF,cls.getShortDef(),ontModel);
|
updatePlainLiteralValue(ontCls, SHORTDEF, cls.getShortDef());
|
||||||
updatePropertyStringValue(ontCls,EXAMPLE_ANNOT,cls.getExample(),ontModel);
|
updatePlainLiteralValue(ontCls, EXAMPLE_ANNOT, cls.getExample());
|
||||||
updatePropertyStringValue(ontCls,DESCRIPTION_ANNOT,cls.getDescription(),ontModel);
|
updatePlainLiteralValue(ontCls, DESCRIPTION_ANNOT, cls.getDescription());
|
||||||
updatePropertyNonNegativeIntValue(ontCls,DISPLAY_LIMIT,cls.getDisplayLimit(),ontModel);
|
updatePropertyNonNegativeIntValue(ontCls,DISPLAY_LIMIT,cls.getDisplayLimit(),ontModel);
|
||||||
updatePropertyNonNegativeIntValue(ontCls,DISPLAY_RANK_ANNOT,cls.getDisplayRank(),ontModel);
|
updatePropertyNonNegativeIntValue(ontCls,DISPLAY_RANK_ANNOT,cls.getDisplayRank(),ontModel);
|
||||||
updatePropertyFloatValue(ontCls, SEARCH_BOOST_ANNOT, cls.getSearchBoost(), ontModel);
|
updatePropertyFloatValue(ontCls, SEARCH_BOOST_ANNOT, cls.getSearchBoost(), ontModel);
|
||||||
|
|
|
@ -276,7 +276,7 @@ public class VClassGroupDaoJena extends JenaBaseDao implements VClassGroupDao {
|
||||||
try {
|
try {
|
||||||
Individual groupInd = ontModel.getIndividual(vcg.getURI());
|
Individual groupInd = ontModel.getIndividual(vcg.getURI());
|
||||||
try {
|
try {
|
||||||
groupInd.setLabel(vcg.getPublicName(), getDefaultLanguage());
|
updateRDFSLabel(groupInd, vcg.getPublicName(), getDefaultLanguage());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("error updating name for "+groupInd.getURI());
|
log.error("error updating name for "+groupInd.getURI());
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,6 +50,8 @@ import edu.cornell.mannlib.vitro.webapp.dao.VClassGroupDao;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactoryConfig;
|
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactoryConfig;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.i18n.I18n;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.i18n.I18nBundle;
|
||||||
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelNames;
|
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelNames;
|
||||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
|
||||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.jena.model.RDFServiceModel;
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.jena.model.RDFServiceModel;
|
||||||
|
@ -611,5 +613,10 @@ public class WebappDaoFactoryJena implements WebappDaoFactory {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public I18nBundle getI18nBundle() {
|
||||||
|
// return context based bundle for preferred locales
|
||||||
|
return I18n.bundle(config.getPreferredLocales());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -132,6 +132,11 @@ public class EditLiteral implements Literal {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isStmtResource() {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
public Literal inModel(Model model) {
|
public Literal inModel(Model model) {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,6 @@ package edu.cornell.mannlib.vitro.webapp.edit.listener.impl;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
|
|
|
@ -24,15 +24,25 @@ import edu.cornell.mannlib.vitro.webapp.beans.Datatype;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.DatatypeDaoJena;
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.DatatypeDaoJena;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactoryJena;
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactoryJena;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.i18n.I18nBundle;
|
||||||
|
|
||||||
public class BasicValidationVTwo {
|
public class BasicValidationVTwo {
|
||||||
|
|
||||||
|
public final static String REQUIRED_FIELD_EMPTY_MSG = "required_field_empty_msg";
|
||||||
|
|
||||||
|
public final static String DATA_NOT_PAST_MSG = "data_not_past_msg";
|
||||||
|
public final static String INVALID_DATE_FORM_MSG = "invalid_date_form_msg";
|
||||||
|
public final static String FILE_MUST_BE_ENTERED_MSG = "file_must_be_entered_msg";
|
||||||
|
public final static String INVALID_URL_MSG = "invalid_url_msg";
|
||||||
|
|
||||||
|
private I18nBundle i18n;
|
||||||
|
|
||||||
Map<String, List<String>> varsToValidations;
|
Map<String, List<String>> varsToValidations;
|
||||||
EditConfigurationVTwo editConfig;
|
EditConfigurationVTwo editConfig;
|
||||||
|
|
||||||
public BasicValidationVTwo(EditConfigurationVTwo editConfig, MultiValueEditSubmission editSub){
|
public BasicValidationVTwo(EditConfigurationVTwo editConfig, I18nBundle i18n){
|
||||||
this.editConfig = editConfig;
|
this.editConfig = editConfig;
|
||||||
|
this.i18n = i18n;
|
||||||
Map<String,List<String>> validatorsForFields = new HashMap<String,List<String>>();
|
Map<String,List<String>> validatorsForFields = new HashMap<String,List<String>>();
|
||||||
for(String fieldName: editConfig.getFields().keySet()){
|
for(String fieldName: editConfig.getFields().keySet()){
|
||||||
FieldVTwo field = editConfig.getField(fieldName);
|
FieldVTwo field = editConfig.getField(fieldName);
|
||||||
|
@ -42,8 +52,9 @@ public class BasicValidationVTwo {
|
||||||
checkValidations();
|
checkValidations();
|
||||||
}
|
}
|
||||||
|
|
||||||
public BasicValidationVTwo(Map<String, List<String>> varsToValidations){
|
public BasicValidationVTwo(Map<String, List<String>> varsToValidations, I18nBundle i18n){
|
||||||
this.varsToValidations = varsToValidations;
|
this.varsToValidations = varsToValidations;
|
||||||
|
this.i18n = i18n;
|
||||||
checkValidations();
|
checkValidations();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,7 +105,7 @@ public class BasicValidationVTwo {
|
||||||
//If no literals and this field was required, this is an error message
|
//If no literals and this field was required, this is an error message
|
||||||
//and can return
|
//and can return
|
||||||
if((literals == null || literals.size() == 0) && isRequiredField) {
|
if((literals == null || literals.size() == 0) && isRequiredField) {
|
||||||
errors.put(name, REQUIRED_FIELD_EMPTY_MSG);
|
errors.put(name, i18n.text(REQUIRED_FIELD_EMPTY_MSG));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
//Loop through literals if literals exist
|
//Loop through literals if literals exist
|
||||||
|
@ -113,7 +124,7 @@ public class BasicValidationVTwo {
|
||||||
// incorrectly generate errors.
|
// incorrectly generate errors.
|
||||||
if (isEmpty(value)) {
|
if (isEmpty(value)) {
|
||||||
if (isRequiredField) {
|
if (isRequiredField) {
|
||||||
errors.put(name, REQUIRED_FIELD_EMPTY_MSG);
|
errors.put(name, i18n.text(REQUIRED_FIELD_EMPTY_MSG));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -154,11 +165,11 @@ public class BasicValidationVTwo {
|
||||||
private String validate(String validationType, List<FileItem> fileItems) {
|
private String validate(String validationType, List<FileItem> fileItems) {
|
||||||
if( "nonempty".equalsIgnoreCase(validationType)){
|
if( "nonempty".equalsIgnoreCase(validationType)){
|
||||||
if( fileItems == null || fileItems.size() == 0 ){
|
if( fileItems == null || fileItems.size() == 0 ){
|
||||||
return "a file must be entered for this field.";
|
return i18n.text(FILE_MUST_BE_ENTERED_MSG);
|
||||||
}else{
|
}else{
|
||||||
FileItem fileItem = fileItems.get(0);
|
FileItem fileItem = fileItems.get(0);
|
||||||
if( fileItem == null || fileItem.getName() == null || fileItem.getName().length() < 1 || fileItem.getSize() < 0){
|
if( fileItem == null || fileItem.getName() == null || fileItem.getName().length() < 1 || fileItem.getSize() < 0){
|
||||||
return "a file must be entered for this field.";
|
return i18n.text(FILE_MUST_BE_ENTERED_MSG);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -174,14 +185,14 @@ public class BasicValidationVTwo {
|
||||||
// This case may be needed for validation of other field types.
|
// This case may be needed for validation of other field types.
|
||||||
if( "nonempty".equalsIgnoreCase(validationType)){
|
if( "nonempty".equalsIgnoreCase(validationType)){
|
||||||
if( isEmpty(value) )
|
if( isEmpty(value) )
|
||||||
return REQUIRED_FIELD_EMPTY_MSG;
|
return i18n.text(REQUIRED_FIELD_EMPTY_MSG);
|
||||||
}
|
}
|
||||||
// Format validation
|
// Format validation
|
||||||
else if("isDate".equalsIgnoreCase(validationType)){
|
else if("isDate".equalsIgnoreCase(validationType)){
|
||||||
if( isDate( value))
|
if( isDate( value))
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
else
|
else
|
||||||
return "must be in valid date format mm/dd/yyyy.";
|
return i18n.text(INVALID_DATE_FORM_MSG);
|
||||||
}
|
}
|
||||||
else if( validationType.indexOf("datatype:") == 0 ) {
|
else if( validationType.indexOf("datatype:") == 0 ) {
|
||||||
String datatypeURI = validationType.substring(9);
|
String datatypeURI = validationType.substring(9);
|
||||||
|
@ -194,7 +205,7 @@ public class BasicValidationVTwo {
|
||||||
} else if ("httpUrl".equalsIgnoreCase(validationType)){
|
} else if ("httpUrl".equalsIgnoreCase(validationType)){
|
||||||
//check if it has http or https, we could do more but for now this is all.
|
//check if it has http or https, we could do more but for now this is all.
|
||||||
if(! value.startsWith("http://") && ! value.startsWith("https://") ){
|
if(! value.startsWith("http://") && ! value.startsWith("https://") ){
|
||||||
return "This URL must start with http:// or https://";
|
return i18n.text(INVALID_URL_MSG);
|
||||||
}else{
|
}else{
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -216,7 +227,7 @@ public class BasicValidationVTwo {
|
||||||
dayParamStr = value.substring(monthDash + 1, value.length());
|
dayParamStr = value.substring(monthDash + 1, value.length());
|
||||||
inputC.set(Integer.parseInt(yearParamStr), Integer.parseInt(monthParamStr) - 1, Integer.parseInt(dayParamStr));
|
inputC.set(Integer.parseInt(yearParamStr), Integer.parseInt(monthParamStr) - 1, Integer.parseInt(dayParamStr));
|
||||||
if(inputC.before(c)) {
|
if(inputC.before(c)) {
|
||||||
return this.DATE_NOT_PAST_MSG;
|
return i18n.text(DATA_NOT_PAST_MSG);
|
||||||
//Returning null makes the error message "field is empty" display instead
|
//Returning null makes the error message "field is empty" display instead
|
||||||
//return null;
|
//return null;
|
||||||
} else {
|
} else {
|
||||||
|
@ -278,14 +289,9 @@ public class BasicValidationVTwo {
|
||||||
return (value == null || value.trim().length() == 0);
|
return (value == null || value.trim().length() == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private static Pattern urlRX = Pattern.compile("(([a-zA-Z][0-9a-zA-Z+\\-\\.]*:)/{0,2}[0-9a-zA-Z;/?:@&=+$\\.\\-_!~*'()%]+)(#[0-9a-zA-Z;/?:@&=+$\\.\\-_!~*'()%]+)?");
|
|
||||||
|
|
||||||
/** we use null to indicate success */
|
/** we use null to indicate success */
|
||||||
public final static String SUCCESS = null;
|
public final static String SUCCESS = null;
|
||||||
public final static String REQUIRED_FIELD_EMPTY_MSG = "This field must not be empty.";
|
|
||||||
public final static String DATE_NOT_PAST_MSG = "Please enter a future target date for publication (past dates are invalid).";
|
|
||||||
//public final static String MIN_FIELDS_NOT_POPULATED = "Please enter values for at least ";
|
//public final static String MIN_FIELDS_NOT_POPULATED = "Please enter values for at least ";
|
||||||
//public final static String FORM_ERROR_FIELD_ID = "formannotationerrors";
|
//public final static String FORM_ERROR_FIELD_ID = "formannotationerrors";
|
||||||
/** regex for strings like "12/31/2004" */
|
/** regex for strings like "12/31/2004" */
|
||||||
|
|
|
@ -28,6 +28,7 @@ import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo;
|
||||||
import edu.cornell.mannlib.vitro.webapp.freemarker.config.FreemarkerConfiguration;
|
import edu.cornell.mannlib.vitro.webapp.freemarker.config.FreemarkerConfiguration;
|
||||||
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess;
|
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess.LanguageOption;
|
||||||
import freemarker.template.Configuration;
|
import freemarker.template.Configuration;
|
||||||
|
|
||||||
public class EditConfigurationUtils {
|
public class EditConfigurationUtils {
|
||||||
|
@ -61,18 +62,24 @@ public class EditConfigurationUtils {
|
||||||
return vreq.getParameter("rangeUri");
|
return vreq.getParameter("rangeUri");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getTypeOfNew(VitroRequest vreq) {
|
||||||
|
return vreq.getParameter("typeOfNew");
|
||||||
|
}
|
||||||
|
|
||||||
public static VClass getRangeVClass(VitroRequest vreq) {
|
public static VClass getRangeVClass(VitroRequest vreq) {
|
||||||
// This needs a WebappDaoFactory with no filtering/RDFService
|
|
||||||
// funny business because it needs to be able to retrieve anonymous union
|
|
||||||
// classes by their "pseudo-bnode URIs".
|
|
||||||
// Someday we'll need to figure out a different way of doing this.
|
|
||||||
WebappDaoFactory ctxDaoFact = ModelAccess.on(
|
WebappDaoFactory ctxDaoFact = ModelAccess.on(
|
||||||
vreq.getSession().getServletContext()).getWebappDaoFactory();
|
vreq.getSession().getServletContext()).getWebappDaoFactory();
|
||||||
return ctxDaoFact.getVClassDao().getVClassByURI(getRangeUri(vreq));
|
return ctxDaoFact.getVClassDao().getVClassByURI(getRangeUri(vreq));
|
||||||
}
|
}
|
||||||
|
|
||||||
//get individual
|
public static VClass getLangAwardRangeVClass(VitroRequest vreq) {
|
||||||
|
// UQAM-Linguistic-Management
|
||||||
|
WebappDaoFactory vreqDaoFact = ModelAccess.on(vreq).getWebappDaoFactory(
|
||||||
|
LanguageOption.LANGUAGE_AWARE);
|
||||||
|
return vreqDaoFact.getVClassDao().getVClassByURI(getRangeUri(vreq));
|
||||||
|
}
|
||||||
|
|
||||||
|
//get individual
|
||||||
public static Individual getSubjectIndividual(VitroRequest vreq) {
|
public static Individual getSubjectIndividual(VitroRequest vreq) {
|
||||||
Individual subject = null;
|
Individual subject = null;
|
||||||
String subjectUri = getSubjectUri(vreq);
|
String subjectUri = getSubjectUri(vreq);
|
||||||
|
@ -122,12 +129,24 @@ public class EditConfigurationUtils {
|
||||||
|
|
||||||
public static ObjectProperty getObjectPropertyForPredicate(VitroRequest vreq,
|
public static ObjectProperty getObjectPropertyForPredicate(VitroRequest vreq,
|
||||||
String predicateUri, String domainUri, String rangeUri) {
|
String predicateUri, String domainUri, String rangeUri) {
|
||||||
WebappDaoFactory wdf = vreq.getWebappDaoFactory();
|
// WebappDaoFactory wdf = vreq.getWebappDaoFactory();
|
||||||
|
// UQAM-Linguistic-Management Use linguistic context
|
||||||
|
WebappDaoFactory wdf = ModelAccess.on(vreq).getWebappDaoFactory(LanguageOption.LANGUAGE_AWARE);
|
||||||
ObjectProperty objectProp = wdf.getObjectPropertyDao().getObjectPropertyByURIs(
|
ObjectProperty objectProp = wdf.getObjectPropertyDao().getObjectPropertyByURIs(
|
||||||
predicateUri, domainUri, rangeUri);
|
predicateUri, domainUri, rangeUri);
|
||||||
return objectProp;
|
return objectProp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UQAM Use linguistic context
|
||||||
|
public static ObjectProperty getObjectPropertyForPredicateLangAware(VitroRequest vreq,
|
||||||
|
String predicateUri, String domainUri, String rangeUri) {
|
||||||
|
// WebappDaoFactory wdf = vreq.getWebappDaoFactory();
|
||||||
|
// UQAM Use linguistic context
|
||||||
|
WebappDaoFactory wdf = ModelAccess.on(vreq).getWebappDaoFactory(LanguageOption.LANGUAGE_AWARE);
|
||||||
|
ObjectProperty objectProp = wdf.getObjectPropertyDao().getObjectPropertyByURIs(
|
||||||
|
predicateUri, domainUri, rangeUri);
|
||||||
|
return objectProp;
|
||||||
|
}
|
||||||
public static DataProperty getDataPropertyForPredicate(VitroRequest vreq, String predicateUri) {
|
public static DataProperty getDataPropertyForPredicate(VitroRequest vreq, String predicateUri) {
|
||||||
WebappDaoFactory wdf = vreq.getWebappDaoFactory();
|
WebappDaoFactory wdf = vreq.getWebappDaoFactory();
|
||||||
//TODO: Check reason for employing unfiltered webapp dao factory and note if using a different version
|
//TODO: Check reason for employing unfiltered webapp dao factory and note if using a different version
|
||||||
|
@ -205,6 +224,7 @@ public class EditConfigurationUtils {
|
||||||
return (op != null && dp == null);
|
return (op != null && dp == null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static boolean isVitroLabel(String predicateUri) {
|
private static boolean isVitroLabel(String predicateUri) {
|
||||||
return predicateUri.equals(VitroVocabulary.LABEL);
|
return predicateUri.equals(VitroVocabulary.LABEL);
|
||||||
}
|
}
|
||||||
|
|
|
@ -366,6 +366,8 @@ public class EditN3GeneratorVTwo {
|
||||||
{
|
{
|
||||||
sbuff.append("@") ;
|
sbuff.append("@") ;
|
||||||
sbuff.append(lang) ;
|
sbuff.append(lang) ;
|
||||||
|
// added by UQAM to exit at this point without adding datatype
|
||||||
|
return sbuff.toString() ;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Format the datatype
|
// Format the datatype
|
||||||
|
|
|
@ -10,23 +10,23 @@ import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.apache.commons.fileupload.FileItem;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.joda.time.format.DateTimeFormat;
|
|
||||||
import org.joda.time.format.DateTimeFormatter;
|
|
||||||
|
|
||||||
import org.apache.jena.rdf.model.Literal;
|
import org.apache.jena.rdf.model.Literal;
|
||||||
import org.apache.jena.rdf.model.Model;
|
import org.apache.jena.rdf.model.Model;
|
||||||
import org.apache.jena.rdf.model.ModelFactory;
|
import org.apache.jena.rdf.model.ModelFactory;
|
||||||
import org.apache.jena.rdf.model.ResourceFactory;
|
import org.apache.jena.rdf.model.ResourceFactory;
|
||||||
import org.apache.jena.vocabulary.XSD;
|
import org.apache.jena.vocabulary.XSD;
|
||||||
|
import org.apache.jena.vocabulary.RDF;
|
||||||
|
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.EditLiteral;
|
import edu.cornell.mannlib.vitro.webapp.edit.EditLiteral;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.i18n.I18n;
|
||||||
|
|
||||||
public class MultiValueEditSubmission {
|
public class MultiValueEditSubmission {
|
||||||
|
|
||||||
|
@ -34,21 +34,31 @@ public class MultiValueEditSubmission {
|
||||||
|
|
||||||
private Map<String,List<Literal>> literalsFromForm ;
|
private Map<String,List<Literal>> literalsFromForm ;
|
||||||
private Map<String,List<String>> urisFromForm ;
|
private Map<String,List<String>> urisFromForm ;
|
||||||
|
|
||||||
private Map<String,String> validationErrors;
|
private Map<String,String> validationErrors;
|
||||||
private BasicValidationVTwo basicValidation;
|
private BasicValidationVTwo basicValidation;
|
||||||
|
|
||||||
private Map<String, List<FileItem>> filesFromForm;
|
|
||||||
|
|
||||||
private static Model literalCreationModel;
|
private static Model literalCreationModel;
|
||||||
|
|
||||||
private String entityToReturnTo;
|
private String entityToReturnTo;
|
||||||
|
private VitroRequest _vreq;
|
||||||
|
|
||||||
|
private static final String TIME_URI = XSD.time.getURI();
|
||||||
|
|
||||||
|
|
||||||
static{
|
static{
|
||||||
literalCreationModel = ModelFactory.createDefaultModel();
|
literalCreationModel = ModelFactory.createDefaultModel();
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
public MultiValueEditSubmission(Map<String,String[]> queryParameters, EditConfigurationVTwo editConfig){
|
* UQAM
|
||||||
|
* replace
|
||||||
|
* public MultiValueEditSubmission(Map<String,String[]> queryParameters, EditConfigurationVTwo editConfig)
|
||||||
|
* by this new signature
|
||||||
|
* This affect PostEditCleanupController and ProcessRdfFormController classes.
|
||||||
|
* This replacement is justified by the fact that we need a linguistic context in this class.
|
||||||
|
*/
|
||||||
|
public MultiValueEditSubmission(VitroRequest vreq, EditConfigurationVTwo editConfig){
|
||||||
|
// UQAM add this both lines
|
||||||
|
_vreq = vreq;
|
||||||
|
Map<String,String[]> queryParameters = vreq.getParameterMap();
|
||||||
if( editConfig == null )
|
if( editConfig == null )
|
||||||
throw new Error("EditSubmission needs an EditConfiguration");
|
throw new Error("EditSubmission needs an EditConfiguration");
|
||||||
this.editKey = editConfig.getEditKey();
|
this.editKey = editConfig.getEditKey();
|
||||||
|
@ -92,11 +102,12 @@ public class MultiValueEditSubmission {
|
||||||
processEditElementFields(editConfig,queryParameters);
|
processEditElementFields(editConfig,queryParameters);
|
||||||
//Incorporating basic validation
|
//Incorporating basic validation
|
||||||
//Validate URIS
|
//Validate URIS
|
||||||
this.basicValidation = new BasicValidationVTwo(editConfig, this);
|
this.basicValidation = new BasicValidationVTwo(editConfig, I18n.bundle(vreq));
|
||||||
Map<String,String> errors = basicValidation.validateUris( urisFromForm );
|
Map<String,String> errors = basicValidation.validateUris( urisFromForm );
|
||||||
//Validate literals and add errors to the list of existing errors
|
//Validate literals and add errors to the list of existing errors
|
||||||
errors.putAll(basicValidation.validateLiterals( literalsFromForm ));
|
errors.putAll(basicValidation.validateLiterals( literalsFromForm ));
|
||||||
if( errors != null ) {
|
// UQAM Add empty contition
|
||||||
|
if( errors != null && !errors.isEmpty()) {
|
||||||
validationErrors.putAll( errors);
|
validationErrors.putAll( errors);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -141,9 +152,8 @@ public class MultiValueEditSubmission {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* maybe this could be static */
|
/* maybe this could be static */
|
||||||
public Literal createLiteral(String value, String datatypeUri, String lang) {
|
public Literal createLiteral_ORIG(String value, String datatypeUri, String lang) {
|
||||||
if( datatypeUri != null ){
|
if( datatypeUri != null ){
|
||||||
if( "http://www.w3.org/2001/XMLSchema:anyURI".equals(datatypeUri) ){
|
if( "http://www.w3.org/2001/XMLSchema:anyURI".equals(datatypeUri) ){
|
||||||
try {
|
try {
|
||||||
|
@ -159,12 +169,27 @@ public class MultiValueEditSubmission {
|
||||||
return ResourceFactory.createPlainLiteral(value);
|
return ResourceFactory.createPlainLiteral(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final String DATE_TIME_URI = XSD.dateTime.getURI();
|
/* maybe this could be static */
|
||||||
private static final String DATE_URI = XSD.date.getURI();
|
public Literal createLiteral(String value, String datatypeUri, String lang) {
|
||||||
private static final String TIME_URI = XSD.time.getURI();
|
if( datatypeUri != null && !datatypeUri.isEmpty() ){
|
||||||
|
// UQAM Original code contained tow-dots ':' in place of '#'
|
||||||
private static DateTimeFormatter dformater = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:00");
|
// if( "http://www.w3.org/2001/XMLSchema:anyURI".equals(datatypeUri) ){
|
||||||
private static DateTimeFormatter dateFormater = DateTimeFormat.forPattern("yyyy-MM-dd");
|
if( XSD.anyURI.getURI().equals(datatypeUri) ){
|
||||||
|
// try {
|
||||||
|
// return literalCreationModel.createTypedLiteral( URLEncoder.encode(value, "UTF8"), datatypeUri);
|
||||||
|
return literalCreationModel.createTypedLiteral( value, datatypeUri);
|
||||||
|
// } catch (UnsupportedEncodingException e) {
|
||||||
|
// log.error(e, e);
|
||||||
|
// }
|
||||||
|
} else if ( XSD.xstring.getURI().equals(datatypeUri) || RDF.dtLangString.getURI().equals(datatypeUri) ){
|
||||||
|
if( lang != null && lang.length() > 0 ) return ResourceFactory.createLangLiteral(value, lang);
|
||||||
|
}
|
||||||
|
return literalCreationModel.createTypedLiteral(value, datatypeUri);
|
||||||
|
// UQAM take into account the linguistic context
|
||||||
|
} else if( lang != null && lang.length() > 0 )
|
||||||
|
return ResourceFactory.createLangLiteral(value, lang);
|
||||||
|
return ResourceFactory.createPlainLiteral(value);
|
||||||
|
}
|
||||||
|
|
||||||
public Map<String,String> getValidationErrors(){
|
public Map<String,String> getValidationErrors(){
|
||||||
return validationErrors;
|
return validationErrors;
|
||||||
|
@ -264,12 +289,46 @@ public class MultiValueEditSubmission {
|
||||||
for(String value:valueList) {
|
for(String value:valueList) {
|
||||||
value = N3EditUtils.stripInvalidXMLChars(value);
|
value = N3EditUtils.stripInvalidXMLChars(value);
|
||||||
//Add to array of literals corresponding to this variable
|
//Add to array of literals corresponding to this variable
|
||||||
|
/* UQAM OLD
|
||||||
if (!StringUtils.isEmpty(value)) {
|
if (!StringUtils.isEmpty(value)) {
|
||||||
literalsArray.add(createLiteral(
|
literalsArray.add(createLiteral(
|
||||||
value,
|
value,
|
||||||
field.getRangeDatatypeUri(),
|
field.getRangeDatatypeUri(),
|
||||||
field.getRangeLang()));
|
field.getRangeLang()));
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
* UQAM Replaced by this to take the linguistic context into consideration.
|
||||||
|
*/
|
||||||
|
if (!StringUtils.isEmpty(value)) {
|
||||||
|
String rangeLang = field.getRangeLang(); //UQAM Default value
|
||||||
|
try {
|
||||||
|
if (_vreq != null ) {
|
||||||
|
// only if the request comes from the rdfsLabelGenerator the language should be used
|
||||||
|
Boolean getLabelLanguage = false;
|
||||||
|
if (!StringUtils.isBlank(editConfig.formUrl) && editConfig.formUrl.contains("RDFSLabelGenerator")) {
|
||||||
|
getLabelLanguage = true;
|
||||||
|
}
|
||||||
|
// if the language is set in the given Literal, this language-tag should be used and remain the same
|
||||||
|
// for example when you edit an label with an langauge-tag (no matter which language is selected globally)
|
||||||
|
if (!StringUtils.isBlank(editConfig.getLiteralsInScope().get("label").get(0).getLanguage()) && getLabelLanguage)
|
||||||
|
{
|
||||||
|
rangeLang = editConfig.getLiteralsInScope().get("label").get(0).getLanguage();
|
||||||
|
} else { // if the literal has no langauge-tag, use the language which is globally selected
|
||||||
|
rangeLang = _vreq.getLocale().getLanguage();
|
||||||
|
if (!_vreq.getLocale().getCountry().isEmpty()) {
|
||||||
|
rangeLang += "-" + _vreq.getLocale().getCountry();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
}
|
||||||
|
literalsArray.add(createLiteral(
|
||||||
|
value,
|
||||||
|
field.getRangeDatatypeUri(),
|
||||||
|
rangeLang));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
literalsFromForm.put(var, literalsArray);
|
literalsFromForm.put(var, literalsArray);
|
||||||
|
|
||||||
|
|
|
@ -9,15 +9,24 @@ import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.apache.jena.datatypes.xsd.XSDDatatype;
|
||||||
import org.apache.jena.ontology.OntModel;
|
import org.apache.jena.ontology.OntModel;
|
||||||
import org.apache.jena.rdf.model.Literal;
|
import org.apache.jena.rdf.model.Literal;
|
||||||
import org.apache.jena.rdf.model.Model;
|
import org.apache.jena.rdf.model.Model;
|
||||||
import org.apache.jena.rdf.model.ModelFactory;
|
import org.apache.jena.rdf.model.ModelFactory;
|
||||||
|
import org.apache.jena.rdf.model.Property;
|
||||||
|
import org.apache.jena.rdf.model.RDFNode;
|
||||||
|
import org.apache.jena.rdf.model.Resource;
|
||||||
|
import org.apache.jena.rdf.model.ResourceFactory;
|
||||||
|
import org.apache.jena.rdf.model.Statement;
|
||||||
import org.apache.jena.shared.Lock;
|
import org.apache.jena.shared.Lock;
|
||||||
|
import org.apache.jena.vocabulary.RDF;
|
||||||
|
import org.apache.jena.vocabulary.XSD;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.InsertException;
|
import edu.cornell.mannlib.vitro.webapp.dao.InsertException;
|
||||||
|
@ -41,6 +50,7 @@ public class ProcessRdfForm {
|
||||||
private EditN3GeneratorVTwo populator;
|
private EditN3GeneratorVTwo populator;
|
||||||
|
|
||||||
private Map<String,String> urisForNewResources = null;
|
private Map<String,String> urisForNewResources = null;
|
||||||
|
// private VitroRequest _vreq;
|
||||||
/**
|
/**
|
||||||
* Construct the ProcessRdfForm object.
|
* Construct the ProcessRdfForm object.
|
||||||
*/
|
*/
|
||||||
|
@ -76,9 +86,9 @@ public class ProcessRdfForm {
|
||||||
|
|
||||||
AdditionsAndRetractions changes;
|
AdditionsAndRetractions changes;
|
||||||
if( configuration.isUpdate() ){
|
if( configuration.isUpdate() ){
|
||||||
changes = editExistingStatements(configuration, submission);
|
changes = editExistingStatements(configuration, submission, vreq); //UQAM vreq for getting linguistic context
|
||||||
} else {
|
} else {
|
||||||
changes = createNewStatements(configuration, submission );
|
changes = createNewStatements(configuration, submission, vreq ); //UQAM vreq for getting linguistic context
|
||||||
}
|
}
|
||||||
|
|
||||||
changes = getMinimalChanges(changes);
|
changes = getMinimalChanges(changes);
|
||||||
|
@ -99,12 +109,15 @@ public class ProcessRdfForm {
|
||||||
* any optional N3 is to originally configure the
|
* any optional N3 is to originally configure the
|
||||||
* configuration.setN3Optional() to be empty.
|
* configuration.setN3Optional() to be empty.
|
||||||
*
|
*
|
||||||
|
* UQAM add vreq for linguistic context managing
|
||||||
|
*
|
||||||
* @throws Exception May throw an exception if the required N3
|
* @throws Exception May throw an exception if the required N3
|
||||||
* does not parse.
|
* does not parse.
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
private AdditionsAndRetractions createNewStatements(
|
private AdditionsAndRetractions createNewStatements(
|
||||||
EditConfigurationVTwo configuration,
|
EditConfigurationVTwo configuration,
|
||||||
MultiValueEditSubmission submission) throws Exception {
|
MultiValueEditSubmission submission, VitroRequest vreq) throws Exception {
|
||||||
log.debug("in createNewStatements()" );
|
log.debug("in createNewStatements()" );
|
||||||
|
|
||||||
//getN3Required and getN3Optional will return copies of the
|
//getN3Required and getN3Optional will return copies of the
|
||||||
|
@ -113,10 +126,10 @@ public class ProcessRdfForm {
|
||||||
List<String> optionalN3 = configuration.getN3Optional();
|
List<String> optionalN3 = configuration.getN3Optional();
|
||||||
|
|
||||||
/* substitute in the form values and existing values */
|
/* substitute in the form values and existing values */
|
||||||
subInValuesToN3( configuration, submission, requiredN3, optionalN3, null , null);
|
subInValuesToN3( configuration, submission, requiredN3, optionalN3, null , null, vreq);
|
||||||
|
|
||||||
/* parse N3 to RDF Models, No retractions since all of the statements are new. */
|
/* parse N3 to RDF Models, No retractions since all of the statements are new. */
|
||||||
return parseN3ToChange(requiredN3, optionalN3, null, null);
|
return parseN3ToChange(requiredN3, optionalN3, null, null, vreq, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* for a list of N3 strings, substitute in the subject, predicate and object URIs
|
/* for a list of N3 strings, substitute in the subject, predicate and object URIs
|
||||||
|
@ -140,10 +153,12 @@ public class ProcessRdfForm {
|
||||||
* retractions are mutually diff'ed before statements are added to or
|
* retractions are mutually diff'ed before statements are added to or
|
||||||
* removed from the model. The explicit change check can cause problems in
|
* removed from the model. The explicit change check can cause problems in
|
||||||
* more complex setups, like the automatic form building in DataStaR.
|
* more complex setups, like the automatic form building in DataStaR.
|
||||||
|
* @param vreq For getting linguistic context
|
||||||
|
|
||||||
*/
|
*/
|
||||||
protected AdditionsAndRetractions editExistingStatements(
|
protected AdditionsAndRetractions editExistingStatements(
|
||||||
EditConfigurationVTwo editConfig,
|
EditConfigurationVTwo editConfig,
|
||||||
MultiValueEditSubmission submission) throws Exception {
|
MultiValueEditSubmission submission, VitroRequest vreq) throws Exception {
|
||||||
|
|
||||||
log.debug("editing an existing resource: " + editConfig.getObject() );
|
log.debug("editing an existing resource: " + editConfig.getObject() );
|
||||||
|
|
||||||
|
@ -156,18 +171,18 @@ public class ProcessRdfForm {
|
||||||
|
|
||||||
subInValuesToN3(editConfig, submission,
|
subInValuesToN3(editConfig, submission,
|
||||||
N3RequiredAssert, N3OptionalAssert,
|
N3RequiredAssert, N3OptionalAssert,
|
||||||
N3RequiredRetract, N3OptionalRetract);
|
N3RequiredRetract, N3OptionalRetract, vreq);
|
||||||
|
|
||||||
return parseN3ToChange(
|
return parseN3ToChange(
|
||||||
N3RequiredAssert,N3OptionalAssert,
|
N3RequiredAssert,N3OptionalAssert,
|
||||||
N3RequiredRetract, N3OptionalRetract);
|
N3RequiredRetract, N3OptionalRetract, vreq, editConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
protected void subInValuesToN3(
|
protected void subInValuesToN3(
|
||||||
EditConfigurationVTwo editConfig, MultiValueEditSubmission submission,
|
EditConfigurationVTwo editConfig, MultiValueEditSubmission submission,
|
||||||
List<String> requiredAsserts, List<String> optionalAsserts,
|
List<String> requiredAsserts, List<String> optionalAsserts,
|
||||||
List<String> requiredRetracts, List<String> optionalRetracts ) throws InsertException{
|
List<String> requiredRetracts, List<String> optionalRetracts, VitroRequest vreq ) throws InsertException{
|
||||||
|
|
||||||
//need to substitute into the return to URL becase it may need new resource URIs
|
//need to substitute into the return to URL becase it may need new resource URIs
|
||||||
List<String> URLToReturnTo = Arrays.asList(submission.getEntityToReturnTo());
|
List<String> URLToReturnTo = Arrays.asList(submission.getEntityToReturnTo());
|
||||||
|
@ -184,7 +199,41 @@ public class ProcessRdfForm {
|
||||||
//Retractions does NOT get values from form.
|
//Retractions does NOT get values from form.
|
||||||
|
|
||||||
/* ******** Form submission Literals *********** */
|
/* ******** Form submission Literals *********** */
|
||||||
substituteInMultiLiterals( submission.getLiteralsFromForm(), requiredAsserts, optionalAsserts, URLToReturnTo);
|
/*
|
||||||
|
* UQAM Set all literals in the linguistic context
|
||||||
|
*/
|
||||||
|
Map<String, List<Literal>> literalsFromForm = submission.getLiteralsFromForm();
|
||||||
|
Set<String> keys = literalsFromForm.keySet();
|
||||||
|
for (String aKey : keys) {
|
||||||
|
List<Literal> literalFromForm = literalsFromForm.get(aKey);
|
||||||
|
List<Literal> newLiteralFromForm = new ArrayList<>();
|
||||||
|
for (Literal aLiteral : literalFromForm) {
|
||||||
|
if (aLiteral != null) {
|
||||||
|
String aLiteratDT = aLiteral.getDatatype().getURI();
|
||||||
|
Literal newLiteral = null;
|
||||||
|
String aText = aLiteral.getLexicalForm();
|
||||||
|
/*
|
||||||
|
* do it only if aLiteral are xstring datatype
|
||||||
|
*/
|
||||||
|
if (RDF.dtLangString.getURI().equals(aLiteratDT) && !aLiteral.getLanguage().isEmpty()) {
|
||||||
|
newLiteral = aLiteral;
|
||||||
|
}
|
||||||
|
else if (XSD.xstring.getURI().equals(aLiteratDT) || RDF.dtLangString.getURI().equals(aLiteratDT)) {
|
||||||
|
String lang = vreq.getLocale().getLanguage();
|
||||||
|
if (!vreq.getLocale().getCountry().isEmpty()) {
|
||||||
|
lang += "-" + vreq.getLocale().getCountry();
|
||||||
|
}
|
||||||
|
newLiteral = ResourceFactory.createLangLiteral(aText, lang);
|
||||||
|
} else {
|
||||||
|
newLiteral = ResourceFactory.createTypedLiteral(aText, aLiteral.getDatatype());
|
||||||
|
}
|
||||||
|
newLiteralFromForm.add(newLiteral);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
literalsFromForm.replace(aKey, newLiteralFromForm);
|
||||||
|
}
|
||||||
|
|
||||||
|
substituteInMultiLiterals( literalsFromForm, requiredAsserts, optionalAsserts, URLToReturnTo);
|
||||||
logSubstitue( "Added form Literals", requiredAsserts, optionalAsserts, requiredRetracts, optionalRetracts);
|
logSubstitue( "Added form Literals", requiredAsserts, optionalAsserts, requiredRetracts, optionalRetracts);
|
||||||
//Retractions does NOT get values from form.
|
//Retractions does NOT get values from form.
|
||||||
|
|
||||||
|
@ -254,20 +303,106 @@ public class ProcessRdfForm {
|
||||||
|
|
||||||
protected AdditionsAndRetractions parseN3ToChange(
|
protected AdditionsAndRetractions parseN3ToChange(
|
||||||
List<String> requiredAdds, List<String> optionalAdds,
|
List<String> requiredAdds, List<String> optionalAdds,
|
||||||
List<String> requiredDels, List<String> optionalDels) throws Exception{
|
List<String> requiredDels, List<String> optionalDels, VitroRequest vreq, EditConfigurationVTwo editConfig) throws Exception{
|
||||||
|
|
||||||
List<Model> adds = parseN3ToRDF(requiredAdds, REQUIRED);
|
List<Model> adds = parseN3ToRDF(requiredAdds, REQUIRED);
|
||||||
adds.addAll( parseN3ToRDF(optionalAdds, OPTIONAL));
|
adds.addAll( parseN3ToRDF(optionalAdds, OPTIONAL));
|
||||||
|
|
||||||
List<Model> retracts = new ArrayList<Model>();
|
List<Model> retracts = new ArrayList<Model>();
|
||||||
if( requiredDels != null && optionalDels != null ){
|
if( requiredDels != null && optionalDels != null ){
|
||||||
retracts.addAll( parseN3ToRDF(requiredDels, REQUIRED) );
|
String lingCxt=null;
|
||||||
retracts.addAll( parseN3ToRDF(optionalDels, OPTIONAL) );
|
//UQAM Taking into account the linguistic context in retract
|
||||||
|
try {
|
||||||
|
// only if the request comes from the rdfsLabelGenerator the language should be used
|
||||||
|
Boolean getLabelLanguage = false;
|
||||||
|
if (!StringUtils.isBlank(editConfig.formUrl) && editConfig.formUrl.contains("RDFSLabelGenerator")) {
|
||||||
|
getLabelLanguage = true;
|
||||||
|
}
|
||||||
|
// if the language is set in the given Literal, this language-tag should be used and remain the same
|
||||||
|
// for example when you edit an label with an langauge-tag (no matter which language is selected globally)
|
||||||
|
if (editConfig != null && !StringUtils.isBlank(editConfig.getLiteralsInScope().get("label").get(0).getLanguage()) && getLabelLanguage) {
|
||||||
|
lingCxt = editConfig.getLiteralsInScope().get("label").get(0).getLanguage();
|
||||||
|
} else { // if the literal has no langauge-tag, use the language which is globally selected
|
||||||
|
lingCxt = vreq.getLocale().getLanguage();
|
||||||
|
if (!vreq.getLocale().getCountry().isEmpty()) {
|
||||||
|
lingCxt += "-" + vreq.getLocale().getCountry();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
}
|
||||||
|
retracts.addAll( parseN3ToRDF(requiredDels, REQUIRED, lingCxt) );
|
||||||
|
retracts.addAll( parseN3ToRDF(optionalDels, OPTIONAL, lingCxt) );
|
||||||
}
|
}
|
||||||
|
|
||||||
return new AdditionsAndRetractions(adds,retracts);
|
return new AdditionsAndRetractions(adds,retracts);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Parse the n3Strings to a List of RDF Model objects.
|
||||||
|
*
|
||||||
|
* @param n3Strings N3 Strings to parse
|
||||||
|
* @param parseType if OPTIONAL, then don't throw exceptions on errors
|
||||||
|
* @param linguisticContext For Literals, Making parse only if the literal linguisticContext are same than linguisticContext parameter //UQAM
|
||||||
|
* If REQUIRED, then throw exceptions on errors.
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
protected static List<Model> parseN3ToRDF(
|
||||||
|
List<String> n3Strings, N3ParseType parseType, String linguisticContext ) throws Exception {
|
||||||
|
// Use non-linguistic version of this method if no linguisticContext is provided
|
||||||
|
if (linguisticContext == null) {
|
||||||
|
return parseN3ToRDF(n3Strings, parseType);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<String> errorMessages = new ArrayList<String>();
|
||||||
|
|
||||||
|
List<Model> rdfModels = new ArrayList<Model>();
|
||||||
|
for(String n3 : n3Strings){
|
||||||
|
try{
|
||||||
|
Model model = ModelFactory.createDefaultModel();
|
||||||
|
StringReader reader = new StringReader(n3);
|
||||||
|
model.read(reader, "", "N3");
|
||||||
|
List<Statement> stmts = model.listStatements().toList();
|
||||||
|
for (Iterator iterator = stmts.iterator(); iterator.hasNext();) {
|
||||||
|
Statement stmt = (Statement) iterator.next();
|
||||||
|
Resource subj = stmt.getSubject();
|
||||||
|
Property pred = stmt.getPredicate();
|
||||||
|
RDFNode obj = stmt.getObject();
|
||||||
|
if (obj.isLiteral()) {
|
||||||
|
Literal lit = obj.asLiteral();
|
||||||
|
String lang = lit.getLanguage();
|
||||||
|
if (! linguisticContext.equals(lang)) {
|
||||||
|
//UQAM Remove if linguisticContext != lang of the Literal
|
||||||
|
model.remove(subj, pred, obj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
rdfModels.add( model );
|
||||||
|
}catch(Throwable t){
|
||||||
|
errorMessages.add(t.getMessage() + "\nN3: \n" + n3 + "\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
StringBuilder errors = new StringBuilder();
|
||||||
|
for( String errorMsg : errorMessages){
|
||||||
|
errors.append(errorMsg).append('\n');
|
||||||
|
}
|
||||||
|
|
||||||
|
if( !errorMessages.isEmpty() ){
|
||||||
|
if( REQUIRED.equals(parseType) ){
|
||||||
|
throw new Exception("Errors processing required N3. The EditConfiguration should " +
|
||||||
|
"be setup so that if a submission passes validation, there will not be errors " +
|
||||||
|
"in the required N3.\n" + errors );
|
||||||
|
}else if( OPTIONAL.equals(parseType) ){
|
||||||
|
log.debug("Some Optional N3 did not parse, if a optional N3 does not parse it " +
|
||||||
|
"will be ignored. This allows optional parts of a form submission to " +
|
||||||
|
"remain unfilled out and then the optional N3 does not get values subsituted in from" +
|
||||||
|
"the form submission values. It may also be the case that there are unintentional " +
|
||||||
|
"syntax errors the optional N3." );
|
||||||
|
log.debug(errors.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return rdfModels;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Parse the n3Strings to a List of RDF Model objects.
|
* Parse the n3Strings to a List of RDF Model objects.
|
||||||
*
|
*
|
||||||
|
|
|
@ -7,6 +7,7 @@ import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.i18n.I18nBundle;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
|
@ -40,7 +41,8 @@ public class ChildVClassesOptions implements FieldOptions {
|
||||||
public Map<String, String> getOptions(
|
public Map<String, String> getOptions(
|
||||||
EditConfigurationVTwo editConfig,
|
EditConfigurationVTwo editConfig,
|
||||||
String fieldName,
|
String fieldName,
|
||||||
WebappDaoFactory wDaoFact) throws Exception{
|
WebappDaoFactory wDaoFact,
|
||||||
|
I18nBundle i18n) throws Exception{
|
||||||
// now create an empty HashMap to populate and return
|
// now create an empty HashMap to populate and return
|
||||||
HashMap <String,String> optionsMap = new LinkedHashMap<String,String>();
|
HashMap <String,String> optionsMap = new LinkedHashMap<String,String>();
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/* $This file is distributed under the terms of the license in LICENSE$ */
|
/* $This file is distributed under the terms of the license in LICENSE$ */
|
||||||
package edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields;
|
|
||||||
|
|
||||||
|
package edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
|
@ -15,6 +15,7 @@ import edu.cornell.mannlib.vitro.webapp.beans.VClass;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.VClassDao;
|
import edu.cornell.mannlib.vitro.webapp.dao.VClassDao;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.i18n.I18nBundle;
|
||||||
|
|
||||||
public class ChildVClassesWithParent implements FieldOptions {
|
public class ChildVClassesWithParent implements FieldOptions {
|
||||||
|
|
||||||
|
@ -37,20 +38,24 @@ public class ChildVClassesWithParent implements FieldOptions {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
/*
|
||||||
|
* UQAM-Linguistic-Management
|
||||||
|
* This method is polymorphism of getOptions(EditConfigurationVTwo editConfig,String fieldName, WebappDaoFactory wDaoFact)
|
||||||
|
* for the internationalization of word "other" in the scroling list of personHasAdvisorRelationship.ftl
|
||||||
|
*/
|
||||||
public Map<String, String> getOptions(
|
public Map<String, String> getOptions(
|
||||||
EditConfigurationVTwo editConfig,
|
EditConfigurationVTwo editConfig,
|
||||||
String fieldName,
|
String fieldName,
|
||||||
WebappDaoFactory wDaoFact) throws Exception {
|
WebappDaoFactory wDaoFact,
|
||||||
|
I18nBundle i18n) throws Exception {
|
||||||
HashMap <String,String> optionsMap = new LinkedHashMap<String,String>();
|
HashMap <String,String> optionsMap = new LinkedHashMap<String,String>();
|
||||||
// first test to see whether there's a default "leave blank" value specified with the literal options
|
// first test to see whether there's a default "leave blank" value specified with the literal options
|
||||||
if ( ! StringUtils.isEmpty( defaultOptionLabel ) ){
|
if ( ! StringUtils.isEmpty( defaultOptionLabel ) ){
|
||||||
optionsMap.put(LEFT_BLANK, defaultOptionLabel);
|
optionsMap.put(LEFT_BLANK, defaultOptionLabel);
|
||||||
}
|
}
|
||||||
|
String other_i18n = i18n.text("other");
|
||||||
optionsMap.put(classUri, "Other");
|
// first character in capital
|
||||||
|
optionsMap.put(classUri, other_i18n.substring(0, 1).toUpperCase() + other_i18n.substring(1));
|
||||||
VClassDao vclassDao = wDaoFact.getVClassDao();
|
VClassDao vclassDao = wDaoFact.getVClassDao();
|
||||||
List<String> subClassList = vclassDao.getAllSubClassURIs(classUri);
|
List<String> subClassList = vclassDao.getAllSubClassURIs(classUri);
|
||||||
if (subClassList != null && subClassList.size() > 0) {
|
if (subClassList != null && subClassList.size() > 0) {
|
||||||
|
|
|
@ -10,6 +10,7 @@ import java.util.Map;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.i18n.I18nBundle;
|
||||||
|
|
||||||
public class ConstantFieldOptions implements FieldOptions {
|
public class ConstantFieldOptions implements FieldOptions {
|
||||||
|
|
||||||
|
@ -54,7 +55,8 @@ public class ConstantFieldOptions implements FieldOptions {
|
||||||
public Map<String, String> getOptions(
|
public Map<String, String> getOptions(
|
||||||
EditConfigurationVTwo editConfig,
|
EditConfigurationVTwo editConfig,
|
||||||
String fieldName,
|
String fieldName,
|
||||||
WebappDaoFactory wDaoFact) throws Exception {
|
WebappDaoFactory wDaoFact,
|
||||||
|
I18nBundle i18n) throws Exception {
|
||||||
// originally not auto-sorted but sorted now, and empty values not removed or replaced
|
// originally not auto-sorted but sorted now, and empty values not removed or replaced
|
||||||
HashMap <String,String> optionsMap = new LinkedHashMap<String,String>();
|
HashMap <String,String> optionsMap = new LinkedHashMap<String,String>();
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ import java.util.Map;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.i18n.I18nBundle;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents an object that can return a list of options
|
* Represents an object that can return a list of options
|
||||||
|
@ -28,7 +29,8 @@ public interface FieldOptions {
|
||||||
public Map<String,String> getOptions(
|
public Map<String,String> getOptions(
|
||||||
EditConfigurationVTwo editConfig,
|
EditConfigurationVTwo editConfig,
|
||||||
String fieldName,
|
String fieldName,
|
||||||
WebappDaoFactory wDaoFact) throws Exception;
|
WebappDaoFactory wDaoFact,
|
||||||
|
I18nBundle i18n) throws Exception;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Certain field options may have custom sorting requirements. If no sorting requirements exist,
|
* Certain field options may have custom sorting requirements. If no sorting requirements exist,
|
||||||
|
|
|
@ -6,6 +6,7 @@ import java.util.Map;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.i18n.I18nBundle;
|
||||||
|
|
||||||
public class IndividualsViaClassGroupOptions implements FieldOptions {
|
public class IndividualsViaClassGroupOptions implements FieldOptions {
|
||||||
|
|
||||||
|
@ -27,7 +28,8 @@ public class IndividualsViaClassGroupOptions implements FieldOptions {
|
||||||
public Map<String, String> getOptions(
|
public Map<String, String> getOptions(
|
||||||
EditConfigurationVTwo editConfig,
|
EditConfigurationVTwo editConfig,
|
||||||
String fieldName,
|
String fieldName,
|
||||||
WebappDaoFactory wDaoFact) throws Exception {
|
WebappDaoFactory wDaoFact,
|
||||||
|
I18nBundle i18n) throws Exception {
|
||||||
throw new Error("not implemented");
|
throw new Error("not implemented");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@ import java.util.Map;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.i18n.I18nBundle;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
|
@ -77,7 +78,8 @@ public class IndividualsViaObjectPropetyOptions implements FieldOptions {
|
||||||
public Map<String, String> getOptions(
|
public Map<String, String> getOptions(
|
||||||
EditConfigurationVTwo editConfig,
|
EditConfigurationVTwo editConfig,
|
||||||
String fieldName,
|
String fieldName,
|
||||||
WebappDaoFactory wDaoFact) {
|
WebappDaoFactory wDaoFact,
|
||||||
|
I18nBundle i18n) {
|
||||||
HashMap<String, String> optionsMap = new LinkedHashMap<String, String>();
|
HashMap<String, String> optionsMap = new LinkedHashMap<String, String>();
|
||||||
int optionsCount = 0;
|
int optionsCount = 0;
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ import java.util.List;
|
||||||
import java.util.ListIterator;
|
import java.util.ListIterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.i18n.I18nBundle;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
|
@ -90,7 +91,8 @@ public class IndividualsViaSearchQueryOptions extends IndividualsViaVClassOption
|
||||||
public Map<String, String> getOptions(
|
public Map<String, String> getOptions(
|
||||||
EditConfigurationVTwo editConfig,
|
EditConfigurationVTwo editConfig,
|
||||||
String fieldName,
|
String fieldName,
|
||||||
WebappDaoFactory wDaoFact) throws Exception {
|
WebappDaoFactory wDaoFact,
|
||||||
|
I18nBundle i18n) throws Exception {
|
||||||
|
|
||||||
Map<String, Individual> individualMap = new HashMap<String, Individual>();
|
Map<String, Individual> individualMap = new HashMap<String, Individual>();
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.i18n.I18nBundle;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
|
@ -48,7 +49,8 @@ public class IndividualsViaVClassOptions implements FieldOptions {
|
||||||
public Map<String, String> getOptions(
|
public Map<String, String> getOptions(
|
||||||
EditConfigurationVTwo editConfig,
|
EditConfigurationVTwo editConfig,
|
||||||
String fieldName,
|
String fieldName,
|
||||||
WebappDaoFactory wDaoFact) throws Exception {
|
WebappDaoFactory wDaoFact,
|
||||||
|
I18nBundle i18n) throws Exception {
|
||||||
|
|
||||||
Map<String, Individual> individualMap = new HashMap<String, Individual>();
|
Map<String, Individual> individualMap = new HashMap<String, Individual>();
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@ import java.util.Map;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
|
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.i18n.I18nBundle;
|
||||||
|
|
||||||
public class RdfTypeOptions implements FieldOptions {
|
public class RdfTypeOptions implements FieldOptions {
|
||||||
|
|
||||||
|
@ -29,7 +30,8 @@ public class RdfTypeOptions implements FieldOptions {
|
||||||
public Map<String, String> getOptions(
|
public Map<String, String> getOptions(
|
||||||
EditConfigurationVTwo editConfig,
|
EditConfigurationVTwo editConfig,
|
||||||
String fieldName,
|
String fieldName,
|
||||||
WebappDaoFactory wdf) {
|
WebappDaoFactory wdf,
|
||||||
|
I18nBundle i18n) {
|
||||||
Map<String,String> uriToLabel = new HashMap<String,String>();
|
Map<String,String> uriToLabel = new HashMap<String,String>();
|
||||||
|
|
||||||
for (String uri : typeURIs) {
|
for (String uri : typeURIs) {
|
||||||
|
|
|
@ -11,6 +11,8 @@ import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.i18n.I18n;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.i18n.I18nBundle;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
|
@ -25,7 +27,8 @@ public class SelectListGeneratorVTwo {
|
||||||
public static Map<String,String> getOptions(
|
public static Map<String,String> getOptions(
|
||||||
EditConfigurationVTwo editConfig,
|
EditConfigurationVTwo editConfig,
|
||||||
String fieldName,
|
String fieldName,
|
||||||
WebappDaoFactory wDaoFact){
|
WebappDaoFactory wDaoFact,
|
||||||
|
I18nBundle i18n){
|
||||||
|
|
||||||
|
|
||||||
if( editConfig == null ){
|
if( editConfig == null ){
|
||||||
|
@ -48,7 +51,45 @@ public class SelectListGeneratorVTwo {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return field.getFieldOptions().getOptions(editConfig,fieldName,wDaoFact);
|
return field.getFieldOptions().getOptions(editConfig,fieldName,wDaoFact,i18n);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Error runing getFieldOptionis()",e);
|
||||||
|
return Collections.emptyMap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// UQAM Overcharge method for linguistic contexte processisng
|
||||||
|
// AWoods: This method appears to never be invoked.
|
||||||
|
public static Map<String,String> getOptions(
|
||||||
|
EditConfigurationVTwo editConfig,
|
||||||
|
String fieldName,
|
||||||
|
VitroRequest vreq){
|
||||||
|
|
||||||
|
|
||||||
|
if( editConfig == null ){
|
||||||
|
log.error( "fieldToSelectItemList() must be called with a non-null EditConfigurationVTwo ");
|
||||||
|
return Collections.emptyMap();
|
||||||
|
}
|
||||||
|
if( fieldName == null ){
|
||||||
|
log.error( "fieldToSelectItemList() must be called with a non-null fieldName");
|
||||||
|
return Collections.emptyMap();
|
||||||
|
}
|
||||||
|
|
||||||
|
FieldVTwo field = editConfig.getField(fieldName);
|
||||||
|
if (field==null) {
|
||||||
|
log.error("no field \""+fieldName+"\" found from editConfig.");
|
||||||
|
return Collections.emptyMap();
|
||||||
|
}
|
||||||
|
|
||||||
|
if( field.getFieldOptions() == null ){
|
||||||
|
return Collections.emptyMap();
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
//UQAM need vreq instead of WebappDaoFactory
|
||||||
|
Map<String, String> parentClass = Collections.emptyMap();
|
||||||
|
FieldOptions fieldOptions = field.getFieldOptions();
|
||||||
|
return fieldOptions.getOptions(editConfig,fieldName,vreq.getWebappDaoFactory(), I18n.bundle(vreq));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Error runing getFieldOptionis()",e);
|
log.error("Error runing getFieldOptionis()",e);
|
||||||
return Collections.emptyMap();
|
return Collections.emptyMap();
|
||||||
|
|
|
@ -16,6 +16,7 @@ import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTw
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.IdModelSelector;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.IdModelSelector;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.StandardModelSelector;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.StandardModelSelector;
|
||||||
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess;
|
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess.LanguageOption;
|
||||||
|
|
||||||
public abstract class BaseEditConfigurationGenerator implements EditConfigurationGenerator {
|
public abstract class BaseEditConfigurationGenerator implements EditConfigurationGenerator {
|
||||||
|
|
||||||
|
@ -63,6 +64,7 @@ public abstract class BaseEditConfigurationGenerator implements EditConfiguratio
|
||||||
setupModelSelectorsFromVitroRequest(vreq, editConfig);
|
setupModelSelectorsFromVitroRequest(vreq, editConfig);
|
||||||
|
|
||||||
OntModel queryModel = ModelAccess.on(vreq).getOntModel();
|
OntModel queryModel = ModelAccess.on(vreq).getOntModel();
|
||||||
|
OntModel languageNeutralModel = vreq.getLanguageNeutralUnionFullModel();
|
||||||
|
|
||||||
if( editConfig.getSubjectUri() == null)
|
if( editConfig.getSubjectUri() == null)
|
||||||
editConfig.setSubjectUri( EditConfigurationUtils.getSubjectUri(vreq));
|
editConfig.setSubjectUri( EditConfigurationUtils.getSubjectUri(vreq));
|
||||||
|
@ -78,7 +80,10 @@ public abstract class BaseEditConfigurationGenerator implements EditConfiguratio
|
||||||
editConfig.prepareForObjPropUpdate(queryModel);
|
editConfig.prepareForObjPropUpdate(queryModel);
|
||||||
} else if( dataKey != null ) { // edit of a data prop statement
|
} else if( dataKey != null ) { // edit of a data prop statement
|
||||||
//do nothing since the data prop form generator must take care of it
|
//do nothing since the data prop form generator must take care of it
|
||||||
editConfig.prepareForDataPropUpdate(queryModel, vreq.getWebappDaoFactory().getDataPropertyDao());
|
// Use language-neutral model to ensure that a data property statement
|
||||||
|
// is found for any literal hash, even if the UI locale is changed.
|
||||||
|
editConfig.prepareForDataPropUpdate(languageNeutralModel,
|
||||||
|
vreq.getWebappDaoFactory().getDataPropertyDao());
|
||||||
} else{
|
} else{
|
||||||
//this might be a create new or a form
|
//this might be a create new or a form
|
||||||
editConfig.prepareForNonUpdate(queryModel);
|
editConfig.prepareForNonUpdate(queryModel);
|
||||||
|
|
|
@ -350,7 +350,7 @@ public class DefaultAddMissingIndividualFormGenerator implements EditConfigurati
|
||||||
|
|
||||||
private void prepareForUpdate(VitroRequest vreq, HttpSession session, EditConfigurationVTwo editConfiguration) {
|
private void prepareForUpdate(VitroRequest vreq, HttpSession session, EditConfigurationVTwo editConfiguration) {
|
||||||
//Here, retrieve model from
|
//Here, retrieve model from
|
||||||
OntModel model = ModelAccess.on(session.getServletContext()).getOntModel();
|
OntModel model = ModelAccess.on(vreq).getOntModel();
|
||||||
//if object property
|
//if object property
|
||||||
if(EditConfigurationUtils.isObjectProperty(EditConfigurationUtils.getPredicateUri(vreq), vreq)){
|
if(EditConfigurationUtils.isObjectProperty(EditConfigurationUtils.getPredicateUri(vreq), vreq)){
|
||||||
Individual objectIndividual = EditConfigurationUtils.getObjectIndividual(vreq);
|
Individual objectIndividual = EditConfigurationUtils.getObjectIndividual(vreq);
|
||||||
|
|
|
@ -28,7 +28,9 @@ public class DefaultDeleteGenerator extends BaseEditConfigurationGenerator imple
|
||||||
private Integer dataHash = 0;
|
private Integer dataHash = 0;
|
||||||
private DataPropertyStatement dps = null;
|
private DataPropertyStatement dps = null;
|
||||||
private String dataLiteral = null;
|
private String dataLiteral = null;
|
||||||
private String template = "confirmDeletePropertyForm.ftl";
|
private String propertyTemplate = "confirmDeletePropertyForm.ftl";
|
||||||
|
private String individualTemplate = "confirmDeleteIndividualForm.ftl";
|
||||||
|
|
||||||
|
|
||||||
//In this case, simply return the edit configuration currently saved in session
|
//In this case, simply return the edit configuration currently saved in session
|
||||||
//Since this is forwarding from another form, an edit configuration should already exist in session
|
//Since this is forwarding from another form, an edit configuration should already exist in session
|
||||||
|
@ -43,12 +45,32 @@ public class DefaultDeleteGenerator extends BaseEditConfigurationGenerator imple
|
||||||
if(editConfiguration == null) {
|
if(editConfiguration == null) {
|
||||||
editConfiguration = setupEditConfiguration(vreq, session);
|
editConfiguration = setupEditConfiguration(vreq, session);
|
||||||
}
|
}
|
||||||
editConfiguration.setTemplate(template);
|
|
||||||
//prepare update?
|
//prepare update?
|
||||||
prepare(vreq, editConfiguration);
|
prepare(vreq, editConfiguration);
|
||||||
|
if (editConfiguration.getPredicateUri() == null && editConfiguration.getSubjectUri() == null) {
|
||||||
|
editConfiguration.setTemplate(individualTemplate);
|
||||||
|
addDeleteParams(vreq, editConfiguration);
|
||||||
|
}else {
|
||||||
|
editConfiguration.setTemplate(propertyTemplate);
|
||||||
|
}
|
||||||
return editConfiguration;
|
return editConfiguration;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void addDeleteParams(VitroRequest vreq, EditConfigurationVTwo editConfiguration) {
|
||||||
|
String redirectUrl = vreq.getParameter("redirectUrl");
|
||||||
|
if (redirectUrl != null) {
|
||||||
|
editConfiguration.addFormSpecificData("redirectUrl", redirectUrl);
|
||||||
|
}
|
||||||
|
String individualName = vreq.getParameter("individualName");
|
||||||
|
if (redirectUrl != null) {
|
||||||
|
editConfiguration.addFormSpecificData("individualName", individualName);
|
||||||
|
}
|
||||||
|
String individualType = vreq.getParameter("individualType");
|
||||||
|
if (redirectUrl != null) {
|
||||||
|
editConfiguration.addFormSpecificData("individualType", individualType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private EditConfigurationVTwo setupEditConfiguration(VitroRequest vreq, HttpSession session) {
|
private EditConfigurationVTwo setupEditConfiguration(VitroRequest vreq, HttpSession session) {
|
||||||
EditConfigurationVTwo editConfiguration = new EditConfigurationVTwo();
|
EditConfigurationVTwo editConfiguration = new EditConfigurationVTwo();
|
||||||
initProcessParameters(vreq, session, editConfiguration);
|
initProcessParameters(vreq, session, editConfiguration);
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators;
|
package edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators;
|
||||||
|
|
||||||
|
import static edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess.LANGUAGE_NEUTRAL;
|
||||||
|
import static edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess.POLICY_NEUTRAL;
|
||||||
import static edu.cornell.mannlib.vitro.webapp.modelaccess.ModelNames.DISPLAY;
|
import static edu.cornell.mannlib.vitro.webapp.modelaccess.ModelNames.DISPLAY;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -35,6 +37,8 @@ import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.IndividualsVi
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.validators.AntiXssValidation;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.validators.AntiXssValidation;
|
||||||
import edu.cornell.mannlib.vitro.webapp.i18n.I18n;
|
import edu.cornell.mannlib.vitro.webapp.i18n.I18n;
|
||||||
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess;
|
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess.LanguageOption;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess.PolicyOption;
|
||||||
import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngine;
|
import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngine;
|
||||||
import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngineException;
|
import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngineException;
|
||||||
import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchQuery;
|
import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchQuery;
|
||||||
|
@ -125,7 +129,10 @@ public class DefaultObjectPropertyFormGenerator implements EditConfigurationGene
|
||||||
// Someday we'll need to figure out a different way of doing this.
|
// Someday we'll need to figure out a different way of doing this.
|
||||||
//WebappDaoFactory ctxDaoFact = ModelAccess.on(
|
//WebappDaoFactory ctxDaoFact = ModelAccess.on(
|
||||||
// vreq.getSession().getServletContext()).getWebappDaoFactory();
|
// vreq.getSession().getServletContext()).getWebappDaoFactory();
|
||||||
WebappDaoFactory ctxDaoFact = vreq.getLanguageNeutralWebappDaoFactory();
|
// WebappDaoFactory ctxDaoFact = vreq.getLanguageNeutralWebappDaoFactory();
|
||||||
|
//UQAM Linguistic-Management Manage linguistic context
|
||||||
|
WebappDaoFactory ctxDaoFact = ModelAccess.on(vreq).getWebappDaoFactory(LanguageOption.LANGUAGE_AWARE, PolicyOption.POLICY_NEUTRAL);
|
||||||
|
|
||||||
|
|
||||||
List<VClass> types = new ArrayList<VClass>();
|
List<VClass> types = new ArrayList<VClass>();
|
||||||
Individual subject = EditConfigurationUtils.getSubjectIndividual(vreq);
|
Individual subject = EditConfigurationUtils.getSubjectIndividual(vreq);
|
||||||
|
@ -460,7 +467,7 @@ public class DefaultObjectPropertyFormGenerator implements EditConfigurationGene
|
||||||
|
|
||||||
private void prepareForUpdate(VitroRequest vreq, HttpSession session, EditConfigurationVTwo editConfiguration) {
|
private void prepareForUpdate(VitroRequest vreq, HttpSession session, EditConfigurationVTwo editConfiguration) {
|
||||||
//Here, retrieve model from
|
//Here, retrieve model from
|
||||||
OntModel model = ModelAccess.on(session.getServletContext()).getOntModel();
|
OntModel model = ModelAccess.on(vreq).getOntModel();
|
||||||
//if object property
|
//if object property
|
||||||
if(EditConfigurationUtils.isObjectProperty(EditConfigurationUtils.getPredicateUri(vreq), vreq)){
|
if(EditConfigurationUtils.isObjectProperty(EditConfigurationUtils.getPredicateUri(vreq), vreq)){
|
||||||
Individual objectIndividual = EditConfigurationUtils.getObjectIndividual(vreq);
|
Individual objectIndividual = EditConfigurationUtils.getObjectIndividual(vreq);
|
||||||
|
|
|
@ -15,6 +15,7 @@ import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.servlet.http.HttpSession;
|
import javax.servlet.http.HttpSession;
|
||||||
|
|
||||||
|
@ -41,6 +42,7 @@ import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.FoafNameToRdfsLabelPreprocessor;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.FoafNameToRdfsLabelPreprocessor;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.ManageLabelsForIndividualPreprocessor;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.ManageLabelsForIndividualPreprocessor;
|
||||||
import edu.cornell.mannlib.vitro.webapp.i18n.selection.SelectedLocale;
|
import edu.cornell.mannlib.vitro.webapp.i18n.selection.SelectedLocale;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.filter.LanguageFilteringUtils;
|
||||||
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.DataPropertyStatementTemplateModel;
|
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.DataPropertyStatementTemplateModel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -202,12 +204,12 @@ public class ManageLabelsForIndividualGenerator extends BaseEditConfigurationGen
|
||||||
|
|
||||||
private void addFormSpecificData(EditConfigurationVTwo config,
|
private void addFormSpecificData(EditConfigurationVTwo config,
|
||||||
VitroRequest vreq) {
|
VitroRequest vreq) {
|
||||||
//Get all language codes/labels in the system, and this list is sorted by language name
|
|
||||||
List<HashMap<String, String>> locales = this.getLocales(vreq);
|
|
||||||
//Get code to label hashmap - we use this to get the language name for the language code returned in the rdf literal
|
|
||||||
HashMap<String, String> localeCodeToNameMap = this.getFullCodeToLanguageNameMap(locales);
|
|
||||||
//the labels already added by the user
|
//the labels already added by the user
|
||||||
ArrayList<Literal> existingLabels = this.getExistingLabels(config.getSubjectUri(), vreq);
|
ArrayList<Literal> existingLabels = this.getExistingLabels(config.getSubjectUri(), vreq);
|
||||||
|
//Get language codes/labels for languages present in the existing labels
|
||||||
|
List<HashMap<String, String>> locales = this.getLocales(vreq, existingLabels);
|
||||||
|
//Get code to label hashmap - we use this to get the language name for the language code returned in the rdf literal
|
||||||
|
HashMap<String, String> localeCodeToNameMap = this.getFullCodeToLanguageNameMap(locales);
|
||||||
int numberExistingLabels = existingLabels.size();
|
int numberExistingLabels = existingLabels.size();
|
||||||
//existing labels keyed by language name and each of the list of labels is sorted by language name
|
//existing labels keyed by language name and each of the list of labels is sorted by language name
|
||||||
HashMap<String, List<LabelInformation>> existingLabelsByLanguageName = this.getLabelsSortedByLanguageName(existingLabels, localeCodeToNameMap, config, vreq);
|
HashMap<String, List<LabelInformation>> existingLabelsByLanguageName = this.getLabelsSortedByLanguageName(existingLabels, localeCodeToNameMap, config, vreq);
|
||||||
|
@ -224,6 +226,20 @@ public class ManageLabelsForIndividualGenerator extends BaseEditConfigurationGen
|
||||||
config.addFormSpecificData("displayRemoveLink", (numberExistingLabels > 1));
|
config.addFormSpecificData("displayRemoveLink", (numberExistingLabels > 1));
|
||||||
|
|
||||||
|
|
||||||
|
// get current selected locale
|
||||||
|
String rangeLang = vreq.getLocale().getLanguage();
|
||||||
|
if (!vreq.getLocale().getCountry().isEmpty()) {
|
||||||
|
rangeLang += "-" + vreq.getLocale().getCountry();
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if locale already has an entry (label)
|
||||||
|
boolean localeEntryExisting = true;
|
||||||
|
for (HashMap<String, String> tmp : availableLocalesForAdd) {
|
||||||
|
if (tmp.get("code").equals(rangeLang)) localeEntryExisting = false;
|
||||||
|
}
|
||||||
|
config.addFormSpecificData("localeEntryExisting", localeEntryExisting);
|
||||||
|
config.addFormSpecificData("currentSelectedLocale", rangeLang);
|
||||||
|
|
||||||
//How do we edit? Will need to see
|
//How do we edit? Will need to see
|
||||||
config.addFormSpecificData("deleteWebpageUrl", "/edit/primitiveDelete");
|
config.addFormSpecificData("deleteWebpageUrl", "/edit/primitiveDelete");
|
||||||
|
|
||||||
|
@ -359,8 +375,9 @@ public class ManageLabelsForIndividualGenerator extends BaseEditConfigurationGen
|
||||||
|
|
||||||
ArrayList<Literal> labels = new ArrayList<Literal>();
|
ArrayList<Literal> labels = new ArrayList<Literal>();
|
||||||
try {
|
try {
|
||||||
//We want to get the labels for all the languages, not just the display language
|
// Get results filtered to current locale so as to be consistent
|
||||||
ResultSet results = QueryUtils.getLanguageNeutralQueryResults(queryStr, vreq);
|
// with other editing forms.
|
||||||
|
ResultSet results = QueryUtils.getQueryResults(queryStr, vreq);
|
||||||
while (results.hasNext()) {
|
while (results.hasNext()) {
|
||||||
QuerySolution soln = results.nextSolution();
|
QuerySolution soln = results.nextSolution();
|
||||||
Literal nodeLiteral = soln.get("label").asLiteral();
|
Literal nodeLiteral = soln.get("label").asLiteral();
|
||||||
|
@ -387,30 +404,32 @@ public class ManageLabelsForIndividualGenerator extends BaseEditConfigurationGen
|
||||||
return template;
|
return template;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//get locales present in list of literals
|
||||||
|
public List<HashMap<String, String>> getLocales(VitroRequest vreq,
|
||||||
//get locales
|
List<Literal> existingLiterals) {
|
||||||
public List<HashMap<String, String>> getLocales(VitroRequest vreq) {
|
Set<Locale> locales = new HashSet<Locale>();
|
||||||
List<Locale> selectables = SelectedLocale.getSelectableLocales(vreq);
|
for(Literal literal : existingLiterals) {
|
||||||
if (selectables.isEmpty()) {
|
String language = literal.getLanguage();
|
||||||
|
if(!StringUtils.isEmpty(language)) {
|
||||||
|
locales.add(LanguageFilteringUtils.languageToLocale(language));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (locales.isEmpty()) {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
List<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
|
List<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
|
||||||
Locale currentLocale = SelectedLocale.getCurrentLocale(vreq);
|
Locale currentLocale = SelectedLocale.getCurrentLocale(vreq);
|
||||||
for (Locale locale : selectables) {
|
for (Locale locale : locales) {
|
||||||
try {
|
try {
|
||||||
list.add(buildLocaleMap(locale, currentLocale));
|
list.add(buildLocaleMap(locale, currentLocale));
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
log.warn("Can't show the Locale selector for '" + locale
|
log.warn("Can't show locale '" + locale + "': " + e);
|
||||||
+ "': " + e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public HashMap<String, String> getFullCodeToLanguageNameMap(List<HashMap<String, String>> localesList) {
|
public HashMap<String, String> getFullCodeToLanguageNameMap(List<HashMap<String, String>> localesList) {
|
||||||
HashMap<String, String> codeToLanguageMap = new HashMap<String, String>();
|
HashMap<String, String> codeToLanguageMap = new HashMap<String, String>();
|
||||||
for(Map<String, String> locale: localesList) {
|
for(Map<String, String> locale: localesList) {
|
||||||
|
|
|
@ -233,7 +233,7 @@ public class NewIndividualFormGenerator implements EditConfigurationGenerator {
|
||||||
|
|
||||||
private void prepareForUpdate(VitroRequest vreq, HttpSession session, EditConfigurationVTwo editConfiguration) {
|
private void prepareForUpdate(VitroRequest vreq, HttpSession session, EditConfigurationVTwo editConfiguration) {
|
||||||
//Here, retrieve model from
|
//Here, retrieve model from
|
||||||
OntModel model = ModelAccess.on(session.getServletContext()).getOntModel();
|
OntModel model = ModelAccess.on(vreq).getOntModel();
|
||||||
//This form is always doing a non-update
|
//This form is always doing a non-update
|
||||||
editConfiguration.prepareForNonUpdate( model );
|
editConfiguration.prepareForNonUpdate( model );
|
||||||
|
|
||||||
|
|
|
@ -298,7 +298,7 @@ public class RDFSLabelGenerator implements EditConfigurationGenerator {
|
||||||
|
|
||||||
private void prepareForUpdate(VitroRequest vreq, HttpSession session, EditConfigurationVTwo editConfiguration) {
|
private void prepareForUpdate(VitroRequest vreq, HttpSession session, EditConfigurationVTwo editConfiguration) {
|
||||||
//Here, retrieve model from
|
//Here, retrieve model from
|
||||||
OntModel model = ModelAccess.on(session.getServletContext()).getOntModel();
|
OntModel model = ModelAccess.on(vreq).getOntModel();
|
||||||
if( editConfiguration.isDataPropertyUpdate() ){
|
if( editConfiguration.isDataPropertyUpdate() ){
|
||||||
editConfiguration.prepareForDataPropUpdate(model, vreq.getWebappDaoFactory().getDataPropertyDao());
|
editConfiguration.prepareForDataPropUpdate(model, vreq.getWebappDaoFactory().getDataPropertyDao());
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,92 @@
|
||||||
|
package edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.apache.jena.rdf.model.Literal;
|
||||||
|
import org.apache.jena.rdf.model.Model;
|
||||||
|
import org.apache.jena.rdf.model.RDFNode;
|
||||||
|
import org.apache.jena.rdf.model.Statement;
|
||||||
|
import org.apache.jena.rdf.model.StmtIterator;
|
||||||
|
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.filter.LanguageFilteringUtils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A model change preprocessor that discards triples with language tags
|
||||||
|
* in the retractionsModel that do not match the specified language, unless
|
||||||
|
* the additionsModel also contains a new value for the same subject and
|
||||||
|
* predicate in that language, or no values in any language are added for the
|
||||||
|
* same subject and predicate (such as when an entire resource is deleted) .
|
||||||
|
*/
|
||||||
|
public class LimitRemovalsToLanguage implements ModelChangePreprocessor {
|
||||||
|
|
||||||
|
private static final Log log = LogFactory.getLog(LimitRemovalsToLanguage.class);
|
||||||
|
private String language;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param locale the Java locale object representing the language
|
||||||
|
* to which edits should be limited. May not be null.
|
||||||
|
*/
|
||||||
|
public LimitRemovalsToLanguage(Locale locale) {
|
||||||
|
if(locale == null) {
|
||||||
|
throw new IllegalArgumentException("Locale may not be null.");
|
||||||
|
}
|
||||||
|
this.language = LanguageFilteringUtils.localeToLanguage(locale);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param language string representing the RDF language tag to which
|
||||||
|
* edits should be limited. May not be null.
|
||||||
|
*/
|
||||||
|
public LimitRemovalsToLanguage(String language) {
|
||||||
|
if(language == null) {
|
||||||
|
throw new IllegalArgumentException("Language may not be null.");
|
||||||
|
}
|
||||||
|
this.language = language;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void preprocess(Model retractionsModel, Model additionsModel,
|
||||||
|
HttpServletRequest request) {
|
||||||
|
log.debug("limiting changes to " + language);
|
||||||
|
List<Statement> eliminatedRetractions = new ArrayList<Statement>();
|
||||||
|
StmtIterator sit = retractionsModel.listStatements();
|
||||||
|
while(sit.hasNext()) {
|
||||||
|
Statement stmt = sit.next();
|
||||||
|
if(stmt.getObject().isLiteral()) {
|
||||||
|
Literal lit = stmt.getObject().asLiteral();
|
||||||
|
if(!StringUtils.isEmpty(lit.getLanguage())
|
||||||
|
&& !lit.getLanguage().equals(language)) {
|
||||||
|
boolean eliminateRetraction = true;
|
||||||
|
StmtIterator replacements = additionsModel
|
||||||
|
.listStatements(stmt.getSubject(),
|
||||||
|
stmt.getPredicate(), (RDFNode) null);
|
||||||
|
if(!replacements.hasNext()) {
|
||||||
|
eliminateRetraction = false;
|
||||||
|
} else {
|
||||||
|
while(replacements.hasNext()) {
|
||||||
|
Statement replacement = replacements.next();
|
||||||
|
if(replacement.getObject().isLiteral()
|
||||||
|
&& lit.getLanguage().equals(replacement
|
||||||
|
.getObject().asLiteral()
|
||||||
|
.getLanguage())) {
|
||||||
|
eliminateRetraction = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(eliminateRetraction) {
|
||||||
|
eliminatedRetractions.add(stmt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
retractionsModel.remove(eliminatedRetractions);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -11,6 +11,7 @@ import javax.servlet.annotation.WebServlet;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import javax.servlet.http.HttpSession;
|
import javax.servlet.http.HttpSession;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.apache.jena.ontology.OntModel;
|
import org.apache.jena.ontology.OntModel;
|
||||||
|
@ -67,9 +68,19 @@ public class EditRequestDispatchController extends FreemarkerHttpServlet {
|
||||||
//TODO: Create this generator
|
//TODO: Create this generator
|
||||||
final String RDFS_LABEL_FORM = "edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.RDFSLabelGenerator";
|
final String RDFS_LABEL_FORM = "edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.RDFSLabelGenerator";
|
||||||
final String DEFAULT_DELETE_FORM = "edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.DefaultDeleteGenerator";
|
final String DEFAULT_DELETE_FORM = "edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.DefaultDeleteGenerator";
|
||||||
|
final String MANAGE_MENUS_FORM = "edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.ManagePageGenerator";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AuthorizationRequest requiredActions(VitroRequest vreq) {
|
protected AuthorizationRequest requiredActions(VitroRequest vreq) {
|
||||||
|
// If request is for new individual, return simple do back end editing action permission
|
||||||
|
if (StringUtils.isNotEmpty(EditConfigurationUtils.getTypeOfNew(vreq))) {
|
||||||
|
return SimplePermission.DO_BACK_END_EDITING.ACTION;
|
||||||
|
} else if(MANAGE_MENUS_FORM.equals(vreq.getParameter("editForm"))) {
|
||||||
|
return SimplePermission.MANAGE_MENUS.ACTION;
|
||||||
|
}
|
||||||
|
if (isIndividualDeletion(vreq)) {
|
||||||
|
return SimplePermission.DO_BACK_END_EDITING.ACTION;
|
||||||
|
}
|
||||||
// Check if this statement can be edited here and return unauthorized if not
|
// Check if this statement can be edited here and return unauthorized if not
|
||||||
String subjectUri = EditConfigurationUtils.getSubjectUri(vreq);
|
String subjectUri = EditConfigurationUtils.getSubjectUri(vreq);
|
||||||
String predicateUri = EditConfigurationUtils.getPredicateUri(vreq);
|
String predicateUri = EditConfigurationUtils.getPredicateUri(vreq);
|
||||||
|
@ -98,6 +109,16 @@ public class EditRequestDispatchController extends FreemarkerHttpServlet {
|
||||||
return isAuthorized? SimplePermission.DO_FRONT_END_EDITING.ACTION: AuthorizationRequest.UNAUTHORIZED;
|
return isAuthorized? SimplePermission.DO_FRONT_END_EDITING.ACTION: AuthorizationRequest.UNAUTHORIZED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isIndividualDeletion(VitroRequest vreq) {
|
||||||
|
String subjectUri = EditConfigurationUtils.getSubjectUri(vreq);
|
||||||
|
String predicateUri = EditConfigurationUtils.getPredicateUri(vreq);
|
||||||
|
String objectUri = EditConfigurationUtils.getObjectUri(vreq);
|
||||||
|
if (objectUri != null && subjectUri == null && predicateUri == null && isDeleteForm(vreq)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ResponseValues processRequest(VitroRequest vreq) {
|
protected ResponseValues processRequest(VitroRequest vreq) {
|
||||||
|
|
||||||
|
@ -148,7 +169,7 @@ public class EditRequestDispatchController extends FreemarkerHttpServlet {
|
||||||
templateData.put("editConfiguration", etm);
|
templateData.put("editConfiguration", etm);
|
||||||
templateData.put("editSubmission", submissionTemplateModel);
|
templateData.put("editSubmission", submissionTemplateModel);
|
||||||
//Corresponding to original note for consistency with selenium tests and 1.1.1
|
//Corresponding to original note for consistency with selenium tests and 1.1.1
|
||||||
templateData.put("title", "Edit");
|
templateData.put("title", etm.getPageTitle());
|
||||||
templateData.put("submitUrl", getSubmissionUrl(vreq));
|
templateData.put("submitUrl", getSubmissionUrl(vreq));
|
||||||
templateData.put("cancelUrl", etm.getCancelUrl());
|
templateData.put("cancelUrl", etm.getCancelUrl());
|
||||||
templateData.put("editKey", editConfig.getEditKey());
|
templateData.put("editKey", editConfig.getEditKey());
|
||||||
|
@ -355,7 +376,7 @@ public class EditRequestDispatchController extends FreemarkerHttpServlet {
|
||||||
String predicateUri = EditConfigurationUtils.getPredicateUri(vreq);
|
String predicateUri = EditConfigurationUtils.getPredicateUri(vreq);
|
||||||
String formParam = getFormParam(vreq);
|
String formParam = getFormParam(vreq);
|
||||||
//if no form parameter, then predicate uri and subject uri must both be populated
|
//if no form parameter, then predicate uri and subject uri must both be populated
|
||||||
if (formParam == null || "".equals(formParam)) {
|
if ((formParam == null || "".equals(formParam)) && !isDeleteForm(vreq)) {
|
||||||
if ((predicateUri == null || predicateUri.trim().length() == 0)) {
|
if ((predicateUri == null || predicateUri.trim().length() == 0)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,7 +76,9 @@ public class PostEditCleanupController extends FreemarkerHttpServlet{
|
||||||
if( entityToReturnTo == null ){
|
if( entityToReturnTo == null ){
|
||||||
// this will not work if there entityToReturnTo has a new resource URI,
|
// this will not work if there entityToReturnTo has a new resource URI,
|
||||||
// in that case entityToReturnTo should not have been passed to this method as null
|
// in that case entityToReturnTo should not have been passed to this method as null
|
||||||
MultiValueEditSubmission submission = new MultiValueEditSubmission(vreq.getParameterMap(), editConfig);
|
// UQAM-Linguistic-Management
|
||||||
|
// MultiValueEditSubmission submission = new MultiValueEditSubmission(vreq.getParameterMap(), editConfig);
|
||||||
|
MultiValueEditSubmission submission = new MultiValueEditSubmission(vreq, editConfig);
|
||||||
entityToReturnTo = N3EditUtils.processEntityToReturnTo(editConfig, submission, vreq);
|
entityToReturnTo = N3EditUtils.processEntityToReturnTo(editConfig, submission, vreq);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,10 +8,11 @@ import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.servlet.annotation.WebServlet;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
import org.apache.jena.rdf.model.Literal;
|
import org.apache.jena.rdf.model.Literal;
|
||||||
import org.apache.jena.rdf.model.Model;
|
import org.apache.jena.rdf.model.Model;
|
||||||
import org.apache.jena.rdf.model.Property;
|
import org.apache.jena.rdf.model.Property;
|
||||||
|
@ -37,8 +38,7 @@ import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.MultiValueEditSubmis
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.N3EditUtils;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.N3EditUtils;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.ProcessRdfForm;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.ProcessRdfForm;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.RdfLiteralHash;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.RdfLiteralHash;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.LimitRemovalsToLanguage;
|
||||||
import javax.servlet.annotation.WebServlet;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This servlet will convert a request to an EditSubmission,
|
* This servlet will convert a request to an EditSubmission,
|
||||||
|
@ -66,7 +66,9 @@ public class ProcessRdfFormController extends FreemarkerHttpServlet{
|
||||||
return handleMissingConfiguration(vreq);
|
return handleMissingConfiguration(vreq);
|
||||||
|
|
||||||
//get the EditSubmission
|
//get the EditSubmission
|
||||||
MultiValueEditSubmission submission = new MultiValueEditSubmission(vreq.getParameterMap(), configuration);
|
// MultiValueEditSubmission submission = new MultiValueEditSubmission(vreq.getParameterMap(), configuration);
|
||||||
|
// Modified by UQAM-Linguistic-Management
|
||||||
|
MultiValueEditSubmission submission = new MultiValueEditSubmission(vreq, configuration);
|
||||||
EditSubmissionUtils.putEditSubmissionInSession(vreq.getSession(), submission);
|
EditSubmissionUtils.putEditSubmissionInSession(vreq.getSession(), submission);
|
||||||
|
|
||||||
//if errors, return error response
|
//if errors, return error response
|
||||||
|
@ -101,6 +103,9 @@ public class ProcessRdfFormController extends FreemarkerHttpServlet{
|
||||||
if( configuration.isUseDependentResourceDelete() )
|
if( configuration.isUseDependentResourceDelete() )
|
||||||
changes = ProcessRdfForm.addDependentDeletes(changes, queryModel);
|
changes = ProcessRdfForm.addDependentDeletes(changes, queryModel);
|
||||||
|
|
||||||
|
// prevent form from removing literals in languages other than the one
|
||||||
|
// associated with the current request
|
||||||
|
configuration.addModelChangePreprocessor(new LimitRemovalsToLanguage(vreq.getLocale()));
|
||||||
N3EditUtils.preprocessModels(changes, configuration, vreq);
|
N3EditUtils.preprocessModels(changes, configuration, vreq);
|
||||||
|
|
||||||
ProcessRdfForm.applyChangesToWriteModel(changes, queryModel, writeModel, N3EditUtils.getEditorUri(vreq) );
|
ProcessRdfForm.applyChangesToWriteModel(changes, queryModel, writeModel, N3EditUtils.getEditorUri(vreq) );
|
||||||
|
|
|
@ -254,4 +254,20 @@ public class UploadedFileHelper {
|
||||||
return !stmts.isEmpty();
|
return !stmts.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void removeUploadedFile(String subjectUri, String predicateUri, String fileUri) {
|
||||||
|
FileInfo fileInfo = FileInfo.instanceFromSurrogateUri(wadf, fileUri);
|
||||||
|
objectPropertyStatementDao
|
||||||
|
.deleteObjectPropertyStatement(new ObjectPropertyStatementImpl(subjectUri, predicateUri, fileUri));
|
||||||
|
deleteIfNotReferenced(fileInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void attachFileToSubject(FileInfo fileInfo, String subjectUri, String predicateUri) {
|
||||||
|
objectPropertyStatementDao
|
||||||
|
.insertNewObjectPropertyStatement(new ObjectPropertyStatementImpl(subjectUri, predicateUri, fileInfo.getUri()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPublicFileName(FileInfo fileInfo, String uploadedFileName) {
|
||||||
|
dataPropertyStatementDao.insertNewDataPropertyStatement(
|
||||||
|
new DataPropertyStatementImpl(fileInfo.getUri(), VitroVocabulary.PUBLIC_FILENAME, uploadedFileName));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,6 +35,7 @@ import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess;
|
||||||
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess.WhichService;
|
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess.WhichService;
|
||||||
import edu.cornell.mannlib.vitro.webapp.modelaccess.impl.RequestModelAccessImpl;
|
import edu.cornell.mannlib.vitro.webapp.modelaccess.impl.RequestModelAccessImpl;
|
||||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
|
||||||
|
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.RDFServiceUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -88,8 +89,10 @@ public class ModelSwitcher {
|
||||||
|
|
||||||
// If they asked for the display model, give it to them.
|
// If they asked for the display model, give it to them.
|
||||||
if (isParameterPresent(vreq, SWITCH_TO_DISPLAY_MODEL)) {
|
if (isParameterPresent(vreq, SWITCH_TO_DISPLAY_MODEL)) {
|
||||||
OntModel mainOntModel = ModelAccess.on(_context).getOntModel(DISPLAY);
|
OntModel mainOntModel = LanguageFilteringUtils.wrapOntModelInALanguageFilter(
|
||||||
OntModel tboxOntModel = ModelAccess.on(_context).getOntModel(DISPLAY_TBOX);
|
ModelAccess.on(vreq).getOntModel(DISPLAY), vreq);
|
||||||
|
OntModel tboxOntModel = LanguageFilteringUtils.wrapOntModelInALanguageFilter(
|
||||||
|
ModelAccess.on(vreq).getOntModel(DISPLAY_TBOX), vreq);
|
||||||
setSpecialWriteModel(vreq, mainOntModel);
|
setSpecialWriteModel(vreq, mainOntModel);
|
||||||
|
|
||||||
vreq.setAttribute(VitroRequest.ID_FOR_ABOX_MODEL, VitroModelSource.ModelName.DISPLAY.toString());
|
vreq.setAttribute(VitroRequest.ID_FOR_ABOX_MODEL, VitroModelSource.ModelName.DISPLAY.toString());
|
||||||
|
|
|
@ -63,6 +63,7 @@ public class PageRoutingFilter implements Filter{
|
||||||
// get URL without hostname or servlet context
|
// get URL without hostname or servlet context
|
||||||
HttpServletResponse response = (HttpServletResponse) arg1;
|
HttpServletResponse response = (HttpServletResponse) arg1;
|
||||||
HttpServletRequest req = (HttpServletRequest) arg0;
|
HttpServletRequest req = (HttpServletRequest) arg0;
|
||||||
|
|
||||||
String path = req.getRequestURI().substring(req.getContextPath().length());
|
String path = req.getRequestURI().substring(req.getContextPath().length());
|
||||||
|
|
||||||
// check for first part of path
|
// check for first part of path
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue