Skip to content
Snippets Groups Projects
Commit 22851679 authored by Faller's avatar Faller
Browse files

Cargo mas Noticias

parent 99831b2b
No related branches found
No related tags found
No related merge requests found
Showing
with 495 additions and 11 deletions
......@@ -64,4 +64,12 @@ public class CheckCheckerDAOBean implements CheckCheckerDaoLocal {
final List<VerificacionChecker> r = query.getResultList();
return r.stream().map(MyMapper.INSTANCE::convert).collect(Collectors.toList());
}
@Override
public List<CheckChecker> findAllByFact(Long idFact) {
final var query = em.createNamedQuery("VerificacionChecker.findByFact", VerificacionChecker.class);
query.setParameter("idFact", idFact);
final List<VerificacionChecker> r = query.getResultList();
return r.stream().map(MyMapper.INSTANCE::convert).collect(Collectors.toList());
}
}
......@@ -4,8 +4,11 @@ import uy.edu.fing.tse.central.db.dao.GenericDao;
import uy.edu.fing.tse.dto.CheckChecker;
import javax.ejb.Local;
import java.util.List;
@Local
public interface CheckCheckerDaoLocal extends GenericDao<CheckChecker> {
List<CheckChecker> findAllByFact(Long idFact);
}
......@@ -64,4 +64,12 @@ public class CheckMechanismDAOBean implements CheckMechanismDaoLocal {
final List<VerificacionMecanismo> r = query.getResultList();
return r.stream().map(MyMapper.INSTANCE::convert).collect(Collectors.toList());
}
@Override
public List<CheckMechanism> findAllByFact(Long idFact) {
final var query = em.createNamedQuery("VerificacionMecanismo.findByFact", VerificacionMecanismo.class);
query.setParameter("idFact", idFact);
final List<VerificacionMecanismo> r = query.getResultList();
return r.stream().map(MyMapper.INSTANCE::convert).collect(Collectors.toList());
}
}
......@@ -4,8 +4,11 @@ import uy.edu.fing.tse.central.db.dao.GenericDao;
import uy.edu.fing.tse.dto.CheckMechanism;
import javax.ejb.Local;
import java.util.List;
@Local
public interface CheckMechanismDaoLocal extends GenericDao<CheckMechanism> {
List<CheckMechanism> findAllByFact(Long idFact);
}
package uy.edu.fing.tse.central.db.dao.subscription;
import uy.edu.fing.tse.central.db.entity.Suscripcion;
import uy.edu.fing.tse.central.db.mapper.MyMapper;
import uy.edu.fing.tse.dto.Subscription;
import javax.annotation.PostConstruct;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import java.util.List;
import java.util.stream.Collectors;
@Stateless
public class SubscriptionDAOBean implements SubscriptionDaoLocal {
@PersistenceContext(unitName = "central")
private EntityManager em;
@PostConstruct
void init() {
//Despues del constructor hace esto
}
@Override
public Subscription create(Subscription elem) {
final var r = MyMapper.INSTANCE.convert(elem);
em.persist(r);
em.flush();
return MyMapper.INSTANCE.convert(r);
}
@Override
public Subscription update(Subscription elem) {
final var r = MyMapper.INSTANCE.convert(elem);
final var then = em.merge(r);
em.flush();
return MyMapper.INSTANCE.convert(then);
}
@Override
public void remove(Subscription elem) {
final var r = em.find(Suscripcion.class, elem.getId());
em.remove(r);
}
@Override
public Subscription find(String key) {
throw new UnsupportedOperationException("Metodo no debe ser utilizado");
}
@Override
public Subscription find(Long id) {
final var r = em.find(Suscripcion.class, id);
return MyMapper.INSTANCE.convert(r);
}
@Override
public List<Subscription> findAll() {
final var query = em.createNamedQuery("Suscripcion.findAll", Suscripcion.class);
final List<Suscripcion> r = query.getResultList();
return r.stream().map(MyMapper.INSTANCE::convert).collect(Collectors.toList());
}
@Override
public List<Subscription> findAllByUser(Long idUser) {
final var query = em.createNamedQuery("Suscripcion.findByUser", Suscripcion.class);
query.setParameter("idUser", idUser);
final List<Suscripcion> r = query.getResultList();
return r.stream().map(MyMapper.INSTANCE::convert).collect(Collectors.toList());
}
@Override
public List<Subscription> findAllByFact(Long idFact) {
final var query = em.createNamedQuery("Suscripcion.findByFact", Suscripcion.class);
query.setParameter("idFact", idFact);
final List<Suscripcion> r = query.getResultList();
return r.stream().map(MyMapper.INSTANCE::convert).collect(Collectors.toList());
}
}
package uy.edu.fing.tse.central.db.dao.subscription;
import uy.edu.fing.tse.central.db.dao.GenericDao;
import uy.edu.fing.tse.dto.Subscription;
import javax.ejb.Local;
import java.util.List;
@Local
public interface SubscriptionDaoLocal extends GenericDao<Subscription> {
List<Subscription> findAllByUser(Long idUser);
List<Subscription> findAllByFact(Long idFact);
}
package uy.edu.fing.tse.central.db.entity;
import javax.persistence.*;
@Entity
@NamedQueries({
@NamedQuery(name = "Suscripcion.findAll", query = "select r from Suscripcion r"),
@NamedQuery(name = "Suscripcion.findByFact", query = "select r from Suscripcion r inner join r.fact as f where f.id = :idFact"),
@NamedQuery(name = "Suscripcion.findByUser", query = "select r from Suscripcion r inner join r.user as u where u.id = :idUser")
})
public class Suscripcion {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@ManyToOne(optional = false)
private UsuarioFO user;
@ManyToOne(optional = false)
private Hecho fact;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public UsuarioFO getUser() {
return user;
}
public void setUser(UsuarioFO user) {
this.user = user;
}
public Hecho getFact() {
return fact;
}
public void setFact(Hecho fact) {
this.fact = fact;
}
}
......@@ -15,7 +15,7 @@ public class VerificacionMecanismo {
private Long id;
@ManyToOne(optional = false)
private Periferico peripheral;
private Mecanismo mechanism;
@ManyToOne(optional = false)
private Hecho fact;
......@@ -37,12 +37,12 @@ public class VerificacionMecanismo {
this.id = id;
}
public Periferico getPeripheral() {
return peripheral;
public Mecanismo getMechanism() {
return mechanism;
}
public void setPeripheral(Periferico peripheral) {
this.peripheral = peripheral;
public void setMechanism(Mecanismo mechanism) {
this.mechanism = mechanism;
}
public Hecho getFact() {
......
......@@ -52,6 +52,10 @@ public interface MyMapper {
}
}
Subscription convert(Suscripcion f);
Suscripcion convert(Subscription f);
VerificacionMecanismo convert(CheckMechanism f);
CheckMechanism convert(VerificacionMecanismo f);
......
......@@ -8,7 +8,7 @@ public final class CheckMechanism implements Serializable {
private static final long serialVersionUID = -5354719133598426738L;
private Long id;
private Peripherical peripheral;
private Mechanism mechanism;
private Fact fact;
private Short grade;
private String justification;
......@@ -22,12 +22,12 @@ public final class CheckMechanism implements Serializable {
this.id = id;
}
public Peripherical getPeripheral() {
return peripheral;
public Mechanism getMechanism() {
return mechanism;
}
public void setPeripheral(Peripherical peripheral) {
this.peripheral = peripheral;
public void setMechanism(Mechanism mechanism) {
this.mechanism = mechanism;
}
public Fact getFact() {
......
package uy.edu.fing.tse.dto;
import java.io.Serializable;
public class Subscription implements Serializable {
private Long id;
private UserFO user;
private Fact fact;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public UserFO getUser() {
return user;
}
public void setUser(UserFO user) {
this.user = user;
}
public Fact getFact() {
return fact;
}
public void setFact(Fact fact) {
this.fact = fact;
}
}
......@@ -98,6 +98,12 @@
<artifactId>amqp-client</artifactId>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.9</version>
</dependency>
</dependencies>
<build>
......
......@@ -33,6 +33,10 @@ public interface Business extends Serializable {
List<Score> listarCalificacion();
List<CheckMechanism> listarVerificacionesMeca(long idHecho);
List<CheckChecker> listarVerificacionesChecker(long idHecho);
//List<User> listarCheckers();
Score altaCalificacion(Score e);
......@@ -62,5 +66,11 @@ public interface Business extends Serializable {
void subscribirse(long idUser, long idHecho);
void updateHecho(Fact fact);
void nuevoEstadoHecho(Fact fact, State state, User user);
void solicitarCheckeoMecanismo(Fact fact, MechanismInternal mechanism);
void solicitarCheckeoPeriferico(Fact fact, Peripherical peripherical);
}
......@@ -3,6 +3,9 @@ package uy.edu.fing.tse.central.business;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import uy.edu.fing.tse.central.business.mechanism.AsyncServiceLocal;
import uy.edu.fing.tse.central.business.mechanism.OuterServiceLocal;
import uy.edu.fing.tse.central.business.mechanism.RandomServiceLocal;
import uy.edu.fing.tse.central.db.dao.category.CategoryDaoLocal;
import uy.edu.fing.tse.central.db.dao.check.checker.CheckCheckerDaoLocal;
import uy.edu.fing.tse.central.db.dao.check.mechanism.CheckMechanismDaoLocal;
......@@ -12,6 +15,7 @@ import uy.edu.fing.tse.central.db.dao.role.RoleDaoLocal;
import uy.edu.fing.tse.central.db.dao.score.ScoreDaoLocal;
import uy.edu.fing.tse.central.db.dao.state.StateDaoLocal;
import uy.edu.fing.tse.central.db.dao.statehistory.StateHistoryDaoLocal;
import uy.edu.fing.tse.central.db.dao.subscription.SubscriptionDaoLocal;
import uy.edu.fing.tse.central.db.dao.user.UserDaoLocal;
import uy.edu.fing.tse.dto.*;
......@@ -46,8 +50,17 @@ public class BusinessBean implements BusinessLocal, BusinessRemote {
private StateHistoryDaoLocal transiciones;
@EJB
private UserDaoLocal usuarios;
@EJB
private SubscriptionDaoLocal subcripciones;
@EJB
private AsyncServiceLocal longTerm;
@EJB
private OuterServiceLocal outer;
@EJB
private RandomServiceLocal random;
@Override
public void altaPeriferico(Peripherical p) {
mecanismos.create(p);
......@@ -144,6 +157,16 @@ public class BusinessBean implements BusinessLocal, BusinessRemote {
return estados.findAll();
}
@Override
public List<CheckMechanism> listarVerificacionesMeca(long idHecho) {
return verificacionesMecanismos.findAllByFact(idHecho);
}
@Override
public List<CheckChecker> listarVerificacionesChecker(long idHecho) {
return verificacionesChecker.findAllByFact(idHecho);
}
@Override
public void altaUsuario(User user) {
usuarios.create(user);
......@@ -200,7 +223,13 @@ public class BusinessBean implements BusinessLocal, BusinessRemote {
@Override
public void subscribirse(long idUser, long idHecho) {
//TODO
final Subscription subscription = new Subscription();
final Fact fact = hechos.find(idHecho);
final User user = usuarios.find(idUser);
subscription.setFact(fact);
subscription.setUser((UserFO) user);
subcripciones.create(subscription);
}
@Override
......@@ -229,4 +258,37 @@ public class BusinessBean implements BusinessLocal, BusinessRemote {
hechos.update(fact);
}
@Override
public void nuevoEstadoHecho(Fact fact, State state, User user) {
StateHistory sh = new StateHistory();
sh.setState(state);
sh.setDate(new Date());
sh.setUser(user);
fact.setActualState(state);
fact.addHistory(sh);
updateHecho(fact);
}
@Override
public void solicitarCheckeoMecanismo(Fact fact, MechanismInternal mechanism) {
switch (mechanism.getName()) {
case "Random":
random.invoke(fact);
break;
case "LongTerm":
longTerm.invoke(fact);
break;
case "Outer":
outer.invoke(fact);
break;
default:
}
}
@Override
public void solicitarCheckeoPeriferico(Fact fact, Peripherical peripherical) {
}
}
package uy.edu.fing.tse.central.business.mechanism;
import uy.edu.fing.tse.central.db.dao.check.mechanism.CheckMechanismDaoLocal;
import uy.edu.fing.tse.central.db.dao.mechanism.MechanismDaoLocal;
import uy.edu.fing.tse.dto.CheckMechanism;
import uy.edu.fing.tse.dto.Fact;
import uy.edu.fing.tse.dto.Mechanism;
import javax.ejb.Asynchronous;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import java.util.Date;
import java.util.Random;
@Stateless
public class AsyncService implements AsyncServiceLocal {
@EJB
private MechanismDaoLocal mecanismos;
@EJB
private CheckMechanismDaoLocal verificacionesMecanismos;
@Asynchronous
public void invoke(Fact hecho) {
try {
Random r = new Random(2222);
Integer time = r.nextInt(60) + 60;
Thread.sleep(time * 1000);
final Mechanism longTerm = mecanismos.find("LongTerm");
final CheckMechanism checkMechanism = new CheckMechanism();
checkMechanism.setFact(hecho);
checkMechanism.setMechanism(longTerm);
checkMechanism.setRegisterDate(new Date());
checkMechanism.setJustification("Beep Beep Boo...");
checkMechanism.setGrade(Short.valueOf(r.nextInt(6) + ""));
verificacionesMecanismos.create(checkMechanism);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
package uy.edu.fing.tse.central.business.mechanism;
import uy.edu.fing.tse.dto.Fact;
import javax.ejb.Local;
@Local
public interface AsyncServiceLocal {
void invoke(Fact hecho);
}
package uy.edu.fing.tse.central.business.mechanism;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.HttpClientBuilder;
import uy.edu.fing.tse.central.db.dao.check.mechanism.CheckMechanismDaoLocal;
import uy.edu.fing.tse.central.db.dao.mechanism.MechanismDaoLocal;
import uy.edu.fing.tse.dto.CheckMechanism;
import uy.edu.fing.tse.dto.Fact;
import uy.edu.fing.tse.dto.Mechanism;
import javax.ejb.Asynchronous;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Date;
import java.util.Random;
import static org.apache.http.protocol.HTTP.USER_AGENT;
@Stateless
public class OuterService implements OuterServiceLocal {
@EJB
private MechanismDaoLocal mecanismos;
@EJB
private CheckMechanismDaoLocal verificacionesMecanismos;
@Asynchronous
public void invoke(Fact hecho) {
try {
Random r = new Random(2222);
Integer time = r.nextInt(60) + 60;
Thread.sleep(time * 1000);
final Mechanism longTerm = mecanismos.find("Outer");
final CheckMechanism checkMechanism = new CheckMechanism();
checkMechanism.setFact(hecho);
checkMechanism.setMechanism(longTerm);
checkMechanism.setRegisterDate(new Date());
checkMechanism.setJustification("Beeeeep. Beeeeeep......");
final short consult = consult();
if (consult == 0) {
checkMechanism.setJustification("Error consultando servicio");
}
checkMechanism.setGrade(consult);
verificacionesMecanismos.create(checkMechanism);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
public short consult() {
try {
HttpClient client = HttpClientBuilder.create().build();
HttpGet request = new HttpGet("http://www.cei.edu.uy/web/");
// add request header
request.addHeader("User-Agent", USER_AGENT);
HttpResponse response = client.execute(request);
final int statusCode = response.getStatusLine().getStatusCode();
BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
StringBuffer result = new StringBuffer();
String line = "";
while ((line = rd.readLine()) != null) {
result.append(line);
}
return ((Integer) ((statusCode * result.length()) % 5)).shortValue();
} catch (Exception e) {
}
return 0;
}
}
package uy.edu.fing.tse.central.business.mechanism;
import uy.edu.fing.tse.dto.Fact;
import javax.ejb.Local;
@Local
public interface OuterServiceLocal {
void invoke(Fact hecho);
}
package uy.edu.fing.tse.central.business.mechanism;
import uy.edu.fing.tse.central.db.dao.check.mechanism.CheckMechanismDaoLocal;
import uy.edu.fing.tse.central.db.dao.mechanism.MechanismDaoLocal;
import uy.edu.fing.tse.dto.CheckMechanism;
import uy.edu.fing.tse.dto.Fact;
import uy.edu.fing.tse.dto.Mechanism;
import javax.ejb.Asynchronous;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import java.util.Date;
import java.util.Random;
@Stateless
public class RandomService implements RandomServiceLocal {
@EJB
private MechanismDaoLocal mecanismos;
@EJB
private CheckMechanismDaoLocal verificacionesMecanismos;
@Asynchronous
public void invoke(Fact hecho) {
Random r = new Random(2222);
final Mechanism longTerm = mecanismos.find("Random");
final CheckMechanism checkMechanism = new CheckMechanism();
checkMechanism.setFact(hecho);
checkMechanism.setMechanism(longTerm);
checkMechanism.setRegisterDate(new Date());
checkMechanism.setJustification("Me parece que es asi...");
checkMechanism.setGrade(Short.valueOf(r.nextInt(6) + ""));
verificacionesMecanismos.create(checkMechanism);
}
}
package uy.edu.fing.tse.central.business.mechanism;
import uy.edu.fing.tse.dto.Fact;
import javax.ejb.Local;
@Local
public interface RandomServiceLocal {
void invoke(Fact hecho);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment