Skip to content
Snippets Groups Projects
Commit b3e92ae7 authored by Falucho's avatar Falucho
Browse files

Va quedando

parent 6624f4a7
Branches
No related tags found
No related merge requests found
Pipeline #6610 passed with warnings
Showing
with 131 additions and 13 deletions
package uy.edu.fing.tse.dto.external;
import uy.edu.fing.tse.dto.Fact;
import java.io.Serializable;
public class VerificationRequest implements Serializable {
private Fact fact;
private String perifericoEndpoint;
public Fact getFact() {
return fact;
}
public VerificationRequest setFact(Fact fact) {
this.fact = fact;
return this;
}
public String getPerifericoEndpoint() {
return perifericoEndpoint;
}
public VerificationRequest setPerifericoEndpoint(String perifericoEndpoint) {
this.perifericoEndpoint = perifericoEndpoint;
return this;
}
@Override
public String toString() {
return "VerificationRequest{" +
"fact=" + fact +
", perifericoEndpoint='" + perifericoEndpoint + '\'' +
'}';
}
}
......@@ -33,7 +33,6 @@
<type>ejb</type>
</dependency>
</dependencies>
<build>
......
......@@ -6,6 +6,7 @@ import uy.edu.fing.tse.dto.*;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import java.util.Map;
public interface Business extends Serializable {
......@@ -67,10 +68,16 @@ public interface Business extends Serializable {
void updateHecho(Fact fact);
void verificarHecho(CheckChecker checkChecker);
void nuevoEstadoHecho(Fact fact, State state, User user);
void solicitarCheckeoMecanismo(Fact fact, MechanismInternal mechanism);
void solicitarCheckeoPeriferico(Fact fact, Peripherical peripherical);
void addOrUpdateProperty(String key, String value);
Map<String, String> obtenerPropiedades();
}
......@@ -6,6 +6,8 @@ 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.business.mq.MessageProducer;
import uy.edu.fing.tse.central.business.mq.Queue;
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;
......@@ -18,11 +20,15 @@ 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.*;
import uy.edu.fing.tse.dto.external.VerificationRequest;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import java.io.IOException;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Stateless
public class BusinessBean implements BusinessLocal, BusinessRemote {
......@@ -61,6 +67,9 @@ public class BusinessBean implements BusinessLocal, BusinessRemote {
@EJB
private RandomServiceLocal random;
@EJB
private MessageProducer messageProducer;
@Override
public void altaPeriferico(Peripherical p) {
mecanismos.create(p);
......@@ -259,6 +268,25 @@ public class BusinessBean implements BusinessLocal, BusinessRemote {
hechos.update(fact);
}
@Override
public void verificarHecho(CheckChecker checkChecker) {
final var u = usuarios.find(checkChecker.getChecker().getMail());
checkChecker.setChecker((UserBO) u);
final var s = calificaciones.find(checkChecker.getScore().getValue());
checkChecker.setScore(s);
final var f = hechos.find(checkChecker.getFact().getId());
checkChecker.setFact(f);
final var st = estados.find("Verificado");
f.setActualState(st);
f.setScore(s);
verificacionesChecker.create(checkChecker);
hechos.update(f);
}
@Override
public void nuevoEstadoHecho(Fact fact, State state, User user) {
StateHistory sh = new StateHistory();
......@@ -288,7 +316,23 @@ public class BusinessBean implements BusinessLocal, BusinessRemote {
@Override
public void solicitarCheckeoPeriferico(Fact fact, Peripherical peripherical) {
VerificationRequest vr = new VerificationRequest();
vr.setFact(fact);
vr.setPerifericoEndpoint(peripherical.getEndpoint());
try {
messageProducer.send(vr, Queue.VERIFICATION);
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public void addOrUpdateProperty(String key, String value) {
System.setProperty(key, value);
}
@Override
public Map<String, String> obtenerPropiedades() {
return System.getProperties().entrySet().stream().collect(Collectors.toMap(o -> o.getKey().toString(), o -> o.getValue().toString()));
}
}
......@@ -9,6 +9,8 @@ import java.util.Properties;
public enum Propiedades {
NOTIFICACIONES_ENEABLE("uy.edu.fing.tse.business.notification.eneable", "true"),
NOTIFICATION_TOKEN("uy.edu.fing.tse.business.notification.token", ""),
URI("uy.edu.fing.tse.business.rabbit.uri", ""),
HOST("uy.edu.fing.tse.business.rabbit.host", ""),
PORT("uy.edu.fing.tse.business.rabbit.port", "5672"),
......@@ -44,7 +46,7 @@ public enum Propiedades {
return Boolean.valueOf(System.getProperty(key));
}
static {
public static void defaultLoad() {
//Agrego valores por defecto
for (Propiedades value : Propiedades.values()) {
System.setProperty(value.key, value.defaultValue);
......
......@@ -32,7 +32,7 @@ public class OuterService implements OuterServiceLocal {
public void invoke(Fact hecho) {
try {
Random r = new Random(2222);
Integer time = r.nextInt(60) + 60;
int time = r.nextInt(60);
Thread.sleep(time * 1000);
final Mechanism longTerm = mecanismos.find("Outer");
......@@ -43,9 +43,27 @@ public class OuterService implements OuterServiceLocal {
checkMechanism.setRegisterDate(new Date());
checkMechanism.setJustification("Beeeeep. Beeeeeep......");
final short consult = consult();
if (consult == 0) {
switch (consult) {
case 0:
checkMechanism.setJustification("Error consultando servicio");
break;
case 1:
checkMechanism.setJustification("Beeeeep. Beeeeeep......");
break;
case 2:
checkMechanism.setJustification("Falacias");
break;
case 3:
checkMechanism.setJustification("Medias tintas");
break;
case 4:
checkMechanism.setJustification("Correcto pero exagerado");
break;
case 5:
checkMechanism.setJustification("Fuente confiable");
break;
}
checkMechanism.setGrade(consult);
verificacionesMecanismos.create(checkMechanism);
......@@ -67,13 +85,13 @@ public class OuterService implements OuterServiceLocal {
BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
StringBuffer result = new StringBuffer();
StringBuilder result = new StringBuilder();
String line = "";
while ((line = rd.readLine()) != null) {
result.append(line);
}
return ((Integer) ((statusCode * result.length()) % 5)).shortValue();
return ((Integer) (result.length() % 5 + 1)).shortValue();
} catch (Exception e) {
}
return 0;
......
......@@ -16,12 +16,14 @@ import uy.edu.fing.tse.dto.external.Verification;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.ejb.EJB;
import javax.ejb.Singleton;
import javax.ejb.Startup;
import java.io.IOException;
import java.util.Date;
import java.util.concurrent.TimeoutException;
//@Singleton
//@Startup
@Singleton
@Startup
public class MessageConsumer {
private static final Logger LOG = LoggerFactory.getLogger(MessageConsumer.class);
......
......@@ -4,12 +4,14 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.rabbitmq.client.Channel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import uy.edu.fing.tse.dto.external.VerificationRequest;
import javax.annotation.PostConstruct;
import javax.ejb.Stateless;
import java.io.IOException;
import java.util.concurrent.TimeoutException;
//@Stateless
@Stateless
public class MessageProducer {
private static final Logger LOG = LoggerFactory.getLogger(MessageProducer.class);
......@@ -26,12 +28,12 @@ public class MessageProducer {
}
}
public void send(final Object message, final Queue queue) throws IOException {
public void send(final VerificationRequest message, final Queue queue) throws IOException {
final String body = new ObjectMapper().writeValueAsString(message);
send(body, queue);
}
public void send(final String message, final Queue queue) throws IOException {
private void send(final String message, final Queue queue) throws IOException {
channel.basicPublish("", queue.name, null, message.getBytes());
}
}
package uy.edu.fing.tse.central.business.startup;
import uy.edu.fing.tse.central.business.BusinessLocal;
import uy.edu.fing.tse.central.business.common.Propiedades;
import uy.edu.fing.tse.central.business.security.SecurityLocal;
import uy.edu.fing.tse.dto.*;
......@@ -25,6 +26,8 @@ public class Config {
@PostConstruct
public void start() {
Propiedades.defaultLoad();
initRole();
initUsers();
initEstados();
......
......@@ -4,3 +4,5 @@ uy.edu.fing.tse.business.rabbit.port=5672
uy.edu.fing.tse.business.rabbit.vhost=hjxhckpo
uy.edu.fing.tse.business.rabbit.username=hjxhckpo
uy.edu.fing.tse.business.rabbit.password=kGFmsQ9HodjSzRVT016ttW-z7d2tn_IF
uy.edu.fing.tse.business.notification.eneable=true
uy.edu.fing.tse.business.notification.token=AAAAMrVaXZ4:APA91bFwjtzxbO7K8DhSkP0eZhWPvFgUfmcz1t_ii9eFySA-UqX38KzKKV7g5y-wDCSbz9WyVmXclHUr1bzrqdSbPvuUhFq4HW3MBMKfHjFp9oNf5BkS2tBCVfaZ-u089QAEydEoL8rp
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment