Skip to content

Commit

Permalink
CSCEXAM-000 Take new control flow syntax in use
Browse files Browse the repository at this point in the history
  • Loading branch information
Matti Lupari committed Jan 11, 2024
1 parent a550106 commit 1b0ee48
Show file tree
Hide file tree
Showing 281 changed files with 11,552 additions and 9,940 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,8 @@ default Either<CompletionStage<Result>, LanguageInspection> findLanguageInspecti
Http.MultipartFormData.FilePart<Files.TemporaryFile> file
) {
Source<ByteString, CompletionStage<IOResult>> source = FileIO.fromPath(file.getRef().path());
Http.MultipartFormData.FilePart<Source<ByteString, CompletionStage<IOResult>>> filePart = new Http.MultipartFormData.FilePart<>(
"file",
file.getFilename(),
file.getContentType(),
source
);
Http.MultipartFormData.FilePart<Source<ByteString, CompletionStage<IOResult>>> filePart =
new Http.MultipartFormData.FilePart<>("file", file.getFilename(), file.getContentType(), source);
return Source.from(Set.of(filePart));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,30 +142,26 @@ boolean isAuthorizedToView(Exam exam, User user, String homeOrg) {
}
return (
user.getLoginRole() == Role.Name.ADMIN ||
(
exam
(exam
.getExamOwners()
.stream()
.anyMatch(u ->
u.getEmail().equalsIgnoreCase(user.getEmail()) || u.getEmail().equalsIgnoreCase(user.getEppn())
) &&
exam.hasState(Exam.State.PRE_PUBLISHED, Exam.State.PUBLISHED)
)
exam.hasState(Exam.State.PRE_PUBLISHED, Exam.State.PUBLISHED))
);
}

boolean isUnauthorizedToAssess(Exam exam, User user) {
return (
user.getLoginRole() != Role.Name.ADMIN &&
(
exam
(exam
.getExamOwners()
.stream()
.noneMatch(u ->
u.getEmail().equalsIgnoreCase(user.getEmail()) || u.getEmail().equalsIgnoreCase(user.getEppn())
) ||
!exam.hasState(Exam.State.REVIEW, Exam.State.REVIEW_STARTED, Exam.State.GRADED)
)
!exam.hasState(Exam.State.REVIEW, Exam.State.REVIEW_STARTED, Exam.State.GRADED))
);
}

Expand Down
8 changes: 2 additions & 6 deletions app/controllers/iop/transfer/impl/DataTransferController.java
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,8 @@ public CompletionStage<Result> exportData(Http.Request request) throws IOExcepti
Attachment attachment
) {
Source<ByteString, CompletionStage<IOResult>> source = FileIO.fromPath(Path.of(attachment.getFilePath()));
Http.MultipartFormData.FilePart<Source<ByteString, CompletionStage<IOResult>>> filePart = new Http.MultipartFormData.FilePart<>(
"file",
attachment.getFileName(),
attachment.getMimeType(),
source
);
Http.MultipartFormData.FilePart<Source<ByteString, CompletionStage<IOResult>>> filePart =
new Http.MultipartFormData.FilePart<>("file", attachment.getFileName(), attachment.getMimeType(), source);
return Source.from(Set.of(filePart));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,13 @@ public CompletableFuture<Void> createExternalAttachment(Attachment attachment) {
return;
}
final Source<ByteString, CompletionStage<IOResult>> source = FileIO.fromPath(file.toPath());
final Http.MultipartFormData.FilePart<Source<ByteString, CompletionStage<IOResult>>> filePart = new Http.MultipartFormData.FilePart<>(
"file",
attachment.getFileName(),
attachment.getMimeType(),
source
);
final Http.MultipartFormData.FilePart<Source<ByteString, CompletionStage<IOResult>>> filePart =
new Http.MultipartFormData.FilePart<>(
"file",
attachment.getFileName(),
attachment.getMimeType(),
source
);
Http.MultipartFormData.DataPart dp = new Http.MultipartFormData.DataPart("key", "value");

updateRequest
Expand Down
2 changes: 1 addition & 1 deletion app/impl/AutoEvaluationHandlerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ private Optional<GradeScale> resolveScale(Exam exam) {
private Grade getGradeBasedOnScore(Exam exam) {
Double totalScore = exam.getTotalScore();
Double maxScore = exam.getMaxScore();
Double percentage = maxScore == 0 ? 0 : totalScore * 100 / maxScore;
Double percentage = maxScore == 0 ? 0 : (totalScore * 100) / maxScore;
List<GradeEvaluation> gradeEvaluations = new ArrayList<>(exam.getAutoEvaluationConfig().getGradeEvaluations());
gradeEvaluations.sort(Comparator.comparingInt(GradeEvaluation::getPercentage));
Grade grade = null;
Expand Down
18 changes: 6 additions & 12 deletions app/models/questions/Question.java
Original file line number Diff line number Diff line change
Expand Up @@ -316,21 +316,15 @@ private boolean getClaimChoiceOptionsValidationResult(ArrayNode options) {
}

return (
(
type == MultipleChoiceOption.ClaimChoiceOptionType.CorrectOption &&
(type == MultipleChoiceOption.ClaimChoiceOptionType.CorrectOption &&
defaultScore > 0 &&
!option.isEmpty()
) ||
(
type == MultipleChoiceOption.ClaimChoiceOptionType.IncorrectOption &&
!option.isEmpty()) ||
(type == MultipleChoiceOption.ClaimChoiceOptionType.IncorrectOption &&
defaultScore <= 0 &&
!option.isEmpty()
) ||
(
type == MultipleChoiceOption.ClaimChoiceOptionType.SkipOption &&
!option.isEmpty()) ||
(type == MultipleChoiceOption.ClaimChoiceOptionType.SkipOption &&
defaultScore == 0 &&
!option.isEmpty()
)
!option.isEmpty())
);
})
.map(n ->
Expand Down
2 changes: 1 addition & 1 deletion app/models/sections/ExamSectionQuestion.java
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ public Double getAssessedScore() {
return 0.0;
}
DecimalFormat df = new DecimalFormat("#.##", new DecimalFormatSymbols(Locale.US));
double value = correct * maxScore / (correct + incorrect);
double value = (correct * maxScore) / (correct + incorrect);
return Double.valueOf(df.format(value));
}
case ClaimChoiceQuestion -> {
Expand Down
12 changes: 4 additions & 8 deletions app/repository/EnrolmentRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -317,16 +317,12 @@ private boolean isInsideBounds(ExamEnrolment ee, int minutesToFuture) {
? ee.getExaminationEventConfiguration().getExaminationEvent()
: null;
return (
(
reservation != null &&
(reservation != null &&
reservation.getStartAt().isBefore(latest) &&
reservation.getEndAt().isAfter(earliest)
) ||
(
event != null &&
reservation.getEndAt().isAfter(earliest)) ||
(event != null &&
event.getStart().isBefore(latest) &&
event.getStart().plusMinutes(ee.getExam().getDuration()).isAfter(earliest)
)
event.getStart().plusMinutes(ee.getExam().getDuration()).isAfter(earliest))
);
}

Expand Down
4 changes: 2 additions & 2 deletions ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@
"prettier --write"
],
"../app/**/*.java": [
"prettier --write --print-width=120 --tab-width=4"
"prettier --write --plugin=prettier-plugin-java --print-width=120 --tab-width=4"
],
"../test/**/*.java": [
"prettier --write --print-width=120 --tab-width=4"
"prettier --write --plugin=prettier-plugin-java --print-width=120 --tab-width=4"
],
"src/app/**/*.ts": [
"eslint --fix"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and limitations under the Licence.
*/
import { NgIf } from '@angular/common';

import { Component, Input } from '@angular/core';
import { NgbPopover } from '@ng-bootstrap/ng-bootstrap';
import { TranslateModule, TranslateService } from '@ngx-translate/core';
Expand All @@ -30,13 +30,14 @@ import { DropdownSelectComponent, Option } from '../../../shared/select/dropdown
<div class="bottom-row d-flex justify-content-between">
<div class="col-lg-10 mb-4">
<label for="enrolment">{{ 'i18n_select_exam' | translate }}</label>
<xm-dropdown-select
id="enrolment"
*ngIf="examNames"
[options]="examNames"
(optionSelected)="enrolmentSelected($event)"
placeholder="{{ 'i18n_select' | translate }}"
></xm-dropdown-select>
@if (examNames) {
<xm-dropdown-select
id="enrolment"
[options]="examNames"
(optionSelected)="enrolmentSelected($event)"
placeholder="{{ 'i18n_select' | translate }}"
></xm-dropdown-select>
}
</div>
<div class="col-lg-2 mb-2">
<label for="link"></label>
Expand All @@ -57,13 +58,17 @@ import { DropdownSelectComponent, Option } from '../../../shared/select/dropdown
`,
selector: 'xm-enrolments-report',
standalone: true,
imports: [NgIf, DropdownSelectComponent, NgbPopover, TranslateModule],
imports: [DropdownSelectComponent, NgbPopover, TranslateModule],
})
export class EnrolmentsReportComponent {
@Input() examNames: Option<string, number>[] = [];
enrolment?: number;

constructor(private translate: TranslateService, private toast: ToastrService, private files: FileService) {}
constructor(
private translate: TranslateService,
private toast: ToastrService,
private files: FileService,
) {}

getExamEnrolments = () => {
if (this.enrolment) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and limitations under the Licence.
*/
import { NgIf } from '@angular/common';

import { Component, Input } from '@angular/core';
import { NgbPopover } from '@ng-bootstrap/ng-bootstrap';
import { TranslateModule, TranslateService } from '@ngx-translate/core';
Expand All @@ -25,20 +25,25 @@ import { DropdownSelectComponent, Option } from '../../../shared/select/dropdown
<div class="top-row">
<h4 class="col-md-12">
{{ 'i18n_get_all_info_from_exam' | translate }}
<span *ngIf="fileType === 'xlsx'">{{ 'i18n_excel_file' | translate }}</span>
<span *ngIf="fileType === 'json'">{{ 'i18n_json_file' | translate }}</span>
@if (fileType === 'xlsx') {
<span>{{ 'i18n_excel_file' | translate }}</span>
}
@if (fileType === 'json') {
<span>{{ 'i18n_json_file' | translate }}</span>
}
</h4>
</div>
<div class="bottom-row d-flex justify-content-between">
<div class="col-lg-10 mb-4">
<label for="exam">{{ 'i18n_select_exam' | translate }}</label>
<xm-dropdown-select
id="exam"
*ngIf="examNames"
[options]="examNames"
(optionSelected)="examSelected($event)"
placeholder="{{ 'i18n_select' | translate }}"
></xm-dropdown-select>
@if (examNames) {
<xm-dropdown-select
id="exam"
[options]="examNames"
(optionSelected)="examSelected($event)"
placeholder="{{ 'i18n_select' | translate }}"
></xm-dropdown-select>
}
</div>
<div class="col-lg-2 mb-2">
<label for="link"></label>
Expand All @@ -51,24 +56,32 @@ import { DropdownSelectComponent, Option } from '../../../shared/select/dropdown
popoverTitle="{{ 'i18n_instructions' | translate }}"
ngbPopover="{{ 'i18n_download' | translate }}"
>
<i *ngIf="fileType === 'xlsx'" class="bi-file-earmark-excel font-6"></i>
<i *ngIf="fileType === 'json'" class="bi-file-earmark-code font-6"></i>
@if (fileType === 'xlsx') {
<i class="bi-file-earmark-excel font-6"></i>
}
@if (fileType === 'json') {
<i class="bi-file-earmark-code font-6"></i>
}
</a>
</div>
</div>
</div>
`,
selector: 'xm-exams-report',
standalone: true,
imports: [NgIf, DropdownSelectComponent, NgbPopover, TranslateModule],
imports: [DropdownSelectComponent, NgbPopover, TranslateModule],
})
export class ExamsReportComponent {
@Input() examNames: Option<string, number>[] = [];
@Input() fileType = '';

exam?: number;

constructor(private translate: TranslateService, private toast: ToastrService, private files: FileService) {}
constructor(
private translate: TranslateService,
private toast: ToastrService,
private files: FileService,
) {}

examSelected = (event?: Option<string, number>) => (this.exam = event?.id);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and limitations under the Licence.
*/
import { NgIf } from '@angular/common';

import { Component, Input } from '@angular/core';
import { NgbPopover } from '@ng-bootstrap/ng-bootstrap';
import { TranslateModule, TranslateService } from '@ngx-translate/core';
Expand All @@ -33,13 +33,14 @@ import { DropdownSelectComponent, Option } from '../../../shared/select/dropdown
<div class="bottom-row">
<div class="col-lg-4 mb-2">
<label for="roomPick">{{ 'i18n_select_room' | translate }}</label>
<xm-dropdown-select
id="roomPick"
*ngIf="rooms"
[options]="rooms"
(optionSelected)="roomSelected($event)"
placeholder="{{ 'i18n_select' | translate }}"
></xm-dropdown-select>
@if (rooms) {
<xm-dropdown-select
id="roomPick"
[options]="rooms"
(optionSelected)="roomSelected($event)"
placeholder="{{ 'i18n_select' | translate }}"
></xm-dropdown-select>
}
</div>
<div class="col-lg-3 mb-2">
<label for="startAt">{{ 'i18n_start_time' | translate }}</label>
Expand Down Expand Up @@ -72,7 +73,7 @@ import { DropdownSelectComponent, Option } from '../../../shared/select/dropdown
`,
selector: 'xm-rooms-report',
standalone: true,
imports: [NgIf, DropdownSelectComponent, DatePickerComponent, NgbPopover, TranslateModule],
imports: [DropdownSelectComponent, DatePickerComponent, NgbPopover, TranslateModule],
})
export class RoomsReportComponent {
@Input() rooms: Option<ExamRoom, number>[] = [];
Expand All @@ -81,7 +82,11 @@ export class RoomsReportComponent {
startDate: Date | null = null;
endDate: Date | null = null;

constructor(private translate: TranslateService, private toast: ToastrService, private files: FileService) {}
constructor(
private translate: TranslateService,
private toast: ToastrService,
private files: FileService,
) {}

roomSelected = (event?: Option<ExamRoom, number>) => {
this.room = event?.id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and limitations under the Licence.
*/
import { DatePipe, NgIf } from '@angular/common';
import { DatePipe } from '@angular/common';
import { Component, Input } from '@angular/core';
import { NgbPopover } from '@ng-bootstrap/ng-bootstrap';
import { TranslateModule, TranslateService } from '@ngx-translate/core';
Expand All @@ -33,13 +33,14 @@ import { DropdownSelectComponent, Option } from '../../../shared/select/dropdown
<div class="bottom-row d-flex justify-content-between">
<div class="col-lg-4 mb-2">
<label for="student">{{ 'i18n_student' | translate }}</label>
<xm-dropdown-select
id="student"
*ngIf="students"
[options]="students"
(optionSelected)="studentSelected($event)"
placeholder="{{ 'i18n_select' | translate }}"
></xm-dropdown-select>
@if (students) {
<xm-dropdown-select
id="student"
[options]="students"
(optionSelected)="studentSelected($event)"
placeholder="{{ 'i18n_select' | translate }}"
></xm-dropdown-select>
}
</div>
<div class="col-lg-3 mb-2">
<label for="startAt">{{ 'i18n_start_time' | translate }}</label>
Expand Down Expand Up @@ -72,7 +73,7 @@ import { DropdownSelectComponent, Option } from '../../../shared/select/dropdown
`,
selector: 'xm-students-report',
standalone: true,
imports: [NgIf, DropdownSelectComponent, DatePickerComponent, NgbPopover, TranslateModule],
imports: [DropdownSelectComponent, DatePickerComponent, NgbPopover, TranslateModule],
})
export class StudentsReportComponent {
@Input() students: Option<User, number>[] = [];
Expand Down
Loading

0 comments on commit 1b0ee48

Please sign in to comment.