Skip to content

Commit

Permalink
Merge pull request #74 from waterflow80/fix-for-issue-70
Browse files Browse the repository at this point in the history
Checking for undefined attributes that could be sent by the user in the comparison POST request
  • Loading branch information
waterflow80 authored Jan 8, 2024
2 parents ca90fc9 + ca954c0 commit 4d82114
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.hibernate.annotations.TypeDefs;

import uk.ac.ebi.eva.evaseqcol.digests.DigestCalculator;
import uk.ac.ebi.eva.evaseqcol.exception.AttributeNotDefinedException;
import uk.ac.ebi.eva.evaseqcol.model.NameLengthPairEntity;
import uk.ac.ebi.eva.evaseqcol.utils.JSONExtData;
import uk.ac.ebi.eva.evaseqcol.utils.JSONIntegerListExtData;
Expand Down Expand Up @@ -71,7 +72,7 @@ public static AttributeType fromAttributeVal(String attrVal) {
return b;
}
}
throw new IllegalArgumentException("No seqcol attribute with value " + attrVal + " found");
throw new AttributeNotDefinedException("No seqcol attribute with value \"" + attrVal + "\" found");
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package uk.ac.ebi.eva.evaseqcol.exception;

/**
* This exception should be thrown when an undefined seqcol attribute has
* been given (normally by the user in the POST comparison request's body)*/
public class AttributeNotDefinedException extends RuntimeException{

public AttributeNotDefinedException(String msg) {
super(msg);
}
}
17 changes: 11 additions & 6 deletions src/main/java/uk/ac/ebi/eva/evaseqcol/service/SeqColService.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import uk.ac.ebi.eva.evaseqcol.entities.SeqColLevelOneEntity;
import uk.ac.ebi.eva.evaseqcol.entities.SeqColExtendedDataEntity;
import uk.ac.ebi.eva.evaseqcol.entities.SeqColLevelTwoEntity;
import uk.ac.ebi.eva.evaseqcol.exception.AttributeNotDefinedException;
import uk.ac.ebi.eva.evaseqcol.exception.DuplicateSeqColException;
import uk.ac.ebi.eva.evaseqcol.exception.SeqColNotFoundException;
import uk.ac.ebi.eva.evaseqcol.exception.UnableToLoadServiceInfoException;
Expand Down Expand Up @@ -377,12 +378,16 @@ public Map<String, String> constructSeqColLevelOneMap(Map<String, List<?>> seqCo
Map<String, String> seqColL1Map = new TreeMap<>();
Set<String> seqColAttributes = seqColL2Map.keySet(); // The set of the seqCol attributes ("lengths", "sequences", etc.)
for (String attribute: seqColAttributes) {
String attributeDigest;
attributeDigest= digestCalculator.getSha512Digest(
convertSeqColLevelTwoAttributeValuesToString(seqColL2Map.get(attribute),
SeqColExtendedDataEntity.AttributeType.fromAttributeVal(
attribute)));
seqColL1Map.put(attribute, attributeDigest);
try {
String attributeDigest;
attributeDigest= digestCalculator.getSha512Digest(
convertSeqColLevelTwoAttributeValuesToString(seqColL2Map.get(attribute),
SeqColExtendedDataEntity.AttributeType.fromAttributeVal(
attribute)));
seqColL1Map.put(attribute, attributeDigest);
} catch (AttributeNotDefinedException e) {
logger.warn(e.getMessage());
}
}
return seqColL1Map;
}
Expand Down

0 comments on commit 4d82114

Please sign in to comment.