Exemplo n.º 1
0
  protected List<IRepositoryViewObject> getSerializable(
      Project project, String id, boolean allVersion, boolean avoidSaveProject)
      throws PersistenceException {
    List<IRepositoryViewObject> toReturn = new ArrayList<IRepositoryViewObject>();

    if (lastFolderForItemMap.containsKey(id)) {
      ERepositoryObjectType itemType = lastRepositoryTypeForItemMap.get(id);
      String currentPath = lastFolderForItemMap.get(id);
      Object fullFolder = getFullFolder(project, itemType, currentPath);

      try {
        if (fullFolder != null
            && (fullFolder instanceof FolderItem || ((IFolder) fullFolder).exists())) {
          List<IRepositoryViewObject> itemsFound =
              getSerializableFromFolder(
                  project, fullFolder, id, itemType, allVersion, false, true, avoidSaveProject);
          if (!itemsFound.isEmpty()) { // add for items in recycle-bin
            toReturn.addAll(itemsFound);
            return toReturn;
          }
        }
      } catch (PersistenceException e) {
        // do nothing.
        // if any exception happen or can't find the item, just try to look for it everywhere.
      }
    }

    // added
    for (ERepositoryObjectType repositoryObjectType :
        (ERepositoryObjectType[]) ERepositoryObjectType.values()) {
      if (!repositoryObjectType.isResourceItem()) {
        continue;
      }
      Object folder = getFolder(project, repositoryObjectType);
      if (folder != null) {
        List<IRepositoryViewObject> itemsFound =
            getSerializableFromFolder(
                project,
                folder,
                id,
                repositoryObjectType,
                allVersion,
                true,
                true,
                avoidSaveProject);
        if (!itemsFound.isEmpty()) {
          addToHistory(
              id,
              repositoryObjectType,
              itemsFound.get(0).getProperty().getItem().getState().getPath());
          toReturn.addAll(itemsFound);
          // all items from the same id are always in the same folder
          // as we shouldn't find any other item with the same id in another folder.
          return toReturn;
        }
      }
    }
    return toReturn;
  }