Search in sources :

Example 11 with CreateApplicationEventRequest

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

the class ManageUserAccountService method processService.

@Override
@Secured({ "ROLE_ADMIN" })
public ManageUserAccountResponse processService(final ManageUserAccountRequest serviceRequest) {
    final ManageUserAccountResponse inputValidation = inputValidation(serviceRequest);
    if (inputValidation != null) {
        return inputValidation;
    }
    final CreateApplicationEventRequest eventRequest = createApplicationEventForService(serviceRequest);
    final UserAccount userAccount = getUserAccountFromSecurityContext();
    if (userAccount != null) {
        eventRequest.setUserId(userAccount.getUserId());
    }
    ManageUserAccountResponse response;
    final Set<ConstraintViolation<ManageUserAccountRequest>> requestConstraintViolations = validateRequest(serviceRequest);
    if (!requestConstraintViolations.isEmpty()) {
        response = new ManageUserAccountResponse(ServiceResult.FAILURE);
        final String errorMessage = requestConstraintViolations.stream().sorted((p1, p2) -> p1.getPropertyPath().toString().compareTo(p2.getPropertyPath().toString())).map(p -> p.getPropertyPath().toString() + " " + p.getMessage()).collect(Collectors.joining(", "));
        response.setErrorMessage(errorMessage);
        eventRequest.setErrorMessage(errorMessage);
    } else {
        response = performOperation(serviceRequest, eventRequest);
    }
    createApplicationEventService.processService(eventRequest);
    return response;
}
Also used : ApplicationOperationType(com.hack23.cia.model.internal.application.system.impl.ApplicationOperationType) BusinessService(com.hack23.cia.service.impl.action.common.BusinessService) ManageUserAccountRequest(com.hack23.cia.service.api.action.admin.ManageUserAccountRequest) ServiceResult(com.hack23.cia.service.api.action.common.ServiceResponse.ServiceResult) EnumMap(java.util.EnumMap) ApplicationEventGroup(com.hack23.cia.model.internal.application.system.impl.ApplicationEventGroup) RemoveDataManager(com.hack23.cia.service.data.api.RemoveDataManager) Set(java.util.Set) Autowired(org.springframework.beans.factory.annotation.Autowired) Collectors(java.util.stream.Collectors) Secured(org.springframework.security.access.annotation.Secured) AbstractBusinessServiceImpl(com.hack23.cia.service.impl.action.common.AbstractBusinessServiceImpl) ManageUserAccountResponse(com.hack23.cia.service.api.action.admin.ManageUserAccountResponse) Propagation(org.springframework.transaction.annotation.Propagation) UserLockStatus(com.hack23.cia.model.internal.application.user.impl.UserLockStatus) Service(org.springframework.stereotype.Service) Map(java.util.Map) UserAccount(com.hack23.cia.model.internal.application.user.impl.UserAccount) PostConstruct(javax.annotation.PostConstruct) UserAccount_(com.hack23.cia.model.internal.application.user.impl.UserAccount_) CreateApplicationEventRequest(com.hack23.cia.service.api.action.application.CreateApplicationEventRequest) ConstraintViolation(javax.validation.ConstraintViolation) UserDAO(com.hack23.cia.service.data.api.UserDAO) Transactional(org.springframework.transaction.annotation.Transactional) ConstraintViolation(javax.validation.ConstraintViolation) ManageUserAccountResponse(com.hack23.cia.service.api.action.admin.ManageUserAccountResponse) 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 12 with CreateApplicationEventRequest

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

the class ManageUserAccountService method performOperation.

/**
 * Perform operation.
 *
 * @param serviceRequest
 *            the service request
 * @param eventRequest
 *            the event request
 * @return the manage user account response
 */
private ManageUserAccountResponse performOperation(final ManageUserAccountRequest serviceRequest, final CreateApplicationEventRequest eventRequest) {
    ManageUserAccountResponse response;
    eventRequest.setElementId(serviceRequest.getUserAcountId());
    eventRequest.setApplicationMessage(serviceRequest.getAccountOperation().toString());
    final UserAccount accountToModify = userDAO.findFirstByProperty(UserAccount_.userId, serviceRequest.getUserAcountId());
    final UserCommand userCommand = userCommandMap.get(serviceRequest.getAccountOperation());
    if (accountToModify != null && userCommand != null) {
        response = userCommand.execute(accountToModify);
    } else {
        response = new ManageUserAccountResponse(ServiceResult.FAILURE);
    }
    eventRequest.setApplicationMessage(response.getResult().toString());
    return response;
}
Also used : ManageUserAccountResponse(com.hack23.cia.service.api.action.admin.ManageUserAccountResponse) UserAccount(com.hack23.cia.model.internal.application.user.impl.UserAccount)

Example 13 with CreateApplicationEventRequest

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

the class RefreshDataViewsService method createApplicationEventForService.

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

Example 14 with CreateApplicationEventRequest

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

the class RefreshDataViewsService method processService.

@Override
@Secured({ "ROLE_ADMIN" })
public RefreshDataViewsResponse processService(final RefreshDataViewsRequest serviceRequest) {
    final RefreshDataViewsResponse inputValidation = inputValidation(serviceRequest);
    if (inputValidation != null) {
        return inputValidation;
    }
    final CreateApplicationEventRequest eventRequest = createApplicationEventForService(serviceRequest);
    final UserAccount userAccount = getUserAccountFromSecurityContext();
    if (userAccount != null) {
        eventRequest.setUserId(userAccount.getUserId());
    }
    final RefreshDataViewsResponse response = new RefreshDataViewsResponse(ServiceResult.SUCCESS);
    viewDataManager.refreshViews();
    eventRequest.setApplicationMessage(response.getResult().toString());
    createApplicationEventService.processService(eventRequest);
    return response;
}
Also used : CreateApplicationEventRequest(com.hack23.cia.service.api.action.application.CreateApplicationEventRequest) RefreshDataViewsResponse(com.hack23.cia.service.api.action.admin.RefreshDataViewsResponse) UserAccount(com.hack23.cia.model.internal.application.user.impl.UserAccount) Secured(org.springframework.security.access.annotation.Secured)

Example 15 with CreateApplicationEventRequest

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

the class RemoveDataService method createApplicationEventForService.

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

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