Ejemplo n.º 1
0
  public void updateServiceMetadata(String serviceUrl, Metadata meta) throws Exception {

    GridService service = getGridServiceDao().getByUrl(serviceUrl);
    if (service == null) {
      throw new RuntimeException("Coudln't find service for " + serviceUrl);
    }

    Set<CQLQueryInstance> cqlQueryInstances = new HashSet<CQLQueryInstance>();
    Map<String, SharedCQLQuery> sharedCqlQueries = new HashMap<String, SharedCQLQuery>();
    if (meta.dmodel != null) {

      // Need to preserve associations with SharedQuery objects
      // and CQLQueryInstance objects.

      GridDataService dataService = (GridDataService) service;
      for (SharedCQLQuery query : getSharedCqlQueryDao().getByDataService(dataService)) {
        UMLClass umlClass = query.getTargetClass();
        sharedCqlQueries.put(umlClass.getPackageName() + "." + umlClass.getClassName(), query);
      }
      cqlQueryInstances.addAll(getCqlQueryInstanceDao().getByDataService(dataService));
    }

    // NOTE: Associations with XML schemas in GME is handled
    // by the XMLSchemaMonitor. So, we don't need to address it here.

    getGridServiceDao().deleteMetadata(service);
    setMetadata(service, meta);
    getGridServiceDao().save(service);
    getGridServiceDao().getHibernateTemplate().flush();

    if (sharedCqlQueries.size() > 0) {
      GridDataService dataService = (GridDataService) service;
      for (UMLClass umlClass : dataService.getDomainModel().getClasses()) {
        SharedCQLQuery query =
            sharedCqlQueries.get(umlClass.getPackageName() + "." + umlClass.getClassName());
        if (query != null) {
          query.setTargetClass(umlClass);
          query.setTargetService(dataService);
          getSharedCqlQueryDao().save(query);
        }
      }
    }

    if (cqlQueryInstances.size() > 0) {
      GridDataService dataService = (GridDataService) service;
      for (CQLQueryInstance instance : cqlQueryInstances) {
        instance.setDataService(dataService);
        getCqlQueryInstanceDao().save(instance);
      }
    }
  }
Ejemplo n.º 2
0
  @Test
  public void metadataChange() {

    GridDataService dataService = new GridDataService();
    dataService.setUrl(
        "http://cabio-gridservice.nci.nih.gov:80/wsrf-cabio/services/cagrid/CaBIOSvc");
    getGridServiceDao().save(dataService);
    Metadata meta = new Metadata();
    try {
      meta.dmodel =
          MetadataUtils.deserializeDomainModel(new FileReader("test/data/cabioModelSnippet.xml"));
      meta.smeta =
          MetadataUtils.deserializeServiceMetadata(
              new FileReader("test/data/cabioServiceMetadata.xml"));
    } catch (Exception ex) {
      fail("Error deserializing test data: " + ex.getMessage());
      ex.printStackTrace();
    }
    try {
      getMetadataListener().loadMetadata(dataService, meta);
    } catch (Exception ex) {
      fail("Error loading metadata: " + ex.getMessage());
      ex.printStackTrace();
    }

    // Now associate some CQLQueryInstance and SharedCQLQuery objects
    String cql = null;
    try {
      cql = loadCQL("test/data/cabioMouseQuery.xml");
    } catch (Exception ex) {
      fail("Error loading test query: " + ex.getMessage());
      ex.printStackTrace();
    }

    CQLQuery query = new CQLQuery();
    query.setXml(cql);
    query.setHash(PortalUtils.createHash(cql));
    getCqlQueryDao().save(query);
    CQLQueryInstance instance = new CQLQueryInstance();
    instance.setQuery(query);
    instance.setDataService(dataService);
    getCqlQueryInstanceDao().save(instance);

    String targetClassName = "gov.nih.nci.cabio.domain.Gene";
    UMLClass targetClass = null;
    for (UMLClass klass : dataService.getDomainModel().getClasses()) {
      String className = klass.getPackageName() + "." + klass.getClassName();
      if (className.equals(targetClassName)) {
        targetClass = klass;
        break;
      }
    }
    SharedCQLQuery sharedCqlQuery = new SharedCQLQuery();
    sharedCqlQuery.setTargetClass(targetClass);
    sharedCqlQuery.setTargetService(dataService);
    getSharedCqlQueryDao().save(sharedCqlQuery);

    verify(dataService, getSharedCqlQueryDao(), getCqlQueryInstanceDao(), targetClassName);

    try {
      getChangeListener().updateServiceMetadata(dataService.getUrl(), meta);
    } catch (Exception ex) {
      fail("Error updating metadata: " + ex.getMessage());
      ex.printStackTrace();
    }

    verify(dataService, getSharedCqlQueryDao(), getCqlQueryInstanceDao(), targetClassName);
  }