1
1
package org .edu_sharing .repository .server .policies ;
2
2
3
3
import jakarta .annotation .PostConstruct ;
4
+ import jakarta .servlet .http .HttpServletRequest ;
5
+ import jakarta .servlet .http .HttpSession ;
4
6
import lombok .RequiredArgsConstructor ;
5
7
import lombok .extern .slf4j .Slf4j ;
6
8
import org .alfresco .model .ContentModel ;
26
28
import java .util .List ;
27
29
import java .util .Map ;
28
30
import java .util .Objects ;
31
+ import java .util .Optional ;
29
32
30
33
@ Slf4j
31
34
@ Component
@@ -50,7 +53,7 @@ public void init() {
50
53
51
54
@ Override
52
55
public void onCreateNode (ChildAssociationRef childAssocRef ) {
53
- checkForResveredNames (childAssocRef .getParentRef (), childAssocRef .getChildRef ());
56
+ checkForReservedNames (childAssocRef .getParentRef (), childAssocRef .getChildRef ());
54
57
}
55
58
56
59
@ Override
@@ -59,19 +62,28 @@ public void onUpdateProperties(NodeRef nodeRef, Map<QName, Serializable> before,
59
62
return ;
60
63
}
61
64
ChildAssociationRef primaryParent = nodeService .getPrimaryParent (nodeRef );
62
- checkForResveredNames (primaryParent .getParentRef (), nodeRef );
65
+ checkForReservedNames (primaryParent .getParentRef (), nodeRef );
63
66
}
64
67
65
68
@ Override
66
69
public CopyBehaviourCallback getCopyCallback (QName classRef , CopyDetails copyDetails ) {
67
- checkForResveredNames (copyDetails .getTargetParentNodeRef (), copyDetails .getSourceNodeRef ());
70
+ checkForReservedNames (copyDetails .getTargetParentNodeRef (), copyDetails .getSourceNodeRef ());
68
71
return new DefaultCopyBehaviourCallback ();
69
72
}
70
73
71
- private void checkForResveredNames (NodeRef parentRef , NodeRef childRef ) {
74
+ private void checkForReservedNames (NodeRef parentRef , NodeRef childRef ) {
72
75
try {
73
76
74
- String userName = new AuthenticationToolAPI ().getAuthentication (Context .getCurrentInstance ().getRequest ().getSession ()).get (CCConstants .AUTH_USERNAME );
77
+ HttpSession httpSession = Optional .ofNullable (Context .getCurrentInstance ())
78
+ .map (Context ::getRequest )
79
+ .map (HttpServletRequest ::getSession )
80
+ .orElse (null );
81
+
82
+ if (httpSession == null ) {
83
+ return ;
84
+ }
85
+
86
+ String userName = new AuthenticationToolAPI ().getAuthentication (httpSession ).get (CCConstants .AUTH_USERNAME );
75
87
MCAlfrescoAPIClient baseClient = new MCAlfrescoAPIClient ();
76
88
String homeFolderID = baseClient .getHomeFolderID (userName );
77
89
if (!parentRef .getId ().equals (homeFolderID )) {
0 commit comments