Skip to content

Commit

Permalink
Added deprecated annotation to classes
Browse files Browse the repository at this point in the history
  • Loading branch information
Nazariii committed Nov 2, 2015
1 parent c0ac4f0 commit 4ca67b4
Show file tree
Hide file tree
Showing 12 changed files with 171 additions and 107 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;

/**
* @deprecated this class have a lot of repeated code <br/>
* {need to be replaced and removed}<br/>
* use {@link com.softserve.edu.specification.SpecificationBuilder} instead
*/
@Deprecated
public class ArchivalCounterTypeQueryConstructorAdmin {
static Logger logger = Logger.getLogger(ArchivalCounterTypeQueryConstructorAdmin.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
import javax.persistence.EntityManager;
import javax.persistence.criteria.*;

/**
* @deprecated this class have a lot of repeated code <br/>
* {need to be replaced and removed}<br/>
* use {@link com.softserve.edu.specification.SpecificationBuilder} instead
*/
@Deprecated
public class ArchivalDevicesCategoryQueryConstructorAdmin {
static Logger logger = Logger.getLogger(ArchivalDevicesCategoryQueryConstructorAdmin.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
import javax.persistence.EntityManager;
import javax.persistence.criteria.*;

/**
* @deprecated this class have a lot of repeated code <br/>
* {need to be replaced and removed}<br/>
* use {@link com.softserve.edu.specification.SpecificationBuilder} instead
*/
@Deprecated
public class ArchivalEmployeeQueryConstructorAdmin {
static Logger logger = Logger.getLogger(ArchivalEmployeeQueryConstructorAdmin.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
import javax.persistence.criteria.*;
import javax.print.DocFlavor;

/**
* @deprecated this class have a lot of repeated code <br/>
* {need to be replaced and removed}<br/>
* use {@link com.softserve.edu.specification.SpecificationBuilder} instead
*/
@Deprecated
public class ArchivalOrganizationsQueryConstructorAdmin {
static Logger logger = Logger.getLogger(ArchivalOrganizationsQueryConstructorAdmin.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

/**
* @deprecated this class have a lot of repeated code <br/>
* {need to be replaced and removed}<br/>
* use {@link com.softserve.edu.specification.SpecificationBuilder} instead
*/
@Deprecated
public class ArchivalVerificationsQueryConstructorCalibrator {
static Logger logger = Logger.getLogger(ArchivalVerificationsQueryConstructorProvider.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

/**
* @deprecated this class have a lot of repeated code <br/>
* {need to be replaced and removed}<br/>
* use {@link com.softserve.edu.specification.SpecificationBuilder} instead
*/
@Deprecated
public class ArchivalVerificationsQueryConstructorProvider {
static Logger logger = Logger.getLogger(ArchivalVerificationsQueryConstructorProvider.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,106 +13,112 @@
import java.util.Calendar;
import java.util.Date;

/**
* @deprecated this class have a lot of repeated code <br/>
* {need to be replaced and removed}<br/>
* use {@link com.softserve.edu.specification.SpecificationBuilder} instead
*/
@Deprecated
public class ArchivalVerificationsQueryConstructorVerificator {
static Logger logger = Logger.getLogger(ArchivalVerificationsQueryConstructorProvider.class);
public static CriteriaQuery<Verification> buildSearchQuery(Long employeeId, String dateToSearch,
String idToSearch, String fullNameToSearch, String streetToSearch, String status, String employeeName,
String sortCriteria, String sortOrder, User providerEmployee, EntityManager em) {

CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Verification> criteriaQuery = cb.createQuery(Verification.class);
Root<Verification> root = criteriaQuery.from(Verification.class);
Join<Verification, Organization> calibratorJoin = root.join("stateVerificator");

Predicate predicate = ArchivalVerificationsQueryConstructorVerificator.buildPredicate(root, cb, employeeId, dateToSearch, idToSearch,
fullNameToSearch, streetToSearch, status, employeeName, providerEmployee, calibratorJoin);
if((sortCriteria != null)&&(sortOrder != null)) {
criteriaQuery.orderBy(SortCriteriaVerification.valueOf(sortCriteria.toUpperCase()).getSortOrder(root, cb, sortOrder));
} else {
criteriaQuery.orderBy(cb.desc(root.get("initialDate")));
}
criteriaQuery.select(root);
criteriaQuery.where(predicate);
return criteriaQuery;
}
public static CriteriaQuery<Long> buildCountQuery(Long employeeId, String dateToSearch,
String idToSearch, String fullNameToSearch, String streetToSearch, String status, String employeeName,
User providerEmployee, EntityManager em) {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Long> countQuery = cb.createQuery(Long.class);
Root<Verification> root = countQuery.from(Verification.class);
Join<Verification, Organization> verificatorJoin = root.join("stateVerificator");
Predicate predicate = ArchivalVerificationsQueryConstructorVerificator.buildPredicate(root, cb, employeeId, dateToSearch, idToSearch,
fullNameToSearch, streetToSearch, status, employeeName, providerEmployee
, verificatorJoin);
countQuery.select(cb.count(root));
countQuery.where(predicate);
return countQuery;
}
private static Predicate buildPredicate(Root<Verification> root, CriteriaBuilder cb, Long employeeId, String dateToSearch, String idToSearch,
String fullNameToSearch, String streetToSearch, String searchStatus,
String employeeName, User employee, Join<Verification, Organization> verificatorJoin) {

Predicate queryPredicate = cb.conjunction();
queryPredicate = cb.and(cb.equal(verificatorJoin.get("id"), employeeId), queryPredicate);
if (searchStatus != null) {
queryPredicate = cb.and(cb.equal(root.get("status"), Status.valueOf(searchStatus.trim())), queryPredicate);
}

if (dateToSearch != null) {
Date date = null;
try {
date = new SimpleDateFormat("yyyy-MM-dd").parse(dateToSearch.substring(0, 10));
Calendar c = Calendar.getInstance();
c.setTime(date);
c.add(Calendar.DATE, 1);
date = c.getTime();
} catch (ParseException pe) {
logger.error("Cannot parse date", pe);
}
queryPredicate = cb.and(cb.equal(root.get("initialDate"), date), queryPredicate);
}

if ((idToSearch != null)&&(idToSearch.length()>0)) {
queryPredicate = cb.and(cb.like(root.get("id"), "%" + idToSearch + "%"), queryPredicate);
}
if ((fullNameToSearch != null)&&(fullNameToSearch.length()>0)) {
queryPredicate = cb.and(cb.like(root.get("clientData").get("lastName"), "%" + fullNameToSearch + "%"),
queryPredicate);
}
if ((fullNameToSearch != null)&&(fullNameToSearch.length()>0)) {
Predicate searchByClientFirstName = cb.like(root.get("clientData").get("firstName"), "%" + fullNameToSearch + "%");
Predicate searchByClientLastName = cb.like(root.get("clientData").get("lastName"), "%" + fullNameToSearch + "%");
Predicate searchByClientMiddleName = cb.like(root.get("clientData").get("middleName"), "%" + fullNameToSearch + "%");
Predicate searchPredicateByClientFullName = cb.or(searchByClientFirstName, searchByClientLastName, searchByClientMiddleName);
queryPredicate = cb.and(searchPredicateByClientFullName, queryPredicate);
}

if ((streetToSearch != null)&&(streetToSearch.length()>0)) {
queryPredicate = cb.and(
cb.like(root.get("clientData").get("clientAddress").get("street"), "%" + streetToSearch + "%"),
queryPredicate);
}
if ((employeeName != null)&&(employeeName.length()>0)) {
Join<Verification, User> joinVerificatorEmployee = root.join("stateVerificatorEmployee");
Predicate searchByVerificatorName = cb.like(joinVerificatorEmployee.get("firstName"),
"%" + employeeName + "%");
Predicate searchByVerificatorSurname = cb.like(joinVerificatorEmployee.get("lastName"),
"%" + employeeName + "%");
Predicate searchByVerificatorLastName = cb.like(joinVerificatorEmployee.get("middleName"),
"%" + employeeName + "%");
Predicate searchPredicateByVerificatorEmployeeName = cb.or(searchByVerificatorName,
searchByVerificatorSurname, searchByVerificatorLastName);
queryPredicate = cb.and(searchPredicateByVerificatorEmployeeName, queryPredicate);
}

return queryPredicate;
}
static Logger logger = Logger.getLogger(ArchivalVerificationsQueryConstructorProvider.class);


public static CriteriaQuery<Verification> buildSearchQuery(Long employeeId, String dateToSearch,
String idToSearch, String fullNameToSearch, String streetToSearch, String status, String employeeName,
String sortCriteria, String sortOrder, User providerEmployee, EntityManager em) {

CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Verification> criteriaQuery = cb.createQuery(Verification.class);
Root<Verification> root = criteriaQuery.from(Verification.class);
Join<Verification, Organization> calibratorJoin = root.join("stateVerificator");

Predicate predicate = ArchivalVerificationsQueryConstructorVerificator.buildPredicate(root, cb, employeeId, dateToSearch, idToSearch,
fullNameToSearch, streetToSearch, status, employeeName, providerEmployee, calibratorJoin);
if ((sortCriteria != null) && (sortOrder != null)) {
criteriaQuery.orderBy(SortCriteriaVerification.valueOf(sortCriteria.toUpperCase()).getSortOrder(root, cb, sortOrder));
} else {
criteriaQuery.orderBy(cb.desc(root.get("initialDate")));
}
criteriaQuery.select(root);
criteriaQuery.where(predicate);
return criteriaQuery;
}


public static CriteriaQuery<Long> buildCountQuery(Long employeeId, String dateToSearch,
String idToSearch, String fullNameToSearch, String streetToSearch, String status, String employeeName,
User providerEmployee, EntityManager em) {

CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Long> countQuery = cb.createQuery(Long.class);
Root<Verification> root = countQuery.from(Verification.class);
Join<Verification, Organization> verificatorJoin = root.join("stateVerificator");
Predicate predicate = ArchivalVerificationsQueryConstructorVerificator.buildPredicate(root, cb, employeeId, dateToSearch, idToSearch,
fullNameToSearch, streetToSearch, status, employeeName, providerEmployee
, verificatorJoin);
countQuery.select(cb.count(root));
countQuery.where(predicate);
return countQuery;
}

private static Predicate buildPredicate(Root<Verification> root, CriteriaBuilder cb, Long employeeId, String dateToSearch, String idToSearch,
String fullNameToSearch, String streetToSearch, String searchStatus,
String employeeName, User employee, Join<Verification, Organization> verificatorJoin) {

Predicate queryPredicate = cb.conjunction();
queryPredicate = cb.and(cb.equal(verificatorJoin.get("id"), employeeId), queryPredicate);

if (searchStatus != null) {
queryPredicate = cb.and(cb.equal(root.get("status"), Status.valueOf(searchStatus.trim())), queryPredicate);
}

if (dateToSearch != null) {
Date date = null;
try {
date = new SimpleDateFormat("yyyy-MM-dd").parse(dateToSearch.substring(0, 10));
Calendar c = Calendar.getInstance();
c.setTime(date);
c.add(Calendar.DATE, 1);
date = c.getTime();
} catch (ParseException pe) {
logger.error("Cannot parse date", pe);
}
queryPredicate = cb.and(cb.equal(root.get("initialDate"), date), queryPredicate);
}

if ((idToSearch != null) && (idToSearch.length() > 0)) {
queryPredicate = cb.and(cb.like(root.get("id"), "%" + idToSearch + "%"), queryPredicate);
}
if ((fullNameToSearch != null) && (fullNameToSearch.length() > 0)) {
queryPredicate = cb.and(cb.like(root.get("clientData").get("lastName"), "%" + fullNameToSearch + "%"),
queryPredicate);
}
if ((fullNameToSearch != null) && (fullNameToSearch.length() > 0)) {
Predicate searchByClientFirstName = cb.like(root.get("clientData").get("firstName"), "%" + fullNameToSearch + "%");
Predicate searchByClientLastName = cb.like(root.get("clientData").get("lastName"), "%" + fullNameToSearch + "%");
Predicate searchByClientMiddleName = cb.like(root.get("clientData").get("middleName"), "%" + fullNameToSearch + "%");
Predicate searchPredicateByClientFullName = cb.or(searchByClientFirstName, searchByClientLastName, searchByClientMiddleName);
queryPredicate = cb.and(searchPredicateByClientFullName, queryPredicate);
}

if ((streetToSearch != null) && (streetToSearch.length() > 0)) {
queryPredicate = cb.and(
cb.like(root.get("clientData").get("clientAddress").get("street"), "%" + streetToSearch + "%"),
queryPredicate);
}
if ((employeeName != null) && (employeeName.length() > 0)) {
Join<Verification, User> joinVerificatorEmployee = root.join("stateVerificatorEmployee");
Predicate searchByVerificatorName = cb.like(joinVerificatorEmployee.get("firstName"),
"%" + employeeName + "%");
Predicate searchByVerificatorSurname = cb.like(joinVerificatorEmployee.get("lastName"),
"%" + employeeName + "%");
Predicate searchByVerificatorLastName = cb.like(joinVerificatorEmployee.get("middleName"),
"%" + employeeName + "%");
Predicate searchPredicateByVerificatorEmployeeName = cb.or(searchByVerificatorName,
searchByVerificatorSurname, searchByVerificatorLastName);
queryPredicate = cb.and(searchPredicateByVerificatorEmployeeName, queryPredicate);
}

return queryPredicate;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;


/**
* @deprecated this class have a lot of repeated code <br/>
* {need to be replaced and removed}<br/>
* use {@link com.softserve.edu.specification.SpecificationBuilder} instead
*/
@Deprecated
public class CalibrationTestQueryConstructorCalibrator {
static Logger logger = Logger.getLogger(CalibrationTestQueryConstructorCalibrator.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@
import java.time.format.DateTimeFormatter;
import java.util.Set;


/**
* @deprecated this class have a lot of repeated code <br/>
* {need to be replaced and removed}<br/>
* use {@link com.softserve.edu.specification.SpecificationBuilder} instead
*/
@Deprecated
public class NewVerificationsQueryConstructorCalibrator {

static Logger logger = Logger.getLogger(NewVerificationsQueryConstructorProvider.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@
import java.time.format.DateTimeFormatter;
import java.util.Set;


/**
* @deprecated this class have a lot of repeated code <br/>
* {need to be replaced and removed}<br/>
* use {@link com.softserve.edu.specification.SpecificationBuilder} instead
*/
@Deprecated
public class NewVerificationsQueryConstructorProvider {

static Logger logger = Logger.getLogger(NewVerificationsQueryConstructorProvider.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@
import com.softserve.edu.entity.enumeration.user.UserRole;
import com.softserve.edu.entity.enumeration.verification.Status;


/**
* @deprecated this class have a lot of repeated code <br/>
* {need to be replaced and removed}<br/>
* use {@link com.softserve.edu.specification.SpecificationBuilder} instead
*/
@Deprecated
public class NewVerificationsQueryConstructorVerificator {

static Logger logger = Logger.getLogger(NewVerificationsQueryConstructorVerificator.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
import javax.persistence.EntityManager;
import javax.persistence.criteria.*;


/**
* Created by MAX on 11.07.2015.
* @deprecated this class have a lot of repeated code <br/>
* {need to be replaced and removed}<br/>
* use {@link com.softserve.edu.specification.SpecificationBuilder} instead
*/
@Deprecated
public class ProviderEmployeeQuery {

static Logger logger = Logger.getLogger(ArchivalVerificationsQueryConstructorProvider.class);
Expand Down

0 comments on commit 4ca67b4

Please sign in to comment.