Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Package Name Edit #53

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/main/java/com/health/config/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public static BCryptPasswordEncoder passwordEncoder() {
"/addPreRequisticWhenNotRequired/**", "/addPreRequistic/**", "/addVideo/**", "/addSlide/**",
"/addScript/**", "/listTutorialForContributorReview/**", "/Contributor/review/**", "/uploadTimescript/**",
"/addLiveTutorial", "/updateLiveTutorial", "/addSpokenVideo", "/spokenVideo/edit/**", "/addVideoResource",
"/createPackage",
"/createPackage", "/packageName/edit/**", "/updatePackageName",

};

Expand Down Expand Up @@ -149,9 +149,9 @@ protected void configure(HttpSecurity http) throws Exception {
.antMatchers("/addBrochure/**", "/addCarousel/**", "/addConsultant/**", "/addEvent/**",
"/addTestimonial/**", "/addPromoVideo/**", "/addResearchPaper/**", "/brochure/edit/**",
"/promoVideo/edit/**", "/carousel/edit/**", "/event/edit/**", "/testimonial/edit/**",

"/researchPaper/edit/**", "/enableDisableBrouchure/**", "/enableDisableConsultant/**",
"/enableDisableTestimonial/**", "/addCitation/**", "/citation/edit/**")
"/createPackage", "/packageName/edit/**", "/updatePackageName", "/researchPaper/edit/**",
"/enableDisableBrouchure/**", "/enableDisableConsultant/**", "/enableDisableTestimonial/**",
"/addCitation/**", "/citation/edit/**")
.hasAnyAuthority("SUPER_USER", "CONTRIBUTOR").antMatchers(PUBLIC_MATCHERS).permitAll().anyRequest()
.authenticated().and().exceptionHandling().accessDeniedPage("/access-denied");

Expand Down
33 changes: 5 additions & 28 deletions src/main/java/com/health/controller/AjaxController.java
Original file line number Diff line number Diff line change
Expand Up @@ -589,46 +589,23 @@ private HashMap<String, String> setResponse(Integer status) {

}

@GetMapping("/enableDisablePacakgeAndPackLan")
@GetMapping("/enableDisablePacakgeLanguage")
public @ResponseBody boolean enableDisablePacakgeAndPackLan(int packLanId) {
PackageLanguage packLan = packLanService.findBypackageLanId(packLanId);

try {
if (packLan.isStatus()) {
packLan.setStatus(false);
packLanService.save(packLan);
return true;

} else {
packLan.setStatus(true);
packLanService.save(packLan);
return true;

}

PackageContainer packContainer = packLan.getPackageContainer();
Set<PackageLanguage> packLanList = packContainer.getPackageLanguages();

boolean flag = false;

for (PackageLanguage temp : packLanList) {
if (temp.getPackageLanId() == packLan.getPackageLanId()) {
if (packLan.isStatus()) {
flag = true;
}
} else if (temp.isStatus()) {
flag = true;
}
}

if (flag) {
packContainer.setStatus(true);
} else {
packContainer.setStatus(false);
}

packageContainerService.save(packContainer);

return true;

} catch (Exception e) {

logger.error("Error in Enable Disbale PacakgeAndPackLan: {}", packLan, e);
Expand Down Expand Up @@ -1066,12 +1043,12 @@ private HashMap<String, String> setResponse(Integer status) {
PackageContainer packageContainer = packageContainerService.findByPackageId(packageId);
List<Language> languages = new ArrayList<>();
if (packageContainer != null) {
languages = packLanService.findAllLanguagesByPackageContainer(packageContainer);
languages = packLanService.findAllEnabledLanguagesByPackageContainer(packageContainer);
}

if (languages.size() > 0) {
for (Language lan : languages) {
logger.info("lan:{}", lan.getLangName());

langName.put(lan.getLanId(), lan.getLangName());

}
Expand Down
102 changes: 91 additions & 11 deletions src/main/java/com/health/controller/HomeController.java
Original file line number Diff line number Diff line change
Expand Up @@ -4477,7 +4477,7 @@ public String createPackageGet(HttpServletRequest req, Principal principal, Mode
public String createPackagePost(HttpServletRequest req, Model model, Principal principal,
@RequestParam(name = "packageContainerId") int packageContainerId,
@RequestParam(name = "packageName") String packageName, @RequestParam(name = "languageId") int languageId,
@RequestParam(name = "tutorialforPackage") int[] tutorialIds,
@RequestParam(name = "tutorialforPackage") Optional<int[]> tutorialIds,
@RequestParam("weekName") List<Integer> weekIds, @RequestParam(name = "videoName") List<Integer> videoIds,
@RequestParam(name = "title") List<String> titles) {

Expand Down Expand Up @@ -4531,9 +4531,7 @@ public String createPackagePost(HttpServletRequest req, Model model, Principal p
List<TutorialWithWeekAndPackage> tutorialWithWeekAndPackages = new ArrayList<>();

try {
logger.info("WeekIds Size:{} ", weekIds.size());
logger.info("VideoIds Size:{}", videoIds.size());
logger.info("Title Size:{}", titles.size());

for (int i = 0; i < weekIds.size(); i++) {
if (i < titles.size())
logger.info("Title: {}", titles.get(i));
Expand All @@ -4546,6 +4544,7 @@ public String createPackagePost(HttpServletRequest req, Model model, Principal p

if (weekTitleVideo == null) {
weekTitleVideo = new WeekTitleVideo(titles.get(i), dateAdded, week, video);
weekTitleVideo.setUser(usr);

weekTitleVideoService.save(weekTitleVideo); // Save the weekTitle before using it
// weekTitles.add(weekTitle);
Expand All @@ -4564,15 +4563,22 @@ public String createPackagePost(HttpServletRequest req, Model model, Principal p

}
}
// weekTitleVideoService.saveAll(weekTitles);
// tutorialWithWeekAndPackageService.saveAll(tutorialWithWeekAndPackages);

List<PackLanTutorialResource> packLanTutorialResourceList = new ArrayList<>();
for (int j = 0; j < tutorialIds.length; j++) {
Tutorial tutorial = tutService.findByTutorialId(tutorialIds[j]);
PackLanTutorialResource temp = new PackLanTutorialResource(dateAdded, tutorial, packageLanguage);
if (tutorialIds != null && tutorialIds.isPresent() && tutorialIds.get().length > 0) {
for (int j = 0; j < tutorialIds.get().length; j++) {
Tutorial tutorial = tutService.findByTutorialId(tutorialIds.get()[j]);
List<PackLanTutorialResource> existingTutorials = packLanTutorialResourceService
.findResourcesByTutorialAndPackageLanguage(tutorial, packageLanguage);

if (existingTutorials == null || existingTutorials.size() < 1) {
PackLanTutorialResource temp = new PackLanTutorialResource(dateAdded, tutorial,
packageLanguage);

packLanTutorialResourceList.add(temp);
}

packLanTutorialResourceList.add(temp);
}
}

if (packLanTutorialResourceList.size() > 0)
Expand All @@ -4590,6 +4596,68 @@ public String createPackagePost(HttpServletRequest req, Model model, Principal p
return createPackageGet(req, principal, model);
}

@GetMapping("/packageName/edit/{id}")
public String editPackageNameGet(@PathVariable int id, HttpServletRequest req, Model model, Principal principal) {

User usr = getUser(principal);
logger.info("{} {} {}", usr.getUsername(), req.getMethod(), req.getRequestURI());
model.addAttribute("userInfo", usr);

PackageContainer packageContainer = packageContainerService.findByPackageId(id);

if (packageContainer == null) {

return "redirect:/createPackage";
}

model.addAttribute("packageContainer", packageContainer);

return "updatePackageName";
}

@PostMapping("/updatePackageName")
public String updatePackageNamePost(HttpServletRequest req, Model model, Principal principal) {

User usr = getUser(principal);
logger.info("{} {} {}", usr.getUsername(), req.getMethod(), req.getRequestURI());

model.addAttribute("userInfo", usr);

String packageId = req.getParameter("packageId");
String packageName = req.getParameter("packageName");

PackageContainer packageContainer = packageContainerService.findByPackageId(Integer.parseInt(packageId));

model.addAttribute("packageContainer", packageContainer);
if (packageContainer == null) {
model.addAttribute("error_msg", "Package doesn't exist");
return "updatePackageName";
}

try {
List<PackageLanguage> packagelanguageList = new ArrayList<>(packageContainer.getPackageLanguages());
for (PackageLanguage temp : packagelanguageList) {
String langName = temp.getLan().getLangName();
zipCreationThreadService.deleteKeyFromZipNamesAndPackageAndLanZipIfExists(
packageContainer.getPackageName(), langName, env);
}

packageContainer.setPackageName(packageName);
packageContainerService.save(packageContainer);

} catch (Exception e) {

model.addAttribute("error_msg", CommonData.RECORD_ERROR);
model.addAttribute("packageContainer", packageContainer);
return "updatePackageName";
}

model.addAttribute("success_msg", CommonData.RECORD_UPDATE_SUCCESS_MSG);
model.addAttribute("packageContainer", packageContainer);

return "updatePackageName";
}

/******************************************
* Assign Tutorial on Week And Package End
********************/
Expand Down Expand Up @@ -4629,6 +4697,8 @@ public String hstTrainingModules(@RequestParam(name = "week", required = false,
weekTitleVideoList.sort(Comparator
.comparingInt((WeekTitleVideo wtv) -> ServiceUtility.extractInteger(wtv.getWeek().getWeekName()))
.thenComparing(wtv -> wtv.getVideoResource().getLan().getLangName())
.thenComparing(Comparator.comparing((WeekTitleVideo wtv) -> wtv.getVideoResource().getSessionName(),
Comparator.nullsLast(Comparator.naturalOrder())))
.thenComparing(WeekTitleVideo::getTitle));

model.addAttribute("userInfo", usr);
Expand Down Expand Up @@ -4669,8 +4739,18 @@ public String hstTrainingModuleView(@PathVariable(name = "weekTitleVideoId") int

}

if (relatedweekTitleVideoList != null && relatedweekTitleVideoList.size() > 0)
if (relatedweekTitleVideoList != null && relatedweekTitleVideoList.size() > 0) {
relatedweekTitleVideoList.sort(Comparator
.comparingInt(
(WeekTitleVideo wtv) -> ServiceUtility.extractInteger(wtv.getWeek().getWeekName()))
.thenComparing(
Comparator.comparing((WeekTitleVideo wtv) -> wtv.getVideoResource().getSessionName(),
Comparator.nullsLast(Comparator.naturalOrder())))
.thenComparing(WeekTitleVideo::getTitle));

model.addAttribute("relatedweekTitleVideoList", relatedweekTitleVideoList);
}

model.addAttribute("weekTitleVideo", weekTitleVideo);
}
model.addAttribute("foundVideo", foundVideo);
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/com/health/model/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,10 @@ public void setOrgRolev(OrganizationRole orgRolev) {
@JsonIgnore
private Set<SpokenVideo> spokenvideos = new HashSet<SpokenVideo>();

@OneToMany(mappedBy = "user", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@JsonIgnore
private Set<WeekTitleVideo> weekTitleVideos = new HashSet<WeekTitleVideo>();

@OneToMany(mappedBy = "user", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@JsonIgnore
private Set<Topic> topics = new HashSet<Topic>();
Expand Down Expand Up @@ -260,6 +264,14 @@ public void setSpokenvideos(Set<SpokenVideo> spokenvideos) {
this.spokenvideos = spokenvideos;
}

public Set<WeekTitleVideo> getWeekTitleVideos() {
return weekTitleVideos;
}

public void setWeekTitleVideos(Set<WeekTitleVideo> weekTitleVideos) {
this.weekTitleVideos = weekTitleVideos;
}

@Override
public String getPassword() {
return password;
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/com/health/model/VideoResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ public class VideoResource implements Serializable {
@Column(name = "file_name", nullable = false)
private String fileName;

@Column(name = "session_name")
private String SessionName;

@Column(name = "video_path", nullable = false, unique = true)
private String videoPath;

Expand Down Expand Up @@ -84,6 +87,14 @@ public Language getLan() {
return lan;
}

public String getSessionName() {
return SessionName;
}

public void setSessionName(String sessionName) {
SessionName = sessionName;
}

public void setLan(Language lan) {
this.lan = lan;
}
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/com/health/model/WeekTitleVideo.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ public class WeekTitleVideo implements Serializable {
@JoinColumn(name = "week_id", nullable = false)
private Week week;

@ManyToOne
@JoinColumn(name = "user_id", nullable = false)
private User user;

@ManyToOne
@JoinColumn(name = "video_resource_id", nullable = false)
private VideoResource videoResource;
Expand Down Expand Up @@ -123,6 +127,14 @@ public WeekTitleVideo() {

}

public User getUser() {
return user;
}

public void setUser(User user) {
this.user = user;
}

public Set<TutorialWithWeekAndPackage> getTutorialsWithWeekAndPack() {
return tutorialsWithWeekAndPack;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ PackLanTutorialResource findByPackageLanguageAndTutorial(@Param("packageLanguage
@Query("SELECT ptr FROM PackLanTutorialResource ptr WHERE ptr.packageLanguage = :packageLanguage")
List<PackLanTutorialResource> findByPackageLanguage(@Param("packageLanguage") PackageLanguage packageLanguage);

List<PackLanTutorialResource> findByTutorialAndPackageLanguage(Tutorial tutorial, PackageLanguage packageLanguage);

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,13 @@ PackageLanguage findByPackageContainerAndLan(@Param("packageContainer") PackageC
@Query("SELECT DISTINCT pl.packageContainer FROM PackageLanguage pl")
List<PackageContainer> findAllDistinctPackageContainers();

@Query("SELECT DISTINCT pl.packageContainer FROM PackageLanguage pl where pl.packageContainer.status=:value")
@Query("SELECT DISTINCT pl.packageContainer FROM PackageLanguage pl where pl.status=:value")
List<PackageContainer> findAllDistinctPackageContainersByStatus(boolean value);

@Query("SELECT pl.lan FROM PackageLanguage pl WHERE pl.packageContainer = :packageContainer AND pl.status = true")
List<Language> findAllEnabledLanguagesByPackageContainer(
@Param("packageContainer") PackageContainer packageContainer);

List<PackageLanguage> findAllByStatus(boolean value);

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,7 @@ public interface PackLanTutorialResourceService {

void saveAll(List<PackLanTutorialResource> packLanTutorialResourceList);

List<PackLanTutorialResource> findResourcesByTutorialAndPackageLanguage(Tutorial tutorial,
PackageLanguage packageLanguage);

}
2 changes: 2 additions & 0 deletions src/main/java/com/health/service/PackageLanguageService.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ public interface PackageLanguageService {

List<PackageLanguage> findAllByStatus(boolean value);

List<Language> findAllEnabledLanguagesByPackageContainer(PackageContainer packageContainer);

}
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,10 @@ public List<PackageContainer> findAllDistinctEnabledPackageContainers() {
return packageList;
}

@Override
public List<Language> findAllEnabledLanguagesByPackageContainer(PackageContainer packageContainer) {

return repo.findAllEnabledLanguagesByPackageContainer(packageContainer);
}

}
Loading