Search in sources :

Example 16 with CreateApplicationEventRequest

use of com.hack23.cia.service.api.action.application.CreateApplicationEventRequest in project cia by Hack23.

the class SendEmailService method createApplicationEventForService.

@Override
protected CreateApplicationEventRequest createApplicationEventForService(final SendEmailRequest serviceRequest) {
    final CreateApplicationEventRequest eventRequest = new CreateApplicationEventRequest();
    eventRequest.setEventGroup(ApplicationEventGroup.ADMIN);
    eventRequest.setApplicationOperation(ApplicationOperationType.CREATE);
    eventRequest.setActionName(SendEmailRequest.class.getSimpleName());
    eventRequest.setSessionId(serviceRequest.getSessionId());
    return eventRequest;
}
Also used : CreateApplicationEventRequest(com.hack23.cia.service.api.action.application.CreateApplicationEventRequest) SendEmailRequest(com.hack23.cia.service.api.action.admin.SendEmailRequest)

Example 17 with CreateApplicationEventRequest

use of com.hack23.cia.service.api.action.application.CreateApplicationEventRequest in project cia by Hack23.

the class SendEmailService method processService.

@Override
@Secured({ "ROLE_ADMIN" })
public SendEmailResponse processService(final SendEmailRequest serviceRequest) {
    final SendEmailResponse inputValidation = inputValidation(serviceRequest);
    if (inputValidation != null) {
        return inputValidation;
    }
    final CreateApplicationEventRequest eventRequest = createApplicationEventForService(serviceRequest);
    final UserAccount userAccount = getUserAccountFromSecurityContext();
    if (userAccount != null) {
        LOGGER.info("{} started:{}", serviceRequest.getClass().getSimpleName(), userAccount.getEmail());
        eventRequest.setUserId(userAccount.getUserId());
    }
    SendEmailResponse response;
    if (isValidEmailAddress(serviceRequest.getEmail())) {
        emailService.sendEmail(serviceRequest.getEmail(), serviceRequest.getSubject(), serviceRequest.getContent());
        response = new SendEmailResponse(ServiceResult.SUCCESS);
    } else {
        response = new SendEmailResponse(ServiceResult.FAILURE);
        response.setErrorMessage(EMAIL_IS_NOT_A_VALID_EMAIL_ADDRESS);
    }
    eventRequest.setApplicationMessage(response.getResult().toString());
    createApplicationEventService.processService(eventRequest);
    return response;
}
Also used : SendEmailResponse(com.hack23.cia.service.api.action.admin.SendEmailResponse) CreateApplicationEventRequest(com.hack23.cia.service.api.action.application.CreateApplicationEventRequest) UserAccount(com.hack23.cia.model.internal.application.user.impl.UserAccount) Secured(org.springframework.security.access.annotation.Secured)

Example 18 with CreateApplicationEventRequest

use of com.hack23.cia.service.api.action.application.CreateApplicationEventRequest in project cia by Hack23.

the class UpdateApplicationConfigurationService method processService.

@Override
@Secured({ "ROLE_ADMIN" })
public UpdateApplicationConfigurationResponse processService(final UpdateApplicationConfigurationRequest serviceRequest) {
    final CreateApplicationEventRequest eventRequest = createApplicationEventForService(serviceRequest);
    final UpdateApplicationConfigurationResponse inputValidation = inputValidation(serviceRequest);
    if (inputValidation != null) {
        return inputValidation;
    }
    final UserAccount userAccount = getUserAccountFromSecurityContext();
    if (userAccount != null) {
        eventRequest.setUserId(userAccount.getUserId());
    }
    UpdateApplicationConfigurationResponse response;
    final ApplicationConfiguration applicationConfiguration = applicationConfigurationDAO.load(serviceRequest.getApplicationConfigurationId());
    if (applicationConfiguration != null) {
        eventRequest.setElementId(serviceRequest.getApplicationConfigurationId().toString());
        applicationConfiguration.setConfigTitle(serviceRequest.getConfigTitle());
        applicationConfiguration.setConfigDescription(serviceRequest.getConfigDescription());
        applicationConfiguration.setComponentTitle(serviceRequest.getComponentTitle());
        applicationConfiguration.setComponentDescription(serviceRequest.getComponentDescription());
        applicationConfiguration.setPropertyValue(serviceRequest.getPropertyValue());
        applicationConfigurationDAO.persist(applicationConfiguration);
        response = new UpdateApplicationConfigurationResponse(ServiceResult.SUCCESS);
    } else {
        response = new UpdateApplicationConfigurationResponse(ServiceResult.FAILURE);
    }
    eventRequest.setApplicationMessage(response.getResult().toString());
    createApplicationEventService.processService(eventRequest);
    return response;
}
Also used : UpdateApplicationConfigurationResponse(com.hack23.cia.service.api.action.admin.UpdateApplicationConfigurationResponse) CreateApplicationEventRequest(com.hack23.cia.service.api.action.application.CreateApplicationEventRequest) UserAccount(com.hack23.cia.model.internal.application.user.impl.UserAccount) ApplicationConfiguration(com.hack23.cia.model.internal.application.system.impl.ApplicationConfiguration) Secured(org.springframework.security.access.annotation.Secured)

Example 19 with CreateApplicationEventRequest

use of com.hack23.cia.service.api.action.application.CreateApplicationEventRequest in project cia by Hack23.

the class UpdateSearchIndexService method createApplicationEventForService.

@Override
protected CreateApplicationEventRequest createApplicationEventForService(final UpdateSearchIndexRequest serviceRequest) {
    final CreateApplicationEventRequest eventRequest = new CreateApplicationEventRequest();
    eventRequest.setEventGroup(ApplicationEventGroup.ADMIN);
    eventRequest.setApplicationOperation(ApplicationOperationType.UPDATE);
    eventRequest.setActionName(UpdateSearchIndexRequest.class.getSimpleName());
    eventRequest.setSessionId(serviceRequest.getSessionId());
    return eventRequest;
}
Also used : CreateApplicationEventRequest(com.hack23.cia.service.api.action.application.CreateApplicationEventRequest) UpdateSearchIndexRequest(com.hack23.cia.service.api.action.admin.UpdateSearchIndexRequest)

Example 20 with CreateApplicationEventRequest

use of com.hack23.cia.service.api.action.application.CreateApplicationEventRequest in project cia by Hack23.

the class UpdateSearchIndexService method processService.

@Override
@Secured({ "ROLE_ADMIN" })
public UpdateSearchIndexResponse processService(final UpdateSearchIndexRequest serviceRequest) {
    final UpdateSearchIndexResponse inputValidation = inputValidation(serviceRequest);
    if (inputValidation != null) {
        return inputValidation;
    }
    final CreateApplicationEventRequest eventRequest = createApplicationEventForService(serviceRequest);
    final UserAccount userAccount = getUserAccountFromSecurityContext();
    if (userAccount != null) {
        LOGGER.info("{} started:{}", serviceRequest.getClass().getSimpleName(), userAccount.getEmail());
        eventRequest.setUserId(userAccount.getUserId());
    }
    UpdateSearchIndexResponse response;
    try {
        searchIndexer.updateSearchIndex();
        response = new UpdateSearchIndexResponse(ServiceResult.SUCCESS);
    } catch (final InterruptedException e) {
        LOGGER.warn("Update Index failed", e);
        Thread.currentThread().interrupt();
        response = new UpdateSearchIndexResponse(ServiceResult.FAILURE);
    }
    eventRequest.setApplicationMessage(response.getResult().toString());
    createApplicationEventService.processService(eventRequest);
    return response;
}
Also used : UpdateSearchIndexResponse(com.hack23.cia.service.api.action.admin.UpdateSearchIndexResponse) CreateApplicationEventRequest(com.hack23.cia.service.api.action.application.CreateApplicationEventRequest) UserAccount(com.hack23.cia.model.internal.application.user.impl.UserAccount) Secured(org.springframework.security.access.annotation.Secured)

Aggregations

CreateApplicationEventRequest (com.hack23.cia.service.api.action.application.CreateApplicationEventRequest)32 UserAccount (com.hack23.cia.model.internal.application.user.impl.UserAccount)15 Secured (org.springframework.security.access.annotation.Secured)14 ArrayList (java.util.ArrayList)5 ConstraintViolation (javax.validation.ConstraintViolation)3 SimpleGrantedAuthority (org.springframework.security.core.authority.SimpleGrantedAuthority)3 DocumentContentData (com.hack23.cia.model.external.riksdagen.documentcontent.impl.DocumentContentData)2 ApplicationConfiguration (com.hack23.cia.model.internal.application.system.impl.ApplicationConfiguration)2 ApplicationSession (com.hack23.cia.model.internal.application.system.impl.ApplicationSession)2 ManageUserAccountRequest (com.hack23.cia.service.api.action.admin.ManageUserAccountRequest)2 ManageUserAccountResponse (com.hack23.cia.service.api.action.admin.ManageUserAccountResponse)2 CreateApplicationEventResponse (com.hack23.cia.service.api.action.application.CreateApplicationEventResponse)2 Date (java.util.Date)2 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)2 DocumentElement (com.hack23.cia.model.external.riksdagen.dokumentlista.impl.DocumentElement)1 ApplicationActionEvent (com.hack23.cia.model.internal.application.system.impl.ApplicationActionEvent)1 ApplicationEventGroup (com.hack23.cia.model.internal.application.system.impl.ApplicationEventGroup)1 ApplicationOperationType (com.hack23.cia.model.internal.application.system.impl.ApplicationOperationType)1 UserAccount_ (com.hack23.cia.model.internal.application.user.impl.UserAccount_)1 UserLockStatus (com.hack23.cia.model.internal.application.user.impl.UserLockStatus)1