/**
   * Artifact is either retrieved or prepared for later addition to registry
   *
   * @param ga
   * @return
   */
  private GovernanceArtifact addArtifact(RBGGovernanceArtifact ga) {
    boolean checkChanged = false;
    boolean isNewer = false;
    GenericArtifactManager gam = registryFactory.getManagerForArtifactType(ga.getRegistryType());
    GenericArtifact fa = (GenericArtifact) findMatchingArtifact(ga);
    log.info("working on: " + ga.getName());
    try {
      if (fa != null) {
        isNewer = isVersionNewer(ga.getVersion(), fa.getAttribute("details_version"));
        checkChanged = updateAttributes(ga, fa);
      } else {
        fa = gam.newGovernanceArtifact(new QName(ga.getName())); // artifactname
        fa.setAttribute("details_version", ga.getVersion());
        updateAttributes(ga, fa);
        gam.addGenericArtifact(fa);
        handleLifeCycle(ga, fa);
      }
      if (isNewer) {
        if (checkChanged) {
          gam.updateGenericArtifact(fa);
          log.info("updated: " + ga.getName());
        }
        handleLifeCycle(ga, fa);
      }
    } catch (GovernanceException e) {
      log.error(e.getMessage());
    } catch (RegistryException e) {
      log.error(e.getMessage());
    }

    return fa;
  }
  @Test(groups = "wso2.greg", dependsOnMethods = "testAddRxt")
  public void testAddResourceThroughRxt() throws RegistryException {
    GovernanceUtils.loadGovernanceArtifacts((UserRegistry) governance);
    GenericArtifactManager artifactManager = new GenericArtifactManager(governance, "person");
    GenericArtifact artifact = artifactManager.newGovernanceArtifact(new QName("testPerson"));

    artifact.setAttribute("ID", "Person_id");
    artifact.setAttribute("Name", "Person_Name");

    artifactManager.addGenericArtifact(artifact);

    assertTrue(artifact.getQName().toString().contains("testPerson"), "artifact name not found");
  }
  public String addURI(String name, String uri, String type) throws RegistryException {
    GovernanceUtils.loadGovernanceArtifacts((UserRegistry) governance);
    GenericArtifactManager artifactManager = new GenericArtifactManager(governance, "uri");
    GenericArtifact artifact = artifactManager.newGovernanceArtifact(new QName(name));

    artifact.setAttribute("overview_uri", uri);

    artifact.setAttribute("overview_type", type);
    artifactManager.addGenericArtifact(artifact);
    uriID = artifact.getId();
    assertTrue(artifact.getAttribute("overview_uri").equals(uri), "artifact URI not found");
    assertTrue(artifact.getAttribute("overview_name").equals(name), "artifact name not found");
    assertTrue(artifact.getAttribute("overview_type").equals(type), "artifact WSDL not found");

    return artifact.getPath();
  }
 private static void addServices(Registry govRegistry)
     throws RegistryException, XMLStreamException {
   GenericArtifactManager artifactManager = new GenericArtifactManager(govRegistry, "service");
   for (int i = 1; i < 10; i++) {
     StringBuilder builder = new StringBuilder();
     builder.append("<serviceMetaData xmlns=\"http://www.wso2.org/governance/metadata\">");
     builder.append("<overview><name>FlightService" + i + "</name><namespace>ns</namespace>");
     builder.append("<version>1.0.0-SNAPSHOT</version></overview>");
     builder.append("</serviceMetaData>");
     org.apache.axiom.om.OMElement XMLContent = AXIOMUtil.stringToOM(builder.toString());
     GenericArtifact artifact = artifactManager.newGovernanceArtifact(XMLContent);
     artifactManager.addGenericArtifact(artifact);
   }
   // Services need to be index before search.
   try {
     Thread.sleep(2 * 60 * 1000);
   } catch (InterruptedException e) {
     e.printStackTrace();
   }
 }