Skip to content

Commit

Permalink
Merge branch 'develop' into feature/#86-event-based-animation
Browse files Browse the repository at this point in the history
  • Loading branch information
Janekdererste committed Apr 17, 2019
2 parents 3c604ed + e16e6b8 commit 1500640
Show file tree
Hide file tree
Showing 16 changed files with 314 additions and 52 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ deploy:
provider: script
# this is the default domain and doesn't require a domain param
script: bash ./vsp-deploy/deploy.sh
skip_cleanup: false
skip_cleanup: true
40 changes: 1 addition & 39 deletions files/src/main/java/org/matsim/viz/files/entities/FileEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,8 @@
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.codec.digest.MessageDigestAlgorithms;

import javax.persistence.*;
import java.util.HashSet;
import java.util.Set;
import java.util.stream.Collectors;

@Getter
@Setter
Expand All @@ -19,7 +14,7 @@
@Table(uniqueConstraints =
{@UniqueConstraint(columnNames = {"project_id", "tagSummary", "userFileName"}),
@UniqueConstraint(columnNames = {"project_id", "persistedFileName"})})
public class FileEntry extends Resource {
public class FileEntry extends Taggable {

@Column(nullable = false)
private String userFileName;
Expand All @@ -40,38 +35,5 @@ public class FileEntry extends Resource {
@ManyToOne(optional = false)
private Project project;

@ManyToMany(fetch = FetchType.EAGER)
private Set<Tag> tags = new HashSet<>();

@JsonIgnore
@Column(nullable = false, length = 64)
private String tagSummary = "";

public enum StorageType {Local, S3}

public void addTag(Tag tag) {
this.tags.add(tag);
updateTagSummary();
}

public void addTags(String[] tagIds) {
for (String tagId : tagIds) {
Tag tag = new Tag();
tag.setId(tagId);
this.addTag(tag);
}
}

public void removeTag(Tag tag) {
this.tags.remove(tag);
updateTagSummary();
}

private void updateTagSummary() {
final String allTags = this.tags.stream()
.sorted((tag1, tag2) -> tag1.getId().compareToIgnoreCase(tag2.getId()))
.map(Tag::getId)
.collect(Collectors.joining("."));
this.tagSummary = new DigestUtils(MessageDigestAlgorithms.SHA_256).digestAsHex(allTags);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;
import org.matsim.viz.database.AbstractEntity;

import javax.persistence.*;
Expand All @@ -23,6 +24,9 @@ public abstract class Resource extends AbstractEntity {
@CreationTimestamp
private Instant createdAt;

@UpdateTimestamp
private Instant updatedAt;

public boolean addPermission(Permission permission) {

if (permission.getId() == null) {
Expand Down
54 changes: 54 additions & 0 deletions files/src/main/java/org/matsim/viz/files/entities/Taggable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package org.matsim.viz.files.entities;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.codec.digest.MessageDigestAlgorithms;

import javax.persistence.*;
import java.util.HashSet;
import java.util.Set;
import java.util.stream.Collectors;

@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@Getter
@Setter
public abstract class Taggable extends Resource {

private static DigestUtils digestUtils = new DigestUtils(MessageDigestAlgorithms.SHA_256);

@ManyToMany(fetch = FetchType.EAGER)
private Set<Tag> tags = new HashSet<>();

@JsonIgnore
@Column(nullable = false, length = 64)
private String tagSummary = "";

void addTag(Tag tag) {
this.tags.add(tag);
updateTagSummary();
}

public void addTags(String[] tagIds) {
for (String tagId : tagIds) {
Tag tag = new Tag();
tag.setId(tagId);
this.addTag(tag);
}
}

void removeTag(Tag tag) {
this.tags.remove(tag);
updateTagSummary();
}

private void updateTagSummary() {
final String allTags = tags.stream()
.sorted((tag1, tag2) -> tag1.getId().compareToIgnoreCase(tag2.getId()))
.map(Tag::getId)
.collect(Collectors.joining());
this.tagSummary = digestUtils.digestAsHex(allTags);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,20 @@
@Setter
@Entity
@Table(indexes = {@Index(columnList = "type")})
public class Visualization extends Resource {
public class Visualization extends Taggable {

private String type;

private String title;

@Lob
private String thumbnail;

// This will create a separate table which is linked automatically
@ElementCollection
@Column(name = "value", length = 10000)
private Map<String, String> properties = new HashMap<>();

@ManyToOne(optional = false)
private Project project;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ List<Project> findAllForUserFlat(Agent agent) {
QPermission permission = QPermission.permission;

return database.executeQuery(query -> query.selectFrom(project)
.innerJoin(project.permissions, permission).on(permission.agent.eq(agent))
.where(project.permissions.any().agent.eq(agent))
.innerJoin(project.permissions, permission).fetchJoin()
.distinct()
.fetch()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.hibernate.validator.constraints.NotEmpty;

import javax.validation.constraints.NotNull;
import java.util.HashMap;
import java.util.Map;

@Getter
Expand All @@ -17,8 +18,16 @@ class CreateVisualizationRequest {
private String projectId;
@NotEmpty
private String typeKey;
@NotEmpty
private String title;
@NotEmpty
private Map<String, String> inputFiles;
@NotNull
private Map<String, String> inputParameters;
@NotNull
private String[] tagIds = new String[0];
@NotNull
private Map<String, String> properties = new HashMap<>();
@NotEmpty
private String thumbnail = "";
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ List<Visualization> findAllByTypeIfHasPermission(String typeName, Instant after,
.leftJoin(visualization.inputFiles).fetchJoin()
.leftJoin(visualization.parameters).fetchJoin()
.leftJoin(visualization.permissions).fetchJoin()
.leftJoin(visualization.tags).fetchJoin()
.distinct()
.fetch()
);
Expand All @@ -58,12 +59,20 @@ void removeVisualization(Visualization viz) {
database.remove(viz);
}

public List<Visualization> findAllForProject(String projectId, Agent agent) {
List<Visualization> findAllForProject(String projectId, Agent agent) {

QVisualization visualization = QVisualization.visualization;

// this query fetches a possibly large dataset and it relations if we should ever encounter performance issues
// the result set could be limited.
return database.executeQuery(query -> query.selectFrom(visualization)
.where(visualization.project.id.eq(projectId)
.and(visualization.permissions.any().agent.eq(agent)))
.leftJoin(visualization.inputFiles).fetchJoin()
.leftJoin(visualization.parameters).fetchJoin()
.leftJoin(visualization.permissions).fetchJoin()
.leftJoin(visualization.tags).fetchJoin()
.leftJoin(visualization.properties).fetchJoin()
.distinct()
.fetch()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ Visualization createVisualizationFromRequest(CreateVisualizationRequest request,
Visualization viz = new Visualization();
project.addVisualization(viz);
viz.setType(request.getTypeKey());
viz.setTitle(request.getTitle());
viz.addTags(request.getTagIds());
viz.setProperties(request.getProperties());
viz.setThumbnail(request.getThumbnail());
viz.addPermission(permissionService.createServicePermission(viz));
addInputFilesAndPersistPermissions(viz, project, request);
addParameters(viz, request);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
--
-- Set character set the client will use to send SQL statements to the server
--
SET NAMES 'utf8';

--
-- Resources now have a updateAt property. We must alter all Resources tables which are
-- Project, FileEntry and Visualization
--

--
-- Add updatedAt property to FileEntry and set it to 'now'
--
ALTER TABLE FileEntry
ADD COLUMN updatedAt DATETIME;

UPDATE FileEntry
SET updatedAt = CURRENT_TIMESTAMP();

--
-- Add updatedAt property to Visualization and set it to 'now'
--
ALTER TABLE Visualization
ADD COLUMN updatedAt DATETIME;

UPDATE Visualization
SET updatedAt = CURRENT_TIMESTAMP();

--
-- Add updatedAt property to Project and set it to 'now'
--
ALTER TABLE Project
ADD COLUMN updatedAt DATETIME;

UPDATE Project
SET updatedAt = CURRENT_TIMESTAMP();

--
-- Tags are now assignable through the Taggable class which FileEntry and Visualization derive from now
-- We need to Create a Taggable_Tag table and copy the old values from FileEntry_Tag
-- At last we delete the old FileEntry_Tag table
--

--
-- Create Table Taggable_Tag
--
CREATE TABLE Taggable_Tag
(
Taggable_id VARCHAR(255) NOT NULL,
tags_id VARCHAR(255) NOT NULL,
PRIMARY KEY (Taggable_id, tags_id),
KEY FKq7cqx9j002d4ywlft24j0ox3e (tags_id),
CONSTRAINT FKq7cqx9j002d4ywlft24j0ox3e FOREIGN KEY (tags_id) REFERENCES Tag (id)
)
CHARACTER SET utf8,
COLLATE utf8_general_ci;

--
-- Also give a tag summary column to Visualization
--
ALTER TABLE Visualization
ADD COLUMN tagSummary VARCHAR(64);

UPDATE Visualization
SET tagSummary = '';

--
-- Copy all values from FileEntry_Tag
--
INSERT INTO Taggable_Tag (Taggable_id, tags_id)
SELECT FileEntry_id, tags_id FROM FileEntry_Tag;

--
-- Drop old FileEntry_Tag table
--
DROP TABLE IF EXISTS FileEntry_Tag;
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
--
-- Set character set the client will use to send SQL statements to the server
--
SET NAMES 'utf8';

--
-- Visualizations have new properties like title, thumbnail, and properties
--

ALTER TABLE Visualization
ADD COLUMN title VARCHAR(255);
UPDATE Visualization
SET title = '';

ALTER TABLE Visualization
ADD COLUMN thumbnail LONGTEXT;
UPDATE Visualization
SET thumbnail = '';

--
-- properties are a separate table
--
CREATE TABLE Visualization_properties
(
Visualization_id varchar(255) NOT NULL,
value varchar(10000) DEFAULT NULL,
properties_KEY varchar(255) NOT NULL,
PRIMARY KEY (Visualization_id, properties_KEY),
CONSTRAINT FK556sp5rugb2160u30kcmyw99n FOREIGN KEY (Visualization_id) REFERENCES Visualization (id)
)
CHARACTER SET utf8,
COLLATE utf8_general_ci;
Loading

0 comments on commit 1500640

Please sign in to comment.