Ejemplo n.º 1
0
  public List<ResourceName> queryMDS(PackageName packageName) {
    MDSInstance mdsInstance;
    List<ResourceName> resources = new ArrayList<ResourceName>();
    try {
      mdsInstance = storeInitializer.getMDSInstance();
      packageName = (packageName == null) ? PackageName.createPackageName("/") : packageName;
      NameCondition condition =
          ConditionFactory.createNameCondition(packageName.getAbsoluteName(), "%");
      ResourceQuery query = QueryFactory.createResourceQuery(mdsInstance, condition);

      Iterator<QueryResult> contents = query.execute();
      if (contents == null) {
        return resources;
      }
      while (contents.hasNext()) {
        QueryResult result = contents.next();
        if (result.getResultType() == QueryResult.ResultType.PACKAGE_RESULT) {
          PackageResult pack = (PackageResult) result;
          resources.add(pack.getPackageName());
        } else {
          DocumentResult doc = (DocumentResult) result;
          resources.add(doc.getDocumentName());
        }
      }
      return resources;
    } catch (MDSAccessException e) {
      throw new IllegalArgumentException("Could not connect to MDS, check login data", e);
    } catch (InvalidReferenceException e) {
      throw new IllegalArgumentException("Could not find/read " + packageName, e);
    } catch (InvalidReferenceTypeException e) {
      throw new IllegalArgumentException("No correct type!", e);
    }
  }
 private void extractPaths(ResourceQuery query) {
   ResourcePathFileTraversal traverser =
       new ResourcePathFileTraversal(new File(query.constructBasePath()));
   traverser.addDatasourceFilters(query.getFilters());
   m_paths = traverser.traverseDirectory();
   Collections.sort(m_paths);
   System.err.println("paths: " + m_paths);
 }
Ejemplo n.º 3
0
  @Test
  public void getResources_exclude_disabled() {
    setupData("getResources_exclude_disabled");

    assertThat(dao.getResourceIds(ResourceQuery.create().setExcludeDisabled(false)))
        .containsOnly(1L, 2L);
    assertThat(dao.getResourceIds(ResourceQuery.create().setExcludeDisabled(true)))
        .containsOnly(2L);
  }
Ejemplo n.º 4
0
  @Test
  public void getResourceIds_filter_by_qualifier() {
    setupData("fixture");

    List<Long> ids =
        dao.getResourceIds(ResourceQuery.create().setQualifiers(new String[] {"TRK", "BRC"}));
    assertThat(ids).containsOnly(1L, 2L);

    ids = dao.getResourceIds(ResourceQuery.create().setQualifiers(new String[] {"XXX"}));
    assertThat(ids).isEmpty();

    ids = dao.getResourceIds(ResourceQuery.create().setQualifiers(new String[] {}));
    assertThat(ids).hasSize(4);
  }
Ejemplo n.º 5
0
  @Test
  public void getResources_filter_by_qualifier() {
    setupData("fixture");

    List<ResourceDto> resources =
        dao.getResources(ResourceQuery.create().setQualifiers(new String[] {"TRK", "BRC"}));
    assertThat(resources).extracting("qualifier").containsOnly("TRK", "BRC");

    resources = dao.getResources(ResourceQuery.create().setQualifiers(new String[] {"XXX"}));
    assertThat(resources).isEmpty();

    resources = dao.getResources(ResourceQuery.create().setQualifiers(new String[] {}));
    assertThat(resources).hasSize(4);
  }
Ejemplo n.º 6
0
  @Test
  public void getResource_filter_by_key() {
    dbTester.prepareDbUnit(getClass(), "fixture.xml");

    ResourceQuery query = ResourceQuery.create().setKey("org.struts:struts-core");

    assertThat(underTest.selectResource(query).getKey()).isEqualTo("org.struts:struts-core");
  }
Ejemplo n.º 7
0
  @Test
  public void getResourceIds_all() {
    setupData("fixture");

    List<Long> ids = dao.getResourceIds(ResourceQuery.create());

    assertThat(ids).hasSize(4);
  }
Ejemplo n.º 8
0
  @Test
  public void getResources_all() {
    setupData("fixture");

    List<ResourceDto> resources = dao.getResources(ResourceQuery.create());

    assertThat(resources).hasSize(4);
  }
Ejemplo n.º 9
0
  @Test
  public void getResources_filter_by_key() {
    setupData("fixture");

    ResourceQuery query = ResourceQuery.create().setKey("org.struts:struts-core");
    List<ResourceDto> resources = dao.getResources(query);
    assertThat(resources).hasSize(1);
    assertThat(resources.get(0).getKey()).isEqualTo("org.struts:struts-core");

    assertThat(dao.getResource(query).getKey()).isEqualTo("org.struts:struts-core");
  }
Ejemplo n.º 10
0
 @CheckForNull
 public Component findByKey(String key) {
   ResourceDto resourceDto = getResource(ResourceQuery.create().setKey(key));
   return resourceDto != null ? toComponent(resourceDto) : null;
 }
 public ResourceDataSource(ResourceQuery query) {
   extractPaths(query);
   m_filterFields = new ResourceFilterFields(query.getFilters(), query.getStringProperties());
 }
Ejemplo n.º 12
0
 @Override
 @SuppressWarnings("unchecked")
 public <T> CompletableFuture<T> submit(Query<T> query) {
   return protocol.submit(ResourceQuery.builder().withResource(resource).withQuery(query).build());
 }