Search in sources :

Example 66 with IApsEntity

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

the class EntityTypeDOM method getXml.

@Override
public String getXml(Map<String, IApsEntity> entityTypes) throws ApsSystemException {
    XMLOutputter out = new XMLOutputter();
    Document document = new Document();
    try {
        Element rootElement = new Element(this.getEntityTypesRootElementName());
        document.setRootElement(rootElement);
        List<String> entityTypeCodes = new ArrayList<>(entityTypes.keySet());
        Collections.sort(entityTypeCodes);
        for (String entityTypeCode : entityTypeCodes) {
            IApsEntity currentEntityType = entityTypes.get(entityTypeCode);
            Element entityTypeElement = this.createTypeElement(currentEntityType);
            rootElement.addContent(entityTypeElement);
        }
        Format format = Format.getPrettyFormat();
        format.setIndent("\t");
        out.setFormat(format);
    } catch (Throwable t) {
        _logger.error("Error building xml", t);
        throw new ApsSystemException("Error building xml", t);
    }
    return out.outputString(document);
}
Also used : XMLOutputter(org.jdom.output.XMLOutputter) Format(org.jdom.output.Format) Element(org.jdom.Element) ArrayList(java.util.ArrayList) IApsEntity(com.agiletec.aps.system.common.entity.model.IApsEntity) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) Document(org.jdom.Document)

Example 67 with IApsEntity

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

the class EntityTypeDOM method createEntityType.

/**
 * Instantiate and initialize an Entity Type starting from the raw
 * configuration data.
 *
 * @param entityElem The element of the Entity Type to initialize.
 * @param entityClass The class of the Entity Type.
 * @return The initialized Entity Type.
 * @throws ApsSystemException If parsing errors are detected.
 */
protected IApsEntity createEntityType(Element entityElem, Class entityClass) throws ApsSystemException {
    try {
        IApsEntity entity = (IApsEntity) entityClass.newInstance();
        entity.setId(null);
        String typeCode = this.extractXmlAttribute(entityElem, "typecode", true);
        entity.setTypeCode(typeCode);
        String typeDescr = this.extractXmlAttribute(entityElem, "typedescr", true);
        entity.setTypeDescription(typeDescr);
        return entity;
    } catch (InstantiationException | IllegalAccessException | ApsSystemException t) {
        throw new ApsSystemException("Error detected while creating a new entity", t);
    }
}
Also used : IApsEntity(com.agiletec.aps.system.common.entity.model.IApsEntity) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException)

Example 68 with IApsEntity

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

the class EntityTypeFactory method extractEntityTypes.

/**
 * Return the Map of the prototypes of the Entity Types (indexed by their code) that the
 * entity service is going to handle.
 * The structure of the Entity Types is obtained from a configuration XML.
 * @param entityClass The class of the entity.
 * @param configItemName The configuration item where the Entity Types are defined.
 * @param entityTypeDom The DOM class that parses the configuration XML.
 * @param entityDom The DOM class that parses the XML representing the single (implemented) entity.
 * @param entityManagerName The entity manager name
 * @return The map of the Entity Types Prototypes, indexed by code.
 * @throws ApsSystemException If errors occurs during the parsing process of the XML.
 */
@Override
public Map<String, IApsEntity> extractEntityTypes(Class entityClass, String configItemName, IEntityTypeDOM entityTypeDom, String entityManagerName, IApsEntityDOM entityDom) throws ApsSystemException {
    Map<String, IApsEntity> entityTypes = null;
    try {
        String xml = this.getConfigManager().getConfigItem(configItemName);
        logger.debug("{} : {}", configItemName, xml);
        entityTypes = entityTypeDom.extractEntityTypes(xml, entityClass, entityDom, entityManagerName);
    } catch (Throwable t) {
        logger.error("Error in the entities initialization process. configItemName:{}", configItemName, t);
        throw new ApsSystemException("Error in the entities initialization process", t);
    }
    return entityTypes;
}
Also used : IApsEntity(com.agiletec.aps.system.common.entity.model.IApsEntity) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException)

Example 69 with IApsEntity

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

the class ApsEntityManager method removeEntityPrototype.

/**
 * Remove an entity type from the catalog.
 *
 * @param entityTypeCode The code of the entity type to remove.
 * @throws ApsSystemException In case of error.
 */
@Override
public void removeEntityPrototype(String entityTypeCode) throws ApsSystemException {
    Map<String, IApsEntity> entityTypes = this.getEntityTypes();
    IApsEntity entityTypeToRemove = entityTypes.get(entityTypeCode);
    if (null == entityTypeToRemove) {
        throw new ApsSystemException("No entity type to remove with code '" + entityTypeCode + "' were found");
    }
    entityTypes.remove(entityTypeCode);
    this.updateEntityPrototypes(entityTypes);
    this.notifyEntityTypesChanging(entityTypeToRemove, null, EntityTypesChangingEvent.REMOVE_OPERATION_CODE);
}
Also used : IApsEntity(com.agiletec.aps.system.common.entity.model.IApsEntity) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException)

Example 70 with IApsEntity

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

the class CmsCacheWrapperManager method updateFromEntityTypesChanging.

@Override
public void updateFromEntityTypesChanging(EntityTypesChangingEvent event) {
    try {
        String entityManagerName = event.getEntityManagerName();
        if (!entityManagerName.equals(JacmsSystemConstants.CONTENT_MANAGER))
            return;
        if (event.getOperationCode() == EntityTypesChangingEvent.INSERT_OPERATION_CODE)
            return;
        IApsEntity oldEntityType = event.getOldEntityType();
        _logger.info("Notified content type modify : type {}", oldEntityType.getTypeCode());
        String typeGroupKey = JacmsSystemConstants.CONTENT_TYPE_CACHE_GROUP_PREFIX + oldEntityType.getTypeCode();
        this.getCacheInfoManager().flushGroup(ICacheInfoManager.DEFAULT_CACHE_NAME, typeGroupKey);
    } catch (Throwable t) {
        _logger.error("Error notifing event {}", EntityTypesChangingEvent.class.getName(), t);
    }
}
Also used : IApsEntity(com.agiletec.aps.system.common.entity.model.IApsEntity)

Aggregations

IApsEntity (com.agiletec.aps.system.common.entity.model.IApsEntity)70 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)24 AttributeInterface (com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)16 IEntityManager (com.agiletec.aps.system.common.entity.IEntityManager)12 IEntityTypesConfigurer (com.agiletec.aps.system.common.entity.IEntityTypesConfigurer)11 ApiException (org.entando.entando.aps.system.services.api.model.ApiException)11 ArrayList (java.util.ArrayList)9 StringApiResponse (org.entando.entando.aps.system.services.api.model.StringApiResponse)6 EntitySearchFilter (com.agiletec.aps.system.common.entity.model.EntitySearchFilter)5 MonoListAttribute (com.agiletec.aps.system.common.entity.model.attribute.MonoListAttribute)4 Lang (com.agiletec.aps.system.services.lang.Lang)4 List (java.util.List)4 BeanComparator (org.apache.commons.beanutils.BeanComparator)4 ListAttribute (com.agiletec.aps.system.common.entity.model.attribute.ListAttribute)3 ListAttributeInterface (com.agiletec.aps.system.common.entity.model.attribute.ListAttributeInterface)3 ApiError (org.entando.entando.aps.system.services.api.model.ApiError)3 IUserProfile (org.entando.entando.aps.system.services.userprofile.model.IUserProfile)3 Widget (com.agiletec.aps.system.services.page.Widget)2 ApsProperties (com.agiletec.aps.util.ApsProperties)2 EntityAttributeConfigAction (com.agiletec.apsadmin.system.entity.type.EntityAttributeConfigAction)2