public QueryResult<FileIndex> updateFileIndexStatus(File file, String newStatus, String message, Integer release, String sessionId)
throws CatalogException {
String userId = catalogManager.getUserManager().getUserId(sessionId);
Long studyId = file.getStudyUid();
authorizationManager.checkFilePermission(studyId, file.getUid(), userId, FileAclEntry.FilePermissions.WRITE);
FileIndex index = file.getIndex();
if (index != null) {
if (!FileIndex.IndexStatus.isValid(newStatus)) {
throw new CatalogException("The status " + newStatus + " is not a valid status.");
} else {
index.setStatus(new FileIndex.IndexStatus(newStatus, message));
}
} else {
index = new FileIndex(userId, TimeUtils.getTime(), new FileIndex.IndexStatus(newStatus), -1, new ObjectMap());
}
if (release != null) {
if (newStatus.equals(FileIndex.IndexStatus.READY)) {
index.setRelease(release);
}
}
ObjectMap params = new ObjectMap(FileDBAdaptor.QueryParams.INDEX.key(), index);
fileDBAdaptor.update(file.getUid(), params, QueryOptions.empty());
auditManager.recordUpdate(AuditRecord.Resource.file, file.getUid(), userId, params, null, null);
return new QueryResult<>("Update file index", 0, 1, 1, "", "", Arrays.asList(index));
}