3122 TR Bättre variabelnamn, metodnamn, klassnamn. Fixade texter. Tog bort oanvända properties.

This commit is contained in:
nikos dimitrakas 2023-11-30 12:56:22 +01:00
parent a0a9142b3d
commit 9100e593a8
10 changed files with 65 additions and 85 deletions

@ -2,8 +2,8 @@ package se.su.dsv.scipro.finalseminar;
import java.util.function.Function;
public abstract class ActiveParticipationRegistrationStatus {
ActiveParticipationRegistrationStatus() {
public abstract class ActiveParticipationRegistrationErrorStatus {
ActiveParticipationRegistrationErrorStatus() {
}
public abstract <A> A fold(
@ -14,7 +14,7 @@ public abstract class ActiveParticipationRegistrationStatus {
Function<ParticipationFinalSeminarCancelled, A> g);
}
final class TooManyParticipants extends ActiveParticipationRegistrationStatus {
final class TooManyParticipants extends ActiveParticipationRegistrationErrorStatus {
@Override
public <A> A fold(
Function<TooManyParticipants, A> a,
@ -26,7 +26,7 @@ final class TooManyParticipants extends ActiveParticipationRegistrationStatus {
}
}
final class ManualParticipants extends ActiveParticipationRegistrationStatus {
final class ManualParticipants extends ActiveParticipationRegistrationErrorStatus {
@Override
public <A> A fold(
Function<TooManyParticipants, A> a,
@ -38,7 +38,7 @@ final class ManualParticipants extends ActiveParticipationRegistrationStatus {
}
}
final class ParticipationAlreadyParticipating extends ActiveParticipationRegistrationStatus {
final class ParticipationAlreadyParticipating extends ActiveParticipationRegistrationErrorStatus {
@Override
public <A> A fold(
Function<TooManyParticipants, A> a,
@ -50,7 +50,7 @@ final class ParticipationAlreadyParticipating extends ActiveParticipationRegistr
}
}
final class ParticipationAlreadyHappened extends ActiveParticipationRegistrationStatus {
final class ParticipationAlreadyHappened extends ActiveParticipationRegistrationErrorStatus {
@Override
public <A> A fold(
Function<TooManyParticipants, A> a,
@ -62,7 +62,7 @@ final class ParticipationAlreadyHappened extends ActiveParticipationRegistration
}
}
final class ParticipationFinalSeminarCancelled extends ActiveParticipationRegistrationStatus {
final class ParticipationFinalSeminarCancelled extends ActiveParticipationRegistrationErrorStatus {
@Override
public <A> A fold(
Function<TooManyParticipants, A> a,

@ -17,15 +17,15 @@ import java.util.Objects;
public interface FinalSeminarService extends GenericService<FinalSeminar, Long>, FilteredService<FinalSeminar, Long, FinalSeminarService.Filter>, FinalSeminarScheduling {
Either<OppositionRegistrationErrorStatus, FinalSeminarOpposition> attemptAddOpposition(User student, FinalSeminar finalSeminar, Project project);
Either<ActiveParticipationRegistrationStatus, FinalSeminarActiveParticipation> attemptAddActiveParticipation(User student, FinalSeminar finalSeminar, Project project);
Either<ActiveParticipationRegistrationErrorStatus, FinalSeminarActiveParticipation> attemptAddActiveParticipation(User student, FinalSeminar finalSeminar, Project project);
Either<OpposeError, FinalSeminarOpposition> SupervisorAttemptAddOpposition(User student, FinalSeminar finalSeminar, Project project);
Either<OpposeError, FinalSeminarOpposition> attemptAddOppositionAsSupervisor(User student, FinalSeminar finalSeminar, Project project);
Either<ParticipateError, FinalSeminarActiveParticipation> SupervisorAttemptAddActiveParticipation(User student, FinalSeminar finalSeminar, Project project);
Either<ParticipateError, FinalSeminarActiveParticipation> attemptAddActiveParticipationAsSupervisor(User student, FinalSeminar finalSeminar, Project project);
Either<OppositionRegistrationErrorStatus, Void> canOppose(User Student, FinalSeminar finalSeminar, Project project);
Either<ActiveParticipationRegistrationStatus, Void> canActiveParticipate(User student, FinalSeminar finalSeminar);
Either<ActiveParticipationRegistrationErrorStatus, Void> canActiveParticipate(User student, FinalSeminar finalSeminar);
Iterable<FinalSeminar> findAll(Filter params);

@ -30,7 +30,8 @@ import java.util.Date;
import java.util.List;
import java.util.Optional;
import static com.querydsl.core.types.dsl.Expressions.*;
import static com.querydsl.core.types.dsl.Expressions.allOf;
import static com.querydsl.core.types.dsl.Expressions.anyOf;
public class FinalSeminarServiceImpl extends AbstractServiceImpl<FinalSeminar, Long> implements FinalSeminarService {
@ -240,7 +241,7 @@ public class FinalSeminarServiceImpl extends AbstractServiceImpl<FinalSeminar, L
}
@Override
public Either<ActiveParticipationRegistrationStatus, Void> canActiveParticipate(User student, FinalSeminar finalSeminar) {
public Either<ActiveParticipationRegistrationErrorStatus, Void> canActiveParticipate(User student, FinalSeminar finalSeminar) {
if (finalSeminar.getManualParticipants()) {
return Either.left(new ManualParticipants());
}
@ -272,7 +273,7 @@ public class FinalSeminarServiceImpl extends AbstractServiceImpl<FinalSeminar, L
@Override
@Transactional
public Either<OpposeError, FinalSeminarOpposition> SupervisorAttemptAddOpposition(User student, FinalSeminar finalSeminar, Project project) {
public Either<OpposeError, FinalSeminarOpposition> attemptAddOppositionAsSupervisor(User student, FinalSeminar finalSeminar, Project project) {
if (!project.isParticipant(student)) {
return Either.left(OpposeError.NotAuthorOfSameProjectType);
} else if (finalSeminar.getActiveParticipants().contains(student)) {
@ -296,14 +297,14 @@ public class FinalSeminarServiceImpl extends AbstractServiceImpl<FinalSeminar, L
@Override
@Transactional
public Either<ActiveParticipationRegistrationStatus, FinalSeminarActiveParticipation> attemptAddActiveParticipation(final User student, final FinalSeminar finalSeminar, final Project project) {
public Either<ActiveParticipationRegistrationErrorStatus, FinalSeminarActiveParticipation> attemptAddActiveParticipation(final User student, final FinalSeminar finalSeminar, final Project project) {
return canActiveParticipate(student, finalSeminar)
.map(allowed -> createAndSaveActiveParticipation(student, finalSeminar, project));
}
@Override
@Transactional
public Either<ParticipateError, FinalSeminarActiveParticipation> SupervisorAttemptAddActiveParticipation(User student, FinalSeminar finalSeminar, Project project) {
public Either<ParticipateError, FinalSeminarActiveParticipation> attemptAddActiveParticipationAsSupervisor(User student, FinalSeminar finalSeminar, Project project) {
if (!project.isParticipant(student)) {
return Either.left(ParticipateError.NotAuthorOfSameProjectType);
} else if (finalSeminar.getActiveParticipants().contains(student)) {

@ -10,25 +10,18 @@ import se.su.dsv.scipro.project.Project;
import se.su.dsv.scipro.report.GradingReportTemplate;
import se.su.dsv.scipro.report.OppositionReport;
import se.su.dsv.scipro.security.auth.roles.Roles;
import se.su.dsv.scipro.system.DegreeType;
import se.su.dsv.scipro.system.Language;
import se.su.dsv.scipro.system.ProjectType;
import se.su.dsv.scipro.system.Unit;
import se.su.dsv.scipro.system.User;
import se.su.dsv.scipro.system.*;
import se.su.dsv.scipro.test.IntegrationTest;
import javax.inject.Inject;
import java.time.LocalDate;
import java.time.ZonedDateTime;
import java.util.*;
import java.util.Date;
import java.util.List;
import static org.hamcrest.CoreMatchers.anything;
import static org.hamcrest.CoreMatchers.hasItem;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.*;
import static se.su.dsv.scipro.test.Matchers.isLeft;
import static se.su.dsv.scipro.test.Matchers.isRight;
@ -111,14 +104,14 @@ public class FinalSeminarServiceImplIntegrationTest extends IntegrationTest {
@Test
public void can_not_oppose_if_already_opponent() {
otherProject.addProjectParticipant(user);
finalSeminarService.SupervisorAttemptAddOpposition(user, futureFinalSeminar, otherProject);
finalSeminarService.attemptAddOppositionAsSupervisor(user, futureFinalSeminar, otherProject);
assertThat(finalSeminarService.canOppose(user, futureFinalSeminar, otherProject), isLeft(instanceOf(AlreadyParticipating.class)));
}
@Test
public void can_not_oppose_if_participant() {
otherProject.addProjectParticipant(user);
finalSeminarService.SupervisorAttemptAddActiveParticipation(user, futureFinalSeminar, otherProject);
finalSeminarService.attemptAddActiveParticipationAsSupervisor(user, futureFinalSeminar, otherProject);
assertThat(finalSeminarService.canOppose(user, futureFinalSeminar, otherProject), isLeft(instanceOf(AlreadyParticipating.class)));
}
@ -135,7 +128,7 @@ public class FinalSeminarServiceImplIntegrationTest extends IntegrationTest {
@Test
public void can_not_participate_twice() {
otherProject.addProjectParticipant(user);
finalSeminarService.SupervisorAttemptAddActiveParticipation(user, futureFinalSeminar, otherProject);
finalSeminarService.attemptAddActiveParticipationAsSupervisor(user, futureFinalSeminar, otherProject);
assertThat(finalSeminarService.canActiveParticipate(user, futureFinalSeminar), isLeft(instanceOf(ParticipationAlreadyParticipating.class)));
}
@ -178,7 +171,7 @@ public class FinalSeminarServiceImplIntegrationTest extends IntegrationTest {
@Test
public void can_participate_if_previous_oppositions_are_failed() {
FinalSeminar secondSeminar = createFinalSeminar(createProject(), 10);
finalSeminarService.SupervisorAttemptAddOpposition(user, futureFinalSeminar, otherProject);
finalSeminarService.attemptAddOppositionAsSupervisor(user, futureFinalSeminar, otherProject);
for (FinalSeminarOpposition finalSeminarOpposition : futureFinalSeminar.getOppositions()) {
finalSeminarOpposition.setGrade(FinalSeminarGrade.NOT_APPROVED);
}

@ -42,15 +42,15 @@ public abstract class OpposeColumnPanel extends Panel {
private Component showError(OppositionRegistrationErrorStatus notAllowed) {
return notAllowed.fold(
ungradedOpposition -> getLabel("You have ungraded oppositions"),
finalSeminarCancelled -> getLabel("The final seminar has been cancelled"),
alreadyParticipating -> getLabel("You are already participating on the final seminar"),
alreadyHappened -> getLabel("The seminar has already happened"),
tooManyOpponents -> getLabel("The seminar is already full on opponents"),
finalSeminarCancelled -> getLabel("This seminar has been cancelled"),
alreadyParticipating -> getLabel("You are already participating on this seminar"),
alreadyHappened -> getLabel("This seminar has already happened"),
tooManyOpponents -> getLabel("This seminar has reached the maximum number of opponents"),
priorityForSeminarAuthors -> getLabel("Authors with their own final seminar have " +
"priority to register for " + priorityForSeminarAuthors.getPriorityDays() +
" day(s). This priority will end at " + asDateTime(Date.from(priorityForSeminarAuthors.getPriorityEnd()))),
alreadyOpposed -> getLabel("You have already completed an opposition and can not perform a second one."),
manualOpponents -> getLabel("Opponents for this seminar are handled by the supervisor."));
alreadyOpposed -> getLabel("You have already completed an opposition and can not perform a second one"),
manualOpponents -> getLabel("Opponents for this seminar are handled by the supervisor"));
}
public String asDateTime(Date date) {

@ -25,7 +25,7 @@ public abstract class ParticipateColumnPanel extends Panel {
public ParticipateColumnPanel(String id, final IModel<FinalSeminar> finalSeminarModel) {
super(id, finalSeminarModel);
final Either<ActiveParticipationRegistrationStatus, Void> canActiveParticipate =
final Either<ActiveParticipationRegistrationErrorStatus, Void> canActiveParticipate =
finalSeminarService.canActiveParticipate(SciProSession.get().getUser(), finalSeminarModel.getObject());
final Component participateLink = canActiveParticipate.fold(
this::showError,
@ -35,13 +35,13 @@ public abstract class ParticipateColumnPanel extends Panel {
add(participateLink);
}
private Component showError(ActiveParticipationRegistrationStatus notAllowed) {
private Component showError(ActiveParticipationRegistrationErrorStatus notAllowed) {
return notAllowed.fold(
tooManyParticipants -> getLabel("The seminar is already has the maximum participants"),
ManualParticipants -> getLabel("Participants for this seminar are handled by the supervisor."),
ParticipationAlreadyParticipating -> getLabel("You are already participating in the final seminar"),
ParticipationAlreadyHappened -> getLabel("The seminar has already happened"),
ParticipationFinalSeminarCancelled -> getLabel("The final seminar has been cancelled"));
tooManyParticipants -> getLabel("This seminar has reached the maximum number of active participants"),
manualParticipants -> getLabel("Active participants for this seminar are handled by the supervisor"),
alreadyParticipating -> getLabel("You are already participating in this seminar"),
alreadyHappened -> getLabel("This seminar has already happened"),
finalSeminarCancelled -> getLabel("This seminar has been cancelled"));
}

@ -23,7 +23,7 @@
</label>
</div>
<small class="text-muted">
If you're having trouble find a seminar to oppose or participate in you can subscribe to
If you're having trouble finding a seminar to oppose or participate in, you can subscribe to
be notified when one is scheduled. This should help you finish the last remaining tasks in
the project.
</small>

@ -100,16 +100,16 @@ public class ProjectOppositionPage extends AbstractProjectDetailsPage implements
notAllowed -> {
final String errorMessage = notAllowed.fold(
ungradedOpposition -> "You have ungraded oppositions",
finalSeminarCancelled -> "The final seminar has been cancelled",
alreadyParticipating -> "You are already participating on the final seminar",
alreadyHappened -> "The seminar has already happened",
tooManyOpponents -> "The seminar is already full on opponents",
finalSeminarCancelled -> "This seminar has been cancelled",
alreadyParticipating -> "You are already participating on this seminar",
alreadyHappened -> "This seminar has already happened",
tooManyOpponents -> "This seminar has reached the maximum number of opponents",
priorityForSeminarAuthors ->
"Authors with their own final seminar have " +
"priority to register for " + priorityForSeminarAuthors.getPriorityDays() +
" day(s). This priority will end at " + asDateTime(Date.from(priorityForSeminarAuthors.getPriorityEnd())),
alreadyOpposed -> "You have already completed an opposition and can't perform a second one.",
manualOpponents -> "Opponents for this seminar are handled by the supervisor."
alreadyOpposed -> "You have already completed an opposition and can't perform a second one",
manualOpponents -> "Opponents for this seminar are handled by the supervisor"
);
error(errorMessage);
return Boolean.FALSE;
@ -131,11 +131,11 @@ public class ProjectOppositionPage extends AbstractProjectDetailsPage implements
.fold(
notAllowed -> {
final String errorMessage = notAllowed.fold(
TooManyParticipants -> "The seminar is already full on participants",
ManualParticipants -> "Participants for this seminar are handled by the supervisor.",
ParticipationAlreadyParticipating -> "You are already participating in the final seminar",
ParticipationAlreadyHappened -> "The seminar has already happened",
ParticipationFinalSeminarCancelled -> "The final seminar has been cancelled");
tooManyParticipants -> "The seminar has already reached the maximum number of active participants",
manualParticipants -> "Active participants for this seminar are handled by the supervisor",
participationAlreadyParticipating -> "You are already participating in this seminar",
participationAlreadyHappened -> "This seminar has already happened",
participationFinalSeminarCancelled -> "This seminar has been cancelled");
error(errorMessage);
return Boolean.FALSE;
},

@ -3,11 +3,7 @@ package se.su.dsv.scipro.finalseminar;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.panel.GenericPanel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.LambdaModel;
import org.apache.wicket.model.LoadableDetachableModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.model.StringResourceModel;
import org.apache.wicket.model.*;
import se.su.dsv.scipro.components.AutoCompleteRoleProvider;
import se.su.dsv.scipro.components.ConfirmationLink;
import se.su.dsv.scipro.components.DefaultSelect2MultiChoice;
@ -208,20 +204,20 @@ public class SeminarCRUDPanel extends GenericPanel<FinalSeminar> {
error(getString("opponent.no.project", Model.of(potentialParticipant)));
} else {
final Project project = maybeProject.get();
Either<ParticipateError, FinalSeminarActiveParticipation> result = seminarService.SupervisorAttemptAddActiveParticipation(potentialParticipant, finalSeminar, project);
Either<ParticipateError, FinalSeminarActiveParticipation> result = seminarService.attemptAddActiveParticipationAsSupervisor(potentialParticipant, finalSeminar, project);
result.fold(
error -> {
switch (error) {
case AlreadyOpponent ->
error("Selected opponent " + potentialParticipant.getFullName() + " is already opponent");
error(potentialParticipant.getFullName() + " that you selected as an active participant is already an opponent");
case AlreadyParticipant ->
error("Selected opponent " + potentialParticipant.getFullName() + " is already active participant");
error(potentialParticipant.getFullName() + " that you selected as an active participant is already an active participant");
case NotAuthorOfSameProjectType ->
error("Failed to add " + potentialParticipant.getFullName() + ", not an author of a project of same type");
error("Failed to add " + potentialParticipant.getFullName() + " as an active participant: Not an author of a project of the same type");
}
return false;
},
opponent -> {
success -> {
success("Added " + potentialParticipant.getFullName() + " as an opponent");
events.add(SeminarEvent.Event.PARTICIPATION_CHANGED);
return true;
@ -232,7 +228,7 @@ public class SeminarCRUDPanel extends GenericPanel<FinalSeminar> {
activeParticipants.getModel().setObject(Collections.emptyList());
}
private void addOpponentsTo(FinalSeminar finalSeminar) {
private void addOpponents(FinalSeminar finalSeminar) {
for (User potentialOpponent : opponents.getModelObject()) {
Optional<Project> maybeProject = getPotentialParticipantProject(potentialOpponent, finalSeminar.getProjectType());
@ -240,20 +236,20 @@ public class SeminarCRUDPanel extends GenericPanel<FinalSeminar> {
error(getString("opponent.no.project", Model.of(potentialOpponent)));
} else {
final Project project = maybeProject.get();
Either<OpposeError, FinalSeminarOpposition> result = seminarService.SupervisorAttemptAddOpposition(potentialOpponent, finalSeminar, project);
Either<OpposeError, FinalSeminarOpposition> result = seminarService.attemptAddOppositionAsSupervisor(potentialOpponent, finalSeminar, project);
result.fold(
error -> {
switch (error) {
case AlreadyOpponent ->
error("Selected opponent " + potentialOpponent.getFullName() + " is already opponent");
error(potentialOpponent.getFullName() + " that you selected as an opponent is already an opponent");
case AlreadyParticipant ->
error("Selected opponent " + potentialOpponent.getFullName() + " is already active participant");
error(potentialOpponent.getFullName() + " that you selected as an opponent is already an active participant");
case NotAuthorOfSameProjectType ->
error("Failed to add " + potentialOpponent.getFullName() + ", not an author of a project of same type");
error("Failed to add " + potentialOpponent.getFullName() + ": Not an author of a project of the same type");
}
return false;
},
opponent -> {
success -> {
success("Added " + potentialOpponent.getFullName() + " as an opponent");
events.add(SeminarEvent.Event.OPPOSITION_CHANGED);
return true;
@ -270,7 +266,7 @@ public class SeminarCRUDPanel extends GenericPanel<FinalSeminar> {
setModelObject(finalSeminar);
success(getString("final.seminar.updated"));
addActiveParticipants(finalSeminar);
addOpponentsTo(finalSeminar);
addOpponents(finalSeminar);
if (roomChanged) {
notificationController.notifySeminar(finalSeminar, SeminarEvent.Event.ROOM_CHANGED, new NotificationSource());
}

@ -4,21 +4,11 @@ maxOpponents.RangeValidator.minimum=The selected number of max oppositions may n
FinalSeminarLanguage.SWEDISH=Swedish
# suppress inspection "UnusedProperty"
FinalSeminarLanguage.ENGLISH=English
opponent.no.project=${fullName} does not have an active project of this projects type.
opponent.too.many.projects=${fullName} has more than one active project of this projects type - unable to add opponent manually.
opponent.no.project=${fullName} does not have an active project of this project type.
final.seminar.updated=Final seminar saved
create= Create
update= Update
deleted= Final seminar deleted
confirm= Are you sure you want to delete the final seminar?
nonworkday= The selected start date is a non-work day.
reviewer.approval.explanation= Before creating a final seminar, the reviewer needs to give his approval that the thesis is good enough to have a final seminar.
reviewer.approval.denied= Your request for final seminar approval was denied by the reviewer on {0, date, yyyy-MM-dd HH:mm} with the reason: {1}
reviewer.approval.waiting= The reviewer has still not made a decision on the request you sent on {0, date, yyyy-MM-dd HH:mm}. \
The deadline to respond is {1, date, yyyy-MM-dd HH:mm} and if there is still no response at that time you will be able to create the final seminar regardless.
reviewer.approval.missing.reason= You must provide a reason why you want to create the final seminar without the approval of the reviewer.
choice.Required= You must select an option before you can continue.
FinalSeminarCreationAction.SEND_REQUEST_FOR_APPROVAL= I want to send a request for reviewer approval before continuing
FinalSeminarCreationAction.CREATE_ANYWAY= I want to create the final seminar anyway because...
SeminarDateValidator.minimum= ${label} must be at least ${minimum}.
startDate= Date