@Transactional(propagation = Propagation.REQUIRES_NEW) private void populateDatabaseIfNeeded() { StandardPasswordEncoder spe = new StandardPasswordEncoder(); if (!AppUser.findAllAppUsers().isEmpty()) { // don't do anything if there is data in the db return; } AppUser user = new AppUser(); user.setUsername("user"); user.setFullName("John Q Public"); user.setPassword("user"); user.setEMail("*****@*****.**"); user.persist(); user = new AppUser(); user.setUsername("admin"); user.setFullName("Admin"); user.setPassword("admin"); user.setEMail("*****@*****.**"); user.persist(); Subject subject = new Subject(); subject.setCode("MTAT.03.230"); subject.setName("Veebirakenduste loomine"); subject.setOwner(user); subject.persist(); }
void populateEditForm(Model uiModel, UsedTime usedTime) { uiModel.addAttribute("usedTime", usedTime); addDateTimeFormatPatterns(uiModel); uiModel.addAttribute("appusers", AppUser.findAllAppUsers()); if (SecurityUtils.getLoggedInUser().isAdmin()) { uiModel.addAttribute("subjects", Subject.findAllSubjects()); } else { uiModel.addAttribute( "subjects", Subject.findSubjectsByOwner(SecurityUtils.getLoggedInUser()).getResultList()); } }