/**
   * @param groupFileUri
   * @return
   */
  private File toDestinationFolder(URI groupFileUri) {
    String toReplace = TstGeneral.GROUP_PATH_STR;
    String forReplace = toReplace + "Y";

    String path = URI.decode(groupFileUri.devicePath());
    // modify to destination folder
    path = path.replace(toReplace, forReplace);
    File destFile = new File(path);
    return destFile;
  }
Esempio n. 2
0
 public static void dumpURI(URI uri, Logger logger) {
   logger.debug("URI: " + uri);
   logger.debug("authority: " + uri.authority());
   logger.debug("device: " + uri.device());
   logger.debug("devicePath: " + uri.devicePath());
   logger.debug("fileExtension: " + uri.fileExtension());
   logger.debug("fragment: " + uri.fragment());
   logger.debug("host: " + uri.host());
   logger.debug("lastSegment: " + uri.lastSegment());
   logger.debug("opaquePart: " + uri.opaquePart());
   logger.debug("path: " + uri.path());
   logger.debug("port: " + uri.port());
   logger.debug("query: " + uri.query());
   logger.debug("scheme: " + uri.scheme());
   logger.debug("segmentCount: " + uri.segmentCount());
   logger.debug("toFileString: " + uri.toFileString());
   logger.debug("userInfo: " + uri.userInfo());
   logger.debug("hasAbsolutePath: " + uri.hasAbsolutePath());
   logger.debug("schemehasAbsolutePath: " + uri.hasAbsolutePath());
   logger.debug("hasAuthority: " + uri.hasAuthority());
   logger.debug("hasDevice: " + uri.hasDevice());
   logger.debug("hasEmptyPath: " + uri.hasEmptyPath());
   logger.debug("hasFragment: " + uri.hasFragment());
   logger.debug("hasOpaquePart: " + uri.hasOpaquePart());
   logger.debug("hasPath: " + uri.hasPath());
   logger.debug("hasQuery: " + uri.hasQuery());
   logger.debug("hasRelativePath: " + uri.hasRelativePath());
   logger.debug("hasTrailingPathSeparator: " + uri.hasTrailingPathSeparator());
   logger.debug("isCurrentDocumentReference: " + uri.isCurrentDocumentReference());
   logger.debug("isEmpty: " + uri.isEmpty());
   logger.debug("isFile: " + uri.isFile());
   logger.debug("isHierarchical: " + uri.isHierarchical());
   logger.debug("isPrefix: " + uri.isPrefix());
   logger.debug("isRelative: " + uri.isRelative());
   logger.debug("segments: " + uri.segments());
 }
  /** Build elements one by one */
  public void testGroupReviewCreate() {
    R4EReviewGroup group = null;
    // required folder path and group name to build the new group file
    try {
      group = fFactory.createR4EReviewGroup(fGroupPath, GROUP_NAME);
    } catch (ResourceHandlingException e) {
      e.printStackTrace();
    }

    assertNotNull(group);
    URI uri = group.eResource().getURI();
    String expectedURI = fGroupPath.appendSegment("Group_One_group_root.xrer").toString();
    assertEquals(expectedURI, uri.toString());

    // Deserialise and assert
    group = null;
    try {
      group = fFactory.openR4EReviewGroup(uri);
    } catch (ResourceHandlingException e) {
      e.printStackTrace();
    } catch (CompatibilityException e) {
      e.printStackTrace();
    }

    // validate
    assertNotNull(group);
    assertEquals(GROUP_NAME, group.getName());

    // crate a review
    R4EReview review = null;
    try {
      review = fFactory.createR4EReview(group, REVIEW_NAME1, fUser1);
    } catch (ResourceHandlingException e) {
      e.printStackTrace();
      fail("Exception");
    }

    assertEquals(REVIEW_NAME1, review.getName());

    // re-open the group
    group = null;
    try {
      group = fFactory.openR4EReviewGroup(uri);
    } catch (ResourceHandlingException e) {
      e.printStackTrace();
      fail("Exception");
    } catch (CompatibilityException e) {
      e.printStackTrace();
      fail("Exception");
    }

    uri = review.eResource().getURI();
    // read the review
    try {
      review = fFactory.openR4EReview(group, review.getName());
    } catch (ResourceHandlingException e) {
      e.printStackTrace();
      fail("Exception");
    } catch (CompatibilityException e) {
      e.printStackTrace();
      fail("Exception");
    }

    assertEquals(REVIEW_NAME1, review.getName());

    // read the participant
    R4EUser participant = review.getUsersMap().values().iterator().next();
    uri = participant.eResource().getURI();
    try {
      ResourceSet resSet = participant.eResource().getResourceSet();
      participant = fReader.deserializeTopElement(uri, resSet, R4EParticipant.class);
    } catch (ResourceHandlingException e) {
      e.printStackTrace();
      fail("Exception");
    }

    assertEquals(fUser1, participant.getId());

    // Clean up
    File folder = new File(URI.decode(fGroupPath.devicePath()));
    try {
      FileUtils.deleteDirectory(folder);
    } catch (IOException e) {
      e.printStackTrace();
      fail("Exception");
    }
  }
  /**
   * Create a new empty model from an existing model that applies the same profiles and has the same
   * imports
   *
   * @param existingModel
   * @return
   */
  public ModelManagement createTargetModel(Model existingModel, String name, boolean copyImports)
      throws TransformationException {
    ModelManagement mm = new ModelManagement();
    Model newModel = mm.getModel();
    newModel.setName(name);

    try {
      // copy profile application
      for (Profile profile : existingModel.getAppliedProfiles()) {
        // reload profile in resource of new model
        monitor.subTask(Messages.InstantiateDepPlan_InfoApplyProfile + profile.getQualifiedName());

        if (profile.eResource() == null) {
          String profileName = profile.getQualifiedName();
          if (profileName == null) {
            if (profile instanceof MinimalEObjectImpl.Container) {
              URI uri = ((MinimalEObjectImpl.Container) profile).eProxyURI();
              if (uri != null) {
                throw new TransformationException(
                    String.format(Messages.InstantiateDepPlan_CheckInputModelProfileNoRes, uri));
              }
            }
            throw new TransformationException(
                Messages.InstantiateDepPlan_CheckInputModelProfileNoResNoName);
          }
          throw new TransformationException(
              String.format(Messages.InstantiateDepPlan_CheckInputModelProfile3, profileName));
        }

        Resource profileResource = null;
        try {
          profileResource =
              ModelManagement.getResourceSet().getResource(profile.eResource().getURI(), true);
        } catch (WrappedException e) {
          // read 2nd time (some diagnostic errors are raised only
          // once)
          Log.log(
              IStatus.WARNING,
              Log.DEPLOYMENT,
              "Warning: exception in profile.eResource() " + e.getMessage()); // $NON-NLS-1$
          profileResource =
              ModelManagement.getResourceSet().getResource(profile.eResource().getURI(), true);
        }
        Profile newProfileTop = (Profile) profileResource.getContents().get(0);
        Profile newProfile;
        String qname = profile.getQualifiedName();
        if ((qname != null) && qname.contains("::")) { // $NON-NLS-1$
          // profile is a sub-profile within same resource
          // TODO: should Copy class copy profile applications?
          // Should be handled in shallowContainer class.
          // if we put profile/newProfile pair into copy map, copy
          // would find (and copy profile
          // applications in sub-folders
          qname = qname.substring(qname.indexOf("::") + 2); // $NON-NLS-1$
          newProfile = (Profile) Utils.getQualifiedElement(newProfileTop, qname);
        } else {
          newProfile = newProfileTop;
        }
        newProfile.getMember("dummy"); // force profile loading //$NON-NLS-1$
        newModel.applyProfile(newProfile);
      }
    } catch (IllegalArgumentException e) {
      throw new TransformationException(
          Messages.InstantiateDepPlan_IllegalArgumentDuringCopy + e.toString());
    }

    // copy imports (and load resources associated - TODO: might not be
    // necessary)
    // While this is useful in general, it implies that code for imported
    // models
    // has been generated and compiled (for the right target) into a
    // library. This may be
    // quite tedious, unless automatically managed.
    // Therefore we do not activate this option in a first pass of the model
    // transformations.
    if (copyImports) {
      for (Package importedPackage : existingModel.getImportedPackages()) {
        if (importedPackage == null) {
          throw new TransformationException(Messages.InstantiateDepPlan_CheckInputImportPkg);
        }
        if (importedPackage.eResource() == null) {
          String errorMsg = Messages.InstantiateDepPlan_CheckInputImportPkgNoRes;
          if (importedPackage instanceof MinimalEObjectImpl.Container) {
            URI uri = ((MinimalEObjectImpl.Container) importedPackage).eProxyURI();
            if (uri != null) {
              errorMsg += " - URI: " + uri.devicePath(); // $NON-NLS-1$
            }
          }
          throw new TransformationException(errorMsg);
        }
        newModel.createPackageImport(importedPackage);
        monitor.subTask(
            String.format(
                Messages.InstantiateDepPlan_InfoImportPackage, importedPackage.getName()));

        try {
          importedPackage.eResource().load(null);
          newModel.getMember("dummy"); // force loading of model //$NON-NLS-1$
        } catch (IOException e) {
          throw new TransformationException(e.getMessage());
        }
      }
    }

    StUtils.copyStereotypes(existingModel, newModel);

    return mm;
  }