use of de.tum.in.www1.artemis.domain.Result in project ArTEMiS by ls1intum.
the class BambooService method retrieveLatestBuildResult.
/**
* Performs a request to the Bamboo REST API to retrive the latest result for the given plan.
*
* @param planKey the key of the plan for which to retrieve the latest result
* @return a map containing the following data:
* - successful: if the build was successful
* - buildTestSummary: a string generated by Bamboo summarizing the build result
* - buildCompletedDate: the completion date of the build
*/
private Map<String, Object> retrieveLatestBuildResult(String planKey) {
HttpHeaders headers = HeaderUtil.createAuthorization(BAMBOO_USER, BAMBOO_PASSWORD);
HttpEntity<?> entity = new HttpEntity<>(headers);
RestTemplate restTemplate = new RestTemplate();
ResponseEntity<Map> response = null;
try {
response = restTemplate.exchange(BAMBOO_SERVER_URL + "/rest/api/latest/result/" + planKey.toUpperCase() + "/latest.json?expand=testResults,artifacts", HttpMethod.GET, entity, Map.class);
} catch (Exception e) {
log.error("HttpError while retrieving results", e);
}
if (response != null) {
Map<String, Object> result = new HashMap<>();
boolean successful = (boolean) response.getBody().get("successful");
result.put("successful", successful);
String buildTestSummary = (String) response.getBody().get("buildTestSummary");
result.put("buildTestSummary", buildTestSummary);
String dateString = (String) response.getBody().get("buildCompletedDate");
ZonedDateTime buildCompletedDate = ZonedDateTime.parse(dateString);
result.put("buildCompletedDate", buildCompletedDate);
if (response.getBody().containsKey("artifacts")) {
Map<String, Object> artifacts = (Map<String, Object>) response.getBody().get("artifacts");
if ((int) artifacts.get("size") > 0 && artifacts.containsKey("artifact")) {
Map<String, Object> firstArtifact = (Map<String, Object>) ((ArrayList<Map>) artifacts.get("artifact")).get(0);
String artifact = (String) ((Map<String, Object>) firstArtifact.get("link")).get("href");
result.put("artifact", artifact);
}
}
return result;
}
return null;
}
use of de.tum.in.www1.artemis.domain.Result in project ArTEMiS by ls1intum.
the class LtiService method onNewBuildResult.
/**
* This method is pinged on new build results.
* It sends an message to the LTI consumer with the new score.
*
* @param participation
*/
public void onNewBuildResult(Participation participation) {
// Get the LTI outcome URL
Optional<LtiOutcomeUrl> ltiOutcomeUrl = ltiOutcomeUrlRepository.findByUserAndExercise(participation.getStudent(), participation.getExercise());
ltiOutcomeUrl.ifPresent(ltiOutcomeUrl1 -> {
String score = "0.00";
// Get the latest result
Optional<Result> latestResult = resultRepository.findFirstByParticipationIdOrderByCompletionDateDesc(participation.getId());
if (latestResult.isPresent() && latestResult.get().getScore() != null) {
// LTI scores needs to be formatted as String between "0.00" and "1.00"
score = String.format(Locale.ROOT, "%.2f", latestResult.get().getScore().floatValue() / 100);
}
log.debug("Reporting to LTI consumer: Score {} for Participation {}", score, participation);
try {
// Using PatchedIMSPOXRequest until they fixed the problem: https://github.com/IMSGlobal/basiclti-util-java/issues/27
HttpPost request = PatchedIMSPOXRequest.buildReplaceResult(ltiOutcomeUrl1.getUrl(), OAUTH_KEY, OAUTH_SECRET, ltiOutcomeUrl1.getSourcedId(), score, null, false);
HttpClient client = HttpClientBuilder.create().build();
HttpResponse response = client.execute(request);
String responseString = new BasicResponseHandler().handleResponse(response);
log.debug("Response from LTI consumer: {}", responseString);
if (response.getStatusLine().getStatusCode() >= 400) {
throw new HttpResponseException(response.getStatusLine().getStatusCode(), response.getStatusLine().getReasonPhrase());
}
} catch (Exception e) {
log.error("Reporting to LTI consumer failed: {}", e);
}
});
}
use of de.tum.in.www1.artemis.domain.Result in project ArTEMiS by ls1intum.
the class LtiUserIdResource method createLtiUserId.
/**
* POST /lti-user-ids : Create a new ltiUserId.
*
* @param ltiUserId the ltiUserId to create
* @return the ResponseEntity with status 201 (Created) and with body the new ltiUserId, or with status 400 (Bad Request) if the ltiUserId has already an ID
* @throws URISyntaxException if the Location URI syntax is incorrect
*/
@PostMapping("/lti-user-ids")
@Timed
public ResponseEntity<LtiUserId> createLtiUserId(@RequestBody LtiUserId ltiUserId) throws URISyntaxException {
log.debug("REST request to save LtiUserId : {}", ltiUserId);
if (ltiUserId.getId() != null) {
return ResponseEntity.badRequest().headers(HeaderUtil.createFailureAlert(ENTITY_NAME, "idexists", "A new ltiUserId cannot already have an ID")).body(null);
}
LtiUserId result = ltiUserIdRepository.save(ltiUserId);
return ResponseEntity.created(new URI("/api/lti-user-ids/" + result.getId())).headers(HeaderUtil.createEntityCreationAlert(ENTITY_NAME, result.getId().toString())).body(result);
}
use of de.tum.in.www1.artemis.domain.Result in project ArTEMiS by ls1intum.
the class LtiUserIdResource method updateLtiUserId.
/**
* PUT /lti-user-ids : Updates an existing ltiUserId.
*
* @param ltiUserId the ltiUserId to update
* @return the ResponseEntity with status 200 (OK) and with body the updated ltiUserId,
* or with status 400 (Bad Request) if the ltiUserId is not valid,
* or with status 500 (Internal Server Error) if the ltiUserId couldn't be updated
* @throws URISyntaxException if the Location URI syntax is incorrect
*/
@PutMapping("/lti-user-ids")
@Timed
public ResponseEntity<LtiUserId> updateLtiUserId(@RequestBody LtiUserId ltiUserId) throws URISyntaxException {
log.debug("REST request to update LtiUserId : {}", ltiUserId);
if (ltiUserId.getId() == null) {
return createLtiUserId(ltiUserId);
}
LtiUserId result = ltiUserIdRepository.save(ltiUserId);
return ResponseEntity.ok().headers(HeaderUtil.createEntityUpdateAlert(ENTITY_NAME, ltiUserId.getId().toString())).body(result);
}
use of de.tum.in.www1.artemis.domain.Result in project ArTEMiS by ls1intum.
the class ModelingExerciseResource method createModelingExercise.
/**
* POST /modeling-exercises : Create a new modelingExercise.
*
* @param modelingExercise the modelingExercise to create
* @return the ResponseEntity with status 201 (Created) and with body the new modelingExercise, or with status 400 (Bad Request) if the modelingExercise has already an ID
* @throws URISyntaxException if the Location URI syntax is incorrect
*/
@PostMapping("/modeling-exercises")
@Timed
public ResponseEntity<ModelingExercise> createModelingExercise(@RequestBody ModelingExercise modelingExercise) throws URISyntaxException {
log.debug("REST request to save ModelingExercise : {}", modelingExercise);
if (modelingExercise.getId() != null) {
return ResponseEntity.badRequest().headers(HeaderUtil.createFailureAlert(ENTITY_NAME, "idexists", "A new modelingExercise cannot already have an ID")).body(null);
}
ModelingExercise result = modelingExerciseRepository.save(modelingExercise);
return ResponseEntity.created(new URI("/api/modeling-exercises/" + result.getId())).headers(HeaderUtil.createEntityCreationAlert(ENTITY_NAME, result.getId().toString())).body(result);
}
Aggregations