Search in sources :

Example 76 with Predicate

use of com.google.common.base.Predicate in project jackrabbit-oak by apache.

the class DataStoreCacheUpgradeUtils method moveDownloadCache.

/**
     * Move the DataStore downloaded cache files to the appropriate folder used by the new cache
     * {@link FileCache}
     * @param path the root of the datastore
     */
public static void moveDownloadCache(final File path) {
    final List<String> exceptions = ImmutableList.of("tmp", UPLOAD_STAGING_DIR, DOWNLOAD_DIR);
    File newDownloadDir = new File(path, DOWNLOAD_DIR);
    Iterator<File> iterator = Files.fileTreeTraverser().postOrderTraversal(path).filter(new Predicate<File>() {

        @Override
        public boolean apply(File input) {
            return input.isFile() && !input.getParentFile().equals(path) && !notInExceptions(input, exceptions);
        }
    }).iterator();
    while (iterator.hasNext()) {
        File download = iterator.next();
        LOG.trace("Download cache file absolute pre-upgrade path " + download);
        File newDownload = new File(newDownloadDir, download.getAbsolutePath().substring(path.getAbsolutePath().length()));
        newDownload.getParentFile().mkdirs();
        LOG.trace("Downloaded cache file absolute post-upgrade path " + newDownload);
        try {
            FileUtils.moveFile(download, newDownload);
            LOG.info("Download cache file [{}] moved to [{}]", download, newDownload);
            recursiveDelete(download, path);
        } catch (Exception e) {
            LOG.warn("Unable to move download cache file [{}] to [{}]", download, newDownload);
        }
    }
}
Also used : File(java.io.File) Predicate(com.google.common.base.Predicate)

Example 77 with Predicate

use of com.google.common.base.Predicate in project jackrabbit-oak by apache.

the class FileBlobStore method getAllChunkIds.

@Override
public Iterator<String> getAllChunkIds(final long maxLastModifiedTime) throws Exception {
    FluentIterable<File> iterable = Files.fileTreeTraverser().postOrderTraversal(baseDir);
    final Iterator<File> iter = iterable.filter(new Predicate<File>() {

        // Ignore the directories and files newer than maxLastModifiedTime if specified
        @Override
        public boolean apply(@Nullable File input) {
            if (!input.isDirectory() && ((maxLastModifiedTime <= 0) || FileUtils.isFileOlder(input, maxLastModifiedTime))) {
                return true;
            }
            return false;
        }
    }).iterator();
    return new AbstractIterator<String>() {

        @Override
        protected String computeNext() {
            if (iter.hasNext()) {
                File file = iter.next();
                return FilenameUtils.removeExtension(file.getName());
            }
            return endOfData();
        }
    };
}
Also used : AbstractIterator(com.google.common.collect.AbstractIterator) File(java.io.File) Nullable(javax.annotation.Nullable) Predicate(com.google.common.base.Predicate)

Example 78 with Predicate

use of com.google.common.base.Predicate in project jackrabbit-oak by apache.

the class SegmentGraph method createRegExpFilter.

/**
     * Create a regular expression based inclusion filter for segment.
     *
     * @param pattern       regular expression specifying inclusion of nodes.
     * @return
     */
public static Predicate<UUID> createRegExpFilter(@Nonnull String pattern, @Nonnull final SegmentIdProvider idProvider) {
    final Pattern regExp = compile(checkNotNull(pattern));
    checkNotNull(idProvider);
    return new Predicate<UUID>() {

        @Override
        public boolean apply(UUID segment) {
            try {
                String info = getSegmentInfo(segment, idProvider);
                if (info == null) {
                    info = "NULL";
                }
                return regExp.matcher(info).matches();
            } catch (Exception e) {
                System.err.println("Error accessing segment " + segment + ": " + e);
                return false;
            }
        }
    };
}
Also used : Pattern(java.util.regex.Pattern) Throwables.getStackTraceAsString(com.google.common.base.Throwables.getStackTraceAsString) UUID(java.util.UUID) IOException(java.io.IOException) Predicate(com.google.common.base.Predicate)

Example 79 with Predicate

use of com.google.common.base.Predicate in project jackrabbit-oak by apache.

the class AbstractBlobTrackerRegistrationTest method assertTrackerReinitialized.

private void assertTrackerReinitialized() {
    File blobIdFiles = new File(repoHome, "blobids");
    ImmutableList<File> files = Files.fileTreeTraverser().postOrderTraversal(blobIdFiles).filter(new Predicate<File>() {

        @Override
        public boolean apply(@Nullable File input) {
            return input.getAbsolutePath().endsWith(".process");
        }
    }).toList();
    assertEquals(1, files.size());
}
Also used : File(java.io.File) Nullable(javax.annotation.Nullable) Predicate(com.google.common.base.Predicate)

Example 80 with Predicate

use of com.google.common.base.Predicate in project jackrabbit-oak by apache.

the class FilteringNodeStateTest method shouldHaveCorrectChildOrderProperty.

@Test
public void shouldHaveCorrectChildOrderProperty() throws CommitFailedException {
    final NodeState content = rootNodeState.getChildNode("content");
    final NodeState decorated = wrap("/content", content, null, of("/content/foo"), null, null);
    assertTrue(decorated.hasProperty(OAK_CHILD_ORDER));
    {
        // access via getProperty()
        final PropertyState childOrder = decorated.getProperty(OAK_CHILD_ORDER);
        final Iterable<String> values = childOrder.getValue(Type.STRINGS);
        assertEquals(newArrayList("football"), newArrayList(values));
    }
    {
        // access via getProperties()
        final Predicate<PropertyState> isChildOrderProperty = new Predicate<PropertyState>() {

            @Override
            public boolean apply(PropertyState propertyState) {
                return OAK_CHILD_ORDER.equals(propertyState.getName());
            }
        };
        final PropertyState childOrder = Iterables.find(decorated.getProperties(), isChildOrderProperty);
        final Iterable<String> values = childOrder.getValue(Type.STRINGS);
        assertEquals(newArrayList("football"), newArrayList(values));
    }
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) NodeStateTestUtils.getNodeState(org.apache.jackrabbit.oak.upgrade.util.NodeStateTestUtils.getNodeState) PropertyState(org.apache.jackrabbit.oak.api.PropertyState) Predicate(com.google.common.base.Predicate) Test(org.junit.Test)

Aggregations

Predicate (com.google.common.base.Predicate)217 List (java.util.List)37 Test (org.junit.Test)37 ArrayList (java.util.ArrayList)34 Nullable (javax.annotation.Nullable)33 Map (java.util.Map)24 UUID (java.util.UUID)21 IOException (java.io.IOException)20 File (java.io.File)18 HashMap (java.util.HashMap)15 Set (java.util.Set)14 Test (org.testng.annotations.Test)14 ImmutableList (com.google.common.collect.ImmutableList)13 Collection (java.util.Collection)11 DateTime (org.joda.time.DateTime)9 BigDecimal (java.math.BigDecimal)8 Path (javax.ws.rs.Path)8 Expression (com.sri.ai.expresso.api.Expression)7 Util (com.sri.ai.util.Util)7 XtextResource (org.eclipse.xtext.resource.XtextResource)7