calculatedFieldsFile = getCalculatedFieldsFile();
Assert.assertNotNull(calculatedFieldsFile, "Destination file cannot be null");
logger.debug("Calculated fields will be saved on file [" + calculatedFieldsFile + "]");
if( !calculatedFieldsFile.getParentFile().exists() ) {
DAOException e = new DAOException("Destination file folder [" + calculatedFieldsFile.getPath()+ "] does not exist");
e.addHint("Check if [" + calculatedFieldsFile.getPath()+ "] folder exist on your server filesystem. If not create it.");
throw e;
}
if( calculatedFieldsFile.exists() ) {
logger.warn("File [" + calculatedFieldsFile + "] already exists. New settings will override the old ones.");
}
document = DocumentHelper.createDocument();
root = document.addElement( ROOT_TAG );
logger.debug("In the target model there are [" + calculatedFields.keySet() + "] entity/es that contain calculated fields" );
it = calculatedFields.keySet().iterator();
while(it.hasNext()) {
entityName = (String)it.next();
logger.debug("Serializing [" + calculatedFields.size() + "] calculated fields for entity [" + entityName + "]");
fields = (List)calculatedFields.get(entityName);
for(int i = 0; i < fields.size(); i++) {
field = (ModelCalculatedField)fields.get(i);
logger.debug("Serializing calculated field [" + field.getName() + "] for entity [" + entityName + "]");
root.addElement( FIELD_TAG )
.addAttribute( FIELD_TAG_ENTIY_ATTR, entityName )
.addAttribute( FIELD_TAG_NAME_ATTR, field.getName() )
.addAttribute( FIELD_TAG_TYPE_ATTR, field.getType() )
.addAttribute( FIELD_TAG_IN_LINE_ATTR, ""+field.isInLine() )
.addCDATA( field.getExpression() );
}
}
guardedWrite(document, calculatedFieldsFile);
} catch(Throwable t){
if(t instanceof DAOException) throw (DAOException)t;
throw new DAOException("An unpredicetd error occurred while saving calculated fields on file [" + calculatedFieldsFile + "]");
} finally {
logger.debug("OUT");
}
}