diff --git a/build.gradle b/build.gradle index 4fb0185..bc20ab3 100644 --- a/build.gradle +++ b/build.gradle @@ -27,8 +27,8 @@ mainClassName = 'ru.ulstu.NgTrackerApplication' build.dependsOn checkstyleMain bootRun.dependsOn checkstyleMain -sourceCompatibility = 1.8 -targetCompatibility = 1.8 +sourceCompatibility = 11 +targetCompatibility = 11 bootRun { systemProperties = System.properties @@ -88,13 +88,9 @@ compileJava { repositories { mavenLocal() mavenCentral() -} - -configurations { - compile.exclude module: "spring-boot-starter-tomcat" - compile.exclude module: "bcmail-jdk14" - compile.exclude module: "bcprov-jdk14" - compile.exclude module: "bctsp-jdk14" + maven { + url "https://repository.primefaces.org/" + } } dependencies { @@ -102,13 +98,15 @@ dependencies { compile group: 'org.springframework.boot', name: 'spring-boot-starter-security' compile group: 'org.springframework.boot', name: 'spring-boot-starter-aop' compile group: 'org.springframework.boot', name: 'spring-boot-starter-mail' - compile group: 'org.springframework.boot', name: 'spring-boot-starter-jetty' + compile group: 'org.springframework.boot', name: 'spring-boot-starter-tomcat' compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa' compile group: 'org.springframework.boot', name: 'spring-boot-starter-thymeleaf' compile group: 'nz.net.ultraq.thymeleaf', name: 'thymeleaf-layout-dialect' compile group: 'org.thymeleaf.extras', name: 'thymeleaf-extras-springsecurity5' compile group: 'com.fasterxml.jackson.module', name: 'jackson-module-afterburner' compile group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-hibernate5' + compile group: 'org.springframework.security', name: 'spring-security-oauth2-client' + compile group: 'org.springframework.security', name: 'spring-security-oauth2-jose' compile group: 'org.postgresql', name: 'postgresql', version: '42.2.5' @@ -117,19 +115,21 @@ dependencies { compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.7' - compile group: 'org.webjars', name: 'bootstrap', version: '4.1.0' - compile group: 'org.webjars', name: 'bootstrap-select', version: '1.13.3' - compile group: 'org.webjars', name: 'jquery', version: '3.3.1-1' - compile group: 'org.webjars.npm', name: 'jquery.easing', version: '1.4.1' - compile group: 'org.webjars', name: 'font-awesome', version: '4.7.0' + //primefaces + compile group: 'org.primefaces', name: 'primefaces', version: '7.0' + compile group: 'net.bootsfaces', name: 'bootsfaces', version: '1.4.2' + compile group: 'org.joinfaces', name: 'jsf-spring-boot-starter', version: '4.1.2' + compile group: 'org.javassist', name: 'javassist', version: '3.25.0-GA' + compile group: 'org.primefaces.themes', name: 'all-themes', version: '1.0.10' compile group: 'io.springfox', name: 'springfox-swagger2', version: '2.6.0' compile group: 'io.springfox', name: 'springfox-swagger-ui', version: '2.6.0' compile group: 'net.sourceforge.htmlunit', name: 'htmlunit', version: '2.35.0' + compile group: 'xalan', name: 'xalan', version: '2.7.2' testCompile group: 'org.springframework.boot', name: 'spring-boot-starter-test' - compile group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '3.3.1' - testCompile group: 'org.seleniumhq.selenium', name: 'selenium-support', version: '3.3.1' + //compile group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '3.3.1' + //testCompile group: 'org.seleniumhq.selenium', name: 'selenium-support', version: '3.3.1' //testCompile group: 'com.google.guava', name: 'guava', version: '21.0' testCompile group: 'org.mockito', name: 'mockito-all', version: '1.10.19' -} \ No newline at end of file +} diff --git a/checkstyle.xml b/checkstyle.xml index 828cdaa..0014271 100644 --- a/checkstyle.xml +++ b/checkstyle.xml @@ -169,4 +169,4 @@ - \ No newline at end of file + diff --git a/src/main/java/ru/ulstu/configuration/Constants.java b/src/main/java/ru/ulstu/configuration/Constants.java index 77a9a4d..5738b8f 100644 --- a/src/main/java/ru/ulstu/configuration/Constants.java +++ b/src/main/java/ru/ulstu/configuration/Constants.java @@ -14,7 +14,7 @@ public class Constants { public static final String LOGIN_REGEX = "^[_'.@A-Za-z0-9-]*$"; public static final String COOKIES_NAME = "JSESSIONID"; - public static final String LOGOUT_URL = "/login?logout"; + public static final String LOGOUT_URL = "/login.xhtml"; public static final String SESSION_ID_ATTR = "sessionId"; public static final int SESSION_TIMEOUT_SECONDS = 30 * 60; @@ -22,4 +22,4 @@ public class Constants { public static final String PASSWORD_RESET_PAGE = "/reset"; public static final int RESET_KEY_LENGTH = 6; -} \ No newline at end of file +} diff --git a/src/main/java/ru/ulstu/configuration/HttpListenerConfiguration.java b/src/main/java/ru/ulstu/configuration/HttpListenerConfiguration.java deleted file mode 100644 index 514319d..0000000 --- a/src/main/java/ru/ulstu/configuration/HttpListenerConfiguration.java +++ /dev/null @@ -1,30 +0,0 @@ -package ru.ulstu.configuration; - -import org.eclipse.jetty.server.ServerConnector; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.web.embedded.jetty.JettyServerCustomizer; -import org.springframework.boot.web.embedded.jetty.JettyServletWebServerFactory; -import org.springframework.boot.web.server.ConfigurableWebServerFactory; -import org.springframework.boot.web.server.WebServerFactoryCustomizer; -import org.springframework.context.annotation.Configuration; - -@Configuration -public class HttpListenerConfiguration implements WebServerFactoryCustomizer { - @Value("${server.http.port}") - private int httpPort; - - private void configureJetty(JettyServletWebServerFactory jettyFactory) { - jettyFactory.addServerCustomizers((JettyServerCustomizer) server -> { - ServerConnector serverConnector = new ServerConnector(server); - serverConnector.setPort(httpPort); - server.addConnector(serverConnector); - }); - } - - @Override - public void customize(ConfigurableWebServerFactory factory) { - if (factory instanceof JettyServletWebServerFactory) { - configureJetty((JettyServletWebServerFactory) factory); - } - } -} diff --git a/src/main/java/ru/ulstu/configuration/MvcConfiguration.java b/src/main/java/ru/ulstu/configuration/MvcConfiguration.java index 35e9ad2..7d2ab4c 100644 --- a/src/main/java/ru/ulstu/configuration/MvcConfiguration.java +++ b/src/main/java/ru/ulstu/configuration/MvcConfiguration.java @@ -1,7 +1,10 @@ package ru.ulstu.configuration; +import org.springframework.boot.web.server.ErrorPage; +import org.springframework.boot.web.server.ErrorPageRegistrar; +import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; +import org.springframework.http.HttpStatus; import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; @@ -9,20 +12,14 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; public class MvcConfiguration implements WebMvcConfigurer { @Override public void addViewControllers(ViewControllerRegistry registry) { - registry.addViewController("/{articlename:\\w+}"); - registry.addViewController("/admin/{articlename:\\w+}"); - registry.addViewController("/papers/{articlename:\\w+}"); - registry.addViewController("/grants/{articlename:\\w+}"); - registry.addViewController("/conferences/{articlename:\\w+}"); - registry.addViewController("/students/{articlename:\\w+}"); - registry.addRedirectViewController("/", "/index"); - registry.addRedirectViewController("/default", "/index"); + registry.addRedirectViewController("/", "/index.xhtml"); } - @Override - public void addResourceHandlers(ResourceHandlerRegistry registry) { - registry - .addResourceHandler("/webjars/**") - .addResourceLocations("/webjars/"); + @Bean + public ErrorPageRegistrar errorPageRegistrar() { + return registry -> { + registry.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, "/error/404.xhtml")); + registry.addErrorPages(new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/error/500.xhtml")); + }; } } diff --git a/src/main/java/ru/ulstu/configuration/SecurityConfiguration.java b/src/main/java/ru/ulstu/configuration/SecurityConfiguration.java index 5eb7220..190f697 100644 --- a/src/main/java/ru/ulstu/configuration/SecurityConfiguration.java +++ b/src/main/java/ru/ulstu/configuration/SecurityConfiguration.java @@ -5,27 +5,49 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.BeanInitializationException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.core.env.Environment; import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.builders.WebSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; +import org.springframework.security.config.oauth2.client.CommonOAuth2Provider; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; +import org.springframework.security.oauth2.client.endpoint.DefaultAuthorizationCodeTokenResponseClient; +import org.springframework.security.oauth2.client.endpoint.OAuth2AccessTokenResponseClient; +import org.springframework.security.oauth2.client.endpoint.OAuth2AuthorizationCodeGrantRequest; +import org.springframework.security.oauth2.client.registration.ClientRegistration; +import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository; +import org.springframework.security.oauth2.client.registration.InMemoryClientRegistrationRepository; +import org.springframework.security.oauth2.client.web.AuthorizationRequestRepository; +import org.springframework.security.oauth2.client.web.HttpSessionOAuth2AuthorizationRequestRepository; +import org.springframework.security.oauth2.core.endpoint.OAuth2AuthorizationRequest; import org.springframework.security.web.authentication.AuthenticationFailureHandler; import org.springframework.security.web.authentication.AuthenticationSuccessHandler; import org.springframework.security.web.authentication.logout.LogoutSuccessHandler; import ru.ulstu.core.model.AuthFailureHandler; -import ru.ulstu.user.controller.UserController; +import ru.ulstu.core.navigation.Page; import ru.ulstu.user.model.UserRoleConstants; import ru.ulstu.user.service.UserService; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + @Configuration @EnableWebSecurity @EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true) public class SecurityConfiguration extends WebSecurityConfigurerAdapter { private final Logger log = LoggerFactory.getLogger(SecurityConfiguration.class); + private static List clients = Arrays.asList("google"); + private static final String CLIENT_PROPERTY_KEY + = "spring.security.oauth2.client.registration."; + + @Autowired + private Environment env; @Value("${server.http.port}") private int httpPort; @@ -55,8 +77,7 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { - http.csrf() - .disable(); + http.csrf().disable(); if (applicationProperties.isDevMode()) { log.debug("Security disabled"); http.authorizeRequests() @@ -66,32 +87,39 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter { .principal("admin") .authorities(UserRoleConstants.ADMIN); } else { - log.debug("Security enabled"); http.authorizeRequests() - .antMatchers(UserController.ACTIVATE_URL).permitAll() - .antMatchers(Constants.PASSWORD_RESET_REQUEST_PAGE).permitAll() - .antMatchers(Constants.PASSWORD_RESET_PAGE).permitAll() - .antMatchers("/users/block").permitAll() - .antMatchers(UserController.URL + UserController.REGISTER_URL).permitAll() - .antMatchers(UserController.URL + UserController.ACTIVATE_URL).permitAll() - .antMatchers(UserController.URL + UserController.PASSWORD_RESET_REQUEST_URL).permitAll() - .antMatchers(UserController.URL + UserController.PASSWORD_RESET_URL).permitAll() + .antMatchers("/login.xhtml", "/logout") + .permitAll() + .anyRequest() + .authenticated() .antMatchers("/swagger-ui.html").hasAuthority(UserRoleConstants.ADMIN) - .anyRequest().authenticated() .and() .formLogin() - .loginPage("/login") + .loginPage("/login.xhtml") .successHandler(authenticationSuccessHandler) .failureHandler(authenticationFailureHandler) .permitAll() .and() + .oauth2Login() + .loginPage("/login.xhtml") + .authorizationEndpoint() + .baseUri("/oauth2/authorize-client") + .authorizationRequestRepository(authorizationRequestRepository()) + .and() + .tokenEndpoint() + .accessTokenResponseClient(accessTokenResponseClient()) + .and() + .defaultSuccessUrl(Page.INDEX) + .failureUrl("/loginFailure") + .and() .logout() .logoutSuccessHandler(logoutSuccessHandler) - .logoutSuccessUrl(Constants.LOGOUT_URL) - .invalidateHttpSession(false) + .logoutSuccessUrl(Page.LOGOUT) + .invalidateHttpSession(true) .clearAuthentication(true) .deleteCookies(Constants.COOKIES_NAME) .permitAll(); + http.csrf().disable(); } if (applicationProperties.isUseHttps()) { http.portMapper() @@ -102,13 +130,51 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter { .anyRequest() .requiresSecure(); } + } + @Bean + public AuthorizationRequestRepository authorizationRequestRepository() { + return new HttpSessionOAuth2AuthorizationRequestRepository(); + } + + @Bean + public OAuth2AccessTokenResponseClient accessTokenResponseClient() { + DefaultAuthorizationCodeTokenResponseClient accessTokenResponseClient = new DefaultAuthorizationCodeTokenResponseClient(); + return accessTokenResponseClient; + } + + //@Bean + public ClientRegistrationRepository clientRegistrationRepository() { + List registrations = clients.stream() + .map(c -> getRegistration(c)) + .filter(registration -> registration != null) + .collect(Collectors.toList()); + + return new InMemoryClientRegistrationRepository(registrations); + } + + private ClientRegistration getRegistration(String client) { + String clientId = env.getProperty(CLIENT_PROPERTY_KEY + client + ".client-id"); + + if (clientId == null) { + return null; + } + + String clientSecret = env.getProperty(CLIENT_PROPERTY_KEY + client + ".client-secret"); + if (client.equals("google")) { + return CommonOAuth2Provider.GOOGLE.getBuilder(client) + .clientId(clientId) + .clientSecret(clientSecret) + .build(); + } + return null; } @Override public void configure(WebSecurity web) { web.ignoring() .antMatchers("/css/**") + .antMatchers("/javax.faces.resource/**") .antMatchers("/js/**") .antMatchers("/templates/**") .antMatchers("/webjars/**") diff --git a/src/main/java/ru/ulstu/core/controller/AdviceController.java b/src/main/java/ru/ulstu/core/controller/AdviceController.java deleted file mode 100644 index 27c9d5b..0000000 --- a/src/main/java/ru/ulstu/core/controller/AdviceController.java +++ /dev/null @@ -1,121 +0,0 @@ -package ru.ulstu.core.controller; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.validation.FieldError; -import org.springframework.web.bind.MethodArgumentNotValidException; -import org.springframework.web.bind.annotation.ControllerAdvice; -import org.springframework.web.bind.annotation.ExceptionHandler; -import org.springframework.web.bind.annotation.ModelAttribute; -import ru.ulstu.core.error.EntityIdIsNullException; -import ru.ulstu.core.model.ErrorConstants; -import ru.ulstu.core.model.response.Response; -import ru.ulstu.core.model.response.ResponseExtended; -import ru.ulstu.user.error.UserActivationError; -import ru.ulstu.user.error.UserEmailExistsException; -import ru.ulstu.user.error.UserIdExistsException; -import ru.ulstu.user.error.UserIsUndeadException; -import ru.ulstu.user.error.UserLoginExistsException; -import ru.ulstu.user.error.UserNotActivatedException; -import ru.ulstu.user.error.UserNotFoundException; -import ru.ulstu.user.error.UserPasswordsNotValidOrNotMatchException; -import ru.ulstu.user.error.UserResetKeyError; -import ru.ulstu.user.error.UserSendingMailException; -import ru.ulstu.user.service.UserService; - -import java.util.Set; -import java.util.stream.Collectors; - -@ControllerAdvice -public class AdviceController { - private final Logger log = LoggerFactory.getLogger(AdviceController.class); - private final UserService userService; - - public AdviceController(UserService userService) { - this.userService = userService; - } - - @ModelAttribute("currentUser") - public String getCurrentUser() { - return userService.getCurrentUser().getUserAbbreviate(); - } - - @ModelAttribute("flashMessage") - public String getFlashMessage() { - return null; - } - - private Response handleException(ErrorConstants error) { - log.warn(error.toString()); - return new Response<>(error); - } - - private ResponseExtended handleException(ErrorConstants error, E errorData) { - log.warn(error.toString()); - return new ResponseExtended<>(error, errorData); - } - - @ExceptionHandler(EntityIdIsNullException.class) - public Response handleEntityIdIsNullException(Throwable e) { - return handleException(ErrorConstants.ID_IS_NULL); - } - - @ExceptionHandler(MethodArgumentNotValidException.class) - public ResponseExtended> handleMethodArgumentNotValidException(MethodArgumentNotValidException e) { - final Set errors = e.getBindingResult().getAllErrors().stream() - .filter(error -> error instanceof FieldError) - .map(error -> ((FieldError) error).getField()) - .collect(Collectors.toSet()); - return handleException(ErrorConstants.VALIDATION_ERROR, errors); - } - - @ExceptionHandler(UserIdExistsException.class) - public Response handleUserIdExistsException(Throwable e) { - return handleException(ErrorConstants.USER_ID_EXISTS); - } - - @ExceptionHandler(UserActivationError.class) - public ResponseExtended handleUserActivationError(Throwable e) { - return handleException(ErrorConstants.USER_ACTIVATION_ERROR, e.getMessage()); - } - - @ExceptionHandler(UserLoginExistsException.class) - public ResponseExtended handleUserLoginExistsException(Throwable e) { - return handleException(ErrorConstants.USER_LOGIN_EXISTS, e.getMessage()); - } - - @ExceptionHandler(UserEmailExistsException.class) - public ResponseExtended handleUserEmailExistsException(Throwable e) { - return handleException(ErrorConstants.USER_EMAIL_EXISTS, e.getMessage()); - } - - @ExceptionHandler(UserPasswordsNotValidOrNotMatchException.class) - public Response handleUserPasswordsNotValidOrNotMatchException(Throwable e) { - return handleException(ErrorConstants.USER_PASSWORDS_NOT_VALID_OR_NOT_MATCH); - } - - @ExceptionHandler(UserNotFoundException.class) - public ResponseExtended handleUserNotFoundException(Throwable e) { - return handleException(ErrorConstants.USER_NOT_FOUND, e.getMessage()); - } - - @ExceptionHandler(UserNotActivatedException.class) - public Response handleUserNotActivatedException(Throwable e) { - return handleException(ErrorConstants.USER_NOT_ACTIVATED); - } - - @ExceptionHandler(UserResetKeyError.class) - public ResponseExtended handleUserResetKeyError(Throwable e) { - return handleException(ErrorConstants.USER_RESET_ERROR, e.getMessage()); - } - - @ExceptionHandler(UserIsUndeadException.class) - public ResponseExtended handleUserIsUndeadException(Throwable e) { - return handleException(ErrorConstants.USER_UNDEAD_ERROR, e.getMessage()); - } - - @ExceptionHandler(UserSendingMailException.class) - public ResponseExtended handleUserSendingMailException(Throwable e) { - return handleException(ErrorConstants.USER_SENDING_MAIL_EXCEPTION, e.getMessage()); - } -} diff --git a/src/main/java/ru/ulstu/core/navigation/Page.java b/src/main/java/ru/ulstu/core/navigation/Page.java new file mode 100644 index 0000000..78da453 --- /dev/null +++ b/src/main/java/ru/ulstu/core/navigation/Page.java @@ -0,0 +1,52 @@ +package ru.ulstu.core.navigation; + +import javax.inject.Named; + +@Named +public class Page { + public static final String INDEX = "/index.xhtml"; + public static final String PAPER = "/paper/paper.xhtml"; + public static final String PAPER_LIST = "/paper/papers.xhtml"; + public static final String PAPER_DASHBOARD = "/paper/dashboard.xhtml"; + public static final String GRANT = "/grant/grant.xhtml"; + public static final String GRANT_LIST = "/grant/grants.xhtml"; + public static final String GRANT_DASHBOARD = "/grant/dashboard.xhtml"; + public static final String USER_LIST = "/admin/users.xhtml"; + public static final String LOGOUT = "/logout"; + + public String getIndex() { + return INDEX; + } + + public String getPaperList() { + return PAPER_LIST; + } + + public String getPaperDashboard() { + return PAPER_DASHBOARD; + } + + public String getUserList() { + return USER_LIST; + } + + public String getLogout() { + return LOGOUT; + } + + public String getGrantList() { + return GRANT_LIST; + } + + public String getGrantDashboard() { + return GRANT_DASHBOARD; + } + + public String getPaper() { + return PAPER; + } + + public String getGrant() { + return GRANT; + } +} diff --git a/src/main/java/ru/ulstu/core/util/DateUtils.java b/src/main/java/ru/ulstu/core/util/DateUtils.java index 6a23521..9cd0ae0 100644 --- a/src/main/java/ru/ulstu/core/util/DateUtils.java +++ b/src/main/java/ru/ulstu/core/util/DateUtils.java @@ -63,4 +63,10 @@ public class DateUtils { cal.add(Calendar.YEAR, count); return cal.getTime(); } + + public static LocalDate convertToLocalDate(Date dateToConvert) { + return dateToConvert.toInstant() + .atZone(ZoneId.systemDefault()) + .toLocalDate(); + } } diff --git a/src/main/java/ru/ulstu/core/util/FacesUtil.java b/src/main/java/ru/ulstu/core/util/FacesUtil.java new file mode 100644 index 0000000..74279dd --- /dev/null +++ b/src/main/java/ru/ulstu/core/util/FacesUtil.java @@ -0,0 +1,47 @@ +package ru.ulstu.core.util; + +import javax.faces.FacesException; +import javax.faces.application.FacesMessage; +import javax.faces.context.ExternalContext; +import javax.faces.context.FacesContext; +import java.io.IOException; +import java.util.Map; + +public class FacesUtil { + public static void redirectToPage(FacesContext context, String page, String params) { + ExternalContext extContext = context.getExternalContext(); + String url = extContext.encodeActionURL(context.getApplication().getViewHandler().getActionURL(context, page) + + params); + try { + extContext.redirect(url); + } catch (IOException e) { + throw new FacesException(e); + } + } + + public static void redirectToPage(String page) { + redirectToPage(FacesContext.getCurrentInstance(), page, ""); + } + + public static void redirectToPage(String page, String params) { + redirectToPage(FacesContext.getCurrentInstance(), page, params); + } + + public static Map getRequestParams() { + return FacesContext.getCurrentInstance(). + getExternalContext().getRequestParameterMap(); + } + + public static void showInfoMessage(String summary, String detail) { + FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, summary, detail); + FacesContext fc = FacesContext.getCurrentInstance(); + fc.getExternalContext().getFlash().setKeepMessages(true); + fc.addMessage("messages", message); + } + + public static void showDangerMessage(String summary, String detail) { + FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, summary, detail); + FacesContext.getCurrentInstance().addMessage(null, message); + } + +} diff --git a/src/main/java/ru/ulstu/deadline/service/DeadlineService.java b/src/main/java/ru/ulstu/deadline/service/DeadlineService.java index 039ddbf..42eac92 100644 --- a/src/main/java/ru/ulstu/deadline/service/DeadlineService.java +++ b/src/main/java/ru/ulstu/deadline/service/DeadlineService.java @@ -2,9 +2,11 @@ package ru.ulstu.deadline.service; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import ru.ulstu.core.util.DateUtils; import ru.ulstu.deadline.model.Deadline; import ru.ulstu.deadline.repository.DeadlineRepository; +import java.time.temporal.ChronoUnit; import java.util.Date; import java.util.List; import java.util.stream.Collectors; @@ -47,6 +49,19 @@ public class DeadlineService { return newDeadline; } + public Deadline create(Date date) { + Deadline deadline = new Deadline(); + deadline.setDate(date); + return create(deadline); + } + + public Deadline create(String description, Date date) { + Deadline deadline = new Deadline(); + deadline.setDate(date); + deadline.setDescription(description); + return create(deadline); + } + @Transactional public void remove(Integer deadlineId) { deadlineRepository.deleteById(deadlineId); @@ -55,4 +70,12 @@ public class DeadlineService { public Date findByGrantIdAndDate(Integer id, Date date) { return deadlineRepository.findByGrantIdAndDate(id, date); } + + public Deadline createWithOffset(Date date, long value, ChronoUnit chronoUnit) { + return create(DateUtils.localDateToDate(DateUtils.convertToLocalDate(date).plus(value, chronoUnit))); + } + + public void delete(List deadlines) { + deadlineRepository.deleteInBatch(deadlines); + } } diff --git a/src/main/java/ru/ulstu/grant/controller/GrantDashboardView.java b/src/main/java/ru/ulstu/grant/controller/GrantDashboardView.java new file mode 100644 index 0000000..81b4685 --- /dev/null +++ b/src/main/java/ru/ulstu/grant/controller/GrantDashboardView.java @@ -0,0 +1,76 @@ +package ru.ulstu.grant.controller; + +import ru.ulstu.core.util.FacesUtil; +import ru.ulstu.grant.model.Grant; +import ru.ulstu.grant.service.GrantService; +import ru.ulstu.user.service.UserService; + +import javax.annotation.PostConstruct; +import javax.faces.view.ViewScoped; +import javax.inject.Inject; +import javax.inject.Named; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +@Named +@ViewScoped +public class GrantDashboardView { + @Inject + private GrantService grantService; + + @Inject + private UserService userService; + + private List grants; + + private List selectedGrants = new ArrayList<>(); + + private String newGrantTitle; + + @PostConstruct + public void init() { + grants = grantService.findAllActiveByCurrentUser(); + } + + public List getGrants() { + return grants; + } + + public void create() { + grantService.createByTitle(newGrantTitle); + FacesUtil.showInfoMessage("Статья создана", newGrantTitle); + newGrantTitle = ""; + grants = grantService.findAllActiveByCurrentUser(); + } + + public void deleteSelected() { + grantService.delete(selectedGrants); + grants = grantService.findAllActiveByCurrentUser(); + FacesUtil.showInfoMessage("Было удалено грантов: " + selectedGrants.size(), ""); + } + + public List getGrantStatuses() { + return Arrays.asList(Grant.GrantStatus.values()); + } + + public String getNewGrantTitle() { + return newGrantTitle; + } + + public void setNewGrantTitle(String newGrantTitle) { + this.newGrantTitle = newGrantTitle; + } + + public List getSelectedGrants() { + return selectedGrants; + } + + public void setSelectedGrants(List selectedGrants) { + this.selectedGrants = selectedGrants; + } + + public String getCurrentUser() { + return userService.getCurrentUser().getUserAbbreviate(); + } +} diff --git a/src/main/java/ru/ulstu/grant/controller/GrantStatusConverter.java b/src/main/java/ru/ulstu/grant/controller/GrantStatusConverter.java new file mode 100644 index 0000000..51d1b2c --- /dev/null +++ b/src/main/java/ru/ulstu/grant/controller/GrantStatusConverter.java @@ -0,0 +1,21 @@ +package ru.ulstu.grant.controller; + +import ru.ulstu.grant.model.Grant; + +import javax.faces.component.UIComponent; +import javax.faces.context.FacesContext; +import javax.faces.convert.Converter; +import javax.faces.convert.FacesConverter; + +@FacesConverter(value = "grantStatusConverter") +public class GrantStatusConverter implements Converter { + @Override + public Object getAsObject(FacesContext context, UIComponent component, String value) { + return Grant.GrantStatus.valueOf(value); + } + + @Override + public String getAsString(FacesContext context, UIComponent component, Object value) { + return value == null ? "" : ((Grant.GrantStatus) value).name(); + } +} diff --git a/src/main/java/ru/ulstu/grant/controller/GrantView.java b/src/main/java/ru/ulstu/grant/controller/GrantView.java new file mode 100644 index 0000000..105f5da --- /dev/null +++ b/src/main/java/ru/ulstu/grant/controller/GrantView.java @@ -0,0 +1,94 @@ +package ru.ulstu.grant.controller; + +import ru.ulstu.core.navigation.Page; +import ru.ulstu.core.util.FacesUtil; +import ru.ulstu.deadline.model.Deadline; +import ru.ulstu.deadline.service.DeadlineService; +import ru.ulstu.grant.model.Grant; +import ru.ulstu.grant.service.GrantService; +import ru.ulstu.user.model.User; +import ru.ulstu.user.service.UserService; + +import javax.annotation.PostConstruct; +import javax.faces.view.ViewScoped; +import javax.inject.Inject; +import javax.inject.Named; +import java.io.Serializable; +import java.util.Arrays; +import java.util.Date; +import java.util.List; + +@Named +@ViewScoped +public class GrantView implements Serializable { + @Inject + private GrantService grantService; + + @Inject + private DeadlineService deadlineService; + + @Inject + private UserService userService; + + private Grant grant; + + private Date newDeadlineDate; + + private String newDeadlineDescription; + + @PostConstruct + public void init() { + grant = grantService.findById(Integer.valueOf(FacesUtil.getRequestParams().get("id"))); + newDeadlineDescription = ""; + newDeadlineDate = new Date(); + FacesUtil.showInfoMessage("Статья открыта", ""); + } + + public Grant getGrant() { + return grant; + } + + public void setGrant(Grant grant) { + this.grant = grant; + } + + public List getGrantStatuses() { + return Arrays.asList(Grant.GrantStatus.values()); + } + + public List getAuthors() { + return userService.findAll(); + } + + public String save() { + grantService.save(grant); + FacesUtil.showInfoMessage("Грант сохранен", ""); + return Page.GRANT_LIST + "?faces-redirect=true"; + } + + public Date getNewDeadlineDate() { + return newDeadlineDate; + } + + public void setNewDeadlineDate(Date newDeadlineDate) { + this.newDeadlineDate = newDeadlineDate; + } + + public String getNewDeadlineDescription() { + return newDeadlineDescription; + } + + public void setNewDeadlineDescription(String newDeadlineDescription) { + this.newDeadlineDescription = newDeadlineDescription; + } + + public void deleteDeadline(Deadline deadline) { + grant.getDeadlines().remove(deadline); + } + + public void addDeadline() { + grant.getDeadlines().add(deadlineService.create(newDeadlineDescription, newDeadlineDate)); + newDeadlineDescription = ""; + newDeadlineDate = new Date(); + } +} diff --git a/src/main/java/ru/ulstu/grant/controller/GrantsView.java b/src/main/java/ru/ulstu/grant/controller/GrantsView.java new file mode 100644 index 0000000..f3c693d --- /dev/null +++ b/src/main/java/ru/ulstu/grant/controller/GrantsView.java @@ -0,0 +1,68 @@ +package ru.ulstu.grant.controller; + +import ru.ulstu.core.util.FacesUtil; +import ru.ulstu.grant.model.Grant; +import ru.ulstu.grant.service.GrantService; + +import javax.annotation.PostConstruct; +import javax.faces.view.ViewScoped; +import javax.inject.Inject; +import javax.inject.Named; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +@Named +@ViewScoped +public class GrantsView { + @Inject + private GrantService grantService; + + private List grants; + + private List selectedGrants = new ArrayList<>(); + + private String newGrantTitle; + + @PostConstruct + public void init() { + grants = grantService.findAll(); + } + + public void create() { + grantService.createByTitle(newGrantTitle); + FacesUtil.showInfoMessage("Статья создана", newGrantTitle); + newGrantTitle = ""; + grants = grantService.findAll(); + } + + public void deleteSelected() { + grantService.delete(selectedGrants); + grants = grantService.findAll(); + FacesUtil.showInfoMessage("Было удалено грантов: " + selectedGrants.size(), ""); + } + + public List getGrantStatuses() { + return Arrays.asList(Grant.GrantStatus.values()); + } + + public List getGrants() { + return grants; + } + + public String getNewGrantTitle() { + return newGrantTitle; + } + + public void setNewGrantTitle(String newGrantTitle) { + this.newGrantTitle = newGrantTitle; + } + + public List getSelectedGrants() { + return selectedGrants; + } + + public void setSelectedGrants(List selectedGrants) { + this.selectedGrants = selectedGrants; + } +} diff --git a/src/main/java/ru/ulstu/grant/model/Grant.java b/src/main/java/ru/ulstu/grant/model/Grant.java index 0d16f77..ec6e90f 100644 --- a/src/main/java/ru/ulstu/grant/model/Grant.java +++ b/src/main/java/ru/ulstu/grant/model/Grant.java @@ -41,24 +41,30 @@ import java.util.Set; @DiscriminatorValue("GRANT") public class Grant extends BaseEntity implements UserActivity, EventSource { public enum GrantStatus { - APPLICATION("Заявка"), - ON_COMPETITION("Отправлен на конкурс"), - SUCCESSFUL_PASSAGE("Успешное прохождение"), - IN_WORK("В работе"), - COMPLETED("Завершен"), - FAILED("Провалены сроки"), - LOADED_FROM_KIAS("Загружен автоматически"), - SKIPPED("Не интересует"); + APPLICATION("Заявка", "text-draft"), + ON_COMPETITION("Отправлен на конкурс", "text-review"), + SUCCESSFUL_PASSAGE("Успешное прохождение", "text-accepted"), + IN_WORK("В работе", "text-primary"), + COMPLETED("Завершен", "text-success"), + FAILED("Провалены сроки", "text-failed"), + LOADED_FROM_KIAS("Загружен автоматически", "text-warning"), + SKIPPED("Не интересует", "text-not-accepted"); private final String statusName; + private final String elementClass; - GrantStatus(String statusName) { + GrantStatus(String statusName, String elementClass) { this.statusName = statusName; + this.elementClass = elementClass; } public String getStatusName() { return statusName; } + + public String getElementClass() { + return elementClass; + } } @NotBlank diff --git a/src/main/java/ru/ulstu/grant/page/KiasPage.java b/src/main/java/ru/ulstu/grant/page/KiasPage.java index 49d54a0..b57d804 100644 --- a/src/main/java/ru/ulstu/grant/page/KiasPage.java +++ b/src/main/java/ru/ulstu/grant/page/KiasPage.java @@ -52,4 +52,4 @@ public class KiasPage { public boolean isTableRowGrantLine(DomNode grantElement) { return !((HtmlTableRow) grantElement).getAttribute("class").contains("pagerSavedHeightSpacer"); } -} +} \ No newline at end of file diff --git a/src/main/java/ru/ulstu/grant/service/GrantService.java b/src/main/java/ru/ulstu/grant/service/GrantService.java index cb4cb32..4b2c9d5 100644 --- a/src/main/java/ru/ulstu/grant/service/GrantService.java +++ b/src/main/java/ru/ulstu/grant/service/GrantService.java @@ -27,6 +27,7 @@ import ru.ulstu.user.service.UserService; import java.io.IOException; import java.text.ParseException; +import java.time.temporal.ChronoUnit; import java.util.Arrays; import java.util.Collections; import java.util.Date; @@ -338,4 +339,65 @@ public class GrantService extends BaseService { public void ping(int grantId) throws IOException { pingService.addPing(findById(grantId)); } + + public void save(Grant grant) { + if (isEmpty(grant.getId())) { + create(grant); + } else { + update(grant); + } + } + + @Transactional + public Grant create(Grant grant) { + Grant newGrant = grantRepository.save(grant); + grantNotificationService.sendCreateNotification(newGrant); + return newGrant; + } + + @Transactional + public Integer update(Grant newGrant) { + Grant oldGrant = grantRepository.getOne(newGrant.getId()); + //Grant.GrantStatus oldStatus = oldGrant.getStatus(); + Set oldAuthors = new HashSet<>(oldGrant.getAuthors()); + newGrant = grantRepository.save(newGrant); + for (User author : newGrant.getAuthors()) { + if (!oldAuthors.contains(author)) { + grantNotificationService.sendCreateNotification(newGrant); + } + } + +// if (newGrant.getStatus() != oldStatus) { +// grantNotificationService.statusChangeNotification(newPaper, oldStatus); +// } + + return newGrant.getId(); + } + + public void createByTitle(String newGrantTitle) { + Grant grant = new Grant(); + grant.setTitle(newGrantTitle); + grant.setStatus(APPLICATION); + grant.getAuthors().add(userService.getCurrentUser()); + grant.setLeader(userService.getCurrentUser()); + grant.getDeadlines().add(deadlineService.createWithOffset(new Date(), 1, ChronoUnit.WEEKS)); + create(grant); + } + + public List findAllActiveByCurrentUser() { + return findAllActive() + .stream() + .filter(grant -> grant.getAuthors().contains(userService.getCurrentUser()) || + grant.getLeader().equals(userService.getCurrentUser())) + .collect(toList()); + } + + public void delete(List grants) { + grants.forEach(grant -> delete(grant)); + } + + public void delete(Grant grant) { + deadlineService.delete(grant.getDeadlines()); + grantRepository.delete(grant); + } } diff --git a/src/main/java/ru/ulstu/grant/service/KiasService.java b/src/main/java/ru/ulstu/grant/service/KiasService.java index e8627d3..c4f3ceb 100644 --- a/src/main/java/ru/ulstu/grant/service/KiasService.java +++ b/src/main/java/ru/ulstu/grant/service/KiasService.java @@ -32,7 +32,7 @@ public class KiasService { public List getNewGrantsDto() throws ParseException, IOException { Integer leaderId = userService.findOneByLoginIgnoreCase("admin").getId(); List grants = new ArrayList<>(); - try (final WebClient webClient = new WebClient()) { + try (WebClient webClient = new WebClient()) { webClient.setJavaScriptTimeout(60 * 1000); webClient.getOptions().setThrowExceptionOnScriptError(false); for (Integer year : generateGrantYears()) { diff --git a/src/main/java/ru/ulstu/index/controller/IndexController.java b/src/main/java/ru/ulstu/index/controller/IndexController.java deleted file mode 100644 index f6ab100..0000000 --- a/src/main/java/ru/ulstu/index/controller/IndexController.java +++ /dev/null @@ -1,23 +0,0 @@ -package ru.ulstu.index.controller; - -import org.springframework.stereotype.Controller; -import org.springframework.ui.ModelMap; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import ru.ulstu.core.controller.AdviceController; -import ru.ulstu.user.service.UserService; -import springfox.documentation.annotations.ApiIgnore; - -@Controller() -@RequestMapping(value = "/index") -@ApiIgnore -public class IndexController extends AdviceController { - public IndexController(UserService userService) { - super(userService); - } - - @GetMapping - public void currentUser(ModelMap modelMap) { - //нужен здесь для добавления параметров на стартовой странице - } -} diff --git a/src/main/java/ru/ulstu/index/controller/IndexView.java b/src/main/java/ru/ulstu/index/controller/IndexView.java new file mode 100644 index 0000000..504081d --- /dev/null +++ b/src/main/java/ru/ulstu/index/controller/IndexView.java @@ -0,0 +1,27 @@ +package ru.ulstu.index.controller; + +import ru.ulstu.index.model.Section; + +import javax.annotation.PostConstruct; +import javax.faces.view.ViewScoped; +import javax.inject.Named; +import java.util.ArrayList; +import java.util.List; + +@Named +@ViewScoped +public class IndexView { + private List
sections = new ArrayList<>(); + + @PostConstruct + public void init() { + sections.add(new Section("Статьи", "papers.jpg")); + sections.add(new Section("Конференции", "conf.jpg")); + sections.add(new Section("Гранты", "grants.jpg")); + sections.add(new Section("Проекты", "projects.jpg")); + } + + public List
getSections() { + return sections; + } +} diff --git a/src/main/java/ru/ulstu/index/model/Section.java b/src/main/java/ru/ulstu/index/model/Section.java new file mode 100644 index 0000000..d11a4c9 --- /dev/null +++ b/src/main/java/ru/ulstu/index/model/Section.java @@ -0,0 +1,27 @@ +package ru.ulstu.index.model; + +public class Section { + private String title; + private String image; + + public Section(String title, String image) { + this.title = title; + this.image = image; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getImage() { + return image; + } + + public void setImage(String image) { + this.image = image; + } +} diff --git a/src/main/java/ru/ulstu/paper/controller/PaperDashboardView.java b/src/main/java/ru/ulstu/paper/controller/PaperDashboardView.java new file mode 100644 index 0000000..5bbf85d --- /dev/null +++ b/src/main/java/ru/ulstu/paper/controller/PaperDashboardView.java @@ -0,0 +1,76 @@ +package ru.ulstu.paper.controller; + +import ru.ulstu.core.util.FacesUtil; +import ru.ulstu.paper.model.Paper; +import ru.ulstu.paper.service.PaperService; +import ru.ulstu.user.service.UserService; + +import javax.annotation.PostConstruct; +import javax.faces.view.ViewScoped; +import javax.inject.Inject; +import javax.inject.Named; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +@Named +@ViewScoped +public class PaperDashboardView { + @Inject + private PaperService paperService; + + @Inject + private UserService userService; + + private List papers; + + private List selectedPapers = new ArrayList<>(); + + private String newPaperTitle; + + @PostConstruct + public void init() { + papers = paperService.findAllActiveByCurrentUser(); + } + + public List getPapers() { + return papers; + } + + public void create() { + paperService.createByTitle(newPaperTitle); + FacesUtil.showInfoMessage("Статья создана", newPaperTitle); + newPaperTitle = ""; + papers = paperService.findAllActiveByCurrentUser(); + } + + public void deleteSelected() { + paperService.delete(selectedPapers); + papers = paperService.findAllActiveByCurrentUser(); + FacesUtil.showInfoMessage("Было удалено статей: " + selectedPapers.size(), ""); + } + + public List getPaperStatuses() { + return Arrays.asList(Paper.PaperStatus.values()); + } + + public String getNewPaperTitle() { + return newPaperTitle; + } + + public void setNewPaperTitle(String newPaperTitle) { + this.newPaperTitle = newPaperTitle; + } + + public List getSelectedPapers() { + return selectedPapers; + } + + public void setSelectedPapers(List selectedPapers) { + this.selectedPapers = selectedPapers; + } + + public String getCurrentUser() { + return userService.getCurrentUser().getUserAbbreviate(); + } +} diff --git a/src/main/java/ru/ulstu/paper/controller/PaperStatusConverter.java b/src/main/java/ru/ulstu/paper/controller/PaperStatusConverter.java new file mode 100644 index 0000000..8f809b0 --- /dev/null +++ b/src/main/java/ru/ulstu/paper/controller/PaperStatusConverter.java @@ -0,0 +1,21 @@ +package ru.ulstu.paper.controller; + +import ru.ulstu.paper.model.Paper; + +import javax.faces.component.UIComponent; +import javax.faces.context.FacesContext; +import javax.faces.convert.Converter; +import javax.faces.convert.FacesConverter; + +@FacesConverter(value = "paperStatusConverter") +public class PaperStatusConverter implements Converter { + @Override + public Object getAsObject(FacesContext context, UIComponent component, String value) { + return Paper.PaperStatus.valueOf(value); + } + + @Override + public String getAsString(FacesContext context, UIComponent component, Object value) { + return value == null ? "" : ((Paper.PaperStatus) value).name(); + } +} diff --git a/src/main/java/ru/ulstu/paper/controller/PaperTypeConverter.java b/src/main/java/ru/ulstu/paper/controller/PaperTypeConverter.java new file mode 100644 index 0000000..b06fb38 --- /dev/null +++ b/src/main/java/ru/ulstu/paper/controller/PaperTypeConverter.java @@ -0,0 +1,21 @@ +package ru.ulstu.paper.controller; + +import ru.ulstu.paper.model.Paper; + +import javax.faces.component.UIComponent; +import javax.faces.context.FacesContext; +import javax.faces.convert.Converter; +import javax.faces.convert.FacesConverter; + +@FacesConverter(value = "paperTypeConverter") +public class PaperTypeConverter implements Converter { + @Override + public Object getAsObject(FacesContext context, UIComponent component, String value) { + return Paper.PaperType.valueOf(value); + } + + @Override + public String getAsString(FacesContext context, UIComponent component, Object value) { + return ((Paper.PaperType) value).name(); + } +} diff --git a/src/main/java/ru/ulstu/paper/controller/PaperView.java b/src/main/java/ru/ulstu/paper/controller/PaperView.java new file mode 100644 index 0000000..0a3432a --- /dev/null +++ b/src/main/java/ru/ulstu/paper/controller/PaperView.java @@ -0,0 +1,98 @@ +package ru.ulstu.paper.controller; + +import ru.ulstu.core.navigation.Page; +import ru.ulstu.core.util.FacesUtil; +import ru.ulstu.deadline.model.Deadline; +import ru.ulstu.deadline.service.DeadlineService; +import ru.ulstu.paper.model.Paper; +import ru.ulstu.paper.service.PaperService; +import ru.ulstu.user.model.User; +import ru.ulstu.user.service.UserService; + +import javax.annotation.PostConstruct; +import javax.faces.view.ViewScoped; +import javax.inject.Inject; +import javax.inject.Named; +import java.io.Serializable; +import java.util.Arrays; +import java.util.Date; +import java.util.List; + +@Named +@ViewScoped +public class PaperView implements Serializable { + @Inject + private PaperService paperService; + + @Inject + private DeadlineService deadlineService; + + @Inject + private UserService userService; + + private Paper paper; + + private Date newDeadlineDate; + + private String newDeadlineDescription; + + @PostConstruct + public void init() { + paper = paperService.findPaperById(Integer.valueOf(FacesUtil.getRequestParams().get("id"))); + newDeadlineDescription = ""; + newDeadlineDate = new Date(); + FacesUtil.showInfoMessage("Статья открыта", ""); + } + + public Paper getPaper() { + return paper; + } + + public void setPaper(Paper paper) { + this.paper = paper; + } + + public List getPaperStatuses() { + return Arrays.asList(Paper.PaperStatus.values()); + } + + public List getPaperTypes() { + return Arrays.asList(Paper.PaperType.values()); + } + + public List getAuthors() { + return userService.findAll(); + } + + public String save() { + paperService.save(paper); + FacesUtil.showInfoMessage("Статья сохранена", ""); + return Page.PAPER_LIST + "?faces-redirect=true"; + } + + public Date getNewDeadlineDate() { + return newDeadlineDate; + } + + public void setNewDeadlineDate(Date newDeadlineDate) { + this.newDeadlineDate = newDeadlineDate; + } + + public String getNewDeadlineDescription() { + return newDeadlineDescription; + } + + public void setNewDeadlineDescription(String newDeadlineDescription) { + this.newDeadlineDescription = newDeadlineDescription; + } + + public void deleteDeadline(Deadline deadline) { + paper.getDeadlines().remove(deadline); + } + + public void addDeadline() { + paper.getDeadlines().add(deadlineService.create(newDeadlineDescription, newDeadlineDate)); + newDeadlineDescription = ""; + newDeadlineDate = new Date(); + } +} diff --git a/src/main/java/ru/ulstu/paper/controller/PapersView.java b/src/main/java/ru/ulstu/paper/controller/PapersView.java new file mode 100644 index 0000000..ae5f7e9 --- /dev/null +++ b/src/main/java/ru/ulstu/paper/controller/PapersView.java @@ -0,0 +1,68 @@ +package ru.ulstu.paper.controller; + +import ru.ulstu.core.util.FacesUtil; +import ru.ulstu.paper.model.Paper; +import ru.ulstu.paper.service.PaperService; + +import javax.annotation.PostConstruct; +import javax.faces.view.ViewScoped; +import javax.inject.Inject; +import javax.inject.Named; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +@Named +@ViewScoped +public class PapersView { + @Inject + private PaperService paperService; + + private List papers; + + private List selectedPapers = new ArrayList<>(); + + private String newPaperTitle; + + @PostConstruct + public void init() { + papers = paperService.findAll(); + } + + public void create() { + paperService.createByTitle(newPaperTitle); + FacesUtil.showInfoMessage("Статья создана", newPaperTitle); + newPaperTitle = ""; + papers = paperService.findAll(); + } + + public void deleteSelected() { + paperService.delete(selectedPapers); + papers = paperService.findAll(); + FacesUtil.showInfoMessage("Было удалено статей: " + selectedPapers.size(), ""); + } + + public List getPaperStatuses() { + return Arrays.asList(Paper.PaperStatus.values()); + } + + public List getPapers() { + return papers; + } + + public String getNewPaperTitle() { + return newPaperTitle; + } + + public void setNewPaperTitle(String newPaperTitle) { + this.newPaperTitle = newPaperTitle; + } + + public List getSelectedPapers() { + return selectedPapers; + } + + public void setSelectedPapers(List selectedPapers) { + this.selectedPapers = selectedPapers; + } +} diff --git a/src/main/java/ru/ulstu/paper/model/Paper.java b/src/main/java/ru/ulstu/paper/model/Paper.java index f7b851c..c76acb8 100644 --- a/src/main/java/ru/ulstu/paper/model/Paper.java +++ b/src/main/java/ru/ulstu/paper/model/Paper.java @@ -39,24 +39,30 @@ import java.util.Set; @DiscriminatorValue("PAPER") public class Paper extends BaseEntity implements UserActivity, EventSource { public enum PaperStatus { - ATTENTION("Обратить внимание"), - ON_PREPARATION("На подготовке"), - ON_REVIEW("Отправлена на проверку"), - ACCEPTED("Принята"), - NOT_ACCEPTED("Не принята"), - COMPLETED("Завершена (опубликована)"), - DRAFT("Черновик"), - FAILED("Провалены сроки"); + ATTENTION("Обратить внимание", "text-warning"), + ON_PREPARATION("На подготовке", "text-primary"), + ON_REVIEW("Отправлена на проверку", "text-review"), + ACCEPTED("Принята", "text-accepted"), + NOT_ACCEPTED("Не принята", "text-not-accepted"), + COMPLETED("Завершена (опубликована)", "text-success"), + DRAFT("Черновик", "text-draft"), + FAILED("Провалены сроки", "text-failed"); private final String statusName; + private final String elementClass; - PaperStatus(String name) { + PaperStatus(String name, String elementClass) { this.statusName = name; + this.elementClass = elementClass; } public String getStatusName() { return statusName; } + + public String getElementClass() { + return elementClass; + } } public enum PaperType { @@ -93,7 +99,7 @@ public class Paper extends BaseEntity implements UserActivity, EventSource { @Temporal(TemporalType.TIMESTAMP) private Date updateDate = new Date(); - @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER) + @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, orphanRemoval = true) @JoinColumn(name = "paper_id", unique = true) @Fetch(FetchMode.SUBSELECT) @OrderBy("date") diff --git a/src/main/java/ru/ulstu/paper/service/PaperService.java b/src/main/java/ru/ulstu/paper/service/PaperService.java index 2fee949..3d61c7f 100644 --- a/src/main/java/ru/ulstu/paper/service/PaperService.java +++ b/src/main/java/ru/ulstu/paper/service/PaperService.java @@ -22,6 +22,7 @@ import ru.ulstu.user.service.UserService; import java.io.IOException; import java.text.MessageFormat; +import java.time.temporal.ChronoUnit; import java.util.Arrays; import java.util.Date; import java.util.HashSet; @@ -85,13 +86,20 @@ public class PaperService { return papers; } - private List findAllActive() { + public List findAllActive() { return findAll() .stream() .filter(paper -> paper.getStatus() != COMPLETED && paper.getStatus() != FAILED) .collect(toList()); } + public List findAllActiveByCurrentUser() { + return findAllActive() + .stream() + .filter(paper -> paper.getAuthors().contains(userService.getCurrentUser())) + .collect(toList()); + } + public List findAllActiveDto() { return convert(findAllActive(), PaperDto::new); } @@ -103,17 +111,14 @@ public class PaperService { @Transactional public Integer create(PaperDto paperDto) throws IOException { Paper newPaper = copyFromDto(new Paper(), paperDto); - newPaper = paperRepository.save(newPaper); - paperNotificationService.sendCreateNotification(newPaper); - eventService.createFromPaper(newPaper); - return newPaper.getId(); + return create(newPaper).getId(); } @Transactional public Paper create(Paper paper) { Paper newPaper = paperRepository.save(paper); + newPaper.setCreateDate(new Date()); paperNotificationService.sendCreateNotification(newPaper); - eventService.createFromPaper(newPaper); return newPaper; } @@ -206,10 +211,29 @@ public class PaperService { return paper.getId(); } + @Transactional + public Integer update(Paper newPaper) { + Paper oldPaper = paperRepository.getOne(newPaper.getId()); + Paper.PaperStatus oldStatus = oldPaper.getStatus(); + Set oldAuthors = new HashSet<>(oldPaper.getAuthors()); + newPaper.setUpdateDate(new Date()); + newPaper = paperRepository.save(newPaper); + for (User author : newPaper.getAuthors()) { + if (!oldAuthors.contains(author)) { + paperNotificationService.sendCreateNotification(newPaper); + } + } + + if (newPaper.getStatus() != oldStatus) { + paperNotificationService.statusChangeNotification(newPaper, oldStatus); + } + + return newPaper.getId(); + } + @Transactional public void delete(Integer paperId) { - Paper paper = paperRepository.getOne(paperId); - paperRepository.delete(paper); + delete(paperRepository.getOne(paperId)); } public List getPaperStatuses() { @@ -292,6 +316,14 @@ public class PaperService { } } + public void save(Paper paper) { + if (isEmpty(paper.getId())) { + create(paper); + } else { + update(paper); + } + } + public PaperDto findById(Integer paperId) { return new PaperDto(paperRepository.getOne(paperId)); } @@ -395,4 +427,22 @@ public class PaperService { public void ping(int paperId) throws IOException { pingService.addPing(findPaperById(paperId)); } + + public void createByTitle(String newPaperTitle) { + Paper paper = new Paper(); + paper.setTitle(newPaperTitle); + paper.setStatus(DRAFT); + paper.getAuthors().add(userService.getCurrentUser()); + paper.getDeadlines().add(deadlineService.createWithOffset(new Date(), 1, ChronoUnit.WEEKS)); + create(paper); + } + + public void delete(List papers) { + papers.forEach(paper -> delete(paper)); + } + + public void delete(Paper paper) { + deadlineService.delete(paper.getDeadlines()); + paperRepository.delete(paper); + } } diff --git a/src/main/java/ru/ulstu/user/controller/UserConverter.java b/src/main/java/ru/ulstu/user/controller/UserConverter.java new file mode 100644 index 0000000..61997f4 --- /dev/null +++ b/src/main/java/ru/ulstu/user/controller/UserConverter.java @@ -0,0 +1,26 @@ +package ru.ulstu.user.controller; + +import org.springframework.stereotype.Service; +import ru.ulstu.user.model.User; +import ru.ulstu.user.service.UserService; + +import javax.faces.component.UIComponent; +import javax.faces.context.FacesContext; +import javax.faces.convert.Converter; +import javax.inject.Inject; + +@Service +public class UserConverter implements Converter { + @Inject + private UserService userService; + + @Override + public Object getAsObject(FacesContext context, UIComponent component, String value) { + return value == null ? null : userService.findById(Integer.valueOf(value)); + } + + @Override + public String getAsString(FacesContext context, UIComponent component, Object value) { + return ((User) value).getId().toString(); + } +} diff --git a/src/main/java/ru/ulstu/user/controller/UserDegreeConverter.java b/src/main/java/ru/ulstu/user/controller/UserDegreeConverter.java new file mode 100644 index 0000000..db8ae77 --- /dev/null +++ b/src/main/java/ru/ulstu/user/controller/UserDegreeConverter.java @@ -0,0 +1,21 @@ +package ru.ulstu.user.controller; + +import ru.ulstu.user.model.User; + +import javax.faces.component.UIComponent; +import javax.faces.context.FacesContext; +import javax.faces.convert.Converter; +import javax.faces.convert.FacesConverter; + +@FacesConverter(value = "userDegreeConverter") +public class UserDegreeConverter implements Converter { + @Override + public Object getAsObject(FacesContext context, UIComponent component, String value) { + return User.UserDegree.valueOf(value); + } + + @Override + public String getAsString(FacesContext context, UIComponent component, Object value) { + return ((User.UserDegree) value).name(); + } +} diff --git a/src/main/java/ru/ulstu/user/controller/UserView.java b/src/main/java/ru/ulstu/user/controller/UserView.java new file mode 100644 index 0000000..2a9bf31 --- /dev/null +++ b/src/main/java/ru/ulstu/user/controller/UserView.java @@ -0,0 +1,46 @@ +package ru.ulstu.user.controller; + +import ru.ulstu.core.navigation.Page; +import ru.ulstu.core.util.FacesUtil; +import ru.ulstu.user.model.User; +import ru.ulstu.user.service.UserService; + +import javax.annotation.PostConstruct; +import javax.faces.view.ViewScoped; +import javax.inject.Inject; +import javax.inject.Named; +import java.io.Serializable; +import java.util.Arrays; +import java.util.List; + +@Named +@ViewScoped +public class UserView implements Serializable { + @Inject + private UserService userService; + + private User user; + + @PostConstruct + public void init() { + user = userService.findById(Integer.valueOf(FacesUtil.getRequestParams().get("id"))); + } + + public User getUser() { + return user; + } + + public void setUser(User user) { + this.user = user; + } + + public List getDegrees() { + return Arrays.asList(User.UserDegree.values()); + } + + public String save() { + userService.updateUserInformation(user); + FacesUtil.showInfoMessage("Данные пользователя сохранены", user.getUserAbbreviate()); + return Page.USER_LIST + "?faces-redirect=true"; + } +} diff --git a/src/main/java/ru/ulstu/user/controller/UsersView.java b/src/main/java/ru/ulstu/user/controller/UsersView.java new file mode 100644 index 0000000..31320c9 --- /dev/null +++ b/src/main/java/ru/ulstu/user/controller/UsersView.java @@ -0,0 +1,29 @@ +package ru.ulstu.user.controller; + +import ru.ulstu.user.model.User; +import ru.ulstu.user.service.UserService; + +import javax.annotation.PostConstruct; +import javax.faces.view.ViewScoped; +import javax.inject.Inject; +import javax.inject.Named; +import java.io.Serializable; +import java.util.List; + +@Named +@ViewScoped +public class UsersView implements Serializable { + @Inject + private UserService userService; + + private List users; + + @PostConstruct + public void init() { + users = userService.findAll(); + } + + public List getUsers() { + return users; + } +} diff --git a/src/main/java/ru/ulstu/user/service/UserService.java b/src/main/java/ru/ulstu/user/service/UserService.java index 0f69c8e..c032332 100644 --- a/src/main/java/ru/ulstu/user/service/UserService.java +++ b/src/main/java/ru/ulstu/user/service/UserService.java @@ -1,435 +1,442 @@ -package ru.ulstu.user.service; - -import com.google.common.collect.ImmutableMap; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.context.annotation.Lazy; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.Sort; -import org.springframework.mail.MailException; -import org.springframework.security.core.authority.SimpleGrantedAuthority; -import org.springframework.security.core.context.SecurityContextHolder; -import org.springframework.security.core.userdetails.UserDetails; -import org.springframework.security.core.userdetails.UserDetailsService; -import org.springframework.security.crypto.password.PasswordEncoder; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import org.springframework.util.StringUtils; -import ru.ulstu.conference.service.ConferenceService; -import ru.ulstu.configuration.ApplicationProperties; -import ru.ulstu.core.error.EntityIdIsNullException; -import ru.ulstu.core.jpa.OffsetablePageRequest; -import ru.ulstu.core.model.BaseEntity; -import ru.ulstu.core.model.UserActivity; -import ru.ulstu.core.model.response.PageableItems; -import ru.ulstu.ping.model.Ping; -import ru.ulstu.ping.service.PingService; -import ru.ulstu.user.error.UserActivationError; -import ru.ulstu.user.error.UserBlockedException; -import ru.ulstu.user.error.UserEmailExistsException; -import ru.ulstu.user.error.UserIdExistsException; -import ru.ulstu.user.error.UserIsUndeadException; -import ru.ulstu.user.error.UserLoginExistsException; -import ru.ulstu.user.error.UserNotActivatedException; -import ru.ulstu.user.error.UserNotFoundException; -import ru.ulstu.user.error.UserPasswordsNotValidOrNotMatchException; -import ru.ulstu.user.error.UserResetKeyError; -import ru.ulstu.user.error.UserSendingMailException; -import ru.ulstu.user.model.User; -import ru.ulstu.user.model.UserDto; -import ru.ulstu.user.model.UserInfoNow; -import ru.ulstu.user.model.UserListDto; -import ru.ulstu.user.model.UserResetPasswordDto; -import ru.ulstu.user.model.UserRole; -import ru.ulstu.user.model.UserRoleConstants; -import ru.ulstu.user.model.UserRoleDto; -import ru.ulstu.user.repository.UserRepository; -import ru.ulstu.user.repository.UserRoleRepository; -import ru.ulstu.user.util.UserUtils; -import ru.ulstu.utils.timetable.TimetableService; -import ru.ulstu.utils.timetable.errors.TimetableClientException; -import ru.ulstu.utils.timetable.model.Lesson; - -import javax.mail.MessagingException; -import java.text.ParseException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.stream.Collectors; - -@Service -@Transactional -public class UserService implements UserDetailsService { - private static final String INVITE_USER_EXCEPTION = "Во время отправки приглашения произошла ошибка"; - - private final Logger log = LoggerFactory.getLogger(UserService.class); - private final UserRepository userRepository; - private final PasswordEncoder passwordEncoder; - private final UserRoleRepository userRoleRepository; - private final UserMapper userMapper; - private final MailService mailService; - private final ApplicationProperties applicationProperties; - private final TimetableService timetableService; - private final ConferenceService conferenceService; - private final UserSessionService userSessionService; - private final PingService pingService; - - public UserService(UserRepository userRepository, - PasswordEncoder passwordEncoder, - UserRoleRepository userRoleRepository, - UserMapper userMapper, - MailService mailService, - ApplicationProperties applicationProperties, - @Lazy PingService pingService, - @Lazy ConferenceService conferenceRepository, - @Lazy UserSessionService userSessionService) throws ParseException { - this.userRepository = userRepository; - this.passwordEncoder = passwordEncoder; - this.userRoleRepository = userRoleRepository; - this.userMapper = userMapper; - this.mailService = mailService; - this.applicationProperties = applicationProperties; - this.conferenceService = conferenceRepository; - this.timetableService = new TimetableService(); - this.userSessionService = userSessionService; - this.pingService = pingService; - } - - private User getUserByEmail(String email) { - return userRepository.findOneByEmailIgnoreCase(email); - } - - private User getUserByActivationKey(String activationKey) { - return userRepository.findOneByActivationKey(activationKey); - } - - public User getUserByLogin(String login) { - return userRepository.findOneByLoginIgnoreCase(login); - } - - @Transactional(readOnly = true) - public UserDto getUserWithRolesById(Integer userId) { - final User userEntity = userRepository.findOneWithRolesById(userId); - if (userEntity == null) { - throw new UserNotFoundException(userId.toString()); - } - return userMapper.userEntityToUserDto(userEntity); - } - - @Transactional(readOnly = true) - public PageableItems getAllUsers(int offset, int count) { - final Page page = userRepository.findAll(new OffsetablePageRequest(offset, count, Sort.by("id"))); - return new PageableItems<>(page.getTotalElements(), userMapper.userEntitiesToUserListDtos(page.getContent())); - } - - // TODO: read only active users - public List findAll() { - return userRepository.findAll(); - } - - @Transactional(readOnly = true) - public PageableItems getUserRoles() { - final List roles = userRoleRepository.findAll().stream() - .map(UserRoleDto::new) - .sorted(Comparator.comparing(UserRoleDto::getViewValue)) - .collect(Collectors.toList()); - return new PageableItems<>(roles.size(), roles); - } - - public UserDto createUser(UserDto userDto) { - if (userDto.getId() != null) { - throw new UserIdExistsException(); - } - if (getUserByLogin(userDto.getLogin()) != null) { - throw new UserLoginExistsException(userDto.getLogin()); - } - if (getUserByEmail(userDto.getEmail()) != null) { - throw new UserEmailExistsException(userDto.getEmail()); - } - if (userDto.isPasswordsValid()) { - throw new UserPasswordsNotValidOrNotMatchException(""); - } - User user = userMapper.userDtoToUserEntity(userDto); - user.setActivated(false); - user.setActivationKey(UserUtils.generateActivationKey()); - user.setRoles(Collections.singleton(new UserRole(UserRoleConstants.USER))); - user.setPassword(passwordEncoder.encode(userDto.getPassword())); - user = userRepository.save(user); - mailService.sendActivationEmail(user); - log.debug("Created Information for User: {}", user.getLogin()); - return userMapper.userEntityToUserDto(user); - } - - public UserDto activateUser(String activationKey) { - final User user = getUserByActivationKey(activationKey); - if (user == null) { - throw new UserActivationError(activationKey); - } - user.setActivated(true); - user.setActivationKey(null); - user.setActivationDate(null); - log.debug("Activated user: {}", user.getLogin()); - return userMapper.userEntityToUserDto(userRepository.save(user)); - } - - public UserDto updateUser(UserDto userDto) { - if (userDto.getId() == null) { - throw new EntityIdIsNullException(); - } - if (!Objects.equals( - Optional.ofNullable(getUserByEmail(userDto.getEmail())) - .map(BaseEntity::getId).orElse(userDto.getId()), - userDto.getId())) { - throw new UserEmailExistsException(userDto.getEmail()); - } - if (!Objects.equals( - Optional.ofNullable(getUserByLogin(userDto.getLogin())) - .map(BaseEntity::getId).orElse(userDto.getId()), - userDto.getId())) { - throw new UserLoginExistsException(userDto.getLogin()); - } - User user = userRepository.getOne(userDto.getId()); - if (user == null) { - throw new UserNotFoundException(userDto.getId().toString()); - } - if (applicationProperties.getUndeadUserLogin().equalsIgnoreCase(user.getLogin())) { - userDto.setLogin(applicationProperties.getUndeadUserLogin()); - userDto.setActivated(true); - userDto.setRoles(Collections.singletonList(new UserRoleDto(UserRoleConstants.ADMIN))); - } - user.setLogin(userDto.getLogin()); - user.setFirstName(userDto.getFirstName()); - user.setLastName(userDto.getLastName()); - user.setEmail(userDto.getEmail()); - if (userDto.isActivated() != user.getActivated()) { - if (userDto.isActivated()) { - user.setActivationKey(null); - user.setActivationDate(null); - } else { - user.setActivationKey(UserUtils.generateActivationKey()); - user.setActivationDate(new Date()); - } - } - user.setActivated(userDto.isActivated()); - final Set roles = userMapper.rolesFromDto(userDto.getRoles()); - user.setRoles(roles.isEmpty() - ? Collections.singleton(new UserRole(UserRoleConstants.USER)) - : roles); - if (!StringUtils.isEmpty(userDto.getOldPassword())) { - if (userDto.isPasswordsValid() || !userDto.isOldPasswordValid()) { - throw new UserPasswordsNotValidOrNotMatchException(""); - } - if (!passwordEncoder.matches(userDto.getOldPassword(), user.getPassword())) { - throw new UserPasswordsNotValidOrNotMatchException(""); - } - user.setPassword(passwordEncoder.encode(userDto.getPassword())); - log.debug("Changed password for User: {}", user.getLogin()); - } - user = userRepository.save(user); - log.debug("Changed Information for User: {}", user.getLogin()); - return userMapper.userEntityToUserDto(user); - } - - public UserDto updateUserInformation(User user, UserDto updateUser) { - user.setFirstName(updateUser.getFirstName()); - user.setLastName(updateUser.getLastName()); - user.setEmail(updateUser.getEmail()); - user.setLogin(updateUser.getLogin()); - user = userRepository.save(user); - log.debug("Updated Information for User: {}", user.getLogin()); - return userMapper.userEntityToUserDto(user); - } - - public void changeUserPassword(User user, Map payload) { - if (!payload.get("password").equals(payload.get("confirmPassword"))) { - throw new UserPasswordsNotValidOrNotMatchException(""); - } - if (!passwordEncoder.matches(payload.get("oldPassword"), user.getPassword())) { - throw new UserPasswordsNotValidOrNotMatchException("Старый пароль введен неправильно"); - } - user.setPassword(passwordEncoder.encode(payload.get("password"))); - log.debug("Changed password for User: {}", user.getLogin()); - userRepository.save(user); - - mailService.sendChangePasswordMail(user); - } - - public boolean requestUserPasswordReset(String email) { - User user = userRepository.findOneByEmailIgnoreCase(email); - if (user == null) { - throw new UserNotFoundException(email); - } - if (!user.getActivated()) { - throw new UserNotActivatedException(); - } - user.setResetKey(UserUtils.generateResetKey()); - user.setResetDate(new Date()); - user = userRepository.save(user); - try { - mailService.sendPasswordResetMail(user); - } catch (MessagingException | MailException e) { - throw new UserSendingMailException(email); - } - log.debug("Created Reset Password Request for User: {}", user.getLogin()); - return true; - } - - public boolean completeUserPasswordReset(UserResetPasswordDto userResetPasswordDto) { - if (!userResetPasswordDto.isPasswordsValid()) { - throw new UserPasswordsNotValidOrNotMatchException("Пароли не совпадают"); - } - User user = userRepository.findOneByResetKey(userResetPasswordDto.getResetKey()); - if (user == null) { - throw new UserResetKeyError(userResetPasswordDto.getResetKey()); - } - user.setPassword(passwordEncoder.encode(userResetPasswordDto.getPassword())); - user.setResetKey(null); - user.setResetDate(null); - user = userRepository.save(user); - - mailService.sendChangePasswordMail(user); - - log.debug("Reset Password for User: {}", user.getLogin()); - return true; - } - - public UserDto deleteUser(Integer userId) { - final User user = userRepository.getOne(userId); - if (user == null) { - throw new UserNotFoundException(userId.toString()); - } - if (applicationProperties.getUndeadUserLogin().equalsIgnoreCase(user.getLogin())) { - throw new UserIsUndeadException(user.getLogin()); - } - userRepository.delete(user); - log.debug("Deleted User: {}", user.getLogin()); - return userMapper.userEntityToUserDto(user); - } - - @Override - public UserDetails loadUserByUsername(String username) { - final User user = userRepository.findOneByLoginIgnoreCase(username); - if (user == null) { - throw new UserNotFoundException(username); - } - if (!user.getActivated()) { - throw new UserNotActivatedException(); - } - if (user.getBlocker() != null) { - throw new UserBlockedException(String.format("Вы заблокированы пользователем %s", user.getBlocker().getUserAbbreviate())); - } - return new org.springframework.security.core.userdetails.User(user.getLogin(), - user.getPassword(), - Optional.ofNullable(user.getRoles()).orElse(Collections.emptySet()).stream() - .map(role -> new SimpleGrantedAuthority(role.getName())) - .collect(Collectors.toList())); - } - - public List findByIds(List ids) { - return userRepository.findAllById(ids); - } - - public User findById(Integer id) { - return userRepository.getOne(id); - } - - public User getCurrentUser() { - String login = UserUtils.getCurrentUserLogin(SecurityContextHolder.getContext()); - User user = userRepository.findOneByLoginIgnoreCase(login); - if (user == null) { - throw new UserNotFoundException(login); - } - return user; - } - - public List filterByAgeAndDegree(boolean hasDegree, boolean hasAge) { - return userRepository.filterByAgeAndDegree(hasDegree, hasAge); - } - - public void inviteUser(String email) throws UserSendingMailException { - if (userRepository.findOneByEmailIgnoreCase(email) != null) { - throw new UserEmailExistsException(email); - } - - String password = UserUtils.generatePassword(); - - User user = new User(); - user.setPassword(passwordEncoder.encode(password)); - user.setLogin(email); - user.setEmail(email); - user.setFirstName("user"); - user.setLastName("user"); - user.setActivated(true); - userRepository.save(user); - - Map variables = ImmutableMap.of("password", password, "email", email); - try { - mailService.sendInviteMail(variables, email); - } catch (MessagingException | MailException e) { - throw new UserSendingMailException(email); - } - } - - public User findOneByLoginIgnoreCase(String login) { - return userRepository.findOneByLoginIgnoreCase(login); - } - - public Map getUsersInfo() { - List usersInfoNow = new ArrayList<>(); - String err = ""; - - for (User user : userRepository.findAll()) { - Lesson lesson = null; - try { - lesson = timetableService.getCurrentLesson(user.getUserAbbreviate()); - } catch (TimetableClientException e) { - err = "Не удалось загрузить расписание"; - } - usersInfoNow.add(new UserInfoNow( - lesson, - conferenceService.getActiveConferenceByUser(user), - user, - userSessionService.isOnline(user)) - ); - } - return ImmutableMap.of("users", usersInfoNow, "error", err); - } - - public Map getActivitiesPings(Integer userId, - String activityName) { - User user = null; - if (userId != null) { - user = findById(userId); - } - Map activitiesPings = new HashMap<>(); - - for (Ping ping : pingService.getPings(activityName)) { - UserActivity activity = ping.getActivity(); - - if (user != null && !activity.getActivityUsers().contains(user)) { - continue; - } - - if (activitiesPings.containsKey(activity.getTitle())) { - activitiesPings.put(activity.getTitle(), activitiesPings.get(activity.getTitle()) + 1); - } else { - activitiesPings.put(activity.getTitle(), 1); - } - - } - return activitiesPings; - } - - public void blockUser(int userId) { - User userToBlock = findById(userId); - userToBlock.setBlocker(getCurrentUser()); - userRepository.save(userToBlock); - } -} +package ru.ulstu.user.service; + +import com.google.common.collect.ImmutableMap; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.context.annotation.Lazy; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Sort; +import org.springframework.mail.MailException; +import org.springframework.security.core.authority.SimpleGrantedAuthority; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.security.core.userdetails.UserDetailsService; +import org.springframework.security.crypto.password.PasswordEncoder; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.StringUtils; +import ru.ulstu.conference.service.ConferenceService; +import ru.ulstu.configuration.ApplicationProperties; +import ru.ulstu.core.error.EntityIdIsNullException; +import ru.ulstu.core.jpa.OffsetablePageRequest; +import ru.ulstu.core.model.BaseEntity; +import ru.ulstu.core.model.UserActivity; +import ru.ulstu.core.model.response.PageableItems; +import ru.ulstu.ping.model.Ping; +import ru.ulstu.ping.service.PingService; +import ru.ulstu.user.error.UserActivationError; +import ru.ulstu.user.error.UserBlockedException; +import ru.ulstu.user.error.UserEmailExistsException; +import ru.ulstu.user.error.UserIdExistsException; +import ru.ulstu.user.error.UserIsUndeadException; +import ru.ulstu.user.error.UserLoginExistsException; +import ru.ulstu.user.error.UserNotActivatedException; +import ru.ulstu.user.error.UserNotFoundException; +import ru.ulstu.user.error.UserPasswordsNotValidOrNotMatchException; +import ru.ulstu.user.error.UserResetKeyError; +import ru.ulstu.user.error.UserSendingMailException; +import ru.ulstu.user.model.User; +import ru.ulstu.user.model.UserDto; +import ru.ulstu.user.model.UserInfoNow; +import ru.ulstu.user.model.UserListDto; +import ru.ulstu.user.model.UserResetPasswordDto; +import ru.ulstu.user.model.UserRole; +import ru.ulstu.user.model.UserRoleConstants; +import ru.ulstu.user.model.UserRoleDto; +import ru.ulstu.user.repository.UserRepository; +import ru.ulstu.user.repository.UserRoleRepository; +import ru.ulstu.user.util.UserUtils; +import ru.ulstu.utils.timetable.TimetableService; +import ru.ulstu.utils.timetable.errors.TimetableClientException; +import ru.ulstu.utils.timetable.model.Lesson; + +import javax.mail.MessagingException; +import java.text.ParseException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; +import java.util.stream.Collectors; + +@Service +@Transactional +public class UserService implements UserDetailsService { + private static final String INVITE_USER_EXCEPTION = "Во время отправки приглашения произошла ошибка"; + + private final Logger log = LoggerFactory.getLogger(UserService.class); + private final UserRepository userRepository; + private final PasswordEncoder passwordEncoder; + private final UserRoleRepository userRoleRepository; + private final UserMapper userMapper; + private final MailService mailService; + private final ApplicationProperties applicationProperties; + private final TimetableService timetableService; + private final ConferenceService conferenceService; + private final UserSessionService userSessionService; + private final PingService pingService; + + public UserService(UserRepository userRepository, + PasswordEncoder passwordEncoder, + UserRoleRepository userRoleRepository, + UserMapper userMapper, + MailService mailService, + ApplicationProperties applicationProperties, + @Lazy PingService pingService, + @Lazy ConferenceService conferenceRepository, + @Lazy UserSessionService userSessionService) throws ParseException { + this.userRepository = userRepository; + this.passwordEncoder = passwordEncoder; + this.userRoleRepository = userRoleRepository; + this.userMapper = userMapper; + this.mailService = mailService; + this.applicationProperties = applicationProperties; + this.conferenceService = conferenceRepository; + this.timetableService = new TimetableService(); + this.userSessionService = userSessionService; + this.pingService = pingService; + } + + private User getUserByEmail(String email) { + return userRepository.findOneByEmailIgnoreCase(email); + } + + private User getUserByActivationKey(String activationKey) { + return userRepository.findOneByActivationKey(activationKey); + } + + public User getUserByLogin(String login) { + return userRepository.findOneByLoginIgnoreCase(login); + } + + @Transactional(readOnly = true) + public UserDto getUserWithRolesById(Integer userId) { + final User userEntity = userRepository.findOneWithRolesById(userId); + if (userEntity == null) { + throw new UserNotFoundException(userId.toString()); + } + return userMapper.userEntityToUserDto(userEntity); + } + + @Transactional(readOnly = true) + public PageableItems getAllUsers(int offset, int count) { + final Page page = userRepository.findAll(new OffsetablePageRequest(offset, count, Sort.by("id"))); + return new PageableItems<>(page.getTotalElements(), userMapper.userEntitiesToUserListDtos(page.getContent())); + } + + // TODO: read only active users + public List findAll() { + return userRepository.findAll(); + } + + @Transactional(readOnly = true) + public PageableItems getUserRoles() { + final List roles = userRoleRepository.findAll().stream() + .map(UserRoleDto::new) + .sorted(Comparator.comparing(UserRoleDto::getViewValue)) + .collect(Collectors.toList()); + return new PageableItems<>(roles.size(), roles); + } + + public UserDto createUser(UserDto userDto) { + if (userDto.getId() != null) { + throw new UserIdExistsException(); + } + if (getUserByLogin(userDto.getLogin()) != null) { + throw new UserLoginExistsException(userDto.getLogin()); + } + if (getUserByEmail(userDto.getEmail()) != null) { + throw new UserEmailExistsException(userDto.getEmail()); + } + if (userDto.isPasswordsValid()) { + throw new UserPasswordsNotValidOrNotMatchException(""); + } + User user = userMapper.userDtoToUserEntity(userDto); + user.setActivated(false); + user.setActivationKey(UserUtils.generateActivationKey()); + user.setRoles(Collections.singleton(new UserRole(UserRoleConstants.USER))); + user.setPassword(passwordEncoder.encode(userDto.getPassword())); + user = userRepository.save(user); + mailService.sendActivationEmail(user); + log.debug("Created Information for User: {}", user.getLogin()); + return userMapper.userEntityToUserDto(user); + } + + public UserDto activateUser(String activationKey) { + final User user = getUserByActivationKey(activationKey); + if (user == null) { + throw new UserActivationError(activationKey); + } + user.setActivated(true); + user.setActivationKey(null); + user.setActivationDate(null); + log.debug("Activated user: {}", user.getLogin()); + return userMapper.userEntityToUserDto(userRepository.save(user)); + } + + public UserDto updateUser(UserDto userDto) { + if (userDto.getId() == null) { + throw new EntityIdIsNullException(); + } + if (!Objects.equals( + Optional.ofNullable(getUserByEmail(userDto.getEmail())) + .map(BaseEntity::getId).orElse(userDto.getId()), + userDto.getId())) { + throw new UserEmailExistsException(userDto.getEmail()); + } + if (!Objects.equals( + Optional.ofNullable(getUserByLogin(userDto.getLogin())) + .map(BaseEntity::getId).orElse(userDto.getId()), + userDto.getId())) { + throw new UserLoginExistsException(userDto.getLogin()); + } + User user = userRepository.getOne(userDto.getId()); + if (user == null) { + throw new UserNotFoundException(userDto.getId().toString()); + } + if (applicationProperties.getUndeadUserLogin().equalsIgnoreCase(user.getLogin())) { + userDto.setLogin(applicationProperties.getUndeadUserLogin()); + userDto.setActivated(true); + userDto.setRoles(Collections.singletonList(new UserRoleDto(UserRoleConstants.ADMIN))); + } + user.setLogin(userDto.getLogin()); + user.setFirstName(userDto.getFirstName()); + user.setLastName(userDto.getLastName()); + user.setEmail(userDto.getEmail()); + if (userDto.isActivated() != user.getActivated()) { + if (userDto.isActivated()) { + user.setActivationKey(null); + user.setActivationDate(null); + } else { + user.setActivationKey(UserUtils.generateActivationKey()); + user.setActivationDate(new Date()); + } + } + user.setActivated(userDto.isActivated()); + final Set roles = userMapper.rolesFromDto(userDto.getRoles()); + user.setRoles(roles.isEmpty() + ? Collections.singleton(new UserRole(UserRoleConstants.USER)) + : roles); + if (!StringUtils.isEmpty(userDto.getOldPassword())) { + if (userDto.isPasswordsValid() || !userDto.isOldPasswordValid()) { + throw new UserPasswordsNotValidOrNotMatchException(""); + } + if (!passwordEncoder.matches(userDto.getOldPassword(), user.getPassword())) { + throw new UserPasswordsNotValidOrNotMatchException(""); + } + user.setPassword(passwordEncoder.encode(userDto.getPassword())); + log.debug("Changed password for User: {}", user.getLogin()); + } + user = userRepository.save(user); + log.debug("Changed Information for User: {}", user.getLogin()); + return userMapper.userEntityToUserDto(user); + } + + public User updateUserInformation(User user) { + return userRepository.save(user); + } + + public UserDto updateUserInformation(User user, UserDto updateUser) { + user.setFirstName(updateUser.getFirstName()); + user.setLastName(updateUser.getLastName()); + user.setEmail(updateUser.getEmail()); + user.setLogin(updateUser.getLogin()); + user = updateUserInformation(user); + log.debug("Updated Information for User: {}", user.getLogin()); + return userMapper.userEntityToUserDto(user); + } + + public void changeUserPassword(User user, Map payload) { + if (!payload.get("password").equals(payload.get("confirmPassword"))) { + throw new UserPasswordsNotValidOrNotMatchException(""); + } + if (!passwordEncoder.matches(payload.get("oldPassword"), user.getPassword())) { + throw new UserPasswordsNotValidOrNotMatchException("Старый пароль введен неправильно"); + } + user.setPassword(passwordEncoder.encode(payload.get("password"))); + log.debug("Changed password for User: {}", user.getLogin()); + userRepository.save(user); + + mailService.sendChangePasswordMail(user); + } + + public boolean requestUserPasswordReset(String email) { + User user = userRepository.findOneByEmailIgnoreCase(email); + if (user == null) { + throw new UserNotFoundException(email); + } + if (!user.getActivated()) { + throw new UserNotActivatedException(); + } + user.setResetKey(UserUtils.generateResetKey()); + user.setResetDate(new Date()); + user = userRepository.save(user); + try { + mailService.sendPasswordResetMail(user); + } catch (MessagingException | MailException e) { + throw new UserSendingMailException(email); + } + log.debug("Created Reset Password Request for User: {}", user.getLogin()); + return true; + } + + public boolean completeUserPasswordReset(UserResetPasswordDto userResetPasswordDto) { + if (!userResetPasswordDto.isPasswordsValid()) { + throw new UserPasswordsNotValidOrNotMatchException("Пароли не совпадают"); + } + User user = userRepository.findOneByResetKey(userResetPasswordDto.getResetKey()); + if (user == null) { + throw new UserResetKeyError(userResetPasswordDto.getResetKey()); + } + user.setPassword(passwordEncoder.encode(userResetPasswordDto.getPassword())); + user.setResetKey(null); + user.setResetDate(null); + user = userRepository.save(user); + + mailService.sendChangePasswordMail(user); + + log.debug("Reset Password for User: {}", user.getLogin()); + return true; + } + + public UserDto deleteUser(Integer userId) { + final User user = userRepository.getOne(userId); + if (user == null) { + throw new UserNotFoundException(userId.toString()); + } + if (applicationProperties.getUndeadUserLogin().equalsIgnoreCase(user.getLogin())) { + throw new UserIsUndeadException(user.getLogin()); + } + userRepository.delete(user); + log.debug("Deleted User: {}", user.getLogin()); + return userMapper.userEntityToUserDto(user); + } + + @Override + public UserDetails loadUserByUsername(String username) { + final User user = userRepository.findOneByLoginIgnoreCase(username); + if (user == null) { + throw new UserNotFoundException(username); + } + if (!user.getActivated()) { + throw new UserNotActivatedException(); + } + if (user.getBlocker() != null) { + throw new UserBlockedException(String.format("Вы заблокированы пользователем %s", user.getBlocker().getUserAbbreviate())); + } + return new org.springframework.security.core.userdetails.User(user.getLogin(), + user.getPassword(), + Optional.ofNullable(user.getRoles()).orElse(Collections.emptySet()).stream() + .map(role -> new SimpleGrantedAuthority(role.getName())) + .collect(Collectors.toList())); + } + + public List findByIds(List ids) { + return userRepository.findAllById(ids); + } + + public User findById(Integer id) { + return userRepository.getOne(id); + } + + public User getCurrentUser() { + String loginOrEmail = UserUtils.getCurrentUserLoginOrEmail(SecurityContextHolder.getContext()); + User user = userRepository.findOneByLoginIgnoreCase(loginOrEmail); + if (user == null) { + user = userRepository.findOneByEmailIgnoreCase(loginOrEmail); + } + if (user == null) { + throw new UserNotFoundException(loginOrEmail); + } + return user; + } + + public List filterByAgeAndDegree(boolean hasDegree, boolean hasAge) { + return userRepository.filterByAgeAndDegree(hasDegree, hasAge); + } + + public void inviteUser(String email) throws UserSendingMailException { + if (userRepository.findOneByEmailIgnoreCase(email) != null) { + throw new UserEmailExistsException(email); + } + + String password = UserUtils.generatePassword(); + + User user = new User(); + user.setPassword(passwordEncoder.encode(password)); + user.setLogin(email); + user.setEmail(email); + user.setFirstName("user"); + user.setLastName("user"); + user.setActivated(true); + userRepository.save(user); + + Map variables = ImmutableMap.of("password", password, "email", email); + try { + mailService.sendInviteMail(variables, email); + } catch (MessagingException | MailException e) { + throw new UserSendingMailException(email); + } + } + + public User findOneByLoginIgnoreCase(String login) { + return userRepository.findOneByLoginIgnoreCase(login); + } + + public Map getUsersInfo() { + List usersInfoNow = new ArrayList<>(); + String err = ""; + + for (User user : userRepository.findAll()) { + Lesson lesson = null; + try { + lesson = timetableService.getCurrentLesson(user.getUserAbbreviate()); + } catch (TimetableClientException e) { + err = "Не удалось загрузить расписание"; + } + usersInfoNow.add(new UserInfoNow( + lesson, + conferenceService.getActiveConferenceByUser(user), + user, + userSessionService.isOnline(user)) + ); + } + return ImmutableMap.of("users", usersInfoNow, "error", err); + } + + public Map getActivitiesPings(Integer userId, + String activityName) { + User user = null; + if (userId != null) { + user = findById(userId); + } + Map activitiesPings = new HashMap<>(); + + for (Ping ping : pingService.getPings(activityName)) { + UserActivity activity = ping.getActivity(); + + if (user != null && !activity.getActivityUsers().contains(user)) { + continue; + } + + if (activitiesPings.containsKey(activity.getTitle())) { + activitiesPings.put(activity.getTitle(), activitiesPings.get(activity.getTitle()) + 1); + } else { + activitiesPings.put(activity.getTitle(), 1); + } + + } + return activitiesPings; + } + + public void blockUser(int userId) { + User userToBlock = findById(userId); + userToBlock.setBlocker(getCurrentUser()); + userRepository.save(userToBlock); + } +} diff --git a/src/main/java/ru/ulstu/user/util/UserUtils.java b/src/main/java/ru/ulstu/user/util/UserUtils.java index 090240b..6f51633 100644 --- a/src/main/java/ru/ulstu/user/util/UserUtils.java +++ b/src/main/java/ru/ulstu/user/util/UserUtils.java @@ -4,6 +4,7 @@ import org.apache.commons.lang3.RandomStringUtils; import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContext; import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.security.oauth2.core.oidc.user.DefaultOidcUser; import ru.ulstu.configuration.Constants; public class UserUtils { @@ -17,7 +18,7 @@ public class UserUtils { return RandomStringUtils.randomNumeric(DEF_COUNT); } - public static String getCurrentUserLogin(SecurityContext securityContext) { + public static String getCurrentUserLoginOrEmail(SecurityContext securityContext) { if (securityContext == null) { return null; } @@ -27,6 +28,10 @@ public class UserUtils { final UserDetails springSecurityUser = (UserDetails) authentication.getPrincipal(); return springSecurityUser.getUsername(); } + if (authentication.getPrincipal() instanceof DefaultOidcUser) { + final DefaultOidcUser oauth2User = (DefaultOidcUser) authentication.getPrincipal(); + return oauth2User.getEmail(); + } if (authentication.getPrincipal() instanceof String) { return (String) authentication.getPrincipal(); } diff --git a/src/main/resources/META-INF/resources/admin/user.xhtml b/src/main/resources/META-INF/resources/admin/user.xhtml new file mode 100644 index 0000000..ec12052 --- /dev/null +++ b/src/main/resources/META-INF/resources/admin/user.xhtml @@ -0,0 +1,113 @@ + + + + + + Редактирование пользователя + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/META-INF/resources/admin/users.xhtml b/src/main/resources/META-INF/resources/admin/users.xhtml new file mode 100644 index 0000000..ba394a0 --- /dev/null +++ b/src/main/resources/META-INF/resources/admin/users.xhtml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + #{user.userAbbreviate} + + + + + + + + + + diff --git a/src/main/resources/META-INF/resources/basicTemplate.xhtml b/src/main/resources/META-INF/resources/basicTemplate.xhtml new file mode 100644 index 0000000..578bea6 --- /dev/null +++ b/src/main/resources/META-INF/resources/basicTemplate.xhtml @@ -0,0 +1,51 @@ + + + + + + <ui:insert name="header">NG-Tracker</ui:insert> + + + + + + + + + +
+
+
+ + + + + + + + + + + + + + + + +
+ + Content +
+
+
+
+
+ diff --git a/src/main/resources/META-INF/resources/css/google/droid.css b/src/main/resources/META-INF/resources/css/google/droid.css new file mode 100644 index 0000000..c321e4d --- /dev/null +++ b/src/main/resources/META-INF/resources/css/google/droid.css @@ -0,0 +1,35 @@ +/* latin */ +@font-face { + font-family: 'Droid Serif'; + font-style: italic; + font-weight: 400; + src: local('Droid Serif Italic'), local('DroidSerif-Italic'), url(https://fonts.gstatic.com/s/droidserif/v8/tDbK2oqRg1oM3QBjjcaDkOr4nAfcHg.woff2) format('woff2'); + unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; +} + +/* latin */ +@font-face { + font-family: 'Droid Serif'; + font-style: italic; + font-weight: 700; + src: local('Droid Serif Bold Italic'), local('DroidSerif-BoldItalic'), url(https://fonts.gstatic.com/s/droidserif/v8/tDbX2oqRg1oM3QBjjcaDkOr4lLz5CwOnSA.woff2) format('woff2'); + unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; +} + +/* latin */ +@font-face { + font-family: 'Droid Serif'; + font-style: normal; + font-weight: 400; + src: local('Droid Serif Regular'), local('DroidSerif-Regular'), url(https://fonts.gstatic.com/s/droidserif/v8/tDbI2oqRg1oM3QBjjcaDkOr9rAU.woff2) format('woff2'); + unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; +} + +/* latin */ +@font-face { + font-family: 'Droid Serif'; + font-style: normal; + font-weight: 700; + src: local('Droid Serif Bold'), local('DroidSerif-Bold'), url(https://fonts.gstatic.com/s/droidserif/v8/tDbV2oqRg1oM3QBjjcaDkOJGiRD7OwE.woff2) format('woff2'); + unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; +} diff --git a/src/main/resources/META-INF/resources/css/google/kaushan.css b/src/main/resources/META-INF/resources/css/google/kaushan.css new file mode 100644 index 0000000..ebc3fd5 --- /dev/null +++ b/src/main/resources/META-INF/resources/css/google/kaushan.css @@ -0,0 +1,17 @@ +/* latin-ext */ +@font-face { + font-family: 'Kaushan Script'; + font-style: normal; + font-weight: 400; + src: local('Kaushan Script'), local('KaushanScript-Regular'), url(https://fonts.gstatic.com/s/kaushanscript/v6/vm8vdRfvXFLG3OLnsO15WYS5DG72wNJHMw.woff2) format('woff2'); + unicode-range: U+0100-024F, U+0259, U+1E00-1EFF, U+2020, U+20A0-20AB, U+20AD-20CF, U+2113, U+2C60-2C7F, U+A720-A7FF; +} + +/* latin */ +@font-face { + font-family: 'Kaushan Script'; + font-style: normal; + font-weight: 400; + src: local('Kaushan Script'), local('KaushanScript-Regular'), url(https://fonts.gstatic.com/s/kaushanscript/v6/vm8vdRfvXFLG3OLnsO15WYS5DG74wNI.woff2) format('woff2'); + unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; +} diff --git a/src/main/resources/META-INF/resources/css/google/montserrat.css b/src/main/resources/META-INF/resources/css/google/montserrat.css new file mode 100644 index 0000000..26c55ad --- /dev/null +++ b/src/main/resources/META-INF/resources/css/google/montserrat.css @@ -0,0 +1,89 @@ +/* cyrillic-ext */ +@font-face { + font-family: 'Montserrat'; + font-style: normal; + font-weight: 400; + src: local('Montserrat Regular'), local('Montserrat-Regular'), url(https://fonts.gstatic.com/s/montserrat/v12/JTUSjIg1_i6t8kCHKm459WRhyzbi.woff2) format('woff2'); + unicode-range: U+0460-052F, U+1C80-1C88, U+20B4, U+2DE0-2DFF, U+A640-A69F, U+FE2E-FE2F; +} + +/* cyrillic */ +@font-face { + font-family: 'Montserrat'; + font-style: normal; + font-weight: 400; + src: local('Montserrat Regular'), local('Montserrat-Regular'), url(https://fonts.gstatic.com/s/montserrat/v12/JTUSjIg1_i6t8kCHKm459W1hyzbi.woff2) format('woff2'); + unicode-range: U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; +} + +/* vietnamese */ +@font-face { + font-family: 'Montserrat'; + font-style: normal; + font-weight: 400; + src: local('Montserrat Regular'), local('Montserrat-Regular'), url(https://fonts.gstatic.com/s/montserrat/v12/JTUSjIg1_i6t8kCHKm459WZhyzbi.woff2) format('woff2'); + unicode-range: U+0102-0103, U+0110-0111, U+1EA0-1EF9, U+20AB; +} + +/* latin-ext */ +@font-face { + font-family: 'Montserrat'; + font-style: normal; + font-weight: 400; + src: local('Montserrat Regular'), local('Montserrat-Regular'), url(https://fonts.gstatic.com/s/montserrat/v12/JTUSjIg1_i6t8kCHKm459Wdhyzbi.woff2) format('woff2'); + unicode-range: U+0100-024F, U+0259, U+1E00-1EFF, U+2020, U+20A0-20AB, U+20AD-20CF, U+2113, U+2C60-2C7F, U+A720-A7FF; +} + +/* latin */ +@font-face { + font-family: 'Montserrat'; + font-style: normal; + font-weight: 400; + src: local('Montserrat Regular'), local('Montserrat-Regular'), url(https://fonts.gstatic.com/s/montserrat/v12/JTUSjIg1_i6t8kCHKm459Wlhyw.woff2) format('woff2'); + unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; +} + +/* cyrillic-ext */ +@font-face { + font-family: 'Montserrat'; + font-style: normal; + font-weight: 700; + src: local('Montserrat Bold'), local('Montserrat-Bold'), url(https://fonts.gstatic.com/s/montserrat/v12/JTURjIg1_i6t8kCHKm45_dJE3gTD_u50.woff2) format('woff2'); + unicode-range: U+0460-052F, U+1C80-1C88, U+20B4, U+2DE0-2DFF, U+A640-A69F, U+FE2E-FE2F; +} + +/* cyrillic */ +@font-face { + font-family: 'Montserrat'; + font-style: normal; + font-weight: 700; + src: local('Montserrat Bold'), local('Montserrat-Bold'), url(https://fonts.gstatic.com/s/montserrat/v12/JTURjIg1_i6t8kCHKm45_dJE3g3D_u50.woff2) format('woff2'); + unicode-range: U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; +} + +/* vietnamese */ +@font-face { + font-family: 'Montserrat'; + font-style: normal; + font-weight: 700; + src: local('Montserrat Bold'), local('Montserrat-Bold'), url(https://fonts.gstatic.com/s/montserrat/v12/JTURjIg1_i6t8kCHKm45_dJE3gbD_u50.woff2) format('woff2'); + unicode-range: U+0102-0103, U+0110-0111, U+1EA0-1EF9, U+20AB; +} + +/* latin-ext */ +@font-face { + font-family: 'Montserrat'; + font-style: normal; + font-weight: 700; + src: local('Montserrat Bold'), local('Montserrat-Bold'), url(https://fonts.gstatic.com/s/montserrat/v12/JTURjIg1_i6t8kCHKm45_dJE3gfD_u50.woff2) format('woff2'); + unicode-range: U+0100-024F, U+0259, U+1E00-1EFF, U+2020, U+20A0-20AB, U+20AD-20CF, U+2113, U+2C60-2C7F, U+A720-A7FF; +} + +/* latin */ +@font-face { + font-family: 'Montserrat'; + font-style: normal; + font-weight: 700; + src: local('Montserrat Bold'), local('Montserrat-Bold'), url(https://fonts.gstatic.com/s/montserrat/v12/JTURjIg1_i6t8kCHKm45_dJE3gnD_g.woff2) format('woff2'); + unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; +} diff --git a/src/main/resources/META-INF/resources/css/google/roboto.css b/src/main/resources/META-INF/resources/css/google/roboto.css new file mode 100644 index 0000000..6f7e4e3 --- /dev/null +++ b/src/main/resources/META-INF/resources/css/google/roboto.css @@ -0,0 +1,251 @@ +/* cyrillic-ext */ +@font-face { + font-family: 'Roboto Slab'; + font-style: normal; + font-weight: 100; + src: local('Roboto Slab Thin'), local('RobotoSlab-Thin'), url(https://fonts.gstatic.com/s/robotoslab/v7/BngOUXZYTXPIvIBgJJSb6u-u1qqh5CCD.woff2) format('woff2'); + unicode-range: U+0460-052F, U+1C80-1C88, U+20B4, U+2DE0-2DFF, U+A640-A69F, U+FE2E-FE2F; +} + +/* cyrillic */ +@font-face { + font-family: 'Roboto Slab'; + font-style: normal; + font-weight: 100; + src: local('Roboto Slab Thin'), local('RobotoSlab-Thin'), url(https://fonts.gstatic.com/s/robotoslab/v7/BngOUXZYTXPIvIBgJJSb6u-u1qOh5CCD.woff2) format('woff2'); + unicode-range: U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; +} + +/* greek-ext */ +@font-face { + font-family: 'Roboto Slab'; + font-style: normal; + font-weight: 100; + src: local('Roboto Slab Thin'), local('RobotoSlab-Thin'), url(https://fonts.gstatic.com/s/robotoslab/v7/BngOUXZYTXPIvIBgJJSb6u-u1quh5CCD.woff2) format('woff2'); + unicode-range: U+1F00-1FFF; +} + +/* greek */ +@font-face { + font-family: 'Roboto Slab'; + font-style: normal; + font-weight: 100; + src: local('Roboto Slab Thin'), local('RobotoSlab-Thin'), url(https://fonts.gstatic.com/s/robotoslab/v7/BngOUXZYTXPIvIBgJJSb6u-u1qSh5CCD.woff2) format('woff2'); + unicode-range: U+0370-03FF; +} + +/* vietnamese */ +@font-face { + font-family: 'Roboto Slab'; + font-style: normal; + font-weight: 100; + src: local('Roboto Slab Thin'), local('RobotoSlab-Thin'), url(https://fonts.gstatic.com/s/robotoslab/v7/BngOUXZYTXPIvIBgJJSb6u-u1qih5CCD.woff2) format('woff2'); + unicode-range: U+0102-0103, U+0110-0111, U+1EA0-1EF9, U+20AB; +} + +/* latin-ext */ +@font-face { + font-family: 'Roboto Slab'; + font-style: normal; + font-weight: 100; + src: local('Roboto Slab Thin'), local('RobotoSlab-Thin'), url(https://fonts.gstatic.com/s/robotoslab/v7/BngOUXZYTXPIvIBgJJSb6u-u1qmh5CCD.woff2) format('woff2'); + unicode-range: U+0100-024F, U+0259, U+1E00-1EFF, U+2020, U+20A0-20AB, U+20AD-20CF, U+2113, U+2C60-2C7F, U+A720-A7FF; +} + +/* latin */ +@font-face { + font-family: 'Roboto Slab'; + font-style: normal; + font-weight: 100; + src: local('Roboto Slab Thin'), local('RobotoSlab-Thin'), url(https://fonts.gstatic.com/s/robotoslab/v7/BngOUXZYTXPIvIBgJJSb6u-u1qeh5A.woff2) format('woff2'); + unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; +} + +/* cyrillic-ext */ +@font-face { + font-family: 'Roboto Slab'; + font-style: normal; + font-weight: 300; + src: local('Roboto Slab Light'), local('RobotoSlab-Light'), url(https://fonts.gstatic.com/s/robotoslab/v7/BngRUXZYTXPIvIBgJJSb6u9mxLCLwR26eg.woff2) format('woff2'); + unicode-range: U+0460-052F, U+1C80-1C88, U+20B4, U+2DE0-2DFF, U+A640-A69F, U+FE2E-FE2F; +} + +/* cyrillic */ +@font-face { + font-family: 'Roboto Slab'; + font-style: normal; + font-weight: 300; + src: local('Roboto Slab Light'), local('RobotoSlab-Light'), url(https://fonts.gstatic.com/s/robotoslab/v7/BngRUXZYTXPIvIBgJJSb6u9mxLCCwR26eg.woff2) format('woff2'); + unicode-range: U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; +} + +/* greek-ext */ +@font-face { + font-family: 'Roboto Slab'; + font-style: normal; + font-weight: 300; + src: local('Roboto Slab Light'), local('RobotoSlab-Light'), url(https://fonts.gstatic.com/s/robotoslab/v7/BngRUXZYTXPIvIBgJJSb6u9mxLCKwR26eg.woff2) format('woff2'); + unicode-range: U+1F00-1FFF; +} + +/* greek */ +@font-face { + font-family: 'Roboto Slab'; + font-style: normal; + font-weight: 300; + src: local('Roboto Slab Light'), local('RobotoSlab-Light'), url(https://fonts.gstatic.com/s/robotoslab/v7/BngRUXZYTXPIvIBgJJSb6u9mxLCFwR26eg.woff2) format('woff2'); + unicode-range: U+0370-03FF; +} + +/* vietnamese */ +@font-face { + font-family: 'Roboto Slab'; + font-style: normal; + font-weight: 300; + src: local('Roboto Slab Light'), local('RobotoSlab-Light'), url(https://fonts.gstatic.com/s/robotoslab/v7/BngRUXZYTXPIvIBgJJSb6u9mxLCJwR26eg.woff2) format('woff2'); + unicode-range: U+0102-0103, U+0110-0111, U+1EA0-1EF9, U+20AB; +} + +/* latin-ext */ +@font-face { + font-family: 'Roboto Slab'; + font-style: normal; + font-weight: 300; + src: local('Roboto Slab Light'), local('RobotoSlab-Light'), url(https://fonts.gstatic.com/s/robotoslab/v7/BngRUXZYTXPIvIBgJJSb6u9mxLCIwR26eg.woff2) format('woff2'); + unicode-range: U+0100-024F, U+0259, U+1E00-1EFF, U+2020, U+20A0-20AB, U+20AD-20CF, U+2113, U+2C60-2C7F, U+A720-A7FF; +} + +/* latin */ +@font-face { + font-family: 'Roboto Slab'; + font-style: normal; + font-weight: 300; + src: local('Roboto Slab Light'), local('RobotoSlab-Light'), url(https://fonts.gstatic.com/s/robotoslab/v7/BngRUXZYTXPIvIBgJJSb6u9mxLCGwR0.woff2) format('woff2'); + unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; +} + +/* cyrillic-ext */ +@font-face { + font-family: 'Roboto Slab'; + font-style: normal; + font-weight: 400; + src: local('Roboto Slab Regular'), local('RobotoSlab-Regular'), url(https://fonts.gstatic.com/s/robotoslab/v7/BngMUXZYTXPIvIBgJJSb6ufA5qW54A.woff2) format('woff2'); + unicode-range: U+0460-052F, U+1C80-1C88, U+20B4, U+2DE0-2DFF, U+A640-A69F, U+FE2E-FE2F; +} + +/* cyrillic */ +@font-face { + font-family: 'Roboto Slab'; + font-style: normal; + font-weight: 400; + src: local('Roboto Slab Regular'), local('RobotoSlab-Regular'), url(https://fonts.gstatic.com/s/robotoslab/v7/BngMUXZYTXPIvIBgJJSb6ufJ5qW54A.woff2) format('woff2'); + unicode-range: U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; +} + +/* greek-ext */ +@font-face { + font-family: 'Roboto Slab'; + font-style: normal; + font-weight: 400; + src: local('Roboto Slab Regular'), local('RobotoSlab-Regular'), url(https://fonts.gstatic.com/s/robotoslab/v7/BngMUXZYTXPIvIBgJJSb6ufB5qW54A.woff2) format('woff2'); + unicode-range: U+1F00-1FFF; +} + +/* greek */ +@font-face { + font-family: 'Roboto Slab'; + font-style: normal; + font-weight: 400; + src: local('Roboto Slab Regular'), local('RobotoSlab-Regular'), url(https://fonts.gstatic.com/s/robotoslab/v7/BngMUXZYTXPIvIBgJJSb6ufO5qW54A.woff2) format('woff2'); + unicode-range: U+0370-03FF; +} + +/* vietnamese */ +@font-face { + font-family: 'Roboto Slab'; + font-style: normal; + font-weight: 400; + src: local('Roboto Slab Regular'), local('RobotoSlab-Regular'), url(https://fonts.gstatic.com/s/robotoslab/v7/BngMUXZYTXPIvIBgJJSb6ufC5qW54A.woff2) format('woff2'); + unicode-range: U+0102-0103, U+0110-0111, U+1EA0-1EF9, U+20AB; +} + +/* latin-ext */ +@font-face { + font-family: 'Roboto Slab'; + font-style: normal; + font-weight: 400; + src: local('Roboto Slab Regular'), local('RobotoSlab-Regular'), url(https://fonts.gstatic.com/s/robotoslab/v7/BngMUXZYTXPIvIBgJJSb6ufD5qW54A.woff2) format('woff2'); + unicode-range: U+0100-024F, U+0259, U+1E00-1EFF, U+2020, U+20A0-20AB, U+20AD-20CF, U+2113, U+2C60-2C7F, U+A720-A7FF; +} + +/* latin */ +@font-face { + font-family: 'Roboto Slab'; + font-style: normal; + font-weight: 400; + src: local('Roboto Slab Regular'), local('RobotoSlab-Regular'), url(https://fonts.gstatic.com/s/robotoslab/v7/BngMUXZYTXPIvIBgJJSb6ufN5qU.woff2) format('woff2'); + unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; +} + +/* cyrillic-ext */ +@font-face { + font-family: 'Roboto Slab'; + font-style: normal; + font-weight: 700; + src: local('Roboto Slab Bold'), local('RobotoSlab-Bold'), url(https://fonts.gstatic.com/s/robotoslab/v7/BngRUXZYTXPIvIBgJJSb6u92w7CLwR26eg.woff2) format('woff2'); + unicode-range: U+0460-052F, U+1C80-1C88, U+20B4, U+2DE0-2DFF, U+A640-A69F, U+FE2E-FE2F; +} + +/* cyrillic */ +@font-face { + font-family: 'Roboto Slab'; + font-style: normal; + font-weight: 700; + src: local('Roboto Slab Bold'), local('RobotoSlab-Bold'), url(https://fonts.gstatic.com/s/robotoslab/v7/BngRUXZYTXPIvIBgJJSb6u92w7CCwR26eg.woff2) format('woff2'); + unicode-range: U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; +} + +/* greek-ext */ +@font-face { + font-family: 'Roboto Slab'; + font-style: normal; + font-weight: 700; + src: local('Roboto Slab Bold'), local('RobotoSlab-Bold'), url(https://fonts.gstatic.com/s/robotoslab/v7/BngRUXZYTXPIvIBgJJSb6u92w7CKwR26eg.woff2) format('woff2'); + unicode-range: U+1F00-1FFF; +} + +/* greek */ +@font-face { + font-family: 'Roboto Slab'; + font-style: normal; + font-weight: 700; + src: local('Roboto Slab Bold'), local('RobotoSlab-Bold'), url(https://fonts.gstatic.com/s/robotoslab/v7/BngRUXZYTXPIvIBgJJSb6u92w7CFwR26eg.woff2) format('woff2'); + unicode-range: U+0370-03FF; +} + +/* vietnamese */ +@font-face { + font-family: 'Roboto Slab'; + font-style: normal; + font-weight: 700; + src: local('Roboto Slab Bold'), local('RobotoSlab-Bold'), url(https://fonts.gstatic.com/s/robotoslab/v7/BngRUXZYTXPIvIBgJJSb6u92w7CJwR26eg.woff2) format('woff2'); + unicode-range: U+0102-0103, U+0110-0111, U+1EA0-1EF9, U+20AB; +} + +/* latin-ext */ +@font-face { + font-family: 'Roboto Slab'; + font-style: normal; + font-weight: 700; + src: local('Roboto Slab Bold'), local('RobotoSlab-Bold'), url(https://fonts.gstatic.com/s/robotoslab/v7/BngRUXZYTXPIvIBgJJSb6u92w7CIwR26eg.woff2) format('woff2'); + unicode-range: U+0100-024F, U+0259, U+1E00-1EFF, U+2020, U+20A0-20AB, U+20AD-20CF, U+2113, U+2C60-2C7F, U+A720-A7FF; +} + +/* latin */ +@font-face { + font-family: 'Roboto Slab'; + font-style: normal; + font-weight: 700; + src: local('Roboto Slab Bold'), local('RobotoSlab-Bold'), url(https://fonts.gstatic.com/s/robotoslab/v7/BngRUXZYTXPIvIBgJJSb6u92w7CGwR0.woff2) format('woff2'); + unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; +} diff --git a/src/main/resources/META-INF/resources/css/style.css b/src/main/resources/META-INF/resources/css/style.css new file mode 100644 index 0000000..d5e56f5 --- /dev/null +++ b/src/main/resources/META-INF/resources/css/style.css @@ -0,0 +1,49 @@ +.black { + background-color: #383838 !important; +} + +.ui-picklist-list-wrapper { + width: 50% !important; +} + +.ui-picklist-list { + width: 100% !important; +} + + +.text-draft { + color: rgba(0, 0, 0, 0.48) !important; +} + +.text-primary { + color: #228bba !important; +} + +.text-warning { + color: #940000 !important; +} + +.text-review { + color: #94028d !important; +} + +.text-success { + color: #007741 !important; +} + +.text-accepted { + color: #fec503 !important; +} + +.text-not-accepted { + color: #A38831 !important; +} + +.text-failed { + color: #A38831 !important; +} + +.navbar-brand { + color: #fed136 !important; + font-family: 'Kaushan Script', 'Helvetica Neue', Helvetica, Arial, cursive; +} diff --git a/src/main/resources/META-INF/resources/error/403.xhtml b/src/main/resources/META-INF/resources/error/403.xhtml new file mode 100644 index 0000000..8d25bc6 --- /dev/null +++ b/src/main/resources/META-INF/resources/error/403.xhtml @@ -0,0 +1,27 @@ + + + + + + Доступ запрещен + + + + + +
+
+
+
+

Доступ запрещен

+ + Вернуться на главную + +
+
+
+
+
+ diff --git a/src/main/resources/META-INF/resources/error/404.xhtml b/src/main/resources/META-INF/resources/error/404.xhtml new file mode 100644 index 0000000..c19d4f4 --- /dev/null +++ b/src/main/resources/META-INF/resources/error/404.xhtml @@ -0,0 +1,23 @@ + + + + + + Страница не найдена + + + +
+
+
+ + + Вернуться на главную + + +
+
+
+ diff --git a/src/main/resources/META-INF/resources/error/500.xhtml b/src/main/resources/META-INF/resources/error/500.xhtml new file mode 100644 index 0000000..72ceb67 --- /dev/null +++ b/src/main/resources/META-INF/resources/error/500.xhtml @@ -0,0 +1,42 @@ + + + + + + Ошибка сервера + + +
+
+
+ + + Вернуться на главную + + + + + + + + + + +
+                                #{requestScope['javax.servlet.error.exception']}
+                            
+
+
+
+ +
+
+
+
+ diff --git a/src/main/resources/META-INF/resources/grant/dashboard.xhtml b/src/main/resources/META-INF/resources/grant/dashboard.xhtml new file mode 100644 index 0000000..dc6d6ed --- /dev/null +++ b/src/main/resources/META-INF/resources/grant/dashboard.xhtml @@ -0,0 +1,91 @@ + + + + + + + + +
+
+
+ + +
+
+ + +
+
+ + + +
+ + + + +
+ + + + + + + + + + + + + + + + #{grant.title} + + + + + + + + + + + + + + + +
+
+
+
+ diff --git a/src/main/resources/META-INF/resources/grant/grant.xhtml b/src/main/resources/META-INF/resources/grant/grant.xhtml new file mode 100644 index 0000000..6941241 --- /dev/null +++ b/src/main/resources/META-INF/resources/grant/grant.xhtml @@ -0,0 +1,142 @@ + + + + + + Редактирование гранта + + + + +
+
+
+ +
+
+ + +
+
+ +
+
+ +
+
+ + + + + + + + + + +
+ +
+ +
+
+ + + + +
+
+ +
+
+
+
+ +
+ +
+
+ +
+
+ + + +
+
+
+ +
+
+ +
+
+ + + +
+
+
+
+ +
+ +
+
+ +
+
+

+ Грант создан +

+

+ Грант обновлен +

+
+
+ +
+
+
+
+
+
+ diff --git a/src/main/resources/META-INF/resources/grant/grantStatusFragment.xhtml b/src/main/resources/META-INF/resources/grant/grantStatusFragment.xhtml new file mode 100644 index 0000000..48313fb --- /dev/null +++ b/src/main/resources/META-INF/resources/grant/grantStatusFragment.xhtml @@ -0,0 +1,10 @@ + + + + + + + + + diff --git a/src/main/resources/META-INF/resources/grant/grants.xhtml b/src/main/resources/META-INF/resources/grant/grants.xhtml new file mode 100644 index 0000000..f919a8a --- /dev/null +++ b/src/main/resources/META-INF/resources/grant/grants.xhtml @@ -0,0 +1,88 @@ + + + + + + + + +
+
+
+ + +
+
+ + +
+
+ + + +
+ + + + +
+ + + + + + + + + + + + + + + + #{grant.title} + + + + + + + + + + + + + + + +
+
+
+
+ diff --git a/src/main/resources/META-INF/resources/img/conference/back.png b/src/main/resources/META-INF/resources/img/conference/back.png new file mode 100644 index 0000000..7667350 Binary files /dev/null and b/src/main/resources/META-INF/resources/img/conference/back.png differ diff --git a/src/main/resources/META-INF/resources/img/conference/delete.png b/src/main/resources/META-INF/resources/img/conference/delete.png new file mode 100644 index 0000000..595bf63 Binary files /dev/null and b/src/main/resources/META-INF/resources/img/conference/delete.png differ diff --git a/src/main/resources/META-INF/resources/img/conference/edit.png b/src/main/resources/META-INF/resources/img/conference/edit.png new file mode 100644 index 0000000..832bef3 Binary files /dev/null and b/src/main/resources/META-INF/resources/img/conference/edit.png differ diff --git a/src/main/resources/META-INF/resources/img/conference/paper.png b/src/main/resources/META-INF/resources/img/conference/paper.png new file mode 100644 index 0000000..78a0dfc Binary files /dev/null and b/src/main/resources/META-INF/resources/img/conference/paper.png differ diff --git a/src/main/resources/META-INF/resources/img/header-bg.jpg b/src/main/resources/META-INF/resources/img/header-bg.jpg new file mode 100644 index 0000000..6ac14cf Binary files /dev/null and b/src/main/resources/META-INF/resources/img/header-bg.jpg differ diff --git a/src/main/resources/META-INF/resources/img/logo.png b/src/main/resources/META-INF/resources/img/logo.png new file mode 100644 index 0000000..7d3d33c Binary files /dev/null and b/src/main/resources/META-INF/resources/img/logo.png differ diff --git a/src/main/resources/META-INF/resources/img/main/ajax-loader.gif b/src/main/resources/META-INF/resources/img/main/ajax-loader.gif new file mode 100644 index 0000000..f2a1bc0 Binary files /dev/null and b/src/main/resources/META-INF/resources/img/main/ajax-loader.gif differ diff --git a/src/main/resources/META-INF/resources/img/main/career.jpg b/src/main/resources/META-INF/resources/img/main/career.jpg new file mode 100644 index 0000000..71615c2 Binary files /dev/null and b/src/main/resources/META-INF/resources/img/main/career.jpg differ diff --git a/src/main/resources/META-INF/resources/img/main/conf.jpg b/src/main/resources/META-INF/resources/img/main/conf.jpg new file mode 100644 index 0000000..bf10948 Binary files /dev/null and b/src/main/resources/META-INF/resources/img/main/conf.jpg differ diff --git a/src/main/resources/META-INF/resources/img/main/grants.jpg b/src/main/resources/META-INF/resources/img/main/grants.jpg new file mode 100644 index 0000000..d7de0e0 Binary files /dev/null and b/src/main/resources/META-INF/resources/img/main/grants.jpg differ diff --git a/src/main/resources/META-INF/resources/img/main/papers.jpg b/src/main/resources/META-INF/resources/img/main/papers.jpg new file mode 100644 index 0000000..055f864 Binary files /dev/null and b/src/main/resources/META-INF/resources/img/main/papers.jpg differ diff --git a/src/main/resources/META-INF/resources/img/main/projects.jpg b/src/main/resources/META-INF/resources/img/main/projects.jpg new file mode 100644 index 0000000..d3085b7 Binary files /dev/null and b/src/main/resources/META-INF/resources/img/main/projects.jpg differ diff --git a/src/main/resources/META-INF/resources/img/main/students.jpg b/src/main/resources/META-INF/resources/img/main/students.jpg new file mode 100644 index 0000000..25ea94a Binary files /dev/null and b/src/main/resources/META-INF/resources/img/main/students.jpg differ diff --git a/src/main/resources/META-INF/resources/img/main/tasks.jpg b/src/main/resources/META-INF/resources/img/main/tasks.jpg new file mode 100644 index 0000000..ca20f61 Binary files /dev/null and b/src/main/resources/META-INF/resources/img/main/tasks.jpg differ diff --git a/src/main/resources/META-INF/resources/img/main/team.jpg b/src/main/resources/META-INF/resources/img/main/team.jpg new file mode 100644 index 0000000..f30744d Binary files /dev/null and b/src/main/resources/META-INF/resources/img/main/team.jpg differ diff --git a/src/main/resources/META-INF/resources/img/main/templates.jpg b/src/main/resources/META-INF/resources/img/main/templates.jpg new file mode 100644 index 0000000..9cafc26 Binary files /dev/null and b/src/main/resources/META-INF/resources/img/main/templates.jpg differ diff --git a/src/main/resources/META-INF/resources/img/map-image.png b/src/main/resources/META-INF/resources/img/map-image.png new file mode 100644 index 0000000..a047a27 Binary files /dev/null and b/src/main/resources/META-INF/resources/img/map-image.png differ diff --git a/src/main/resources/META-INF/resources/index.xhtml b/src/main/resources/META-INF/resources/index.xhtml new file mode 100644 index 0000000..307066f --- /dev/null +++ b/src/main/resources/META-INF/resources/index.xhtml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/META-INF/resources/login.xhtml b/src/main/resources/META-INF/resources/login.xhtml new file mode 100644 index 0000000..9ac6cff --- /dev/null +++ b/src/main/resources/META-INF/resources/login.xhtml @@ -0,0 +1,61 @@ + + + + + + + + Вход в систему + + +
+
+
+
+ + + + + + + + + + + + + + + + + + + +
+
+
+
+ +
+ +
+ Войти с учетной записью Google +
+
+
+
+
+
+
+ diff --git a/src/main/resources/META-INF/resources/paper/dashboard.xhtml b/src/main/resources/META-INF/resources/paper/dashboard.xhtml new file mode 100644 index 0000000..b7e97bd --- /dev/null +++ b/src/main/resources/META-INF/resources/paper/dashboard.xhtml @@ -0,0 +1,91 @@ + + + + + + + + +
+
+
+ + +
+
+ + +
+
+ + + +
+ + + + +
+ + + + + + + + + + + + + + + + #{paper.title} + + + + + + + + + + + + + + + +
+
+
+
+ diff --git a/src/main/resources/META-INF/resources/paper/paper.xhtml b/src/main/resources/META-INF/resources/paper/paper.xhtml new file mode 100644 index 0000000..20f4978 --- /dev/null +++ b/src/main/resources/META-INF/resources/paper/paper.xhtml @@ -0,0 +1,165 @@ + + + + + + Редактирование статьи + + + + +
+
+
+ +
+
+ + +
+
+ + + +
+
+ +
+
+ + + + + + + + + + +
+
+ +
+
+ + + +
+
+ +
+
+ + + + +
+
+ +
+
+
+
+ +
+ +
+
+ +
+
+ + + +
+
+
+ +
+
+ +
+
+ + + +
+
+
+
+ +
+ +
+
+ +
+
+

+ Статья создана + + + +

+

+ Статья обновлена + + + +

+
+
+ +
+
+
+
+
+
+ diff --git a/src/main/resources/META-INF/resources/paper/paperStatusFragment.xhtml b/src/main/resources/META-INF/resources/paper/paperStatusFragment.xhtml new file mode 100644 index 0000000..b99161f --- /dev/null +++ b/src/main/resources/META-INF/resources/paper/paperStatusFragment.xhtml @@ -0,0 +1,10 @@ + + + + + + + + + diff --git a/src/main/resources/META-INF/resources/paper/papers.xhtml b/src/main/resources/META-INF/resources/paper/papers.xhtml new file mode 100644 index 0000000..96beeed --- /dev/null +++ b/src/main/resources/META-INF/resources/paper/papers.xhtml @@ -0,0 +1,88 @@ + + + + + + + + +
+
+
+ + +
+
+ + +
+
+ + + +
+ + + + +
+ + + + + + + + + + + + + + + + #{paper.title} + + + + + + + + + + + + + + + +
+
+
+
+ diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 1949a5b..60afbc3 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,7 +1,8 @@ # Server Settings spring.main.banner-mode=off -server.port=8443 -server.http.port=8080 +server.port=8080 +server.http.port=8443 +server.ssl.enabled=false multipart.maxFileSize=20MB multipart.maxRequestSize=20MB # Thymeleaf Settings @@ -14,6 +15,11 @@ server.ssl.key-password=password logging.level.ru.ulstu=DEBUG #HtmlUnit logging.level.com.gargoylesoftware.htmlunit=ERROR +#jsf +#joinfaces.primefaces.theme=casablanca +joinfaces.primefaces.theme=afterdark +joinfaces.primefaces.font-awesome=true +joinfaces.mojarra.enable-restore-view11-compatibility=true # Mail Settings spring.mail.host=smtp.yandex.ru spring.mail.port=465 @@ -35,8 +41,10 @@ spring.liquibase.enabled=true # Application Settings ng-tracker.base-url=http://127.0.0.1:8080 ng-tracker.undead-user-login=admin -ng-tracker.dev-mode=true -ng-tracker.debug_email= +ng-tracker.dev-mode=false +ng-tracker.debug_email=romanov73@gmail.com ng-tracker.use-https=false ng-tracker.check-run=false ng-tracker.driver-path= +spring.security.oauth2.client.registration.google.client-id=128435862215-4ltm7dr6enb6sfll0qhkt6a1op9juve6.apps.googleusercontent.com +spring.security.oauth2.client.registration.google.client-secret=W_B-KMpqsSdKahqFxpuK4OoT diff --git a/src/main/resources/templates/error/403.html b/src/main/resources/templates/error/403.html deleted file mode 100644 index a80b444..0000000 --- a/src/main/resources/templates/error/403.html +++ /dev/null @@ -1,21 +0,0 @@ - - - - - -
-
-
-
-
-

Доступ запрещен

-

Вернуться на главную

-
-
-
-
-
- - \ No newline at end of file diff --git a/src/main/resources/templates/error/404.html b/src/main/resources/templates/error/404.html deleted file mode 100644 index 8f1d80b..0000000 --- a/src/main/resources/templates/error/404.html +++ /dev/null @@ -1,21 +0,0 @@ - - - - - -
-
-
-
-
-

Страница не найдена

-

Вернуться на главную

-
-
-
-
-
- - \ No newline at end of file diff --git a/src/main/resources/templates/error/500.html b/src/main/resources/templates/error/500.html deleted file mode 100644 index f89b83a..0000000 --- a/src/main/resources/templates/error/500.html +++ /dev/null @@ -1,21 +0,0 @@ - - - - - -
-
-
-
-
-

Ошибка сервера

-

Вернуться на главную

-
-
-
-
-
- - \ No newline at end of file diff --git a/src/main/resources/templates/login.html b/src/main/resources/templates/login.html index 48e325e..1478197 100644 --- a/src/main/resources/templates/login.html +++ b/src/main/resources/templates/login.html @@ -34,10 +34,14 @@ +

Login with:

+

+ Client +

- \ No newline at end of file + diff --git a/src/test/java/ConferenceTest.java b/src/test/java/ConferenceTest.java deleted file mode 100644 index 3fae34b..0000000 --- a/src/test/java/ConferenceTest.java +++ /dev/null @@ -1,230 +0,0 @@ -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Iterables; -import conference.ConferencePage; -import conference.ConferencesDashboardPage; -import conference.ConferencesPage; -import core.PageObject; -import core.TestTemplate; -import org.junit.Assert; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.MethodSorters; -import org.openqa.selenium.By; -import org.openqa.selenium.WebElement; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; -import ru.ulstu.NgTrackerApplication; -import ru.ulstu.configuration.ApplicationProperties; - -import java.util.Arrays; -import java.util.Date; -import java.util.List; -import java.util.Map; - -@RunWith(SpringRunner.class) -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -@SpringBootTest(classes = NgTrackerApplication.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) -public class ConferenceTest extends TestTemplate { - private final Map> navigationHolder = ImmutableMap.of( - new ConferencesPage(), Arrays.asList("КОНФЕРЕНЦИИ", "/conferences/conferences"), - new ConferencePage(), Arrays.asList("РЕДАКТИРОВАНИЕ КОНФЕРЕНЦИИ", "/conferences/conference?id=0"), - new ConferencesDashboardPage(), Arrays.asList("АКТУАЛЬНЫЕ КОНФЕРЕНЦИИ", "/conferences/dashboard") - ); - - @Autowired - private ApplicationProperties applicationProperties; - - @Test - public void testACreateNewConference() { - Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 1); - - getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); - ConferencePage conferencePage = (ConferencePage) getContext().initPage(page.getKey()); - ConferencesPage conferencesPage = (ConferencesPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 0).getKey()); - - String newConferenceName = "test " + (new Date()).getTime(); - conferencePage.setName(newConferenceName); - conferencePage.clickSaveBut(); - - Assert.assertTrue(conferencesPage.checkNameInList(newConferenceName)); - } - - @Test - public void testBChangeConferenceNameAndSave() { - Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); - - getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); - ConferencesPage conferencesPage = (ConferencesPage) getContext().initPage(page.getKey()); - ConferencePage conferencePage = (ConferencePage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); - - conferencesPage.getFirstConference(); - String newConferenceName = "test " + (new Date()).getTime(); - conferencePage.clearName(); - conferencePage.setName(newConferenceName); - conferencePage.clickSaveBut(); - - Assert.assertTrue(conferencesPage.checkNameInList(newConferenceName)); - } - - @Test - public void testCAddDeadlineAndSave() { - Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); - - getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); - ConferencesPage conferencesPage = (ConferencesPage) getContext().initPage(page.getKey()); - ConferencePage conferencePage = (ConferencePage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); - - conferencesPage.getFirstConference(); - String conferenceId = conferencePage.getId(); - Integer deadlineCount = conferencePage.getDeadlineCount(); - - String description = "test"; - String date = "09.09.2019"; - String dateValue = "2019-09-09"; - conferencePage.clickAddDeadlineBut(); - conferencePage.setDeadlineDescription(description, deadlineCount); - conferencePage.setDeadlineDate(date, deadlineCount); - conferencePage.clickSaveBut(); - - getContext().goTo(applicationProperties.getBaseUrl() + String.format("/conferences/conference?id=%s", conferenceId)); - - Assert.assertTrue(conferencePage.checkDeadline(description, dateValue)); - } - - @Test - public void testDTakePartAndSave() { - Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); - - getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); - ConferencesPage conferencesPage = (ConferencesPage) getContext().initPage(page.getKey()); - ConferencePage conferencePage = (ConferencePage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); - - conferencesPage.getFirstConference(); - String conferenceId = conferencePage.getId(); - Integer membersCount = conferencePage.getMemberCount(); - - conferencePage.clickTakePartBut(); - conferencePage.clickSaveBut(); - - getContext().goTo(applicationProperties.getBaseUrl() + String.format("/conferences/conference?id=%s", conferenceId)); - - Assert.assertTrue(membersCount + 1 == conferencePage.getMemberCount() - && conferencePage.isTakePartButDisabledValueTrue()); - } - - @Test - public void testEDeleteDeadlineAndSave() { - Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); - - getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); - ConferencesPage conferencesPage = (ConferencesPage) getContext().initPage(page.getKey()); - ConferencePage conferencePage = (ConferencePage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); - - conferencesPage.getFirstConference(); - String conferenceId = conferencePage.getId(); - Integer deadlineCount = conferencePage.getDeadlineCount(); - - conferencePage.clickDeleteDeadlineBut(); - conferencePage.clickSaveBut(); - - getContext().goTo(applicationProperties.getBaseUrl() + String.format("/conferences/conference?id=%s", conferenceId)); - - Assert.assertEquals(deadlineCount - 1, (int) conferencePage.getDeadlineCount()); - } - - @Test - public void testFAttachArticle() { - Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); - - getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); - ConferencesPage conferencesPage = (ConferencesPage) getContext().initPage(page.getKey()); - ConferencePage conferencePage = (ConferencePage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); - - conferencesPage.getFirstConference(); - String conferenceId = conferencePage.getId(); - Integer paperCount = conferencePage.getArticlesCount(); - - conferencePage.showAllowToAttachArticles(); - WebElement paper = conferencePage.selectArticle(); - String paperName = paper.findElement(By.className("text")).getText(); - conferencePage.clickSaveBut(); - - getContext().goTo(applicationProperties.getBaseUrl() + String.format("/conferences/conference?id=%s", conferenceId)); - - Assert.assertTrue(paperCount + 1 == conferencePage.getArticlesCount() - && conferencePage.checkArticle(paperName)); - } - - @Test - public void testGAddArticle() { - Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); - - getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); - ConferencesPage conferencesPage = (ConferencesPage) getContext().initPage(page.getKey()); - ConferencePage conferencePage = (ConferencePage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); - - conferencesPage.getFirstConference(); - String conferenceId = conferencePage.getId(); - Integer paperCount = conferencePage.getArticlesCount(); - - conferencePage.clickAddPaperBut(); - List webElements = conferencePage.getArticles(); - String paperName = webElements.get(webElements.size() - 1).findElements(By.tagName("input")).get(1).getAttribute("value"); - conferencePage.clickSaveBut(); - - getContext().goTo(applicationProperties.getBaseUrl() + String.format("/conferences/conference?id=%s", conferenceId)); - - Assert.assertTrue(paperCount + 1 == conferencePage.getArticlesCount() - && conferencePage.checkArticle(paperName)); - } - - @Test - public void testHUndockArticle() { - Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); - - getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); - ConferencesPage conferencesPage = (ConferencesPage) getContext().initPage(page.getKey()); - ConferencePage conferencePage = (ConferencePage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); - - conferencesPage.getFirstConference(); - String conferenceId = conferencePage.getId(); - Integer paperCount = conferencePage.getArticlesCount(); - - conferencePage.clickUndockArticleBut(); - conferencePage.clickSaveBut(); - - getContext().goTo(applicationProperties.getBaseUrl() + String.format("/conferences/conference?id=%s", conferenceId)); - - Assert.assertEquals(paperCount - 1, (int) conferencePage.getArticlesCount()); - } - - @Test - public void testISortAndFilterConferenceList() { - Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); - - getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); - ConferencesPage conferencesPage = (ConferencesPage) getContext().initPage(page.getKey()); - - conferencesPage.selectMember(); - conferencesPage.selectYear(); - - Assert.assertEquals(1, conferencesPage.getConferencesList().size()); - } - - @Test - public void testJDeleteConf() throws InterruptedException { - Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); - - getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); - ConferencesPage conferencesPage = (ConferencesPage) getContext().initPage(page.getKey()); - - Integer size = conferencesPage.getConferencesList().size(); - conferencesPage.deleteFirst(); - Thread.sleep(3000); - conferencesPage.clickConfirm(); - - Assert.assertEquals(size - 1, conferencesPage.getConferencesList().size()); - } -} diff --git a/src/test/java/GrantTest.java b/src/test/java/GrantTest.java deleted file mode 100644 index b824852..0000000 --- a/src/test/java/GrantTest.java +++ /dev/null @@ -1,225 +0,0 @@ -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Iterables; -import core.PageObject; -import core.TestTemplate; -import grant.GrantPage; -import grant.GrantsDashboardPage; -import grant.GrantsPage; -import org.junit.Assert; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.MethodSorters; -import org.openqa.selenium.WebElement; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; -import ru.ulstu.NgTrackerApplication; -import ru.ulstu.configuration.ApplicationProperties; - -import java.util.Arrays; -import java.util.Date; -import java.util.List; -import java.util.Map; - -@RunWith(SpringRunner.class) -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -@SpringBootTest(classes = NgTrackerApplication.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) -public class GrantTest extends TestTemplate { - private final Map> navigationHolder = ImmutableMap.of( - new GrantsPage(), Arrays.asList("ГРАНТЫ", "/grants/grants"), - new GrantPage(), Arrays.asList("РЕДАКТИРОВАНИЕ ГРАНТА", "/grants/grant?id=0"), - new GrantsDashboardPage(), Arrays.asList("Гранты", "/grants/dashboard") - ); - - @Autowired - private ApplicationProperties applicationProperties; - - @Test - public void aCreateNewGrant() { - Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 1); - getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); - GrantPage grantPage = (GrantPage) getContext().initPage(page.getKey()); - GrantsPage grantsPage = (GrantsPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 0).getKey()); - - String newGrantName = "test grant" + (new Date()); - grantPage.setTitle(newGrantName); - String deadlineDate = new Date().toString(); - String deadlineDescription = "test deadline description"; - grantPage.setDeadline(deadlineDate, 0, deadlineDescription); - grantPage.setLeader(); - grantPage.saveGrant(); - - Assert.assertTrue(grantsPage.findGrantByTitle(newGrantName)); - } - - @Test - public void bCreateBlankGrant() { - Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 1); - getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); - GrantPage grantPage = (GrantPage) getContext().initPage(page.getKey()); - - grantPage.saveGrant(); - - Assert.assertTrue(grantPage.checkBlankFields()); - } - - @Test - public void cUpdateGrantTitle() { - Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); - getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); - GrantsPage grantsPage = (GrantsPage) getContext().initPage(page.getKey()); - GrantPage grantPage = (GrantPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); - - grantsPage.getFirstGrant(); - String newGrantTitle = "test " + (new Date()); - grantPage.setTitle(newGrantTitle); - grantPage.saveGrant(); - - Assert.assertTrue(grantsPage.findGrantByTitle(newGrantTitle)); - } - - @Test - public void dAttachPaper() { - Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); - getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); - GrantsPage grantsPage = (GrantsPage) getContext().initPage(page.getKey()); - GrantPage grantPage = (GrantPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); - - grantsPage.getFirstGrant(); - Integer countPapers = grantPage.getAttachedPapers().size(); - - Assert.assertEquals(countPapers + 1, grantPage.attachPaper().size()); - } - - @Test - public void eDeletePaper() { - Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); - getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); - GrantsPage grantsPage = (GrantsPage) getContext().initPage(page.getKey()); - GrantPage grantPage = (GrantPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); - - grantsPage.getFirstGrant(); - Integer oldCountPapers = grantPage.getAttachedPapers().size(); - if (oldCountPapers == 0) { - oldCountPapers = grantPage.attachPaper().size(); - } - - Assert.assertEquals(oldCountPapers - 1, grantPage.deletePaper().size()); - } - - @Test - public void fAddDeadline() { - Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); - getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); - GrantsPage grantsPage = (GrantsPage) getContext().initPage(page.getKey()); - GrantPage grantPage = (GrantPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); - - grantsPage.getFirstGrant(); - String grantId = grantPage.getId(); - Integer deadlineCount = grantPage.getDeadlineCount(); - - String description = "deadline test"; - String date = "08.08.2019"; - String dateValue = "2019-08-08"; - grantPage.addDeadline(); - grantPage.setDeadline(date, deadlineCount, description); - grantPage.saveGrant(); - - getContext().goTo(applicationProperties.getBaseUrl() + String.format("/grants/grant?id=%s", grantId)); - - Assert.assertTrue(grantPage.checkDeadline(description, dateValue)); - } - - @Test - public void gDeleteDeadline() { - Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); - getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); - GrantsPage grantsPage = (GrantsPage) getContext().initPage(page.getKey()); - GrantPage grantPage = (GrantPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); - - grantsPage.getFirstGrant(); - String grantId = grantPage.getId(); - Integer deadlineCount = grantPage.getDeadlineCount(); - - grantPage.deleteDeadline(); - grantPage.saveGrant(); - - getContext().goTo(applicationProperties.getBaseUrl() + String.format("/grants/grant?id=%s", grantId)); - Integer newDeadlineCount = grantPage.getDeadlineCount(); - Assert.assertEquals(deadlineCount - 1, (int) newDeadlineCount); - } - - @Test - public void hAddAuthor() { - Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); - getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); - GrantsPage grantsPage = (GrantsPage) getContext().initPage(page.getKey()); - GrantPage grantPage = (GrantPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); - - WebElement grant = grantsPage.getFirstGrantWithoutClick(); - String grantTitle = grantsPage.getGrantTitle(grant); - Integer authorsCount = grantsPage.getAuthorsCount(grant); - - grantsPage.getFirstGrant(); - grantPage.addAuthor(); - grantPage.saveGrant(); - - grant = grantsPage.getGrantByTitle(grantTitle); - Integer newAuthorsCount = grantsPage.getAuthorsCount(grant); - - Assert.assertEquals(authorsCount + 1, (int) newAuthorsCount); - } - - @Test - public void iDeleteAuthor() { - Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); - getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); - GrantsPage grantsPage = (GrantsPage) getContext().initPage(page.getKey()); - GrantPage grantPage = (GrantPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); - - WebElement grant = grantsPage.getFirstGrantWithoutClick(); - String grantTitle = grantsPage.getGrantTitle(grant); - Integer authorsCount = grantsPage.getAuthorsCount(grant); - - grantsPage.getFirstGrant(); - grantPage.deleteAuthor(); - grantPage.saveGrant(); - - grant = grantsPage.getGrantByTitle(grantTitle); - Integer newAuthorsCount = grantsPage.getAuthorsCount(grant); - - authorsCount = (authorsCount == 0) ? 0 : authorsCount - 1; - - Assert.assertEquals((int) authorsCount, (int) newAuthorsCount); - } - - @Test - public void jUpdateGrantDescription() { - Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); - getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); - GrantsPage grantsPage = (GrantsPage) getContext().initPage(page.getKey()); - GrantPage grantPage = (GrantPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); - - String description = "newDescriptionForGrant"; - grantsPage.getFirstGrant(); - String grantId = grantPage.getId(); - grantPage.setDescription(description); - grantPage.saveGrant(); - - getContext().goTo(applicationProperties.getBaseUrl() + String.format("/grants/grant?id=%s", grantId)); - - Assert.assertTrue(description.equals(grantPage.getDescription())); - } - - @Test - public void kDeleteGrant() throws InterruptedException { - Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); - getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); - GrantsPage grantsPage = (GrantsPage) getContext().initPage(page.getKey()); - - Integer size = grantsPage.getGrantsList().size(); - grantsPage.deleteFirst(); - Assert.assertEquals(size - 1, grantsPage.getGrantsList().size()); - } -} diff --git a/src/test/java/IndexPageTest.java b/src/test/java/IndexPageTest.java deleted file mode 100644 index 1817240..0000000 --- a/src/test/java/IndexPageTest.java +++ /dev/null @@ -1,52 +0,0 @@ -import com.google.common.collect.ImmutableMap; -import core.PageObject; -import core.TestTemplate; -import org.assertj.core.api.Assertions; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; -import paper.PaperPage; -import paper.PapersDashboardPage; -import paper.PapersPage; -import ru.ulstu.NgTrackerApplication; -import ru.ulstu.configuration.ApplicationProperties; - -import java.util.Arrays; -import java.util.List; -import java.util.Map; - -@RunWith(SpringRunner.class) -@SpringBootTest(classes = NgTrackerApplication.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) -public class IndexPageTest extends TestTemplate { - private final Map> navigationHolder = ImmutableMap.of( - new PapersPage(), Arrays.asList("СТАТЬИ", "/papers/papers"), - new PaperPage(), Arrays.asList("РЕДАКТИРОВАНИЕ СТАТЬИ", "/papers/paper?id=0"), - new PapersDashboardPage(), Arrays.asList("СТАТЬИ", "/papers/dashboard") - ); - - @Autowired - private ApplicationProperties applicationProperties; - - @Test - public void testStartApplication() { - getContext().goTo(applicationProperties.getBaseUrl()); - Assertions - .assertThat(getContext().getTitle()) - .isEqualTo("NG-Tracker"); - } - - @Test - public void testModulesNavigation() { - navigationHolder.entrySet() - .stream() - .forEach(navigationEntry -> { - getContext().goTo(applicationProperties.getBaseUrl() + navigationEntry.getValue().get(1)); - PageObject pageObject = getContext().initPage(navigationEntry.getKey()); - Assertions - .assertThat(pageObject.getSubTitle()) - .isEqualToIgnoringCase(navigationEntry.getValue().get(0)); - }); - } -} diff --git a/src/test/java/PaperTest.java b/src/test/java/PaperTest.java deleted file mode 100644 index 081f01f..0000000 --- a/src/test/java/PaperTest.java +++ /dev/null @@ -1,247 +0,0 @@ -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Iterables; -import core.PageObject; -import core.TestTemplate; -import org.junit.Assert; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.MethodSorters; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; -import paper.PaperPage; -import paper.PapersDashboardPage; -import paper.PapersPage; -import ru.ulstu.NgTrackerApplication; -import ru.ulstu.configuration.ApplicationProperties; - -import java.util.Arrays; -import java.util.List; -import java.util.Map; - -@RunWith(SpringRunner.class) -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -@SpringBootTest(classes = NgTrackerApplication.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) -public class PaperTest extends TestTemplate { - private final Map> navigationHolder = ImmutableMap.of( - new PapersPage(), Arrays.asList("СТАТЬИ", "/papers/papers"), - new PaperPage(), Arrays.asList("РЕДАКТИРОВАНИЕ СТАТЬИ", "/papers/paper?id=0"), - new PapersDashboardPage(), Arrays.asList("СТАТЬИ", "/papers/dashboard") - ); - - @Autowired - private ApplicationProperties applicationProperties; - - private String getPaperPageUrl() { - return Iterables.get(navigationHolder.entrySet(), 1).getValue().get(1); - } - - private PaperPage getPaperPage() { - PaperPage paperPage = (PaperPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); - paperPage.initElements(); - return paperPage; - } - - private String getPapersPageUrl() { - return Iterables.get(navigationHolder.entrySet(), 0).getValue().get(1); - } - - private PapersPage getPapersPage() { - PapersPage papersPage = (PapersPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 0).getKey()); - papersPage.initElements(); - return papersPage; - } - - private String getPapersDashboardPageUrl() { - return Iterables.get(navigationHolder.entrySet(), 2).getValue().get(1); - } - - private PapersDashboardPage getPapersDashboardPage() { - PapersDashboardPage papersDashboardPage = (PapersDashboardPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 2).getKey()); - papersDashboardPage.initElements(); - return papersDashboardPage; - } - - @Test - public void createNewPaperTest() { - getContext().goTo(applicationProperties.getBaseUrl() + getPaperPageUrl()); - PaperPage paperPage = getPaperPage(); - - String testTitle = "test " + System.currentTimeMillis(); - fillRequiredFields(paperPage, testTitle); - paperPage.clickSaveBtn(); - - PapersPage papersPage = getPapersPage(); - - Assert.assertTrue(papersPage.havePaperWithTitle(testTitle)); - } - - @Test - public void editPaperTest() { - createNewPaper(); - getContext().goTo(applicationProperties.getBaseUrl() + getPapersPageUrl()); - PapersPage papersPage = getPapersPage(); - papersPage.clickFirstPaper(); - - PaperPage paperPage = getPaperPage(); - String testTitle = "test " + System.currentTimeMillis(); - paperPage.setTitle(testTitle); - paperPage.clickSaveBtn(); - - Assert.assertTrue(papersPage.havePaperWithTitle(testTitle)); - } - - private void createNewPaper() { - getContext().goTo(applicationProperties.getBaseUrl() + getPaperPageUrl()); - PaperPage paperPage = getPaperPage(); - String testTitle = "test " + System.currentTimeMillis(); - fillRequiredFields(paperPage, testTitle); - paperPage.clickSaveBtn(); - } - - @Test - public void addDeadlineTest() { - createNewPaper(); - getContext().goTo(applicationProperties.getBaseUrl() + getPapersPageUrl()); - PapersPage papersPage = getPapersPage(); - papersPage.clickFirstPaper(); - - PaperPage paperPage = getPaperPage(); - papersPage.clickAddDeadline(); - String testDate = "01.01.2019"; - String testDateResult = "2019-01-01"; - String testDesc = "desc"; - Integer deadlineNumber = 2; - paperPage.setDeadlineDate(deadlineNumber, testDate); - paperPage.setDeadlineDescription(deadlineNumber, testDesc); - String paperId = paperPage.getId(); - paperPage.clickSaveBtn(); - - getContext().goTo(applicationProperties.getBaseUrl() + String.format("/papers/paper?id=%s", paperId)); - - Assert.assertTrue(paperPage.deadlineExist(testDesc, testDateResult)); - } - - @Test - public void noDeadlinesValidationTest() { - getContext().goTo(applicationProperties.getBaseUrl() + getPaperPageUrl()); - PaperPage paperPage = getPaperPage(); - - String testTitle = "test " + System.currentTimeMillis(); - paperPage.setTitle(testTitle); - paperPage.clickSaveBtn(); - - Assert.assertTrue(paperPage.hasAlert("Не может быть пустым")); - } - - private void fillRequiredFields(PaperPage paperPage, String title) { - paperPage.setTitle(title); - String testDate = "01.01.2019"; - String testDesc = "desc"; - Integer deadlineNumber = 1; - paperPage.setDeadlineDate(deadlineNumber, testDate); - paperPage.setDeadlineDescription(deadlineNumber, testDesc); - } - - @Test - public void addReferenceTest() { - createNewPaper(); - getContext().goTo(applicationProperties.getBaseUrl() + getPapersPageUrl()); - PapersPage papersPage = getPapersPage(); - papersPage.clickFirstPaper(); - - PaperPage paperPage = getPaperPage(); - fillRequiredFields(paperPage, "test " + System.currentTimeMillis()); - paperPage.clickReferenceTab(); - paperPage.clickAddReferenceButton(); - - paperPage.clickReferenceTab(); - paperPage.showFirstReference(); - String authors = "testAuthors"; - paperPage.setFirstReferenceAuthors(authors); - - String paperId = paperPage.getId(); - paperPage.clickSaveBtn(); - - getContext().goTo(applicationProperties.getBaseUrl() + String.format("/papers/paper?id=%s", paperId)); - - Assert.assertTrue(paperPage.authorsExists(authors)); - } - - @Test - public void referencesFormatTest() { - getContext().goTo(applicationProperties.getBaseUrl() + getPaperPageUrl()); - - PaperPage paperPage = getPaperPage(); - paperPage.setTitle("test"); - paperPage.clickReferenceTab(); - paperPage.clickAddReferenceButton(); - - paperPage.clickReferenceTab(); - paperPage.showFirstReference(); - paperPage.setFirstReferenceAuthors("authors"); - paperPage.setFirstReferencePublicationTitle("title"); - paperPage.setFirstReferencePublicationYear("2010"); - paperPage.setFirstReferencePublisher("publisher"); - paperPage.setFirstReferencePages("200"); - paperPage.setFirstReferenceJournalOrCollectionTitle("journal"); - paperPage.setFormatStandardSpringer(); - paperPage.clickFormatButton(); - - Assert.assertEquals("authors (2010) title. journal, publisher, pp 200", paperPage.getFormatString()); - } - - @Test - public void dashboardLinkTest() { - getContext().goTo(applicationProperties.getBaseUrl() + getPaperPageUrl()); - PaperPage paperPage = getPaperPage(); - - fillRequiredFields(paperPage, "test " + System.currentTimeMillis()); - String testLink = "http://test.com/"; - paperPage.setUrl(testLink); - paperPage.clickSaveBtn(); - - getContext().goTo(applicationProperties.getBaseUrl() + getPapersDashboardPageUrl()); - PapersDashboardPage papersDashboardPage = getPapersDashboardPage(); - - Assert.assertTrue(papersDashboardPage.externalLinkExists(testLink)); - } - - @Test - public void deletePaperTest() { - createNewPaper(); - getContext().goTo(applicationProperties.getBaseUrl() + getPapersPageUrl()); - PapersPage papersPage = getPapersPage(); - - int size = papersPage.getPapersCount(); - papersPage.clickRemoveFirstPaperButton(); - papersPage.clickConfirmDeleteButton(); - - Assert.assertEquals(size - 1, papersPage.getPapersCount()); - } - - @Test - public void latexValidationTest() { - getContext().goTo(applicationProperties.getBaseUrl() + getPaperPageUrl()); - - PaperPage paperPage = getPaperPage(); - paperPage.setTitle("test"); - paperPage.clickLatexTab(); - paperPage.setLatexText("test"); - paperPage.clickPdfButton(); - - Assert.assertTrue(paperPage.dangerMessageExist("Ошибка при создании PDF")); - } - - @Test - public void titleValidationTest() { - getContext().goTo(applicationProperties.getBaseUrl() + getPaperPageUrl()); - PaperPage paperPage = getPaperPage(); - - paperPage.clickSaveBtn(); - - Assert.assertTrue(paperPage.hasAlert("не может быть пусто")); - } - -} diff --git a/src/test/java/ProjectTest.java b/src/test/java/ProjectTest.java deleted file mode 100644 index f2c6367..0000000 --- a/src/test/java/ProjectTest.java +++ /dev/null @@ -1,174 +0,0 @@ -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Iterables; -import core.PageObject; -import core.TestTemplate; -import org.junit.Assert; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.MethodSorters; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; -import project.ProjectDashboard; -import project.ProjectPage; -import project.ProjectsPage; -import ru.ulstu.NgTrackerApplication; -import ru.ulstu.configuration.ApplicationProperties; - -import java.util.Arrays; -import java.util.Date; -import java.util.List; -import java.util.Map; - -@RunWith(SpringRunner.class) -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -@SpringBootTest(classes = NgTrackerApplication.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) -public class ProjectTest extends TestTemplate { - private final Map> navigationHolder = ImmutableMap.of( - new ProjectPage(), Arrays.asList("ПРОЕКТЫ", "/projects/projects"), - new ProjectsPage(), Arrays.asList("РЕДАКТИРОВАНИЕ ПРОЕКТА", "/projects/project?id=0"), - new ProjectDashboard(), Arrays.asList("ПРОЕКТЫ", "/projects/dashboard") - ); - - @Autowired - private ApplicationProperties applicationProperties; - - @Test - public void testACreateNewProject() { - Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 1); - getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); - ProjectsPage projectsPage = (ProjectsPage) getContext().initPage(page.getKey()); - ProjectPage projectPage = (ProjectPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 0).getKey()); - String name = "Project " + (new Date()).getTime(); - String date = "01.01.2019"; - Integer deadNum = projectPage.getDeadlineCount(); - projectPage.setName(name); - projectPage.clickAddDeadline(); - projectPage.addDeadlineDate(date, deadNum); - projectPage.clickSave(); - Assert.assertTrue(projectsPage.checkNameInList(name)); - } - - @Test - public void testBChangeNameAndSave() { - Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); - getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); - ProjectPage projectPage = (ProjectPage) getContext().initPage(page.getKey()); - ProjectsPage projectsPage = (ProjectsPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); - projectsPage.getFirstProject(); - String name = "Project " + (new Date()).getTime(); - projectPage.clearName(); - projectPage.setName(name); - projectPage.clickSave(); - Assert.assertTrue(projectsPage.checkNameInList(name)); - } - - @Test - public void testCChangeDeadlineAndSave() { - Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); - getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); - ProjectPage projectPage = (ProjectPage) getContext().initPage(page.getKey()); - ProjectsPage projectsPage = (ProjectsPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); - projectsPage.getFirstProject(); - String name = projectPage.getName(); - String date = "01.01.2019"; - Integer deadNum = projectPage.getDeadlineCount(); - projectPage.addDeadlineDate(date, deadNum); - projectPage.clickSave(); - Assert.assertTrue(projectsPage.checkNameInList(name)); - } - - @Test - public void testDSetStatusAndSave() { - Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); - getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); - ProjectPage projectPage = (ProjectPage) getContext().initPage(page.getKey()); - ProjectsPage projectsPage = (ProjectsPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); - projectsPage.getFirstProject(); - String name = projectPage.getName(); - projectPage.setStatus(); - projectPage.clickSave(); - Assert.assertTrue(projectsPage.checkNameInList(name)); - } - - @Test - public void testEAddDescriptionAndSave() { - Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); - getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); - ProjectPage projectPage = (ProjectPage) getContext().initPage(page.getKey()); - ProjectsPage projectsPage = (ProjectsPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); - projectsPage.getFirstProject(); - String name = projectPage.getName(); - String description = "Description " + (new Date()).getTime(); - projectPage.addDescription(description); - projectPage.clickSave(); - Assert.assertTrue(projectsPage.checkNameInList(name)); - } - - @Test - public void testFAddLinkAndSave() { - Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); - getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); - ProjectPage projectPage = (ProjectPage) getContext().initPage(page.getKey()); - ProjectsPage projectsPage = (ProjectsPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); - projectsPage.getFirstProject(); - String name = projectPage.getName(); - String link = "Link " + (new Date()).getTime(); - projectPage.addLink(link); - projectPage.clickSave(); - Assert.assertTrue(projectsPage.checkNameInList(name)); - } - - @Test - public void testGAddDeadlineDescriptionAndSave() { - Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); - getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); - ProjectPage projectPage = (ProjectPage) getContext().initPage(page.getKey()); - ProjectsPage projectsPage = (ProjectsPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); - projectsPage.getFirstProject(); - String name = projectPage.getName(); - String deadDesc = "Description " + (new Date()).getTime(); - projectPage.addDeadlineDescription(deadDesc); - projectPage.clickSave(); - Assert.assertTrue(projectsPage.checkNameInList(name)); - } - - @Test - public void testHSetDeadlineCompletionAndSave() { - Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); - getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); - ProjectPage projectPage = (ProjectPage) getContext().initPage(page.getKey()); - ProjectsPage projectsPage = (ProjectsPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); - projectsPage.getFirstProject(); - String name = projectPage.getName(); - projectPage.setDeadlineCompletion(); - projectPage.clickSave(); - Assert.assertTrue(projectsPage.checkNameInList(name)); - } - - @Test - public void testIDeleteDeadline() { - Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); - getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); - ProjectPage projectPage = (ProjectPage) getContext().initPage(page.getKey()); - ProjectsPage projectsPage = (ProjectsPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); - projectsPage.getFirstProject(); - projectPage.clickDeleteDeadline(); - Assert.assertTrue(projectPage.getDeadlineCount() == 0); - } - - @Test - public void testJDeleteProject() { - Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); - getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); - ProjectPage projectPage = (ProjectPage) getContext().initPage(page.getKey()); - ProjectsPage projectsPage = (ProjectsPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); - projectsPage.getFirstProject(); - String name = projectPage.getName(); - projectPage.clickSave(); - projectsPage.deleteFirst(); - projectsPage.clickConfirm(); - Assert.assertFalse(projectsPage.checkNameInList(name)); - } -} diff --git a/src/test/java/StudentTaskTest.java b/src/test/java/StudentTaskTest.java deleted file mode 100644 index f55a679..0000000 --- a/src/test/java/StudentTaskTest.java +++ /dev/null @@ -1,214 +0,0 @@ -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Iterables; -import core.PageObject; -import core.TestTemplate; -import org.junit.Assert; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.MethodSorters; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; -import ru.ulstu.NgTrackerApplication; -import ru.ulstu.configuration.ApplicationProperties; -import students.TaskPage; -import students.TasksDashboardPage; -import students.TasksPage; - -import java.util.Arrays; -import java.util.Date; -import java.util.List; -import java.util.Map; - -@RunWith(SpringRunner.class) -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -@SpringBootTest(classes = NgTrackerApplication.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) -public class StudentTaskTest extends TestTemplate { - private final Map> navigationHolder = ImmutableMap.of( - new TasksPage(), Arrays.asList("Список задач", "/students/tasks"), - new TasksDashboardPage(), Arrays.asList("Панель управления", "/students/dashboard"), - new TaskPage(), Arrays.asList("Создать задачу", "/students/task?id=0") - ); - - private final String tag = "ATag"; - - @Autowired - private ApplicationProperties applicationProperties; - - - @Test - public void testACreateTask() { - Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 2); - getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); - - TaskPage taskPage = (TaskPage) getContext().initPage(page.getKey()); - TasksPage tasksPage = (TasksPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 0).getKey()); - String taskName = "Task " + (new Date()).getTime(); - - taskPage.setName(taskName); - taskPage.addDeadlineDate("01.01.2020", 0); - taskPage.addDeadlineDescription("Description", 0); - taskPage.save(); - - Assert.assertTrue(tasksPage.findTask(taskName)); - } - - @Test - public void testBEditTaskName() { - Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); - - getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); - TasksPage tasksPage = (TasksPage) getContext().initPage(page.getKey()); - TaskPage taskPage = (TaskPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 2).getKey()); - String taskNewName = "Task " + (new Date()).getTime(); - - tasksPage.goToFirstTask(); - taskPage.removeName(); - taskPage.setName(taskNewName); - taskPage.save(); - - Assert.assertTrue(tasksPage.findTask(taskNewName)); - } - - @Test - public void testCDeleteTask() throws InterruptedException { - Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); - - getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); - TasksPage tasksPage = (TasksPage) getContext().initPage(page.getKey()); - - Integer size = tasksPage.getTasks().size(); - tasksPage.deleteFirstTask(); - Thread.sleep(3000); - tasksPage.submit(); - - Assert.assertEquals(size - 1, tasksPage.getTasks().size()); - } - - @Test - public void testDAddDeadline() { - Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); - - getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); - TasksPage tasksPage = (TasksPage) getContext().initPage(page.getKey()); - TaskPage taskPage = (TaskPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 2).getKey()); - - tasksPage.goToFirstTask(); - String taskId = taskPage.getId(); - Integer deadnum = taskPage.getDeadNum(); - - String descr = "Description"; - String date = "06.06.2019"; - String dateValue = "2019-06-06"; - - taskPage.clickAddDeadline(); - taskPage.addDeadlineDescription(descr, deadnum); - taskPage.addDeadlineDate(date, deadnum); - taskPage.save(); - - getContext().goTo(applicationProperties.getBaseUrl() + String.format("/students/task?id=%s", taskId)); - - Assert.assertTrue(taskPage.hasDeadline(descr, dateValue)); - } - - @Test - public void testEEditDeadline() { - Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); - - getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); - TasksPage tasksPage = (TasksPage) getContext().initPage(page.getKey()); - TaskPage taskPage = (TaskPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 2).getKey()); - - tasksPage.goToFirstTask(); - String taskId = taskPage.getId(); - - String descr = "DescriptionTwo"; - String date = "12.12.2019"; - String dateValue = "2019-12-12"; - - taskPage.clearDeadlineDate(0); - taskPage.clearDeadlineDescription(0); - taskPage.addDeadlineDescription(descr, 0); - taskPage.addDeadlineDate(date, 0); - taskPage.save(); - - getContext().goTo(applicationProperties.getBaseUrl() + String.format("/students/task?id=%s", taskId)); - - Assert.assertTrue(taskPage.hasDeadline(descr, dateValue)); - } - - @Test - public void testFDeleteDeadline() { - Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); - - getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); - TasksPage tasksPage = (TasksPage) getContext().initPage(page.getKey()); - TaskPage taskPage = (TaskPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 2).getKey()); - - tasksPage.goToFirstTask(); - String taskId = taskPage.getId(); - Integer deadNum = taskPage.getDeadNum(); - - taskPage.deleteDeadline(); - taskPage.save(); - - getContext().goTo(applicationProperties.getBaseUrl() + String.format("/students/task?id=%s", taskId)); - - Assert.assertEquals(deadNum - 1, (int) taskPage.getDeadNum()); - } - - @Test - public void testGCreateTaskWithTag() throws InterruptedException { - Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 2); - getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); - - TaskPage taskPage = (TaskPage) getContext().initPage(page.getKey()); - TasksPage tasksPage = (TasksPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 0).getKey()); - String taskName = "Task " + (new Date()).getTime(); - - taskPage.setName(taskName); - taskPage.setTag(tag); - Thread.sleep(1000); - taskPage.addDeadlineDate("01.01.2020", 0); - taskPage.addDeadlineDescription("Description", 0); - taskPage.save(); - - Assert.assertTrue(tasksPage.findTaskByTag(taskName, tag)); - } - - @Test - public void testHFindTagInFilter() { - Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); - - getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); - TasksPage tasksPage = (TasksPage) getContext().initPage(page.getKey()); - - - Assert.assertTrue(tasksPage.findTag(tag)); - } - - @Test - public void testIFilterByTag() { - Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); - - getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); - TasksPage tasksPage = (TasksPage) getContext().initPage(page.getKey()); - tasksPage.selectTag(tag); - - Assert.assertTrue(tasksPage.findTasksByTag(tag)); - } - - @Test - public void testJFilterByStatus() { - Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); - - getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); - TasksPage tasksPage = (TasksPage) getContext().initPage(page.getKey()); - - tasksPage.selectStatus(); - Assert.assertTrue(tasksPage.findAllStatus()); - } - - -} diff --git a/src/test/java/conference/ConferencePage.java b/src/test/java/conference/ConferencePage.java deleted file mode 100644 index 4717217..0000000 --- a/src/test/java/conference/ConferencePage.java +++ /dev/null @@ -1,116 +0,0 @@ -package conference; - -import core.PageObject; -import org.openqa.selenium.By; -import org.openqa.selenium.WebElement; - -import java.util.List; - -public class ConferencePage extends PageObject { - - public String getSubTitle() { - return driver.findElement(By.tagName("h3")).getText(); - } - - public String getId() { - return driver.findElement(By.id("id")).getAttribute("value"); - } - - public void setName(String name) { - driver.findElement(By.id("title")).sendKeys(name); - } - - public String getName() { - return driver.findElement(By.id("title")).getAttribute("value"); - } - - public void clearName() { - driver.findElement(By.id("title")).clear(); - } - - public void clickSaveBut() { - driver.findElement(By.id("send-message-button")).click(); - } - - public void clickAddDeadlineBut() { - driver.findElement(By.id("addDeadline")).click(); - } - - private List getDeadlineList() { - return driver.findElements(By.className("deadline")); - } - - public Integer getDeadlineCount() { - return driver.findElements(By.className("deadline")).size(); - } - - public void setDeadlineDescription(String description, Integer i) { - driver.findElement(By.id(String.format("deadlines%d.description", i))).sendKeys(description); - } - - public void setDeadlineDate(String date, Integer i) { - driver.findElement(By.id(String.format("deadlines%d.date", i))).sendKeys(date); - } - - public void clickTakePartBut() { - driver.findElement(By.id("take-part")).click(); - } - - public Boolean isTakePartButDisabledValueTrue() { - return driver.findElement(By.id("take-part")).getAttribute("disabled").equals("true"); - } - - public Integer getMemberCount() { - return driver.findElements(By.className("member")).size(); - } - - public void clickDeleteDeadlineBut() { - driver.findElement(By.xpath("//*[@id=\"deadlines\"]/div/input[4]")).click(); - } - - public void showAllowToAttachArticles() { - driver.findElement(By.cssSelector("button[data-id=\"paperIds\"]")).click(); - } - - public void clickAddPaperBut() { - driver.findElement(By.id("add-paper")).click(); - } - - - public List getArticles() { - return driver.findElements(By.className("paper")); - } - - public Integer getArticlesCount() { - return driver.findElements(By.className("paper")).size(); - } - - public WebElement selectArticle() { - WebElement webElement = driver.findElement(By.xpath("//*[@id=\"conference-form\"]/div/div[2]/div[5]/div/div/div[2]/ul/li[1]/a")); - webElement.click(); - return webElement; - } - - public void clickUndockArticleBut() { - driver.findElement(By.name("removePaper")).click(); - } - - public boolean checkDeadline(String description, String dateValue) { - return getDeadlineList() - .stream() - .anyMatch(webElement -> { - return webElement.findElement(By.className("deadline-text")).getAttribute("value").equals(description) - && webElement.findElement(By.cssSelector("input[type=\"date\"]")).getAttribute("value").equals(dateValue); - }); - } - - public boolean checkArticle(String paperName) { - return getArticles() - .stream() - .anyMatch(webElement -> webElement - .findElements(By.tagName("input")) - .get(1).getAttribute("value") - .equals(paperName)); - } - -} \ No newline at end of file diff --git a/src/test/java/conference/ConferencesDashboardPage.java b/src/test/java/conference/ConferencesDashboardPage.java deleted file mode 100644 index d358c4a..0000000 --- a/src/test/java/conference/ConferencesDashboardPage.java +++ /dev/null @@ -1,11 +0,0 @@ -package conference; - -import core.PageObject; -import org.openqa.selenium.By; - -public class ConferencesDashboardPage extends PageObject { - - public String getSubTitle() { - return driver.findElement(By.tagName("h2")).getText(); - } -} diff --git a/src/test/java/conference/ConferencesPage.java b/src/test/java/conference/ConferencesPage.java deleted file mode 100644 index c11429f..0000000 --- a/src/test/java/conference/ConferencesPage.java +++ /dev/null @@ -1,47 +0,0 @@ -package conference; - -import core.PageObject; -import org.openqa.selenium.By; -import org.openqa.selenium.WebElement; - -import java.util.List; - -public class ConferencesPage extends PageObject { - - public String getSubTitle() { - return driver.findElement(By.tagName("h3")).getText(); - } - - public List getConferencesList() { - return driver.findElements(By.cssSelector("span.h6.float-left.m-2")); - } - - public void getFirstConference() { - driver.findElement(By.xpath("//*[@id=\"conferences\"]/div/div[2]/div[1]/div[1]/div/a")).click(); - } - - public void selectMember() { - driver.findElements(By.className("bootstrap-select")).get(0).findElement(By.className("btn")).click(); - driver.findElements(By.className("bootstrap-select")).get(0).findElements(By.className("dropdown-item")).get(1).click(); - } - - public void selectYear() { - driver.findElements(By.className("bootstrap-select")).get(1).findElement(By.className("btn")).click(); - driver.findElements(By.className("bootstrap-select")).get(1).findElements(By.className("dropdown-item")).get(1).click(); - } - - public void deleteFirst() { - js.executeScript("$('input[data-confirm]').click();"); - } - - public void clickConfirm() { - driver.findElement(By.id("deleteConference")).click(); - } - - - public boolean checkNameInList(String newConferenceName) { - return getConferencesList() - .stream() - .anyMatch(webElement -> webElement.getText().equals(newConferenceName)); - } -} \ No newline at end of file diff --git a/src/test/java/context/ChromeContext.java b/src/test/java/context/ChromeContext.java deleted file mode 100644 index 899d51d..0000000 --- a/src/test/java/context/ChromeContext.java +++ /dev/null @@ -1,27 +0,0 @@ -package context; - -import org.openqa.selenium.chrome.ChromeDriver; -import org.openqa.selenium.chrome.ChromeOptions; - -public class ChromeContext extends Context { - private final static String WINDOWS_DRIVER = "chromedriver.exe"; - private final static String LINUX_DRIVER = "chromedriver"; - private final static String DRIVER_TYPE = "webdriver.chrome.driver"; - - @Override - protected void createDriver() { - final ChromeOptions chromeOptions = new ChromeOptions(); - chromeOptions.addArguments("--headless"); - driver = new ChromeDriver(chromeOptions); - } - - @Override - protected String getDriverExecutable(boolean isWindows) { - return isWindows ? WINDOWS_DRIVER : LINUX_DRIVER; - } - - @Override - protected String getDriverType() { - return DRIVER_TYPE; - } -} diff --git a/src/test/java/context/Context.java b/src/test/java/context/Context.java deleted file mode 100644 index a1c5d1c..0000000 --- a/src/test/java/context/Context.java +++ /dev/null @@ -1,65 +0,0 @@ -package context; - -import core.PageObject; -import org.openqa.selenium.Dimension; -import org.openqa.selenium.WebDriver; - -import java.util.concurrent.TimeUnit; - -public abstract class Context { - private final static String DRIVER_LOCATION = "drivers/%s"; - - WebDriver driver; - - private WebDriver getDriver() { - if (driver != null) { - return driver; - } - throw new IllegalStateException("WebDriver is not initialized"); - } - - public void start() { - System.setProperty(getDriverType(), getDriverExecutablePath()); - - createDriver(); - // это плохая инструкция для автотестов, т.к. лучше задавать для конкретного элемента или кейса - getDriver().manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); - } - - public void close() { - if (driver != null) { - driver.quit(); - } - } - - public void goTo(String url) { - getDriver().get(url); - } - - public String getTitle() { - return getDriver().getTitle(); - } - - public PageObject initPage(T pageObject) { - return pageObject.setDriver(getDriver()); - } - - protected abstract void createDriver(); - - protected abstract String getDriverType(); - - protected abstract String getDriverExecutable(boolean windows); - - private String getDriverExecutablePath() { - return Context.class.getClassLoader().getResource( - String.format(DRIVER_LOCATION, getDriverExecutable(isWindows()))).getFile(); - } - - private boolean isWindows() { - return System.getProperty("os.name").toLowerCase().contains("windows"); - } - - public void setSize(Dimension dimension) { - driver.manage().window().setSize(dimension); - } -} diff --git a/src/test/java/context/FirefoxContext.java b/src/test/java/context/FirefoxContext.java deleted file mode 100644 index 1d5c163..0000000 --- a/src/test/java/context/FirefoxContext.java +++ /dev/null @@ -1,24 +0,0 @@ -package context; - -import org.openqa.selenium.firefox.FirefoxDriver; - -public class FirefoxContext extends Context { - private final static String WINDOWS_DRIVER = "geckodriver.exe"; - private final static String LINUX_DRIVER = "geckodriver"; - private final static String DRIVER_TYPE = "webdriver.gecko.driver"; - - @Override - protected void createDriver() { - driver = new FirefoxDriver(); - } - - @Override - protected String getDriverExecutable(boolean isWindows) { - return isWindows ? WINDOWS_DRIVER : LINUX_DRIVER; - } - - @Override - protected String getDriverType() { - return DRIVER_TYPE; - } -} diff --git a/src/test/java/core/PageObject.java b/src/test/java/core/PageObject.java deleted file mode 100644 index e8eae6e..0000000 --- a/src/test/java/core/PageObject.java +++ /dev/null @@ -1,25 +0,0 @@ -package core; - -import org.openqa.selenium.JavascriptExecutor; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.support.PageFactory; -import org.openqa.selenium.support.ui.WebDriverWait; - -public abstract class PageObject { - protected WebDriver driver; - protected JavascriptExecutor js; - protected WebDriverWait waiter; - - public abstract String getSubTitle(); - - public PageObject setDriver(WebDriver driver) { - this.driver = driver; - js = (JavascriptExecutor) driver; - waiter = new WebDriverWait(driver, 10); - return this; - } - - public void initElements() { - PageFactory.initElements(driver, this); - } -} diff --git a/src/test/java/core/TestTemplate.java b/src/test/java/core/TestTemplate.java deleted file mode 100644 index 44a61fb..0000000 --- a/src/test/java/core/TestTemplate.java +++ /dev/null @@ -1,29 +0,0 @@ -package core; - -import context.ChromeContext; -import context.Context; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.openqa.selenium.Dimension; - -public abstract class TestTemplate { - private static Context context; - - protected static Context getContext() { - return context; - } - - @BeforeClass - public static void setup() { - context = new ChromeContext(); - context.start(); - context.setSize(new Dimension(1600, 900)); - } - - @AfterClass - public static void quit() { - if (context != null) { - context.close(); - } - } -} diff --git a/src/test/java/grant/GrantPage.java b/src/test/java/grant/GrantPage.java deleted file mode 100644 index 363a195..0000000 --- a/src/test/java/grant/GrantPage.java +++ /dev/null @@ -1,149 +0,0 @@ -package grant; - -import core.PageObject; -import org.openqa.selenium.By; -import org.openqa.selenium.WebElement; -import org.openqa.selenium.support.ui.Select; - -import java.util.List; - -public class GrantPage extends PageObject { - @Override - public String getSubTitle() { - return driver.findElement(By.tagName("h2")).getText(); - } - - public String getId() { - return driver.findElement(By.id("grantId")).getAttribute("value"); - } - - public void setTitle(String name) { - driver.findElement(By.id("title")).clear(); - driver.findElement(By.id("title")).sendKeys(name); - } - - public String getTitle() { - return driver.findElement(By.id("title")).getAttribute("value"); - } - - public void setDeadline(String date, Integer i, String description) { - driver.findElement(By.id(String.format("deadlines%d.date", i))).sendKeys(date); - driver.findElement(By.id(String.format("deadlines%d.description", i))).sendKeys(description); - } - - public void setLeader() { - WebElement webElement = driver.findElement(By.id("leaderId")); - Select selectLeader = new Select(webElement); - selectLeader.selectByVisibleText("Романов"); - } - - public void saveGrant() { - driver.findElement(By.id("sendMessageButton")).click(); - } - - public boolean checkBlankFields() { - return driver.findElements(By.className("alert-danger")).size() > 0; - } - - public List getAttachedPapers() { - try { - return driver.findElement(By.className("div-selected-papers")).findElements(By.tagName("div")); - } catch (Exception ex) { - return null; - } - } - - public List attachPaper() { - WebElement selectPapers = driver.findElement(By.id("allPapers")); - Select select = new Select(selectPapers); - List selectedOptions = select.getAllSelectedOptions(); - List allOptions = select.getOptions(); - if (selectedOptions.size() >= allOptions.size()) { - for (int i = 0; i < allOptions.size(); i++) { - if (!allOptions.get(i).equals(selectedOptions.get(i))) { - select.selectByVisibleText(allOptions.get(i).getText()); - selectedOptions.add(allOptions.get(i)); - return selectedOptions; - } - } - } else { - select.selectByVisibleText(allOptions.get(0).getText()); - selectedOptions.add(allOptions.get(0)); - return selectedOptions; - } - return null; - } - - public List deletePaper() { - WebElement selectPapers = driver.findElement(By.id("allPapers")); - Select select = new Select(selectPapers); - select.deselectByVisibleText(select.getFirstSelectedOption().getText()); - return select.getAllSelectedOptions(); - } - - private List getDeadlineList() { - return driver.findElements(By.id("deadlines")); - } - - public Integer getDeadlineCount() { - return getDeadlineList().size(); - } - - public void addDeadline() { - driver.findElement(By.id("addDeadline")).click(); - } - - public boolean checkDeadline(String description, String dateValue) { - return getDeadlineList() - .stream() - .anyMatch(webElement -> { - return webElement.findElement(By.className("div-deadline-description")).findElement( - By.tagName("input")).getAttribute("value").equals(description) - && webElement.findElement(By.className("form-deadline-date")).getAttribute("value").equals(dateValue); - }); - } - - public void deleteDeadline() { - driver.findElements(By.className("btn-delete-deadline")).get(0).click(); - } - - public List addAuthor() { - WebElement selectAuthors = driver.findElement(By.id("authors")); - Select select = new Select(selectAuthors); - List selectedOptions = select.getAllSelectedOptions(); - List allOptions = select.getOptions(); - int i = 0; - while (i < selectedOptions.size()) { - if (!allOptions.get(i).equals(selectedOptions.get(i))) { - select.selectByVisibleText(allOptions.get(i).getText()); - selectedOptions.add(allOptions.get(i)); - return selectedOptions; - } else { - i++; - } - } - if (selectedOptions.size() != allOptions.size()) { - select.selectByVisibleText(allOptions.get(i).getText()); - selectedOptions.add(allOptions.get(i)); - } - return selectedOptions; - } - - public void deleteAuthor() { - WebElement selectAuthors = driver.findElement(By.id("authors")); - Select select = new Select(selectAuthors); - List selectedOptions = select.getAllSelectedOptions(); - if (selectedOptions.size() != 0) { - select.deselectByVisibleText(selectedOptions.get(0).getText()); - } - } - - public void setDescription(String description) { - driver.findElement(By.id("comment")).clear(); - driver.findElement(By.id("comment")).sendKeys(description); - } - - public String getDescription() { - return driver.findElement(By.id("comment")).getText(); - } -} diff --git a/src/test/java/grant/GrantsDashboardPage.java b/src/test/java/grant/GrantsDashboardPage.java deleted file mode 100644 index 036e785..0000000 --- a/src/test/java/grant/GrantsDashboardPage.java +++ /dev/null @@ -1,11 +0,0 @@ -package grant; - -import core.PageObject; -import org.openqa.selenium.By; - -public class GrantsDashboardPage extends PageObject { - @Override - public String getSubTitle() { - return driver.findElement(By.tagName("h2")).getText(); - } -} diff --git a/src/test/java/grant/GrantsPage.java b/src/test/java/grant/GrantsPage.java deleted file mode 100644 index 33c388d..0000000 --- a/src/test/java/grant/GrantsPage.java +++ /dev/null @@ -1,66 +0,0 @@ -package grant; - -import core.PageObject; -import org.openqa.selenium.By; -import org.openqa.selenium.WebElement; - -import java.util.List; - -public class GrantsPage extends PageObject { - @Override - public String getSubTitle() { - return driver.findElement(By.tagName("h2")).getText(); - } - - public List getGrantsList() { - return driver.findElements(By.className("grant-row")); - } - - public boolean findGrantByTitle(String grantTitle) { - return getGrantsList() - .stream() - .map(el -> el.findElement(By.cssSelector("span.h6"))) - .anyMatch(webElement -> webElement.getText().equals(grantTitle)); - } - - public void deleteFirst() throws InterruptedException { - WebElement findDeleteButton = driver.findElement(By.xpath("//*[@id=\"grants\"]/div/div[2]/div[1]/div[1]/div")); - findDeleteButton.click(); - Thread.sleep(3000); - WebElement grant = driver.findElement(By.xpath("//*[@id=\"grants\"]/div/div[2]/div[1]/div[1]/div/a[2]")); - grant.click(); - WebElement ok = driver.findElement(By.id("dataConfirmOK")); - ok.click(); - } - - public void getFirstGrant() { - driver.findElement(By.xpath("//*[@id=\"grants\"]/div/div[2]/div[1]/div[1]/div/a[1]")).click(); - } - - public WebElement getFirstGrantWithoutClick() { - return driver.findElement(By.xpath("//*[@id=\"grants\"]/div/div[2]/div[1]/div[1]")); - } - - public String getGrantTitle(WebElement webElement) { - return webElement.findElement(By.cssSelector("span.h6")).getText(); - } - - public WebElement getGrantByTitle(String title) { - List list = getGrantsList(); - for (int i = 0; i < list.size(); i++) { - if (getGrantTitle(list.get(i)).equals(title)) { - return list.get(i); - } - } - return null; - } - - public Integer getAuthorsCount(WebElement webElement) { - String authors = webElement.findElement(By.className("text-muted")).getText(); - if (!authors.equals("")) { - String[] mas = authors.split(","); - return mas.length; - } - return 0; - } -} diff --git a/src/test/java/grant/KiasPage.java b/src/test/java/grant/KiasPage.java deleted file mode 100644 index 5864511..0000000 --- a/src/test/java/grant/KiasPage.java +++ /dev/null @@ -1,11 +0,0 @@ -package grant; - -import core.PageObject; -import org.openqa.selenium.By; - -public class KiasPage extends PageObject { - @Override - public String getSubTitle() { - return driver.findElement(By.tagName("h1")).getText(); - } -} diff --git a/src/test/java/paper/PaperPage.java b/src/test/java/paper/PaperPage.java deleted file mode 100644 index 908f8a1..0000000 --- a/src/test/java/paper/PaperPage.java +++ /dev/null @@ -1,217 +0,0 @@ -package paper; - -import core.PageObject; -import org.openqa.selenium.By; -import org.openqa.selenium.WebElement; -import org.openqa.selenium.support.FindBy; -import org.openqa.selenium.support.ui.ExpectedConditions; -import org.openqa.selenium.support.ui.Select; - -import java.util.List; - -public class PaperPage extends PageObject { - - @FindBy(id = "title") - private WebElement titleInput; - - @FindBy(id = "sendMessageButton") - private WebElement sendMessageButton; - - @FindBy(id = "id") - private WebElement idInput; - - @FindBy(css = "#messages .alert-danger span") - private WebElement dangerMessage; - - @FindBy(className = "deadline") - private List deadlines; - - @FindBy(className = "deadline-date") - private List deadlineDates; - - @FindBy(className = "deadline-desc") - private List deadlineDescs; - - @FindBy(css = ".alert.alert-danger") - private List dangerAlerts; - - @FindBy(className = "collapse-heading") - private WebElement firstCollapsedLink; - - @FindBy(id = "nav-references-tab") - private WebElement referenceTab; - - @FindBy(id = "nav-latex-tab") - private WebElement latexTab; - - @FindBy(id = "latex-text") - private WebElement latexTextarea; - - @FindBy(id = "addReference") - private WebElement addReferenceButton; - - @FindBy(css = "input.author ") - private WebElement firstAuthorInput; - - @FindBy(css = "input.publicationTitle") - private WebElement firstPublicationTitleInput; - - @FindBy(css = "input.publicationYear") - private WebElement firstPublicationYearInput; - - @FindBy(css = "input.publisher") - private WebElement firstPublisherInput; - - @FindBy(css = "input.pages") - private WebElement firstPagesInput; - - @FindBy(css = "input.journalOrCollectionTitle") - private WebElement firstJournalOrCollectionTitleInput; - - @FindBy(id = "formatBtn") - private WebElement formatButton; - - @FindBy(id = "formattedReferencesArea") - private WebElement formatArea; - - @FindBy(id = "url") - private WebElement urlInput; - - @FindBy(id = "pdfBtn") - private WebElement pdfButton; - - @FindBy(css = "input.author ") - private List authorInputs; - - public String getSubTitle() { - return driver.findElement(By.tagName("h2")).getText(); - } - - public void clickReferenceTab() { - js.executeScript("document.getElementById('nav-references-tab').scrollIntoView(false);"); - referenceTab.click(); - } - - public void clickLatexTab() { - latexTab.click(); - } - - public void showFirstReference() { - waiter.until(ExpectedConditions.elementToBeClickable(firstCollapsedLink)); - firstCollapsedLink.click(); - } - - public void clickAddReferenceButton() { - js.executeScript("arguments[0].click()", addReferenceButton); - } - - public void clickFormatButton() { - formatButton.click(); - } - - public void clickPdfButton() { - pdfButton.click(); - } - - public void setTitle(String title) { - titleInput.clear(); - titleInput.sendKeys(title); - } - - public void setLatexText(String text) { - waiter.until(ExpectedConditions.visibilityOf(latexTextarea)); - latexTextarea.clear(); - latexTextarea.sendKeys(text); - } - - public void setFirstReferenceAuthors(String authors) { - waiter.until(ExpectedConditions.visibilityOf(firstAuthorInput)); - - firstAuthorInput.clear(); - firstAuthorInput.sendKeys(authors); - } - - public void setFirstReferencePublicationTitle(String title) { - firstPublicationTitleInput.clear(); - firstPublicationTitleInput.sendKeys(title); - } - - public void setFirstReferencePublicationYear(String year) { - firstPublicationYearInput.clear(); - firstPublicationYearInput.sendKeys(year); - } - - public void setFirstReferencePublisher(String publisher) { - firstPublisherInput.clear(); - firstPublisherInput.sendKeys(publisher); - } - - public void setFirstReferencePages(String pages) { - firstPagesInput.clear(); - firstPagesInput.sendKeys(pages); - } - - public void setFirstReferenceJournalOrCollectionTitle(String journal) { - firstJournalOrCollectionTitleInput.clear(); - firstJournalOrCollectionTitleInput.sendKeys(journal); - } - - public void setUrl(String url) { - urlInput.clear(); - urlInput.sendKeys(url); - } - - public void setFormatStandardSpringer() { - Select standards = new Select(driver.findElement(By.id("formatStandard"))); - standards.selectByValue("SPRINGER"); - } - - public void setDeadlineDate(Integer deadlineNumber, String date) { - deadlineDates.get(deadlineNumber - 1).sendKeys(date); - } - - public void setDeadlineDescription(Integer deadlineNumber, String desc) { - deadlineDescs.get(deadlineNumber - 1).clear(); - deadlineDescs.get(deadlineNumber - 1).sendKeys(desc); - } - - public boolean hasAlert(String alertMessage) { - return dangerAlerts - .stream() - .anyMatch( - webElement -> webElement.getText().contains(alertMessage)); - } - - public void clickSaveBtn() { - sendMessageButton.click(); - } - - public String getId() { - return idInput.getAttribute("value"); - } - - public String getFormatString() { - waiter.until(ExpectedConditions.attributeToBeNotEmpty(formatArea, "value")); - return formatArea.getAttribute("value"); - } - - public boolean deadlineExist(String desc, String date) { - return deadlines - .stream() - .anyMatch( - webElement -> webElement.findElement(By.className("deadline-desc")).getAttribute("value").equals(desc) - && webElement.findElement(By.className("deadline-date")).getAttribute("value").equals(date)); - } - - public boolean authorsExists(String authors) { - return authorInputs - .stream() - .anyMatch( - webElement -> webElement.getAttribute("value").equals(authors)); - } - - public boolean dangerMessageExist(String message) { - waiter.until(ExpectedConditions.visibilityOf(dangerMessage)); - return dangerMessage.getText().equals(message); - } -} diff --git a/src/test/java/paper/PapersDashboardPage.java b/src/test/java/paper/PapersDashboardPage.java deleted file mode 100644 index 4567490..0000000 --- a/src/test/java/paper/PapersDashboardPage.java +++ /dev/null @@ -1,24 +0,0 @@ -package paper; - -import core.PageObject; -import org.openqa.selenium.By; -import org.openqa.selenium.WebElement; -import org.openqa.selenium.support.FindBy; - -import java.util.List; - -public class PapersDashboardPage extends PageObject { - @FindBy(className = "externalLink") - private List externalLinks; - - public String getSubTitle() { - return driver.findElement(By.tagName("h2")).getText(); - } - - public boolean externalLinkExists(String link) { - return externalLinks - .stream() - .anyMatch( - webElement -> webElement.getAttribute("href").equals(link)); - } -} diff --git a/src/test/java/paper/PapersPage.java b/src/test/java/paper/PapersPage.java deleted file mode 100644 index 620d0c0..0000000 --- a/src/test/java/paper/PapersPage.java +++ /dev/null @@ -1,61 +0,0 @@ -package paper; - -import core.PageObject; -import org.openqa.selenium.By; -import org.openqa.selenium.WebElement; -import org.openqa.selenium.support.FindBy; -import org.openqa.selenium.support.ui.ExpectedConditions; - -import java.util.List; - -public class PapersPage extends PageObject { - @FindBy(css = ".paper-row .h6") - private List paperTitles; - - @FindBy(className = "paper-row") - private List paperItems; - - @FindBy(className = "remove-paper") - private WebElement removeFirstPaperButton; - - @FindBy(id = "dataConfirmOK") - private WebElement confirmDeleteButton; - - @FindBy(id = "addDeadline") - private WebElement addDeadlineButton; - - @FindBy(css = ".paper-row a:nth-child(2)") - private WebElement firstPaper; - - public String getSubTitle() { - return driver.findElement(By.tagName("h2")).getText(); - } - - public void clickFirstPaper() { - firstPaper.click(); - } - - public void clickAddDeadline() { - addDeadlineButton.click(); - } - - public void clickRemoveFirstPaperButton() { - js.executeScript("arguments[0].click()", removeFirstPaperButton); - } - - public void clickConfirmDeleteButton() { - waiter.until(ExpectedConditions.visibilityOf(confirmDeleteButton)); - confirmDeleteButton.click(); - } - - public boolean havePaperWithTitle(String title) { - return paperTitles - .stream() - .anyMatch(webElement -> webElement.getText().equals(title)); - } - - public int getPapersCount() { - return paperItems.size(); - } - -} diff --git a/src/test/java/project/ProjectDashboard.java b/src/test/java/project/ProjectDashboard.java deleted file mode 100644 index 0b36204..0000000 --- a/src/test/java/project/ProjectDashboard.java +++ /dev/null @@ -1,11 +0,0 @@ -package project; - -import core.PageObject; -import org.openqa.selenium.By; - -public class ProjectDashboard extends PageObject { - - public String getSubTitle() { - return driver.findElement(By.tagName("h2")).getText(); - } -} diff --git a/src/test/java/project/ProjectPage.java b/src/test/java/project/ProjectPage.java deleted file mode 100644 index 9953177..0000000 --- a/src/test/java/project/ProjectPage.java +++ /dev/null @@ -1,141 +0,0 @@ -package project; - -import core.PageObject; -import org.openqa.selenium.By; -import org.openqa.selenium.WebElement; - -import java.util.List; - -public class ProjectPage extends PageObject { - - public String getSubTitle() { - return driver.findElement(By.tagName("h3")).getText(); - } - - public String getId() { - return driver.findElement(By.id("id")).getAttribute("value"); - } - - public void setName(String name) { - driver.findElement(By.id("title")).sendKeys(name); - } - - public String getName() { - return driver.findElement(By.id("title")).getAttribute("value"); - } - - public void clearName() { - driver.findElement(By.id("title")).clear(); - } - - public void clickSave() { - driver.findElement(By.id("sendMessageButton")).click(); - } - - public void clickAddDeadline() { - driver.findElement(By.id("addDeadline")).click(); - } - - public void addDeadlineDate(String deadDate, Integer deadNum) { - driver.findElement(By.id(String.format("deadlines%d.date", deadNum))).sendKeys(deadDate); - } - - public void addDeadlineDescription(String description) { - driver.findElement(By.id("deadlines0.description")).sendKeys(description); - } - - public void setDeadlineCompletion() { - driver.findElement(By.id("deadlines0.done1")).click(); - } - - public void setStatus() { - driver.findElement(By.id("status")).click(); - getFirstStatus(); - } - - private void getFirstStatus() { - driver.findElement(By.xpath("//*[@id=\"status\"]/option[1]")).click(); - } - - public void addDescription(String description) { - driver.findElement(By.id("description")).sendKeys(description); - } - - public void addLink(String link) { - driver.findElement(By.id("repository")).sendKeys(link); - } - - private List getDeadlineList() { - return driver.findElements(By.className("deadline")); - } - - public Integer getDeadlineCount() { - return driver.findElements(By.className("deadline")).size(); - } - - public void setExecutors() { - driver.findElement(By.id("status")).click(); - getFirstExecutor(); - } - - private void getFirstExecutor() { - driver.findElement(By.xpath("//*[@id=\"status\"]/option[1]")).click(); - } - - public void setDeadlineDescription(String description, Integer i) { - driver.findElement(By.id(String.format("deadlines%d.description", i))).sendKeys(description); - } - - public void setDeadlineDate(String date, Integer i) { - driver.findElement(By.id(String.format("deadlines%d.date", i))).sendKeys(date); - } - - public Boolean isTakePartButDisabledValueTrue() { - return driver.findElement(By.id("take-part")).getAttribute("disabled").equals("true"); - } - - public Integer getMemberCount() { - return driver.findElements(By.className("member")).size(); - } - - public void clickDeleteDeadline() { - driver.findElement(By.className("btn-danger")).click(); - } - - public void showAllowToAttachArticles() { - driver.findElement(By.cssSelector("button[data-id=\"paperIds\"]")).click(); - } - - public void clickAddPaperBut() { - driver.findElement(By.id("add-paper")).click(); - } - - - public List getArticles() { - return driver.findElements(By.className("paper")); - } - - public Integer getArticlesCount() { - return driver.findElements(By.className("paper")).size(); - } - - public WebElement selectArticle() { - WebElement webElement = driver.findElement(By.xpath("//*[@id=\"project-form\"]/div/div[2]/div[5]/div/div/div[2]/ul/li[1]/a")); - webElement.click(); - return webElement; - } - - public void clickUndockArticleBut() { - driver.findElement(By.name("removePaper")).click(); - } - - public boolean checkDeadline(String description, String dateValue) { - return getDeadlineList() - .stream() - .anyMatch(webElement -> { - return webElement.findElement(By.className("deadline-text")).getAttribute("value").equals(description) - && webElement.findElement(By.cssSelector("input[type=\"date\"]")).getAttribute("value").equals(dateValue); - }); - } - -} \ No newline at end of file diff --git a/src/test/java/project/ProjectsPage.java b/src/test/java/project/ProjectsPage.java deleted file mode 100644 index 123bc50..0000000 --- a/src/test/java/project/ProjectsPage.java +++ /dev/null @@ -1,41 +0,0 @@ -package project; - -import core.PageObject; -import org.openqa.selenium.By; -import org.openqa.selenium.WebElement; - -import java.util.List; - -public class ProjectsPage extends PageObject { - - public String getSubTitle() { - return driver.findElement(By.tagName("h2")).getText(); - } - - private List getProjectsList() { - return driver.findElements(By.cssSelector("span.h6")); - } - - public void getFirstProject() { - driver.findElement(By.xpath("//*[@id=\"projects\"]/div/div[2]/div[1]/div[1]/div/a")).click(); - } - - public void selectMember() { - driver.findElements(By.className("bootstrap-select")).get(0).findElement(By.className("btn")).click(); - driver.findElements(By.className("bootstrap-select")).get(0).findElements(By.className("dropdown-item")).get(1).click(); - } - - public void deleteFirst() { - js.executeScript("$('a[data-confirm]').click();"); - } - - public void clickConfirm() { - driver.findElement(By.id("dataConfirmOK")).click(); - } - - public boolean checkNameInList(String newProjectName) { - return getProjectsList() - .stream() - .anyMatch(webElement -> webElement.getText().equals(newProjectName)); - } -} \ No newline at end of file diff --git a/src/test/java/ru/ulstu/conference/service/ConferenceServiceTest.java b/src/test/java/ru/ulstu/conference/service/ConferenceServiceTest.java deleted file mode 100644 index 56756a3..0000000 --- a/src/test/java/ru/ulstu/conference/service/ConferenceServiceTest.java +++ /dev/null @@ -1,278 +0,0 @@ -package ru.ulstu.conference.service; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.springframework.data.domain.Sort; -import org.springframework.test.context.junit4.SpringRunner; -import ru.ulstu.conference.model.Conference; -import ru.ulstu.conference.model.ConferenceDto; -import ru.ulstu.conference.model.ConferenceFilterDto; -import ru.ulstu.conference.model.ConferenceUser; -import ru.ulstu.conference.repository.ConferenceRepository; -import ru.ulstu.deadline.model.Deadline; -import ru.ulstu.deadline.service.DeadlineService; -import ru.ulstu.paper.model.Paper; -import ru.ulstu.paper.service.PaperService; -import ru.ulstu.ping.service.PingService; -import ru.ulstu.timeline.service.EventService; -import ru.ulstu.user.model.User; -import ru.ulstu.user.service.UserService; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Date; -import java.util.List; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.when; - -@RunWith(SpringRunner.class) -public class ConferenceServiceTest { - - @Mock - ConferenceRepository conferenceRepository; - - @Mock - DeadlineService deadlineService; - - @Mock - ConferenceUserService conferenceUserService; - - @Mock - PaperService paperService; - - @Mock - UserService userService; - - @Mock - EventService eventService; - - @Mock - ConferenceNotificationService conferenceNotificationService; - - @Mock - PingService pingService; - - @InjectMocks - ConferenceService conferenceService; - - private final static Integer ID = 1; - private final static Integer INDEX = 0; - private final static String NAME = "Name"; - private final static String DESCRIPTION = "Desc"; - private final static boolean TRUE = true; - private final static Integer YEAR = 2019; - private final static Sort SORT = new Sort(Sort.Direction.DESC, "beginDate"); - - private List conferences; - private List deadlines; - private List papers; - private List conferenceUsers; - - private Conference conferenceWithId; - - private Paper paperWithId; - private Paper paperWithoutId; - - private ConferenceDto conferenceDto; - private User user; - private Deadline deadline; - - @Before - public void setUp() throws Exception { - conferences = new ArrayList<>(); - conferenceWithId = new Conference(); - - conferenceWithId.setId(ID); - conferenceWithId.setTitle(NAME); - conferenceWithId.setDescription(DESCRIPTION); - - paperWithId = new Paper(); - paperWithId.setId(1); - paperWithId.setTitle(NAME); - - paperWithoutId = new Paper(); - paperWithoutId.setTitle(NAME); - - papers = new ArrayList<>(); - papers.add(paperWithId); - papers.add(paperWithoutId); - - deadlines = new ArrayList<>(); - deadline = new Deadline(new Date(), DESCRIPTION); - deadline.setId(ID); - deadlines.add(deadline); - - ConferenceUser conferenceUser = new ConferenceUser(); - conferenceUser.setDeposit(ConferenceUser.Deposit.ARTICLE); - conferenceUser.setParticipation(ConferenceUser.Participation.INTRAMURAL); - user = new User(); - user.setFirstName(NAME); - conferenceUser.setUser(user); - - conferenceUsers = new ArrayList<>(); - conferenceUsers.add(conferenceUser); - - conferences.add(conferenceWithId); - conferenceDto = new ConferenceDto(conferenceWithId); - } - - @Test - public void getExistConferenceById() { - when(conferenceRepository.getOne(ID)).thenReturn(conferenceWithId); - when(paperService.findAllNotSelect(new ArrayList<>())).thenReturn(papers); - when(userService.getCurrentUser()).thenReturn(user); - - ConferenceDto newConferenceDto = new ConferenceDto(conferenceWithId); - newConferenceDto.setNotSelectedPapers(papers); - newConferenceDto.setDisabledTakePart(!TRUE); - ConferenceDto result = conferenceService.getExistConferenceById(ID); - - assertEquals(newConferenceDto.getId(), result.getId()); - assertEquals(newConferenceDto.getNotSelectedPapers(), result.getNotSelectedPapers()); - assertEquals(newConferenceDto.isDisabledTakePart(), result.isDisabledTakePart()); - } - - @Test - public void getNewConference() { - when(paperService.findAllNotSelect(new ArrayList<>())).thenReturn(papers); - - ConferenceDto newConferenceDto = new ConferenceDto(); - newConferenceDto.setNotSelectedPapers(papers); - ConferenceDto result = conferenceService.getNewConference(); - - assertEquals(newConferenceDto.getId(), result.getId()); - assertEquals(newConferenceDto.getNotSelectedPapers(), result.getNotSelectedPapers()); - assertEquals(newConferenceDto.isDisabledTakePart(), result.isDisabledTakePart()); - } - - @Test - public void findAll() { - when(conferenceRepository.findAll(SORT)).thenReturn(conferences); - - assertEquals(Collections.singletonList(conferenceWithId), conferenceService.findAll()); - } - - @Test - public void create() throws IOException { - when(paperService.findPaperById(ID)).thenReturn(paperWithId); - when(paperService.create(new Paper())).thenReturn(paperWithoutId); - when(deadlineService.saveOrCreate(new ArrayList<>())).thenReturn(deadlines); - when(conferenceUserService.saveOrCreate(new ArrayList<>())).thenReturn(conferenceUsers); - when(conferenceRepository.save(new Conference())).thenReturn(conferenceWithId); - - conferenceDto.setPapers(papers); - conferenceDto.setDeadlines(deadlines); - conferenceDto.setUsers(conferenceUsers); - conferenceDto.getPaperIds().add(ID); - - Conference newConference = new Conference(); - newConference.setId(ID); - newConference.setTitle(NAME); - newConference.setDescription(DESCRIPTION); - newConference.setPapers(papers); - newConference.getPapers().add(paperWithId); - newConference.setDeadlines(deadlines); - newConference.setUsers(conferenceUsers); - - assertEquals(newConference, conferenceService.create(conferenceDto)); - } - - @Test - public void delete() { - when(conferenceRepository.existsById(ID)).thenReturn(true); - when(conferenceRepository.getOne(ID)).thenReturn(conferenceWithId); - assertTrue(conferenceService.delete(ID)); - } - - @Test - public void addDeadline() { - ConferenceDto newConferenceDto = new ConferenceDto(); - newConferenceDto.getDeadlines().add(new Deadline()); - conferenceDto.getDeadlines().clear(); - - assertEquals(newConferenceDto.getDeadlines().get(0), conferenceService.addDeadline(conferenceDto).getDeadlines().get(0)); - } - - @Test - public void removeDeadline() throws IOException { - ConferenceDto newConferenceDto = new ConferenceDto(); - newConferenceDto.getRemovedDeadlineIds().add(ID); - conferenceDto.getDeadlines().add(deadline); - ConferenceDto result = conferenceService.removeDeadline(conferenceDto, INDEX); - - assertEquals(newConferenceDto.getDeadlines(), result.getDeadlines()); - assertEquals(newConferenceDto.getRemovedDeadlineIds(), result.getRemovedDeadlineIds()); - } - - @Test - public void addPaper() { - when(userService.getCurrentUser()).thenReturn(user); - - ConferenceDto newConferenceDto = new ConferenceDto(); - newConferenceDto.getPapers().add(paperWithoutId); - conferenceDto.getPapers().clear(); - ConferenceDto result = conferenceService.addPaper(conferenceDto); - result.getPapers().get(INDEX).setTitle(NAME); // приходится вручную назначать название, т.е. название зависит от даты - - assertEquals(newConferenceDto.getPapers(), result.getPapers()); - } - - @Test - public void removePaper() throws IOException { - ConferenceDto newConferenceDto = new ConferenceDto(); - newConferenceDto.getNotSelectedPapers().add(paperWithId); - newConferenceDto.getPapers().add(paperWithoutId); - conferenceDto.getPapers().add(paperWithId); - conferenceDto.getPapers().add(paperWithoutId); - ConferenceDto result = conferenceService.removePaper(conferenceDto, INDEX); - - assertEquals(newConferenceDto.getPapers(), result.getPapers()); - assertEquals(newConferenceDto.getNotSelectedPapers(), result.getNotSelectedPapers()); - } - - @Test - public void takePart() throws IOException { - when(userService.getCurrentUser()).thenReturn(user); - - ConferenceDto newConferenceDto = new ConferenceDto(); - newConferenceDto.setUsers(conferenceUsers); - newConferenceDto.setDisabledTakePart(TRUE); - conferenceDto.getPapers().clear(); - ConferenceDto result = conferenceService.takePart(conferenceDto); - - assertEquals(newConferenceDto.getUsers(), result.getUsers()); - assertEquals(newConferenceDto.isDisabledTakePart(), result.isDisabledTakePart()); - } - - @Test - public void getAllUsers() { - List users = Collections.singletonList(user); - when(userService.findAll()).thenReturn(users); - assertEquals(users, conferenceService.getAllUsers()); - } - - @Test - public void filter() { - when(userService.findById(ID)).thenReturn(user); - when(conferenceRepository.findByUserAndYear(user, YEAR)).thenReturn(conferences); - - ConferenceFilterDto conferenceFilterDto = new ConferenceFilterDto(); - conferenceFilterDto.setFilterUserId(ID); - conferenceFilterDto.setYear(YEAR); - - assertEquals(Collections.singletonList(conferenceDto), conferenceService.filter(conferenceFilterDto)); - } - - @Test - public void isAttachedToConference() { - when(conferenceRepository.isPaperAttached(ID)).thenReturn(TRUE); - - assertTrue(conferenceService.isAttachedToConference(ID)); - } -} \ No newline at end of file diff --git a/src/test/java/ru/ulstu/grant/service/GrantServiceTest.java b/src/test/java/ru/ulstu/grant/service/GrantServiceTest.java deleted file mode 100644 index c8df288..0000000 --- a/src/test/java/ru/ulstu/grant/service/GrantServiceTest.java +++ /dev/null @@ -1,223 +0,0 @@ -package ru.ulstu.grant.service; - -import org.apache.commons.lang3.StringUtils; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.springframework.test.context.junit4.SpringRunner; -import ru.ulstu.deadline.model.Deadline; -import ru.ulstu.deadline.service.DeadlineService; -import ru.ulstu.grant.model.Grant; -import ru.ulstu.grant.model.GrantDto; -import ru.ulstu.grant.repository.GrantRepository; -import ru.ulstu.paper.model.Paper; -import ru.ulstu.paper.model.PaperDto; -import ru.ulstu.paper.service.PaperService; -import ru.ulstu.timeline.service.EventService; -import ru.ulstu.user.model.User; -import ru.ulstu.user.service.UserService; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.Date; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.stream.Collectors; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.when; - -@RunWith(SpringRunner.class) -public class GrantServiceTest { - - @Mock - GrantRepository grantRepository; - - @Mock - DeadlineService deadlineService; - - @Mock - PaperService paperService; - - @Mock - UserService userService; - - @Mock - EventService eventService; - - @Mock - GrantNotificationService grantNotificationService; - - @InjectMocks - GrantService grantService; - - private final static Integer ID = 1; - private final static Integer INDEX = 0; - private final static String TITLE = "Title"; - private final static String COMMENT = "Comment"; - private final static boolean TRUE = true; - private final static Integer YEAR = 2019; - private final static Integer MAX_DISPLAY_SIZE = 50; - - private List grants; - private List deadlines; - private List paperDtos; - private GrantDto grantDto; - private Deadline deadline; - private User leader; - - private Grant grantWithId; - - - @Before - public void setUp() throws Exception { - grants = new ArrayList<>(); - paperDtos = new ArrayList<>(); - grantWithId = new Grant(); - - deadlines = new ArrayList<>(); - deadline = new Deadline(new Date(), COMMENT); - deadline.setId(ID); - deadlines.add(deadline); - - leader = Mockito.mock(User.class); - - List papers = new ArrayList<>(); - Paper paperWithId = new Paper(); - paperWithId.setId(ID); - paperWithId.setTitle(TITLE); - papers.add(paperWithId); - PaperDto paperDto = new PaperDto(paperWithId); - paperDtos.add(paperDto); - - Set authors = new HashSet<>(); - User author = leader; - authors.add(author); - - grantWithId.setId(ID); - grantWithId.setTitle(TITLE); - grantWithId.setComment(COMMENT); - grantWithId.setDeadlines(deadlines); - grantWithId.setLeader(leader); - grantWithId.setPapers(papers); - grantWithId.setAuthors(authors); - - grants.add(grantWithId); - grantDto = new GrantDto(grantWithId); - } - - @Test - public void getExistGrantById() { - when(grantRepository.getOne(ID)).thenReturn(grantWithId); - - GrantDto newGrantDto = new GrantDto(grantWithId); - GrantDto result = grantService.getExistGrantById(ID); - - assertEquals(newGrantDto.getId(), result.getId()); - } - - @Test - public void findAll() { - when(grantRepository.findAll()).thenReturn(grants); - - assertEquals(Collections.singletonList(grantWithId), grantService.findAll()); - } - - @Test - public void create() throws IOException { - when(deadlineService.saveOrCreate(new ArrayList<>())).thenReturn(deadlines); - when(userService.getUserByLogin("admin")).thenReturn(leader); - when(grantRepository.save(new Grant())).thenReturn(grantWithId); - - Grant newGrant = new Grant(); - newGrant.setId(ID); - newGrant.setTitle(TITLE); - newGrant.setComment(COMMENT); - newGrant.setDeadlines(deadlines); - newGrant.setLeader(leader); - - assertEquals(newGrant, grantService.create(grantDto)); - } - - @Test - public void getGrantStatuses() { - assertEquals(Arrays.asList(Grant.GrantStatus.values()), grantService.getGrantStatuses()); - } - - @Test - public void getGrantPapers() { - when(paperService.findAllSelect(Collections.singletonList(ID))).thenReturn(paperDtos); - - assertEquals(paperDtos, grantService.getGrantPapers(Collections.singletonList(ID))); - } - - @Test - public void getAllUncompletedPapers() { - when(paperService.findAllNotCompleted()).thenReturn(paperDtos); - paperDtos.stream() - .forEach(paperDto -> { - paperDto.setTitle(StringUtils.abbreviate(paperDto.getTitle(), MAX_DISPLAY_SIZE)); - }); - - assertEquals(paperDtos, grantService.getAllUncompletedPapers()); - } - - @Test - public void delete() throws IOException { - when(grantRepository.getOne(ID)).thenReturn(grantWithId); - assertTrue(grantService.delete(grantWithId.getId())); - } - - @Test - public void removeDeadline() { - GrantDto newGrantDto = new GrantDto(); - newGrantDto.getRemovedDeadlineIds().add(ID); - grantDto.getDeadlines().add(deadline); - GrantDto result = grantService.removeDeadline(grantDto, INDEX); - - assertEquals(newGrantDto.getRemovedDeadlineIds(), result.getRemovedDeadlineIds()); - } - - @Test - public void findById() { - when(grantRepository.getOne(ID)).thenReturn(grantWithId); - Grant findGrant = grantService.findById(ID); - - assertEquals(grantWithId.getId(), findGrant.getId()); - } - - @Test - public void attachPaper() { - when(grantRepository.getOne(ID)).thenReturn(grantWithId); - when(paperService.findAllSelect(Collections.singletonList(ID))).thenReturn(paperDtos); - GrantDto newGrantDto = new GrantDto(grantWithId); - - if (!newGrantDto.getPaperIds().isEmpty()) { - newGrantDto.getPapers().clear(); - newGrantDto.setPapers(paperDtos); - } else { - newGrantDto.getPapers().clear(); - } - - assertEquals(newGrantDto.getPapers(), grantService.attachPaper(grantDto)); - } - - @Test - public void filterEmptyDeadlines() { - when(grantRepository.getOne(ID)).thenReturn(grantWithId); - GrantDto newGrantDto = new GrantDto(grantWithId); - - newGrantDto.setDeadlines(newGrantDto.getDeadlines().stream() - .filter(dto -> dto.getDate() != null || !StringUtils.isEmpty(dto.getDescription())) - .collect(Collectors.toList())); - - assertEquals(newGrantDto.getDeadlines(), grantService.filterEmptyDeadlines(grantDto)); - } -} \ No newline at end of file diff --git a/src/test/java/ru/ulstu/project/service/ProjectServiceTest.java b/src/test/java/ru/ulstu/project/service/ProjectServiceTest.java deleted file mode 100644 index f46971c..0000000 --- a/src/test/java/ru/ulstu/project/service/ProjectServiceTest.java +++ /dev/null @@ -1,149 +0,0 @@ -package ru.ulstu.project.service; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.springframework.test.context.junit4.SpringRunner; -import ru.ulstu.deadline.model.Deadline; -import ru.ulstu.deadline.service.DeadlineService; -import ru.ulstu.file.model.FileData; -import ru.ulstu.file.service.FileService; -import ru.ulstu.grant.model.GrantDto; -import ru.ulstu.grant.service.GrantService; -import ru.ulstu.project.model.Project; -import ru.ulstu.project.model.ProjectDto; -import ru.ulstu.project.repository.ProjectRepository; -import ru.ulstu.timeline.service.EventService; -import ru.ulstu.user.model.User; -import ru.ulstu.user.service.UserService; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Date; -import java.util.List; - -import static junit.framework.TestCase.assertTrue; -import static org.junit.Assert.assertEquals; -import static org.mockito.Mockito.when; - -@RunWith(SpringRunner.class) -public class ProjectServiceTest { - - @Mock - ProjectRepository projectRepository; - - @Mock - DeadlineService deadlineService; - - @Mock - EventService eventService; - - @Mock - FileService fileService; - - @Mock - UserService userService; - - @Mock - GrantService grantService; - - @InjectMocks - ProjectService projectService; - - private final static String TITLE = "title"; - private final static String DESCR = "descr"; - private final static Integer ID = 1; - private final static Integer INDEX = 0; - private final static String NAME = "name"; - - private List projects; - private Project project; - private ProjectDto projectDto; - private Deadline deadline; - private List deadlines; - private FileData file; - private List files; - private User user; - - @Before - public void setUp() throws Exception { - projects = new ArrayList<>(); - project = new Project(); - - projects.add(project); - projectDto = new ProjectDto(project); - - deadlines = new ArrayList<>(); - deadline = new Deadline(new Date(), DESCR); - deadline.setId(ID); - deadlines.add(deadline); - - user = new User(); - user.setFirstName(NAME); - - List grants = new ArrayList<>(); - GrantDto grant = new GrantDto(); - grant.setId(ID); - grants.add(grant); - } - - @Test - public void findAll() { - when(projectRepository.findAll()).thenReturn(projects); - assertEquals(projects, projectService.findAll()); - } - - @Test - public void create() throws IOException { - when(deadlineService.saveOrCreate(new ArrayList<>())).thenReturn(deadlines); - when(projectRepository.save(new Project())).thenReturn(project); - eventService.createFromObject(new Project(), Collections.emptyList(), false, "проекта"); - - projectDto.setTitle(TITLE); - projectDto.setDeadlines(deadlines); - - project.setId(ID); - project.setTitle(TITLE); - project.setDescription(DESCR); - project.setDeadlines(deadlines); - project.setFiles(files); - - assertEquals(project.getId(), (projectService.create(projectDto)).getId()); - } - - @Test - public void delete() throws IOException { - when(projectRepository.existsById(ID)).thenReturn(true); - when(projectRepository.getOne(ID)).thenReturn(project); - - assertTrue(projectService.delete(ID)); - } - - @Test - public void getProjectExecutors() { - List executors = Collections.singletonList(user); - when(userService.findAll()).thenReturn(executors); - - assertEquals(executors, projectService.getProjectExecutors(projectDto)); - } - - @Test - public void findById() { - when(projectRepository.getOne(ID)).thenReturn(project); - assertEquals(project, projectService.findById(ID)); - } - - @Test - public void removeDeadline() throws IOException { - ProjectDto newProjectDto = new ProjectDto(); - newProjectDto.getRemovedDeadlineIds().add(INDEX); - projectDto.getDeadlines().add(deadline); - ProjectDto result = projectService.removeDeadline(projectDto, INDEX); - - assertEquals(newProjectDto.getDeadlines(), result.getDeadlines()); - assertEquals(newProjectDto.getRemovedDeadlineIds(), result.getRemovedDeadlineIds()); - } -} \ No newline at end of file diff --git a/src/test/java/ru/ulstu/students/service/TaskServiceTest.java b/src/test/java/ru/ulstu/students/service/TaskServiceTest.java deleted file mode 100644 index 97b9990..0000000 --- a/src/test/java/ru/ulstu/students/service/TaskServiceTest.java +++ /dev/null @@ -1,215 +0,0 @@ -package ru.ulstu.students.service; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.springframework.data.domain.Sort; -import org.springframework.test.context.junit4.SpringRunner; -import ru.ulstu.core.util.DateUtils; -import ru.ulstu.deadline.model.Deadline; -import ru.ulstu.deadline.service.DeadlineService; -import ru.ulstu.students.model.Scheduler; -import ru.ulstu.students.model.Task; -import ru.ulstu.students.model.TaskDto; -import ru.ulstu.students.model.TaskFilterDto; -import ru.ulstu.students.repository.SchedulerRepository; -import ru.ulstu.students.repository.TaskRepository; -import ru.ulstu.tags.model.Tag; -import ru.ulstu.tags.service.TagService; -import ru.ulstu.timeline.service.EventService; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.Date; -import java.util.HashSet; -import java.util.List; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.when; - -@RunWith(SpringRunner.class) -public class TaskServiceTest { - - @Mock - TaskRepository taskRepository; - - @Mock - SchedulerRepository schedulerRepository; - - @Mock - private TagService tagService; - - @Mock - DeadlineService deadlineService; - - @Mock - EventService eventService; - - @InjectMocks - TaskService taskService; - - private final static Sort SORT = new Sort(Sort.Direction.DESC, "createDate"); - private final static Integer ID = 1; - private final static Task.TaskStatus STATUS = Task.TaskStatus.IN_WORK; - private final static String TITLE = "title"; - private final static String DESCR = "descr"; - private final static String TAG = "tag"; - private final static Date YEAR = DateUtils.clearTime(DateUtils.addYears(new Date(), 0)); - - private List tasks; - private List tags; - private Task task; - private Task taskForSchedule; - private TaskDto taskDto; - private Tag tag; - private Deadline deadline; - private List deadlines; - private Scheduler scheduler; - - - @Before - public void setUp() throws Exception { - - tasks = new ArrayList<>(); - task = new Task(); - - task.setId(ID); - task.setTitle(TITLE); - task.setDescription(DESCR); - - - tag = new Tag(); - tag.setId(ID); - tag.setTagName(TAG); - - deadlines = new ArrayList<>(); - deadline = new Deadline(new Date(), DESCR); - deadline.setId(ID); - deadlines.add(deadline); - - task.setDeadlines(deadlines); - - tags = new ArrayList<>(); - tags.add(tag); - - tasks.add(task); - taskDto = new TaskDto(task); - - taskForSchedule = new Task(); - taskForSchedule.setTitle(TITLE); - taskForSchedule.setDescription(DESCR); - - scheduler = new Scheduler(); - scheduler.setDate(new Date()); - scheduler.setTask(taskForSchedule); - - - } - - @Test - public void findAll() { - when(taskRepository.findAll(SORT)).thenReturn(tasks); - assertEquals(Collections.singletonList(task), taskService.findAll()); - } - - @Test - public void filter() { - when(tagService.findById(ID)).thenReturn(tag); - when(taskRepository.filterNew(STATUS, tag)).thenReturn(tasks); - - TaskFilterDto taskFilterDto = new TaskFilterDto(); - taskFilterDto.setTag(ID); - taskFilterDto.setOrder("new"); - taskFilterDto.setStatus(STATUS); - - assertEquals(Collections.singletonList(taskDto), taskService.filter(taskFilterDto)); - } - - @Test - public void create() throws IOException { - when(tagService.saveOrCreate(new ArrayList<>())).thenReturn(tags); - when(deadlineService.saveOrCreate(new ArrayList<>())).thenReturn(deadlines); - when(taskRepository.save(new Task())).thenReturn(task); - eventService.createFromObject(new Task(), Collections.emptyList(), true, "задачи"); - - taskDto.setTags(tags); - taskDto.setDeadlines(deadlines); - - Task newTask = new Task(); - task.setId(ID); - task.setTitle(TITLE); - task.setDescription(DESCR); - task.setTags(tags); - task.setDeadlines(deadlines); - - assertEquals(task.getId(), taskService.create(taskDto)); - } - - @Test - public void delete() throws IOException { - when(taskRepository.existsById(ID)).thenReturn(true); - when(taskRepository.getOne(ID)).thenReturn(task); - when(schedulerRepository.findOneByTask(task)).thenReturn(null); - - assertTrue(taskService.delete(ID)); - } - - @Test - public void generateYearTasks() { - when(tagService.getTags()).thenReturn(tags); - tasks.get(0).setTags(tags); - when(taskRepository.findAllYear(DateUtils.clearTime(DateUtils.addYears(new Date(), -1)))).thenReturn(tasks); - tasks.get(0).setCreateDate(DateUtils.clearTime(DateUtils.addYears(new Date(), -1))); - when(taskRepository.findByTag(tag)).thenReturn(tasks); - - Task newTask = new Task(); - newTask.setTitle(tasks.get(0).getTitle()); - newTask.setTags(tasks.get(0).getTags()); - newTask.setCreateDate(new Date()); - newTask.setStatus(Task.TaskStatus.LOADED_FROM_KIAS); - - Deadline newDeadline = new Deadline(); - newDeadline.setId(ID); - newDeadline.setDescription(deadline.getDescription()); - newDeadline.setDate(DateUtils.addYears(deadline.getDate(), 1)); - when(deadlineService.create(newDeadline)).thenReturn(newDeadline); - newTask.setDeadlines(Arrays.asList(newDeadline)); - - when(taskRepository.save(newTask)).thenReturn(task); - - assertEquals(Arrays.asList(task), taskService.generateYearTasks()); - } - - @Test - public void checkRepeatingTags() { - when(tagService.getTags()).thenReturn(tags); - tasks.get(0).setTags(tags); - when(taskRepository.findAllYear(DateUtils.clearTime(DateUtils.addYears(new Date(), -1)))).thenReturn(tasks); - - assertEquals(new HashSet(Arrays.asList(tag)), taskService.checkRepeatingTags(false)); - } - - @Test - public void createPeriodTask() { - Task newTask = new Task(); - newTask.setTitle(scheduler.getTask().getTitle()); - newTask.setTags(scheduler.getTask().getTags()); - newTask.setCreateDate(new Date()); - - Deadline newDeadline = new Deadline(); - newDeadline.setId(ID); - newDeadline.setDescription(deadline.getDescription()); - newDeadline.setDate(DateUtils.addYears(deadline.getDate(), 1)); - when(deadlineService.create(newDeadline)).thenReturn(newDeadline); - newTask.setDeadlines(Arrays.asList(newDeadline)); - - when(taskRepository.save(newTask)).thenReturn(taskForSchedule); - - assertEquals(taskForSchedule, taskService.createPeriodTask(scheduler)); - } -} \ No newline at end of file diff --git a/src/test/java/students/TaskPage.java b/src/test/java/students/TaskPage.java deleted file mode 100644 index e6a1e0d..0000000 --- a/src/test/java/students/TaskPage.java +++ /dev/null @@ -1,81 +0,0 @@ -package students; - -import core.PageObject; -import org.openqa.selenium.By; -import org.openqa.selenium.Keys; -import org.openqa.selenium.WebElement; - -import java.util.List; - -public class TaskPage extends PageObject { - - @Override - public String getSubTitle() { - return driver.findElement(By.tagName("h3")).getText(); - } - - public void setName(String name) { - driver.findElement(By.id("title")).sendKeys(name); - } - - public void save() { - driver.findElement(By.id("sendMessageButton")).click(); - } - - public void addDeadlineDate(String deadDate, Integer deadNum) { - driver.findElement(By.id(String.format("deadlines%d.date", deadNum))).sendKeys(deadDate); - } - - public void addDeadlineDescription(String deadDescr, Integer deadNum) { - driver.findElement(By.id(String.format("deadlines%d.description", deadNum))).sendKeys(deadDescr); - } - - public void removeName() { - driver.findElement(By.id("title")).clear(); - } - - public String getId() { - return driver.findElement(By.id("id")).getAttribute("value"); - } - - public Integer getDeadNum() { - return driver.findElements(By.cssSelector("#task-form .form-group:nth-of-type(5) .row")).size(); - } - - public void clickAddDeadline() { - driver.findElement(By.cssSelector("#addDeadline")).click(); - } - - private List getDeadlines() { - return driver.findElements(By.cssSelector(".form-group:nth-of-type(5) .row")); - } - - public void deleteDeadline() { - driver.findElement(By.xpath("//*[@id=\"task-form\"]/div/div[1]/div[5]/div[1]/div[3]/a")).click(); - - } - - public void clearDeadlineDate(Integer deadNum) { - driver.findElement(By.id(String.format("deadlines%d.date", deadNum))).sendKeys(Keys.DELETE); - } - - public void clearDeadlineDescription(Integer deadNum) { - driver.findElement(By.id(String.format("deadlines%d.description", deadNum))).clear(); - } - - public boolean hasDeadline(String deadDescr, String deadValue) { - return getDeadlines() - .stream() - .anyMatch(webElement -> { - return webElement.findElement(By.cssSelector("input[type=\"text\"]")).getAttribute("value").equals(deadDescr) - && webElement.findElement(By.cssSelector("input[type=\"date\"]")).getAttribute("value").equals(deadValue); - }); - } - - public void setTag(String tag) { - driver.findElement(By.className("input-tag-name")).sendKeys(tag); - driver.findElement(By.className("input-tag-name")).sendKeys(Keys.ENTER); - } - - -} diff --git a/src/test/java/students/TasksDashboardPage.java b/src/test/java/students/TasksDashboardPage.java deleted file mode 100644 index 8cc6eda..0000000 --- a/src/test/java/students/TasksDashboardPage.java +++ /dev/null @@ -1,10 +0,0 @@ -package students; - -import core.PageObject; - -public class TasksDashboardPage extends PageObject { - @Override - public String getSubTitle() { - return null; - } -} diff --git a/src/test/java/students/TasksPage.java b/src/test/java/students/TasksPage.java deleted file mode 100644 index 9769cca..0000000 --- a/src/test/java/students/TasksPage.java +++ /dev/null @@ -1,75 +0,0 @@ -package students; - -import core.PageObject; -import org.openqa.selenium.By; -import org.openqa.selenium.WebElement; - -import java.util.List; - -public class TasksPage extends PageObject { - - @Override - public String getSubTitle() { - return driver.findElement(By.tagName("h3")).getText(); - } - - public List getTasks() { - return driver.findElements(By.cssSelector("span.h6")); - } - - private List getTaskRows() { - return driver.findElements(By.className("task-row")); - } - - public void goToFirstTask() { - driver.findElement(By.xpath("//*[@id=\"tasks\"]/div/div[2]/div[1]/div/div/a[1]")).click(); - } - - public boolean findTask(String taskName) { - return getTasks().stream() - .anyMatch(webElement -> webElement.getText().equals(taskName)); - - } - - public void deleteFirstTask() { - js.executeScript("$('a[data-confirm]').click();"); - } - - public void submit() { - driver.findElement(By.xpath("//*[@id=\"dataConfirmOK\"]")).click(); - } - - public boolean findTag(String tag) { - driver.findElements(By.className("bootstrap-select")).get(2).findElement(By.className("btn")).click(); - driver.findElement(By.cssSelector(".bs-searchbox input")).sendKeys(tag); - return driver.findElement(By.xpath("//*[@id=\"tasks\"]/div/div[2]/div[2]/div[2]/div[2]/div/div[2]/ul")).findElement(By.className("text")).getText().equals(tag); - } - - public boolean findTaskByTag(String name, String tag) { - return getTasks().stream() - .anyMatch(webElement -> webElement.getText().equals(name) - && webElement.findElement(By.xpath("//*[@id=\"tasks\"]/div/div[2]/div[1]/div/div/a[1]/span[3]")).getText().equals(tag)); - } - - public boolean findTasksByTag(String tag) { - return getTaskRows().stream() - .allMatch(webElement -> webElement.findElement(By.cssSelector("span.text-muted")).getText().equals(tag)); - } - - public void selectTag(String tag) { - driver.findElements(By.className("bootstrap-select")).get(2).findElement(By.className("btn")).click(); - driver.findElement(By.cssSelector(".bs-searchbox input")).sendKeys(tag); - driver.findElement(By.xpath("//*[@id=\"tasks\"]/div/div[2]/div[2]/div[2]/div[2]/div/div[2]/ul/li/a")).click(); - } - - - public void selectStatus() { - driver.findElements(By.className("bootstrap-select")).get(1).findElement(By.className("btn")).click(); - driver.findElement(By.xpath("//*[@id=\"tasks\"]/div/div[2]/div[2]/div[2]/div[1]/div/div/ul/li[2]/a")).click(); - } - - public boolean findAllStatus() { - return getTaskRows().stream() - .allMatch(webElement -> webElement.findElement(By.cssSelector("div i.text-primary")).isDisplayed()); - } -}