Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/main/java/fr/istic/domain/Exam.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ public static long removeIdZoneId(Exam exam) {
if (exam.id == null) {
return 0;
} else {
exam.idzone = null;
return update("idzone = ?1 where id = ?2", null, exam.id);

}
Expand Down
69 changes: 31 additions & 38 deletions src/main/java/fr/istic/service/CacheUploadService.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,15 @@ protected InputStream getObject(String name)

protected void putObject(String name, byte[] bytes, String contenttype)
throws InvalidKeyException, NoSuchAlgorithmException, IllegalArgumentException, IOException {
if (this.fichierS3Service.isObjectExist(name)) {
try {
this.fichierS3Service.deleteObject(name);
} catch (ErrorResponseException | InsufficientDataException | InternalException
| InvalidResponseException | ServerException | XmlParserException e) {
e.printStackTrace();
}

if (this.fichierS3Service.isObjectExist(name)) {
try {
this.fichierS3Service.deleteObject(name);
} catch (ErrorResponseException | InsufficientDataException | InternalException
| InvalidResponseException | ServerException | XmlParserException e) {
e.printStackTrace();
}

}
}
this.fichierS3Service.putObject(name, bytes, contenttype);
}

Expand Down Expand Up @@ -160,7 +159,7 @@ protected void deleteFile(long id) {
if (!customDir.exists()) {
customDir.mkdirs();
}
String fileName = "cache" +File.separator + id + "indexdb.json";
String fileName = "cache" + File.separator + id + "indexdb.json";

fileName = customDir.getAbsolutePath() +
File.separator + fileName;
Expand All @@ -169,11 +168,11 @@ protected void deleteFile(long id) {
} else {
long k = 1;
fileName = customDir.getAbsolutePath() +
File.separator + "cache"+ File.separator + id + "_part_" + k + "_indexdb.json";
File.separator + "cache" + File.separator + id + "_part_" + k + "_indexdb.json";
while (Paths.get(fileName).toFile().exists()) {
Paths.get(fileName).toFile().delete();
k = k + 1;
fileName = "cache" +File.separator + id + "_part_" + k + "_indexdb.json";
fileName = "cache" + File.separator + id + "_part_" + k + "_indexdb.json";
}

}
Expand Down Expand Up @@ -237,7 +236,7 @@ public InputStream getFile(String fileName) throws Exception {
if (!customDir.exists()) {
customDir.mkdirs();
}
File customDir1 = new File(UPLOAD_DIR + File.separator + "cache" );
File customDir1 = new File(UPLOAD_DIR + File.separator + "cache");
if (!customDir1.exists()) {
customDir1.mkdirs();
}
Expand Down Expand Up @@ -371,7 +370,7 @@ public long getCachePageInTemplateSqlite(long id) throws IOException {

// create a connection to the database
conn = DriverManager.getConnection(url);
//TODO
// TODO
String query = "select count(*) from template";
try (Statement stmt = conn.createStatement()) {
ResultSet rs = stmt.executeQuery(query);
Expand Down Expand Up @@ -401,7 +400,7 @@ public long getCachePageInTemplateSqlite(long id) throws IOException {
return 0;
}

public long getCacheTimeStampSqlite(long id) throws IOException {
public long getCacheTimeStampSqlite(long id) throws IOException {

InputStream inputStream = null;
String dbpath = "";
Expand Down Expand Up @@ -471,10 +470,8 @@ public long getCacheTimeStampSqlite(long id) throws IOException {
return 0;
}



public long getCacheTimeStamp(long id) throws IOException{
InputStream inputStream = null;
public long getCacheTimeStamp(long id) throws IOException {
InputStream inputStream = null;
long timestamp = 0;
if (this.uses3) {
String fileName = "cache/" + id + "indexdb.json";
Expand Down Expand Up @@ -510,7 +507,7 @@ public long getCacheTimeStamp(long id) throws IOException{
inputStream = Files.newInputStream(Paths.get(fileName));

} else {
fileName = "cache/" + id + "_exam_template_indexdb.json";
fileName = "cache/" + id + "_exam_template_indexdb.json";
fileName = customDir.getAbsolutePath() +
File.separator + fileName;
if (Paths.get(fileName).toFile().exists()) {
Expand Down Expand Up @@ -548,34 +545,31 @@ public long getCacheTimeStamp(long id) throws IOException{
reader.beginObject();
reader.nextName();
reader.nextString();
reader.nextName();
reader.nextName();
reader.skipValue();
reader.nextName();
reader.beginArray();
while (reader.hasNext()){
reader.beginObject();
reader.nextName();
reader.nextLong();
if (reader.hasNext()){
while (reader.hasNext()) {
reader.beginObject();
reader.nextName();
timestamp= reader.nextLong();
}
reader.endObject();
reader.nextLong();
if (reader.hasNext()) {
reader.nextName();
timestamp = reader.nextLong();
}
reader.endObject();
}
reader.endArray();


reader.endObject();


// reader.endObject();

reader.close();
inputStream.close();
return timestamp;

}

}

public long getCachePageInTemplate(long id) throws IOException {
InputStream inputStream = null;
Expand Down Expand Up @@ -614,7 +608,7 @@ public long getCachePageInTemplate(long id) throws IOException {
inputStream = Files.newInputStream(Paths.get(fileName));

} else {
fileName = "cache/" + id + "_exam_template_indexdb.json";
fileName = "cache/" + id + "_exam_template_indexdb.json";
fileName = customDir.getAbsolutePath() +
File.separator + fileName;
if (Paths.get(fileName).toFile().exists()) {
Expand Down Expand Up @@ -666,16 +660,16 @@ public long getCachePageInTemplate(long id) throws IOException {
reader.nextName();
reader.skipValue();
reader.nextName();
//reader.skipValue();
// reader.skipValue();
reader.beginArray();
while (reader.hasNext()){
while (reader.hasNext()) {

reader.beginObject();
reader.nextName();
reader.nextString();
reader.nextName();
long l = reader.nextLong();
if (l > pageNumber){
if (l > pageNumber) {
pageNumber = l;
}
reader.nextName();
Expand All @@ -694,7 +688,6 @@ public long getCachePageInTemplate(long id) throws IOException {

}


public String getAlignPage(long id, int pagefileter, boolean nonalign) throws IOException {
InputStream inputStream = null;
if (this.uses3) {
Expand Down
125 changes: 70 additions & 55 deletions src/main/java/fr/istic/service/HybridGradedCommentService.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,59 +34,72 @@ public class HybridGradedCommentService {
public HybridGradedCommentDTO persistOrUpdate(HybridGradedCommentDTO hybridGradedCommentDTO) {
log.debug("Request to save HybridGradedComment : {}", hybridGradedCommentDTO);
var hybridGradedComment = hybridGradedCommentMapper.toEntity(hybridGradedCommentDTO);
boolean shouldUpdate =false;
// boolean shouldUpdate = false;

if (hybridGradedComment.id!= null){
if (hybridGradedComment.id != null) {
HybridGradedComment h2 = HybridGradedComment.findById(hybridGradedComment.id);
if (h2 != null){
var oldGrade = h2.grade;
var oldRelative = h2.relative;
var oldStep = h2.step;
if (hybridGradedComment.grade != oldGrade || hybridGradedComment.step != oldStep || hybridGradedComment.relative!= oldRelative){
shouldUpdate =true;
}

}
}
hybridGradedComment = HybridGradedComment.persistOrUpdate(hybridGradedComment);
if (shouldUpdate){
List<Answer2HybridGradedComment> ans = Answer2HybridGradedComment.findAllAnswerHybridGradedCommentByCommentIdWithFetchWithStepvalueUpperThan0(hybridGradedComment.id).list(); //.stream().filter(an3 -> an3.stepValue>0).collect(Collectors.toList());
for( Answer2HybridGradedComment an : ans){
var st = an.studentResponse;
var ans2 = an.studentResponse.hybridcommentsValues;

var currentNote = 0.0;
var absoluteNote2Add = 0.0;
double pourcentage = 0.0;
if (st.question != null && st.question.defaultpoint != null){
pourcentage = st.question.defaultpoint.doubleValue() *4;

}
for (Answer2HybridGradedComment an2 : ans2){
var stepValue = an2.stepValue !=null ? an2.stepValue.doubleValue(): 0.0;
if (stepValue > 0) {
var relative = an2.hybridcomments.relative != null ? an2.hybridcomments.relative : false;
var step = an2.hybridcomments.step != null ? an2.hybridcomments.step.doubleValue() : 1.0;
var grade = an2.hybridcomments.grade != null ? an2.hybridcomments.grade.doubleValue() : 0.0;
if (relative) {
pourcentage = pourcentage + (stepValue / step) * grade;
} else {
absoluteNote2Add = absoluteNote2Add + (stepValue / step) * grade;
if (h2 != null) {
var oldGrade = h2.grade;
var oldRelative = h2.relative;
var oldStep = h2.step;
if (hybridGradedComment.grade != oldGrade || hybridGradedComment.step != oldStep
|| hybridGradedComment.relative != oldRelative) {
List<Answer2HybridGradedComment> ans = Answer2HybridGradedComment
.findAllAnswerHybridGradedCommentByCommentIdWithFetchWithStepvalueUpperThan0(
hybridGradedComment.id)
.list(); // .stream().filter(an3 -> an3.stepValue>0).collect(Collectors.toList());
for (Answer2HybridGradedComment an : ans) {
var st = an.studentResponse;
var ans2 = an.studentResponse.hybridcommentsValues;

var currentNote = 0.0;
var absoluteNote2Add = 0.0;
double pourcentage = 0.0;
if (st.question != null && st.question.defaultpoint != null) {
pourcentage = st.question.defaultpoint.doubleValue() * 4;

}
for (Answer2HybridGradedComment an2 : ans2) {
var stepValue = an2.stepValue != null ? an2.stepValue.doubleValue() : 0.0;
if (stepValue > 0) {
var relative = an2.hybridcomments.relative != null ? an2.hybridcomments.relative
: false;
var step = an2.hybridcomments.step != null ? an2.hybridcomments.step.doubleValue()
: 1.0;
var grade = an2.hybridcomments.grade != null ? an2.hybridcomments.grade.doubleValue()
: 0.0;
if (relative) {
pourcentage = pourcentage + (stepValue / step) * grade;
} else {
absoluteNote2Add = absoluteNote2Add + (stepValue / step) * grade;
}
}
}
}
var point = st.question.quarterpoint !=null ? st.question.quarterpoint.doubleValue(): 0.0;
currentNote = (point * pourcentage) / 400.0 + absoluteNote2Add;
if (currentNote > point && !st.question.canExceedTheMax) {
currentNote = point;
} else if (currentNote < 0 && !st.question.canBeNegative) {
currentNote = 0;
}
var point = st.question.quarterpoint != null ? st.question.quarterpoint.doubleValue() : 0.0;
currentNote = (point * pourcentage) / 400.0 + absoluteNote2Add;
if (currentNote > point && !st.question.canExceedTheMax) {
currentNote = point;
} else if (currentNote < 0 && !st.question.canBeNegative) {
currentNote = 0;
}
st.quarternote = Double.valueOf(currentNote * 100).intValue();
st.persistOrUpdate();
}
st.quarternote = Double.valueOf(currentNote*100).intValue();
st.persistOrUpdate();
}

}

h2.description = hybridGradedComment.description;
h2.grade = hybridGradedComment.grade;
h2.relative = hybridGradedComment.relative;
h2.step = hybridGradedComment.step;
h2.text = hybridGradedComment.text;
hybridGradedComment = HybridGradedComment.persistOrUpdate(h2);


} else {
hybridGradedComment = HybridGradedComment.persistOrUpdate(hybridGradedComment);
}

return hybridGradedCommentMapper.toDto(hybridGradedComment);
}
Expand All @@ -101,10 +114,10 @@ public void delete(Long id) {
log.debug("Request to delete HybridGradedComment : {}", id);
this.answer2HybridGradedCommentService.deleteAllAnswerHybridGradedCommentByCommentId(id);
HybridGradedComment
.findByIdOptional(id)
.ifPresent(hybridGradedComment -> {
hybridGradedComment.delete();
});
.findByIdOptional(id)
.ifPresent(hybridGradedComment -> {
hybridGradedComment.delete();
});
}

/**
Expand All @@ -116,23 +129,25 @@ public void delete(Long id) {
public Optional<HybridGradedCommentDTO> findOne(Long id) {
log.debug("Request to get HybridGradedComment : {}", id);
return HybridGradedComment
.findByIdOptional(id)
.map(hybridGradedComment -> hybridGradedCommentMapper.toDto((HybridGradedComment) hybridGradedComment));
.findByIdOptional(id)
.map(hybridGradedComment -> hybridGradedCommentMapper.toDto((HybridGradedComment) hybridGradedComment));
}

/**
* Get all the hybridGradedComments.
*
* @param page the pagination information.
* @return the list of entities.
*/
public Paged<HybridGradedCommentDTO> findAll(Page page) {
log.debug("Request to get all HybridGradedComments");
return new Paged<>(HybridGradedComment.findAll().page(page))
.map(hybridGradedComment -> hybridGradedCommentMapper.toDto((HybridGradedComment) hybridGradedComment));
.map(hybridGradedComment -> hybridGradedCommentMapper.toDto((HybridGradedComment) hybridGradedComment));
}

public Paged<HybridGradedCommentDTO> findHybridGradedCommentByQuestionId(Page page, long qId) {
log.debug("Request to get all GradedComments by QID");
log.debug("Request to get all GradedComments by QID");
return new Paged<>(HybridGradedComment.findByQuestionId(qId).page(page))
.map(hgradedComment -> hybridGradedCommentMapper.toDto((HybridGradedComment) hgradedComment)); }
.map(hgradedComment -> hybridGradedCommentMapper.toDto((HybridGradedComment) hgradedComment));
}
}
5 changes: 4 additions & 1 deletion src/main/java/fr/istic/service/ZoneService.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ public ZoneDTO persistOrUpdate(ZoneDTO zoneDTO) {

@Transactional
void deleteZone (long id){
Zone.deleteById(id);
Zone z = Zone.findById(id);
z.delete();
}


Expand Down Expand Up @@ -70,6 +71,8 @@ else if (exam.get().firstnamezone != null && exam.get().firstnamezone.id.equals
}
else if (exam.get().idzone != null && exam.get().idzone.id.equals(id)){
Exam.removeIdZoneId(exam.get());
exam.get().idzone = null;

}
else if (exam.get().notezone != null && exam.get().notezone.id.equals(id))
{
Expand Down