Example #1
0
 protected Ticket(
     int sharedObjectId,
     String componentId,
     UserDetail creator,
     Date creationDate,
     Date endDate,
     int nbAccessMax) {
   this(sharedObjectId, componentId, creator.getId(), creationDate, endDate, nbAccessMax);
 }
 /*
  * Retourne true si la liste contient deja le user
  */
 private boolean exist(UserDetail user, Collection<UserDetail> listUser) {
   int i = 0;
   List<UserDetail> arrayUser = new ArrayList<UserDetail>(listUser);
   if (user != null) {
     String idUser = user.getId();
     while (i < arrayUser.size()) {
       UserDetail theUser = arrayUser.get(i);
       String theId = theUser.getId();
       if (theId.equals(idUser)) {
         return true;
       }
       i++;
     }
   } else {
     return true;
   }
   return false;
 }
 /**
  * Is the specified user can access this publication?
  *
  * <p>A user can access a publication if he has enough rights to access both the application
  * instance in which is managed this publication and one of the nodes to which this publication
  * belongs to.
  *
  * @param user a user in Silverpeas.
  * @return true if the user can access this publication, false otherwise.
  */
 @Override
 public boolean canBeAccessedBy(final UserDetail user) {
   AccessController<String> accessController =
       AccessControllerProvider.getAccessController("componentAccessController");
   boolean canBeAccessed =
       accessController.isUserAuthorized(user.getId(), getComponentInstanceId());
   if (canBeAccessed) {
     AccessController<NodePK> nodeAccessController =
         AccessControllerProvider.getAccessController("nodeAccessController");
     Collection<NodePK> nodes =
         getPublicationBm().getAllFatherPK(new PublicationPK(getId(), getInstanceId()));
     for (NodePK aNode : nodes) {
       canBeAccessed = nodeAccessController.isUserAuthorized(user.getId(), aNode);
       if (canBeAccessed) {
         break;
       }
     }
   }
   return canBeAccessed;
 }
  /*
   * Récupère la liste des experts du domaine de la question qui ne sont pas déjà destinataires
   */
  public Collection<UserDetail> getCurrentQuestionAvailableWriters() throws QuestionReplyException {
    Collection<UserDetail> users = getCurrentQuestionWriters();
    Collection<UserDetail> availableUsers = new ArrayList<UserDetail>();
    Collection<Recipient> recipients = getCurrentQuestion().readRecipients();

    for (UserDetail user : users) {
      boolean isRecipient = false;
      for (Recipient recipient : recipients) {
        if (user.getId().equals(recipient.getUserId())) {
          isRecipient = true;
        }
      }
      if (!isRecipient) {
        availableUsers.add(user);
      }
    }
    return availableUsers;
  }
  private void processMailContent(
      PublicationDetail pubDetail,
      File file,
      ImportReportManager reportManager,
      UnitReport unitReport,
      GEDImportExport gedIE,
      boolean isVersioningUsed)
      throws ImportExportException {

    String componentId = gedIE.getCurrentComponentId();
    UserDetail userDetail = gedIE.getCurentUserDetail();
    MailExtractor extractor = null;
    Mail mail = null;
    try {
      extractor = Extractor.getExtractor(file);
      mail = extractor.getMail();
    } catch (Exception e) {
      SilverTrace.error(
          "importExport",
          "RepositoriesTypeManager.processMailContent",
          "importExport.EX_CANT_EXTRACT_MAIL_DATA",
          e);
    }
    if (mail != null) {
      // save mail data into dedicated form
      String content = mail.getBody();
      PublicationContentType pubContent = new PublicationContentType();
      XMLModelContentType modelContent = new XMLModelContentType("mail");
      pubContent.setXMLModelContentType(modelContent);
      List<XMLField> fields = new ArrayList<XMLField>();
      modelContent.setFields(fields);

      XMLField subject = new XMLField("subject", mail.getSubject());
      fields.add(subject);

      XMLField body = new XMLField("body", ESCAPE_ISO8859_1.translate(content));
      fields.add(body);

      XMLField date = new XMLField("date", DateUtil.getOutputDateAndHour(mail.getDate(), "fr"));
      fields.add(date);

      InternetAddress address = mail.getFrom();
      String from = "";
      if (StringUtil.isDefined(address.getPersonal())) {
        from += address.getPersonal() + " - ";
      }
      from += "<a href=\"mailto:" + address.getAddress() + "\">" + address.getAddress() + "</a>";
      XMLField fieldFROM = new XMLField("from", from);
      fields.add(fieldFROM);

      Address[] recipients = mail.getAllRecipients();
      String to = "";
      for (Address recipient : recipients) {
        InternetAddress ia = (InternetAddress) recipient;
        if (StringUtil.isDefined(ia.getPersonal())) {
          to += ia.getPersonal() + " - ";
        }
        to += "<a href=\"mailto:" + ia.getAddress() + "\">" + ia.getAddress() + "</a></br>";
      }
      XMLField fieldTO = new XMLField("to", to);
      fields.add(fieldTO);

      // save form
      gedIE.createPublicationContent(
          reportManager,
          unitReport,
          Integer.parseInt(pubDetail.getPK().getId()),
          pubContent,
          userDetail.getId(),
          null);

      // extract each file from mail...
      try {
        List<AttachmentDetail> documents = new ArrayList<AttachmentDetail>();

        List<MailAttachment> attachments = extractor.getAttachments();
        for (MailAttachment attachment : attachments) {
          if (attachment != null) {
            AttachmentDetail attDetail = new AttachmentDetail();
            AttachmentPK pk = new AttachmentPK("unknown", "useless", componentId);
            attDetail.setLogicalName(attachment.getName());
            attDetail.setPhysicalName(attachment.getPath());
            attDetail.setAuthor(userDetail.getId());
            attDetail.setSize(attachment.getSize());
            attDetail.setPK(pk);

            documents.add(attDetail);
          }
        }

        // ... and save it
        if (isVersioningUsed) {
          // versioning mode
          VersioningImportExport versioningIE = new VersioningImportExport(userDetail);
          versioningIE.importDocuments(
              pubDetail.getPK().getId(),
              componentId,
              documents,
              Integer.parseInt(userDetail.getId()),
              pubDetail.isIndexable());
        } else {
          // classic mode
          AttachmentImportExport attachmentIE = new AttachmentImportExport();
          attachmentIE.importAttachments(
              pubDetail.getPK().getId(),
              componentId,
              documents,
              userDetail.getId(),
              pubDetail.isIndexable());
        }
      } catch (Exception e) {
        SilverTrace.error(
            "importExport", "RepositoriesTypeManager.processMailContent", "root.EX_NO_MESSAGE", e);
      }
    }
  }
  private PublicationDetail importFile(
      File file,
      ImportReportManager reportManager,
      MassiveReport massiveReport,
      GEDImportExport gedIE,
      PdcImportExport pdcIE,
      ImportSettings settings) {
    SilverTrace.debug(
        "importExport",
        "RepositoriesTypeManager.importFile",
        "root.MSG_GEN_ENTER_METHOD",
        "file = " + file.getName());
    String componentId = gedIE.getCurrentComponentId();
    UserDetail userDetail = gedIE.getCurentUserDetail();
    PublicationDetail pubDetailToCreate = null;
    try {
      // Création du rapport unitaire
      UnitReport unitReport = new UnitReport();
      massiveReport.addUnitReport(unitReport);

      // Check the file size
      ResourceLocator uploadSettings =
          new ResourceLocator("org.silverpeas.util.uploads.uploadSettings", "");
      long maximumFileSize = uploadSettings.getLong("MaximumFileSize", 10485760);
      long fileSize = file.length();
      if (fileSize <= 0L) {
        unitReport.setError(UnitReport.ERROR_NOT_EXISTS_OR_INACCESSIBLE_FILE);
        reportManager.addNumberOfFilesNotImported(1);
        return pubDetailToCreate;
      } else if (fileSize > maximumFileSize) {
        unitReport.setError(UnitReport.ERROR_FILE_SIZE_EXCEEDS_LIMIT);
        reportManager.addNumberOfFilesNotImported(1);
        return pubDetailToCreate;
      }

      // On récupére les infos nécéssaires à la création de la publication
      pubDetailToCreate =
          PublicationImportExport.convertFileInfoToPublicationDetail(file, settings);
      pubDetailToCreate.setPk(new PublicationPK("unknown", "useless", componentId));
      if ((settings.isDraftUsed() && pdcIE.isClassifyingMandatory(componentId))
          || settings.isDraftUsed()) {
        pubDetailToCreate.setStatus(PublicationDetail.DRAFT);
        pubDetailToCreate.setStatusMustBeChecked(false);
      }
      SilverTrace.debug(
          "importExport",
          "RepositoriesTypeManager.importFile",
          "root.MSG_GEN_PARAM_VALUE",
          "pubDetailToCreate.status = " + pubDetailToCreate.getStatus());

      // Création de la publication
      pubDetailToCreate =
          gedIE.createPublicationForMassiveImport(unitReport, pubDetailToCreate, settings);
      unitReport.setLabel(pubDetailToCreate.getPK().getId());

      SilverTrace.debug(
          "importExport",
          "RepositoriesTypeManager.importFile",
          "root.MSG_GEN_PARAM_VALUE",
          "pubDetailToCreate created");

      if (FileUtil.isMail(file.getName())) {
        // if imported file is an e-mail, its textual content is saved in a dedicated form
        // and attached files are attached to newly created publication
        processMailContent(
            pubDetailToCreate, file, reportManager, unitReport, gedIE, settings.isVersioningUsed());
      }

      // add attachment
      SimpleDocument document;
      SimpleDocumentPK pk = new SimpleDocumentPK(null, componentId);
      if (settings.isVersioningUsed()) {
        document = new HistorisedDocument();
        document.setPublicDocument(
            settings.getVersionType() == DocumentVersion.TYPE_PUBLIC_VERSION);
      } else {
        document = new SimpleDocument();
      }
      document.setPK(pk);
      document.setFile(new SimpleAttachment());
      document.setFilename(file.getName());
      document.setSize(fileSize);
      document.getFile().setCreatedBy(userDetail.getId());
      if (settings.useFileDates()) {
        document.setCreated(pubDetailToCreate.getCreationDate());
        if (pubDetailToCreate.getUpdateDate() != null) {
          document.setUpdated(pubDetailToCreate.getUpdateDate());
        }
      } else {
        document.setCreated(new Date());
      }
      document.setForeignId(pubDetailToCreate.getPK().getId());
      document.setContentType(FileUtil.getMimeType(file.getName()));
      AttachmentServiceFactory.getAttachmentService()
          .createAttachment(document, file, pubDetailToCreate.isIndexable(), false);
      reportManager.addNumberOfFilesProcessed(1);
      reportManager.addImportedFileSize(document.getSize(), componentId);
    } catch (Exception ex) {
      massiveReport.setError(UnitReport.ERROR_ERROR);
      SilverTrace.error(
          "importExport", "RepositoriesTypeManager.importFile", "root.EX_NO_MESSAGE", ex);
    }
    return pubDetailToCreate;
  }
Example #7
0
 public void setLastModifier(UserDetail modifier) {
   this.updaterId = modifier.getId();
 }
Example #8
0
 public void setCreator(final UserDetail creator) {
   this.creatorId = creator.getId();
 }