Examples of ContentRepositoryException


Examples of ch.entwine.weblounge.common.repository.ContentRepositoryException

    try {
      uris = listResources();
    } catch (IOException e) {
      logger.error("Error reading available uris: {}", e.getMessage());
      throw new ContentRepositoryException(e);
    }

    for (ResourceURI uri : uris) {

      // Rule out types that we don't need
View Full Code Here

Examples of ch.entwine.weblounge.common.repository.ContentRepositoryException

      newIndex = new ContentRepositoryIndex(site, searchIndex);
      indexingOffsite = true;
      rebuildIndex(newIndex);
    } catch (IOException e) {
      indexingOffsite = false;
      throw new ContentRepositoryException("Error creating index " + site.getIdentifier(), e);
    } finally {
      try {
        if (newIndex != null)
          newIndex.close();
      } catch (IOException e) {
        throw new ContentRepositoryException("Error closing new index " + site.getIdentifier(), e);
      }
    }

    try {
      indexing = true;
      index.close();
      logger.info("Loading new index");
      index = new ContentRepositoryIndex(site, searchIndex);
    } catch (IOException e) {
      Throwable cause = e.getCause();
      if (cause == null)
        cause = e;
      throw new ContentRepositoryException("Error during reindex of '" + site.getIdentifier() + "'", cause);
    } finally {
      indexing = false;
      indexingOffsite = false;
      logger.info("Switching site '{}' back to write mode", site);
      readOnly = oldReadOnly;
View Full Code Here

Examples of ch.entwine.weblounge.common.repository.ContentRepositoryException

        logger.info("Site index populated in {} ms", ConfigurationUtils.toHumanReadableDuration(time));
        logger.info("{} resources added to index", resourceCount);
      }
    } catch (IOException e) {
      success = false;
      throw new ContentRepositoryException("Error while writing to index", e);
    } catch (MalformedResourceURIException e) {
      success = false;
      throw new ContentRepositoryException("Error while reading resource uri for index", e);
    } finally {
      if (!success) {
        try {
          idx.clear();
        } catch (IOException e) {
View Full Code Here

Examples of ch.entwine.weblounge.common.repository.ContentRepositoryException

    if (!preparedIndices.contains(query.getSite().getIdentifier())) {
      try {
        createIndex(query.getSite());
      } catch (IOException e) {
        throw new ContentRepositoryException(e);
      }
    }

    logger.debug("Searching index using query '{}'", query);

    // See if the index version exists and check if it matches.
    String indexName = query.getSite().getIdentifier();
    SearchRequestBuilder requestBuilder = new SearchRequestBuilder(nodeClient);
    requestBuilder.setIndices(indexName);
    requestBuilder.setSearchType(SearchType.QUERY_THEN_FETCH);
    requestBuilder.setPreference("_local");

    // Create the actual search query
    QueryBuilder queryBuilder = new ElasticSearchSearchQuery(query);
    requestBuilder.setQuery(queryBuilder);
    logger.debug("Searching for {}", requestBuilder.toString());

    // Make sure all fields are being returned
    if (query.getFields().length > 0) {
      requestBuilder.addFields(query.getFields());
      requestBuilder.addField(IndexSchema.RESOURCE_ID);
      requestBuilder.addField(IndexSchema.PATH);
      requestBuilder.addField(IndexSchema.VERSION);
    } else {
      requestBuilder.addField("*");
    }

    // Restrict the scope to the given type
    if (query.getTypes().length > 0) {
      requestBuilder.setTypes(query.getTypes());
    } else {
      requestBuilder.setTypes(FileResource.TYPE, ImageResource.TYPE, MovieResource.TYPE, Page.TYPE);
    }

    // Pagination
    if (query.getOffset() >= 0)
      requestBuilder.setFrom(query.getOffset());

    if (query.getLimit() >= 0)
      requestBuilder.setSize(query.getLimit());

    // Order by publishing date
    if (!SearchQuery.Order.None.equals(query.getPublishingDateSortOrder())) {
      switch (query.getPublishingDateSortOrder()) {
        case Ascending:
          requestBuilder.addSort(IndexSchema.PUBLISHED_FROM, SortOrder.ASC);
          break;
        case Descending:
          requestBuilder.addSort(IndexSchema.PUBLISHED_FROM, SortOrder.DESC);
          break;
        case None:
        default:
          break;
      }
    }

    // Order by modification date
    else if (!SearchQuery.Order.None.equals(query.getModificationDateSortOrder())) {
      switch (query.getModificationDateSortOrder()) {
        case Ascending:
          requestBuilder.addSort(IndexSchema.MODIFIED, SortOrder.ASC);
          break;
        case Descending:
          requestBuilder.addSort(IndexSchema.MODIFIED, SortOrder.DESC);
          break;
        case None:
        default:
          break;
      }
    }

    // Order by creation date
    else if (!SearchQuery.Order.None.equals(query.getCreationDateSortOrder())) {
      switch (query.getCreationDateSortOrder()) {
        case Ascending:
          requestBuilder.addSort(IndexSchema.CREATED, SortOrder.ASC);
          break;
        case Descending:
          requestBuilder.addSort(IndexSchema.CREATED, SortOrder.DESC);
          break;
        case None:
        default:
          break;
      }
    }

    // Order by score
    // TODO: Order by score
    // else {
    // requestBuilder.addSort(IndexSchema.SCORE, SortOrder.DESC);
    // }

    try {

      // Execute the query and try to get hold of a query response
      SearchResponse response = null;
      try {
        response = nodeClient.search(requestBuilder.request()).actionGet();
      } catch (Throwable t) {
        throw new ContentRepositoryException(t);
      }

      // Create and configure the query result
      long hits = response.getHits().getTotalHits();
      long size = response.getHits().getHits().length;
      SearchResultImpl result = new SearchResultImpl(query, hits, size);
      result.setSearchTime(response.getTookInMillis());

      // Walk through response and create new items with title, creator, etc:
      for (SearchHit doc : response.getHits()) {

        // Get the resource serializer
        String type = doc.getType();
        ResourceSerializer<?, ?> serializer = resourceSerializer.getSerializerByType(type);
        if (serializer == null) {
          logger.warn("Skipping search result due to missing serializer of type {}", type);
          size--;
          continue;
        }

        // Wrap the search result metadata
        List<ResourceMetadata<?>> metadata = new ArrayList<ResourceMetadata<?>>(doc.getFields().size());
        for (SearchHitField field : doc.getFields().values()) {
          String name = field.getName();
          ResourceMetadata<Object> m = new ResourceMetadataImpl<Object>(name);
          // TODO: Add values with more care (localized, correct type etc.)
          if (field.getValues().size() > 1) {
            for (Object v : field.getValues()) {
              m.addValue(v);
            }
          } else {
            m.addValue(field.getValue());
          }
          metadata.add(m);
        }

        // Get the score for this item
        float score = doc.getScore();

        // Have the serializer in charge create a type-specific search result
        // item
        try {
          SearchResultItem item = serializer.toSearchResultItem(query.getSite(), score, metadata);
          result.addResultItem(item);
        } catch (Throwable t) {
          logger.warn("Error during search result serialization: '{}'. Skipping this search result.", t.getMessage());
          size--;
          continue;
        }
      }

      result.setDocumentCount(size);
      return result;

    } catch (Throwable t) {
      throw new ContentRepositoryException("Error querying index", t);
    }
  }
View Full Code Here

Examples of ch.entwine.weblounge.common.repository.ContentRepositoryException

    if (!preparedIndices.contains(uri.getSite().getIdentifier())) {
      try {
        createIndex(uri.getSite());
      } catch (IOException e) {
        throw new ContentRepositoryException(e);
      }
    }

    logger.debug("Removing element with id '{}' from searching index", uri.getIdentifier());
View Full Code Here

Examples of ch.entwine.weblounge.common.repository.ContentRepositoryException

    if (!preparedIndices.contains(resource.getURI().getSite().getIdentifier())) {
      try {
        createIndex(resource.getURI().getSite());
      } catch (IOException e) {
        throw new ContentRepositoryException(e);
      }
    }

    // Have the serializer create an input document
    ResourceURI uri = resource.getURI();
    String resourceType = uri.getType();
    ResourceSerializer<?, ?> serializer = resourceSerializer.getSerializerByType(resourceType);
    if (serializer == null)
      throw new ContentRepositoryException("Unable to create an input document for " + resource + ": no serializer found");

    // Add the resource to the index
    List<ResourceMetadata<?>> resourceMetadata = serializer.toMetadata(resource);
    ElasticSearchDocument doc = new ElasticSearchDocument(uri, resourceMetadata);
    try {
      update(doc);
    } catch (Throwable t) {
      throw new ContentRepositoryException("Cannot write resource " + resource + " to index", t);
    }

    // Adjust the version information
    updateVersions(uri);
  }
View Full Code Here

Examples of ch.entwine.weblounge.common.repository.ContentRepositoryException

      throws ContentRepositoryException {

    String resourceType = uri.getType();
    ResourceSerializer<?, ?> serializer = resourceSerializer.getSerializerByType(resourceType);
    if (serializer == null)
      throw new ContentRepositoryException("Unable to create an input document for " + uri + ": no serializer found");

    // List all versions of the resource
    List<Resource<?>> resources = new ArrayList<Resource<?>>();
    Site site = uri.getSite();
    String id = uri.getIdentifier();
    SearchQuery q = new SearchQueryImpl(site).withIdentifier(id);
    for (SearchResultItem existingResource : getByQuery(q).getItems()) {
      List<ResourceMetadata<?>> resourceMetadata = ((ResourceSearchResultItem) existingResource).getMetadata();
      resources.add(serializer.toResource(site, resourceMetadata));
    }

    if (resources.size() == 0)
      return;

    // Add the alternate version information to each resource's metadata and
    // write it back to the search index (including the new one)
    List<ElasticSearchDocument> documents = new ArrayList<ElasticSearchDocument>();
    for (Resource<?> r : resources) {
      List<ResourceMetadata<?>> resourceMetadata = serializer.toMetadata(r);
      ResourceMetadataImpl<Long> alternateVersions = new ResourceMetadataImpl<Long>(ALTERNATE_VERSION);
      alternateVersions.setAddToFulltext(false);

      // Look for alternate versions
      long currentVersion = r.getURI().getVersion();
      for (Resource<?> v : resources) {
        long version = v.getURI().getVersion();
        if (version != currentVersion) {
          alternateVersions.addValue(version);
        }
      }

      // If alternate versions were found, add them
      if (alternateVersions.getValues().size() > 0) {
        resourceMetadata.add(alternateVersions);
      }

      // Write the resource to the index
      documents.add(new ElasticSearchDocument(r.getURI(), resourceMetadata));
    }

    // Now update all documents at once
    try {
      update(documents.toArray(new ElasticSearchDocument[documents.size()]));
    } catch (Throwable t) {
      throw new ContentRepositoryException("Cannot update versions of resource " + uri + " in index", t);
    }
  }
View Full Code Here

Examples of ch.entwine.weblounge.common.repository.ContentRepositoryException

      // Check for errors
      if (bulkResponse.hasFailures()) {
        for (BulkItemResponse item : bulkResponse.items()) {
          if (item.isFailed()) {
            logger.warn("Error updating {}: {}", item, item.failureMessage());
            throw new ContentRepositoryException(item.getFailureMessage());
          }
        }
      }

      return bulkResponse;
    } catch (Throwable t) {
      throw new ContentRepositoryException("Cannot update documents in index", t);
    }
  }
View Full Code Here

Examples of ch.entwine.weblounge.common.repository.ContentRepositoryException

    if (!preparedIndices.contains(uri.getSite().getIdentifier())) {
      try {
        createIndex(uri.getSite());
      } catch (IOException e) {
        throw new ContentRepositoryException(e);
      }
    }

    logger.debug("Updating path {} in search index to ", uri.getPath(), path);

    SearchQuery q = new SearchQueryImpl(uri.getSite()).withVersion(uri.getVersion()).withIdentifier(uri.getIdentifier());
    SearchResultItem[] searchResult = getByQuery(q).getItems();
    if (searchResult.length != 1) {
      logger.warn("Resource to be moved not found: {}", uri);
      return false;
    }

    // Have the serializer create an input document
    String resourceType = uri.getType();
    ResourceSerializer<?, ?> serializer = resourceSerializer.getSerializerByType(resourceType);
    if (serializer == null) {
      logger.error("Unable to create an input document for {}: no serializer found", uri);
      return false;
    }

    // Prepare the search metadata as a map, keep a reference to the path
    List<ResourceMetadata<?>> metadata = ((ResourceSearchResultItem) searchResult[0]).getMetadata();
    Map<String, ResourceMetadata<?>> metadataMap = new HashMap<String, ResourceMetadata<?>>();
    for (ResourceMetadata<?> m : metadata) {
      metadataMap.put(m.getName(), m);
    }

    // Add the updated metadata, keep the rest
    Resource<?> resource = serializer.toResource(uri.getSite(), metadata);
    resource.setPath(path);
    for (ResourceMetadata<?> m : serializer.toMetadata(resource)) {
      metadataMap.put(m.getName(), m);
    }
    metadata = new ArrayList<ResourceMetadata<?>>(metadataMap.values());

    // Read the current resource and post the updated data to the search
    // index
    try {
      update(new ElasticSearchDocument(resource.getURI(), metadata));
      return true;
    } catch (Throwable t) {
      throw new ContentRepositoryException("Cannot update resource " + uri + " in index", t);
    }
  }
View Full Code Here

Examples of ch.entwine.weblounge.common.repository.ContentRepositoryException

    // SuggestRequest request = new SuggestRequest(solrServer, dictionary,
    // onlyMorePopular, count, collate);
    try {
      return request.getSuggestions(seed);
    } catch (Throwable t) {
      throw new ContentRepositoryException(t);
    }
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.