@Override public void remove(Iterable<String> ids) throws IllegalArgumentException, YardException { yard.remove(ids); } @Override
@Override public void remove(Iterable<String> ids) throws IllegalArgumentException, YardException { yard.remove(ids); } @Override
@Override public void remove(String id) throws IllegalArgumentException, YardException { yard.remove(id); }
@Override public void remove(String id) throws IllegalArgumentException, YardException { yard.remove(id); }
@Test(expected = IllegalArgumentException.class) public void testRemoveRepresentationWithNull() throws YardException { getYard().remove((String) null); }
@Test(expected = IllegalArgumentException.class) public void testRemoveRepresentationsWithNull() throws YardException { getYard().remove((Iterable<String>) null); }
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); } }
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); } }
/** * Deleted both the representation and the metadata of an Entity * @param yard the yard to delete the entity from * @param entity the entity to delete * @throws YardException an any Exception while deleting the Entity */ private void deleteEntity(Entity entity) throws YardException { if(entity != null){ entityhubYard.remove(Arrays.asList( entity.getRepresentation().getId(), entity.getMetadata().getId())); } } private void deleteEntities(Collection<String> ids) throws YardException {
@Override public void delete(String id) throws ManagedSiteException { try { getYard().remove(id); } catch (YardException e) { throw new ManagedSiteException(e.getMessage(), e); } }
/** * Deleted both the representation and the metadata of an Entity * @param yard the yard to delete the entity from * @param entity the entity to delete * @throws YardException an any Exception while deleting the Entity */ private void deleteEntity(Entity entity) throws YardException { if(entity != null){ entityhubYard.remove(Arrays.asList( entity.getRepresentation().getId(), entity.getMetadata().getId())); } } private void deleteEntities(Collection<String> ids) throws YardException {
/** * 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); } } /**
/** * 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); } } /**
/** * Stores the baseMappings to the {@link Yard}. This may cause unexpected * behaviour for subsequest calls of the stored configuration does not * correspond with the actual data stored within the cache.<p> * Typically this is only used at the start or end of the creation of a * full Cache ({@link CacheStrategy#all}) of an referenced site (entity source).<p> * Note also that if the {@link #baseMapper} is <code>null</code> this * method removes any existing configuration from the yard. * @throws YardException an any error while storing the config to the yard. * @throws IllegalArgumentException if <code>null</code> is parsed as {@link Yard}. */ public static void storeBaseMappingsConfiguration(Yard yard,FieldMapper baseMapper) throws YardException,IllegalArgumentException { if(yard == null){ throw new IllegalArgumentException("The parsed Yard MUST NOT be NULL!"); } if(baseMapper == null){ yard.remove(Cache.BASE_CONFIGURATION_URI); } else { Representation config = yard.getValueFactory().createRepresentation(Cache.BASE_CONFIGURATION_URI); writeFieldConfig(config,baseMapper); yard.store(config); } } /**
/** * Stores the baseMappings to the {@link Yard}. This may cause unexpected * behaviour for subsequest calls of the stored configuration does not * correspond with the actual data stored within the cache.<p> * Typically this is only used at the start or end of the creation of a * full Cache ({@link CacheStrategy#all}) of an referenced site (entity source).<p> * Note also that if the {@link #baseMapper} is <code>null</code> this * method removes any existing configuration from the yard. * @throws YardException an any error while storing the config to the yard. * @throws IllegalArgumentException if <code>null</code> is parsed as {@link Yard}. */ public static void storeBaseMappingsConfiguration(Yard yard,FieldMapper baseMapper) throws YardException,IllegalArgumentException { if(yard == null){ throw new IllegalArgumentException("The parsed Yard MUST NOT be NULL!"); } if(baseMapper == null){ yard.remove(Cache.BASE_CONFIGURATION_URI); } else { Representation config = yard.getValueFactory().createRepresentation(Cache.BASE_CONFIGURATION_URI); writeFieldConfig(config,baseMapper); yard.store(config); } } /**
/** * 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())); }
/** * Tests that {@link Representation} IDs that are not stored by the yard are ignored by the multiple * remove method * * @throws YardException */ @Test public void testRemoveRepresentationsWithNonStoredValue() 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.stored"; String id2 = "urn:yard.test.testRemoveRepresentationsWithNullValue:representation.notStored"; Yard yard = getYard(); Representation test = yard.create(id); // create and add assertTrue(yard.isRepresentation(test.getId())); yard.remove(Arrays.asList(test.getId(), id2)); assertFalse(yard.isRepresentation(test.getId())); assertFalse(yard.isRepresentation(id2)); }
@Test public void testIsRepresentation() throws YardException { String id = "urn:yard.test.testIsRepresentation:representation.id"; Yard yard = getYard(); // Representations created via the yard need to be created (as empty // representation within the yard Representation test = create(); assertTrue(yard.isRepresentation(test.getId())); // Representations created via the ValueFactory MUST NOT be added to the // Yard Representation test2 = create(id, false); assertFalse(yard.isRepresentation(test2.getId())); // now store test2 and test again yard.store(test2); assertTrue(yard.isRepresentation(test2.getId())); // now remove test and test again yard.remove(test.getId()); assertFalse(yard.isRepresentation(test.getId())); yard.remove(test2.getId()); assertFalse(yard.isRepresentation(test2.getId())); }
/** * Tests that multiple Representations are removed. * * @throws YardException */ @Test public void testRemoveRepresentations() 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.id1"; String id2 = "urn:yard.test.testRemoveRepresentationsWithNullValue:representation.id2"; String field = "urn:the.field:used.for.this.Test"; String testValue = "This is a test"; Yard yard = getYard(); // use both ways to add the two Representations (should make no differences, // but one never can know ... Representation test1 = yard.create(id); // create and add Representation test2 = yard.getValueFactory().createRepresentation(id2); // create test2.add(field, testValue); // add value yard.store(test2);// store assertTrue(yard.isRepresentation(test1.getId())); // test if stored assertTrue(yard.isRepresentation(test2.getId())); yard.remove(Arrays.asList(test1.getId(), test2.getId())); // remove assertFalse(yard.isRepresentation(test1.getId())); // test if removed assertFalse(yard.isRepresentation(test2.getId())); } /**
yard.remove(test.getId()); // test (1) - the remove