Skip to content

Commit fcad241

Browse files
committed
Fix issues detected by SonarCloud
1 parent edda14b commit fcad241

File tree

10 files changed

+101
-47
lines changed

10 files changed

+101
-47
lines changed

core-api/src/main/java/org/silverpeas/core/calendar/Attendee.java

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
*/
2424
package org.silverpeas.core.calendar;
2525

26-
import org.silverpeas.core.admin.user.model.User;
2726
import org.silverpeas.core.persistence.datasource.model.identifier.UuidIdentifier;
2827
import org.silverpeas.core.persistence.datasource.model.jpa.SilverpeasJpaEntity;
2928
import org.silverpeas.kernel.SilverpeasRuntimeException;
@@ -134,28 +133,12 @@ public Optional<Attendee> getDelegate() {
134133
/**
135134
* Delegates the participation of this attendee to another participant. The delegated is added
136135
* among the calendar event's attendees.
137-
* @param user a user in Silverpeas.
136+
* @param anotherAttendee a supplier of another attendee to the same calendar component.
138137
*/
139-
public void delegateTo(final User user) {
138+
public void delegateTo(final AttendeeSupplier anotherAttendee) {
140139
participationStatusAnswered = this.participationStatus != ParticipationStatus.DELEGATED;
141140
this.participationStatus = ParticipationStatus.DELEGATED;
142-
this.delegate = InternalAttendee.fromUser(user).to(this.component)
143-
.withPresenceStatus(this.presenceStatus);
144-
this.delegate.delegate = this;
145-
this.component.getAttendees().add(this.delegate);
146-
}
147-
148-
/**
149-
* Delegates the participation of this attendee to another participant. The delegated is added
150-
* among the calendar event's attendees.
151-
* @param email the email of another attendee. This attendee is expected to be a person external
152-
* to Silverpeas.
153-
*/
154-
public void delegateTo(final String email) {
155-
participationStatusAnswered = this.participationStatus != ParticipationStatus.DELEGATED;
156-
this.participationStatus = ParticipationStatus.DELEGATED;
157-
this.delegate = ExternalAttendee.withEmail(email).to(this.component)
158-
.withPresenceStatus(this.presenceStatus);
141+
this.delegate = anotherAttendee.to(this.component).withPresenceStatus(this.presenceStatus);
159142
this.delegate.delegate = this;
160143
this.component.getAttendees().add(this.delegate);
161144
}
@@ -365,7 +348,7 @@ public boolean isInformative() {
365348
* A supplier of an instance of a concrete implementation of {@link Attendee}
366349
*/
367350
@FunctionalInterface
368-
interface AttendeeSupplier {
351+
public interface AttendeeSupplier {
369352

370353
/**
371354
* Supplies an instance of an {@link Attendee} to the specified calendar component.

core-api/src/main/java/org/silverpeas/core/calendar/AttendeeSet.java

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,9 @@
2727
import org.silverpeas.core.util.CollectionUtil;
2828
import org.silverpeas.kernel.annotation.NonNull;
2929

30-
import javax.persistence.CascadeType;
31-
import javax.persistence.Embeddable;
32-
import javax.persistence.FetchType;
33-
import javax.persistence.OneToMany;
34-
import javax.persistence.Transient;
30+
import javax.persistence.*;
3531
import java.io.Serializable;
36-
import java.util.Collection;
37-
import java.util.HashSet;
38-
import java.util.Iterator;
39-
import java.util.Optional;
40-
import java.util.Set;
41-
import java.util.Spliterator;
32+
import java.util.*;
4233
import java.util.function.Consumer;
4334
import java.util.function.Predicate;
4435
import java.util.stream.Stream;
@@ -83,6 +74,7 @@ public Iterator<Attendee> iterator() {
8374
* relayed to the caller.
8475
* @param action the action to be performed for each attendee.
8576
*/
77+
@Override
8678
public void forEach(final Consumer<? super Attendee> action) {
8779
attendees.forEach(action);
8880
}
@@ -121,7 +113,7 @@ public Optional<Attendee> get(String id) {
121113
* @return the added attendee.
122114
*/
123115
public Attendee add(final String email) {
124-
Attendee attendee = ExternalAttendee.withEmail(email).to(component);
116+
Attendee attendee = AttendeeSuppliers.fromEmail(email).to(component);
125117
attendees.add(attendee);
126118
return attendee;
127119
}
@@ -133,7 +125,7 @@ public Attendee add(final String email) {
133125
* @return the added attendee.
134126
*/
135127
public Attendee add(final User user) {
136-
Attendee attendee = InternalAttendee.fromUser(user).to(component);
128+
Attendee attendee = AttendeeSuppliers.fromUser(user).to(component);
137129
attendees.add(attendee);
138130
return attendee;
139131
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright (C) 2000 - 2025 Silverpeas
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU Affero General Public License as
6+
* published by the Free Software Foundation, either version 3 of the
7+
* License, or (at your option) any later version.
8+
*
9+
* As a special exception to the terms and conditions of version 3.0 of
10+
* the GPL, you may redistribute this Program in connection with Free/Libre
11+
* Open Source Software ("FLOSS") applications as described in Silverpeas's
12+
* FLOSS exception. You should have received a copy of the text describing
13+
* the FLOSS exception, and it is also available here:
14+
* "https://www.silverpeas.org/legal/floss_exception.html"
15+
*
16+
* This program is distributed in the hope that it will be useful,
17+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
* GNU Affero General Public License for more details.
20+
*
21+
* You should have received a copy of the GNU Affero General Public License
22+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
23+
*/
24+
25+
package org.silverpeas.core.calendar;
26+
27+
import org.silverpeas.core.admin.user.model.User;
28+
import org.silverpeas.core.calendar.Attendee.AttendeeSupplier;
29+
30+
/**
31+
* Providers of suppliers of Attendee objects by encapsulating their concrete implementation.
32+
*
33+
* @author mmoquillon
34+
*/
35+
public class AttendeeSuppliers {
36+
37+
private AttendeeSuppliers() {}
38+
39+
/**
40+
* Gets a supplier of attendee representing a user from outside Silverpeas having the specified
41+
* email address.
42+
* @param email the email address of the attendee to supply later.
43+
* @return a supplier of an external attendee.
44+
*/
45+
public static AttendeeSupplier fromEmail(final String email) {
46+
return ExternalAttendee.withEmail(email);
47+
}
48+
49+
/**
50+
* Gets a supplier of an attendee representing the specified user in Silverpeas.
51+
* @param user a user in Silverpeas.
52+
* @return a supplier of an internal attendee.
53+
*/
54+
public static AttendeeSupplier fromUser(final User user) {
55+
return InternalAttendee.fromUser(user);
56+
}
57+
}
58+

core-api/src/main/java/org/silverpeas/core/calendar/ExternalAttendee.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ protected ExternalAttendee() {
4242
// empty constructor for JPA
4343
}
4444

45-
private ExternalAttendee(final String email, final CalendarComponent calendarComponent) {
45+
ExternalAttendee(final String email, final CalendarComponent calendarComponent) {
4646
super(email, calendarComponent);
4747
}
4848

core-api/src/main/java/org/silverpeas/core/calendar/InternalAttendee.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ protected InternalAttendee() {
4343
// empty constructor for JPA
4444
}
4545

46-
private InternalAttendee(final User user, final CalendarComponent calendarComponent) {
46+
InternalAttendee(final User user, final CalendarComponent calendarComponent) {
4747
super(user.getId(), calendarComponent);
4848
}
4949

core-api/src/test/java/org/silverpeas/core/calendar/EventAttendeeManagementTest.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@
3333
* Unit tests on the management of attendees to events.
3434
* @author mmoquillon
3535
*/
36-
public class EventAttendeeManagementTest {
36+
class EventAttendeeManagementTest {
3737

3838
@Test
39-
public void addAnAttendeeToAnEvent() {
39+
void addAnAttendeeToAnEvent() {
4040
CalendarEvent event =
4141
anEvent().withAttendee("joe@dalton.com").withAttendee("averel@dalton.com");
4242
assertThat(
@@ -50,14 +50,14 @@ public void addAnAttendeeToAnEvent() {
5050
}
5151

5252
@Test
53-
public void delegateAnAttendeeToAnotherUserAddThisUserAmongTheAttendeesToTheEvent() {
53+
void delegateAnAttendeeToAnotherUserAddThisUserAmongTheAttendeesToTheEvent() {
5454
CalendarEvent event = anEvent();
5555
Attendee attendee = ExternalAttendee.withEmail("joe@dalton.com")
5656
.to(event.asCalendarComponent());
5757
event.getAttendees().add(attendee);
5858
assertThat(event.getAttendees().size(), is(1));
5959

60-
attendee.delegateTo("averel@dalton.com");
60+
attendee.delegateTo(AttendeeSuppliers.fromEmail("averel@dalton.com"));
6161

6262
assertThat(event.getAttendees().size(), is(2));
6363
assertThat(
@@ -67,32 +67,34 @@ public void delegateAnAttendeeToAnotherUserAddThisUserAmongTheAttendeesToTheEven
6767
}
6868

6969
@Test
70-
public void delegateAnAttendeeToAnotherUserChangeTheParticipationStatus() {
70+
void delegateAnAttendeeToAnotherUserChangeTheParticipationStatus() {
7171
CalendarEvent event = anEvent();
7272
Attendee attendee = ExternalAttendee.withEmail("joe@dalton.com")
7373
.to(event.asCalendarComponent());
7474
event.getAttendees().add(attendee);
7575
assertThat(event.getAttendees().size(), is(1));
7676

77-
attendee.delegateTo("averel@dalton.com");
77+
attendee.delegateTo(AttendeeSuppliers.fromEmail("averel@dalton.com"));
7878

7979
assertThat(attendee.getParticipationStatus(), is(Attendee.ParticipationStatus.DELEGATED));
8080
}
8181

8282
@Test
83-
public void delegateAnAttendeeToAnotherUserSetsTheDelegationBetweenTwoThem() {
83+
void delegateAnAttendeeToAnotherUserSetsTheDelegationBetweenTwoThem() {
8484
CalendarEvent event = anEvent();
8585
Attendee attendee = ExternalAttendee.withEmail("joe@dalton.com")
8686
.to(event.asCalendarComponent());
8787
event.getAttendees().add(attendee);
8888
assertThat(event.getAttendees().size(), is(1));
8989

90-
attendee.delegateTo("averel@dalton.com");
90+
attendee.delegateTo(AttendeeSuppliers.fromEmail("averel@dalton.com"));
9191

9292
assertThat(attendee.getDelegate().isPresent(), is(true));
9393
assertThat(attendee.getDelegate().get(),
9494
is(ExternalAttendee.withEmail("averel@dalton.com")
9595
.to(event.asCalendarComponent())));
96+
assertThat(attendee.getDelegate().isPresent(), is(true));
97+
assertThat(attendee.getDelegate().get().getDelegate().isPresent(), is(true));
9698
assertThat(attendee.getDelegate().get().getDelegate().get(), is(attendee));
9799
}
98100

core-library/src/integration-test/java/org/silverpeas/core/calendar/CalendarEventAttendeeManagementIT.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ public void delegateTheAttendanceToAnotherUser() {
198198

199199
Attendee attendeeToDelegate =
200200
in(eventWithAttendees.getAttendees()).find(expectedUser().getId());
201-
attendeeToDelegate.delegateTo(getUser());
201+
attendeeToDelegate.delegateTo(AttendeeSuppliers.fromUser(getUser()));
202202
eventWithAttendees.update();
203203

204204
mayBeEvent = calendar.event(EVENT_WITH_ATTENDEE);
@@ -358,7 +358,7 @@ private List<CalendarEventOccurrence> allOccurrencesOf(final CalendarEvent event
358358
.collect(Collectors.toList());
359359
}
360360

361-
public static AttendeeFinder in(final AttendeeSet attendees) {
361+
static AttendeeFinder in(final AttendeeSet attendees) {
362362
return new AttendeeFinder(attendees);
363363
}
364364

core-library/src/integration-test/java/org/silverpeas/core/calendar/CalendarEventNotificationIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ public void delegateParticipationSendTwoNotifications() {
256256
Optional<Attendee> mayBeAttendee = event.getAttendees().stream().findFirst();
257257
assertThat(mayBeAttendee.isPresent(), is(true));
258258
Attendee attendee = mayBeAttendee.get();
259-
attendee.delegateTo(User.getById("2"));
259+
attendee.delegateTo(AttendeeSuppliers.fromUser(User.getById("2")));
260260
event.update();
261261

262262
assertThat(eventListener.hasBeenNotified(), is(false));

core-library/src/main/java/org/silverpeas/core/admin/space/SpaceProfileInst.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,13 @@ public boolean isManager() {
7575
return SPACE_MANAGER.equalsIgnoreCase(getName());
7676
}
7777

78+
@Override
79+
public boolean equals(Object o) {
80+
return o instanceof SpaceProfileInst && super.equals(o);
81+
}
82+
83+
@Override
84+
public int hashCode() {
85+
return super.hashCode();
86+
}
7887
}

core-library/src/main/java/org/silverpeas/core/admin/user/model/ProfileInst.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,4 +135,14 @@ public void setParentObjectId(final ProfiledObjectId parentObjectId) {
135135
public boolean isOnComponentInstance() {
136136
return this.objectId == ProfiledObjectId.NOTHING;
137137
}
138+
139+
@Override
140+
public boolean equals(Object o) {
141+
return o instanceof ProfileInst && super.equals(o);
142+
}
143+
144+
@Override
145+
public int hashCode() {
146+
return super.hashCode();
147+
}
138148
}

0 commit comments

Comments
 (0)