Package net.sf.mpxj

Examples of net.sf.mpxj.ResourceAssignment


            if (task != null && resource != null)
            {
               Duration work = task.getWork();
               int percentComplete = NumberUtility.getInt(task.getPercentageComplete());

               ResourceAssignment assignment = task.addResourceAssignment(resource);
               assignment.setUnits(units);
               assignment.setWork(work);

               if (percentComplete != 0)
               {
                  Duration actualWork = Duration.getInstance((work.getDuration() * percentComplete) / 100, work.getUnits());
                  assignment.setActualWork(actualWork);
                  assignment.setRemainingWork(Duration.getInstance(work.getDuration() - actualWork.getDuration(), work.getUnits()));
               }
               else
               {
                  assignment.setRemainingWork(work);
               }

               assignment.setStart(task.getStart());
               assignment.setFinish(task.getFinish());

               tasksWithAssignments.add(task);

               m_projectFile.fireAssignmentReadEvent(assignment);
            }
         }

         //
         // Adjust work per assignment for tasks with multiple assignments
         //
         for (Task task : tasksWithAssignments)
         {
            List<ResourceAssignment> assignments = task.getResourceAssignments();
            if (assignments.size() > 1)
            {
               double maxUnits = 0;
               for (ResourceAssignment assignment : assignments)
               {
                  maxUnits += assignment.getUnits().doubleValue();
               }

               for (ResourceAssignment assignment : assignments)
               {
                  Duration work = assignment.getWork();
                  double factor = assignment.getUnits().doubleValue() / maxUnits;

                  work = Duration.getInstance(work.getDuration() * factor, work.getUnits());
                  assignment.setWork(work);
                  Duration actualWork = assignment.getActualWork();
                  if (actualWork != null)
                  {
                     actualWork = Duration.getInstance(actualWork.getDuration() * factor, actualWork.getUnits());
                     assignment.setActualWork(actualWork);
                  }

                  Duration remainingWork = assignment.getRemainingWork();
                  if (remainingWork != null)
                  {
                     remainingWork = Duration.getInstance(remainingWork.getDuration() * factor, remainingWork.getUnits());
                     assignment.setRemainingWork(remainingWork);
                  }
               }
            }
         }
      }
View Full Code Here


         Task task = m_file.getTaskByUniqueID(Integer.valueOf(MPPUtility.getInt(data, 16)));
         Resource resource = m_file.getResourceByUniqueID(Integer.valueOf(MPPUtility.getInt(data, 20)));
         if (task != null && resource != null)
         {
            ResourceAssignment assignment = task.addResourceAssignment(resource);
            assignment.setActualCost(NumberUtility.getDouble(((double) MPPUtility.getLong6(data, 138)) / 100));
            assignment.setActualWork(MPPUtility.getDuration(((double) MPPUtility.getLong6(data, 96)) / 100, TimeUnit.HOURS));
            assignment.setCost(NumberUtility.getDouble(((double) MPPUtility.getLong6(data, 132)) / 100));
            //assignment.setDelay(); // Not sure what this field maps on to in MSP
            assignment.setFinish(MPPUtility.getTimestamp(data, 28));
            assignment.setOvertimeWork(MPPUtility.getDuration(((double) MPPUtility.getLong6(data, 90)) / 100, TimeUnit.HOURS));
            //assignment.setPlannedCost(); // Not sure what this field maps on to in MSP
            //assignment.setPlannedWork(); // Not sure what this field maps on to in MSP
            assignment.setRemainingWork(MPPUtility.getDuration(((double) MPPUtility.getLong6(data, 114)) / 100, TimeUnit.HOURS));
            assignment.setStart(MPPUtility.getTimestamp(data, 24));
            assignment.setUniqueID(Integer.valueOf(MPPUtility.getInt(data, 0)));
            assignment.setUnits(Double.valueOf(((double) MPPUtility.getShort(data, 80)) / 100));
            assignment.setWork(MPPUtility.getDuration(((double) MPPUtility.getLong6(data, 84)) / 100, TimeUnit.HOURS));

            m_file.fireAssignmentReadEvent(assignment);

            //
            // Uncommenting the call to this method is useful when trying
View Full Code Here

TOP

Related Classes of net.sf.mpxj.ResourceAssignment

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.