class VersionDefinitionResourceProvider extends AbstractAuthorizedResourceProvider {

  @Override
  public Set<Resource> getResources(Request request, Predicate predicate)
      throws SystemException, UnsupportedPropertyException,
      NoSuchResourceException, NoSuchParentResourceException {

    Set<Resource> results = new HashSet<>();
    Set<String> requestPropertyIds = getRequestPropertyIds(request, predicate);

    Set<Map<String, Object>> propertyMaps = getPropertyMaps(predicate);

    if (propertyMaps.isEmpty()) {
      List<RepositoryVersionEntity> versions = s_repoVersionDAO.findRepositoriesWithVersionDefinitions();

      for (RepositoryVersionEntity entity : versions) {
        results.add(toResource(entity, requestPropertyIds));
      }
    } else {
      for (Map<String, Object> propertyMap : propertyMaps) {

        if (propertyMap.containsKey(SHOW_AVAILABLE) &&
            Boolean.parseBoolean(propertyMap.get(SHOW_AVAILABLE).toString())) {

          for (Entry<String, VersionDefinitionXml> entry : s_metaInfo.get().getVersionDefinitions().entrySet()) {
            Resource res = toResource(entry.getKey(), entry.getValue(), requestPropertyIds, null);
            res.setProperty(SHOW_AVAILABLE, true);
            results.add(res);
          }
        } else {
          String id = (String) propertyMap.get(VERSION_DEF_ID);

          if (null != id) {
            // id is either the repo version id from the db, or it's a phantom id from
            // the stack
            if (NumberUtils.isDigits(id)) {

              RepositoryVersionEntity entity = s_repoVersionDAO.findByPK(Long.parseLong(id));
              if (null != entity) {
                results.add(toResource(entity, requestPropertyIds));
              }
            } else {
              VersionDefinitionXml xml = s_metaInfo.get().getVersionDefinition(id);

              if (null == xml) {
                throw new NoSuchResourceException(String.format("Could not find version %s",
                    id));
              }
              Resource res = toResource(id, xml, requestPropertyIds, null);
              res.setProperty(SHOW_AVAILABLE, true);
              results.add(res);
            }
          } else {
            List<RepositoryVersionEntity> versions = s_repoVersionDAO.findRepositoriesWithVersionDefinitions();

            for (RepositoryVersionEntity entity : versions) {
              results.add(toResource(entity, requestPropertyIds));
            }
          }

        }
      }
    }
    return results;
  }

    VersionDefinitionResourceProvider();

}