Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into upstream-merge
Browse files Browse the repository at this point in the history
# Conflicts:
#	ontology/termit-glosář.ttl
#	ontology/termit-model.ttl
#	pom.xml
#	src/test/java/cz/cvut/kbss/termit/service/repository/BaseAssetRepositoryServiceTest.java
  • Loading branch information
ledsoft committed May 3, 2021
2 parents 2a6349d + 079ce0f commit 32d700b
Show file tree
Hide file tree
Showing 19 changed files with 284 additions and 206 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,13 @@ Build configuration and deployment is described in [setup.md](doc/setup.md).
## Dockerization

The docker image of TermIt backend can be built by
`docker build -t kbss-cvut:termit .`
An optional argument is `REPOSITORY_URL` pointing to the RDF4J/GraphDB repository.
`docker build -t termit-server .`

Then, TermIt can be run and exposed at the port 8080 as
`sudo docker run -p 8080:8080 kbss-cvut:termit`
`sudo docker run -e REPOSITORY_URL=<GRAPHDB_REPOSITORY_URL> -p 8080:8080 termit-server`

An optional argument is `<GRAPHDB_REPOSITORY_URL>` pointing to the RDF4J/GraphDB repository.


## License

Expand Down
9 changes: 9 additions & 0 deletions ontology/termit-glosář.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -469,3 +469,12 @@ termit-pojem:je-publikován
termit:glosář ;
<http://www.w3.org/2004/02/skos/core#prefLabel>
"Is published"@en , "Je publikován"@cs .

termit-pojem:má-můj-poslední-komentář
a <http://www.w3.org/2004/02/skos/core#Concept> ;
<http://www.w3.org/2004/02/skos/core#broader>
<https://slovník.gov.cz/základní/pojem/vlastnost> , <https://slovník.gov.cz/základní/pojem/typ-vlastnosti> ;
<http://www.w3.org/2004/02/skos/core#inScheme>
termit:glosář ;
<http://www.w3.org/2004/02/skos/core#prefLabel>
"Has my last comment"@en , "Má můj poslední komentář"@cs .
11 changes: 7 additions & 4 deletions ontology/termit-model.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ termit-pojem:uživatel-termitu
termit-pojem:má-zdroj-definice-termu
a owl:ObjectProperty , <https://slovník.gov.cz/základní/pojem/typ-vztahu> ;
rdfs:domain <http://onto.fel.cvut.cz/ontologies/slovník/agendový/popis-dat/pojem/term> ;
rdfs:range xsd:boolean ;
rdfs:subPropertyOf <https://slovník.gov.cz/základní/pojem/vlastnost> .
rdfs:range termit-pojem:zdroj-definice-termu ;
rdfs:subPropertyOf <https://slovník.gov.cz/základní/pojem/vztah> .

termit-pojem:je-draft
a owl:DatatypeProperty , <https://slovník.gov.cz/základní/pojem/typ-vlastnosti> ;
rdfs:domain <http://onto.fel.cvut.cz/ontologies/slovník/agendový/popis-dat/pojem/term> ;
rdfs:range termit-pojem:zdroj-definice-termu ;
rdfs:subPropertyOf <https://slovník.gov.cz/základní/pojem/vztah> .
rdfs:range xsd:boolean ;
rdfs:subPropertyOf <https://slovník.gov.cz/základní/pojem/vlastnost> .

<http://onto.fel.cvut.cz/ontologies/slovník/agendový/popis-dat/pojem/term>
a owl:Class .
Expand Down Expand Up @@ -264,3 +264,6 @@ termit-pojem:je-publikován
a owl:DatatypeProperty , <https://slovník.gov.cz/základní/pojem/typ-vlastnosti> ;
rdfs:domain <http://onto.fel.cvut.cz/ontologies/slovník/agendový/popis-dat/pojem/term> ;
rdfs:subPropertyOf <https://slovník.gov.cz/základní/pojem/vlastnost> .

termit-pojem:má-můj-poslední-komentář
a owl:ObjectProperty.
10 changes: 9 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</parent>

<artifactId>termit</artifactId>
<version>2.4.0</version>
<version>2.4.1</version>
<name>TermIt</name>
<description>Terminology manager based on Semantic Web technologies.</description>
<packaging>${packaging}</packaging>
Expand All @@ -38,6 +38,7 @@
<!-- Default value for deployment type property which should otherwise specified on command line -->
<deployment>DEV</deployment>
<packaging>jar</packaging>
<org.apache.tika.tika-core.version>1.26</org.apache.tika.tika-core.version>
<!-- Do not activate any Spring profiles by default -->
<spring.profiles.active/>
</properties>
Expand Down Expand Up @@ -92,6 +93,13 @@
<version>1.11</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.apache.tika/tika-core -->
<dependency>
<groupId>org.apache.tika</groupId>
<artifactId>tika-core</artifactId>
<version>${org.apache.tika.tika-core.version}</version>
</dependency>

<!-- JOPA -->
<dependency>
<groupId>cz.cvut.kbss.jopa</groupId>
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/cz/cvut/kbss/termit/config/WebAppConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import cz.cvut.kbss.jopa.model.MultilingualString;
import cz.cvut.kbss.jopa.sessions.UnitOfWorkImpl;
import cz.cvut.kbss.jsonld.JsonLd;
import cz.cvut.kbss.jsonld.jackson.JsonLdModule;
import cz.cvut.kbss.termit.rest.servlet.DiagnosticsContextFilter;
import cz.cvut.kbss.termit.util.AdjustedUriTemplateProxyServlet;
import cz.cvut.kbss.termit.util.ConfigParam;
import cz.cvut.kbss.termit.util.Constants;
import cz.cvut.kbss.termit.util.json.ManageableIgnoreMixin;
import cz.cvut.kbss.termit.util.json.MultilingualStringDeserializer;
import cz.cvut.kbss.termit.util.json.MultilingualStringSerializer;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
Expand Down Expand Up @@ -79,12 +81,14 @@ public ObjectMapper objectMapper() {
*/
public static ObjectMapper createJsonObjectMapper() {
final ObjectMapper objectMapper = new ObjectMapper();
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
objectMapper.setSerializationInclusion(JsonInclude.Include.ALWAYS);
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
final SimpleModule multilingualStringModule = new SimpleModule();
multilingualStringModule.addSerializer(MultilingualString.class, new MultilingualStringSerializer());
multilingualStringModule.addDeserializer(MultilingualString.class, new MultilingualStringDeserializer());
objectMapper.registerModule(multilingualStringModule);
// Ignore UoW references injected into entities
objectMapper.addMixIn(UnitOfWorkImpl.class, ManageableIgnoreMixin.class);
// JSR 310 (Java 8 DateTime API)
objectMapper.registerModule(new JavaTimeModule());
return objectMapper;
Expand Down
33 changes: 30 additions & 3 deletions src/main/java/cz/cvut/kbss/termit/dto/RecentlyCommentedAsset.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
variables = {
@VariableResult(name = "entity", type = URI.class),
@VariableResult(name = "lastCommentUri", type = URI.class),
@VariableResult(name = "myLastCommentUri", type = URI.class),
@VariableResult(name = "type", type = String.class)
})})
public class RecentlyCommentedAsset implements Serializable {
Expand All @@ -34,15 +35,22 @@ public class RecentlyCommentedAsset implements Serializable {
@OWLObjectProperty(iri = Vocabulary.s_p_je_tematem)
private Comment lastComment;

@Transient
private URI myLastCommentUri;

@OWLObjectProperty(iri = Vocabulary.s_p_ma_muj_posledni_komentar)
private Comment myLastComment;

@Types
private Set<String> types;

public RecentlyCommentedAsset() {
}

public RecentlyCommentedAsset(URI entity, URI lastCommentUri, String type) {
public RecentlyCommentedAsset(URI entity, URI lastCommentUri, URI myLastCommentUri, String type) {
this.uri = entity;
this.lastCommentUri = lastCommentUri;
this.myLastCommentUri = myLastCommentUri;
this.types = new HashSet<>(Collections.singleton(type));
}

Expand Down Expand Up @@ -79,11 +87,29 @@ public RecentlyCommentedAsset setLastComment(Comment lastComment) {
return this;
}

public URI getMyLastCommentUri() {
return myLastCommentUri;
}

public void setMyLastCommentUri(URI myLastCommentUri) {
this.myLastCommentUri = myLastCommentUri;
}

public Comment getMyLastComment() {
return myLastComment;
}

public RecentlyCommentedAsset setMyLastComment(Comment myLastComment) {
this.myLastComment = myLastComment;
return this;
}

@Override
public String toString() {
return "RecentlyCommentedAsset{" +
"uri=" + uri +
", comment=" + lastComment.toString() +
", comment=" + lastComment +
", myLastComment=" + myLastComment +
", types=" + types +
'}';
}
Expand All @@ -99,11 +125,12 @@ public boolean equals(Object o) {
RecentlyCommentedAsset that = (RecentlyCommentedAsset) o;
return Objects.equals(uri, that.uri) &&
Objects.equals(lastComment, that.lastComment) &&
Objects.equals(myLastComment, that.myLastComment) &&
Objects.equals(types, that.types);
}

@Override
public int hashCode() {
return Objects.hash(uri, lastComment, types);
return Objects.hash(uri, lastComment, myLastComment, types);
}
}
34 changes: 34 additions & 0 deletions src/main/java/cz/cvut/kbss/termit/event/DocumentRenameEvent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package cz.cvut.kbss.termit.event;

import cz.cvut.kbss.termit.model.resource.Document;
import java.util.Objects;
import org.springframework.context.ApplicationEvent;

/**
* Indicates that a {@link Document} asset has changed its label.
*/
public class DocumentRenameEvent extends ApplicationEvent {

private final String originalName;

private final String newName;

public DocumentRenameEvent(Document source, String originalName, String newName) {
super(source);
this.originalName = Objects.requireNonNull(originalName);
this.newName = Objects.requireNonNull(newName);
}

public String getOriginalName() {
return originalName;
}

public String getNewName() {
return newName;
}

@Override
public Document getSource() {
return (Document) super.getSource();
}
}
72 changes: 20 additions & 52 deletions src/main/java/cz/cvut/kbss/termit/persistence/dao/AssetDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ List<URI> findUniqueLastModifiedEntitiesBy(User author, int limit) {
public List<RecentlyCommentedAsset> findLastCommented(int limit) {
try {
return (List<RecentlyCommentedAsset>) em
.createNativeQuery("SELECT DISTINCT ?entity ?lastCommentUri ?type"
.createNativeQuery("SELECT DISTINCT ?entity ?lastCommentUri ?myLastCommentUri ?type"
+ " WHERE { ?lastCommentUri a ?commentType ;"
+ " ?hasEntity ?entity ."
+ " OPTIONAL { ?lastCommentUri ?hasModifiedTime ?modified . }"
Expand Down Expand Up @@ -226,12 +226,24 @@ public List<RecentlyCommentedAsset> findLastCommented(int limit) {
public List<RecentlyCommentedAsset> findLastCommentedInReaction(User author, int limit) {
try {
return (List<RecentlyCommentedAsset>) em
.createNativeQuery("SELECT DISTINCT ?entity ?lastCommentUri ?type"
.createNativeQuery("SELECT DISTINCT ?entity ?lastCommentUri ?myLastCommentUri ?type"
+ " WHERE { ?lastCommentUri a ?commentType ;"
+ " ?hasEntity ?entity ."
+ " FILTER EXISTS { ?comment3 ?hasEntity ?entity ;"
+ " ?hasAuthor ?author . "
+ " FILTER(?comment3 != ?lastCommentUri)}"
+ " ?myLastCommentUri ?hasEntity ?entity ;"
+ " ?hasAuthor ?author . "
+ " OPTIONAL { ?myLastCommentUri ?hasModifiedTime ?modifiedByMe . } "
+ " OPTIONAL { ?myLastCommentUri ?hasCreatedByMe ?createdByMe . } "
+ " BIND(COALESCE(?modifiedByMe,?createdByMe) AS ?lastCommentedByMe) "
+ " { SELECT (MAX(?lastCommentedByMe2) AS ?maxByMe) {"
+ " ?commentByMe ?hasEntity ?entity ; "
+ " ?hasAuthor ?author . "
+ " OPTIONAL { ?commentByMe ?hasModifiedTime ?modifiedByMe2 . } "
+ " OPTIONAL { ?commentByMe ?hasCreatedTime ?createdByMe2 . } "
+ " BIND(COALESCE(?modifiedByMe2,?createdByMe2) AS ?lastCommentedByMe2) "
+ " } GROUP BY ?entity "
+ " }"
+ " FILTER (?lastCommentedByMe = ?maxByMe )"
+ " FILTER(?myLastCommentUri != ?lastCommentUri)"
+ " OPTIONAL { ?lastCommentUri ?hasModifiedTime ?modified . }"
+ " OPTIONAL { ?lastCommentUri ?hasCreatedTime ?created . }"
+ " BIND(COALESCE(?modified,?created) AS ?lastCommented) "
Expand All @@ -257,7 +269,8 @@ public List<RecentlyCommentedAsset> findLastCommentedInReaction(User author, int
.setMaxResults(limit).getResultStream()
.map(r -> {
final RecentlyCommentedAsset a = (RecentlyCommentedAsset) r;
return a.setLastComment(em.find(Comment.class, a.getLastCommentUri()));
return a.setLastComment(em.find(Comment.class, a.getLastCommentUri()))
.setMyLastComment(em.find(Comment.class, a.getMyLastCommentUri()));
}
).collect(Collectors.toList());
} catch (RuntimeException e) {
Expand All @@ -273,7 +286,7 @@ public List<RecentlyCommentedAsset> findLastCommentedInReaction(User author, int
public List<RecentlyCommentedAsset> findMyLastCommented(User author, int limit) {
try {
return (List<RecentlyCommentedAsset>) em
.createNativeQuery("SELECT DISTINCT ?entity ?lastCommentUri ?type"
.createNativeQuery("SELECT DISTINCT ?entity ?lastCommentUri ?myLastCommentUri ?type"
+ " WHERE { ?lastCommentUri a ?commentType ;"
+ " ?hasEntity ?entity ."
+ " FILTER EXISTS{ ?x ?hasModifiedEntity ?entity ;"
Expand Down Expand Up @@ -312,51 +325,6 @@ public List<RecentlyCommentedAsset> findMyLastCommented(User author, int limit)
}
}

/**
* Finds unique assets last commented by me.
* @param limit max number of entities
* @return list
*/
public List<RecentlyCommentedAsset> findLastCommentedByMe(User author, int limit) {
try {
return (List<RecentlyCommentedAsset>) em
.createNativeQuery("SELECT DISTINCT ?entity ?lastCommentUri ?type"
+ " WHERE { ?lastCommentUri a ?commentType ;"
+ " ?hasEntity ?entity ;"
+ " ?hasCreator ?author ."
+ " OPTIONAL { ?lastCommentUri ?hasModifiedTime ?modified . }"
+ " OPTIONAL { ?lastCommentUri ?hasCreatedTime ?created . }"
+ " BIND(COALESCE(?modified,?created) AS ?lastCommented) "
+ " BIND(?cls as ?type) "
+ " { SELECT (MAX(?lastCommented2) AS ?max) {"
+ " ?comment2 ?hasEntity ?entity ."
+ " OPTIONAL { ?comment2 ?hasModifiedTime ?modified2 . }"
+ " OPTIONAL { ?comment2 ?hasCreatedTime ?created2 . }"
+ " BIND(COALESCE(?modified2,?created2) AS ?lastCommented2) "
+ " } GROUP BY ?entity"
+ " }"
+ " FILTER (?lastCommented = ?max )"
+ "} ORDER BY DESC(?lastCommented) ", "RecentlyCommentedAsset")
.setParameter("cls", typeUri)
.setParameter("commentType", URI.create(Vocabulary.s_c_Comment))
.setParameter("hasEntity", URI.create(Vocabulary.s_p_topic))
.setParameter("hasCreator", URI.create(Vocabulary.s_p_has_creator))
.setParameter("author", author)
.setParameter("hasModifiedTime",
URI.create(Vocabulary.s_p_ma_datum_a_cas_posledni_modifikace))
.setParameter("hasCreatedTime",
URI.create(Vocabulary.s_p_ma_datum_a_cas_vytvoreni))
.setMaxResults(limit).getResultStream()
.map(r -> {
final RecentlyCommentedAsset a = (RecentlyCommentedAsset) r;
return a.setLastComment(em.find(Comment.class, a.getLastCommentUri()));
}
).collect(Collectors.toList());
} catch (RuntimeException e) {
throw new PersistenceException(e);
}
}

/**
* Identifier of an RDF property representing this assets label.
*
Expand Down
6 changes: 0 additions & 6 deletions src/main/java/cz/cvut/kbss/termit/rest/AssetController.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,4 @@ public List<RecentlyCommentedAsset> getMyLastCommented(
@RequestParam(name = "limit", required = false, defaultValue = DEFAULT_LIMIT) int limit) {
return assetService.findMyLastCommented(limit);
}

@RequestMapping(value = "/last-commented-by-me", produces = {MediaType.APPLICATION_JSON_VALUE, JsonLd.MEDIA_TYPE})
public List<RecentlyCommentedAsset> getLastCommentedByMe(
@RequestParam(name = "limit", required = false, defaultValue = DEFAULT_LIMIT) int limit) {
return assetService.findLastCommentedByMe(limit);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -150,19 +150,6 @@ public List<RecentlyCommentedAsset> findMyLastCommented(int limit) {
return result.subList(0, Math.min(result.size(), limit));
}

/**
* Finds the specified number of assets most recently commented by me.
*
* @param limit Maximum number of assets to retrieve
* @return List of recently commented assets
*/
public List<RecentlyCommentedAsset> findLastCommentedByMe(int limit) {
ensureValidLimitForLastCommented(limit);
final User me = securityUtils.getCurrentUser().toUser();
final List<RecentlyCommentedAsset> result = termRepositoryService.findLastCommentedByMe(me, limit);
return result.subList(0, Math.min(result.size(), limit));
}

private void ensureValidLimitForLastCommented(int limit) {
if (limit < 0) {
throw new IllegalArgumentException("Maximum for recently commented assets must not be less than 0.");
Expand Down
Loading

0 comments on commit 32d700b

Please sign in to comment.