001: /*
002: * Wilos Is a cLever process Orchestration Software - http://www.wilos-project.org
003: * Copyright (C) 2007-2008 Paul Sabatier University, IUP ISI (Toulouse, France) <massie@irit.fr>
004: *
005: * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
006: * General Public License as published by the Free Software Foundation; either version 2 of the License,
007: * or (at your option) any later version.
008: *
009: * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
010: * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
011: * GNU General Public License for more details.
012: *
013: * You should have received a copy of the GNU General Public License along with this program; if not,
014: * write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
015: */
016:
017: //TODO [Wilos3]MAPPING hibernate
018: package wilos.model.misc.concreteworkproduct;
019:
020: import java.util.HashSet;
021: import java.util.Set;
022:
023: import org.apache.commons.lang.builder.EqualsBuilder;
024: import org.apache.commons.lang.builder.HashCodeBuilder;
025:
026: import wilos.model.misc.concretebreakdownelement.ConcreteBreakdownElement;
027: import wilos.model.misc.concreterole.ConcreteRoleDescriptor;
028: import wilos.model.misc.concretetask.ConcreteTaskDescriptor;
029: import wilos.model.misc.project.Project;
030: import wilos.model.misc.wilosuser.Participant;
031: import wilos.model.spem2.task.TaskDescriptor;
032: import wilos.model.spem2.workproduct.WorkProductDescriptor;
033: import wilos.utils.Constantes.State;
034:
035: /**
036: * A ConcreteRoleDescriptor is a specific {@link WorkProductDescriptor} for a
037: * {@link Project}.
038: *
039: */
040: public class ConcreteWorkProductDescriptor extends
041: ConcreteBreakdownElement {
042:
043: // TODO [Wilos3]MAPPING add relations with ConcreteRoleDescriptor and
044: // ConcreteActivity
045:
046: private WorkProductDescriptor workProductDescriptor;
047:
048: private String state;
049:
050: private Participant participant;
051:
052: private ConcreteRoleDescriptor responsibleConcreteRoleDescriptor;
053:
054: private boolean isDeliverable;
055:
056: private Set<ConcreteTaskDescriptor> producerConcreteTasks;
057:
058: private Set<ConcreteTaskDescriptor> optionalUserConcreteTasks;
059:
060: private Set<ConcreteTaskDescriptor> mandatoryUserConcreteTasks;
061:
062: /**
063: * Class constructor
064: *
065: */
066: public ConcreteWorkProductDescriptor() {
067: this .producerConcreteTasks = new HashSet<ConcreteTaskDescriptor>();
068: this .optionalUserConcreteTasks = new HashSet<ConcreteTaskDescriptor>();
069: this .mandatoryUserConcreteTasks = new HashSet<ConcreteTaskDescriptor>();
070: this .state = State.CREATED;
071: }
072:
073: /**
074: * Returns a copy of the current instance of ConcreteWorkProductDescriptor
075: *
076: * @return a copy of the ConcreteWorkProductDescriptor
077: * @throws CloneNotSupportedException
078: */
079: @Override
080: public ConcreteWorkProductDescriptor clone()
081: throws CloneNotSupportedException {
082: ConcreteWorkProductDescriptor concreteWorkProductDescriptor = new ConcreteWorkProductDescriptor();
083: concreteWorkProductDescriptor.copy(this );
084: return concreteWorkProductDescriptor;
085: }
086:
087: /**
088: * Copy the values of the specified ConcreteWorkProductDescriptor into the
089: * current instance of the class.
090: *
091: * @param _concreteWorkProductDescriptor
092: * the ConcreteWorkProductDescriptor to copy
093: */
094: protected void copy(
095: final ConcreteWorkProductDescriptor _concreteWorkProductDescriptor) {
096: super .copy(_concreteWorkProductDescriptor);
097: this .producerConcreteTasks
098: .addAll(_concreteWorkProductDescriptor
099: .getProducerConcreteTasks());
100: this .optionalUserConcreteTasks
101: .addAll(_concreteWorkProductDescriptor
102: .getOptionalUserConcreteTasks());
103: this .mandatoryUserConcreteTasks
104: .addAll(_concreteWorkProductDescriptor
105: .getMandatoryUserConcreteTasks());
106: this .responsibleConcreteRoleDescriptor = _concreteWorkProductDescriptor
107: .getResponsibleConcreteRoleDescriptor();
108: this .state = _concreteWorkProductDescriptor.getState();
109: }
110:
111: /**
112: * Defines if the specified Object is the same or has the same values as the
113: * current instance of the class.
114: *
115: * @param obj
116: * the Object to be compare to the ConcreteWorkProductDescriptor
117: * @return true if the specified Object is the same, false otherwise
118: */
119: public boolean equals(Object obj) {
120: if (obj instanceof ConcreteWorkProductDescriptor == false) {
121: return false;
122: }
123: if (this == obj) {
124: return true;
125: }
126: ConcreteWorkProductDescriptor concreteWorkProductDescriptor = (ConcreteWorkProductDescriptor) obj;
127: return new EqualsBuilder()
128: .appendSuper(
129: super .equals(concreteWorkProductDescriptor))
130: .append(
131: this .producerConcreteTasks,
132: concreteWorkProductDescriptor.producerConcreteTasks)
133: .append(
134: this .optionalUserConcreteTasks,
135: concreteWorkProductDescriptor.optionalUserConcreteTasks)
136: .append(
137: this .mandatoryUserConcreteTasks,
138: concreteWorkProductDescriptor.mandatoryUserConcreteTasks)
139: .append(
140: this .responsibleConcreteRoleDescriptor,
141: concreteWorkProductDescriptor.responsibleConcreteRoleDescriptor)
142: .append(this .state, concreteWorkProductDescriptor.state)
143: .isEquals();
144: }
145:
146: /**
147: * Returns a hash code value for the object. This method is supported for
148: * the benefit of hash tables.
149: *
150: * @return the hash code of the current instance of
151: * ConcreteWorkProductDescriptor
152: */
153: public int hashCode() {
154: return new HashCodeBuilder(17, 37)
155: .appendSuper(super .hashCode()).append(
156: this .workProductDescriptor).append(
157: this .participant).append(
158: this .producerConcreteTasks).append(
159: this .optionalUserConcreteTasks).append(
160: this .mandatoryUserConcreteTasks).append(
161: this .responsibleConcreteRoleDescriptor).append(
162: this .state).toHashCode();
163: }
164:
165: /*
166: * Relation between ConcreteWorkProductDescriptor and ConcreteActivity
167: *
168: */
169:
170: /**
171: * Adds a relation between the current instance of
172: * ConcreteWorkProductDescriptor and a specified ConcreteTaskDescriptor.
173: *
174: * @param _producer
175: * Task which produces this workproduct
176: */
177: public void addProducerConcreteTask(ConcreteTaskDescriptor _producer) {
178: this .producerConcreteTasks.add(_producer);
179: _producer.getOutputConcreteWorkProductDescriptors().add(this );
180: }
181:
182: /**
183: * REmoves the relation between the current instance of
184: * ConcreteWorkProductDescriptor and a specified ConcreteTaskDescriptor.
185: *
186: * @param _producer
187: * Task which produces this workproduct
188: */
189: public void removeProducerConcreteTask(
190: ConcreteTaskDescriptor _producer) {
191: _producer.getOutputConcreteWorkProductDescriptors()
192: .remove(this );
193: this .producerConcreteTasks.remove(_producer);
194:
195: }
196:
197: /**
198: * Adds a relation between the current instance of
199: * ConcreteWorkProductDescriptor and a specified optional
200: * ConcreteTaskDescriptor.
201: *
202: * @param _user
203: * Activity which uses this workproduct
204: */
205: public void addOptionalUserConcreteTask(ConcreteTaskDescriptor _user) {
206: this .optionalUserConcreteTasks.add(_user);
207: _user.getOptionalInputConcreteWorkProductDescriptors()
208: .add(this );
209: }
210:
211: /**
212: * Removes the relation between the current instance of
213: * ConcreteWorkProductDescriptor and a specified optional
214: * ConcreteTaskDescriptor.
215: *
216: * @param _user
217: * Activity which uses this workproduct
218: */
219: public void removeOptionalUserConcreteTask(
220: ConcreteTaskDescriptor _user) {
221: _user.getOptionalInputConcreteWorkProductDescriptors().remove(
222: this );
223: this .optionalUserConcreteTasks.remove(_user);
224:
225: }
226:
227: /**
228: * Adds a relation between the current instance of
229: * ConcreteWorkProductDescriptor and a specified mandatory user
230: * ConcreteTaskDescriptor.
231: *
232: * @param _user
233: * Activity which uses this workproduct
234: */
235: public void addMandatoryUserConcreteTask(
236: ConcreteTaskDescriptor _user) {
237: this .mandatoryUserConcreteTasks.add(_user);
238: _user.getMandatoryInputConcreteWorkProductDescriptors().add(
239: this );
240: }
241:
242: /**
243: * Removes the relation between the current instance of
244: * ConcreteWorkProductDescriptor and a specified mandatory user
245: * ConcreteTaskDescriptor.
246: *
247: * @param _user
248: * Activity which uses this workproduct
249: */
250: public void removeMandatoryUserConcreteTask(
251: ConcreteTaskDescriptor _user) {
252: _user.getMandatoryInputConcreteWorkProductDescriptors().remove(
253: this );
254: this .mandatoryUserConcreteTasks.remove(_user);
255:
256: }
257:
258: /*
259: * Relation between ConcreteWorkProductDescriptor and ConcreteRoleDescriptor
260: *
261: */
262:
263: /**
264: * Adds a relation between the current instance of
265: * ConcreteWorkProductDescriptor and a specified ConcreteRoleDescriptor.
266: *
267: * @param _responsible
268: * the ConcreteRoleDescriptor to link
269: */
270: public void addResponsibleConcreteRoleDescriptor(
271: ConcreteRoleDescriptor _responsible) {
272: this .responsibleConcreteRoleDescriptor = _responsible;
273: _responsible.getConcreteWorkProductDescriptors().add(this );
274: }
275:
276: /**
277: * Removes the relation between the current instance of
278: * ConcreteWorkProductDescriptor and a specified ConcreteRoleDescriptor.
279: *
280: * @param _responsible
281: * the ConcreteRoleDescriptor to unlink
282: */
283: public void removeResponsibleConcreteRoleDescriptor(
284: ConcreteRoleDescriptor _responsible) {
285: this .responsibleConcreteRoleDescriptor = null;
286: _responsible.getConcreteWorkProductDescriptors().remove(this );
287: }
288:
289: /*
290: * Getter and Setter
291: *
292: */
293:
294: /**
295: * Returns the ConcreteRoleDescriptor assigned to the
296: * ConcreteWorkProductDescriptor
297: *
298: * @return the responsibleConcreteRoleDescriptor
299: */
300: public ConcreteRoleDescriptor getResponsibleConcreteRoleDescriptor() {
301: return this .responsibleConcreteRoleDescriptor;
302: }
303:
304: /**
305: * Sets the ConcreteRoleDescriptor assigned to the
306: * ConcreteWorkProductDescriptor
307: *
308: * @param _responsibleConcreteRoleDescriptor
309: * the responsibleConcreteRoleDescriptor to set
310: */
311: public void setResponsibleConcreteRoleDescriptor(
312: ConcreteRoleDescriptor _responsibleConcreteRoleDescriptor) {
313: this .responsibleConcreteRoleDescriptor = _responsibleConcreteRoleDescriptor;
314: }
315:
316: /**
317: * Defines whether a ConcreteWorkProductDescriptor is deliverable or not
318: *
319: * @return true if the ConcreteWorkProductDescriptor is deliverable, false
320: * otherwise
321: */
322: public boolean isDeliverable() {
323: return this .isDeliverable;
324: }
325:
326: /**
327: * Sets the deliverable status of the ConcreteWorkProductDescriptor
328: *
329: * @param _isDeliverable
330: * the isDeliverable to set
331: */
332: public void setDeliverable(boolean _isDeliverable) {
333: this .isDeliverable = _isDeliverable;
334: }
335:
336: /**
337: * Adds a relation between the current instance of
338: * ConcreteWorkProductDescriptor and a specified WorkProductDescriptor.
339: *
340: * @param _workProductDescriptor
341: * the WorkProductDescriptor to link
342: */
343: public void addWorkProductDescriptor(
344: WorkProductDescriptor _workProductDescriptor) {
345: this .workProductDescriptor = _workProductDescriptor;
346: _workProductDescriptor.getConcreteWorkProductDescriptors().add(
347: this );
348: }
349:
350: /**
351: * Removes the relation between the current instance of
352: * ConcreteWorkProductDescriptor and a specified WorkProductDescriptor.
353: *
354: * @param _workProductDescriptor
355: * the WorkProductDescriptor to unlink
356: */
357: public void removeWorkProductDescriptor(
358: WorkProductDescriptor _workProductDescriptor) {
359: this .workProductDescriptor = null;
360: _workProductDescriptor.getConcreteWorkProductDescriptors()
361: .remove(this );
362: }
363:
364: /**
365: * Assigns a WorkProductDescriptor to the current instance of
366: * ConcreteWorkProductDescriptor
367: *
368: * @param _workProductDescriptor
369: * the WorkProductDescriptor to assigned
370: */
371: public void setWorkProductDescriptor(
372: WorkProductDescriptor _workProductDescriptor) {
373: this .workProductDescriptor = _workProductDescriptor;
374: }
375:
376: /**
377: * Returns the WorkProductDescriptor of the ConcreteWorkProductDescriptor
378: *
379: * @param _workProductDescriptor
380: * the WorkProductDescriptor to get
381: */
382: public WorkProductDescriptor getWorkProductDescriptor() {
383: return this .workProductDescriptor;
384: }
385:
386: /**
387: * Returns the Participant assigned to the ConcreteWorkProductDescriptor
388: *
389: * @return the participant
390: */
391: public Participant getParticipant() {
392: return participant;
393: }
394:
395: /**
396: * Sets the Participant assigned to the ConcreteWorkProductDescriptor
397: *
398: * @param _participant
399: * the participant to set
400: */
401: public void setParticipant(Participant _participant) {
402: participant = _participant;
403: }
404:
405: /**
406: * Returns the state of the ConcreteWorkProductDescriptor
407: *
408: * @return the String that symbolizes the ConcreteWorkProductDescriptor
409: * state
410: */
411: public String getState() {
412: return state;
413: }
414:
415: /**
416: * Sets the state of the ConcreteWorkProductDescriptor
417: *
418: * @param state
419: * the state to set
420: */
421: public void setState(String state) {
422: this .state = state;
423: }
424:
425: /**
426: * Returns the Collection of ConcreteTaskDescriptor related to the
427: * ConcreteWorkProductDescriptor
428: *
429: * @return the producerConcreteTasks
430: */
431: public Set<ConcreteTaskDescriptor> getProducerConcreteTasks() {
432: return this .producerConcreteTasks;
433: }
434:
435: /**
436: * Sets the Collection of ConcreteTaskDescriptor related to the
437: * ConcreteWorkProductDescriptor with the one in parameter
438: *
439: * @param _producerConcreteTasks
440: * the producerConcreteTasks to set
441: */
442: public void setProducerConcreteTasks(
443: Set<ConcreteTaskDescriptor> _producerConcreteTasks) {
444: this .producerConcreteTasks = _producerConcreteTasks;
445: }
446:
447: /**
448: * Returns the Collection of optional ConcreteTaskDescriptor related to the
449: * ConcreteWorkProductDescriptor
450: *
451: * @return the optionalUserConcreteTasks
452: */
453: public Set<ConcreteTaskDescriptor> getOptionalUserConcreteTasks() {
454: return this .optionalUserConcreteTasks;
455: }
456:
457: /**
458: * Sets the Collection of optional ConcreteTaskDescriptor related to the
459: * ConcreteWorkProductDescriptor with the one in parameter
460: *
461: * @param _optionalUserConcreteTasks
462: * the optionalUserConcreteTasks to set
463: */
464: public void setOptionalUserConcreteTasks(
465: Set<ConcreteTaskDescriptor> _optionalUserConcreteTasks) {
466: this .optionalUserConcreteTasks = _optionalUserConcreteTasks;
467: }
468:
469: /**
470: * Returns the Collection of mandatory user ConcreteTaskDescriptor related
471: * to the ConcreteWorkProductDescriptor
472: *
473: * @return the mandatoryUserConcreteTasks
474: */
475: public Set<ConcreteTaskDescriptor> getMandatoryUserConcreteTasks() {
476: return this .mandatoryUserConcreteTasks;
477: }
478:
479: /**
480: * Sets the Collection of mandatory user ConcreteTaskDescriptor related to
481: * the ConcreteWorkProductDescriptor with the one in parameter
482: *
483: * @param _mandatoryUserConcreteTasks
484: * the mandatoryUserConcreteTasks to set
485: */
486: public void setMandatoryUserConcreteTasks(
487: Set<ConcreteTaskDescriptor> _mandatoryUserConcreteTasks) {
488: this .mandatoryUserConcreteTasks = _mandatoryUserConcreteTasks;
489: }
490:
491: /**
492: * Adds a relation between the current instance of
493: * ConcreteWorkProductDescriptor, the specified Project and all the
494: * specified producer TaskDescriptor.
495: *
496: * @param _producerTasks
497: * the Collection of producer TaskDescriptor
498: * @param _project
499: * the Project related to the ConcreteWorkProductDescriptor
500: */
501: public void addAllProducerConcreteTasks(
502: Set<TaskDescriptor> _producerTasks, Project _project) {
503: for (TaskDescriptor td : _producerTasks) {
504: for (ConcreteTaskDescriptor ctd : td
505: .getConcreteTaskDescriptors()) {
506: if (ctd.getProject().getId().equals(_project.getId())) {
507: this .producerConcreteTasks.add(ctd);
508: ctd.addOutputConcreteWorkProduct(this );
509: }
510: }
511: }
512: }
513:
514: /**
515: * Adds a relation between the current instance of
516: * ConcreteWorkProductDescriptor, the specified Project and all the
517: * specified optional TaskDescriptor.
518: *
519: * @param _optionalUserTasks
520: * the Collection of optional TaskDescriptor
521: * @param _project
522: * the Project related to the ConcreteWorkProductDescriptor
523: */
524: public void addAllOptionalUserConcreteTasks(
525: Set<TaskDescriptor> _optionalUserTasks, Project _project) {
526: for (TaskDescriptor td : _optionalUserTasks) {
527: for (ConcreteTaskDescriptor ctd : td
528: .getConcreteTaskDescriptors()) {
529: if (ctd.getProject().getId().equals(_project.getId())) {
530: this .optionalUserConcreteTasks.add(ctd);
531: ctd.addOptionalInputConcreteWorkProduct(this );
532: }
533: }
534: }
535: }
536:
537: /**
538: * Adds a relation between the current instance of
539: * ConcreteWorkProductDescriptor, the specified Project and all the
540: * specified mandatory user TaskDescriptor.
541: *
542: * @param _optionalUserTasks
543: * the Collection of mandatory user TaskDescriptor
544: * @param _project
545: * the Project related to the ConcreteWorkProductDescriptor
546: */
547: public void addAllMandatoryUserConcreteTasks(
548: Set<TaskDescriptor> _mandatoryUserTasks, Project _project) {
549: for (TaskDescriptor td : _mandatoryUserTasks) {
550: for (ConcreteTaskDescriptor ctd : td
551: .getConcreteTaskDescriptors()) {
552: if (ctd.getProject().getId().equals(_project.getId())) {
553: this .mandatoryUserConcreteTasks.add(ctd);
554: ctd.addMandatoryInputConcreteWorkProduct(this );
555: }
556: }
557: }
558: }
559:
560: /**
561: * remove all producer/output links between the task and the workproduct
562: *
563: */
564: public void removeAllProducerConcreteTasks() {
565: for (ConcreteTaskDescriptor ctd : this .producerConcreteTasks) {
566: ctd.removeOutputConcreteWorkProduct(this );
567: }
568: this .producerConcreteTasks.clear();
569: }
570:
571: /**
572: * remove all optionaluser/optionalinput links between the task and the
573: * workproduct
574: *
575: */
576: public void removeAllOptionalUserConcreteTasks() {
577: for (ConcreteTaskDescriptor ctd : this .optionalUserConcreteTasks) {
578: ctd.removeOptionalInputConcreteWorkProduct(this );
579: }
580: this .optionalUserConcreteTasks.clear();
581: }
582:
583: /**
584: * remove all mandatoryuser/mandatoryinput links between the task and the
585: * workproduct
586: *
587: */
588: public void removeAllMandatoryUserConcreteTasks() {
589: for (ConcreteTaskDescriptor ctd : this.mandatoryUserConcreteTasks) {
590: ctd.removeMandatoryInputConcreteWorkProduct(this);
591: }
592: this.mandatoryUserConcreteTasks.clear();
593: }
594: }
|