Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Issue #1956]: Patch file upload interface #1957

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 25 additions & 20 deletions src/main/java/org/tdl/vireo/controller/SubmissionController.java
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ public ApiResponse addComment(@WeaverUser User user, @PathVariable Long submissi
String subject = (String) data.get("subject");
String templatedMessage = templateUtility.compileString((String) data.get("message"), submission);
actionLogRepo.createPublicLog(submission, user, subject + ": " + templatedMessage);
}
}
} else {
String subject = (String) data.get("subject");
String templatedMessage = templateUtility.compileString((String) data.get("message"), submission);
Expand Down Expand Up @@ -1023,29 +1023,34 @@ public ApiResponse removeFile(@WeaverUser User user, @PathVariable Long submissi
Submission submission = submissionRepo.read(submissionId);
ApiResponse apiResponse = new ApiResponse(SUCCESS);
int hash = user.getEmail().hashCode();
FieldValue fileFieldValue = fieldValueRepo.findById(fieldValueId).get();
String documentType = fileFieldValue.getFieldPredicate().getValue();
String uri = fileFieldValue.getValue();
if (user.getRole().equals(Role.ROLE_STUDENT) && documentType.equals("_doctype_license")) {
apiResponse = new ApiResponse(ERROR, "You are not allowed to delete license files!");
} else {
if (user.getRole().equals(Role.ROLE_ADMIN) || user.getRole().equals(Role.ROLE_MANAGER) || uri.contains(String.valueOf(hash))) {
String fileName = "";
String fileSize = "file not found";
if (assetService.assetFileExists(uri)) {
JsonNode fileInfo = assetService.getAssetFileInfo(uri, submission);
fileName = fileInfo.get("name").asText();
fileSize = fileInfo.get("readableSize").asText();
Optional<FieldValue> fileFieldValue = fieldValueRepo.findById(fieldValueId);
if (fileFieldValue.isPresent()) {
String documentType = fileFieldValue.get().getFieldPredicate().getValue();
String uri = fileFieldValue.get().getValue();
if (user.getRole().equals(Role.ROLE_STUDENT) && documentType.equals("_doctype_license")) {
apiResponse = new ApiResponse(ERROR, "You are not allowed to delete license files!");
} else {
if (user.getRole().equals(Role.ROLE_ADMIN) || user.getRole().equals(Role.ROLE_MANAGER) || uri.contains(String.valueOf(hash))) {
String fileName = "";
String fileSize = "file not found";
if (assetService.assetFileExists(uri)) {
JsonNode fileInfo = assetService.getAssetFileInfo(uri, submission);
fileName = fileInfo.get("name").asText();
fileSize = fileInfo.get("readableSize").asText();
} else {
fileName = assetService.getAssetFileName(uri);
}

assetService.delete(uri);
actionLogRepo.createPublicLog(submission, user, documentType.substring(9).toUpperCase() + " file " + fileName + " (" + fileSize + ") removed");
} else {
fileName = assetService.getAssetFileName(uri);
apiResponse = new ApiResponse(ERROR, "This is not your file to delete!");
}

assetService.delete(uri);
actionLogRepo.createPublicLog(submission, user, documentType.substring(9).toUpperCase() + " file " + fileName + " (" + fileSize + ") removed");
} else {
apiResponse = new ApiResponse(ERROR, "This is not your file to delete!");
}
} else {
apiResponse = new ApiResponse(ERROR, "There is no field value with id " + fieldValueId);
}

return apiResponse;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,17 @@ vireo.controller("OrganizationManagementController", function ($controller, $loc
};

$scope.reorderWorkflowStepUp = function (workflowStepID) {
$scope.getSelectedOrganization().$dirty = true;
if (!!$scope.getSelectedOrganizationId()) {
$scope.getSelectedOrganization().$dirty = true;
}
AccordionService.closeAll();
return OrganizationRepo.reorderWorkflowSteps("up", workflowStepID);
};

$scope.reorderWorkflowStepDown = function (workflowStepID) {
$scope.getSelectedOrganization().$dirty = true;
if (!!$scope.getSelectedOrganizationId()) {
$scope.getSelectedOrganization().$dirty = true;
}
AccordionService.closeAll();
return OrganizationRepo.reorderWorkflowSteps("down", workflowStepID);
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
vireo.controller("SubmissionViewController", function ($controller, $q, $scope, $routeParams, CustomActionDefinitionRepo, EmbargoRepo, FieldPredicateRepo, FileUploadService, StudentSubmissionRepo, SubmissionStates) {
vireo.controller("SubmissionViewController", function ($controller, $q, $routeParams, $scope, $timeout, CustomActionDefinitionRepo, EmbargoRepo, FieldPredicateRepo, FileUploadService, StudentSubmissionRepo, SubmissionStates) {

angular.extend(this, $controller('AbstractController', {
$scope: $scope
Expand All @@ -12,21 +12,42 @@ vireo.controller("SubmissionViewController", function ($controller, $q, $scope,

$scope.actionLogDelay = 2000;

$scope.fieldProfile = undefined;
$scope.fieldPredicate = undefined;

FieldPredicateRepo.ready().then(function() {

var deleteFile = function (fieldValue) {
fieldValue.removing = true;
FileUploadService.removeFile($scope.submission, fieldValue).then(function (removed) {
delete fieldValue.removing;
var deleteFilePromise = FileUploadService.removeFile($scope.submission, fieldValue);

deleteFilePromise.then(function (removed) {
if (removed) {
delete fieldValue.removing;
}
});

return deleteFilePromise;
};

StudentSubmissionRepo.fetchSubmissionById($routeParams.submissionId).then(function (submission) {
$scope.loaded = true;
$scope.submission = submission;
$scope.submission.enableListeners();
$scope.submission.fetchDocumentTypeFileInfo();
});
var fetchSubmission = function (refreshScope) {
StudentSubmissionRepo.fetchSubmissionById($routeParams.submissionId).then(function (submission) {
if (refreshScope) {
$scope.submission = submission;

$scope.fieldProfile = undefined;
$timeout(function () {
$scope.onSelectDocumentType($scope.fieldPredicate);
});
} else {
angular.extend($scope.submission, submission);
}
$scope.submission.enableListeners();
$scope.submission.fetchDocumentTypeFileInfo();
});
}

fetchSubmission(true);

$scope.message = '';

Expand All @@ -36,6 +57,13 @@ vireo.controller("SubmissionViewController", function ($controller, $q, $scope,

$scope.archivingManuscript = false;

$scope.onSelectDocumentType = function (fieldPredicate) {
if (!!fieldPredicate && !!fieldPredicate.id) {
$scope.fieldPredicate = fieldPredicate;
$scope.fieldProfile = $scope.submission.getFieldProfileByPredicate(fieldPredicate);
}
};

$scope.addMessage = function () {
$scope.messaging = true;
$scope.submission.addMessage($scope.message).then(function () {
Expand Down Expand Up @@ -84,7 +112,13 @@ vireo.controller("SubmissionViewController", function ($controller, $q, $scope,
var fieldValue = $scope.removeQueue[i];
removePromises.push(deleteFile(fieldValue));
}
$q.all(removePromises).then(function () {
$q.all(removePromises).then(function (removeFiles) {
if (removeFiles.every(Boolean)) {
fetchSubmission(true);
} else {
console.error('Failed to remove additional files. Please refresh the page.');
}
$scope.removeQueue = [];
$scope.removingUploads = false;
});
};
Expand All @@ -97,9 +131,13 @@ vireo.controller("SubmissionViewController", function ($controller, $q, $scope,

$scope.archiveManuscript = function () {
$scope.archivingManuscript = true;
FileUploadService.archiveFile($scope.submission, $scope.submission.primaryDocumentFieldValue, true).then(function () {
FileUploadService.archiveFile($scope.submission, $scope.submission.primaryDocumentFieldValue, true).then(function (removeFieldValue) {
$scope.archivingManuscript = false;
$scope.submission.addFieldValue($scope.submission.getPrimaryDocumentFieldProfile().fieldPredicate);
if (removeFieldValue) {
fetchSubmission(true);
} else {
console.error('Failed to remove field value. Please refresh the page.');
}
});
};

Expand Down Expand Up @@ -170,10 +208,7 @@ vireo.controller("SubmissionViewController", function ($controller, $q, $scope,

CustomActionDefinitionRepo.listen(function(apiRes) {
if(apiRes.meta.status === 'SUCCESS') {
StudentSubmissionRepo.remove($scope.submission);
StudentSubmissionRepo.fetchSubmissionById($routeParams.submissionId).then(function (submission) {
angular.extend($scope.submission, submission);
});
fetchSubmission();
}
});

Expand Down
14 changes: 9 additions & 5 deletions src/main/webapp/app/directives/fieldProfileDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ vireo.directive("field", function ($controller, $filter, $q, $timeout, Controlle
}

$scope.hasFile = function (fieldValue) {
return fieldValue !== undefined && fieldValue.fieldPredicate.documentTypePredicate && fieldValue.value && fieldValue.value.length > 0;
return fieldValue !== undefined && fieldValue.id && fieldValue.fieldPredicate.documentTypePredicate && fieldValue.value && fieldValue.value.length > 0;
};

$scope.addFieldValue = function () {
Expand Down Expand Up @@ -285,12 +285,11 @@ vireo.directive("field", function ($controller, $filter, $q, $timeout, Controlle

$scope.cancel = function (fieldValue) {
$scope.submission.removeUnsavedFieldValue(fieldValue);
refreshFieldValues();
if ($scope.fieldValues.length === 0) {
$scope.addFieldValue();
refreshFieldValues();
$scope.previewing = false;
}
refreshFieldValues();
$scope.previewing = false;
};

$scope.getPreview = function (fieldValue) {
Expand Down Expand Up @@ -339,13 +338,17 @@ vireo.directive("field", function ($controller, $filter, $q, $timeout, Controlle
FileUploadService.removeFile($scope.submission, fieldValue).then(function (removed) {
$scope.deleting = false;
$scope.previewing = false;
if(removed) {
if (removed) {
delete fieldValue.id;
delete fieldValue.file;
delete fieldValue.value;
if (!$scope.profile.repeatable) {
$scope.addFieldValue();
}
}

$scope.submission.removeUnsavedFieldValue(fieldValue);

refreshFieldValues();
$scope.closeModal();
});
Expand Down Expand Up @@ -408,6 +411,7 @@ vireo.directive("field", function ($controller, $filter, $q, $timeout, Controlle
$scope.fieldValues = $filter('fieldValuePerProfile')($scope.submission.fieldValues, $scope.profile.fieldPredicate);
$scope.fieldValue = $scope.fieldValues[0];

$scope.hasFiles = false;
for (var i in $scope.fieldValues) {
if ($scope.hasFile($scope.fieldValues[i])) {
$scope.hasFiles = true;
Expand Down
16 changes: 9 additions & 7 deletions src/main/webapp/app/model/submission.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,16 @@ var submissionModel = function ($filter, $q, ActionLog, FieldValue, FileService,
var enrichDocumentTypeFieldValue = function (fieldValue) {
if (!!fieldValue.value) {
if (!fieldValue.fileInfo && fieldValue.value.length > 0) {
submission.fileInfo(fieldValue).then(function (response) {
fieldValue.fileInfo = angular.fromJson(response.body).payload.ObjectNode;
});
}
submission.fileInfo(fieldValue).then(function (response) {
fieldValue.fileInfo = angular.fromJson(response.body).payload.ObjectNode;
});
}

if (fieldValue.value.length > 0 && submission.getFileType(fieldValue.fieldPredicate) === 'PRIMARY') {
submission.primaryDocumentFieldValue = fieldValue;
}
if (fieldValue.value.length > 0 && submission.getFileType(fieldValue.fieldPredicate) === 'PRIMARY') {
angular.extend(submission, {
primaryDocumentFieldValue: fieldValue
});
}
}
};

Expand Down
12 changes: 6 additions & 6 deletions src/main/webapp/app/views/submission/submissionView.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
</ul>

<h1 class="center">Submission View</h1>
<div class="student-submission-loader" ng-class="{'ready': loaded}">
<div class="student-submission-loader" ng-class="{'ready': !!submission}">
<span>
<span class="glyphicon glyphicon-refresh spinning"></span>
Loading Submission ...</span>
</div>

<submissiondialog submission="submission" type="actions"></submissiondialog>
<reviewsubmissionsfields submission="submission" hide-links="true" ng-if="loaded" show-vocabulary-word="showVocabularyWord" is-embargo="isEmbargo" sort-embargos="sortEmbargos"></reviewsubmissionsfields>
<div id="upload-files" class="row" ng-if="loaded && submission.submissionStatus.submissionState === SubmissionStates.NEEDS_CORRECTIONS">
<reviewsubmissionsfields submission="submission" hide-links="true" ng-if="!!submission" show-vocabulary-word="showVocabularyWord" is-embargo="isEmbargo" sort-embargos="sortEmbargos"></reviewsubmissionsfields>
<div id="upload-files" class="row" ng-if="!!submission && submission.submissionStatus.submissionState === SubmissionStates.NEEDS_CORRECTIONS">
<span class="text-danger">
<h3>Upload/Remove Files</h3>
<hr class="submission-view-upload-files-hr"/>
Expand Down Expand Up @@ -77,7 +77,7 @@ <h3>Upload/Remove Files</h3>
<select
class="form-control"
ng-model="fieldPredicate"
ng-selected="fieldProfile = fieldPredicate.id ? submission.getFieldProfileByPredicate(fieldPredicate) : undefined"
ng-change="onSelectDocumentType(fieldPredicate)"
ng-options="documentFieldPredicate as getFileType(documentFieldPredicate) for documentFieldPredicate in filteredFieldPredicates = (fieldPredicates | filter:uploadableFieldPredicates) track by documentFieldPredicate.value">
<option value="">-- select document type --</option>
</select>
Expand Down Expand Up @@ -106,7 +106,7 @@ <h3>Upload/Remove Files</h3>
</div>
</div>

<div class="row" ng-show="loaded">
<div class="row" ng-show="!!submission">
<div class="col-md-12">
<h3>Application Activity</h3>
</div>
Expand All @@ -116,7 +116,7 @@ <h3>Application Activity</h3>
</div>
</div>

<div class="row" ng-show="loaded">
<div class="row" ng-show="!!submission">
<div class="col-md-12">
<h3>Leave a Message</h3>
</div>
Expand Down
10 changes: 8 additions & 2 deletions src/test/java/org/tdl/vireo/model/EmailRecipientContactTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ public void testGetEmails() {

emails.add("[email protected]");
emails.add("[email protected]");

// expected, actual
assertEquals(2, emails.size(), "Expected emails are not as expected.");

otherFieldValue.setId(1L);
otherFieldValue.setValue("value1");
fieldValue.setId(2L);
Expand All @@ -40,14 +44,16 @@ public void testGetEmails() {
fieldValues.add(fieldValue);
fieldValues.add(otherFieldValue);
fieldPredicate.setId(1L);
fieldPredicate.setValue("notnull");

ReflectionTestUtils.setField(emailRecipientContact, "fieldPredicate", fieldPredicate);

when(submission.getFieldValuesByPredicate(any(FieldPredicate.class))).thenReturn(fieldValues);
when(submission.getFieldValuesByPredicateValue(any(String.class))).thenReturn(fieldValues);

List<String> got = emailRecipientContact.getEmails(submission);

assertEquals(got.size(), emails.size(), "Emails array does not have the correct length.");
// expected, actual
assertEquals(emails.size(), got.size(), "Emails array does not have the correct length.");

emails.forEach(email -> {
String found = null;
Expand Down
Loading