use of org.apache.archiva.repository.content.Version in project archiva by apache.
the class ManagedDefaultRepositoryContent method newItemStream.
@Override
public Stream<? extends ContentItem> newItemStream(ItemSelector selector, boolean parallel) throws ContentAccessException, IllegalArgumentException {
final Predicate<StorageAsset> filter = getItemFileFilterFromSelector(selector);
StorageAsset startDir;
if (selector.getNamespace().contains("*")) {
startDir = getAsset("");
} else if (selector.hasProjectId() && selector.getProjectId().contains("*")) {
startDir = getAsset(selector.getNamespace());
} else if (selector.hasProjectId() && selector.hasVersion() && selector.getVersion().contains("*")) {
startDir = getAsset(selector.getNamespace(), selector.getProjectId());
} else if (selector.hasProjectId() && selector.hasVersion()) {
startDir = getAsset(selector.getNamespace(), selector.getProjectId(), selector.getVersion());
} else if (selector.hasProjectId()) {
startDir = getAsset(selector.getNamespace(), selector.getProjectId());
} else {
startDir = getAsset(selector.getNamespace());
if (!selector.recurse()) {
// We descend into 2 subdirectories (project and version)
return startDir.list().stream().flatMap(a -> getChildrenDF(a, 1)).map(this::getItemFromPath);
}
}
return StorageUtil.newAssetStream(startDir, parallel).filter(filter).map(this::getItemFromPath);
}
use of org.apache.archiva.repository.content.Version in project archiva by apache.
the class DefaultRepositoriesService method removeProjectVersion.
@Override
public ActionStatus removeProjectVersion(String repositoryId, String namespace, String projectId, String version) throws ArchivaRestServiceException {
// if not a generic we can use the standard way to delete artifact
if (!VersionUtil.isGenericSnapshot(version)) {
Artifact artifact = new Artifact(namespace, projectId, version);
artifact.setRepositoryId(repositoryId);
artifact.setContext(repositoryId);
return deleteArtifact(artifact);
}
if (StringUtils.isEmpty(repositoryId)) {
throw new ArchivaRestServiceException("repositoryId cannot be null", 400, null);
}
if (!getPermissionStatus(repositoryId).isAuthorizedToDeleteArtifacts()) {
throw new ArchivaRestServiceException("not authorized to delete artifacts", 403, null);
}
if (StringUtils.isEmpty(namespace)) {
throw new ArchivaRestServiceException("groupId cannot be null", 400, null);
}
if (StringUtils.isEmpty(projectId)) {
throw new ArchivaRestServiceException("artifactId cannot be null", 400, null);
}
if (StringUtils.isEmpty(version)) {
throw new ArchivaRestServiceException("version cannot be null", 400, null);
}
RepositorySession repositorySession = null;
try {
repositorySession = repositorySessionFactory.createSession();
} catch (MetadataRepositoryException e) {
e.printStackTrace();
}
try {
ManagedRepositoryContent repository = getManagedRepositoryContent(repositoryId);
BaseRepositoryContentLayout layout = repository.getLayout(BaseRepositoryContentLayout.class);
ArchivaItemSelector selector = ArchivaItemSelector.builder().withNamespace(namespace).withProjectId(projectId).withVersion(version).build();
Version versionItem = layout.getVersion(selector);
if (versionItem != null && versionItem.exists()) {
repository.deleteItem(versionItem);
}
MetadataRepository metadataRepository = repositorySession.getRepository();
Collection<ArtifactMetadata> artifacts = metadataRepository.getArtifacts(repositorySession, repositoryId, namespace, projectId, version);
for (ArtifactMetadata artifactMetadata : artifacts) {
metadataRepository.removeTimestampedArtifact(repositorySession, artifactMetadata, version);
}
metadataRepository.removeProjectVersion(repositorySession, repositoryId, namespace, projectId, version);
} catch (MetadataRepositoryException | MetadataResolutionException | RepositoryException | ItemNotFoundException | LayoutException e) {
throw new ArchivaRestServiceException("Repository exception: " + e.getMessage(), 500, e);
} finally {
try {
repositorySession.save();
} catch (MetadataSessionException e) {
log.error("Session save failed {}", e.getMessage());
}
repositorySession.close();
}
return ActionStatus.SUCCESS;
}
use of org.apache.archiva.repository.content.Version in project archiva by apache.
the class MetadataTransferTest method assertFetchVersioned.
/**
* Transfer the metadata file.
*
* @param requestedResource the requested resource
* @throws Exception
*/
private void assertFetchVersioned(String requestedResource) throws Exception {
Path expectedFile = managedDefaultDir.resolve(requestedResource);
ContentItem item = managedDefaultRepository.toItem(requestedResource);
if (item instanceof DataItem) {
item = managedDefaultRepository.getParent(item);
}
assertNotNull(item);
BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout(BaseRepositoryContentLayout.class);
Version version = layout.adaptItem(Version.class, item);
assertNotNull(version);
String metaPath = managedDefaultRepository.toPath(layout.getMetadataItem(version));
StorageAsset downloadedFile = proxyHandler.fetchMetadataFromProxies(managedDefaultRepository.getRepository(), metaPath).getFile();
assertNotNull("Should have downloaded a file.", downloadedFile);
assertNoTempFiles(expectedFile);
}
use of org.apache.archiva.repository.content.Version in project archiva by apache.
the class ManagedDefaultRepositoryContentTest method deleteItemNotFound.
@Test
public void deleteItemNotFound() throws IOException, URISyntaxException, ItemNotFoundException {
ManagedRepository repo = createManagedRepoWithContent("delete-repository");
ManagedRepositoryContent myRepoContent = repo.getContent();
Path repoRoot = repo.getRoot().getFilePath();
ArchivaItemSelector selector = ArchivaItemSelector.builder().withNamespace("org.apache.test2").build();
ContentItem item = myRepoContent.getItem(selector);
assertTrue(item instanceof Namespace);
try {
myRepoContent.deleteItem(item);
assertTrue("ItemNotFoundException expected for non existing namespace", false);
} catch (ItemNotFoundException e) {
}
selector = ArchivaItemSelector.builder().withNamespace("org.apache.test").withProjectId("samplejar2").build();
item = myRepoContent.getItem(selector);
assertTrue(item instanceof Project);
try {
myRepoContent.deleteItem(item);
assertTrue("ItemNotFoundException expected for non existing project", false);
} catch (ItemNotFoundException e) {
}
selector = ArchivaItemSelector.builder().withNamespace("org.apache.test").withProjectId("samplejar").withVersion("1.1").build();
item = myRepoContent.getItem(selector);
assertTrue(item instanceof Version);
try {
myRepoContent.deleteItem(item);
assertTrue("ItemNotFoundException expected for non existing version", false);
} catch (ItemNotFoundException e) {
}
selector = ArchivaItemSelector.builder().withNamespace("org.apache.test").withProjectId("samplejar").withVersion("1.0").withArtifactId("samplejar").withArtifactVersion("1.0").withExtension("jax").build();
item = myRepoContent.getItem(selector);
assertTrue(item instanceof Artifact);
try {
myRepoContent.deleteItem(item);
assertTrue("ItemNotFoundException expected for non existing artifact", false);
} catch (ItemNotFoundException e) {
}
}
use of org.apache.archiva.repository.content.Version in project archiva by apache.
the class ManagedDefaultRepositoryContentTest method getNonExistingMetadataItem.
@Test
public void getNonExistingMetadataItem() {
// org/apache/maven/some-ejb/1.0
ArchivaItemSelector versionSelector = ArchivaItemSelector.builder().withNamespace("javax.sql").withProjectId("jdbc").withVersion("2.0").build();
Version version = repoContent.getVersion(versionSelector);
DataItem metaData = repoContent.getMetadataItem(version);
assertFalse(metaData.exists());
assertEquals("/javax/sql/jdbc/2.0/maven-metadata.xml", metaData.getAsset().getPath());
}
Aggregations