Search in sources :

Example 1 with CacheLock

use of run.halo.app.cache.lock.CacheLock in project halo by halo-dev.

the class InstallController method installBlog.

@PostMapping
@ResponseBody
@CacheLock
@ApiOperation("Initializes the blog")
public BaseResponse<String> installBlog(@RequestBody InstallParam installParam) {
    // Validate manually
    ValidationUtils.validate(installParam, CreateCheck.class);
    // Check is installed
    boolean isInstalled = optionService.getByPropertyOrDefault(PrimaryProperties.IS_INSTALLED, Boolean.class, false);
    if (isInstalled) {
        throw new BadRequestException("该博客已初始化,不能再次安装!");
    }
    // Initialize settings
    initSettings(installParam);
    // Create default user
    User user = createUser(installParam);
    // Create default category
    Category category = createDefaultCategoryIfAbsent();
    // Create default post
    PostDetailVO post = createDefaultPostIfAbsent(category);
    // Create default sheet
    createDefaultSheet();
    // Create default postComment
    createDefaultComment(post);
    // Create default menu
    createDefaultMenu();
    eventPublisher.publishEvent(new LogEvent(this, user.getId().toString(), LogType.BLOG_INITIALIZED, "博客已成功初始化"));
    return BaseResponse.ok("安装完成!");
}
Also used : User(run.halo.app.model.entity.User) Category(run.halo.app.model.entity.Category) LogEvent(run.halo.app.event.logger.LogEvent) PostDetailVO(run.halo.app.model.vo.PostDetailVO) BadRequestException(run.halo.app.exception.BadRequestException) CacheLock(run.halo.app.cache.lock.CacheLock) PostMapping(org.springframework.web.bind.annotation.PostMapping) ApiOperation(io.swagger.annotations.ApiOperation) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 2 with CacheLock

use of run.halo.app.cache.lock.CacheLock in project halo-plugin-experimental by guqing.

the class InstallController method installBlog.

@PostMapping
@ResponseBody
@CacheLock
@ApiOperation("Initializes the blog")
public BaseResponse<String> installBlog(@RequestBody InstallParam installParam) {
    // Validate manually
    ValidationUtils.validate(installParam, CreateCheck.class);
    // Check is installed
    boolean isInstalled = optionService.getByPropertyOrDefault(PrimaryProperties.IS_INSTALLED, Boolean.class, false);
    if (isInstalled) {
        throw new BadRequestException("该博客已初始化,不能再次安装!");
    }
    // Initialize settings
    initSettings(installParam);
    // Create default user
    User user = createUser(installParam);
    // Create default category
    Category category = createDefaultCategoryIfAbsent();
    // Create default post
    PostDetailVO post = createDefaultPostIfAbsent(category);
    // Create default sheet
    createDefaultSheet();
    // Create default postComment
    createDefaultComment(post);
    // Create default menu
    createDefaultMenu();
    eventPublisher.publishEvent(new LogEvent(this, user.getId().toString(), LogType.BLOG_INITIALIZED, "博客已成功初始化"));
    return BaseResponse.ok("安装完成!");
}
Also used : User(run.halo.app.model.entity.User) Category(run.halo.app.model.entity.Category) LogEvent(run.halo.app.event.logger.LogEvent) PostDetailVO(run.halo.app.model.vo.PostDetailVO) BadRequestException(run.halo.app.exception.BadRequestException) CacheLock(run.halo.app.cache.lock.CacheLock) PostMapping(org.springframework.web.bind.annotation.PostMapping) ApiOperation(io.swagger.annotations.ApiOperation) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 3 with CacheLock

use of run.halo.app.cache.lock.CacheLock in project halo by halo-dev.

the class UserServiceImpl method create.

@Override
@CacheLock
public User create(User user) {
    // Check user
    if (count() != 0) {
        throw new BadRequestException("当前博客已有用户");
    }
    User createdUser = super.create(user);
    eventPublisher.publishEvent(new UserUpdatedEvent(this, createdUser.getId()));
    return createdUser;
}
Also used : User(run.halo.app.model.entity.User) BadRequestException(run.halo.app.exception.BadRequestException) UserUpdatedEvent(run.halo.app.event.user.UserUpdatedEvent) CacheLock(run.halo.app.cache.lock.CacheLock)

Example 4 with CacheLock

use of run.halo.app.cache.lock.CacheLock in project halo-plugin-experimental by guqing.

the class UserServiceImpl method create.

@Override
@CacheLock
public User create(User user) {
    // Check user
    if (count() != 0) {
        throw new BadRequestException("当前博客已有用户");
    }
    User createdUser = super.create(user);
    eventPublisher.publishEvent(new UserUpdatedEvent(this, createdUser.getId()));
    return createdUser;
}
Also used : User(run.halo.app.model.entity.User) BadRequestException(run.halo.app.exception.BadRequestException) UserUpdatedEvent(run.halo.app.event.user.UserUpdatedEvent) CacheLock(run.halo.app.cache.lock.CacheLock)

Example 5 with CacheLock

use of run.halo.app.cache.lock.CacheLock in project halo by ruibaby.

the class InstallController method installBlog.

@PostMapping
@ResponseBody
@CacheLock
@ApiOperation("Initializes the blog")
public BaseResponse<String> installBlog(@RequestBody InstallParam installParam) {
    // Validate manually
    ValidationUtils.validate(installParam, CreateCheck.class);
    // Check is installed
    boolean isInstalled = optionService.getByPropertyOrDefault(PrimaryProperties.IS_INSTALLED, Boolean.class, false);
    if (isInstalled) {
        throw new BadRequestException("该博客已初始化,不能再次安装!");
    }
    // Initialize settings
    initSettings(installParam);
    // Create default user
    User user = createUser(installParam);
    // Create default category
    Category category = createDefaultCategoryIfAbsent();
    // Create default post
    PostDetailVO post = createDefaultPostIfAbsent(category);
    // Create default sheet
    createDefaultSheet();
    // Create default postComment
    createDefaultComment(post);
    // Create default menu
    createDefaultMenu();
    eventPublisher.publishEvent(new LogEvent(this, user.getId().toString(), LogType.BLOG_INITIALIZED, "博客已成功初始化"));
    return BaseResponse.ok("安装完成!");
}
Also used : User(run.halo.app.model.entity.User) Category(run.halo.app.model.entity.Category) LogEvent(run.halo.app.event.logger.LogEvent) PostDetailVO(run.halo.app.model.vo.PostDetailVO) BadRequestException(run.halo.app.exception.BadRequestException) CacheLock(run.halo.app.cache.lock.CacheLock) PostMapping(org.springframework.web.bind.annotation.PostMapping) ApiOperation(io.swagger.annotations.ApiOperation) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

CacheLock (run.halo.app.cache.lock.CacheLock)6 BadRequestException (run.halo.app.exception.BadRequestException)6 User (run.halo.app.model.entity.User)6 ApiOperation (io.swagger.annotations.ApiOperation)3 PostMapping (org.springframework.web.bind.annotation.PostMapping)3 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)3 LogEvent (run.halo.app.event.logger.LogEvent)3 UserUpdatedEvent (run.halo.app.event.user.UserUpdatedEvent)3 Category (run.halo.app.model.entity.Category)3 PostDetailVO (run.halo.app.model.vo.PostDetailVO)3