use of com.hack23.cia.model.internal.application.user.impl.UserAccount in project cia by Hack23.
the class RegisterUserServiceITest method serviceRegisterUserRequestUserAlreadyExistFailureTest.
/**
* Service register user request user already exist failure test.
*
* @throws Exception
* the exception
*/
@Test
public void serviceRegisterUserRequestUserAlreadyExistFailureTest() throws Exception {
final CreateApplicationSessionRequest createApplicationSesstion = createApplicationSesstionWithRoleAnonymous();
final RegisterUserRequest serviceRequest = new RegisterUserRequest();
serviceRequest.setCountry("Sweden");
serviceRequest.setUsername(UUID.randomUUID().toString());
serviceRequest.setEmail(serviceRequest.getUsername() + "@email.com");
serviceRequest.setUserpassword("Userpassword1!");
serviceRequest.setUserType(UserType.PRIVATE);
serviceRequest.setSessionId(createApplicationSesstion.getSessionId());
final RegisterUserResponse response = (RegisterUserResponse) applicationManager.service(serviceRequest);
assertNotNull(EXPECT_A_RESULT, response);
assertEquals(EXPECT_SUCCESS, ServiceResult.SUCCESS, response.getResult());
createApplicationSesstionWithRoleAnonymous();
final DataContainer<UserAccount, Long> dataContainer = applicationManager.getDataContainer(UserAccount.class);
final List<UserAccount> allBy = dataContainer.getAllBy(UserAccount_.username, serviceRequest.getUsername());
assertEquals(1, allBy.size());
final RegisterUserResponse errorResponse = (RegisterUserResponse) applicationManager.service(serviceRequest);
assertNotNull(EXPECT_A_RESULT, errorResponse);
assertEquals(EXPECT_SUCCESS, ServiceResult.FAILURE, errorResponse.getResult());
assertEquals(RegisterUserResponse.ErrorMessage.USER_ALREADY_EXIST.toString(), errorResponse.getErrorMessage());
}
use of com.hack23.cia.model.internal.application.user.impl.UserAccount in project cia by Hack23.
the class SetGoogleAuthenticatorCredentialServiceITest method servicesetGoogleAuthenticatorCredentialRequestSuccessTest.
/**
* Serviceset google authenticator credential request success test.
*
* @throws Exception
* the exception
*/
@Test
@PerfTest(threads = 2, duration = 4000, warmUp = 1500)
@Required(max = 3000, average = 2500, percentile95 = 2700, throughput = 1)
public void servicesetGoogleAuthenticatorCredentialRequestSuccessTest() throws Exception {
final CreateApplicationSessionRequest createApplicationSesstion = createApplicationSesstionWithRoleAnonymous();
final RegisterUserRequest serviceRequest = new RegisterUserRequest();
serviceRequest.setCountry("Sweden");
serviceRequest.setUsername(UUID.randomUUID().toString());
serviceRequest.setEmail(serviceRequest.getUsername() + "@email.com");
serviceRequest.setUserpassword("Userpassword1!");
serviceRequest.setUserType(UserType.PRIVATE);
serviceRequest.setSessionId(createApplicationSesstion.getSessionId());
final RegisterUserResponse response = (RegisterUserResponse) applicationManager.service(serviceRequest);
assertNotNull(EXPECT_A_RESULT, response);
assertEquals(EXPECT_SUCCESS, ServiceResult.SUCCESS, response.getResult());
final DataContainer<UserAccount, Long> dataContainer = applicationManager.getDataContainer(UserAccount.class);
final List<UserAccount> allBy = dataContainer.getAllBy(UserAccount_.username, serviceRequest.getUsername());
assertEquals(1, allBy.size());
final LoginRequest loginRequest = new LoginRequest();
loginRequest.setEmail(serviceRequest.getEmail());
loginRequest.setSessionId(serviceRequest.getSessionId());
loginRequest.setUserpassword(serviceRequest.getUserpassword());
final LoginResponse loginResponse = (LoginResponse) applicationManager.service(loginRequest);
assertNotNull(EXPECT_A_RESULT, loginResponse);
assertEquals(EXPECT_SUCCESS, ServiceResult.SUCCESS, loginResponse.getResult());
final SetGoogleAuthenticatorCredentialRequest setGoogleAuthenticatorCredentialRequest = new SetGoogleAuthenticatorCredentialRequest();
setGoogleAuthenticatorCredentialRequest.setSessionId(serviceRequest.getSessionId());
final ServiceResponse setGoogleAuthenticatorCredentialResponse = applicationManager.service(setGoogleAuthenticatorCredentialRequest);
assertNotNull(EXPECT_A_RESULT, setGoogleAuthenticatorCredentialResponse);
assertEquals(EXPECT_SUCCESS, ServiceResult.SUCCESS, setGoogleAuthenticatorCredentialResponse.getResult());
final LogoutRequest logoutRequest = new LogoutRequest();
logoutRequest.setSessionId(serviceRequest.getSessionId());
final ServiceResponse logoutResponse = applicationManager.service(logoutRequest);
assertNotNull(EXPECT_A_RESULT, logoutResponse);
assertEquals(EXPECT_SUCCESS, ServiceResult.SUCCESS, logoutResponse.getResult());
}
use of com.hack23.cia.model.internal.application.user.impl.UserAccount in project cia by Hack23.
the class DisableGoogleAuthenticatorCredentialService method processService.
@Override
@Secured({ "ROLE_USER", "ROLE_ADMIN" })
public DisableGoogleAuthenticatorCredentialResponse processService(final DisableGoogleAuthenticatorCredentialRequest serviceRequest) {
final DisableGoogleAuthenticatorCredentialResponse inputValidation = inputValidation(serviceRequest);
if (inputValidation != null) {
return inputValidation;
}
LOGGER.info("{}:{}", serviceRequest.getClass().getSimpleName(), serviceRequest.getSessionId());
final CreateApplicationEventRequest eventRequest = createApplicationEventForService(serviceRequest);
final UserAccount userAccount = getUserAccountFromSecurityContext();
final DisableGoogleAuthenticatorCredentialResponse response = new DisableGoogleAuthenticatorCredentialResponse(ServiceResult.SUCCESS);
if (userAccount != null) {
eventRequest.setUserId(userAccount.getUserId());
final UserAccount updateUserAccount = userDAO.load(userAccount.getHjid());
updateUserAccount.setGoogleAuthKey(null);
updateUserAccount.setGoogleAuthVerificationCode(null);
updateUserAccount.setGoogleAuthScratchCodes(null);
userDAO.merge(updateUserAccount);
}
eventRequest.setApplicationMessage(response.getResult().toString());
createApplicationEventService.processService(eventRequest);
return response;
}
use of com.hack23.cia.model.internal.application.user.impl.UserAccount in project cia by Hack23.
the class DocumentWordCountService method processService.
@Override
@Secured({ "ROLE_USER", "ROLE_ADMIN", "ROLE_ANONYMOUS" })
public DocumentWordCountResponse processService(final DocumentWordCountRequest serviceRequest) {
final DocumentWordCountResponse inputValidation = inputValidation(serviceRequest);
if (inputValidation != null) {
return inputValidation;
}
LOGGER.info("{}:{}", serviceRequest.getClass().getSimpleName(), serviceRequest.getDocumentId());
final CreateApplicationEventRequest eventRequest = createApplicationEventForService(serviceRequest);
final UserAccount userAccount = getUserAccountFromSecurityContext();
if (userAccount != null) {
eventRequest.setUserId(userAccount.getUserId());
}
final DocumentWordCountResponse response = new DocumentWordCountResponse(ServiceResult.SUCCESS);
final DocumentContentData documentContentData = documentContentDataDAO.findFirstByProperty(DocumentContentData_.id, serviceRequest.getDocumentId());
if (documentContentData == null) {
response.setWordCountMap(new HashMap<>());
} else {
response.setWordCountMap(wordCounter.calculateWordCount(documentContentData, serviceRequest.getMaxResults()));
}
eventRequest.setApplicationMessage(response.getResult().toString());
createApplicationEventService.processService(eventRequest);
return response;
}
use of com.hack23.cia.model.internal.application.user.impl.UserAccount in project cia by Hack23.
the class SearchDocumentService method processService.
@Override
@Secured({ "ROLE_USER", "ROLE_ADMIN", "ROLE_ANONYMOUS" })
public SearchDocumentResponse processService(final SearchDocumentRequest serviceRequest) {
final SearchDocumentResponse inputValidation = inputValidation(serviceRequest);
if (inputValidation != null) {
return inputValidation;
}
LOGGER.info("{}:{}", serviceRequest.getClass().getSimpleName(), serviceRequest.getSearchExpression());
final CreateApplicationEventRequest eventRequest = createApplicationEventForService(serviceRequest);
final UserAccount userAccount = getUserAccountFromSecurityContext();
if (userAccount != null) {
eventRequest.setUserId(userAccount.getUserId());
}
final SearchDocumentResponse response = new SearchDocumentResponse(ServiceResult.SUCCESS);
final List<DocumentElement> searchResultTitles = documentElementDAO.search(serviceRequest.getSearchExpression(), serviceRequest.getMaxResults(), "id", "title", "subTitle");
if (!searchResultTitles.isEmpty()) {
response.setResultElement(searchResultTitles);
} else {
final List<DocumentContentData> searchResultContent = documentContentDataDAO.search(serviceRequest.getSearchExpression(), serviceRequest.getMaxResults(), "id", "content");
if (!searchResultContent.isEmpty()) {
final List<DocumentElement> searchResultTitlesForContent = new ArrayList<>();
for (final DocumentContentData documentContent : searchResultContent) {
searchResultTitlesForContent.add(documentElementDAO.load(documentContent.getId()));
}
response.setResultElement(searchResultTitlesForContent);
}
}
eventRequest.setApplicationMessage(response.getResult().toString());
createApplicationEventService.processService(eventRequest);
return response;
}
Aggregations