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

WIP: Feature/skfp 146 delete phantom sets #29

Draft
wants to merge 52 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
c0f3f46
ISSUE-1644 Check if the shorten belong to the user before update and …
Apr 26, 2019
6a3caf6
ISSUE-1644 Move security logic into service layer and use more functi…
Apr 30, 2019
40ef801
Merge pull request #1 from kids-first/issue-1644
May 2, 2019
34d916a
Fix build error during maven download
May 2, 2019
ee5c954
Merge pull request #2 from kids-first/issue-1644
May 2, 2019
d1064b7
Change checksum
May 2, 2019
8f292d9
Merge pull request #3 from kids-first/issue-1644
May 2, 2019
9d77a9b
Merge pull request #4 from kids-first/develop
nyanofthemoon May 9, 2019
1261a96
Update Jenkinsfile
nyanofthemoon May 9, 2019
4c8b067
Merge pull request #5 from kids-first/nyanofthemoon-patch-1
nyanofthemoon May 9, 2019
553c64d
Update Jenkinsfile
nyanofthemoon May 9, 2019
76f389e
Update Jenkinsfile
nyanofthemoon May 9, 2019
c2a011f
Update Jenkinsfile
nyanofthemoon May 9, 2019
4ea1b10
Add description field
May 10, 2019
48afe07
Merge pull request #6 from kids-first/add-description
May 10, 2019
75dd363
Bump version
May 10, 2019
2a27d1f
Merge pull request #8 from kids-first/develop
May 10, 2019
935dcf0
Update description
May 13, 2019
fc786ec
Use standard jenkins template
May 13, 2019
a65e2f6
Merge pull request #9 from kids-first/add-description
May 13, 2019
4396622
Merge branch 'master' into develop
May 13, 2019
9d48bbe
Merge pull request #10 from kids-first/develop
May 13, 2019
c160721
Remove description (use the one from the content field)
May 13, 2019
e553d83
Merge pull request #11 from kids-first/add-description
May 13, 2019
024136d
Remove description - fix tests
May 13, 2019
c3c8654
Merge pull request #13 from kids-first/add-description
May 13, 2019
b27b8bd
Merge pull request #14 from kids-first/develop
May 13, 2019
afa694d
Bump version
May 15, 2019
080e93a
Add V3__rename_studies_with_KF_prefix.sql migration
aalex Jun 28, 2019
de54d97
Update the list of studies to rename
aalex Jun 28, 2019
22d8f0d
Name fixes in the renaming
aalex Jul 2, 2019
e16474c
Merge pull request #15 from kids-first/feat/rename-studies
Jul 17, 2019
2650ead
Fix study name for CBTTC Atlas
Aug 8, 2019
8ffae4e
Merge pull request #18 from kids-first/fix-rename-study
Aug 8, 2019
5396ad3
adding agent label
Aug 12, 2019
701819b
Merge pull request #19 from kids-first/0.12UPGRADE
blackdenc Aug 12, 2019
aedcad8
Merge pull request #20 from kids-first/develop
blackdenc Aug 16, 2019
89620b2
:wrench: Updated the Jenkinsfile
Jul 15, 2020
cc2266e
:wrench: Added postgres dependency
Jul 15, 2020
9f5fe0c
:penci2: Fixed the dependency name
Jul 15, 2020
90b805f
Merge pull request #21 from kids-first/feature/move-to-standard-deploy
alubneuski Sep 1, 2020
9c752e6
Update Jenkinsfile
alubneuski Sep 6, 2020
2bbc83c
Added additional certificate
Sep 14, 2020
1b1c18d
Merge branch 'master' into feature/move-to-standard-deploy
alubneuski Sep 14, 2020
865156e
Merge pull request #22 from kids-first/feature/move-to-standard-deploy
alubneuski Sep 14, 2020
5845354
:wrench: Added tests
Nov 20, 2020
0e0cde0
updated Jenkinsfile
Nov 25, 2020
e3082e8
:wrench: Added push to public ecr
alubneuski Mar 11, 2021
656ea59
Merge pull request #23 from kids-first/feature/add-public-ecr-push
alubneuski Mar 11, 2021
194bce7
Added additional_internal_alb
alubneuski Apr 26, 2021
4d6e2df
SKFP-146: add delete-phantom-sets endpoint
aodiogo Oct 22, 2021
9f9faec
SKFP-146: make deletePhantomSets int instead of long
aodiogo Nov 1, 2021
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
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM openjdk:8u121-jdk-alpine

ARG MAVEN_VERSION=3.5.3
ARG SHA=b52956373fab1dd4277926507ab189fb797b3bc51a2a267a193c931fffad8408
ARG MAVEN_VERSION=3.5.4
ARG SHA=ce50b1c91364cb77efe3776f756a6d92b76d9038b0a0782f7d53acf1e997a14d
ARG BASE_URL=https://apache.osuosl.org/maven/maven-3/${MAVEN_VERSION}/binaries

RUN apk add --no-cache curl tar bash \
Expand Down
23 changes: 21 additions & 2 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,21 @@
@Library(value="oicr", changelog=false) _
riff_api{}
@Library(value='kids-first/aws-infra-jenkins-shared-libraries', changelog=false) _
ecs_service_type_1_standard {
projectName = "riff"
agentLabel = "terraform-testing"
environments = "dev,qa,prd"
docker_image_type = "alpine"
entrypoint_command = "/srv/riff/exec/run.sh"
quick_deploy = "true"
external_config_repo = "false"
internal_app = "false"
container_port = "8081"
vcpu_container = "1024"
memory_container = "2048"
vcpu_task = "1024"
memory_task = "2048"
health_check_path = "/swagger-ui.html"
dependencies = "ecr"
additional_ssl_cert_domain_name = "*.kidsfirstdrc.org"
publish_to_public_repo = "true"
create_additional_internal_alb = "1"
}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

<groupId>bio.overture</groupId>
<artifactId>riff</artifactId>
<version>1.1.2-SNAPSHOT</version>
<version>1.2.3-SNAPSHOT</version>
<packaging>jar</packaging>

<name>riff</name>
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/bio/overture/riff/controller/RiffController.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,16 @@ public boolean deleteRiff(@RequestHeader(value = HttpHeaders.AUTHORIZATION, requ
}
}

@DeleteMapping("/delete-phantom-sets")
public int deletePhantomSets(@RequestHeader(value = HttpHeaders.AUTHORIZATION) final String accessToken) {
int result;
val user = jwtFacade.getUser();
if (user.isPresent()) {
result = service.deletePhantomSets(user.get());
} else {
throw new UnauthorizedUserException("No user");
}
return result;
}

}
23 changes: 11 additions & 12 deletions src/main/java/bio/overture/riff/model/Riff.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,15 @@
@AllArgsConstructor
public class Riff {

@Id
@Column(nullable = false, name = "id", updatable = false)
@GeneratedValue(strategy = GenerationType.IDENTITY)
Long id;
String uid;
@Type(type = "bio.overture.riff.utils.CustomJsonType")
Map<String, Object> content;
String alias;
boolean sharedPublicly;
Date creationDate;
Date updatedDate;

@Id
@Column(nullable = false, name = "id", updatable = false)
@GeneratedValue(strategy = GenerationType.IDENTITY)
Long id;
String uid;
@Type(type = "bio.overture.riff.utils.CustomJsonType")
Map<String, Object> content;
String alias;
boolean sharedPublicly;
Date creationDate;
Date updatedDate;
}
1 change: 0 additions & 1 deletion src/main/java/bio/overture/riff/model/RiffResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.RequiredArgsConstructor;

import java.util.Date;
import java.util.Map;
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/bio/overture/riff/model/ShortenRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@
package bio.overture.riff.model;

import lombok.Data;

import java.util.Date;
import java.util.Map;

@Data
public class ShortenRequest {

Map<String, Object> content;
String alias;
boolean sharedPublicly;
Map<String, Object> content;
String alias;
boolean sharedPublicly;
Date creationDate;

}
12 changes: 11 additions & 1 deletion src/main/java/bio/overture/riff/repository/RiffRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,22 @@
package bio.overture.riff.repository;

import bio.overture.riff.model.Riff;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;

import javax.transaction.Transactional;
import java.util.Date;
import java.util.List;

public interface RiffRepository extends CrudRepository<Riff, Long> {

List<Riff> findByUidAndSharedPublicly(String uid, Boolean shared);
List<Riff> findByUidAndSharedPublicly(String uid, Boolean shared);

@Modifying
@Transactional
@Query("DELETE FROM Riff r WHERE r.creationDate <= :creationDate AND r.alias = :alias")
int deleteByAliasAndCreationDateBefore(@Param("alias") String alias, @Param("creationDate") Date creationDate);

}
146 changes: 78 additions & 68 deletions src/main/java/bio/overture/riff/service/RiffService.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,87 +24,97 @@
import bio.overture.riff.model.ShortenRequest;
import bio.overture.riff.repository.RiffRepository;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import lombok.val;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

@Slf4j
@Service
public class RiffService {

private RiffRepository repository;

@Autowired
public RiffService(RiffRepository repository) {
this.repository = repository;
}

public List<RiffResponse> getUserRiffs(JWTUser user) {
return repository.findByUidAndSharedPublicly(user.getUid(), false)
.stream()
.map(RiffResponse::new)
.collect(Collectors.toList());
}

@SneakyThrows
public RiffResponse getRiff(String id) {
val opt = repository.findById(Long.valueOf(id, 36));
if (opt.isPresent()) {
return new RiffResponse(opt.get());
} else {
throw new RiffNotFoundException();
private RiffRepository repository;

@Autowired
public RiffService(RiffRepository repository) {
this.repository = repository;
}

public List<RiffResponse> getUserRiffs(JWTUser user) {
return repository.findByUidAndSharedPublicly(user.getUid(), false)
.stream()
.map(RiffResponse::new)
.collect(Collectors.toList());
}

@SneakyThrows
public RiffResponse getRiff(String id) {
val opt = repository.findById(Long.valueOf(id, 36));
return opt.map(RiffResponse::new).orElseThrow(RiffNotFoundException::new);
}

@SneakyThrows
public RiffResponse makeRiff(JWTUser user, ShortenRequest request) {
val riff = Riff.builder()
.content(request.getContent())
.uid(user.getUid())
.alias(request.getAlias())
.sharedPublicly(request.isSharedPublicly())
.creationDate(request.getCreationDate() == null? new Date() : request.getCreationDate())
.updatedDate(new Date())
.build();

val newRiff = repository.save(riff);
return new RiffResponse(newRiff);
}
}

@SneakyThrows
public RiffResponse makeRiff(JWTUser user, ShortenRequest request) {
val riff = Riff.builder()
.content(request.getContent())
.uid(user.getUid())
.alias(request.getAlias())
.sharedPublicly(request.isSharedPublicly())
.creationDate(new Date())
.updatedDate(new Date())
.build();

val newRiff = repository.save(riff);
return new RiffResponse(newRiff);
}

public boolean deleteRiff(JWTUser user, String id) {
val optionalRiff = repository.findById(Long.valueOf(id, 36));
if (optionalRiff.isPresent()) {
val riff = optionalRiff.get();
if (user.getUid().equals(riff.getUid())) {
repository.delete(riff);
return true;
}

public boolean deleteRiff(JWTUser user, String id) {
val optionalRiff = repository.findById(Long.valueOf(id, 36));
return optionalRiff
.filter(r -> canAccessRiff(user, r))
.map(r -> {
repository.delete(r);
return true;
})
.orElse(false);
}

public int deletePhantomSets(JWTUser user) {
//TODO: add user verification
Calendar cal = Calendar.getInstance();
cal.add(Calendar.MONTH, -1);

return repository.deleteByAliasAndCreationDateBefore("", cal.getTime());
}
return false;
}

@SneakyThrows
public RiffResponse updateRiff(JWTUser user, String id, ShortenRequest request) {
val storageId = Long.valueOf(id, 36);
val optionalRiff = repository.findById(storageId);
if (optionalRiff.isPresent()) {
val riff = Riff.builder()
.id(storageId)
.content(request.getContent())
.uid(user.getUid())
.alias(request.getAlias())
.sharedPublicly(request.isSharedPublicly())
.creationDate(optionalRiff.get().getCreationDate())
.updatedDate(new Date())
.build();
val updated = repository.save(riff);
return new RiffResponse(updated);
} else {
throw new RiffNotFoundException();

@SneakyThrows
public RiffResponse updateRiff(JWTUser user, String id, ShortenRequest request) {
val storageId = Long.valueOf(id, 36);
val optionalRiff = repository.findById(storageId);
val riff = optionalRiff
.filter(r -> canAccessRiff(user, r))
.map(r ->
Riff.builder().id(storageId).content(request.getContent())
.uid(user.getUid())
.alias(request.getAlias())
.sharedPublicly(request.isSharedPublicly())
.creationDate(r.getCreationDate())
.updatedDate(new Date())
.build()
)
.orElseThrow(RiffNotFoundException::new);
val updated = repository.save(riff);
return new RiffResponse(updated);
}

private boolean canAccessRiff(JWTUser user, Riff r) {
return r.getUid().equals(user.getUid());
}
}


}
2 changes: 1 addition & 1 deletion src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ server:

auth:
jwt:
publicKeyUrl: "https://demo.ego.kfdrc.org/oauth/token/public_key"
publicKeyUrl: "https://kf-strides-ego-qa.kidsfirstdrc.org/oauth/token/public_key"

spring:
jpa:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* Database migration script for Riff's PostgreSQL database.
*
* This script renames the study names stored in the queries for the cohort builder and the file repository.
* This is done so that the former queries remain valid once the studies have been renamed in the release coordinator.
*
* @date 2019-06-28
*/

/*
* The search queries in the cohort builder are stored as JSON.
* The elements in this list are alphatically sorted.
* We include the initial double quote, to reduce risks of false positives.
*/
UPDATE riff SET content = REPLACE(content::TEXT, '"Adolescent Idiopathic Scoliosis', '"Kids First: Adolescent Idiopathic Scoliosis')::JSON;
UPDATE riff SET content = REPLACE(content::TEXT, '"Congenital Diaphragmatic Hernia', '"Kids First: Congenital Diaphragmatic Hernia')::JSON;
UPDATE riff SET content = REPLACE(content::TEXT, '"Congenital Hearth Defects', '"Kids First: Congenital Hearth Defects')::JSON;
UPDATE riff SET content = REPLACE(content::TEXT, '"Disorder of Sex Development', '"Kids First: Disorder of Sex Development')::JSON;
UPDATE riff SET content = REPLACE(content::TEXT, '"Ewing Sarcoma: Genetic Risk', '"Kids First: Ewing Sarcoma - Genetic Risk')::JSON;
UPDATE riff SET content = REPLACE(content::TEXT, '"Orofacial Cleft: European Ancestry', '"Kids First: Orofacial Cleft - European Ancestry')::JSON;
UPDATE riff SET content = REPLACE(content::TEXT, '"Orofacial Cleft: Latin American', '"Kids First: Orofacial Cleft - Latin American')::JSON;
UPDATE riff SET content = REPLACE(content::TEXT, '"Pediatric Brain Tumors: CBTTC', '"Consortium: Pediatric Brain Tumors - CBTTC')::JSON;
UPDATE riff SET content = REPLACE(content::TEXT, '"Syndromic Cranial Dysinnervation', '"Kids First: Syndromic Cranial Dysinnervation')::JSON;

/*
* The search queries in the file repository are stored as their full URL. The SQON is therefore URL-encoded:
* The elements in this list are alphatically sorted.
* We include the initial double quote, to reduce risks of false positives.
*/
UPDATE riff SET content = REPLACE(content::TEXT, '%22Adolescent%20Idiopathic%20Scoliosis', '%22Kids%20First%3A%20Adolescent%20Idiopathic%20Scoliosis')::JSON;
UPDATE riff SET content = REPLACE(content::TEXT, '%22Congenital%20Diaphragmatic%20Hernia', '%22Kids%20First%3A%20Congenital%20Diaphragmatic%20Hernia')::JSON;
UPDATE riff SET content = REPLACE(content::TEXT, '%22Congenital%20Hearth%20Defects', '%22Kids%20First%3A%20Congenital%20Hearth%20Defects')::JSON;
UPDATE riff SET content = REPLACE(content::TEXT, '%22Disorder%20of%20Sex%20Development', '%22Kids%20First%3A%20Disorder%20of%20Sex%20Development')::JSON;
UPDATE riff SET content = REPLACE(content::TEXT, '%22Ewing%20Sarcoma%3A%20Genetic%20Risk', '%22Kids%20First%3A%20Ewing%20Sarcoma%20-%20Genetic%20Risk')::JSON;
UPDATE riff SET content = REPLACE(content::TEXT, '%22Orofacial%20Cleft:%20European%20Ancestry', '%22Kids%20First%3A%20Orofacial%20Cleft%20-%20European%20Ancestry')::JSON;
UPDATE riff SET content = REPLACE(content::TEXT, '%22Orofacial%20Cleft:%20Latin%20American', '%22Kids%20First%3A%20Orofacial%20Cleft%20-%20Latin%20American')::JSON;
UPDATE riff SET content = REPLACE(content::TEXT, '%22Pediatric%20Brain%20Tumors%3A%20CBTTC', '%22Consortium3A%20Pediatric%20Brain%20Tumors%20-%20CBTTC')::JSON;
UPDATE riff SET content = REPLACE(content::TEXT, '%22Syndromic%20Cranial%20Dysinnervation', '%22Kids%20First%3A%20Syndromic%20Cranial%20Dysinnervation')::JSON;

21 changes: 21 additions & 0 deletions src/main/resources/flyway/sql/V4__rename_study_cbttc_atlas.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* Database migration script for Riff's PostgreSQL database.
*
* This script renames the study names stored in the queries for the cohort builder and the file repository.
* This is done so that the former queries remain valid once the studies have been renamed in the release coordinator.
*
* @date 2019-08-07
*/

/*
* The search queries in the cohort builder are stored as JSON.
* We include the initial double quote, to reduce risks of false positives.
*/
UPDATE riff SET content = REPLACE(content::TEXT, '"Consortium: Pediatric Brain Tumors - CBTTC', '"Pediatric Brain Tumor Atlas: CBTTC')::JSON;

/*
* The search queries in the file repository are stored as their full URL. The SQON is therefore URL-encoded:
* We include the initial double quote, to reduce risks of false positives.
*/
UPDATE riff SET content = REPLACE(content::TEXT, '%22Consortium3A%20Pediatric%20Brain%20Tumors%20-%20CBTTC', '%22Pediatric%20Brain%20Tumors%20Atlas%3A%20CBTTC')::JSON;

Loading