Skip to content

Commit 922d5e6

Browse files
committed
documentation and code cleanup
1 parent be51c58 commit 922d5e6

File tree

13 files changed

+259
-85
lines changed

13 files changed

+259
-85
lines changed

src/main/java/ch/ethz/seb/sps/server/datalayer/batis/custommappers/SearchSessionMapper.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,16 @@
1111
import java.sql.Date;
1212
import java.util.List;
1313

14+
/** This mapper is used to search for dates that has matching screenshot data for a given filter.*/
1415
@Mapper
1516
public interface SearchSessionMapper {
1617

1718
@SelectProvider(type = CustomSqlProvider.class, method = "selectDistinctCreationDates")
1819
List<Date> selectDistinctCreationTimes(SelectStatementProvider selectStatement);
1920

21+
/** Used to select on session records creation_time by dates (instead of timestamp).
22+
*
23+
* @return QueryExpressionDSL to add additional clauses if needed*/
2024
default QueryExpressionDSL<MyBatis3SelectModelAdapter<List<Date>>> selectCreationTimesAsDates(){
2125
return SelectDSL.selectDistinctWithMapper(this::selectDistinctCreationTimes, SessionRecordDynamicSqlSupport.creationTime)
2226
.from(SessionRecordDynamicSqlSupport.sessionRecord);

src/main/java/ch/ethz/seb/sps/server/datalayer/dao/ActivatableEntityDAO.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ public interface ActivatableEntityDAO<T extends Entity, M extends ModelIdAware>
2525
* @return The Collection of Results refer to the EntityKey instance or refer to an error if happened */
2626
Result<EntityKey> setActive(EntityKey entityKey, boolean active);
2727

28+
/** Set all entities referred by the given Collection of EntityKey active / inactive
29+
*
30+
* @param entity T the entity to set active or inactive
31+
* @param active The active flag
32+
* @return The Collection of Results refer to the Entity instance or refer to an error if happened */
2833
default Result<T> setActive(final T entity, final boolean active) {
2934
return setActive(entity.getEntityKey(), active)
3035
.map(key -> byModelId(key.modelId).getOr(entity));

src/main/java/ch/ethz/seb/sps/server/datalayer/dao/ClientAccessDAO.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313

1414
public interface ClientAccessDAO extends ActivatableEntityDAO<ClientAccess, ClientAccess> {
1515

16-
public Result<CharSequence> getEncodedClientPWD(String clientId, boolean checkActive);
16+
/** Get the encoded client password that is used by a SEB client to authenticate.
17+
*
18+
* @param clientId The client authentication entity id.
19+
* @param checkActive Only gets the password if the client authentication entity is active.
20+
* @return Result refer to CharSequence with the encoded client password. */
21+
Result<CharSequence> getEncodedClientPWD(String clientId, boolean checkActive);
1722

1823
}

src/main/java/ch/ethz/seb/sps/server/datalayer/dao/DAOAdapterType.java

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/main/java/ch/ethz/seb/sps/server/datalayer/dao/EntityPrivilegeDAO.java

Lines changed: 56 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,33 +18,74 @@
1818
import ch.ethz.seb.sps.domain.model.user.EntityPrivilege;
1919
import ch.ethz.seb.sps.utils.Result;
2020

21+
/** An EntityPrivilege is a privilege for a specific user on a specific entity instance.
22+
* EntityPrivilege maps a user UUID to a entity (type and id) and specifies a privilege for the user.
23+
* The PrivilegeType is either "r" for read, "m" for modify (and read) or "w" for write (and modify and read) */
2124
public interface EntityPrivilegeDAO {
2225

23-
Result<Collection<EntityPrivilege>> getEntityPrivileges(
24-
EntityType type,
25-
Long entityId);
26+
/** Get all entity privileges for a given entity type and id.
27+
*
28+
* @param entityType The entity type
29+
* @param entityId The entity id (PK)
30+
* @return Result refer to a collection of all EntityPrivilege for the given entity or to an error when happened.*/
31+
Result<Collection<EntityPrivilege>> getEntityPrivileges(EntityType entityType, Long entityId);
2632

27-
Result<Set<Long>> getEntityIdsWithPrivilegeForUser(
28-
EntityType type,
29-
String userUUID,
30-
PrivilegeType privilegeType);
33+
/** Get all entity ids for a given user and a given PrivilegeType.
34+
*
35+
* @param entityType The entity type
36+
* @param userUUID The user UUID
37+
* @param privilegeType The privilege type
38+
* @return Result refer to a set of entity ids (PKs) that the given user has the privilege for, or to an error when happened */
39+
Result<Set<Long>> getEntityIdsWithPrivilegeForUser(EntityType entityType, String userUUID, PrivilegeType privilegeType);
3140

41+
/** Get all EntityPrivilege for a given user.
42+
*
43+
* @param userUUID The user UUID
44+
* @return Result refer to the collection of EntityPrivilege the given user has or to an error when happened */
3245
Result<Collection<EntityPrivilege>> getEntityPrivilegesForUser(String userUUID);
3346

47+
/** Add a given privilege for a user to an entity.
48+
*
49+
* @param entityType The entity type
50+
* @param entityId The entity id (PK)
51+
* @param userUUID The user UUID
52+
* @param privilegeType The type of privilege to give to the user on entity
53+
* @return Result refer to added EntityPrivilege or to an error when happened */
3454
Result<EntityPrivilege> addPrivilege(
35-
EntityType type,
55+
EntityType entityType,
3656
Long entityId,
3757
String userUUID,
3858
PrivilegeType privilegeType);
3959

40-
Result<EntityKey> deletePrivilege(
41-
EntityType type,
42-
Long entityId,
43-
String userUUID);
44-
45-
Result<Collection<EntityKey>> deleteAllPrivileges(EntityType type, Long entityId);
60+
/** Deletes a privilege for a user on an object.
61+
*
62+
* @param entityType The entity type
63+
* @param entityId The entity id (PK)
64+
* @param userUUID The user UUID
65+
* @return Result refer to the EntityKey of the deleted EntityPrivilege or to an error when happened*/
66+
Result<EntityKey> deletePrivilege(EntityType entityType, Long entityId, String userUUID);
4667

47-
void updatePrivileges(Long epId, PrivilegeType privilegeType);
68+
/** Deletes all EntityPrivileges of a specific entity.
69+
*
70+
* @param entityType The entity type
71+
* @param entityId The entity id (PK)
72+
* @return Result refer to a collection of all deleted EntityPrivilege keys or to an error when happened. */
73+
Result<Collection<EntityKey>> deleteAllPrivileges(EntityType entityType, Long entityId);
4874

75+
/** Deletes all privileges for a specified user.
76+
*
77+
* @param user_uuid The user UUID to delete all privileges for*/
4978
void deleteAllPrivilegesForUser(String user_uuid);
79+
80+
/** Update one single EntityPrivilege.
81+
*
82+
* @param epId EntityPrivilege id (PK)
83+
* @param privilegeType The PrivilegeType to update to */
84+
void updatePrivilege(Long epId, PrivilegeType privilegeType);
85+
86+
/** Update all given EntityPrivileges to a given PrivilegeType.
87+
*
88+
* @param epIds Collection of EntityPrivilege ids (PKs)
89+
* @param privilegeType The PrivilegeType to update to */
90+
void updatePrivileges(Collection<Long> epIds, PrivilegeType privilegeType);
5091
}

src/main/java/ch/ethz/seb/sps/server/datalayer/dao/ScreenshotDAO.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,18 @@
1515

1616
public interface ScreenshotDAO {
1717

18-
Result<InputStream> getImage(
19-
Long pk,
20-
String sessionUUID);
18+
/** Get an Image via InputStream.
19+
*
20+
* @param pk The PK of the image to get
21+
* @param sessionUUID The session UUID where the image belongs to.
22+
* @return Result refer to an InputSteam for the image data */
23+
Result<InputStream> getImage(Long pk, String sessionUUID);
2124

22-
Result<List<Long>> deleteAllForSession(
23-
String sessionUUID,
24-
List<Long> screenShotPKs);
25+
/** Deletes all images for a specified session
26+
*
27+
* @param sessionUUID The session UUID
28+
* @param screenShotPKs List of all image PKs to delete.
29+
* @return Result refer to the list of image PK that has been deleted or to an error when happened */
30+
Result<List<Long>> deleteAllForSession(String sessionUUID, List<Long> screenShotPKs);
2531

2632
}

src/main/java/ch/ethz/seb/sps/server/datalayer/dao/ScreenshotDataDAO.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,17 @@ public interface ScreenshotDataDAO extends EntityDAO<ScreenshotData, ScreenshotD
4040

4141
Result<ScreenshotDataRecord> getLatest(String sessionUUID);
4242

43-
@Transactional(readOnly = true)
44-
default Result<Map<String, ScreenshotDataRecord>> allLatestOf(final String sessionUUIDList) {
45-
return Result.tryCatch(() -> {
46-
47-
final List<String> ids = sessionUUIDList.contains(Constants.LIST_SEPARATOR)
48-
? Arrays.asList(StringUtils.split(sessionUUIDList, Constants.LIST_SEPARATOR))
49-
: Arrays.asList(sessionUUIDList);
50-
51-
return allLatestIn(ids).getOrThrow();
52-
});
53-
}
43+
// @Transactional(readOnly = true)
44+
// default Result<Map<String, ScreenshotDataRecord>> allLatestOf(final String sessionUUIDList) {
45+
// return Result.tryCatch(() -> {
46+
//
47+
// final List<String> ids = sessionUUIDList.contains(Constants.LIST_SEPARATOR)
48+
// ? Arrays.asList(StringUtils.split(sessionUUIDList, Constants.LIST_SEPARATOR))
49+
// : Arrays.asList(sessionUUIDList);
50+
//
51+
// return allLatestIn(ids).getOrThrow();
52+
// });
53+
// }
5454

5555
Result<Map<String, ScreenshotDataRecord>> allLatestIn(List<String> sessionUUIDs);
5656

src/main/java/ch/ethz/seb/sps/server/datalayer/dao/SessionDAO.java

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,17 @@
2121

2222
public interface SessionDAO extends ActivatableEntityDAO<Session, Session> {
2323

24+
/** Creates a new Session for a specified group
25+
*
26+
* @param groupUUID The group UUID
27+
* @param uuid The Session UUID that is used to identify the new session
28+
* @param userSessionName The username for the session
29+
* @param clientIP The client IP of the new session
30+
* @param clientMachineName The client machine name for the new session
31+
* @param clientOSName The client OS name for the new session
32+
* @param clientVersion The client version of the new session
33+
* @param imageFormat The image format of the new session
34+
* @return Result refer to the new created session or to an error when happened*/
2435
Result<Session> createNew(
2536
String groupUUID,
2637
String uuid,
@@ -31,29 +42,97 @@ Result<Session> createNew(
3142
String clientVersion,
3243
ImageFormat imageFormat);
3344

45+
/** Get a collection of all session uuid that are actually active for a given group.
46+
*
47+
* @param groupId The group id (PK)
48+
* @return Result refer to the resulting collection or to an error if happened */
3449
Result<Collection<String>> allLiveSessionUUIDsByGroupId(Long groupId);
3550

51+
/** Get a collection of all session uuid for a given group.
52+
*
53+
* @param groupId The group id (PK)
54+
* @return Result refer to the resulting collection or to an error if happened */
3655
Result<Collection<String>> allSessionUUIDsByGroupId(Long groupId);
3756

57+
/** Get a count of all active live session of a given group.
58+
*
59+
* @param groupId The group id (PK)
60+
* @return Result refer to the count or to an error when happened */
3861
Result<Long> allLiveSessionCount(Long groupId);
3962

63+
/** Get a count of all session of a given group.
64+
*
65+
* @param groupId The group id (PK)
66+
* @return Result refer to the count or to an error when happened */
4067
Result<Long> allSessionCount(Long groupId);
4168

69+
/** Close a given session.
70+
*
71+
* @param sessionUUID The session UUID to close.
72+
* @return Result refer to the UUID of the closed session or to an error when happened */
4273
Result<String> closeSession(String sessionUUID);
4374

75+
/** Close all open sessions within a given group.
76+
*
77+
* @param groupPK The group id (PK)
78+
* @return Result refer to a collection of EntityKey of all sessions that has been closed, or to an error when happened*/
4479
Result<Collection<EntityKey>> closeAllSessionsForGroup(Long groupPK);
4580

81+
/** Deletes all Session for a given list of groups
82+
*
83+
* @param groupPKs List of group PKs to delete all sessions for
84+
* @return Result refer to a collection of EntityKey of all deleted session, or to an error when happened*/
4685
Result<Collection<EntityKey>> deleteAllForGroups(final List<Long> groupPKs);
4786

87+
/** Get the number of screenshots for a given session filtered by screenshot metadata.
88+
* Filter criteria are of type API.ScreenshotMetadataType and are AND combined.
89+
*
90+
* @param uuid The session UUID
91+
* @param filterMap filter map containing filter criteria to apply to before count
92+
* @return the number of filtered screenshots for a given session */
4893
Long getNumberOfScreenshots(String uuid, FilterMap filterMap);
4994

95+
/** Indicates if there are any session data for a given list of groups.
96+
*
97+
* @param groupIds Collection of group ids (PK) to check for.
98+
* @return Result refer to the indicator or to an error when happened.*/
5099
Result<Boolean> hasAnySessionData(Collection<Long> groupIds);
51100

101+
/** Get a list of dates for which screenshot data exists for a given filter criteria.
102+
* This is used in multiple step searches where first a list of dates is presented where screenshot data exists
103+
* and only if one is interested in screenshot data of a specific date, the search is applied to get the data for
104+
* only this date, to improve performance.
105+
* <p>
106+
* Filter criteria:
107+
* <pre>
108+
* active = filterMap.getBooleanObject(API.ACTIVE_FILTER);
109+
* fromTime = filterMap.getLong(API.PARAM_FROM_TIME);
110+
* toTime = filterMap.getLong(API.PARAM_TO_TIME);
111+
* groupPKs = filterMap.getString(Domain.SESSION.ATTR_GROUP_ID);
112+
* sessionUUID = filterMap.contains(API.PARAM_SESSION_ID)
113+
* </pre>
114+
* @param filterMap The map containing the filter criteria
115+
* @return Result refer to a list of dates where screenshots exists or to an error when happened.*/
52116
Result<List<Date>> queryMatchingDaysForSessionSearch(final FilterMap filterMap);
53117

118+
/** This is only for distributed setups where we can get all session UUIDs of a given group that
119+
* are out of sync on its cached instances. This checks the update_time timestamps of cached instances with the once
120+
* on the database and gives all Session UUID that has different update_time and where updated by another SPS service.
121+
* @param groupId The group id (PK)
122+
* @param updateTimes List of update_time timestamps of all cached sessions.
123+
* @return Result refer to the list of session UUIDs that needs update, ot to an error when happened*/
54124
Result<List<String>> allTokensThatNeedsUpdate(Long groupId, Set<Long> updateTimes);
55-
125+
126+
/** Get the encryption key of the session used to encrypt/decrypt client side stored screenshot data.
127+
*
128+
* @param uuid The UUID of the session
129+
* @return Result refer to the encryption key of the session or to an error when happened */
56130
Result<String> getEncryptionKey(String uuid);
57131

132+
/** This us used to close a given open session at a given time.
133+
*
134+
* @param sessionUUID The UUID of the session to close at given time
135+
* @param termination_time The timestamp on which to close the session (unix timestamp im milliseconds)
136+
* @return Result refer to the close timestamp or to an error when happened.*/
58137
Result<Long> closeAt(String sessionUUID, Long termination_time);
59138
}

0 commit comments

Comments
 (0)