use of org.apache.archiva.metadata.repository.MetadataRepositoryException in project archiva by apache.
the class FileMetadataRepository method getMetadataFacets.
@Override
public List<String> getMetadataFacets(String repoId, String facetId) throws MetadataRepositoryException {
try {
Path directory = getMetadataDirectory(repoId, facetId);
if (!(Files.exists(directory) && Files.isDirectory(directory))) {
return Collections.emptyList();
}
List<String> facets;
final String searchFile = METADATA_KEY + ".properties";
try (Stream<Path> fs = Files.walk(directory, FileVisitOption.FOLLOW_LINKS)) {
facets = fs.filter(Files::isDirectory).filter(path -> Files.exists(path.resolve(searchFile))).map(path -> directory.relativize(path).toString()).collect(Collectors.toList());
}
return facets;
} catch (IOException e) {
throw new MetadataRepositoryException(e.getMessage(), e);
}
}
use of org.apache.archiva.metadata.repository.MetadataRepositoryException in project archiva by apache.
the class FileMetadataRepository method removeMetadataFacets.
@Override
public void removeMetadataFacets(String repositoryId, String facetId) throws MetadataRepositoryException {
try {
Path dir = getMetadataDirectory(repositoryId, facetId);
org.apache.archiva.common.utils.FileUtils.deleteDirectory(dir);
} catch (IOException e) {
throw new MetadataRepositoryException(e.getMessage(), e);
}
}
use of org.apache.archiva.metadata.repository.MetadataRepositoryException in project archiva by apache.
the class FileMetadataRepository method getArtifactsByDateRange.
@Override
public List<ArtifactMetadata> getArtifactsByDateRange(String repoId, Date startTime, Date endTime) throws MetadataRepositoryException {
try {
// TODO: this is quite slow - if we are to persist with this repository implementation we should build an index
// of this information (eg. in Lucene, as before)
List<ArtifactMetadata> artifacts = new ArrayList<>();
for (String ns : getRootNamespaces(repoId)) {
getArtifactsByDateRange(artifacts, repoId, ns, startTime, endTime);
}
artifacts.sort(new ArtifactComparator());
return artifacts;
} catch (MetadataResolutionException e) {
throw new MetadataRepositoryException(e.getMessage(), e);
}
}
use of org.apache.archiva.metadata.repository.MetadataRepositoryException in project archiva by apache.
the class JcrMetadataRepository method getArtifactsByDateRange.
@Override
public List<ArtifactMetadata> getArtifactsByDateRange(String repoId, Date startTime, Date endTime) throws MetadataRepositoryException {
List<ArtifactMetadata> artifacts;
String q = getArtifactQuery(repoId);
if (startTime != null) {
q += " AND [whenGathered] >= $start";
}
if (endTime != null) {
q += " AND [whenGathered] <= $end";
}
try {
Query query = getJcrSession().getWorkspace().getQueryManager().createQuery(q, Query.JCR_SQL2);
ValueFactory valueFactory = getJcrSession().getValueFactory();
if (startTime != null) {
query.bindValue("start", valueFactory.createValue(createCalendar(startTime)));
}
if (endTime != null) {
query.bindValue("end", valueFactory.createValue(createCalendar(endTime)));
}
QueryResult result = query.execute();
artifacts = new ArrayList<>();
for (Node n : JcrUtils.getNodes(result)) {
artifacts.add(getArtifactFromNode(repoId, n));
}
} catch (RepositoryException e) {
throw new MetadataRepositoryException(e.getMessage(), e);
}
return artifacts;
}
use of org.apache.archiva.metadata.repository.MetadataRepositoryException in project archiva by apache.
the class JcrMetadataRepository method removeMetadataFacets.
@Override
public void removeMetadataFacets(String repositoryId, String facetId) throws MetadataRepositoryException {
try {
Node root = getJcrSession().getRootNode();
String path = getFacetPath(repositoryId, facetId);
if (root.hasNode(path)) {
root.getNode(path).remove();
}
} catch (RepositoryException e) {
throw new MetadataRepositoryException(e.getMessage(), e);
}
}
Aggregations