/**
  * Test whether there is a translation relationship between a scenario and a responsibility
  *
  * @param scenario The source scenario
  * @param resp The target responsibility
  */
 public boolean existTranslation(ArchEScenarioVO scenario, ArchEResponsibilityVO resp) {
   ArchETranslationRelationVO rel = null;
   for (Iterator<ArchETranslationRelationVO> it = trVOs.iterator(); it.hasNext(); ) {
     rel = it.next(); // TODO: Check if an equal 'by name' is needed below
     ArchEScenarioVO parent = rel.getParent();
     ArchEResponsibilityVO child = rel.getChild();
     if ((parent != null) && (child != null) && parent.equals(scenario) && child.equals(resp))
       return (true);
   }
   return (false);
 }
  /**
   * Return those responsibilities that are linked to a particular scenario (via translation
   * relations)
   *
   * @param scenario The parent scenario
   */
  public List<ArchEResponsibility> getResponsibilitiesByScenario(ArchEScenario scenario) {
    List<ArchEResponsibility> responsibilitiesOfInterest = new ArrayList<ArchEResponsibility>();

    ArchETranslationRelationVO item = null;
    for (Iterator<ArchETranslationRelationVO> it = trVOs.iterator(); it.hasNext(); ) {
      item = it.next();
      // TODO: Check if an equal 'by name' works better here
      ArchEScenarioVO parent = item.getParent();
      ArchEResponsibility child = item.getChild();
      if ((parent != null) && parent.equals((ArchEScenarioVO) scenario) && child != null)
        responsibilitiesOfInterest.add(child);
    }
    return (responsibilitiesOfInterest);
  }
  /**
   * 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());
      }
    }
  }
  /**
   * Establish a refinement relation between two existing responsibilities
   *
   * @param parent The source responsibility
   * @param child The target responsibility
   */
  public boolean refineResponsibility(ArchEResponsibilityVO parent, ArchEResponsibilityVO child) {

    ArchERelation rel = this.getRelation(parent, child, ArchERefinementRelationVO.class.getName());

    if (rel == null) { // There's no previous refinement between the two responsibilities

      ArchERefinementRelationVO refinement = new ArchERefinementRelationVO(this.version);
      refinement.setParent(parent);
      refinement.setChild(child);
      refVOs.add(refinement);

      // The child in the refinement relation "inherits" the scenario
      // translations from its parent responsibility
      ArchETranslationRelationVO translation = null;
      ArchETranslationRelationVO newTranslation = null;
      ArchEScenarioVO baseScenario = null;
      List<ArchETranslationRelationVO> derivedTranslations =
          new ArrayList<ArchETranslationRelationVO>();
      for (Iterator<ArchETranslationRelationVO> it = trVOs.iterator(); it.hasNext(); ) {
        translation = it.next();

        baseScenario = translation.getParent();
        if (parent.equals(translation.getChild()) && !this.existTranslation(baseScenario, child)) {
          // A translation relation exists for the parent responsibility
          newTranslation = new ArchETranslationRelationVO(this.version);
          newTranslation.setParent(baseScenario);
          newTranslation.setChild(child);
          derivedTranslations.add(newTranslation);
        }
      }

      for (Iterator<ArchETranslationRelationVO> it = derivedTranslations.iterator(); it.hasNext(); )
        trVOs.add(it.next());

      return (true);
    }

    return (false);
  }