Skip to content

Commit

Permalink
Merge pull request #285 from overture-stack/feature/song-128-score-mo…
Browse files Browse the repository at this point in the history
…unt-endpoint

Feature/song 128 score mount endpoint
  • Loading branch information
andricDu authored May 28, 2018
2 parents 008d741 + 938c64d commit 851a4bc
Show file tree
Hide file tree
Showing 23 changed files with 903 additions and 136 deletions.
22 changes: 22 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,18 @@
<version>${hibernate-native-json.version}</version>
</dependency>

<!-- Mapstruct - automated pojo mapping -->
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-jdk8</artifactId>
<version>${mapstruct.version}</version>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${mapstruct.version}</version>
</dependency>

<!-- Hibernate Validator -->
<!--Validates annotations at build time-->
<dependency>
Expand All @@ -114,6 +126,11 @@
<version>${hibernate-validator.version}</version>
</dependency>

<dependency>
<groupId>com.github.bohnman</groupId>
<artifactId>squiggly-filter-jackson</artifactId>
<version>${squiggly-version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.uuid</groupId>
<artifactId>java-uuid-generator</artifactId>
Expand Down Expand Up @@ -203,6 +220,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<inherited>true</inherited>
<configuration>
<source>${java.version}</source>
Expand Down Expand Up @@ -254,6 +272,7 @@

<properties>
<!-- Project Related Properties -->
<maven-compiler-plugin.version>3.7.0</maven-compiler-plugin.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
Expand Down Expand Up @@ -284,6 +303,9 @@
<guava.version>24.1-jre</guava.version>
<jcommander.version>1.69</jcommander.version>
<jansi.version>1.16</jansi.version>
<squiggly-version>1.3.11</squiggly-version>
<mapstruct.version>1.2.0.Final</mapstruct.version>

</properties>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public enum ServerErrors implements ServerError {
PAYLOAD_PARSING(UNPROCESSABLE_ENTITY),
UPLOAD_ID_NOT_FOUND(NOT_FOUND ),
FILE_NOT_FOUND(NOT_FOUND ),
LEGACY_ENTITY_NOT_FOUND(NOT_FOUND ),
INFO_NOT_FOUND(NOT_FOUND ),
UPLOAD_ID_NOT_VALIDATED(CONFLICT),
ANALYSIS_ID_NOT_CREATED(INTERNAL_SERVER_ERROR),
Expand Down Expand Up @@ -85,6 +86,9 @@ public enum ServerErrors implements ServerError {
SEQUENCING_READ_CORRUPTED_DUPLICATE(INTERNAL_SERVER_ERROR),
DUPLICATE_ANALYSIS_ATTEMPT(CONFLICT),
STUDY_ALREADY_EXISTS(CONFLICT),
ILLEGAL_FILTER_PARAMETER(BAD_REQUEST),
ILLEGAL_QUERY_PARAMETER(BAD_REQUEST),
UNREGISTERED_TYPE(INTERNAL_SERVER_ERROR),
UNKNOWN_ERROR(INTERNAL_SERVER_ERROR);

private static final String ERROR_ID_SEPARATOR = ".";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.icgc.dcc.song.core.utils;

import com.fasterxml.uuid.impl.RandomBasedGenerator;
import com.google.common.collect.ImmutableList;
import com.google.common.hash.Hashing;
import lombok.Getter;
import lombok.NonNull;
Expand All @@ -36,7 +37,9 @@
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.collect.Lists.newArrayList;
import static java.lang.Integer.MAX_VALUE;
import static java.util.Collections.shuffle;
import static java.util.stream.Collectors.toList;
import static org.icgc.dcc.common.core.util.stream.Collectors.toImmutableList;

/**
* Utility for generating random integers, strings and UUIDs using seed values while recording call counts to
Expand Down Expand Up @@ -115,19 +118,19 @@ public int generateRandomInt(){
}

/**
* Generate a random integer between the interval [min, max)
* @param min inclusive lower bound
* @param max exclusive upper bound
* Generate a random integer between the interval [inclusiveMin, exlusiveMax)
* @param inclusiveMin inclusive lower bound
* @param exlusiveMax exclusive upper bound
*/
public int generateRandomIntRange(int min, int max){
public int generateRandomIntRange(int inclusiveMin, int exlusiveMax){
log.info("Generating RandomIntRange for RandomGenerator[{}] with seed '{}' and callCount '{}'",
id, seed, callCount);
checkArgument(min<max,"The min(%s) must be LESS THAN max(%s)", min, max);
val difference = (long)max - min;
checkArgument(inclusiveMin<exlusiveMax,"The inclusiveMin(%s) must be LESS THAN exclusiveMax(%s)", inclusiveMin, exlusiveMax);
val difference = (long)exlusiveMax - inclusiveMin;
checkArgument(difference <= MAX_VALUE,
"The difference (%s) between max (%s) and (%s) must not exceed the integer max (%s)",
difference, max, min, MAX_VALUE);
return generateRandomInt(min, max-min);
"The difference (%s) between exclusiveMax (%s) and (%s) must not exceed the integer exclusiveMax (%s)",
difference, exlusiveMax, inclusiveMin, MAX_VALUE);
return generateRandomInt(inclusiveMin, exlusiveMax-inclusiveMin);
}

/**
Expand Down Expand Up @@ -158,6 +161,42 @@ public <E extends Enum<E>> E randomEnum(Class<E> enumClass){
return randomElement(enumList);
}

/**
* Creates a new shuffled list. Assumes the input list is immutable
* @param list input List
* @return shuffles list
*/
public <T> List<T> shuffleList(List<T> list){
log.info("Shuffling list for RandomGenerator[{}] with seed '{}' and callCount '{}'",
id, seed, callCount++);
val mutableList = newArrayList(list);
shuffle(mutableList, random);
return ImmutableList.copyOf(mutableList);
}

/**
* Creates a random sublist of size {@code size}, from an input list
*/
public <T> List<T> randomSublist(List<T> list, int size){
checkArgument(size <= list.size(),
"The input sublist size (%s) is greater than the list size (%s)", size, list.size());
val shuffledList = shuffleList(IntStream.range(0,list.size()).boxed().collect(toList()));
return IntStream.range(0, size)
.boxed()
.map(shuffledList::get)
.map(list::get)
.collect(toImmutableList());
}

/**
* Take an input list of size {@code inputSize}, and generate a random sublist of size {@code outputSize}
* where {@code outputSize} is in the range [1, inputSize )
*/
public <T> List<T> randomSublist(List<T> list){
val size = generateRandomIntRange(1,list.size());
return randomSublist(list, size);
}

/**
* Select a random element from a list
* @param list input list to select from
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ public void testRandomMd5(){
assertThat(md5).isEqualTo("953a2fb1afb52dc0ef6a95ec5cac8680");
val randomGenerator2 = createRandomGenerator("rand1-seed1", 100);
assertThat(randomGenerator2.generateRandomMD5()).isNotEqualTo(md5);


}

@Test
Expand Down Expand Up @@ -177,7 +175,7 @@ public void runRandomIntRangeTest(int min, int max){
assertThat(throwable1)
.isInstanceOf(IllegalArgumentException.class)
.hasMessage(
format("The min(%s) must be LESS THAN max(%s)", max, min));
format("The inclusiveMin(%s) must be LESS THAN exclusiveMax(%s)", max, min));

val throwable2 = catchThrowable( () -> randomGenerator1.generateRandomIntRange(MIN_VALUE, MAX_VALUE));
assertThat(throwable2)
Expand Down
19 changes: 19 additions & 0 deletions song-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,17 @@
<artifactId>postgresql</artifactId>
</dependency>

<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-jdk8</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<scope>provided</scope>
</dependency>

<!-- Hibernate Json Types -->
<dependency>
<groupId>com.marvinformatics.hibernate</groupId>
Expand Down Expand Up @@ -110,6 +121,12 @@
<artifactId>jackson-datatype-jsr310</artifactId>
</dependency>

<!-- Squiggly - Dynamic JSON Views -->
<dependency>
<groupId>com.github.bohnman</groupId>
<artifactId>squiggly-filter-jackson</artifactId>
</dependency>

<!-- spring-kafka -->
<dependency>
<groupId>org.springframework.kafka</groupId>
Expand All @@ -120,6 +137,7 @@
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.icgc.dcc</groupId>
Expand Down Expand Up @@ -193,6 +211,7 @@
<!--</execution>-->
<!--</executions>-->
<!--</plugin>-->

<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.icgc.dcc.song.server.config;

import org.icgc.dcc.song.server.converter.LegacyEntityConverter;
import org.mapstruct.factory.Mappers;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ConverterConfig {

@Bean
public LegacyEntityConverter legacyEntityConverter(){
return Mappers.getMapper(LegacyEntityConverter.class);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
import lombok.val;
import org.icgc.dcc.song.core.utils.JsonDocUtils;
import org.icgc.dcc.song.core.utils.JsonSchemaUtils;
import org.icgc.dcc.song.server.model.legacy.LegacyEntity;
import org.icgc.dcc.song.server.model.entity.IdView;
import org.icgc.dcc.song.server.repository.search.IdSearchRequest;
import org.icgc.dcc.song.server.utils.ParameterChecker;
import org.icgc.dcc.song.server.validation.SchemaValidator;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
Expand All @@ -33,6 +37,8 @@
import java.util.HashMap;
import java.util.Map;

import static org.icgc.dcc.song.server.utils.ParameterChecker.createParameterChecker;

@Slf4j
@Configuration
@Data
Expand All @@ -49,6 +55,16 @@ public SchemaValidator schemaValidator() {
return new SchemaValidator();
}

@Bean
public ParameterChecker parameterChecker(){
return createParameterChecker(
LegacyEntity.class,
IdSearchRequest.class,
IdView.class,
IdView.IdViewProjection.class
);
}

@Bean
@Profile("async-test")
public Long validationDelayMs(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,20 @@

package org.icgc.dcc.song.server.controller;

import com.fasterxml.jackson.databind.JsonNode;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.icgc.dcc.song.server.model.LegacyEntity;
import org.icgc.dcc.song.server.model.legacy.Legacy;
import org.icgc.dcc.song.server.model.legacy.LegacyDto;
import org.icgc.dcc.song.server.service.LegacyEntityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.http.ResponseEntity;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
Expand All @@ -49,18 +54,18 @@ public class LegacyEntityController {
@ApiOperation(value = "ReadLegacyEntity", notes = "Read entity data for a legacy entity id")
@GetMapping(value = "/{id}")
@ResponseBody
public ResponseEntity<LegacyEntity> read(@PathVariable("id") String id) {
public ResponseEntity<Legacy> read(@PathVariable("id") String id) {
return ok(legacyEntityService.getEntity(id));
}

@ApiOperation(value = "ReadLegacyEntitiesByGnosId", notes = "Page through LegacyEntity data for a gnosId")
@GetMapping
@ApiOperation(value = "FindLegacyEntities", notes = "Page through LegacyEntity data")
@ResponseBody
public ResponseEntity<Page<LegacyEntity>> readGnosId(
@RequestParam(value = "gnosId") String gnosId,
@RequestParam(value = "size", required = false, defaultValue = "2000") int size,
@RequestParam(value = "page", required = false, defaultValue = "0") int page ) {
return ok(legacyEntityService.getEntitiesByGnosId(gnosId,size,page));
@GetMapping
public ResponseEntity<JsonNode> find(
@RequestParam MultiValueMap<String, String> params,
@ModelAttribute LegacyDto probe,
@PageableDefault(sort = "id") Pageable pageable) {
return ok(legacyEntityService.find(params, probe, pageable));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.icgc.dcc.song.server.converter;

import org.icgc.dcc.song.server.model.legacy.Legacy;
import org.icgc.dcc.song.server.model.legacy.LegacyDto;
import org.icgc.dcc.song.server.model.legacy.LegacyEntity;
import org.mapstruct.Mapper;

@Mapper
public interface LegacyEntityConverter {

LegacyDto convertToLegacyDto(Legacy legacy);
LegacyEntity convertToLegacyEntity(Legacy legacy);

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@

package org.icgc.dcc.song.server.model.enums;

import lombok.NonNull;
import org.icgc.dcc.common.core.util.stream.Streams;

import static java.lang.String.format;
import static java.util.Arrays.stream;

public enum AnalysisStates {
Expand All @@ -28,6 +32,14 @@ public String toString(){
return this.name();
}

public static AnalysisStates resolveAnalysisState(@NonNull String analysisState) {
return Streams.stream(values())
.filter(x -> x.toString().equals(analysisState))
.findFirst()
.orElseThrow(
() -> new IllegalStateException(format("The analysis state '%s' cannot be resolved", analysisState)));
}

public static String[] toStringArray(){
return stream(values())
.map(Enum::name)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.icgc.dcc.song.server.model.legacy;

public interface Legacy {

String getId();

String getGnosId();

String getFileName();

String getProjectCode();

String getAccess();

void setId(String id);

void setGnosId(String gnosId);

void setFileName(String fileName);

void setProjectCode(String projectCode);

void setAccess(String access);
}
Loading

0 comments on commit 851a4bc

Please sign in to comment.