/** * Find the page with the lowest position value which is visible in the current securit context * * @param securityContext * @return * @throws FrameworkException */ private Page findIndexPage(final SecurityContext securityContext) throws FrameworkException { Result<Page> results = StructrApp.getInstance(securityContext) .nodeQuery(Page.class) .sort(Page.position) .order(false) .getResult(); Collections.sort( results.getResults(), new GraphObjectComparator(Page.position, GraphObjectComparator.ASCENDING)); // Find first visible page Page page = null; if (!results.isEmpty()) { int i = 0; while (page == null || (i < results.size() && !securityContext.isVisible(page))) { page = results.get(i++); } } return page; }
private List<Linkable> findPossibleEntryPointsByName( final SecurityContext securityContext, HttpServletRequest request, final String name) throws FrameworkException { List<Linkable> possibleEntryPoints = (List<Linkable>) request.getAttribute(POSSIBLE_ENTRY_POINTS); if (CollectionUtils.isNotEmpty(possibleEntryPoints)) { return possibleEntryPoints; } if (name.length() > 0) { logger.log(Level.FINE, "Requested name: {0}", name); final Query query = StructrApp.getInstance(securityContext).nodeQuery(); query.and(AbstractNode.name, name); query.and().orType(Page.class).orTypes(File.class); // Searching for pages needs super user context anyway Result results = query.getResult(); logger.log(Level.FINE, "{0} results", results.size()); request.setAttribute(POSSIBLE_ENTRY_POINTS, results.getResults()); return (List<Linkable>) results.getResults(); } return Collections.EMPTY_LIST; }
public void test04SearchByLocation() { try { final PropertyMap props = new PropertyMap(); final PropertyKey lat = TestSeven.latitude; final PropertyKey lon = TestSeven.longitude; final String type = TestSeven.class.getSimpleName(); props.put(lat, 50.12284d); props.put(lon, 8.73923d); props.put(AbstractNode.name, "TestSeven-0"); AbstractNode node = createTestNode(type, props); boolean includeDeletedAndHidden = true; boolean publicOnly = false; List<SearchAttribute> searchAttributes = new LinkedList<SearchAttribute>(); searchAttributes.add(new TextualSearchAttribute(AbstractNode.type, type, SearchOperator.AND)); searchAttributes.add( new DistanceSearchAttribute( "Hanauer Landstr. 200, 60314 Frankfurt, Germany", 10.0, SearchOperator.AND)); Result result = searchNodeCommand.execute(includeDeletedAndHidden, publicOnly, searchAttributes); assertEquals(1, result.size()); assertTrue(result.get(0).equals(node)); } catch (FrameworkException ex) { logger.log(Level.SEVERE, ex.toString()); fail("Unexpected exception"); } }
public void test02SearchSingleNodeByDate() { try { PropertyMap props = new PropertyMap(); PropertyKey key = TestOne.aDate; Date date = new Date(); String type = TestOne.class.getSimpleName(); props.put(key, date); AbstractNode node = createTestNode(type, props); boolean includeDeletedAndHidden = true; boolean publicOnly = false; List<SearchAttribute> searchAttributes = new LinkedList<SearchAttribute>(); searchAttributes.add(new TextualSearchAttribute(AbstractNode.type, type, SearchOperator.AND)); searchAttributes.add(new FilterSearchAttribute(key, date, SearchOperator.AND)); Result result = searchNodeCommand.execute(includeDeletedAndHidden, publicOnly, searchAttributes); assertEquals(1, result.size()); assertTrue(result.get(0).equals(node)); } catch (FrameworkException ex) { logger.log(Level.SEVERE, ex.toString()); fail("Unexpected exception"); } }
public void testSimpleSearchOnNode() { try { final PropertyMap properties = new PropertyMap(); final PropertyKey<String> key = TestFour.stringProperty; properties.put(key, "test"); final TestFour testEntity = createTestNode(TestFour.class, properties); assertNotNull(testEntity); try (final Tx tx = app.tx()) { // check value from database assertEquals("test", testEntity.getProperty(key)); Result<TestFour> result = app.nodeQuery(TestFour.class).and(key, "test").getResult(); assertEquals(result.size(), 1); assertEquals(result.get(0), testEntity); } } catch (FrameworkException fex) { fail("Unable to store array"); } }
public void test01SearchSingleNodeByName() { try { PropertyMap props = new PropertyMap(); PropertyKey key = AbstractNode.name; String name = "89w3hklsdfghsdkljth"; props.put(key, name); AbstractNode node = createTestNode(TestOne.class.getSimpleName(), props); boolean includeDeletedAndHidden = true; boolean publicOnly = false; List<SearchAttribute> searchAttributes = new LinkedList<SearchAttribute>(); searchAttributes.add(new TextualSearchAttribute(key, name, SearchOperator.AND)); Result result = searchNodeCommand.execute(includeDeletedAndHidden, publicOnly, searchAttributes); assertTrue(result.size() == 1); assertTrue(result.get(0).equals(node)); // Change name attribute and search again name = "klppptzoehigösoiutzüw0e9hg"; node.setProperty(key, name); searchAttributes.clear(); searchAttributes.add(new TextualSearchAttribute(key, name, SearchOperator.AND)); result = searchNodeCommand.execute(includeDeletedAndHidden, publicOnly, searchAttributes); assertTrue(result.size() == 1); assertTrue(result.get(0).equals(node)); } catch (FrameworkException ex) { logger.log(Level.SEVERE, ex.toString()); fail("Unexpected exception"); } }
/** * Find first node whose name matches the last part of the given path * * @param securityContext * @param request * @param path * @return * @throws FrameworkException */ private AbstractNode findFirstNodeByName( final SecurityContext securityContext, HttpServletRequest request, final String path) throws FrameworkException { final String name = PathHelper.getName(path); if (!name.isEmpty()) { logger.log(Level.FINE, "Requested name: {0}", name); final Result results = StructrApp.getInstance(securityContext) .nodeQuery() .and(AbstractNode.name, name) .getResult(); logger.log(Level.FINE, "{0} results", results.size()); request.setAttribute(POSSIBLE_ENTRY_POINTS, results.getResults()); return (results.size() > 0 ? (AbstractNode) results.get(0) : null); } return null; }
public void testSimpleSearchOnRelationship() { try { final TestOne testOne = createTestNode(TestOne.class); final TestFour testFour = createTestNode(TestFour.class); final Property<String> key = OneFourOneToOne.stringProperty; assertNotNull(testOne); assertNotNull(testFour); final OneFourOneToOne testEntity = createTestRelationship(testOne, testFour, OneFourOneToOne.class); assertNotNull(testEntity); try (final Tx tx = app.tx()) { testEntity.setProperty(key, "test"); tx.success(); } try (final Tx tx = app.tx()) { // check value from database assertEquals("test", testEntity.getProperty(key)); Result<OneFourOneToOne> result = app.relationshipQuery(OneFourOneToOne.class).and(key, "test").getResult(); assertEquals(result.size(), 1); assertEquals(result.get(0), testEntity); } } catch (FrameworkException fex) { fail("Unable to store array"); } }
public void test06DistanceSearchOnEmptyDB() { try { boolean includeDeletedAndHidden = true; boolean publicOnly = false; List<SearchAttribute> searchAttributes = new LinkedList<SearchAttribute>(); searchAttributes.add( new DistanceSearchAttribute( "Hanauer Landstr. 200, 60314 Frankfurt, Germany", 10.0, SearchOperator.AND)); Result result = searchNodeCommand.execute(includeDeletedAndHidden, publicOnly, searchAttributes); assertEquals(0, result.size()); } catch (FrameworkException ex) { logger.log(Level.SEVERE, ex.toString()); System.out.println(ex.toString()); fail("Unexpected exception"); } }