private void compareActionRecords(ActionLogRecord expected, ActionLogRecord received) {
   assertEquals(expected.getId(), received.getId());
   assertEquals(expected.getUsername(), received.getUsername());
   assertEquals(expected.getActionName(), received.getActionName());
   assertEquals(expected.getNamespace(), received.getNamespace());
   assertEquals(expected.getParameters(), received.getParameters());
   assertEquals(
       DateConverter.getFormattedDate(expected.getActionDate(), "ddMMyyyyHHmm"),
       DateConverter.getFormattedDate(received.getActionDate(), "ddMMyyyyHHmm"));
 }
 public List<AttributeFieldError> validate(
     AttributeInterface attribute, AttributeTracer tracer, ILangManager langManager) {
   List<AttributeFieldError> errors = super.validate(attribute, tracer, langManager);
   if (this.isEmpty()) return errors;
   try {
     Date attributeValue = ((DateAttribute) attribute).getDate();
     if (null == attributeValue) return errors;
     Date startValue =
         (this.getRangeStart() != null)
             ? (Date) this.getRangeStart()
             : this.getOtherAttributeValue(attribute, this.getRangeStartAttribute());
     if (null != startValue && attributeValue.before(startValue)) {
       AttributeFieldError error =
           new AttributeFieldError(attribute, FieldError.LESS_THAN_ALLOWED, tracer);
       String allowedDate = DateConverter.getFormattedDate(startValue, DATE_PATTERN);
       error.setMessage("Date less than " + allowedDate);
       errors.add(error);
     }
     Date endValue =
         (this.getRangeEnd() != null)
             ? (Date) this.getRangeEnd()
             : this.getOtherAttributeValue(attribute, this.getRangeEndAttribute());
     if (null != endValue && attributeValue.after(endValue)) {
       AttributeFieldError error =
           new AttributeFieldError(attribute, FieldError.GREATER_THAN_ALLOWED, tracer);
       String allowedDate = DateConverter.getFormattedDate(endValue, DATE_PATTERN);
       error.setMessage("Date greater than " + allowedDate);
       errors.add(error);
     }
     Date value =
         (this.getValue() != null)
             ? (Date) this.getValue()
             : this.getOtherAttributeValue(attribute, this.getValueAttribute());
     if (null != value && !attributeValue.equals(value)) {
       AttributeFieldError error =
           new AttributeFieldError(attribute, FieldError.NOT_EQUALS_THAN_ALLOWED, tracer);
       String allowedDate = DateConverter.getFormattedDate(value, DATE_PATTERN);
       error.setMessage("Date not equals than " + allowedDate);
       errors.add(error);
     }
   } catch (Throwable t) {
     ApsSystemUtils.logThrowable(
         t, this, "validate", "Error validating Attribute '" + attribute.getName() + "'");
     throw new RuntimeException("Error validating Attribute '" + attribute.getName() + "'", t);
   }
   return errors;
 }
 protected void extractValidationRules(Element validationElement) {
   super.extractValidationRules(validationElement);
   Element valueElement = validationElement.getChild("value");
   if (null != valueElement) {
     this.setValue(DateConverter.parseDate(valueElement.getText(), DATE_PATTERN));
     this.setValueAttribute(valueElement.getAttributeValue("attribute"));
   }
   Element rangeStartElement = validationElement.getChild("rangestart");
   if (null != rangeStartElement) {
     this.setRangeStart(DateConverter.parseDate(rangeStartElement.getText(), DATE_PATTERN));
     this.setRangeStartAttribute(rangeStartElement.getAttributeValue("attribute"));
   }
   Element rangeEndElement = validationElement.getChild("rangeend");
   if (null != rangeEndElement) {
     this.setRangeEnd(DateConverter.parseDate(rangeEndElement.getText(), DATE_PATTERN));
     this.setRangeEndAttribute(rangeEndElement.getAttributeValue("attribute"));
   }
 }
Exemplo n.º 4
0
 /**
  * Costruttore dello scheduler
  *
  * @param task Task da eseguire.
  * @param start Data di partenza dello scheduler
  * @param delay Intervallo di schedulazione in millisecondi
  */
 public Scheduler(Task task, Date start, long delay) {
   this._timer = new Timer();
   this._task = task;
   this._timer.schedule(this, start, delay);
   ApsSystemUtils.getLogger()
       .trace(
           "jpcontentworkflow: Scheduler - StartTime: "
               + DateConverter.getFormattedDate(start, "dd/MM/yyyy HH:mm:ss")
               + " - Delay: "
               + delay);
 }
 /** Generated random token */
 protected String createToken(String word) throws NoSuchAlgorithmException {
   Random random = new Random();
   StringBuffer salt = new StringBuffer();
   long rndLong = random.nextLong();
   salt.append(rndLong);
   String date = DateConverter.getFormattedDate(new Date(), "SSSmmyyyy-SSS-MM:ssddmmHHmmEEE");
   salt.append(date);
   rndLong = random.nextLong();
   salt.append(rndLong);
   // genero il token in base a username e salt
   String token = ShaEncoder.encodeWord(word, salt.toString());
   return token;
 }
 private String toStringValue(Object value) {
   if (null == value) return null;
   Date date = null;
   if (value instanceof XMLGregorianCalendar) {
     XMLGregorianCalendar grCal = (XMLGregorianCalendar) value;
     Calendar calendar = Calendar.getInstance();
     calendar.set(Calendar.DAY_OF_MONTH, grCal.getDay());
     calendar.set(Calendar.MONTH, grCal.getMonth() - 1);
     calendar.set(Calendar.YEAR, grCal.getYear());
     date = calendar.getTime();
   } else if (value instanceof Date) {
     date = (Date) value;
   }
   if (null != date) {
     return DateConverter.getFormattedDate(date, DATE_PATTERN);
   }
   return null;
 }
 private void deleteStatsRecord() throws ApsSystemException {
   String today = DateConverter.getFormattedDate(new Date(), "dd/MM/yyyy");
   Calendar start = CalendarConverter.getCalendarDay(today, 0, 0, 0, 0);
   Calendar end = CalendarConverter.getCalendarDay(today, 23, 59, 59, 999);
   _statsManager.deleteStatsRecord(start.getTime(), end.getTime());
 }
  public void testGetActionRecords() throws Throwable {
    List<Integer> ids = this._actionLoggerManager.getActionRecords(null);
    this.compareIds(new Integer[] {}, ids);

    ActionLogRecord record1 =
        this._helper.createActionRecord(
            1,
            "username1",
            "actionName1",
            "namespace1",
            DateConverter.parseDate("01/01/2009 00:00", "dd/MM/yyyy HH:mm"),
            "params1");
    ActionLogRecord record2 =
        this._helper.createActionRecord(
            2,
            "username2",
            "actionName2",
            "namespace2",
            DateConverter.parseDate("01/01/2009 10:00", "dd/MM/yyyy HH:mm"),
            "params2");
    ActionLogRecord record3 =
        this._helper.createActionRecord(
            3,
            "username123",
            "actionName123",
            "namespace123",
            DateConverter.parseDate("02/01/2009 12:00", "dd/MM/yyyy HH:mm"),
            "params123");
    this._helper.addActionRecord(record1);
    this._helper.addActionRecord(record2);
    this._helper.addActionRecord(record3);

    ids = this._actionLoggerManager.getActionRecords(null);
    this.compareIds(new Integer[] {1, 2, 3}, ids);

    ActionLogRecordSearchBean searchBean =
        this._helper.createSearchBean("name", "Name", "space", "arams", null, null);
    ids = this._actionLoggerManager.getActionRecords(searchBean);
    this.compareIds(new Integer[] {1, 2, 3}, ids);

    searchBean =
        this._helper.createSearchBean(
            "name",
            "Name",
            "space",
            "arams",
            DateConverter.parseDate("01/01/2009 10:01", "dd/MM/yyyy HH:mm"),
            null);
    ids = this._actionLoggerManager.getActionRecords(searchBean);
    this.compareIds(new Integer[] {3}, ids);

    searchBean =
        this._helper.createSearchBean(
            null,
            null,
            null,
            null,
            null,
            DateConverter.parseDate("01/01/2009 10:01", "dd/MM/yyyy HH:mm"));
    ids = this._actionLoggerManager.getActionRecords(searchBean);
    this.compareIds(new Integer[] {1, 2}, ids);

    searchBean =
        this._helper.createSearchBean(
            null,
            "Name",
            null,
            null,
            DateConverter.parseDate("01/01/2009 09:01", "dd/MM/yyyy HH:mm"),
            DateConverter.parseDate("01/01/2009 10:01", "dd/MM/yyyy HH:mm"));
    ids = this._actionLoggerManager.getActionRecords(searchBean);
    this.compareIds(new Integer[] {2}, ids);
  }