Search in sources :

Example 1 with IncidentL10n

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;
        }
    };
}
Also used : Incident(org.opencastproject.job.api.Incident) IncidentL10n(org.opencastproject.serviceregistry.api.IncidentL10n)

Example 2 with IncidentL10n

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);
    }
}
Also used : JSONObject(org.json.simple.JSONObject) WebApplicationException(javax.ws.rs.WebApplicationException) IncidentServiceException(org.opencastproject.serviceregistry.api.IncidentServiceException) IncidentL10n(org.opencastproject.serviceregistry.api.IncidentL10n) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Aggregations

IncidentL10n (org.opencastproject.serviceregistry.api.IncidentL10n)2 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 JSONObject (org.json.simple.JSONObject)1 Incident (org.opencastproject.job.api.Incident)1 IncidentServiceException (org.opencastproject.serviceregistry.api.IncidentServiceException)1 RestQuery (org.opencastproject.util.doc.rest.RestQuery)1