Package ch.entwine.weblounge.common.repository

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


      synchronized (internalListener) {
        isRunning = false;
        error = t;
        fireOperationFailed(t);
      }
      throw new ContentRepositoryException(t);
    } finally {
      CurrentOperation.remove();
    }
  }
View Full Code Here


      if (error instanceof ContentRepositoryException)
        throw (ContentRepositoryException) error;
      else if (error instanceof IOException)
        throw (IOException) error;
      else
        throw new ContentRepositoryException(error);
    }
    return result;
  }
View Full Code Here

      initializing = true;

      // Find the site's bundle
      bundle = loadBundle(site);
      if (bundle == null)
        throw new ContentRepositoryException("Unable to locate bundle for site '" + site + "'");

      // Add the bundle contents to the index if needed
      File rootDirecotry = getRootDirectory();
      if (getResourceCount() == 0 || !rootDirecotry.exists() || rootDirecotry.list().length == 0)
        indexBundleContents();
View Full Code Here

        ResourceURI uri = pi.next();

        try {
          Resource<?> resource = loadResourceFromBundle(uri);
          if (resource == null) {
            throw new ContentRepositoryException("Unable to load " + uri.getType() + " " + uri + " from bundle");
          }

          // Update the uri, it now contains the id in addition to just the path
          uri = resource.getURI();

          // Make sure we are not updating existing resources, since this is the
          // first time import.
          if (exists(uri)) {
            throw new ContentRepositoryException("Error adding resource " + uri + " to repository: a resource with id '" + uri.getIdentifier() + "' or path '" + uri.getPath() + "' already exists");
          }

          logger.info("Loading {} {}:{}", new Object[] {
              uri.getType(),
              site,
              uri });
          Set<? extends ResourceContent> content = resource.contents();
          if (content.size() == 0) {
            put(resource);
          } else {
            for (ResourceContent c : content)
              resource.removeContent(c.getLanguage());
            put(resource);
            for (ResourceContent c : content) {
              InputStream is = null;
              try {
                is = loadResourceContentFromBundle(uri, c);
                if (is == null && c.getExternalLocation() == null)
                  throw new ContentRepositoryException("Resource content " + c + " missing from repository");
                putContent(uri, c, is);
              } finally {
                IOUtils.closeQuietly(is);
              }
            }
          }
        } catch (IOException e) {
          logger.error("Error reading " + uri.getType() + " " + uri + ": " + e.getMessage(), e);
          throw new ContentRepositoryException(e);
        }
      }
    } catch (ContentRepositoryException e) {
      cleanupAfterFailure();
      throw e;
View Full Code Here

      SearchQuery q = new SearchQueryImpl(site).withIdentifier(id).withPreferredVersion(version).withLimit(1).withField(PATH);
      SearchResultItem[] items = searchIdx.getByQuery(q).getItems();
      if (items.length > 0) {
        long versionInIndex = (Long) ((ResourceSearchResultItem) items[0]).getMetadataByKey(VERSION).getValue();
        if (items.length == 1 && versionInIndex == version)
          throw new ContentRepositoryException("Resource '" + id + "' already exists in version " + version);
        if (path == null) {
          path = (String) ((ResourceSearchResultItem) items[0]).getMetadataByKey(PATH).getValue();
          resource.getURI().setPath(path);
        }
      }
    }

    // Make sure we are not asked to add a resource to the index that has the
    // same path as an existing one
    if (path != null) {
      SearchQuery q = new SearchQueryImpl(site).withPath(path).withPreferredVersion(version).withLimit(1).withField(RESOURCE_ID);
      SearchResultItem[] items = searchIdx.getByQuery(q).getItems();
      if (items.length > 0) {
        long versionInIndex = (Long) ((ResourceSearchResultItem) items[0]).getMetadataByKey(VERSION).getValue();
        if (items.length == 1 && versionInIndex == version)
          throw new ContentRepositoryException("Resource '" + id + "' already exists in version " + version);
        if (id == null) {
          id = (String) ((ResourceSearchResultItem) items[0]).getMetadataByKey(RESOURCE_ID).getValue();
          resource.getURI().setIdentifier(id);
        }
      }
    }

    // Create an id if necessary. A missing id indicates that the resource
    // has never been added to the index before
    if (id == null) {
      id = UUID.randomUUID().toString();
      resource.setIdentifier(id);
      uri.setIdentifier(id);
    }

    try {
      searchIdx.add(resource);
    } catch (ContentRepositoryException e) {
      throw e;
    } catch (Throwable t) {
      throw new ContentRepositoryException("Error adding " + resource + " to index", t);
    }

    return uri;
  }
View Full Code Here

  @Override
  public void connect(Site site) throws ContentRepositoryException {
    // Find the site's bundle
    bundle = loadBundle(site);
    if (bundle == null)
      throw new ContentRepositoryException("Unable to locate bundle for site '" + site + "'");

    super.connect(site);
  }
View Full Code Here

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

   */
  public void connect(Site site) throws ContentRepositoryException {
    if (connected)
      throw new IllegalStateException("Content repository has already been started");
    if (site == null)
      throw new ContentRepositoryException("Site must not be null");
    this.site = site;

    try {
      index = loadIndex();
    } catch (IOException e) {
      throw new ContentRepositoryException("Error loading repository index", e);
    }

    Bundle bundle = loadBundle(site);
    if (bundle != null) {
      imageStyleTracker = new ImageStyleTracker(bundle.getBundleContext());
View Full Code Here

    try {
      connected = false;
      if (index != null)
        index.close();
    } catch (IOException e) {
      throw new ContentRepositoryException("Error closing repository index", e);
    }
  }
View Full Code Here

      InputStream is = null;
      try {
        ResourceSerializer<?, ?> serializer = getSerializerByType(uri.getType());
        if (serializer == null) {
          logger.warn("No resource serializer for type '{}' found", uri.getType());
          throw new ContentRepositoryException("No resource serializer for type '" + uri.getType() + "' found");
        }
        ResourceReader<?, ?> reader = serializer.getReader();
        is = IOUtils.toInputStream(searchResultItem.getResourceXml(), "utf-8");
        return (R) reader.read(is, site);
      } catch (Throwable t) {
        logger.error("Error loading {}: {}", uri, t.getMessage());
        throw new ContentRepositoryException(t);
      } finally {
        IOUtils.closeQuietly(is);
      }

    } else {

      try {
        Resource<?> resource = null;
        InputStream is = null;
        try {
          InputStream resourceStream = loadResource(uri);
          if (resourceStream == null) {
            return null;
          }
          is = new BufferedInputStream(resourceStream);
          ResourceSerializer<?, ?> serializer = getSerializerByType(uri.getType());
          ResourceReader<?, ?> reader = serializer.getReader();
          resource = reader.read(is, site);
        } catch (Throwable t) {
          String version = ResourceUtils.getVersionString(uri.getVersion());
          throw new IOException("Error reading " + version + " version of " + uri + " (" + uri.getIdentifier() + ")", t);
        } finally {
          IOUtils.closeQuietly(is);
        }

        if (resource == null) {
          logger.error("Index inconsistency detected: version '{}' of {} does not exist on disk", ResourceUtils.getVersionString(uri.getVersion()), uri);
          return null;
        }

        return (R) resource;
      } catch (IOException e) {
        logger.error("Error loading {}: {}", uri, e.getMessage());
        throw new ContentRepositoryException(e);
      }
    }

  }
View Full Code Here

TOP

Related Classes of ch.entwine.weblounge.common.repository.ContentRepositoryException

Copyright © 2018 www.massapicom. 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.