@Override
 public String getDate() {
   if (getUpdateDate() != null) {
     return DateUtil.date2SQLDate(getUpdateDate());
   }
   return DateUtil.date2SQLDate(getCreationDate());
 }
 /** Test of selectByNameAndNodeId method, of class PublicationDAO. */
 @Test
 public void testSelectByNameAndNodeId() throws Exception {
   IDatabaseConnection connection = getConnection();
   try {
     Connection con = connection.getConnection();
     PublicationPK pubPK = new PublicationPK("100", "kmelia200");
     String name = "Publication 1";
     int nodeId = 110;
     PublicationDetail result = PublicationDAO.selectByNameAndNodeId(con, pubPK, name, nodeId);
     assertEquals(pubPK, result.getPK());
     assertEquals("Homer Simpson", result.getAuthor());
     assertEquals("2009/10/18", DateUtil.formatDate(result.getBeginDate()));
     assertEquals("00:00", result.getBeginHour());
     assertEquals("Contenu de la publication 1", result.getContent());
     assertEquals("2008/11/18", DateUtil.formatDate(result.getCreationDate()));
     assertEquals("100", result.getCreatorId());
     assertEquals("Première publication de test", result.getDescription());
     assertEquals("2020/12/18", DateUtil.formatDate(result.getEndDate()));
     assertEquals("23:59", result.getEndHour());
     assertEquals(1, result.getImportance());
     assertEquals("0", result.getInfoId());
     assertEquals("kmelia200", result.getInstanceId());
     assertEquals("test", result.getKeywords());
     assertEquals("Publication 1", result.getName());
     assertEquals("Valid", result.getStatus());
     assertEquals("300", result.getValidatorId());
     assertEquals("Publication 1", result.getTitle());
   } finally {
     connection.close();
   }
 }
 public Period getVisibilityPeriod() {
   Date begin = getBeginDate();
   if (begin == null) {
     begin = DateUtil.MINIMUM_DATE;
   } else {
     begin = DateUtil.getDate(begin, getBeginHour());
   }
   Date end = getEndDate();
   if (end == null) {
     end = DateUtil.MAXIMUM_DATE;
   } else {
     end = DateUtil.getDate(end, getEndHour());
   }
   return Period.from(begin, end);
 }
  /**
   * SiteDetail
   *
   * @throws ParseException
   */
  public SiteDetail(
      String idSite,
      String name,
      String description,
      String page,
      int type,
      String creatorId,
      String date,
      int state,
      int popup) {
    super(
        "X",
        name,
        description,
        null,
        null,
        null,
        creatorId,
        new Integer(type).toString(),
        idSite,
        "",
        page);

    if (date != null) {
      Date theCreationDate = null;
      try {
        theCreationDate = DateUtil.parse(date);
      } catch (ParseException e) {

      }
      this.setCreationDate(theCreationDate);
    }
    init(idSite, type, state, popup);
  }
 public void setVisibilityPeriod(Period period) {
   if (period.isBeginNotDefined()) {
     setBeginDate(null);
     setBeginHour(null);
   } else {
     setBeginDate(period.getBeginDate());
     setBeginHour(DateUtil.formatTime(period.getBeginDate()));
   }
   if (period.isEndNotDefined()) {
     setEndDate(null);
     setEndHour(null);
   } else {
     setEndDate(period.getEndDate());
     setEndHour(DateUtil.formatTime(period.getEndDate()));
   }
 }
 @XmlElement
 public String getPublishedFor() {
   TimeData timeData = UnitUtil.getTimeData(DateUtil.getNow().getTime() - getDate().getTime());
   TimeUnit bestUnit = timeData.getBestUnit();
   return UnitUtil.getTimeData(
           new BigDecimal(String.valueOf(timeData.getBestValue().intValue())), bestUnit)
       .getBestDisplayValue();
 }
 protected Date parseDate(Property property) {
   String date = metadata.get(property);
   if (date != null) {
     try {
       return DateUtil.parse(date, "yyyy-MM-dd'T'HH:mm:ss'Z'");
     } catch (ParseException ex) {
       return null;
     }
   }
   return null;
 }
  public synchronized void createCategory(Category category) throws QuestionReplyException {
    try {
      category.setCreationDate(DateUtil.date2SQLDate(new Date()));
      category.setCreatorId(getUserId());
      category.getNodePK().setComponentName(getComponentId());

      getNodeBm().createNode((NodeDetail) category, new NodeDetail());
    } catch (Exception e) {
      throw new QuestionReplyException(
          "QuestionReplySessioncontroller.createCategory()",
          SilverpeasRuntimeException.ERROR,
          "QuestionReply.MSG_CATEGORIES_NOT_CREATE",
          e);
    }
  }
  /** Test of selectByFatherPK method, of class PublicationDAO. */
  @Test
  public void testSelectByFatherPK_Connection_NodePK() throws Exception {
    IDatabaseConnection connection = getConnection();
    try {
      Connection con = connection.getConnection();
      NodePK fatherPK = new NodePK("110", "kmelia200");
      Collection<PublicationDetail> result = PublicationDAO.selectByFatherPK(con, fatherPK);
      assertNotNull(result);
      assertEquals(2, result.size());
      Iterator<PublicationDetail> iter = result.iterator();
      PublicationDetail detail = iter.next();
      PublicationPK primaryKey = new PublicationPK("100", "kmelia200");
      assertEquals(primaryKey, detail.getPK());
      assertEquals("Homer Simpson", detail.getAuthor());
      assertEquals("2009/10/18", DateUtil.formatDate(detail.getBeginDate()));
      assertEquals("00:00", detail.getBeginHour());
      assertEquals("Contenu de la publication 1", detail.getContent());
      assertEquals("2008/11/18", DateUtil.formatDate(detail.getCreationDate()));
      assertEquals("100", detail.getCreatorId());
      assertEquals("Première publication de test", detail.getDescription());
      assertEquals("2020/12/18", DateUtil.formatDate(detail.getEndDate()));
      assertEquals("23:59", detail.getEndHour());
      assertEquals(1, detail.getImportance());
      assertEquals("0", detail.getInfoId());
      assertEquals("kmelia200", detail.getInstanceId());
      assertEquals("test", detail.getKeywords());
      assertEquals("Publication 1", detail.getName());
      assertEquals("Valid", detail.getStatus());
      assertEquals("300", detail.getValidatorId());
      assertEquals("Publication 1", detail.getTitle());

      detail = iter.next();
      primaryKey = new PublicationPK("101", "kmelia200");
      assertEquals(primaryKey, detail.getPK());
      assertEquals("Bart Simpson", detail.getAuthor());
      assertEquals("2009/10/18", DateUtil.formatDate(detail.getBeginDate()));
      assertEquals("01:10", detail.getBeginHour());
      assertEquals("Contenu de la publication 2", detail.getContent());
      assertEquals("2008/11/18", DateUtil.formatDate(detail.getCreationDate()));
      assertEquals("101", detail.getCreatorId());
      assertEquals("2ème publication de test", detail.getDescription());
      assertEquals("2020/12/18", DateUtil.formatDate(detail.getEndDate()));
      assertEquals("20:35", detail.getEndHour());
      assertEquals(5, detail.getImportance());
      assertEquals("0", detail.getInfoId());
      assertEquals("kmelia200", detail.getInstanceId());
      assertEquals("test", detail.getKeywords());
      assertEquals("Publication 2", detail.getName());
      assertEquals("Valid", detail.getStatus());
      assertEquals("300", detail.getValidatorId());
      assertEquals("Publication 2", detail.getTitle());
    } finally {
      connection.close();
    }
  }
 /** Test of changeInstanceId method, of class PublicationDAO. */
 @Test
 public void testChangeInstanceId() throws Exception {
   IDatabaseConnection connection = getConnection();
   try {
     Connection con = connection.getConnection();
     PublicationPK pk = new PublicationPK("100", "kmelia200");
     PublicationDetail detail = PublicationDAO.loadRow(con, pk);
     assertEquals(pk, detail.getPK());
     assertEquals("Homer Simpson", detail.getAuthor());
     assertEquals("2009/10/18", DateUtil.formatDate(detail.getBeginDate()));
     assertEquals("00:00", detail.getBeginHour());
     assertEquals("Contenu de la publication 1", detail.getContent());
     assertEquals("2008/11/18", DateUtil.formatDate(detail.getCreationDate()));
     assertEquals("100", detail.getCreatorId());
     assertEquals("Première publication de test", detail.getDescription());
     assertEquals("2020/12/18", DateUtil.formatDate(detail.getEndDate()));
     assertEquals("23:59", detail.getEndHour());
     assertEquals(1, detail.getImportance());
     assertEquals("0", detail.getInfoId());
     assertEquals("kmelia200", detail.getInstanceId());
     assertEquals("test", detail.getKeywords());
     assertEquals("Publication 1", detail.getName());
     assertEquals("Valid", detail.getStatus());
     assertEquals("300", detail.getValidatorId());
     assertEquals("Publication 1", detail.getTitle());
     String targetInstance = "kmelia" + RandomGenerator.getRandomInt(600);
     PublicationDAO.changeInstanceId(con, pk, targetInstance);
     pk = new PublicationPK("100", targetInstance);
     detail = PublicationDAO.loadRow(con, pk);
     assertEquals(pk, detail.getPK());
     assertEquals("Homer Simpson", detail.getAuthor());
     assertEquals("2009/10/18", DateUtil.formatDate(detail.getBeginDate()));
     assertEquals("00:00", detail.getBeginHour());
     assertEquals("Contenu de la publication 1", detail.getContent());
     assertEquals("2008/11/18", DateUtil.formatDate(detail.getCreationDate()));
     assertEquals("100", detail.getCreatorId());
     assertEquals("Première publication de test", detail.getDescription());
     assertEquals("2020/12/18", DateUtil.formatDate(detail.getEndDate()));
     assertEquals("23:59", detail.getEndHour());
     assertEquals(1, detail.getImportance());
     assertEquals("0", detail.getInfoId());
     assertEquals(targetInstance, detail.getInstanceId());
     assertEquals("test", detail.getKeywords());
     assertEquals("Publication 1", detail.getName());
     assertEquals("Valid", detail.getStatus());
     assertEquals("300", detail.getValidatorId());
     assertEquals("Publication 1", detail.getTitle());
   } finally {
     connection.close();
   }
 }
 @Override
 public String getSilverCreationDate() {
   return DateUtil.date2SQLDate(getCreationDate());
 }
  /**
   * Prints the HTML value of the field. The displayed value must be updatable by the end user. The
   * value format may be adapted to a local language. The fieldName must be used to name the html
   * form input. Never throws an Exception but log a silvertrace and writes an empty string when :
   *
   * <UL>
   *   <LI>the field type is not a managed type.
   * </UL>
   *
   * @param out
   * @param field
   * @param template
   * @param pageContext
   * @throws FormException
   */
  @Override
  public void display(
      PrintWriter out, TextField field, FieldTemplate template, PagesContext pageContext)
      throws FormException {
    String value = "";
    String html = "";

    String fieldName = template.getFieldName();
    SilverTrace.info(
        "form", "TimeFieldDisplayer.display", "root.MSG_GEN_PARAM_VALUE", "fieldName=" + fieldName);
    Map<String, String> parameters = template.getParameters(pageContext.getLanguage());
    if (field == null) {
      return;
    }
    if (!field.getTypeName().equals(TextField.TYPE)) {
      SilverTrace.info(
          "form", "TimeFieldDisplayer.display", "form.INFO_NOT_CORRECT_TYPE", TextField.TYPE);
    }

    String defaultParam = (parameters.containsKey("default") ? parameters.get("default") : "");
    String defaultValue = "";
    if ("now".equalsIgnoreCase(defaultParam) && !pageContext.isIgnoreDefaultValues()) {
      defaultValue = DateUtil.formatTime(new Date());
    }
    value = (!field.isNull() ? field.getValue(pageContext.getLanguage()) : defaultValue);
    if (pageContext.isBlankFieldsUse()) {
      value = "";
    }

    if (template.isReadOnly() && !template.isHidden()) {
      html = value;
    } else {
      input inputField = new input();
      inputField.setName(template.getFieldName());
      inputField.setID(template.getFieldName());
      inputField.setValue(EncodeHelper.javaStringToHtmlString(value));
      inputField.setType(template.isHidden() ? input.hidden : input.text);
      inputField.setMaxlength("5");
      inputField.setSize("10");
      if (template.isDisabled()) {
        inputField.setDisabled(true);
      } else if (template.isReadOnly()) {
        inputField.setReadOnly(true);
      }

      img image = null;
      if (template.isMandatory()
          && !template.isDisabled()
          && !template.isReadOnly()
          && !template.isHidden()
          && pageContext.useMandatory()) {
        image = new img();
        image.setSrc(Util.getIcon("mandatoryField"));
        image.setWidth(5);
        image.setHeight(5);
        image.setBorder(0);
      }

      // print field
      if (image != null) {
        ElementContainer container = new ElementContainer();
        container.addElement(inputField);
        container.addElement("&nbsp;");
        container.addElement(image);
        out.println(container.toString());
      } else {
        out.println(inputField.toString());
      }
    }
    out.println(html);
  }
  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);
      }
    }
  }
  @Test
  public void testGetAllPublicationsIDbyUserid() throws Exception {

    IDatabaseConnection connection = getConnection();
    try {
      Connection con = connection.getConnection();

      String user100 = "100"; // who created  pub1

      String user200 = "200"; // who updated pub1 and pub2
      String pub1Id = "100";

      PublicationDetail detail1 = PublicationDAO.loadRow(con, new PublicationPK(pub1Id));

      // who created  pub1
      SocialInformationPublication sp1 =
          new SocialInformationPublication(new PublicationWithStatus((detail1), false));
      assertNotNull("SocialInformationPublication1 must be not null", sp1);
      List<SocialInformation> list100 = new ArrayList<SocialInformation>();
      list100.add(sp1);

      Date begin = DateUtil.parse("2008/11/01");
      Date end = DateUtil.parse("2008/11/30");

      List<SocialInformation> list100DOA =
          PublicationDAO.getAllPublicationsIDbyUserid(con, user100, begin, end);
      assertEquals("Must be equal", list100.get(0), list100DOA.get(0));

      // who created pub2
      String user101 = "101"; // who created pub2
      String pub2Id = "101";
      PublicationDetail detail2 = PublicationDAO.loadRow(con, new PublicationPK(pub2Id));
      SocialInformationPublication sp2 =
          new SocialInformationPublication(new PublicationWithStatus((detail2), false));
      assertNotNull("SocialInformationPublication2 must be not null", sp2);

      List<SocialInformation> list101 = new ArrayList<SocialInformation>();
      list101.add(sp2);
      List<SocialInformation> list101DOA =
          PublicationDAO.getAllPublicationsIDbyUserid(con, user101, begin, end);
      assertTrue("Must be equal", list101.get(0).equals(list101DOA.get(0)));

      // who updated pub1 and pub2
      begin = DateUtil.parse("2009/11/01");
      end = DateUtil.parse("2009/11/30");
      SocialInformationPublication sp1User200 =
          new SocialInformationPublication(new PublicationWithStatus((detail1), true));
      assertNotNull("SocialInformationPublication2 must be not null", sp1User200);
      SocialInformationPublication sp2User200 =
          new SocialInformationPublication(new PublicationWithStatus((detail2), true));
      assertNotNull("SocialInformationPublication2 must be not null", sp2User200);
      List<SocialInformation> list200 = new ArrayList<SocialInformation>();
      list200.add(sp2User200);
      list200.add(sp1User200);
      List<SocialInformation> list200DOA =
          PublicationDAO.getAllPublicationsIDbyUserid(con, user200, begin, end);
      assertEquals("Must be equal", list200.get(0), list200DOA.get(0));
      assertEquals("Must be equal", list200.get(1), list200DOA.get(1));

      // test nbr of elements
      list200DOA = PublicationDAO.getAllPublicationsIDbyUserid(con, user200, begin, end);
      assertEquals("Must be equal", list200.get(0), list200DOA.get(0));
      List<String> options = new ArrayList<String>();
      options.add("kmelia200");
      List<String> myContactsIds = new ArrayList<String>();
      myContactsIds.add(user100);
      myContactsIds.add(user200);
      list200DOA =
          PublicationDAO.getSocialInformationsListOfMyContacts(
              con, myContactsIds, options, begin, end);
      assertNotNull("SocialInformationPublication of my contact must be not null", list200DOA);
      assertTrue(
          "SocialInformationPublication of my contact must be not empty", !list200DOA.isEmpty());
    } finally {
      connection.close();
    }
  }
  /** prepareStatementSetProperties */
  private int prepareStatementSetProperties(PreparedStatement prepStmt, T bean)
      throws IllegalAccessException, SQLException, InvocationTargetException {
    int count = 1;

    for (PropertyDescriptor property : properties) {
      String type = property.getPropertyType().getName();
      if (isInteger(type)) {
        Integer integer = (Integer) property.getReadMethod().invoke(bean);
        if (integer == null) {
          prepStmt.setInt(count, -1);
        } else {
          prepStmt.setInt(count, integer);
        }
        count++;
      } else if (isLong(type)) {
        Long l = (Long) property.getReadMethod().invoke(bean);
        if (l == null) {
          prepStmt.setLong(count, 0);
        } else {
          prepStmt.setLong(count, l);
        }
        count++;
      } else if (isBoolean(type)) {
        Boolean l = (Boolean) property.getReadMethod().invoke(bean);
        if (l == null) {
          prepStmt.setBoolean(count, false);
        } else {
          prepStmt.setBoolean(count, l);
        }
        count++;
      } else if (isString(type)) {
        String string = (String) property.getReadMethod().invoke(bean);
        if (string == null) {
          prepStmt.setNull(count, Types.VARCHAR);
        } else {
          prepStmt.setString(count, string);
        }
        count++;
      } else if (isDate(type)) {
        Date date = (Date) property.getReadMethod().invoke(bean);
        if (date == null) {
          prepStmt.setNull(count, Types.VARCHAR);
        } else {
          prepStmt.setString(count, DateUtil.date2SQLDate(date));
        }
        count++;
      } else if (isFloat(type)) {
        Float f = (Float) property.getReadMethod().invoke(bean);
        if (f == null) {
          prepStmt.setFloat(count, 0);
        } else {
          prepStmt.setFloat(count, f);
        }
        count++;
      } else if (isDouble(type)) {
        Double d = (Double) property.getReadMethod().invoke(bean);
        if (d == null) {
          prepStmt.setDouble(count, 0);
        } else {
          prepStmt.setDouble(count, d);
        }
        count++;
      } else {
        SilverTrace.debug(
            "persistence",
            "SilverpeasBeanDAO.prepareStatementSetProperties",
            "persistence.MSG_WARN_PROPERTIE_NOT_MANAGED",
            type);
      }
    }
    return count;
  }
 /** Return the creation time of the indexed document. */
 public String getCreationDate() {
   if (creationDate != null) {
     return creationDate;
   }
   return DateUtil.date2SQLDate(new Date());
 }
 @XmlElement
 public String getPublishTime() {
   return DateUtil.formatTime(getDate());
 }
 @Override
 public String toString(Object o) {
   return DateUtil.formatDate((Date) o);
 }
  /** Test of selectByFatherPK method, of class PublicationDAO. */
  @Test
  public void testSelectByFatherPK_5args() throws Exception {
    IDatabaseConnection connection = getConnection();
    try {
      Connection con = connection.getConnection();
      NodePK fatherPK = new NodePK("110", "kmelia200");
      String sorting = null;
      boolean filterOnVisibilityPeriod = false;
      String userId = "100";
      Collection<PublicationDetail> result =
          PublicationDAO.selectByFatherPK(con, fatherPK, sorting, filterOnVisibilityPeriod, userId);
      assertNotNull(result);
      assertEquals(1, result.size());
      Iterator<PublicationDetail> iter = result.iterator();
      PublicationDetail detail = iter.next();
      PublicationPK primaryKey = new PublicationPK("100", "kmelia200");
      assertEquals(primaryKey, detail.getPK());
      assertEquals("Homer Simpson", detail.getAuthor());
      assertEquals("2009/10/18", DateUtil.formatDate(detail.getBeginDate()));
      assertEquals("00:00", detail.getBeginHour());
      assertEquals("Contenu de la publication 1", detail.getContent());
      assertEquals("2008/11/18", DateUtil.formatDate(detail.getCreationDate()));
      assertEquals("100", detail.getCreatorId());
      assertEquals("Première publication de test", detail.getDescription());
      assertEquals("2020/12/18", DateUtil.formatDate(detail.getEndDate()));
      assertEquals("23:59", detail.getEndHour());
      assertEquals(1, detail.getImportance());
      assertEquals("0", detail.getInfoId());
      assertEquals("kmelia200", detail.getInstanceId());
      assertEquals("test", detail.getKeywords());
      assertEquals("Publication 1", detail.getName());
      assertEquals("Valid", detail.getStatus());
      assertEquals("300", detail.getValidatorId());
      assertEquals("Publication 1", detail.getTitle());

      filterOnVisibilityPeriod = true;
      result =
          PublicationDAO.selectByFatherPK(con, fatherPK, sorting, filterOnVisibilityPeriod, userId);
      assertNotNull(result);
      assertEquals(1, result.size());
      iter = result.iterator();
      detail = iter.next();
      primaryKey = new PublicationPK("100", "kmelia200");
      assertEquals(primaryKey, detail.getPK());
      assertEquals("Homer Simpson", detail.getAuthor());
      assertEquals("2009/10/18", DateUtil.formatDate(detail.getBeginDate()));
      assertEquals("00:00", detail.getBeginHour());
      assertEquals("Contenu de la publication 1", detail.getContent());
      assertEquals("2008/11/18", DateUtil.formatDate(detail.getCreationDate()));
      assertEquals("100", detail.getCreatorId());
      assertEquals("Première publication de test", detail.getDescription());
      assertEquals("2020/12/18", DateUtil.formatDate(detail.getEndDate()));
      assertEquals("23:59", detail.getEndHour());
      assertEquals(1, detail.getImportance());
      assertEquals("0", detail.getInfoId());
      assertEquals("kmelia200", detail.getInstanceId());
      assertEquals("test", detail.getKeywords());
      assertEquals("Publication 1", detail.getName());
      assertEquals("Valid", detail.getStatus());
      assertEquals("300", detail.getValidatorId());
      assertEquals("Publication 1", detail.getTitle());
    } finally {
      connection.close();
    }
  }
 @Override
 public String toString(Object o, String formatName) {
   return DateUtil.formatDate((Date) o, formatName);
 }
 @XmlElement
 public int getPublishedForNbDays() {
   return UnitUtil.getTimeData(DateUtil.getNow().getTime() - getDate().getTime())
       .getTimeConverted(TimeUnit.DAY)
       .intValue();
 }
 /** Test of storeRow method, of class PublicationDAO. */
 @Test
 public void testStoreRow() throws Exception {
   IDatabaseConnection connection = getConnection();
   try {
     Connection con = connection.getConnection();
     PublicationPK pk = new PublicationPK("100", "kmelia200");
     PublicationDetail detail = PublicationDAO.loadRow(con, pk);
     assertEquals(pk, detail.getPK());
     assertEquals("Homer Simpson", detail.getAuthor());
     assertEquals("2009/10/18", DateUtil.formatDate(detail.getBeginDate()));
     assertEquals("00:00", detail.getBeginHour());
     assertEquals("Contenu de la publication 1", detail.getContent());
     assertEquals("2008/11/18", DateUtil.formatDate(detail.getCreationDate()));
     assertEquals("100", detail.getCreatorId());
     assertEquals("Première publication de test", detail.getDescription());
     assertEquals("2020/12/18", DateUtil.formatDate(detail.getEndDate()));
     assertEquals("23:59", detail.getEndHour());
     assertEquals(1, detail.getImportance());
     assertEquals("0", detail.getInfoId());
     assertEquals("kmelia200", detail.getInstanceId());
     assertEquals("test", detail.getKeywords());
     assertEquals("Publication 1", detail.getName());
     assertEquals("Valid", detail.getStatus());
     assertEquals("300", detail.getValidatorId());
     assertEquals("Publication 1", detail.getTitle());
     Calendar now = Calendar.getInstance();
     now.set(Calendar.SECOND, 0);
     now.set(Calendar.MILLISECOND, 0);
     now.set(Calendar.MINUTE, 0);
     now.set(Calendar.HOUR_OF_DAY, 0);
     Calendar beginDate = RandomGenerator.getCalendarAfter(now);
     Calendar endDate = RandomGenerator.getCalendarAfter(beginDate);
     String name = RandomGenerator.getRandomString();
     String description = RandomGenerator.getRandomString();
     String creatorId = "" + RandomGenerator.getRandomInt();
     int importance = RandomGenerator.getRandomInt(5);
     String version = RandomGenerator.getRandomString();
     String contenu = RandomGenerator.getRandomString();
     StringBuilder buffer = new StringBuilder();
     int nbKeywords = RandomGenerator.getRandomInt(5) + 2;
     for (int i = 0; i < nbKeywords; i++) {
       buffer.append(RandomGenerator.getRandomString());
       if (i < (nbKeywords - 1)) {
         buffer.append(' ');
       }
     }
     String keywords = buffer.toString();
     detail.setName(name);
     detail.setDescription(description);
     detail.setCreationDate(now.getTime());
     detail.setBeginDateAndHour(beginDate.getTime());
     detail.setEndDateAndHour(endDate.getTime());
     detail.setCreatorId(creatorId);
     detail.setImportance(importance);
     detail.setVersion(version);
     detail.setKeywords(keywords);
     detail.setContent(contenu);
     detail.setBeginHour(DateUtil.formatTime(beginDate));
     detail.setEndHour(DateUtil.formatTime(endDate));
     PublicationDAO.storeRow(con, detail);
     PublicationDetail result = PublicationDAO.loadRow(con, pk);
     detail.setUpdateDate(now.getTime());
     detail.setUpdaterId(creatorId);
     detail.setInfoId("0");
     assertEquals(detail.getPK(), result.getPK());
     assertEquals(detail.getAuthor(), result.getAuthor());
     assertEquals(detail.getBeginDate(), result.getBeginDate());
     assertEquals(detail.getBeginHour(), result.getBeginHour());
     assertEquals(detail.getContent(), result.getContent());
     assertEquals(detail.getCreationDate(), result.getCreationDate());
     assertEquals(detail.getUpdateDate(), result.getCreationDate());
     assertEquals(detail.getCreatorId(), result.getCreatorId());
     assertEquals(detail.getDescription(), result.getDescription());
     assertEquals(detail.getEndDate(), result.getEndDate());
     assertEquals(detail.getEndHour(), result.getEndHour());
     assertEquals(detail.getImportance(), result.getImportance());
     assertEquals(detail.getInfoId(), result.getInfoId());
     assertEquals(detail.getInstanceId(), result.getInstanceId());
     assertEquals(detail.getKeywords(), result.getKeywords());
     assertEquals(detail.getName(), result.getName());
     assertEquals(detail.getStatus(), result.getStatus());
     assertEquals(detail.getTitle(), result.getTitle());
   } finally {
     connection.close();
   }
 }
 /** Set the creation time of the indexed document. */
 public void setCreationDate(Date creationDate) {
   this.creationDate = DateUtil.date2SQLDate(creationDate);
 }
 /** Test of insertRow method, of class PublicationDAO. */
 @Test
 public void testInsertRow() throws Exception {
   IDatabaseConnection connection = getConnection();
   try {
     Connection con = connection.getConnection();
     PublicationPK pk = new PublicationPK("500", "kmelia36");
     Calendar now = Calendar.getInstance();
     now.set(Calendar.SECOND, 0);
     now.set(Calendar.MILLISECOND, 0);
     now.set(Calendar.MINUTE, 0);
     now.set(Calendar.HOUR_OF_DAY, 0);
     Calendar beginDate = RandomGenerator.getCalendarAfter(now);
     Calendar endDate = RandomGenerator.getCalendarAfter(beginDate);
     String name = RandomGenerator.getRandomString();
     String description = RandomGenerator.getRandomString();
     String creatorId = "" + RandomGenerator.getRandomInt();
     int importance = RandomGenerator.getRandomInt(5);
     String version = RandomGenerator.getRandomString();
     String contenu = RandomGenerator.getRandomString();
     StringBuilder buffer = new StringBuilder();
     int nbKeywords = RandomGenerator.getRandomInt(5) + 2;
     for (int i = 0; i < nbKeywords; i++) {
       buffer.append(RandomGenerator.getRandomString());
       if (i < (nbKeywords - 1)) {
         buffer.append(' ');
       }
     }
     String keywords = buffer.toString();
     PublicationDetail detail =
         new PublicationDetail(
             pk,
             name,
             description,
             now.getTime(),
             beginDate.getTime(),
             endDate.getTime(),
             creatorId,
             importance,
             version,
             keywords,
             contenu);
     detail.setBeginHour(DateUtil.formatTime(beginDate));
     detail.setEndHour(DateUtil.formatTime(endDate));
     PublicationDAO.insertRow(con, detail);
     PublicationDetail result = PublicationDAO.loadRow(con, pk);
     detail.setUpdateDate(now.getTime());
     detail.setUpdaterId(creatorId);
     detail.setInfoId("0");
     assertEquals(detail.getPK(), result.getPK());
     assertEquals(detail.getAuthor(), result.getAuthor());
     assertEquals(detail.getBeginDate(), result.getBeginDate());
     assertEquals(detail.getBeginHour(), result.getBeginHour());
     assertEquals(detail.getContent(), result.getContent());
     assertEquals(detail.getCreationDate(), result.getCreationDate());
     assertEquals(detail.getUpdateDate(), result.getCreationDate());
     assertEquals(detail.getCreatorId(), result.getCreatorId());
     assertEquals(detail.getDescription(), result.getDescription());
     assertEquals(detail.getEndDate(), result.getEndDate());
     assertEquals(detail.getEndHour(), result.getEndHour());
     assertEquals(detail.getImportance(), result.getImportance());
     assertEquals(detail.getInfoId(), result.getInfoId());
     assertEquals(detail.getInstanceId(), result.getInstanceId());
     assertEquals(detail.getKeywords(), result.getKeywords());
     assertEquals(detail.getName(), result.getName());
     assertEquals(detail.getStatus(), result.getStatus());
     assertEquals(detail.getTitle(), result.getTitle());
   } finally {
     connection.close();
   }
 }
 public void setLastModificationDate(Date lastModificationDate) {
   this.lastModificationDate = DateUtil.date2SQLDate(lastModificationDate);
 }
  /** getSilverpeasBeanFromResultSet */
  private T getSilverpeasBeanFromResultSet(WAPrimaryKey pk, ResultSet rs) throws Exception {

    T bean = silverpeasBeanClass.newInstance();
    int count = 1;

    for (PropertyDescriptor property : properties) {
      String type = property.getPropertyType().getName();
      if (isInteger(type)) {
        int value = rs.getInt(count);
        if (!rs.wasNull()) {
          Object[] parameters = new Integer[] {value};
          property.getWriteMethod().invoke(bean, parameters);
        }
        count++;
      } else if (isLong(type)) {
        long value = rs.getLong(count);
        if (!rs.wasNull()) {
          Object[] parameters = new Long[] {value};
          property.getWriteMethod().invoke(bean, parameters);
        }
        count++;
      } else if (isBoolean(type)) {
        boolean value = rs.getBoolean(count);
        if (!rs.wasNull()) {
          Object[] parameters = new Boolean[] {value};
          property.getWriteMethod().invoke(bean, parameters);
        }
        count++;
      } else if (isString(type)) {
        String value = rs.getString(count);
        if (value != null) {
          Object[] parameters = new String[1];
          parameters[0] = value;
          property.getWriteMethod().invoke(bean, parameters);
        }
        count++;
      } else if (isDate(type)) {
        String value = rs.getString(count);
        if (value != null) {
          Object[] parameters = new Date[1];
          try {
            parameters[0] = DateUtil.parse(value);
          } catch (Exception e) {
            SilverTrace.error(
                "persistence",
                "SilverpeasBeanDAOImpl.getSilverpeasBeanFromResultSet(WAPrimaryKey pk, ResultSet rs)",
                "root.EX_CANT_PARSE_DATE",
                "property Name = " + property.getName() + ", date= " + value);
            throw e;
          }
          property.getWriteMethod().invoke(bean, parameters);
        }
        count++;
      } else if (isFloat(type)) {
        float value = rs.getFloat(count);
        if (!rs.wasNull()) {
          Object[] parameters = new Float[] {value};
          property.getWriteMethod().invoke(bean, parameters);
        }
        count++;
      } else if ((type.equals("double")) || (type.equals("java.lang.Double"))) {
        double value = rs.getDouble(count);
        if (!rs.wasNull()) {
          Object[] parameters = new Double[] {value};
          property.getWriteMethod().invoke(bean, parameters);
        }
        count++;
      }
    }

    Class<? extends WAPrimaryKey> pkClass = pk.getClass();
    String id = rs.getInt(count) + "";
    Class<?> types[] = new Class[2];
    types[0] = String.class;
    types[1] = WAPrimaryKey.class; // pkClass;
    Constructor<? extends WAPrimaryKey> construct = pkClass.getConstructor(types);
    Object[] parameters = new Object[2];
    parameters[0] = id;
    parameters[1] = pk;
    WAPrimaryKey maPk = construct.newInstance(parameters);
    bean.setPK(maPk);
    return bean;
  }