コード例 #1
0
ファイル: FileModel.java プロジェクト: aikuma/aikuma
  /**
   * Returns a File that refers to the item's file/metadata-file.
   *
   * @param option 0: file, 1: metadata-file
   * @return The file/metadata-file of the item
   */
  public File getFile(int option) {
    if (option != 0 && option != 1) return null;

    File itemPath;
    String suffix;
    if (fileType.equals(TAG_TYPE)) {
      if (option != 0) return null;

      itemPath = new File(FileIO.getOwnerPath(versionName, ownerId), Recording.TAG_PATH);
      itemPath.mkdirs();

      String groupId = getId().split("-")[0];
      return new File(itemPath, groupId + "/" + getId());
    } else if (fileType.equals(SPEAKER_TYPE)) {
      itemPath = new File(FileIO.getOwnerPath(versionName, ownerId), Speaker.PATH);
      itemPath.mkdirs();

      suffix = getSuffixExt(versionName, FileType.METADATA);

      return new File(itemPath, getId() + "/" + getId() + suffix);
    } else {
      itemPath = new File(FileIO.getOwnerPath(versionName, ownerId), Recording.PATH);
      itemPath.mkdirs();

      if (option == 0) suffix = "." + getExtension();
      else if (!(fileType.equals(SOURCE_TYPE)
          || fileType.equals(RESPEAKING_TYPE)
          || fileType.equals(TRANSLATION_TYPE)
          || fileType.equals(SEGMENT_TYPE))) // No metadata for transcript/mapping/preview
      return null;
      else suffix = getSuffixExt(versionName, FileType.METADATA);
      String groupId = getId().split("-")[0];

      return new File(itemPath, groupId + "/" + getId() + suffix);
    }
  }
コード例 #2
0
ファイル: FileModel.java プロジェクト: aikuma/aikuma
  /**
   * Get all of the recording's tags as a map(tagType, tagContent) (Used for fullText-indexing in
   * GoogleCloudService)
   *
   * @return Map of the recording's tags
   */
  public Map<String, String> getAllTagMapStrs() {
    // List<String> tagStrs = new ArrayList<String>();
    Map<String, String> tagStrs = new HashMap<String, String>();
    String respeakingId = "";

    if (!(fileType.equals(SOURCE_TYPE)
        || fileType.equals(SEGMENT_TYPE)
        || fileType.equals(RESPEAKING_TYPE)
        || fileType.equals(TRANSLATION_TYPE))) return tagStrs;
    if (!fileType.equals(SOURCE_TYPE)) respeakingId = getId().split("-")[3];

    List<String> selectedVerGroupOwners = new ArrayList<String>();
    List<File> groupDirList = new ArrayList<File>();

    File indexFile = new File(FileIO.getAppRootPath(), "index.json");
    JSONObject indices = null;
    try {
      indices = FileIO.readJSONObject(indexFile);
    } catch (IOException e1) {
      // TODO: How to deal with no index-file?
      Log.e(TAG, "getRespeakings(): error in reading index file");
      indices = new JSONObject();
    }

    // Collect directories where related respeakings exist form index file
    JSONArray verGroupOwnerList = (JSONArray) indices.get(getId());
    if (verGroupOwnerList == null) {
      // TODO: How to deal with no index-file?
      verGroupOwnerList = new JSONArray();
    }

    for (int i = 0; i < verGroupOwnerList.size(); i++) {
      String verGroupOwnerStr = (String) verGroupOwnerList.get(i);
      String[] splitVerGroupOwnerStr = verGroupOwnerStr.split("-");
      if (!splitVerGroupOwnerStr[0].matches(
          versionName)) // tag version needs to match recording version
      continue;

      File ownerDir = FileIO.getOwnerPath(splitVerGroupOwnerStr[0], splitVerGroupOwnerStr[2]);
      File groupDir = new File(Recording.getTagsPath(ownerDir), splitVerGroupOwnerStr[1]);

      if (groupDir.exists()) {
        selectedVerGroupOwners.add(verGroupOwnerStr);
        groupDirList.add(groupDir);
      }
    }

    // Process all the tag files
    for (int i = 0; i < groupDirList.size(); i++) {
      File groupDir = groupDirList.get(i);

      File[] tagFiles = groupDir.listFiles();
      for (File tagFile : tagFiles) {
        String tagTypeSuffix = "";
        String tagStr = "";
        String[] splitName = tagFile.getName().split("-");

        if (fileType.equals(SOURCE_TYPE) && splitName[2].equals(SOURCE_TYPE)) {
          tagTypeSuffix = splitName[3];
          tagStr = splitName[4];
        } else if (fileType.equals(splitName[2])
            && respeakingId.equals(splitName[3])) { // Respeaking/Interpret
          tagTypeSuffix = splitName[4];
          tagStr = splitName[5];
        } else continue;

        String val = tagStrs.get(tagTypeSuffix);
        if (val != null) {
          tagStrs.put(tagTypeSuffix, val + "|" + tagStr);
        } else {
          tagStrs.put(tagTypeSuffix, tagStr);
        }
        // tagStrs.add(tagTypeSuffix + "__" + tagStr);
        /*
        if(tagTypeSuffix.equals(Recording.SPEAKER_TAG_TYPE)) {

        } else if(tagTypeSuffix.equals(Recording.LANGUAGE_TAG_TYPE)) {

        } else if(tagTypeSuffix.equals(Recording.OLAC_TAG_TYPE)) {

        } else if(tagTypeSuffix.equals(Recording.CUSTOM_TAG_TYPE)) {

        }*/
      }
    }
    return tagStrs;
  }