/**
 * Title : ApplicationAdminApplicationComponentAccess.java
 *
 * <p>Description : Application component projet Administration
 */
public class ProjectAdminProjectComponentAccess extends DefaultExecuteComponent {

  /** log */
  private static final Log LOG = LogFactory.getLog(ProjectAdminProjectComponentAccess.class);

  /** persistence provider */
  private static final IPersistenceProvider PERSISTENTPROVIDER =
      PersistenceHelper.getPersistenceProvider();

  /**
   * Default construcor
   *
   * @roseuid 42CBFC010285
   */
  public ProjectAdminProjectComponentAccess() {}

  /**
   * Adds a tag on the current project
   *
   * @param pProjectId project id
   * @param pTag the tag to add
   * @throws JrafEnterpriseException if an error occurs
   */
  public void addTag(Long pProjectId, TagDTO pTag) throws JrafEnterpriseException {
    try {
      ISession session = PERSISTENTPROVIDER.getSession();
      session.beginTransaction();
      ProjectFacade.addTag(session, pProjectId, pTag);
      session.commitTransaction();
    } catch (JrafDaoException e) {
      LOG.fatal(e, e);
    }
  }

  /**
   * removes a tag from a project
   *
   * @param pProjectId project accessed
   * @param pTag The tag that will be removed from the project
   * @throws JrafEnterpriseException if an error occurs
   */
  public void removeTag(Long pProjectId, TagDTO pTag) throws JrafEnterpriseException {
    try {
      ISession session = PERSISTENTPROVIDER.getSession();
      session.beginTransaction();
      ProjectFacade.removeTag(session, pProjectId, pTag);
      session.commitTransaction();
    } catch (JrafDaoException e) {
      LOG.fatal(e, e);
    }
  }
}
/**
 * Test de la facade project Pour changer le modèle de ce commentaire de type généré, allez à :
 * Fenêtre&gt;Préférences&gt;Java&gt;Génération de code&gt;Code et commentaires
 */
public class ProjectFacadeTest extends SqualeTestCase {
  /** provider de persistence */
  private static IPersistenceProvider PERSISTENTPROVIDER =
      PersistenceHelper.getPersistenceProvider();

  /** Test du get */
  public void testGet() {
    try {
      ISession session = PERSISTENTPROVIDER.getSession();
      ApplicationBO application = getComponentFactory().createApplication(session);
      QualityGridBO grid = getComponentFactory().createGrid(session);
      ProjectProfileBO profile = getComponentFactory().createProjectProfile(session);
      SourceManagementBO manager = getComponentFactory().createSourceManagement(session);
      MapParameterBO parameters = getComponentFactory().createParameters(session);
      ProjectBO project =
          getComponentFactory()
              .createProject(session, application, grid, profile, manager, parameters);
      ProjectConfDTO projectConf = new ProjectConfDTO();
      projectConf.setId(project.getId());
      ProjectConfDTO out = ProjectFacade.get(projectConf);
      FacadeHelper.closeSession(session, "");
    } catch (Exception e) {
      e.printStackTrace();
      fail("unexpected exception");
    }
  }

  /** Test du update */
  public void testUpdate() {
    try {
      ISession session = PERSISTENTPROVIDER.getSession();
      ApplicationBO application = getComponentFactory().createApplication(session);
      QualityGridBO grid = getComponentFactory().createGrid(session);
      ProjectProfileBO profile = getComponentFactory().createProjectProfile(session);
      SourceManagementBO manager = getComponentFactory().createSourceManagement(session);
      MapParameterBO parameters = getComponentFactory().createParameters(session);
      ProjectBO project =
          getComponentFactory()
              .createProject(session, application, grid, profile, manager, parameters);
      assertEquals(0, project.getParameters().getParameters().size());
      ApplicationConfDTO applicationConf = new ApplicationConfDTO();
      applicationConf.setId(application.getId());
      ProjectConfDTO projectConf = new ProjectConfDTO();
      projectConf.setId(project.getId());
      projectConf.setName(project.getName());
      // Création des paramètres
      MapParameterDTO params = new MapParameterDTO();
      StringParameterDTO strParam = new StringParameterDTO("strParam");
      params.getParameters().put("strParam", strParam);
      projectConf.setParameters(params);
      // La grille
      QualityGridDTO gridDTO = new QualityGridDTO();
      gridDTO.setName(grid.getName());
      projectConf.setQualityGrid(gridDTO);
      // Le profil
      ProjectProfileDTO profileDTO = new ProjectProfileDTO();
      profileDTO.setName(profile.getName());
      projectConf.setProfile(profileDTO);
      // Le source manager
      SourceManagementDTO managerDTO = new SourceManagementDTO();
      managerDTO.setName(manager.getName());
      projectConf.setSourceManager(managerDTO);
      ProjectFacade.update(projectConf, applicationConf, getSession());
      ProjectConfDTO projectconfGetting = ProjectFacade.get(projectConf);
      MapParameterDTO paramsDTOGetting = projectconfGetting.getParameters();
      Map mapGetting = paramsDTOGetting.getParameters();
      assertEquals(1, mapGetting.size());
      FacadeHelper.closeSession(session, "");
    } catch (Exception e) {
      e.printStackTrace();
      fail("unexpected exception");
    }
  }
}
/**
 * Title : ApplicationAdminApplicationComponentAccess.java
 *
 * <p>Description : Application component de configuration du projet
 */
public class TagAdminTagComponentAccess extends DefaultExecuteComponent {

  /** log */
  private static final Log LOG = LogFactory.getLog(TagAdminTagComponentAccess.class);

  /** provider de persistence */
  private static final IPersistenceProvider PERSISTENTPROVIDER =
      PersistenceHelper.getPersistenceProvider();

  /**
   * default constructor
   *
   * @roseuid 42CBFC010285
   */
  public TagAdminTagComponentAccess() {}

  /**
   * Retrieves the tag from the database with its Id
   *
   * @param pTagId the id of the wanted tag
   * @return the tag if it exists, null otherwise
   * @throws JrafEnterpriseException if an error occurs
   */
  public TagDTO getTag(Long pTagId) throws JrafEnterpriseException {
    return TagFacade.getTag(pTagId);
  }

  /**
   * Retrieves the tags from the given name
   *
   * @param pStringFirstChars array containing the beginning of the names of the wanted TagDTOs
   * @return the list of tag if there is at least one, null otherwise
   * @throws JrafEnterpriseException if an error occurs
   */
  public Collection<TagDTO> getTagsByName(String[] pStringFirstChars)
      throws JrafEnterpriseException {
    return TagFacade.getTagsByName(pStringFirstChars);
  }

  /**
   * Retrieves all the existing tags
   *
   * @return the list of existing tags in the database, null if there are none
   * @throws JrafEnterpriseException if an error occurs
   */
  public Collection<TagDTO> getTags() throws JrafEnterpriseException {
    return TagFacade.getTags();
  }

  /**
   * Retrieves all the existing tag categories
   *
   * @return the list of existing tag categories in the database, null if there are none
   * @throws JrafEnterpriseException si erreur
   */
  public Collection<TagCategoryDTO> getTagCategories() throws JrafEnterpriseException {
    return TagFacade.getTagCategories();
  }

  /**
   * Retrieves the tag categories from the given name
   *
   * @param pStringFirstChars the beginning of the name of the tag category
   * @return the list of tag categories if there is at least one, null otherwise
   * @throws JrafEnterpriseException if an error occurs
   */
  public Collection<TagCategoryDTO> getTagCategoriesByName(String pStringFirstChars)
      throws JrafEnterpriseException {
    return TagFacade.getTagCategoriesByName(pStringFirstChars);
  }

  /**
   * creates a Tag in the database from a given object tag
   *
   * @param pTagDTO the tag to create in the database
   * @return the TagDTO once it is created
   * @throws JrafEnterpriseException exception JRAF
   */
  public TagDTO createTag(TagDTO pTagDTO) throws JrafEnterpriseException {
    return TagFacade.createTag(pTagDTO);
  }

  /**
   * modifies a Tag in the database from a given object tag
   *
   * @param pTagDTO the tag to modify in the database
   * @return the TagDTO once it has been modified
   * @throws JrafEnterpriseException exception JRAF
   */
  public TagDTO modifyTag(TagDTO pTagDTO) throws JrafEnterpriseException {
    return TagFacade.modifyTag(pTagDTO);
  }

  /**
   * creates a TagCategory in the database from a given object tagCategory
   *
   * @param pTagCategoryDTO the tag to create in the database
   * @return the TagCategoryDTO once it is created
   * @throws JrafEnterpriseException exception JRAF
   */
  public TagCategoryDTO createTagCategory(TagCategoryDTO pTagCategoryDTO)
      throws JrafEnterpriseException {
    return TagFacade.createTagCategory(pTagCategoryDTO);
  }

  /**
   * modifies a TagCategory in the database from a given object tag category
   *
   * @param pTagCategoryDTO the tag category to modify in the database
   * @return the TagCategoryDTO once it has been modified
   * @throws JrafEnterpriseException exception JRAF
   */
  public TagCategoryDTO modifyTagCategory(TagCategoryDTO pTagCategoryDTO)
      throws JrafEnterpriseException {
    return TagFacade.modifyTagCategory(pTagCategoryDTO);
  }

  /**
   * deletes one or more tags from the database with the naves given as a parameter
   *
   * @param pNamesToDelete a collection of Strings of the names of the tags to delete
   * @return boolean if the number of removals from the database equals the number wanted
   * @throws JrafEnterpriseException exception JRAF
   */
  public Boolean deleteTags(Collection<String> pNamesToDelete) throws JrafEnterpriseException {
    return TagFacade.deleteTags(pNamesToDelete);
  }

  /**
   * deletes one or more tag categories from the database with the naves given as a parameter
   *
   * @param pNamesToDelete a collection of Strings of the names of the tag categories to delete
   * @return boolean if the number of removals from the database equals the number wanted
   * @throws JrafEnterpriseException exception JRAF
   */
  public Boolean deleteTagCategories(Collection<String> pNamesToDelete)
      throws JrafEnterpriseException {
    return TagFacade.deleteTagCategories(pNamesToDelete);
  }
}