1 package com.atlassian.core.ofbiz.association;
2
3 import com.opensymphony.user.EntityNotFoundException;
4 import com.opensymphony.user.User;
5 import org.ofbiz.core.entity.GenericEntityException;
6 import org.ofbiz.core.entity.GenericValue;
7
8 import java.util.List;
9
10 public interface AssociationManager
11 {
12 public GenericValue createAssociation(User user, GenericValue sink, String associationType)
13 throws GenericEntityException;
14
15 /**
16 * Creates an association between a user and a sink node.
17 *
18 * @param userName the user name to associate with the sink node.
19 * @param sinkNodeId the id of the sink node entity
20 * @param sinkNodeEntity the entity name of the sink node
21 * @param associationType the association type
22 * @return the created association
23 * @throws GenericEntityException
24 */
25 public GenericValue createAssociation(String userName, Long sinkNodeId, String sinkNodeEntity, String associationType)
26 throws GenericEntityException;
27
28 /**
29 * Create an association between two entities, given a particular association type.
30 * <p/>
31 * If the association already exists - it will not be created.
32 *
33 * @return The new association, or the existing association if it already existed.
34 */
35 public GenericValue createAssociation(GenericValue source, GenericValue sink, String associationType)
36 throws GenericEntityException;
37
38 /**
39 * Create an association between two entities, given a particular assocation type.
40 * <p/>
41 * If the association already exists - it will not be created.
42 * <p/>
43 * NOTE: this is a convenience method that should only be used when you are certain of the related entity id's.
44 * This method does not verify the integrity of the links it creates.
45 *
46 * @return The new association, or the existing association if it already existed.
47 */
48 public GenericValue createAssociation(Long sourceNodeId, String sourceNodeEntity, Long sinkNodeId, String sinkNodeEntity, String associationType)
49 throws GenericEntityException;
50
51 public void removeAssociation(GenericValue source, GenericValue sink, String associationType)
52 throws GenericEntityException;
53
54 public void removeAssociation(User user, GenericValue sink, String associationType) throws GenericEntityException;
55
56 /**
57 * Removes association between the user with given username and the generic value
58 *
59 * @param username username
60 * @param sink generic value, e.g. issue
61 * @param associationType association type
62 * @throws GenericEntityException if error occurs
63 */
64 public void removeAssociation(String username, GenericValue sink, String associationType)
65 throws GenericEntityException;
66
67 /**
68 * Remove all entity<->entity associations, given the source
69 */
70 public void removeAssociationsFromSource(GenericValue source) throws GenericEntityException;
71
72 public void removeAssociationsFromSink(GenericValue sink) throws GenericEntityException;
73
74 /**
75 * Remove all user<->entity associations, given the entity
76 */
77 public void removeUserAssociationsFromSink(GenericValue sink) throws GenericEntityException;
78
79 /**
80 * Remove all uer associations given an entity and association type
81 *
82 * @param sink The entity disassociate with all users
83 * @param associationType the association type to remove
84 * @throws GenericEntityException throws if problem with ofbiz
85 */
86 public void removeUserAssociationsFromSink(GenericValue sink, String associationType) throws GenericEntityException;
87
88 /**
89 * Remove all user<->entity associations, given the user
90 */
91 public void removeUserAssociationsFromUser(User user) throws GenericEntityException;
92
93 /**
94 * Remove all user<->entity associations, given the user and association type
95 *
96 * @param user The user to remove all associations with
97 * @param associationType the type of associations to remove
98 * @throws GenericEntityException if database exception occurs
99 */
100 public void removeUserAssociationsFromUser(User user, String associationType) throws GenericEntityException;
101
102 /**
103 * Remove all user<->entity associations, given the user and association type
104 *
105 * @param user The user to remove all associations with
106 * @param entityName The type of entity to remove
107 * @param associationType the type of associations to remove
108 * @throws GenericEntityException if database exception occurs
109 */
110 public void removeUserAssociationsFromUser(User user, String associationType, String entityName)
111 throws GenericEntityException;
112
113
114 /**
115 * Swap all assocaitions of a particular type from one sink to another.
116 * <p/>
117 * Used in ComponentDelete and VersionDelete.
118 */
119 public void swapAssociation(String sourceEntityType, String associationType, GenericValue fromSink, GenericValue toSink)
120 throws GenericEntityException;
121
122 public void swapAssociation(List entities, String associationType, GenericValue fromSink, GenericValue toSink)
123 throws GenericEntityException;
124
125
126 /**
127 * Operates on NodeAssociations - gets MANY sinks from ONE source
128 */
129 public List getSinkFromSource(GenericValue source, String sinkName, String associationType, boolean useCache)
130 throws GenericEntityException;
131
132 public List getSinkFromSource(GenericValue source, String sinkName, String associationType, boolean useCache, boolean useSequence)
133 throws GenericEntityException;
134
135 /**
136 * Operates on NodeAssociations - gets MANY sources from ONE sink
137 */
138 public List getSourceFromSink(GenericValue sink, String sourceName, String associationType, boolean useCache)
139 throws GenericEntityException;
140
141 /**
142 * Operates on NodeAssociations - gets MANY sources from ONE sink
143 */
144 public List getSourceFromSink(GenericValue sink, String sourceName, String associationType, boolean useCache, boolean useSequence)
145 throws GenericEntityException;
146
147 /**
148 * Operates on UserAssociations - gets MANY sinks from ONE user
149 */
150 public List getSinkFromUser(User source, String sinkName, String associationType, boolean useCache)
151 throws GenericEntityException;
152
153 /**
154 * Operates on UserAssociations - gets MANY sinks Ids from ONE user
155 *
156 * @param source The associated user
157 * @param sinkName The type of entity
158 * @param associationType The association type
159 * @param useCache Do we use the cache
160 * @return a List of ids (Long)
161 */
162 public List /*<Long>*/ getSinkIdsFromUser(User source, String sinkName, String associationType, boolean useCache)
163 throws GenericEntityException;
164
165 /**
166 * Operates on UserAssociations - gets MANY sinks from ONE user
167 */
168 public List getSinkFromUser(User source, String sinkName, String associationType, boolean useCache, boolean useSequence)
169 throws GenericEntityException;
170
171 /**
172 * Operates on UserAssociations - gets MANY users from ONE sink
173 */
174 public List getUserFromSink(GenericValue sink, String associationType, boolean useCache)
175 throws GenericEntityException, EntityNotFoundException;
176
177 /**
178 * Operates on UserAssociations - gets MANY users from ONE sink
179 */
180 public List getUserFromSink(GenericValue sink, String associationType, boolean useCache, boolean useSequence)
181 throws GenericEntityException, EntityNotFoundException;
182
183 /**
184 * Finds and returns a list of associated usernames, never null.
185 *
186 * @param sink generic value
187 * @param associationType association type
188 * @param useCache use cache flag
189 * @param useSequence use sequence number flag
190 * @return a list of associated usernames, never null
191 * @throws GenericEntityException if an error occurs
192 */
193 public List/*<String>*/ getUsernamesFromSink(GenericValue sink, String associationType, boolean useCache, boolean useSequence)
194 throws GenericEntityException;
195
196 public GenericValue getAssociation(GenericValue source, GenericValue sink, String associationType)
197 throws GenericEntityException;
198
199 public GenericValue getAssociation(User user, GenericValue sink, String associationType)
200 throws GenericEntityException;
201
202 public List getSinkIdsFromSource(GenericValue source, String sinkEntity, String associationType)
203 throws GenericEntityException;
204
205 public List getSourceIdsFromSink(GenericValue sink, String sourceEntity, String associationType)
206 throws GenericEntityException;
207
208
209 }