use of org.motechproject.mds.listener.MotechLifecycleListener in project motech by motech.
the class InstanceLifecycleListenerProcessorTest method shouldReturnCorrectListeners.
@Test
public void shouldReturnCorrectListeners() {
processor.processAnnotations(bundle);
jdoListenerRegistryService.updateEntityNames();
jdoListenerRegistryService.removeInactiveListeners(ENTITY_NAMES);
List<MotechLifecycleListener> listeners = jdoListenerRegistryService.getListeners();
Set<String> postCreateMethods = new HashSet<>();
postCreateMethods.add("correctListener");
Set<String> postDeleteMethods = new HashSet<>();
postDeleteMethods.add("correctListener");
postDeleteMethods.add("correctPostDeleteListener");
assertEquals(2, listeners.size());
for (MotechLifecycleListener listener : listeners) {
if (!listener.getPackageName().isEmpty()) {
assertEquals(Arrays.asList("org.motechproject.Test"), listener.getEntityNames());
} else {
assertEquals(Sample.class.getName(), listener.getParameterType());
assertEquals(Sample.class, listener.getService());
assertEquals(postCreateMethods, listener.getMethodsByType().get(InstanceLifecycleListenerType.POST_CREATE));
assertEquals(postDeleteMethods, listener.getMethodsByType().get(InstanceLifecycleListenerType.POST_DELETE));
}
}
}
use of org.motechproject.mds.listener.MotechLifecycleListener in project motech by motech.
the class JdoListenerRegistryServiceImpl method getEntitiesListenerStr.
@Override
public String getEntitiesListenerStr() {
StringBuilder entityListenerNames = new StringBuilder();
Set<String> entityNames = new HashSet<>();
// duplicate entity names using set collection.
for (MotechLifecycleListener listener : listeners) {
entityNames.addAll(listener.getEntityNames());
}
entityNames.addAll(entitiesWithListeners);
for (String entityName : entityNames) {
entityListenerNames.append(entityName).append('\n');
}
return entityListenerNames.toString();
}
use of org.motechproject.mds.listener.MotechLifecycleListener in project motech by motech.
the class JdoListenerRegistryServiceImpl method removeInactiveListeners.
@Override
public void removeInactiveListeners(String entitiesNames) {
Set<String> entitiesList = getEntities(entitiesNames);
List<MotechLifecycleListener> listenersToRemove = new ArrayList<>();
for (MotechLifecycleListener listener : listeners) {
if (Collections.disjoint(entitiesList, listener.getEntityNames())) {
listenersToRemove.add(listener);
if (!listener.getPackageName().isEmpty() && listener.getEntityNames().isEmpty()) {
LOGGER.warn("The InstanceLifecycleListener from service {} for {} was removed, " + "because in its package {} there were no persistable classes.", listener.getService(), listener.getParameterType(), listener.getPackageName());
} else {
LOGGER.warn("The InstanceLifecycleListener from service {} for {} was removed, " + "because {} is not a persistable class.", listener.getService(), listener.getParameterType(), listener.getParameterType());
}
}
}
listeners.removeAll(listenersToRemove);
}
Aggregations