View Javadoc
1   /*
2    * Licensed to The Apereo Foundation under one or more contributor license
3    * agreements. See the NOTICE file distributed with this work for additional
4    * information regarding copyright ownership.
5    *
6    *
7    * The Apereo Foundation licenses this file to you under the Educational
8    * Community License, Version 2.0 (the "License"); you may not use this file
9    * except in compliance with the License. You may obtain a copy of the License
10   * at:
11   *
12   *   http://opensource.org/licenses/ecl2.txt
13   *
14   * Unless required by applicable law or agreed to in writing, software
15   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
17   * License for the specific language governing permissions and limitations under
18   * the License.
19   *
20   */
21  
22  package org.opencastproject.transcription.microsoft.azure.model;
23  
24  import org.apache.commons.lang3.StringUtils;
25  
26  import java.net.URI;
27  import java.util.List;
28  import java.util.Map;
29  
30  public class MicrosoftAzureSpeechTranscription {
31  
32    // Documentation:
33    // https://eastus.dev.cognitive.microsoft.com/docs/services/speech-to-text-api-v3-1/operations/Transcriptions_Get
34  
35    // CHECKSTYLE:OFF checkstyle:VisibilityModifier
36    public class TranscriptionFiles {
37      public String files;
38    }
39    public class TranscriptionSelf {
40      public String self;
41    }
42    public String self;
43    public TranscriptionSelf model;
44    public TranscriptionFiles links;
45    public Map<String, Object> properties;
46    public TranscriptionSelf project;
47    public TranscriptionSelf dataset;
48    public List<String> contentUrls;
49    public String contentContainerUrl;
50    public String locale;
51    public String displayName;
52    public String description;
53    public Map<String, Object> customProperties;
54    public String lastActionDateTime;
55    public String status;
56    public String createdDateTime;
57  
58    // CHECKSTYLE:ON checkstyle:VisibilityModifier
59  
60    /** Default constructor. */
61    public MicrosoftAzureSpeechTranscription() { }
62  
63    public String getID() {
64      if (StringUtils.isEmpty(self)) {
65        return null;
66      }
67      URI selfUriPath = URI.create(URI.create(self).getPath());
68      String speechServiceEndpointPath = "/speechtotext/v3.1/transcriptions/";
69      if (StringUtils.startsWithIgnoreCase(selfUriPath.getPath(), speechServiceEndpointPath)) {
70        String id = StringUtils.substringAfter(selfUriPath.getPath(), speechServiceEndpointPath);
71        if (!StringUtils.contains(id, "/")) {
72          return id;
73        }
74        return StringUtils.substringBefore(id, "/");
75      }
76      return null;
77    }
78  
79    public boolean isFailed() {
80      return StringUtils.equalsIgnoreCase("Failed", status);
81    }
82  
83    public boolean isRunning() {
84      return StringUtils.equalsIgnoreCase("Running", status);
85    }
86  
87    public boolean isSucceeded() {
88      return StringUtils.equalsIgnoreCase("Succeeded", status);
89    }
90  }