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);
}
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);
}
}
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;
}
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);
}
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);
}
}
Aggregations