Search in sources :

Example 21 with DataObject

use of org.entando.entando.aps.system.services.dataobject.model.DataObject in project entando-core by entando.

the class TestDataObjectManager method testLoadDataObject.

public void testLoadDataObject() throws Throwable {
    DataObject dataObject = this._dataObjectManager.loadDataObject("ART111", false);
    assertEquals(DataObject.STATUS_PUBLIC, dataObject.getStatus());
    assertEquals("coach", dataObject.getMainGroup());
    assertEquals(2, dataObject.getGroups().size());
    assertTrue(dataObject.getGroups().contains("customers"));
    assertTrue(dataObject.getGroups().contains("helpdesk"));
    Map<String, AttributeInterface> attributes = dataObject.getAttributeMap();
    assertEquals(5, attributes.size());
    TextAttribute title = (TextAttribute) attributes.get("Titolo");
    assertEquals("Titolo Contenuto 3 Coach", title.getTextForLang("it"));
    assertNull(title.getTextForLang("en"));
    MonoListAttribute authors = (MonoListAttribute) attributes.get("Autori");
    assertEquals(4, authors.getAttributes().size());
    HypertextAttribute hypertext = (HypertextAttribute) attributes.get("CorpoTesto");
    assertEquals("<p>Corpo Testo Contenuto 3 Coach</p>", hypertext.getTextForLang("it").trim());
    assertNull(hypertext.getTextForLang("en"));
    DateAttribute date = (DateAttribute) attributes.get("Data");
    assertEquals("13/12/2006", DateConverter.getFormattedDate(date.getDate(), "dd/MM/yyyy"));
}
Also used : MonoListAttribute(com.agiletec.aps.system.common.entity.model.attribute.MonoListAttribute) HypertextAttribute(com.agiletec.aps.system.common.entity.model.attribute.HypertextAttribute) DataObject(org.entando.entando.aps.system.services.dataobject.model.DataObject) TextAttribute(com.agiletec.aps.system.common.entity.model.attribute.TextAttribute) MonoTextAttribute(com.agiletec.aps.system.common.entity.model.attribute.MonoTextAttribute) AttributeInterface(com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface) DateAttribute(com.agiletec.aps.system.common.entity.model.attribute.DateAttribute)

Example 22 with DataObject

use of org.entando.entando.aps.system.services.dataobject.model.DataObject in project entando-core by entando.

the class TestDataObjectManager method testLoadOrderedEvents_4.

public void testLoadOrderedEvents_4() throws Throwable {
    DataObject masterDataObject = this._dataObjectManager.loadDataObject("EVN193", true);
    masterDataObject.setId(null);
    DateAttribute dateAttribute = (DateAttribute) masterDataObject.getAttribute("DataInizio");
    dateAttribute.setDate(DateConverter.parseDate("17/06/2019", "dd/MM/yyyy"));
    try {
        this._dataObjectManager.saveDataObject(masterDataObject);
        this._dataObjectManager.insertDataObject(masterDataObject);
        this.waitNotifyingThread();
        EntitySearchFilter filterForDate = new EntitySearchFilter("DataInizio", true);
        filterForDate.setOrder(EntitySearchFilter.DESC_ORDER);
        EntitySearchFilter[] filters = { filterForDate };
        List<String> dataObjects = _dataObjectManager.loadDataObjectsId("EVN", null, filters, null);
        String[] expectedFreeOrderedDataObjectsId = { "EVN194", masterDataObject.getId(), "EVN193", "EVN24", "EVN23", "EVN25", "EVN20", "EVN21", "EVN192", "EVN191" };
        assertEquals(expectedFreeOrderedDataObjectsId.length, dataObjects.size());
        for (int i = 0; i < expectedFreeOrderedDataObjectsId.length; i++) {
            assertEquals(expectedFreeOrderedDataObjectsId[i], dataObjects.get(i));
        }
    } catch (Throwable t) {
        throw t;
    } finally {
        if (null != masterDataObject.getId() && !"EVN193".equals(masterDataObject.getId())) {
            this._dataObjectManager.removeDataObject(masterDataObject);
            this._dataObjectManager.deleteDataObject(masterDataObject);
        }
    }
}
Also used : DataObject(org.entando.entando.aps.system.services.dataobject.model.DataObject) EntitySearchFilter(com.agiletec.aps.system.common.entity.model.EntitySearchFilter) DateAttribute(com.agiletec.aps.system.common.entity.model.attribute.DateAttribute)

Example 23 with DataObject

use of org.entando.entando.aps.system.services.dataobject.model.DataObject in project entando-core by entando.

the class DataObjectActionHelper method updateEntity.

@Override
public void updateEntity(IApsEntity entity, HttpServletRequest request) {
    DataObject dataObject = (DataObject) entity;
    try {
        if (null != dataObject) {
            String descr = request.getParameter("descr");
            if (descr != null) {
                dataObject.setDescription(descr.trim());
            }
            String status = request.getParameter("status");
            if (status != null) {
                dataObject.setStatus(status);
            }
            if (null == dataObject.getId()) {
                String mainGroup = request.getParameter("mainGroup");
                if (mainGroup != null) {
                    request.getSession().setAttribute("dataObjectGroupOnSession", mainGroup);
                }
            }
            super.updateEntity(dataObject, request);
            String description = dataObject.getDescription();
            if (null == description || description.trim().length() == 0) {
                ITextAttribute titleAttribute = (ITextAttribute) dataObject.getAttributeByRole(SystemConstants.DATA_TYPE_ATTRIBUTE_ROLE_TITLE);
                if (null != titleAttribute && StringUtils.isNotEmpty(titleAttribute.getText())) {
                    dataObject.setDescription(titleAttribute.getText());
                }
            }
        }
    } catch (Throwable t) {
        _logger.error("DataObjectActionHelper - updateDataObject", t);
        throw new RuntimeException("Error updating DataObject", t);
    }
}
Also used : ITextAttribute(com.agiletec.aps.system.common.entity.model.attribute.ITextAttribute) DataObject(org.entando.entando.aps.system.services.dataobject.model.DataObject)

Example 24 with DataObject

use of org.entando.entando.aps.system.services.dataobject.model.DataObject 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 25 with DataObject

use of org.entando.entando.aps.system.services.dataobject.model.DataObject in project entando-core by entando.

the class TestValidateDataObject method testValidate_2.

public void testValidate_2() throws Throwable {
    try {
        DataObject content = this.createNewVoid("RAH", "descr", DataObject.STATUS_DRAFT, Group.FREE_GROUP_NAME, "admin");
        ITextAttribute emailAttribute = (ITextAttribute) content.getAttribute("email");
        emailAttribute.setText("wrongEmailAddress", null);
        List<FieldError> errors = content.validate(this._groupManager);
        assertEquals(1, errors.size());
        FieldError error = errors.get(0);
        assertEquals("Monotext:email", error.getFieldCode());
        assertEquals(FieldError.INVALID_FORMAT, error.getErrorCode());
    } catch (Throwable t) {
        throw t;
    }
}
Also used : ITextAttribute(com.agiletec.aps.system.common.entity.model.attribute.ITextAttribute) DataObject(org.entando.entando.aps.system.services.dataobject.model.DataObject) FieldError(com.agiletec.aps.system.common.entity.model.FieldError)

Aggregations

DataObject (org.entando.entando.aps.system.services.dataobject.model.DataObject)72 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)10 UserDetails (com.agiletec.aps.system.services.user.UserDetails)9 ApiException (org.entando.entando.aps.system.services.api.model.ApiException)7 JAXBDataObject (org.entando.entando.aps.system.services.dataobject.api.model.JAXBDataObject)7 Test (org.junit.Test)7 TextAttribute (com.agiletec.aps.system.common.entity.model.attribute.TextAttribute)6 ArrayList (java.util.ArrayList)5 AttributeInterface (com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)4 ITextAttribute (com.agiletec.aps.system.common.entity.model.attribute.ITextAttribute)4 MonoTextAttribute (com.agiletec.aps.system.common.entity.model.attribute.MonoTextAttribute)4 Category (com.agiletec.aps.system.services.category.Category)4 Date (java.util.Date)4 EntitySearchFilter (com.agiletec.aps.system.common.entity.model.EntitySearchFilter)3 FieldError (com.agiletec.aps.system.common.entity.model.FieldError)3 DateAttribute (com.agiletec.aps.system.common.entity.model.attribute.DateAttribute)3 MonoListAttribute (com.agiletec.aps.system.common.entity.model.attribute.MonoListAttribute)3 Group (com.agiletec.aps.system.services.group.Group)3 StringApiResponse (org.entando.entando.aps.system.services.api.model.StringApiResponse)3 IDataObjectManager (org.entando.entando.aps.system.services.dataobject.IDataObjectManager)3