Package org.fao.geonet.repository

Examples of org.fao.geonet.repository.GroupRepository


  //--------------------------------------------------------------------------

  public GroupMapper(ServiceContext context) throws Exception
  {

        final GroupRepository groupRepository = context.getBean(GroupRepository.class);

        for (Group record : groupRepository.findAll()) {
            String id = "" + record.getId();
            String name = record.getName();

            add(name, id);
        }
View Full Code Here


     * @param includingSystemGroups if true, also returns the system groups ('GUEST', 'intranet', 'all')
     * @return
     * @throws java.sql.SQLException
     */
    private Element getGroups(ServiceContext context, Profile profile, boolean includingSystemGroups) throws SQLException {
        final GroupRepository groupRepository = context.getBean(GroupRepository.class);
        final UserGroupRepository userGroupRepository = context.getBean(UserGroupRepository.class);
        final Sort sort = SortUtils.createSort(Group_.id);

        UserSession session = context.getUserSession();
        if (!session.isAuthenticated()) {
            return groupRepository.findAllAsXml(Specifications.not(GroupSpecs.isReserved()), sort);
        }

        Element result;
        // you're Administrator
        if (Profile.Administrator == session.getProfile()) {
            // return all groups
            result = groupRepository.findAllAsXml(null, sort);
        } else {
            Specifications<UserGroup> spec = Specifications.where(UserGroupSpecs.hasUserId(session.getUserIdAsInt()));
            // you're no Administrator
            // retrieve your groups
      if (profile != null) {
                spec = spec.and(UserGroupSpecs.hasProfile(profile));
            }
            Set<Integer> ids = new HashSet<Integer>(userGroupRepository.findGroupIds(spec));

            // include system groups if requested (used in harvesters)
            if (includingSystemGroups) {
                // these DB keys of system groups are hardcoded !
                for (ReservedGroup reservedGroup : ReservedGroup.values()) {
                    ids.add(reservedGroup.getId());
                }
            }

            // retrieve all groups
            Element groups = groupRepository.findAllAsXml(null, sort);

            // filter all groups so only your groups (+ maybe system groups) are retained
            result = Lib.element.pruneChildren(groups, ids);
    }
        return result;
View Full Code Here

    }

    private void saveUser(LDAPUser userDetails) {
        try {
            UserRepository userRepo = applicationContext.getBean(UserRepository.class);
            GroupRepository groupRepo = applicationContext.getBean(GroupRepository.class);
            UserGroupRepository userGroupRepo = applicationContext.getBean(UserGroupRepository.class);
            LDAPUtils.saveUser(userDetails, userRepo, groupRepo, userGroupRepo, importPrivilegesFromLdap, createNonExistingLdapGroup);
        } catch (Exception e) {
            throw new AuthenticationServiceException(
                    "Unexpected error while saving/updating LDAP user in database",
View Full Code Here

                if (b) {
                    groupName = m.group(1);
                }
            }
           
            GroupRepository groupRepo = this.applicationContext.getBean(GroupRepository.class);
            Group group = groupRepo.findByName(groupName);
           
            if (group == null) {
                group = groupRepo.save(new Group().setName(groupName));
            } else {
                // Update something ?
                // Group description is only defined in catalog, not in LDAP for the time
                // being
            }
View Full Code Here

        boolean groupProvided = ((groupName != null) && (!(groupName.equals(""))));
        int groupId = -1;
        int userId = -1;

        if (groupProvided) {
            GroupRepository groupRepo = context.getBean(GroupRepository.class);
            Group group = groupRepo.findByName(groupName);

            if (group == null) {
                group = groupRepo.save(new Group().setName(groupName));
            }
            groupId = group.getId();
        }
        // --- update user information into the database
        if (username.length() > 256) // only accept the first 256 chars
View Full Code Here

        // Logo management ported/adapted from GeoNovum GeoNetwork app.
        // Original devs: Heikki Doeleman and Thijs Brentjens
        String logoFile = params.getChildText("logofile");
        final String logoUUID = copyLogoFromRequest(context, logoFile);
        final GroupRepository groupRepository = context.getBean(GroupRepository.class);

        final Element elRes = new Element(Jeeves.Elem.RESPONSE);

        if (id == null || "".equals(id)) {

            Group group = new Group()
                    .setName(name)
                    .setDescription(description)
                    .setEmail(email)
                    .setLogo(logoUUID)
                    .setWebsite(website);

            final LanguageRepository langRepository = context.getBean(LanguageRepository.class);
            java.util.List<Language> allLanguages = langRepository.findAll();
            for (Language l : allLanguages) {
                group.getLabelTranslations().put(l.getId(), name);
            }

            groupRepository.save(group);

            elRes.addContent(new Element(Jeeves.Elem.OPERATION).setText(Jeeves.Text.ADDED));
        } else {
            final String finalWebsite = website;
            groupRepository.update(Integer.valueOf(id), new Updater<Group>() {
                @Override
                public void apply(final Group entity) {
                    entity.setEmail(email)
                            .setName(name)
                            .setDescription(description)
View Full Code Here

        myGroups.remove(ReservedGroup.all.getId());

        Element response = new Element("response");

        OperationAllowedRepository opAllowedRepo = context.getBean(OperationAllowedRepository.class);
        final GroupRepository groupRepository = context.getBean(GroupRepository.class);
        for (Integer groupId : userGroups) {
            Specifications<OperationAllowed> spec = where(hasGroupId(groupId)).and(hasMetadataId(userId));
            long count = opAllowedRepo.count(spec);

            if (count > 0) {
                Group group = groupRepository.findOne(groupId);

                if (group != null) {
                    Element record = group.asXml();
                    record.detach();
                    record.setName("group");

                    response.addContent(record);
                }
            }
        }

        for (Integer groupId : myGroups) {
            @SuppressWarnings("unchecked")
            Group group = groupRepository.findOne(groupId);

            if (group != null) {
                Element record = group.asXml();
                record.detach();
                record.setName("targetGroup");
View Full Code Here

      throws Exception {

    int iId = md.getId();

    OperationAllowedRepository allowedRepository = context.getBean(OperationAllowedRepository.class);
    GroupRepository groupRepository = context.getBean(GroupRepository.class);
    OperationRepository operationRepository = context.getBean(OperationRepository.class);

    allowedRepository.findAllById_MetadataId(iId);

    // Get group Owner ID
    Integer grpOwnerId = md.getSourceInfo().getGroupOwner();
    String grpOwnerName = "";

    HashMap<String, ArrayList<String>> hmPriv = new HashMap<String, ArrayList<String>>();

    // --- retrieve accessible groups

    GeonetContext gc = (GeonetContext) context
        .getHandlerContext(Geonet.CONTEXT_NAME);
    AccessManager am = gc.getBean(AccessManager.class);

    Set<Integer> userGroups = am.getUserGroups(context.getUserSession(), context.getIpAddress(), false);

    // --- scan query result to collect info

        OperationAllowedRepository operationAllowedRepository = context.getBean(OperationAllowedRepository.class);
        List<OperationAllowed> opsAllowed = operationAllowedRepository.findAllById_MetadataId(iId);

        for (OperationAllowed operationAllowed : opsAllowed) {
            int grpId = operationAllowed.getId().getGroupId();
            Group group = groupRepository.findOne(grpId);
            String grpName = group.getName();

            if (!userGroups.contains(grpId)) {
                continue;
            }
View Full Code Here

    String id = Util.getParam(params, Params.ID);


        OperationAllowedRepository operationAllowedRepo = context.getBean(OperationAllowedRepository.class);
        UserGroupRepository userGroupRepo = context.getBean(UserGroupRepository.class);
        GroupRepository groupRepo = context.getBean(GroupRepository.class);

    Integer iId = Integer.valueOf(id);
        List<Integer> reindex = operationAllowedRepo.findAllIds(OperationAllowedSpecs.hasGroupId(iId), OperationAllowedId_.metadataId);

        operationAllowedRepo.deleteAllByIdAttribute(OperationAllowedId_.groupId, iId);
        userGroupRepo.deleteAllByIdAttribute(UserGroupId_.groupId, Arrays.asList(iId));
        groupRepo.delete(iId);
    //--- reindex affected metadata

    GeonetContext gc = (GeonetContext) context.getHandlerContext(Geonet.CONTEXT_NAME);
    DataManager   dm = gc.getBean(DataManager.class);
View Full Code Here

    //---
    //--------------------------------------------------------------------------

    public Element serviceSpecificExec(final Element params, final ServiceContext context) throws Exception {

        final GroupRepository groupRepository = context.getBean(GroupRepository.class);
        for (Object g : params.getChildren("group")) {
            Element groupEl = (Element) g;

            String id = Util.getAttrib(groupEl, Params.ID);
            final Element label = Util.getChild(groupEl, "label");


            groupRepository.update(Integer.valueOf(id), new Updater<Group>() {
                @Override
                public void apply(@Nonnull Group group) {
                    for (Object t : label.getChildren()) {
                        Element translationEl = (Element) t;
                        group.getLabelTranslations().put(translationEl.getName(), translationEl.getText());
View Full Code Here

TOP

Related Classes of org.fao.geonet.repository.GroupRepository

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.