11package com .github .simple_mocks .session .api ;
22
33import com .github .simple_mocks .session .api .dto .Session ;
4- import com .github .simple_mocks .session .api .dto .action .Action ;
5- import com .github .simple_mocks .session .api .dto .action .DeleteAction ;
6- import com .github .simple_mocks .session .api .dto .action .SetAction ;
4+ import com .github .simple_mocks .session .api .dto .SessionOwnerType ;
5+ import jakarta .annotation .Nonnull ;
76
87import java .io .Serializable ;
98import java .util .List ;
9+ import java .util .Map ;
1010import java .util .Set ;
1111
1212/**
@@ -22,7 +22,7 @@ public interface SessionService {
2222 * @param sessionId session identifier
2323 * @return session or null
2424 */
25- Session get (SessionId sessionId );
25+ Session get (@ Nonnull SessionId sessionId );
2626
2727 /**
2828 * Get the last version of session common info.<br/>
@@ -31,18 +31,19 @@ public interface SessionService {
3131 * @param uid session uid
3232 * @return session or null
3333 */
34- Session get (String uid );
34+ Session get (@ Nonnull String uid );
3535
3636 /**
3737 * Get attribute names from session's section.<br/>
38- * In case if a section not exists when null should be returned.<br/>
38+ * In case if a section doesn't exist when null should be returned.<br/>
3939 * If session isn't found when {@link SessionErrors#NOT_EXISTS} should be thrown.
4040 *
4141 * @param sessionId session identifier
4242 * @param section section in session
4343 * @return attribute names
4444 */
45- Set <String > getAttributeNames (SessionId sessionId , String section );
45+ Set <String > getAttributeNames (@ Nonnull SessionId sessionId ,
46+ @ Nonnull String section );
4647
4748 /**
4849 * Get attribute value from session.<br/>
@@ -55,53 +56,34 @@ public interface SessionService {
5556 * @param <T> type of attribute
5657 * @return attribute value or null
5758 */
58- <T extends Serializable > T getAttribute (SessionId sessionId , String section , String attribute );
59+ <T extends Serializable > T getAttribute (@ Nonnull SessionId sessionId ,
60+ @ Nonnull String section ,
61+ @ Nonnull String attribute );
5962
6063 /**
61- * Put attribute value into session's section<br/>
62- * If session not found when {@link SessionErrors#NOT_EXISTS} should be thrown.<br/>
63- * If a section is readonly when {@link SessionErrors#READONLY} should be thrown.
64+ * Create session with passed data.<br/>
6465 *
65- * @param sessionId session id
66- * @param section section in session
67- * @param attribute attribute code
68- * @param value attribute value
69- * @param <T> type of attribute
70- * @return new session identifier
71- */
72- default <T extends Serializable > SessionId putAttribute (
73- SessionId sessionId ,
74- String section ,
75- String attribute ,
76- T value ) {
77- var action = new SetAction (section , attribute , value );
78- return update (sessionId , List .of (action ));
79- }
80-
81- /**
82- * Remove attribute value from session<br/>
83- * If session not found when {@link SessionErrors#NOT_EXISTS} should be thrown.<br/>
84- * If a section is readonly when {@link SessionErrors#READONLY} should be thrown.
85- *
86- * @param sessionId session id
87- * @param section section in session
88- * @param attribute attribute code
66+ * @param sections shared sections data
67+ * @param ownerType session owner type
68+ * @param ownerId session owner id
69+ * @param permissions list of user permissions
8970 * @return new session identifier
9071 */
91- default SessionId removeAttribute ( SessionId sessionId , String section , String attribute ) {
92- var action = new DeleteAction ( section , attribute );
93- return update ( sessionId , List . of ( action ));
94- }
72+ SessionId create ( @ Nonnull Map < String , Map < String , Serializable >> sections ,
73+ @ Nonnull SessionOwnerType ownerType ,
74+ @ Nonnull String ownerId ,
75+ @ Nonnull List < String > permissions );
9576
9677 /**
9778 * Update session by applying passed actions.<br/>
9879 * Method should apply actions transitionally, in case if some action can't be applied session state should be reset.<br/>
9980 * If session isn't found when {@link SessionErrors#NOT_EXISTS} should be thrown.<br/>
10081 * If any of sections are readonly when {@link SessionErrors#READONLY} should be thrown.
10182 *
102- * @param sessionId session id
103- * @param actions actions
83+ * @param sessionId session id
84+ * @param modificationQuery query to modify session
10485 * @return new session identifier
10586 */
106- SessionId update (SessionId sessionId , List <? extends Action > actions );
87+ SessionId update (@ Nonnull SessionId sessionId ,
88+ @ Nonnull ModificationQuery modificationQuery );
10789}
0 commit comments