Search in sources :

Example 1 with TranscriptionDatabaseException

use of org.opencastproject.transcription.ibmwatson.persistence.TranscriptionDatabaseException in project opencast by opencast.

the class IBMWatsonTranscriptionService method transcriptionDone.

@Override
public void transcriptionDone(String mpId, Object obj) throws TranscriptionServiceException {
    JSONObject jsonObj = null;
    String jobId = null;
    try {
        jsonObj = (JSONObject) obj;
        jobId = (String) jsonObj.get("id");
        logger.info("Transcription done for mpId {}, jobId {}", mpId, jobId);
        // Update state in database
        // If there's an optimistic lock exception here, it's ok because the workflow dispatcher
        // may be doing the same thing
        database.updateJobControl(jobId, TranscriptionJobControl.Status.TranscriptionComplete.name());
        // Save results in file system if there
        if (jsonObj.get("results") != null)
            saveResults(jobId, jsonObj);
    } catch (IOException e) {
        logger.warn("Could not save transcription results file for mpId {}, jobId {}: {}", mpId, jobId, jsonObj == null ? "null" : jsonObj.toJSONString());
        throw new TranscriptionServiceException("Could not save transcription results file", e);
    } catch (TranscriptionDatabaseException e) {
        logger.warn("Transcription results file were saved but state in db not updated for mpId {}, jobId {}", mpId, jobId);
        throw new TranscriptionServiceException("Could not update transcription job control db", e);
    }
}
Also used : JSONObject(org.json.simple.JSONObject) TranscriptionDatabaseException(org.opencastproject.transcription.ibmwatson.persistence.TranscriptionDatabaseException) IOException(java.io.IOException) TranscriptionServiceException(org.opencastproject.transcription.api.TranscriptionServiceException)

Example 2 with TranscriptionDatabaseException

use of org.opencastproject.transcription.ibmwatson.persistence.TranscriptionDatabaseException in project opencast by opencast.

the class IBMWatsonTranscriptionService method getGeneratedTranscription.

@Override
public MediaPackageElement getGeneratedTranscription(String mpId, String jobId) throws TranscriptionServiceException {
    try {
        // If jobId is unknown, look for all jobs associated to that mpId
        if (jobId == null || "null".equals(jobId)) {
            jobId = null;
            for (TranscriptionJobControl jc : database.findByMediaPackage(mpId)) {
                if (TranscriptionJobControl.Status.Closed.name().equals(jc.getStatus()) || TranscriptionJobControl.Status.TranscriptionComplete.name().equals(jc.getStatus()))
                    jobId = jc.getTranscriptionJobId();
            }
        }
        if (jobId == null)
            throw new TranscriptionServiceException("No completed or closed transcription job found in database for media package " + mpId);
        // Results already saved?
        URI uri = workspace.getCollectionURI(TRANSCRIPT_COLLECTION, buildResultsFileName(jobId));
        try {
            workspace.get(uri);
        } catch (Exception e) {
            // Not saved yet so call the ibm watson service to get the results
            getAndSaveJobResults(jobId);
        }
        MediaPackageElementBuilder builder = MediaPackageElementBuilderFactory.newInstance().newElementBuilder();
        return builder.elementFromURI(uri, Attachment.TYPE, new MediaPackageElementFlavor("captions", "ibm-watson-json"));
    } catch (TranscriptionDatabaseException e) {
        throw new TranscriptionServiceException("Job id not informed and could not find transcription", e);
    }
}
Also used : MediaPackageElementBuilder(org.opencastproject.mediapackage.MediaPackageElementBuilder) TranscriptionJobControl(org.opencastproject.transcription.ibmwatson.persistence.TranscriptionJobControl) TranscriptionDatabaseException(org.opencastproject.transcription.ibmwatson.persistence.TranscriptionDatabaseException) TranscriptionServiceException(org.opencastproject.transcription.api.TranscriptionServiceException) URI(java.net.URI) MediaPackageElementFlavor(org.opencastproject.mediapackage.MediaPackageElementFlavor) TranscriptionServiceException(org.opencastproject.transcription.api.TranscriptionServiceException) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException) TranscriptionDatabaseException(org.opencastproject.transcription.ibmwatson.persistence.TranscriptionDatabaseException) MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) IOException(java.io.IOException)

Example 3 with TranscriptionDatabaseException

use of org.opencastproject.transcription.ibmwatson.persistence.TranscriptionDatabaseException in project opencast by opencast.

the class IBMWatsonTranscriptionService method transcriptionError.

@Override
public void transcriptionError(String mpId, Object obj) throws TranscriptionServiceException {
    JSONObject jsonObj = null;
    String jobId = null;
    try {
        jsonObj = (JSONObject) obj;
        jobId = (String) jsonObj.get("id");
        // Update state in database
        database.updateJobControl(jobId, TranscriptionJobControl.Status.Error.name());
        TranscriptionJobControl jobControl = database.findByJob(jobId);
        logger.warn(String.format("Error callback received for media package %s, job id %s", jobControl.getMediaPackageId(), jobId));
        // Send notification email
        sendEmail("Transcription ERROR", String.format("There was a transcription error for for media package %s, job id %s.", jobControl.getMediaPackageId(), jobId));
    } catch (TranscriptionDatabaseException e) {
        logger.warn("Transcription error. State in db could not be updated to error for mpId {}, jobId {}", mpId, jobId);
        throw new TranscriptionServiceException("Could not update transcription job control db", e);
    }
}
Also used : TranscriptionJobControl(org.opencastproject.transcription.ibmwatson.persistence.TranscriptionJobControl) JSONObject(org.json.simple.JSONObject) TranscriptionDatabaseException(org.opencastproject.transcription.ibmwatson.persistence.TranscriptionDatabaseException) TranscriptionServiceException(org.opencastproject.transcription.api.TranscriptionServiceException)

Aggregations

TranscriptionServiceException (org.opencastproject.transcription.api.TranscriptionServiceException)3 TranscriptionDatabaseException (org.opencastproject.transcription.ibmwatson.persistence.TranscriptionDatabaseException)3 IOException (java.io.IOException)2 JSONObject (org.json.simple.JSONObject)2 TranscriptionJobControl (org.opencastproject.transcription.ibmwatson.persistence.TranscriptionJobControl)2 URI (java.net.URI)1 MediaPackageElementBuilder (org.opencastproject.mediapackage.MediaPackageElementBuilder)1 MediaPackageElementFlavor (org.opencastproject.mediapackage.MediaPackageElementFlavor)1 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)1 ServiceRegistryException (org.opencastproject.serviceregistry.api.ServiceRegistryException)1