Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Share GPX #978

Merged
merged 31 commits into from
Jan 4, 2025
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
0b9d50c
remove unused annotations
alisa911 Nov 20, 2024
e017c8f
add share gpx
alisa911 Nov 20, 2024
96fedd7
fix shared token
alisa911 Nov 20, 2024
14d564e
refactoring share gpx
alisa911 Nov 21, 2024
033af30
merge master
alisa911 Nov 28, 2024
e493f00
add share api
alisa911 Nov 28, 2024
d91e40d
add index
alisa911 Nov 28, 2024
b2b40b0
fix saveAccessedUser
alisa911 Nov 28, 2024
138137f
refactoring
alisa911 Nov 29, 2024
c635cbd
create table share_files
alisa911 Dec 2, 2024
bcf7abe
refactoring
alisa911 Dec 2, 2024
267b58e
merge master
alisa911 Dec 6, 2024
20d7d02
change share api
alisa911 Dec 11, 2024
a14d5da
open share file for owner
alisa911 Dec 11, 2024
9989a01
Merge branch 'master' into T2527
alisa911 Dec 13, 2024
593764b
add share details
alisa911 Dec 13, 2024
2878b47
add share flag for list-files
alisa911 Dec 13, 2024
de77bde
add changeShareType
alisa911 Dec 13, 2024
88ff43f
add share error file is not available
alisa911 Dec 16, 2024
579e4eb
add nickname field to PremiumUser
alisa911 Dec 17, 2024
b128058
add private share type
alisa911 Dec 18, 2024
161a9e0
Merge branch 'master' into T2527
alisa911 Dec 18, 2024
41e92f4
rename column id
alisa911 Dec 18, 2024
e71e43c
refactoring
alisa911 Dec 18, 2024
4450b40
change UUID
alisa911 Dec 18, 2024
a313d4d
refactoring
alisa911 Dec 18, 2024
36d2757
refactoring
alisa911 Dec 18, 2024
5a54608
Merge branch 'master' into T2527
alisa911 Dec 20, 2024
965f2f5
Merge branch 'master' into T2527
alisa911 Dec 26, 2024
36e6920
Merge branch 'master' into T2527
alisa911 Dec 27, 2024
4c76626
Merge branch 'master' into T2527
alisa911 Dec 31, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion db/sql_changeset_schema
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ CREATE INDEX supporters_device_sub_orderid_idx on supporters_device_sub(orderid)
ALTER TABLE supporters_device_sub add primary key (sku, orderid);

------ PREMIUM accounts ----
CREATE TABLE user_accounts(id serial primary key, email text not null, tokendevice text, orderid text, token text, tokentime timestamp, regtime timestamp);
CREATE TABLE user_accounts(id serial primary key, email text not null, nickname text, tokendevice text, orderid text, token text, tokentime timestamp, regtime timestamp);
CREATE TABLE user_account_devices(id serial primary key, userid integer, deviceid text, accesstoken text, lang text, brand text, model text, udpatetime timestamp);
CREATE TABLE user_files(id bigserial primary key, type text, name text, userid integer, deviceid integer, updatetime timestamp, clienttime timestamp, filesize bigint, zipfilesize bigint, storage text, gendetails jsonb, data bytea);
CREATE TABLE promo_campaigns(name text, starttime timestamp, endtime timestamp, subactivemonths integer, numberlimit integer, used integer, lastusers text);
Expand All @@ -39,6 +39,36 @@ CREATE INDEX user_account_devices_userid_idx on user_account_devices(userid);
CREATE INDEX user_files_userid_idx on user_files(userid);
CREATE INDEX user_files_deviceid_idx on user_files(deviceid);

-- share file
CREATE TABLE user_share_files (
id SERIAL PRIMARY KEY,
alisa911 marked this conversation as resolved.
Show resolved Hide resolved
ownerid INTEGER NOT NULL,
uuid UUID UNIQUE,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to use VARCHAR not UUID. Some day we might decide to use some shorter code such as set of [a-zA-Z0-9]. VARCHAR would be OK for both UUID and String.

filepath TEXT NOT NULL,
name TEXT NOT NULL,
alisa911 marked this conversation as resolved.
Show resolved Hide resolved
type TEXT NOT NULL,
public_access BOOLEAN NOT NULL
);

CREATE TABLE user_share_files_access (
id SERIAL UNIQUE,
user_id INTEGER NOT NULL,
access TEXT NOT NULL,
date TIMESTAMP NOT NULL,
file_id INTEGER NOT NULL,
alisa911 marked this conversation as resolved.
Show resolved Hide resolved
CONSTRAINT user_share_files_access_pk PRIMARY KEY (file_id, user_id),
CONSTRAINT fk_user_share_files_access_user FOREIGN KEY (user_id) REFERENCES user_accounts(id) ON DELETE CASCADE,
CONSTRAINT fk_user_share_files_access_file FOREIGN KEY (file_id) REFERENCES user_share_files(id) ON DELETE CASCADE
);

CREATE INDEX user_share_files_ownerid_idx ON user_share_files(ownerid);
CREATE INDEX user_share_files_uuid_idx ON user_share_files(uuid);
CREATE INDEX user_share_files_filepath_idx ON user_share_files(filepath);
CREATE INDEX user_share_files_ownerid_filepath_idx ON user_share_files(ownerid, filepath);

CREATE INDEX user_share_files_access_userid_idx ON user_share_files_access(user_id);
CREATE INDEX user_share_files_access_file_id_idx ON user_share_files_access(file_id);
alisa911 marked this conversation as resolved.
Show resolved Hide resolved

-- mail group
CREATE TABLE email_free_users(aid text, email text, os text, updatetime timestamp);
CREATE TABLE email_blocked(email text, reason text, timestamp timestamp);
Expand Down
2 changes: 2 additions & 0 deletions java-tools/OsmAndServer/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ dependencies {
implementation 'org.apache.httpcomponents.client5:httpclient5:5.3.1'
implementation 'org.lz4:lz4-java:1.8.0'

compileOnly group: 'org.projectlombok', name: 'lombok', version: '1.18.28'
annotationProcessor group: 'org.projectlombok', name: 'lombok', version: '1.18.28'
// implementation 'com.clickhouse:clickhouse-http-client:0.6.0'

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.osmand.server.api.repo;


import java.io.IOException;
import java.io.Serial;
import java.io.Serializable;
import java.util.Date;
Expand All @@ -15,6 +16,7 @@
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import com.google.gson.Gson;
import org.hibernate.annotations.Type;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
Expand All @@ -37,7 +39,7 @@ public interface PremiumUserFilesRepository extends JpaRepository<UserFile, Long
UserFile findTopByUseridAndNameAndTypeAndUpdatetimeGreaterThanOrderByUpdatetimeDesc(int userid, String name, String type, Date updatetime);

List<UserFile> findAllByUseridAndNameAndTypeOrderByUpdatetimeDesc(int userid, String name, String type);

Iterable<UserFile> findAllByUserid(int userid);

@Query("SELECT uf FROM UserFile uf "
Expand All @@ -54,6 +56,8 @@ public interface PremiumUserFilesRepository extends JpaRepository<UserFile, Long
@Entity(name = "UserFile")
@Table(name = "user_files")
class UserFile implements Serializable {
private static final Gson gson = new Gson();

@Serial
private static final long serialVersionUID = 1L;

Expand Down Expand Up @@ -93,14 +97,24 @@ class UserFile implements Serializable {
@Column(name = "gendetails", columnDefinition = "jsonb")
@Type(type = "net.osmand.server.assist.data.JsonbType")
public JsonObject details;

// @Fetch(FetchMode.JOIN)
@Column(name = "data", columnDefinition="bytea")
public byte[] data;

// @Lob
// public Blob data;

@Column(name = "data", columnDefinition = "bytea")
public byte[] data;

@Serial
private void writeObject(java.io.ObjectOutputStream out) throws IOException {
out.defaultWriteObject();
out.writeObject(details != null ? gson.toJson(details) : null);
}

@Serial
private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException {
in.defaultReadObject();
String json = (String) in.readObject();
if (json != null) {
this.details = gson.fromJson(json, JsonObject.class);
}
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ class PremiumUser implements Serializable {

@Column(name = "email")
public String email;

@Column(name = "nickname")
public String nickname;

@Column(name = "token")
public String token;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
package net.osmand.server.api.repo;

import lombok.Getter;
import lombok.Setter;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.data.jpa.repository.Query;

import javax.persistence.*;
import java.io.Serial;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;

@Repository
public interface ShareFileRepository extends JpaRepository<ShareFileRepository.ShareFile, Long> {

ShareFile findByUuid(UUID uuid);

ShareFile findByOwneridAndFilepath(int ownerid, String filepath);
alisa911 marked this conversation as resolved.
Show resolved Hide resolved

List<ShareFile> findByOwnerid(int ownerid);

@Query("SELECT a FROM ShareFilesAccess a WHERE a.id = :id")
ShareFilesAccess findShareFilesAccessById(@Param("id") long id);

<S extends ShareFilesAccess> S saveAndFlush(S entity);

@Setter
@Getter
@Entity(name = "ShareFile")
@Table(name = "user_share_files")
class ShareFile implements Serializable {

@Serial
private static final long serialVersionUID = 1L;

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(nullable = false)
public long id;

@Column(nullable = false)
public int ownerid;

@Column(unique = true)
private UUID uuid;

@Column(nullable = false)
public String filepath;

@Column(nullable = false)
public String name;

@Column(nullable = false)
public String type;

@Column(nullable = false)
public boolean publicAccess;

@OneToMany(mappedBy = "file", cascade = CascadeType.ALL, orphanRemoval = true)
private List<ShareFilesAccess> accessRecords;

public void addAccessRecord(ShareFilesAccess access) {
accessRecords.add(access);
access.setFile(this);
}
}

@Setter
@Getter
@Entity(name = "ShareFilesAccess")
@Table(name = "user_share_files_access")
class ShareFilesAccess implements Serializable {

@Serial
private static final long serialVersionUID = 1L;

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;

@ManyToOne
@JoinColumn(name = "user_id", nullable = false)
private PremiumUsersRepository.PremiumUser user;

@Column(nullable = false)
private String access;

@Column(name = "date")
@Temporal(TemporalType.TIMESTAMP)
public Date requestDate;

@ManyToOne
@JoinColumn(name = "file_id", nullable = false)
private ShareFile file;
}

@Getter
@Setter
public class ShareFileDTO {

private long id;
private int ownerid;
private String uuid;
private String filepath;
private String name;
private String type;
private boolean publicAccess;
private List<ShareFilesAccessDTO> accessRecords;

public ShareFileDTO(ShareFile shareFile, boolean includeAccessRecords) {
this.id = shareFile.getId();
this.ownerid = shareFile.getOwnerid();
this.uuid = shareFile.getUuid() != null ? shareFile.getUuid().toString() : null;
this.filepath = shareFile.getFilepath();
this.name = shareFile.getName();
this.type = shareFile.getType();
this.publicAccess = shareFile.isPublicAccess();
if (includeAccessRecords && shareFile.getAccessRecords() != null) {
this.accessRecords = shareFile.getAccessRecords().stream()
.map((ShareFilesAccess access) -> new ShareFilesAccessDTO(access, false))
.collect(Collectors.toList());
}
}
}

@Getter
@Setter
class ShareFilesAccessDTO {

private long id;
private String name;
private String access;
private Date requestDate;

public ShareFilesAccessDTO(ShareFilesAccess access, boolean includeFile) {
this.id = access.getId();
this.name = access.getUser().nickname;
this.access = access.getAccess();
this.requestDate = access.getRequestDate();
if (includeFile) {
this.id = access.getFile().getId();
}
}
}
}
Loading