/**
   * Converts the soap model instance into a normal model instance.
   *
   * @param soapModel the soap model instance to convert
   * @return the normal model instance
   */
  public static Group toModel(GroupSoap soapModel) {
    if (soapModel == null) {
      return null;
    }

    Group model = new GroupImpl();

    model.setUuid(soapModel.getUuid());
    model.setGroupId(soapModel.getGroupId());
    model.setCompanyId(soapModel.getCompanyId());
    model.setCreatorUserId(soapModel.getCreatorUserId());
    model.setClassNameId(soapModel.getClassNameId());
    model.setClassPK(soapModel.getClassPK());
    model.setParentGroupId(soapModel.getParentGroupId());
    model.setLiveGroupId(soapModel.getLiveGroupId());
    model.setTreePath(soapModel.getTreePath());
    model.setName(soapModel.getName());
    model.setDescription(soapModel.getDescription());
    model.setType(soapModel.getType());
    model.setTypeSettings(soapModel.getTypeSettings());
    model.setFriendlyURL(soapModel.getFriendlyURL());
    model.setSite(soapModel.getSite());
    model.setActive(soapModel.getActive());

    return model;
  }
  @Override
  public LayoutPrototype updateLayoutPrototype(
      long layoutPrototypeId,
      Map<Locale, String> nameMap,
      String description,
      boolean active,
      ServiceContext serviceContext)
      throws PortalException, SystemException {

    // Layout prototype

    LayoutPrototype layoutPrototype =
        layoutPrototypePersistence.findByPrimaryKey(layoutPrototypeId);

    layoutPrototype.setModifiedDate(serviceContext.getModifiedDate(new Date()));
    layoutPrototype.setNameMap(nameMap);
    layoutPrototype.setDescription(description);
    layoutPrototype.setActive(active);

    layoutPrototypePersistence.update(layoutPrototype);

    // Group

    Group group =
        groupLocalService.getLayoutPrototypeGroup(
            layoutPrototype.getCompanyId(), layoutPrototypeId);

    group.setName(layoutPrototype.getName(LocaleUtil.getDefault()));

    groupPersistence.update(group);

    // Layout

    Layout layout = layoutPrototype.getLayout();

    layout.setModifiedDate(layoutPrototype.getModifiedDate());
    layout.setNameMap(nameMap);

    layoutPersistence.update(layout);

    return layoutPrototype;
  }
  @Override
  public List<Group> getUserSitesGroups() throws PortalException {
    try {
      User user = getUser();

      List<Group> groups = new ArrayList<>();

      LinkedHashMap<String, Object> groupParams = new LinkedHashMap<>();

      groupParams.put("active", true);
      groupParams.put("usersGroups", user.getUserId());

      List<Group> userSiteGroups =
          groupLocalService.search(
              user.getCompanyId(), null, groupParams, QueryUtil.ALL_POS, QueryUtil.ALL_POS);

      for (Group userSiteGroup : userSiteGroups) {
        if (SyncUtil.isSyncEnabled(userSiteGroup)) {
          userSiteGroup.setName(userSiteGroup.getDescriptiveName());

          groups.add(userSiteGroup);
        }
      }

      List<Organization> organizations =
          organizationLocalService.getOrganizations(
              user.getUserId(), QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);

      for (Organization organization : organizations) {
        Group userOrganizationGroup = organization.getGroup();

        if (SyncUtil.isSyncEnabled(userOrganizationGroup)) {
          groups.add(userOrganizationGroup);
        }

        if (!GetterUtil.getBoolean(PropsUtil.get(PropsKeys.ORGANIZATIONS_MEMBERSHIP_STRICT))) {

          for (Organization ancestorOrganization : organization.getAncestors()) {

            Group userAncestorOrganizationGroup = ancestorOrganization.getGroup();

            if (SyncUtil.isSyncEnabled(userAncestorOrganizationGroup)) {

              groups.add(userAncestorOrganizationGroup);
            }
          }
        }
      }

      if (PrefsPropsUtil.getBoolean(
          user.getCompanyId(),
          PortletPropsKeys.SYNC_ALLOW_USER_PERSONAL_SITES,
          PortletPropsValues.SYNC_ALLOW_USER_PERSONAL_SITES)) {

        groups.add(user.getGroup());
      }

      Collections.sort(groups, new GroupNameComparator());

      return ListUtil.unique(groups);
    } catch (PortalException pe) {
      throw new PortalException(pe.getClass().getName(), pe);
    }
  }