@Test
  public void testGetIndexerByModelClassName() throws Exception {
    Indexer<User> userIndexer = IndexerRegistryUtil.getIndexer(User.class.getName());

    assertNotNull(userIndexer);

    Indexer<UserGroup> userGroupIndexer = IndexerRegistryUtil.getIndexer(UserGroup.class.getName());

    assertNotNull(userGroupIndexer);
  }
  @Test
  public void testGetIndexerByIndexerClassName() throws Exception {
    Indexer<MBMessage> mbMessageIndexer =
        IndexerRegistryUtil.getIndexer(MBMessageIndexer.class.getName());

    assertNotNull(mbMessageIndexer);

    Indexer<MBThread> mbThreadIndexer =
        IndexerRegistryUtil.getIndexer(MBThreadIndexer.class.getName());

    assertNotNull(mbThreadIndexer);
  }
  public SearchContainer<MBMessage> getCommentsSearchContainer() throws PortalException {

    SearchContainer<MBMessage> searchContainer =
        new SearchContainer(
            _liferayPortletRequest, _liferayPortletResponse.createRenderURL(), null, null);

    SearchContext searchContext =
        SearchContextFactory.getInstance(_liferayPortletRequest.getHttpServletRequest());

    searchContext.setAttribute(
        Field.CLASS_NAME_ID, PortalUtil.getClassNameId(JournalArticle.class));

    searchContext.setAttribute("discussion", true);

    List<MBMessage> mbMessages = new ArrayList<>();

    Indexer indexer = IndexerRegistryUtil.getIndexer(MBMessage.class);

    Hits hits = indexer.search(searchContext);

    for (Document document : hits.getDocs()) {
      long entryClassPK = GetterUtil.getLong(document.get(Field.ENTRY_CLASS_PK));

      MBMessage mbMessage = MBMessageLocalServiceUtil.fetchMBMessage(entryClassPK);

      mbMessages.add(mbMessage);
    }

    searchContainer.setResults(mbMessages);

    searchContainer.setTotal(hits.getLength());

    return searchContainer;
  }
  public Books updateStatus(
      long userId, long resourcePrimKey, int status, ServiceContext serviceContext)
      throws PortalException, SystemException {

    User user = userLocalService.getUser(userId);
    Books book = getBooks(resourcePrimKey);

    book.setStatus(status);
    book.setStatusByUserId(userId);
    book.setStatusByUserName(user.getFullName());
    book.setStatusDate(serviceContext.getModifiedDate());

    booksPersistence.update(book, false);

    if (status == WorkflowConstants.STATUS_APPROVED) {
      assetEntryLocalService.updateVisible(Books.class.getName(), resourcePrimKey, true);
    } else {
      assetEntryLocalService.updateVisible(Books.class.getName(), resourcePrimKey, false);
    }

    // Indexer
    Indexer indexer = IndexerRegistryUtil.getIndexer(Books.class);
    indexer.reindex(book);
    return book;
  }
  @Test
  public void testSearchAndDeleteFolderAndSearch() throws Exception {
    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group.getGroupId());

    BookmarksFolder folder =
        BookmarksTestUtil.addFolder(_group.getGroupId(), RandomTestUtil.randomString());

    BookmarksEntry entry = BookmarksTestUtil.addEntry(folder.getFolderId(), true, serviceContext);

    long companyId = entry.getCompanyId();
    long groupId = entry.getFolder().getGroupId();
    long folderId = entry.getFolderId();
    String keywords = "test";

    SearchContext searchContext =
        BookmarksTestUtil.getSearchContext(companyId, groupId, folderId, keywords);

    Indexer indexer = IndexerRegistryUtil.getIndexer(BookmarksEntry.class);

    Hits hits = indexer.search(searchContext);

    Assert.assertEquals(1, hits.getLength());

    BookmarksFolderLocalServiceUtil.deleteFolder(folderId);

    hits = indexer.search(searchContext);

    Query query = hits.getQuery();

    Assert.assertEquals(query.toString(), 0, hits.getLength());
  }
  /**
   * Returns the number of user groups that match the name and description.
   *
   * @param companyId the primary key of the user group's company
   * @param name the user group's name (optionally <code>null</code>)
   * @param description the user group's description (optionally <code>null</code>)
   * @param params the finder params (optionally <code>null</code>). For more information see {@link
   *     com.liferay.portal.service.persistence.UserGroupFinder}
   * @param andOperator whether every field must match its keywords or just one field
   * @return the number of matching user groups
   * @see com.liferay.portal.service.persistence.UserGroupFinder
   */
  @Override
  public int searchCount(
      long companyId,
      String name,
      String description,
      LinkedHashMap<String, Object> params,
      boolean andOperator) {

    Indexer<?> indexer = IndexerRegistryUtil.nullSafeGetIndexer(UserGroup.class);

    if (!indexer.isIndexerEnabled()
        || !PropsValues.USER_GROUPS_SEARCH_WITH_INDEX
        || isUseCustomSQL(params)) {

      return userGroupFinder.countByC_N_D(companyId, name, description, params, andOperator);
    }

    try {
      SearchContext searchContext =
          buildSearchContext(
              companyId,
              name,
              description,
              params,
              true,
              QueryUtil.ALL_POS,
              QueryUtil.ALL_POS,
              null);

      return (int) indexer.searchCount(searchContext);
    } catch (Exception e) {
      throw new SystemException(e);
    }
  }
  @Override
  public List<AssetVocabulary> getVocabularies(Hits hits) throws PortalException {

    List<Document> documents = hits.toList();

    List<AssetVocabulary> vocabularies = new ArrayList<>(documents.size());

    for (Document document : documents) {
      long vocabularyId = GetterUtil.getLong(document.get(Field.ASSET_VOCABULARY_ID));

      AssetVocabulary vocabulary = fetchAssetVocabulary(vocabularyId);

      if (vocabulary == null) {
        vocabularies = null;

        Indexer indexer = IndexerRegistryUtil.getIndexer(AssetVocabulary.class);

        long companyId = GetterUtil.getLong(document.get(Field.COMPANY_ID));

        indexer.delete(companyId, document.getUID());
      } else if (vocabularies != null) {
        vocabularies.add(vocabulary);
      }
    }

    return vocabularies;
  }
  /**
   * Updates the user group.
   *
   * @param companyId the primary key of the user group's company
   * @param userGroupId the primary key of the user group
   * @param name the user group's name
   * @param description the user group's description
   * @param serviceContext the service context to be applied (optionally <code>null</code>). Can set
   *     expando bridge attributes for the user group.
   * @return the user group
   */
  @Override
  public UserGroup updateUserGroup(
      long companyId,
      long userGroupId,
      String name,
      String description,
      ServiceContext serviceContext)
      throws PortalException {

    // User group

    validate(userGroupId, companyId, name);

    UserGroup userGroup = userGroupPersistence.findByPrimaryKey(userGroupId);

    userGroup.setName(name);
    userGroup.setDescription(description);
    userGroup.setExpandoBridgeAttributes(serviceContext);

    userGroupPersistence.update(userGroup);

    // Indexer

    Indexer<UserGroup> indexer = IndexerRegistryUtil.nullSafeGetIndexer(UserGroup.class);

    indexer.reindex(userGroup);

    return userGroup;
  }
  public EmpDiscipline addEmpDiscipline(
      EmpDiscipline prePersistedObj, ServiceContext serviceContext) {
    try {
      final EmpDiscipline o = super.addEmpDiscipline(prePersistedObj);

      // add permission
      resourceLocalService.addResources(
          o.getCompanyId(),
          o.getGroupId(),
          o.getUserId(),
          EmpDiscipline.class.getName(),
          o.getEmpDisciplineId(),
          false,
          true,
          true);

      // index new EmpDiscipline
      Indexer indexer = IndexerRegistryUtil.nullSafeGetIndexer(EmpDiscipline.class);
      indexer.reindex(EmpDiscipline.class.getName(), o.getEmpDisciplineId());

      final Emp emp = empLocalService.fetchEmp(o.getEmpId());
      emp.setStatus(EmployeeStatus.DISCIPLINE.toString());
      empLocalService.updateEmp(emp);

      return o;
    } catch (SystemException e) {
      LOGGER.info(e);
    } catch (SearchException e) {
      LOGGER.info(e);
    } catch (PortalException e) {
      LOGGER.info(e);
    }
    return null;
  }
  @Test
  public void testSearchAndVerifyDocs() throws Exception {
    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group.getGroupId());

    BookmarksFolder folder =
        BookmarksTestUtil.addFolder(_group.getGroupId(), RandomTestUtil.randomString());

    BookmarksEntry entry = BookmarksTestUtil.addEntry(folder.getFolderId(), true, serviceContext);

    SearchContext searchContext =
        BookmarksTestUtil.getSearchContext(
            entry.getCompanyId(), entry.getGroupId(), entry.getFolderId(), "test");

    Indexer indexer = IndexerRegistryUtil.getIndexer(BookmarksEntry.class);

    Hits hits = indexer.search(searchContext);

    Assert.assertEquals(1, hits.getLength());

    List<Document> results = hits.toList();

    for (Document doc : results) {
      Assert.assertEquals(entry.getCompanyId(), GetterUtil.getLong(doc.get(Field.COMPANY_ID)));
      Assert.assertEquals(BookmarksEntry.class.getName(), doc.get(Field.ENTRY_CLASS_NAME));
      Assert.assertEquals(entry.getEntryId(), GetterUtil.getLong(doc.get(Field.ENTRY_CLASS_PK)));
      AssertUtils.assertEqualsIgnoreCase(entry.getName(), doc.get(Field.TITLE));
      Assert.assertEquals(entry.getUrl(), doc.get(Field.URL));
    }
  }
  @Test
  public void testSearchRange() throws Exception {
    BookmarksEntry entry = BookmarksTestUtil.addEntry(_group.getGroupId(), true);

    BookmarksTestUtil.addEntry(_group.getGroupId(), true);
    BookmarksTestUtil.addEntry(_group.getGroupId(), true);
    BookmarksTestUtil.addEntry(_group.getGroupId(), true);

    SearchContext searchContext =
        BookmarksTestUtil.getSearchContext(
            _group.getCompanyId(), _group.getGroupId(), entry.getFolderId(), "test");

    Indexer indexer = IndexerRegistryUtil.getIndexer(BookmarksEntry.class);

    searchContext.setEnd(3);
    searchContext.setFolderIds((long[]) null);
    searchContext.setStart(1);

    Hits hits = indexer.search(searchContext);

    Assert.assertEquals(4, hits.getLength());

    Document[] documents = hits.getDocs();

    Assert.assertEquals(2, documents.length);
  }
  @Override
  @SystemEvent(action = SystemEventConstants.ACTION_SKIP, type = SystemEventConstants.TYPE_DELETE)
  public void deleteCategory(MBCategory category, boolean includeTrashedEntries)
      throws PortalException, SystemException {

    // Categories

    List<MBCategory> categories =
        mbCategoryPersistence.findByG_P(category.getGroupId(), category.getCategoryId());

    for (MBCategory curCategory : categories) {
      if (includeTrashedEntries || !curCategory.isInTrash()) {
        deleteCategory(curCategory, includeTrashedEntries);
      }
    }

    // Indexer

    Indexer indexer = IndexerRegistryUtil.nullSafeGetIndexer(MBMessage.class);

    indexer.delete(category);

    // Threads

    mbThreadLocalService.deleteThreads(
        category.getGroupId(), category.getCategoryId(), includeTrashedEntries);

    // Mailing list

    try {
      mbMailingListLocalService.deleteCategoryMailingList(
          category.getGroupId(), category.getCategoryId());
    } catch (NoSuchMailingListException nsmle) {
    }

    // Subscriptions

    subscriptionLocalService.deleteSubscriptions(
        category.getCompanyId(), MBCategory.class.getName(), category.getCategoryId());

    // Expando

    expandoRowLocalService.deleteRows(category.getCategoryId());

    // Resources

    resourceLocalService.deleteResource(
        category.getCompanyId(),
        MBCategory.class.getName(),
        ResourceConstants.SCOPE_INDIVIDUAL,
        category.getCategoryId());

    // Trash

    trashEntryLocalService.deleteEntry(MBCategory.class.getName(), category.getCategoryId());

    // Category

    mbCategoryPersistence.remove(category);
  }
  @Override
  public BaseModelSearchResult<UserGroup> searchUserGroups(
      long companyId,
      String name,
      String description,
      LinkedHashMap<String, Object> params,
      boolean andSearch,
      int start,
      int end,
      Sort sort)
      throws PortalException {

    Indexer<UserGroup> indexer = IndexerRegistryUtil.nullSafeGetIndexer(UserGroup.class);

    SearchContext searchContext =
        buildSearchContext(companyId, name, description, params, andSearch, start, end, sort);

    for (int i = 0; i < 10; i++) {
      Hits hits = indexer.search(searchContext);

      List<UserGroup> userGroups = UsersAdminUtil.getUserGroups(hits);

      if (userGroups != null) {
        return new BaseModelSearchResult<>(userGroups, hits.getLength());
      }
    }

    throw new SearchException("Unable to fix the search index after 10 attempts");
  }
  @Override
  public List<AssetCategory> getCategories(Hits hits) throws PortalException {
    List<Document> documents = hits.toList();

    List<AssetCategory> categories = new ArrayList<>(documents.size());

    for (Document document : documents) {
      long categoryId = GetterUtil.getLong(document.get(Field.ASSET_CATEGORY_ID));

      AssetCategory category = fetchCategory(categoryId);

      if (category == null) {
        categories = null;

        Indexer<AssetCategory> indexer = IndexerRegistryUtil.getIndexer(AssetCategory.class);

        long companyId = GetterUtil.getLong(document.get(Field.COMPANY_ID));

        indexer.delete(companyId, document.getUID());
      } else if (categories != null) {
        categories.add(category);
      }
    }

    return categories;
  }
    @Override
    public IndexerPostProcessor addingService(
        ServiceReference<IndexerPostProcessor> serviceReference) {

      Registry registry = RegistryUtil.getRegistry();

      IndexerPostProcessor indexerPostProcessor = registry.getService(serviceReference);

      List<String> indexerClassNames =
          StringPlus.asList(serviceReference.getProperty("indexer.class.name"));

      for (String indexerClassName : indexerClassNames) {
        Indexer indexer = IndexerRegistryUtil.getIndexer(indexerClassName);

        if (indexer == null) {
          _log.error("No indexer for " + indexerClassName + " was found");

          continue;
        }

        indexer.registerIndexerPostProcessor(indexerPostProcessor);
      }

      return indexerPostProcessor;
    }
  public void removePluginPackage(PluginPackage pluginPackage) throws PortalException {

    _pluginPackages.remove(pluginPackage.getContext());

    Indexer indexer = IndexerRegistryUtil.getIndexer(PluginPackage.class);

    indexer.delete(pluginPackage);
  }
  @Override
  public MBThread moveThread(long groupId, long categoryId, long threadId)
      throws PortalException, SystemException {

    MBThread thread = mbThreadPersistence.findByPrimaryKey(threadId);

    long oldCategoryId = thread.getCategoryId();

    MBCategory oldCategory = null;

    if (oldCategoryId != MBCategoryConstants.DEFAULT_PARENT_CATEGORY_ID) {
      oldCategory = mbCategoryPersistence.fetchByPrimaryKey(oldCategoryId);
    }

    MBCategory category = null;

    if (categoryId != MBCategoryConstants.DEFAULT_PARENT_CATEGORY_ID) {
      category = mbCategoryPersistence.fetchByPrimaryKey(categoryId);
    }

    // Thread

    thread.setModifiedDate(new Date());
    thread.setCategoryId(categoryId);

    mbThreadPersistence.update(thread);

    // Messages

    List<MBMessage> messages =
        mbMessagePersistence.findByG_C_T(groupId, oldCategoryId, thread.getThreadId());

    for (MBMessage message : messages) {
      message.setCategoryId(categoryId);

      mbMessagePersistence.update(message);

      // Indexer

      if (!message.isDiscussion()) {
        Indexer indexer = IndexerRegistryUtil.nullSafeGetIndexer(MBMessage.class);

        indexer.reindex(message);
      }
    }

    // Category

    if ((oldCategory != null) && (categoryId != oldCategoryId)) {
      MBUtil.updateCategoryStatistics(oldCategory.getCompanyId(), oldCategory.getCategoryId());
    }

    if ((category != null) && (categoryId != oldCategoryId)) {
      MBUtil.updateCategoryStatistics(category.getCompanyId(), category.getCategoryId());
    }

    return thread;
  }
  protected void doUpdatePermissionFields(String resourceName, String resourceClassPK)
      throws Exception {

    Indexer indexer = IndexerRegistryUtil.getIndexer(resourceName);

    if (indexer != null) {
      indexer.reindex(resourceName, GetterUtil.getLong(resourceClassPK));
    }
  }
  public void reindex(List<AssetEntry> entries) throws PortalException {
    for (AssetEntry entry : entries) {
      String className = PortalUtil.getClassName(entry.getClassNameId());

      Indexer indexer = IndexerRegistryUtil.nullSafeGetIndexer(className);

      indexer.reindex(className, entry.getClassPK());
    }
  }
  /**
   * Adds the roles to the user. The user is reindexed after the roles are added.
   *
   * @param userId the primary key of the user
   * @param roleIds the primary keys of the roles
   * @throws PortalException if a user with the primary key could not be found
   * @throws SystemException if a system exception occurred
   * @see com.liferay.portal.service.persistence.UserPersistence#addRoles( long, long[])
   */
  public void addUserRoles(long userId, long[] roleIds) throws PortalException, SystemException {

    userPersistence.addRoles(userId, roleIds);

    Indexer indexer = IndexerRegistryUtil.nullSafeGetIndexer(User.class);

    indexer.reindex(userId);

    PermissionCacheUtil.clearCache();
  }
예제 #21
0
  protected int searchBaseModelsCount(Class<?> clazz, long groupId, SearchContext searchContext)
      throws Exception {

    Indexer indexer = IndexerRegistryUtil.getIndexer(clazz);

    searchContext.setGroupIds(new long[] {groupId});

    Hits results = indexer.search(searchContext);

    return results.getLength();
  }
 /**
  * Xóa bỏ thông tin một thống kê theo ngày
  *
  * <p>Version: OEP 2.0
  *
  * <p>History: DATE AUTHOR DESCRIPTION -------------------------------------------------
  * 21-September-2015 trungdk Xóa bỏ thông tin thống kê theo ngày
  *
  * @param statisticByDomain thống kê theo ngày được xóa
  * @return
  */
 public void removeStatisticByDomain(StatisticByDomain statisticByDomain)
     throws PortalException, SystemException {
   statisticByDomainPersistence.remove(statisticByDomain);
   Indexer indexer = IndexerRegistryUtil.nullSafeGetIndexer(StatisticByDomain.class);
   indexer.delete(statisticByDomain);
   resourceLocalService.deleteResource(
       statisticByDomain.getCompanyId(),
       StatisticByDomain.class.getName(),
       ResourceConstants.SCOPE_INDIVIDUAL,
       statisticByDomain.getStatisticByDomainId());
 }
  protected void mergeCategories(MBCategory fromCategory, long toCategoryId)
      throws PortalException, SystemException {

    if ((toCategoryId == MBCategoryConstants.DEFAULT_PARENT_CATEGORY_ID)
        || (toCategoryId == MBCategoryConstants.DISCUSSION_CATEGORY_ID)) {

      return;
    }

    List<MBCategory> categories =
        mbCategoryPersistence.findByG_P(fromCategory.getGroupId(), fromCategory.getCategoryId());

    for (MBCategory category : categories) {
      mergeCategories(category, toCategoryId);
    }

    List<MBThread> threads =
        mbThreadPersistence.findByG_C(fromCategory.getGroupId(), fromCategory.getCategoryId());

    for (MBThread thread : threads) {

      // Thread

      thread.setCategoryId(toCategoryId);

      mbThreadPersistence.update(thread);

      List<MBMessage> messages = mbMessagePersistence.findByThreadId(thread.getThreadId());

      for (MBMessage message : messages) {

        // Message

        message.setCategoryId(toCategoryId);

        mbMessagePersistence.update(message);

        // Indexer

        Indexer indexer = IndexerRegistryUtil.nullSafeGetIndexer(MBMessage.class);

        indexer.reindex(message);
      }
    }

    MBCategory toCategory = mbCategoryPersistence.findByPrimaryKey(toCategoryId);

    toCategory.setThreadCount(fromCategory.getThreadCount() + toCategory.getThreadCount());
    toCategory.setMessageCount(fromCategory.getMessageCount() + toCategory.getMessageCount());

    mbCategoryPersistence.update(toCategory);

    deleteCategory(fromCategory);
  }
  public Message addMessage(
      long userId,
      long folderId,
      String sender,
      String to,
      String cc,
      String bcc,
      Date sentDate,
      String subject,
      String body,
      String flags,
      long remoteMessageId)
      throws PortalException, SystemException {

    // Message

    User user = userPersistence.findByPrimaryKey(userId);
    Folder folder = folderPersistence.findByPrimaryKey(folderId);
    Date now = new Date();

    long messageId = counterLocalService.increment();

    Message message = messagePersistence.create(messageId);

    message.setCompanyId(user.getCompanyId());
    message.setUserId(user.getUserId());
    message.setUserName(user.getFullName());
    message.setCreateDate(now);
    message.setModifiedDate(now);
    message.setAccountId(folder.getAccountId());
    message.setFolderId(folderId);
    message.setSender(sender);
    message.setTo(to);
    message.setCc(cc);
    message.setBcc(bcc);
    message.setSentDate(sentDate);
    message.setSubject(subject);
    message.setPreview(getPreview(body));
    message.setBody(getBody(body));
    message.setFlags(flags);
    message.setSize(getSize(messageId, body));
    message.setRemoteMessageId(remoteMessageId);

    messagePersistence.update(message, false);

    // Indexer

    Indexer indexer = IndexerRegistryUtil.getIndexer(Message.class);

    indexer.reindex(message);

    return message;
  }
  /**
   * Removes the matching roles associated with the user. The user is reindexed after the roles are
   * removed.
   *
   * @param userId the primary key of the user
   * @param roleIds the primary keys of the roles
   * @throws PortalException if a user with the primary key could not be found or if a role with any
   *     one of the primary keys could not be found
   * @throws SystemException if a system exception occurred
   */
  public void unsetUserRoles(long userId, long[] roleIds) throws PortalException, SystemException {

    roleIds = UsersAdminUtil.removeRequiredRoles(userId, roleIds);

    userPersistence.removeRoles(userId, roleIds);

    Indexer indexer = IndexerRegistryUtil.nullSafeGetIndexer(User.class);

    indexer.reindex(userId);

    PermissionCacheUtil.clearCache();
  }
  protected void search(
      FileEntry fileEntry, boolean rootFolder, String keywords, boolean assertTrue)
      throws Exception {

    SearchContext searchContext = new SearchContext();

    searchContext.setAttribute("paginationType", "regular");
    searchContext.setCompanyId(fileEntry.getCompanyId());
    searchContext.setFolderIds(new long[] {fileEntry.getFolderId()});
    searchContext.setGroupIds(new long[] {fileEntry.getRepositoryId()});
    searchContext.setKeywords(keywords);

    QueryConfig queryConfig = new QueryConfig();

    queryConfig.setHighlightEnabled(false);
    queryConfig.setScoreEnabled(false);

    searchContext.setQueryConfig(queryConfig);

    Indexer indexer = IndexerRegistryUtil.getIndexer(DLFileEntryConstants.getClassName());

    Hits hits = indexer.search(searchContext);

    List<Document> documents = hits.toList();

    boolean found = false;

    for (Document document : documents) {
      long fileEntryId = GetterUtil.getLong(document.get(Field.ENTRY_CLASS_PK));

      if (fileEntryId == fileEntry.getFileEntryId()) {
        found = true;

        break;
      }
    }

    String message = "Search engine could not find ";

    if (rootFolder) {
      message += "root file entry by " + keywords;
    } else {
      message += "file entry by " + keywords;
    }

    message += " using query " + hits.getQuery();

    if (assertTrue) {
      Assert.assertTrue(message, found);
    } else {
      Assert.assertFalse(message, found);
    }
  }
  /**
   * Adds a role with additional parameters. The user is reindexed after role is added.
   *
   * @param userId the primary key of the user
   * @param companyId the primary key of the company
   * @param name the role's name
   * @param titleMap the role's localized titles (optionally <code>null</code>)
   * @param descriptionMap the role's localized descriptions (optionally <code>null</code>)
   * @param type the role's type (optionally <code>0</code>)
   * @param className the name of the class for which the role is created (optionally <code>null
   *     </code>)
   * @param classPK the primary key of the class for which the role is created (optionally <code>0
   *     </code>)
   * @return the role
   * @throws PortalException if the class name or the role name were invalid, if the role is a
   *     duplicate, or if a user with the primary key could not be found
   * @throws SystemException if a system exception occurred
   */
  public Role addRole(
      long userId,
      long companyId,
      String name,
      Map<Locale, String> titleMap,
      Map<Locale, String> descriptionMap,
      int type,
      String className,
      long classPK)
      throws PortalException, SystemException {

    // Role

    className = GetterUtil.getString(className);
    long classNameId = PortalUtil.getClassNameId(className);

    long roleId = counterLocalService.increment();

    if ((classNameId <= 0) || className.equals(Role.class.getName())) {
      classNameId = PortalUtil.getClassNameId(Role.class);
      classPK = roleId;
    }

    validate(0, companyId, classNameId, name);

    Role role = rolePersistence.create(roleId);

    role.setCompanyId(companyId);
    role.setClassNameId(classNameId);
    role.setClassPK(classPK);
    role.setName(name);
    role.setTitleMap(titleMap);
    role.setDescriptionMap(descriptionMap);
    role.setType(type);

    rolePersistence.update(role, false);

    // Resources

    if (userId > 0) {
      resourceLocalService.addResources(
          companyId, 0, userId, Role.class.getName(), role.getRoleId(), false, false, false);

      if (!ImportExportThreadLocal.isImportInProcess()) {
        Indexer indexer = IndexerRegistryUtil.nullSafeGetIndexer(User.class);

        indexer.reindex(userId);
      }
    }

    return role;
  }
예제 #28
0
 public void indexAll() {
   final List<EmpDiscipline> all = findAll();
   // re-index modified employee
   Indexer indexer = IndexerRegistryUtil.nullSafeGetIndexer(EmpDiscipline.class.getName());
   for (EmpDiscipline item : all) {
     // re-index
     try {
       indexer.reindex(item);
     } catch (SearchException e) {
       LOGGER.info(e);
     }
   }
 }
예제 #29
0
  public EmpDiscipline updateEmpDiscipline(EmpDiscipline empDiscipline) throws SystemException {
    try {
      EmpDiscipline o = super.updateEmpDiscipline(empDiscipline);
      // index new EmpDiscipline
      Indexer indexer = IndexerRegistryUtil.nullSafeGetIndexer(EmpDiscipline.class);

      indexer.reindex(EmpDiscipline.class.getName(), o.getEmpDisciplineId());
      return o;
    } catch (SearchException e) {
      LOGGER.info(e);
    }
    return null;
  }
예제 #30
0
  public void deleteCategory(MBCategory category) throws PortalException, SystemException {

    // Categories

    List<MBCategory> categories =
        mbCategoryPersistence.findByG_P(category.getGroupId(), category.getCategoryId());

    for (MBCategory curCategory : categories) {
      deleteCategory(curCategory);
    }

    // Indexer

    Indexer indexer = IndexerRegistryUtil.nullSafeGetIndexer(MBMessage.class);

    indexer.delete(category);

    // Threads

    mbThreadLocalService.deleteThreads(category.getGroupId(), category.getCategoryId());

    // Mailing list

    try {
      mbMailingListLocalService.deleteCategoryMailingList(
          category.getGroupId(), category.getCategoryId());
    } catch (NoSuchMailingListException nsmle) {
    }

    // Subscriptions

    subscriptionLocalService.deleteSubscriptions(
        category.getCompanyId(), MBCategory.class.getName(), category.getCategoryId());

    // Expando

    expandoValueLocalService.deleteValues(MBCategory.class.getName(), category.getCategoryId());

    // Resources

    resourceLocalService.deleteResource(
        category.getCompanyId(),
        MBCategory.class.getName(),
        ResourceConstants.SCOPE_INDIVIDUAL,
        category.getCategoryId());

    // Category

    mbCategoryPersistence.remove(category);
  }