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;
}
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;
}
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;
}
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);
}
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;
}
Aggregations