Search in sources :

Example 16 with AccessKey

use of com.ctrip.framework.apollo.biz.entity.AccessKey in project apollo by ctripcorp.

the class AccessKeyService method create.

@Transactional
public AccessKey create(String appId, AccessKey entity) {
    long count = accessKeyRepository.countByAppId(appId);
    if (count >= ACCESSKEY_COUNT_LIMIT) {
        throw new BadRequestException("AccessKeys count limit exceeded");
    }
    entity.setId(0L);
    entity.setAppId(appId);
    entity.setDataChangeLastModifiedBy(entity.getDataChangeCreatedBy());
    AccessKey accessKey = accessKeyRepository.save(entity);
    auditService.audit(AccessKey.class.getSimpleName(), accessKey.getId(), Audit.OP.INSERT, accessKey.getDataChangeCreatedBy());
    return accessKey;
}
Also used : BadRequestException(com.ctrip.framework.apollo.common.exception.BadRequestException) AccessKey(com.ctrip.framework.apollo.biz.entity.AccessKey) Transactional(org.springframework.transaction.annotation.Transactional)

Example 17 with AccessKey

use of com.ctrip.framework.apollo.biz.entity.AccessKey in project apollo by ctripcorp.

the class AccessKeyService method delete.

@Transactional
public void delete(String appId, long id, String operator) {
    AccessKey accessKey = accessKeyRepository.findOneByAppIdAndId(appId, id);
    if (accessKey == null) {
        throw new BadRequestException("AccessKey not exist");
    }
    if (accessKey.isEnabled()) {
        throw new BadRequestException("AccessKey should disable first");
    }
    accessKey.setDeleted(Boolean.TRUE);
    accessKey.setDataChangeLastModifiedBy(operator);
    accessKeyRepository.save(accessKey);
    auditService.audit(AccessKey.class.getSimpleName(), id, Audit.OP.DELETE, operator);
}
Also used : BadRequestException(com.ctrip.framework.apollo.common.exception.BadRequestException) AccessKey(com.ctrip.framework.apollo.biz.entity.AccessKey) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

AccessKey (com.ctrip.framework.apollo.biz.entity.AccessKey)17 Test (org.junit.Test)5 AbstractIntegrationTest (com.ctrip.framework.apollo.biz.AbstractIntegrationTest)4 Date (java.util.Date)4 BadRequestException (com.ctrip.framework.apollo.common.exception.BadRequestException)3 Transactional (org.springframework.transaction.annotation.Transactional)3 PutMapping (org.springframework.web.bind.annotation.PutMapping)2 Instant (java.time.Instant)1 List (java.util.List)1 ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)1 Sql (org.springframework.test.context.jdbc.Sql)1 PostMapping (org.springframework.web.bind.annotation.PostMapping)1