Search in sources :

Example 6 with AttributeInterface

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

the class TestEntityManager method testGetEntityTypes.

public void testGetEntityTypes() throws Throwable {
    if (null == this._entityManager)
        return;
    Map<String, AttributeInterface> attributes = this._entityManager.getEntityAttributePrototypes();
    String testTypeCode = "XXX";
    String testAttributeName = "testAttributeName";
    Map<String, IApsEntity> entityTypes = this._entityManager.getEntityPrototypes();
    try {
        assertNotNull(entityTypes);
        assertTrue(entityTypes.size() > 0);
        assertNull(entityTypes.get(testTypeCode));
        IApsEntity entityPrototype = new ArrayList<IApsEntity>(entityTypes.values()).get(0);
        int initAttributeNumber = entityPrototype.getAttributeList().size();
        entityPrototype.setTypeCode(testTypeCode);
        entityPrototype.setTypeDescr("testDescription");
        assertNull(entityPrototype.getAttribute(testAttributeName));
        AttributeInterface newAttribute = attributes.get("Text");
        newAttribute.setName(testAttributeName);
        newAttribute.setRequired(true);
        entityPrototype.addAttribute(newAttribute);
        ((IEntityTypesConfigurer) this._entityManager).addEntityPrototype(entityPrototype);
        entityTypes = this._entityManager.getEntityPrototypes();
        IApsEntity extractedEntityPrototype = entityTypes.get(testTypeCode);
        assertNotNull(extractedEntityPrototype);
        assertEquals(initAttributeNumber + 1, extractedEntityPrototype.getAttributeList().size());
    } catch (Throwable t) {
        throw t;
    } finally {
        ((IEntityTypesConfigurer) this._entityManager).removeEntityPrototype(testTypeCode);
        entityTypes = this._entityManager.getEntityPrototypes();
        assertNull(entityTypes.get(testTypeCode));
    }
}
Also used : IApsEntity(com.agiletec.aps.system.common.entity.model.IApsEntity) AttributeInterface(com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)

Example 7 with AttributeInterface

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

the class ApiUserProfileTypeInterface method updateUserProfileType.

public StringApiResponse updateUserProfileType(JAXBUserProfileType jaxbProfileType) throws Throwable {
    StringApiResponse response = new StringApiResponse();
    try {
        String typeCode = jaxbProfileType.getTypeCode();
        IApsEntity masterProfileType = this.getUserProfileManager().getEntityPrototype(typeCode);
        if (null == masterProfileType) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "User Profile type with code '" + typeCode + "' doesn't exist");
        }
        Map<String, AttributeInterface> attributes = this.getUserProfileManager().getEntityAttributePrototypes();
        IApsEntity profileType = jaxbProfileType.buildEntityType(this.getUserProfileManager().getEntityClass(), attributes);
        ((IEntityTypesConfigurer) this.getUserProfileManager()).updateEntityPrototype(profileType);
        response.setResult(IResponseBuilder.SUCCESS, null);
    } catch (ApiException ae) {
        response.addErrors(ae.getErrors());
        response.setResult(IResponseBuilder.FAILURE, null);
    } catch (Throwable t) {
        _logger.error("Error updating user profile type", t);
        // ApsSystemUtils.logThrowable(t, this, "updateProfileType");
        throw new ApsSystemException("Error updating user profile type", t);
    }
    return response;
}
Also used : IApsEntity(com.agiletec.aps.system.common.entity.model.IApsEntity) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) IEntityTypesConfigurer(com.agiletec.aps.system.common.entity.IEntityTypesConfigurer) StringApiResponse(org.entando.entando.aps.system.services.api.model.StringApiResponse) AttributeInterface(com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 8 with AttributeInterface

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

the class ApiUserProfileTypeInterface method addUserProfileType.

public StringApiResponse addUserProfileType(JAXBUserProfileType jaxbProfileType) throws Throwable {
    StringApiResponse response = new StringApiResponse();
    try {
        String typeCode = jaxbProfileType.getTypeCode();
        IApsEntity masterProfileType = this.getUserProfileManager().getEntityPrototype(typeCode);
        if (null != masterProfileType) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "User Profile type with code '" + typeCode + "' already exists");
        }
        if (typeCode == null || typeCode.length() != 3) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Invalid type code - '" + typeCode + "'");
        }
        Map<String, AttributeInterface> attributes = this.getUserProfileManager().getEntityAttributePrototypes();
        IApsEntity profileType = jaxbProfileType.buildEntityType(this.getUserProfileManager().getEntityClass(), attributes);
        ((IEntityTypesConfigurer) this.getUserProfileManager()).addEntityPrototype(profileType);
        response.setResult(IResponseBuilder.SUCCESS, null);
    } catch (ApiException ae) {
        response.addErrors(ae.getErrors());
        response.setResult(IResponseBuilder.FAILURE, null);
    } catch (Throwable t) {
        _logger.error("Error adding user profile type", t);
        // ApsSystemUtils.logThrowable(t, this, "addProfileType");
        throw new ApsSystemException("Error adding user profile type", t);
    }
    return response;
}
Also used : IApsEntity(com.agiletec.aps.system.common.entity.model.IApsEntity) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) IEntityTypesConfigurer(com.agiletec.aps.system.common.entity.IEntityTypesConfigurer) StringApiResponse(org.entando.entando.aps.system.services.api.model.StringApiResponse) AttributeInterface(com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 9 with AttributeInterface

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

the class DataObjectDAO method addDataObjectRelationsRecord.

/**
 * Add a record in the table 'dataobjectrelations' for every resource, page,
 * other dataobject, role and category associated to the given dataobject).
 *
 * @param dataobject The current dataobject.
 * @param conn The connection to the database.
 * @throws ApsSystemException when connection error are detected.
 */
protected void addDataObjectRelationsRecord(DataObject dataobject, Connection conn) throws ApsSystemException {
    PreparedStatement stat = null;
    try {
        stat = conn.prepareStatement(ADD_DATAOBJECT_REL_RECORD);
        this.addCategoryRelationsRecord(dataobject, true, stat);
        this.addGroupRelationsRecord(dataobject, stat);
        EntityAttributeIterator attributeIter = new EntityAttributeIterator(dataobject);
        while (attributeIter.hasNext()) {
            AttributeInterface currAttribute = (AttributeInterface) attributeIter.next();
        }
        stat.executeBatch();
    } catch (BatchUpdateException e) {
        _logger.error("Error saving record into dataobjectrelations {}", dataobject.getId(), e.getNextException());
        throw new RuntimeException("Error saving record into dataobjectrelations " + dataobject.getId(), e.getNextException());
    } catch (Throwable t) {
        _logger.error("Error saving record into dataobjectrelations {}", dataobject.getId(), t);
        throw new RuntimeException("Error saving record into dataobjectrelations " + dataobject.getId(), t);
    } finally {
        closeDaoResources(null, stat);
    }
}
Also used : PreparedStatement(java.sql.PreparedStatement) AttributeInterface(com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface) EntityAttributeIterator(com.agiletec.aps.system.common.util.EntityAttributeIterator) BatchUpdateException(java.sql.BatchUpdateException)

Example 10 with AttributeInterface

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

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