Skip to content

Commit

Permalink
Merge branch 'Lv157Final' of https://github.com/Nazariii/calibration-…
Browse files Browse the repository at this point in the history
…devices-system into Lv157Final
  • Loading branch information
volodymyrihnatyev committed Oct 23, 2015
2 parents 8d3dda8 + ad46e2e commit 0b0ffe6
Show file tree
Hide file tree
Showing 29 changed files with 1,188 additions and 27 deletions.
18 changes: 15 additions & 3 deletions database_script.sql
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ INSERT INTO `VERIFICATION`

USE measurement_devices;
INSERT INTO `CALIBRATION_MODULE`
(`id`,`condDesignation`, `deviceType`,`email`,`employeeFullName`,`moduleType`,`organizationCode`,`serialNumber`,`telephone`,`workDate`,`calibratorId`)
(`moduleId`,`condDesignation`, `deviceType`,`email`,`employeeFullName`,`moduleType`,`organizationCode`,`serialNumber`,`telephone`,`workDate`,`calibratorId`)
VALUES
(1,'АС-П', 'WATER', '[email protected]', 'Пупкін Євген Вікторович', 'mobile_station', '569859878', '895678', '0634524378', '2015-10-25', '11'),
(2,'АС-К', 'WATER', '[email protected]', 'Мупкін Орест Вікторович', 'mobile_station', '569859333', '111678', '0634524888', '2015-10-25', '11'),
Expand All @@ -330,9 +330,21 @@ INSERT INTO `CALIBRATION_TEST` VALUES (2, 'В зоні', '2015-07-24 11:49:42',
INSERT INTO `CALIBRATION_TEST` VALUES (3, 'В зоні', '2015-09-15 12:40:30', 76, 77, 'Державна система забезпечення єдності вимірювань', 'ДСТУ 2681-94', 'Successful Test', NULL, 8, 30, 'SUCCESS', 'bbae737e-d7fe-4fff-a4c1-bca0ab5ec706');
INSERT INTO `CALIBRATION_TEST` VALUES (4, 'Придатний', '2015-07-24 11:57:42', 75, 77, 'Державна система забезпечення єдності вимірювань', 'ДСТУ 2681-94', 'Тест №7', NULL, 7, 77, 'SUCCESS', '44479022-k720-5524-ab71-eed574d1b48d');
INSERT INTO `CALIBRATION_TEST` VALUES (5, 'Придатний', '2015-07-24 12:41:42', 72, 75, 'Державна система забезпечення єдності вимірювань', 'ДСТУ 2681-94', 'Тест №7', NULL, 7, 77, 'FAILED', '44479022-k720-5524-ab71-eed574d1b48d');
UPDATE `CALIBRATION_TEST`
/*UPDATE `CALIBRATION_TEST`
SET
`consumptionStatus` = 'IN_THE_AREA';
`consumptionStatus` = 'IN_THE_AREA'
*/


USE measurement_devices;
-- ------------------------------- СALIBRATION DISASSEMBLY TEAM ---------------------------- --
INSERT INTO `DISASSEMBLY_TEAM` (`id`, `name`, `effectiveTo`, `specialization`, `leaderFullName`, `leaderPhone`, `leaderEmail`, `calibratorId`)
VALUES
('1', 'Dart Vader', '2015-10-20', 'WATER', 'Nazarkevych V.T.', '957000105', '[email protected]', '11'),
('2', 'Dart', '2015-10-24', 'WATER', 'Nazarkevych V.T.', '957000105', '[email protected]', '11'),
('3', 'Dart Vader 1', '2015-10-24', 'WATER', 'Nazarkevych V.T.', '957000105', '[email protected]', '11'),
('4', 'Dart Vader 2', '2015-11-24', 'WATER', 'Nazarkevych V.T.', '957000105', '[email protected]', '11');



UPDATE `VERIFICATION`
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package com.softserve.edu.entity.catalogue.Team;


import com.softserve.edu.entity.device.Device;
import com.softserve.edu.entity.organization.Organization;
import lombok.*;

import javax.persistence.*;
import java.util.Date;

/**
* Disassembly team entity. Contain information about teams.
*/
@Entity
@Getter
@Setter
@EqualsAndHashCode(of = "id")
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Table(name = "DISASSEMBLY_TEAM")
public class DisassemblyTeam {

@Setter(AccessLevel.PRIVATE)
@Id
private String id;

private String name;

@Temporal(TemporalType.DATE)
private Date effectiveTo;

@Enumerated(EnumType.STRING)
private Device.DeviceType specialization;

private String leaderFullName;

private String leaderPhone;

private String leaderEmail;

@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "calibratorId")
private Organization organization;

public DisassemblyTeam(String id, String name, Date effectiveTo, Device.DeviceType specialization, String leaderFullName,
String leaderPhone, String leaderEmail) {
this.id = id;
this.name = name;
this.effectiveTo = effectiveTo;
this.specialization = specialization;
this.leaderFullName = leaderFullName;
this.leaderPhone = leaderPhone;
this.leaderEmail = leaderEmail;
}

@Override
public String toString() {
return "DisassemblyTeam{" +
"id='" + id + '\'' +
", name='" + name + '\'' +
", effectiveTo=" + effectiveTo +
", specialization=" + specialization +
", leaderFullName='" + leaderFullName + '\'' +
", leaderPhone='" + leaderPhone + '\'' +
", leaderEmail='" + leaderEmail + '\'' +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

import lombok.*;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.*;


@Entity
Expand All @@ -16,9 +13,9 @@
@NoArgsConstructor
public class MeasuringEquipment {

@Id
@GeneratedValue
@Setter(AccessLevel.PRIVATE)
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

private String name;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
package com.softserve.edu.entity.organization;

import com.fasterxml.jackson.annotation.JsonBackReference;

import com.softserve.edu.entity.Address;
import com.softserve.edu.entity.catalogue.Locality;
import com.softserve.edu.entity.catalogue.Team.DisassemblyTeam;
import com.softserve.edu.entity.device.CalibrationModule;
import com.softserve.edu.entity.device.Device;
import com.softserve.edu.entity.enumeration.organization.OrganizationType;
import com.softserve.edu.entity.user.User;
import com.softserve.edu.entity.verification.calibration.CalibrationTask;

import lombok.*;
import org.hibernate.annotations.*;


import javax.persistence.*;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
Expand Down Expand Up @@ -67,6 +61,10 @@ public class Organization {
@JsonBackReference
private Set<CalibrationModule> modules = new HashSet<>();

@OneToMany(mappedBy = "organization", cascade = CascadeType.ALL)
@JsonBackReference
private Set<DisassemblyTeam> disassemblyTeams = new HashSet<>();

@OneToMany(mappedBy = "organization", cascade = CascadeType.ALL)
@JsonBackReference
private Set<CalibrationTask> tasks = new HashSet<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
@Table(name = "VERIFICATION")
public class Verification {

@Id
@Setter(AccessLevel.PRIVATE)
@Id
private String id;

@Enumerated(EnumType.STRING)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.softserve.edu.repository;

import com.softserve.edu.entity.catalogue.Team.DisassemblyTeam;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;


public interface CalibrationDisassemblyTeamRepository extends
PagingAndSortingRepository<DisassemblyTeam, String>, JpaSpecificationExecutor {

Page<DisassemblyTeam> findAll(Pageable pageable);

//Page<DisassemblyTeam> findByCalibratorId(Long calibratorId, Pageable pageable);

Page<DisassemblyTeam> findByNameLikeIgnoreCase(String name, Pageable pageable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
@Repository
public interface MeasuringEquipmentRepository extends CrudRepository<MeasuringEquipment, Long> {

public Page<MeasuringEquipment> findAll(Pageable pageable);
Page<MeasuringEquipment> findAll(Pageable pageable);
Page<MeasuringEquipment> findByNameLikeIgnoreCase(String name, Pageable pageable);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.softserve.edu.service.calibrator;


import com.softserve.edu.entity.catalogue.Team.DisassemblyTeam;
import com.softserve.edu.entity.device.Device;
import com.softserve.edu.service.exceptions.DuplicateRecordException;
import org.springframework.data.domain.Page;

import java.util.Date;
import java.util.List;

public interface CalibratorDisassemblyTeamService {

List<DisassemblyTeam> getAll();

Page<DisassemblyTeam> getDisassemblyTeamBySearchAndPagination(int pageNumber,int itemsPerPage, String search);

void addDisassemblyTeam(DisassemblyTeam disassemblyTeam) throws DuplicateRecordException;

DisassemblyTeam getDisassemblyTeamById(String teamId);

void editDisassemblyTeam(String id, String name, Date effectiveTo, Device.DeviceType specialization, String leaderFullName,
String leaderPhone, String leaderEmail);

void deleteDisassemblyTeam(String teamId);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package com.softserve.edu.service.calibrator.impl;

import com.softserve.edu.entity.catalogue.Team.DisassemblyTeam;
import com.softserve.edu.entity.device.Device;
import com.softserve.edu.repository.CalibrationDisassemblyTeamRepository;
import com.softserve.edu.service.calibrator.CalibratorDisassemblyTeamService;
import com.softserve.edu.service.exceptions.DuplicateRecordException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;


@Service
public class CalibrationDisassemblyTeamServiceImpl implements CalibratorDisassemblyTeamService {

@Autowired
private CalibrationDisassemblyTeamRepository teamRepository;

@Override
@Transactional
public List<DisassemblyTeam> getAll() {
return (List<DisassemblyTeam>) teamRepository.findAll();
}

@Override
@Transactional
public Page<DisassemblyTeam> getDisassemblyTeamBySearchAndPagination(int pageNumber, int itemsPerPage, String search) {
PageRequest pageRequest = new PageRequest(pageNumber - 1, itemsPerPage);
return search == null ? teamRepository.findAll(pageRequest) :
teamRepository.findByNameLikeIgnoreCase("%" + search + "%", pageRequest);
}

@Override
@Transactional
public void addDisassemblyTeam(DisassemblyTeam disassemblyTeam) throws DuplicateRecordException {
try {
teamRepository.save(disassemblyTeam);
} catch (Exception e) {
throw new DuplicateRecordException(String.format("Team %s already exists.", disassemblyTeam.getId()));
}
}

@Override
@Transactional
public DisassemblyTeam getDisassemblyTeamById(String teamId) {
return teamRepository.findOne(teamId);
}

@Override
@Transactional
public void editDisassemblyTeam(String id, String name, Date effectiveTo, Device.DeviceType specialization,
String leaderFullName, String leaderPhone, String leaderEmail) {
DisassemblyTeam team = teamRepository.findOne(id);
team.setName(name);
team.setEffectiveTo(effectiveTo);
team.setSpecialization(specialization);
team.setLeaderFullName(leaderFullName);
team.setLeaderPhone(leaderPhone);
team.setLeaderEmail(leaderEmail);
teamRepository.save(team);
}

@Override
@Transactional
public void deleteDisassemblyTeam(String teamId) {
teamRepository.delete(teamRepository.findOne(teamId));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package com.softserve.edu.service.calibrator.specifications;

import com.softserve.edu.entity.catalogue.Team.DisassemblyTeam;
import com.softserve.edu.entity.device.Device;
import org.springframework.data.jpa.domain.Specification;

import java.util.Date;

/**
* Created for filtering data using PagingAndSortingRepository
*/
public class CalibrationDisassenblyTeamSpecifications {

/**
* build query for id, filtering by id
* @param id
* @return query, for searching
*/
public static Specification<DisassemblyTeam> disassemblyTeamHasId(String id) {
return (root, criteriaQuery, criteriaBuilder) -> criteriaBuilder.equal(root.get("id"), id);
}

/**
* build query for name, filtering by name
* @param name
* @return query, for searching
*/
public static Specification<DisassemblyTeam> disassemblyTeamHasName(String name) {
return (root, criteriaQuery, criteriaBuilder) -> criteriaBuilder.equal(root.get("name"), name);
}

/**
* build query for effectiveTo, filtering by effective
* @param effectiveTo
* @return query, for searching
*/
public static Specification<DisassemblyTeam> disassemblyTeamHasEffectiveTo(Date effectiveTo) {
return (root, criteriaQuery, criteriaBuilder) -> criteriaBuilder.lessThan(root.get("effectiveTo"), effectiveTo);
}

/**
* build query for disassemblyTeamType, filtering by disassemblyTeamType
* @param disassemblyTeamType
* @return query, for searching
*/
public static Specification<DisassemblyTeam> disassemblyTeamHasType(Device.DeviceType disassemblyTeamType){
return (root, criteriaQuery, criteriaBuilder) ->
criteriaBuilder.equal(root.get("specialization"), disassemblyTeamType);
}

/**
* build query for leaderFullName, filtering by leaderFullName
* @param leaderFullName
* @return query, for searching
*/
public static Specification<DisassemblyTeam> disassemblyTeamHasLeaderFullName(String leaderFullName) {
return (root, criteriaQuery, criteriaBuilder) ->
criteriaBuilder.equal(root.get("leaderFullName"), leaderFullName);
}

/**
* build query for leaderPhone, filtering by leaderPhone
* @param leaderPhone
* @return query, for searching
*/
public static Specification<DisassemblyTeam> disassemblyTeamHasLeaderPhone(String leaderPhone) {
return (root, criteriaQuery, criteriaBuilder) -> criteriaBuilder.equal(root.get("leaderPhone"), leaderPhone);
}

/**
* build query for leaderEmail, filtering by leaderEmail
* @param leaderEmail
* @return query, for searching
*/
public static Specification<DisassemblyTeam> disassemblyTeamHasLeaderEmail(String leaderEmail) {
return (root, criteriaQuery, criteriaBuilder) -> criteriaBuilder.equal(root.get("leaderEmail"), leaderEmail);
}

public static Specification<DisassemblyTeam> disassemblyTeamHasCalibratorId(Long calibratorId){
return (root, criteriaQuery, criteriaBuilder) ->
criteriaBuilder.equal(root.get("organization").get("id"), calibratorId);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.softserve.edu.service.exceptions;

import lombok.NoArgsConstructor;

@NoArgsConstructor
public class DuplicateRecordException extends Exception {
public DuplicateRecordException(String format) {
super(format);
}
}
Loading

0 comments on commit 0b0ffe6

Please sign in to comment.