private File createEmptyRestExtensionFile(String entityName, String extensionName, FlowType flowType, CodeFormat codeFormat) { Path restDir = getRestDirectory(entityName, flowType); return createEmptyFile(restDir, "services", extensionName + "." + codeFormat); }
private void writeMetadataForFile(File file, String metadataTemplatePath, String metadataName) { String fileContent = getFileContent(metadataTemplatePath, metadataName); File metadataFile = createEmptyMetadataForFile(file, metadataName); writeToFile(fileContent, metadataFile); }
@Override public void createRestExtension(String entityName, String extensionName, FlowType flowType, CodeFormat codeFormat) throws ScaffoldingValidationException { logger.info(extensionName); if(!validator.isUniqueRestServiceExtension(extensionName)) { throw new ScaffoldingValidationException("A rest service extension with the same name as " + extensionName + " already exists."); } String scaffoldRestServicesPath = "scaffolding/rest/services/"; String fileContent = getFileContent(scaffoldRestServicesPath + codeFormat + "/template." + codeFormat, extensionName); File dstFile = createEmptyRestExtensionFile(entityName, extensionName, flowType, codeFormat); writeToFile(fileContent, dstFile); writeMetadataForFile(dstFile, scaffoldRestServicesPath + "metadata/template.xml", extensionName); }
@Override public void createRestTransform(String entityName, String transformName, FlowType flowType, CodeFormat codeFormat) throws ScaffoldingValidationException { logger.info(transformName); if(!validator.isUniqueRestTransform(transformName)) { throw new ScaffoldingValidationException("A rest transform with the same name as " + transformName + " already exists."); } String scaffoldRestTransformsPath = "scaffolding/rest/transforms/"; String fileContent = getFileContent(scaffoldRestTransformsPath + codeFormat + "/template." + codeFormat, transformName); File dstFile = createEmptyRestTransformFile(entityName, transformName, flowType, codeFormat); writeToFile(fileContent, dstFile); writeMetadataForFile(dstFile, scaffoldRestTransformsPath + "metadata/template.xml", transformName); }
DataFormat dataFormat, boolean useEsModel, String mappingNameWithVersion) { try { Path flowDir = getFlowDir(entityName, flowName, flowType); flowDir.toFile().mkdirs(); ContentPlugin cp = new ContentPlugin(hubConfig.newStagingClient()); String content = cp.getContents(entityName, codeFormat, flowType, mappingNameWithVersion); writeBuffer(content, flowDir.resolve("content." + codeFormat)); } else { writeFile("scaffolding/" + flowType + "/" + codeFormat + "/content." + codeFormat, flowDir.resolve("content." + codeFormat)); writeFile("scaffolding/" + flowType + "/" + codeFormat + "/collector." + codeFormat, flowDir.resolve("collector." + codeFormat)); writeFile("scaffolding/" + flowType + "/" + codeFormat + "/writer." + codeFormat, flowDir.resolve("writer." + codeFormat)); writeFile("scaffolding/" + flowType + "/" + codeFormat + "/headers." + codeFormat, flowDir.resolve("headers." + codeFormat)); writeFile("scaffolding/" + flowType + "/" + codeFormat + "/triples." + codeFormat, flowDir.resolve("triples." + codeFormat)); writeFile("scaffolding/" + flowType + "/" + codeFormat + "/main." + codeFormat, flowDir.resolve("main." + codeFormat));
@Override public boolean updateLegacyFlow(String fromVersion, String entityName, String flowName, FlowType flowType) { boolean updated = false; Path flowDir = getFlowDir(entityName, flowName, flowType); File[] mainFiles = flowDir.toFile().listFiles((dir, name) -> name.matches("main\\.(sjs|xqy)")); if (mainFiles.length < 1 || !flowDir.resolve(flowName + ".properties").toFile().exists()) { Document doc = readLegacyFlowXml(file); if (doc.getDocumentElement().getLocalName().equals("flow")) { DataFormat dataFormat = null; suffix = "-1x"; writeFile("scaffolding/" + flowType + "/" + codeFormat + "/main-legacy" + suffix + "." + codeFormat, flowDir.resolve("main." + codeFormat)); updateLegacySjsWriter(flowDir);
@Override public void updateLegacyEntity(String entityName) { Path entityDir = project.getHubEntitiesDir().resolve(entityName); File[] entityFiles = entityDir.toFile().listFiles((dir, name) -> name.matches("[^.]+\\.entity\\.json")); if (entityFiles != null && entityFiles.length == 0) { String fileContents = getFileContent("scaffolding/Entity.json", entityName); writeToFile(fileContents, entityDir.resolve(entityName + ".entity.json").toFile()); } }
private Plugin createPluginObj(String flowPath, String pluginType, FlowType flowType, CodeFormat codeFormat) { String parentDirectory = ScaffoldingImpl.getAbsolutePath(flowPath, pluginType); String filename = pluginType + "." + codeFormat; String templateFilePath = "scaffolding/" + flowType + "/" + codeFormat + "/" + pluginType + "." + codeFormat; return new Plugin(parentDirectory, filename, templateFilePath); }
private Path getRestDirectory(String entityName, FlowType flowType) { return getFlowDir(entityName, "REST", flowType); }
@Override public void createFlow(String entityName, String flowName, FlowType flowType, CodeFormat codeFormat, DataFormat dataFormat) { createFlow(entityName, flowName, flowType, codeFormat, dataFormat, true); }
@Override public void createEntity(String entityName) { Path entityDir = project.getEntityDir(entityName); entityDir.toFile().mkdirs(); if(entityDir.toFile().exists()){ String fileContents = getFileContent("scaffolding/Entity.json", entityName); writeToFile(fileContents, entityDir.resolve(entityName + ".entity.json").toFile()); } }
private void createPlugins(String entityName, FlowType flowType, CodeFormat codeFormat) throws IOException { String flowName = entityName + flowType + "-flow"; String flowTypePath = ScaffoldingImpl.getAbsolutePath(projectPath, "entities", entityName, flowType.toString()); String flowPath = ScaffoldingImpl.getAbsolutePath(flowTypePath, flowName); List<Plugin> plugins = new ArrayList<>(); if (flowType.equals(FlowType.HARMONIZE)) { plugins.add(createPluginObj(flowPath, "collector", flowType, codeFormat)); } plugins.add(createPluginObj(flowPath, "content", flowType, codeFormat)); plugins.add(createPluginObj(flowPath, "headers", flowType, codeFormat)); plugins.add(createPluginObj(flowPath, "triples", flowType, codeFormat)); for (Plugin plugin : plugins) { createFile(plugin.getParentDirectory(), plugin.getFilename(), plugin.getTemplateFilePath()); } }
public boolean update2xFlow(String entityName, String flowName, FlowType flowType) { boolean updated = false; Path flowDir = getFlowDir(entityName, flowName, flowType); Path mainPath = flowDir.resolve("main.sjs"); Path xqyMainPath = flowDir.resolve("main.xqy");
private File createEmptyRestTransformFile(String entityName, String transformName, FlowType flowType, CodeFormat codeFormat) { Path restDir = getRestDirectory(entityName, flowType); return createEmptyFile(restDir, "transforms", transformName + "." + codeFormat); }