Search in sources :

Example 1 with ContentPackMetadata

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;
}
Also used : ContentPackInstallation(org.graylog2.contentpacks.model.ContentPackInstallation) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map) ModelId(org.graylog2.contentpacks.model.ModelId) ContentPackMetadata(org.graylog2.rest.models.system.contentpacks.responses.ContentPackMetadata)

Example 2 with ContentPackMetadata

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);
}
Also used : ContentPackList(org.graylog2.rest.models.system.contentpacks.responses.ContentPackList) ContentPack(org.graylog2.contentpacks.model.ContentPack) Map(java.util.Map) ModelId(org.graylog2.contentpacks.model.ModelId) Test(org.junit.Test)

Aggregations

Map (java.util.Map)2 ModelId (org.graylog2.contentpacks.model.ModelId)2 HashMap (java.util.HashMap)1 ContentPack (org.graylog2.contentpacks.model.ContentPack)1 ContentPackInstallation (org.graylog2.contentpacks.model.ContentPackInstallation)1 ContentPackList (org.graylog2.rest.models.system.contentpacks.responses.ContentPackList)1 ContentPackMetadata (org.graylog2.rest.models.system.contentpacks.responses.ContentPackMetadata)1 Test (org.junit.Test)1