Java Code Examples for org.apache.solr.common.SolrException.ErrorCode#NOT_FOUND

The following examples show how to use org.apache.solr.common.SolrException.ErrorCode#NOT_FOUND . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ManagedSynonymGraphFilterFactory.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Override
public void doGet(BaseSolrResource endpoint, String childId) {
  SolrQueryResponse response = endpoint.getSolrResponse();
  if (childId != null) {
    boolean ignoreCase = getIgnoreCase();
    String key = applyCaseSetting(ignoreCase, childId);

    // if ignoreCase==true, then we get the mappings using the lower-cased key
    // and then return a union of all case-sensitive keys, if false, then
    // we only return the mappings for the exact case requested
    CasePreservedSynonymMappings cpsm = synonymMappings.get(key);
    Set<String> mappings = (cpsm != null) ? cpsm.getMappings(ignoreCase, childId) : null;
    if (mappings == null)
      throw new SolrException(ErrorCode.NOT_FOUND,
          String.format(Locale.ROOT, "%s not found in %s", childId, getResourceId()));

    response.add(childId, mappings);
  } else {
    response.add(SYNONYM_MAPPINGS, buildMapToStore(getStoredView()));
  }
}
 
Example 2
Source File: ManagedWordSetResource.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/**
 * Implements the GET request to provide the list of words to the client.
 * Alternatively, if a specific word is requested, then it is returned
 * or a 404 is raised, indicating that the requested word does not exist.
 */
@Override
public void doGet(BaseSolrResource endpoint, String childId) {
  SolrQueryResponse response = endpoint.getSolrResponse();
  if (childId != null) {
    // downcase arg if we're configured to ignoreCase
    String key = getIgnoreCase() ? childId.toLowerCase(Locale.ROOT) : childId;       
    if (!managedWords.contains(key))
      throw new SolrException(ErrorCode.NOT_FOUND, 
          String.format(Locale.ROOT, "%s not found in %s", childId, getResourceId()));
      
    response.add(childId, key);
  } else {
    response.add(WORD_SET_JSON_FIELD, buildMapToStore(managedWords));      
  }
}
 
Example 3
Source File: ManagedSynonymFilterFactory.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Override
public void doGet(BaseSolrResource endpoint, String childId) {
  SolrQueryResponse response = endpoint.getSolrResponse();
  if (childId != null) {
    boolean ignoreCase = getIgnoreCase();
    String key = applyCaseSetting(ignoreCase, childId);
    
    // if ignoreCase==true, then we get the mappings using the lower-cased key
    // and then return a union of all case-sensitive keys, if false, then
    // we only return the mappings for the exact case requested
    CasePreservedSynonymMappings cpsm = synonymMappings.get(key);
    Set<String> mappings = (cpsm != null) ? cpsm.getMappings(ignoreCase, childId) : null;
    if (mappings == null)
      throw new SolrException(ErrorCode.NOT_FOUND,
          String.format(Locale.ROOT, "%s not found in %s", childId, getResourceId()));          
    
    response.add(childId, mappings);
  } else {
    response.add(SYNONYM_MAPPINGS, buildMapToStore(getStoredView()));      
  }
}
 
Example 4
Source File: RepositoryManager.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
private List<Path> downloadPackageArtifacts(String packageName, String version) throws SolrException {
  try {
    SolrPackageRelease release = getPackageRelease(packageName, version);
    List<Path> downloadedPaths = new ArrayList<Path>(release.artifacts.size());

    for (PackageRepository repo: getRepositories()) {
      if (repo.hasPackage(packageName)) {
        for (Artifact art: release.artifacts) {
          downloadedPaths.add(repo.download(art.url));
        }
        return downloadedPaths;
      }
    }
  } catch (IOException e) {
    throw new SolrException(ErrorCode.SERVER_ERROR, "Error during download of package " + packageName, e);
  }
  throw new SolrException(ErrorCode.NOT_FOUND, "Package not found in any repository.");
}
 
Example 5
Source File: MiniSolrCloudCluster.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public static Overseer getOpenOverseer(List<Overseer> overseers) {
  ArrayList<Overseer> shuffledOverseers = new ArrayList<Overseer>(overseers);
  Collections.shuffle(shuffledOverseers, LuceneTestCase.random());
  for (Overseer overseer : shuffledOverseers) {
    if (!overseer.isClosed()) {
      return overseer;
    }
  }
  throw new SolrException(ErrorCode.NOT_FOUND, "No open Overseer found");
}
 
Example 6
Source File: ManagedSynonymGraphFilterFactory.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized void doDeleteChild(BaseSolrResource endpoint, String childId) {
  boolean ignoreCase = getIgnoreCase();
  String key = applyCaseSetting(ignoreCase, childId);

  CasePreservedSynonymMappings cpsm = synonymMappings.get(key);
  if (cpsm == null)
    throw new SolrException(ErrorCode.NOT_FOUND,
        String.format(Locale.ROOT, "%s not found in %s", childId, getResourceId()));

  if (ignoreCase) {
    // delete all mappings regardless of case
    synonymMappings.remove(key);
  } else {
    // just delete the mappings for the specific case-sensitive key
    if (cpsm.mappings.containsKey(childId)) {
      cpsm.mappings.remove(childId);

      if (cpsm.mappings.isEmpty())
        synonymMappings.remove(key);
    } else {
      throw new SolrException(ErrorCode.NOT_FOUND,
          String.format(Locale.ROOT, "%s not found in %s", childId, getResourceId()));
    }
  }

  // store the updated data (using the stored view)
  storeManagedData(getStoredView());

  log.info("Removed synonym mappings for: {}", childId);
}
 
Example 7
Source File: ManagedWordSetResource.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/**
 * Deletes words managed by this resource.
 */
@Override
public synchronized void doDeleteChild(BaseSolrResource endpoint, String childId) {
  // downcase arg if we're configured to ignoreCase
  String key = getIgnoreCase() ? childId.toLowerCase(Locale.ROOT) : childId;       
  if (!managedWords.contains(key))
    throw new SolrException(ErrorCode.NOT_FOUND, 
        String.format(Locale.ROOT, "%s not found in %s", childId, getResourceId()));

  managedWords.remove(key);
  storeManagedData(managedWords);
  log.info("Removed word: {}", key);
}
 
Example 8
Source File: ManagedSynonymFilterFactory.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized void doDeleteChild(BaseSolrResource endpoint, String childId) {
  boolean ignoreCase = getIgnoreCase();
  String key = applyCaseSetting(ignoreCase, childId);
  
  CasePreservedSynonymMappings cpsm = synonymMappings.get(key);
  if (cpsm == null)
    throw new SolrException(ErrorCode.NOT_FOUND, 
        String.format(Locale.ROOT, "%s not found in %s", childId, getResourceId()));

  if (ignoreCase) {
    // delete all mappings regardless of case
    synonymMappings.remove(key);
  } else {
    // just delete the mappings for the specific case-sensitive key
    if (cpsm.mappings.containsKey(childId)) {
      cpsm.mappings.remove(childId);
      
      if (cpsm.mappings.isEmpty())
        synonymMappings.remove(key);            
    } else {
      throw new SolrException(ErrorCode.NOT_FOUND, 
          String.format(Locale.ROOT, "%s not found in %s", childId, getResourceId()));          
    }
  }
  
  // store the updated data (using the stored view)
  storeManagedData(getStoredView());
  
  log.info("Removed synonym mappings for: {}", childId);      
}
 
Example 9
Source File: PackageUtils.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/**
 * Returns JSON string from a given URL
 */
public static String getJsonStringFromUrl(HttpClient client, String url) {
  try {
    HttpResponse resp = client.execute(new HttpGet(url));
    if (resp.getStatusLine().getStatusCode() != 200) {
      throw new SolrException(ErrorCode.NOT_FOUND,
          "Error (code="+resp.getStatusLine().getStatusCode()+") fetching from URL: "+url);
    }
    return IOUtils.toString(resp.getEntity().getContent(), "UTF-8");
  } catch (UnsupportedOperationException | IOException e) {
    throw new RuntimeException(e);
  }
}
 
Example 10
Source File: MockExchangeRateProvider.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
  public double getExchangeRate(String sourceCurrencyCode, String targetCurrencyCode) {
//    System.out.println("***** getExchangeRate("+sourceCurrencyCode+targetCurrencyCode+")");
    if(sourceCurrencyCode.equals(targetCurrencyCode)) return 1.0;

    Double result = map.get(sourceCurrencyCode+","+targetCurrencyCode);
    if(result == null) {
      throw new SolrException(ErrorCode.NOT_FOUND, "No exchange rate found for the pair "+sourceCurrencyCode+","+targetCurrencyCode);
    }
    return result;
  }