コード例 #1
0
  protected void retrieveResourcesForMerge(Project existingProject) throws Exception {
    ResourceMappingForm form = getResourceMapping();
    if (form == null) return;

    Vector projityResources = new Vector();
    // map the existint project resourse impls for later use
    _localResourceMap = new HashMap<Long, com.projity.pm.resource.Resource>();

    EnterpriseResourceData unassigned = new EnterpriseResourceData();
    unassigned.setUniqueId(EnterpriseResource.UNASSIGNED_ID);
    unassigned.setName(Messages.getString("Text.Unassigned")); // $NON-NLS-1$
    form.setUnassignedResource(unassigned);
    projityResources.add(unassigned);

    Serializer serializer = new Serializer();

    ProjectData projectData =
        (ProjectData) serializer.serialize(existingProject, ProjectData.FACTORY, null);
    if (existingProject.isForceNonIncremental()) projectData.setVersion(0);
    projectData.setMaster(existingProject.isMaster());

    // resources
    Map resourceMap = serializer.saveResources(existingProject, projectData);
    List<com.projity.pm.resource.Resource> existingResources =
        (List<com.projity.pm.resource.Resource>)
            existingProject.getResourcePool().getResourceList();
    for (com.projity.pm.resource.Resource resource : existingResources) {
      if (resource == null) continue;
      ResourceData r = (ResourceData) resourceMap.get(resource.getUniqueId());
      if (r != null) {
        EnterpriseResourceData er = r.getEnterpriseResource();
        er.setName(resource.getName());
        projityResources.add(er);
        _localResourceMap.put((Long) r.getUniqueId(), resource);
      }
    }

    form.setResources(projityResources);
  }
コード例 #2
0
  protected boolean importResources() throws Exception {
    ResourceMappingForm form = getResourceMapping();

    if (form != null && !form.isLocal()) {
      //			if (Environment.isNoPodServer()){ //claur
      //				//importLocalResources.execute(null);
      //				Project existingProject=form.getExistingProject();
      //				existingProject.setMaster(true);
      //				retrieveResourcesForMerge(existingProject);
      //			}

      if (!form.execute()) return false;
      if (form.isLocal()) {
        return true;
      }

      List<ResourceData> resources = new ArrayList<ResourceData>();
      Map<Long, ResourceData> resourceMap = new HashMap<Long, ResourceData>();

      Iterator r = form.getResources().iterator();
      while (r.hasNext()) {
        EnterpriseResourceData enterpriseResource = (EnterpriseResourceData) r.next();
        if (enterpriseResource.getUniqueId() != EnterpriseResource.UNASSIGNED_ID) {
          ResourceData resource = new ResourceData();
          resource.setEnterpriseResource(enterpriseResource);
          resourceMap.put(enterpriseResource.getUniqueId(), resource);
          resources.add(resource);
        }
      }
      projectData.setResources(resources);

      Map<Long, ResourceData> idMap = new HashMap<Long, ResourceData>();
      Iterator ir = form.getImportedResources().iterator();
      Iterator sr = form.getSelectedResources().iterator();
      while (ir.hasNext()) {
        EnterpriseResourceData enterpriseSrc = (EnterpriseResourceData) ir.next();
        EnterpriseResourceData enterpriseDest = (EnterpriseResourceData) sr.next();
        if (enterpriseDest.getUniqueId() != EnterpriseResource.UNASSIGNED_ID) {
          ResourceData resource = new ResourceData();
          resource.setEnterpriseResource(enterpriseDest);
          idMap.put(enterpriseSrc.getUniqueId(), resourceMap.get(enterpriseDest.getUniqueId()));
        }
      }

      // remove assignments that have lost resources
      for (TaskData task : (Collection<TaskData>) projectData.getTasks()) {
        if (task.getAssignments() != null)
          for (AssignmentData assignment : (Collection<AssignmentData>) task.getAssignments()) {
            ResourceData resourceData = idMap.get(assignment.getUniqueId());
            if (resourceData == null) {
              // assignment becomes unassigned
              assignment.setResource(null);
              assignment.setResourceId(-1L);
            } else {
              assignment.setResource(resourceData.getEnterpriseResource());
              assignment.setResourceId(resourceData.getEnterpriseResource().getUniqueId());
            }
          }
      }
      // remove distributions that have lost resources
      Collection<DistributionData> dists =
          (Collection<DistributionData>) projectData.getDistributions();
      if (dists != null)
        for (Iterator<DistributionData> i = dists.iterator(); i.hasNext(); ) {
          DistributionData dist = i.next();
          ResourceData resourceData = idMap.get(dist.getResourceId());
          if (resourceData == null) {
            i.remove();
          } else {
            dist.setResourceId(resourceData.getEnterpriseResource().getUniqueId());
          }
        }
    }

    //		if (Environment.isNoPodServer()){ //claur
    //			Project existingProject=form.getExistingProject();
    //			projectData.setUniqueId(existingProject.getUniqueId()); //should be elsewhere, but it's
    // easiest here in the import job
    //		}

    return true;
  }