Package org.fao.geonet.domain

Examples of org.fao.geonet.domain.MetadataRatingByIp


     * @param rating range should be 1..5
     * @return
     * @throws Exception hmm
     */
    public int rateMetadata(final int metadataId, final String ipAddress, final int rating) throws Exception {
        MetadataRatingByIp ratingEntity = new MetadataRatingByIp();
        ratingEntity.setRating(rating);
        ratingEntity.setId(new MetadataRatingByIpId(metadataId, ipAddress));

        final MetadataRatingByIpRepository ratingByIpRepository = _applicationContext.getBean(MetadataRatingByIpRepository.class);
        ratingByIpRepository.save(ratingEntity);

        //
View Full Code Here


    @Autowired
    MetadataRatingByIpRepository _repo;

    @Test
    public void testFindOne() {
        MetadataRatingByIp rating1 = newMetadataRatingByIp();
        rating1 = _repo.save(rating1);

        MetadataRatingByIp rating2 = newMetadataRatingByIp();
        rating2 = _repo.save(rating2);

        assertEquals(rating2, _repo.findOne(rating2.getId()));
        assertEquals(rating1, _repo.findOne(rating1.getId()));
    }
View Full Code Here

        assertEquals(rating1, _repo.findOne(rating1.getId()));
    }

    @Test
    public void testAverageRating() {
        MetadataRatingByIp rating1 = _repo.save(newMetadataRatingByIp());
        MetadataRatingByIp rating2 = _repo.save(updateMetadataId(rating1, newMetadataRatingByIp()));
        MetadataRatingByIp rating3 = _repo.save(updateMetadataId(rating1, newMetadataRatingByIp()));
        MetadataRatingByIp rating4 = _repo.save(newMetadataRatingByIp());

        final double sum = (double) (rating1.getRating() + rating2.getRating() + rating3.getRating());
        final double average = sum / 3;
        assertEquals((int) average, _repo.averageRating(rating1.getId().getMetadataId()));
    }
View Full Code Here

        return toUpdate;
    }

    @Test
    public void testDeleteAllById_MetadataId() throws Exception {
        MetadataRatingByIp rating1 = _repo.save(newMetadataRatingByIp());
        MetadataRatingByIp rating2 = newMetadataRatingByIp();
        rating2.getId().setMetadataId(rating1.getId().getMetadataId());
        rating2 = _repo.save(rating2);
        MetadataRatingByIp rating3 = _repo.save(newMetadataRatingByIp());

        assertEquals(3, _repo.count());
        _repo.deleteAllById_MetadataId(rating1.getId().getMetadataId());
        assertEquals(1, _repo.count());
        final List<MetadataRatingByIp> all = _repo.findAll();
        assertEquals(1, all.size());
        assertEquals(rating3.getId(), all.get(0).getId());
    }
View Full Code Here

        assertEquals(rating3.getId(), all.get(0).getId());
    }

    @Test
    public void testSaveAndUpdate() {
        MetadataRatingByIp rating1 = newMetadataRatingByIp();
        rating1 = _repo.save(rating1);

        MetadataRatingByIp rating2 = new MetadataRatingByIp();
        final int newRating = rating1.getRating() * 100;
        rating2.setRating(newRating);
        rating2.setId(new MetadataRatingByIpId(rating1.getId().getMetadataId(), rating1.getId().getIpAddress()));

        MetadataRatingByIp saved = _repo.save(rating2);

        assertEquals(1, _repo.count());

        MetadataRatingByIp loaded = _repo.findAll().get(0);

        assertEquals(loaded.getRating(), newRating);
        assertEquals(rating1.getId(), loaded.getId());
        assertEquals(rating2.getId(), loaded.getId());
        assertEquals(saved.getId(), loaded.getId());
    }
View Full Code Here

        assertEquals(saved.getId(), loaded.getId());
    }

    @Test
    public void testFindAllByMetadataId() {
        MetadataRatingByIp rating1 = newMetadataRatingByIp();
        rating1 = _repo.save(rating1);

        MetadataRatingByIp rating2 = newMetadataRatingByIp();
        rating2 = _repo.save(rating2);

        List<MetadataRatingByIp> metadataRatings = _repo.findAllByIdMetadataId(rating1.getId().getMetadataId());
        assertEquals(rating1, metadataRatings.get(0));

        metadataRatings = _repo.findAllByIdMetadataId(rating2.getId().getMetadataId());
        assertEquals(rating2, metadataRatings.get(0));
    }
View Full Code Here

    private MetadataRatingByIp newMetadataRatingByIp() {
        return newMetadataRatingByIp(_inc);
    }
    public static MetadataRatingByIp newMetadataRatingByIp(AtomicInteger inc) {
        int val = inc.incrementAndGet();
        MetadataRatingByIp metadataRatingByIp = new MetadataRatingByIp();
        metadataRatingByIp.setRating(1);
        MetadataRatingByIpId id = new MetadataRatingByIpId();
        id.setIpAddress("ip" + val);
        id.setMetadataId(val);
        metadataRatingByIp.setId(id);

        return metadataRatingByIp;
    }
View Full Code Here

        assertEquals(6, _operationRepo.count());
        Operation operation = _operationRepo.saveAndFlush(OperationRepositoryTest.newOperation(_inc));
        assertEquals(72, _opAllowedRepo.count());
        _opAllowedRepo.saveAndFlush(new OperationAllowed(new OperationAllowedId(metadata.getId(), group.getId(), operation.getId())));
        assertEquals(2, _ratingRepo.count());
        final MetadataRatingByIp ratingByIp = MetadataRatingByIpRepositoryTest.newMetadataRatingByIp(_inc);
        ratingByIp.getId().setMetadataId(metadata.getId());
        _ratingRepo.saveAndFlush(ratingByIp);
        assertEquals(0, _relationRepo.count());
        _relationRepo.saveAndFlush(MetadataRelationRepositoryTest.newMetadataRelation(_inc, _mdRepo));
        assertEquals(4, _searchRequestParamRepo.count());
        _searchRequestParamRepo.saveAndFlush(SearchRequestParamRepositoryTest.newRequestParam(_inc));
View Full Code Here

TOP

Related Classes of org.fao.geonet.domain.MetadataRatingByIp

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.