001: /*
002: The contents of this file are subject to the Common Public Attribution License
003: Version 1.0 (the "License"); you may not use this file except in compliance with
004: the License. You may obtain a copy of the License at
005: http://www.projity.com/license . The License is based on the Mozilla Public
006: License Version 1.1 but Sections 14 and 15 have been added to cover use of
007: software over a computer network and provide for limited attribution for the
008: Original Developer. In addition, Exhibit A has been modified to be consistent
009: with Exhibit B.
010:
011: Software distributed under the License is distributed on an "AS IS" basis,
012: WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the
013: specific language governing rights and limitations under the License. The
014: Original Code is OpenProj. The Original Developer is the Initial Developer and
015: is Projity, Inc. All portions of the code written by Projity are Copyright (c)
016: 2006, 2007. All Rights Reserved. Contributors Projity, Inc.
017:
018: Alternatively, the contents of this file may be used under the terms of the
019: Projity End-User License Agreeement (the Projity License), in which case the
020: provisions of the Projity License are applicable instead of those above. If you
021: wish to allow use of your version of this file only under the terms of the
022: Projity License and not to allow others to use your version of this file under
023: the CPAL, indicate your decision by deleting the provisions above and replace
024: them with the notice and other provisions required by the Projity License. If
025: you do not delete the provisions above, a recipient may use your version of this
026: file under either the CPAL or the Projity License.
027:
028: [NOTE: The text of this license may differ slightly from the text of the notices
029: in Exhibits A and B of the license at http://www.projity.com/license. You should
030: use the latest text at http://www.projity.com/license for your modifications.
031: You may not remove this license text from the source files.]
032:
033: Attribution Information: Attribution Copyright Notice: Copyright © 2006, 2007
034: Projity, Inc. Attribution Phrase (not exceeding 10 words): Powered by OpenProj,
035: an open source solution from Projity. Attribution URL: http://www.projity.com
036: Graphic Image as provided in the Covered Code as file: openproj_logo.png with
037: alternatives listed on http://www.projity.com/logo
038:
039: Display of Attribution Information is required in Larger Works which are defined
040: in the CPAL as a work which combines Covered Code or portions thereof with code
041: not governed by the terms of the CPAL. However, in addition to the other notice
042: obligations, all copies of the Covered Code in Executable and Source Code form
043: distributed must, as a form of attribution of the original author, include on
044: each user interface screen the "OpenProj" logo visible to all users. The
045: OpenProj logo should be located horizontally aligned with the menu bar and left
046: justified on the top left of the screen adjacent to the File menu. The logo
047: must be at least 100 x 25 pixels. When users click on the "OpenProj" logo it
048: must direct them back to http://www.projity.com.
049: */
050: package com.projity.pm.task;
051:
052: import java.io.IOException;
053: import java.io.ObjectInputStream;
054: import java.io.ObjectOutputStream;
055: import java.util.Collection;
056:
057: import org.apache.commons.collections.Closure;
058:
059: import com.projity.algorithm.ReverseQuery;
060: import com.projity.algorithm.TimeIteratorGenerator;
061: import com.projity.algorithm.buffer.CalculatedValues;
062: import com.projity.association.AssociationList;
063: import com.projity.field.FieldContext;
064: import com.projity.pm.assignment.Assignment;
065: import com.projity.pm.assignment.HasAssignments;
066: import com.projity.pm.assignment.HasAssignmentsImpl;
067: import com.projity.pm.calendar.WorkCalendar;
068: import com.projity.pm.costing.Accrual;
069: import com.projity.pm.criticalpath.TaskSchedule;
070: import com.projity.pm.resource.Resource;
071: import com.projity.pm.snapshot.DataSnapshot;
072:
073: /**
074: *
075: */
076: public class TaskSnapshot implements DataSnapshot, HasAssignments,
077: Cloneable {
078: TaskSchedule currentSchedule;
079: HasAssignments hasAssignments = null;
080: double fixedCost = 0;
081: int fixedCostAccrual = Accrual.END;
082: boolean ignoreResourceCalendar = false;
083:
084: public long getEarliestAssignmentStart() {
085: return hasAssignments.getEarliestAssignmentStart();
086: }
087:
088: public boolean hasActiveAssignment(long start, long end) {
089: return hasAssignments.hasActiveAssignment(start, end);
090: }
091:
092: /**
093: * @param modified
094: */
095: public void updateAssignment(Assignment modified) {
096: hasAssignments.updateAssignment(modified);
097: }
098:
099: /**
100: * @return Returns the taskSchedule.
101: */
102: public TaskSchedule getCurrentSchedule() {
103: return currentSchedule;
104: }
105:
106: /**
107: * @param currentSchedule The taskSchedule to set.
108: */
109: public void setCurrentSchedule(TaskSchedule currentSchedule) {
110: this .currentSchedule = currentSchedule;
111: }
112:
113: public HasAssignments getHasAssignments() {
114: if (hasAssignments == null) // lazy instantiation
115: hasAssignments = new HasAssignmentsImpl();
116: return hasAssignments;
117: }
118:
119: /**
120: *
121: */
122: public TaskSnapshot() {
123: }
124:
125: public TaskSnapshot(Collection details) {
126: hasAssignments = new HasAssignmentsImpl(details);
127: }
128:
129: public Object clone() {
130: TaskSnapshot newOne = null;
131: try {
132: newOne = (TaskSnapshot) super .clone();
133: newOne.currentSchedule = (TaskSchedule) currentSchedule
134: .clone();
135: newOne.hasAssignments = (HasAssignments) ((HasAssignmentsImpl) hasAssignments)
136: .cloneWithSchedule(newOne.currentSchedule);
137: } catch (CloneNotSupportedException e) {
138: e.printStackTrace();
139: }
140:
141: return newOne;
142: }
143:
144: public Object deepCloneWithTask(Task task) {
145:
146: TaskSnapshot newOne = null;
147: try {
148: newOne = (TaskSnapshot) super .clone();
149: newOne.currentSchedule = (TaskSchedule) currentSchedule
150: .cloneWithTask(task);
151: newOne.hasAssignments = (HasAssignments) ((HasAssignmentsImpl) hasAssignments)
152: .deepCloneWithTask(task);
153: } catch (CloneNotSupportedException e) {
154: e.printStackTrace();
155: }
156:
157: return newOne;
158: }
159:
160: /**
161: * @param assignment
162: */
163: public void addAssignment(Assignment assignment) {
164: getHasAssignments().addAssignment(assignment);
165: }
166:
167: /**
168: * @param resource
169: * @return
170: */
171: public Assignment findAssignment(Resource resource) {
172: return getHasAssignments().findAssignment(resource);
173: }
174:
175: /**
176: * @param task
177: * @return
178: */
179: public Assignment findAssignment(Task task) {
180: return getHasAssignments().findAssignment(task);
181: }
182:
183: /**
184: * @param assignment
185: */
186: public void removeAssignment(Assignment assignment) {
187: getHasAssignments().removeAssignment(assignment);
188: }
189:
190: /* (non-Javadoc)
191: * @see com.projity.pm.assignment.HasAssignments#getAssignments()
192: */
193: public AssociationList getAssignments() {
194: return getHasAssignments().getAssignments();
195: }
196:
197: /**
198: * @return
199: */
200: public int getSchedulingType() {
201: return getHasAssignments().getSchedulingType();
202: }
203:
204: /**
205: * @param schedulingType
206: */
207: public void setSchedulingType(int schedulingType) {
208: getHasAssignments().setSchedulingType(schedulingType);
209: }
210:
211: /**
212: * @return
213: */
214: public boolean isEffortDriven() {
215: return getHasAssignments().isEffortDriven();
216: }
217:
218: /**
219: * @param effortDriven
220: */
221: public void setEffortDriven(boolean effortDriven) {
222: getHasAssignments().setEffortDriven(effortDriven);
223: }
224:
225: /* (non-Javadoc)
226: * @see com.projity.pm.assignment.HasTimeDistributedData#buildComplexQuery(com.projity.algorithm.ComplexQuery)
227: */
228: public void buildReverseQuery(ReverseQuery reverseQuery) {
229: getHasAssignments().buildReverseQuery(reverseQuery);
230: }
231:
232: /**
233: * @param visitor
234: * @return
235: */
236: public static Closure forAllAssignments(Closure visitor) {
237: return HasAssignmentsImpl.forAllAssignments(visitor);
238: }
239:
240: /**
241: * @param visitor
242: * @param mergeWorking
243: */
244: public void forEachWorkingInterval(Closure visitor,
245: boolean mergeWorking, WorkCalendar workCalendar) {
246: hasAssignments.forEachWorkingInterval(visitor, mergeWorking,
247: workCalendar);
248: }
249:
250: /**
251: * @return
252: */
253: public boolean isReadOnlyEffortDriven(FieldContext fieldContext) {
254: return hasAssignments.isReadOnlyEffortDriven(fieldContext);
255: }
256:
257: /**
258: * @param start
259: * @param end
260: * @return
261: */
262: public double actualCost(long start, long end) {
263: return hasAssignments.actualCost(start, end);
264: }
265:
266: /**
267: * @param start
268: * @param end
269: * @return
270: */
271: public long actualWork(long start, long end) {
272: return hasAssignments.actualWork(start, end);
273: }
274:
275: /**
276: * @param start
277: * @param end
278: * @return
279: */
280: public long remainingWork(long start, long end) {
281: return hasAssignments.remainingWork(start, end);
282: }
283:
284: /**
285: * @param start
286: * @param end
287: * @return
288: */
289: public double acwp(long start, long end) {
290: return hasAssignments.acwp(start, end);
291: }
292:
293: /**
294: * @param start
295: * @param end
296: * @return
297: */
298: public double bac(long start, long end) {
299: return hasAssignments.bac(start, end);
300: }
301:
302: /**
303: * @param start
304: * @param end
305: * @return
306: */
307: public double bcwp(long start, long end) {
308: return hasAssignments.bcwp(start, end);
309: }
310:
311: /**
312: * @param start
313: * @param end
314: * @return
315: */
316: public double bcws(long start, long end) {
317: return hasAssignments.bcws(start, end);
318: }
319:
320: /**
321: * @param start
322: * @param end
323: * @return
324: */
325: public double cost(long start, long end) {
326: return hasAssignments.cost(start, end);
327: }
328:
329: /**
330: * @param start
331: * @param end
332: * @return
333: */
334: public long work(long start, long end) {
335: return hasAssignments.work(start, end);
336: }
337:
338: /**
339: * @param type
340: * @param generator
341: * @param values
342: */
343: public void calcDataBetween(Object type,
344: TimeIteratorGenerator generator, CalculatedValues values) {
345: hasAssignments.calcDataBetween(type, generator, values);
346: }
347:
348: /**
349: * @return
350: */
351: public Collection childrenToRollup() {
352: return hasAssignments.childrenToRollup();
353: }
354:
355: /**
356: * @param start
357: * @param end
358: * @return
359: */
360: public double baselineCost(long start, long end) {
361: return hasAssignments.baselineCost(start, end);
362: }
363:
364: /**
365: * @param start
366: * @param end
367: * @return
368: */
369: public long baselineWork(long start, long end) {
370: return hasAssignments.baselineWork(start, end);
371: }
372:
373: /**
374: * @param workCalendar
375: * @return
376: */
377: public long calcActiveAssignmentDuration(WorkCalendar workCalendar) {
378: return hasAssignments
379: .calcActiveAssignmentDuration(workCalendar);
380: }
381:
382: public double fixedCost(long start, long end) {
383: return 0;
384: }
385:
386: public double actualFixedCost(long start, long end) {
387: return 0;
388: }
389:
390: /**
391: * @return Returns the fixedCost.
392: */
393: public final double getFixedCost() {
394: return fixedCost;
395: }
396:
397: /**
398: * @param fixedCost The fixedCost to set.
399: */
400: public final void setFixedCost(double fixedCost) {
401: this .fixedCost = fixedCost;
402: }
403:
404: /**
405: * @return Returns the fixedCostAccrual.
406: */
407: public final int getFixedCostAccrual() {
408: return fixedCostAccrual;
409: }
410:
411: /**
412: * @param fixedCostAccrual The fixedCostAccrual to set.
413: */
414: public final void setFixedCostAccrual(int fixedCostAccrual) {
415: this .fixedCostAccrual = fixedCostAccrual;
416: }
417:
418: /**
419: * @return Returns the ignoreResourceCalendar.
420: */
421: public final boolean isIgnoreResourceCalendar() {
422: return ignoreResourceCalendar;
423: }
424:
425: /**
426: * @param ignoreResourceCalendar The ignoreResourceCalendar to set.
427: */
428: public final void setIgnoreResourceCalendar(
429: boolean ignoreResourceCalendar) {
430: this .ignoreResourceCalendar = ignoreResourceCalendar;
431: }
432:
433: /* (non-Javadoc)
434: * @see com.projity.pm.assignment.HasTimeDistributedData#isLabor()
435: */
436: public boolean isLabor() {
437: return true;
438: }
439:
440: public boolean hasLaborAssignment() {
441: return hasAssignments.hasLaborAssignment();
442: }
443:
444: public void invalidateAssignmentCalendars() {
445: hasAssignments.invalidateAssignmentCalendars();
446: }
447:
448: public void serialize(ObjectOutputStream s) throws IOException {
449: currentSchedule.serialize(s);
450: //s.writeObject(hasAssignments);
451: s.writeDouble(fixedCost);
452: s.writeInt(fixedCostAccrual);
453: s.writeBoolean(ignoreResourceCalendar);
454: s.writeInt(hasAssignments.getSchedulingType());
455: s.writeBoolean(hasAssignments.isEffortDriven());
456: }
457:
458: //call init to complete initialization
459: public static TaskSnapshot deserialize(ObjectInputStream s,
460: NormalTask hasAssignments) throws IOException,
461: ClassNotFoundException {
462: TaskSnapshot t = new TaskSnapshot();
463: TaskSchedule schedule = TaskSchedule.deserialize(s);
464: schedule.setTask(hasAssignments);
465: t.setCurrentSchedule(schedule);
466: t.hasAssignments = new HasAssignmentsImpl();//(HasAssignments)s.readObject();
467:
468: t.setFixedCost(s.readDouble());
469: t.setFixedCostAccrual(s.readInt());
470: t.setIgnoreResourceCalendar(s.readBoolean());
471:
472: if (hasAssignments.getVersion() >= 2) {
473: t.hasAssignments.setSchedulingType(s.readInt());
474: t.hasAssignments.setEffortDriven(s.readBoolean());
475: }
476: return t;
477: }
478:
479: }
|