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); }
@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); }
@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); }
@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); }
@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"); }
@Test public void getResourceIds_all() { setupData("fixture"); List<Long> ids = dao.getResourceIds(ResourceQuery.create()); assertThat(ids).hasSize(4); }
@Test public void getResources_all() { setupData("fixture"); List<ResourceDto> resources = dao.getResources(ResourceQuery.create()); assertThat(resources).hasSize(4); }
@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"); }
@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()); }
@Override @SuppressWarnings("unchecked") public <T> CompletableFuture<T> submit(Query<T> query) { return protocol.submit(ResourceQuery.builder().withResource(resource).withQuery(query).build()); }