Example #1
0
  /**
   * Get a list of all available tests
   *
   * @return
   * @throws BioclipseException
   */
  public List<String> getEndpoints() throws BioclipseException {

    initialize();

    List<String> epIDs = new ArrayList<String>();
    for (Endpoint ep : dsBusinessModel.getEndpoints()) {
      epIDs.add(ep.getId());
    }
    return epIDs;
  }
Example #2
0
  public Endpoint getEndpoint(String endpointID) throws BioclipseException {

    if (endpointID == null)
      throw new BioclipseException("Endpoint: " + endpointID + " must not be null.");

    initialize();

    for (Endpoint ep : dsBusinessModel.getEndpoints()) {
      if (endpointID.equals(ep.getId())) return ep;
    }

    logger.warn("Endpoint: " + endpointID + " could not be found.");
    throw new BioclipseException("Endpoint: " + endpointID + " could not be found.");
  }
Example #3
0
  /**
   * Removes a model. Removes extension and any files.
   *
   * @param model
   */
  public void removeModel(IDSTest model, String pluginID) {

    // Remove from DSBusinessModel
    dsBusinessModel.getTests().remove(model);
    for (Endpoint ep : dsBusinessModel.getEndpoints()) {
      if (ep.getTests() != null) {
        ep.getTests().remove(model);
        logger.debug("Removed model " + model.getName() + " from EP " + ep.getName());
      }
    }

    // Remove extensions in models.container plugin
    // =============================================
    File pluginXMLfile;
    try {
      pluginXMLfile = new File(FileUtil.getFilePath("plugin.xml", pluginID));

      Builder parser = new Builder();
      Document doc = parser.build(pluginXMLfile);
      Element root = doc.getRootElement();

      Element extension = null;

      // Find extension in plugin.xml, if exists
      Elements existingExtensions = root.getChildElements("extension");
      if (existingExtensions != null && existingExtensions.size() > 0) {
        for (int i = 0; i < existingExtensions.size(); i++) {
          extension = existingExtensions.get(i);

          // If exists a model with same name, remove it
          Elements existingTests = extension.getChildElements("test");
          if (existingTests != null && existingTests.size() > 0) {
            for (int j = 0; j < existingTests.size(); j++) {
              Element test = existingTests.get(j);
              String testName = test.getAttribute("name").getValue();

              // Remove spaces included by XML serialization
              while (testName.contains("  ")) testName = testName.replace("  ", " ");

              if (model.getName().equals(testName)) {
                test.getParent().removeChild(test);
                logger.debug("Removing existing model extension: " + model.getName());

                // Also remove the files
                Elements resources = test.getChildElements("resource");
                for (int rescnt = 0; rescnt < resources.size(); rescnt++) {
                  Element resource = resources.get(rescnt);
                  String path = resource.getAttribute("path").getValue();
                  try {
                    File reFile = new File(FileUtil.getFilePath(path, pluginID));
                    if (reFile.exists()) {
                      logger.debug("Removing file: " + reFile);
                      reFile.delete();
                    } else logger.debug("Unable to locate file to remove: " + path);
                  } catch (Exception e) {
                    logger.error("Problems removing file: " + path);
                  }
                }
              }
            }
          }
        }
      }

      // Serialize the updated plugin.xml to file
      Serializer serializer = new Serializer(new FileOutputStream(pluginXMLfile));
      serializer.setIndent(4);
      serializer.setMaxLength(64);
      serializer.write(doc);

    } catch (IllegalArgumentException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    } catch (ValidityException e) {
      e.printStackTrace();
    } catch (ParsingException e) {
      e.printStackTrace();
    }
  }