Search in sources :

Example 6 with EventListener

use of org.springframework.context.event.EventListener in project metacat by Netflix.

the class SNSNotificationServiceImpl method notifyOfPartitionDeletion.

/**
     * {@inheritDoc}
     */
@Override
@EventListener
public void notifyOfPartitionDeletion(@NonNull final MetacatDeleteTablePartitionPostEvent event) {
    log.debug("Received DeleteTablePartition event {}", event);
    final String name = event.getName().toString();
    final long timestamp = event.getRequestContext().getTimestamp();
    final String requestId = event.getRequestContext().getId();
    DeletePartitionMessage message = null;
    try {
        for (final String partitionId : event.getPartitionIds()) {
            message = new DeletePartitionMessage(UUID.randomUUID().toString(), timestamp, requestId, name, partitionId);
            this.publishNotification(this.partitionTopicArn, message);
            this.registry.counter(this.registry.createId(Metrics.CounterSNSNotificationPartitionDelete.name()).withTags(Metrics.statusSuccessMap)).increment();
            log.debug("Published delete partition message {} on {}", message, this.partitionTopicArn);
        }
    } catch (final Exception e) {
        handleException(event.getName(), "Unable to publish partition deletion notification", Metrics.CounterSNSNotificationPartitionDelete.name(), message, e);
    }
    UpdateTablePartitionsMessage tableMessage = null;
    try {
        // Publish a global message stating how many partitions were updated for the table to the table topic
        tableMessage = new UpdateTablePartitionsMessage(UUID.randomUUID().toString(), timestamp, requestId, name, new TablePartitionsUpdatePayload(0, event.getPartitionIds().size()));
        this.publishNotification(this.tableTopicArn, tableMessage);
        this.registry.counter(this.registry.createId(Metrics.CounterSNSNotificationTablePartitionDelete.name()).withTags(Metrics.statusSuccessMap)).increment();
    } catch (final Exception e) {
        this.handleException(event.getName(), "Unable to publish table partition delete notification", Metrics.CounterSNSNotificationTablePartitionDelete.name(), tableMessage, e);
    }
}
Also used : TablePartitionsUpdatePayload(com.netflix.metacat.common.dto.notifications.sns.payloads.TablePartitionsUpdatePayload) UpdateTablePartitionsMessage(com.netflix.metacat.common.dto.notifications.sns.messages.UpdateTablePartitionsMessage) DeletePartitionMessage(com.netflix.metacat.common.dto.notifications.sns.messages.DeletePartitionMessage) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) EventListener(org.springframework.context.event.EventListener)

Example 7 with EventListener

use of org.springframework.context.event.EventListener in project metacat by Netflix.

the class SNSNotificationServiceImpl method notifyOfTableDeletion.

/**
     * {@inheritDoc}
     */
@Override
@EventListener
public void notifyOfTableDeletion(@NonNull final MetacatDeleteTablePostEvent event) {
    log.debug("Received DeleteTableEvent {}", event);
    DeleteTableMessage message = null;
    try {
        message = new DeleteTableMessage(UUID.randomUUID().toString(), event.getRequestContext().getTimestamp(), event.getRequestContext().getId(), event.getName().toString(), event.getTable());
        this.publishNotification(this.tableTopicArn, message);
        this.registry.counter(this.registry.createId(Metrics.CounterSNSNotificationTableDelete.name()).withTags(Metrics.statusSuccessMap)).increment();
    } catch (final Exception e) {
        this.handleException(event.getName(), "Unable to publish delete table notification", Metrics.CounterSNSNotificationTableDelete.name(), message, e);
    }
}
Also used : DeleteTableMessage(com.netflix.metacat.common.dto.notifications.sns.messages.DeleteTableMessage) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) EventListener(org.springframework.context.event.EventListener)

Example 8 with EventListener

use of org.springframework.context.event.EventListener in project SpringStepByStep by JavaProgrammerLB.

the class UserServiceImpl method afterApplicationReady.

@Override
@EventListener
@Transactional(propagation = Propagation.REQUIRED, readOnly = false)
public void afterApplicationReady(ApplicationReadyEvent event) {
    if (!userRepository.findByEmail(adminEmail).isPresent()) {
        User user = new User();
        user.setEmail(adminEmail);
        user.setName(adminName);
        user.setPassword(adminPassword);
        user.setPassword(passwordEncoder.encode(adminPassword));
        user.getRoles().add(Role.ADMIN);
        userRepository.save(user);
    }
}
Also used : User(com.naturalprogrammer.spring.tutorial.domain.User) EventListener(org.springframework.context.event.EventListener) Transactional(org.springframework.transaction.annotation.Transactional)

Example 9 with EventListener

use of org.springframework.context.event.EventListener in project dhis2-core by dhis2.

the class DefaultSchemaService method handleContextRefresh.

@EventListener
public void handleContextRefresh(ContextRefreshedEvent contextRefreshedEvent) {
    I18n i18n = i18nManager.getI18n();
    for (SchemaDescriptor descriptor : descriptors) {
        Schema schema = descriptor.getSchema();
        if (sessionFactory.getClassMetadata(schema.getKlass()) != null) {
            schema.setPersisted(true);
        }
        schema.setDisplayName(i18n.getString("schema_class_" + schema.getKlass().getName()));
        if (schema.getProperties().isEmpty()) {
            schema.setPropertyMap(Maps.newHashMap(propertyIntrospectorService.getPropertiesMap(schema.getKlass())));
        }
        classSchemaMap.put(schema.getKlass(), schema);
        singularSchemaMap.put(schema.getSingular(), schema);
        pluralSchemaMap.put(schema.getPlural(), schema);
        updateSelf(schema);
        schema.getPersistedProperties();
        schema.getNonPersistedProperties();
        schema.getReadableProperties();
        schema.getEmbeddedObjectProperties();
    }
}
Also used : I18n(org.hisp.dhis.i18n.I18n) EventListener(org.springframework.context.event.EventListener)

Example 10 with EventListener

use of org.springframework.context.event.EventListener in project cas by apereo.

the class DefaultCasEventListener method handleCasAuthenticationPolicyFailureEvent.

/**
     * Handle cas authentication policy failure event.
     *
     * @param event the event
     */
@EventListener
public void handleCasAuthenticationPolicyFailureEvent(final CasAuthenticationPolicyFailureEvent event) {
    if (this.casEventRepository != null) {
        final CasEvent dto = prepareCasEvent(event);
        dto.setPrincipalId(event.getAuthentication().getPrincipal().getId());
        dto.putId(CasAuthenticationPolicyFailureEvent.class.getSimpleName());
        this.casEventRepository.save(dto);
    }
}
Also used : AbstractCasEvent(org.apereo.cas.support.events.AbstractCasEvent) CasEvent(org.apereo.cas.support.events.dao.CasEvent) CasAuthenticationPolicyFailureEvent(org.apereo.cas.support.events.authentication.CasAuthenticationPolicyFailureEvent) EventListener(org.springframework.context.event.EventListener)

Aggregations

EventListener (org.springframework.context.event.EventListener)19 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)6 IOException (java.io.IOException)6 TableDto (com.netflix.metacat.common.dto.TableDto)5 AbstractCasEvent (org.apereo.cas.support.events.AbstractCasEvent)4 CasEvent (org.apereo.cas.support.events.dao.CasEvent)4 DatabaseDto (com.netflix.metacat.common.dto.DatabaseDto)3 PartitionDto (com.netflix.metacat.common.dto.PartitionDto)2 UpdateTableMessage (com.netflix.metacat.common.dto.notifications.sns.messages.UpdateTableMessage)2 UpdateTablePartitionsMessage (com.netflix.metacat.common.dto.notifications.sns.messages.UpdateTablePartitionsMessage)2 TablePartitionsUpdatePayload (com.netflix.metacat.common.dto.notifications.sns.payloads.TablePartitionsUpdatePayload)2 CasAuthenticationPolicyFailureEvent (org.apereo.cas.support.events.authentication.CasAuthenticationPolicyFailureEvent)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 User (com.naturalprogrammer.spring.tutorial.domain.User)1 MetacatRequestContext (com.netflix.metacat.common.MetacatRequestContext)1 AddPartitionMessage (com.netflix.metacat.common.dto.notifications.sns.messages.AddPartitionMessage)1 CreateTableMessage (com.netflix.metacat.common.dto.notifications.sns.messages.CreateTableMessage)1 DeletePartitionMessage (com.netflix.metacat.common.dto.notifications.sns.messages.DeletePartitionMessage)1 DeleteTableMessage (com.netflix.metacat.common.dto.notifications.sns.messages.DeleteTableMessage)1 MetacatJsonLocator (com.netflix.metacat.common.json.MetacatJsonLocator)1