Package org.apache.stanbol.entityhub.servicesapi.mapping

Examples of org.apache.stanbol.entityhub.servicesapi.mapping.FieldMapper


        //(1) Read the base mappings from the Yard
        this.baseMapper = CacheUtils.loadBaseMappings(yard,nsPrefixService);

        //(2) Init the additional mappings based on the configuration
        Object mappings = context.getProperties().get(Cache.ADDITIONAL_MAPPINGS);
        FieldMapper configuredMappings = null;
        if (mappings instanceof String[] && ((String[]) mappings).length > 0) {
            configuredMappings = new DefaultFieldMapperImpl(ValueConverterFactory.getDefaultInstance());
            for (String mappingString : (String[]) mappings) {
                FieldMapping fieldMapping = FieldMappingUtils.parseFieldMapping(mappingString, nsPrefixService);
                if (fieldMapping != null) {
                    configuredMappings.addMapping(fieldMapping);
                }
            }
            //check if there are valid mappings
            if (configuredMappings.getMappings().isEmpty()) {
                configuredMappings = null; //if no mappings where found set to null
            }
        }
        FieldMapper yardAdditionalMappings = CacheUtils.loadAdditionalMappings(yard,nsPrefixService);
        if (yardAdditionalMappings == null) {
            if (configuredMappings != null) {
                setAdditionalMappings(yard, configuredMappings);
            }
        } else if (!yardAdditionalMappings.equals(configuredMappings)) {
            //this may also set the additional mappings to null!
            log.info("Replace Additional Mappings for Cache " + yardId + "with Mappings configured by OSGI");
            setAdditionalMappings(yard, configuredMappings);
        } //else current config equals configured one -> nothing to do!
        initWithYard = true;
View Full Code Here


     * @param yard the yard used to set the configured additional mappings
     * @param fieldMapper the configuration
     * @throws YardException on any error while accessing the yard
     */
    protected void setAdditionalMappings(Yard yard, FieldMapper fieldMapper) throws YardException {
        FieldMapper old = this.additionalMapper;
        this.additionalMapper = fieldMapper;
        try {
            CacheUtils.storeAdditionalMappingsConfiguration(yard, additionalMapper);
        } catch (YardException e) {
            this.additionalMapper = old;
View Full Code Here

        Yard yard = getCacheYard();
        if (yard == null) {
            throw new YardException(String.format("The Yard %s for this cache is currently not available", yardId));
        } else {
            if (isAvailable()) {
                FieldMapper old = this.baseMapper;
                this.baseMapper = fieldMapper;
                try {
                    CacheUtils.storeBaseMappingsConfiguration(yard, baseMapper);
                } catch (YardException e) {
                    this.baseMapper = old;
View Full Code Here

        if(state == null){
            state =  config.getDefaultManagedEntityState();
        }
        //this wrapper allows to use an API to write metadata
        ManagedEntity managedEntity = ManagedEntity.init(localEntity, state);
        FieldMapper siteMapper = site.getFieldMapper();
        FieldMapper mapper = this.fieldMapper.clone();
        for(FieldMapping siteMapping : siteMapper.getMappings()){
            mapper.addMapping(siteMapping);
        }
        //TODO: As soon as MappingActivities are implemented we need to add such
        //      information to the EntityMapping instance!
        mapper.applyMappings(remoteEntity.getRepresentation(),
            localEntity.getRepresentation(),valueFactory);
        //set general metadata
        managedEntity.setCreated(new Date());
        //set the metadata required by the referenced site
        managedEntity.addAttributionLink(site.getConfiguration().getAttributionUrl());
View Full Code Here

    @SuppressWarnings("unchecked")
    @Override
    public void finalise() {
        //write the indexing configuration
        FieldMapper mapper = FieldMappingUtils.createDefaultFieldMapper(indexFieldConfiguration);
        try {
            CacheUtils.storeBaseMappingsConfiguration(solrYard, mapper);
        } catch (YardException e) {
            log.error("Unable to store FieldMapperConfiguration to the Store!",e);
        }
View Full Code Here

        if(state == null){
            state =  config.getDefaultManagedEntityState();
        }
        //this wrapper allows to use an API to write metadata
        ManagedEntity managedEntity = ManagedEntity.init(localEntity, state);
        FieldMapper siteMapper = site.getFieldMapper();
        FieldMapper mapper = this.fieldMapper.clone();
        for(FieldMapping siteMapping : siteMapper.getMappings()){
            mapper.addMapping(siteMapping);
        }
        //TODO: As soon as MappingActivities are implemented we need to add such
        //      information to the EntityMapping instance!
        mapper.applyMappings(remoteEntity.getRepresentation(),
            localEntity.getRepresentation(),valueFactory);
        //set general metadata
        managedEntity.setCreated(new Date());
        //set the metadata required by the referenced site
        managedEntity.addAttributionLink(site.getConfiguration().getAttributionUrl());
View Full Code Here

     * @param writeLock the write lock for the graph
     */
    private void copyMapped(UriRef uri, Representation rep, Set<String> langs,
            MGraph graph, Lock writeLock) {
        //init the fieldMapper
        FieldMapper fieldMapper;
        if(!langs.isEmpty()){ //if we need to filter for specific languages
            //we need to modify the field and add a global filter for the
            //languages. NOTE that the field might be null. In that case we
            //need just filter literals by language
            //TODO: maybe cache fieldMappers for sets of languages
            fieldMapper = this.fieldMapper != null ? this.fieldMapper.clone() :
                new DefaultFieldMapperImpl(ValueConverterFactory.getDefaultInstance());
            fieldMapper.addMapping(new FieldMapping(new TextConstraint(
                (String)null, langs.toArray(new String[graph.size()]))));
        } else { //just use the fieldMapper as parsed in the config
            fieldMapper = this.fieldMapper;
        }
        //execute the field mappings
        writeLock.lock();
        try {
            RdfRepresentation clerezzaRep = valueFactory.createRdfRepresentation(uri, graph);
            fieldMapper.applyMappings(rep, clerezzaRep, valueFactory);
             if(log.isTraceEnabled()){
            log.trace("dereferenced via Mappings {}", ModelUtils.getRepresentationInfo(clerezzaRep));
          }
        } finally {
            writeLock.unlock();
View Full Code Here

            throw new IllegalArgumentException("The parsed Yard MUST NOT be NULL!");
        }
        this.yard = yard;
        //(1) Read the base mappings from the Yard
        this.baseMapper = CacheUtils.loadBaseMappings(yard,nsPrefixService);
        FieldMapper configuredMappings = null;
        if(additionalMappings != null && additionalMappings.length > 0){
            configuredMappings = new DefaultFieldMapperImpl(ValueConverterFactory.getDefaultInstance());
            for (String mappingString : additionalMappings) {
                FieldMapping fieldMapping = FieldMappingUtils.parseFieldMapping(mappingString, nsPrefixService);
                if (fieldMapping != null) {
                    configuredMappings.addMapping(fieldMapping);
                }
            }
            //check if there are valid mappings
            if (configuredMappings.getMappings().isEmpty()) {
                configuredMappings = null; //if no mappings where found set to null
            }
        }
        FieldMapper yardAdditionalMappings = CacheUtils.loadAdditionalMappings(yard,nsPrefixService);
        if (yardAdditionalMappings == null) {
            if (configuredMappings != null) {
                setAdditionalMappings(yard, configuredMappings);
            }
        } else if (!yardAdditionalMappings.equals(configuredMappings)) {
            //this may also set the additional mappings to null!
            log.info("Replace Additional Mappings for Cache {} with Mappings configured by OSGI",yard.getId());
            setAdditionalMappings(yard, configuredMappings);
        } //else current config equals configured one -> nothing to do!   
    }
View Full Code Here

     * @param yard the yard used to set the configured additional mappings
     * @param fieldMapper the configuration
     * @throws YardException on any error while accessing the yard
     */
    protected void setAdditionalMappings(Yard yard, FieldMapper fieldMapper) throws YardException {
        FieldMapper old = this.additionalMapper;
        this.additionalMapper = fieldMapper;
        try {
            CacheUtils.storeAdditionalMappingsConfiguration(yard, additionalMapper);
        } catch (YardException e) {
            this.additionalMapper = old;
View Full Code Here

    }

    @Override
    public void setBaseMappings(FieldMapper fieldMapper) throws YardException {
        if (isAvailable()) {
            FieldMapper old = this.baseMapper;
            this.baseMapper = fieldMapper;
            try {
                CacheUtils.storeBaseMappingsConfiguration(yard, baseMapper);
            } catch (YardException e) {
                this.baseMapper = old;
View Full Code Here

TOP

Related Classes of org.apache.stanbol.entityhub.servicesapi.mapping.FieldMapper

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.