diff --git a/cd_waste_docs/cdwaste_aadhar/10_bird.jpg b/cd_waste_docs/cdwaste_aadhar/10_bird.jpg new file mode 100644 index 0000000..82d0eb5 Binary files /dev/null and b/cd_waste_docs/cdwaste_aadhar/10_bird.jpg differ diff --git a/cd_waste_docs/cdwaste_aadhar/9_duck-7406987.jpg b/cd_waste_docs/cdwaste_aadhar/9_duck-7406987.jpg new file mode 100644 index 0000000..84ff232 Binary files /dev/null and b/cd_waste_docs/cdwaste_aadhar/9_duck-7406987.jpg differ diff --git a/cd_waste_docs/cdwaste_rcbookdoc/10_joban-khangura-hG8B9pKiilw-unsplash.jpg b/cd_waste_docs/cdwaste_rcbookdoc/10_joban-khangura-hG8B9pKiilw-unsplash.jpg new file mode 100644 index 0000000..755d359 Binary files /dev/null and b/cd_waste_docs/cdwaste_rcbookdoc/10_joban-khangura-hG8B9pKiilw-unsplash.jpg differ diff --git a/cd_waste_docs/cdwaste_rcbookdoc/9_bird.jpg b/cd_waste_docs/cdwaste_rcbookdoc/9_bird.jpg new file mode 100644 index 0000000..82d0eb5 Binary files /dev/null and b/cd_waste_docs/cdwaste_rcbookdoc/9_bird.jpg differ diff --git a/cd_waste_docs/cdwaste_userphoto/10_duck-7406987.jpg b/cd_waste_docs/cdwaste_userphoto/10_duck-7406987.jpg new file mode 100644 index 0000000..84ff232 Binary files /dev/null and b/cd_waste_docs/cdwaste_userphoto/10_duck-7406987.jpg differ diff --git a/cd_waste_docs/cdwaste_userphoto/9_duck-7406987.jpg b/cd_waste_docs/cdwaste_userphoto/9_duck-7406987.jpg new file mode 100644 index 0000000..84ff232 Binary files /dev/null and b/cd_waste_docs/cdwaste_userphoto/9_duck-7406987.jpg differ diff --git a/src/main/java/com/volunteersregistration/controller/ApiController.java b/src/main/java/com/volunteersregistration/controller/ApiController.java index 158ba34..1a92ac9 100644 --- a/src/main/java/com/volunteersregistration/controller/ApiController.java +++ b/src/main/java/com/volunteersregistration/controller/ApiController.java @@ -84,7 +84,7 @@ public class ApiController { System.out.print("\n otp---:"+otp); DateTimeFormatter dtf = DateTimeFormatter.ofPattern("dd-MMM-yyyy%20HH:mm"); LocalDateTime now = LocalDateTime.now(); - System.out.println(dtf.format(now)); + System.out.println("\n"+dtf.format(now)); // String generatedToken = "OTP for Volunteer "; // String key="qxg4mklD"; @@ -161,5 +161,15 @@ public class ApiController { public List> getSubCategoryById(@RequestParam int category_id) { return volunteerRegistrationRepo.getSubCategoryById(category_id); } + + @GetMapping(value = "/getAllExpertise") + public List> getAllExpertise() { + return volunteerRegistrationRepo.getAllExpertise(); + } + + @GetMapping(value = "/getAllVolunteerDocs") + public List> getAllVolunteerDocs() { + return volunteerRegistrationRepo.getAllVolunteerDocs(); + } } \ No newline at end of file diff --git a/src/main/java/com/volunteersregistration/controller/VolunteerController.java b/src/main/java/com/volunteersregistration/controller/VolunteerController.java index 5647e5b..6159c4c 100644 --- a/src/main/java/com/volunteersregistration/controller/VolunteerController.java +++ b/src/main/java/com/volunteersregistration/controller/VolunteerController.java @@ -44,8 +44,8 @@ public class VolunteerController { model.addAttribute("ref", ref); - //return "webindex"; - return "coming_soon"; + return "webindex"; + //return "coming_soon"; } @GetMapping("/webtamil") @@ -54,8 +54,8 @@ public class VolunteerController { model.addAttribute("ref", ref); - //return "webindex_tamil"; - return "coming_soon"; + return "webindex_tamil"; + //return "coming_soon"; } @GetMapping(value = { "/", "", "/index" }) @@ -64,8 +64,8 @@ public class VolunteerController { model.addAttribute("ref", ref); - //return "index"; - return "coming_soon"; + return "index"; + //return "coming_soon"; } @GetMapping(value = {"/index_tamil" }) @@ -74,10 +74,35 @@ public class VolunteerController { model.addAttribute("ref", ref); - //return "index_tamil"; - return "coming_soon"; + return "index_tamil"; + //return "coming_soon"; } + + //testing urls + + @GetMapping("/devtest") + public String MobileViewdevtest(@RequestParam(required = false) String ref, Model model) { + System.out.println("indesx page....." + ref); + model.addAttribute("ref", ref); + + + return "index"; + //return "coming_soon"; + } + + @GetMapping("/devtestweb") + public String MobileViewdevtestweb(@RequestParam(required = false) String ref, Model model) { + System.out.println("indesx page....." + ref); + model.addAttribute("ref", ref); + + + return "webindex"; + //return "coming_soon"; + } + + // + // Check session and redirect to login if user is not logged in diff --git a/src/main/java/com/volunteersregistration/controller/VolunteerRegistrationController.java b/src/main/java/com/volunteersregistration/controller/VolunteerRegistrationController.java index 73dba6c..069a2f3 100644 --- a/src/main/java/com/volunteersregistration/controller/VolunteerRegistrationController.java +++ b/src/main/java/com/volunteersregistration/controller/VolunteerRegistrationController.java @@ -1,38 +1,174 @@ package com.volunteersregistration.controller; +import com.fasterxml.jackson.databind.ObjectMapper; import com.volunteersregistration.entity.CorporateInformation; import com.volunteersregistration.entity.NgoInformation; import com.volunteersregistration.entity.VolunteerInformation; +import com.volunteersregistration.service.MobileAlreadyRegisteredException; import com.volunteersregistration.service.VolunteerRegistrationService; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestPart; import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.multipart.MultipartFile; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import java.util.Map; + @RestController @RequestMapping("/volunteer/api") public class VolunteerRegistrationController { + @Autowired + private ObjectMapper objectMapper; + @Autowired private VolunteerRegistrationService volunteerRegistrationService; - @PostMapping("/register") - public String register(@RequestBody VolunteerInformation vol, Model model) { - System.out.println("save volunteers....."); - return volunteerRegistrationService.register(vol); - } + + +// @PostMapping("/register") +// public String register(@RequestBody VolunteerInformation vol, Model model) { +// System.out.println("save volunteers....."); +// return volunteerRegistrationService.register(vol); +// } + + +// @PostMapping(value = "/register", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) +// public String register( +// @RequestPart("volunteer") String volunteerJson, +// @RequestPart("doc_url") MultipartFile docFile) { +// +// try { +// +// VolunteerInformation vol = +// objectMapper.readValue( +// volunteerJson, +// VolunteerInformation.class +// ); +// +// return volunteerRegistrationService.register(vol, docFile); +// +// } catch (Exception e) { +// +// e.printStackTrace(); +// return "error"; +// } +// } + + @PostMapping( + value = "/register", + consumes = MediaType.MULTIPART_FORM_DATA_VALUE + ) + public ResponseEntity register( + @RequestPart("volunteer") String volunteerJson, + @RequestPart("doc_url") MultipartFile docFile) { + + try { + + VolunteerInformation vol = + objectMapper.readValue( + volunteerJson, + VolunteerInformation.class + ); + + String result = + volunteerRegistrationService.register(vol, docFile); + + return ResponseEntity.ok(result); + + } catch (MobileAlreadyRegisteredException e) { + + return ResponseEntity + .status(HttpStatus.CONFLICT) + .body(Map.of( + "status", "DUPLICATE_MOBILE", + "message", "This mobile number is already registered" + )); + + } catch (Exception e) { + + e.printStackTrace(); + + return ResponseEntity + .status(HttpStatus.INTERNAL_SERVER_ERROR) + .body(Map.of( + "status", "ERROR", + "message", "Error saving data" + )); + } + } + @PostMapping("/registerAsCorporate") - public String register(@RequestBody CorporateInformation copInfo, Model model) { + public ResponseEntity register(@RequestBody CorporateInformation copInfo, Model model) { System.out.println("save volunteers....."); - return volunteerRegistrationService.registerAsCorporate(copInfo); + + try { + + String result = volunteerRegistrationService.registerAsCorporate(copInfo); + return ResponseEntity.ok(result); + + } catch (MobileAlreadyRegisteredException e) { + + return ResponseEntity + .status(HttpStatus.CONFLICT) + .body(Map.of( + "status", "DUPLICATE_MOBILE", + "message", "This mobile number is already registered" + )); + + } catch (Exception e) { + + e.printStackTrace(); + + return ResponseEntity + .status(HttpStatus.INTERNAL_SERVER_ERROR) + .body(Map.of( + "status", "ERROR", + "message", "Error saving data" + )); + } + + } @PostMapping("/registerAsNgo") - public String register(@RequestBody NgoInformation ngoInfo, Model model) { + public ResponseEntity register(@RequestBody NgoInformation ngoInfo, Model model) { System.out.println("save volunteers....."); - return volunteerRegistrationService.registerAsNgo(ngoInfo); + + try { + + String result = volunteerRegistrationService.registerAsNgo(ngoInfo); + return ResponseEntity.ok(result); + + } catch (MobileAlreadyRegisteredException e) { + + return ResponseEntity + .status(HttpStatus.CONFLICT) + .body(Map.of( + "status", "DUPLICATE_MOBILE", + "message", "This mobile number is already registered" + )); + + } catch (Exception e) { + + e.printStackTrace(); + + return ResponseEntity + .status(HttpStatus.INTERNAL_SERVER_ERROR) + .body(Map.of( + "status", "ERROR", + "message", "Error saving data" + )); + } + + + } diff --git a/src/main/java/com/volunteersregistration/entity/CorporateInformation.java b/src/main/java/com/volunteersregistration/entity/CorporateInformation.java index dbaf50d..4f00b33 100644 --- a/src/main/java/com/volunteersregistration/entity/CorporateInformation.java +++ b/src/main/java/com/volunteersregistration/entity/CorporateInformation.java @@ -31,13 +31,45 @@ public class CorporateInformation { private String category; private String subCategory; + + private String ephno; + private int expertise_area; + private String other_expertise; // @Column(name = "category_id") // private Category category; + + private String referBy; - public int getCop_id() { + public String getEphno() { + return ephno; + } + + public void setEphno(String ephno) { + this.ephno = ephno; + } + + + + public int getExpertise_area() { + return expertise_area; + } + + public void setExpertise_area(int expertise_area) { + this.expertise_area = expertise_area; + } + + public String getOther_expertise() { + return other_expertise; + } + + public void setOther_expertise(String other_expertise) { + this.other_expertise = other_expertise; + } + + public int getCop_id() { return cop_id; } diff --git a/src/main/java/com/volunteersregistration/entity/NgoInformation.java b/src/main/java/com/volunteersregistration/entity/NgoInformation.java index fe8093a..15d0cad 100644 --- a/src/main/java/com/volunteersregistration/entity/NgoInformation.java +++ b/src/main/java/com/volunteersregistration/entity/NgoInformation.java @@ -34,11 +34,44 @@ public class NgoInformation { private String subCategory; private String referBy; + + private String ephno; + private int expertise_area; + private String other_expertise; + + + // @Column(name = "category_id") // private Category category; - public int getNgo_id() { + public String getEphno() { + return ephno; + } + + public void setEphno(String ephno) { + this.ephno = ephno; + } + + + + public int getExpertise_area() { + return expertise_area; + } + + public void setExpertise_area(int expertise_area) { + this.expertise_area = expertise_area; + } + + public String getOther_expertise() { + return other_expertise; + } + + public void setOther_expertise(String other_expertise) { + this.other_expertise = other_expertise; + } + + public int getNgo_id() { return ngo_id; } diff --git a/src/main/java/com/volunteersregistration/entity/VolunteerInformation.java b/src/main/java/com/volunteersregistration/entity/VolunteerInformation.java index 8912a03..db0d72a 100644 --- a/src/main/java/com/volunteersregistration/entity/VolunteerInformation.java +++ b/src/main/java/com/volunteersregistration/entity/VolunteerInformation.java @@ -54,6 +54,66 @@ public class VolunteerInformation { private String aadhar; private String bloodgroup; + + private String ephno; + private int expertise_area; + private String other_expertise; + private int doc_type; + private String doc_number; + private String doc_url; + + + + + public String getEphno() { + return ephno; + } + + public void setEphno(String ephno) { + this.ephno = ephno; + } + + + + public int getExpertise_area() { + return expertise_area; + } + + public void setExpertise_area(int expertise_area) { + this.expertise_area = expertise_area; + } + + public String getOther_expertise() { + return other_expertise; + } + + public void setOther_expertise(String other_expertise) { + this.other_expertise = other_expertise; + } + + public int getDoc_type() { + return doc_type; + } + + public void setDoc_type(int doc_type) { + this.doc_type = doc_type; + } + + public String getDoc_number() { + return doc_number; + } + + public void setDoc_number(String doc_number) { + this.doc_number = doc_number; + } + + public String getDoc_url() { + return doc_url; + } + + public void setDoc_url(String doc_url) { + this.doc_url = doc_url; + } public int getVolunteer_id() { return volunteer_id; diff --git a/src/main/java/com/volunteersregistration/repository/VolunteerRegistrationRepo.java b/src/main/java/com/volunteersregistration/repository/VolunteerRegistrationRepo.java index d3e974a..fa0b566 100644 --- a/src/main/java/com/volunteersregistration/repository/VolunteerRegistrationRepo.java +++ b/src/main/java/com/volunteersregistration/repository/VolunteerRegistrationRepo.java @@ -29,4 +29,11 @@ public interface VolunteerRegistrationRepo extends JpaRepository> getSubCategoryById(@Param("category_id") int category_id); + + @Query(value = "SELECT * FROM expertise_area_master WHERE is_active=1 AND is_delete=0 order by orderby ASC", nativeQuery = true) + List> getAllExpertise(); + + @Query(value = "SELECT * FROM volunteer_docs WHERE is_active=1 AND is_delete=0", nativeQuery = true) + List> getAllVolunteerDocs(); + } diff --git a/src/main/java/com/volunteersregistration/service/DateTimeUtil.java b/src/main/java/com/volunteersregistration/service/DateTimeUtil.java new file mode 100644 index 0000000..87e64c7 --- /dev/null +++ b/src/main/java/com/volunteersregistration/service/DateTimeUtil.java @@ -0,0 +1,35 @@ +package com.volunteersregistration.service; + +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; + +import org.springframework.stereotype.Component; + +@Component("volunteerDateTimeUtil") +public final class DateTimeUtil { + public static String getCurrentDateTime() { + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("ddMMyyyyHHmmss"); + LocalDateTime now = LocalDateTime.now(); + return now.format(formatter); + } + public static String getCurrentYear() { + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy"); + LocalDateTime now = LocalDateTime.now(); + return now.format(formatter); + } + public static String getCurrentMonth() { + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM"); + LocalDateTime now = LocalDateTime.now(); + return now.format(formatter); + } + public static String getCurrentDay() { + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd"); + LocalDateTime now = LocalDateTime.now(); + return now.format(formatter); + } + public static String getCurrentDateTimeMysql() { + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); + LocalDateTime now = LocalDateTime.now(); + return now.format(formatter); + } +} diff --git a/src/main/java/com/volunteersregistration/service/MobileAlreadyRegisteredException.java b/src/main/java/com/volunteersregistration/service/MobileAlreadyRegisteredException.java new file mode 100644 index 0000000..75a832c --- /dev/null +++ b/src/main/java/com/volunteersregistration/service/MobileAlreadyRegisteredException.java @@ -0,0 +1,7 @@ +package com.volunteersregistration.service; + +public class MobileAlreadyRegisteredException extends RuntimeException{ + public MobileAlreadyRegisteredException(String message) { + super(message); + } +} diff --git a/src/main/java/com/volunteersregistration/service/VolunteerRegistrationService.java b/src/main/java/com/volunteersregistration/service/VolunteerRegistrationService.java index 46fb243..a460b01 100644 --- a/src/main/java/com/volunteersregistration/service/VolunteerRegistrationService.java +++ b/src/main/java/com/volunteersregistration/service/VolunteerRegistrationService.java @@ -6,13 +6,26 @@ import com.volunteersregistration.entity.VolunteerInformation; import com.volunteersregistration.repository.CompanyInfoRepo; import com.volunteersregistration.repository.NgoInfoRepo; import com.volunteersregistration.repository.VolunteerRegistrationRepo; + + import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.env.Environment; +import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.stereotype.Service; +import org.springframework.web.client.RestTemplate; +import org.springframework.web.multipart.MultipartFile; +import java.awt.image.BufferedImage; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; import java.time.LocalDate; import java.time.LocalDateTime; import java.util.ArrayList; @@ -20,9 +33,24 @@ import java.util.List; import java.util.Map; import java.util.StringJoiner; +import javax.imageio.ImageIO; +import javax.imageio.ImageWriteParam; +import javax.imageio.ImageWriter; +import javax.imageio.stream.ImageOutputStream; + @Service public class VolunteerRegistrationService { + + private final Environment environment; + + public VolunteerRegistrationService(Environment environment) { + this.environment = environment; + } + + @Autowired + private JdbcTemplate jdbcTemplate; + @Autowired private VolunteerRegistrationRepo volunteerRegistrationRepo; @@ -32,46 +60,268 @@ public class VolunteerRegistrationService { @Autowired private NgoInfoRepo ngoInfoRepo; + private boolean isMobileAlreadyRegistered(Long mobileNo) { + String sql = " SELECT COUNT(*) " + + " FROM ( " + + " SELECT mobile_no " + + " FROM volunteer_information" + + " WHERE mobile_no = ? and isactive=1 " + + "" + + " UNION ALL " + + "" + + " SELECT contact_per_mobile " + + " FROM corporate_information " + + " WHERE contact_per_mobile = ? and isactive=1 " + + "" + + " UNION ALL " + + "" + + " SELECT mobile_no " + + " FROM ngo_information " + + " WHERE mobile_no = ? and isactive=1 " + + " ) AS mobile_check "; - public String register(VolunteerInformation volun) { + Integer count = jdbcTemplate.queryForObject( + sql, + Integer.class, + mobileNo, + mobileNo, + mobileNo + ); - volun.setCdate(LocalDateTime.now()); - volun.setIsactive(true); - try{ - if(volun!=null){ - String preferredAreas[] =volun.getPreferredAreas(); - if (preferredAreas != null) { - StringJoiner zones = new StringJoiner(","); - StringJoiner joiner = new StringJoiner(","); - for (String area : preferredAreas) { - String areaWZone[] =area.split("-"); - if(areaWZone != null && areaWZone.length==2) { - joiner.add(areaWZone[1]); - zones.add(areaWZone[0]); - }else{ - joiner.add(area); - } + return count != null && count > 0; + } + +// public String register(VolunteerInformation volun, MultipartFile docFile) { +// +// volun.setCdate(LocalDateTime.now()); +// volun.setIsactive(true); +// try{ +// if(volun!=null){ +// +// if (docFile != null && !docFile.isEmpty()) { +// +// String docPath = fileUpload(docFile,"volunteer"); +// +// // Set returned path into entity +// volun.setDoc_url(docPath); +// } +// +// String preferredAreas[] =volun.getPreferredAreas(); +// if (preferredAreas != null) { +// StringJoiner zones = new StringJoiner(","); +// StringJoiner joiner = new StringJoiner(","); +// for (String area : preferredAreas) { +// String areaWZone[] =area.split("-"); +// if(areaWZone != null && areaWZone.length==2) { +// joiner.add(areaWZone[1]); +// zones.add(areaWZone[0]); +// }else{ +// joiner.add(area); +// } +// } +// volun.setPreferred_area(joiner.toString()); +// volun.setPreferred_zones(zones.toString()); +// } +// volun= volunteerRegistrationRepo.save(volun); +// +// sendWhatsappMsgENG(volun.getVolunteer_id(),volun.getMobile_no(),"GCC-VOL-"); +// sendWhatsappMsgTam(volun.getVolunteer_id(),volun.getMobile_no(),"GCC-VOL-"); +// +// return "VOL-"+String.format("%05d",volun.getVolunteer_id()); +// } else { +// return "Not Saved"; +// } +// +// }catch(Exception e) { +// e.printStackTrace(); +// } +// return "error"; +// } + + + public String register( + VolunteerInformation volun, + MultipartFile docFile) { + + try { + + if (volun == null) { + return "Not Saved"; + } + + // ------------------------------------ + // Check mobile number duplication + // ------------------------------------ + Long mobileNo = volun.getMobile_no(); + + if (isMobileAlreadyRegistered(mobileNo)) { + throw new MobileAlreadyRegisteredException( + "This mobile number is already registered" + ); + } + + // ------------------------------------ + // Set common fields + // ------------------------------------ + volun.setCdate(LocalDateTime.now()); + volun.setIsactive(true); + + // ------------------------------------ + // Save document + // ------------------------------------ + if (docFile != null && !docFile.isEmpty()) { + + String docPath = fileUpload(docFile,"volunteer"); + + volun.setDoc_url(docPath); + } + + // ------------------------------------ + // Preferred Areas + // ------------------------------------ + String preferredAreas[] = volun.getPreferredAreas(); + + if (preferredAreas != null) { + + StringJoiner zones = new StringJoiner(","); + StringJoiner joiner = new StringJoiner(","); + + for (String area : preferredAreas) { + + String areaWZone[] = area.split("-"); + + if (areaWZone.length == 2) { + + joiner.add(areaWZone[1]); + zones.add(areaWZone[0]); + + } else { + + joiner.add(area); } - volun.setPreferred_area(joiner.toString()); - volun.setPreferred_zones(zones.toString()); } - volun= volunteerRegistrationRepo.save(volun); - - sendWhatsappMsgENG(volun.getVolunteer_id(),volun.getMobile_no(),"GCC-VOL-"); - sendWhatsappMsgTam(volun.getVolunteer_id(),volun.getMobile_no(),"GCC-VOL-"); - - return "VOL-"+String.format("%05d",volun.getVolunteer_id()); + + volun.setPreferred_area(joiner.toString()); + volun.setPreferred_zones(zones.toString()); + } + + // ------------------------------------ + // Save volunteer + // ------------------------------------ + volun = volunteerRegistrationRepo.save(volun); + + // ------------------------------------ + // Send WhatsApp + // ------------------------------------ + sendWhatsappMsgENG( + volun.getVolunteer_id(), + volun.getMobile_no(), + "GCC-VOL-" + ); + + sendWhatsappMsgTam( + volun.getVolunteer_id(), + volun.getMobile_no(), + "GCC-VOL-" + ); + + return "VOL-" + String.format( + "%05d", + volun.getVolunteer_id() + ); + + } catch (MobileAlreadyRegisteredException e) { + + // IMPORTANT: + // Don't convert this to generic "error" + throw e; + + } catch (Exception e) { + + e.printStackTrace(); + return "error"; + } + } + + public String fileUpload(MultipartFile file, String name) { + + // Set the file path where you want to save it + String uploadDirectory = environment.getProperty("file.upload.directory.mobile"); + String serviceFolderName = environment.getProperty("volunteer_individual_foldername"); + var year = DateTimeUtil.getCurrentYear(); + var month = DateTimeUtil.getCurrentMonth(); + + uploadDirectory = uploadDirectory + serviceFolderName + "/" + year + "/" + month; + + try { + // Create directory if it doesn't exist + Path directoryPath = Paths.get(uploadDirectory); + if (!Files.exists(directoryPath)) { + Files.createDirectories(directoryPath); + } + + // Datetime string + String datetimetxt = DateTimeUtil.getCurrentDateTime(); + + // File name + String fileName = name + "_" + datetimetxt + "_" + file.getOriginalFilename(); + fileName = fileName.replaceAll("\\s+", ""); // Remove space on filename + + String filePath = uploadDirectory + "/" + fileName; + + String filepath_txt = "/" + serviceFolderName + "/" + year + "/" + month + "/" + fileName; + + // Create a new Path object + Path path = Paths.get(filePath); + + // Get the bytes of the file + byte[] bytes = file.getBytes(); + + String originalFileName = file.getOriginalFilename(); + String extension = originalFileName.substring(originalFileName.lastIndexOf('.') + 1).toLowerCase(); + + if ("jpg".equals(extension) || "jpeg".equals(extension)) { + BufferedImage image = ImageIO.read(new ByteArrayInputStream(bytes)); + byte[] compressedBytes = compressImage(image, 0.5f); // Compress with 50% quality + + // Write the compressed bytes to the file + Files.write(path, compressedBytes); } else { - return "Not Saved"; + // Write the original bytes to the file + Files.write(path, bytes); } - }catch(Exception e) { + //System.out.println(filePath); + return filepath_txt; + + } catch (IOException e) { e.printStackTrace(); + return "Failed to save file " + file.getOriginalFilename(); } - return "error"; } + private byte[] compressImage(BufferedImage image, float quality) throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + ImageOutputStream imageOutputStream = ImageIO.createImageOutputStream(byteArrayOutputStream); + + ImageWriter writer = ImageIO.getImageWritersByFormatName("jpg").next(); + writer.setOutput(imageOutputStream); + + ImageWriteParam param = writer.getDefaultWriteParam(); + if (param.canWriteCompressed()) { + param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT); + param.setCompressionQuality(quality); + } + + writer.write(null, new javax.imageio.IIOImage(image, null, null), param); + + writer.dispose(); + imageOutputStream.close(); + + return byteArrayOutputStream.toByteArray(); + } + private String sendWhatsappMsgTam(int id, Long mob_no,String prefix) { String urlString = ""; @@ -152,7 +402,23 @@ public class VolunteerRegistrationService { public String registerAsNgo(NgoInformation ngo) { try { - if (ngo != null) { + + if (ngo == null) { + return "Not Saved"; + } + + // ------------------------------------ + // Check mobile number duplication + // ------------------------------------ + Long mobileNo = ngo.getMobileNo(); + + if (isMobileAlreadyRegistered(mobileNo)) { + throw new MobileAlreadyRegisteredException( + "This mobile number is already registered" + ); + } + + ngo.setCdate(LocalDateTime.now()); ngo.setIsactive(true); String preferredAreas[] = ngo.getPreferredAreas(); @@ -177,19 +443,40 @@ public class VolunteerRegistrationService { sendWhatsappMsgTam(ngo.getNgo_id(),ngo.getMobileNo(),"GCC-NGO_VOL-"); return "NGO_VOL-"+String.format("%05d",ngo.getNgo_id()); - } else { - return "Not Saved"; - } + + + }catch (MobileAlreadyRegisteredException e) { + + // IMPORTANT: + // Don't convert this to generic "error" + throw e; } catch (Exception e) { + e.printStackTrace(); + return "error"; } - return "error"; } public String registerAsCorporate(CorporateInformation cop){ try{ - if(cop!=null){ + + if (cop == null) { + return "Not Saved"; + } + + // ------------------------------------ + // Check mobile number duplication + // ------------------------------------ + Long mobileNo = cop.getContactPerMobile(); + + if (isMobileAlreadyRegistered(mobileNo)) { + throw new MobileAlreadyRegisteredException( + "This mobile number is already registered" + ); + } + + cop.setCdate(LocalDateTime.now()); cop.setIsactive(true); String preferredAreas[] =cop.getPreferredAreas(); @@ -214,14 +501,20 @@ public class VolunteerRegistrationService { sendWhatsappMsgTam(cop.getCop_id(),cop.getContactPerMobile(),"GCC-COR_VOL-"); return "COR_VOL-"+String.format("%05d",cop.getCop_id()); - } else { - return "Not Saved"; - } + + + } catch (MobileAlreadyRegisteredException e) { + + // IMPORTANT: + // Don't convert this to generic "error" + throw e; + + } catch (Exception e) { - }catch(Exception e) { e.printStackTrace(); + return "error"; } - return "error"; + } diff --git a/src/main/java/com/volunteersregistration/wasteCollector/controller/ApiController.java b/src/main/java/com/volunteersregistration/wasteCollector/controller/ApiController.java index e3038ac..0fa7682 100644 --- a/src/main/java/com/volunteersregistration/wasteCollector/controller/ApiController.java +++ b/src/main/java/com/volunteersregistration/wasteCollector/controller/ApiController.java @@ -212,7 +212,7 @@ public class ApiController { System.out.print("\n otp---:"+otp); DateTimeFormatter dtf = DateTimeFormatter.ofPattern("dd-MMM-yyyy%20HH:mm"); LocalDateTime now = LocalDateTime.now(); - System.out.println(dtf.format(now)); + System.out.println("\n"+dtf.format(now)); //String generatedToken = "Welcome to GCC! Your OTP for C%26D waste collectors Registration process is "+otp; //String generatedToken = "Welcome to GCC "+otp+" is your OTP for gcc QR System"; diff --git a/src/main/resources/application-dev.properties b/src/main/resources/application-dev.properties index 416feea..d46c343 100644 --- a/src/main/resources/application-dev.properties +++ b/src/main/resources/application-dev.properties @@ -31,5 +31,10 @@ file.leasedoc.fullpath=/cd_waste_docs/ file.rcbookdoc.fullpath=/cd_waste_docs/ file.userphoto.fullpath=/cd_waste_docs/ + +file.upload.directory.mobile=${user.dir}/gcc_mobile_service_uploads/ + +volunteer_individual_foldername=volunteer_individual_docs + #testing key payment.razorpay.my_key_id=rzp_test_tDkHFEqWXmuEi8 diff --git a/src/main/resources/application-prod.properties b/src/main/resources/application-prod.properties index e803359..3d94a47 100644 --- a/src/main/resources/application-prod.properties +++ b/src/main/resources/application-prod.properties @@ -32,6 +32,10 @@ file.leasedoc.fullpath=/cd_waste_docs/ file.rcbookdoc.fullpath=/cd_waste_docs/ file.userphoto.fullpath=/cd_waste_docs/ +file.upload.directory.mobile=${user.dir}/gcc_mobile_service_uploads/ + +volunteer_individual_foldername=volunteer_individual_docs + #live key payment.razorpay.my_key_id=rzp_live_ySI5Ns54Y7qOcJ \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 96687da..b589b60 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1 +1 @@ - spring.profiles.active=prod \ No newline at end of file + spring.profiles.active=dev \ No newline at end of file diff --git a/src/main/resources/templates/allreports.html b/src/main/resources/templates/allreports.html index 47bb11a..dc586a7 100644 --- a/src/main/resources/templates/allreports.html +++ b/src/main/resources/templates/allreports.html @@ -310,7 +310,7 @@ - + diff --git a/src/main/resources/templates/index.html b/src/main/resources/templates/index.html index a4786c7..38dd594 100644 --- a/src/main/resources/templates/index.html +++ b/src/main/resources/templates/index.html @@ -551,6 +551,25 @@ + +
+
+ + + + + +
+
+ + +
+ + @@ -643,7 +662,7 @@
- +
@@ -663,7 +682,7 @@
- +
@@ -708,7 +727,7 @@
- +
@@ -781,7 +800,7 @@
- +
@@ -800,7 +819,7 @@
- +
@@ -829,6 +848,40 @@
+ +
+ +
+ + + +
+ + + + + +
+ + + +
+ + +
@@ -1096,7 +1149,71 @@ } } */ + $("#name").on("input", function () { + this.value = this.value.replace(/[^a-zA-Z.\s]/g, ''); + }); + $("#cmpPoc").on("input", function () { + this.value = this.value.replace(/[^a-zA-Z.\s]/g, ''); + }); + + $("#oPoc").on("input", function () { + this.value = this.value.replace(/[^a-zA-Z.\s]/g, ''); + }); + + $("#dob").on("keydown paste drop", function (e) { + e.preventDefault(); + }); + + $("#pincode").on("input", function () { + this.value = this.value.replace(/\D/g, '').slice(0, 6); + }); + + $("#ephno").on("input", function () { + this.value = this.value.replace(/\D/g, '').slice(0, 10); + }); + + + $("#mobile").on("input", function () { + this.value = this.value.replace(/\D/g, '').slice(0, 10); + }); + + $("#cmdPom").on("input", function () { + this.value = this.value.replace(/\D/g, '').slice(0, 10); + }); + + $("#oPom").on("input", function () { + this.value = this.value.replace(/\D/g, '').slice(0, 10); + }); + + $("#expertise").on("change", function () { + + var selectedOption = $(this).find("option:selected"); + + var selectedId = selectedOption.val(); + var expertiseArea = selectedOption.attr("data-category") || ""; + + // Check ID = 7 OR expertise contains "Others" + var isOtherExpertise = + selectedId === "7" || + expertiseArea.toLowerCase().includes("others"); + + if (isOtherExpertise) { + + $("#otherExpertiseContainer").show(); + + } else { + + $("#otherExpertiseContainer").hide(); + + // Clear previous value and error + $("#other_expertise").val(""); + $("#otherExpertiseError").text(""); + } + }); + $(document).ready(function () { + + $.ajax({ url: "/volunteer/api/registration/getAllCategory", type: "GET", @@ -1114,6 +1231,79 @@ }); } }); + + $.ajax({ + url: "/volunteer/api/registration/getAllExpertise", + type: "GET", + success: function (expertise) { + let expertiseDropdown = $('#expertise'); + expertiseDropdown.empty(); + expertiseDropdown.append(``); + expertise.forEach(function (exp) { + + $('`); + docsvalues.forEach(function (docs) { + + $('
+ +
+
+ + + + + +
+
+ + +
+
@@ -570,9 +588,8 @@
- - + +
@@ -643,7 +660,7 @@
- +
@@ -663,7 +680,7 @@
- +
@@ -708,7 +725,7 @@
- +
@@ -798,7 +815,7 @@
- +
@@ -826,6 +843,41 @@
+ + +
+ +
+ + + +
+ + + + + +
+ + + +
+ + +
@@ -882,7 +934,7 @@
- +
@@ -1093,6 +1145,69 @@ } } */ + $("#name").on("input", function () { + this.value = this.value.replace(/[^a-zA-Z.\s]/g, ''); + }); + $("#cmpPoc").on("input", function () { + this.value = this.value.replace(/[^a-zA-Z.\s]/g, ''); + }); + + $("#oPoc").on("input", function () { + this.value = this.value.replace(/[^a-zA-Z.\s]/g, ''); + }); + + $("#dob").on("keydown paste drop", function (e) { + e.preventDefault(); + }); + + $("#pincode").on("input", function () { + this.value = this.value.replace(/\D/g, '').slice(0, 6); + }); + + $("#ephno").on("input", function () { + this.value = this.value.replace(/\D/g, '').slice(0, 10); + }); + + + $("#mobile").on("input", function () { + this.value = this.value.replace(/\D/g, '').slice(0, 10); + }); + + $("#cmdPom").on("input", function () { + this.value = this.value.replace(/\D/g, '').slice(0, 10); + }); + + $("#oPom").on("input", function () { + this.value = this.value.replace(/\D/g, '').slice(0, 10); + }); + + + $("#expertise").on("change", function () { + + var selectedOption = $(this).find("option:selected"); + + var selectedId = selectedOption.val(); + var expertiseArea = selectedOption.attr("data-category") || ""; + + // Check ID = 7 OR expertise contains "Others" + var isOtherExpertise = + selectedId === "7" || + expertiseArea.toLowerCase().includes("others"); + + if (isOtherExpertise) { + + $("#otherExpertiseContainer").show(); + + } else { + + $("#otherExpertiseContainer").hide(); + + // Clear previous value and error + $("#other_expertise").val(""); + $("#otherExpertiseError").text(""); + } + }); + $(document).ready(function () { $.ajax({ url: "/volunteer/api/registration/getAllCategory", @@ -1112,6 +1227,78 @@ }); } }); + + $.ajax({ + url: "/volunteer/api/registration/getAllExpertise", + type: "GET", + success: function (expertise) { + let expertiseDropdown = $('#expertise'); + expertiseDropdown.empty(); + expertiseDropdown.append(``); + expertise.forEach(function (exp) { + + $('`); + docsvalues.forEach(function (docs) { + + $('
@@ -548,9 +597,8 @@
- - + +
@@ -613,7 +661,7 @@

No of volunteers from your Company*

- +
@@ -621,7 +669,7 @@
- +
@@ -641,7 +689,7 @@
- +
@@ -686,9 +734,9 @@
- + - +
@@ -759,7 +807,7 @@
- +
@@ -778,7 +826,7 @@
- +
@@ -807,6 +855,42 @@
+ + +
+ +
+ + + +
+ + + + + +
+ + + +
+ + +
+ @@ -1074,6 +1158,73 @@ } } */ + + $("#name").on("input", function () { + this.value = this.value.replace(/[^a-zA-Z.\s]/g, ''); + }); + + $("#cmpPoc").on("input", function () { + this.value = this.value.replace(/[^a-zA-Z.\s]/g, ''); + }); + + $("#oPoc").on("input", function () { + this.value = this.value.replace(/[^a-zA-Z.\s]/g, ''); + }); + + $("#dob").on("keydown paste drop", function (e) { + e.preventDefault(); + }); + + + $("#pincode").on("input", function () { + this.value = this.value.replace(/\D/g, '').slice(0, 6); + }); + + + $("#ephno").on("input", function () { + this.value = this.value.replace(/\D/g, '').slice(0, 10); + }); + + + $("#mobile").on("input", function () { + this.value = this.value.replace(/\D/g, '').slice(0, 10); + }); + + $("#cmdPom").on("input", function () { + this.value = this.value.replace(/\D/g, '').slice(0, 10); + }); + + $("#oPom").on("input", function () { + this.value = this.value.replace(/\D/g, '').slice(0, 10); + }); + + + $("#expertise").on("change", function () { + + var selectedOption = $(this).find("option:selected"); + + var selectedId = selectedOption.val(); + var expertiseArea = selectedOption.attr("data-category") || ""; + + // Check ID = 7 OR expertise contains "Others" + var isOtherExpertise = + selectedId === "7" || + expertiseArea.toLowerCase().includes("others"); + + if (isOtherExpertise) { + + $("#otherExpertiseContainer").show(); + + } else { + + $("#otherExpertiseContainer").hide(); + + // Clear previous value and error + $("#other_expertise").val(""); + $("#otherExpertiseError").text(""); + } + }); + $(document).ready(function () { $.ajax({ url: "/volunteer/api/registration/getAllCategory", @@ -1092,6 +1243,80 @@ }); } }); + + + + $.ajax({ + url: "/volunteer/api/registration/getAllExpertise", + type: "GET", + success: function (expertise) { + let expertiseDropdown = $('#expertise'); + expertiseDropdown.empty(); + expertiseDropdown.append(``); + expertise.forEach(function (exp) { + + $('`); + docsvalues.forEach(function (docs) { + + $('
@@ -1072,6 +1151,69 @@ } } */ + $("#name").on("input", function () { + this.value = this.value.replace(/[^a-zA-Z.\s]/g, ''); + }); + $("#cmpPoc").on("input", function () { + this.value = this.value.replace(/[^a-zA-Z.\s]/g, ''); + }); + + $("#oPoc").on("input", function () { + this.value = this.value.replace(/[^a-zA-Z.\s]/g, ''); + }); + + $("#dob").on("keydown paste drop", function (e) { + e.preventDefault(); + }); + + $("#pincode").on("input", function () { + this.value = this.value.replace(/\D/g, '').slice(0, 6); + }); + + $("#ephno").on("input", function () { + this.value = this.value.replace(/\D/g, '').slice(0, 10); + }); + + + $("#mobile").on("input", function () { + this.value = this.value.replace(/\D/g, '').slice(0, 10); + }); + + $("#cmdPom").on("input", function () { + this.value = this.value.replace(/\D/g, '').slice(0, 10); + }); + + $("#oPom").on("input", function () { + this.value = this.value.replace(/\D/g, '').slice(0, 10); + }); + + + $("#expertise").on("change", function () { + + var selectedOption = $(this).find("option:selected"); + + var selectedId = selectedOption.val(); + var expertiseArea = selectedOption.attr("data-category") || ""; + + // Check ID = 7 OR expertise contains "Others" + var isOtherExpertise = + selectedId === "7" || + expertiseArea.toLowerCase().includes("others"); + + if (isOtherExpertise) { + + $("#otherExpertiseContainer").show(); + + } else { + + $("#otherExpertiseContainer").hide(); + + // Clear previous value and error + $("#other_expertise").val(""); + $("#otherExpertiseError").text(""); + } + }); + $(document).ready(function () { $.ajax({ url: "/volunteer/api/registration/getAllCategory", @@ -1091,6 +1233,79 @@ }); } }); + + + $.ajax({ + url: "/volunteer/api/registration/getAllExpertise", + type: "GET", + success: function (expertise) { + let expertiseDropdown = $('#expertise'); + expertiseDropdown.empty(); + expertiseDropdown.append(``); + expertise.forEach(function (exp) { + + $('`); + docsvalues.forEach(function (docs) { + + $('