-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46 from VEuPathDB/dataset-upload-fix
Dataset upload fix
Showing
14 changed files
with
325 additions
and
207 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
Model/src/main/java/org/gusdb/wdk/model/record/PrimaryKeyIterator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package org.gusdb.wdk.model.record; | ||
|
||
import java.util.Iterator; | ||
|
||
public interface PrimaryKeyIterator extends Iterator<String[]>, AutoCloseable { | ||
|
||
// no additional methods | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
Model/src/main/java/org/gusdb/wdk/model/record/ResultSetPrimaryKeyIterator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package org.gusdb.wdk.model.record; | ||
|
||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
import java.util.Optional; | ||
|
||
import org.gusdb.fgputil.db.stream.ResultSetIterator; | ||
|
||
public class ResultSetPrimaryKeyIterator extends ResultSetIterator<String[]> implements PrimaryKeyIterator { | ||
|
||
private static class PrimaryKeyRowConverter implements RowConverter<String[]> { | ||
|
||
private final String[] _pkColumns; | ||
|
||
public PrimaryKeyRowConverter(PrimaryKeyDefinition pkDef) { | ||
_pkColumns = pkDef.getColumnRefs(); | ||
} | ||
|
||
@Override | ||
public Optional<String[]> convert(ResultSet rs) throws SQLException { | ||
String[] values = new String[_pkColumns.length]; | ||
for (int i = 0; i < _pkColumns.length; i++) { | ||
Object value = rs.getObject(_pkColumns[i]); | ||
values[i] = (value == null) ? null : value.toString(); | ||
} | ||
return Optional.of(values); | ||
} | ||
} | ||
|
||
public ResultSetPrimaryKeyIterator(PrimaryKeyDefinition pkDef, ResultSet rs) { | ||
super(rs, new PrimaryKeyRowConverter(pkDef)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
Service/src/main/java/org/gusdb/wdk/service/request/user/dataset/DatasetRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package org.gusdb.wdk.service.request.user.dataset; | ||
|
||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.stream.Collectors; | ||
|
||
import org.gusdb.fgputil.functional.Functions; | ||
import org.gusdb.fgputil.json.JsonType; | ||
import org.gusdb.fgputil.json.JsonUtil; | ||
import org.gusdb.wdk.core.api.JsonKeys; | ||
import org.gusdb.wdk.service.request.exception.RequestMisformatException; | ||
import org.json.JSONObject; | ||
|
||
public class DatasetRequest { | ||
|
||
private final DatasetSourceType _sourceType; | ||
private final JsonType _configValue; | ||
private final Optional<String> _displayName; | ||
private final Map<String,JsonType> _additionalConfig; | ||
|
||
public DatasetRequest(JSONObject input) throws RequestMisformatException { | ||
_sourceType = DatasetSourceType.getFromTypeIndicator(input.getString(JsonKeys.SOURCE_TYPE)); | ||
JSONObject sourceContent = input.getJSONObject(JsonKeys.SOURCE_CONTENT); | ||
_configValue = new JsonType(sourceContent.get(_sourceType.getConfigJsonKey())); | ||
if (!_configValue.getType().equals(_sourceType.getConfigType())) { | ||
throw new RequestMisformatException("Value of '" + | ||
_sourceType.getConfigJsonKey() + "' must be a " + _sourceType.getConfigType()); | ||
} | ||
_additionalConfig = Functions.getMapFromKeys( | ||
JsonUtil.getKeys(sourceContent).stream() | ||
.filter(key -> !key.equals(_sourceType.getConfigJsonKey())) | ||
.collect(Collectors.toSet()), | ||
key -> new JsonType(sourceContent.get(key))); | ||
_displayName = Optional.ofNullable(JsonUtil.getStringOrDefault(input, JsonKeys.DISPLAY_NAME, null)); | ||
} | ||
|
||
public DatasetSourceType getSourceType() { return _sourceType; } | ||
public JsonType getConfigValue() { return _configValue; } | ||
public Optional<String> getDisplayName() { return _displayName; } | ||
public Map<String,JsonType> getAdditionalConfig() { return _additionalConfig; } | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
Service/src/main/java/org/gusdb/wdk/service/request/user/dataset/DatasetSourceType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package org.gusdb.wdk.service.request.user.dataset; | ||
|
||
import java.util.Arrays; | ||
|
||
import org.gusdb.fgputil.FormatUtil; | ||
import org.gusdb.fgputil.json.JsonType.ValueType; | ||
import org.gusdb.wdk.core.api.JsonKeys; | ||
import org.gusdb.wdk.service.request.exception.RequestMisformatException; | ||
|
||
/** | ||
* Contains the possible ways a user can submit a dataset (for use as a dataset param), | ||
* along with how to parse the config JSON for the submission. | ||
*/ | ||
public enum DatasetSourceType { | ||
|
||
ID_LIST("idList", "ids", ValueType.ARRAY), | ||
BASKET("basket", "basketName", ValueType.STRING), | ||
FILE("file", "temporaryFileId", ValueType.STRING), | ||
STRATEGY("strategy", JsonKeys.STRATEGY_ID, ValueType.NUMBER), | ||
URL("url", "url", ValueType.STRING); | ||
|
||
private final String _typeIndicator; | ||
private final String _configJsonKey; | ||
private final ValueType _configValueType; | ||
|
||
DatasetSourceType(String typeIndicator, String configJsonKey, ValueType configValueType) { | ||
_typeIndicator = typeIndicator; | ||
_configJsonKey = configJsonKey; | ||
_configValueType = configValueType; | ||
} | ||
|
||
public String getTypeIndicator() { | ||
return _typeIndicator; | ||
} | ||
|
||
public String getConfigJsonKey() { | ||
return _configJsonKey; | ||
} | ||
|
||
public ValueType getConfigType() { | ||
return _configValueType; | ||
} | ||
|
||
public static DatasetSourceType getFromTypeIndicator(String typeIndicator) throws RequestMisformatException { | ||
return Arrays.stream(values()) | ||
.filter(val -> val._typeIndicator.equals(typeIndicator)) | ||
.findFirst() | ||
.orElseThrow(() -> new RequestMisformatException( | ||
"Invalid source type. Only [" + FormatUtil.join(values(), ", ") + "] allowed.")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters