Skip to content

Commit

Permalink
SHIBUI-2584
Browse files Browse the repository at this point in the history
Added additional beacon data collection to the output
  • Loading branch information
chasegawa committed Jul 7, 2023
1 parent 83631bd commit fd71b08
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

import edu.internet2.tier.shibboleth.admin.ui.domain.beacon.BeaconEvent;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.Date;
import java.util.List;

public interface BeaconEventRepository extends JpaRepository<BeaconEvent, Long> {

@Query(value = "SELECT be FROM BeaconEvent be WHERE be.eventTime >= :sinceDate")
List<BeaconEvent> getEventsSince(@Param("sinceDate") Date sinceDate);

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,17 @@
import edu.internet2.tier.shibboleth.admin.ui.service.beacon.BeaconDetail;
import edu.internet2.tier.shibboleth.admin.ui.service.beacon.ShibuiDetail;
import lombok.SneakyThrows;
import org.apache.commons.lang.time.DateUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.boot.actuate.health.HealthEndpoint;
import org.springframework.boot.actuate.info.InfoEndpoint;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class BeaconDataServiceImpl implements IBeaconDataService {
private ObjectMapper mapper;
Expand Down Expand Up @@ -66,10 +70,16 @@ public BeaconDataServiceImpl(String productName, InfoEndpoint info, String tierV
@Override
@SneakyThrows
public String getBeaconData() {
BeaconDetail detail = new BeaconDetail().setTbProduct(productName).setTbProductVersion(version).setTbTIERRelease(tierVersion).setShibui(getShibuiDetailData());
BeaconDetail detail = new BeaconDetail().setTbProduct(productName).setTbProductVersion(version).setTbTIERRelease(tierVersion).setShibui(getShibuiDetailData()).setBeaconEvents(getBeaconEvents());
return mapper.writeValueAsString(detail);
}

private Map<String, Long> getBeaconEvents() {
List<BeaconEvent> results = beaconEventRepository.getEventsSince(DateUtils.addDays(new Date(), -1));
Map<String, Long> counts = results.stream().collect(Collectors.groupingBy(e -> e.getEventName(), Collectors.counting()));
return counts;
}

@Override
public void addBeaconEvent(BeaconEvent event) {
beaconEventRepository.save(event);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package edu.internet2.tier.shibboleth.admin.ui.service.beacon;

import edu.internet2.tier.shibboleth.admin.ui.domain.beacon.BeaconEvent;
import lombok.Data;
import lombok.experimental.Accessors;

import java.util.List;
import java.util.Map;

@Data
@Accessors(chain = true)
public class BeaconDetail {
Expand All @@ -16,4 +20,6 @@ public class BeaconDetail {
private String tbMaintainer = "Unicon";

private ShibuiDetail shibui;

private Map<String, Long> beaconEvents;
}

0 comments on commit fd71b08

Please sign in to comment.