use of de.ipk_gatersleben.bit.bi.bridge.brapicomp.ci.EmailManager in project IPK-BrAPI-Validator by plantbreeding.
the class RunnerService method TestAllEndpointsWithFreq.
/**
* Test all endpoints with a certain frequency set in database
*
* @param testCollection Config instance.
* @param frequency Get endpoints with this frequency.
* @return List of TestSuiteReport containing the test results.
* @throws SQLException SQL connection
*/
public static int TestAllEndpointsWithFreq(TestCollection testCollection, String frequency) throws SQLException {
List<Resource> l = ResourceService.getAllEndpointsWithFreq(frequency);
LOGGER.info("Endpoints found: " + l.size());
int count = 0;
boolean sent;
for (int i = 0; i < l.size(); i++) {
Resource resource = l.get(i);
TestSuiteReport testSuiteReport = RunnerService.testEndpointWithCall(resource, testCollection);
final int N = resource.getStoreprev();
// Get last N reports
List<TestReport> prevReports = TestReportService.getLastReports(resource, N);
if (prevReports.size() >= N) {
// Delete older than last N.
TestReportService.deleteOlderThan(prevReports.get(prevReports.size() - 1));
}
ObjectMapper mapper = new ObjectMapper();
try {
TestReport report = new TestReport(resource, mapper.writeValueAsString(testSuiteReport));
String reportId = TestReportService.saveReport(report);
testSuiteReport.setId(reportId);
} catch (JsonProcessingException e) {
LOGGER.warn("Unable to save report:" + e.getMessage());
}
EmailManager manager = new EmailManager(resource);
manager.setPrevReports(prevReports);
sent = manager.sendReport(testSuiteReport);
if (sent) {
count += 1;
}
}
return count;
}
use of de.ipk_gatersleben.bit.bi.bridge.brapicomp.ci.EmailManager in project IPK-BrAPI-Validator by plantbreeding.
the class ContinuousIntegrationResource method createEndpoint.
/**
* Register new resource
*
* @param endp Json containing the resource's url.
* @return Json message.
*/
@POST
@Path("/resources")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response createEndpoint(@Context HttpHeaders headers, Resource res) {
if (Config.get("advancedMode") == null) {
return Response.status(Status.NOT_FOUND).build();
}
LOGGER.debug("New POST /ci/resources call.");
Dao<Resource, UUID> endpointDao = DataSourceManager.getDao(Resource.class);
try {
// Check if the record exists in the database already.
Resource e = ResourceService.getEndpointWithEmailAndUrlAndFreq(res.getEmail(), res.getUrl(), res.getFrequency());
if (res.getEmail() == null) {
String e2 = JsonMessageManager.jsonMessage(400, "Invalid email", 4100);
return Response.status(Status.BAD_REQUEST).entity(e2).build();
} else if (e != null && e.isConfirmed()) {
String e2 = JsonMessageManager.jsonMessage(400, "Url already in use", 4101);
return Response.status(Status.BAD_REQUEST).entity(e2).build();
} else if (e != null && !e.isConfirmed()) {
EmailManager em = new EmailManager(res);
em.sendConfirmation();
String e2 = JsonMessageManager.jsonMessage(200, "We'll resend you a confirmation email.", 2100);
return Response.status(Status.ACCEPTED).entity(e2).build();
} else {
res.setPublic(false);
endpointDao.create(res);
EmailManager em = new EmailManager(res);
em.sendConfirmation();
return Response.status(Status.ACCEPTED).entity(JsonMessageManager.jsonMessage(200, "We'll send you a confirmation email.", 2101)).build();
}
} catch (SQLException e) {
e.printStackTrace();
String e1 = JsonMessageManager.jsonMessage(500, "Internal server error", 5100);
return Response.status(Status.INTERNAL_SERVER_ERROR).entity(e1).build();
}
}
use of de.ipk_gatersleben.bit.bi.bridge.brapicomp.ci.EmailManager in project IPK-BrAPI-Validator by plantbreeding.
the class RunnerService method TestAllEndpointsWithFreq.
/**
* Test all endpoints with a certain frequency set in database
*
* @param testCollection Config instance.
* @param frequency Get endpoints with this frequency.
* @return List of TestSuiteReport containing the test results.
* @throws SQLException SQL connection
*/
public static int TestAllEndpointsWithFreq(TestCollection testCollection, String frequency, boolean allowAdditional) throws SQLException {
List<Resource> l = ResourceService.getAllEndpointsWithFreq(frequency);
LOGGER.info("Endpoints found: " + l.size());
int count = 0;
boolean sent;
for (int i = 0; i < l.size(); i++) {
Resource resource = l.get(i);
TestSuiteReport testSuiteReport = RunnerService.testEndpointWithCall(resource, testCollection, allowAdditional, false);
final int N = resource.getStoreprev();
// Get last N reports
List<TestReport> prevReports = TestReportService.getLastReports(resource, N);
if (prevReports.size() >= N) {
// Delete older than last N.
TestReportService.deleteOlderThan(prevReports.get(prevReports.size() - 1));
}
ObjectMapper mapper = new ObjectMapper();
try {
TestReport report = new TestReport(resource, mapper.writeValueAsString(testSuiteReport));
String reportId = TestReportService.saveReport(report);
testSuiteReport.setId(reportId);
} catch (JsonProcessingException e) {
LOGGER.warn("Unable to save report:" + e.getMessage());
}
EmailManager manager = new EmailManager(resource);
manager.setPrevReports(prevReports);
sent = manager.sendReport(testSuiteReport);
if (sent) {
count += 1;
}
}
return count;
}
Aggregations