Merge branch 'lastdev' of https://github.com/ArenMg/aren into lastdev

This commit is contained in:
Henintsoa 2021-11-11 09:48:30 +03:00
commit 9ba4c7b813
14 changed files with 356 additions and 31 deletions

View file

@ -99,6 +99,9 @@ public class Debate extends AbstractOwnedEntity implements Serializable {
@Column(name = "open_public")
private boolean openPublic = false;
@Column(name = "is_carto")
private boolean carto = false;
/**
*
* @return
@ -346,6 +349,22 @@ public class Debate extends AbstractOwnedEntity implements Serializable {
this.openPublic = openPublic;
}
/**
*
* @return
*/
public boolean isCarto() {
return carto;
}
/**
*
* @param carto
*/
public void setCarto(boolean carto) {
this.carto = carto;
}
/**
*
* @return

View file

@ -59,6 +59,21 @@ public class Document extends AbstractDatedEntity implements Serializable {
@Column(name = "debates_count")
private Integer debatesCount = 0;
@Column(name = "is_carto")
private boolean carto = false;
@Column(name = "mesh_line")
private int meshLine = 1;
@Column(name = "mesh_column")
private int meshColumn = 1;
@Lob
@Type(type = "org.hibernate.type.TextType")
@Column(name = "map_link")
private String mapLink;
/**
*
* @return
@ -165,6 +180,54 @@ public class Document extends AbstractDatedEntity implements Serializable {
return debates.isEmpty();
}
/**
*
* @return
*/
public boolean isCarto() {
return carto;
}
/**
*
* @param carto
*/
public void setCarto(boolean carto) {
this.carto = carto;
}
/**
*
* @return
*/
public int getMeshLine() {
return meshLine;
}
/**
*
* @param meshLine
*/
public void setMeshLine(int meshLine) {
this.meshLine = meshLine;
}
public int getMeshColumn() {
return meshColumn;
}
public void setMeshColumn(int meshColumn) {
this.meshColumn = meshColumn;
}
public String getMapLink() {
return mapLink;
}
public void setMapLink(String mapLink) {
this.mapLink = mapLink;
}
/**
*
* @return

View file

@ -58,6 +58,10 @@ public class Team extends AbstractEntEntity implements Serializable {
@Column(name = "debates_count")
private Integer debatesCount = 0;
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
@Column(name = "debates_carto_count")
private Integer debatesCartoCount = 0;
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
@Column(name = "users_count")
private Integer usersCount = 0;

View file

@ -290,6 +290,7 @@ public class User extends AbstractEntEntity implements Serializable {
this.invitedDebates = invitedDebates;
}
/**
*
* @return

View file

@ -0,0 +1,38 @@
package fr.lirmm.aren.model.vm;
import java.time.ZonedDateTime;
import java.util.List;
import java.util.Set;
/**
* @author ANDRIAMBOLAHARIMIHANTA Havana on 01/08/2021
* @project aren-1
*/
public class VMNotification {
private String link ;
private List<String>emails ;
private String expiracy ;
public String getLink() {
return link;
}
public void setLink(String link) {
this.link = link;
}
public List<String> getEmails() {
return emails;
}
public void setEmails(List<String> emails) {
this.emails = emails;
}
public String getExpiracy() {
return expiracy;
}
public void setExpiracy(String expiracy) {
this.expiracy = expiracy;
}
}

View file

@ -58,36 +58,36 @@ public class DebateService extends AbstractService<Debate> {
boolean isUser = user != null && user.is(Authority.USER) && !user.is(Authority.ADMIN);
boolean onlyPublic = user != null && user.getAuthority().equals(Authority.GUEST);
TypedQuery<Debate> query = getEntityManager().createQuery("SELECT d "
+ "FROM Debate d "
+ (withComments
+ "FROM Debate d "
+ (withComments
? "LEFT JOIN FETCH d.comments c "
: "")
+ (withTeams || withUsers || isUser
+ (withTeams || withUsers || isUser
? "LEFT JOIN " + (withTeams || withUsers ? "FETCH" : "") + " d.teams t "
: "")
+ (withUsers || isUser
+ (withUsers || isUser
? "LEFT JOIN " + (withUsers ? "FETCH" : "") + " t.users u "
: "")
+ (withGuests || isUser
+ (withGuests || isUser
? "LEFT JOIN " + (withGuests ? "FETCH" : "") + " d.guests g "
: "")
+ (withDocument
+ (withDocument
? "LEFT JOIN FETCH d.document do "
: "")
+ (debateId != null
+ (debateId != null
? "WHERE d.id = :debateId "
: "WHERE d.id IS NOT NULL ")
+ (categoryId != null
+ (categoryId != null
? "AND d.document.category.id = :categoryId "
: "")
+ (isUser
+ (isUser
? "AND (d.openPublic IS TRUE "
+ "OR :user = d.owner "
+ "OR :user IN g "
+ "OR :user IN u) "
: (onlyPublic
? "AND d.openPublic IS TRUE "
: "")),
? "AND d.openPublic IS TRUE "
: "")),
Debate.class
);
@ -122,6 +122,26 @@ public class DebateService extends AbstractService<Debate> {
return results.get(0);
}
public void remove(Long debateId){
super.transactionBegin();
try{
getEntityManager().createNativeQuery("DELETE FROM debates_teams WHERE debate_id=:debateId")
.setParameter("debateId",debateId)
.executeUpdate() ;
getEntityManager().createNativeQuery("DELETE FROM debates_guests WHERE debate_id=:debateId")
.setParameter("debateId",debateId)
.executeUpdate() ;
getEntityManager().createNativeQuery("DELETE FROM notifications WHERE debate_id = :debateId")
.setParameter("debateId", debateId)
.executeUpdate();
super.commit();
Debate debate=super.find(debateId) ;
super.remove(debate);
}catch (Exception e){
e.printStackTrace();
}
}
/**
*
* @param user
@ -172,15 +192,15 @@ public class DebateService extends AbstractService<Debate> {
public void clearComments(Long debateId) {
this.transactionBegin();
getEntityManager().createQuery("DELETE FROM Comment c "
+ "WHERE c.debate.id = :debateId")
+ "WHERE c.debate.id = :debateId")
.setParameter("debateId", debateId)
.executeUpdate();
getEntityManager().createQuery("UPDATE Debate d SET "
+ "d.commentsCount = 0, "
+ "d.commentsCountFor = 0, "
+ "d.commentsCountAgainst = 0, "
+ "d.lastCommentDate = null "
+ "WHERE d.id = :debateId")
+ "d.commentsCount = 0, "
+ "d.commentsCountFor = 0, "
+ "d.commentsCountAgainst = 0, "
+ "d.lastCommentDate = null "
+ "WHERE d.id = :debateId")
.setParameter("debateId", debateId)
.executeUpdate();
this.commit();
@ -193,18 +213,18 @@ public class DebateService extends AbstractService<Debate> {
public void updateExternaleTables(Debate debate) {
super.transactionBegin();
getEntityManager().createQuery("UPDATE Category c SET "
+ "c.debatesCount = (SELECT COUNT(d) FROM c.documents doc LEFT JOIN doc.debates d) "
+ "WHERE c.id = :id")
+ "c.debatesCount = (SELECT COUNT(d) FROM c.documents doc LEFT JOIN doc.debates d) "
+ "WHERE c.id = :id")
.setParameter("id", debate.getDocument().getCategory().getId())
.executeUpdate();
getEntityManager().createQuery("UPDATE Document doc SET "
+ "doc.debatesCount = (SELECT COUNT(d) FROM doc.debates d) "
+ "WHERE doc.id = :id")
+ "doc.debatesCount = (SELECT COUNT(d) FROM doc.debates d) "
+ "WHERE doc.id = :id")
.setParameter("id", debate.getDocument().getId())
.executeUpdate();
getEntityManager().createQuery("UPDATE Team t SET "
+ "t.debatesCount = (SELECT COUNT(d) from t.debates d) "
+ "WHERE t IN (SELECT t1 FROM Debate d LEFT JOIN d.teams t1 WHERE d.id = :id)")
+ "t.debatesCount = (SELECT COUNT(d) from t.debates d) "
+ "WHERE t IN (SELECT t1 FROM Debate d LEFT JOIN d.teams t1 WHERE d.id = :id)")
.setParameter("id", debate.getId())
.executeUpdate();
super.commit();

View file

@ -0,0 +1,125 @@
package fr.lirmm.aren.service.vm;
import com.fasterxml.jackson.databind.ObjectMapper;
import fr.lirmm.aren.model.User;
import fr.lirmm.aren.model.vm.VMNotification;
import fr.lirmm.aren.model.vm.VMTheme;
import fr.lirmm.aren.producer.Configurable;
import fr.lirmm.aren.service.MailingService;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.mail.*;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import java.io.File;
import java.text.MessageFormat;
import java.time.ZonedDateTime;
import java.util.*;
/**
* @author ANDRIAMBOLAHARIMIHANTA Havana on 18/07/2021
* @project aren-1
*/
@ApplicationScoped
public class VMSendNotificationService extends Thread implements Runnable{
@Inject
@Configurable("reverse-proxy")
private String reverseProxy;
public VMSendNotificationService() {
}
@Override
public void run(){
int i=0 ;
try {
VMNotification notification=null ;
while(true){
File file = new File("/aren/tmp/vote_majoritaire.json");
if((file.exists() && notification==null) || notification.getEmails().size()==0){
ObjectMapper mapper = new ObjectMapper();
Map<?, ?> map = (Map<String, Object>) mapper.readValue(file, Map.class);
notification=new VMNotification() ;
for (Map.Entry<?, ?> entry : map.entrySet()) {
switch(entry.getKey().toString()){
case "link":
notification.setLink(entry.getValue().toString());
break;
case "expiracy":
notification.setExpiracy(entry.getValue().toString());
break;
case "emails":
notification.setEmails((List<String>) entry.getValue());
break;
}
}
}
if(notification!=null){
final String link=notification.getLink() ;
ZonedDateTime dateTime=ZonedDateTime.now();
if(dateTime.getHour()==20 && dateTime.getMinute()==0 && dateTime.getSecond()==0) {
notification.getEmails().forEach(email->{
try {
sendNotification(link,email,"mail_vm_notification_subject","mail_vm_notification_body");
} catch (MessagingException e) {
e.printStackTrace();
}
}) ;
}
}
i++ ;
Thread.sleep(1000);
}
}catch (Exception ex){
ex.printStackTrace();
}
}
private void sendNotification(String link, String adress, String subject, String body) throws MessagingException {
Locale currentLocale = Locale.getDefault();
ResourceBundle messages = ResourceBundle.getBundle("messages", currentLocale);
ResourceBundle application_config = ResourceBundle.getBundle("application", currentLocale);
String localSubject;
String localBody;
localSubject = messages.getString(subject);
localBody = MessageFormat.format(messages.getString(body), link, link);
System.out.println(localBody) ;
Properties properties=System.getProperties() ;
properties.put("mail.smtp.host",application_config.getString("smtp.server")) ;
properties.put("mail.smtp.auth", application_config.getString("smtp.auth"));
properties.put("mail.smtp.starttls.enable", application_config.getString("smtp.tls"));
properties.put("mail.smtp.port", application_config.getString("smtp.port"));
Authenticator auth = new Authenticator() {
//override the getPasswordAuthentication method
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(application_config.getString("smtp.username"), application_config.getString("smtp.password"));
}
};
Session session = Session.getInstance(properties,auth) ;
// Create a default MimeMessage object.
Message message = new MimeMessage(session);
// Set From: header field of the header.
message.setFrom(new InternetAddress(application_config.getString("smtp.username")));
// Set To: header field of the header.
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse(adress));
// Set Subject: header field
message.setSubject(localSubject);
// Send the actual HTML message, as big as you like
message.setContent(localBody, "text/html");
// Send message
Transport.send(message);
}
}

View file

@ -7,6 +7,8 @@ import fr.lirmm.aren.service.AbstractService;
import javax.enterprise.context.ApplicationScoped;
import javax.persistence.TypedQuery;
import javax.ws.rs.NotFoundException;
import java.io.File;
import java.io.IOException;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@ -35,8 +37,10 @@ public class VMThemeService extends AbstractService<VMTheme> {
}
return query ;
}
public Set<VMTheme> findAll(boolean withChoices, boolean withVotes) {
return new HashSet<VMTheme>(generateQuery(null, withChoices,withVotes).getResultList());
List<VMTheme> themes=generateQuery(null, withChoices,withVotes).getResultList() ;
return new HashSet<>(themes);
}
@Override

View file

@ -6,6 +6,8 @@
package fr.lirmm.aren.servlet;
import fr.lirmm.aren.service.CommentService;
import fr.lirmm.aren.service.vm.VMSendNotificationService;
import java.util.Calendar;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
@ -42,6 +44,9 @@ public class BackgroundJobManager implements ServletContextListener {
this.scheduler.scheduleAtFixedRate(() -> {
this.commentService.updateAllTags();
}, untilMidnight, millisInDay, TimeUnit.MILLISECONDS);
VMSendNotificationService sendNotificationService=new VMSendNotificationService() ;
sendNotificationService.start();
}
@Override

View file

@ -43,6 +43,7 @@ public class Root implements Filter {
String path = request.getRequestURI().substring(request.getContextPath().length());
if (!path.startsWith("/caslogin") && !path.startsWith("/ws/") && !path.startsWith("/assets/")) {
request.getRequestDispatcher("/index.jsp").forward(request, response);
} else {
chain.doFilter(request, response);
}

View file

@ -151,9 +151,10 @@ public class DebateRESTFacade extends AbstractRESTFacade<Debate> {
* @param id
*/
@Override
@RolesAllowed({"MODO"})
@RolesAllowed({"ADMIN"})
public void remove(Long id) {
super.remove(id);
debateService.clearComments(id);
debateService.remove(id);
}
/**
@ -211,7 +212,6 @@ public class DebateRESTFacade extends AbstractRESTFacade<Debate> {
@Path("{id}/comments")
@RolesAllowed({"ADMIN"})
public void clear(@PathParam("id") Long id) {
debateService.clearComments(id);
}

View file

@ -83,5 +83,4 @@ public class NotificationRESTFacade extends AbstractRESTFacade<Notification> {
}
return entityToUpdate;
}
}

View file

@ -1,7 +1,12 @@
package fr.lirmm.aren.ws.rest;
import com.fasterxml.jackson.databind.ObjectMapper;
import fr.lirmm.aren.model.Team;
import fr.lirmm.aren.model.vm.VMChoice;
import fr.lirmm.aren.model.vm.VMNotification;
import fr.lirmm.aren.model.vm.VMTeam;
import fr.lirmm.aren.model.vm.VMTheme;
import fr.lirmm.aren.service.TeamService;
import fr.lirmm.aren.service.vm.VMChoiceService;
import fr.lirmm.aren.service.vm.VMThemeService;
import fr.lirmm.aren.service.vm.VMVoteService;
@ -14,6 +19,9 @@ import javax.inject.Inject;
import javax.ws.rs.DELETE;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import java.io.File;
import java.io.IOException;
import java.time.ZonedDateTime;
import java.util.*;
/**
@ -32,6 +40,9 @@ public class VMThemeRESTFacade extends AbstractRESTFacade<VMTheme>{
@Inject
VMVoteService voteService ;
@Inject
TeamService teamService ;
@Override
protected VMThemeService getService() {
return themeService;
@ -41,8 +52,40 @@ public class VMThemeRESTFacade extends AbstractRESTFacade<VMTheme>{
//@RolesAllowed({"ADMIN"})
@PermitAll
public VMTheme create(VMTheme theme){
System.out.println(theme.toString());
return super.create(theme);
VMTheme res= super.create(theme);
try{
File file = new File("/aren/tmp/vote_majoritaire.json");
File directory = new File("/aren/tmp");
if (! directory.exists()){
directory.mkdirs() ;
}
System.out.println(file.getAbsolutePath());
if(!file.exists())
file.createNewFile() ;
VMNotification notification=new VMNotification() ;
List<String> emails=new ArrayList<>() ;
Team team=teamService.find(theme.getTeam().getId());
team.getUsers().forEach(user->{
emails.add(user.getEmail()) ;
});
notification.setExpiracy(theme.getExpiracyDate().toString());
String serverRoot = request.getRequestURL().substring(0, request.getRequestURL().length() - "/ws/vm/themes".length());
notification.setLink(serverRoot+"/votemajoritairedetails?id="+res.getId());
notification.setEmails(emails);
String []emails_array=new String[notification.getEmails().size()] ;
for(int j=0 ; j<emails_array.length ; j++){
emails_array[j]=notification.getEmails().get(j) ;
}
Map<String, Object> map = new HashMap<>() ;
map.put("link",notification.getLink()) ;
map.put("expiracy",notification.getExpiracy()) ;
map.put("emails",emails_array) ;
ObjectMapper mapper = new ObjectMapper();
mapper.writeValue(file,map);
}catch (IOException e) {
e.printStackTrace();
}
return res ;
}
@Override

View file

@ -22,4 +22,7 @@ mail_new_user_subject: Activation utilisateur
mail_new_user_body: <p>Bonjour,</p><p>Pour poursuivre l''activation de votre compte sur la plateforme AREN veuillez <a href="{0}">cliquer ici</a></p><p>Si le lien ne fonctionne pas, veuillez copier-coller l''url suivante dans la barre d''adresse de votre navigateur : <br><span style="font-size: 10px;text-decoration: underline;">{0}</span></p><br><p><b>Attention ce lien n''est valable que pendant 24h</b>.</p><br><p>PS : Veuillez ne pas r&eacute;pondre &agrave; ce mail qui est envoy&eacute; automatiquement par l''application de gestion de comptes informatiques.</p>
mail_reset_password_subject: R&eacute;initialisation du mot de passe
mail_reset_password_body: <p>Bonjour,</p><p>Une demande de r&eacute;initialisation de mot de passe &agrave; &eacute;t&eacute; faite en votre nom pour la plateforme AREN.</p><p>Si vous &ecirc;tes l''auteur\u22c5e de cette demande, pour r&eacute;initialiser votre mot de passe, <a href="{0}">cliquer ici</a></p><p>Si le lien ne fonctionne pas, veuillez copier-coller l''url suivante dans la barre d''adresse de votre navigateur : <br><span style="color:blue">{0}</span></p><br><p><b>Attention ce lien n''est valable que pendant 24h</b>.</p><br><p>Si vous n''&ecirc;tes pas l''auteur\u22c5e de cette demande, vous pouvez ignorer cet e-mail.</p><br><p>PS : Veuillez ne pas r&eacute;pondre &agrave; ce mail qui est envoy&eacute; automatiquement par l''application de gestion de comptes informatiques.</p>
mail_reset_password_body: <p>Bonjour,</p><p>Une demande de r&eacute;initialisation de mot de passe &agrave; &eacute;t&eacute; faite en votre nom pour la plateforme AREN.</p><p>Si vous &ecirc;tes l''auteur\u22c5e de cette demande, pour r&eacute;initialiser votre mot de passe, <a href="{0}">cliquer ici</a></p><p>Si le lien ne fonctionne pas, veuillez copier-coller l''url suivante dans la barre d''adresse de votre navigateur : <br><span style="color:blue">{0}</span></p><br><p><b>Attention ce lien n''est valable que pendant 24h</b>.</p><br><p>Si vous n''&ecirc;tes pas l''auteur\u22c5e de cette demande, vous pouvez ignorer cet e-mail.</p><br><p>PS : Veuillez ne pas r&eacute;pondre &agrave; ce mail qui est envoy&eacute; automatiquement par l''application de gestion de comptes informatiques.</p>
mail_vm_notification_subject: Notification sur le vote
mail_vm_notification_body : <p>Bonjour,</p><p>Pour poursuivre l''evolution du vote sur la plateforme AREN veuillez <a href="{0}">cliquer ici</a></p><p>Si le lien ne fonctionne pas, veuillez copier-coller l''url suivante dans la barre d''adresse de votre navigateur : <br><span style="font-size: 10px;text-decoration: underline;">{0}</span></p><br><br><p>PS : Veuillez ne pas r&eacute;pondre &agrave; ce mail qui est envoy&eacute; automatiquement par l''application de gestion de comptes informatiques.</p>