Search in sources :

Example 71 with AttributeInterface

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

the class TestDataObjectManager method testLoadFullDataObject.

public void testLoadFullDataObject() throws Throwable {
    DataObject dataObject = this._dataObjectManager.loadDataObject("ALL4", false);
    assertEquals(DataObject.STATUS_PUBLIC, dataObject.getStatus());
    assertEquals(Group.FREE_GROUP_NAME, dataObject.getMainGroup());
    assertEquals(0, dataObject.getGroups().size());
    Map<String, AttributeInterface> attributes = dataObject.getAttributeMap();
    assertEquals(37, attributes.size());
    CheckBoxAttribute checkBoxAttribute = (CheckBoxAttribute) attributes.get("CheckBox");
    assertNotNull(checkBoxAttribute);
    assertNull(checkBoxAttribute.getBooleanValue());
    DateAttribute dateAttribute = (DateAttribute) attributes.get("Date");
    assertNotNull(dateAttribute);
    assertEquals("20100321", DateConverter.getFormattedDate(dateAttribute.getDate(), "yyyyMMdd"));
    DateAttribute dateAttribute2 = (DateAttribute) attributes.get("Date2");
    assertNotNull(dateAttribute2);
    assertEquals("20120321", DateConverter.getFormattedDate(dateAttribute2.getDate(), "yyyyMMdd"));
    EnumeratorAttribute enumeratorAttribute = (EnumeratorAttribute) attributes.get("Enumerator");
    assertNotNull(enumeratorAttribute);
    assertEquals("a", enumeratorAttribute.getText());
    EnumeratorMapAttribute enumeratorMapAttribute = (EnumeratorMapAttribute) attributes.get("EnumeratorMap");
    assertNotNull(enumeratorMapAttribute);
    assertEquals("02", enumeratorMapAttribute.getMapKey());
    assertEquals("Value 2", enumeratorMapAttribute.getMapValue());
    HypertextAttribute hypertextAttribute = (HypertextAttribute) attributes.get("Hypertext");
    assertNotNull(hypertextAttribute);
    assertEquals("<p>text Hypertext</p>", hypertextAttribute.getTextForLang("it"));
    TextAttribute longtextAttribute = (TextAttribute) attributes.get("Longtext");
    assertNotNull(longtextAttribute);
    assertEquals("text Longtext", longtextAttribute.getTextForLang("it"));
    MonoTextAttribute monoTextAttribute = (MonoTextAttribute) attributes.get("Monotext");
    assertNotNull(monoTextAttribute);
    assertEquals("text Monotext", monoTextAttribute.getText());
    MonoTextAttribute monoTextAttribute2 = (MonoTextAttribute) attributes.get("Monotext2");
    assertNotNull(monoTextAttribute2);
    assertEquals("aaaa@entando.com", monoTextAttribute2.getText());
    NumberAttribute numberAttribute = (NumberAttribute) attributes.get("Number");
    assertNotNull(numberAttribute);
    assertEquals(25, numberAttribute.getValue().intValue());
    NumberAttribute numberAttribute2 = (NumberAttribute) attributes.get("Number2");
    assertNotNull(numberAttribute2);
    assertEquals(85, numberAttribute2.getValue().intValue());
    TextAttribute textAttribute = (TextAttribute) attributes.get("Text");
    assertNotNull(textAttribute);
    assertEquals("text Text", textAttribute.getTextForLang("it"));
    TextAttribute textAttribute2 = (TextAttribute) attributes.get("Text2");
    assertNotNull(textAttribute2);
    assertEquals("bbbb@entando.com", textAttribute2.getTextForLang("it"));
    ThreeStateAttribute threeStateAttribute = (ThreeStateAttribute) attributes.get("ThreeState");
    assertNotNull(threeStateAttribute);
    assertEquals(Boolean.FALSE, threeStateAttribute.getBooleanValue());
    CompositeAttribute compositeAttribute = (CompositeAttribute) attributes.get("Composite");
    assertNotNull(compositeAttribute);
    assertEquals(10, compositeAttribute.getAttributeMap().size());
    ListAttribute listAttribute1 = (ListAttribute) attributes.get("ListBoolea");
    assertNotNull(listAttribute1);
    assertEquals(2, listAttribute1.getAttributeList("it").size());
    ListAttribute listAttribute2 = (ListAttribute) attributes.get("ListCheck");
    assertNotNull(listAttribute2);
    assertEquals(2, listAttribute2.getAttributeList("it").size());
    ListAttribute listAttribute3 = (ListAttribute) attributes.get("ListDate");
    assertNotNull(listAttribute3);
    assertEquals(2, listAttribute3.getAttributeList("it").size());
    ListAttribute listAttribute4 = (ListAttribute) attributes.get("ListEnum");
    assertNotNull(listAttribute4);
    assertEquals(2, listAttribute4.getAttributeList("it").size());
    ListAttribute listAttribute5 = (ListAttribute) attributes.get("ListMonot");
    assertNotNull(listAttribute5);
    assertEquals(2, listAttribute5.getAttributeList("it").size());
    ListAttribute listAttribute6 = (ListAttribute) attributes.get("ListNumber");
    assertNotNull(listAttribute6);
    assertEquals(2, listAttribute6.getAttributeList("it").size());
    ListAttribute listAttribute7 = (ListAttribute) attributes.get("List3Stat");
    assertNotNull(listAttribute7);
    assertEquals(3, listAttribute7.getAttributeList("it").size());
    MonoListAttribute monoListAttribute2 = (MonoListAttribute) attributes.get("MonoLBool");
    assertNotNull(monoListAttribute2);
    assertEquals(2, monoListAttribute2.getAttributes().size());
    MonoListAttribute monoListAttribute3 = (MonoListAttribute) attributes.get("MonoLChec");
    assertNotNull(monoListAttribute3);
    assertEquals(2, monoListAttribute3.getAttributes().size());
    MonoListAttribute monoListAttribute4 = (MonoListAttribute) attributes.get("MonoLCom");
    assertNotNull(monoListAttribute4);
    assertEquals(1, monoListAttribute4.getAttributes().size());
    MonoListAttribute monoListAttribute5 = (MonoListAttribute) attributes.get("MonoLCom2");
    assertNotNull(monoListAttribute5);
    assertEquals(2, monoListAttribute5.getAttributes().size());
    MonoListAttribute monoListAttribute6 = (MonoListAttribute) attributes.get("MonoLDate");
    assertNotNull(monoListAttribute6);
    assertEquals(2, monoListAttribute6.getAttributes().size());
    MonoListAttribute monoListAttribute7 = (MonoListAttribute) attributes.get("MonoLEnum");
    assertNotNull(monoListAttribute7);
    assertEquals(2, monoListAttribute7.getAttributes().size());
    MonoListAttribute monoListAttribute8 = (MonoListAttribute) attributes.get("MonoLHyper");
    assertNotNull(monoListAttribute8);
    assertEquals(2, monoListAttribute8.getAttributes().size());
    MonoListAttribute monoListAttribute11 = (MonoListAttribute) attributes.get("MonoLLong");
    assertNotNull(monoListAttribute11);
    assertEquals(1, monoListAttribute11.getAttributes().size());
    MonoListAttribute monoListAttribute12 = (MonoListAttribute) attributes.get("MonoLMonot");
    assertNotNull(monoListAttribute12);
    assertEquals(2, monoListAttribute12.getAttributes().size());
    MonoListAttribute monoListAttribute13 = (MonoListAttribute) attributes.get("MonoLNumb");
    assertNotNull(monoListAttribute13);
    assertEquals(2, monoListAttribute13.getAttributes().size());
    MonoListAttribute monoListAttribute14 = (MonoListAttribute) attributes.get("MonoLText");
    assertNotNull(monoListAttribute14);
    assertEquals(2, monoListAttribute14.getAttributes().size());
    MonoListAttribute monoListAttribute15 = (MonoListAttribute) attributes.get("MonoL3stat");
    assertNotNull(monoListAttribute15);
    assertEquals(3, monoListAttribute15.getAttributes().size());
    EnumeratorMapAttribute enumeratorMapAttribute2 = (EnumeratorMapAttribute) attributes.get("EnumeratorMapBis");
    assertNotNull(enumeratorMapAttribute2);
    assertEquals("01", enumeratorMapAttribute2.getMapKey());
    assertEquals("Value 1 Bis", enumeratorMapAttribute2.getMapValue());
}
Also used : HypertextAttribute(com.agiletec.aps.system.common.entity.model.attribute.HypertextAttribute) EnumeratorMapAttribute(org.entando.entando.aps.system.common.entity.model.attribute.EnumeratorMapAttribute) TextAttribute(com.agiletec.aps.system.common.entity.model.attribute.TextAttribute) MonoTextAttribute(com.agiletec.aps.system.common.entity.model.attribute.MonoTextAttribute) ThreeStateAttribute(com.agiletec.aps.system.common.entity.model.attribute.ThreeStateAttribute) EnumeratorAttribute(com.agiletec.aps.system.common.entity.model.attribute.EnumeratorAttribute) MonoListAttribute(com.agiletec.aps.system.common.entity.model.attribute.MonoListAttribute) DataObject(org.entando.entando.aps.system.services.dataobject.model.DataObject) CompositeAttribute(com.agiletec.aps.system.common.entity.model.attribute.CompositeAttribute) CheckBoxAttribute(com.agiletec.aps.system.common.entity.model.attribute.CheckBoxAttribute) NumberAttribute(com.agiletec.aps.system.common.entity.model.attribute.NumberAttribute) AttributeInterface(com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface) MonoTextAttribute(com.agiletec.aps.system.common.entity.model.attribute.MonoTextAttribute) MonoListAttribute(com.agiletec.aps.system.common.entity.model.attribute.MonoListAttribute) ListAttribute(com.agiletec.aps.system.common.entity.model.attribute.ListAttribute) DateAttribute(com.agiletec.aps.system.common.entity.model.attribute.DateAttribute)

Example 72 with AttributeInterface

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

the class TestApiContentInterface method checkAttributes.

private void checkAttributes(AttributeInterface oldAttribute, AttributeInterface newAttribute) {
    if (null == newAttribute) {
        fail();
    }
    assertEquals(oldAttribute.getName(), newAttribute.getName());
    assertEquals(oldAttribute.getType(), newAttribute.getType());
    if (!oldAttribute.isSimple()) {
        if (oldAttribute instanceof AbstractListAttribute) {
            List<AttributeInterface> oldListAttributes = ((AbstractComplexAttribute) oldAttribute).getAttributes();
            List<AttributeInterface> newListAttributes = ((AbstractComplexAttribute) newAttribute).getAttributes();
            assertEquals(oldListAttributes.size(), newListAttributes.size());
            for (int i = 0; i < oldListAttributes.size(); i++) {
                AttributeInterface oldElement = oldListAttributes.get(i);
                AttributeInterface newElement = newListAttributes.get(i);
                this.checkAttributes(oldElement, newElement);
            }
        } else if (oldAttribute instanceof CompositeAttribute) {
            Map<String, AttributeInterface> oldAttributeMap = ((CompositeAttribute) oldAttribute).getAttributeMap();
            Map<String, AttributeInterface> newAttributeMap = ((CompositeAttribute) newAttribute).getAttributeMap();
            assertEquals(oldAttributeMap.size(), newAttributeMap.size());
            Iterator<String> iterator = oldAttributeMap.keySet().iterator();
            while (iterator.hasNext()) {
                String key = iterator.next();
                AttributeInterface oldElement = oldAttributeMap.get(key);
                AttributeInterface newElement = newAttributeMap.get(key);
                this.checkAttributes(oldElement, newElement);
            }
        }
    } else {
        if (oldAttribute instanceof AbstractResourceAttribute || oldAttribute instanceof LinkAttribute) {
            return;
        }
        assertEquals(oldAttribute.getValue(), newAttribute.getValue());
    }
}
Also used : AbstractResourceAttribute(com.agiletec.plugins.jacms.aps.system.services.content.model.extraAttribute.AbstractResourceAttribute) LinkAttribute(com.agiletec.plugins.jacms.aps.system.services.content.model.extraAttribute.LinkAttribute) AbstractComplexAttribute(com.agiletec.aps.system.common.entity.model.attribute.AbstractComplexAttribute) CompositeAttribute(com.agiletec.aps.system.common.entity.model.attribute.CompositeAttribute) Iterator(java.util.Iterator) Map(java.util.Map) AbstractListAttribute(com.agiletec.aps.system.common.entity.model.attribute.AbstractListAttribute) AttributeInterface(com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)

Example 73 with AttributeInterface

use of com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface 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 74 with AttributeInterface

use of com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface 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 75 with AttributeInterface

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

Aggregations

AttributeInterface (com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)147 Content (com.agiletec.plugins.jacms.aps.system.services.content.model.Content)55 AttributeTracer (com.agiletec.aps.system.common.entity.model.AttributeTracer)38 MonoListAttribute (com.agiletec.aps.system.common.entity.model.attribute.MonoListAttribute)37 CompositeAttribute (com.agiletec.aps.system.common.entity.model.attribute.CompositeAttribute)27 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)22 ArrayList (java.util.ArrayList)18 IApsEntity (com.agiletec.aps.system.common.entity.model.IApsEntity)17 ITextAttribute (com.agiletec.aps.system.common.entity.model.attribute.ITextAttribute)16 DateAttribute (com.agiletec.aps.system.common.entity.model.attribute.DateAttribute)14 NumberAttribute (com.agiletec.aps.system.common.entity.model.attribute.NumberAttribute)12 ListAttribute (com.agiletec.aps.system.common.entity.model.attribute.ListAttribute)11 BooleanAttribute (com.agiletec.aps.system.common.entity.model.attribute.BooleanAttribute)10 IndexableAttributeInterface (com.agiletec.aps.system.common.searchengine.IndexableAttributeInterface)10 HttpSession (javax.servlet.http.HttpSession)10 EntityAttributeIterator (com.agiletec.aps.system.common.util.EntityAttributeIterator)9 IEntityManager (com.agiletec.aps.system.common.entity.IEntityManager)7 MonoTextAttribute (com.agiletec.aps.system.common.entity.model.attribute.MonoTextAttribute)7 Lang (com.agiletec.aps.system.services.lang.Lang)7 Date (java.util.Date)7