in app/libraries/ExperimentUtilities.php [382:555]
public static function process_inputs($experimentFilePath, $applicationInputs, $experimentInputs)
{
$experimentAssemblySuccessful = true;
$newExperimentInputs = array();
//sending application inputs in the order defined by the admins.
$order = array();
foreach ($applicationInputs as $index => $input) {
$order[$index] = $input->inputOrder;
}
array_multisort($order, SORT_ASC, $applicationInputs);
foreach ($applicationInputs as $applicationInput) {
$experimentInput = $applicationInput;
if (($applicationInput->type == DataType::STRING) ||
($applicationInput->type == DataType::INTEGER) ||
($applicationInput->type == DataType::FLOAT)
) {
if (isset($_POST[$applicationInput->sanitizedFormName]) && (trim($_POST[$applicationInput->sanitizedFormName]) != '')) {
$experimentInput->value = $_POST[$applicationInput->sanitizedFormName];
$experimentInput->type = $applicationInput->type;
} else // use previous value
{
$index = -1;
for ($i = 0; $i < sizeof($experimentInputs); $i++) {
if ($experimentInputs[$i]->name == $applicationInput->name) {
$index = $i;
}
}
if ($index >= 0) {
$experimentInput->value = $experimentInputs[$index]->value;
$experimentInput->type = $applicationInput->type;
}
}
} elseif ($applicationInput->type == DataType::URI) {
if ($_FILES[$applicationInput->sanitizedFormName]['name']) {
$file = $_FILES[$applicationInput->sanitizedFormName];
if ($file['error'] != 0) {
throw new Exception("Failure occurred while uploading file '"
. $file['name'] . "'. File upload error code is " . $file['error'] . ".");
}
//FIX - AIRAVATA - 2674
//Replaced spaces with Underscore
$file['name'] = str_replace(' ', '_', $file['name']);
//
// move file to experiment data directory
//
if (!empty($applicationInput->value)) {
$filePath = $experimentFilePath . $applicationInput->value;
} else {
$filePath = $experimentFilePath . $file['name'];
}
// check if file already exists
if (is_file($filePath)) {
unlink($filePath);
CommonUtilities::print_warning_message('Uploaded file already exists! Overwriting...');
}
$moveFile = move_uploaded_file($file['tmp_name'], $filePath);
if (!$moveFile) {
CommonUtilities::print_error_message('<p>Error moving uploaded file ' . $file['name'] . '!
Please try again later or report a bug using the link in the Help menu.</p>');
$experimentAssemblySuccessful = false;
}
$experimentInput->type = $applicationInput->type;
$dataProductModel = new DataProductModel();
$dataProductModel->gatewayId = Config::get("pga_config.airavata")["gateway-id"];
$dataProductModel->ownerName = Session::get("username");
$dataProductModel->productName = basename($filePath);
$dataProductModel->dataProductType = DataProductType::FILE;
$dataReplicationModel = new DataReplicaLocationModel();
$dataReplicationModel->storageResourceId = Config::get("pga_config.airavata")["gateway-data-store-resource-id"];
$dataReplicationModel->replicaName = basename($filePath) . " gateway data store copy";
$dataReplicationModel->replicaLocationCategory = ReplicaLocationCategory::GATEWAY_DATA_STORE;
$dataReplicationModel->replicaPersistentType = ReplicaPersistentType::TRANSIENT;
$hostName = $_SERVER['SERVER_NAME'];
$dataReplicationModel->filePath = "file://" . $hostName . ":" . $filePath;
$dataProductModel->replicaLocations[] = $dataReplicationModel;
$uri = Airavata::registerDataProduct(Session::get('authz-token'), $dataProductModel);
$experimentInput->value = $uri;
} else {
$index = -1;
for ($i = 0; $i < sizeof($experimentInputs); $i++) {
if ($experimentInputs[$i]->name == $applicationInput->name) {
$index = $i;
}
}
if ($index >= 0) {
$experimentInput->value = $experimentInputs[$index]->value;
$experimentInput->type = $applicationInput->type;
}
}
} else {
CommonUtilities::print_error_message('I cannot accept this input type yet!');
}
$newExperimentInputs[] = $experimentInput;
}
if(isset($_FILES['optInputFiles'])){
$uriList = "";
for($i=0; $i < count($_FILES['optInputFiles']['name']); $i++){
if(!empty($_FILES['optInputFiles']['name'][$i])){
// Check if there is an error with the upload (like if it exceeded upload_max_filesize)
if ($_FILES['optInputFiles']['error'][$i] != 0) {
throw new Exception("Failure occurred while uploading file '"
. $_FILES['optInputFiles']['name'][$i] . "'. File upload error code is " . $_FILES['optInputFiles']['error'][$i] . ".");
}
$filePath = $experimentFilePath . $_FILES['optInputFiles']['name'][$i];
// check if file already exists
if (is_file($filePath)) {
unlink($filePath);
CommonUtilities::print_warning_message('Uploaded file already exists! Overwriting...');
}
$moveFile = move_uploaded_file($_FILES['optInputFiles']['tmp_name'][$i], $filePath);
if (!$moveFile) {
CommonUtilities::print_error_message('<p>Error moving uploaded file ' . $_FILES['optInputFiles']['name'][$i] . '!
Please try again later or report a bug using the link in the Help menu.</p>');
$experimentAssemblySuccessful = false;
}
$dataProductModel = new DataProductModel();
$dataProductModel->gatewayId = Config::get("pga_config.airavata")["gateway-id"];
$dataProductModel->ownerName = Session::get("username");
$dataProductModel->productName = basename($filePath);
$dataProductModel->dataProductType = DataProductType::FILE;
$dataReplicationModel = new DataReplicaLocationModel();
$dataReplicationModel->storageResourceId = Config::get("pga_config.airavata")["gateway-data-store-resource-id"];
$dataReplicationModel->replicaName = basename($filePath) . " gateway data store copy";
$dataReplicationModel->replicaLocationCategory = ReplicaLocationCategory::GATEWAY_DATA_STORE;
$dataReplicationModel->replicaPersistentType = ReplicaPersistentType::TRANSIENT;
$hostName = $_SERVER['SERVER_NAME'];
$dataReplicationModel->filePath = "file://" . $hostName . ":" . $filePath;
$dataProductModel->replicaLocations[] = $dataReplicationModel;
$uri = Airavata::registerDataProduct(Session::get('authz-token'), $dataProductModel);
$uriList = $uriList . $uri . ",";
}
}
if(strlen($uriList) > 0){
$uriList = substr($uriList,0, strlen($uriList) - 1);
$optInput = new InputDataObjectType();
$optInput->name = "Optional-File-Input-List";
$optInput->type = DataType::URI_COLLECTION;
$optInput->value = $uriList;
$newExperimentInputs[] = $optInput;
}
}
if ($experimentAssemblySuccessful) {
return $newExperimentInputs;
} else {
return false;
}
}