/** Save all the VOs related to this core responsibility structure */
  public void save() throws ArchEException {
    Session openSession = ArchECoreDataProvider.getSessionFactory().getCurrentSession();
    if (openSession != null && openSession.isConnected() && openSession.isOpen()) {
      try {
        // Save or update the raw responsibility structure
        //				openSession.saveOrUpdate(rawRSVO);

        for (Iterator<ArchEResponsibilityVO> itResps = rawRSVO.getResponsibilities().iterator();
            itResps.hasNext(); ) {
          ArchEResponsibilityVO resp = itResps.next();
          String name = resp.getName();
          openSession.saveOrUpdate(resp);
          this.saveParametersForResponsibility(resp, openSession);
        }

        // Save or update the translation relations
        for (Iterator<ArchETranslationRelationVO> it = trVOs.iterator(); it.hasNext(); )
          openSession.saveOrUpdate(it.next());

        // Save or update the refinement relations
        for (Iterator<ArchERefinementRelationVO> it = refVOs.iterator(); it.hasNext(); )
          openSession.saveOrUpdate(it.next());

        // It deletes the list of 'removed' VOs
        for (Iterator it = removedRelationVOs.iterator(); it.hasNext(); )
          openSession.delete(it.next());

      } catch (HibernateException ex) {
        throw new ArchEException(ex.getMessage(), ex.getCause());
      }
    }
  }
 public boolean containResponsibility(ArchEResponsibility responsibility) {
   for (Iterator<ArchEResponsibilityVO> it = rawRSVO.getResponsibilities().iterator();
       it.hasNext(); ) {
     // Two responsibilities are equal if they have the same name
     // (under the same version of the architecture)
     if (it.next().getName().equals(responsibility.getName())) return (true);
   }
   return (false);
 }
  /** Restore all the VOs related to this core responsibility structure */
  public void restore() throws ArchEException {
    Session openSession = ArchECoreDataProvider.getSessionFactory().getCurrentSession();
    if (openSession != null && openSession.isConnected() && openSession.isOpen()) {
      try {
        // Restore a raw responsibility structure
        rawRSVO =
            (ArchEResponsibilityStructureVO)
                (openSession
                    .createQuery("from ArchEResponsibilityStructureVO as v where v.id = ?")
                    .setInteger(0, version.getId())
                    .uniqueResult());

        // Lazy initialization of collections
        Hibernate.initialize(rawRSVO.getResponsibilities());

        for (Iterator<ArchEResponsibilityVO> itResps = rawRSVO.getResponsibilities().iterator();
            itResps.hasNext(); )
          this.restoreParametersForResponsibility(itResps.next(), openSession);

        // Restore the translation relations from requirements to responsibilities
        Query qrels =
            ArchECoreDataProvider.getSessionFactory()
                .getCurrentSession()
                .createQuery(
                    "from ArchETranslationRelationVO as rel where rel.parentType = ? and rel.version = ?");
        qrels.setString(0, "Scenario");
        qrels.setInteger(1, version.getId());
        trVOs = qrels.list();

        // Restore the refinement relations (between responsibilities)
        Query qrefs =
            ArchECoreDataProvider.getSessionFactory()
                .getCurrentSession()
                .createQuery("from ArchERefinementRelationVO as rel where rel.version = ?");
        qrefs.setInteger(0, version.getId());
        refVOs = qrefs.list();

      } catch (HibernateException ex) {
        throw new ArchEException(ex.getMessage(), ex.getCause());
      }
    }
  }
  /**
   * Save AS all the VOs related to this core responsibility structure
   *
   * @param newVersion The version for the new VOs
   * @throws ArchEException
   */
  public void saveAs(ArchEVersionVO newVersion) throws ArchEException {
    Session openSession = ArchECoreDataProvider.getSessionFactory().getCurrentSession();
    if (openSession != null && openSession.isConnected() && openSession.isOpen()) {
      try {

        // Save the newly-created raw responsibility structure
        rawRSVO.setId(newVersion.getId());

        ArchEResponsibilityVO itemResp = null;
        for (Iterator<ArchEResponsibilityVO> it = rawRSVO.getResponsibilities().iterator();
            it.hasNext(); ) {
          itemResp = it.next();
          itemResp.setVersion(newVersion);
          openSession.save(itemResp);
          this.saveParametersForResponsibilityAs(newVersion, itemResp, openSession);
        }

        // Create a copy of the existing translation relations
        ArchETranslationRelationVO itemTr = null;
        for (Iterator<ArchETranslationRelationVO> it = trVOs.iterator(); it.hasNext(); ) {
          itemTr = it.next();
          itemTr.setVersion(newVersion);
          openSession.save(itemTr);
        }

        // Create a copy of the existing refinement relations
        ArchERefinementRelationVO itemRef = null;
        for (Iterator<ArchERefinementRelationVO> it = refVOs.iterator(); it.hasNext(); ) {
          itemRef = it.next();
          itemRef.setVersion(newVersion);
          openSession.save(itemRef);
        }

      } catch (HibernateException ex) {
        throw new ArchEException(ex.getMessage(), ex.getCause());
      }
    }
  }
  /**
   * Delete all the VOs related to this core responsibility structure
   *
   * @throws ArchEException
   */
  public void delete() throws ArchEException {
    Session openSession = ArchECoreDataProvider.getSessionFactory().getCurrentSession();
    if (openSession != null && openSession.isConnected() && openSession.isOpen()) {
      try {
        // Delete the raw responsibility structure
        openSession.delete(rawRSVO);

        for (Iterator<ArchEResponsibilityVO> itResps = rawRSVO.getResponsibilities().iterator();
            itResps.hasNext(); )
          this.deleteParametersForResponsibility(itResps.next(), openSession);

        // Delete the translation relations
        for (Iterator<ArchETranslationRelationVO> itTr = trVOs.iterator(); itTr.hasNext(); )
          openSession.delete(itTr.next());

        // Delete the refinement relations
        for (Iterator<ArchERefinementRelationVO> itRef = refVOs.iterator(); itRef.hasNext(); )
          openSession.delete(itRef.next());

      } catch (HibernateException ex) {
        throw new ArchEException(ex.getMessage(), ex.getCause());
      }
    }
  }
 public boolean addResponsibility(ArchEResponsibility resp) {
   return rawRSVO.getResponsibilities().add((ArchEResponsibilityVO) resp);
 }
 public List<ArchEResponsibility> getResponsibilities() {
   List<ArchEResponsibility> responsibilityList = new ArrayList(rawRSVO.getResponsibilities());
   return responsibilityList;
 }