Package com.projity.pm.resource

Examples of com.projity.pm.resource.ResourceImpl


        });

      if (resources!=null)
        for (Iterator i=resources.iterator();i.hasNext();){
          ResourceData resourceData=(ResourceData)i.next();
          ResourceImpl resource=deserializeResourceAndAddToPool(resourceData,resourcePool,reindex,enterpriseResources);
          Resource origImpl =  _localResourceMap.get(resourceData.getUniqueId());
          //old code below
          //resourceNodeMap.put(resourceData.getEnterpriseResource(),NodeFactory.getInstance().createNode(resource));
          //replaced with change for DEF165936
          resourceNodeMap.put(resourceData.getEnterpriseResource(),NodeFactory.getInstance().createNode(origImpl));
        }
      project.setResourcePool(resourcePool);

      //resource outline
      /* version with outline on project resource
       * if (resources!=null){
            for (Iterator i=resources.iterator();i.hasNext();){
                ResourceData resourceData=(ResourceData)i.next();
                ResourceData parentData=(ResourceData)resourceData.getParentResource();
                Node node=(Node)resourceNodeMap.get(resourceData.getEnterpriseResource());
                Node parentNode=(parentData==null)?
                    null:
                    ((Node)resourceNodeMap.get(parentData.getEnterpriseResource()));
                project.getResourcePool().addToDefaultOutline(parentNode,node,(int)resourceData.getChildPosition());
            }
        }*/
      if (resources!=null){

        for (Iterator i=resources.iterator();i.hasNext();){
          ResourceData resourceData=(ResourceData)i.next();
          EnterpriseResourceData enterpriseResourceData=resourceData.getEnterpriseResource();
          EnterpriseResourceData parentData=enterpriseResourceData.getParentResource();
          Node node=(Node)resourceNodeMap.get(enterpriseResourceData);
          Node parentNode=(parentData==null)?
              null:
                ((Node)resourceNodeMap.get(parentData));
          project.getResourcePool().addToDefaultOutline(parentNode,node,(int)enterpriseResourceData.getChildPosition(),false);
          ((ResourceImpl)node.getImpl()).getGlobalResource().setResourcePool(project.getResourcePool());
        }
        project.getResourcePool().getResourceOutline().getHierarchy().cleanVoidChildren();

        //renumber resources
        project.getResourcePool().getResourceOutline().getHierarchy().visitAll(new Closure(){
          int id=1;
          public void execute(Object o) {
            Node node=(Node)o;
            if (node.getImpl() instanceof HasId){
              HasId impl=(HasId)node.getImpl();
              if (impl.getId()>0) impl.setId(id++); //if id=0 means id not used
            }
          }

        });
      }

      if (loadResources!=null){
        loadResources.execute(project);
        resourceNodeMap.clear();
        project.getResourcePool().getResourceOutline().getHierarchy().visitAll(new Closure(){
          public void execute(Object o) {
            Node node=(Node)o;
            HasKey k=(HasKey)node.getImpl();
            resourceNodeMap.put(k.getUniqueId(), node);
          }

        });
      }


      //tasks
      Collection tasks=projectData.getTasks();
      Map taskNodeMap=new HashMap();
      long projectId = project.getUniqueId();
      NormalTask task;

      if (tasks!=null){
        //order by position parents don't matter
        Collections.sort((List<TaskData>)tasks,new Comparator<TaskData>(){
          public int compare(TaskData task1, TaskData task2) {
            if (!task1.isExternal() && task2.isExternal()) return -1; //keep external tasks at the end
            else if (task1.isExternal() && !task2.isExternal()) return 1;
            else if (task1.getChildPosition()>task2.getChildPosition()) return 1;
            else return -1;
          }
        });

        //Set<Long> initialTaskIds=new HashSet<Long>();
        //project.setInitialTaskIds(initialTaskIds);
        for (Iterator i=tasks.iterator();i.hasNext();){
          task = null;
          TaskData taskData=(TaskData)i.next();
//        initialTaskIds.add(taskData.getUniqueId());
          if (taskData.isDirty()) fixCorruption=true; //recovers errors
//          if (Environment.isAddSummaryTask()&&taskData.getUniqueId()==Task.SUMMARY_UNIQUE_ID&&taskData.getSerialized()==null){ //claur
//          System.out.println("Fixing null binary summary task");
//          task = new NormalTask(project);
//          task.setName(taskData.getName());
//          task.setUniqueId(taskData.getUniqueId());
//          }else
          if (taskData.getSerialized()==null) {
            if (taskData.isTimesheetCreated()) {
              task = new NormalTask(project);
              task.setName(taskData.getName());
              System.out.println("made new task in serializer " + task + " parent " + taskData.getParentTask().getName());
            } else {
              continue; // void node
            }
          } else {
            try {
              task = (NormalTask)deserialize(taskData,reindex);
            } catch (Exception e) {
              if (taskData.isSubproject()){ //For migration
                try {
                  task = (NormalTask) Class.forName(Messages.getMetaString("Subproject")).getConstructor(new Class[]{Project.class,Long.class}).newInstance(project,taskData.getSubprojectId());
                } catch (Exception e1) {
                  e1.printStackTrace();
                }

//              task=new Subproject(project,taskData.getSubprojectId());
                task.setUniqueId(taskData.getUniqueId());
                task.setName(taskData.getName());
                ((SubProj)task).setSubprojectFieldValues(taskData.getSubprojectFieldValues());
              }
              else{
                e.printStackTrace();
                throw new IOException("Subproject:"+e);
              }
            }
          }
          taskNodeMap.put(taskData,NodeFactory.getInstance().createNode(task));
          task.setProject(project);
          project.initializeId(task);
          project.add(task);
          if (taskData.isExternal()) {
            task.setExternal(true);
            task.setProjectId(taskData.getProjectId());
            task.setAllSchedulesToCurrentDates();
            project.addExternalTask(task);
          } else {
            task.setOwningProject(project);
            task.setProjectId(projectId);
          }
          if (taskData.isSubproject()) {
            SubProj sub = (SubProj)task;
            sub.setSubprojectUniqueId(taskData.getSubprojectId());
            sub.setSubprojectFieldValues(taskData.getSubprojectFieldValues());
            sub.setSchedulesFromSubprojectFieldValues();
          }
//          if (task.isRoot()){ //claur
//            project.setSummaryTaskEnabled(true);
//          }

          WorkingCalendar cal=(WorkingCalendar) task.getWorkCalendar();
          if (cal!=null){ // use global one
            WorkingCalendar newCal = (WorkingCalendar) CalendarService.findBaseCalendar(cal.getName());
            if (newCal != null && newCal != cal)
              task.setWorkCalendar(newCal);
          }

          //project.addToDefaultOutline(null,);


          //assignments
          List assignments=new ArrayList();
//          if (Environment.isNoPodServer()&&task.getPersistedAssignments()!=null){ //claur
//            assignments.addAll(task.getPersistedAssignments());
//          }
          if (taskData.getAssignments()!=null) assignments.addAll(taskData.getAssignments());

          if (assignments.size()>0)
        for (Iterator j=assignments.iterator();j.hasNext();){
          Object obj=j.next();
          AssignmentData assignmentData=null;
//          if (loadResources!=null&&obj instanceof PersistedAssignment){ //claur
//          }else{
            assignmentData=(AssignmentData)obj;
            if (assignmentData.getSerialized() == null) { // timesheet created
                System.out.println("==== no cached start found " + task.getName());
                if (assignments.size()==1)
                  assignmentData.setResourceId(-1L);
                else j.remove();
            }
//          }
        }

          if (assignments.size()>0)
            for (Iterator j=assignments.iterator();j.hasNext();){
              Object obj=j.next();
              AssignmentData assignmentData=null;
              Assignment assignment=null;
              Resource resource;
              boolean assigned=true;
              int s;
//              if (loadResources!=null&&obj instanceof PersistedAssignment){ //claur
//                PersistedAssignment pa=(PersistedAssignment)obj;
//                assignment=pa.getAssignment();
//                s=pa.getSnapshot();
//
//                 long resId=pa.getResourceId();
//              Node node=(Node)resourceNodeMap.get(resId);
//              resource=node==null?ResourceImpl.getUnassignedInstance():(Resource)node.getImpl();
//
//              if (resource==null) assigned=false;
//              }else{
                assignmentData=(AssignmentData)obj;
                if (loadResources==null){
                  EnterpriseResourceData r=assignmentData.getResource();
                  if (r==null) assigned=false;
                  resource=(r==null)?ResourceImpl.getUnassignedInstance():(Resource)((Node)resourceNodeMap.get(r)).getImpl();
                }else{
                  long resId=assignmentData.getResourceId();
                  Node node=(Node)resourceNodeMap.get(resId);
                  resource=node==null?ResourceImpl.getUnassignedInstance():(Resource)node.getImpl();
                }
                if (assignmentData.getSerialized() != null){
                  try {
                    assignment=(Assignment)deserialize(assignmentData,reindex);
                  } catch (Exception e) {
                    e.printStackTrace();
                  }
                }
                if (assignmentData.getSerialized() == null||(assignmentData.getSerialized() != null&&assignment==null)) { // timesheet created
                  assignment = Assignment.getInstance(task,resource,  1.0, 0);
                  if (assignment.getCachedStart() == null) { //doesn't occur filtered above
                    System.out.println("==== no cached start found " + task.getName());

                  } else {
                    task.setActualStart(assignment.getCachedStart().getTime());
                    task.setActualFinish(assignment.getCachedEnd().getTime());
                  }
                }
                assignment.setCachedStart(assignmentData.getCachedStart());
                assignment.setCachedEnd(assignmentData.getCachedEnd());
                assignment.setTimesheetStatus(assignmentData.getTimesheetStatus());
                long lastUpdate = (assignmentData.getLastTimesheetUpdate() == null) ? 0 : assignmentData.getLastTimesheetUpdate().getTime();
                assignment.setLastTimesheetUpdate(lastUpdate);
                assignment.setWorkflowState(assignmentData.getWorkflowState());
                s=assignmentData.getSnapshotId();
//              }

              assignment.getDetail().setTask(task);
              assignment.getDetail().setResource(resource);
              Object snapshotId=new Integer(s);
              TaskSnapshot snapshot=(TaskSnapshot)task.getSnapshot(snapshotId);

              //TODO was commented but needed for loading  because task.getSnapshot(snapshotId)==null
              //for snapshots other than CURRENT
              if (snapshot==null){
                snapshot=new TaskSnapshot();
                snapshot.setCurrentSchedule(task.getCurrentSchedule());
                task.setSnapshot(snapshotId,snapshot);
              }
              if (Snapshottable.TIMESHEET.equals(snapshotId)) {
                assignment.setTimesheetAssignment(true);
              }
              //

              snapshot.addAssignment(assignment);

              if (assigned&&Snapshottable.CURRENT.equals(snapshotId)) resource.addAssignment(assignment);

              if (assignmentData!=null) assignmentData.emtpy();
              //incremental.addAssignment(assignmentData);
            }
//          task.setPersistedAssignments(null);
View Full Code Here


//    }
//
    public static ResourceImpl deserializeResourceAndAddToPool(EnterpriseResourceData enterpriseResourceData,ResourcePool resourcePool,Session reindex) throws IOException, ClassNotFoundException{
      ResourceData resourceData=new ResourceData();
      resourceData.setEnterpriseResource(enterpriseResourceData);
      ResourceImpl resource=deserializeResourceAndAddToPool(resourceData,resourcePool,reindex,null);
        setRoles(resource, resourceData);
        return resource;

    }
View Full Code Here

          enterpriseResource =(EnterpriseResource)deserialize(e,reindex);
          enterpriseResource.setUserAccount(e.getUserAccount());
        }
        enterpriseResource.setGlobalWorkVector(enterpriseResourceData.getGlobalWorkVector());
        enterpriseResource.setMaster(resourcePool.isMaster());
        ResourceImpl resource=(resourceData.getSerialized()==null)?
                createResourceFromEnterpriseResource(enterpriseResource):
                (ResourceImpl)deserialize(resourceData,reindex);

        resource.setGlobalResource(enterpriseResource);
        setRoles(resource, resourceData);


        // to ensure older projects import correctly
        WorkingCalendar cal = (WorkingCalendar) enterpriseResource.getWorkCalendar();
View Full Code Here

        }

    }

    private static ResourceImpl createResourceFromEnterpriseResource(EnterpriseResource enterpriseResource){
        ResourceImpl resource=new ResourceImpl();
        return resource;
    }
View Full Code Here

    public static void setEnterpriseResources(Collection resources,ResourcePool resourcePool,Session reindex) throws IOException, ClassNotFoundException{
        if (resources!=null){
          Map resourceNodeMap=new HashMap();
            for (Iterator i=resources.iterator();i.hasNext();){
                EnterpriseResourceData resourceData=(EnterpriseResourceData)i.next();
                ResourceImpl resource=deserializeResourceAndAddToPool(resourceData,resourcePool,reindex);
                //resourceNodeMap.put(resourceData,resource.getGlobalResource()); //TODO Lolo - why is this line here given the line below?
                resourceNodeMap.put(resourceData,NodeFactory.getInstance().createNode(resource));
            }
            //NodeModel model=resourcePool.getResourceOutline();
            for (Iterator i=resources.iterator();i.hasNext();){
View Full Code Here

    availabilitySpreadsheet.setSpreadSheetCategory("availabilitySpreadsheet"); //$NON-NLS-1$
      availabilitySpreadsheet.setCanSelectFieldArray(false);
      //availabilitySpreadsheet.setActions(new String[]{SpreadSheet.DELETE});

//      availabilitySpreadsheet.setHasRowPopup(false);
      ResourceImpl resourceImpl=(ResourceImpl)object;
      SpreadSheetUtils.createCollectionSpreadSheet(availabilitySpreadsheet
        ,(object==null)?new LinkedList():resourceImpl.getAvailabilityTable().getList()
        //,(object==null)?null:((Resource)object).getDocument()
        ,"View.ResourceInformation.Availability" //$NON-NLS-1$
        ,"availabilitySpreadsheet" //$NON-NLS-1$
        ,"Spreadsheet.availability" //$NON-NLS-1$
        ,false
View Full Code Here

      SpreadSheetUtils.updateCollectionSpreadSheet(availabilitySpreadsheet
        ,(object==null)?new LinkedList():((ResourceImpl)object).getAvailabilityTable().getList()
        ,(object==null)?null:((ResourceImpl)object).getAvailabilityTable(),
        1);
      if (object!=null){
        ResourceImpl resourceImpl=(ResourceImpl)object;
        NodeModel model=((SpreadSheetModel)availabilitySpreadsheet.getModel()).getCache().getModel();
//        availabilitySpreadsheet.clearActions();
        availabilitySpreadsheet.setReadOnly(resourceImpl.isReadOnly());
        availabilitySpreadsheet.setEnabled(!resourceImpl.isReadOnly());

        model.setMaster(resourceImpl.getGlobalResource().isMaster());
        model.setLocal(resourceImpl.getGlobalResource().isLocal());
        //TODO instead of doing this availabilityTable and Availability can contain a read-only field
      }
     
    }
View Full Code Here

      return ss;

    }
 
    protected void createCostTableSpreadsheets() {
      ResourceImpl resourceImpl=(ResourceImpl)object;
      for (int i = 0; i < Settings.NUM_COST_RATES; i++) {
          SpreadSheetUtils.createCollectionSpreadSheet(costTableSpreadsheets[i]
          ,(object==null)?new LinkedList():resourceImpl.getCostRateTable(i).getList()
          //,(object==null)?null:((Resource)object).getDocument()
          ,"View.ResourceInformation.CostRate" //$NON-NLS-1$
          ,"costRates" //$NON-NLS-1$
          ,"Spreadsheet.costRates" //$NON-NLS-1$
          ,false
View Full Code Here

          SpreadSheetUtils.updateCollectionSpreadSheet(costTableSpreadsheets[i]
          ,(object==null)?new LinkedList():((Resource)object).getCostRateTable(i).getList()
          ,(object==null)?null:((Resource)object).getCostRateTable(i)
          , 1);
          if (object!=null){
            ResourceImpl resourceImpl=(ResourceImpl)object;
            NodeModel model=((SpreadSheetModel)costTableSpreadsheets[i].getModel()).getCache().getModel();
//            costTableSpreadsheets[i].clearActions();
            costTableSpreadsheets[i].setReadOnly(resourceImpl.isReadOnly());
            costTableSpreadsheets[i].setEnabled(!resourceImpl.isReadOnly());
            model.setMaster(resourceImpl.getGlobalResource().isMaster());
            model.setLocal(resourceImpl.getGlobalResource().isLocal());
            //TODO instead of doing this availabilityTable and Availability can contain a read-only field
          }
       }
    }
View Full Code Here

    ResourcePool resourcePool = project.getResourcePool();
    project.setLocal(true);
    resourcePool.setLocal(true);
    resourcePool.setMaster(false);
        resourcePool.updateOutlineTypes();
    ResourceImpl openprojResource;
    OpenprojResourceConverter converter=new OpenprojResourceConverter();
    for (com.projectlibre.pm.resources.Resource plResource : plProject.getResourcePool().getResources()){
      openprojResource = resourcePool.newResourceInstance();
      converter.to(openprojResource,plResource,state);
      state.mapOpenprojResource(plResource, openprojResource);
View Full Code Here

TOP

Related Classes of com.projity.pm.resource.ResourceImpl

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.