@Override public void removeAll() throws YardException { //ensure that the baseConfig (if present) is not deleted by this //operation Representation baseConfig = yard.getRepresentation(Cache.BASE_CONFIGURATION_URI); yard.removeAll(); if(baseConfig != null){ yard.store(baseConfig); } }
@Override protected ValueFactory getValueFactory() { return yard.getValueFactory(); } @Override
@Override public final QueryResultList<String> findEntityReferences(FieldQuery query) throws YardException{ return entityhubYard.findReferences(query); } @Override
/** * Stores the current configuration used for caching documents back to the * {@link Yard}. This configuration is present in the {@link #additionalMapper}). * If this field is <code>null</code> than any existing configuration is * removed form the index. * @throws YardException on any error while changing the configuration in the * yard. * @throws IllegalArgumentException if <code>null</code> is parsed as {@link Yard}. */ protected static void storeAdditionalMappingsConfiguration(Yard yard,FieldMapper additionalMapper) throws YardException,IllegalArgumentException { if(yard == null){ throw new IllegalArgumentException("The parsed Yard MUST NOT be NULL!"); } if(additionalMapper == null){ yard.remove(Cache.ADDITIONAL_CONFIGURATION_URI); } else { Representation config = yard.getValueFactory().createRepresentation(Cache.ADDITIONAL_CONFIGURATION_URI); writeFieldConfig(config,additionalMapper); yard.store(config); } } /**
Representation test1 = yard.create(id); // create and add yard.store(test1);// store Representation test2 = yard.getValueFactory().createRepresentation(id2); // create yard.store(test2);// store assertTrue(yard.isRepresentation(test1.getId())); // test if stored assertTrue(yard.isRepresentation(test2.getId())); yard.removeAll(); // remove assertFalse(yard.isRepresentation(test1.getId())); // test if removed assertFalse(yard.isRepresentation(test2.getId())); yard.store(test1);// store assertTrue(yard.isRepresentation(test1.getId())); // test if stored yard.removeAll(); // remove assertFalse(yard.isRepresentation(test1.getId()));
@Test public void testFindTextWildcards(){ //init the test data FieldQueryTestData data = getFieldQueryTestData(); //prefix search with * FieldQuery query = getYard().getQueryFactory().createFieldQuery(); String wildcard = data.textValue1.getText(); wildcard = wildcard.substring(0, wildcard.length()-1) + "*"; query.setConstraint(data.textField, new TextConstraint(wildcard,PatternType.wildcard,false, "en")); query.addSelectedField(data.refField); query.addSelectedField(data.textField); validateQueryResults(query, getYard().find(query), Arrays.asList(data.r1en.getId(), data.r2en.getId()), Arrays.asList(data.refField, data.textField)); //wildcard with ? query = getYard().getQueryFactory().createFieldQuery(); //selects r1en and r2en wildcard = data.textValue1.getText(); wildcard = wildcard.substring(0, wildcard.length()-1) + "?"; query.setConstraint(data.textField, new TextConstraint(wildcard,PatternType.wildcard,false, "de")); query.addSelectedField(data.refField); query.addSelectedField(data.textField); validateQueryResults(query, getYard().find(query), Arrays.asList(data.r1de.getId(), data.r2de.getId()), Arrays.asList(data.refField, data.textField)); }
@Override protected Representation getRepresentation(String id) throws EntityhubException { return yard.getRepresentation(id); } @Override
@Override public Iterable<Representation> store(Iterable<Representation> representations) throws IllegalArgumentException, YardException { return yard.store(representations); }
/** * Stores the parsed representation to the Yard and also applies the * configured {@link #getFieldMapper() FieldMappings}. * @param The representation to store */ @Override public void store(Representation representation) throws ManagedSiteException { try { Yard yard = getYard(); fieldMapper.applyMappings(representation, representation, yard.getValueFactory()); yard.store(representation); } catch (YardException e) { throw new ManagedSiteException(e.getMessage(), e); } } /**
@Override public QueryResultList<Representation> findRepresentation(FieldQuery query) throws YardException, IllegalArgumentException { return yard.findRepresentation(query); }
@Override public String getId() { return yard.getId(); }
private void deleteEntities(Collection<String> ids) throws YardException { FieldQuery fieldQuery = getQueryFactory().createFieldQuery(); Collection<String> toDelete = new HashSet<String>(ids); for(String id : ids){ if(id != null && !id.isEmpty()){ fieldQuery.setConstraint(RdfResourceEnum.aboutRepresentation.getUri(), new ReferenceConstraint(id)); for(Iterator<String> it = entityhubYard.findReferences(fieldQuery).iterator();it.hasNext();){ toDelete.add(it.next()); } } } if(!toDelete.isEmpty()){ entityhubYard.remove(toDelete); } }
protected Representation create(String id, boolean store) throws YardException { Representation r; if (store) { r = getYard().create(id); } else if (id != null && !id.isEmpty()) { r = getYard().getValueFactory().createRepresentation(id); } else { throw new IllegalArgumentException("If store is FALSE the id MUST NOT be NULL nor EMPTY!"); } representationIds.add(r.getId()); return r; }
@Override protected FieldQuery createQuery() { return yard.getQueryFactory().createFieldQuery(); } @Override
/** * Same as {@link #testFindText()} but using * {@link Yard#findRepresentation(FieldQuery)} to execute the queries */ @Test public void testFindRepresentationText(){ //init the test data FieldQueryTestData data = getFieldQueryTestData(); //query for all languages and value1 FieldQuery query = getYard().getQueryFactory().createFieldQuery(); query.setConstraint(data.textField, new TextConstraint(data.textValue1.getText())); validateQueryResults(query, getYard().findRepresentation(query), Arrays.asList( data.r1.getId(), data.r1en.getId(), data.r1de.getId()), Arrays.asList(data.textField, data.refField, data.intField)); //same for value2 query = getYard().getQueryFactory().createFieldQuery(); query.setConstraint(data.textField, new TextConstraint(data.textValue2.getText())); validateQueryResults(query, getYard().findRepresentation(query), Arrays.asList( data.r2.getId(), data.r2en.getId(), data.r2de.getId()), Arrays.asList(data.textField, data.refField, data.intField)); } /**
/** * Tests if <code>null</code> values within the Iterable are ignored and do not cause an Exception * * @throws YardException */ @Test public void testRemoveRepresentationsWithNullValue() throws YardException { // NOTE: This test needs not to use the create(..) method, because we // remove the created representation form the store anyway as part of the // test String id = "urn:yard.test.testRemoveRepresentationsWithNullValue:representation.id"; Yard yard = getYard(); Representation test = yard.create(id); // create and add assertTrue(yard.isRepresentation(test.getId())); yard.remove(Arrays.asList(test.getId(), null)); assertFalse(yard.isRepresentation(test.getId())); }
/** * Same as {@link #testFindText()} but using * {@link Yard#findReferences(FieldQuery)} to execute the queries */ @Test public void testFindReferencesText(){ //init the test data FieldQueryTestData data = getFieldQueryTestData(); //query for all languages and value1 FieldQuery query = getYard().getQueryFactory().createFieldQuery(); query.setConstraint(data.textField, new TextConstraint(data.textValue1.getText())); validateQueryResults(query, getYard().findReferences(query), Arrays.asList(data.r1.getId(), data.r1en.getId(), data.r1de.getId())); //same for value2 query = getYard().getQueryFactory().createFieldQuery(); query.setConstraint(data.textField, new TextConstraint(data.textValue2.getText())); validateQueryResults(query, getYard().findReferences(query), Arrays.asList( data.r2.getId(), data.r2en.getId(), data.r2de.getId())); }
@Override public void remove(Iterable<String> ids) throws IllegalArgumentException, YardException { yard.remove(ids); } @Override
@Override public final QueryResultList<Representation> find(FieldQuery query) throws YardException{ return entityhubYard.find(query); } @Override