Package org.sonatype.nexus.proxy.item

Examples of org.sonatype.nexus.proxy.item.StorageItem


    }
  }

  private void onItemDelete(RepositoryItemEventDelete evt) throws IOException {
    // we only care about POM files
    StorageItem item = evt.getItem();
    if (item instanceof StorageFileItem && item.getPath().endsWith(".pom")) {
      calculator.removeArtifactUsage((StorageFileItem) item);
    }
  }
View Full Code Here


    }
  }

  private void onItemCache(RepositoryItemEventCache evt) throws IOException,
      ArtifactDescriptorException {
    StorageItem item = evt.getItem();
    if (item instanceof StorageFileItem && item.getPath().endsWith(".pom")) {
      calculator.calculateArtifactUsage((StorageFileItem) item);
    }
  }
View Full Code Here

  }

  private void onItemStore(RepositoryItemEventStore evt) throws IOException,
      ArtifactDescriptorException {
    // we only care about POM files
    StorageItem item = evt.getItem();
    if (item instanceof StorageFileItem && item.getPath().endsWith(".pom")) {
      calculator.calculateArtifactUsage((StorageFileItem) item);
    }
  }
View Full Code Here

        {
          installArchetypeCatalog(repository);
        }
        else if ( evt instanceof RepositoryItemEvent )
        {
          StorageItem item = ((RepositoryItemEvent) evt).getItem();
          if( item.getName().toLowerCase().endsWith(".deb") )
          {
            updateFileModificationDate( repository );
          }
        }
    }
View Full Code Here

      for(String path : PATHS_TO_GENERATOR_MAP.keySet())
      {
        try
        {
          // Retrieve the item, update the modification time and save it
        StorageItem item = repository.retrieveItem(new ResourceStoreRequest(path));
        item.getRepositoryItemAttributes().setModified(System.currentTimeMillis());
        repository.storeItem(false, item);
      }
        catch (StorageException e)
        {
          logger.error("e");
View Full Code Here

  {
    try {
      final ResourceStoreRequest request = new ResourceStoreRequest(DISCOVERY_STATUS_FILE_PATH);
      request.setRequestLocalOnly(true);
      request.setRequestGroupLocalOnly(true);
      @SuppressWarnings("deprecation")
      final StorageItem item = getMavenProxyRepository().retrieveItem(true, request);
      if (item instanceof StorageFileItem) {
        return (StorageFileItem) item;
      }
      else {
View Full Code Here

      try {
        // user may call stop()
        beforeWalk(context);

        if (!context.isStopped()) {
          final StorageItem item = context.getRepository().retrieveItem(true, context.getResourceStoreRequest());
          final WalkerFilter filter =
              context.getFilter() != null ? context.getFilter() : new DefaultStoreWalkerFilter();
          try {
            if (StorageCollectionItem.class.isAssignableFrom(item.getClass())) {
              int collCount = walkRecursive(0, context, filter, (StorageCollectionItem) item);
              context.getContext().put(WALKER_WALKED_COLLECTION_COUNT, collCount);
            }
            else {
              walkItem(context, filter, item);
View Full Code Here

    // simulate "user request" by adding IP address to requests
    shadowRequest.getRequestContext().put(AccessManager.REQUEST_REMOTE_ADDRESS, "127.0.0.1");
    masterRequest.getRequestContext().put(AccessManager.REQUEST_REMOTE_ADDRESS, "127.0.0.1");

    StorageItem shadowItem = shadowRepository.retrieveItem(shadowRequest);
    assertTrue("Shadow MUST return a link", StorageLinkItem.class.isAssignableFrom(shadowItem.getClass()));
    StorageItem masterItem = masterRepository.retrieveItem(masterRequest);
    assertTrue("Master MUST NOT return a link", !StorageLinkItem.class.isAssignableFrom(masterItem.getClass()));

    // produce a lastRequest timestamp to now less 10 days
    long lastRequest = System.currentTimeMillis() - 10 * A_DAY;

    // now set the lastRequest stamp programatically to both items to this "old" timestamp
    shadowRepository.getAttributesHandler().touchItemLastRequested(lastRequest, shadowItem);
    masterRepository.getAttributesHandler().touchItemLastRequested(lastRequest, masterItem);

    // now request the object, the lastRequested timestamp should be updated
    shadowItem = shadowRepository.retrieveItem(shadowRequest);
    assertTrue("Shadow MUST return a link", StorageLinkItem.class.isAssignableFrom(shadowItem.getClass()));

    // verify that shadow item lastRequested is updated, but master is still untouched
    // the attribute load will give us items without UIDs!
    Attributes shadowItem1 =
        shadowRepository.getAttributesHandler().getAttributeStorage().getAttributes(
            shadowRepository.createUid(shadowPath));
    Assert.assertTrue("Shadow must have updated lastRequested field!",
        shadowItem1.getLastRequested() > lastRequest);

    // verify that shadow item lastRequested is updated, but master is still untouched
    // the attribute load will give us items without UIDs!
    Attributes masterItem1 =
        masterRepository.getAttributesHandler().getAttributeStorage().getAttributes(
            masterRepository.createUid(masterPath));
    Assert.assertTrue("Master must have untouched lastRequested field!",
        masterItem1.getLastRequested() == lastRequest);

    // now dereference the link
    masterItem = getRootRouter().dereferenceLink((StorageLinkItem) shadowItem);
    assertTrue("Dereferenced item MUST NOT return a link", !StorageLinkItem.class.isAssignableFrom(masterItem
        .getClass()));

    // remember the lastRequests
    long shadowLastRequested = shadowItem.getLastRequested();
    long masterLastRequested = masterItem.getLastRequested();

    // verify that lastRequested is maintained (is updated to now)
    Assert.assertTrue("Shadow lastRequested have to be updated", shadowLastRequested > lastRequest);
    Assert.assertTrue("Master lastRequested have to be updated", masterLastRequested > lastRequest);

View Full Code Here

      String parentPath =
          req.getRequestPath().substring(0, req.getRequestPath().lastIndexOf(item.getName()));
      ResourceStoreRequest parentRequest = new ResourceStoreRequest(parentPath);

      while (parentRequest != null) {
        StorageItem parentItem = null;
        parentItem = this.retrieveItem(false, parentRequest);

        // this should be a collection Item
        if (StorageCollectionItem.class.isInstance(parentItem)) {
          StorageCollectionItem parentCollectionItem = (StorageCollectionItem) parentItem;
          try {
            if (parentCollectionItem.list().size() == 0) {
              deleteItem(false, parentRequest);
              parentRequest = new ResourceStoreRequest(parentCollectionItem.getParentPath());
            }
            else {
              // exit loop
              parentRequest = null;
            }
          }
          catch (AccessDeniedException e) {
            this.log.debug(
                "Failed to delete shadow parent: " + this.getId() + ":" + parentItem.getPath()
                    + " Access Denied", e);
            // exit loop
            parentRequest = null;
          }
          catch (NoSuchResourceStoreException e) {
            this.log.debug(
                "Failed to delete shadow parent: " + this.getId() + ":" + parentItem.getPath()
                    + " does not exist", e);
            // exit loop
            parentRequest = null;
          }
        }
        else {
          this.log.debug("ExpectedCollectionItem, found: " + parentItem.getClass() + ", ignoring.");
        }
      }
    }
  }
View Full Code Here

  @Override
  protected StorageItem doRetrieveItem(final ResourceStoreRequest request)
      throws IllegalOperationException, ItemNotFoundException, StorageException
  {
    StorageItem result = null;

    try {
      result = super.doRetrieveItem(request);

      return result;
View Full Code Here

TOP

Related Classes of org.sonatype.nexus.proxy.item.StorageItem

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.