use of org.graylog2.rest.models.system.contentpacks.responses.ContentPackMetadata in project graylog2-server by Graylog2.
the class ContentPackInstallationPersistenceService method getInstallationMetadata.
public Map<ModelId, Map<Integer, ContentPackMetadata>> getInstallationMetadata(Set<ModelId> ids) {
final Set<ContentPackInstallation> contentPackInstallations = findByContentPackIds(ids);
Map<ModelId, Map<Integer, ContentPackMetadata>> installationMetaData = new HashMap<>();
for (ContentPackInstallation installation : contentPackInstallations) {
Map<Integer, ContentPackMetadata> metadataMap = installationMetaData.get(installation.contentPackId());
if (metadataMap == null) {
metadataMap = new HashMap<>();
}
ContentPackMetadata metadata = metadataMap.get(installation.contentPackRevision());
int count = 1;
if (metadata != null) {
count = metadata.installationCount() + 1;
}
ContentPackMetadata newMetadata = ContentPackMetadata.create(count);
metadataMap.put(installation.contentPackRevision(), newMetadata);
installationMetaData.put(installation.contentPackId(), metadataMap);
}
return installationMetaData;
}
use of org.graylog2.rest.models.system.contentpacks.responses.ContentPackMetadata in project graylog2-server by Graylog2.
the class ContentPackResourceTest method listAndLatest.
@Test
public void listAndLatest() throws Exception {
final ContentPack contentPack = objectMapper.readValue(CONTENT_PACK, ContentPack.class);
final Set<ContentPack> contentPacks = Collections.singleton(contentPack);
final Map<ModelId, Map<Integer, ContentPackMetadata>> metaDataMap = Collections.emptyMap();
final ContentPackList expectedList = ContentPackList.create(contentPacks.size(), contentPacks, metaDataMap);
when(contentPackPersistenceService.loadAll()).thenReturn(Collections.singleton(contentPack));
final ContentPackList contentPackList = contentPackResource.listContentPacks();
verify(contentPackPersistenceService, times(1)).loadAll();
assertThat(contentPackList).isEqualTo(expectedList);
when(contentPackPersistenceService.loadAllLatest()).thenReturn(Collections.singleton(contentPack));
final ContentPackList contentPackLatest = contentPackResource.listLatestContentPacks();
verify(contentPackPersistenceService, times(1)).loadAll();
assertThat(contentPackLatest).isEqualTo(expectedList);
}
Aggregations