@After
  @Override
  public void tearDown() throws Exception {
    ExpandoTable expandoTable =
        ExpandoTableLocalServiceUtil.getDefaultTable(
            PortalUtil.getDefaultCompanyId(), DLFileEntry.class.getName());

    ExpandoTableLocalServiceUtil.deleteTable(expandoTable);

    super.tearDown();
  }
  @Before
  @Override
  public void setUp() throws Exception {
    super.setUp();

    SimpleAction simpleAction = new AddDefaultDocumentLibraryStructuresAction();

    String companyIdString = String.valueOf(TestPropsValues.getCompanyId());

    simpleAction.run(new String[] {companyIdString});

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

    for (DLFileEntryType dlFileEntryType : dlFileEntryTypes) {
      String name = dlFileEntryType.getName(LocaleUtil.getSiteDefault());

      if (name.equals(DLFileEntryTypeConstants.NAME_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);
  }
  @Override
  protected void doUpgrade() throws Exception {
    String name = PrincipalThreadLocal.getName();

    try {
      long companyId = PortalUtil.getDefaultCompanyId();

      long defaultUserId = UserLocalServiceUtil.getDefaultUserId(companyId);

      PrincipalThreadLocal.setName(defaultUserId);

      clearData(companyId);
      setupPermissionsDefined(defaultUserId);
    } finally {
      PrincipalThreadLocal.setName(name);
    }
  }
 @Override
 public List<User> findMatchingUsers(String prefix) {
   try {
     List<com.liferay.portal.model.User> search =
         UserLocalServiceUtil.search(
             PortalUtil.getDefaultCompanyId(),
             prefix,
             0,
             null,
             0,
             100,
             (OrderByComparator) null);
     List<User> result = new ArrayList<User>(search.size());
     for (com.liferay.portal.model.User portalUser : search) {
       result.add(new LiferayUserImpl(portalUser));
     }
     return result;
   } catch (SystemException e) {
     throw new RuntimeException(e);
   }
 }
Beispiel #5
0
  public void run(String[] arg0) throws ActionException {

    File file = new File("old-users.csv");

    _log.debug("file ==> " + file.getAbsolutePath());

    InputStream inputStream = null;
    try {
      inputStream = new FileInputStream(file);
    } catch (FileNotFoundException e) {
      _log.debug("File not found...Existing....");
      return;
    }

    BufferedReader br = new BufferedReader(new InputStreamReader(inputStream));

    long companyId = PortalUtil.getDefaultCompanyId();
    long creatorUserId = 0l;
    try {
      creatorUserId = UserLocalServiceUtil.getDefaultUserId(companyId);
    } catch (PortalException e) {
      e.printStackTrace();
    } catch (SystemException e) {
      e.printStackTrace();
    }

    try {
      String line = StringPool.BLANK;
      while (Validator.isNotNull(line = br.readLine())) {
        insertOldUser(companyId, creatorUserId, line);
      }
    } catch (IOException e) {
      e.printStackTrace();
    }

    file.delete();
  }
 private boolean isAdmin(HttpServletRequest httpRequest) throws PortalException, SystemException {
   final long userId = PortalUtil.getUserId(httpRequest);
   final long companyId = PortalUtil.getDefaultCompanyId();
   return UserLocalServiceUtil.hasRoleUser(companyId, RoleConstants.ADMINISTRATOR, userId, true);
 }
  @RenderMapping(params = "action=ricercaLibera")
  public String effettuaRicerca(
      RenderRequest renderRequest,
      RenderResponse renderResponse,
      Model model,
      @ModelAttribute("navigaProgetti") NavigaProgetti navigaProgetti,
      @RequestParam("cercaPerKeyword") String cercaPerKeyword) {

    model.addAttribute("currentAction", "ricercaLibera");
    navigaProgetti.setCurrentAction("ricercaLibera");

    model.addAttribute("cercaPerKeyword", cercaPerKeyword);
    model.addAttribute("navigaProgetti", navigaProgetti);

    logger.info("effettuaRicerca.cercaPerKeyword: " + cercaPerKeyword);
    try {

      Document[] documents = null;
      List<DocumentoDTO> risultatiGenerici = new ArrayList<DocumentoDTO>();
      List<Progetto> risultatiProgetti = new ArrayList<Progetto>();

      if (cercaPerKeyword != null && cercaPerKeyword.length() > 3) {
        Query query =
            StringQueryFactoryUtil.create(
                Field.TITLE
                    + ":"
                    + cercaPerKeyword
                    + " or "
                    + Field.CONTENT
                    + ":"
                    + cercaPerKeyword
                    + " or "
                    + Constants.RICERCALIBERA_FIELD_SEARCH
                    + ":"
                    + cercaPerKeyword
                    + " or "
                    + Constants.RICERCALIBERA_FIELD_LOCALIZZAZIONE
                    + ":"
                    + cercaPerKeyword
                    + " or "
                    + Constants.RICERCALIBERA_FIELD_CODICE_CUP
                    + ":"
                    + cercaPerKeyword);

        logger.debug("query = " + query.toString());

        Hits hits =
            SearchEngineUtil.search(
                SearchEngineUtil.SYSTEM_ENGINE_ID, PortalUtil.getDefaultCompanyId(), query, -1, -1);

        logger.info("hits = " + hits.getLength());
        documents = hits.getDocs();
        model.addAttribute("valoreRicercaValido", "SI");
      } else {
        SessionMessages.add(renderRequest, "valore-ricerca-non-valido");
        model.addAttribute("valoreRicercaValido", "NO");
      }

      if (documents != null) {
        DocumentoDTO documento = null;
        Progetto progetto = null;
        int contaDoc = 0;
        for (Document document : documents) {
          logger.debug("Document: " + document.getUID());

          //					for (Map.Entry<String, Field> entry : document.getFields().entrySet() ) {
          //						logger.debug("-- " +  entry.getKey() + ": " + entry.getValue().getValue() );
          //					}

          if (document.get(Field.ENTRY_CLASS_NAME).equals(Progetto.class.getName())) {

            progetto = getProgettoFromDocument(document);
            risultatiProgetti.add(progetto);

          } else {

            documento = new DocumentoDTO();
            documento.setTitolo(document.getField(Field.TITLE).getValue());
            String testo = "non disponibile";
            if (document.getField(Field.CONTENT) != null) {
              testo = trunc(document.getField(Field.CONTENT).getValue(), 37);
            }
            documento.setTesto(testo);
            documento.setId(contaDoc++);

            AssetEntry assetEntry =
                AssetEntryLocalServiceUtil.getEntry(
                    document.get(Field.ENTRY_CLASS_NAME),
                    Long.parseLong(document.get(Field.ENTRY_CLASS_PK)));
            documento.setUrl(
                getAssetViewURL(renderRequest, renderResponse, assetEntry, cercaPerKeyword));

            risultatiGenerici.add(documento);
          }
        }
      }

      // model.addAttribute("risultatiGenerici", risultatiGenerici);
      model.addAttribute("risultatiGenericiSize", risultatiGenerici.size());

      SearchContainer<DocumentoDTO> searchContainerElencoDoc =
          new SearchContainer<DocumentoDTO>(
              renderRequest,
              renderResponse.createRenderURL(),
              null,
              "Nessun dato trovato per la selezione fatta");
      searchContainerElencoDoc.setDelta(risultatiGenerici.size());
      searchContainerElencoDoc.setTotal(risultatiGenerici.size());
      searchContainerElencoDoc.setResults(risultatiGenerici);
      model.addAttribute("searchContainerElencoDoc", searchContainerElencoDoc);

      // model.addAttribute("risultatiProgetti", risultatiProgetti);
      SearchContainer<Progetto> searchContainerElencoPro =
          new SearchContainer<Progetto>(
              renderRequest,
              renderResponse.createRenderURL(),
              null,
              "Nessun dato trovato per la selezione fatta");
      searchContainerElencoPro.setDelta(risultatiProgetti.size());
      searchContainerElencoPro.setTotal(risultatiProgetti.size());
      searchContainerElencoPro.setResults(risultatiProgetti);
      model.addAttribute("searchContainerElenco", searchContainerElencoPro);

    } catch (SearchException e) {
      logger.error("SearchException: ", e);
    } catch (NumberFormatException e) {
      logger.error("NumberFormatException: ", e);
    } catch (PortalException e) {
      logger.error("PortalException: ", e);
    } catch (SystemException e) {
      logger.error("SystemException: ", e);
    }

    return "elenco-progetti-view";
  }