/**
   * 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);
  }
Example #2
0
 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;
 }
  @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();
    }
  }
  /** 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;
  }