Package org.sonatype.nexus.proxy.attributes

Examples of org.sonatype.nexus.proxy.attributes.Attributes


        final RepositoryItemUid uid = item.getRepositoryItemUid();

        final AttributeStorage attributeStorage = repository
            .getAttributesHandler().getAttributeStorage();

        final Attributes attributes = attributeStorage
            .getAttributes(uid);

        attributes.put(ATTR_IS_SAVED, "true");
        attributes.put(ATTR_SAVE_TIME, "" + System.currentTimeMillis());

        attributeStorage.putAttributes(uid, attributes);

      } catch (final Exception e) {
View Full Code Here


    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);

    // verify that master item, requested during resolution has lastRequested greater or equal then shadow link
    Assert.assertTrue("Master have to be updated at least at same time or later then shadow",
        masterLastRequested >= shadowLastRequested);

    // check the shadow attributes programatically
    Attributes shadowItemAttrs =
        shadowRepository.getAttributesHandler().getAttributeStorage().getAttributes(
            shadowRepository.createUid(shadowPath));
    Assert.assertEquals("The attributes differ", shadowLastRequested, shadowItemAttrs.getLastRequested());

    // check the master attributes programatically
    Attributes masterItemAttrs =
        masterRepository.getAttributesHandler().getAttributeStorage().getAttributes(
            masterRepository.createUid(masterPath));
    Assert.assertEquals("The attributes differ", masterLastRequested, masterItemAttrs.getLastRequested());
  }
View Full Code Here

    fileTimestamp = mdFile.lastModified();

    // set up last checked timestamp so that nexus should go remote
    final RepositoryItemUid uid = item.getRepositoryItemUid();
    final AttributeStorage storage = uid.getRepository().getAttributesHandler().getAttributeStorage();
    final Attributes attributes = item.getRepositoryItemAttributes();
    attributes.setCheckedRemotely(System.currentTimeMillis() - ((Math.abs(age) + 1) * 60 * 1000));
    storage.putAttributes(uid, attributes);

    // We need to wait a bit to avoid the check that last remote check = current time
    Thread.sleep(500);
    repository.retrieveItem(new ResourceStoreRequest(path, false));
View Full Code Here

    // now request the object, the lastRequested timestamp should be updated
    StorageItem resultItem = repository.retrieveItem(request);
    Assert.assertTrue(resultItem.getLastRequested() > lastRequest);

    // check the shadow attributes
    Attributes shadowStorageItem =
        repository.getAttributesHandler().getAttributeStorage().getAttributes(
            repository.createUid(request.getRequestPath()));
    assertThat(shadowStorageItem.getLastRequested(), is(resultItem.getLastRequested()));
  }
View Full Code Here

    // now request the object, the lastRequested timestamp should be updated
    StorageItem resultItem = repository.retrieveItem(request);
    Assert.assertTrue(resultItem.getLastRequested() > lastRequest);

    // check the shadow attributes
    Attributes shadowStorageItem =
        repository.getAttributesHandler().getAttributeStorage().getAttributes(
            repository.createUid(request.getRequestPath()));
    assertThat(shadowStorageItem.getLastRequested(), is(resultItem.getLastRequested()));
  }
View Full Code Here

      throws ItemNotFoundException, UnsupportedStorageOperationException, LocalStorageException
  {
    RepositoryItemUid fromUid = repository.createUid(from.getRequestPath());

    try {
      Attributes fromAttr = repository.getAttributesHandler().getAttributeStorage().getAttributes(fromUid);

      // check does it have attrs at all
      if (fromAttr != null) {
        RepositoryItemUid toUid = repository.createUid(to.getRequestPath());
        fromAttr.setRepositoryId(toUid.getRepository().getId());
        fromAttr.setPath(toUid.getPath());
        repository.getAttributesHandler().getAttributeStorage().putAttributes(toUid, fromAttr);
      }

      File fromTarget = getFileFromBase(repository, from);
View Full Code Here

      throws ItemNotFoundException, LocalStorageException
  {
    final RepositoryItemUid itemUid = artifact.getRepositoryItemUid();
    itemUid.getLock().lock(Action.read);
    try {
      final Attributes attributes = artifact.getRepositoryItemAttributes();

      if (attributes == null) {
        throw new LocalStorageException("Null item repository attributes");
      }

      if (Boolean.parseBoolean(attributes.get(noattrname)) && !request.isRequestAsExpired()) {
        throw new ItemNotFoundException(request);
      }

      String hash = attributes.get(attrname);
      if (hash == null || request.isRequestAsExpired()) {
        try {
          final StorageFileItem remoteItem =
              (StorageFileItem) proxy.getRemoteStorage().retrieveItem(proxy, request, proxy.getRemoteUrl());
          hash = MUtils.readDigestFromFileItem(remoteItem); // closes http input stream
View Full Code Here

                                          String noattrname, String hash)
      throws IOException
  {
    final RepositoryItemUid itemUid = artifact.getRepositoryItemUid();
    itemUid.getLock().lock(Action.update);
    final Attributes attributes = artifact.getRepositoryItemAttributes();
    try {
      if (hash != null) {
        attributes.put(attrname, hash);
      }
      else {
        attributes.put(noattrname, Boolean.toString(true));
      }
      proxy.getAttributesHandler().storeAttributes(artifact);
    }
    finally {
      itemUid.getLock().unlock();
View Full Code Here

            neverDeleteFiles.add(repoFilePart);
          }

          // modify the file corresponding attribute
          final File attributeFile = new File(new File(new File(storageWorkDir, repoId), ".nexus/attributes"), filePart);
          Attributes attributes;
          try (FileInputStream in = new FileInputStream(attributeFile)) {
            attributes = marshaller.unmarshal(in);
          }

          // set new value
          attributes.setLastRequested(now + offset);

          // write it out
          try (FileOutputStream out = new FileOutputStream(attributeFile)) {
            marshaller.marshal(attributes, out);
          }
View Full Code Here

  private void changeProxyAttributeDate(File attributeFile, int daysFromToday)
      throws IOException
  {
    // load file
    Attributes attributes;
    FileInputStream fis = new FileInputStream(attributeFile);
    try {
      attributes = getMarshaller().unmarshal(fis);
    }
    finally {
      fis.close();
    }

    Calendar cal = Calendar.getInstance();
    cal.setTime(new Date());
    cal.add(Calendar.DATE, daysFromToday);

    // edit object
    attributes.incrementGeneration();
    attributes.setLastRequested(cal.getTime().getTime());
    attributes.setCheckedRemotely(cal.getTime().getTime());

    // save file
    FileOutputStream fos = new FileOutputStream(attributeFile);
    try {
      getMarshaller().marshal(attributes, fos);
View Full Code Here

TOP

Related Classes of org.sonatype.nexus.proxy.attributes.Attributes

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.