Package org.fao.geonet.domain

Examples of org.fao.geonet.domain.OperationAllowed


public class OperationAllowedRepositoryTest extends AbstractOperationsAllowedTest {

    @Test
    public void testSaveById() {
        OperationAllowed unsaved = new OperationAllowed(new OperationAllowedId(_md1.getId(), _allGroup.getId(), _viewOp.getId()));
        OperationAllowed newOp = _opAllowRepo.save(unsaved);

        assertEquals(_md1.getId(), newOp.getId().getMetadataId());
        assertEquals(_allGroup.getId(), newOp.getId().getGroupId());
        assertEquals(_viewOp.getId(), newOp.getId().getOperationId());
    }
View Full Code Here


        assertFalse(opAllowedFound.contains(_opAllowed4));
    }

    @Test
    public void testFindByGroupIdAndMetadataIdAndOperationId() {
        OperationAllowed opAllowedFound = _opAllowRepo.findOneById_GroupIdAndId_MetadataIdAndId_OperationId(_intranetGroup.getId(),
                _md1.getId(),
                _viewOp.getId());
        assertEquals(_opAllowed4.getId(), opAllowedFound.getId());

        opAllowedFound = _opAllowRepo.findOneById_GroupIdAndId_MetadataIdAndId_OperationId(_allGroup.getId(), _md1.getId(),
                _viewOp.getId());
        assertEquals(_opAllowed1.getId(), opAllowedFound.getId());

        opAllowedFound = _opAllowRepo.findOneById_GroupIdAndId_MetadataIdAndId_OperationId(_allGroup.getId(), _md1.getId(),
                Integer.MAX_VALUE / 2);
        assertNull(opAllowedFound);
    }
View Full Code Here

                    OperationAllowedRepository repository = context.getBean(OperationAllowedRepository.class);
                    OperationAllowedId id = new OperationAllowedId()
                            .setGroupId(targetGrp)
                            .setMetadataId(mdId)
                            .setOperationId(opId);
                    OperationAllowed operationAllowed = new OperationAllowed(id );
                    repository.save(operationAllowed);
                }
            }

            // Collect all metadata ids
View Full Code Here

     * @return
     */
    public Optional<OperationAllowed> getOperationAllowedToAdd(final ServiceContext context, final int mdId, final int grpId, final int opId) {
        OperationAllowedRepository opAllowedRepo = _applicationContext.getBean(OperationAllowedRepository.class);
        UserGroupRepository userGroupRepo = _applicationContext.getBean(UserGroupRepository.class);
        final OperationAllowed operationAllowed = opAllowedRepo
                .findOneById_GroupIdAndId_MetadataIdAndId_OperationId(grpId, mdId, opId);

        if (operationAllowed == null) {
            // Check user privileges
            // Session may not be defined when a harvester is running
            if (context.getUserSession() != null) {
                Profile userProfile = context.getUserSession().getProfile();
                if (!(userProfile == Profile.Administrator || userProfile == Profile.UserAdmin)) {
                    int userId = Integer.parseInt(context.getUserSession().getUserId());
                    // Reserved groups
                    if (ReservedGroup.isReserved(grpId)) {

                        Specification<UserGroup> hasUserIdAndProfile = where(UserGroupSpecs.hasProfile(Profile.Reviewer))
                                .and(UserGroupSpecs.hasUserId(userId));
                        List<Integer> groupIds = userGroupRepo.findGroupIds(hasUserIdAndProfile);

                        if (groupIds.isEmpty()) {
                            throw new ServiceNotAllowedEx("User can't set operation for group " + grpId + " because the user in not a "
                                                          + "Reviewer of any group.");
                        }
                    } else {
                        String userGroupsOnly = settingMan.getValue("system/metadataprivs/usergrouponly");
                        if (userGroupsOnly.equals("true")) {
                            // If user is member of the group, user can set operation

                            if (userGroupRepo.exists(new UserGroupId().setGroupId(grpId).setUserId(userId))) {
                                throw new ServiceNotAllowedEx("User can't set operation for group " + grpId + " because the user in not"
                                                              + " member of this group.");
                            }
                        }
                    }
                }
            }
        }

        if (operationAllowed == null) {
            return Optional.of(new OperationAllowed(new OperationAllowedId().setGroupId(grpId).setMetadataId(mdId).setOperationId(opId)));
        } else {
            return Optional.absent();
        }
    }
View Full Code Here

        assertEquals(3, _metadataValidationRepo.count());
        _metadataValidationRepo.saveAndFlush(MetadataValidationRepositoryTest.newValidation(_inc, _mdRepo));
        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());
View Full Code Here

TOP

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

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.