Skip to content

Commit

Permalink
Util to generateId, remove extra userEmail args (#999)
Browse files Browse the repository at this point in the history
  • Loading branch information
dexamundsen authored Sep 13, 2024
1 parent 6a3ee72 commit 41a32d7
Show file tree
Hide file tree
Showing 39 changed files with 291 additions and 360 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/regression-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ jobs:
env:
TEST_PROJECT_SA_KEY: ${{ secrets.TEST_PROJECT_SA_KEY }}
- name: Gradle Run Regression Tests Only
run: ./gradlew service:regressionTests -PregressionTestUnderlays=cmssynpuf,aouSR2019q4r4 --info --scan
run: ./gradlew service:regressionTests -PregressionTestUnderlays=cmssynpuf,aouSR2019q4r4 --scan
env:
DBMS: postgresql
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
mkdir -p rendered/
echo "$GHA_SA_KEY" > rendered/gha_sa_key.json
export GOOGLE_APPLICATION_CREDENTIALS=$PWD/rendered/gha_sa_key.json
./tanagra/gradlew -p tanagra service:regressionTests -PregressionTestUnderlays="${UNDERLAYS:-$DEFAULT_UNDERLAYS}" --info --scan
./tanagra/gradlew -p tanagra service:regressionTests -PregressionTestUnderlays="${UNDERLAYS:-$DEFAULT_UNDERLAYS}" --scan
env:
DBMS: postgresql
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -497,14 +497,11 @@ public enum JobExecutor {

public JobRunner getRunner(
List<SequencedJobSet> jobSets, boolean isDryRun, IndexingJob.RunType runType) {
switch (this) {
case SERIAL:
return new SerialRunner(jobSets, isDryRun, runType);
case PARALLEL:
return new ParallelRunner(jobSets, isDryRun, runType);
default:
throw new IllegalArgumentException("Unknown JobExecution enum type: " + this);
}
return switch (this) {
case SERIAL -> new SerialRunner(jobSets, isDryRun, runType);
case PARALLEL -> new ParallelRunner(jobSets, isDryRun, runType);
default -> throw new IllegalArgumentException("Unknown JobExecution enum type: " + this);
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ public ResponseEntity<ApiCohort> createCohort(String studyId, ApiCohortCreateInf
Cohort.builder()
.displayName(body.getDisplayName())
.description(body.getDescription())
.underlay(body.getUnderlayName()),
SpringAuthentication.getCurrentUser().getEmail());
.underlay(body.getUnderlayName())
.createdBy(SpringAuthentication.getCurrentUser().getEmail()));
return ResponseEntity.ok(ToApiUtils.toApiObject(createdCohort));
}

Expand Down Expand Up @@ -195,36 +195,36 @@ public ResponseEntity<ApiInstanceCountList> queryCohortCounts(

private static CohortRevision.CriteriaGroupSection fromApiObject(ApiCriteriaGroupSection apiObj) {
BooleanAndOrFilter.LogicalOperator operator;
JoinOperator joinOperator;
switch (apiObj.getOperator()) {
case OR:
operator = BooleanAndOrFilter.LogicalOperator.OR;
joinOperator = null;
break;
case AND:
operator = BooleanAndOrFilter.LogicalOperator.AND;
joinOperator = null;
break;
case DURING_SAME_ENCOUNTER:
operator = BooleanAndOrFilter.LogicalOperator.OR;
joinOperator = JoinOperator.DURING_SAME_ENCOUNTER;
break;
case WITHIN_NUM_DAYS:
operator = BooleanAndOrFilter.LogicalOperator.OR;
joinOperator = JoinOperator.WITHIN_NUM_DAYS;
break;
case NUM_DAYS_BEFORE:
operator = BooleanAndOrFilter.LogicalOperator.OR;
joinOperator = JoinOperator.NUM_DAYS_BEFORE;
break;
case NUM_DAYS_AFTER:
operator = BooleanAndOrFilter.LogicalOperator.OR;
joinOperator = JoinOperator.NUM_DAYS_AFTER;
break;
default:
throw new IllegalArgumentException(
"Unknown criteria group section operator: " + apiObj.getOperator());
}
JoinOperator joinOperator =
switch (apiObj.getOperator()) {
case OR -> {
operator = BooleanAndOrFilter.LogicalOperator.OR;
yield null;
}
case AND -> {
operator = BooleanAndOrFilter.LogicalOperator.AND;
yield null;
}
case DURING_SAME_ENCOUNTER -> {
operator = BooleanAndOrFilter.LogicalOperator.OR;
yield JoinOperator.DURING_SAME_ENCOUNTER;
}
case WITHIN_NUM_DAYS -> {
operator = BooleanAndOrFilter.LogicalOperator.OR;
yield JoinOperator.WITHIN_NUM_DAYS;
}
case NUM_DAYS_BEFORE -> {
operator = BooleanAndOrFilter.LogicalOperator.OR;
yield JoinOperator.NUM_DAYS_BEFORE;
}
case NUM_DAYS_AFTER -> {
operator = BooleanAndOrFilter.LogicalOperator.OR;
yield JoinOperator.NUM_DAYS_AFTER;
}
default ->
throw new IllegalArgumentException(
"Unknown criteria group section operator: " + apiObj.getOperator());
};

return CohortRevision.CriteriaGroupSection.builder()
.id(apiObj.getId())
Expand Down Expand Up @@ -258,15 +258,11 @@ private static CohortRevision.CriteriaGroup fromApiObject(ApiCriteriaGroup apiOb
}

private static ReducingOperator fromApiObject(ApiReducingOperator apiObj) {
switch (apiObj) {
case ANY:
return null;
case FIRST_MENTION_OF:
return ReducingOperator.FIRST_MENTION_OF;
case LAST_MENTION_OF:
return ReducingOperator.LAST_MENTION_OF;
default:
throw new IllegalArgumentException("Unknown reducing operator: " + apiObj);
}
return switch (apiObj) {
case ANY -> null;
case FIRST_MENTION_OF -> ReducingOperator.FIRST_MENTION_OF;
case LAST_MENTION_OF -> ReducingOperator.LAST_MENTION_OF;
default -> throw new IllegalArgumentException("Unknown reducing operator: " + apiObj);
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,10 @@ public ResponseEntity<ApiReviewList> listReviews(
offset,
limit);
ApiReviewList apiReviews = new ApiReviewList();
Cohort cohort = cohortService.getCohort(studyId, cohortId);
reviewService
.listReviews(authorizedReviewIds, offset, limit)
.forEach(
review ->
apiReviews.add(toApiObject(review, cohortService.getCohort(studyId, cohortId))));
.forEach(review -> apiReviews.add(toApiObject(review, cohort)));
return ResponseEntity.ok(apiReviews);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -481,18 +481,13 @@ private static ValueDisplayField buildRelationshipField(
}

public static Literal fromApiObject(ApiLiteral apiLiteral) {
switch (apiLiteral.getDataType()) {
case INT64:
return Literal.forInt64(apiLiteral.getValueUnion().getInt64Val());
case STRING:
return Literal.forString(apiLiteral.getValueUnion().getStringVal());
case BOOLEAN:
return Literal.forBoolean(apiLiteral.getValueUnion().isBoolVal());
case DATE:
return Literal.forDate(apiLiteral.getValueUnion().getDateVal());
default:
throw new SystemException("Unknown API data type: " + apiLiteral.getDataType());
}
return switch (apiLiteral.getDataType()) {
case INT64 -> Literal.forInt64(apiLiteral.getValueUnion().getInt64Val());
case STRING -> Literal.forString(apiLiteral.getValueUnion().getStringVal());
case BOOLEAN -> Literal.forBoolean(apiLiteral.getValueUnion().isBoolVal());
case DATE -> Literal.forDate(apiLiteral.getValueUnion().getDateVal());
default -> throw new SystemException("Unknown API data type: " + apiLiteral.getDataType());
};
}

public static BinaryOperator fromApiObject(ApiBinaryOperator apiOperator) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,29 +67,28 @@ public static ApiLiteral toApiObject(Literal literal) {

ApiLiteral apiLiteral =
new ApiLiteral().dataType(ApiDataType.fromValue(literal.getDataType().name()));
switch (literal.getDataType()) {
case INT64:
return apiLiteral.valueUnion(new ApiLiteralValueUnion().int64Val(literal.getInt64Val()));
case STRING:
return apiLiteral.valueUnion(new ApiLiteralValueUnion().stringVal(literal.getStringVal()));
case BOOLEAN:
return apiLiteral.valueUnion(new ApiLiteralValueUnion().boolVal(literal.getBooleanVal()));
case DATE:
return apiLiteral.valueUnion(
new ApiLiteralValueUnion()
.dateVal(literal.getDateVal() == null ? null : literal.getDateVal().toString()));
case TIMESTAMP:
return apiLiteral.valueUnion(
new ApiLiteralValueUnion()
.timestampVal(
literal.getTimestampVal() == null
? null
: literal.getTimestampVal().toString()));
case DOUBLE:
return apiLiteral.valueUnion(new ApiLiteralValueUnion().doubleVal(literal.getDoubleVal()));
default:
throw new SystemException("Unknown data type: " + literal.getDataType());
}
return switch (literal.getDataType()) {
case INT64 ->
apiLiteral.valueUnion(new ApiLiteralValueUnion().int64Val(literal.getInt64Val()));
case STRING ->
apiLiteral.valueUnion(new ApiLiteralValueUnion().stringVal(literal.getStringVal()));
case BOOLEAN ->
apiLiteral.valueUnion(new ApiLiteralValueUnion().boolVal(literal.getBooleanVal()));
case DATE ->
apiLiteral.valueUnion(
new ApiLiteralValueUnion()
.dateVal(literal.getDateVal() == null ? null : literal.getDateVal().toString()));
case TIMESTAMP ->
apiLiteral.valueUnion(
new ApiLiteralValueUnion()
.timestampVal(
literal.getTimestampVal() == null
? null
: literal.getTimestampVal().toString()));
case DOUBLE ->
apiLiteral.valueUnion(new ApiLiteralValueUnion().doubleVal(literal.getDoubleVal()));
default -> throw new SystemException("Unknown data type: " + literal.getDataType());
};
}

public static ApiCohort toApiObject(Cohort cohort) {
Expand Down Expand Up @@ -215,8 +214,7 @@ private static ApiInstance toApiObject(ListInstance listInstance) {
hierarchyFieldSets,
((HierarchyIsMemberField) field).getHierarchy().getName())
.setIsMember(value.getValue().getBooleanVal());
} else if (field instanceof RelatedEntityIdCountField) {
RelatedEntityIdCountField countField = (RelatedEntityIdCountField) field;
} else if (field instanceof RelatedEntityIdCountField countField) {
relationshipFieldSets.add(
new ApiInstanceRelationshipFields()
.relatedEntity(countField.getCountedEntity().getName())
Expand Down
3 changes: 0 additions & 3 deletions service/src/main/java/bio/terra/tanagra/db/CohortDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -327,10 +327,7 @@ public String createNextRevision(
.setIsMostRecent(true)
.version(cohort.getMostRecentRevision().getVersion() + 1)
.createdBy(userEmail)
.lastModifiedBy(userEmail)
.id(null) // Builder will generate a new id.
.created(null)
.lastModified(null)
.recordsCount(null) // Only store the records count for frozen revisions.
.build();
createRevision(cohortId, nextRevision);
Expand Down
11 changes: 11 additions & 0 deletions service/src/main/java/bio/terra/tanagra/service/ServiceUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package bio.terra.tanagra.service;

import org.apache.commons.lang3.RandomStringUtils;

public class ServiceUtils {
private ServiceUtils() {}

public static String newArtifactId() {
return RandomStringUtils.randomAlphanumeric(10);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

Expand Down Expand Up @@ -65,23 +64,19 @@ public UnderlayService(

public List<Underlay> listUnderlays(ResourceCollection authorizedIds) {
if (authorizedIds.isAllResources()) {
return underlayCache.values().stream()
.map(CachedUnderlay::getUnderlay)
.collect(Collectors.toUnmodifiableList());
return underlayCache.values().stream().map(CachedUnderlay::getUnderlay).toList();
} else {
// If the incoming list is empty, the caller does not have permission to see any
// underlays, so we return an empty list.
if (authorizedIds.isEmpty()) {
return Collections.emptyList();
}
List<String> authorizedNames =
authorizedIds.getResources().stream()
.map(ResourceId::getUnderlay)
.collect(Collectors.toList());
authorizedIds.getResources().stream().map(ResourceId::getUnderlay).toList();
return underlayCache.values().stream()
.map(CachedUnderlay::getUnderlay)
.filter(underlay -> authorizedNames.contains(underlay.getName()))
.collect(Collectors.toUnmodifiableList());
.toList();
}
}

Expand Down
Loading

0 comments on commit 41a32d7

Please sign in to comment.