use of org.opencastproject.serviceregistry.api.IncidentL10n in project opencast by opencast.
the class AbstractIncidentService method getLocalization.
@Override
public IncidentL10n getLocalization(long id, Locale locale) throws IncidentServiceException, NotFoundException {
final Incident incident = getIncident(id);
final List<String> loc = localeToList(locale);
// check if cache map is empty
// fill cache from
final String title = findText(loc, incident.getCode(), FIELD_TITLE).getOrElse(NO_TITLE);
final String description = findText(loc, incident.getCode(), FIELD_DESCRIPTION).map(replaceVarsF(incident.getDescriptionParameters())).getOrElse(NO_DESCRIPTION);
return new IncidentL10n() {
@Override
public String getTitle() {
return title;
}
@Override
public String getDescription() {
return description;
}
};
}
use of org.opencastproject.serviceregistry.api.IncidentL10n in project opencast by opencast.
the class IncidentServiceEndpoint method getLocalization.
@GET
@SuppressWarnings("unchecked")
@Produces(MediaType.APPLICATION_JSON)
@Path("localization/{id}")
@RestQuery(name = "getlocalization", description = "Returns the localization of an incident by it's id as JSON", returnDescription = "The localization of the incident as JSON", pathParameters = { @RestParameter(name = "id", isRequired = true, description = "The incident identifiers.", type = Type.INTEGER) }, restParameters = { @RestParameter(name = "locale", isRequired = true, description = "The locale.", type = Type.STRING) }, reponses = { @RestResponse(responseCode = SC_OK, description = "The localization of the given job incidents."), @RestResponse(responseCode = SC_NOT_FOUND, description = "No job incident with this incident identifier was found.") })
public Response getLocalization(@PathParam("id") final long incidentId, @QueryParam("locale") String locale) throws NotFoundException {
try {
IncidentL10n localization = svc.getLocalization(incidentId, LocaleUtils.toLocale(locale));
JSONObject json = new JSONObject();
json.put("title", localization.getTitle());
json.put("description", localization.getDescription());
return Response.ok(json.toJSONString()).build();
} catch (IncidentServiceException e) {
logger.warn("Unable to get job localization of jo incident:", e);
throw new WebApplicationException(INTERNAL_SERVER_ERROR);
}
}
Aggregations