Search in sources :

Example 1 with Resource

use of eu.openminted.registry.core.domain.Resource in project resource-catalogue by madgeek-arc.

the class StatisticsManager method events.

public Map<DateTime, Map<String, Long>> events(Event.UserActionType type, Date from, Date to, Interval by) {
    Map<DateTime, Map<String, Long>> results = new LinkedHashMap<>();
    Paging<Resource> resources = searchService.cqlQuery(String.format("type=\"%s\" AND creation_date > %s AND creation_date < %s", type, from.toInstant().toEpochMilli(), to.toInstant().toEpochMilli()), "event", maxQuantity, 0, "creation_date", "ASC");
    List<Event> events = resources.getResults().stream().map(resource -> parserService.deserialize(resource, Event.class)).collect(Collectors.toList());
    DateTime start = new DateTime(from);
    DateTime stop = new DateTime(to);
    Map<DateTime, List<Event>> eventsByDate = new LinkedHashMap<>();
    start.plusWeeks(1);
    while (start.getMillis() <= stop.getMillis()) {
        DateTime endDate = addInterval(start, by);
        List<Event> weekEvents = new LinkedList<>();
        events = events.stream().map(event -> {
            if (endDate.isAfter(event.getInstant())) {
                weekEvents.add(event);
                return null;
            } else
                return event;
        }).filter(Objects::nonNull).collect(Collectors.toList());
        // weekEvents.sort(Comparator.comparing(Event::getService));
        eventsByDate.put(start, weekEvents);
        start = endDate;
    }
    for (Map.Entry<DateTime, List<Event>> weekEntry : eventsByDate.entrySet()) {
        Map<String, Long> weekResults = weekEntry.getValue().stream().collect(Collectors.groupingBy(Event::getService, Collectors.counting()));
        weekResults = weekResults.entrySet().stream().sorted(Map.Entry.comparingByKey()).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (oldValue, newValue) -> oldValue, LinkedHashMap::new));
        results.put(weekEntry.getKey(), weekResults);
    }
    return results;
}
Also used : Resource(eu.openminted.registry.core.domain.Resource) MapValues(eu.einfracentral.dto.MapValues) Cacheable(org.springframework.cache.annotation.Cacheable) InfraServiceManager(eu.einfracentral.registry.manager.InfraServiceManager) NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate) Autowired(org.springframework.beans.factory.annotation.Autowired) Service(eu.einfracentral.domain.Service) QueryBuilders(org.elasticsearch.index.query.QueryBuilders) PgArray(org.postgresql.jdbc.PgArray) ServiceException(eu.openminted.registry.core.service.ServiceException) Logger(org.apache.log4j.Logger) SearchResponse(org.elasticsearch.action.search.SearchResponse) RequestOptions(org.elasticsearch.client.RequestOptions) DateHistogramInterval(org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval) SearchType(org.elasticsearch.action.search.SearchType) Paging(eu.openminted.registry.core.domain.Paging) Terms(org.elasticsearch.search.aggregations.bucket.terms.Terms) ProviderService(eu.einfracentral.registry.service.ProviderService) FacetFilter(eu.openminted.registry.core.domain.FacetFilter) PlaceCount(eu.einfracentral.dto.PlaceCount) Collectors(java.util.stream.Collectors) ParserService(eu.openminted.registry.core.service.ParserService) PipelineAggregatorBuilders(org.elasticsearch.search.aggregations.PipelineAggregatorBuilders) ProviderBundle(eu.einfracentral.domain.ProviderBundle) StatisticsService(eu.einfracentral.service.StatisticsService) MultiBucketsAggregation(org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation) CACHE_VISITS(eu.einfracentral.config.CacheConfig.CACHE_VISITS) Authentication(org.springframework.security.core.Authentication) java.util(java.util) SearchService(eu.openminted.registry.core.service.SearchService) SimpleValue(org.elasticsearch.search.aggregations.pipeline.SimpleValue) Histogram(org.elasticsearch.search.aggregations.bucket.histogram.Histogram) MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) SearchRequest(org.elasticsearch.action.search.SearchRequest) SQLException(java.sql.SQLException) SearchSourceBuilder(org.elasticsearch.search.builder.SearchSourceBuilder) DataSource(javax.sql.DataSource) Value(eu.einfracentral.dto.Value) EnableScheduling(org.springframework.scheduling.annotation.EnableScheduling) Event(eu.einfracentral.domain.Event) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) DateTime(org.joda.time.DateTime) ParsedDateHistogram(org.elasticsearch.search.aggregations.bucket.histogram.ParsedDateHistogram) AggregationBuilders(org.elasticsearch.search.aggregations.AggregationBuilders) IOException(java.io.IOException) RestHighLevelClient(org.elasticsearch.client.RestHighLevelClient) DateHistogramAggregationBuilder(org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramAggregationBuilder) Component(org.springframework.stereotype.Component) InfraService(eu.einfracentral.domain.InfraService) AnalyticsService(eu.einfracentral.service.AnalyticsService) LogManager(org.apache.log4j.LogManager) VocabularyService(eu.einfracentral.registry.service.VocabularyService) Resource(eu.openminted.registry.core.domain.Resource) DateTime(org.joda.time.DateTime) Event(eu.einfracentral.domain.Event)

Example 2 with Resource

use of eu.openminted.registry.core.domain.Resource in project resource-catalogue by madgeek-arc.

the class VocabularyManager method update.

@Override
@CacheEvict(value = { CACHE_VOCABULARIES, CACHE_VOCABULARY_MAP, CACHE_VOCABULARY_TREE }, allEntries = true)
public Vocabulary update(Vocabulary vocabulary, Authentication auth) {
    Resource existing = whereID(vocabulary.getId(), true);
    String serialized = serialize(vocabulary);
    serialized = serialized.replace(":tns", "");
    serialized = serialized.replace("tns:", "");
    existing.setPayload(serialized);
    existing.setResourceType(resourceType);
    resourceService.updateResource(existing);
    logger.debug("Updating Vocabulary {}", vocabulary);
    return vocabulary;
}
Also used : Resource(eu.openminted.registry.core.domain.Resource) CacheEvict(org.springframework.cache.annotation.CacheEvict)

Example 3 with Resource

use of eu.openminted.registry.core.domain.Resource in project resource-catalogue by madgeek-arc.

the class VocabularyManager method add.

@Override
@CacheEvict(value = { CACHE_VOCABULARIES, CACHE_VOCABULARY_MAP, CACHE_VOCABULARY_TREE }, allEntries = true)
public Vocabulary add(Vocabulary vocabulary, Authentication auth) {
    if (vocabulary.getId() == null || "".equals(vocabulary.getId())) {
        String id = vocabulary.getName().toLowerCase();
        id = id.replace(" ", "_");
        id = id.replace("&", "and");
        if (vocabulary.getParentId() != null) {
            id = String.format("%s-%s", vocabulary.getParentId().toLowerCase(), id);
        }
        vocabulary.setId(id);
    }
    if (exists(vocabulary)) {
        logger.error("{} already exists!\n{}", resourceType.getName(), vocabulary);
        throw new ResourceException(String.format("%s already exists!", resourceType.getName()), HttpStatus.CONFLICT);
    }
    String serialized = serialize(vocabulary);
    Resource created = new Resource();
    created.setPayload(serialized);
    created.setResourceType(resourceType);
    resourceService.addResource(created);
    logger.debug("Adding Vocabulary {}", vocabulary);
    return vocabulary;
}
Also used : Resource(eu.openminted.registry.core.domain.Resource) ResourceException(eu.einfracentral.exception.ResourceException) CacheEvict(org.springframework.cache.annotation.CacheEvict)

Example 4 with Resource

use of eu.openminted.registry.core.domain.Resource in project resource-catalogue by madgeek-arc.

the class PendingProviderManager method transformToPending.

@Override
@CacheEvict(value = CACHE_PROVIDERS, allEntries = true)
public ProviderBundle transformToPending(String providerId, Authentication auth) {
    logger.trace("User '{}' is attempting to transform the Active Provider with id '{}' to Pending", auth, providerId);
    Resource resource = providerManager.getResource(providerId);
    // make sure that resource type is present
    resource.setResourceTypeName("provider");
    resourceService.changeResourceType(resource, resourceType);
    return deserialize(resource);
}
Also used : Resource(eu.openminted.registry.core.domain.Resource) CacheEvict(org.springframework.cache.annotation.CacheEvict)

Example 5 with Resource

use of eu.openminted.registry.core.domain.Resource in project resource-catalogue by madgeek-arc.

the class PendingProviderManager method update.

@Override
@CacheEvict(value = CACHE_PROVIDERS, allEntries = true)
public ProviderBundle update(ProviderBundle providerBundle, Authentication auth) {
    logger.trace("User '{}' is attempting to update the Pending Provider: {}", auth, providerBundle);
    providerBundle.setMetadata(Metadata.updateMetadata(providerBundle.getMetadata(), User.of(auth).getFullName(), User.of(auth).getEmail()));
    // get existing resource
    Resource existing = whereID(providerBundle.getId(), true);
    // save existing resource with new payload
    existing.setPayload(serialize(providerBundle));
    existing.setResourceType(resourceType);
    resourceService.updateResource(existing);
    logger.debug("Updating PendingProvider: {}", providerBundle);
    return providerBundle;
}
Also used : Resource(eu.openminted.registry.core.domain.Resource) CacheEvict(org.springframework.cache.annotation.CacheEvict)

Aggregations

Resource (eu.openminted.registry.core.domain.Resource)13 CacheEvict (org.springframework.cache.annotation.CacheEvict)10 ResourceException (eu.einfracentral.exception.ResourceException)4 ResourceType (eu.openminted.registry.core.domain.ResourceType)4 ResourceNotFoundException (eu.openminted.registry.core.exception.ResourceNotFoundException)4 ArrayList (java.util.ArrayList)4 CACHE_VISITS (eu.einfracentral.config.CacheConfig.CACHE_VISITS)1 Event (eu.einfracentral.domain.Event)1 InfraService (eu.einfracentral.domain.InfraService)1 ProviderBundle (eu.einfracentral.domain.ProviderBundle)1 Service (eu.einfracentral.domain.Service)1 MapValues (eu.einfracentral.dto.MapValues)1 PlaceCount (eu.einfracentral.dto.PlaceCount)1 Value (eu.einfracentral.dto.Value)1 InfraServiceManager (eu.einfracentral.registry.manager.InfraServiceManager)1 ProviderService (eu.einfracentral.registry.service.ProviderService)1 VocabularyService (eu.einfracentral.registry.service.VocabularyService)1 AnalyticsService (eu.einfracentral.service.AnalyticsService)1 StatisticsService (eu.einfracentral.service.StatisticsService)1 FacetFilter (eu.openminted.registry.core.domain.FacetFilter)1