/**
  * DOC gwu Comment method "findByAuthor".
  *
  * @param author
  * @param transaction
  * @return List<Project>
  * @throws DBException
  */
 public List<Project> findByAuthor(User author, ITransactionHolder transaction)
     throws DBException {
   Project project = AdminFactory.eINSTANCE.createProject();
   project.setAuthor(author);
   return PersistenceUtil.getPersistenceAdapter()
       .retrieve(
           transaction,
           project,
           HibernatePersistenceAdapter.createCriterions(project, new String[] {"author"}),
           dependentObjects);
 }
 /**
  * findByName.
  *
  * @param name the name of the project to find
  * @param ITransactionHolder
  * @return the found project
  * @throws BusinessException
  * @throws DBException
  */
 public Project findByName(ITransactionHolder transactionHolder, String name)
     throws BusinessException, DBException {
   Project project = AdminFactory.eINSTANCE.createProject();
   project.setLabel(name);
   if (transactionHolder == null)
     return PersistenceUtil.getPersistenceAdapter()
         .retrieveUnique(project, new String[] {"label"}, getDependentObjectsWithFolders());
   else
     return PersistenceUtil.getPersistenceAdapter()
         .retrieveUnique(
             transactionHolder, project, new String[] {"label"}, getDependentObjectsWithFolders());
 }
  private List<Project> listProjects(
      boolean loadActiveProjectsOnly,
      boolean loadFolders,
      User sessionUser,
      ITransactionHolder transactionHolder)
      throws DBException {
    Project project = AdminFactory.eINSTANCE.createProject();
    List<String> matches = new ArrayList<String>();
    Criterion[] criterions = null;
    if (loadActiveProjectsOnly) {
      project.setDeleted(false);
      matches.add("deleted");
    }
    if (matches != null) {
      criterions =
          HibernatePersistenceAdapter.createCriterions(project, matches.toArray(new String[] {}));
    }

    String[] projectDependantObjects;
    if (loadFolders) {
      projectDependantObjects = getDependentObjectsWithFolders();
    } else {
      projectDependantObjects = dependentObjects;
    }
    List<Project> retrieve = null;

    if (transactionHolder == null) {
      retrieve =
          PersistenceUtil.getPersistenceAdapter()
              .retrieve(project, criterions, projectDependantObjects);
    } else {
      retrieve =
          PersistenceUtil.getPersistenceAdapter()
              .retrieve(transactionHolder, project, criterions, projectDependantObjects);
    }

    ProjectFilter<Project> projectFilter = new EmfProjectFilter(sessionUser);
    retrieve = projectFilter.filter(retrieve);
    return retrieve;
  }
  /**
   * DOC kpchen Comment method "listReferenceProjects".
   *
   * @param sessionUser
   * @return List<Project>
   * @throws DBException
   */
  public List<Project> listReferenceProjects(User sessionUser) throws DBException {
    Project project = AdminFactory.eINSTANCE.createProject();
    List<String> matches = new ArrayList<String>();
    Criterion[] criterions = null;

    project.setReference(true);
    matches.add("reference");

    if (matches != null) {
      criterions =
          HibernatePersistenceAdapter.createCriterions(project, matches.toArray(new String[] {}));
    }

    String[] projectDependantObjects = dependentObjects;

    List<Project> toReturn =
        PersistenceUtil.getPersistenceAdapter()
            .retrieve(project, criterions, projectDependantObjects);
    ProjectFilter<Project> projectFilter = new EmfProjectFilter(sessionUser);
    toReturn = projectFilter.filter(toReturn);
    return toReturn;
  }
  private String constructProjectsObjectsXmi() throws Exception {
    User user = AdminFactory.eINSTANCE.createUser();
    user.setLogin("*****@*****.**");

    List<EObject> objects = new ArrayList<EObject>();
    objects.add(user);
    final String BRANCHES = "branches";

    final String TRUNK = "trunk";
    List<Project> projectsList = new ArrayList<Project>();

    Project projectRef1 = AdminFactory.eINSTANCE.createProject();
    projectRef1.setId(1);
    projectRef1.setLabel("projectRef1 id=" + projectRef1.getId());
    projectRef1.setCreationDate(new Date());
    projectsList.add(projectRef1);

    Project projectRef2 = AdminFactory.eINSTANCE.createProject();
    projectRef2.setId(2);
    projectRef2.setLabel("projectRef2 id=" + projectRef2.getId());
    projectsList.add(projectRef2);

    Project projectRef3 = AdminFactory.eINSTANCE.createProject();
    projectRef3.setId(3);
    projectRef3.setLabel("projectRef3 id=" + projectRef3.getId());
    projectsList.add(projectRef3);

    Project project1 = AdminFactory.eINSTANCE.createProject();
    project1.setId(11);
    project1.setLabel("project1 id=" + project1.getId());
    projectsList.add(project1);

    Project project2 = AdminFactory.eINSTANCE.createProject();
    project2.setId(22);
    project2.setLabel("project2 id=" + project2.getId());
    projectsList.add(project2);

    Project project3 = AdminFactory.eINSTANCE.createProject();
    project3.setId(33);
    project3.setLabel("project3 id=" + project3.getId());
    projectsList.add(project3);

    for (Project project : projectsList) {
      project.setCreationDate(new Date());
      project.setAuthor(user);
    }

    List<ProjectReference> projectReferenceList = new ArrayList<ProjectReference>();

    ProjectReference ref1 = AdminFactory.eINSTANCE.createProjectReference();
    ref1.setProject(project1);
    ref1.setBranch(TRUNK);
    ref1.setReferencedProject(projectRef1);
    ref1.setReferencedBranch(BRANCHES + "/" + "myBranch1");
    projectReferenceList.add(ref1);

    ProjectReference ref2 = AdminFactory.eINSTANCE.createProjectReference();
    ref2.setProject(project1);
    ref2.setBranch(TRUNK);
    ref2.setReferencedProject(projectRef2);
    ref2.setReferencedBranch(BRANCHES + "/" + "myBranch2");
    projectReferenceList.add(ref2);

    ProjectReference ref3 = AdminFactory.eINSTANCE.createProjectReference();
    ref3.setProject(projectRef2);
    ref3.setBranch(BRANCHES + "/" + "myBranch2");
    ref3.setReferencedProject(projectRef3);
    ref3.setReferencedBranch(BRANCHES + "/" + "myBranch3");
    projectReferenceList.add(ref3);
    for (Project project : projectsList) {
      UserProjectAuthorization authorization =
          AdminFactory.eINSTANCE.createUserProjectAuthorization();
      authorization.setType(UserProjectAuthorizationType.READ_ONLY_LITERAL);
      authorization.setUser(user);
      authorization.setProject(project);
      objects.add(project);
      objects.add(authorization);
      objects.add(project.getAuthor());
      for (Iterator iterator = project.getReferencedProjects().iterator(); iterator.hasNext(); ) {
        ProjectReference projectReference = (ProjectReference) iterator.next();
        if (projectReference.getReferencedProject() != null) {
          objects.add(projectReference);
          // should not add this, will be duplicated.
          // objects.add(projectReference.getReferencedProject());
          objects.add(projectReference.getReferencedProject().getAuthor());
        }
      }
    }

    return generateObjectsEncodedXmi(objects);
  }
 /**
  * findById.
  *
  * @param id the id of the project to find
  * @return the found project
  * @throws BusinessException
  * @throws DBException
  */
 public Project findById(int id) throws BusinessException, DBException {
   Project project = AdminFactory.eINSTANCE.createProject();
   project.setId(id);
   return PersistenceUtil.getPersistenceAdapter()
       .retrieveUnique(project, new String[] {"id"}, getDependentObjectsWithFolders());
 }