Search in sources :

Example 1 with DateAttribute

use of com.agiletec.aps.system.common.entity.model.attribute.DateAttribute in project entando-core by entando.

the class TestContentManager method testLoadOrderedPublicEvents_4.

public void testLoadOrderedPublicEvents_4() throws Throwable {
    Content masterContent = this._contentManager.loadContent("EVN193", true);
    masterContent.setId(null);
    DateAttribute dateAttribute = (DateAttribute) masterContent.getAttribute("DataInizio");
    dateAttribute.setDate(DateConverter.parseDate("17/06/2019", "dd/MM/yyyy"));
    try {
        this._contentManager.saveContent(masterContent);
        this._contentManager.insertOnLineContent(masterContent);
        this.waitNotifyingThread();
        EntitySearchFilter filterForDate = new EntitySearchFilter("DataInizio", true);
        filterForDate.setOrder(EntitySearchFilter.DESC_ORDER);
        EntitySearchFilter[] filters = { filterForDate };
        List<String> contents = _contentManager.loadPublicContentsId("EVN", null, filters, null);
        String[] expectedFreeOrderedContentsId = { "EVN194", masterContent.getId(), "EVN193", "EVN24", "EVN23", "EVN25", "EVN20", "EVN21", "EVN192", "EVN191" };
        assertEquals(expectedFreeOrderedContentsId.length, contents.size());
        for (int i = 0; i < expectedFreeOrderedContentsId.length; i++) {
            assertEquals(expectedFreeOrderedContentsId[i], contents.get(i));
        }
    } catch (Throwable t) {
        throw t;
    } finally {
        if (null != masterContent.getId() && !"EVN193".equals(masterContent.getId())) {
            this._contentManager.removeOnLineContent(masterContent);
            this._contentManager.deleteContent(masterContent);
        }
    }
}
Also used : Content(com.agiletec.plugins.jacms.aps.system.services.content.model.Content) EntitySearchFilter(com.agiletec.aps.system.common.entity.model.EntitySearchFilter) DateAttribute(com.agiletec.aps.system.common.entity.model.attribute.DateAttribute)

Example 2 with DateAttribute

use of com.agiletec.aps.system.common.entity.model.attribute.DateAttribute in project entando-core by entando.

the class UserFilterOptionBean method extractFormParameters.

protected void extractFormParameters(HttpServletRequest request) throws Throwable {
    String[] formFieldNames = null;
    try {
        String frameIdSuffix = (null != this.getCurrentFrame()) ? "_frame" + this.getCurrentFrame().toString() : "";
        if (!this.isAttributeFilter()) {
            if (this.getKey().equals(KEY_FULLTEXT)) {
                String fieldName = TYPE_METADATA + "_fulltext" + frameIdSuffix;
                String[] fieldsSuffix = { "", "_option", "_attachSearch" };
                formFieldNames = this.extractParams(fieldName, fieldsSuffix, frameIdSuffix, request);
            } else if (this.getKey().equals(KEY_CATEGORY)) {
                formFieldNames = new String[1];
                formFieldNames[0] = TYPE_METADATA + "_category" + frameIdSuffix;
                String value = request.getParameter(formFieldNames[0]);
                this.addFormValue(formFieldNames[0], value, formFieldNames.length);
            }
        } else {
            AttributeInterface attribute = this.getAttribute();
            if (attribute instanceof ITextAttribute) {
                String[] fieldsSuffix = { "_textFieldName" };
                formFieldNames = this.extractAttributeParams(fieldsSuffix, frameIdSuffix, request);
            } else if (attribute instanceof DateAttribute) {
                String[] fieldsSuffix = { "_dateStartFieldName", "_dateEndFieldName" };
                formFieldNames = this.extractAttributeParams(fieldsSuffix, frameIdSuffix, request);
                this.checkRange(formFieldNames);
            } else if (attribute instanceof BooleanAttribute) {
                String[] fieldsSuffix = { "_booleanFieldName", "_booleanFieldName_ignore", "_booleanFieldName_control" };
                formFieldNames = this.extractAttributeParams(fieldsSuffix, frameIdSuffix, request);
            } else if (attribute instanceof NumberAttribute) {
                String[] fieldsSuffix = { "_numberStartFieldName", "_numberEndFieldName" };
                formFieldNames = this.extractAttributeParams(fieldsSuffix, frameIdSuffix, request);
                this.checkRange(formFieldNames);
            }
        }
    } catch (Throwable t) {
        _logger.error("Error extracting form parameters", t);
        throw new ApsSystemException("Error extracting form parameters", t);
    }
    this.setFormFieldNames(formFieldNames);
}
Also used : ITextAttribute(com.agiletec.aps.system.common.entity.model.attribute.ITextAttribute) BooleanAttribute(com.agiletec.aps.system.common.entity.model.attribute.BooleanAttribute) NumberAttribute(com.agiletec.aps.system.common.entity.model.attribute.NumberAttribute) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) AttributeInterface(com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface) DateAttribute(com.agiletec.aps.system.common.entity.model.attribute.DateAttribute)

Example 3 with DateAttribute

use of com.agiletec.aps.system.common.entity.model.attribute.DateAttribute in project entando-core by entando.

the class DateAttributeValidationRules method validate.

@Override
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) {
        _logger.error("Error validating Attribute '{}'", attribute.getName(), t);
        throw new RuntimeException("Error validating Attribute '" + attribute.getName() + "'", t);
    }
    return errors;
}
Also used : AttributeFieldError(com.agiletec.aps.system.common.entity.model.AttributeFieldError) Date(java.util.Date) DateAttribute(com.agiletec.aps.system.common.entity.model.attribute.DateAttribute)

Example 4 with DateAttribute

use of com.agiletec.aps.system.common.entity.model.attribute.DateAttribute in project entando-core by entando.

the class UserFilterOptionBean method getEntityFilter.

public EntitySearchFilter getEntityFilter() throws ApsSystemException {
    EntitySearchFilter filter = null;
    try {
        if (!this.isAttributeFilter() || null == this.getFormFieldValues()) {
            return null;
        }
        AttributeInterface attribute = this.getAttribute();
        if (attribute instanceof ITextAttribute) {
            String text = this.getFormFieldValues().get(this.getFormFieldNames()[0]);
            filter = new EntitySearchFilter(attribute.getName(), true, text, true);
            if (attribute.isMultilingual()) {
                filter.setLangCode(this.getCurrentLang().getCode());
            }
        } else if (attribute instanceof DateAttribute) {
            String start = this.getFormFieldValues().get(this.getFormFieldNames()[0]);
            String end = this.getFormFieldValues().get(this.getFormFieldNames()[1]);
            Date startDate = DateConverter.parseDate(start, this.getDateFormat());
            Date endDate = DateConverter.parseDate(end, this.getDateFormat());
            filter = new EntitySearchFilter(attribute.getName(), true, startDate, endDate);
        } else if (attribute instanceof BooleanAttribute) {
            String value = this.getFormFieldValues().get(this.getFormFieldNames()[0]);
            String ignore = this.getFormFieldValues().get(this.getFormFieldNames()[1]);
            if (null != ignore) {
                return null;
            } else if (null == value || value.equals("both")) {
                // special option for three state Attribute
                filter = new EntitySearchFilter(attribute.getName(), true);
                filter.setNullOption(true);
            } else {
                filter = new EntitySearchFilter(attribute.getName(), true, value, false);
            }
        } else if (attribute instanceof NumberAttribute) {
            String start = this.getFormFieldValues().get(this.getFormFieldNames()[0]);
            String end = this.getFormFieldValues().get(this.getFormFieldNames()[1]);
            BigDecimal startNumber = null;
            try {
                Integer startNumberInt = Integer.parseInt(start);
                startNumber = new BigDecimal(startNumberInt);
            } catch (Throwable t) {
            }
            BigDecimal endNumber = null;
            try {
                Integer endNumberInt = Integer.parseInt(end);
                endNumber = new BigDecimal(endNumberInt);
            } catch (Throwable t) {
            }
            filter = new EntitySearchFilter(attribute.getName(), true, startNumber, endNumber);
        }
    } catch (Throwable t) {
        _logger.error("Error extracting entity search filters", t);
        throw new ApsSystemException("Error extracting entity search filters", t);
    }
    return filter;
}
Also used : ITextAttribute(com.agiletec.aps.system.common.entity.model.attribute.ITextAttribute) BooleanAttribute(com.agiletec.aps.system.common.entity.model.attribute.BooleanAttribute) NumberAttribute(com.agiletec.aps.system.common.entity.model.attribute.NumberAttribute) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) EntitySearchFilter(com.agiletec.aps.system.common.entity.model.EntitySearchFilter) AttributeInterface(com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface) Date(java.util.Date) BigDecimal(java.math.BigDecimal) DateAttribute(com.agiletec.aps.system.common.entity.model.attribute.DateAttribute)

Example 5 with DateAttribute

use of com.agiletec.aps.system.common.entity.model.attribute.DateAttribute in project entando-core by entando.

the class UserProfileManagerIntegrationTest method createProfile.

private IUserProfile createProfile(String name, String surname, String email, Date birthdate, String language) {
    IUserProfile profile = this.profileManager.getDefaultProfileType();
    MonoTextAttribute nameAttr = (MonoTextAttribute) profile.getAttribute("fullname");
    nameAttr.setText(name + " " + surname);
    MonoTextAttribute emailAttr = (MonoTextAttribute) profile.getAttribute("email");
    emailAttr.setText(email);
    DateAttribute birthdateAttr = (DateAttribute) profile.getAttribute("birthdate");
    birthdateAttr.setDate(birthdate);
    MonoTextAttribute languageAttr = (MonoTextAttribute) profile.getAttribute("language");
    languageAttr.setText(language);
    ((UserProfile) profile).setPublicProfile(true);
    return profile;
}
Also used : UserProfile(org.entando.entando.aps.system.services.userprofile.model.UserProfile) IUserProfile(org.entando.entando.aps.system.services.userprofile.model.IUserProfile) IUserProfile(org.entando.entando.aps.system.services.userprofile.model.IUserProfile) MonoTextAttribute(com.agiletec.aps.system.common.entity.model.attribute.MonoTextAttribute) DateAttribute(com.agiletec.aps.system.common.entity.model.attribute.DateAttribute)

Aggregations

DateAttribute (com.agiletec.aps.system.common.entity.model.attribute.DateAttribute)29 NumberAttribute (com.agiletec.aps.system.common.entity.model.attribute.NumberAttribute)20 AttributeInterface (com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)16 Date (java.util.Date)13 BooleanAttribute (com.agiletec.aps.system.common.entity.model.attribute.BooleanAttribute)12 ITextAttribute (com.agiletec.aps.system.common.entity.model.attribute.ITextAttribute)12 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)7 MonoTextAttribute (com.agiletec.aps.system.common.entity.model.attribute.MonoTextAttribute)6 BigDecimal (java.math.BigDecimal)6 EntitySearchFilter (com.agiletec.aps.system.common.entity.model.EntitySearchFilter)5 MonoListAttribute (com.agiletec.aps.system.common.entity.model.attribute.MonoListAttribute)5 TextAttribute (com.agiletec.aps.system.common.entity.model.attribute.TextAttribute)5 EnumeratorAttribute (com.agiletec.aps.system.common.entity.model.attribute.EnumeratorAttribute)4 HypertextAttribute (com.agiletec.aps.system.common.entity.model.attribute.HypertextAttribute)4 DateAttributeValidationRules (com.agiletec.aps.system.common.entity.model.attribute.util.DateAttributeValidationRules)4 IAttributeValidationRules (com.agiletec.aps.system.common.entity.model.attribute.util.IAttributeValidationRules)4 NumberAttributeValidationRules (com.agiletec.aps.system.common.entity.model.attribute.util.NumberAttributeValidationRules)4 TextAttributeValidationRules (com.agiletec.aps.system.common.entity.model.attribute.util.TextAttributeValidationRules)4 Content (com.agiletec.plugins.jacms.aps.system.services.content.model.Content)4 CompositeAttribute (com.agiletec.aps.system.common.entity.model.attribute.CompositeAttribute)3