use of org.sonatype.nexus.common.entity.Continuation in project nexus-public by sonatype.
the class AptHostedFacet method buildPackageIndexes.
private CompressingTempFileStore buildPackageIndexes(final List<AssetChange> changes) throws IOException {
CompressingTempFileStore result = new CompressingTempFileStore();
Map<String, Writer> streams = new HashMap<>();
boolean ok = false;
try {
Set<String> architectures = changes.stream().map(change -> getArchitecture(change.getAsset())).collect(Collectors.toSet());
final Continuation<FluentAsset> allAssets = getRepository().facet(ContentFacet.class).assets().byKind(DEB).browse(Integer.MAX_VALUE, null);
allAssets.stream().map(this::getArchitecture).collect(Collectors.toCollection(() -> architectures));
Map<String, List<FluentAsset>> assetsPerArch = new HashMap<>();
for (String architecture : architectures) {
List<FluentAsset> assets = allAssets.stream().filter(asset -> getArchitecture(asset).equals(architecture)).collect(Collectors.toList());
assetsPerArch.put(architecture, assets);
}
for (List<FluentAsset> assets : assetsPerArch.values()) {
Optional<AssetChange> removeAssetChange = changes.stream().filter(change -> change.getAsset().kind().equals(DEB)).filter(change -> change.getAction() == AssetAction.REMOVED).findAny();
if (assets.isEmpty() && removeAssetChange.isPresent()) {
createEmptyMetadataFile(result, streams, removeAssetChange.get());
} else {
createMetadataFileWithData(changes, result, streams, assets);
}
}
ok = true;
} finally {
for (Writer writer : streams.values()) {
IOUtils.closeQuietly(writer);
}
if (!ok) {
result.close();
}
}
return result;
}
use of org.sonatype.nexus.common.entity.Continuation in project nexus-public by sonatype.
the class DatastoreMetadataRebuilderTest method infiniteContinuation.
private Continuation infiniteContinuation(Object returnItem) {
Continuation continuation = mock(Continuation.class);
Iterator iterator = mock(Iterator.class);
Spliterator spliterator = mock(Spliterator.class);
when(continuation.spliterator()).thenReturn(spliterator);
when(continuation.iterator()).thenReturn(iterator);
when(iterator.hasNext()).thenReturn(true);
when(iterator.next()).thenReturn(returnItem);
return continuation;
}
use of org.sonatype.nexus.common.entity.Continuation in project nexus-public by sonatype.
the class AssetDAOTest method testReadPathTest.
@Test
public void testReadPathTest() {
TestAssetData asset1 = randomAsset(repositoryId);
TestAssetData asset2 = randomAsset(repositoryId);
// make sure paths are different
asset2.setPath(asset1.path() + "/2");
try (DataSession<?> session = sessionRule.openSession(DEFAULT_DATASTORE_NAME)) {
TestAssetDAO dao = session.access(TestAssetDAO.class);
// our bespoke schema will be applied automatically via 'extendSchema'...
dao.createAsset(asset1);
dao.createAsset(asset2);
asset2.setTestFlag(true);
dao.updateAssetFlag(asset2);
TestAssetData test1 = dao.readPathTest(repositoryId, asset1.path()).orElse(null);
TestAssetData test2 = dao.readPathTest(repositoryId, asset2.path()).orElse(null);
assertThat(test1, notNullValue());
assertThat(test1.getTestFlag(), equalTo(false));
assertThat(test2, notNullValue());
assertThat(test2.getTestFlag(), equalTo(true));
Continuation<Asset> continuation = dao.browseFlaggedAssets(repositoryId, 10, null);
assertThat(continuation.size(), equalTo(1));
TestAssetData test3 = continuation.stream().filter(obj -> obj instanceof TestAssetData).map(obj -> (TestAssetData) obj).findFirst().orElseThrow(() -> new IllegalStateException("Expect asset not found"));
assertThat(test3.getTestFlag(), equalTo(true));
}
}
Aggregations