Search in sources :

Example 11 with ITextAttribute

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

the class TestContentPreviewAction method testPreviewNewContent.

public void testPreviewNewContent() throws Throwable {
    String insertedDescr = "XXX Prova preview XXX";
    String contentTypeCode = "ART";
    Content prototype = this.getContentManager().createContentType(contentTypeCode);
    String contentOnSessionMarker = AbstractContentAction.buildContentOnSessionMarker(prototype, ApsAdminSystemConstants.ADD);
    String result = this.executeCreateNewVoid(contentTypeCode, insertedDescr, Content.STATUS_DRAFT, Group.FREE_GROUP_NAME, "admin");
    assertEquals(Action.SUCCESS, result);
    Content content = this.getContentOnEdit(contentOnSessionMarker);
    ITextAttribute titleAttribute = (ITextAttribute) content.getAttribute("Titolo");
    assertNull(titleAttribute.getTextForLang("it"));
    assertEquals(content.getDescr(), insertedDescr);
    this.initContentAction("/do/jacms/Content", "preview", contentOnSessionMarker);
    this.addParameter("Text:it_Titolo", "Nuovo titolo di prova");
    result = this.executeAction();
    assertEquals(Action.SUCCESS, result);
    content = this.getContentOnEdit(contentOnSessionMarker);
    titleAttribute = (ITextAttribute) content.getAttribute("Titolo");
    assertEquals("Nuovo titolo di prova", titleAttribute.getTextForLang("it"));
}
Also used : ITextAttribute(com.agiletec.aps.system.common.entity.model.attribute.ITextAttribute) Content(com.agiletec.plugins.jacms.aps.system.services.content.model.Content)

Example 12 with ITextAttribute

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

the class ApiDataObjectInterface method updateDataObjectText.

public void updateDataObjectText(JAXBDataObjectAttribute jaxbDataObjectAttribute, Properties properties) throws ApiException, Throwable {
    try {
        String dataId = jaxbDataObjectAttribute.getDataId();
        DataObject masterDataObject = this.getDataObjectManager().loadDataObject(jaxbDataObjectAttribute.getDataId(), true);
        if (null == masterDataObject) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "DataObject with code '" + dataId + "' does not exist", Response.Status.CONFLICT);
        }
        String attributeName = jaxbDataObjectAttribute.getAttributeName();
        AttributeInterface attribute = (AttributeInterface) masterDataObject.getAttribute(attributeName);
        if (null == attribute) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "DataObject Attribute with code '" + attributeName + "' does not exist into DataObject " + dataId, Response.Status.CONFLICT);
        } else if (!(attribute instanceof ITextAttribute)) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "DataObject Attribute with code '" + attributeName + "' isn't a Text Atttribute", Response.Status.CONFLICT);
        }
        String langCode = jaxbDataObjectAttribute.getLangCode();
        String value = jaxbDataObjectAttribute.getValue();
        if (StringUtils.isEmpty(langCode) || StringUtils.isEmpty(value)) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "LangCode or value is Empty", Response.Status.CONFLICT);
        }
        ((ITextAttribute) attribute).setText(value, langCode);
        this.getDataObjectManager().insertDataObject(masterDataObject);
    } catch (ApiException ae) {
        throw ae;
    } catch (Throwable t) {
        _logger.error("Error updating DataObject attribute", t);
        throw new ApsSystemException("Error updating DataObject attribute", t);
    }
}
Also used : ITextAttribute(com.agiletec.aps.system.common.entity.model.attribute.ITextAttribute) JAXBDataObject(org.entando.entando.aps.system.services.dataobject.api.model.JAXBDataObject) DataObject(org.entando.entando.aps.system.services.dataobject.model.DataObject) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) AttributeInterface(com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 13 with ITextAttribute

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

the class ApiContentInterface method updateContentText.

public void updateContentText(JAXBContentAttribute jaxbContentAttribute, Properties properties) throws ApiException, Throwable {
    try {
        String contentId = jaxbContentAttribute.getContentId();
        Content masterContent = this.getContentManager().loadContent(jaxbContentAttribute.getContentId(), true);
        if (null == masterContent) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Content with code '" + contentId + "' does not exist", Response.Status.CONFLICT);
        }
        String attributeName = jaxbContentAttribute.getAttributeName();
        AttributeInterface attribute = (AttributeInterface) masterContent.getAttribute(attributeName);
        if (null == attribute) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Content Attribute with code '" + attributeName + "' does not exist into content " + contentId, Response.Status.CONFLICT);
        } else if (!(attribute instanceof ITextAttribute)) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Content Attribute with code '" + attributeName + "' isn't a Text Atttribute", Response.Status.CONFLICT);
        }
        String langCode = jaxbContentAttribute.getLangCode();
        String value = jaxbContentAttribute.getValue();
        if (StringUtils.isEmpty(langCode) || StringUtils.isEmpty(value)) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "LangCode or value is Empty", Response.Status.CONFLICT);
        }
        ((ITextAttribute) attribute).setText(value, langCode);
        this.getContentManager().insertOnLineContent(masterContent);
    } catch (ApiException ae) {
        throw ae;
    } catch (Throwable t) {
        _logger.error("Error updating content attribute", t);
        throw new ApsSystemException("Error updating content attribute", t);
    }
}
Also used : ITextAttribute(com.agiletec.aps.system.common.entity.model.attribute.ITextAttribute) Content(com.agiletec.plugins.jacms.aps.system.services.content.model.Content) JAXBContent(org.entando.entando.plugins.jacms.aps.system.services.api.model.JAXBContent) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) AttributeInterface(com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 14 with ITextAttribute

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

the class UserFilterOptionBean method extractFilter.

public SearchEngineFilter extractFilter() {
    if (null == this.getFormFieldValues()) {
        return null;
    }
    SearchEngineFilter filter = null;
    String value0 = this.getFormValue(0);
    String value1 = this.getFormValue(1);
    if (!this.isAttributeFilter()) {
        if (this.getKey().equals(KEY_FULLTEXT) && !StringUtils.isEmpty(value0)) {
            // String[] fieldsSuffix = {"", "_option"};
            filter = new SearchEngineFilter(this.getCurrentLang().getCode(), value0, this.getOption(value1));
            String attachOption = this.getFormValue(2);
            try {
                filter.setIncludeAttachments(Boolean.parseBoolean(attachOption));
            } catch (Exception e) {
            }
        } else if (this.getKey().equals(KEY_CATEGORY) && !StringUtils.isEmpty(value0)) {
            filter = new SearchEngineFilter(IIndexerDAO.CONTENT_CATEGORY_FIELD_NAME, value0, SearchEngineFilter.TextSearchOption.EXACT);
        }
    } else {
        AttributeInterface attribute = this.getAttribute();
        if (attribute instanceof ITextAttribute && !StringUtils.isEmpty(value0)) {
            filter = new SearchEngineFilter(this.getIndexFieldName(), value0, SearchEngineFilter.TextSearchOption.EXACT);
        // String[] fieldsSuffix = {"_textFieldName"};
        } else if (attribute instanceof DateAttribute && (!StringUtils.isEmpty(value0) || !StringUtils.isEmpty(value1))) {
            Date big0 = null;
            try {
                big0 = DateConverter.parseDate(value0, this.getDateFormat());
            } catch (Exception e) {
            }
            Date big1 = null;
            try {
                big1 = DateConverter.parseDate(value1, this.getDateFormat());
            } catch (Exception e) {
            }
            // String[] fieldsSuffix = {"_dateStartFieldName", "_dateEndFieldName"};
            filter = new SearchEngineFilter(this.getIndexFieldName(), big0, big1);
        } else if (attribute instanceof BooleanAttribute && (!StringUtils.isEmpty(value0) && !StringUtils.isEmpty(value1))) {
            filter = new SearchEngineFilter(this.getIndexFieldName(), value0, SearchEngineFilter.TextSearchOption.EXACT);
        // String[] fieldsSuffix = {"_booleanFieldName", "_booleanFieldName_ignore", "_booleanFieldName_control"};
        } else if (attribute instanceof NumberAttribute && (!StringUtils.isEmpty(value0) || !StringUtils.isEmpty(value1))) {
            // String[] fieldsSuffix = {"_numberStartFieldName", "_numberEndFieldName"};
            BigDecimal big0 = null;
            try {
                big0 = new BigDecimal(value0);
            } catch (Exception e) {
            }
            BigDecimal big1 = null;
            try {
                big1 = new BigDecimal(value1);
            } catch (Exception e) {
            }
            filter = new SearchEngineFilter(this.getIndexFieldName(), big0, big1);
        }
    }
    return filter;
}
Also used : SearchEngineFilter(org.entando.entando.aps.system.services.searchengine.SearchEngineFilter) 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) Date(java.util.Date) BigDecimal(java.math.BigDecimal) DateAttribute(com.agiletec.aps.system.common.entity.model.attribute.DateAttribute)

Example 15 with ITextAttribute

use of com.agiletec.aps.system.common.entity.model.attribute.ITextAttribute 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)

Aggregations

ITextAttribute (com.agiletec.aps.system.common.entity.model.attribute.ITextAttribute)27 AttributeInterface (com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)16 BooleanAttribute (com.agiletec.aps.system.common.entity.model.attribute.BooleanAttribute)10 DateAttribute (com.agiletec.aps.system.common.entity.model.attribute.DateAttribute)10 NumberAttribute (com.agiletec.aps.system.common.entity.model.attribute.NumberAttribute)10 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)9 Content (com.agiletec.plugins.jacms.aps.system.services.content.model.Content)7 BigDecimal (java.math.BigDecimal)5 Date (java.util.Date)5 FieldError (com.agiletec.aps.system.common.entity.model.FieldError)4 DataObject (org.entando.entando.aps.system.services.dataobject.model.DataObject)4 EntitySearchFilter (com.agiletec.aps.system.common.entity.model.EntitySearchFilter)3 TextAttributeValidationRules (com.agiletec.aps.system.common.entity.model.attribute.util.TextAttributeValidationRules)2 Lang (com.agiletec.aps.system.services.lang.Lang)2 ArrayList (java.util.ArrayList)2 ApiException (org.entando.entando.aps.system.services.api.model.ApiException)2 SearchEngineFilter (org.entando.entando.aps.system.services.searchengine.SearchEngineFilter)2 IEntityManager (com.agiletec.aps.system.common.entity.IEntityManager)1 AttributeFieldError (com.agiletec.aps.system.common.entity.model.AttributeFieldError)1 IApsEntity (com.agiletec.aps.system.common.entity.model.IApsEntity)1