Search in sources :

Example 1 with ContentFacet

use of org.sonatype.nexus.repository.content.facet.ContentFacet in project nexus-public by sonatype.

the class MavenContentFacetImpl method collectGavs.

private Set<List<String>> collectGavs(final int[] componentIds) {
    ContentFacetSupport contentFacet = (ContentFacetSupport) facet(ContentFacet.class);
    ComponentStore<?> componentStore = contentFacet.stores().componentStore;
    return Arrays.stream(componentIds).mapToObj(componentStore::readComponent).filter(Optional::isPresent).map(Optional::get).map(this::collectGabv).map(Arrays::asList).collect(toSet());
}
Also used : Optional(java.util.Optional) MavenContentFacet(org.sonatype.nexus.content.maven.MavenContentFacet) ContentFacet(org.sonatype.nexus.repository.content.facet.ContentFacet) ContentFacetSupport(org.sonatype.nexus.repository.content.facet.ContentFacetSupport)

Example 2 with ContentFacet

use of org.sonatype.nexus.repository.content.facet.ContentFacet in project nexus-public by sonatype.

the class ReplicationFacetSupport method doReplicateDelete.

public boolean doReplicateDelete(final String path) {
    ContentFacet contentFacet = facet(ContentFacet.class);
    ContentMaintenanceFacet componentMaintenance = facet(ContentMaintenanceFacet.class);
    FluentAssets fluentAssets = contentFacet.assets();
    Optional<FluentAsset> result = fluentAssets.path(path).find();
    result.ifPresent(componentMaintenance::deleteAsset);
    return result.isPresent();
}
Also used : ContentMaintenanceFacet(org.sonatype.nexus.repository.content.maintenance.ContentMaintenanceFacet) FluentAssets(org.sonatype.nexus.repository.content.fluent.FluentAssets) ContentFacet(org.sonatype.nexus.repository.content.facet.ContentFacet) FluentAsset(org.sonatype.nexus.repository.content.fluent.FluentAsset)

Example 3 with ContentFacet

use of org.sonatype.nexus.repository.content.facet.ContentFacet in project nexus-public by sonatype.

the class ContentDirector method copyComponent.

/**
 * This is a hook that allows format implementations to customize how a component is copied.
 *
 * @param source the component to copy
 * @param destination the repository to copy the component to
 * @return a reference to the component
 *
 * @since 3.38
 */
default FluentComponent copyComponent(final Component source, final Repository destination) {
    ContentFacet content = destination.facet(ContentFacet.class);
    FluentComponentBuilder destComponentBuilder = content.components().name(source.name()).namespace(source.namespace()).version(source.version());
    source.attributes().forEach(attribute -> destComponentBuilder.attributes(attribute.getKey(), attribute.getValue()));
    return destComponentBuilder.getOrCreate();
}
Also used : ContentFacet(org.sonatype.nexus.repository.content.facet.ContentFacet) FluentComponentBuilder(org.sonatype.nexus.repository.content.fluent.FluentComponentBuilder)

Example 4 with ContentFacet

use of org.sonatype.nexus.repository.content.facet.ContentFacet in project nexus-public by sonatype.

the class PurgeUnusedFacetImpl method purgeUnused.

@Override
@Guarded(by = STARTED)
public void purgeUnused(final int numberOfDays) {
    checkArgument(numberOfDays > 0, "Number of days must be greater then zero");
    log.info("Purging unused components from repository {}", getRepository().getName());
    ContentFacetSupport contentFacet = (ContentFacetSupport) getRepository().facet(ContentFacet.class);
    ComponentStore<?> componentStore = contentFacet.stores().componentStore;
    AssetStore<?> assetStore = contentFacet.stores().assetStore;
    int contentRepositoryId = contentFacet.contentRepositoryId();
    int purgedAssets = assetStore.purgeNotRecentlyDownloaded(contentRepositoryId, numberOfDays);
    log.debug("Deleted {} unused assets without components", purgedAssets);
    int purgedComponents = componentStore.purgeNotRecentlyDownloaded(contentRepositoryId, numberOfDays);
    log.debug("Deleted {} unused components and their assets", purgedComponents);
    log.info("Purged {} unused components from repository {}", purgedComponents, getRepository().getName());
}
Also used : ContentFacet(org.sonatype.nexus.repository.content.facet.ContentFacet) ContentFacetSupport(org.sonatype.nexus.repository.content.facet.ContentFacetSupport) Guarded(org.sonatype.nexus.common.stateguard.Guarded)

Example 5 with ContentFacet

use of org.sonatype.nexus.repository.content.facet.ContentFacet in project nexus-public by sonatype.

the class MaintenanceServiceImpl method canDeleteComponent.

@Override
public boolean canDeleteComponent(final Repository repository, final Component component) {
    boolean canDeleteComponent = true;
    ContentFacet contentFacet = repository.facet(ContentFacet.class);
    String repositoryName = repository.getName();
    String format = repository.getFormat().getValue();
    VariableResolverAdapter variableResolverAdapter = variableResolverAdapterManager.get(format);
    for (Asset asset : contentFacet.components().with(component).assets()) {
        if (!canDeleteAssetInRepository(repositoryName, format, variableResolverAdapter, asset)) {
            canDeleteComponent = false;
            break;
        }
    }
    return canDeleteComponent;
}
Also used : VariableResolverAdapter(org.sonatype.nexus.repository.security.VariableResolverAdapter) ContentFacet(org.sonatype.nexus.repository.content.facet.ContentFacet) Asset(org.sonatype.nexus.repository.content.Asset)

Aggregations

ContentFacet (org.sonatype.nexus.repository.content.facet.ContentFacet)18 Asset (org.sonatype.nexus.repository.content.Asset)5 ContentFacetSupport (org.sonatype.nexus.repository.content.facet.ContentFacetSupport)5 FluentAsset (org.sonatype.nexus.repository.content.fluent.FluentAsset)4 List (java.util.List)3 Optional (java.util.Optional)3 Inject (javax.inject.Inject)3 Named (javax.inject.Named)3 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)2 Stopwatch (com.google.common.base.Stopwatch)2 IOException (java.io.IOException)2 OffsetDateTime (java.time.OffsetDateTime)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 Collectors (java.util.stream.Collectors)2 Singleton (javax.inject.Singleton)2 Before (org.junit.Before)2 ComponentSupport (org.sonatype.goodies.common.ComponentSupport)2 Blob (org.sonatype.nexus.blobstore.api.Blob)2 BlobStoreManager (org.sonatype.nexus.blobstore.api.BlobStoreManager)2