Buisness logic docs updated
This commit is contained in:
@ -29,6 +29,13 @@ public class CommisionService {
|
||||
public CommisionService() {
|
||||
}
|
||||
|
||||
/**
|
||||
* save to database commision. It also checks for missing assignments from
|
||||
* previous commision (you can not get rid of accepted assignment)
|
||||
*
|
||||
* @param commision to save to db
|
||||
* @return Commision instance with id from database
|
||||
*/
|
||||
public Commision save(Commision commision) {
|
||||
Optional<Commision> lastCommision = this.getNewestCommision(commision.getCommisionOwner());
|
||||
if (lastCommision.isPresent()) {
|
||||
|
@ -10,7 +10,8 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* Service of CourseService which can get(Course By Name, All Courses, Courses Ammount ), save, delete course.
|
||||
* Service of CourseService which can get(Course By Name, All Courses, Courses
|
||||
* Ammount ), save, delete course.
|
||||
*/
|
||||
|
||||
@Service
|
||||
@ -18,42 +19,46 @@ public class CourseService {
|
||||
@Autowired
|
||||
private CourseRepository repo;
|
||||
|
||||
/*
|
||||
/**
|
||||
* getCourseByName
|
||||
* Return Course By Name
|
||||
*
|
||||
* @param name
|
||||
* @return Course By Name
|
||||
*/
|
||||
public Optional<Course> getCourseByName(String name) {
|
||||
return this.repo.findByName(name);
|
||||
}
|
||||
|
||||
/*
|
||||
* getAllCourses
|
||||
* Return List of get courses
|
||||
/**
|
||||
*
|
||||
* @return all courses from db
|
||||
*/
|
||||
public List<Course> getAllCourses() {
|
||||
return this.repo.findAll();
|
||||
}
|
||||
|
||||
/*
|
||||
* save
|
||||
/**
|
||||
* save to db
|
||||
*
|
||||
* @param course which course you would like to save
|
||||
* @return Course instance with id from db
|
||||
*/
|
||||
public Course save(Course course) {
|
||||
this.repo.save(course);
|
||||
return course;
|
||||
}
|
||||
|
||||
/*
|
||||
* delete
|
||||
/**
|
||||
* delete course from db
|
||||
*
|
||||
* @param course which course you would like to delete
|
||||
*/
|
||||
public void delete(Course course) {
|
||||
this.repo.delete(course);
|
||||
}
|
||||
|
||||
/*
|
||||
* getCoursesAmmount
|
||||
* Return a ammount of courses
|
||||
/**
|
||||
* @return ammount of courses in db
|
||||
*/
|
||||
public int getCoursesAmmount() {
|
||||
return (int) this.repo.count();
|
||||
|
@ -12,6 +12,9 @@ import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
|
||||
import org.springframework.scheduling.support.CronTrigger;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* Service to manage app events
|
||||
*/
|
||||
@Service
|
||||
public class EventService {
|
||||
|
||||
@ -29,6 +32,9 @@ public class EventService {
|
||||
System.out.println("Checking for groups");
|
||||
}
|
||||
|
||||
/**
|
||||
* perfroms checks for matching exchanges daily
|
||||
*/
|
||||
@Scheduled(cron = "0 0 0 * * *")
|
||||
public void performExchangeService() {
|
||||
System.out.println("Performing Exchange");
|
||||
@ -53,6 +59,10 @@ public class EventService {
|
||||
jobsMap.put(taskId, scheduledTask);
|
||||
}
|
||||
|
||||
/**
|
||||
* init resources needed for dynamicly creating new tasks (needed to set tours
|
||||
* end events)
|
||||
*/
|
||||
@PostConstruct
|
||||
public void initialize() {
|
||||
this.scheduler = new ThreadPoolTaskScheduler();
|
||||
|
@ -19,6 +19,9 @@ import com.plannaplan.repositories.ExchangeRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* Service to manage Exchanges
|
||||
*/
|
||||
@Service
|
||||
public class ExchangeService {
|
||||
|
||||
@ -50,6 +53,9 @@ public class ExchangeService {
|
||||
return this.repo.findById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list of all exchanges in database
|
||||
*/
|
||||
public List<Exchange> getAllExchanges() {
|
||||
return this.repo.findAll();
|
||||
}
|
||||
@ -78,6 +84,12 @@ public class ExchangeService {
|
||||
return this.repo.checkForExchange(assignment, group);
|
||||
}
|
||||
|
||||
/**
|
||||
* method to perform Exchange algorythm. It search for matches and swap
|
||||
* assignments between latests user commisions if it can be performed. After
|
||||
* swap we block users matches that contains switched groups. After algorythm
|
||||
* email is being sent to all users with information about performed exchanges
|
||||
*/
|
||||
public void performExchange() {
|
||||
final List<MatchData> matchData = this.getMatches();
|
||||
final List<Long> performedAssignmentExchanges = new ArrayList<>();
|
||||
@ -127,6 +139,9 @@ public class ExchangeService {
|
||||
this.repo.deleteAll(exchangesToDelete);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list of matches found in database
|
||||
*/
|
||||
public List<MatchData> getMatches() {
|
||||
final List<MatchData> matches = this.repo.getMatches().stream().map(m -> {
|
||||
final Exchange exchangeOne = (Exchange) m[0];
|
||||
|
@ -18,7 +18,6 @@ import org.springframework.stereotype.Service;
|
||||
* Service of GroupService which can find(optional), get(By Course, Groups
|
||||
* Ammount, Group By Id, find Not Existing Group), save, delete group.
|
||||
*/
|
||||
|
||||
@Service
|
||||
public class GroupService {
|
||||
@Autowired
|
||||
@ -27,34 +26,84 @@ public class GroupService {
|
||||
public GroupService() {
|
||||
}
|
||||
|
||||
/**
|
||||
* find group with given properties
|
||||
*
|
||||
* @param time scheduled time for group as int of minutes passed from 00:00
|
||||
* @param capacity capacity of group
|
||||
* @param room class room
|
||||
* @return optional with Groups instance if found
|
||||
*/
|
||||
public Optional<Groups> find(int time, int capacity, String room) {
|
||||
return this.repo.find(time, room, capacity);
|
||||
}
|
||||
|
||||
/**
|
||||
* find group with given properties
|
||||
*
|
||||
* @param zajCykId proteprty from usos
|
||||
* @param nrGr group number
|
||||
* @return optional with Groups instance if found
|
||||
*/
|
||||
public Optional<Groups> find(Integer zajCykId, Integer nrGr) {
|
||||
return this.repo.find(zajCykId, nrGr);
|
||||
}
|
||||
|
||||
/**
|
||||
* find group with given properties
|
||||
*
|
||||
* @param id course id of groups belogns to
|
||||
* @return list of found groups
|
||||
*/
|
||||
public List<Groups> getGroupsByCourse(Long id) {
|
||||
return this.repo.getByCourse(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* save group to database
|
||||
*
|
||||
* @param group insatnce to be saved
|
||||
* @return new instance that has id form database
|
||||
*/
|
||||
public Groups save(Groups group) {
|
||||
return this.repo.save(group);
|
||||
}
|
||||
|
||||
/**
|
||||
* delete from database
|
||||
*
|
||||
* @param groups isntance to delete
|
||||
*/
|
||||
public void delete(Groups groups) {
|
||||
this.repo.delete(groups);
|
||||
}
|
||||
|
||||
/**
|
||||
* get hom manyh groups are in database in general
|
||||
*
|
||||
* @return int - groups ammount
|
||||
*/
|
||||
public int getGroupsAmmount() {
|
||||
return (int) this.repo.count();
|
||||
}
|
||||
|
||||
/**
|
||||
* find group with given properties
|
||||
*
|
||||
* @param id group id
|
||||
* @return optional with group if found
|
||||
*/
|
||||
public Optional<Groups> getGroupById(Long id) {
|
||||
return this.repo.findById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* get wich of provided id is not existind groups
|
||||
*
|
||||
* @param ids list of ids to check
|
||||
* @return optional with id that is not group if found. If there is multiple
|
||||
* will be returned first found
|
||||
*/
|
||||
public Optional<Long> findNotExistingGroup(List<Long> ids) {
|
||||
for (Long oneId : ids) {
|
||||
if (this.repo.existsById(oneId) == false) {
|
||||
|
Reference in New Issue
Block a user