Export csv data
This commit is contained in:
86
buisnesslogic/src/main/java/com/plannaplan/models/ExportData.java
Executable file
86
buisnesslogic/src/main/java/com/plannaplan/models/ExportData.java
Executable file
@ -0,0 +1,86 @@
|
||||
package com.plannaplan.models;
|
||||
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* Container to keep data to export
|
||||
*/
|
||||
public class ExportData {
|
||||
|
||||
private static final String GROUP_FIELD = "gr_nr";
|
||||
private static final String USER_FIELD = "user_id";
|
||||
private static final String CYKL_FIELD = "zaj_cykl_id";
|
||||
|
||||
private String userId;
|
||||
private String zajCyklId;
|
||||
private String grNr;
|
||||
|
||||
/**
|
||||
* @param userId usosid
|
||||
* @param zajCyklId course cycle
|
||||
* @param grNr group number
|
||||
*/
|
||||
public ExportData(String userId, String zajCyklId, String grNr) {
|
||||
this.setUserId(userId);
|
||||
this.setZajCyklId(zajCyklId);
|
||||
this.setGrNr(grNr);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return group number
|
||||
*/
|
||||
public String getGrNr() {
|
||||
return grNr;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param grNr group number
|
||||
*/
|
||||
public void setGrNr(String grNr) {
|
||||
this.grNr = grNr;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return course cycle
|
||||
*/
|
||||
public String getZajCyklId() {
|
||||
return zajCyklId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param zajCyklId course cycle
|
||||
*/
|
||||
public void setZajCyklId(String zajCyklId) {
|
||||
this.zajCyklId = zajCyklId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return usosid
|
||||
*/
|
||||
public String getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param userId usosid
|
||||
*/
|
||||
public void setUserId(String userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return csv fromated line
|
||||
*/
|
||||
public String convertToCSVRecord() {
|
||||
return Stream.of(this.userId, this.zajCyklId, this.grNr).collect(Collectors.joining(","));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return csv formated first line
|
||||
*/
|
||||
public static String getCSVHeader() {
|
||||
return USER_FIELD + ", " + CYKL_FIELD + ", " + GROUP_FIELD;
|
||||
}
|
||||
|
||||
}
|
@ -1,10 +1,12 @@
|
||||
package com.plannaplan.services;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import com.plannaplan.entities.Commision;
|
||||
import com.plannaplan.entities.User;
|
||||
import com.plannaplan.models.ExportData;
|
||||
import com.plannaplan.repositories.AssignmentRepository;
|
||||
import com.plannaplan.repositories.CommisionRepository;
|
||||
|
||||
@ -22,6 +24,8 @@ public class CommisionService {
|
||||
private CommisionRepository repo;
|
||||
@Autowired
|
||||
private AssignmentRepository aRepository;
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
public CommisionService() {
|
||||
}
|
||||
@ -77,4 +81,21 @@ public class CommisionService {
|
||||
public long getCommisionsAmmount() {
|
||||
return this.repo.count();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list of ExportData inmstancces keeping data to exprt to file
|
||||
*/
|
||||
public List<ExportData> getExportData() {
|
||||
final List<ExportData> response = new ArrayList<>();
|
||||
|
||||
this.userService.getAllStudents().forEach(student -> {
|
||||
student.getStudentRegisteredGrups().forEach(group -> {
|
||||
response.add(new ExportData(student.getUsosId(), Integer.toString(group.getZajCykId()),
|
||||
Integer.toString(group.getGrNr())));
|
||||
});
|
||||
});
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user