Package org.apache.stanbol.entityhub.servicesapi.yard

Examples of org.apache.stanbol.entityhub.servicesapi.yard.Yard


     * @throws YardException
     */
    @Test
    public void testGetRepresentation() throws YardException {
        String id = "urn:yard.test.testGetRepresentation.id";
        Yard yard = getYard();
        String field = "urn:the.field:used.for.this.Test";
        String value1 = "this is a test";
        // Representations created via the yard need to be created (as empty
        // representation within the yard
        Representation test = create(id, true);
        // retrieve the representation from the store
        Representation retrieved = yard.getRepresentation(id);
        assertNotNull(retrieved);
        // they MUST NOT be the same, but the MUST be equals
        // Note:
        // the fact that two representations with the same id are equals is tested
        // by the unit tests for the representation interface
        assertEquals(test, retrieved);
        assertNotSame("getRepresentation MUST return an new instance for each "
                      + "call, so that changes in one return instance do not influence "
                      + "an other returned instance!", test, retrieved);
        // now add a property to the original one
        test.add(field, value1);
        // and check that the retrieved does not have the value
        assertFalse(retrieved.get(field).hasNext());
        // now store the representation and check that updated are not reflected
        // within the retrieved one
        yard.store(test);
        assertFalse(retrieved.get(field).hasNext());
        // now retrieve again an representation
        retrieved = null;
        retrieved = yard.getRepresentation(id);
        // now the Representation MUST HAVE the new field
        assertTrue(retrieved.get(field).hasNext());
        assertEquals(value1, retrieved.getFirst(field));

        // finally retrieve a second and perform the change test again
        Representation retrieved2 = yard.getRepresentation(id);
        retrieved.removeAll(field);
        // check the value is still in retrieved2
        assertTrue(retrieved2.get(field).hasNext());
        assertEquals(value1, retrieved2.getFirst(field));

View Full Code Here


            throw new IllegalStateException("The parsed id MUST NOT be NULL nor empty!");
        }
        if(state == null){
            throw new IllegalStateException("The parsed state for the Entity MUST NOT ne NULL");
        }
        Yard yard = lookupYard();
        Entity entity = loadEntity(yard, id);
        if(entity != null){
            ManagedEntity managed = new ManagedEntity(entity);
            if(managed.getState() != state){
                managed.setState(state);
View Full Code Here

        if(site == null){
            log.warn("Unable to import Entity {} because the ReferencedSite {} is currently not active -> return null",
                remoteEntity.getId(),remoteEntity.getSite());
            return null;
        }
        Yard entityhubYard = lookupYard();
        ValueFactory valueFactory = entityhubYard.getValueFactory();
        //Create the locally managed Entity
        Representation localRep = entityhubYard.create(constructResourceId(DEFAULT_MANAGED_ENTITY_PREFIX));
        Entity localEntity = loadEntity(entityhubYard, localRep);
        importEntity(remoteEntity, site, localEntity, valueFactory);

        //Second create and init the Mapping
        Representation entityMappingRepresentation = entityhubYard.create(
            constructResourceId(DEFAULT_MAPPING_PREFIX));
        Entity entityMappingEntity = loadEntity(entityhubYard, entityMappingRepresentation);
        establishMapping(localEntity, remoteEntity, site, entityMappingEntity);
       
        //Store the entity and the mappedEntity in the entityhubYard
View Full Code Here

    }

    @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()));
    }
View Full Code Here

            log.warn("NULL parsed as Reference -> call to getMappingByEntity ignored (return null)");
            return null;
        }
        FieldQuery fieldQuery = getQueryFactory().createFieldQuery();
        fieldQuery.setConstraint(RdfResourceEnum.mappingSource.getUri(), new ReferenceConstraint(reference));
        Yard entityhubYard = lookupYard();
        QueryResultList<Representation> resultList = entityhubYard.findRepresentation(fieldQuery);
        if(!resultList.isEmpty()){
            Iterator<Representation> resultIterator = resultList.iterator();
            Entity mapping = loadEntity(entityhubYard, resultIterator.next());
           //print warnings in case of multiple mappings
            if(resultIterator.hasNext()){
View Full Code Here

            log.warn("NULL parsed as Reference -> call to getMappingsBySymbol ignored (return null)");
            return null;
        }
        FieldQuery fieldQuery = getQueryFactory().createFieldQuery();
        fieldQuery.setConstraint(RdfResourceEnum.mappingTarget.getUri(), new ReferenceConstraint(targetId));
        Yard enttiyhubYard = lookupYard();
        QueryResultList<Representation> resultList = enttiyhubYard.findRepresentation(fieldQuery);
        Collection<Entity> mappings = new HashSet<Entity>();
        for(Representation rep : resultList){
            mappings.add(loadEntity(enttiyhubYard, rep));
        }
        return mappings;
View Full Code Here

    @Override
    public final Entity getMappingById(String id) throws IllegalArgumentException, EntityhubException{
        if(id == null || id.isEmpty()){
            throw new IllegalArgumentException("The parsed id MUST NOT be NULL nor empty");
        }
        Yard entityhubYard = lookupYard();
        Entity mapping = loadEntity(entityhubYard, id);
        if(mapping == null){
            return null;
        } else if(mapping != null && EntityMapping.isValid(mapping)){
            return mapping;
View Full Code Here

    @Test
    public void testUpdateRepresentations() throws YardException {
        // NOTE: this does not test if the updated view of the representation is
        // stored, but only that the update method works correctly
        Yard yard = getYard();
        String id1 = "urn:yard.test.testUpdateRepresentations:representation.id1";
        String id2 = "urn:yard.test.testUpdateRepresentations:representation.id2";
        String field = "urn:the.field:used.for.this.Test";
        Representation test1 = create(id1, true);
        Representation test2 = create(id2, true);
        // change the representations to be sure to force an update even if the
        // implementation checks for changes before updating a representation
        test1.add(field, "test value 1");
        test2.add(field, "test value 2");
        Iterable<Representation> updatedIterable = yard.update(Arrays.asList(test1, test2));
        assertNotNull(updatedIterable);
        Collection<Representation> updated = asCollection(updatedIterable.iterator());
        // test that both the parsed Representations where stored (updated & created)
        assertTrue(updated.remove(test1));
        assertTrue(updated.remove(test2));
View Full Code Here

            return null;
        }
    }
    @Override
    public final FieldQueryFactory getQueryFactory() {
        Yard entityhubYard = getYard();
        return entityhubYard==null? //if no yard available
                DefaultQueryFactory.getInstance(): //use the default
                    entityhubYard.getQueryFactory(); //else return the query factory used by the yard
    }
View Full Code Here

     */
    @Test
    public void testUpdateRepresentationsWithNullElement() throws YardException {
        // NOTE: this does not test if the updated view of the representation is
        // stored, but only that the update method works correctly
        Yard yard = getYard();
        String id1 = "urn:yard.test.testUpdateRepresentationsWithNullElement:representation.id";
        String field = "urn:the.field:used.for.this.Test";
        Representation test1 = create(id1, true);
        // change the representations to be sure to force an update even if the
        // implementation checks for changes before updating a representation
        test1.add(field, "test value 1");
        Iterable<Representation> updated = yard.update(Arrays.asList(test1, null));
        assertNotNull(updated);
        Iterator<Representation> updatedIt = updated.iterator();
        assertTrue(updatedIt.hasNext());
        assertEquals(test1, updatedIt.next());
        assertFalse(updatedIt.hasNext());
View Full Code Here

TOP

Related Classes of org.apache.stanbol.entityhub.servicesapi.yard.Yard

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.