Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public UupPotentialPrevention create(@NonNull Case admCase) {
- checkArgument(admCase.getCitizen() != null, "Can't create UupPotentialPrevention, citizen is null, caseId = %s", admCase.getCaseId());
- log.info("Creating UupPotentialPrevention, caseId = {}", admCase.getCaseId());
- UupPrevention prevention = uupPreventionService.findByCitizenId(admCase.getCitizen().getCitizenId());
- House house = houseService.findHouseByAddressId(admCase.getCommitAddress().getAddressId());
- AdmDistrict district = house != null ? house.getDistrict() : null;
- if (prevention != null) {
- if (uupPreventionService.hasActiveMonitoringWithCategory(prevention, UUP_PREVENTIVE_CATEGORY_OFFENSE_IN_FAMILY_RELATIONS)) {
- return null;
- }
- if (district == null || uupPreventionService.hasActiveMonitoring(admCase.getCitizen().getCitizenId())) {
- district = prevention.getDistrict();
- }
- }
- UupPotentialPrevention entity = new UupPotentialPrevention();
- entity.setAdmDistrict(district);
- entity.setDepartment(district != null && district.getDepartment() != null ? district.getDepartment() : admCase.getDepartment());
- entity.setAdmCase(admCase);
- entity.setPreventiveCategory(listService.findElement(ListEntityItem.PREVENTIVE_CATEGORY, UUP_PREVENTIVE_CATEGORY_OFFENSE_IN_FAMILY_RELATIONS));
- if (admCase.getResolutions() != null) {
- admCase.getResolutions().stream()
- .filter(r -> isAdmPunishmentResolutionType(r.getResolutionType().getReferenceId()))
- .findFirst()
- .map(Resolution::getMainPunishment)
- .map(Punishment::getPunishmentTypeElm)
- .ifPresent(entity::setMainPunishmentType);
- }
- repository.save(entity);
- log.info("created UupPotentialPrevention with id = {}", entity.getPotentialPreventionId());
- return entity;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement