protected void deleteSocialOfficeLayoutSetPrototypes(long companyId) throws Exception {

    LayoutSetPrototype layoutSetPrototype =
        LayoutSetPrototypeUtil.fetchLayoutSetPrototype(
            companyId, SocialOfficeConstants.LAYOUT_SET_PROTOTYPE_KEY_SITE);

    if (layoutSetPrototype != null) {
      try {
        LayoutSetPrototypeLocalServiceUtil.deleteLayoutSetPrototype(layoutSetPrototype);
      } catch (Exception e) {
        _log.error(e, e);
      }
    }

    layoutSetPrototype =
        LayoutSetPrototypeUtil.fetchLayoutSetPrototype(
            companyId, SocialOfficeConstants.LAYOUT_SET_PROTOTYPE_KEY_USER_PRIVATE);

    if (layoutSetPrototype != null) {
      try {
        LayoutSetPrototypeLocalServiceUtil.deleteLayoutSetPrototype(layoutSetPrototype);
      } catch (Exception e) {
        _log.error(e, e);
      }
    }

    layoutSetPrototype =
        LayoutSetPrototypeUtil.fetchLayoutSetPrototype(
            companyId, SocialOfficeConstants.LAYOUT_SET_PROTOTYPE_KEY_USER_PUBLIC);

    if (layoutSetPrototype != null) {
      try {
        LayoutSetPrototypeLocalServiceUtil.deleteLayoutSetPrototype(layoutSetPrototype);
      } catch (Exception e) {
        _log.error(e, e);
      }
    }

    try {
      ExpandoColumn expandoColumn =
          ExpandoColumnLocalServiceUtil.getColumn(
              companyId,
              LayoutSetPrototype.class.getName(),
              ExpandoTableConstants.DEFAULT_TABLE_NAME,
              SocialOfficeConstants.LAYOUT_SET_PROTOTYPE_KEY);

      ExpandoValueLocalServiceUtil.deleteColumnValues(expandoColumn.getColumnId());
    } catch (Exception e) {
      _log.error(e, e);
    }
  }
  @Before
  public void setUp() throws Exception {
    setUpPermissionThreadLocal();
    setUpPrincipalThreadLocal();

    _group = GroupTestUtil.addGroup();

    setUpParentFolder();
    setUpResourcePermission();

    List<DLFileEntryType> dlFileEntryTypes =
        DLFileEntryTypeLocalServiceUtil.getFileEntryTypes(
            PortalUtil.getCurrentAndAncestorSiteGroupIds(_group.getGroupId()));

    for (DLFileEntryType dlFileEntryType : dlFileEntryTypes) {
      String fileEntryTypeKey = dlFileEntryType.getFileEntryTypeKey();

      if (fileEntryTypeKey.equals(DLFileEntryTypeConstants.FILE_ENTRY_TYPE_KEY_CONTRACT)) {

        _contractDLFileEntryTypeId = dlFileEntryType.getFileEntryTypeId();
      }
    }

    ExpandoTable expandoTable =
        ExpandoTableLocalServiceUtil.addDefaultTable(
            PortalUtil.getDefaultCompanyId(), DLFileEntry.class.getName());

    ExpandoColumnLocalServiceUtil.addColumn(
        expandoTable.getTableId(),
        _EXPANDO_ATTRIBUTE_NAME,
        ExpandoColumnConstants.STRING,
        StringPool.BLANK);

    _serviceContext = getServiceContext();

    FileEntry fileEntry =
        DLAppServiceUtil.addFileEntry(
            _group.getGroupId(),
            _parentFolder.getFolderId(),
            _SOURCE_FILE_NAME,
            ContentTypes.APPLICATION_OCTET_STREAM,
            _TITLE,
            StringPool.BLANK,
            StringPool.BLANK,
            _DATA_VERSION_1,
            _serviceContext);

    _fileVersion =
        DLFileVersionLocalServiceUtil.getFileVersion(
            fileEntry.getFileEntryId(), DLFileEntryConstants.VERSION_DEFAULT);
  }
  protected void doAddAttributes(Document document, ExpandoBridge expandoBridge) {

    List<ExpandoColumn> expandoColumns =
        ExpandoColumnLocalServiceUtil.getDefaultTableColumns(
            expandoBridge.getCompanyId(), expandoBridge.getClassName());

    if ((expandoColumns == null) || expandoColumns.isEmpty()) {
      return;
    }

    List<ExpandoColumn> indexedColumns = new ArrayList<>();

    for (ExpandoColumn expandoColumn : expandoColumns) {
      UnicodeProperties properties = expandoColumn.getTypeSettingsProperties();

      int indexType = GetterUtil.getInteger(properties.get(ExpandoColumnConstants.INDEX_TYPE));

      if (indexType != ExpandoColumnConstants.INDEX_TYPE_NONE) {
        indexedColumns.add(expandoColumn);
      }
    }

    if (indexedColumns.isEmpty()) {
      return;
    }

    List<ExpandoValue> expandoValues =
        ExpandoValueLocalServiceUtil.getRowValues(
            expandoBridge.getCompanyId(),
            expandoBridge.getClassName(),
            ExpandoTableConstants.DEFAULT_TABLE_NAME,
            expandoBridge.getClassPK(),
            QueryUtil.ALL_POS,
            QueryUtil.ALL_POS);

    for (ExpandoColumn expandoColumn : indexedColumns) {
      try {
        addAttribute(document, expandoColumn, expandoValues);
      } catch (Exception e) {
        _log.error("Indexing " + expandoColumn.getName(), e);
      }
    }
  }