Skip to content

Instantly share code, notes, and snippets.

View pavankjadda's full-sized avatar
😀
Follow me on Twitter @pavankjadda

Pavan Kumar Jadda pavankjadda

😀
Follow me on Twitter @pavankjadda
View GitHub Profile
//Predicate for Employee Projects data
  Predicate predicateForData = criteriaBuilder.or(
      criteriaBuilder.like(root.get("firstName"), "%" + employeeRequestDTO.getFilterText() + "%"),
      criteriaBuilder.like(root.get("lastName"), "%" + employeeRequestDTO.getFilterText() + "%"),
      criteriaBuilder.like(root.get("projectId").as(String.class), "%" + employeeRequestDTO.getFilterText() + "%"),
      criteriaBuilder.like(root.get("projectName"), "%" + employeeRequestDTO.getFilterText() + "%"),
      criteriaBuilder.like(root.get("projectBudget").as(String.class), "%" + employeeRequestDTO.getFilterText() + "%"),
      criteriaBuilder.like(root.get("projectLocation"), "%" + employeeRequestDTO.getFilterText() + "%"));
@pavankjadda
pavankjadda / getSpecification.md
Last active January 12, 2021 06:22
Get Specification
/**
 * Builds and return specification object that filters data based on search string
 *
 * @param employeeRequestDTO Employee Projects Request DTO object
 *
 * @return Specification with Employee Id and Filter Text
 */
private Specification<EmployeeProjectView> getSpecification(EmployeeRequestDTO employeeRequestDTO)
{
@pavankjadda
pavankjadda / Find Employees By Example Matcher.md
Created January 6, 2021 04:14
findEmployeeProjectsExampleMatcher
	@Override
	public Page<EmployeeProjectView> findEmployeeProjectsExampleMatcher(EmployeeRequestDTO employeeRequestDTO)
	{
		/* Build Search object */
		EmployeeProjectView employeeProjectView=new EmployeeProjectView();
		employeeProjectView.setEmployeeId(employeeRequestDTO.getEmployeeId());
		employeeProjectView.setLastName(employeeRequestDTO.getFilterText());
		employeeProjectView.setFirstName(employeeRequestDTO.getFilterText());
		try
@pavankjadda
pavankjadda / EmployeeProjectView.md
Created January 6, 2021 04:11
Employee Project View
package com.pj.multicolumnsearch.domain;

import lombok.Data;
import org.springframework.data.annotation.Immutable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
@pavankjadda
pavankjadda / Add or Remove years from Date Time in SQL server.md
Last active October 25, 2023 14:41
Add or Remove years from Date Time in SQL server
  1. Add 5 years to user date of birth timestamp
update user set date_of_birth=dateadd(year, 5, date_of_birth) where datepart(year, date_of_birth)>1965;

  1. Remove 100 years from user date of birth timestamp
update user set date_of_birth=dateadd(year , -100, date_of_birth) where datepart(year, date_of_birth)>2015;
@pavankjadda
pavankjadda / H2 Database Initialization in Spring Boot.md
Last active October 7, 2020 23:03
How to insert data in to H2 database during Spring Boot Application startup
  1. Create schema.sql file src/main/resources directory. This file contains all DDL statements
  2. Create data.sql file in src/main/resources directory. This file contains all DML statements(insert,update statements)
  3. Create the application.yml file with following config
spring:
  datasource:
    url: jdbc:h2:mem:db
    username: admin
    password: admin
 initialization-mode: always
@pavankjadda
pavankjadda / employee.service.ts.md
Created October 2, 2020 21:00
employee.service.ts
async createEmployee(url:string,employee: Employee)
{
  return await this.httpClient.post(url, employee).toPromise();
}
  
getEmployees(url:string)
{
  return this.httpClient.get<Employee[]>(url);
}
@pavankjadda
pavankjadda / app.component.ts.md
Last active October 2, 2020 20:59
Synchronous HTTP calls - app.component.ts
async createEmployee()
{
    let url = API_URL + 'employees';
    let employee = new Employee();
    employee.id = Math.floor(Math.random() * 10000);
    employee.firstName = "John";
    employee.lastName = "McCain" + employee.id;

 //Wait for POST operation to complete then return response
@pavankjadda
pavankjadda / Security Config.md
Created September 12, 2020 19:24
Security Config
package com.pj.jwt.security;


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.BeanIds;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
@pavankjadda
pavankjadda / JwtUtil.java.md
Last active September 13, 2020 05:25
JwtUtil
private String createToken(Map<String, Object> claims, String subject)
	{
		return Jwts.builder().setClaims(claims).setSubject(subject).setIssuedAt(new Date(System.currentTimeMillis()))
				.setExpiration(new Date(System.currentTimeMillis() + 1000 * 60 * 60 * 24))
				.signWith(Keys.hmacShaKeyFor(coreProperties.getJwtSecret().getBytes()), SignatureAlgorithm.HS512).compact();
	}
	
public boolean validateToken(String token, UserDetails userDetails)
	{