@Override public Iterable<Representation> store(Iterable<Representation> representations) throws IllegalArgumentException, YardException { return yard.store(representations); }
@Override public Iterable<Representation> store(Iterable<Representation> representations) throws IllegalArgumentException, YardException { return yard.store(representations); }
@Override public Representation store(Representation representation) throws IllegalArgumentException, YardException { return yard.store(applyCacheMappings(yard, representation)); }
@Override public Representation store(Representation representation) throws IllegalArgumentException, YardException { return yard.store(applyCacheMappings(yard, representation)); }
/** * Stores both the Representation and the Metadata of the parsed Entity to the * parsed yard.<p> * This Method also updated the modification date of the Metadata. * @param entity the stored entity * @throws YardException */ private void storeEntity(Entity entity) throws YardException{ if(entity != null){ entityhubYard.store(entity.getRepresentation()); entity.getMetadata().set(NamespaceEnum.dcTerms+"modified", new Date()); entityhubYard.store(entity.getMetadata()); } }
/** * Stores both the Representation and the Metadata of the parsed Entity to the * parsed yard.<p> * This Method also updated the modification date of the Metadata. * @param entity the stored entity * @throws YardException */ private void storeEntity(Entity entity) throws YardException{ if(entity != null){ entityhubYard.store(entity.getRepresentation()); entity.getMetadata().set(NamespaceEnum.dcTerms+"modified", new Date()); entityhubYard.store(entity.getMetadata()); } }
@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 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); } }
@Test(expected = IllegalArgumentException.class) public void testStoreRepresentationWithNull() throws YardException { getYard().store((Representation) null); }
@Test(expected = IllegalArgumentException.class) public void testStoreRepresentationsWithNull() throws YardException { getYard().store((Iterable<Representation>) null); }
@Test public void testStoreRepresentationsWithNullElement() throws YardException { String testId = "urn:yard.test.testStoreRepresentationsWithNullElement:representation.id"; Yard yard = getYard(); Representation test = create(testId, false); Iterable<Representation> added = yard.store(Arrays.asList(test, null)); // now test that only the valid representation was added and the null // value was ignored assertNotNull(added); Iterator<Representation> addedIt = added.iterator(); assertTrue(addedIt.hasNext()); assertEquals(test, addedIt.next()); assertFalse(addedIt.hasNext()); }
@Test public void testStoreRepresentation() throws YardException { // NOTE: this does not test if the updated view of the representation is // stored, but only that the store method works for representations // that are already in the Yard AND representations that are not yet // present within the yard String testId = "urn:yard.test.testStoreRepresentation:representation.id1"; String testId2 = "urn:yard.test.testStoreRepresentation:representation.id2"; Yard yard = getYard(); Representation test = create(testId, false); Representation added = yard.store(test); // this adds the representation assertEquals(test, added); Representation test2 = create(testId2, true); // this creates and adds the representation // now test that the representation can also be updated added = yard.store(test2); assertEquals(test2, added); }
/** * 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); } } /**
Yard yard = getYard(); final ValueFactory vf = yard.getValueFactory(); yard.store(new Iterable<Representation>() { @Override public Iterator<Representation> iterator() {
@Test public void testStoreRepresentations() throws YardException { // NOTE: this does not test if the updated view of the representation is // stored, but only that the store method works for representations // that are already in the Yard AND representations that are not yet // present within the yard String testId = "urn:yard.test.testStoreRepresentations:representation.id1"; String testId2 = "urn:yard.test.testStoreRepresentations:representation.id2"; String field = "urn:the.field:used.for.this.Test"; Yard yard = getYard(); Representation test = create(testId, false); Representation test2 = create(testId2, true); // this creates and adds the representation // now add both and mix Representations that are already present in the yard // with an other that is not yet present in the yard // change the representations to be sure to force an update even if the // implementation checks for changes before updating a representation test2.add(field, "test value 2"); Iterable<Representation> addedIterable = yard.store(Arrays.asList(test, test2)); assertNotNull(addedIterable); Collection<Representation> added = asCollection(addedIterable.iterator()); // test that both the parsed Representations where stored (updated & created) assertTrue(added.remove(test)); assertTrue(added.remove(test2)); assertTrue(added.isEmpty()); }
/** * 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); } } /**
@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())); }