This commit is contained in:
string 2025-03-20 11:40:38 +05:30
parent 818a51a264
commit 4d2b28392c
27 changed files with 731 additions and 60 deletions

View File

@ -0,0 +1,66 @@
package com.realnet.Accesstype_back.Controllers;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.realnet.Accesstype_back.Entity.Accesstype;
import com.realnet.Accesstype_back.Services.AccesstypeService;
import com.realnet.fnd.response.EntityResponse;
@RequestMapping(value = "/access_type")
@RestController
public class AccesstypeController {
@Autowired
private AccesstypeService Service;
// add data
@PostMapping("/Accesstype")
public Accesstype Savedata(@RequestBody Accesstype data) throws JsonProcessingException {
Accesstype save = Service.Savedata(data);
return save;
}
// get all
@GetMapping("/Accesstype")
public List<Accesstype> getdetails() {
List<Accesstype> get = Service.getdetails();
return get;
}
// getby id
@GetMapping("/Accesstype/{id}")
public Accesstype getdetailsbyId(@PathVariable Long id) {
Accesstype get = Service.getdetailsbyId(id);
return get;
}
// update by id
@PutMapping("/Accesstype/{id}")
public Accesstype update(@RequestBody Accesstype data, @PathVariable Long id) {
Accesstype update = Service.update(data, id);
return update;
}
// delete by id
@DeleteMapping("/Accesstype/{id}")
public ResponseEntity<?> delete_by_id(@PathVariable Long id) {
Service.delete_by_id(id);
return new ResponseEntity<>(new EntityResponse("deleted"), HttpStatus.OK);
}
}

View File

@ -0,0 +1,30 @@
package com.realnet.Accesstype_back.Controllers;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.realnet.Accesstype_back.Entity.Agyana;
import com.realnet.Accesstype_back.Repository.AgyanaRepository;
@RequestMapping(value = "/token/access_type")
@RestController
public class AgyanaController {
@Autowired
private AgyanaRepository agyanaRepository;
@GetMapping("/agyana")
public List<Agyana> getAlldetails() {
List<Agyana> get = getdetails();
return get;
}
public List<Agyana> getdetails() {
return (List<Agyana>) agyanaRepository.findAll();
}
}

View File

@ -0,0 +1,51 @@
package com.realnet.Accesstype_back.Controllers;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import com.realnet.Accesstype_back.Entity.Arani;
import com.realnet.Accesstype_back.Services.AraniService;
@RestController
public class AraniController {
@Autowired
private AraniService service;
@GetMapping("/Arani")
public List<Arani> getAlldetails(){
List<Arani> get = service.getAll();
return get;
}
@GetMapping("/Arani/{id}")
public Arani getAlldetails(@PathVariable Long id) {
Arani get = service.getdetailsbyid(id);
return get;
}
@PostMapping("/Arani")
public Arani saverani(@RequestBody Arani rani) {
Arani saverani = service.saverani(rani);
return saverani;
}
@DeleteMapping("/Arani/{id}")
public void delete_by_id(@PathVariable Long id) {
service.delete_by_id(id);
}
@PutMapping("/Arani/{id}")
public Arani update(@RequestBody Arani data, @PathVariable Long id) {
Arani update = service.update(data, id);
return update;
}
}

View File

@ -0,0 +1,68 @@
package com.realnet.Accesstype_back.Controllers;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.realnet.Accesstype_back.Entity.Accesstype;
import com.realnet.Accesstype_back.Services.AccesstypeService;
@RequestMapping(value = "/token/access_type")
@RestController
public class TokenFreeAccesstypeController {
@Autowired
private AccesstypeService Service;
// @Autowired
// private Workflow_service workflow_service;
//add data
@PostMapping("/Accesstype")
public Accesstype Savedata(@RequestBody Accesstype data) throws JsonProcessingException {
Accesstype save = Service.Savedata(data);
// workflow_service.save_webhook(data, "post", "Accesstype");
return save;
}
//get all
@GetMapping("/Accesstype")
public List<Accesstype> getdetails() {
List<Accesstype> get = Service.getdetails();
return get;
}
//getby id
@GetMapping("/Accesstype/{id}")
public Accesstype getdetailsbyId(@PathVariable Long id) {
Accesstype get = Service.getdetailsbyId(id);
return get;
}
//update by id
@PutMapping("/Accesstype/{id}")
public Accesstype update(@RequestBody Accesstype data, @PathVariable Long id) {
Accesstype update = Service.update(data, id);
return update;
}
//delete by id
@DeleteMapping("/Accesstype/{id}")
public ResponseEntity<?> delete_by_id(@PathVariable Long id) {
Service.delete_by_id(id);
return new ResponseEntity<>("deleted",HttpStatus.OK);
}
}

View File

@ -0,0 +1,19 @@
package com.realnet.Accesstype_back.Entity;
import lombok.*;
import javax.persistence.*;
import java.time.LocalDateTime;
import java.util.*;
@Entity
@Data
public class Accesstype{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String name;
private String description;
private boolean defaultvalue;
}

View File

@ -0,0 +1,27 @@
package com.realnet.Accesstype_back.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import lombok.*;
import javax.persistence.*;
import java.time.LocalDateTime;
import java.util.*;
@Entity
@Data
public class Agyana {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String name;
private String mark;
private Date timestamp;
private String mark2;
}

View File

@ -0,0 +1,22 @@
package com.realnet.Accesstype_back.Entity;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import lombok.Data;
@Entity
@Data
public class Arani {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String name;
private String email;
private String address;
}

View File

@ -0,0 +1,13 @@
package com.realnet.Accesstype_back.Repository;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import com.realnet.Accesstype_back.Entity.Accesstype;
@Repository
public interface AccesstypeRepository extends JpaRepository<Accesstype, Long> {
}

View File

@ -0,0 +1,11 @@
package com.realnet.Accesstype_back.Repository;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import com.realnet.Accesstype_back.Entity.Agyana;
@Repository
public interface AgyanaRepository extends JpaRepository<Agyana, Long>{
}

View File

@ -0,0 +1,11 @@
package com.realnet.Accesstype_back.Repository;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import com.realnet.Accesstype_back.Entity.Arani;
@Repository
public interface AraniRepository extends JpaRepository<Arani, Long> {
}

View File

@ -0,0 +1,49 @@
package com.realnet.Accesstype_back.Services;
import com.realnet.Accesstype_back.Repository.AccesstypeRepository;
//import com.realnet.AudiTrail.Service.AuditrailService;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.realnet.Accesstype_back.Entity.Accesstype;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class AccesstypeService {
@Autowired
private AccesstypeRepository Repository;
// @Autowired
// private AuditrailService auditrailService;
public Accesstype Savedata(Accesstype data) {
return Repository.save(data);
}
public List<Accesstype> getdetails() {
return (List<Accesstype>) Repository.findAll();
}
public Accesstype getdetailsbyId(Long id) {
return Repository.findById(id).get();
}
public void delete_by_id(Long id) {
Repository.deleteById(id);
}
public Accesstype update(Accesstype data, Long id) {
Accesstype old = Repository.findById(id).get();
old.setName(data.getName());
old.setDescription(data.getDescription());
final Accesstype test = Repository.save(old);
// try {
// auditrailService.saveaudiTrail_t(old, test,"Accesstype");
// } catch (JsonProcessingException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
return test;
}
}

View File

@ -0,0 +1,44 @@
package com.realnet.Accesstype_back.Services;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.realnet.Accesstype_back.Entity.Arani;
import com.realnet.Accesstype_back.Repository.AraniRepository;
@Service
public class AraniService {
@Autowired
private AraniRepository repo;
public List<Arani> getAll() {
return (List<Arani>) repo.findAll();
}
public Arani getdetailsbyid(Long id) {
return repo.findById(id).get();
}
public Arani saverani(Arani rani){
Arani saverani = repo.save(rani);
return saverani;
}
public void delete_by_id(Long id) {
repo.deleteById(id);
}
public Arani update(Arani data, Long id) {
Arani old = repo.findById(id).get();
old.setName(data.getName());
old.setEmail(data.getEmail());
old.setAddress(data.getAddress());
final Arani test = repo.save(old);
return test;
}
}

View File

@ -5,11 +5,13 @@ import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import com.realnet.WhoColumn.Entity.Who_column;
import lombok.Data;
@Entity
@Data
public class Gaurav_testing_t {
public class Gaurav_testing_t extends Who_column {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@ -22,5 +24,4 @@ public class Gaurav_testing_t {
private String pincode;
private String description;
}

View File

@ -0,0 +1,46 @@
package com.realnet.Modules_t_back.Controllers;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.realnet.Modules_t_back.Entity.Modules_t;
import com.realnet.Modules_t_back.Services.Modules_tService;
@RequestMapping(value = "/_back")
@RestController
public class Modules_tController {
@Autowired
private Modules_tService Service;
@PostMapping("/Modules_t")
public Modules_t Savedata(@RequestBody Modules_t data) {
Modules_t save = Service.Savedata(data);
return save;
}
@GetMapping("/Modules_t")
public List<Modules_t> getdetails() {
List<Modules_t> get = Service.getdetails();
return get;
}
@GetMapping("/Modules_t/{id}")
public Modules_t getdetailsbyId(@PathVariable Long id) {
Modules_t get = Service.getdetailsbyId(id);
return get;
}
@DeleteMapping("/Modules_t/{id}")
public void delete_by_id(@PathVariable Long id) {
Service.delete_by_id(id);
}
@PutMapping("/Modules_t/{id}")
public Modules_t update(@RequestBody Modules_t data, @PathVariable Long id) {
Modules_t update = Service.update(data, id);
return update;
}
}

View File

@ -0,0 +1,24 @@
package com.realnet.Modules_t_back.Entity;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import lombok.Data;
@Entity
@Data
public class Modules_t {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String modules;
private String description;
private String access_exclusive;
private Boolean isdeleted;
}

View File

@ -0,0 +1,13 @@
package com.realnet.Modules_t_back.Repository;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import com.realnet.Modules_t_back.Entity.Modules_t;
@Repository
public interface Modules_tRepository extends JpaRepository<Modules_t, Long> {
}

View File

@ -0,0 +1,42 @@
package com.realnet.Modules_t_back.Services;
import com.realnet.Modules_t_back.Repository.Modules_tRepository;
import com.realnet.Modules_t_back.Entity.Modules_t;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class Modules_tService {
@Autowired
private Modules_tRepository Repository;
public Modules_t Savedata(Modules_t data) {
data.setIsdeleted(false);
Modules_t save = Repository.save(data);
return save;
}
public List<Modules_t> getdetails() {
return (List<Modules_t>) Repository.findAll();
}
public Modules_t getdetailsbyId(Long id) {
return Repository.findById(id).get();
}
public void delete_by_id(Long id) {
Repository.deleteById(id);
}
public Modules_t update(Modules_t data, Long id) {
Modules_t old = Repository.findById(id).get();
old.setModules(data.getModules());
old.setDescription(data.getDescription());
old.setAccess_exclusive(data.getAccess_exclusive());
final Modules_t test = Repository.save(old);
return test;
}
}

View File

@ -0,0 +1,30 @@
package com.realnet.OpenAi.Controller;
import org.springframework.beans.factory.annotation.Autowired;
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.RestController;
import com.realnet.OpenAi.Models.openAi;
import com.realnet.OpenAi.Services.OpenAiServices;
@RestController
@RequestMapping("/token/openAi")
public class OpenAiController {
@Autowired
private OpenAiServices openAiServices;
@PostMapping
public String chat(@RequestBody openAi request) {
String prompt = request.getPrompt();
System.out.println("open api start..");
return openAiServices.getChatGPTResponse(prompt);
}
public String fallbackResponse(Exception e) {
return "Rate limit exceeded. Please try again later.";
}
}

View File

@ -0,0 +1,10 @@
package com.realnet.OpenAi.Models;
import lombok.Data;
@Data
public class openAi {
private String prompt;
}

View File

@ -0,0 +1,44 @@
package com.realnet.OpenAi.Services;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import java.util.HashMap;
import java.util.Map;
@Service
public class OpenAiServices {
@Value("${chatgpt.api.url}")
private String apiUrl;
@Value("${chatgpt.api.key}")
private String apiKey;
public String getChatGPTResponse(String prompt) {
RestTemplate restTemplate = new RestTemplate();
// Create headers
HttpHeaders headers = new HttpHeaders();
headers.set("Authorization", "Bearer " + apiKey);
headers.set("Content-Type", "application/json");
// Create body
Map<String, Object> body = new HashMap<>();
body.put("model", "gpt-3.5-turbo"); // Updated model
body.put("prompt", prompt);
body.put("max_tokens", 150);
body.put("temperature", 0.7);
// Build request
HttpEntity<Map<String, Object>> entity = new HttpEntity<>(body, headers);
// Make API call
ResponseEntity<String> response = restTemplate.postForEntity(apiUrl, entity, String.class);
return response.getBody();
}
}

View File

@ -1,55 +0,0 @@
package com.realnet.WhoColumn.Component;
import java.time.ZonedDateTime;
import java.util.Date;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.realnet.MultiTimeZone.Services.TimezoneService;
import com.realnet.WhoColumn.Entity.Who_column;
import com.realnet.users.entity1.AppUser;
@Aspect
@Component
public class WhoColumnAspect {
@Autowired
private TimezoneService timezoneService;
@PersistenceContext
private EntityManager entityManager;
@Before("execution(* org.springframework.data.jpa.repository.JpaRepository.save(..)) && args(entity)")
public void applyTimezone(Object entity) {
if (entity instanceof Who_column) {
Who_column whoColumn = (Who_column) entity;
// Fetching user timezone
Long createdByUserId = whoColumn.getCreatedBy(); // Assuming you store `createdBy` as user ID
AppUser appUser = entityManager.find(AppUser.class, createdByUserId);
if (appUser != null) {
String userTimezone = appUser.getMultitime(); // Retrieve user's timezone
// Convert timestamps
if (whoColumn.getCreatedAt() != null) {
ZonedDateTime convertedCreatedAt = timezoneService.convertToUserTimezone(whoColumn.getCreatedAt(),
userTimezone);
whoColumn.setCreatedAt(Date.from(convertedCreatedAt.toInstant()));
}
if (whoColumn.getUpdatedAt() != null) {
ZonedDateTime convertedUpdatedAt = timezoneService.convertToUserTimezone(whoColumn.getUpdatedAt(),
userTimezone);
whoColumn.setUpdatedAt(Date.from(convertedUpdatedAt.toInstant()));
}
}
}
}
}

View File

@ -21,6 +21,7 @@ import lombok.Data;
public class Who_column implements Serializable {
private static final long serialVersionUID = 1L;
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "CREATED_AT", nullable = false, updatable = false)
@CreatedDate

View File

@ -82,7 +82,16 @@ public class EmailService {
email.setSubject(subject);
email.setText(body);
email.setTo(sendTo);
mailSender.send(email);
try {
mailSender.send(email);
System.out.println(" email sent to " + sendTo);
} catch (Exception e) {
System.out.println(" invalid email " + e);
// TODO: handle exception
}
}

View File

@ -0,0 +1,69 @@
package com.realnet.exceptions;
import java.nio.file.AccessDeniedException;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.ResourceAccessException;
import com.realnet.exceptions.OperationResponse.ResponseStatusEnum;
import lombok.extern.slf4j.Slf4j;
/*
@ControllerAdvice tells your spring application that this class will do the exception handling for your application.
@RestController will make it a controller and let this class render the response.
Use @ExceptionHandler annotation to define the class of Exception it will catch. (A Base class will catch all the Inherited and extended classes)
*/
@Slf4j
@ControllerAdvice
@RestController
public class GlobalExceptionHandler {
@ExceptionHandler(value = DataIntegrityViolationException.class)
public OperationResponse handleBaseException(DataIntegrityViolationException e) {
OperationResponse resp = new OperationResponse();
resp.setOperationStatus(ResponseStatusEnum.ERROR);
resp.setOperationMessage(e.getRootCause().getMessage());
log.info("Global Exception Handler : " + resp.toString());
return resp;
}
@ExceptionHandler(value = AccessDeniedException.class)
public OperationResponse handleAccessDeniedException(AccessDeniedException e) {
OperationResponse resp = new OperationResponse();
resp.setOperationStatus(ResponseStatusEnum.NO_ACCESS);
resp.setOperationMessage("Your Access is Denied Plz contact Admin " + e.getLocalizedMessage());
log.info("Global Exception Handler : " + resp.toString());
return resp;
}
// @ExceptionHandler(value = ConnectException.class)
// private OperationResponse handleconnectionrefusedexception(ConnectException e) {
// OperationResponse resp = new OperationResponse();
// resp.setOperationMessage("connection refused please start server");
// resp.setOperationStatus(ResponseStatusEnum.WARNING);
// return resp;
//
// }
@ExceptionHandler(value = ResourceAccessException.class)
private OperationResponse handleconnectionrefusedexception(ResourceAccessException e) {
OperationResponse resp = new OperationResponse();
resp.setOperationMessage("connection refused please start server " + "\n " + e.getLocalizedMessage());
resp.setOperationStatus(ResponseStatusEnum.WARNING);
return resp;
}
@ExceptionHandler(value = IllegalArgumentException.class)
private OperationResponse illegalargsException(IllegalArgumentException e) {
OperationResponse resp = new OperationResponse();
resp.setOperationMessage(e.getLocalizedMessage());
resp.setOperationStatus(ResponseStatusEnum.WARNING);
return resp;
}
}

View File

@ -0,0 +1,19 @@
/**
This is the common structure for all responses
if the response contains a list(array) then it will have 'items' field
if the response contains a single item then it will have 'item' field
*/
package com.realnet.exceptions;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data //for getters and setters
public class OperationResponse {
public enum ResponseStatusEnum {SUCCESS, ERROR, WARNING, NO_ACCESS};
@ApiModelProperty(required = true)
private ResponseStatusEnum operationStatus;
private String operationMessage;
}

View File

@ -16,7 +16,6 @@ import com.realnet.sysparameter.entity.SysParamEntity;
import com.realnet.sysparameter.entity.SysParamUpload;
import com.realnet.sysparameter.repository.SysParamRepository;
import com.realnet.sysparameter.repository.SysparamUploadRepo;
import lombok.extern.slf4j.Slf4j;
@Slf4j

View File

@ -1,5 +1,7 @@
package com.realnet.users.service1;
import static org.hamcrest.CoreMatchers.nullValue;
import java.math.BigDecimal;
import java.security.SecureRandom;
import java.util.ArrayList;
@ -316,8 +318,14 @@ public class AppUserServiceImpl implements UserDetailsService, AppUserService {
public AppUser getLoggedInUser() {
String loggedInUserName = this.getLoggedInUserEmail();
Optional<AppUser> user = appUserRepository.findByUsername(loggedInUserName);
if (user.isPresent()) {
return user.get();
} else {
return null;
}
// log.info("getLoggedInUser() : {} ", user.get());
return user.get();
}
@Override