Package com.projity.grouping.core

Examples of com.projity.grouping.core.Node


    //Undo
    if (isUndo(actionType)) postEdit(new NodeImplChangeAndValueSetEdit(this,node,previous,previousPosition,oldImpl,field,value,context,eventSource));
    return node;
  }
  public Node replaceImpl(Node node,Object newImpl, Object eventSource,int actionType){
    Node parent = getParent(node);
    Object parentImpl = (parent==getHierarchy().getRoot())?null:parent.getImpl();
    NodeModelDataFactory factory = getFactory(parentImpl);

    factory.addUnvalidatedObject(newImpl,this, parentImpl);
    Object oldImpl=node.getImpl();
    node.setImpl(newImpl);
View Full Code Here


      final Set endVoids=new HashSet();
      //lastIndex=0;
        getHierarchy().visitAll(root, true,new Closure(){
          //int tmpIndex=0;
          public void execute(Object arg){
            Node node=(Node)arg;
            Object nodeImpl=node.getImpl();
            if (!(nodeImpl instanceof Assignment)){
//              if (!node.isVoid()) lastIndex=tmpIndex;
//              tmpIndex++;
              if (node.isVoid()) endVoids.add(node);
              else endVoids.clear();
            }
          }
        });

        getHierarchy().visitAllLevelOrder(root, true,new Closure(){
          Node thisParent=null;
          long position=0;
          //int index=0;
          public void execute(Object arg){
            //if (index++>lastIndex) return;
            Node node=(Node)arg;
            if (endVoids.contains(node)) return;
            Object nodeImpl=node.getImpl();
            if (!(nodeImpl instanceof Assignment)){
              Node currentParent=getHierarchy().getParent(node);
              if (currentParent!=null&&currentParent.isRoot()) currentParent=null; //for compatibility
              if (thisParent!=currentParent){
                thisParent=currentParent;
                position=0;
              }
              if (node.isVoid()||addOutlineElement(nodeImpl,(thisParent==null)?null:thisParent.getImpl(),position))
View Full Code Here

        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);
        }


        // the collection which holds a list of corresponding subproject tasks for projects which include this project
        // note that their task names have been transformed to hold the name of the project
        Collection referringSubprojectTaskData=projectData.getReferringSubprojectTasks();
        if (tasks!=null&&referringSubprojectTaskData!=null){
          ArrayList referringSubprojectTasks = new ArrayList(referringSubprojectTaskData.size());
          project.setReferringSubprojectTasks(referringSubprojectTasks);
          for (Iterator i=referringSubprojectTaskData.iterator();i.hasNext();){
            TaskData taskData=(TaskData)i.next();
            String projectName = taskData.getName(); // it was set to the referrig project name by synchronizer
            task = null;
            try {
              task = (NormalTask)deserialize(taskData,reindex);
            } catch (Exception e) {
              if (taskData.isSubproject()){ //For migration
                task=(NormalTask) project.getSubprojectHandler().createSubProj(taskData.getSubprojectId());
                task.setUniqueId(taskData.getUniqueId());
                task.setName(taskData.getName());
                ((SubProj)task).setSubprojectFieldValues(taskData.getSubprojectFieldValues());
              }
              else throw new IOException("Subproject:"+e);
            }
            task.setName(projectName);
            task.setProjectId(taskData.getProjectId());
            referringSubprojectTasks.add(task);
          }
        }

        //dependencies
        //Set<DependencyKey> initialLinkIds=null;
        for (Iterator i=projectData.getTasks().iterator();i.hasNext();){
          TaskData successorssorData=(TaskData)i.next();
          if (successorssorData.getPredecessors()!=null){
            final Task successor=(Task)((Node)taskNodeMap.get(successorssorData)).getImpl();
            for (Iterator j=successorssorData.getPredecessors().iterator();j.hasNext();){
              LinkData linkData=(LinkData)j.next();
//            if (initialLinkIds==null){
//            initialLinkIds=new HashSet<DependencyKey>();
//            project.setInitialLinkIds(initialLinkIds);
//            }
//            initialLinkIds.add(new DependencyKey(linkData.getPredecessorId(),linkData.getSuccessorId()/*,externalId*/));
              Dependency dependency=(Dependency)deserialize(linkData,reindex);

              if (linkData.getPredecessor() == null) {
                System.out.println("null pred - this shouldn't happen. skipping"); // todo treat it
                continue;
              }
              final Task predecessor=(Task)((Node)taskNodeMap.get(linkData.getPredecessor())).getImpl();
              connectDependency(dependency,predecessor,successor);

              linkData.emtpy(); //why is this there?
            }
          }
        }

      }

      //task outline
      if (tasks!=null){

        //add missing summary task
        Node summaryNode=null;
//        if (Environment.isAddSummaryTask()&&!project.isSummaryTaskEnabled() //needed for import, add other conditions? //claur
//          && (tasks.size()==0||((TaskData)tasks.iterator().next()).getUniqueId()!=Task.SUMMARY_UNIQUE_ID)){
//          NormalTask projityTask = project.newNormalTaskInstance(false);
//          projityTask.setName(Messages.getString("Text.DefaultSummaryTaskName"));
//          projityTask.setUniqueId(DataObject.SUMMARY_UNIQUE_ID);
//          projityTask.setOwningProject(project);
//          projityTask.setProjectId(project.getUniqueId());
//          summaryNode = NodeFactory.getInstance().createNode(projityTask); // get a node for this task
//          project.addToDefaultOutline(null,summaryNode);
//          project.setSummaryTaskEnabled(true);
//        }


        Map<Long, Node> subprojectsMap=new HashMap<Long, Node>();
        for (Iterator i=tasks.iterator();i.hasNext();){
          TaskData taskData=(TaskData)i.next();
          TaskData parentData=taskData.getParentTask();
//        if (taskData.isTimesheetCreated())
//        System.out.println("timesheet created parent is  " + parentData == null ? null : parentData.getName());
          Node node;
          if (taskData.getSerialized()==null /*&& taskData.getUniqueId()!=Task.SUMMARY_UNIQUE_ID*/ &&!taskData.isTimesheetCreated()) //void node //claur
            node=NodeFactory.getInstance().createVoidNode();
          else node=(Node)taskNodeMap.get(taskData);
          Node parentNode=null;
          int position=-1;
          if (taskData.isExternal()){
            Node previous=subprojectsMap.get(taskData.getProjectId());
            if (previous!=null) parentNode=(Node)previous.getParent();
            if (parentNode!=null){
              position=parentNode.getIndex(previous)+1;
              if (parentNode.isRoot()) parentNode=null;
            }
          }
          if (position==-1){
            if (parentData==null&&summaryNode!=null)
              parentNode=summaryNode;
            else
              parentNode=(parentData==null)?
                null:
                  ((Node)taskNodeMap.get(parentData));
            position=(int)taskData.getChildPosition();
          }
          if (taskData.isTimesheetCreated())
            System.out.println("new task " + node + "parent node is " + parentNode);
          if (node.getImpl() instanceof SubProj){
            SubProj sub=(SubProj)node.getImpl();
            subprojectsMap.put(sub.getSubprojectUniqueId(), node);
          }

          project.addToDefaultOutline(parentNode,node,position,false);

          taskData.emtpy();
          //incremental.addTask(taskData);

        }
        //renumber tasks and save outline
        project.getTaskOutline().getHierarchy().visitAll(new Closure(){
          int id=1;
          public void execute(Object o) {
            Node node=(Node)o;
            if (node.getImpl() instanceof HasId){ //renumber
              HasId impl=(HasId)node.getImpl();
              if (impl.getId()>0) impl.setId(id++); //if id=0 means id not used
            }
//          if (node.getImpl() instanceof Task){ //save outline
//          Task t=(Task)node.getImpl();
//          Node parent=(Node)node.getParent();
View Full Code Here

            }
            //NodeModel model=resourcePool.getResourceOutline();
            for (Iterator i=resources.iterator();i.hasNext();){
                EnterpriseResourceData resourceData=(EnterpriseResourceData)i.next();
                EnterpriseResourceData parentData=resourceData.getParentResource();
                Node node=(Node)resourceNodeMap.get(resourceData);
                Node parentNode=(parentData==null)?
                    null:
                    ((Node)resourceNodeMap.get(parentData));
                //model.add(parentNode,node,(int)resourceData.getChildPosition(),NodeModel.SILENT); //global update instead
                resourcePool.addToDefaultOutline(parentNode,node,(int)resourceData.getChildPosition(),false);
                ((ResourceImpl)node.getImpl()).getGlobalResource().setResourcePool(resourcePool);
View Full Code Here

  public static final Resource findResource(String name) {
    return findResourceByName(name, globalPool);
  }
  public List getChildrenResoures(Resource parent) {
    NodeModel resourceModel = getResourceOutline();
    Node node = resourceModel.search(parent);
    return NodeList.nodeListToImplList(resourceModel.getChildren(node));
  }
View Full Code Here

    Node node = resourceModel.search(parent);
    return NodeList.nodeListToImplList(resourceModel.getChildren(node));
  }
  public Resource getRbsParentResource(Resource child) {
    NodeModel resourceModel = getResourceOutline();
    Node node = resourceModel.search(child);
    Node parent = resourceModel.getParent(node);
    if (parent == null || parent.isVoid())
      return null;
    return (Resource)parent.getImpl();
  }
View Full Code Here

    if (parent == null || parent.isVoid())
      return null;
    return (Resource)parent.getImpl();
  }
  public void setLocalParent(Resource child, Resource parent) {
    Node childNode = getResourceOutline().search(child);
    Node parentNode = parent == null ? null : getResourceOutline().search(parent);
    setLocalParent(childNode,parentNode);
  }
View Full Code Here

  public void setLocalParent(Node childNode, Node parentNode) {
    Resource child = (Resource) childNode.getImpl();
    Resource parent = (Resource) (parentNode == null ? null : parentNode.getImpl());
    if (getRbsParentResource(child) == parent)
      return;
    Node oldParentNode = getResourceOutline().search(getRbsParentResource(child));
    if (oldParentNode != null)
      oldParentNode.getChildren().remove(childNode);
    ArrayList temp = new ArrayList();
    temp.add(childNode);
    getResourceOutline().move(parentNode, temp, -1,NodeModel.NORMAL);
  }
View Full Code Here

    Object oldValue = getValueAt(row, col);
    // if (oldValue==null&&(value==null||"".equals(value))) return;
    if (oldValue == null && ("".equals(value)))
      return;

    Node rowNode = getNodeInRow(row);
    //Field field = getFieldInColumn(col);

    try {
      if (rowNode.isVoid()) {
        if (value == null) { // null means parse error, so generate error here
          getCache().getModel().setFieldValue(field, rowNode, this, value, fieldContext, NodeModel.NORMAL);
        } else{
          //boolean previousIsParent=false;
          LinkedList previousNodes=getPreviousVisibleNodesFromRow(row);
          if (previousNodes!=null){
            Node nextSibling=getNextNonVoidSiblingFromRow(row);
            if(nextSibling!=null&&nextSibling.getParent()==previousNodes.getFirst()) previousNodes=null;
          }
          getCache().getModel()
              .replaceImplAndSetFieldValue(rowNode, previousNodes, getFieldInColumn(col), this, value, fieldContext, NodeModel.NORMAL);
     
        }
View Full Code Here

  public boolean isRowEditable(int row) {
    if (isReadOnly()) return false;
    NodeModel nodeModel=getCache().getModel();
    //if (!nodeModel.isLocal()&&!nodeModel.isMaster()&&!Environment.getStandAlone()) return false;
    Node node = getNodeInRow(row);
    if (node.isVoid())
      return true;
    return !ClassUtils.isObjectReadOnly(node.getImpl());
  }
View Full Code Here

TOP

Related Classes of com.projity.grouping.core.Node

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.