};
public String getJavaScript() throws Exception {
ExtConfig config = this.extConfig;
AdaptrexPersistenceManager apm = config.getORMPersistenceManager();
if (config.getEntityClass() == null) {
String str = "Adaptrex Model Error: Persistent Class Not Found (" + this.extConfig.getClassName() + ")";
log.warn(str);
return StringUtilities.getErrorJavaScript(str);
}
if (this.namespace == null) {
this.namespace = configComponent.getNamespace();
}
String modelName = config.getModelName();
List<String> modelDefinitionStrings = new ArrayList<String>();
String fullModelName = namespace + ".model." + modelName;
boolean isTouch = this.configComponent.isTouch();
/*
* Get the model definition
*/
log.debug("Creating model definition for " + fullModelName);
ModelDefinition modelDefinition = new ModelDefinition(this.extConfig);
/*
* Add the rest API to the model
*/
modelDefinition.setProxy(this.restProxy);
modelDefinitionStrings.add("Ext.define('" + fullModelName + "', " +
(isTouch ? "{extend:'Ext.data.Model', config:" : "") +
StringUtilities.json(modelDefinition, this.request.getServletContext()) + (isTouch ? "}" : "") + ");\n");
/*
* Get the model's association definitions
*/
getAllAssociations(modelDefinition);
for (Association association : associations) {
ModelDefinition assocModelDef = association.getModelDefinition();
if (assocModelDef != null) {
/*
* If we have a rest proxy for the parent model, add one for associated models
*/
if (this.restProxy != null) {
String restPath = getRestPath(association.getEntityClassName().toLowerCase());
if (!restPath.equals("false")) {
RestProxy associatedProxy = new RestProxy(restPath, extConfig, this.configComponent.isTouch());
assocModelDef.setProxy(associatedProxy);
}
}
modelDefinitionStrings.add("Ext.define('" + assocModelDef.getModelName() + "', " +
(isTouch ? "{extend:'Ext.data.Model', config:" : "") +
StringUtilities.json(assocModelDef, this.request.getServletContext()) + (isTouch ? "}" : "") + ");\n");
}
}
/*
* If we have an entity ID or a key/value configuration on our component,
* we also return an online instance
* TODO: We should add the ability to load this via rest to enable associations
*/
String modelInstanceString = "";
if (this.entityId != null || entityKey != null) {
ModelInstance modelInstance = this.entityId != null
? apm.getModelInstance(this.extConfig, this.entityId)
: apm.getModelInstance(this.extConfig, this.entityKey, this.entityValue);
// ModelInstance modelInstance = this.entityId != null
// ? new ModelInstance(extConfig, this.entityId)
// : new ModelInstance(extConfig, this.entityKey, this.entityValue);