diff --git a/marklogic-data-hub/src/main/java/com/marklogic/hub/deploy/commands/GenerateHubTDETemplateCommand.java b/marklogic-data-hub/src/main/java/com/marklogic/hub/deploy/commands/GenerateHubTDETemplateCommand.java index 3b35f0ee34..e6c3a25de1 100644 --- a/marklogic-data-hub/src/main/java/com/marklogic/hub/deploy/commands/GenerateHubTDETemplateCommand.java +++ b/marklogic-data-hub/src/main/java/com/marklogic/hub/deploy/commands/GenerateHubTDETemplateCommand.java @@ -19,6 +19,7 @@ import com.marklogic.appdeployer.command.CommandContext; import com.marklogic.appdeployer.command.es.GenerateModelArtifactsCommand; import com.marklogic.client.DatabaseClient; +import com.marklogic.client.eval.EvalResultIterator; import com.marklogic.client.ext.es.CodeGenerationRequest; import com.marklogic.client.ext.es.EntityServicesManager; import com.marklogic.client.ext.es.GeneratedCode; @@ -77,7 +78,14 @@ public void execute(CommandContext context) { File esModel; try { //Write the ES model to a temp file - esModel = File.createTempFile("es-", f.getName()); + String tempDir = System.getProperty("java.io.tmpdir"); + String fileName = f.getName(); + esModel = new File(tempDir, fileName); + String modelString = generateModel(f); + if(modelString == null) { + logger.warn(f.getName() + " is not deployed to the database"); + continue; + } FileUtils.writeStringToFile(esModel, generateModel(f)); } catch (IOException e) { throw new RuntimeException("Unable to generate ES model"); @@ -109,7 +117,11 @@ private String generateModel(File f) { String xquery = "import module namespace hent = \"http://marklogic.com/data-hub/hub-entities\"\n" + "at \"/data-hub/4/impl/hub-entities.xqy\";\n" + String.format("hent:get-model(\"%s\")", extactEntityNameFromFilename(f.getName()).get()); - return hubConfig.newStagingClient().newServerEval().xquery(xquery).eval().next().getString(); + EvalResultIterator resp = hubConfig.newStagingClient().newServerEval().xquery(xquery).eval(); + if (resp.hasNext()) { + return resp.next().getString(); + } + return null ; } public String getEntityNames() {