1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.directory.server.core.api.interceptor.context;
21
22
23 import java.util.ArrayList;
24 import java.util.List;
25
26 import org.apache.directory.api.ldap.model.entry.Attribute;
27 import org.apache.directory.api.ldap.model.entry.DefaultModification;
28 import org.apache.directory.api.ldap.model.entry.Entry;
29 import org.apache.directory.api.ldap.model.entry.Modification;
30 import org.apache.directory.api.ldap.model.entry.ModificationOperation;
31 import org.apache.directory.api.ldap.model.exception.LdapException;
32 import org.apache.directory.api.ldap.model.exception.LdapOperationErrorException;
33 import org.apache.directory.api.ldap.model.message.MessageTypeEnum;
34 import org.apache.directory.api.ldap.model.message.ModifyRequest;
35 import org.apache.directory.api.ldap.model.message.controls.ManageDsaIT;
36 import org.apache.directory.api.ldap.model.name.Dn;
37 import org.apache.directory.server.core.api.CoreSession;
38 import org.apache.directory.server.core.api.OperationEnum;
39 import org.apache.directory.server.core.api.entry.ServerEntryUtils;
40
41
42
43
44
45
46
47
48
49
50 public class ModifyOperationContext extends AbstractChangeOperationContext
51 {
52
53 private List<Modification> modItems;
54
55
56 private Entry alteredEntry;
57
58
59
60
61
62
63
64 public ModifyOperationContext( CoreSession session )
65 {
66 super( session );
67
68 if ( session != null )
69 {
70 setInterceptors( session.getDirectoryService().getInterceptors( OperationEnum.MODIFY ) );
71 }
72 }
73
74
75
76
77
78
79
80
81
82 public ModifyOperationContext( CoreSession session, Dn dn, List<Modification> modItems )
83 {
84 super( session, dn );
85
86 if ( session != null )
87 {
88 setInterceptors( session.getDirectoryService().getInterceptors( OperationEnum.MODIFY ) );
89 }
90
91 this.modItems = modItems;
92 }
93
94
95
96
97
98
99
100
101
102 public ModifyOperationContext( CoreSession session, ModifyRequest modifyRequest ) throws LdapException
103 {
104 super( session, modifyRequest.getName() );
105
106 if ( session != null )
107 {
108 setInterceptors( session.getDirectoryService().getInterceptors( OperationEnum.MODIFY ) );
109 }
110 else
111 {
112 throw new LdapOperationErrorException( "Cannot proceed the operation with no session" );
113 }
114
115 modItems = ServerEntryUtils.toServerModification( modifyRequest.getModifications().toArray(
116 new DefaultModification[0] ), session.getDirectoryService().getSchemaManager() );
117
118 requestControls = modifyRequest.getControls();
119
120 if ( requestControls.containsKey( ManageDsaIT.OID ) )
121 {
122 ignoreReferral();
123 }
124 else
125 {
126 throwReferral();
127 }
128 }
129
130
131
132
133
134
135 public void setModItems( List<Modification> modItems )
136 {
137 this.modItems = modItems;
138 }
139
140
141
142
143
144 public List<Modification> getModItems()
145 {
146 return modItems;
147 }
148
149
150 public static List<Modification> createModItems( Entry serverEntry, ModificationOperation modOp )
151 {
152 List<Modification> items = new ArrayList<>( serverEntry.size() );
153
154 for ( Attribute attribute : serverEntry )
155 {
156 items.add( new DefaultModification( modOp, attribute ) );
157 }
158
159 return items;
160 }
161
162
163
164
165
166 public String getName()
167 {
168 return MessageTypeEnum.MODIFY_REQUEST.name();
169 }
170
171
172
173
174
175
176
177
178 public Entry getAlteredEntry()
179 {
180 return alteredEntry;
181 }
182
183
184
185
186
187
188
189
190 public void setAlteredEntry( Entry alteredEntry )
191 {
192 this.alteredEntry = alteredEntry;
193 }
194
195
196
197
198
199 public String toString()
200 {
201 StringBuilder sb = new StringBuilder();
202
203 sb.append( "ModifyContext for Dn '" ).append( getDn().getName() ).append( "', modifications :\n" );
204
205 if ( modItems != null )
206 {
207 for ( Modification mod : modItems )
208 {
209 sb.append( mod ).append( '\n' );
210 }
211 }
212
213 return sb.toString();
214 }
215 }