@Override protected Representation getRepresentation(String id) throws EntityhubException { return yard.getRepresentation(id); } @Override
@Override public Representation getRepresentation(String id) throws YardException, IllegalArgumentException { return yard.getRepresentation(id); }
@Override public Representation getRepresentation(String id) throws YardException, IllegalArgumentException { return yard.getRepresentation(id); }
@Override public Representation getEntityData(String id) { try { return yard.getRepresentation(id); } catch (YardException e) { log.error("Unable to get Representation '"+id+"' from Yard",e); return null; } catch (IllegalArgumentException e) { log.error("Unable to get Representation '"+id+"' from Yard",e); return null; } }
@Override public Representation getEntityData(String id) { try { return yard.getRepresentation(id); } catch (YardException e) { log.error("Unable to get Representation '"+id+"' from Yard",e); return null; } catch (IllegalArgumentException e) { log.error("Unable to get Representation '"+id+"' from Yard",e); return null; } }
/** * Loads an Entity (Representation and Metadata) for the parsed id. In case * the parsed id represents metadata, than the id of the returned Entity will * be different from the parsed id. * @param id the id of the data or the metadata of the Entity to load * @return the Entity or <code>null</code> if not found * @throws YardException On any error with the parsed Yard. */ private Entity loadEntity(String id) throws YardException { return id == null || id.isEmpty() ? null : loadEntity(entityhubYard.getRepresentation(id)); } /**
/** * Loads an Entity (Representation and Metadata) for the parsed id. In case * the parsed id represents metadata, than the id of the returned Entity will * be different from the parsed id. * @param id the id of the data or the metadata of the Entity to load * @return the Entity or <code>null</code> if not found * @throws YardException On any error with the parsed Yard. */ private Entity loadEntity(String id) throws YardException { return id == null || id.isEmpty() ? null : loadEntity(entityhubYard.getRepresentation(id)); } /**
/** * Lookups (or initialises) the metadata for the entity with the parsed id * @param entityId The id of the entity * @param init if the metadata should be initialised of not existing * @return the metadata for that Entity or <code>null</code> if not existing * and <code>init == false</code> * @throws YardException */ private Representation lookupMetadata(String entityId, boolean init) throws YardException { Representation metadata; //TODO: check the asumption that the Metadata always use the // extension ".meta" String metaID = entityId+".meta"; metadata = entityhubYard.getRepresentation(metaID); if(metadata == null){ metadata = entityhubYard.create(metaID); } return metadata; } /**
/** * Lookups (or initialises) the metadata for the entity with the parsed id * @param entityId The id of the entity * @param init if the metadata should be initialised of not existing * @return the metadata for that Entity or <code>null</code> if not existing * and <code>init == false</code> * @throws YardException */ private Representation lookupMetadata(String entityId, boolean init) throws YardException { Representation metadata; //TODO: check the asumption that the Metadata always use the // extension ".meta" String metaID = entityId+".meta"; metadata = entityhubYard.getRepresentation(metaID); if(metadata == null){ metadata = entityhubYard.create(metaID); } return metadata; } /**
@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 testGetRepresentationWithNull() throws YardException { getYard().getRepresentation(null); }
@Test(expected = IllegalArgumentException.class) public void testGetRepresentationWithEmptyString() throws YardException { getYard().getRepresentation(""); }
/** * Loads the additional field mappings used by this cache from the yard. * This method sets the {@link #baseMapper} field during initialisation. * @param yard The yard * @param nsPrefixService if present '{prefix}:{localname}' configurations are * @return The parsed mappings or <code>null</code> if no found * @throws YardException on any Error while reading the {@link Representation} * holding the configuration from the {@link Yard}. * @throws IllegalArgumentException if <code>null</code> is parsed as {@link Yard}. */ protected static FieldMapper loadAdditionalMappings(Yard yard, NamespacePrefixService nsPrefixService) throws YardException { if(yard == null){ throw new IllegalArgumentException("The parsed Yard MUST NOT be NULL!"); } Representation addConfig = yard.getRepresentation(Cache.ADDITIONAL_CONFIGURATION_URI); if(addConfig != null){ FieldMapper mapper = readFieldConfig(yard,addConfig, nsPrefixService); if(mapper == null){ log.warn("Invalid Additinal Configuration: Unable to parse FieldMappings from Field "+Cache.FIELD_MAPPING_CONFIG_FIELD+"-> return NULL (no additional Configuration)"); if(log.isWarnEnabled()){ log.warn(ModelUtils.getRepresentationInfo(addConfig)); } } return mapper; } else { return null; } } /**
/** * Loads the additional field mappings used by this cache from the yard. * This method sets the {@link #baseMapper} field during initialisation. * @param yard The yard * @param nsPrefixService if present '{prefix}:{localname}' configurations are * @return The parsed mappings or <code>null</code> if no found * @throws YardException on any Error while reading the {@link Representation} * holding the configuration from the {@link Yard}. * @throws IllegalArgumentException if <code>null</code> is parsed as {@link Yard}. */ protected static FieldMapper loadAdditionalMappings(Yard yard, NamespacePrefixService nsPrefixService) throws YardException { if(yard == null){ throw new IllegalArgumentException("The parsed Yard MUST NOT be NULL!"); } Representation addConfig = yard.getRepresentation(Cache.ADDITIONAL_CONFIGURATION_URI); if(addConfig != null){ FieldMapper mapper = readFieldConfig(yard,addConfig, nsPrefixService); if(mapper == null){ log.warn("Invalid Additinal Configuration: Unable to parse FieldMappings from Field "+Cache.FIELD_MAPPING_CONFIG_FIELD+"-> return NULL (no additional Configuration)"); if(log.isWarnEnabled()){ log.warn(ModelUtils.getRepresentationInfo(addConfig)); } } return mapper; } else { return null; } } /**
@Test public void testGetNonExistantRepresentation() throws YardException { String id = "urn:yard.test.testGetNonExistantRepresentation:representation.id"; assertNull(getYard().getRepresentation(id)); }
throw new IllegalArgumentException("The parsed Yard MUST NOT be NULL!"); Representation baseConfig = yard.getRepresentation(Cache.BASE_CONFIGURATION_URI); if(baseConfig != null){ FieldMapper mapper = readFieldConfig(yard,baseConfig, nsPrefixService);
String entityId = ModelUtils.getAboutRepresentation(rep); if(entityId != null){ data = entityhubYard.getRepresentation(entityId); metadata = rep; } else {
@Override public Entity getEntity(String id) throws ManagedSiteException { Representation rep; try { rep = getYard().getRepresentation(id); } catch (YardException e) { throw new ManagedSiteException(e.getMessage(), e); } if(rep != null){ Entity entity = new EntityImpl(config.getId(), rep, null); SiteUtils.initEntityMetadata(entity, siteMetadata, null); return entity; } else { return null; } }
test = yard.getRepresentation(id);