Skip to content

Commit

Permalink
SHIBUI-1788
Browse files Browse the repository at this point in the history
Refactored event notification to use Spring event model
  • Loading branch information
chasegawa committed Jun 10, 2021
1 parent 78ae4d0 commit e3e0ca3
Show file tree
Hide file tree
Showing 5 changed files with 159 additions and 163 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
import edu.internet2.tier.shibboleth.admin.ui.domain.IRelyingPartyOverrideProperty;
import edu.internet2.tier.shibboleth.admin.ui.domain.RelyingPartyOverrideProperty;
import edu.internet2.tier.shibboleth.admin.ui.service.CustomEntityAttributesDefinitionService;
import edu.internet2.tier.shibboleth.admin.ui.service.ICustomEntityAttributesDefinitionListener;
import edu.internet2.tier.shibboleth.admin.ui.service.events.CustomEntityAttributeDefinitionChangeEvent;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Configuration;

import java.util.ArrayList;
Expand All @@ -18,7 +19,7 @@

@Configuration
@ConfigurationProperties(prefix = "custom")
public class CustomPropertiesConfiguration implements ICustomEntityAttributesDefinitionListener {
public class CustomPropertiesConfiguration implements ApplicationListener<CustomEntityAttributeDefinitionChangeEvent> {
private List<? extends Map<String, String>> attributes = new ArrayList<>();

private CustomEntityAttributesDefinitionService ceadService;
Expand All @@ -41,15 +42,6 @@ private void buildRelyingPartyOverrides() {
}
}

/**
* We don't know what change occurred, so the easiest thing to do is just rebuild our map of overrides.
* (especially since the small occurrence of this and number of items makes doing this ok perf-wise).
*/
@Override
public void customEntityAttributesDefinitionChangeOccurred() {
buildRelyingPartyOverrides();
}

public List<? extends Map<String, String>> getAttributes() {
return attributes;
}
Expand All @@ -58,15 +50,21 @@ public List<IRelyingPartyOverrideProperty> getOverrides() {
return new ArrayList<>(overrides.values());
}

/**
* We don't know what change occurred, so the easiest thing to do is just rebuild our map of overrides.
* (especially since the small occurrence of this and number of items makes doing this ok perf-wise).
*/
@Override
public void onApplicationEvent(CustomEntityAttributeDefinitionChangeEvent arg0) {
buildRelyingPartyOverrides();
}

@PostConstruct
public void postConstruct() {
// Register with service to get the updates when changes are made to the DB definitions
ceadService.addCustomEntityAttributesDefinitionListener(this);

// Make sure we have the right data
buildRelyingPartyOverrides();
}

public void setAttributes(List<? extends Map<String, String>> attributes) {
this.attributes = attributes;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

public interface CustomEntityAttributesDefinitionService {

void addCustomEntityAttributesDefinitionListener(ICustomEntityAttributesDefinitionListener listener);

CustomEntityAttributeDefinition createOrUpdateDefinition(CustomEntityAttributeDefinition definition);

void deleteDefinition(CustomEntityAttributeDefinition definition);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,38 +1,34 @@
package edu.internet2.tier.shibboleth.admin.ui.service;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.EntityManager;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import edu.internet2.tier.shibboleth.admin.ui.domain.CustomEntityAttributeDefinition;
import edu.internet2.tier.shibboleth.admin.ui.domain.filters.CustomEntityAttributeFilterValue;
import edu.internet2.tier.shibboleth.admin.ui.repository.CustomEntityAttributeDefinitionRepository;
import edu.internet2.tier.shibboleth.admin.ui.repository.CustomEntityAttributeFilterValueRepository;
import edu.internet2.tier.shibboleth.admin.ui.service.events.CustomEntityAttributeDefinitionChangeEvent;

@Service
public class CustomEntityAttributesDefinitionServiceImpl implements CustomEntityAttributesDefinitionService {
public class CustomEntityAttributesDefinitionServiceImpl implements CustomEntityAttributesDefinitionService {
@Autowired
private ApplicationEventPublisher applicationEventPublisher;

@Autowired
CustomEntityAttributeFilterValueRepository customEntityAttributeFilterValueRepository;

@Autowired
EntityManager entityManager;

private List<ICustomEntityAttributesDefinitionListener> listeners = new ArrayList<>();

@Autowired
private CustomEntityAttributeDefinitionRepository repository;

@Override
public void addCustomEntityAttributesDefinitionListener(ICustomEntityAttributesDefinitionListener listener) {
listeners.add(listener);
}


@Override
@Transactional
public CustomEntityAttributeDefinition createOrUpdateDefinition(CustomEntityAttributeDefinition definition) {
Expand Down Expand Up @@ -67,6 +63,6 @@ public List<CustomEntityAttributeDefinition> getAllDefinitions() {
}

private void notifyListeners() {
listeners.forEach(l -> l.customEntityAttributesDefinitionChangeOccurred());
applicationEventPublisher.publishEvent(new CustomEntityAttributeDefinitionChangeEvent(this));
}
}

This file was deleted.

Loading

0 comments on commit e3e0ca3

Please sign in to comment.