Search in sources :

Example 51 with CacheEvict

use of org.springframework.cache.annotation.CacheEvict in project entando-core by entando.

the class GuiFragmentManager method updateGuiFragment.

@Override
@CacheEvict(value = ICacheInfoManager.DEFAULT_CACHE_NAME, key = "'GuiFragment_'.concat(#guiFragment.code)")
// TODO improve group handling
@CacheInfoEvict(value = ICacheInfoManager.DEFAULT_CACHE_NAME, groups = "'GuiFragment_uniqueByWidgetTypeGroup,GuiFragment_codesByWidgetTypeGroup'")
public void updateGuiFragment(GuiFragment guiFragment) throws ApsSystemException {
    try {
        this.getGuiFragmentDAO().updateGuiFragment(guiFragment);
        this.notifyGuiFragmentChangedEvent(guiFragment, GuiFragmentChangedEvent.UPDATE_OPERATION_CODE);
    } catch (Throwable t) {
        logger.error("Error updating GuiFragment", t);
        throw new ApsSystemException("Error updating GuiFragment " + guiFragment, t);
    }
}
Also used : ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) CacheEvict(org.springframework.cache.annotation.CacheEvict) CacheInfoEvict(org.entando.entando.aps.system.services.cache.CacheInfoEvict)

Example 52 with CacheEvict

use of org.springframework.cache.annotation.CacheEvict in project mica2 by obiba.

the class MicaConfigService method save.

@CacheEvict(value = "micaConfig", allEntries = true)
public void save(@NotNull @Valid MicaConfig micaConfig) {
    MicaConfig savedConfig = getOrCreateMicaConfig();
    ArrayList<String> removedRoles = Lists.newArrayList(Sets.difference(Sets.newHashSet(savedConfig.getRoles()), Sets.newHashSet(micaConfig.getRoles())));
    BeanUtils.copyProperties(micaConfig, savedConfig, "id", "version", "createdBy", "createdDate", "lastModifiedBy", "lastModifiedDate", "secretKey", "micaVersion");
    if (micaConfig.getMicaVersion() != null)
        savedConfig.setMicaVersion(micaConfig.getMicaVersion());
    micaConfigRepository.save(savedConfig);
    eventBus.post(new MicaConfigUpdatedEvent(getConfig(), removedRoles));
}
Also used : MicaConfig(org.obiba.mica.micaConfig.domain.MicaConfig) MicaConfigUpdatedEvent(org.obiba.mica.micaConfig.event.MicaConfigUpdatedEvent) CacheEvict(org.springframework.cache.annotation.CacheEvict)

Example 53 with CacheEvict

use of org.springframework.cache.annotation.CacheEvict in project ArachneCentralAPI by OHDSI.

the class CommentServiceImpl method addComment.

@CacheEvict(cacheNames = "comments", allEntries = true)
@Override
@PreAuthorize("hasPermission(#topicId, 'CommentTopic', " + "T(com.odysseusinc.arachne.portal.security.ArachnePermission).EDIT_INSIGHT)")
public Comment addComment(Long topicId, Long parentId, Comment comment) {
    comment.setId(null);
    comment.setDate(new Date());
    final CommentTopic topic = commentTopicRepository.getOne(topicId);
    comment.setTopic(topic);
    if (parentId != null) {
        final Comment parent = commentRepository.findById(parentId).orElse(null);
        comment.setParent(parent);
    }
    return commentRepository.save(comment);
}
Also used : Comment(com.odysseusinc.arachne.portal.model.Comment) CommentTopic(com.odysseusinc.arachne.portal.model.CommentTopic) Date(java.util.Date) CacheEvict(org.springframework.cache.annotation.CacheEvict) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 54 with CacheEvict

use of org.springframework.cache.annotation.CacheEvict in project codekvast by crispab.

the class CustomerServiceImpl method deleteCustomerByExternalId.

@Override
@Transactional(rollbackFor = Exception.class)
@CacheEvict(value = CUSTOMERS_CACHE, allEntries = true)
public void deleteCustomerByExternalId(@NonNull String source, String externalId) {
    CustomerData customerData = getCustomerDataByExternalId(source, externalId);
    long customerId = customerData.getCustomerId();
    deleteFromTable("invocations", customerId);
    deleteFromTable("method_locations", customerId);
    deleteFromTable("methods", customerId);
    deleteFromTable("jvms", customerId);
    deleteFromTable("environments", customerId);
    deleteFromTable("applications", customerId);
    deleteFromTable("users", customerId);
    deleteFromTable("agent_state", customerId);
    deleteFromTable("price_plan_overrides", customerId);
    deleteFromTable("heroku_details", customerId);
    deleteFromTable("facts", customerId);
    deleteFromTable("customers", customerId);
    eventService.send(CustomerDeletedEvent.builder().customerId(customerId).name(customerData.getCustomerName()).displayName(customerData.getDisplayName()).source(customerData.getSource()).plan(customerData.getPricePlan().getName()).build());
    slackService.sendNotification("Deleted `" + customerData + "`", SlackService.Channel.BUSINESS_EVENTS);
    logger.info("Deleted customer {}", customerData);
}
Also used : CustomerData(io.codekvast.common.customer.CustomerData) CacheEvict(org.springframework.cache.annotation.CacheEvict) Transactional(org.springframework.transaction.annotation.Transactional)

Example 55 with CacheEvict

use of org.springframework.cache.annotation.CacheEvict in project codekvast by crispab.

the class CustomerServiceImpl method changePlanForExternalId.

@Override
@Transactional(rollbackFor = Exception.class)
@CacheEvict(value = CUSTOMERS_CACHE, allEntries = true)
public void changePlanForExternalId(String source, @NonNull String externalId, @NonNull String newPlanName) {
    CustomerData customerData = getCustomerDataByExternalId(source, externalId);
    PricePlan oldEffectivePricePlan = customerData.getPricePlan();
    String oldPlanName = oldEffectivePricePlan.getName();
    if (newPlanName.equals(oldPlanName)) {
        logger.info("{} is already on plan '{}'", customerData, newPlanName);
        return;
    }
    int count = jdbcTemplate.update("UPDATE customers SET plan = ? WHERE source = ? AND externalId = ? ORDER BY id ", newPlanName, source, externalId);
    if (count == 0) {
        logger.error("Failed to change plan for customer {} from '{}' to '{}'", customerData.getDisplayName(), oldPlanName, newPlanName);
        return;
    }
    String logMessage = String.format("Changed plan for customer %s from '%s' to '%s'", customerData.getDisplayName(), oldPlanName, newPlanName);
    logger.info(logMessage);
    slackService.sendNotification(logMessage, SlackService.Channel.BUSINESS_EVENTS);
    eventService.send(PlanChangedEvent.builder().customerId(customerData.getCustomerId()).oldPlan(oldPlanName).newPlan(newPlanName).build());
    count = jdbcTemplate.update("DELETE FROM price_plan_overrides WHERE customerId = ?", customerData.getCustomerId());
    if (count > 0) {
        PricePlan newEffectivePricePlan = PricePlan.of(PricePlanDefaults.ofDatabaseName(newPlanName));
        eventService.send(PlanOverridesDeletedEvent.builder().customerId(customerData.getCustomerId()).oldEffectivePlan(oldEffectivePricePlan).newEffectivePlan(newEffectivePricePlan).build());
        String pricePlanOverridesMessage = String.format("Removed price plan overrides for customer %s, effective price plan changed from `%s` to `%s`", customerData.getDisplayName(), oldEffectivePricePlan, newEffectivePricePlan);
        slackService.sendNotification(pricePlanOverridesMessage, SlackService.Channel.BUSINESS_EVENTS);
        logger.warn(pricePlanOverridesMessage);
    }
}
Also used : CustomerData(io.codekvast.common.customer.CustomerData) PricePlan(io.codekvast.common.customer.PricePlan) CacheEvict(org.springframework.cache.annotation.CacheEvict) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

CacheEvict (org.springframework.cache.annotation.CacheEvict)64 Transactional (org.springframework.transaction.annotation.Transactional)17 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)14 Date (java.util.Date)8 ArrayList (java.util.ArrayList)6 CacheInfoEvict (org.entando.entando.aps.system.services.cache.CacheInfoEvict)5 DataValidationException (org.thingsboard.server.dao.exception.DataValidationException)5 EntityView (org.thingsboard.server.common.data.EntityView)4 QUser (com.github.liuweijw.business.admin.domain.QUser)3 MetacatRequestContext (com.netflix.metacat.common.MetacatRequestContext)3 ConnectorRequestContext (com.netflix.metacat.common.server.connectors.ConnectorRequestContext)3 ConnectorTableService (com.netflix.metacat.common.server.connectors.ConnectorTableService)3 ExecutionException (java.util.concurrent.ExecutionException)3 ConstraintViolationException (org.hibernate.exception.ConstraintViolationException)3 QMenu (com.github.liuweijw.business.admin.domain.QMenu)2 QRole (com.github.liuweijw.business.admin.domain.QRole)2 QUserRole (com.github.liuweijw.business.admin.domain.QUserRole)2 Role (com.github.liuweijw.business.admin.domain.Role)2 User (com.github.liuweijw.business.admin.domain.User)2 UserRole (com.github.liuweijw.business.admin.domain.UserRole)2